forked from github/server
automatic tree growth is a b*tch
This commit is contained in:
parent
87a71d24e6
commit
a94e4219b1
|
@ -5,10 +5,13 @@ module("tests.e2.trees", package.seeall, lunit.testcase )
|
||||||
function setup()
|
function setup()
|
||||||
eressea.game.reset()
|
eressea.game.reset()
|
||||||
eressea.settings.set("rules.food.flags", "4") -- food is free
|
eressea.settings.set("rules.food.flags", "4") -- food is free
|
||||||
|
eressea.settings.set("rules.treeseeds.chance", "0.0") -- trees make no seeds
|
||||||
|
eressea.settings.set("rules.grow.formula", "0") -- no tree or seed growth
|
||||||
eressea.settings.set("NewbieImmunity", "0")
|
eressea.settings.set("NewbieImmunity", "0")
|
||||||
end
|
end
|
||||||
|
|
||||||
function test_no_growth()
|
function test_no_growth()
|
||||||
|
eressea.settings.set("rules.grow.formula", "2") -- E2 growth rules
|
||||||
set_turn(204)
|
set_turn(204)
|
||||||
assert_equal('spring', get_season())
|
assert_equal('spring', get_season())
|
||||||
local r = region.create(0, 0, 'plain')
|
local r = region.create(0, 0, 'plain')
|
||||||
|
@ -21,6 +24,20 @@ function test_no_growth()
|
||||||
assert_equal(0, r:get_resource('tree'))
|
assert_equal(0, r:get_resource('tree'))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function test_spring_growth()
|
||||||
|
eressea.settings.set("rules.grow.formula", "2") -- E2 growth rules
|
||||||
|
set_turn(204)
|
||||||
|
assert_equal('spring', get_season())
|
||||||
|
local r = region.create(0, 0, 'plain')
|
||||||
|
r:set_resource('seed', 6)
|
||||||
|
r:set_resource('sapling', 17)
|
||||||
|
r:set_resource('tree', 0)
|
||||||
|
process_orders()
|
||||||
|
assert_equal(5, r:get_resource('seed'))
|
||||||
|
assert_equal(16, r:get_resource('sapling'))
|
||||||
|
assert_equal(2, r:get_resource('tree'))
|
||||||
|
end
|
||||||
|
|
||||||
-- hebalism < T6 cannot plant
|
-- hebalism < T6 cannot plant
|
||||||
function test_plant_fail()
|
function test_plant_fail()
|
||||||
set_turn(184)
|
set_turn(184)
|
||||||
|
@ -63,14 +80,22 @@ end
|
||||||
|
|
||||||
-- in spring, herbalism >= T12 plants saplings at 10:1 rate
|
-- in spring, herbalism >= T12 plants saplings at 10:1 rate
|
||||||
function test_plant_spring_saplings()
|
function test_plant_spring_saplings()
|
||||||
set_turn(204)
|
set_turn(203)
|
||||||
assert_equal('spring', get_season())
|
assert_equal('spring', get_season())
|
||||||
local f = faction.create('goblin')
|
local f = faction.create('goblin')
|
||||||
local r = region.create(0, 0, 'plain')
|
local r = region.create(0, 0, 'plain')
|
||||||
|
local u = unit.create(f, r)
|
||||||
r:set_resource('seed', 0)
|
r:set_resource('seed', 0)
|
||||||
r:set_resource('sapling', 0)
|
r:set_resource('sapling', 0)
|
||||||
r:set_resource('tree', 0)
|
r:set_resource('tree', 0)
|
||||||
local u = unit.create(f, r)
|
|
||||||
|
assert_equal('spring', get_season())
|
||||||
|
process_orders() -- to initialize at_germs
|
||||||
|
assert_equal(0, r:get_resource('sapling'))
|
||||||
|
assert_equal(0, r:get_resource('seed'))
|
||||||
|
assert_equal(0, r:get_resource('tree'))
|
||||||
|
|
||||||
|
assert_equal('spring', get_season())
|
||||||
u:set_skill('herbalism', 12)
|
u:set_skill('herbalism', 12)
|
||||||
u:add_item('seed', 20)
|
u:add_item('seed', 20)
|
||||||
u:add_order("PFLANZE 20 Samen") -- limited by herbalism
|
u:add_order("PFLANZE 20 Samen") -- limited by herbalism
|
||||||
|
@ -84,13 +109,20 @@ end
|
||||||
-- herbalism < T12 means we are still planting seeds at 1:1
|
-- herbalism < T12 means we are still planting seeds at 1:1
|
||||||
function test_plant_spring_seeds()
|
function test_plant_spring_seeds()
|
||||||
set_turn(204)
|
set_turn(204)
|
||||||
assert_equal('spring', get_season())
|
|
||||||
local f = faction.create('goblin')
|
local f = faction.create('goblin')
|
||||||
local r = region.create(0, 0, 'plain')
|
local r = region.create(0, 0, 'plain')
|
||||||
|
local u = unit.create(f, r)
|
||||||
r:set_resource('seed', 0)
|
r:set_resource('seed', 0)
|
||||||
r:set_resource('sapling', 0)
|
r:set_resource('sapling', 0)
|
||||||
r:set_resource('tree', 0)
|
r:set_resource('tree', 0)
|
||||||
local u = unit.create(f, r)
|
|
||||||
|
assert_equal('spring', get_season())
|
||||||
|
process_orders() -- to initialize at_germs
|
||||||
|
assert_equal(0, r:get_resource('sapling'))
|
||||||
|
assert_equal(0, r:get_resource('seed'))
|
||||||
|
assert_equal(0, r:get_resource('tree'))
|
||||||
|
|
||||||
|
assert_equal('spring', get_season())
|
||||||
u:set_skill('herbalism', 10)
|
u:set_skill('herbalism', 10)
|
||||||
u:add_item('seed', 40)
|
u:add_item('seed', 40)
|
||||||
u:add_order("PFLANZE 10 Samen")
|
u:add_order("PFLANZE 10 Samen")
|
||||||
|
|
24
src/laws.c
24
src/laws.c
|
@ -603,9 +603,9 @@ growing_trees(region * r, const season_t current_season, const season_t last_wee
|
||||||
{
|
{
|
||||||
int grownup_trees, i, seeds, sprout;
|
int grownup_trees, i, seeds, sprout;
|
||||||
attrib *a;
|
attrib *a;
|
||||||
|
double seedchance = config_get_flt("rules.treeseeds.chance", 0.01F) * RESOURCE_QUANTITY;
|
||||||
|
|
||||||
if (current_season == SEASON_SUMMER || current_season == SEASON_AUTUMN) {
|
if (current_season == SEASON_SUMMER || current_season == SEASON_AUTUMN) {
|
||||||
double seedchance = 0.01F * RESOURCE_QUANTITY;
|
|
||||||
int mp, elves = count_race(r, get_race(RC_ELF));
|
int mp, elves = count_race(r, get_race(RC_ELF));
|
||||||
direction_t d;
|
direction_t d;
|
||||||
|
|
||||||
|
@ -653,6 +653,7 @@ growing_trees(region * r, const season_t current_season, const season_t last_wee
|
||||||
|
|
||||||
/* Gesamtzahl der Samen:
|
/* Gesamtzahl der Samen:
|
||||||
* bis zu 6% (FORESTGROWTH*3) der Baeume samen in die Nachbarregionen */
|
* bis zu 6% (FORESTGROWTH*3) der Baeume samen in die Nachbarregionen */
|
||||||
|
if (seedchance > 0) {
|
||||||
seeds = (rtrees(r, 2) * FORESTGROWTH * 3) / 1000000;
|
seeds = (rtrees(r, 2) * FORESTGROWTH * 3) / 1000000;
|
||||||
for (d = 0; d != MAXDIRECTIONS; ++d) {
|
for (d = 0; d != MAXDIRECTIONS; ++d) {
|
||||||
region *r2 = rconnect(r, d);
|
region *r2 = rconnect(r, d);
|
||||||
|
@ -671,11 +672,9 @@ growing_trees(region * r, const season_t current_season, const season_t last_wee
|
||||||
rsettrees(r2, 0, rtrees(r2, 0) + sprout);
|
rsettrees(r2, 0, rtrees(r2, 0) + sprout);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (current_season == SEASON_SPRING) {
|
else if (current_season == SEASON_SPRING) {
|
||||||
int growth;
|
|
||||||
|
|
||||||
/* in at_germs merken uns die Zahl der Samen und Sproesslinge, die
|
/* in at_germs merken uns die Zahl der Samen und Sproesslinge, die
|
||||||
* dieses Jahr aelter werden duerfen, damit nicht ein Same im selben
|
* dieses Jahr aelter werden duerfen, damit nicht ein Same im selben
|
||||||
* Zyklus zum Baum werden kann */
|
* Zyklus zum Baum werden kann */
|
||||||
|
@ -685,19 +684,11 @@ growing_trees(region * r, const season_t current_season, const season_t last_wee
|
||||||
a->data.sa[0] = cap_short(rtrees(r, 0));
|
a->data.sa[0] = cap_short(rtrees(r, 0));
|
||||||
a->data.sa[1] = cap_short(rtrees(r, 1));
|
a->data.sa[1] = cap_short(rtrees(r, 1));
|
||||||
}
|
}
|
||||||
/* wir haben 6 Wochen zum wachsen, jeder Same/Spross hat 18% Chance
|
|
||||||
* zu wachsen, damit sollten nach 5-6 Wochen alle gewachsen sein */
|
|
||||||
growth = 1800;
|
|
||||||
|
|
||||||
/* Baumwachstum */
|
/* Baumwachstum */
|
||||||
sprout = rtrees(r, 1);
|
sprout = rtrees(r, 1);
|
||||||
if (sprout > a->data.sa[1]) sprout = a->data.sa[1];
|
if (sprout > a->data.sa[1]) sprout = a->data.sa[1];
|
||||||
grownup_trees = 0;
|
grownup_trees = sprout / 6;
|
||||||
|
|
||||||
for (i = 0; i < sprout; i++) {
|
|
||||||
if (rng_int() % 10000 < growth)
|
|
||||||
grownup_trees++;
|
|
||||||
}
|
|
||||||
/* aus dem Sproesslingepool dieses Jahres abziehen */
|
/* aus dem Sproesslingepool dieses Jahres abziehen */
|
||||||
a->data.sa[1] = (short)(sprout - grownup_trees);
|
a->data.sa[1] = (short)(sprout - grownup_trees);
|
||||||
/* aus dem gesamt Sproesslingepool abziehen */
|
/* aus dem gesamt Sproesslingepool abziehen */
|
||||||
|
@ -708,12 +699,7 @@ growing_trees(region * r, const season_t current_season, const season_t last_wee
|
||||||
/* Samenwachstum */
|
/* Samenwachstum */
|
||||||
seeds = rtrees(r, 0);
|
seeds = rtrees(r, 0);
|
||||||
if (seeds > a->data.sa[0]) seeds = a->data.sa[0];
|
if (seeds > a->data.sa[0]) seeds = a->data.sa[0];
|
||||||
sprout = 0;
|
sprout = seeds / 6;
|
||||||
|
|
||||||
for (i = 0; i < seeds; i++) {
|
|
||||||
if (rng_int() % 10000 < growth)
|
|
||||||
sprout++;
|
|
||||||
}
|
|
||||||
/* aus dem Samenpool dieses Jahres abziehen */
|
/* aus dem Samenpool dieses Jahres abziehen */
|
||||||
a->data.sa[0] = (short)(seeds - sprout);
|
a->data.sa[0] = (short)(seeds - sprout);
|
||||||
/* aus dem gesamt Samenpool abziehen */
|
/* aus dem gesamt Samenpool abziehen */
|
||||||
|
|
Loading…
Reference in New Issue