forked from github/server
eliminate silly caching logic from natural armor calculation
This commit is contained in:
parent
990fda6234
commit
7dae5aa035
3 changed files with 30 additions and 20 deletions
28
src/battle.c
28
src/battle.c
|
@ -1024,30 +1024,20 @@ static void vampirism(troop at, int damage)
|
|||
|
||||
#define MAXRACES 128
|
||||
|
||||
static int natural_armor(unit * du)
|
||||
static int armor_bonus(const race *rc) {
|
||||
return get_param_int(rc->parameters, "armor.stamina", -1);
|
||||
}
|
||||
|
||||
int natural_armor(unit * du)
|
||||
{
|
||||
static int cookie = -1;
|
||||
static int bonus[MAXRACES];
|
||||
const race *rc = u_race(du);
|
||||
int index, an = rc->armor;
|
||||
int bonus, an = rc->armor;
|
||||
|
||||
assert(rc);
|
||||
if (cookie!=global.cookie) {
|
||||
cookie = global.cookie;
|
||||
memset(bonus, 0, sizeof(bonus));
|
||||
}
|
||||
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[index] > 0) {
|
||||
bonus = armor_bonus(rc);
|
||||
if (bonus > 0) {
|
||||
int sk = effskill(du, SK_STAMINA, 0);
|
||||
sk /= bonus[index];
|
||||
sk /= bonus;
|
||||
an += sk;
|
||||
}
|
||||
return an;
|
||||
|
|
|
@ -243,6 +243,7 @@ extern "C" {
|
|||
|
||||
int count_enemies(struct battle *b, const struct fighter *af,
|
||||
int minrow, int maxrow, int select);
|
||||
int natural_armor(struct unit * u);
|
||||
int calculate_armor(troop dt, const struct weapon_type *dwtype, const struct weapon_type *awtype, double *magres);
|
||||
bool terminate(troop dt, troop at, int type, const char *damage,
|
||||
bool missile);
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#include "battle.h"
|
||||
#include "skill.h"
|
||||
|
||||
#include <kernel/config.h>
|
||||
#include <kernel/building.h>
|
||||
#include <kernel/faction.h>
|
||||
#include <kernel/item.h>
|
||||
|
@ -201,13 +202,30 @@ static void test_building_defence_bonus(CuTest * tc)
|
|||
test_cleanup();
|
||||
}
|
||||
|
||||
fighter *setup_fighter(battle **bp, unit *u) {
|
||||
static fighter *setup_fighter(battle **bp, unit *u) {
|
||||
battle *b;
|
||||
|
||||
*bp = b = make_battle(u->region);
|
||||
return make_fighter(b, u, make_side(b, u->faction, 0, 0, 0), false);
|
||||
}
|
||||
|
||||
static void test_natural_armor(CuTest * tc)
|
||||
{
|
||||
race *rc;
|
||||
unit *u;
|
||||
|
||||
test_cleanup();
|
||||
rc = test_create_race("human");
|
||||
u = test_create_unit(test_create_faction(rc), test_create_region(0, 0, 0));
|
||||
set_level(u, SK_STAMINA, 2);
|
||||
CuAssertIntEquals(tc, 0, natural_armor(u));
|
||||
set_param(&rc->parameters, "armor.stamina", "1");
|
||||
CuAssertIntEquals(tc, 2, natural_armor(u));
|
||||
set_param(&rc->parameters, "armor.stamina", "2");
|
||||
CuAssertIntEquals(tc, 1, natural_armor(u));
|
||||
test_cleanup();
|
||||
}
|
||||
|
||||
static void test_calculate_armor(CuTest * tc)
|
||||
{
|
||||
troop dt;
|
||||
|
@ -321,6 +339,7 @@ CuSuite *get_battle_suite(void)
|
|||
SUITE_ADD_TEST(suite, test_building_bonus_respects_size);
|
||||
SUITE_ADD_TEST(suite, test_building_defence_bonus);
|
||||
SUITE_ADD_TEST(suite, test_calculate_armor);
|
||||
SUITE_ADD_TEST(suite, test_natural_armor);
|
||||
SUITE_ADD_TEST(suite, test_projectile_armor);
|
||||
return suite;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue