From a94e4219b1d07fda4c4431eacea4efa332076e0a Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 18 Jan 2020 21:06:48 +0100 Subject: [PATCH] automatic tree growth is a b*tch --- scripts/tests/e2/trees.lua | 40 +++++++++++++++++++++++++--- src/laws.c | 54 ++++++++++++++------------------------ 2 files changed, 56 insertions(+), 38 deletions(-) diff --git a/scripts/tests/e2/trees.lua b/scripts/tests/e2/trees.lua index 85f3f64ca..d2a1ec277 100644 --- a/scripts/tests/e2/trees.lua +++ b/scripts/tests/e2/trees.lua @@ -5,10 +5,13 @@ module("tests.e2.trees", package.seeall, lunit.testcase ) function setup() eressea.game.reset() 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") end function test_no_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') @@ -21,6 +24,20 @@ function test_no_growth() assert_equal(0, r:get_resource('tree')) 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 function test_plant_fail() set_turn(184) @@ -63,14 +80,22 @@ end -- in spring, herbalism >= T12 plants saplings at 10:1 rate function test_plant_spring_saplings() - set_turn(204) + set_turn(203) assert_equal('spring', get_season()) local f = faction.create('goblin') local r = region.create(0, 0, 'plain') + local u = unit.create(f, r) r:set_resource('seed', 0) r:set_resource('sapling', 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:add_item('seed', 20) 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 function test_plant_spring_seeds() set_turn(204) - assert_equal('spring', get_season()) local f = faction.create('goblin') local r = region.create(0, 0, 'plain') + local u = unit.create(f, r) r:set_resource('seed', 0) r:set_resource('sapling', 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:add_item('seed', 40) u:add_order("PFLANZE 10 Samen") diff --git a/src/laws.c b/src/laws.c index b065c3a31..d3912abac 100644 --- a/src/laws.c +++ b/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; attrib *a; + double seedchance = config_get_flt("rules.treeseeds.chance", 0.01F) * RESOURCE_QUANTITY; 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)); direction_t d; @@ -653,29 +653,28 @@ growing_trees(region * r, const season_t current_season, const season_t last_wee /* Gesamtzahl der Samen: * bis zu 6% (FORESTGROWTH*3) der Baeume samen in die Nachbarregionen */ - seeds = (rtrees(r, 2) * FORESTGROWTH * 3) / 1000000; - for (d = 0; d != MAXDIRECTIONS; ++d) { - region *r2 = rconnect(r, d); - if (r2 && fval(r2->terrain, LAND_REGION) && r2->terrain->size) { - /* Eine Landregion, wir versuchen Samen zu verteilen: - * Die Chance, das Samen ein Stueck Boden finden, in dem sie - * keimen koennen, haengt von der Bewuchsdichte und der - * verfuegbaren Flaeche ab. In Gletschern gibt es weniger - * Moeglichkeiten als in Ebenen. */ - sprout = 0; - seedchance = (1000.0 * region_maxworkers(r2)) / r2->terrain->size; - for (i = 0; i < seeds / MAXDIRECTIONS; i++) { - if (rng_int() % 10000 < seedchance) - sprout++; + if (seedchance > 0) { + seeds = (rtrees(r, 2) * FORESTGROWTH * 3) / 1000000; + for (d = 0; d != MAXDIRECTIONS; ++d) { + region *r2 = rconnect(r, d); + if (r2 && fval(r2->terrain, LAND_REGION) && r2->terrain->size) { + /* Eine Landregion, wir versuchen Samen zu verteilen: + * Die Chance, das Samen ein Stueck Boden finden, in dem sie + * keimen koennen, haengt von der Bewuchsdichte und der + * verfuegbaren Flaeche ab. In Gletschern gibt es weniger + * Moeglichkeiten als in Ebenen. */ + sprout = 0; + seedchance = (1000.0 * region_maxworkers(r2)) / r2->terrain->size; + for (i = 0; i < seeds / MAXDIRECTIONS; i++) { + if (rng_int() % 10000 < seedchance) + sprout++; + } + rsettrees(r2, 0, rtrees(r2, 0) + sprout); } - rsettrees(r2, 0, rtrees(r2, 0) + sprout); } } - } else if (current_season == SEASON_SPRING) { - int growth; - /* in at_germs merken uns die Zahl der Samen und Sproesslinge, die * dieses Jahr aelter werden duerfen, damit nicht ein Same im selben * 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[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 */ sprout = rtrees(r, 1); if (sprout > a->data.sa[1]) sprout = a->data.sa[1]; - grownup_trees = 0; - - for (i = 0; i < sprout; i++) { - if (rng_int() % 10000 < growth) - grownup_trees++; - } + grownup_trees = sprout / 6; /* aus dem Sproesslingepool dieses Jahres abziehen */ a->data.sa[1] = (short)(sprout - grownup_trees); /* aus dem gesamt Sproesslingepool abziehen */ @@ -708,12 +699,7 @@ growing_trees(region * r, const season_t current_season, const season_t last_wee /* Samenwachstum */ seeds = rtrees(r, 0); if (seeds > a->data.sa[0]) seeds = a->data.sa[0]; - sprout = 0; - - for (i = 0; i < seeds; i++) { - if (rng_int() % 10000 < growth) - sprout++; - } + sprout = seeds / 6; /* aus dem Samenpool dieses Jahres abziehen */ a->data.sa[0] = (short)(seeds - sprout); /* aus dem gesamt Samenpool abziehen */