diff --git a/res/core/de/strings.xml b/res/core/de/strings.xml index c9a2ae616..0b09a972b 100644 --- a/res/core/de/strings.xml +++ b/res/core/de/strings.xml @@ -4464,10 +4464,6 @@ Heimstein Homestone - - Mauern der Ewigkeit - Eternal Walls - Wasserelementar Water Elemental diff --git a/res/core/messages.xml b/res/core/messages.xml index bb57fd32d..4669ab8b1 100644 --- a/res/core/messages.xml +++ b/res/core/messages.xml @@ -1097,13 +1097,6 @@ "Plötzlich löst sich $building($building) in kleine Traumwolken auf." "$building($building) suddenly dissolves into small pink clouds." - - - - - "Für das Gebäude $building($building) konnte die ganze Woche kein Unterhalt bezahlt werden." - "Upkeep for $building($building) could not be paid all week." - @@ -7087,13 +7080,6 @@ "Der Unterhalt von $building($building) konnte nicht gezahlt werden, das Gebäude war diese Woche nicht funktionstüchtig." "The upkeep for $building($building) was not paid, the building was not operational this week." - - - - - "Der Unterhalt von $building($building) konnte nur verspätet gezahlt werden, das Gebäude war diese Woche nicht funktionstüchtig." - "The upkeep for $building($building) was paid late, the building was not operational this week." - diff --git a/src/bind_building.c b/src/bind_building.c index a3ecb5913..3724d4db5 100644 --- a/src/bind_building.c +++ b/src/bind_building.c @@ -52,15 +52,15 @@ static int tolua_building_set_working(lua_State * L) { building *self = (building *)tolua_tousertype(L, 1, 0); bool flag = !!lua_toboolean(L, 2); - if (flag) self->flags |= BLD_WORKING; - else self->flags &= ~BLD_WORKING; + if (flag) self->flags |= BLD_MAINTAINED; + else self->flags &= ~BLD_MAINTAINED; return 1; } static int tolua_building_get_working(lua_State * L) { building *self = (building *)tolua_tousertype(L, 1, 0); - bool flag = (self->flags&BLD_WORKING) != 0; + bool flag = (self->flags&BLD_MAINTAINED) != 0; lua_pushboolean(L, flag); return 1; } diff --git a/src/bind_process.c b/src/bind_process.c index 7d0124400..e8420c654 100755 --- a/src/bind_process.c +++ b/src/bind_process.c @@ -274,7 +274,7 @@ void process_maintenance(void) { } } } - maintain_buildings(r, 0); + maintain_buildings(r); } } diff --git a/src/bind_region.c b/src/bind_region.c index 24c2fb08d..e56c3443c 100644 --- a/src/bind_region.c +++ b/src/bind_region.c @@ -77,8 +77,8 @@ static int tolua_region_set_blocked(lua_State * L) { region *self = (region *)tolua_tousertype(L, 1, 0); bool flag = !!tolua_toboolean(L, 2, 1); - if (flag) self->flags |= BLD_WORKING; - else self->flags &= ~BLD_WORKING; + if (flag) self->flags |= RF_BLOCKED; + else self->flags &= ~RF_BLOCKED; return 0; } diff --git a/src/economy.c b/src/economy.c index 2156744b0..155a46b7e 100644 --- a/src/economy.c +++ b/src/economy.c @@ -709,33 +709,29 @@ static int forget_cmd(unit * u, order * ord) return 0; } -static bool maintain(building * b, bool first) -/* first==false -> take money from wherever you can */ +static int maintain(building * b) { - const resource_type *rsilver = get_resourcetype(R_SILVER); int c; region *r = b->region; - bool paid = true, work = first; + bool paid = true, work = true; unit *u; - if (fval(b, BLD_MAINTAINED) || b->type == NULL || b->type->maintenance == NULL || is_cursed(b->attribs, C_NOCOST, 0)) { - fset(b, BLD_MAINTAINED); - fset(b, BLD_WORKING); - return true; + if (fval(b, BLD_MAINTAINED) || b->type == NULL || b->type->maintenance == NULL) { + return BLD_MAINTAINED; } if (fval(b, BLD_DONTPAY)) { - return false; + return 0; } u = building_owner(b); if (u == NULL) { /* no owner - send a message to the entire region */ ADDMSG(&r->msgs, msg_message("maintenance_noowner", "building", b)); - return false; + return 0; } /* If the owner is the region owner, check if dontpay flag is set for the building where he is in */ if (config_token("rules.region_owner_pay_building", b->type->_name)) { if (fval(u->building, BLD_DONTPAY)) { - return false; + return 0; } } for (c = 0; b->type->maintenance[c].number; ++c) { @@ -748,25 +744,7 @@ static bool maintain(building * b, bool first) /* first ist im ersten versuch true, im zweiten aber false! Das * bedeutet, das in der Runde in die Region geschafften Resourcen * nicht genutzt werden können, weil die reserviert sind! */ - if (!first) - need -= get_pooled(u, m->rtype, GET_ALL, need); - else - need -= get_pooled(u, m->rtype, GET_DEFAULT, need); - if (!first && need > 0) { - unit *ua; - for (ua = r->units; ua; ua = ua->next) - freset(ua->faction, FFL_SELECT); - fset(u->faction, FFL_SELECT); /* hat schon */ - for (ua = r->units; ua; ua = ua->next) { - if (!fval(ua->faction, FFL_SELECT) && (ua->faction == u->faction - || alliedunit(ua, u->faction, HELP_MONEY))) { - need -= get_pooled(ua, m->rtype, GET_ALL, need); - fset(ua->faction, FFL_SELECT); - if (need <= 0) - break; - } - } - } + need -= get_pooled(u, m->rtype, GET_DEFAULT, need); } if (need > 0) { if (!fval(m, MTF_VITAL)) @@ -778,11 +756,12 @@ static bool maintain(building * b, bool first) } } if (fval(b, BLD_DONTPAY)) { - return false; + return 0; } u = building_owner(b); - if (u == NULL) - return false; + if (!u) { + return 0; + } for (c = 0; b->type->maintenance[c].number; ++c) { const maintenance *m = b->type->maintenance + c; int need = m->number; @@ -790,32 +769,10 @@ static bool maintain(building * b, bool first) if (fval(m, MTF_VARIABLE)) need = need * b->size; if (u) { - /* first ist im ersten versuch true, im zweiten aber false! Das - * bedeutet, das in der Runde in die Region geschafften Resourcen - * nicht genutzt werden können, weil die reserviert sind! */ - if (!first) - need -= get_pooled(u, m->rtype, GET_ALL, need); - else - need -= get_pooled(u, m->rtype, GET_DEFAULT, need); - if (!first && need > 0) { - unit *ua; - for (ua = r->units; ua; ua = ua->next) - freset(ua->faction, FFL_SELECT); - fset(u->faction, FFL_SELECT); /* hat schon */ - for (ua = r->units; ua; ua = ua->next) { - if (!fval(ua->faction, FFL_SELECT) && (ua->faction == u->faction - || alliedunit(ua, u->faction, HELP_MONEY))) { - need -= get_pooled(ua, m->rtype, GET_ALL, need); - fset(ua->faction, FFL_SELECT); - if (need <= 0) - break; - } - } - } + need -= get_pooled(u, m->rtype, GET_DEFAULT, need); if (need > 0) { work = false; - if (fval(m, MTF_VITAL)) - { + if (fval(m, MTF_VITAL)) { paid = false; break; } @@ -823,20 +780,9 @@ static bool maintain(building * b, bool first) } } if (paid && c > 0) { - /* TODO: wieviel von was wurde bezahlt */ - if (first && work) { - ADDMSG(&u->faction->msgs, msg_message("maintenance", "unit building", u, b)); - fset(b, BLD_WORKING); - fset(b, BLD_MAINTAINED); - } - if (!first) { - ADDMSG(&u->faction->msgs, msg_message("maintenance_late", "building", b)); - fset(b, BLD_MAINTAINED); - } - - if (first && !work) { + if (!work) { ADDMSG(&u->faction->msgs, msg_message("maintenancefail", "unit building", u, b)); - return false; + return 0; } for (c = 0; b->type->maintenance[c].number; ++c) { @@ -848,66 +794,44 @@ static bool maintain(building * b, bool first) if (fval(m, MTF_VARIABLE)) cost = cost * b->size; - if (!first) - cost -= use_pooled(u, m->rtype, GET_ALL, cost); - else - cost -= + cost -= use_pooled(u, m->rtype, GET_SLACK | GET_RESERVE | GET_POOLED_SLACK, cost); - if (!first && cost > 0) { - unit *ua; - for (ua = r->units; ua; ua = ua->next) - freset(ua->faction, FFL_SELECT); - fset(u->faction, FFL_SELECT); /* hat schon */ - for (ua = r->units; ua; ua = ua->next) { - if (!fval(ua->faction, FFL_SELECT) - && alliedunit(ua, u->faction, HELP_MONEY)) { - int give = use_pooled(ua, m->rtype, GET_ALL, cost); - if (!give) - continue; - cost -= give; - fset(ua->faction, FFL_SELECT); - if (m->rtype == rsilver) - add_donation(ua->faction, u->faction, give, r); - if (cost <= 0) - break; - } - } - } assert(cost == 0); } + if (work) { + ADDMSG(&u->faction->msgs, msg_message("maintenance", "unit building", u, b)); + return BLD_MAINTAINED; + } } - else { - ADDMSG(&u->faction->msgs, msg_message("maintenancefail", "unit building", u, b)); - return false; - } - return true; + ADDMSG(&u->faction->msgs, msg_message("maintenancefail", "unit building", u, b)); + return 0; } -void maintain_buildings(region * r, bool crash) +void maintain_buildings(region * r) { + const curse_type *nocost_ct = ct_find("nocostbuilding"); building **bp = &r->buildings; while (*bp) { building *b = *bp; - bool maintained = maintain(b, !crash); + int flags = BLD_MAINTAINED; + + if (!curse_active(get_curse(b->attribs, nocost_ct))) { + flags = maintain(b); + } + fset(b, flags); - /* the second time, send a message */ - if (crash) { - if (!fval(b, BLD_WORKING)) { - unit *u = building_owner(b); - const char *msgtype = - maintained ? "maintenance_nowork" : "maintenance_none"; - struct message *msg = msg_message(msgtype, "building", b); - - if (u) { - add_message(&u->faction->msgs, msg); - r_addmessage(r, u->faction, msg); - } - else { - add_message(&r->msgs, msg); - } - msg_release(msg); + if (!fval(b, BLD_MAINTAINED)) { + unit *u = building_owner(b); + struct message *msg = msg_message("maintenance_nowork", "building", b); + if (u) { + add_message(&u->faction->msgs, msg); + r_addmessage(r, u->faction, msg); } + else { + add_message(&r->msgs, msg); + } + msg_release(msg); } bp = &b->next; } diff --git a/src/economy.h b/src/economy.h index 7e399cc76..b6c8002c9 100644 --- a/src/economy.h +++ b/src/economy.h @@ -54,10 +54,9 @@ extern "C" { void auto_work(struct region *r); enum { IC_WORK, IC_ENTERTAIN, IC_TAX, IC_TRADE, IC_TRADETAX, IC_STEAL, IC_MAGIC, IC_LOOT }; - void maintain_buildings(struct region *r, bool crash); + void maintain_buildings(struct region *r); int make_cmd(struct unit *u, struct order *ord); void split_allocations(struct region *r); - int recruit_archetypes(void); int give_control_cmd(struct unit *u, struct order *ord); void give_control(struct unit * u, struct unit * u2); void tax_cmd(struct unit * u, struct order *ord, struct request ** taxorders); diff --git a/src/economy.test.c b/src/economy.test.c index 577c7931a..ce09aae43 100644 --- a/src/economy.test.c +++ b/src/economy.test.c @@ -222,8 +222,6 @@ static void test_tax_cmd(CuTest *tc) { CuAssertPtrEquals(tc, 0, test_find_messagetype(u->faction->msgs, "error_no_tax_skill")); CuAssertPtrNotNull(tc, taxorders); - - rsetmoney(r, 11); expandtax(r, taxorders); CuAssertPtrNotNull(tc, test_find_messagetype(u->faction->msgs, "income")); @@ -243,6 +241,55 @@ static void test_tax_cmd(CuTest *tc) { test_cleanup(); } +static void test_maintain_buildings(CuTest *tc) { + region *r; + building *b; + building_type *btype; + unit *u; + maintenance *req; + item_type *itype; + + test_cleanup(); + btype = test_create_buildingtype("Hort"); + btype->maxsize = 10; + r = test_create_region(0, 0, 0); + u = test_create_unit(test_create_faction(0), r); + b = test_create_building(r, btype); + itype = test_create_itemtype("money"); + b->size = btype->maxsize; + u_set_building(u, b); + + // this building has no upkeep, it just works: + b->flags = 0; + maintain_buildings(r); + CuAssertIntEquals(tc, BLD_MAINTAINED, fval(b, BLD_MAINTAINED)); + + req = calloc(2, sizeof(maintenance)); + req[0].number = 100; + req[0].rtype = itype->rtype; + btype->maintenance = req; + + // we cannot afford to pay: + b->flags = 0; + maintain_buildings(r); + CuAssertIntEquals(tc, 0, fval(b, BLD_MAINTAINED)); + + // we can afford to pay: + i_change(&u->items, itype, 100); + b->flags = 0; + maintain_buildings(r); + CuAssertIntEquals(tc, BLD_MAINTAINED, fval(b, BLD_MAINTAINED)); + CuAssertIntEquals(tc, 0, i_get(u->items, itype)); + + // this building has no owner, it doesn't work: + u_set_building(u, NULL); + b->flags = 0; + maintain_buildings(r); + CuAssertIntEquals(tc, 0, fval(b, BLD_MAINTAINED)); + + test_cleanup(); +} + CuSuite *get_economy_suite(void) { CuSuite *suite = CuSuiteNew(); @@ -254,5 +301,6 @@ CuSuite *get_economy_suite(void) SUITE_ADD_TEST(suite, test_normals_recruit); SUITE_ADD_TEST(suite, test_heroes_dont_recruit); SUITE_ADD_TEST(suite, test_tax_cmd); + SUITE_ADD_TEST(suite, test_maintain_buildings); return suite; } diff --git a/src/kernel/build.c b/src/kernel/build.c index 97e5e84d0..f9e10b09e 100644 --- a/src/kernel/build.c +++ b/src/kernel/build.c @@ -805,7 +805,7 @@ build_building(unit * u, const building_type * btype, int id, int want, order * /* build a new building */ b = new_building(btype, r, lang); b->type = btype; - fset(b, BLD_MAINTAINED | BLD_WORKING); + fset(b, BLD_MAINTAINED); /* Die Einheit befindet sich automatisch im Inneren der neuen Burg. */ if (u->number && leave(u, false)) { diff --git a/src/kernel/build.test.c b/src/kernel/build.test.c index c2185cd29..41dcdb1a5 100644 --- a/src/kernel/build.test.c +++ b/src/kernel/build.test.c @@ -83,7 +83,7 @@ static void test_build_requires_building(CuTest *tc) { btype->capacity = 1; CuAssertIntEquals_Msg(tc, "must be inside a production building", EBUILDINGREQ, build(u, &bf.cons, 0, 1)); u->building = test_create_building(u->region, btype); - fset(u->building, BLD_WORKING); + fset(u->building, BLD_MAINTAINED); CuAssertIntEquals(tc, 1, build(u, &bf.cons, 0, 1)); btype->maxcapacity = 0; CuAssertIntEquals_Msg(tc, "cannot build when production building capacity exceeded", EBUILDINGREQ, build(u, &bf.cons, 0, 1)); diff --git a/src/kernel/building.c b/src/kernel/building.c index c6d7f7af2..cf40c0ea3 100644 --- a/src/kernel/building.c +++ b/src/kernel/building.c @@ -23,7 +23,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. /* kernel includes */ #include "item.h" -#include "curse.h" /* für C_NOCOST */ #include "unit.h" #include "faction.h" #include "race.h" @@ -649,7 +648,7 @@ buildingtype_exists(const region * r, const building_type * bt, bool working) building *b; for (b = rbuildings(r); b; b = b->next) { - if (b->type == bt && (!working || fval(b, BLD_WORKING)) && building_finished(b)) { + if (b->type == bt && (!working || fval(b, BLD_MAINTAINED)) && building_finished(b)) { return true; } } @@ -662,7 +661,7 @@ bool building_finished(const struct building *b) { } bool building_is_active(const struct building *b) { - return b && fval(b, BLD_WORKING) && building_finished(b); + return b && fval(b, BLD_MAINTAINED) && building_finished(b); } building *active_building(const unit *u, const struct building_type *btype) { diff --git a/src/kernel/building.h b/src/kernel/building.h index 52b715c59..fda4a4676 100644 --- a/src/kernel/building.h +++ b/src/kernel/building.h @@ -95,11 +95,10 @@ extern "C" { #define BFL_NONE 0x00 #define BLD_MAINTAINED 0x01 /* vital maintenance paid for */ -#define BLD_WORKING 0x02 /* full maintenance paid, it works */ +#define BLD_DONTPAY 0x02 /* PAY NOT */ #define BLD_UNGUARDED 0x04 /* you can enter this building anytime */ #define BLD_EXPANDED 0x08 /* has been expanded this turn */ #define BLD_SELECT 0x10 /* formerly FL_DH */ -#define BLD_DONTPAY 0x20 /* PAY NOT */ #define BLD_SAVEMASK 0x00 /* mask for persistent flags */ diff --git a/src/kernel/building.test.c b/src/kernel/building.test.c index c0c355940..1c5ff1fe2 100644 --- a/src/kernel/building.test.c +++ b/src/kernel/building.test.c @@ -409,17 +409,17 @@ static void test_buildingtype_exists(CuTest * tc) CuAssertTrue(tc, buildingtype_exists(r, btype, false)); b->size = 9; - fset(b, BLD_WORKING); + fset(b, BLD_MAINTAINED); CuAssertTrue(tc, !buildingtype_exists(r, btype, false)); btype->maxsize = 0; - freset(b, BLD_WORKING); + freset(b, BLD_MAINTAINED); CuAssertTrue(tc, buildingtype_exists(r, btype, false)); btype->maxsize = 10; b->size = 10; - fset(b, BLD_WORKING); + fset(b, BLD_MAINTAINED); CuAssertTrue(tc, buildingtype_exists(r, btype, true)); - freset(b, BLD_WORKING); + freset(b, BLD_MAINTAINED); CuAssertTrue(tc, !buildingtype_exists(r, btype, true)); } @@ -438,7 +438,7 @@ static void test_active_building(CuTest *tc) { CuAssertIntEquals(tc, false, building_is_active(b)); CuAssertPtrEquals(tc, NULL, active_building(u, btype)); - b->flags |= BLD_WORKING; + b->flags |= BLD_MAINTAINED; CuAssertIntEquals(tc, true, building_is_active(b)); CuAssertPtrEquals(tc, NULL, active_building(u, btype)); u_set_building(u, b); @@ -452,7 +452,7 @@ static void test_active_building(CuTest *tc) { CuAssertIntEquals(tc, false, building_is_active(b)); CuAssertPtrEquals(tc, NULL, active_building(u, btype)); btype->maxsize = -1; - b->flags &= ~BLD_WORKING; + b->flags &= ~BLD_MAINTAINED; CuAssertIntEquals(tc, false, building_is_active(b)); CuAssertPtrEquals(tc, NULL, active_building(u, btype)); test_cleanup(); diff --git a/src/kernel/curse.c b/src/kernel/curse.c index 11f389474..612127182 100644 --- a/src/kernel/curse.c +++ b/src/kernel/curse.c @@ -359,6 +359,7 @@ static bool cmp_curse(const attrib * a, const void *data) curse *get_curse(attrib * ap, const curse_type * ctype) { attrib *a = ap; + if (!ctype) return NULL; while (a) { if (a->type->flags & ATF_CURSE) { const attrib_type *at = a->type; @@ -724,7 +725,6 @@ static const char *oldnames[MAXCURSE] = { "oldrace", "fumble", "riotzone", - "nocostbuilding", "godcursezone", "speed", "orcish", diff --git a/src/kernel/curse.h b/src/kernel/curse.h index 3e2cf3095..c78e43405 100644 --- a/src/kernel/curse.h +++ b/src/kernel/curse.h @@ -130,7 +130,6 @@ extern "C" { C_OLDRACE, C_FUMBLE, C_RIOT, /*region in Aufruhr */ - C_NOCOST, C_CURSED_BY_THE_GODS, C_SPEED, /* Beschleunigt */ C_ORC, diff --git a/src/kernel/unit.c b/src/kernel/unit.c index b789ebeb6..47e4a63b4 100644 --- a/src/kernel/unit.c +++ b/src/kernel/unit.c @@ -782,7 +782,7 @@ ship *leftship(const unit * u) void u_set_building(unit * u, building * b) { - assert(!u->building); /* you must leave first */ + assert(!b || !u->building); /* you must leave first */ u->building = b; if (b && (!b->_owner || b->_owner->number <= 0)) { building_set_owner(u); diff --git a/src/laws.c b/src/laws.c index cec092d4c..3129bd16b 100755 --- a/src/laws.c +++ b/src/laws.c @@ -4251,11 +4251,6 @@ bool rule_force_leave(int flags) { return (rules&flags) == flags; } -static void maintain_buildings_1(region * r) -{ - maintain_buildings(r, false); -} - void init_processor(void) { int p; @@ -4340,10 +4335,9 @@ void init_processor(void) p += 10; if (!keyword_disabled(K_PAY)) { - add_proc_order(p, K_PAY, pay_cmd, 0, "Gebaeudeunterhalt (disable)"); + add_proc_order(p, K_PAY, pay_cmd, 0, "Gebaeudeunterhalt (BEZAHLE NICHT)"); } - add_proc_postregion(p, maintain_buildings_1, - "Gebaeudeunterhalt (1. Versuch)"); + add_proc_postregion(p, maintain_buildings, "Gebaeudeunterhalt"); p += 10; /* QUIT fuer sich alleine */ add_proc_global(p, quit, "Sterben"); diff --git a/src/laws.test.c b/src/laws.test.c index 9bb4bc8ef..32144fc4d 100644 --- a/src/laws.test.c +++ b/src/laws.test.c @@ -576,7 +576,12 @@ static void test_new_units(CuTest *tc) { assert(loc); u->orders = create_order(K_MAKETEMP, loc, "hurr"); new_units(); - CuAssertPtrNotNull(tc, u->next); + CuAssertPtrNotNull(tc, u = u->next); + CuAssertIntEquals(tc, UFL_ISNEW, fval(u, UFL_ISNEW)); + CuAssertIntEquals(tc, 0, u->number); + CuAssertIntEquals(tc, 0, u->age); + CuAssertPtrEquals(tc, f, u->faction); + CuAssertStrEquals(tc, "EINHEIT hurr", u->_name); test_cleanup(); } diff --git a/src/lighthouse.c b/src/lighthouse.c index 88193ecc7..6192db142 100644 --- a/src/lighthouse.c +++ b/src/lighthouse.c @@ -66,7 +66,7 @@ void update_lighthouse(building * lh) int lighthouse_range(const building * b, const faction * f) { int d = 0; - if (fval(b, BLD_WORKING) && b->size >= 10) { + if (fval(b, BLD_MAINTAINED) && b->size >= 10) { int maxd = (int)log10(b->size) + 1; if (skill_enabled(SK_PERCEPTION)) { @@ -112,7 +112,7 @@ bool check_leuchtturm(region * r, faction * f) building *b = (building *)a->data.v; assert(b->type == bt_find("lighthouse")); - if (fval(b, BLD_WORKING) && b->size >= 10) { + if (fval(b, BLD_MAINTAINED) && b->size >= 10) { int maxd = (int)log10(b->size) + 1; if (skill_enabled(SK_PERCEPTION) && f) { diff --git a/src/market.test.c b/src/market.test.c index 6132db39b..43e070b5e 100644 --- a/src/market.test.c +++ b/src/market.test.c @@ -67,7 +67,7 @@ static void test_market_curse(CuTest * tc) } r = findregion(1, 1); b = test_create_building(r, btype); - b->flags |= BLD_WORKING; + b->flags |= BLD_MAINTAINED; b->size = b->type->maxsize; f = test_create_faction(0); diff --git a/src/move.test.c b/src/move.test.c index e974a7b69..2ce9cccda 100644 --- a/src/move.test.c +++ b/src/move.test.c @@ -76,7 +76,7 @@ static void setup_harbor(move_fixture *mf) { r = test_create_region(0, 0, ttype); b = test_create_building(r, btype); - b->flags |= BLD_WORKING; + b->flags |= BLD_MAINTAINED; u = test_create_unit(test_create_faction(0), r); u->ship = sh; diff --git a/src/report.c b/src/report.c index 84b1291b2..6436fe990 100644 --- a/src/report.c +++ b/src/report.c @@ -1376,15 +1376,7 @@ static int buildingmaintenance(const building * b, const resource_type * rtype) { const building_type *bt = b->type; int c, cost = 0; - static bool init = false; - static const curse_type *nocost_ct; - if (!init) { - init = true; - nocost_ct = ct_find("nocostbuilding"); - } - if (curse_active(get_curse(b->attribs, nocost_ct))) { - return 0; - } + for (c = 0; bt->maintenance && bt->maintenance[c].number; ++c) { const maintenance *m = bt->maintenance + c; if (m->rtype == rtype) { @@ -1410,6 +1402,7 @@ report_template(const char *filename, report_context * ctx, const char *charset) size_t size; int bytes; bool utf8 = _strcmpl(charset, "utf8") == 0 || _strcmpl(charset, "utf-8") == 0; + const curse_type *nocost_ct = ct_find("nocostbuilding"); if (F == NULL) { perror(filename); @@ -1484,15 +1477,16 @@ report_template(const char *filename, report_context * ctx, const char *charset) WARN_STATIC_BUFFER(); if (u->building && building_owner(u->building) == u) { building *b = u->building; - int cost = buildingmaintenance(b, rsilver); - - if (cost > 0) { - bytes = (int)strlcpy(bufp, ",U", size); - if (wrptr(&bufp, &size, bytes) != 0) - WARN_STATIC_BUFFER(); - bytes = (int)strlcpy(bufp, itoa10(cost), size); - if (wrptr(&bufp, &size, bytes) != 0) - WARN_STATIC_BUFFER(); + if (!curse_active(get_curse(b->attribs, nocost_ct))) { + int cost = buildingmaintenance(b, rsilver); + if (cost > 0) { + bytes = (int)strlcpy(bufp, ",U", size); + if (wrptr(&bufp, &size, bytes) != 0) + WARN_STATIC_BUFFER(); + bytes = (int)strlcpy(bufp, itoa10(cost), size); + if (wrptr(&bufp, &size, bytes) != 0) + WARN_STATIC_BUFFER(); + } } } else if (u->ship) { diff --git a/src/study.test.c b/src/study.test.c index 729981145..7e0eb8744 100644 --- a/src/study.test.c +++ b/src/study.test.c @@ -161,7 +161,7 @@ static void test_study_bug_2194(CuTest *tc) { u_set_building(u2, b); i_change(&u1->items, get_resourcetype(R_SILVER)->itype, 50); i_change(&u2->items, get_resourcetype(R_SILVER)->itype, 50); - b->flags = BLD_WORKING; + b->flags = BLD_MAINTAINED; learn_inject(); teach_cmd(u, u->thisorder); learn_reset(); @@ -236,7 +236,7 @@ static void test_academy_building(CuTest *tc) { u_set_building(u2, b); i_change(&u1->items, get_resourcetype(R_SILVER)->itype, 50); i_change(&u2->items, get_resourcetype(R_SILVER)->itype, 50); - b->flags = BLD_WORKING; + b->flags = BLD_MAINTAINED; learn_inject(); teach_cmd(u, u->thisorder); learn_reset();