laen test does not work. trying to make setresource add the raw material to fix it

This commit is contained in:
Enno Rehling 2012-08-02 00:06:03 -07:00
parent 166d4ccc2c
commit 1fe075e82d
2 changed files with 16 additions and 15 deletions

View File

@ -570,20 +570,11 @@ function test_config()
end end
local function _test_create_laen() local function _test_create_laen()
local r = region.create(0,0, "mountain") local r = region.create(0,0, "mountain")
local f1 = faction.create("noreply@eressea.de", "human", "de") local f1 = faction.create("noreply@eressea.de", "human", "de")
local u1 = unit.create(f1, r, 1) local u1 = unit.create(f1, r, 1)
r:set_resource("laen", 3)
-- TODO this is a stupid way to create a laen region return r, u1
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
end end
function test_laen1() function test_laen1()

View File

@ -1016,6 +1016,16 @@ void region_setresource(region * r, const resource_type * rtype, int value)
rsetpeasants(r, value); rsetpeasants(r, value);
else if (rtype == rt_find("horse")) else if (rtype == rt_find("horse"))
rsethorses(r, value); 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;
}
}
}
} }
} }