extract RC_SPELL handling into a small function, minimize get_race calls.

This commit is contained in:
Enno Rehling 2016-09-22 20:22:23 +02:00
parent 37a5954c20
commit c606a9ac4d
1 changed files with 13 additions and 2 deletions

View File

@ -1308,6 +1308,17 @@ static void cb_add_seen(region *r, unit *u, void *cbdata) {
} }
} }
static bool unit_cansee(const unit *u)
{
const race *rc = u_race(u);
static const race *rc_spell;
static int rc_cache;
if (rc_changed(&rc_cache)) {
rc_spell = get_race(RC_SPELL);
}
return (rc!=rc_spell || u->number == RS_FARVISION);
}
/** set region.seen based on visibility by one faction. /** set region.seen based on visibility by one faction.
* *
* this function may also update ctx->last and ctx->first for potential * this function may also update ctx->last and ctx->first for potential
@ -1344,7 +1355,7 @@ void prepare_report(report_context *ctx, faction *f)
u = building_owner(b); u = building_owner(b);
if (u && u->faction==f) { if (u && u->faction==f) {
prepare_lighthouse(b, ctx); prepare_lighthouse(b, ctx);
if (u_race(u) != get_race(RC_SPELL) || u->number == RS_FARVISION) { if (unit_cansee(u)) {
add_seen_nb(f, r, seen_unit); add_seen_nb(f, r, seen_unit);
} }
} }
@ -1355,7 +1366,7 @@ void prepare_report(report_context *ctx, faction *f)
} }
for (u = r->units; u; u = u->next) { for (u = r->units; u; u = u->next) {
if (u->faction==f) { if (u->faction==f) {
if (u_race(u) != get_race(RC_SPELL) || u->number == RS_FARVISION) { if (unit_cansee(u)) {
add_seen_nb(f, r, seen_unit); add_seen_nb(f, r, seen_unit);
} }
if (fval(r, RF_LIGHTHOUSE)) { if (fval(r, RF_LIGHTHOUSE)) {