separate interval generation from seen-markup a bit more.

This commit is contained in:
Enno Rehling 2016-09-20 15:53:55 +02:00
parent a06f73c086
commit 69b420ae2f
3 changed files with 24 additions and 9 deletions

View File

@ -1135,19 +1135,24 @@ static void add_seen(region *r, seen_mode mode) {
}
}
static void faction_add_seen(faction *f, region *r, seen_mode mode) {
static void add_seen_nb(faction *f, region *r, seen_mode mode) {
region *first = r, *last = r;
add_seen(r, mode);
if (mode > seen_neighbour) {
region *next[MAXDIRECTIONS];
int d;
get_neighbours(r, next);
for (d = 0; d != MAXDIRECTIONS; ++d) {
if (next[d] && next[d]->seen.mode<seen_neighbour) {
faction_add_seen(f, next[d], seen_neighbour);
region *rn = next[d];
if (rn && rn->seen.mode<seen_neighbour) {
add_seen(rn, seen_neighbour);
if (first->index>rn->index) first = rn;
if (last->index<rn->index) last = rn;
}
}
}
update_interval(f, r);
update_interval(f, first);
update_interval(f, last);
}
/** mark all regions seen by the lighthouse.
@ -1162,7 +1167,7 @@ static void prepare_lighthouse(building * b, report_context *ctx)
for (ql = rlist, qi = 0; ql; ql_advance(&ql, &qi, 1)) {
region *rl = (region *)ql_get(ql, qi);
if (!fval(rl->terrain, FORBIDDEN_REGION)) {
faction_add_seen(f, rl, seen_lighthouse);
add_seen_nb(f, rl, seen_lighthouse);
}
}
ql_free(rlist);
@ -1286,7 +1291,7 @@ static region *firstregion(faction * f)
static void cb_add_seen(region *r, unit *u, void *cbdata) {
faction *f = (faction *)cbdata;
if (u->faction==f) {
faction_add_seen(f, r, seen_travel);
add_seen_nb(f, r, seen_travel);
}
}
@ -1327,7 +1332,7 @@ void prepare_report(report_context *ctx, faction *f)
if (u && u->faction==f) {
prepare_lighthouse(b, ctx);
if (u_race(u) != get_race(RC_SPELL) || u->number == RS_FARVISION) {
faction_add_seen(f, r, seen_unit);
add_seen_nb(f, r, seen_unit);
}
}
}
@ -1338,7 +1343,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) {
faction_add_seen(f, r, seen_unit);
add_seen_nb(f, r, seen_unit);
}
if (fval(r, RF_LIGHTHOUSE)) {
if (u->building && u->building->type == bt_lighthouse && inside_building(u)) {
@ -1349,7 +1354,7 @@ void prepare_report(report_context *ctx, faction *f)
}
}
if (fval(r, RF_TRAVELUNIT)) {
if (fval(r, RF_TRAVELUNIT) && r->seen.mode<seen_travel) {
travelthru_map(r, cb_add_seen, f);
}
}

View File

@ -410,7 +410,11 @@ static void test_seen_travelthru(CuTest *tc) {
r3 = test_create_region(2, 0, 0);
u = test_create_unit(f, r1);
CuAssertPtrEquals(tc, r1, f->first);
CuAssertPtrEquals(tc, r1, f->last);
travelthru_add(r2, u);
CuAssertPtrEquals(tc, r1, f->first);
CuAssertPtrEquals(tc, r3, f->last);
prepare_report(&ctx, f);
CuAssertPtrEquals(tc, r1, ctx.first);
CuAssertPtrEquals(tc, 0, ctx.last);

View File

@ -64,6 +64,8 @@ attrib_type at_travelunit = {
*/
void travelthru_add(region * r, unit * u)
{
region *next[MAXDIRECTIONS];
int d;
attrib *a;
quicklist *ql;
@ -84,6 +86,10 @@ void travelthru_add(region * r, unit * u)
* could be in regions that are located before the [first, last] interval,
* and recalculation is needed */
update_interval(u->faction, r);
get_neighbours(r, next);
for (d=0;d!=MAXDIRECTIONS;++d) {
update_interval(u->faction, next[d]);
}
}
bool travelthru_cansee(const struct region *r, const struct faction *f, const struct unit *u) {