fairland: Eliminate global variable @fl_status
grow_one_sector() sets @fl_status when it fails to grow a continent. grow_continents() uses @fl_status to find out whether grow_one_sector() succeeded, and main() uses it to find out whether grow_continents() succeeded. Change grow_continents() to return success / failure. grow_one_sector() already does. Use the return values, and eliminate @fl_status. Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
This commit is contained in:
parent
cf27d16e47
commit
b392b68bd5
1 changed files with 21 additions and 18 deletions
|
@ -193,8 +193,7 @@ static int **sectc; /* which sectors are on the coast? */
|
||||||
static int *vector; /* used for measuring distances */
|
static int *vector; /* used for measuring distances */
|
||||||
static int *weight; /* used for placing mountains */
|
static int *weight; /* used for placing mountains */
|
||||||
static int *dsea, *dmoun; /* the dist to the ocean and mountain */
|
static int *dsea, *dmoun; /* the dist to the ocean and mountain */
|
||||||
static int fl_status; /* is anything wrong? */
|
|
||||||
#define STATUS_NO_ROOM 1 /* there was no room to grow */
|
|
||||||
#define NUMTRIES 10 /* keep trying to grow this many times */
|
#define NUMTRIES 10 /* keep trying to grow this many times */
|
||||||
|
|
||||||
static const char *numletter =
|
static const char *numletter =
|
||||||
|
@ -206,7 +205,7 @@ static void parse_args(int argc, char *argv[]);
|
||||||
static void allocate_memory(void);
|
static void allocate_memory(void);
|
||||||
static void init(void);
|
static void init(void);
|
||||||
static int drift(void);
|
static int drift(void);
|
||||||
static void grow_continents(void);
|
static int grow_continents(void);
|
||||||
static void create_elevations(void);
|
static void create_elevations(void);
|
||||||
static void write_sects(void);
|
static void write_sects(void);
|
||||||
static void output(void);
|
static void output(void);
|
||||||
|
@ -233,7 +232,7 @@ main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int opt;
|
int opt;
|
||||||
char *config_file = NULL;
|
char *config_file = NULL;
|
||||||
int i = 0;
|
int try, done;
|
||||||
unsigned rnd_seed = 0;
|
unsigned rnd_seed = 0;
|
||||||
int seed_set = 0;
|
int seed_set = 0;
|
||||||
|
|
||||||
|
@ -284,17 +283,18 @@ main(int argc, char *argv[])
|
||||||
|
|
||||||
qprint("\n #*# ...fairland rips open a rift in the datumplane... #*#\n\n");
|
qprint("\n #*# ...fairland rips open a rift in the datumplane... #*#\n\n");
|
||||||
qprint("seed is %u\n", rnd_seed);
|
qprint("seed is %u\n", rnd_seed);
|
||||||
|
try = 0;
|
||||||
do {
|
do {
|
||||||
init();
|
init();
|
||||||
if (i)
|
if (try)
|
||||||
qprint("\ntry #%d (out of %d)...\n", i + 1, NUMTRIES);
|
qprint("\ntry #%d (out of %d)...\n", try + 1, NUMTRIES);
|
||||||
qprint("placing capitals...\n");
|
qprint("placing capitals...\n");
|
||||||
if (!drift())
|
if (!drift())
|
||||||
qprint("unstable drift\n");
|
qprint("unstable drift\n");
|
||||||
qprint("growing continents...\n");
|
qprint("growing continents...\n");
|
||||||
grow_continents();
|
done = grow_continents();
|
||||||
} while (fl_status && ++i < NUMTRIES);
|
} while (!done && ++try < NUMTRIES);
|
||||||
if (fl_status) {
|
if (!done) {
|
||||||
fprintf(stderr, "%s: world not large enough to hold continents\n",
|
fprintf(stderr, "%s: world not large enough to hold continents\n",
|
||||||
program_name);
|
program_name);
|
||||||
exit(1);
|
exit(1);
|
||||||
|
@ -512,7 +512,6 @@ init(void)
|
||||||
int i, j, xx = 0, yy = 0;
|
int i, j, xx = 0, yy = 0;
|
||||||
|
|
||||||
mcc = 0;
|
mcc = 0;
|
||||||
fl_status = 0;
|
|
||||||
|
|
||||||
for (i = 0; i < WORLD_X; ++i) {
|
for (i = 0; i < WORLD_X; ++i) {
|
||||||
for (j = 0; j < WORLD_Y; ++j) {
|
for (j = 0; j < WORLD_Y; ++j) {
|
||||||
|
@ -777,16 +776,17 @@ grow_one_sector(int c)
|
||||||
++coast_search;
|
++coast_search;
|
||||||
} while (!done && coast_search < COAST_SEARCH_MAX &&
|
} while (!done && coast_search < COAST_SEARCH_MAX &&
|
||||||
(isecs[c] == 1 || x != sx || y != sy));
|
(isecs[c] == 1 || x != sx || y != sy));
|
||||||
if (!done && c < nc)
|
|
||||||
fl_status |= STATUS_NO_ROOM;
|
|
||||||
return done;
|
return done;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Grow all the continents
|
/*
|
||||||
|
* Grow the continents.
|
||||||
|
* Return 1 on success, 0 on error.
|
||||||
*/
|
*/
|
||||||
static void
|
static int
|
||||||
grow_continents(void)
|
grow_continents(void)
|
||||||
{
|
{
|
||||||
|
int done = 1;
|
||||||
int c, secs;
|
int c, secs;
|
||||||
|
|
||||||
for (c = 0; c < nc; ++c) {
|
for (c = 0; c < nc; ++c) {
|
||||||
|
@ -799,18 +799,21 @@ grow_continents(void)
|
||||||
isecs[c] = 2;
|
isecs[c] = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (secs = 2; secs < sc && !fl_status; ++secs) {
|
for (secs = 2; secs < sc && done; secs++) {
|
||||||
for (c = 0; c < nc; ++c) {
|
for (c = 0; c < nc; ++c) {
|
||||||
find_coast(c);
|
find_coast(c);
|
||||||
grow_one_sector(c);
|
if (!grow_one_sector(c))
|
||||||
|
done = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (c = 0; c < nc; ++c)
|
for (c = 0; c < nc; ++c)
|
||||||
find_coast(c);
|
find_coast(c);
|
||||||
|
|
||||||
if (fl_status)
|
if (!done)
|
||||||
qprint("Only managed to grow %d out of %d sectors.\n", secs, sc);
|
qprint("Only managed to grow %d out of %d sectors.\n", secs, sc);
|
||||||
ctot = nc;
|
ctot = nc;
|
||||||
|
return done;
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue