forked from github/server
extract RC_SPELL handling into a small function, minimize get_race calls.
This commit is contained in:
parent
37a5954c20
commit
c606a9ac4d
1 changed files with 13 additions and 2 deletions
|
@ -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.
|
||||
*
|
||||
* 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);
|
||||
if (u && u->faction==f) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -1355,7 +1366,7 @@ void prepare_report(report_context *ctx, faction *f)
|
|||
}
|
||||
for (u = r->units; u; u = u->next) {
|
||||
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);
|
||||
}
|
||||
if (fval(r, RF_LIGHTHOUSE)) {
|
||||
|
|
Loading…
Reference in a new issue