From a42bd9c3bfadd65fbddf9626d9a89e9146458cb5 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 21 Aug 2016 20:12:28 +0200 Subject: [PATCH] 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();