forked from github/server
space savings: update data files, remove names from NPC units where their name is their race.
This commit is contained in:
parent
0fead39b41
commit
2c077c25e8
5 changed files with 36 additions and 23 deletions
|
@ -642,9 +642,6 @@ unit *read_unit(struct gamedata *data)
|
|||
READ_INT(data->store, &number);
|
||||
set_number(u, number);
|
||||
|
||||
|
||||
|
||||
|
||||
READ_INT(data->store, &n);
|
||||
u->age = (short)n;
|
||||
|
||||
|
@ -1711,6 +1708,13 @@ int readgame(const char *filename, int backup)
|
|||
unit *u = read_unit(&gdata);
|
||||
sc_mage *mage;
|
||||
|
||||
if (gdata.version < AUTO_RACENAME_VERSION) {
|
||||
if (u->name && fval(u->faction, FFL_NPC)) {
|
||||
if (unit_name_equals_race(u)) {
|
||||
unit_setname(u, NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
assert(u->region == NULL);
|
||||
u->region = r;
|
||||
*up = u;
|
||||
|
|
|
@ -1853,8 +1853,9 @@ char *write_unitname(const unit * u, char *buffer, size_t size)
|
|||
if (u->name) {
|
||||
slprintf(buffer, size, "%s (%s)", u->name, itoa36(u->no));
|
||||
} else {
|
||||
const struct locale * lang = u->faction ? u->faction->locale : default_locale;
|
||||
const char * name = rc_name_s(u->_race, u->number == 1 ? NAME_SINGULAR : NAME_PLURAL);
|
||||
slprintf(buffer, size, "%s (%s)", locale_string(u->faction->locale, name), itoa36(u->no));
|
||||
slprintf(buffer, size, "%s (%s)", locale_string(lang, name), itoa36(u->no));
|
||||
}
|
||||
buffer[size - 1] = 0;
|
||||
return buffer;
|
||||
|
@ -1866,15 +1867,17 @@ const char *unitname(const unit * u)
|
|||
return write_unitname(u, ubuf, sizeof(name));
|
||||
}
|
||||
|
||||
void update_monster_name(unit *u) {
|
||||
bool unit_name_equals_race(const unit *u) {
|
||||
if (u->name) {
|
||||
char sing[32], plur[32];
|
||||
const struct locale *lang = u->faction->locale;
|
||||
if (!u->name) return;
|
||||
rc_name(u->_race, NAME_SINGULAR, sing, sizeof(sing));
|
||||
rc_name(u->_race, NAME_PLURAL, plur, sizeof(plur));
|
||||
if (strcmp(u->name, sing) == 0 || strcmp(u->name, plur) == 0 ||
|
||||
strcmp(u->name, locale_string(lang, sing)) == 0 ||
|
||||
strcmp(u->name, locale_string(lang, plur)) == 0) {
|
||||
unit_setname(u, 0);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -249,7 +249,7 @@ extern "C" {
|
|||
|
||||
const char *unitname(const struct unit *u);
|
||||
char *write_unitname(const struct unit *u, char *buffer, size_t size);
|
||||
void update_monster_name(struct unit *u);
|
||||
bool unit_name_equals_race(const struct unit *u);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -175,16 +175,22 @@ static void test_update_monster_name(CuTest *tc) {
|
|||
locale_setstring(lang, rc_name_s(u->_race, NAME_PLURAL), "Menschen");
|
||||
|
||||
unit_setname(u, "Hodor");
|
||||
update_monster_name(u);
|
||||
CuAssertStrEquals(tc, "Hodor", u->name);
|
||||
CuAssertTrue(tc, !unit_name_equals_race(u));
|
||||
|
||||
unit_setname(u, "Menschling");
|
||||
CuAssertTrue(tc, !unit_name_equals_race(u));
|
||||
|
||||
unit_setname(u, rc_name_s(u->_race, NAME_SINGULAR));
|
||||
CuAssertTrue(tc, unit_name_equals_race(u));
|
||||
|
||||
unit_setname(u, rc_name_s(u->_race, NAME_PLURAL));
|
||||
CuAssertTrue(tc, unit_name_equals_race(u));
|
||||
|
||||
unit_setname(u, "Mensch");
|
||||
update_monster_name(u);
|
||||
CuAssertPtrEquals(tc, 0, u->name);
|
||||
CuAssertTrue(tc, unit_name_equals_race(u));
|
||||
|
||||
unit_setname(u, "Menschen");
|
||||
update_monster_name(u);
|
||||
CuAssertPtrEquals(tc, 0, u->name);
|
||||
CuAssertTrue(tc, unit_name_equals_race(u));
|
||||
|
||||
test_cleanup();
|
||||
}
|
||||
|
|
|
@ -73,8 +73,8 @@
|
|||
#define INTFLAGS_VERSION 342 /* turn 876, FFL_NPC is now bit 25, flags is an int */
|
||||
#define SAVEGAMEID_VERSION 343 /* instead of XMLNAME, save the game.id parameter from the config */
|
||||
#define BUILDNO_VERSION 344 /* storing the build number in the save */
|
||||
|
||||
#define AUTO_RACENAME_VERSION 345 /* NPC units with name==NULL will automatically get their race for a name */
|
||||
#define MIN_VERSION CURSETYPE_VERSION /* minimal datafile we support */
|
||||
#define RELEASE_VERSION BUILDNO_VERSION /* current datafile */
|
||||
#define RELEASE_VERSION AUTO_RACENAME_VERSION /* current datafile */
|
||||
|
||||
#define STREAM_VERSION 2 /* internal encoding of binary files */
|
||||
|
|
Loading…
Reference in a new issue