diff --git a/src/common/gamecode/creport.c b/src/common/gamecode/creport.c index 9f8ab1e22..d37359512 100644 --- a/src/common/gamecode/creport.c +++ b/src/common/gamecode/creport.c @@ -1185,7 +1185,7 @@ cr_output_region(FILE * F, report_context * ctx, seen_region * sr) if (production(r)) { int p_wage = wage(r, NULL, NULL, turn+1); fprintf(F, "%d;Lohn\n", p_wage); - if (owner_change(r)==turn) { + if (is_mourning(r, turn+1)) { fputs("1;mourning\n", F); } } diff --git a/src/common/gamecode/report.c b/src/common/gamecode/report.c index 8e75c5b61..d25db0ac6 100644 --- a/src/common/gamecode/report.c +++ b/src/common/gamecode/report.c @@ -967,7 +967,7 @@ describe(FILE * F, const seen_region * sr, faction * f) bytes = (int)strlcpy(bufp, LOC(f->locale, n==1?"peasant":"peasant_p"), size); } if (wrptr(&bufp, &size, bytes)!=0) WARN_STATIC_BUFFER(); - if (owner_change(r)==turn) { + if (is_mourning(r, turn+1)) { bytes = (int)strlcpy(bufp, LOC(f->locale, "nr_mourning"), size); if (wrptr(&bufp, &size, bytes)!=0) WARN_STATIC_BUFFER(); } diff --git a/src/common/kernel/eressea.c b/src/common/kernel/eressea.c index f5244e1db..d3a630697 100644 --- a/src/common/kernel/eressea.c +++ b/src/common/kernel/eressea.c @@ -2683,7 +2683,7 @@ default_wage(const region *r, const faction * f, const race * rc, int in_turn) } #endif /* KARMA_MODULE */ } else { - if (owner_change(r) == in_turn-1) { + if (is_mourning(r, in_turn)) { wage = 10; } else if (fval(r->terrain, SEA_REGION)) { wage = 11; diff --git a/src/common/kernel/region.c b/src/common/kernel/region.c index eb0701997..7e3f84a25 100644 --- a/src/common/kernel/region.c +++ b/src/common/kernel/region.c @@ -1457,14 +1457,15 @@ region_set_owner(struct region * r, struct faction * owner, int turn) if (!r->land->ownership) { r->land->ownership = malloc(sizeof(region_owner)); region_set_morale(r, MORALE_DEFAULT, turn); - r->land->ownership->since_turn = -turn; r->land->ownership->owner = NULL; + r->land->ownership->flags = 0; } else if (r->land->ownership->owner) { region_set_morale(r, MORALE_TAKEOVER, turn); - r->land->ownership->since_turn = turn; + r->land->ownership->flags |= OWNER_MOURNING; } else { - r->land->ownership->since_turn = -turn; + r->land->ownership->flags &= ~OWNER_MOURNING; } + r->land->ownership->since_turn = turn; assert(r->land->ownership->owner != owner); r->land->ownership->owner = owner; } @@ -1529,3 +1530,9 @@ int owner_change(const region * r) } return -1; } + +boolean is_mourning(const region * r, int in_turn) +{ + int change = owner_change(r); + return (change==in_turn-1 && (r->land->ownership->flags&OWNER_MOURNING)); +} diff --git a/src/common/kernel/region.h b/src/common/kernel/region.h index 75edef3dc..3fcdf0641 100644 --- a/src/common/kernel/region.h +++ b/src/common/kernel/region.h @@ -67,10 +67,12 @@ struct item; #define MORALE_TAKEOVER 0 /* Morale of peasants after they lose their lord */ #define MORALE_COOLDOWN 2 /* minimum cooldown before a morale change occurs */ +#define OWNER_MOURNING 0x01 typedef struct region_owner { struct faction * owner; int since_turn; /* turn the region changed owners */ int morale_turn; /* turn when morale has changed most recently */ + unsigned int flags; } region_owner; typedef struct demand { @@ -275,6 +277,7 @@ void region_setinfo(struct region * self, const char * name); int region_getresource(const struct region * r, const struct resource_type * rtype); void region_setresource(struct region * r, const struct resource_type * rtype, int value); int owner_change(const region * r); +boolean is_mourning(const region * r, int in_turn); extern const struct item_type * r_luxury(struct region * r); extern void get_neighbours(const struct region * r, struct region ** list); #ifdef __cplusplus diff --git a/src/common/kernel/save.c b/src/common/kernel/save.c index c61c73c9a..42a31e335 100644 --- a/src/common/kernel/save.c +++ b/src/common/kernel/save.c @@ -602,6 +602,7 @@ write_owner(struct storage * store, region_owner *owner) if (owner) { store->w_int(store, owner->since_turn); store->w_int(store, owner->morale_turn); + store->w_int(store, owner->flags); write_faction_reference(owner->owner, store); } else { store->w_int(store, -1); @@ -616,6 +617,11 @@ read_owner(struct storage * store, region_owner **powner) region_owner * owner = malloc(sizeof(region_owner)); owner->since_turn = since_turn; owner->morale_turn = store->r_int(store); + if (store->version>=MOURNING_VERSION) { + owner->flags = store->r_int(store); + } else { + owner->flags = 0; + } read_reference(&owner->owner, store, read_faction_reference, resolve_faction); *powner = owner; } else { diff --git a/src/common/kernel/version.h b/src/common/kernel/version.h index 5198f4e03..803602e18 100644 --- a/src/common/kernel/version.h +++ b/src/common/kernel/version.h @@ -63,6 +63,7 @@ #define REGIONOWNER_VERSION 333 /* regions have owners and morale */ #define ALLIANCELEADER_VERSION 333 /* alliances have a leader */ #define CURSEFLOAT_VERSION 334 /* all curse-effects are float */ +#define MOURNING_VERSION 335 /* mourning peasants */ #define MIN_VERSION CURSETYPE_VERSION /* minimal datafile we support */ #define RELEASE_VERSION CURSEFLOAT_VERSION /* current datafile */