forked from github/server
refactoring the "nocostbuilding" curse.
- remove C_NOCOST constant and other baggage - refactor maintenance a bit
This commit is contained in:
parent
b2e79dc5e9
commit
901cf97cb2
|
@ -4464,10 +4464,6 @@
|
|||
<text locale="de">Heimstein</text>
|
||||
<text locale="en">Homestone</text>
|
||||
</string>
|
||||
<string name="nocostbuilding">
|
||||
<text locale="de">Mauern der Ewigkeit</text>
|
||||
<text locale="en">Eternal Walls</text>
|
||||
</string>
|
||||
<string name="nodrift">
|
||||
<text locale="de">Wasserelementar</text>
|
||||
<text locale="en">Water Elemental</text>
|
||||
|
|
|
@ -274,7 +274,7 @@ void process_maintenance(void) {
|
|||
}
|
||||
}
|
||||
}
|
||||
maintain_buildings(r, 0);
|
||||
maintain_buildings(r, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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,
|
||||
|
|
30
src/report.c
30
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) {
|
||||
|
|
Loading…
Reference in New Issue