forked from github/server
Eliminate rules.magic.multipotion, it's too much code.
This commit is contained in:
parent
a2d23d01fa
commit
438ae6f905
6 changed files with 38 additions and 77 deletions
|
@ -93,7 +93,6 @@
|
|||
"rules.region_owners": true,
|
||||
"rules.cavalry.skill": 2,
|
||||
"rules.cavalry.mode": 1,
|
||||
"rules.magic.multipotion": true,
|
||||
"rules.magic.wol_effect": 5,
|
||||
"rules.magic.factionlist": true,
|
||||
"rules.magic.wol_type": 2,
|
||||
|
|
|
@ -173,6 +173,41 @@ function test_use_healing_potion_multi_units()
|
|||
turn_end()
|
||||
end
|
||||
|
||||
function test_use_multiple_healing_potions()
|
||||
-- Einheit kann mehr als einen Heiltrank benutzen
|
||||
local r = region.create(0, 0, "plain")
|
||||
local f = faction.create("human")
|
||||
local u = unit.create(f, r, 60)
|
||||
assert_equal(1200, u.hp)
|
||||
u.hp = 400
|
||||
turn_begin()
|
||||
u:add_item("p14", 2)
|
||||
u:clear_orders()
|
||||
u:add_order("BENUTZEN 2 Heiltrank")
|
||||
turn_process()
|
||||
assert_equal(1200, u.hp)
|
||||
assert_equal(0, u:get_item("p14"))
|
||||
turn_end()
|
||||
end
|
||||
|
||||
function test_use_healing_potions_twice()
|
||||
-- Einheit kann mehr als einen BENUTZE Heiltrank Befehl haben
|
||||
local r = region.create(0, 0, "plain")
|
||||
local f = faction.create("human")
|
||||
local u = unit.create(f, r, 60)
|
||||
assert_equal(1200, u.hp)
|
||||
u.hp = 400
|
||||
turn_begin()
|
||||
u:add_item("p14", 2)
|
||||
u:clear_orders()
|
||||
u:add_order("BENUTZEN 1 Heiltrank")
|
||||
u:add_order("BENUTZEN 1 Heiltrank")
|
||||
turn_process()
|
||||
assert_equal(1200, u.hp)
|
||||
assert_equal(0, u:get_item("p14"))
|
||||
turn_end()
|
||||
end
|
||||
|
||||
function test_speedsail()
|
||||
local r = region.create(0, 0, "plain")
|
||||
local f = faction.create("human")
|
||||
|
|
|
@ -129,37 +129,6 @@ void herbsearch(unit * u, int max_take)
|
|||
}
|
||||
}
|
||||
|
||||
static int begin_potion(unit * u, const item_type * itype, struct order *ord)
|
||||
{
|
||||
static int config;
|
||||
static bool rule_multipotion;
|
||||
|
||||
assert(itype);
|
||||
if (config_changed(&config)) {
|
||||
/* should we allow multiple different potions to be used the same turn? */
|
||||
rule_multipotion = config_get_int("rules.magic.multipotion", 0) != 0;
|
||||
}
|
||||
|
||||
if (!rule_multipotion) {
|
||||
const item_type *use = ugetpotionuse(u);
|
||||
if (use != NULL && use != itype) {
|
||||
ADDMSG(&u->faction->msgs,
|
||||
msg_message("errusingpotion", "unit using command",
|
||||
u, use->rtype, ord));
|
||||
return ECUSTOM;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void end_potion(unit * u, const item_type * itype, int amount)
|
||||
{
|
||||
usetpotionuse(u, itype);
|
||||
|
||||
ADDMSG(&u->faction->msgs, msg_message("usepotion",
|
||||
"unit potion", u, itype->rtype));
|
||||
}
|
||||
|
||||
void show_potions(faction *f, int sklevel)
|
||||
{
|
||||
const potion_type *ptype;
|
||||
|
@ -229,8 +198,10 @@ static int potion_healing(struct unit *user, int amount)
|
|||
}
|
||||
|
||||
|
||||
static int do_potion(unit * u, region *r, const item_type * itype, int amount)
|
||||
int use_potion(unit * u, const item_type * itype, int amount, struct order *ord)
|
||||
{
|
||||
region *r = u->region;
|
||||
|
||||
/* TODO: this function should only be used for effect-changing potions */
|
||||
if (itype == oldpotiontype[P_PEOPLE]) {
|
||||
return potion_luck(u, r, &at_peasantluck, amount);
|
||||
|
@ -253,16 +224,6 @@ static int do_potion(unit * u, region *r, const item_type * itype, int amount)
|
|||
return amount;
|
||||
}
|
||||
|
||||
int use_potion(unit * u, const item_type * itype, int amount, struct order *ord)
|
||||
{
|
||||
int result = begin_potion(u, itype, ord);
|
||||
if (result)
|
||||
return result;
|
||||
amount = do_potion(u, u->region, itype, amount);
|
||||
end_potion(u, itype, amount);
|
||||
return amount;
|
||||
}
|
||||
|
||||
/*****************/
|
||||
/* at_effect */
|
||||
/*****************/
|
||||
|
|
|
@ -303,7 +303,6 @@ struct order *ord)
|
|||
}
|
||||
use_pooled(u, itype->rtype, GET_SLACK | GET_RESERVE | GET_POOLED_SLACK,
|
||||
amount);
|
||||
usetpotionuse(u, itype);
|
||||
|
||||
ADDMSG(&u->faction->msgs, msg_message("usepotion",
|
||||
"unit potion", u, itype->rtype));
|
||||
|
@ -369,7 +368,6 @@ static int use_warmthpotion(unit *u, const item_type *itype,
|
|||
return ECUSTOM;
|
||||
}
|
||||
use_pooled(u, itype->rtype, GET_DEFAULT, amount);
|
||||
usetpotionuse(u, itype);
|
||||
|
||||
ADDMSG(&u->faction->msgs, msg_message("usepotion",
|
||||
"unit potion", u, itype->rtype));
|
||||
|
|
|
@ -573,35 +573,6 @@ void usetprivate(unit * u, const char *str)
|
|||
a->data.v = str_strdup(str);
|
||||
}
|
||||
|
||||
/*********************/
|
||||
/* at_potionuser */
|
||||
/*********************/
|
||||
/* Einheit BENUTZT einen Trank */
|
||||
attrib_type at_potionuser = {
|
||||
"potionuser",
|
||||
DEFAULT_INIT,
|
||||
DEFAULT_FINALIZE,
|
||||
DEFAULT_AGE,
|
||||
NO_WRITE,
|
||||
NO_READ
|
||||
};
|
||||
|
||||
void usetpotionuse(unit * u, const item_type * ptype)
|
||||
{
|
||||
attrib *a = a_find(u->attribs, &at_potionuser);
|
||||
if (!a)
|
||||
a = a_add(&u->attribs, a_new(&at_potionuser));
|
||||
a->data.v = (void *)ptype;
|
||||
}
|
||||
|
||||
const item_type *ugetpotionuse(const unit * u)
|
||||
{
|
||||
attrib *a = a_find(u->attribs, &at_potionuser);
|
||||
if (!a)
|
||||
return NULL;
|
||||
return (const item_type *)a->data.v;
|
||||
}
|
||||
|
||||
/*********************/
|
||||
/* at_target */
|
||||
/*********************/
|
||||
|
|
|
@ -150,9 +150,6 @@ extern "C" {
|
|||
const char *uprivate(const struct unit *u);
|
||||
void usetprivate(struct unit *u, const char *c);
|
||||
|
||||
const struct item_type *ugetpotionuse(const struct unit *u); /* benutzt u einein trank? */
|
||||
void usetpotionuse(struct unit *u, const struct item_type *p); /* u benutzt trank p (es darf halt nur einer pro runde) */
|
||||
|
||||
bool ucontact(const struct unit *u, const struct unit *u2);
|
||||
void usetcontact(struct unit *u, const struct unit *c);
|
||||
|
||||
|
|
Loading…
Reference in a new issue