From bf86c4e043f7890115f140065be5c09751b74105 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Wed, 27 Dec 2017 22:26:50 +0100 Subject: [PATCH] backfill missing manacrystal test. --- src/items/xerewards.c | 5 +++-- src/items/xerewards.test.c | 24 +++++++++++++++++++++++- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/items/xerewards.c b/src/items/xerewards.c index 1f2e09c4e..71746bbf3 100644 --- a/src/items/xerewards.c +++ b/src/items/xerewards.c @@ -67,15 +67,16 @@ int use_manacrystal(struct unit *u, const struct item_type *itype, int amount, struct order *ord) { - int i, sp = 0; + int i, sp = 0, msp; if (!is_mage(u)) { cmistake(u, u->thisorder, 295, MSG_EVENT); return -1; } + msp = max_spellpoints(u->region, u) / 2; for (i = 0; i != amount; ++i) { - sp += MAX(25, max_spellpoints(u->region, u) / 2); + sp += MAX(25, msp); change_spellpoints(u, sp); } diff --git a/src/items/xerewards.test.c b/src/items/xerewards.test.c index ad9876997..a027a8838 100644 --- a/src/items/xerewards.test.c +++ b/src/items/xerewards.test.c @@ -2,17 +2,39 @@ #include "xerewards.h" #include "study.h" +#include "magic.h" -#include +#include #include #include #include +#include #include #include static void test_manacrystal(CuTest *tc) { + struct item_type *itype; + unit *u; test_setup(); + + u = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL)); + itype = test_create_itemtype("manacrystal"); + change_resource(u, itype->rtype, 1); + CuAssertIntEquals(tc, -1, use_manacrystal(u, itype, 1, NULL)); + CuAssertPtrNotNull(tc, test_find_messagetype(u->faction->msgs, "error295")); + test_clear_messages(u->faction); + create_mage(u, M_GRAY); + set_level(u, SK_MAGIC, 5); + CuAssertIntEquals(tc, 0, get_spellpoints(u)); + CuAssertIntEquals(tc, 1, use_manacrystal(u, itype, 1, NULL)); + CuAssertIntEquals(tc, 25, get_spellpoints(u)); + CuAssertPtrNotNull(tc, test_find_messagetype(u->faction->msgs, "manacrystal_use")); + test_clear_messages(u->faction); + set_level(u, SK_MAGIC, 8); + CuAssertIntEquals(tc, 1, use_manacrystal(u, itype, 1, NULL)); + CuAssertPtrNotNull(tc, test_find_messagetype(u->faction->msgs, "manacrystal_use")); + CuAssertIntEquals(tc, 25 + 33, get_spellpoints(u)); test_teardown(); }