Miscellaneous fixes, all related to region_owners having leaked into E2.

Issue: 1720
This commit is contained in:
Enno Rehling 2010-02-11 04:42:58 +00:00
parent 61c1dac6ce
commit ef60ac9ece
8 changed files with 47 additions and 21 deletions

View file

@ -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]) {

View file

@ -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);
}
}
}

View file

@ -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);
}
}
}

View file

@ -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.",

View file

@ -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;

View file

@ -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);

View file

@ -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;

View file

@ -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);