move region display to land_region struct, oceans do not have descriptions.

This commit is contained in:
Enno Rehling 2017-09-16 07:58:57 +02:00
parent 8c6362002e
commit 423fe65377
8 changed files with 52 additions and 45 deletions

View file

@ -1365,8 +1365,8 @@ static void cr_output_region(FILE * F, report_context * ctx, region * r)
unit *u; unit *u;
int stealthmod = stealth_modifier(r->seen.mode); int stealthmod = stealth_modifier(r->seen.mode);
if (r->display && r->display[0]) if (r->land && r->land->display && r->land->display[0])
fprintf(F, "\"%s\";Beschr\n", r->display); fprintf(F, "\"%s\";Beschr\n", r->land->display);
if (fval(r->terrain, LAND_REGION)) { if (fval(r->terrain, LAND_REGION)) {
assert(r->land); assert(r->land);
fprintf(F, "%d;Bauern\n", rpeasants(r)); fprintf(F, "%d;Bauern\n", rpeasants(r));

View file

@ -825,8 +825,8 @@ void free_land(land_region * lr)
lr->demands = d->next; lr->demands = d->next;
free(d); free(d);
} }
if (lr->name)
free(lr->name); free(lr->name);
free(lr->display);
free(lr); free(lr);
} }
@ -894,7 +894,6 @@ void free_region(region * r)
{ {
if (last == r) if (last == r)
last = NULL; last = NULL;
free(r->display);
if (r->land) if (r->land)
free_land(r->land); free_land(r->land);
@ -1088,7 +1087,6 @@ void terraform_region(region * r, const terrain_type * terrain)
terraform_resources(r); terraform_resources(r);
if (!fval(terrain, LAND_REGION)) { if (!fval(terrain, LAND_REGION)) {
region_setinfo(r, NULL);
if (r->land) { if (r->land) {
free_land(r->land); free_land(r->land);
r->land = NULL; r->land = NULL;
@ -1444,13 +1442,14 @@ faction *update_owners(region * r)
void region_setinfo(struct region *r, const char *info) void region_setinfo(struct region *r, const char *info)
{ {
free(r->display); assert(r->land);
r->display = info ? strdup(info) : 0; free(r->land->display);
r->land->display = info ? strdup(info) : 0;
} }
const char *region_getinfo(const region * r) 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) void region_setname(struct region *r, const char *name)

View file

@ -96,7 +96,7 @@ extern "C" {
typedef struct land_region { typedef struct land_region {
char *name; char *name;
/* TODO: demand kann nach Konvertierung entfernt werden. */ char *display;
demand *demands; demand *demands;
const struct item_type *herbtype; const struct item_type *herbtype;
short herbs; short herbs;
@ -122,7 +122,6 @@ extern "C" {
int uid; /* a unique id */ int uid; /* a unique id */
int x, y; int x, y;
struct plane *_plane; /* to access, use rplane(r) */ struct plane *_plane; /* to access, use rplane(r) */
char *display;
int flags; int flags;
unsigned short age; unsigned short age;
struct message_list *msgs; struct message_list *msgs;

View file

@ -377,7 +377,7 @@ race_t typus2race(unsigned char typus)
return NORACE; return NORACE;
} }
static void read_alliances(struct gamedata *data) static void read_alliances(gamedata *data)
{ {
storage *store = data->store; storage *store = data->store;
char pbuf[8]; 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; alliance *al = alliances;
while (al) { while (al) {
@ -524,7 +524,7 @@ static int resolve_owner(variant id, void *address)
return result; return result;
} }
static void read_owner(struct gamedata *data, region_owner ** powner) static void read_owner(gamedata *data, region_owner ** powner)
{ {
int since_turn; 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) { if (owner) {
faction *f; faction *f;
@ -821,7 +821,7 @@ unit *read_unit(gamedata *data)
return u; return u;
} }
void write_unit(struct gamedata *data, const unit * u) void write_unit(gamedata *data, const unit * u)
{ {
order *ord; order *ord;
int p = 0; int p = 0;
@ -885,7 +885,23 @@ void write_unit(struct gamedata *data, const unit * u)
WRITE_SECTION(data->store); 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); region *r = findregion(x, y);
const terrain_type *terrain; const terrain_type *terrain;
@ -915,16 +931,8 @@ static region *readregion(struct gamedata *data, int x, int y)
} }
r->land = 0; r->land = 0;
} }
if (lomem) { if (data->version < LANDDISPLAY_VERSION) {
READ_STR(data->store, NULL, 0); read_regioninfo(data, r);
}
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);
} }
READ_STR(data->store, name, sizeof(name)); READ_STR(data->store, name, sizeof(name));
@ -941,7 +949,7 @@ static region *readregion(struct gamedata *data, int x, int y)
if (fval(r->terrain, LAND_REGION)) { if (fval(r->terrain, LAND_REGION)) {
r->land = calloc(1, sizeof(land_region)); r->land = calloc(1, sizeof(land_region));
READ_STR(data->store, name, sizeof(name)); READ_STR(data->store, name, sizeof(name));
if (unicode_utf8_trim(name)!=0) { if (unicode_utf8_trim(name) != 0) {
log_warning("trim region %d name to '%s'", uid, name); log_warning("trim region %d name to '%s'", uid, name);
}; };
r->land->name = strdup(name); r->land->name = strdup(name);
@ -950,6 +958,9 @@ static region *readregion(struct gamedata *data, int x, int y)
int i; int i;
rawmaterial **pres = &r->resources; rawmaterial **pres = &r->resources;
if (data->version >= LANDDISPLAY_VERSION) {
read_regioninfo(data, r);
}
READ_INT(data->store, &i); READ_INT(data->store, &i);
if (i < 0) { if (i < 0) {
log_error("number of trees in %s is %d.", regionname(r, NULL), i); log_error("number of trees in %s is %d.", regionname(r, NULL), i);
@ -1069,24 +1080,23 @@ region *read_region(gamedata *data)
return r; return r;
} }
void writeregion(struct gamedata *data, const region * r) void writeregion(gamedata *data, const region * r)
{ {
assert(r); assert(r);
assert(data); assert(data);
WRITE_INT(data->store, r->uid); WRITE_INT(data->store, r->uid);
WRITE_STR(data->store, region_getinfo(r));
WRITE_TOK(data->store, r->terrain->_name); WRITE_TOK(data->store, r->terrain->_name);
WRITE_INT(data->store, r->flags & RF_SAVEMASK); WRITE_INT(data->store, r->flags & RF_SAVEMASK);
WRITE_INT(data->store, r->age); WRITE_INT(data->store, r->age);
WRITE_SECTION(data->store); WRITE_SECTION(data->store);
if (fval(r->terrain, LAND_REGION)) { if (r->land) {
const item_type *rht; const item_type *rht;
struct demand *demand; struct demand *demand;
rawmaterial *res = r->resources; rawmaterial *res = r->resources;
assert(r->land);
WRITE_STR(data->store, (const char *)r->land->name); WRITE_STR(data->store, (const char *)r->land->name);
WRITE_STR(data->store, region_getinfo(r));
assert(rtrees(r, 0) >= 0); assert(rtrees(r, 0) >= 0);
assert(rtrees(r, 1) >= 0); assert(rtrees(r, 1) >= 0);
assert(rtrees(r, 2) >= 0); assert(rtrees(r, 2) >= 0);
@ -1122,11 +1132,9 @@ void writeregion(struct gamedata *data, const region * r)
} }
WRITE_TOK(data->store, "end"); WRITE_TOK(data->store, "end");
WRITE_SECTION(data->store); WRITE_SECTION(data->store);
#if RELEASE_VERSION>=REGIONOWNER_VERSION
WRITE_INT(data->store, region_get_morale(r)); WRITE_INT(data->store, region_get_morale(r));
write_owner(data, r->land->ownership); write_owner(data, r->land->ownership);
WRITE_SECTION(data->store); WRITE_SECTION(data->store);
#endif
} }
write_attribs(data->store, r->attribs, r); write_attribs(data->store, r->attribs, r);
WRITE_SECTION(data->store); WRITE_SECTION(data->store);
@ -1243,7 +1251,7 @@ void _test_write_password(gamedata *data, const faction *f) {
write_password(data, f); write_password(data, f);
} }
faction *read_faction(struct gamedata * data) faction *read_faction(gamedata * data)
{ {
ally **sfp; ally **sfp;
int planes, n; int planes, n;
@ -1395,7 +1403,7 @@ faction *read_faction(struct gamedata * data)
return f; return f;
} }
void write_faction(struct gamedata *data, const faction * f) void write_faction(gamedata *data, const faction * f)
{ {
ally *sf; ally *sf;
ursprung *ur; ursprung *ur;
@ -1584,7 +1592,7 @@ void write_ship(gamedata *data, const ship *sh)
write_attribs(store, sh->attribs, sh); write_attribs(store, sh->attribs, sh);
} }
ship *read_ship(struct gamedata *data) ship *read_ship(gamedata *data)
{ {
char name[DISPLAYSIZE]; char name[DISPLAYSIZE];
ship *sh; ship *sh;

View file

@ -1559,11 +1559,11 @@ int display_cmd(unit * u, struct order *ord)
break; break;
case P_REGION: 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); cmistake(u, ord, 147, MSG_EVENT);
break; break;
} }
s = &r->display; s = &r->land->display;
break; break;
default: default:

View file

@ -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])); ord = create_order(K_DISPLAY, f->locale, "%s Hodor", LOC(f->locale, parameters[P_REGION]));
CuAssertIntEquals(tc, 0, display_cmd(u, ord)); CuAssertIntEquals(tc, 0, display_cmd(u, ord));
CuAssertPtrEquals(tc, NULL, r->display); CuAssertPtrEquals(tc, NULL, r->land->display);
free_order(ord); free_order(ord);
test_cleanup(); test_cleanup();

View file

@ -1069,15 +1069,15 @@ void report_region(struct stream *out, const region * r, faction * f)
if (wrptr(&bufp, &size, bytes) != 0) if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
if (r->display && r->display[0]) { if (r->land && r->land->display && r->land->display[0]) {
bytes = (int)strlcpy(bufp, " ", size); bytes = (int)strlcpy(bufp, " ", size);
if (wrptr(&bufp, &size, bytes) != 0) if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
bytes = (int)strlcpy(bufp, r->display, size); bytes = (int)strlcpy(bufp, r->land->display, size);
if (wrptr(&bufp, &size, bytes) != 0) if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
n = r->display[strlen(r->display) - 1]; n = r->land->display[strlen(r->land->display) - 1];
if (n != '!' && n != '?' && n != '.') { if (n != '!' && n != '?' && n != '.') {
bytes = (int)strlcpy(bufp, ".", size); bytes = (int)strlcpy(bufp, ".", size);
if (wrptr(&bufp, &size, bytes) != 0) if (wrptr(&bufp, &size, bytes) != 0)

View file

@ -38,6 +38,7 @@
#define SORTKEYS_VERSION 358 /* at_keys is sorted */ #define SORTKEYS_VERSION 358 /* at_keys is sorted */
#define FAMILIAR_FIX_VERSION 359 /* familiar links are fixed */ #define FAMILIAR_FIX_VERSION 359 /* familiar links are fixed */
#define SKILLSORT_VERSION 360 /* u->skills is sorted */ #define SKILLSORT_VERSION 360 /* u->skills is sorted */
#define LANDDISPLAY_VERSION 360 /* r.display is now in r.land.display */
/* unfinished: */ /* unfinished: */
#define CRYPT_VERSION 400 /* passwords are encrypted */ #define CRYPT_VERSION 400 /* passwords are encrypted */