tighten up some lookups.

This commit is contained in:
Enno Rehling 2016-10-03 20:27:36 +02:00
parent fbdf845cb9
commit 8f1a1fc8c3

View file

@ -1031,9 +1031,8 @@ cancast(unit * u, const spell * sp, int level, int range, struct order * ord)
double double
spellpower(region * r, unit * u, const spell * sp, int cast_level, struct order *ord) spellpower(region * r, unit * u, const spell * sp, int cast_level, struct order *ord)
{ {
curse *c;
double force = cast_level; double force = cast_level;
int elf_power; static int elf_power, config;
const struct resource_type *rtype; const struct resource_type *rtype;
if (sp == NULL) { if (sp == NULL) {
@ -1046,16 +1045,27 @@ spellpower(region * r, unit * u, const spell * sp, int cast_level, struct order
if (btype && btype->flags & BTF_MAGIC) ++force; if (btype && btype->flags & BTF_MAGIC) ++force;
} }
if (config_changed(&config)) {
elf_power = config_get_int("rules.magic.elfpower", 0); elf_power = config_get_int("rules.magic.elfpower", 0);
}
if (elf_power && u_race(u) == get_race(RC_ELF) && r_isforest(r)) { if (elf_power) {
static int rc_cache;
static const race *rc_elf;
if (rc_changed(&rc_cache)) {
rc_elf = get_race(RC_ELF);
}
if (u_race(u) == rc_elf && r_isforest(r)) {
++force; ++force;
} }
}
rtype = rt_find("rop"); rtype = rt_find("rop");
if (rtype && i_get(u->items, rtype->itype) > 0) { if (rtype && i_get(u->items, rtype->itype) > 0) {
++force; ++force;
} }
if (r->attribs) {
curse *c;
/* Antimagie in der Zielregion */ /* Antimagie in der Zielregion */
c = get_curse(r->attribs, ct_find("antimagiczone")); c = get_curse(r->attribs, ct_find("antimagiczone"));
if (curse_active(c)) { if (curse_active(c)) {
@ -1093,7 +1103,7 @@ spellpower(region * r, unit * u, const spell * sp, int cast_level, struct order
} }
} }
} }
}
return _max(force, 0); return _max(force, 0);
} }
@ -2784,6 +2794,8 @@ void magic(void)
int rank; int rank;
castorder *co; castorder *co;
spellrank spellranks[MAX_SPELLRANK]; spellrank spellranks[MAX_SPELLRANK];
const race *rc_spell = get_race(RC_SPELL);
const race *rc_insect = get_race(RC_INSECT);
memset(spellranks, 0, sizeof(spellranks)); memset(spellranks, 0, sizeof(spellranks));
@ -2792,10 +2804,10 @@ void magic(void)
for (u = r->units; u; u = u->next) { for (u = r->units; u; u = u->next) {
order *ord; order *ord;
if (u->number <= 0 || u_race(u) == get_race(RC_SPELL)) if (u->number <= 0 || u_race(u) == rc_spell)
continue; continue;
if (u_race(u) == get_race(RC_INSECT) && r_insectstalled(r) && if (u_race(u) == rc_insect && r_insectstalled(r) &&
!is_cursed(u->attribs, C_KAELTESCHUTZ, 0)) !is_cursed(u->attribs, C_KAELTESCHUTZ, 0))
continue; continue;