From ea8721367a8fb8e213900752e28e4187b9f7639c Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 9 Nov 2015 19:43:51 +0100 Subject: [PATCH] test and fix shock trigger. https://bugs.eressea.de/view.php?id=2154 --- src/CMakeLists.txt | 1 + src/kernel/unit.test.c | 4 ++-- src/magic.c | 5 +++++ src/test_eressea.c | 1 + src/tests.c | 4 +++- src/triggers/shock.c | 13 +++++++++---- 6 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 037898ed9..ada49aad9 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -210,6 +210,7 @@ set(TESTS_SRC upkeep.test.c spells/flyingship.test.c spells/magicresistance.test.c + triggers/shock.test.c ${ATTRIBUTES_TESTS} ${UTIL_TESTS} ${KERNEL_TESTS} diff --git a/src/kernel/unit.test.c b/src/kernel/unit.test.c index 0fd58a55a..db2751026 100644 --- a/src/kernel/unit.test.c +++ b/src/kernel/unit.test.c @@ -123,11 +123,11 @@ static void test_scale_number(CuTest *tc) { u = test_create_unit(test_create_faction(test_create_race("human")), findregion(0, 0)); change_effect(u, ptype, 1); CuAssertIntEquals(tc, 1, u->number); - CuAssertIntEquals(tc, 1, u->hp); + CuAssertIntEquals(tc, 20, u->hp); CuAssertIntEquals(tc, 1, get_effect(u, ptype)); scale_number(u, 2); CuAssertIntEquals(tc, 2, u->number); - CuAssertIntEquals(tc, 2, u->hp); + CuAssertIntEquals(tc, 40, u->hp); CuAssertIntEquals(tc, 2, get_effect(u, ptype)); set_level(u, SK_ALCHEMY, 1); scale_number(u, 0); diff --git a/src/magic.c b/src/magic.c index 20fd47ccd..ce69df78f 100644 --- a/src/magic.c +++ b/src/magic.c @@ -995,6 +995,11 @@ cancast(unit * u, const spell * sp, int level, int range, struct order * ord) if (reslist != NULL) { ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "missing_components_list", "list", reslist)); + while (reslist) { + resource *res = reslist->next; + free(reslist); + reslist = res; + } return false; } return true; diff --git a/src/test_eressea.c b/src/test_eressea.c index c04764992..8f5c1faa0 100644 --- a/src/test_eressea.c +++ b/src/test_eressea.c @@ -127,6 +127,7 @@ int RunAllTests(int argc, char *argv[]) ADD_SUITE(wormhole); ADD_SUITE(spy); ADD_SUITE(study); + ADD_SUITE(shock); if (suites) { CuSuite *summary = CuSuiteNew(); diff --git a/src/tests.c b/src/tests.c index 8cf97bede..e7518211e 100644 --- a/src/tests.c +++ b/src/tests.c @@ -35,6 +35,8 @@ struct race *test_create_race(const char *name) { race *rc = rc_get_or_create(name); rc->maintenance = 10; + rc->hitpoints = 20; + rc->maxaura = 1.0; rc->ec_flags |= GETITEM; return rc; } @@ -59,7 +61,7 @@ struct region *test_create_region(int x, int y, const terrain_type *terrain) struct faction *test_create_faction(const struct race *rc) { - faction *f = addfaction("nobody@eressea.de", NULL, rc ? rc : rc_get_or_create("human"), default_locale, 0); + faction *f = addfaction("nobody@eressea.de", NULL, rc ? rc : test_create_race("human"), default_locale, 0); return f; } diff --git a/src/triggers/shock.c b/src/triggers/shock.c index fd52c49b5..95e7b61b6 100644 --- a/src/triggers/shock.c +++ b/src/triggers/shock.c @@ -59,13 +59,18 @@ static void do_shock(unit * u, const char *reason) if (u->number > 0) { /* HP - Verlust */ - u->hp = (unit_max_hp(u) * u->number) / 10; - u->hp = _max(1, u->hp); + int hp = (unit_max_hp(u) * u->number) / 10; + hp = _min(u->hp, hp); + u->hp = _max(1, hp); } /* Aura - Verlust */ if (is_mage(u)) { - set_spellpoints(u, max_spellpoints(u->region, u) / 10); + int aura = max_spellpoints(u->region, u) / 10; + int now = get_spellpoints(u); + if (now > aura) { + set_spellpoints(u, aura); + } } /* Evt. Talenttageverlust */ @@ -86,7 +91,7 @@ static void do_shock(unit * u, const char *reason) } if (u->faction != NULL) { ADDMSG(&u->faction->msgs, msg_message("shock", - "mage reason", u, _strdup(reason))); + "mage reason", u, reason)); } }