testing insect warmth potion

This commit is contained in:
Enno Rehling 2017-02-27 20:26:48 +01:00
parent 462d0118e3
commit 9e239c88f4
4 changed files with 54 additions and 30 deletions

View File

@ -11,6 +11,38 @@ function setup()
eressea.settings.set("magic.regeneration.enable", "0") eressea.settings.set("magic.regeneration.enable", "0")
end end
function test_nestwarmth_insect()
local r = region.create(0, 0, "plain")
local f = faction.create("noreply@eressea.de", "insect", "de")
local u = unit.create(f, r, 1)
local flags = u.flags
u:add_item("nestwarmth", 2)
u:clear_orders()
u:add_order("BENUTZEN 1 Nestwaerme")
turn_begin()
turn_process()
assert_equal(flags+64, u.flags) -- UFL_WARMTH
assert_equal(1, u:get_item("nestwarmth"))
assert_equal(1, f:count_msg_type('usepotion'))
turn_end()
end
function test_nestwarmth_other()
local r = region.create(0, 0, "plain")
local f = faction.create("noreply@eressea.de", "human", "de")
local u = unit.create(f, r, 1)
local flags = u.flags
u:add_item("nestwarmth", 2)
u:clear_orders()
u:add_order("BENUTZEN 1 Nestwaerme")
turn_begin()
turn_process()
assert_equal(flags, u.flags) -- nothing happens
assert_equal(2, u:get_item("nestwarmth"))
assert_equal(1, f:count_msg_type('error163'))
turn_end()
end
function test_meow() function test_meow()
local r = region.create(0, 0, "plain") local r = region.create(0, 0, "plain")
local f = faction.create("noreply@eressea.de", "human", "de") local f = faction.create("noreply@eressea.de", "human", "de")

View File

@ -58,7 +58,7 @@ function test_dreameye()
assert_equal(1, u:get_item("dreameye")) assert_equal(1, u:get_item("dreameye"))
assert_equal(1, f:count_msg_type('use_tacticcrystal')) assert_equal(1, f:count_msg_type('use_tacticcrystal'))
turn_end() turn_end()
assert_equal(nil, u:get_curse('skillmod')) assert_nil(u:get_curse('skillmod'))
end end
function test_manacrystal() function test_manacrystal()

View File

@ -389,6 +389,26 @@ use_mistletoe(struct unit *user, const struct item_type *itype, int amount,
return 0; return 0;
} }
static int use_warmthpotion(unit *u, const item_type *itype,
int amount, struct order *ord)
{
if (u->faction->race == get_race(RC_INSECT)) {
u->flags |= UFL_WARMTH;
}
else {
/* nur fuer insekten: */
cmistake(u, ord, 163, MSG_EVENT);
return ECUSTOM;
}
use_pooled(u, itype->rtype, GET_SLACK | GET_RESERVE | GET_POOLED_SLACK,
amount);
usetpotionuse(u, itype->rtype->ptype);
ADDMSG(&u->faction->msgs, msg_message("usepotion",
"unit potion", u, itype->rtype));
return 0;
}
void register_itemfunctions(void) void register_itemfunctions(void)
{ {
/* have tests: */ /* have tests: */
@ -403,4 +423,5 @@ void register_itemfunctions(void)
register_item_use(use_foolpotion, "use_p7"); register_item_use(use_foolpotion, "use_p7");
register_item_use(use_bloodpotion, "use_peasantblood"); register_item_use(use_bloodpotion, "use_peasantblood");
register_item_use(use_healingpotion, "use_ointment"); register_item_use(use_healingpotion, "use_ointment");
register_item_use(use_warmthpotion, "use_nestwarmth");
} }

View File

@ -726,26 +726,6 @@ struct order *), const char *name)
register_function((pf_generic)foo, name); register_function((pf_generic)foo, name);
} }
static int use_warmthpotion(unit *u, const item_type *itype,
int amount, struct order *ord)
{
if (u->faction->race == get_race(RC_INSECT)) {
fset(u, UFL_WARMTH);
}
else {
/* nur fuer insekten: */
cmistake(u, ord, 163, MSG_EVENT);
return ECUSTOM;
}
use_pooled(u, itype->rtype, GET_SLACK | GET_RESERVE | GET_POOLED_SLACK,
amount);
usetpotionuse(u, itype->rtype->ptype);
ADDMSG(&u->faction->msgs, msg_message("usepotion",
"unit potion", u, itype->rtype));
return 0;
}
static int static int
use_magicboost(struct unit *user, const struct item_type *itype, int amount, use_magicboost(struct unit *user, const struct item_type *itype, int amount,
struct order *ord) struct order *ord)
@ -775,13 +755,6 @@ struct order *ord)
return 0; return 0;
} }
static int
use_snowball(struct unit *user, const struct item_type *itype, int amount,
struct order *ord)
{
return 0;
}
static void init_oldpotions(void) static void init_oldpotions(void)
{ {
const char *potionnames[MAX_POTIONS] = { const char *potionnames[MAX_POTIONS] = {
@ -1113,9 +1086,7 @@ void register_resources(void)
register_function((pf_generic)res_changeaura, "changeaura"); register_function((pf_generic)res_changeaura, "changeaura");
register_item_use(use_potion_delayed, "use_p2"); register_item_use(use_potion_delayed, "use_p2");
register_item_use(use_warmthpotion, "use_nestwarmth");
register_item_use(use_magicboost, "usemagicboost"); register_item_use(use_magicboost, "usemagicboost");
register_item_use(use_snowball, "usesnowball");
register_item_give(give_horses, "givehorses"); register_item_give(give_horses, "givehorses");
} }