diff --git a/src/creport.c b/src/creport.c index 12cb4e5b5..b68f3e4fe 100644 --- a/src/creport.c +++ b/src/creport.c @@ -1365,8 +1365,8 @@ static void cr_output_region(FILE * F, report_context * ctx, region * r) unit *u; int stealthmod = stealth_modifier(r->seen.mode); - if (r->display && r->display[0]) - fprintf(F, "\"%s\";Beschr\n", r->display); + if (r->land && r->land->display && r->land->display[0]) + fprintf(F, "\"%s\";Beschr\n", r->land->display); if (fval(r->terrain, LAND_REGION)) { assert(r->land); fprintf(F, "%d;Bauern\n", rpeasants(r)); diff --git a/src/kernel/region.c b/src/kernel/region.c index e8da83c50..f770ec089 100644 --- a/src/kernel/region.c +++ b/src/kernel/region.c @@ -825,8 +825,8 @@ void free_land(land_region * lr) lr->demands = d->next; free(d); } - if (lr->name) - free(lr->name); + free(lr->name); + free(lr->display); free(lr); } @@ -894,7 +894,6 @@ void free_region(region * r) { if (last == r) last = NULL; - free(r->display); if (r->land) free_land(r->land); @@ -1088,7 +1087,6 @@ void terraform_region(region * r, const terrain_type * terrain) terraform_resources(r); if (!fval(terrain, LAND_REGION)) { - region_setinfo(r, NULL); if (r->land) { free_land(r->land); r->land = NULL; @@ -1444,13 +1442,14 @@ faction *update_owners(region * r) void region_setinfo(struct region *r, const char *info) { - free(r->display); - r->display = info ? strdup(info) : 0; + assert(r->land); + free(r->land->display); + r->land->display = info ? strdup(info) : 0; } const char *region_getinfo(const region * r) { - return r->display ? r->display : ""; + return (r->land && r->land->display) ? r->land->display : ""; } void region_setname(struct region *r, const char *name) diff --git a/src/kernel/region.h b/src/kernel/region.h index c81411468..827ddbdab 100644 --- a/src/kernel/region.h +++ b/src/kernel/region.h @@ -96,7 +96,7 @@ extern "C" { typedef struct land_region { char *name; - /* TODO: demand kann nach Konvertierung entfernt werden. */ + char *display; demand *demands; const struct item_type *herbtype; short herbs; @@ -122,7 +122,6 @@ extern "C" { int uid; /* a unique id */ int x, y; struct plane *_plane; /* to access, use rplane(r) */ - char *display; int flags; unsigned short age; struct message_list *msgs; diff --git a/src/kernel/save.c b/src/kernel/save.c index f1f4f3c60..a719cb17b 100644 --- a/src/kernel/save.c +++ b/src/kernel/save.c @@ -377,7 +377,7 @@ race_t typus2race(unsigned char typus) return NORACE; } -static void read_alliances(struct gamedata *data) +static void read_alliances(gamedata *data) { storage *store = data->store; char pbuf[8]; @@ -492,7 +492,7 @@ void write_planes(storage *store) { } } -void write_alliances(struct gamedata *data) +void write_alliances(gamedata *data) { alliance *al = alliances; while (al) { @@ -524,7 +524,7 @@ static int resolve_owner(variant id, void *address) return result; } -static void read_owner(struct gamedata *data, region_owner ** powner) +static void read_owner(gamedata *data, region_owner ** powner) { int since_turn; @@ -563,7 +563,7 @@ static void read_owner(struct gamedata *data, region_owner ** powner) } } -static void write_owner(struct gamedata *data, region_owner * owner) +static void write_owner(gamedata *data, region_owner * owner) { if (owner) { faction *f; @@ -821,7 +821,7 @@ unit *read_unit(gamedata *data) return u; } -void write_unit(struct gamedata *data, const unit * u) +void write_unit(gamedata *data, const unit * u) { order *ord; int p = 0; @@ -885,7 +885,23 @@ void write_unit(struct gamedata *data, const unit * u) WRITE_SECTION(data->store); } -static region *readregion(struct gamedata *data, int x, int y) +static void read_regioninfo(gamedata *data, region *r) { + if (lomem) { + READ_STR(data->store, NULL, 0); + } + else { + char info[DISPLAYSIZE]; + READ_STR(data->store, info, sizeof(info)); + if (unicode_utf8_trim(info) != 0) { + log_warning("trim region %d info to '%s'", r->uid, info); + } + if (r->land) { + region_setinfo(r, info); + } + } +} + +static region *readregion(gamedata *data, int x, int y) { region *r = findregion(x, y); const terrain_type *terrain; @@ -915,16 +931,8 @@ static region *readregion(struct gamedata *data, int x, int y) } r->land = 0; } - if (lomem) { - READ_STR(data->store, NULL, 0); - } - else { - char info[DISPLAYSIZE]; - READ_STR(data->store, info, sizeof(info)); - if (unicode_utf8_trim(info)!=0) { - log_warning("trim region %d info to '%s'", uid, info); - }; - region_setinfo(r, info); + if (data->version < LANDDISPLAY_VERSION) { + read_regioninfo(data, r); } READ_STR(data->store, name, sizeof(name)); @@ -941,15 +949,18 @@ static region *readregion(struct gamedata *data, int x, int y) if (fval(r->terrain, LAND_REGION)) { r->land = calloc(1, sizeof(land_region)); READ_STR(data->store, name, sizeof(name)); - if (unicode_utf8_trim(name)!=0) { - log_warning("trim region %d name to '%s'", uid, name); - }; + if (unicode_utf8_trim(name) != 0) { + log_warning("trim region %d name to '%s'", uid, name); + }; r->land->name = strdup(name); } if (r->land) { int i; rawmaterial **pres = &r->resources; + if (data->version >= LANDDISPLAY_VERSION) { + read_regioninfo(data, r); + } READ_INT(data->store, &i); if (i < 0) { log_error("number of trees in %s is %d.", regionname(r, NULL), i); @@ -1069,24 +1080,23 @@ region *read_region(gamedata *data) return r; } -void writeregion(struct gamedata *data, const region * r) +void writeregion(gamedata *data, const region * r) { assert(r); assert(data); WRITE_INT(data->store, r->uid); - WRITE_STR(data->store, region_getinfo(r)); WRITE_TOK(data->store, r->terrain->_name); WRITE_INT(data->store, r->flags & RF_SAVEMASK); WRITE_INT(data->store, r->age); WRITE_SECTION(data->store); - if (fval(r->terrain, LAND_REGION)) { + if (r->land) { const item_type *rht; struct demand *demand; rawmaterial *res = r->resources; - assert(r->land); WRITE_STR(data->store, (const char *)r->land->name); + WRITE_STR(data->store, region_getinfo(r)); assert(rtrees(r, 0) >= 0); assert(rtrees(r, 1) >= 0); assert(rtrees(r, 2) >= 0); @@ -1122,11 +1132,9 @@ void writeregion(struct gamedata *data, const region * r) } WRITE_TOK(data->store, "end"); WRITE_SECTION(data->store); -#if RELEASE_VERSION>=REGIONOWNER_VERSION WRITE_INT(data->store, region_get_morale(r)); write_owner(data, r->land->ownership); WRITE_SECTION(data->store); -#endif } write_attribs(data->store, r->attribs, r); WRITE_SECTION(data->store); @@ -1243,7 +1251,7 @@ void _test_write_password(gamedata *data, const faction *f) { write_password(data, f); } -faction *read_faction(struct gamedata * data) +faction *read_faction(gamedata * data) { ally **sfp; int planes, n; @@ -1395,7 +1403,7 @@ faction *read_faction(struct gamedata * data) return f; } -void write_faction(struct gamedata *data, const faction * f) +void write_faction(gamedata *data, const faction * f) { ally *sf; ursprung *ur; @@ -1584,7 +1592,7 @@ void write_ship(gamedata *data, const ship *sh) write_attribs(store, sh->attribs, sh); } -ship *read_ship(struct gamedata *data) +ship *read_ship(gamedata *data) { char name[DISPLAYSIZE]; ship *sh; diff --git a/src/laws.c b/src/laws.c index c3c7d968e..d7f73fa6c 100644 --- a/src/laws.c +++ b/src/laws.c @@ -1559,11 +1559,11 @@ int display_cmd(unit * u, struct order *ord) break; case P_REGION: - if (u->faction != region_get_owner(r)) { + if (!r->land || u->faction != region_get_owner(r)) { cmistake(u, ord, 147, MSG_EVENT); break; } - s = &r->display; + s = &r->land->display; break; default: diff --git a/src/laws.test.c b/src/laws.test.c index 4d6adbfe9..9f7884fc5 100644 --- a/src/laws.test.c +++ b/src/laws.test.c @@ -227,7 +227,7 @@ static void test_display_cmd(CuTest *tc) { ord = create_order(K_DISPLAY, f->locale, "%s Hodor", LOC(f->locale, parameters[P_REGION])); CuAssertIntEquals(tc, 0, display_cmd(u, ord)); - CuAssertPtrEquals(tc, NULL, r->display); + CuAssertPtrEquals(tc, NULL, r->land->display); free_order(ord); test_cleanup(); diff --git a/src/report.c b/src/report.c index 18d48b86b..2dac94011 100644 --- a/src/report.c +++ b/src/report.c @@ -1069,15 +1069,15 @@ void report_region(struct stream *out, const region * r, faction * f) if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); - if (r->display && r->display[0]) { + if (r->land && r->land->display && r->land->display[0]) { bytes = (int)strlcpy(bufp, " ", size); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); - bytes = (int)strlcpy(bufp, r->display, size); + bytes = (int)strlcpy(bufp, r->land->display, size); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); - n = r->display[strlen(r->display) - 1]; + n = r->land->display[strlen(r->land->display) - 1]; if (n != '!' && n != '?' && n != '.') { bytes = (int)strlcpy(bufp, ".", size); if (wrptr(&bufp, &size, bytes) != 0) diff --git a/src/util/gamedata.h b/src/util/gamedata.h index 7ff7569ba..7d355f86b 100644 --- a/src/util/gamedata.h +++ b/src/util/gamedata.h @@ -38,6 +38,7 @@ #define SORTKEYS_VERSION 358 /* at_keys is sorted */ #define FAMILIAR_FIX_VERSION 359 /* familiar links are fixed */ #define SKILLSORT_VERSION 360 /* u->skills is sorted */ +#define LANDDISPLAY_VERSION 360 /* r.display is now in r.land.display */ /* unfinished: */ #define CRYPT_VERSION 400 /* passwords are encrypted */