From 438ae6f905b1a63246c78e6edc8c5bd9f68ba1ba Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 17 Feb 2018 15:17:05 +0100 Subject: [PATCH] Eliminate rules.magic.multipotion, it's too much code. --- conf/e3/config.json | 1 - scripts/tests/e2/items.lua | 35 +++++++++++++++++++++++++++++ src/alchemy.c | 45 +++----------------------------------- src/items.c | 2 -- src/kernel/unit.c | 29 ------------------------ src/kernel/unit.h | 3 --- 6 files changed, 38 insertions(+), 77 deletions(-) diff --git a/conf/e3/config.json b/conf/e3/config.json index 528d0a7f2..b5f9aed5c 100644 --- a/conf/e3/config.json +++ b/conf/e3/config.json @@ -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, diff --git a/scripts/tests/e2/items.lua b/scripts/tests/e2/items.lua index c66d08bfa..85ec40e19 100644 --- a/scripts/tests/e2/items.lua +++ b/scripts/tests/e2/items.lua @@ -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") diff --git a/src/alchemy.c b/src/alchemy.c index c6c550774..ec5c3dc7a 100644 --- a/src/alchemy.c +++ b/src/alchemy.c @@ -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 */ /*****************/ diff --git a/src/items.c b/src/items.c index 5132b31cb..18c2d7b0f 100644 --- a/src/items.c +++ b/src/items.c @@ -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)); diff --git a/src/kernel/unit.c b/src/kernel/unit.c index 356e73354..9af46b28c 100644 --- a/src/kernel/unit.c +++ b/src/kernel/unit.c @@ -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 */ /*********************/ diff --git a/src/kernel/unit.h b/src/kernel/unit.h index e7bf6a9e4..4d1cc4362 100644 --- a/src/kernel/unit.h +++ b/src/kernel/unit.h @@ -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);