From 9938b3fb66d59d854ac69dce6325c840c85ab65d Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 2 Aug 2015 23:15:13 +0200 Subject: [PATCH] eliminate update_gbdream completely, make code smaller and simpler. simplify tests (no need to use create_spell if we don't use it) increase build no for hotfix. --- src/buildno.h | 2 +- src/kernel/unit.c | 29 +++++++++-------------------- src/spells.test.c | 15 ++++++--------- 3 files changed, 16 insertions(+), 30 deletions(-) diff --git a/src/buildno.h b/src/buildno.h index 813baf03b..a8118b327 100644 --- a/src/buildno.h +++ b/src/buildno.h @@ -1,3 +1,3 @@ #define VERSION_MAJOR 3 #define VERSION_MINOR 5 -#define VERSION_BUILD 3 +#define VERSION_BUILD 4 diff --git a/src/kernel/unit.c b/src/kernel/unit.c index c5c60d08d..3a07344af 100644 --- a/src/kernel/unit.c +++ b/src/kernel/unit.c @@ -1274,22 +1274,7 @@ static int item_modification(const unit * u, skill_t sk, int val) return val; } -static int update_gbdream(const unit * u, int bonus, curse *c, int sign) { - double effect = curse_geteffect(c); - unit *mage = c->magician; - /* wir suchen jeweils den groessten Bonus und den groessten Malus */ - if (sign * effect > sign * bonus) { - bool allied; - assert(mage && mage->number > 0); - allied = alliedunit(mage, u->faction, HELP_GUARD); - if ((sign>0)?allied:!allied) { - bonus = (int)effect; - } - } - return bonus; -} - -int att_modification(const unit * u, skill_t sk) +static int att_modification(const unit * u, skill_t sk) { double result = 0; static bool init = false; // TODO: static variables are bad global state @@ -1321,16 +1306,20 @@ int att_modification(const unit * u, skill_t sk) /* TODO hier kann nicht mit get/iscursed gearbeitet werden, da nur der * jeweils erste vom Typ C_GBDREAM zurueckgegen wird, wir aber alle * durchsuchen und aufaddieren muessen */ - if (u->region) { + if (gbdream_ct && u->region) { int bonus = 0, malus = 0; attrib *a = a_find(u->region->attribs, &at_curse); while (a && a->type == &at_curse) { curse *c = (curse *)a->data.v; if (curse_active(c) && c->type == gbdream_ct) { - assert(c->magician); // update_gbdream makes no sense if there is no caster (calls alliedunit) - bonus = update_gbdream(u, bonus, c, 1); - malus = update_gbdream(u, malus, c, -1); + int effect = curse_geteffect_int(c); + bool allied = alliedunit(c->magician, u->faction, HELP_GUARD); + if (allied) { + if (effect > bonus) bonus = effect; + } else { + if (effect < malus) malus = effect; + } } a = a->next; } diff --git a/src/spells.test.c b/src/spells.test.c index ff67dd58d..5ecb8bd88 100644 --- a/src/spells.test.c +++ b/src/spells.test.c @@ -20,13 +20,10 @@ #include -static struct castorder *test_create_castorder(castorder *order, unit *u, const char *name, int level, float force, int range) { +static void test_create_castorder(castorder *order, unit *u, int level, float force, int range) { struct locale * lang; - spell *sp; - lang = get_or_create_locale("en"); - sp = create_spell(name, 0); - return order = create_castorder(order, u, NULL, sp, u->region, level, force, range, create_order(K_CAST, lang, ""), NULL); + create_castorder(order, u, NULL, NULL, u->region, level, force, range, create_order(K_CAST, lang, ""), NULL); } static void test_dreams(CuTest *tc) { @@ -39,12 +36,12 @@ static void test_dreams(CuTest *tc) { test_cleanup(); test_create_world(); r=findregion(0, 0); - f1 = test_create_faction(test_create_race("human")); - f2 = test_create_faction(test_create_race("human")); + f1 = test_create_faction(0); + f2 = test_create_faction(0); u1 = test_create_unit(f1, r); u2 = test_create_unit(f2, r); - test_create_castorder(&order, u1, "goodreams", 10, 10., 0); + test_create_castorder(&order, u1, 10, 10., 0); level = sp_gooddreams(&order); CuAssertIntEquals(tc, 10, level); @@ -57,7 +54,7 @@ static void test_dreams(CuTest *tc) { CuAssertIntEquals(tc, 1, get_modifier(u1, SK_MELEE, 11, r, false)); CuAssertIntEquals(tc, 0, get_modifier(u2, SK_MELEE, 11, r, false)); - test_create_castorder(&order, u1, "baddreams", 10, 10., 0); + test_create_castorder(&order, u1, 10, 10., 0); level = sp_baddreams(&order); CuAssertIntEquals(tc, 10, level);