diff --git a/src/common/gamecode/creport.c b/src/common/gamecode/creport.c index 4293139bb..90bf9d815 100644 --- a/src/common/gamecode/creport.c +++ b/src/common/gamecode/creport.c @@ -1202,9 +1202,11 @@ cr_output_region(FILE * F, report_context * ctx, seen_region * sr) fprintf(F, "%d;Pferde\n", rhorses(r)); if (sr->mode>=see_unit) { - faction * owner = region_get_owner(r); - if (owner) { - fprintf(F, "%d;owner\n", owner->no); + if (rule_region_owners()) { + faction * owner = region_get_owner(r); + if (owner) { + fprintf(F, "%d;owner\n", owner->no); + } } fprintf(F, "%d;Silber\n", rmoney(r)); if (skill_enabled[SK_ENTERTAINMENT]) { diff --git a/src/common/gamecode/economy.c b/src/common/gamecode/economy.c index 06fa057f2..290ffd9d6 100644 --- a/src/common/gamecode/economy.c +++ b/src/common/gamecode/economy.c @@ -634,21 +634,26 @@ recruit(unit * u, struct order * ord, request ** recruitorders) addlist(recruitorders, o); } +static void apply_owner_change(region * r, faction * f) +{ + int morale = region_get_morale(r); + region_set_owner(r, f, turn); + if (morale>0) { + morale = MAX(0, morale-MORALE_TRANSFER); + region_set_morale(r, morale, turn); + } +} + static void give_control(unit * u, unit * u2) { - if (u->building && u->faction!=u2->faction) { + if (u->building && u->faction!=u2->faction && rule_region_owners()) { region * r = u->region; faction * f = region_get_owner(r); if (f==u->faction) { building * b = largestbuilding(r, &cmp_current_owner, false); if (b==u->building) { - int morale = region_get_morale(r); - region_set_owner(r, u2->faction, turn); - if (morale>0) { - morale = MAX(0, morale-MORALE_TRANSFER); - region_set_morale(r, morale, turn); - } + apply_owner_change(r, u2->faction); } } } diff --git a/src/common/gamecode/laws.c b/src/common/gamecode/laws.c index f91686774..6389ae726 100644 --- a/src/common/gamecode/laws.c +++ b/src/common/gamecode/laws.c @@ -209,7 +209,6 @@ get_food(region *r) plane * pl = rplane(r); unit *u; int peasantfood = rpeasants(r)*10; - faction * owner = region_get_owner(r); static int food_rules = -1; if (food_rules<0) { @@ -249,6 +248,7 @@ get_food(region *r) } if (food_rules&1) { + faction * owner = region_get_owner(r); /* if the region is owned, and the owner is nice, then we'll get * food from the peasants - should not be used with WORK */ if (owner!=NULL && (get_alliance(owner, u->faction) & HELP_MONEY)) { @@ -1492,6 +1492,17 @@ prefix_cmd(unit * u, struct order * ord) return 0; } + +static cmp_building_cb +get_cmp_region_owner() +{ + if (rule_region_owners()) { + return &cmp_current_owner; + } else { + return &cmp_wage; + } +} + static int display_cmd(unit * u, struct order * ord) { @@ -1556,7 +1567,7 @@ display_cmd(unit * u, struct order * ord) cmistake(u, ord, 148, MSG_EVENT); break; } - if (b != largestbuilding(r, rule_region_owners()?&cmp_current_owner:&cmp_wage, false)) { + if (b != largestbuilding(r, get_cmp_region_owner(), false)) { cmistake(u, ord, 147, MSG_EVENT); break; } @@ -1801,7 +1812,7 @@ name_cmd(unit * u, struct order * ord) break; } - if (b != largestbuilding(r, rule_region_owners()?&cmp_current_owner:&cmp_wage, false)) { + if (b != largestbuilding(r, get_cmp_region_owner(), false)) { cmistake(u, ord, 147, MSG_EVENT); break; } @@ -3068,7 +3079,7 @@ age_building(building * b) effect = 100; /* the mage reactivates the circle */ c = create_curse(mage, &rt->attribs, ct_astralblock, - (float)sk, sk/2, effect, 0); + (float)MAX(1, sk), MAX(1, sk/2), effect, 0); ADDMSG(&r->msgs, msg_message("astralshield_activate", "region unit", r, mage)); } @@ -3195,7 +3206,9 @@ ageing(void) if (b==*bp) bp = &b->next; } - update_owners(r); + if (rule_region_owners()) { + update_owners(r); + } } } diff --git a/src/common/gamecode/report.c b/src/common/gamecode/report.c index ca77279fc..51332eed5 100644 --- a/src/common/gamecode/report.c +++ b/src/common/gamecode/report.c @@ -1003,7 +1003,7 @@ describe(FILE * F, const seen_region * sr, faction * f) } } - { + if (rule_region_owners()) { const faction * owner = region_get_owner(r); if (owner!=NULL) { bytes = snprintf(bufp, size, " Die Region ist im Besitz von %s.", diff --git a/src/common/kernel/eressea.c b/src/common/kernel/eressea.c index 3843dda0d..a52b4f263 100644 --- a/src/common/kernel/eressea.c +++ b/src/common/kernel/eressea.c @@ -1699,7 +1699,7 @@ cstring(const char *s) } building * -largestbuilding(const region * r, int (*cmp_gt)(const struct building *, const struct building *), boolean imaginary) +largestbuilding(const region * r, cmp_building_cb cmp_gt, boolean imaginary) { building *b, *best = NULL; diff --git a/src/common/kernel/eressea.h b/src/common/kernel/eressea.h index ae0a8421a..b5fa7fa66 100644 --- a/src/common/kernel/eressea.h +++ b/src/common/kernel/eressea.h @@ -244,7 +244,8 @@ extern char *cstring_i(char *s); extern const char *unitname(const struct unit * u); extern char * write_unitname(const struct unit * u, char * buffer, size_t size); -struct building *largestbuilding(const struct region * r, int (*eval_gt)(const struct building *,const struct building *), boolean imaginary); +typedef int (*cmp_building_cb)(const struct building * b, const struct building * a); +struct building *largestbuilding(const struct region * r, cmp_building_cb, boolean imaginary); int cmp_wage(const struct building * b, const struct building * bother); int cmp_taxes(const struct building * b, const struct building * bother); int cmp_current_owner(const struct building * b, const struct building * bother); diff --git a/src/common/kernel/move.c b/src/common/kernel/move.c index aa96a4250..b07f434c2 100644 --- a/src/common/kernel/move.c +++ b/src/common/kernel/move.c @@ -901,6 +901,8 @@ is_guardian_r(const unit * guard) { if (guard->number == 0) return false; if (besieged(guard)) return false; + + /* if region_owners exist then they may be guardians: */ if (guard->building && rule_region_owners() && fval(guard, UFL_OWNER)) { faction * owner = region_get_owner(guard->region); if (owner==guard->faction) { @@ -910,6 +912,7 @@ is_guardian_r(const unit * guard) } } } + if ((guard->flags&UFL_GUARD)==0) return false; if (!armedmen(guard, true) && !fval(guard->race, RCF_UNARMEDGUARD)) return false; return true; diff --git a/src/common/modules/score.c b/src/common/modules/score.c index d513b77b3..ad48f3a22 100644 --- a/src/common/modules/score.c +++ b/src/common/modules/score.c @@ -78,9 +78,11 @@ score(void) unit * u; building * b; ship * s; - - fc = region_get_owner(r); - if (fc) fc->score += 10; + + if (rule_region_owners()) { + fc = region_get_owner(r); + if (fc) fc->score += 10; + } for (b = r->buildings; b; b = b->next) { u = buildingowner(r, b);