eliminated region_list use from get_island

This commit is contained in:
Enno Rehling 2011-04-26 21:22:30 -07:00
parent c4cc06a80f
commit 6798c497f8
2 changed files with 30 additions and 27 deletions

View file

@ -35,6 +35,7 @@
#include <util/language.h> #include <util/language.h>
#include <util/lists.h> #include <util/lists.h>
#include <util/log.h> #include <util/log.h>
#include <util/quicklist.h>
#include <util/rng.h> #include <util/rng.h>
#include <util/sql.h> #include <util/sql.h>
#include <util/unicode.h> #include <util/unicode.h>
@ -364,35 +365,35 @@ static boolean virgin_region(const region * r)
return true; return true;
} }
void get_island(region * root, region_list ** rlist) static quicklist * get_island(region * root)
{ {
region_list **rnext = rlist; quicklist * ql, * result = 0;
while (*rnext) int qi = 0;
rnext = &(*rnext)->next;
fset(root, RF_MARK); fset(root, RF_MARK);
add_regionlist(rnext, root); ql_push(&result, root);
while (*rnext) { for (ql=result,qi=0; ql; ql_advance(&ql, &qi, 1)) {
direction_t dir; int dir;
region *r = (region *)ql_get(ql, qi);
region * next[MAXDIRECTIONS];
region *rcurrent = (*rnext)->data; get_neighbours(r, next);
rnext = &(*rnext)->next;
for (dir = 0; dir != MAXDIRECTIONS; ++dir) { for (dir = 0; dir != MAXDIRECTIONS; ++dir) {
region *r = rconnect(rcurrent, dir); region *rn = next[dir];
if (r != NULL && r->land && !fval(r, RF_MARK)) { if (rn != NULL && rn->land && !fval(rn, RF_MARK)) {
fset(r, RF_MARK); fset(rn, RF_MARK);
add_regionlist(rnext, r); ql_push(&result, rn);
} }
} }
} }
rnext = rlist;
while (*rnext) { for (ql=result,qi=0; ql; ql_advance(&ql, &qi, 1)) {
region_list *rptr = *rnext; region *r = (region *)ql_get(ql, qi);
freset(rptr->data, RF_MARK); freset(r, RF_MARK);
rnext = &rptr->next;
} }
return result;
} }
static void static void
@ -405,7 +406,7 @@ get_island_info(region * root, int *size_p, int *inhabited_p, int *maxage_p)
island = rlist; island = rlist;
fset(root, RF_MARK); fset(root, RF_MARK);
while (rlist) { while (rlist) {
direction_t d; int d;
region *r = rlist->data; region *r = rlist->data;
if (r->units) { if (r->units) {
unit *u; unit *u;
@ -572,11 +573,12 @@ int autoseed(newfaction ** players, int nsize, int max_agediff)
} }
} }
if (rmin != NULL) { if (rmin != NULL) {
region_list *rlist = NULL, *rptr;
faction *f; faction *f;
get_island(rmin, &rlist); quicklist *ql, *rlist = get_island(rmin);
for (rptr = rlist; rptr; rptr = rptr->next) { int qi;
region *r = rlist->data;
for (ql=rlist,qi=0;ql;ql_advance(&ql, &qi, 1)) {
region *r = (region *)ql_get(ql, qi);
unit *u; unit *u;
for (u = r->units; u; u = u->next) { for (u = r->units; u; u = u->next) {
f = u->faction; f = u->faction;
@ -586,10 +588,12 @@ int autoseed(newfaction ** players, int nsize, int max_agediff)
} }
} }
} }
free_regionlist(rlist); ql_free(rlist);
if (psize > 0) if (psize > 0) {
for (f = factions; f; f = f->next) for (f = factions; f; f = f->next) {
freset(f, FFL_MARK); freset(f, FFL_MARK);
}
}
if (psize < PLAYERS_PER_ISLAND) { if (psize < PLAYERS_PER_ISLAND) {
r = rmin; r = rmin;
} }

View file

@ -36,7 +36,6 @@ extern "C" {
extern int autoseed(newfaction ** players, int nsize, int max_agediff); extern int autoseed(newfaction ** players, int nsize, int max_agediff);
extern newfaction *read_newfactions(const char *filename); extern newfaction *read_newfactions(const char *filename);
extern void get_island(struct region *root, struct region_list **rlist);
extern int fix_demand(struct region *r); extern int fix_demand(struct region *r);
extern const struct terrain_type *random_terrain(const struct terrain_type extern const struct terrain_type *random_terrain(const struct terrain_type
*terrains[], int distribution[], int size); *terrains[], int distribution[], int size);