Bug 2625 PFLANZE Implementation aufgeklärt, Tests geschrieben.

This commit is contained in:
Enno Rehling 2020-01-07 20:28:43 +01:00
parent 2e054f27cc
commit 043949c8d0
3 changed files with 76 additions and 78 deletions

View file

@ -21,7 +21,28 @@ function test_no_growth()
assert_equal(0, r:get_resource('tree')) assert_equal(0, r:get_resource('tree'))
end end
function test_plant_seeds() -- hebalism < T6 cannot plant
function test_plant_fail()
set_turn(184)
assert_equal('summer', get_season())
local f = faction.create('goblin')
local r = region.create(0, 0, 'plain')
r:set_resource('seed', 0)
r:set_resource('sapling', 0)
r:set_resource('tree', 0)
local u = unit.create(f, r)
u:set_skill('herbalism', 5)
u:add_item('seed', 40)
u:add_order("PFLANZE 20 Samen")
process_orders()
assert_equal(0, r:get_resource('seed'))
assert_equal(0, r:get_resource('sapling'))
assert_equal(0, r:get_resource('tree'))
assert_equal(40, u:get_item('seed'))
end
-- T6+ herbalism allows planting seeds at 1:1 rates
function test_plant_summer()
set_turn(184) set_turn(184)
assert_equal('summer', get_season()) assert_equal('summer', get_season())
local f = faction.create('goblin') local f = faction.create('goblin')
@ -34,33 +55,48 @@ function test_plant_seeds()
u:add_item('seed', 40) u:add_item('seed', 40)
u:add_order("PFLANZE 20 Samen") u:add_order("PFLANZE 20 Samen")
process_orders() process_orders()
assert_equal(0, r:get_resource('sapling'))
assert_equal(20, r:get_resource('seed')) assert_equal(20, r:get_resource('seed'))
assert_equal(0, r:get_resource('sapling'))
assert_equal(0, r:get_resource('tree')) assert_equal(0, r:get_resource('tree'))
assert_equal(20, u:get_item('seed')) assert_equal(20, u:get_item('seed'))
end end
function disable_test_plant_seeds_spring() -- in spring, herbalism >= T12 plants saplings at 10:1 rate
set_turn(202) function test_plant_spring_saplings()
set_turn(204)
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')
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)
process_orders()
assert_equal(0, r:get_resource('sapling'))
assert_equal(0, r:get_resource('seed'))
assert_equal(0, r:get_resource('tree'))
local u = unit.create(f, r) local u = unit.create(f, r)
u:set_skill('herbalism', 20) u:set_skill('herbalism', 20)
u:add_item('seed', 40) u:add_item('seed', 40)
u:add_order("PFLANZE 20 Samen") u:add_order("PFLANZE 20 Samen")
process_orders() process_orders()
assert_equal(20, r:get_resource('sapling')) -- T12+ in Spring assert_equal(2, r:get_resource('sapling'))
assert_equal(0, r:get_resource('seed')) assert_equal(0, r:get_resource('seed'))
assert_equal(0, r:get_resource('tree')) assert_equal(0, r:get_resource('tree'))
assert_equal(20, u:get_item('seed')) assert_equal(20, u:get_item('seed'))
end 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')
r:set_resource('seed', 0)
r:set_resource('sapling', 0)
r:set_resource('tree', 0)
local u = unit.create(f, r)
u:set_skill('herbalism', 10)
u:add_item('seed', 40)
u:add_order("PFLANZE 10 Samen")
process_orders()
assert_equal(0, r:get_resource('sapling'))
assert_equal(10, r:get_resource('seed'))
assert_equal(0, r:get_resource('tree'))
assert_equal(30, u:get_item('seed'))
end

View file

