forked from github/server
* morale fixes for NMR factions.
This commit is contained in:
parent
0faffa9f2f
commit
a94aea618b
|
@ -3082,24 +3082,6 @@ static double rc_popularity(const struct race * rc)
|
|||
return 1.0/(pop-MORALE_COOLDOWN); /* 10 turns average */
|
||||
}
|
||||
|
||||
void update_owners(region * r)
|
||||
{
|
||||
building * bowner = largestbuilding(r, &is_owner_building, false);
|
||||
building * blargest = largestbuilding(r, &is_tax_building, false);
|
||||
if (blargest) {
|
||||
if (!bowner || bowner->size<blargest->size) {
|
||||
/* region owners update? */
|
||||
faction * f = region_get_owner(r);
|
||||
unit * u = buildingowner(r, blargest);
|
||||
if (u==NULL) {
|
||||
if (f) region_set_owner(r, NULL, turn);
|
||||
} else if (u->faction!=f) {
|
||||
region_set_owner(r, u->faction, turn);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void age_region(region * r)
|
||||
{
|
||||
a_age(&r->attribs);
|
||||
|
|
|
@ -32,9 +32,8 @@ void demographics(void);
|
|||
void last_orders(void);
|
||||
void find_address(void);
|
||||
void update_guards(void);
|
||||
void update_owners(struct region * r);
|
||||
void update_subscriptions(void);
|
||||
extern void deliverMail(struct faction * f, struct region * r, struct unit * u, const char *s, struct unit * receiver);
|
||||
void deliverMail(struct faction * f, struct region * r, struct unit * u, const char *s, struct unit * receiver);
|
||||
|
||||
/* eressea-specific. put somewhere else, please. */
|
||||
void processorders(void);
|
||||
|
|
|
@ -1471,6 +1471,29 @@ region_set_owner(struct region * r, struct faction * owner, int turn)
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
void update_owners(region * r)
|
||||
{
|
||||
if (r->land) {
|
||||
building * bowner = largestbuilding(r, &is_owner_building, false);
|
||||
building * blargest = largestbuilding(r, &is_tax_building, false);
|
||||
if (blargest) {
|
||||
if (!bowner || bowner->size<blargest->size) {
|
||||
/* region owners update? */
|
||||
faction * f = region_get_owner(r);
|
||||
unit * u = buildingowner(r, blargest);
|
||||
if (u==NULL) {
|
||||
if (f) region_set_owner(r, NULL, turn);
|
||||
} else if (u->faction!=f) {
|
||||
region_set_owner(r, u->faction, turn);
|
||||
}
|
||||
}
|
||||
} else if (r->land->ownership && r->land->ownership->owner) {
|
||||
region_set_owner(r, NULL, turn);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
region_setinfo(struct region * r, const char * info)
|
||||
{
|
||||
|
|
|
@ -278,8 +278,11 @@ int region_getresource(const struct region * r, const struct resource_type * rty
|
|||
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);
|
||||
const struct item_type * r_luxury(struct region * r);
|
||||
void get_neighbours(const struct region * r, struct region ** list);
|
||||
|
||||
void update_owners(struct region * r);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -609,6 +609,23 @@ write_owner(struct storage * store, region_owner *owner)
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
resolve_owner(variant id, void * address)
|
||||
{
|
||||
int result = 0;
|
||||
faction * f = NULL;
|
||||
if (id.i!=0) {
|
||||
f = findfaction(id.i);
|
||||
if (f==NULL) {
|
||||
log_error(("region has an invalid owner (%s)\n", itoa36(id.i)));
|
||||
f = get_monsters();
|
||||
}
|
||||
}
|
||||
*(faction**)address = f;
|
||||
return result;
|
||||
}
|
||||
|
||||
static void
|
||||
read_owner(struct storage * store, region_owner **powner)
|
||||
{
|
||||
|
@ -622,7 +639,7 @@ read_owner(struct storage * store, region_owner **powner)
|
|||
} else {
|
||||
owner->flags = 0;
|
||||
}
|
||||
read_reference(&owner->owner, store, read_faction_reference, resolve_faction);
|
||||
read_reference(&owner->owner, store, &read_faction_reference, &resolve_owner);
|
||||
*powner = owner;
|
||||
} else {
|
||||
*powner = 0;
|
||||
|
@ -1037,6 +1054,9 @@ readregion(struct storage * store, int x, int y)
|
|||
if (store->version>=REGIONOWNER_VERSION) {
|
||||
r->land->morale = (short)store->r_int(store);
|
||||
read_owner(store, &r->land->ownership);
|
||||
if (r->land->ownership && r->land->ownership->owner==get_monsters()) {
|
||||
update_owners(r);
|
||||
}
|
||||
}
|
||||
}
|
||||
a_read(store, &r->attribs);
|
||||
|
|
Loading…
Reference in New Issue