fix marking seen_neighbour regions.

fix reports-tests that didn't think about them.
This commit is contained in:
Enno Rehling 2016-09-18 13:27:25 +02:00
parent 63a97d6bc0
commit ec9d8eab1c
2 changed files with 22 additions and 13 deletions

View File

@ -1137,6 +1137,16 @@ static void add_seen(region *r, seen_mode mode) {
static void faction_add_seen(faction *f, region *r, seen_mode mode) { static void faction_add_seen(faction *f, region *r, seen_mode mode) {
add_seen(r, mode); 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);
}
}
}
#ifdef SMART_INTERVALS #ifdef SMART_INTERVALS
update_interval(f, r); update_interval(f, r);
#endif #endif
@ -1154,16 +1164,7 @@ static void prepare_lighthouse(building * b, report_context *ctx)
for (ql = rlist, qi = 0; ql; ql_advance(&ql, &qi, 1)) { for (ql = rlist, qi = 0; ql; ql_advance(&ql, &qi, 1)) {
region *rl = (region *)ql_get(ql, qi); region *rl = (region *)ql_get(ql, qi);
if (!fval(rl->terrain, FORBIDDEN_REGION)) { if (!fval(rl->terrain, FORBIDDEN_REGION)) {
region * next[MAXDIRECTIONS];
int d;
get_neighbours(rl, next);
faction_add_seen(f, rl, seen_lighthouse); faction_add_seen(f, rl, seen_lighthouse);
for (d = 0; d != MAXDIRECTIONS; ++d) {
if (next[d]) {
faction_add_seen(f, next[d], seen_neighbour);
}
}
} }
} }
ql_free(rlist); ql_free(rlist);

View File

@ -237,7 +237,7 @@ static void test_prepare_travelthru(CuTest *tc) {
f2 = test_create_faction(0); f2 = test_create_faction(0);
r1 = test_create_region(0, 0, 0); r1 = test_create_region(0, 0, 0);
r2 = test_create_region(1, 0, 0); r2 = test_create_region(1, 0, 0);
r3 = test_create_region(2, 0, 0); r3 = test_create_region(3, 0, 0);
test_create_unit(f2, r1); test_create_unit(f2, r1);
test_create_unit(f2, r3); test_create_unit(f2, r3);
u = test_create_unit(f, r1); u = test_create_unit(f, r1);
@ -253,7 +253,9 @@ static void test_prepare_travelthru(CuTest *tc) {
CuAssertIntEquals(tc, seen_none, r2->seen.mode); CuAssertIntEquals(tc, seen_none, r2->seen.mode);
prepare_report(&ctx, f2); prepare_report(&ctx, f2);
CuAssertIntEquals(tc, seen_none, r2->seen.mode); CuAssertIntEquals(tc, seen_unit, r1->seen.mode);
CuAssertIntEquals(tc, seen_neighbour, r2->seen.mode);
CuAssertIntEquals(tc, seen_unit, r3->seen.mode);
CuAssertPtrEquals(tc, f2, ctx.f); CuAssertPtrEquals(tc, f2, ctx.f);
CuAssertPtrEquals(tc, r1, ctx.first); CuAssertPtrEquals(tc, r1, ctx.first);
CuAssertPtrEquals(tc, NULL, ctx.last); CuAssertPtrEquals(tc, NULL, ctx.last);
@ -295,11 +297,17 @@ void test_prepare_lighthouse_capacity(CuTest *tc) {
prepare_report(&ctx, u1->faction); prepare_report(&ctx, u1->faction);
CuAssertPtrEquals(tc, r1, ctx.first); CuAssertPtrEquals(tc, r1, ctx.first);
CuAssertPtrEquals(tc, NULL, ctx.last); CuAssertPtrEquals(tc, NULL, ctx.last);
CuAssertIntEquals(tc, seen_unit, r1->seen.mode);
CuAssertIntEquals(tc, seen_lighthouse, r2->seen.mode);
finish_reports(&ctx); finish_reports(&ctx);
prepare_report(&ctx, u2->faction); prepare_report(&ctx, u2->faction);
CuAssertPtrEquals(tc, r1, ctx.first); CuAssertPtrEquals(tc, r1, ctx.first);
CuAssertPtrEquals(tc, r2, ctx.last); CuAssertPtrEquals(tc, 0, ctx.last);
CuAssertIntEquals(tc, seen_unit, r1->seen.mode);
CuAssertIntEquals(tc, seen_neighbour, r2->seen.mode);
finish_reports(&ctx); finish_reports(&ctx);
test_cleanup(); test_cleanup();
} }
@ -360,7 +368,7 @@ static void test_prepare_report(CuTest *tc) {
CuAssertIntEquals(tc, seen_none, r->seen.mode); CuAssertIntEquals(tc, seen_none, r->seen.mode);
finish_reports(&ctx); finish_reports(&ctx);
r = test_create_region(1, 0, 0); r = test_create_region(2, 0, 0);
CuAssertPtrEquals(tc, r, regions->next); CuAssertPtrEquals(tc, r, regions->next);
prepare_report(&ctx, f); prepare_report(&ctx, f);
CuAssertPtrEquals(tc, regions, ctx.first); CuAssertPtrEquals(tc, regions, ctx.first);