forked from github/server
Bug 2625 PFLANZE Implementation aufgeklärt, Tests geschrieben.
This commit is contained in:
parent
2e054f27cc
commit
043949c8d0
3 changed files with 76 additions and 78 deletions
|
@ -21,7 +21,28 @@ function test_no_growth()
|
|||
assert_equal(0, r:get_resource('tree'))
|
||||
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)
|
||||
assert_equal('summer', get_season())
|
||||
local f = faction.create('goblin')
|
||||
|
@ -34,33 +55,48 @@ function test_plant_seeds()
|
|||
u:add_item('seed', 40)
|
||||
u:add_order("PFLANZE 20 Samen")
|
||||
process_orders()
|
||||
assert_equal(0, r:get_resource('sapling'))
|
||||
assert_equal(20, r:get_resource('seed'))
|
||||
assert_equal(0, r:get_resource('sapling'))
|
||||
assert_equal(0, r:get_resource('tree'))
|
||||
assert_equal(20, u:get_item('seed'))
|
||||
end
|
||||
|
||||
function disable_test_plant_seeds_spring()
|
||||
set_turn(202)
|
||||
-- in spring, herbalism >= T12 plants saplings at 10:1 rate
|
||||
function test_plant_spring_saplings()
|
||||
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)
|
||||
|
||||
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)
|
||||
u:set_skill('herbalism', 20)
|
||||
u:add_item('seed', 40)
|
||||
u:add_order("PFLANZE 20 Samen")
|
||||
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('tree'))
|
||||
assert_equal(20, u:get_item('seed'))
|
||||
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
|
||||
|
|
|
@ -1682,84 +1682,39 @@ static void plant(unit * u, int raw)
|
|||
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;
|
||||
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));
|
||||
rsettrees(r, type, rtrees(r, type) + n);
|
||||
}
|
||||
|
||||
/* zuechte baeume */
|
||||
static void breedtrees(unit * u, int raw)
|
||||
{
|
||||
int n, i, skill, planted = 0;
|
||||
int n, i, skill, planted;
|
||||
const resource_type *rtype;
|
||||
season_t current_season = calendar_season(turn);
|
||||
region *r = u->region;
|
||||
|
||||
/* Baeume zuechten geht nur im Fruehling */
|
||||
if (current_season != SEASON_SPRING) {
|
||||
planttrees(u, raw);
|
||||
return;
|
||||
}
|
||||
int minskill = 6;
|
||||
|
||||
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);
|
||||
if (fval(r, RF_MALLORN)) {
|
||||
++minskill;
|
||||
rtype = get_resourcetype(R_MALLORN_SEED);
|
||||
}
|
||||
else {
|
||||
rtype = get_resourcetype(R_SEED);
|
||||
}
|
||||
|
||||
/* Skill pruefen */
|
||||
skill = effskill(u, SK_HERBALISM, NULL);
|
||||
if (skill < 12) {
|
||||
planttrees(u, raw);
|
||||
if (skill < minskill) {
|
||||
ADDMSG(&u->faction->msgs,
|
||||
msg_feedback(u, u->thisorder, "plant_skills",
|
||||
"skill minskill product", SK_HERBALISM, 6, rtype, 1));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1775,14 +1730,21 @@ static void breedtrees(unit * u, int raw)
|
|||
}
|
||||
if (n > raw) n = raw;
|
||||
|
||||
/* Fuer jeden Samen Talent*5% Erfolgschance. */
|
||||
for (i = n; i > 0; i--) {
|
||||
if (rng_int() % 100 < skill * 5)
|
||||
planted++;
|
||||
if (skill >= 12 && current_season == SEASON_SPRING) {
|
||||
// Plant saplings at a rate of 10:1
|
||||
int remain = n % 10;
|
||||
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);
|
||||
use_pooled(u, rtype, GET_DEFAULT, n);
|
||||
|
||||
|
|
|
@ -217,7 +217,7 @@ int monster_attacks(unit * monster, bool rich_only)
|
|||
static order *get_money_for_dragon(region * r, unit * u, int wanted)
|
||||
{
|
||||
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. */
|
||||
if (rmoney(r) >= wanted) {
|
||||
|
|
Loading…
Reference in a new issue