diff --git a/src/battle.c b/src/battle.c index 97afb3de4..f57e7b377 100644 --- a/src/battle.c +++ b/src/battle.c @@ -1022,23 +1022,32 @@ static void vampirism(troop at, int damage) } } +#define MAXRACES 128 + static int natural_armor(unit * du) { - static int *bonus = 0; - int an = u_race(du)->armor; - if (bonus == 0) { - assert(num_races > 0); - bonus = calloc((size_t)num_races, sizeof(int)); + static int cookie = -1; + static int bonus[MAXRACES]; + const race *rc = u_race(du); + int index, an = rc->armor; + + assert(rc); + if (cookie!=global.cookie) { + cookie = global.cookie; + memset(bonus, 0, sizeof(bonus)); } - if (bonus[u_race(du)->index] == 0) { - bonus[u_race(du)->index] = - get_param_int(u_race(du)->parameters, "armor.stamina", -1); - if (bonus[u_race(du)->index] == 0) - bonus[u_race(du)->index] = -1; + assert(num_races < MAXRACES); + index = rc->index; + assert(index >= 0 && index < num_races); + if (bonus[index] == 0) { + bonus[index] = + get_param_int(rc->parameters, "armor.stamina", -1); + if (bonus[index] == 0) + bonus[index] = -1; } - if (bonus[u_race(du)->index] > 0) { + if (bonus[index] > 0) { int sk = effskill(du, SK_STAMINA, 0); - sk /= bonus[u_race(du)->index]; + sk /= bonus[index]; an += sk; } return an; diff --git a/src/kernel/race.c b/src/kernel/race.c index 191c4f27d..7d881fe7f 100644 --- a/src/kernel/race.c +++ b/src/kernel/race.c @@ -146,6 +146,7 @@ void free_races(void) { free(races); races = rc; } + num_races = 0; } static race *rc_find_i(const char *name) diff --git a/src/spells/flyingship.test.c b/src/spells/flyingship.test.c index 00199e971..b3d03f01b 100644 --- a/src/spells/flyingship.test.c +++ b/src/spells/flyingship.test.c @@ -26,13 +26,13 @@ static void test_flyingship(CuTest * tc) ship_type *shipType1, *shipType2; ship *sh1, *sh2; + test_cleanup(); + par.param = &par_data_ptr; par_data.typ = SPP_SHIP; + par_data.flag = 0; - test_cleanup(); - test_create_world(); - - r = findregion(0, 0); + r = test_create_region(0, 0, 0); f = test_create_faction(test_create_race("human")); u = test_create_unit(f, r); @@ -57,6 +57,7 @@ static void test_flyingship(CuTest * tc) CuAssertTrue(tc, !flying_ship(sh2)); CuAssertIntEquals(tc, 0, sp_flying_ship(&co)); CuAssertTrue(tc, !flying_ship(sh2)); + test_cleanup(); } CuSuite *get_flyingship_suite(void) diff --git a/tests/write-reports.sh b/tests/write-reports.sh index 775fdb622..c87059854 100755 --- a/tests/write-reports.sh +++ b/tests/write-reports.sh @@ -21,13 +21,16 @@ cd $ROOT/tests setup cleanup VALGRIND=`which valgrind` +TESTS=../Debug/eressea/test_eressea SERVER=../Debug/eressea/eressea if [ -n "$VALGRIND" ]; then SUPP=../share/ubuntu-12_04.supp -SERVER="$VALGRIND --suppressions=$SUPP --error-exitcode=1 --leak-check=no $SERVER" +VALGRIND="$VALGRIND --suppressions=$SUPP --error-exitcode=1 --leak-check=no" fi +echo "running $TESTS" +$VALGRIND $TESTS echo "running $SERVER" -$SERVER -t 184 ../scripts/reports.lua +$VALGRIND $SERVER -t 184 ../scripts/reports.lua [ -d reports ] || quit 4 "no reports directory created" CRFILE=184-zvto.cr grep -q PARTEI reports/$CRFILE || quit 1 "CR did not contain any factions"