From 2df881c6ed49db7a4c977c29ca1910e45f8d38b8 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 21 Aug 2016 12:38:25 +0200 Subject: [PATCH 1/6] check the results of MAKE TEMP new units have the UFL_ISNEW flag --- src/laws.test.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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(); } From b2e79dc5e9611aa02d3cf67e7decdb62d94c2613 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 21 Aug 2016 20:01:30 +0200 Subject: [PATCH 2/6] building maintenance unit tests. backfilling some very basic test coverage. --- src/economy.test.c | 52 ++++++++++++++++++++++++++++++++++++++++++++-- src/kernel/unit.c | 2 +- 2 files changed, 51 insertions(+), 3 deletions(-) diff --git a/src/economy.test.c b/src/economy.test.c index 577c7931a..8b0726ebc 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, false); + 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, false); + CuAssertIntEquals(tc, 0, fval(b, BLD_MAINTAINED)); + + // we can afford to pay: + i_change(&u->items, itype, 100); + b->flags = 0; + maintain_buildings(r, false); + 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, false); + 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/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); From 901cf97cb2629595b467374019ae71ad9e66ce00 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 21 Aug 2016 17:19:22 +0200 Subject: [PATCH 3/6] refactoring the "nocostbuilding" curse. - remove C_NOCOST constant and other baggage - refactor maintenance a bit --- res/core/de/strings.xml | 4 --- src/bind_process.c | 2 +- src/economy.c | 59 ++++++++++++++++++++--------------------- src/economy.h | 1 - src/kernel/building.c | 1 - src/kernel/curse.c | 2 +- src/kernel/curse.h | 1 - src/report.c | 30 +++++++++------------ 8 files changed, 43 insertions(+), 57 deletions(-) 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/src/bind_process.c b/src/bind_process.c index 7d0124400..e22a65bc9 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, false); } } diff --git a/src/economy.c b/src/economy.c index 2156744b0..594935871 100644 --- a/src/economy.c +++ b/src/economy.c @@ -709,7 +709,7 @@ static int forget_cmd(unit * u, order * ord) return 0; } -static bool maintain(building * b, bool first) +static int maintain(building * b, bool first) /* first==false -> take money from wherever you can */ { const resource_type *rsilver = get_resourcetype(R_SILVER); @@ -718,24 +718,22 @@ static bool maintain(building * b, bool first) bool paid = true, work = first; 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|BLD_WORKING); } 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) { @@ -778,11 +776,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; @@ -823,20 +822,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) { ADDMSG(&u->faction->msgs, msg_message("maintenancefail", "unit building", u, b)); - return false; + return 0; } for (c = 0; b->type->maintenance[c].number; ++c) { @@ -876,27 +864,38 @@ static bool maintain(building * b, bool first) } assert(cost == 0); } + if (!first) { + ADDMSG(&u->faction->msgs, msg_message("maintenance_late", "building", b)); + return (BLD_MAINTAINED); + } + else if (work) { + ADDMSG(&u->faction->msgs, msg_message("maintenance", "unit building", u, b)); + return (BLD_MAINTAINED | BLD_WORKING); + } } - 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) { + 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 | BLD_WORKING); + + if (!curse_active(get_curse(b->attribs, nocost_ct))) { + flags = maintain(b, !crash); + } + 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"; + flags ? "maintenance_nowork" : "maintenance_none"; struct message *msg = msg_message(msgtype, "building", b); if (u) { diff --git a/src/economy.h b/src/economy.h index 7e399cc76..40e05a8a7 100644 --- a/src/economy.h +++ b/src/economy.h @@ -57,7 +57,6 @@ extern "C" { void maintain_buildings(struct region *r, bool crash); 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/kernel/building.c b/src/kernel/building.c index c6d7f7af2..707edd4c0 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" 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/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) { From 43090e1492227eba0035542f4e32428d578e86b8 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 21 Aug 2016 18:06:38 +0200 Subject: [PATCH 4/6] remove any reference to old two-stage maintenance. getting rid of a lot of dead code. --- res/core/messages.xml | 7 --- src/bind_process.c | 2 +- src/economy.c | 116 ++++++++---------------------------------- src/economy.h | 2 +- src/laws.c | 10 +--- 5 files changed, 26 insertions(+), 111 deletions(-) diff --git a/res/core/messages.xml b/res/core/messages.xml index bb57fd32d..5f319eacf 100644 --- a/res/core/messages.xml +++ b/res/core/messages.xml @@ -7087,13 +7087,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_process.c b/src/bind_process.c index e22a65bc9..e8420c654 100755 --- a/src/bind_process.c +++ b/src/bind_process.c @@ -274,7 +274,7 @@ void process_maintenance(void) { } } } - maintain_buildings(r, false); + maintain_buildings(r); } } diff --git a/src/economy.c b/src/economy.c index 594935871..3712c0d13 100644 --- a/src/economy.c +++ b/src/economy.c @@ -709,13 +709,11 @@ static int forget_cmd(unit * u, order * ord) return 0; } -static int 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) { @@ -746,25 +744,7 @@ static int 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)) @@ -789,32 +769,10 @@ static int 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; } @@ -822,7 +780,7 @@ static int maintain(building * b, bool first) } } if (paid && c > 0) { - if (first && !work) { + if (!work) { ADDMSG(&u->faction->msgs, msg_message("maintenancefail", "unit building", u, b)); return 0; } @@ -836,39 +794,12 @@ static int 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 (!first) { - ADDMSG(&u->faction->msgs, msg_message("maintenance_late", "building", b)); - return (BLD_MAINTAINED); - } - else if (work) { + if (work) { ADDMSG(&u->faction->msgs, msg_message("maintenance", "unit building", u, b)); return (BLD_MAINTAINED | BLD_WORKING); } @@ -877,7 +808,7 @@ static int maintain(building * b, bool first) 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; @@ -886,27 +817,24 @@ void maintain_buildings(region * r, bool crash) int flags = (BLD_MAINTAINED | BLD_WORKING); if (!curse_active(get_curse(b->attribs, nocost_ct))) { - flags = maintain(b, !crash); + 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 = - flags ? "maintenance_nowork" : "maintenance_none"; - struct message *msg = msg_message(msgtype, "building", b); + if (!fval(b, BLD_WORKING)) { + unit *u = building_owner(b); + const char *msgtype = + flags ? "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 (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 40e05a8a7..b6c8002c9 100644 --- a/src/economy.h +++ b/src/economy.h @@ -54,7 +54,7 @@ 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 give_control_cmd(struct unit *u, struct order *ord); 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"); From d3e05c7ddf9e9160f63c20b4960d171f99c8beea Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 21 Aug 2016 20:04:51 +0200 Subject: [PATCH 5/6] merge in and fix the economy tests --- src/economy.test.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/economy.test.c b/src/economy.test.c index 8b0726ebc..ce09aae43 100644 --- a/src/economy.test.c +++ b/src/economy.test.c @@ -261,7 +261,7 @@ static void test_maintain_buildings(CuTest *tc) { // this building has no upkeep, it just works: b->flags = 0; - maintain_buildings(r, false); + maintain_buildings(r); CuAssertIntEquals(tc, BLD_MAINTAINED, fval(b, BLD_MAINTAINED)); req = calloc(2, sizeof(maintenance)); @@ -271,20 +271,20 @@ static void test_maintain_buildings(CuTest *tc) { // we cannot afford to pay: b->flags = 0; - maintain_buildings(r, false); + 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, false); + 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, false); + maintain_buildings(r); CuAssertIntEquals(tc, 0, fval(b, BLD_MAINTAINED)); test_cleanup(); From a42bd9c3bfadd65fbddf9626d9a89e9146458cb5 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 21 Aug 2016 20:12:28 +0200 Subject: [PATCH 6/6] remove the BLD_WORKING flag. it's all about BLD_MAINTAINED now. fix region.blocked (Lua property). --- res/core/messages.xml | 7 ------- src/bind_building.c | 6 +++--- src/bind_region.c | 4 ++-- src/economy.c | 13 +++++-------- src/kernel/build.c | 2 +- src/kernel/build.test.c | 2 +- src/kernel/building.c | 4 ++-- src/kernel/building.h | 3 +-- src/kernel/building.test.c | 12 ++++++------ src/lighthouse.c | 4 ++-- src/market.test.c | 2 +- src/move.test.c | 2 +- src/study.test.c | 4 ++-- 13 files changed, 27 insertions(+), 38 deletions(-) diff --git a/res/core/messages.xml b/res/core/messages.xml index 5f319eacf..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." - 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_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 3712c0d13..155a46b7e 100644 --- a/src/economy.c +++ b/src/economy.c @@ -717,7 +717,7 @@ static int maintain(building * b) unit *u; if (fval(b, BLD_MAINTAINED) || b->type == NULL || b->type->maintenance == NULL) { - return (BLD_MAINTAINED|BLD_WORKING); + return BLD_MAINTAINED; } if (fval(b, BLD_DONTPAY)) { return 0; @@ -801,7 +801,7 @@ static int maintain(building * b) } if (work) { ADDMSG(&u->faction->msgs, msg_message("maintenance", "unit building", u, b)); - return (BLD_MAINTAINED | BLD_WORKING); + return BLD_MAINTAINED; } } ADDMSG(&u->faction->msgs, msg_message("maintenancefail", "unit building", u, b)); @@ -814,19 +814,16 @@ void maintain_buildings(region * r) building **bp = &r->buildings; while (*bp) { building *b = *bp; - int flags = (BLD_MAINTAINED | BLD_WORKING); + int flags = BLD_MAINTAINED; if (!curse_active(get_curse(b->attribs, nocost_ct))) { flags = maintain(b); } fset(b, flags); - if (!fval(b, BLD_WORKING)) { + if (!fval(b, BLD_MAINTAINED)) { unit *u = building_owner(b); - const char *msgtype = - flags ? "maintenance_nowork" : "maintenance_none"; - struct message *msg = msg_message(msgtype, "building", b); - + struct message *msg = msg_message("maintenance_nowork", "building", b); if (u) { add_message(&u->faction->msgs, msg); r_addmessage(r, u->faction, msg); 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 707edd4c0..cf40c0ea3 100644 --- a/src/kernel/building.c +++ b/src/kernel/building.c @@ -648,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; } } @@ -661,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/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/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();