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.
This commit is contained in:
Enno Rehling 2015-08-02 23:15:13 +02:00
parent d99ffaf1ed
commit 9938b3fb66
3 changed files with 16 additions and 30 deletions

View File

@ -1,3 +1,3 @@
#define VERSION_MAJOR 3 #define VERSION_MAJOR 3
#define VERSION_MINOR 5 #define VERSION_MINOR 5
#define VERSION_BUILD 3 #define VERSION_BUILD 4

View File

@ -1274,22 +1274,7 @@ static int item_modification(const unit * u, skill_t sk, int val)
return val; return val;
} }
static int update_gbdream(const unit * u, int bonus, curse *c, int sign) { static int att_modification(const unit * u, skill_t sk)
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)
{ {
double result = 0; double result = 0;
static bool init = false; // TODO: static variables are bad global state 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 /* TODO hier kann nicht mit get/iscursed gearbeitet werden, da nur der
* jeweils erste vom Typ C_GBDREAM zurueckgegen wird, wir aber alle * jeweils erste vom Typ C_GBDREAM zurueckgegen wird, wir aber alle
* durchsuchen und aufaddieren muessen */ * durchsuchen und aufaddieren muessen */
if (u->region) { if (gbdream_ct && u->region) {
int bonus = 0, malus = 0; int bonus = 0, malus = 0;
attrib *a = a_find(u->region->attribs, &at_curse); attrib *a = a_find(u->region->attribs, &at_curse);
while (a && a->type == &at_curse) { while (a && a->type == &at_curse) {
curse *c = (curse *)a->data.v; curse *c = (curse *)a->data.v;
if (curse_active(c) && c->type == gbdream_ct) { if (curse_active(c) && c->type == gbdream_ct) {
assert(c->magician); // update_gbdream makes no sense if there is no caster (calls alliedunit) int effect = curse_geteffect_int(c);
bonus = update_gbdream(u, bonus, c, 1); bool allied = alliedunit(c->magician, u->faction, HELP_GUARD);
malus = update_gbdream(u, malus, c, -1); if (allied) {
if (effect > bonus) bonus = effect;
} else {
if (effect < malus) malus = effect;
}
} }
a = a->next; a = a->next;
} }

View File

@ -20,13 +20,10 @@
#include <assert.h> #include <assert.h>
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; struct locale * lang;
spell *sp;
lang = get_or_create_locale("en"); lang = get_or_create_locale("en");
sp = create_spell(name, 0); create_castorder(order, u, NULL, NULL, u->region, level, force, range, create_order(K_CAST, lang, ""), NULL);
return order = create_castorder(order, u, NULL, sp, u->region, level, force, range, create_order(K_CAST, lang, ""), NULL);
} }
static void test_dreams(CuTest *tc) { static void test_dreams(CuTest *tc) {
@ -39,12 +36,12 @@ static void test_dreams(CuTest *tc) {
test_cleanup(); test_cleanup();
test_create_world(); test_create_world();
r=findregion(0, 0); r=findregion(0, 0);
f1 = test_create_faction(test_create_race("human")); f1 = test_create_faction(0);
f2 = test_create_faction(test_create_race("human")); f2 = test_create_faction(0);
u1 = test_create_unit(f1, r); u1 = test_create_unit(f1, r);
u2 = test_create_unit(f2, 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); level = sp_gooddreams(&order);
CuAssertIntEquals(tc, 10, level); 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, 1, get_modifier(u1, SK_MELEE, 11, r, false));
CuAssertIntEquals(tc, 0, get_modifier(u2, 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); level = sp_baddreams(&order);
CuAssertIntEquals(tc, 10, level); CuAssertIntEquals(tc, 10, level);