forked from github/server
remove item_useonother callbacks (use is fine).
add a test for foolpotion.
This commit is contained in:
parent
3c60f863a5
commit
b8ffc20d87
6 changed files with 37 additions and 31 deletions
|
@ -101,7 +101,7 @@
|
||||||
|
|
||||||
<resource name="p7" appearance="vial">
|
<resource name="p7" appearance="vial">
|
||||||
<item weight="0" score="90">
|
<item weight="0" score="90">
|
||||||
<function name="useonother" value="usefoolpotion"/>
|
<function name="use" value="usefoolpotion"/>
|
||||||
<potion level="3"/>
|
<potion level="3"/>
|
||||||
<construction skill="alchemy" minskill="6">
|
<construction skill="alchemy" minskill="6">
|
||||||
<requirement type="h2"/>
|
<requirement type="h2"/>
|
||||||
|
|
|
@ -230,6 +230,30 @@ function test_no_uruk()
|
||||||
assert_equal(f1.race, "orc")
|
assert_equal(f1.race, "orc")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function test_foolpotion()
|
||||||
|
local r = region.create(0, 0, "plain")
|
||||||
|
local f = faction.create("noreply@eressea.de", "human", "de")
|
||||||
|
local u = unit.create(f, r, 1)
|
||||||
|
u:add_item("p7", 1)
|
||||||
|
u:clear_orders()
|
||||||
|
u:add_order("BENUTZEN 1 Dumpfbackenbrot 4242")
|
||||||
|
process_orders()
|
||||||
|
assert_equal(1, u:get_item("p7"))
|
||||||
|
assert_equal(1, f:count_msg_type('feedback_unit_not_found'))
|
||||||
|
local u2 = unit.create(f, r, 1)
|
||||||
|
|
||||||
|
u:clear_orders()
|
||||||
|
u:add_order("BENUTZEN 1 Dumpfbackenbrot " .. itoa36(u2.id))
|
||||||
|
process_orders()
|
||||||
|
assert_equal(1, u:get_item("p7"))
|
||||||
|
assert_equal(1, f:count_msg_type('error64'))
|
||||||
|
|
||||||
|
u:set_skill("stealth", 1);
|
||||||
|
process_orders()
|
||||||
|
assert_equal(0, u:get_item("p7"))
|
||||||
|
assert_equal(1, f:count_msg_type('givedumb'))
|
||||||
|
end
|
||||||
|
|
||||||
function test_snowman()
|
function test_snowman()
|
||||||
local r = region.create(0, 0, "glacier")
|
local r = region.create(0, 0, "glacier")
|
||||||
local f = faction.create("noreply@eressea.de", "human", "de")
|
local f = faction.create("noreply@eressea.de", "human", "de")
|
||||||
|
|
|
@ -820,9 +820,8 @@ struct order *ord)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int use_warmthpotion(unit *u, const item_type *itype,
|
||||||
use_warmthpotion(struct unit *u, const struct item_type *itype, int amount,
|
int amount, struct order *ord)
|
||||||
struct order *ord)
|
|
||||||
{
|
{
|
||||||
if (u->faction->race == get_race(RC_INSECT)) {
|
if (u->faction->race == get_race(RC_INSECT)) {
|
||||||
fset(u, UFL_WARMTH);
|
fset(u, UFL_WARMTH);
|
||||||
|
@ -841,10 +840,10 @@ struct order *ord)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int use_foolpotion(unit *u, const item_type *itype, int amount,
|
||||||
use_foolpotion(struct unit *u, int targetno, const struct item_type *itype,
|
struct order *ord)
|
||||||
int amount, struct order *ord)
|
|
||||||
{
|
{
|
||||||
|
int targetno = read_unitid(u->faction, u->region);
|
||||||
unit *target = findunit(targetno);
|
unit *target = findunit(targetno);
|
||||||
if (target == NULL || u->region != target->region) {
|
if (target == NULL || u->region != target->region) {
|
||||||
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "feedback_unit_not_found",
|
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "feedback_unit_not_found",
|
||||||
|
@ -1295,7 +1294,7 @@ void register_resources(void)
|
||||||
register_item_use(use_warmthpotion, "usewarmthpotion");
|
register_item_use(use_warmthpotion, "usewarmthpotion");
|
||||||
register_item_use(use_bloodpotion, "usebloodpotion");
|
register_item_use(use_bloodpotion, "usebloodpotion");
|
||||||
register_item_use(use_healingpotion, "usehealingpotion");
|
register_item_use(use_healingpotion, "usehealingpotion");
|
||||||
register_item_useonother(use_foolpotion, "usefoolpotion");
|
register_item_use(use_foolpotion, "usefoolpotion");
|
||||||
register_item_use(use_mistletoe, "usemistletoe");
|
register_item_use(use_mistletoe, "usemistletoe");
|
||||||
register_item_use(use_magicboost, "usemagicboost");
|
register_item_use(use_magicboost, "usemagicboost");
|
||||||
register_item_use(use_snowball, "usesnowball");
|
register_item_use(use_snowball, "usesnowball");
|
||||||
|
|
|
@ -127,8 +127,6 @@ extern "C" {
|
||||||
const struct item_type * itype);
|
const struct item_type * itype);
|
||||||
int(*use) (struct unit * user, const struct item_type * itype, int amount,
|
int(*use) (struct unit * user, const struct item_type * itype, int amount,
|
||||||
struct order * ord);
|
struct order * ord);
|
||||||
int(*useonother) (struct unit * user, int targetno,
|
|
||||||
const struct item_type * itype, int amount, struct order * ord);
|
|
||||||
int(*give) (struct unit * src, struct unit * dest,
|
int(*give) (struct unit * src, struct unit * dest,
|
||||||
const struct item_type * itm, int number, struct order * ord);
|
const struct item_type * itm, int number, struct order * ord);
|
||||||
int score;
|
int score;
|
||||||
|
|
|
@ -857,11 +857,6 @@ static item_type *xml_readitem(xmlXPathContextPtr xpath, resource_type * rtype)
|
||||||
itype->canuse =
|
itype->canuse =
|
||||||
(bool(*)(const struct unit *, const struct item_type *))fun;
|
(bool(*)(const struct unit *, const struct item_type *))fun;
|
||||||
}
|
}
|
||||||
else if (strcmp((const char *)propValue, "useonother") == 0) {
|
|
||||||
itype->useonother =
|
|
||||||
(int(*)(struct unit *, int, const struct item_type *, int,
|
|
||||||
struct order *))fun;
|
|
||||||
}
|
|
||||||
else {
|
else {
|
||||||
log_error("unknown function type '%s' for item '%s'\n", (const char *)propValue, rtype->_name);
|
log_error("unknown function type '%s' for item '%s'\n", (const char *)propValue, rtype->_name);
|
||||||
}
|
}
|
||||||
|
|
10
src/laws.c
10
src/laws.c
|
@ -3242,11 +3242,6 @@ void update_long_order(unit * u)
|
||||||
static int use_item(unit * u, const item_type * itype, int amount, struct order *ord)
|
static int use_item(unit * u, const item_type * itype, int amount, struct order *ord)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
int target = -1;
|
|
||||||
|
|
||||||
if (itype->useonother) {
|
|
||||||
target = read_unitid(u->faction, u->region);
|
|
||||||
}
|
|
||||||
|
|
||||||
i = get_pooled(u, itype->rtype, GET_DEFAULT, amount);
|
i = get_pooled(u, itype->rtype, GET_DEFAULT, amount);
|
||||||
if (amount > i) {
|
if (amount > i) {
|
||||||
|
@ -3257,7 +3252,6 @@ static int use_item(unit * u, const item_type * itype, int amount, struct order
|
||||||
return ENOITEM;
|
return ENOITEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (target == -1) {
|
|
||||||
if (itype->use) {
|
if (itype->use) {
|
||||||
int result = itype->use(u, itype, amount, ord);
|
int result = itype->use(u, itype, amount, ord);
|
||||||
if (result > 0) {
|
if (result > 0) {
|
||||||
|
@ -3266,10 +3260,6 @@ static int use_item(unit * u, const item_type * itype, int amount, struct order
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
return EUNUSABLE;
|
return EUNUSABLE;
|
||||||
}
|
|
||||||
else {
|
|
||||||
return itype->useonother(u, target, itype, amount, ord);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void monthly_healing(void)
|
void monthly_healing(void)
|
||||||
|
|
Loading…
Reference in a new issue