From dbde06fb8f5a980abda2ceb7f126f73e01a408cb Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 12 Feb 2010 05:06:26 +0000 Subject: [PATCH] fix: taxation buildings only count if they are currently in use. --- src/common/attributes/giveitem.c | 2 +- src/common/gamecode/creport.c | 6 ++--- src/common/gamecode/economy.c | 10 ++++---- src/common/gamecode/laws.c | 4 +-- src/common/gamecode/market.c | 2 +- src/common/gamecode/randenc.c | 2 +- src/common/gamecode/report.c | 6 ++--- src/common/kernel/alliance.c | 2 +- src/common/kernel/build.c | 6 ++--- src/common/kernel/building.c | 42 +++++++++++++++---------------- src/common/kernel/building.h | 2 +- src/common/kernel/eressea.c | 12 +++++---- src/common/kernel/move.c | 2 +- src/common/kernel/region.c | 2 +- src/common/kernel/unit.c | 2 +- src/common/modules/score.c | 2 +- src/eressea/tolua/bind_building.c | 2 +- 17 files changed, 53 insertions(+), 53 deletions(-) diff --git a/src/common/attributes/giveitem.c b/src/common/attributes/giveitem.c index b960e91da..04f980d31 100644 --- a/src/common/attributes/giveitem.c +++ b/src/common/attributes/giveitem.c @@ -97,7 +97,7 @@ a_giveitem(attrib * a) unit * u; if (gdata->building==NULL || gdata->items==NULL) return 0; r = gdata->building->region; - u = buildingowner(r, gdata->building); + u = building_owner(gdata->building); if (u==NULL) return 1; while (gdata->items) { item * itm = gdata->items; diff --git a/src/common/gamecode/creport.c b/src/common/gamecode/creport.c index aadfab0c5..56a76496e 100644 --- a/src/common/gamecode/creport.c +++ b/src/common/gamecode/creport.c @@ -206,10 +206,10 @@ cr_output_curses(FILE * F, const faction * viewer, const void * obj, typ_t typ) } } else if (typ == TYP_BUILDING) { building * b = (building*)obj; - unit * owner; + unit * owner = building_owner(b); a = b->attribs; r = b->region; - if((owner = buildingowner(r,b)) != NULL){ + if (owner != NULL){ if (owner->faction == viewer){ self = 2; } else { /* steht eine Person der Partei in der Burg? */ @@ -1323,7 +1323,7 @@ cr_output_region(FILE * F, report_context * ctx, seen_region * sr) /* buildings */ for (b = rbuildings(r); b; b = b->next) { int fno = -1; - u = buildingowner(r, b); + u = building_owner(b); if (u && !fval(u, UFL_PARTEITARNUNG)) { const faction * sf = visible_faction(f,u); fno = sf->no; diff --git a/src/common/gamecode/economy.c b/src/common/gamecode/economy.c index 4c5770bad..cd9bf8a12 100644 --- a/src/common/gamecode/economy.c +++ b/src/common/gamecode/economy.c @@ -1025,7 +1025,7 @@ maintain(building * b, boolean first) if (fval(b, BLD_DONTPAY)) { return false; } - u = buildingowner(r, b); + u = building_owner(b); if (u==NULL) return false; for (c=0;b->type->maintenance[c].number;++c) { const maintenance * m = b->type->maintenance+c; @@ -1165,7 +1165,7 @@ maintain_buildings(region * r, boolean crash) } #endif if (!fval(b, BLD_WORKING)) { - unit * u = buildingowner(r, b); + unit * u = building_owner(b); const char * msgtype = maintained?"maintenance_nowork":"maintenance_none"; struct message * msg = msg_message(msgtype, "building", b); @@ -2226,11 +2226,11 @@ expandselling(region * r, request * sellorders, int limit) * Verkauf. Wenn zwei Burgen gleicher Größe bekommt gar keiner etwas. */ for (b = rbuildings(r); b; b = b->next) { - if (b->size > maxsize && buildingowner(r, b) != NULL + if (b->size > maxsize && building_owner(b) != NULL && b->type == bt_find("castle")) { maxb = b; maxsize = b->size; - maxowner = buildingowner(r, b); + maxowner = building_owner(b); } else if (b->size == maxsize && b->type == bt_find("castle")) { maxb = (building *) NULL; maxowner = (unit *) NULL; @@ -3309,7 +3309,7 @@ peasant_taxes(region * r) b = largestbuilding(r, cmp_taxes, false); if (b==NULL) return; - u = buildingowner(r, b); + u = building_owner(b); if (u==NULL || u->faction!=f) return; maxsize = buildingeffsize(b, false); diff --git a/src/common/gamecode/laws.c b/src/common/gamecode/laws.c index 3d5e0fd39..de4497c1d 100644 --- a/src/common/gamecode/laws.c +++ b/src/common/gamecode/laws.c @@ -1654,7 +1654,7 @@ name_cmd(unit * u, struct order * ord) } } - uo = buildingowner(r, b); + uo = building_owner(b); if (uo) { if (cansee(uo->faction, r, u, 0)) { ADDMSG(&uo->faction->msgs, msg_message("renamed_building_seen", @@ -3697,7 +3697,7 @@ pay_cmd(unit * u, struct order * ord) skip_token(); p = getparam(u->faction->locale); if (p==P_NOT) { - unit * owner = buildingowner(u->building->region, u->building); + unit * owner = building_owner(u->building); if (owner->faction!=u->faction) { cmistake(u, ord, 1222, MSG_EVENT); } else { diff --git a/src/common/gamecode/market.c b/src/common/gamecode/market.c index 74330d9f3..49382e537 100644 --- a/src/common/gamecode/market.c +++ b/src/common/gamecode/market.c @@ -37,7 +37,7 @@ get_markets(region * r, unit ** results, size_t size) if (!btype) return 0; for (b=r->buildings;nnext) { if (b->type==btype && (b->flags&BLD_WORKING) && b->size>=b->type->maxsize) { - unit * u = buildingowner(r, b); + unit * u = building_owner(b); unsigned int i; for (i=0;u && i!=n;++i) { /* only one market per faction */ diff --git a/src/common/gamecode/randenc.c b/src/common/gamecode/randenc.c index 8450650eb..c4e8cd39a 100644 --- a/src/common/gamecode/randenc.c +++ b/src/common/gamecode/randenc.c @@ -1258,7 +1258,7 @@ randomevents(void) building ** blist = &r->buildings; while (*blist) { building * b = *blist; - if (fval(b->type, BTF_DECAY) && !buildingowner(r, b)) { + if (fval(b->type, BTF_DECAY) && !building_owner(b)) { b->size -= MAX(1, (b->size * 20) / 100); if (b->size == 0) { remove_building(blist, r->buildings); diff --git a/src/common/gamecode/report.c b/src/common/gamecode/report.c index 36c14bbcd..6d4c81258 100644 --- a/src/common/gamecode/report.c +++ b/src/common/gamecode/report.c @@ -570,7 +570,7 @@ nr_curses(FILE *F, const faction *viewer, const void * obj, typ_t typ, int inden unit * owner; a = b->attribs; r = b->region; - if ((owner = buildingowner(r,b)) != NULL){ + if ((owner = building_owner(b)) != NULL){ if (owner->faction == viewer){ self = 2; } else { /* steht eine Person der Partei in der Burg? */ @@ -1809,7 +1809,7 @@ nr_building(FILE *F, const seen_region * sr, const building * b, const faction * bytes = (int)strlcpy(bufp, name, size); if (wrptr(&bufp, &size, bytes)!=0) WARN_STATIC_BUFFER(); if (billusion) { - unit * owner = buildingowner(r, b); + unit * owner = building_owner(b); if (owner && owner->faction==f) { /* illusion. report real type */ name = LOC(lang, bname); @@ -1851,7 +1851,7 @@ nr_building(FILE *F, const seen_region * sr, const building * b, const faction * } if (b->type == bt_find("pyramid")) { - unit * owner = buildingowner(r, b); + unit * owner = building_owner(b); scat("Größenstufe "); icat(wdw_pyramid_level(b)); scat("."); diff --git a/src/common/kernel/alliance.c b/src/common/kernel/alliance.c index a5292d910..53aedbb8d 100644 --- a/src/common/kernel/alliance.c +++ b/src/common/kernel/alliance.c @@ -453,7 +453,7 @@ alliancevictory(void) building * b = r->buildings; while (b!=NULL) { if (b->type==btype) { - unit * u = buildingowner(r, b); + unit * u = building_owner(b); if (u) { fset(u->faction->alliance, FFL_MARK); } diff --git a/src/common/kernel/build.c b/src/common/kernel/build.c index 8f7bef727..23dd95eb1 100644 --- a/src/common/kernel/build.c +++ b/src/common/kernel/build.c @@ -887,7 +887,7 @@ build_building(unit * u, const building_type * btype, int want, order * ord) rule_other = get_param_int(global.parameters, "rules.build.other_buildings", 1); } if (!rule_other) { - unit * owner = buildingowner(r, b); + unit * owner = building_owner(b); if (!owner || owner->faction!=u->faction) { cmistake(u, ord, 1222, MSG_PRODUCE); return; @@ -1117,7 +1117,7 @@ mayenter(region * r, unit * u, building * b) { unit *u2; if (fval(b, BLD_UNGUARDED)) return true; - u2 = buildingowner(r, b); + u2 = building_owner(b); if (u2==NULL || ucontact(u2, u) || alliedunit(u2, u->faction, HELP_GUARD)) return true; @@ -1255,7 +1255,7 @@ enter_building(unit * u, order * ord, int id, boolean report) } if (leave(u, false)) { - if (buildingowner(r, b) == 0) { + if (building_owner(b) == 0) { fset(u, UFL_OWNER); } fset(u, UFL_ENTER); diff --git a/src/common/kernel/building.c b/src/common/kernel/building.c index 9d6eff8cb..7a98ca48e 100644 --- a/src/common/kernel/building.c +++ b/src/common/kernel/building.c @@ -612,32 +612,30 @@ buildingname(const building * b) } unit * -buildingowner(const region * r, const building * b) +building_owner(const building * b) { - unit *u = NULL; - unit *first = NULL; -#ifndef BROKEN_OWNERS - assert(r == b->region); -#endif - /* Prüfen ob Eigentümer am leben. */ + unit *u = NULL; + unit *first = NULL; + region * r = b->region; + /* Prüfen ob Eigentümer am leben. */ - for (u = r->units; u; u = u->next) { - if (u->building == b) { - if (!first && u->number > 0) - first = u; - if (fval(u, UFL_OWNER) && u->number > 0) - return u; - if (u->number == 0) - freset(u, UFL_OWNER); - } - } + for (u = r->units; u; u = u->next) { + if (u->building == b) { + if (!first && u->number > 0) + first = u; + if (fval(u, UFL_OWNER) && u->number > 0) + return u; + if (u->number == 0) + freset(u, UFL_OWNER); + } + } - /* Eigentümer tot oder kein Eigentümer vorhanden. Erste lebende Einheit - * nehmen. */ + /* Eigentümer tot oder kein Eigentümer vorhanden. Erste lebende Einheit + * nehmen. */ - if (first) - fset(first, UFL_OWNER); - return first; + if (first) + fset(first, UFL_OWNER); + return first; } const char * building_getname(const building * self) diff --git a/src/common/kernel/building.h b/src/common/kernel/building.h index b471b69d9..ffdd0532d 100644 --- a/src/common/kernel/building.h +++ b/src/common/kernel/building.h @@ -143,7 +143,7 @@ extern variant read_building_reference(struct storage * store); extern struct building *findbuilding(int n); -extern struct unit * buildingowner(const struct region * r, const struct building * b); +extern struct unit * building_owner(const struct building * b); extern struct attrib_type at_building_action; void building_addaction(struct building * b, const char * fname, const char * param); diff --git a/src/common/kernel/eressea.c b/src/common/kernel/eressea.c index 446c8ed81..db33fe40c 100644 --- a/src/common/kernel/eressea.c +++ b/src/common/kernel/eressea.c @@ -2637,7 +2637,7 @@ boolean is_owner_building(const struct building * b) { region * r = b->region; if (b->type->taxes && r->land && r->land->ownership) { - unit * u = buildingowner(r, b); + unit * u = building_owner(b); return u && u->faction == r->land->ownership->owner; } return false; @@ -2648,7 +2648,10 @@ cmp_taxes(const building * b, const building * a) { faction * f = region_get_owner(b->region); if (b->type->taxes) { - if (a) { + unit * u = building_owner(b); + if (!u) { + return -1; + } else if (a) { int newsize = buildingeffsize(b, false); double newtaxes = b->type->taxes(b, newsize); int oldsize = buildingeffsize(a, false); @@ -2659,9 +2662,8 @@ cmp_taxes(const building * b, const building * a) else if (b->sizesize) return -1; else if (b->size>a->size) return 1; else { - unit * u = buildingowner(b->region, b); if (u && u->faction==f) { - u = buildingowner(a->region, a); + u = building_owner(a); if (u && u->faction==f) return -1; return 1; } @@ -2680,7 +2682,7 @@ cmp_current_owner(const building * b, const building * a) assert(rule_region_owners()); if (f && b->type->taxes) { - unit * u = buildingowner(b->region, b); + unit * u = building_owner(b); if (!u || u->faction!=f) return -1; if (a) { int newsize = buildingeffsize(b, false); diff --git a/src/common/kernel/move.c b/src/common/kernel/move.c index b07f434c2..9f0f20d7c 100644 --- a/src/common/kernel/move.c +++ b/src/common/kernel/move.c @@ -1599,7 +1599,7 @@ owner_buildingtyp(const region * r, const building_type * bt) unit *owner; for (b = rbuildings(r); b; b = b->next) { - owner = buildingowner(r, b); + owner = building_owner(b); if (b->type == bt && owner != NULL) { if (b->size >= bt->maxsize) { return owner; diff --git a/src/common/kernel/region.c b/src/common/kernel/region.c index d0dacb74a..3eff5d7c2 100644 --- a/src/common/kernel/region.c +++ b/src/common/kernel/region.c @@ -1482,7 +1482,7 @@ faction * update_owners(region * r) if (blargest) { if (!bowner || bowner->sizesize) { /* region owners update? */ - unit * u = buildingowner(r, blargest); + unit * u = building_owner(blargest); f = region_get_owner(r); if (u==NULL) { if (f) { diff --git a/src/common/kernel/unit.c b/src/common/kernel/unit.c index 9802e74c0..bbcf22bd1 100644 --- a/src/common/kernel/unit.c +++ b/src/common/kernel/unit.c @@ -840,7 +840,7 @@ can_leave(unit * u) if (rule_leave<0) { rule_leave = get_param_int(global.parameters, "rules.move.owner_leave", 0); } - if (rule_leave && u->building && u==buildingowner(u->region, u->building)) { + if (rule_leave && u->building && u==building_owner(u->building)) { return false; } return true; diff --git a/src/common/modules/score.c b/src/common/modules/score.c index ad48f3a22..1ae9c76b4 100644 --- a/src/common/modules/score.c +++ b/src/common/modules/score.c @@ -85,7 +85,7 @@ score(void) } for (b = r->buildings; b; b = b->next) { - u = buildingowner(r, b); + u = building_owner(b); if (u!=NULL) { faction * fbo = u->faction; diff --git a/src/eressea/tolua/bind_building.c b/src/eressea/tolua/bind_building.c index 8abc8a75c..da0f4b704 100644 --- a/src/eressea/tolua/bind_building.c +++ b/src/eressea/tolua/bind_building.c @@ -151,7 +151,7 @@ static int tolua_building_get_owner(lua_State* L) { building* b = (building*) tolua_tousertype(L, 1, 0); - unit * u = b?buildingowner(b->region, b):NULL; + unit * u = b?building_owner(b):NULL; tolua_pushusertype(L, u, TOLUA_CAST "unit"); return 1; }