cache get_race calls

This commit is contained in:
Enno Rehling 2016-09-19 08:25:39 +02:00
parent 025c0b91d9
commit ee77075cb6
2 changed files with 21 additions and 8 deletions

View File

@ -140,6 +140,7 @@ int NMRTimeout(void)
race_t old_race(const struct race * rc) race_t old_race(const struct race * rc)
{ {
race_t i; race_t i;
// TODO: this sucks so bad!
for (i = 0; i != MAXRACES; ++i) { for (i = 0; i != MAXRACES; ++i) {
if (get_race(i) == rc) return i; if (get_race(i) == rc) return i;
} }

View File

@ -104,16 +104,22 @@ int value, int flags)
int skill_mod(const race * rc, skill_t sk, const struct terrain_type *terrain) int skill_mod(const race * rc, skill_t sk, const struct terrain_type *terrain)
{ {
int result = 0; int result = 0;
static int rc_cache;
static race *rc_dwarf, *rc_insect;
if (rc_changed(&rc_cache)) {
rc_dwarf = get_race(RC_DWARF);
rc_insect = get_race(RC_INSECT);
}
result = rc->bonus[sk]; result = rc->bonus[sk];
if (rc == get_race(RC_DWARF)) { if (rc == rc_dwarf) {
if (sk == SK_TACTICS) { if (sk == SK_TACTICS) {
if (terrain == newterrain(T_MOUNTAIN) || fval(terrain, ARCTIC_REGION)) if (terrain == newterrain(T_MOUNTAIN) || fval(terrain, ARCTIC_REGION))
++result; ++result;
} }
} }
else if (rc == get_race(RC_INSECT)) { else if (rc == rc_insect) {
if (terrain == newterrain(T_MOUNTAIN) || fval(terrain, ARCTIC_REGION)) if (terrain == newterrain(T_MOUNTAIN) || fval(terrain, ARCTIC_REGION))
--result; --result;
else if (terrain == newterrain(T_DESERT) || terrain == newterrain(T_SWAMP)) else if (terrain == newterrain(T_DESERT) || terrain == newterrain(T_SWAMP))
@ -126,19 +132,25 @@ int skill_mod(const race * rc, skill_t sk, const struct terrain_type *terrain)
int rc_skillmod(const struct race *rc, const region * r, skill_t sk) int rc_skillmod(const struct race *rc, const region * r, skill_t sk)
{ {
int mods = 0; int mods = 0;
if (!skill_enabled(sk)) { if (!skill_enabled(sk)) {
return 0; return 0;
} }
if (r) { if (r) {
mods = skill_mod(rc, sk, r->terrain); mods = skill_mod(rc, sk, r->terrain);
} }
if (rc == get_race(RC_ELF) && r && r_isforest(r)) { if (r && r_isforest(r)) {
if (sk == SK_PERCEPTION || sk == SK_STEALTH) { static int rc_cache;
++mods; static race * rc_elf;
if (rc_changed(&rc_cache)) {
rc_elf = get_race(RC_ELF);
} }
else if (sk == SK_TACTICS) { if (rc == rc_elf) {
mods += 2; if (sk == SK_PERCEPTION || sk == SK_STEALTH) {
++mods;
}
else if (sk == SK_TACTICS) {
mods += 2;
}
} }
} }
return mods; return mods;