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
|
@ -101,7 +101,7 @@
|
|||
|
||||
<resource name="p7" appearance="vial">
|
||||
<item weight="0" score="90">
|
||||
<function name="useonother" value="usefoolpotion"/>
|
||||
<function name="use" value="usefoolpotion"/>
|
||||
<potion level="3"/>
|
||||
<construction skill="alchemy" minskill="6">
|
||||
<requirement type="h2"/>
|
||||
|
|
|
@ -230,6 +230,30 @@ function test_no_uruk()
|
|||
assert_equal(f1.race, "orc")
|
||||
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()
|
||||
local r = region.create(0, 0, "glacier")
|
||||
local f = faction.create("noreply@eressea.de", "human", "de")
|
||||
|
|
|
@ -820,9 +820,8 @@ struct order *ord)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
use_warmthpotion(struct unit *u, const struct item_type *itype, int amount,
|
||||
struct order *ord)
|
||||
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);
|
||||
|
@ -841,10 +840,10 @@ struct order *ord)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
use_foolpotion(struct unit *u, int targetno, const struct item_type *itype,
|
||||
int amount, struct order *ord)
|
||||
static int use_foolpotion(unit *u, const item_type *itype, int amount,
|
||||
struct order *ord)
|
||||
{
|
||||
int targetno = read_unitid(u->faction, u->region);
|
||||
unit *target = findunit(targetno);
|
||||
if (target == NULL || u->region != target->region) {
|
||||
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_bloodpotion, "usebloodpotion");
|
||||
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_magicboost, "usemagicboost");
|
||||
register_item_use(use_snowball, "usesnowball");
|
||||
|
|
|
@ -127,8 +127,6 @@ extern "C" {
|
|||
const struct item_type * itype);
|
||||
int(*use) (struct unit * user, const struct item_type * itype, int amount,
|
||||
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,
|
||||
const struct item_type * itm, int number, struct order * ord);
|
||||
int score;
|
||||
|
|
|
@ -857,11 +857,6 @@ static item_type *xml_readitem(xmlXPathContextPtr xpath, resource_type * rtype)
|
|||
itype->canuse =
|
||||
(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 {
|
||||
log_error("unknown function type '%s' for item '%s'\n", (const char *)propValue, rtype->_name);
|
||||
}
|
||||
|
|
22
src/laws.c
22
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)
|
||||
{
|
||||
int i;
|
||||
int target = -1;
|
||||
|
||||
if (itype->useonother) {
|
||||
target = read_unitid(u->faction, u->region);
|
||||
}
|
||||
|
||||
i = get_pooled(u, itype->rtype, GET_DEFAULT, amount);
|
||||
if (amount > i) {
|
||||
|
@ -3257,19 +3252,14 @@ static int use_item(unit * u, const item_type * itype, int amount, struct order
|
|||
return ENOITEM;
|
||||
}
|
||||
|
||||
if (target == -1) {
|
||||
if (itype->use) {
|
||||
int result = itype->use(u, itype, amount, ord);
|
||||
if (result > 0) {
|
||||
use_pooled(u, itype->rtype, GET_DEFAULT, result);
|
||||
}
|
||||
return result;
|
||||
if (itype->use) {
|
||||
int result = itype->use(u, itype, amount, ord);
|
||||
if (result > 0) {
|
||||
use_pooled(u, itype->rtype, GET_DEFAULT, result);
|
||||
}
|
||||
return EUNUSABLE;
|
||||
}
|
||||
else {
|
||||
return itype->useonother(u, target, itype, amount, ord);
|
||||
return result;
|
||||
}
|
||||
return EUNUSABLE;
|
||||
}
|
||||
|
||||
void monthly_healing(void)
|
||||
|
|
Loading…
Reference in New Issue