From bf591ecec5cecd5c5350fad13670dd3d27728eb5 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Thu, 15 Feb 2018 20:25:58 +0100 Subject: [PATCH] BUG 2415: eliminate at_potiondelay and WdL delay. BUG 2419: refactor ointment and healing, add tests for USE --- scripts/tests/e2/items.lua | 59 ++++++++++++++++++++++++++++----- scripts/tests/e3/production.lua | 1 - src/alchemy.c | 58 ++------------------------------ src/alchemy.h | 4 +-- src/battle.h | 1 + src/creport.h | 1 + src/items.c | 16 ++++----- src/kernel/building.h | 1 + src/kernel/region.test.c | 2 +- src/kernel/save.c | 2 +- src/kernel/types.h | 8 ++--- src/magic.h | 1 + src/volcano.h | 3 ++ 13 files changed, 74 insertions(+), 83 deletions(-) diff --git a/scripts/tests/e2/items.lua b/scripts/tests/e2/items.lua index 2f2b13e88..fe3bca370 100644 --- a/scripts/tests/e2/items.lua +++ b/scripts/tests/e2/items.lua @@ -28,7 +28,7 @@ end function test_nestwarmth_insect() local r = region.create(0, 0, "plain") - local f = faction.create("insect", "noreply@eressea.de", "de") + local f = faction.create("insect") local u = unit.create(f, r, 1) local flags = u.flags u:add_item("nestwarmth", 2) @@ -44,7 +44,7 @@ end function test_nestwarmth_other() local r = region.create(0, 0, "plain") - local f = faction.create("human", "noreply@eressea.de", "de") + local f = faction.create("human") local u = unit.create(f, r, 1) local flags = u.flags u:add_item("nestwarmth", 2) @@ -60,7 +60,7 @@ end function test_meow() local r = region.create(0, 0, "plain") - local f = faction.create("human", "noreply@eressea.de", "de") + local f = faction.create("human") local u = unit.create(f, r, 1) u:add_item("aoc", 1) u:clear_orders() @@ -74,7 +74,7 @@ end function test_aurapotion50() local r = region.create(0, 0, "plain") - local f = faction.create("human", "noreply@eressea.de", "de") + local f = faction.create("human") local u = unit.create(f, r, 1) u:add_item("aurapotion50", 1) u:set_skill('magic', 10); @@ -92,7 +92,7 @@ end function test_bagpipe() local r = region.create(0, 0, "plain") - local f = faction.create("human", "noreply@eressea.de", "de") + local f = faction.create("human") local u = unit.create(f, r, 1) turn_begin() u:add_item("bagpipeoffear", 1) @@ -109,9 +109,52 @@ function test_bagpipe() assert_equal(0, r:get_curse('depression')) end +function test_monthly_healing() + local r = region.create(0, 0, "plain") + local f = faction.create("human") + local u = unit.create(f, r, 30) + assert_equal(600, u.hp) + u.hp = 100 + process_orders() + assert_equal(130, u.hp) +end + +function test_ointment() + local r = region.create(0, 0, "plain") + local f = faction.create("human") + local u = unit.create(f, r, 30) + assert_equal(600, u.hp) + u.hp = 100 + turn_begin() + u:add_item("ointment", 1) + u:clear_orders() + u:add_order("BENUTZEN 1 Wundsalbe") + turn_process() + assert_equal(530, u.hp) + assert_equal(0, u:get_item("ointment")) + turn_end() +end + +function test_use_healing_potion() + -- Heiltrank kann (auch) mit BENUTZE eingesetzt werden + local r = region.create(0, 0, "plain") + local f = faction.create("human") + local u = unit.create(f, r, 30) + assert_equal(600, u.hp) + u.hp = 100 + turn_begin() + u:add_item("p14", 1) + u:clear_orders() + u:add_order("BENUTZEN 1 Heiltrank") + turn_process() + assert_equal(530, 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", "noreply@eressea.de", "de") + local f = faction.create("human") local u = unit.create(f, r, 1) turn_begin() @@ -130,7 +173,7 @@ end function disable_test_foolpotion() local r = region.create(0, 0, "plain") - local f = faction.create("human", "noreply@eressea.de", "de") + local f = faction.create("human") local u = unit.create(f, r, 1) turn_begin() u:add_item('p7', 2) @@ -159,7 +202,7 @@ end function test_snowman() local r = region.create(0, 0, "glacier") - local f = faction.create("human", "noreply@eressea.de", "de") + local f = faction.create("human") local u = unit.create(f, r, 1) u:add_item("snowman", 1) u:clear_orders() diff --git a/scripts/tests/e3/production.lua b/scripts/tests/e3/production.lua index be63158cf..3469b06c4 100644 --- a/scripts/tests/e3/production.lua +++ b/scripts/tests/e3/production.lua @@ -53,7 +53,6 @@ function test_dwarf_no_mining_bonus() local r = region.create(0, 0, 'mountain') local f = create_faction('dwarf') local u = unit.create(f, r, 1) - u.name = 'Xolgrim' turn_begin() r:set_resource('iron', 100) diff --git a/src/alchemy.c b/src/alchemy.c index 3ec21159d..b766278c6 100644 --- a/src/alchemy.c +++ b/src/alchemy.c @@ -211,7 +211,7 @@ void show_potions(faction *f, int sklevel) } } -static int potion_healing(unit * u, int amount) { +static int potion_ointment(unit * u, int amount) { int maxhp = unit_max_hp(u) * u->number; u->hp = u->hp + 400 * amount; if (u->hp > maxhp) u->hp = maxhp; @@ -244,8 +244,8 @@ static int do_potion(unit * u, region *r, const item_type * itype, int amount) if (itype == oldpotiontype[P_LIFE]) { return potion_water_of_life(u, r, amount); } - else if (itype == oldpotiontype[P_HEILWASSER]) { - return potion_healing(u, amount); + else if (itype == oldpotiontype[P_OINTMENT]) { + return potion_ointment(u, amount); } else if (itype == oldpotiontype[P_PEOPLE]) { return potion_luck(u, r, &at_peasantluck, amount); @@ -277,58 +277,6 @@ int use_potion(unit * u, const item_type * itype, int amount, struct order *ord) return 0; } -typedef struct potiondelay { - unit *u; - region *r; - const item_type *itype; - int amount; -} potiondelay; - -static void init_potiondelay(variant *var) -{ - var->v = malloc(sizeof(potiondelay)); -} - -static int age_potiondelay(attrib * a, void *owner) -{ - potiondelay *pd = (potiondelay *)a->data.v; - UNUSED_ARG(owner); - pd->amount = do_potion(pd->u, pd->r, pd->itype, pd->amount); - return AT_AGE_REMOVE; -} - -attrib_type at_potiondelay = { - "potiondelay", - init_potiondelay, - a_free_voidptr, - age_potiondelay, 0, 0 -}; - -static attrib *make_potiondelay(unit * u, const item_type * itype, int amount) -{ - attrib *a = a_new(&at_potiondelay); - potiondelay *pd = (potiondelay *)a->data.v; - pd->u = u; - pd->r = u->region; - pd->itype = itype; - pd->amount = amount; - return a; -} - -int -use_potion_delayed(unit * u, const item_type * itype, int amount, -struct order *ord) -{ - int result = begin_potion(u, itype, ord); - if (result) - return result; - - a_add(&u->attribs, make_potiondelay(u, itype, amount)); - - end_potion(u, itype, amount); - return 0; -} - /*****************/ /* at_effect */ /*****************/ diff --git a/src/alchemy.h b/src/alchemy.h index d183cacd0..3ce6b9547 100644 --- a/src/alchemy.h +++ b/src/alchemy.h @@ -41,7 +41,7 @@ extern "C" { P_LIFE, /* Stufe 2 */ P_DOMORE, - P_HEILWASSER, + P_OINTMENT, P_BAUERNBLUT, /* Stufe 3 */ P_WISE, /* 6 */ @@ -64,8 +64,6 @@ extern "C" { void herbsearch(struct unit *u, int max); int use_potion(struct unit *u, const struct item_type *itype, int amount, struct order *); - int use_potion_delayed(struct unit *u, const struct item_type *itype, - int amount, struct order *); int get_effect(const struct unit *u, const struct item_type *effect); int change_effect(struct unit *u, const struct item_type *effect, diff --git a/src/battle.h b/src/battle.h index 6494a6e27..fd31a0284 100644 --- a/src/battle.h +++ b/src/battle.h @@ -28,6 +28,7 @@ extern "C" { struct message; struct selist; + union variant; /** more defines **/ #define FS_ENEMY 1 diff --git a/src/creport.h b/src/creport.h index ed8f3bfbd..f4e0cd4bd 100644 --- a/src/creport.h +++ b/src/creport.h @@ -13,6 +13,7 @@ #define H_GC_CREPORT #include +#include #ifdef __cplusplus extern "C" { diff --git a/src/items.c b/src/items.c index ba9f35388..f1940a644 100644 --- a/src/items.c +++ b/src/items.c @@ -16,6 +16,7 @@ #include #include +#include #include #include #include @@ -321,8 +322,8 @@ static int heal(unit * user, int effect) } static int -use_healingpotion(struct unit *user, const struct item_type *itype, int amount, -struct order *ord) +use_healingpotion(struct unit *user, const struct item_type *itype, + int amount, struct order *ord) { int effect = amount * 400; unit *u = user->region->units; @@ -400,8 +401,7 @@ static int use_warmthpotion(unit *u, const item_type *itype, cmistake(u, ord, 163, MSG_EVENT); return ECUSTOM; } - use_pooled(u, itype->rtype, GET_SLACK | GET_RESERVE | GET_POOLED_SLACK, - amount); + use_pooled(u, itype->rtype, GET_DEFAULT, amount); usetpotionuse(u, itype); ADDMSG(&u->faction->msgs, msg_message("usepotion", @@ -422,9 +422,9 @@ 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_healingpotion, "use_ointment"); + register_item_use(use_potion, "use_ointment"); + register_item_use(use_healingpotion, "use_p14"); register_item_use(use_warmthpotion, "use_nestwarmth"); - - /* ungetestet: Wasser des Lebens */ - register_item_use(use_potion_delayed, "use_p2"); + /* p2 = P_LIFE = Wasser des Lebens */ + register_item_use(use_potion, "use_p2"); } diff --git a/src/kernel/building.h b/src/kernel/building.h index e162e041f..5a83fd0ca 100644 --- a/src/kernel/building.h +++ b/src/kernel/building.h @@ -21,6 +21,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include +#include #include #include diff --git a/src/kernel/region.test.c b/src/kernel/region.test.c index 4baa807c8..d54049b8e 100644 --- a/src/kernel/region.test.c +++ b/src/kernel/region.test.c @@ -16,7 +16,7 @@ void test_terraform(CuTest *tc) { item_type *itype; test_setup(); - itype = test_create_itemtype("ointment"); + itype = test_create_itemtype("oil"); itype->rtype->flags |= (RTF_ITEM | RTF_POOLED); new_luxurytype(itype, 0); diff --git a/src/kernel/save.c b/src/kernel/save.c index 1d415038d..4408ab909 100644 --- a/src/kernel/save.c +++ b/src/kernel/save.c @@ -496,7 +496,7 @@ unit *read_unit(gamedata *data) } READ_INT(data->store, &n); - unit_setstatus(u, n); + unit_setstatus(u, (status_t)n); READ_INT(data->store, &u->flags); u->flags &= UFL_SAVEMASK; if ((u->flags & UFL_ANON_FACTION) && !rule_stealth_anon()) { diff --git a/src/kernel/types.h b/src/kernel/types.h index 9e9ed3b66..61f1268cc 100644 --- a/src/kernel/types.h +++ b/src/kernel/types.h @@ -20,9 +20,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #define ERESSEA_TYPES_H #include -#include - -typedef short item_t; struct attrib; struct attrib_type; @@ -77,15 +74,14 @@ typedef enum { /* ------------------ Status von Einheiten --------------------- */ -typedef unsigned char status_t; -enum { +typedef enum { ST_AGGRO, ST_FIGHT, ST_BEHIND, ST_CHICKEN, ST_AVOID, ST_FLEE -}; +} status_t; /* ----------------- Parameter --------------------------------- */ diff --git a/src/magic.h b/src/magic.h index cbd508163..98d2dabe8 100644 --- a/src/magic.h +++ b/src/magic.h @@ -20,6 +20,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #define H_KRNL_MAGIC #include +#include #include #ifdef __cplusplus diff --git a/src/volcano.h b/src/volcano.h index 225a76143..c72801cce 100644 --- a/src/volcano.h +++ b/src/volcano.h @@ -19,6 +19,9 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #ifndef H_GC_VOLCANO #define H_GC_VOLCANO + +#include + #ifdef __cplusplus extern "C" { #endif