@ -1682,84 +1682,39 @@ static void plant(unit * u, int raw)
u, r, planted, itype->rtype)); u, r, planted, itype->rtype));
} }
static void planttrees(unit * u, int raw) static void planttrees(region * r, int type, int n)
{ {
int n, i, skill, planted = 0; rsettrees(r, type, rtrees(r, type) + n);
const resource_type *rtype;
region * r = u->region;
if (!fval(r->terrain, LAND_REGION)) {
return;
}
/* Mallornbaeume kann man nur in Mallornregionen zuechten */
rtype = get_resourcetype(fval(r, RF_MALLORN) ? R_MALLORN_SEED : R_SEED);
/* Skill pruefen */
skill = effskill(u, SK_HERBALISM, NULL);
if (skill < 6) {
ADDMSG(&u->faction->msgs,
msg_feedback(u, u->thisorder, "plant_skills",
"skill minskill product", SK_HERBALISM, 6, rtype, 1));
return;
}
if (fval(r, RF_MALLORN) && skill < 7) {
ADDMSG(&u->faction->msgs,
msg_feedback(u, u->thisorder, "plant_skills",
"skill minskill product", SK_HERBALISM, 7, rtype, 1));
return;
}
/* wenn eine Anzahl angegeben wurde, nur soviel verbrauchen */
if (raw > skill * u->number) raw = skill * u->number;
n = get_pooled(u, rtype, GET_DEFAULT, raw);
if (n == 0) {
ADDMSG(&u->faction->msgs,
msg_feedback(u, u->thisorder, "resource_missing", "missing", rtype));
return;
}
if (n > raw) n = raw;
/* Fuer jeden Samen Talent*10% Erfolgschance. */
for (i = n; i > 0; i--) {
if (rng_int() % 10 < skill)
planted++;
}
rsettrees(r, 0, rtrees(r, 0) + planted);
/* Alles ok. Abziehen. */
produceexp(u, SK_HERBALISM, u->number);
use_pooled(u, rtype, GET_DEFAULT, n);
ADDMSG(&u->faction->msgs, msg_message("plant",
"unit region amount herb", u, r, planted, rtype));
} }
/* zuechte baeume */ /* zuechte baeume */
static void breedtrees(unit * u, int raw) static void breedtrees(unit * u, int raw)
{ {
int n, i, skill, planted = 0; int n, i, skill, planted;
const resource_type *rtype; const resource_type *rtype;
season_t current_season = calendar_season(turn); season_t current_season = calendar_season(turn);
region *r = u->region; region *r = u->region;
int minskill = 6;
/* Baeume zuechten geht nur im Fruehling */
if (current_season != SEASON_SPRING) {
planttrees(u, raw);
return;
}
if (!fval(r->terrain, LAND_REGION)) { if (!fval(r->terrain, LAND_REGION)) {
return; return;
} }
/* Mallornbaeume kann man nur in Mallornregionen zuechten */ /* Mallornbaeume kann man nur in Mallornregionen zuechten */
rtype = get_resourcetype(fval(r, RF_MALLORN) ? R_MALLORN_SEED : R_SEED); if (fval(r, RF_MALLORN)) {
++minskill;
rtype = get_resourcetype(R_MALLORN_SEED);
}
else {
rtype = get_resourcetype(R_SEED);
}
/* Skill pruefen */ /* Skill pruefen */
skill = effskill(u, SK_HERBALISM, NULL); skill = effskill(u, SK_HERBALISM, NULL);
if (skill < 12) { if (skill < minskill) {
planttrees(u, raw); ADDMSG(&u->faction->msgs,
msg_feedback(u, u->thisorder, "plant_skills",
"skill minskill product", SK_HERBALISM, 6, rtype, 1));
return; return;
} }
@ -1775,14 +1730,21 @@ static void breedtrees(unit * u, int raw)
} }
if (n > raw) n = raw; if (n > raw) n = raw;
/* Fuer jeden Samen Talent*5% Erfolgschance. */ if (skill >= 12 && current_season == SEASON_SPRING) {
for (i = n; i > 0; i--) { // Plant saplings at a rate of 10:1
if (rng_int() % 100 < skill * 5) int remain = n % 10;
planted++; planted = n / 10;
if ((remain > 0) && (rng_int() % 10) < remain) {
++planted;
}
planttrees(r, 1, planted);
}
else {
planted = n;
planttrees(r, 0, planted);
} }
rsettrees(r, 1, rtrees(r, 1) + planted);
/* Alles ok. Abziehen. */ /* Alles ok. Samen abziehen. */
produceexp(u, SK_HERBALISM, u->number); produceexp(u, SK_HERBALISM, u->number);
use_pooled(u, rtype, GET_DEFAULT, n); use_pooled(u, rtype, GET_DEFAULT, n);

View file

@ -217,7 +217,7 @@ int monster_attacks(unit * monster, bool rich_only)
static order *get_money_for_dragon(region * r, unit * u, int wanted) static order *get_money_for_dragon(region * r, unit * u, int wanted)
{ {
int money; int money;
bool attacks = (attack_chance > 0.0) && armedmen(u); bool attacks = (attack_chance > 0.0) && armedmen(u, false);
/* falls genug geld in der region ist, treiben wir steuern ein. */ /* falls genug geld in der region ist, treiben wir steuern ein. */
if (rmoney(r) >= wanted) { if (rmoney(r) >= wanted) {