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 i;
// TODO: this sucks so bad!
for (i = 0; i != MAXRACES; ++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 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];
if (rc == get_race(RC_DWARF)) {
if (rc == rc_dwarf) {
if (sk == SK_TACTICS) {
if (terrain == newterrain(T_MOUNTAIN) || fval(terrain, ARCTIC_REGION))
++result;
}
}
else if (rc == get_race(RC_INSECT)) {
else if (rc == rc_insect) {
if (terrain == newterrain(T_MOUNTAIN) || fval(terrain, ARCTIC_REGION))
--result;
else if (terrain == newterrain(T_DESERT) || terrain == newterrain(T_SWAMP))
@ -126,14 +132,19 @@ 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 mods = 0;
if (!skill_enabled(sk)) {
return 0;
}
if (r) {
mods = skill_mod(rc, sk, r->terrain);
}
if (rc == get_race(RC_ELF) && r && r_isforest(r)) {
if (r && r_isforest(r)) {
static int rc_cache;
static race * rc_elf;
if (rc_changed(&rc_cache)) {
rc_elf = get_race(RC_ELF);
}
if (rc == rc_elf) {
if (sk == SK_PERCEPTION || sk == SK_STEALTH) {
++mods;
}
@ -141,6 +152,7 @@ int rc_skillmod(const struct race *rc, const region * r, skill_t sk)
mods += 2;
}
}
}
return mods;
}