fairland: Move global variables mc[] into stable(), eliminate mcc
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
This commit is contained in:
parent
9623f3e038
commit
29992a90a8
1 changed files with 25 additions and 19 deletions
|
@ -181,8 +181,6 @@ static int ctot; /* total number of continents and islands grown */
|
||||||
static int *isecs; /* array of how large each island is */
|
static int *isecs; /* array of how large each island is */
|
||||||
|
|
||||||
static int *capx, *capy; /* location of the nc capitals */
|
static int *capx, *capy; /* location of the nc capitals */
|
||||||
static int *mc, mcc; /* array and counter used for stability
|
|
||||||
check when perturbing */
|
|
||||||
static int dirx[] = { -2, -1, 1, 2, 1, -1 }; /* gyujnb */
|
static int dirx[] = { -2, -1, 1, 2, 1, -1 }; /* gyujnb */
|
||||||
static int diry[] = { 0, -1, -1, 0, 1, 1 };
|
static int diry[] = { 0, -1, -1, 0, 1, 1 };
|
||||||
|
|
||||||
|
@ -210,7 +208,7 @@ static void create_elevations(void);
|
||||||
static void write_sects(void);
|
static void write_sects(void);
|
||||||
static void output(void);
|
static void output(void);
|
||||||
static int write_newcap_script(void);
|
static int write_newcap_script(void);
|
||||||
static int stable(void);
|
static int stable(int);
|
||||||
static void elevate_land(void);
|
static void elevate_land(void);
|
||||||
static void elevate_sea(void);
|
static void elevate_sea(void);
|
||||||
static void set_coastal_flags(void);
|
static void set_coastal_flags(void);
|
||||||
|
@ -479,7 +477,6 @@ allocate_memory(void)
|
||||||
capx = calloc(nc, sizeof(int));
|
capx = calloc(nc, sizeof(int));
|
||||||
capy = calloc(nc, sizeof(int));
|
capy = calloc(nc, sizeof(int));
|
||||||
vector = calloc(WORLD_X + WORLD_Y, sizeof(int));
|
vector = calloc(WORLD_X + WORLD_Y, sizeof(int));
|
||||||
mc = calloc(STABLE_CYCLE, sizeof(int));
|
|
||||||
own = calloc(WORLD_X, sizeof(int *));
|
own = calloc(WORLD_X, sizeof(int *));
|
||||||
elev = calloc(WORLD_X, sizeof(int *));
|
elev = calloc(WORLD_X, sizeof(int *));
|
||||||
for (i = 0; i < WORLD_X; ++i) {
|
for (i = 0; i < WORLD_X; ++i) {
|
||||||
|
@ -511,8 +508,6 @@ init(void)
|
||||||
{
|
{
|
||||||
int i, j, xx = 0, yy = 0;
|
int i, j, xx = 0, yy = 0;
|
||||||
|
|
||||||
mcc = 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) {
|
||||||
own[i][j] = -1;
|
own[i][j] = -1;
|
||||||
|
@ -535,8 +530,6 @@ init(void)
|
||||||
capy[i] = yy;
|
capy[i] = yy;
|
||||||
xx += 2;
|
xx += 2;
|
||||||
}
|
}
|
||||||
for (i = 0; i < STABLE_CYCLE; ++i)
|
|
||||||
mc[i] = i;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
|
@ -561,15 +554,17 @@ iso(int j, int newx, int newy)
|
||||||
return d;
|
return d;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Drift all the capitals
|
/*
|
||||||
|
* Drift the capitals
|
||||||
|
* Return 1 for a stable drift, 0 for an unstable one.
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
drift(void)
|
drift(void)
|
||||||
{
|
{
|
||||||
int i, turns;
|
int turns, i;
|
||||||
|
|
||||||
for (turns = 0; turns < DRIFT_MAX; ++turns) {
|
for (turns = 0; turns < DRIFT_MAX; ++turns) {
|
||||||
if (turns > DRIFT_BEFORE_CHECK && stable())
|
if (stable(turns))
|
||||||
return 1;
|
return 1;
|
||||||
for (i = 0; i < nc; ++i)
|
for (i = 0; i < nc; ++i)
|
||||||
fl_move(i);
|
fl_move(i);
|
||||||
|
@ -577,25 +572,36 @@ drift(void)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check to see if we have stabilized--can we stop drifting the capitals?
|
/*
|
||||||
|
* Has the drift stabilized?
|
||||||
|
* @turns is the number of turns so far.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static int
|
static int
|
||||||
stable(void)
|
stable(int turns)
|
||||||
{
|
{
|
||||||
|
static int mc[STABLE_CYCLE];
|
||||||
int i, isod, d = 0, stab = 1;
|
int i, isod, d = 0, stab = 1;
|
||||||
|
|
||||||
|
if (!turns) {
|
||||||
|
for (i = 0; i < STABLE_CYCLE; i++)
|
||||||
|
mc[i] = i;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (turns <= DRIFT_BEFORE_CHECK)
|
||||||
|
return 0;
|
||||||
|
|
||||||
for (i = 0; i < nc; ++i) {
|
for (i = 0; i < nc; ++i) {
|
||||||
isod = iso(i, capx[i], capy[i]);
|
isod = iso(i, capx[i], capy[i]);
|
||||||
if (isod > d)
|
if (isod > d)
|
||||||
d = isod;
|
d = isod;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < STABLE_CYCLE; ++i)
|
for (i = 0; i < STABLE_CYCLE; ++i)
|
||||||
if (d != mc[i])
|
if (d != mc[i])
|
||||||
stab = 0;
|
stab = 0;
|
||||||
mc[mcc] = d;
|
|
||||||
mcc = (mcc + 1) % STABLE_CYCLE;
|
mc[turns % STABLE_CYCLE] = d;
|
||||||
return stab ? d : 0;
|
return stab;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This routine does the actual drifting
|
/* This routine does the actual drifting
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue