From a624915a0634ef1ac731c6c12e99242e25609a3d Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Thu, 16 Feb 2017 20:26:34 +0100 Subject: [PATCH] error message if building is required. was broken in recent commit. also fix reference counts. --- src/economy.c | 6 ++---- src/economy.test.c | 7 +++++++ src/kernel/messages.c | 2 -- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/economy.c b/src/economy.c index df01f3b45..4c54cb5da 100644 --- a/src/economy.c +++ b/src/economy.c @@ -891,9 +891,6 @@ struct message * get_modifiers(unit *u, const resource_mod *mod, double *savep, for (; mod->flags != 0; ++mod) { if (mod->btype == NULL || mod->btype == btype) { - if (mod->flags & RMF_REQUIREDBUILDING) { - return msg_error(u, u->thisorder, 104);; - } if (mod->race == NULL || mod->race == u_race(u)) { if (mod->flags & RMF_SAVEMATERIAL) { save *= mod->value.f; @@ -902,6 +899,8 @@ struct message * get_modifiers(unit *u, const resource_mod *mod, double *savep, skill += mod->value.i; } } + } else if (mod->flags & RMF_REQUIREDBUILDING) { + return msg_error(u, u->thisorder, 104); } } *skillp = skill; @@ -945,7 +944,6 @@ static void allocate_resource(unit * u, const resource_type * rtype, int want) message *msg = get_modifiers(u, rdata->modifiers, &save_mod, &skill_mod); if (msg) { ADDMSG(&u->faction->msgs, msg); - msg_release(msg); return; } } diff --git a/src/economy.test.c b/src/economy.test.c index ddb0cafbc..7101d859a 100644 --- a/src/economy.test.c +++ b/src/economy.test.c @@ -402,6 +402,13 @@ static void test_make_item(CuTest *tc) { split_allocations(u->region); CuAssertIntEquals(tc, 21, get_item(u, itype)); CuAssertIntEquals(tc, 284, u->region->resources->amount); /* 60% saving = 6 stones make 10 stones */ + + rdata->modifiers[0].flags = RMF_REQUIREDBUILDING; + rdata->modifiers[0].race = NULL; + rdata->modifiers[0].btype = bt_get_or_create("mine"); + make_item(u, itype, 10); + CuAssertPtrNotNull(tc, test_find_messagetype(u->faction->msgs, "error104")); + test_cleanup(); } diff --git a/src/kernel/messages.c b/src/kernel/messages.c index cb859df96..f74e9c0d7 100644 --- a/src/kernel/messages.c +++ b/src/kernel/messages.c @@ -270,8 +270,6 @@ void syntax_error(const struct unit *u, struct order *ord) ADDMSG(&u->faction->msgs, result); } -extern unsigned int new_hashstring(const char *s); - void free_messagelist(mlist *msgs) { struct mlist **mlistptr;