From 1fe075e82d4f84c4e198389b4e85304e10557570 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Thu, 2 Aug 2012 00:06:03 -0700 Subject: [PATCH] laen test does not work. trying to make setresource add the raw material to fix it --- scripts/tests/common.lua | 21 ++++++--------------- src/kernel/region.c | 10 ++++++++++ 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/scripts/tests/common.lua b/scripts/tests/common.lua index 287736c66..f8f546e05 100755 --- a/scripts/tests/common.lua +++ b/scripts/tests/common.lua @@ -570,20 +570,11 @@ function test_config() end local function _test_create_laen() - local r = region.create(0,0, "mountain") - local f1 = faction.create("noreply@eressea.de", "human", "de") - local u1 = unit.create(f1, r, 1) - - -- TODO this is a stupid way to create a laen region - for i = 1, 10000 do - r = region.create(i,0, "mountain") - if r:get_resource("laen") > 2 then - break - end - end - assert(r:get_resource("laen")>2, "could not run test properly, please try again") - - return r, u1 + local r = region.create(0,0, "mountain") + local f1 = faction.create("noreply@eressea.de", "human", "de") + local u1 = unit.create(f1, r, 1) + r:set_resource("laen", 3) + return r, u1 end function test_laen1() @@ -611,7 +602,7 @@ function test_laen2() u1.building = b local laen = r:get_resource("laen") - process_orders() + process_orders() assert_equal(2, u1:get_item("laen")) assert_equal(laen - 2, r:get_resource("laen")) end diff --git a/src/kernel/region.c b/src/kernel/region.c index 491efa290..e22e5ef62 100644 --- a/src/kernel/region.c +++ b/src/kernel/region.c @@ -1016,6 +1016,16 @@ void region_setresource(region * r, const resource_type * rtype, int value) rsetpeasants(r, value); else if (rtype == rt_find("horse")) rsethorses(r, value); + else { + int i; + for (i = 0; r->terrain->production[i].type; ++i) { + const terrain_production *production = r->terrain->production + i; + if (production->type==rtype) { + add_resource(r, 1, value, dice_rand(production->divisor), rtype); + break; + } + } + } } }