diff --git a/res/core/common/potions.xml b/res/core/common/potions.xml index 84b1e5f52..12ac67aa2 100644 --- a/res/core/common/potions.xml +++ b/res/core/common/potions.xml @@ -101,7 +101,7 @@ - + diff --git a/scripts/tests/e2/e2features.lua b/scripts/tests/e2/e2features.lua index de94ea34f..28cbbf69b 100644 --- a/scripts/tests/e2/e2features.lua +++ b/scripts/tests/e2/e2features.lua @@ -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") diff --git a/src/kernel/item.c b/src/kernel/item.c index 38d2e8711..9240a7994 100644 --- a/src/kernel/item.c +++ b/src/kernel/item.c @@ -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"); diff --git a/src/kernel/item.h b/src/kernel/item.h index 4351d611d..a2e588318 100644 --- a/src/kernel/item.h +++ b/src/kernel/item.h @@ -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; diff --git a/src/kernel/xmlreader.c b/src/kernel/xmlreader.c index 21c80566c..f5e45dd5c 100644 --- a/src/kernel/xmlreader.c +++ b/src/kernel/xmlreader.c @@ -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); } diff --git a/src/laws.c b/src/laws.c index 253b45b89..09b1439c0 100644 --- a/src/laws.c +++ b/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)