error message if building is required.

was broken in recent commit.
also fix reference counts.
This commit is contained in:
Enno Rehling 2017-02-16 20:26:34 +01:00
parent a5dfe12d48
commit a624915a06
3 changed files with 9 additions and 6 deletions

View File

@ -891,9 +891,6 @@ struct message * get_modifiers(unit *u, const resource_mod *mod, double *savep,
for (; mod->flags != 0; ++mod) { for (; mod->flags != 0; ++mod) {
if (mod->btype == NULL || mod->btype == btype) { 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->race == NULL || mod->race == u_race(u)) {
if (mod->flags & RMF_SAVEMATERIAL) { if (mod->flags & RMF_SAVEMATERIAL) {
save *= mod->value.f; save *= mod->value.f;
@ -902,6 +899,8 @@ struct message * get_modifiers(unit *u, const resource_mod *mod, double *savep,
skill += mod->value.i; skill += mod->value.i;
} }
} }
} else if (mod->flags & RMF_REQUIREDBUILDING) {
return msg_error(u, u->thisorder, 104);
} }
} }
*skillp = skill; *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); message *msg = get_modifiers(u, rdata->modifiers, &save_mod, &skill_mod);
if (msg) { if (msg) {
ADDMSG(&u->faction->msgs, msg); ADDMSG(&u->faction->msgs, msg);
msg_release(msg);
return; return;
} }
} }

View File

@ -402,6 +402,13 @@ static void test_make_item(CuTest *tc) {
split_allocations(u->region); split_allocations(u->region);
CuAssertIntEquals(tc, 21, get_item(u, itype)); CuAssertIntEquals(tc, 21, get_item(u, itype));
CuAssertIntEquals(tc, 284, u->region->resources->amount); /* 60% saving = 6 stones make 10 stones */ 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(); test_cleanup();
} }

View File

@ -270,8 +270,6 @@ void syntax_error(const struct unit *u, struct order *ord)
ADDMSG(&u->faction->msgs, result); ADDMSG(&u->faction->msgs, result);
} }
extern unsigned int new_hashstring(const char *s);
void free_messagelist(mlist *msgs) void free_messagelist(mlist *msgs)
{ {
struct mlist **mlistptr; struct mlist **mlistptr;