get_regions_distance converted to quicklist

This commit is contained in:
Enno Rehling 2011-04-25 22:30:54 -07:00
parent dbd338c284
commit c4cc06a80f
1 changed files with 30 additions and 24 deletions

View File

@ -1251,27 +1251,32 @@ void register_reporttype(const char *extension, report_fun write, int flag)
report_types = type; report_types = type;
} }
static region_list *get_regions_distance(region * root, int radius) static quicklist *get_regions_distance(region * root, int radius)
{ {
region_list *rptr, *rlist = NULL; quicklist *ql, *rlist = NULL;
region_list **rp = &rlist; int qi = 0;
add_regionlist(rp, root);
fset(root, RF_MARK); ql_push(&rlist, root);
while (*rp) { fset(root, RF_MARK);
region_list *r = *rp; ql = rlist;
int d;
while (ql) {
region *r = (region *)ql_get(ql, qi);
region * next[MAXDIRECTIONS];
int d;
get_neighbours(r, next);
rp = &r->next;
for (d = 0; d != MAXDIRECTIONS; ++d) { for (d = 0; d != MAXDIRECTIONS; ++d) {
region *rn = rconnect(r->data, d); if (next[d] && !fval(next[d], RF_MARK) && distance(next[d], root) <= radius) {
if (rn != NULL && !fval(rn, RF_MARK) && distance(rn, root) <= radius) { ql_push(&rlist, next[d]);
add_regionlist(rp, rn); fset(next[d], RF_MARK);
fset(rn, RF_MARK);
} }
} }
ql_advance(&ql, &qi, 1);
} }
for (rptr = rlist; rptr; rptr = rptr->next) { for (ql=rlist,qi=0;ql;ql_advance(&ql, &qi, 1)) {
freset(rptr->data, RF_MARK); region *r = (region *)ql_get(ql, qi);
freset(r, RF_MARK);
} }
return rlist; return rlist;
} }
@ -1383,24 +1388,25 @@ static void view_regatta(struct seen_region **seen, region * r, faction * f)
static void prepare_lighthouse(building * b, faction * f) static void prepare_lighthouse(building * b, faction * f)
{ {
int range = lighthouse_range(b, f); int range = lighthouse_range(b, f);
region_list *rlist = get_regions_distance(b->region, range); quicklist *ql, *rlist = get_regions_distance(b->region, range);
region_list *rp = rlist; int qi;
while (rp) { for (ql=rlist,qi=0;ql;ql_advance(&ql, &qi,1)) {
region *rl = rp->data; region *rl = (region *)ql_get(ql, qi);
if (!fval(rl->terrain, FORBIDDEN_REGION)) { if (!fval(rl->terrain, FORBIDDEN_REGION)) {
region * next[MAXDIRECTIONS];
int d; int d;
get_neighbours(rl, next);
add_seen(f->seen, rl, see_lighthouse, false); add_seen(f->seen, rl, see_lighthouse, false);
for (d = 0; d != MAXDIRECTIONS; ++d) { for (d = 0; d != MAXDIRECTIONS; ++d) {
region *rn = rconnect(rl, d); if (next[d]) {
if (rn != NULL) { add_seen(f->seen, next[d], see_neighbour, false);
add_seen(f->seen, rn, see_neighbour, false);
} }
} }
} }
rp = rp->next;
} }
free_regionlist(rlist); ql_free(rlist);
} }
static void prepare_reports(void) static void prepare_reports(void)