test that mistletoe users survive attacks.

This commit is contained in:
Enno Rehling 2018-01-21 18:13:42 +01:00
parent 1eaa1e6d84
commit 0b036557c0
2 changed files with 20 additions and 5 deletions

View File

@ -15,7 +15,6 @@ function test_use_mistletoe()
local r = region.create(0, 0, "plain") local r = region.create(0, 0, "plain")
local f = faction.create("human") local f = faction.create("human")
local u = unit.create(f, r, 1) local u = unit.create(f, r, 1)
u.name = 'Miraculix'
u:add_item('mistletoe', 3) u:add_item('mistletoe', 3)
u:add_order("BENUTZEN 2 Mistelzweig") u:add_order("BENUTZEN 2 Mistelzweig")
process_orders() process_orders()
@ -24,6 +23,20 @@ function test_use_mistletoe()
assert_equal(1, f:count_msg_type('use_item')) assert_equal(1, f:count_msg_type('use_item'))
end end
function test_mistletoe_survive()
local r = region.create(0, 0, "plain")
local u = unit.create(faction.create("human"), r, 1)
local u2 = unit.create(faction.create("human"), r, 1)
local uno = u.id
u:add_item('mistletoe', 2)
u:add_order("BENUTZEN 2 Mistelzweig")
u2:add_order('ATTACKIERE ' .. itoa36(uno))
process_orders()
u = get_unit(uno)
assert_not_nil(u)
assert_equal(1, u:effect('mistletoe'))
end
function test_dreameye() function test_dreameye()
local r = region.create(0, 0, "plain") local r = region.create(0, 0, "plain")
local f = faction.create("human") local f = faction.create("human")

View File

@ -142,11 +142,14 @@ static int rule_tactics_formula;
static int rule_nat_armor; static int rule_nat_armor;
static int rule_cavalry_mode; static int rule_cavalry_mode;
static int rule_vampire; static int rule_vampire;
static const item_type *it_mistletoe;
/** initialize rules from configuration. /** initialize rules from configuration.
*/ */
static void init_rules(void) static void init_rules(void)
{ {
it_mistletoe = it_find("mistletoe");
rule_nat_armor = config_get_int("rules.combat.nat_armor", 0); rule_nat_armor = config_get_int("rules.combat.nat_armor", 0);
rule_tactics_formula = config_get_int("rules.tactics.formula", 0); rule_tactics_formula = config_get_int("rules.tactics.formula", 0);
rule_goblin_bonus = config_get_int("rules.combat.goblinbonus", 10); rule_goblin_bonus = config_get_int("rules.combat.goblinbonus", 10);
@ -3354,11 +3357,10 @@ static int join_battle(battle * b, unit * u, bool attack, fighter ** cp)
fighter *fc = NULL; fighter *fc = NULL;
if (!attack && u->attribs) { if (!attack && u->attribs) {
const item_type *itype = it_find("mistletoe"); if (it_mistletoe) {
if (itype) { int effect = get_effect(u, it_mistletoe);
int effect = get_effect(u, itype);
if (effect >= u->number) { if (effect >= u->number) {
change_effect(u, itype, -u->number); change_effect(u, it_mistletoe, -u->number);
*cp = NULL; *cp = NULL;
return false; return false;
} }