gamedata version SHIP_NUMBER_VERSION

This commit is contained in:
Enno Rehling 2019-10-05 20:31:00 +02:00
parent f02c4cbaeb
commit 84633b50e1
4 changed files with 18 additions and 9 deletions

View file

@ -45,8 +45,9 @@
#define FIX_RES_BASE_VERSION 367 /* fixing resource base */ #define FIX_RES_BASE_VERSION 367 /* fixing resource base */
#define FIX_CLONES_VERSION 368 /* dissolve clones */ #define FIX_CLONES_VERSION 368 /* dissolve clones */
#define FIX_MIGRANT_AURA_VERSION 369 /* bug 2585, migrants with aura */ #define FIX_MIGRANT_AURA_VERSION 369 /* bug 2585, migrants with aura */
#define SHIP_NUMBER_VERISON 370 /* ships have a number */
#define RELEASE_VERSION FIX_MIGRANT_AURA_VERSION /* current datafile */ #define RELEASE_VERSION SHIP_NUMBER_VERISON /* current datafile */
#define MIN_VERSION UIDHASH_VERSION /* minimal datafile we support */ #define MIN_VERSION UIDHASH_VERSION /* minimal datafile we support */
#define MAX_VERSION RELEASE_VERSION /* change this if we can need to read the future datafile, and we can do so */ #define MAX_VERSION RELEASE_VERSION /* change this if we can need to read the future datafile, and we can do so */

View file

@ -1283,6 +1283,7 @@ void write_ship(gamedata *data, const ship *sh)
WRITE_STR(store, (const char *)sh->name); WRITE_STR(store, (const char *)sh->name);
WRITE_STR(store, sh->display ? (const char *)sh->display : ""); WRITE_STR(store, sh->display ? (const char *)sh->display : "");
WRITE_TOK(store, sh->type->_name); WRITE_TOK(store, sh->type->_name);
WRITE_INT(store, sh->number);
WRITE_INT(store, sh->size); WRITE_INT(store, sh->size);
WRITE_INT(store, sh->damage); WRITE_INT(store, sh->damage);
WRITE_INT(store, sh->flags & SFL_SAVEMASK); WRITE_INT(store, sh->flags & SFL_SAVEMASK);
@ -1320,6 +1321,12 @@ ship *read_ship(gamedata *data)
} }
assert(sh->type || !"ship_type not registered!"); assert(sh->type || !"ship_type not registered!");
if (data->version < SHIP_NUMBER_VERISON) {
sh->number = 1;
}
else {
READ_INT(store, &sh->number);
}
READ_INT(store, &sh->size); READ_INT(store, &sh->size);
READ_INT(store, &sh->damage); READ_INT(store, &sh->damage);
if (data->version >= FOSS_VERSION) { if (data->version >= FOSS_VERSION) {

View file

@ -389,7 +389,7 @@ int shipcapacity(const ship * sh)
{ {
int i = sh->type->cargo; int i = sh->type->cargo;
if (sh->type->construction && sh->size != sh->type->construction->maxsize) if (sh->type->construction && sh->size < sh->number * sh->type->construction->maxsize)
return 0; return 0;
if (sh->damage) { if (sh->damage) {
@ -465,17 +465,17 @@ void write_ship_reference(const struct ship *sh, struct storage *store)
WRITE_INT(store, (sh && sh->region) ? sh->no : 0); WRITE_INT(store, (sh && sh->region) ? sh->no : 0);
} }
void ship_setname(ship * self, const char *name) void ship_setname(ship * sh, const char *name)
{ {
free(self->name); free(sh->name);
self->name = name ? str_strdup(name) : 0; sh->name = name ? str_strdup(name) : 0;
} }
const char *ship_getname(const ship * self) const char *ship_getname(const ship * sh)
{ {
return self->name; return sh->name;
} }
int ship_damage_percent(const ship *ship) { int ship_damage_percent(const ship *sh) {
return (ship->damage * 100 + DAMAGE_SCALE - 1) / (ship->size * DAMAGE_SCALE); return (sh->damage * 100 + DAMAGE_SCALE - 1) / (sh->size * DAMAGE_SCALE);
} }

View file

@ -73,6 +73,7 @@ extern "C" {
struct ship *nexthash; struct ship *nexthash;
struct unit * _owner; /* never use directly, always use ship_owner() */ struct unit * _owner; /* never use directly, always use ship_owner() */
int no; int no;
int number;
struct region *region; struct region *region;
char *name; char *name;
char *display; char *display;