From ef7d0c40ed1d7f59ca4713bff9c1a582db868d04 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 17 Feb 2018 18:51:11 +0100 Subject: [PATCH] remove the two helaing special cases from use_potion --- src/alchemy.c | 38 ------------------------------------ src/items.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++-- src/laws.test.c | 2 +- 3 files changed, 50 insertions(+), 41 deletions(-) diff --git a/src/alchemy.c b/src/alchemy.c index 2973c3748..b51437967 100644 --- a/src/alchemy.c +++ b/src/alchemy.c @@ -166,38 +166,6 @@ static int potion_power(unit *u, int amount) { return amount; } -static int heal(unit * user, int effect) -{ - int req = unit_max_hp(user) * user->number - user->hp; - if (req > 0) { - if (req > effect) req = effect; - effect -= req; - user->hp += req; - } - return effect; -} - -static int potion_ointment(unit * u, int amount) { - int effect = amount * 400; - effect = heal(u, effect); - return amount; -} - -static int potion_healing(struct unit *user, int amount) -{ - int effect = amount * 400; - unit *u = user->region->units; - effect = heal(user, effect); - while (effect > 0 && u != NULL) { - if (u->faction == user->faction) { - effect = heal(u, effect); - } - u = u->next; - } - return amount; -} - - int use_potion(unit * u, const item_type * itype, int amount, struct order *ord) { region *r = u->region; @@ -208,12 +176,6 @@ int use_potion(unit * u, const item_type * itype, int amount, struct order *ord) else if (itype == oldpotiontype[P_HORSE]) { amount = potion_luck(u, r, &at_horseluck, amount); } - else if (itype == oldpotiontype[P_HEAL]) { - amount = potion_healing(u, amount); - } - else if (itype == oldpotiontype[P_OINTMENT]) { - amount = potion_ointment(u, amount); - } else if (itype == oldpotiontype[P_MACHT]) { amount = potion_power(u, amount); } diff --git a/src/items.c b/src/items.c index 9376fe1c5..6f1981a08 100644 --- a/src/items.c +++ b/src/items.c @@ -411,6 +411,53 @@ static int use_water_of_life(unit *u, const item_type *itype, return potion_water_of_life(u, u->region, amount); } +static int heal(unit * user, int effect) +{ + int req = unit_max_hp(user) * user->number - user->hp; + if (req > 0) { + if (req > effect) req = effect; + effect -= req; + user->hp += req; + } + return effect; +} + +static int potion_healing(struct unit *user, int amount) +{ + int effect = amount * 400; + unit *u = user->region->units; + effect = heal(u, effect); + while (effect > 0 && u != NULL) { + if (u->faction == user->faction) { + effect = heal(u, effect); + } + u = u->next; + } + return amount; +} + +static int use_healing_potion(unit *u, const item_type *itype, + int amount, struct order *ord) +{ + ADDMSG(&u->faction->msgs, msg_message("use_item", + "unit amount item", u, amount, itype->rtype)); + return potion_healing(u, amount); +} + +static int potion_ointment(unit * u, int amount) { + int effect = amount * 400; + effect = heal(u, effect); + return amount; +} + +static int use_ointment(unit *u, const item_type *itype, + int amount, struct order *ord) +{ + ADDMSG(&u->faction->msgs, msg_message("use_item", + "unit amount item", u, amount, itype->rtype)); + return potion_ointment(u, amount); +} + void register_itemfunctions(void) { /* have tests: */ @@ -425,7 +472,7 @@ void register_itemfunctions(void) register_item_use(use_birthdayamulet, "use_aoc"); register_item_use(use_foolpotion, "use_p7"); register_item_use(use_bloodpotion, "use_peasantblood"); - register_item_use(use_potion, "use_ointment"); - register_item_use(use_potion, "use_p14"); + register_item_use(use_ointment, "use_ointment"); + register_item_use(use_healing_potion, "use_p14"); register_item_use(use_warmthpotion, "use_nestwarmth"); } diff --git a/src/laws.test.c b/src/laws.test.c index 888614a1a..4d641cc52 100644 --- a/src/laws.test.c +++ b/src/laws.test.c @@ -883,7 +883,7 @@ static void test_luck_message(CuTest *tc) { demographics(); - CuAssertPtrEquals_Msg(tc, "unexpected message", (void *)NULL, r->msgs); + CuAssertPtrEquals_Msg(tc, "unexpected message", NULL, r->msgs); a = (attrib *)a_find(r->attribs, &at_peasantluck); if (!a)