From ab87b1da852f8e25016e6dc390b11c0bceea38ac Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Thu, 23 Mar 2017 18:51:30 +0100 Subject: [PATCH] add failing test for skill bonus from mine, start work --- scripts/tests/e2/adamantium.lua | 6 ++++++ src/economy.c | 14 ++++++++++---- src/kernel/building.h | 1 + 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/scripts/tests/e2/adamantium.lua b/scripts/tests/e2/adamantium.lua index 8cb703f33..0def0772f 100644 --- a/scripts/tests/e2/adamantium.lua +++ b/scripts/tests/e2/adamantium.lua @@ -49,5 +49,11 @@ function test_adamantium2() process_orders() assert_equal(1, u1:get_item("adamantium")) assert_equal(adamantium - 1, r:get_resource("adamantium")) + + -- mines give +1 to mining. mining 16 should give 2 adamantium + u1:set_skill("mining", 15) + process_orders() + assert_equal(3, u1:get_item("adamantium")) + assert_equal(adamantium - 3, r:get_resource("adamantium")) end diff --git a/src/economy.c b/src/economy.c index ce174dd09..971cbe794 100644 --- a/src/economy.c +++ b/src/economy.c @@ -923,7 +923,7 @@ static void allocate_resource(unit * u, const resource_type * rtype, int want) allocation *al; const resource_type *rring; int amount, skill, skill_mod = 0; - variant save_mod; + variant save_mod = frac_make(1, 1); /* momentan kann man keine ressourcen abbauen, wenn man daf�r * Materialverbrauch hat: */ @@ -950,9 +950,15 @@ static void allocate_resource(unit * u, const resource_type * rtype, int want) return; } } - else { - save_mod.sa[0] = 1; - save_mod.sa[1] = 1; + if (u->building && u->building->type->modifiers) { + building *b = inside_building(u); + if (b) { + message *msg = get_modifiers(u, b->type->modifiers, &save_mod, &skill_mod); + if (msg) { + ADDMSG(&u->faction->msgs, msg); + return; + } + } } /* Bergw�chter k�nnen Abbau von Eisen/Laen durch Bewachen verhindern. diff --git a/src/kernel/building.h b/src/kernel/building.h index 6d66aa9ab..88fe9bedd 100644 --- a/src/kernel/building.h +++ b/src/kernel/building.h @@ -73,6 +73,7 @@ extern "C" { void(*age) (struct building *); double(*taxes) (const struct building *, int size); struct attrib *attribs; + struct resource_mod *modifiers; } building_type; extern struct selist *buildingtypes;