diff --git a/src/kernel/gamedata.h b/src/kernel/gamedata.h index bc1701173..b0fd7762c 100644 --- a/src/kernel/gamedata.h +++ b/src/kernel/gamedata.h @@ -45,8 +45,9 @@ #define FIX_RES_BASE_VERSION 367 /* fixing resource base */ #define FIX_CLONES_VERSION 368 /* dissolve clones */ #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 MAX_VERSION RELEASE_VERSION /* change this if we can need to read the future datafile, and we can do so */ diff --git a/src/kernel/save.c b/src/kernel/save.c index 2eb36b134..2774f3401 100644 --- a/src/kernel/save.c +++ b/src/kernel/save.c @@ -1283,6 +1283,7 @@ void write_ship(gamedata *data, const ship *sh) WRITE_STR(store, (const char *)sh->name); WRITE_STR(store, sh->display ? (const char *)sh->display : ""); WRITE_TOK(store, sh->type->_name); + WRITE_INT(store, sh->number); WRITE_INT(store, sh->size); WRITE_INT(store, sh->damage); WRITE_INT(store, sh->flags & SFL_SAVEMASK); @@ -1320,6 +1321,12 @@ ship *read_ship(gamedata *data) } 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->damage); if (data->version >= FOSS_VERSION) { diff --git a/src/kernel/ship.c b/src/kernel/ship.c index d1657b926..6d458843e 100644 --- a/src/kernel/ship.c +++ b/src/kernel/ship.c @@ -389,7 +389,7 @@ int shipcapacity(const ship * sh) { 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; 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); } -void ship_setname(ship * self, const char *name) +void ship_setname(ship * sh, const char *name) { - free(self->name); - self->name = name ? str_strdup(name) : 0; + free(sh->name); + 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) { - return (ship->damage * 100 + DAMAGE_SCALE - 1) / (ship->size * DAMAGE_SCALE); +int ship_damage_percent(const ship *sh) { + return (sh->damage * 100 + DAMAGE_SCALE - 1) / (sh->size * DAMAGE_SCALE); } diff --git a/src/kernel/ship.h b/src/kernel/ship.h index cd6966040..6c4e0bf95 100644 --- a/src/kernel/ship.h +++ b/src/kernel/ship.h @@ -73,6 +73,7 @@ extern "C" { struct ship *nexthash; struct unit * _owner; /* never use directly, always use ship_owner() */ int no; + int number; struct region *region; char *name; char *display;