refactoring the "nocostbuilding" curse.

- remove C_NOCOST constant and other baggage
- refactor maintenance a bit
This commit is contained in:
Enno Rehling 2016-08-21 17:19:22 +02:00
parent b2e79dc5e9
commit 901cf97cb2
8 changed files with 43 additions and 57 deletions

View File

@ -4464,10 +4464,6 @@
<text locale="de">Heimstein</text> <text locale="de">Heimstein</text>
<text locale="en">Homestone</text> <text locale="en">Homestone</text>
</string> </string>
<string name="nocostbuilding">
<text locale="de">Mauern der Ewigkeit</text>
<text locale="en">Eternal Walls</text>
</string>
<string name="nodrift"> <string name="nodrift">
<text locale="de">Wasserelementar</text> <text locale="de">Wasserelementar</text>
<text locale="en">Water Elemental</text> <text locale="en">Water Elemental</text>

View File

@ -274,7 +274,7 @@ void process_maintenance(void) {
} }
} }
} }
maintain_buildings(r, 0); maintain_buildings(r, false);
} }
} }

View File

@ -709,7 +709,7 @@ static int forget_cmd(unit * u, order * ord)
return 0; return 0;
} }
static bool maintain(building * b, bool first) static int maintain(building * b, bool first)
/* first==false -> take money from wherever you can */ /* first==false -> take money from wherever you can */
{ {
const resource_type *rsilver = get_resourcetype(R_SILVER); const resource_type *rsilver = get_resourcetype(R_SILVER);
@ -718,24 +718,22 @@ static bool maintain(building * b, bool first)
bool paid = true, work = first; bool paid = true, work = first;
unit *u; unit *u;
if (fval(b, BLD_MAINTAINED) || b->type == NULL || b->type->maintenance == NULL || is_cursed(b->attribs, C_NOCOST, 0)) { if (fval(b, BLD_MAINTAINED) || b->type == NULL || b->type->maintenance == NULL) {
fset(b, BLD_MAINTAINED); return (BLD_MAINTAINED|BLD_WORKING);
fset(b, BLD_WORKING);
return true;
} }
if (fval(b, BLD_DONTPAY)) { if (fval(b, BLD_DONTPAY)) {
return false; return 0;
} }
u = building_owner(b); u = building_owner(b);
if (u == NULL) { if (u == NULL) {
/* no owner - send a message to the entire region */ /* no owner - send a message to the entire region */
ADDMSG(&r->msgs, msg_message("maintenance_noowner", "building", b)); 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 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 (config_token("rules.region_owner_pay_building", b->type->_name)) {
if (fval(u->building, BLD_DONTPAY)) { if (fval(u->building, BLD_DONTPAY)) {
return false; return 0;
} }
} }
for (c = 0; b->type->maintenance[c].number; ++c) { 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)) { if (fval(b, BLD_DONTPAY)) {
return false; return 0;
} }
u = building_owner(b); u = building_owner(b);
if (u == NULL) if (!u) {
return false; return 0;
}
for (c = 0; b->type->maintenance[c].number; ++c) { for (c = 0; b->type->maintenance[c].number; ++c) {
const maintenance *m = b->type->maintenance + c; const maintenance *m = b->type->maintenance + c;
int need = m->number; int need = m->number;
@ -823,20 +822,9 @@ static bool maintain(building * b, bool first)
} }
} }
if (paid && c > 0) { 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 (first && !work) {
ADDMSG(&u->faction->msgs, msg_message("maintenancefail", "unit building", u, b)); ADDMSG(&u->faction->msgs, msg_message("maintenancefail", "unit building", u, b));
return false; return 0;
} }
for (c = 0; b->type->maintenance[c].number; ++c) { for (c = 0; b->type->maintenance[c].number; ++c) {
@ -876,27 +864,38 @@ static bool maintain(building * b, bool first)
} }
assert(cost == 0); 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)); ADDMSG(&u->faction->msgs, msg_message("maintenancefail", "unit building", u, b));
return false; return 0;
}
return true;
} }
void maintain_buildings(region * r, bool crash) void maintain_buildings(region * r, bool crash)
{ {
const curse_type *nocost_ct = ct_find("nocostbuilding");
building **bp = &r->buildings; building **bp = &r->buildings;
while (*bp) { while (*bp) {
building *b = *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 */ /* the second time, send a message */
if (crash) { if (crash) {
if (!fval(b, BLD_WORKING)) { if (!fval(b, BLD_WORKING)) {
unit *u = building_owner(b); unit *u = building_owner(b);
const char *msgtype = const char *msgtype =
maintained ? "maintenance_nowork" : "maintenance_none"; flags ? "maintenance_nowork" : "maintenance_none";
struct message *msg = msg_message(msgtype, "building", b); struct message *msg = msg_message(msgtype, "building", b);
if (u) { if (u) {

View File

@ -57,7 +57,6 @@ extern "C" {
void maintain_buildings(struct region *r, bool crash); void maintain_buildings(struct region *r, bool crash);
int make_cmd(struct unit *u, struct order *ord); int make_cmd(struct unit *u, struct order *ord);
void split_allocations(struct region *r); void split_allocations(struct region *r);
int recruit_archetypes(void);
int give_control_cmd(struct unit *u, struct order *ord); int give_control_cmd(struct unit *u, struct order *ord);
void give_control(struct unit * u, struct unit * u2); void give_control(struct unit * u, struct unit * u2);
void tax_cmd(struct unit * u, struct order *ord, struct request ** taxorders); void tax_cmd(struct unit * u, struct order *ord, struct request ** taxorders);

View File

@ -23,7 +23,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
/* kernel includes */ /* kernel includes */
#include "item.h" #include "item.h"
#include "curse.h" /* für C_NOCOST */
#include "unit.h" #include "unit.h"
#include "faction.h" #include "faction.h"
#include "race.h" #include "race.h"

View File

@ -359,6 +359,7 @@ static bool cmp_curse(const attrib * a, const void *data)
curse *get_curse(attrib * ap, const curse_type * ctype) curse *get_curse(attrib * ap, const curse_type * ctype)
{ {
attrib *a = ap; attrib *a = ap;
if (!ctype) return NULL;
while (a) { while (a) {
if (a->type->flags & ATF_CURSE) { if (a->type->flags & ATF_CURSE) {
const attrib_type *at = a->type; const attrib_type *at = a->type;
@ -724,7 +725,6 @@ static const char *oldnames[MAXCURSE] = {
"oldrace", "oldrace",
"fumble", "fumble",
"riotzone", "riotzone",
"nocostbuilding",
"godcursezone", "godcursezone",
"speed", "speed",
"orcish", "orcish",

View File

@ -130,7 +130,6 @@ extern "C" {
C_OLDRACE, C_OLDRACE,
C_FUMBLE, C_FUMBLE,
C_RIOT, /*region in Aufruhr */ C_RIOT, /*region in Aufruhr */
C_NOCOST,
C_CURSED_BY_THE_GODS, C_CURSED_BY_THE_GODS,
C_SPEED, /* Beschleunigt */ C_SPEED, /* Beschleunigt */
C_ORC, C_ORC,

View File

@ -1376,15 +1376,7 @@ static int buildingmaintenance(const building * b, const resource_type * rtype)
{ {
const building_type *bt = b->type; const building_type *bt = b->type;
int c, cost = 0; 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) { for (c = 0; bt->maintenance && bt->maintenance[c].number; ++c) {
const maintenance *m = bt->maintenance + c; const maintenance *m = bt->maintenance + c;
if (m->rtype == rtype) { if (m->rtype == rtype) {
@ -1410,6 +1402,7 @@ report_template(const char *filename, report_context * ctx, const char *charset)
size_t size; size_t size;
int bytes; int bytes;
bool utf8 = _strcmpl(charset, "utf8") == 0 || _strcmpl(charset, "utf-8") == 0; bool utf8 = _strcmpl(charset, "utf8") == 0 || _strcmpl(charset, "utf-8") == 0;
const curse_type *nocost_ct = ct_find("nocostbuilding");
if (F == NULL) { if (F == NULL) {
perror(filename); perror(filename);
@ -1484,8 +1477,8 @@ report_template(const char *filename, report_context * ctx, const char *charset)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
if (u->building && building_owner(u->building) == u) { if (u->building && building_owner(u->building) == u) {
building *b = u->building; building *b = u->building;
if (!curse_active(get_curse(b->attribs, nocost_ct))) {
int cost = buildingmaintenance(b, rsilver); int cost = buildingmaintenance(b, rsilver);
if (cost > 0) { if (cost > 0) {
bytes = (int)strlcpy(bufp, ",U", size); bytes = (int)strlcpy(bufp, ",U", size);
if (wrptr(&bufp, &size, bytes) != 0) if (wrptr(&bufp, &size, bytes) != 0)
@ -1495,6 +1488,7 @@ report_template(const char *filename, report_context * ctx, const char *charset)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
} }
} }
}
else if (u->ship) { else if (u->ship) {
if (ship_owner(u->ship) == u) { if (ship_owner(u->ship) == u) {
bytes = (int)strlcpy(bufp, ",S", size); bytes = (int)strlcpy(bufp, ",S", size);