fairland: Fuse capx[], capy[] into cap[]

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
This commit is contained in:
Markus Armbruster 2020-08-21 13:42:51 +02:00
parent 9c9e0ff8d5
commit d8db5b7308

View file

@ -226,14 +226,18 @@ struct xy {
coord x, y; coord x, y;
}; };
/*
* Capital locations
* The i-th capital is at cap[i].
*/
static struct xy *cap;
/* /*
* Island sizes * Island sizes
* isecs[i] is the size of the i-th island. * isecs[i] is the size of the i-th island.
*/ */
static int *isecs; static int *isecs;
static int *capx, *capy; /* location of the nc capitals */
/* /*
* Island sectors * Island sectors
* The i-th island's j-th sector is at sect[i][j]. * The i-th island's j-th sector is at sect[i][j].
@ -589,8 +593,7 @@ allocate_memory(void)
{ {
int i; int i;
capx = calloc(nc, sizeof(int)); cap = malloc(nc * sizeof(*cap));
capy = calloc(nc, sizeof(int));
own = malloc(WORLD_SZ() * sizeof(*own)); own = malloc(WORLD_SZ() * sizeof(*own));
adj_land = malloc(WORLD_SZ() * sizeof(*adj_land)); adj_land = malloc(WORLD_SZ() * sizeof(*adj_land));
elev = calloc(WORLD_SZ(), sizeof(*elev)); elev = calloc(WORLD_SZ(), sizeof(*elev));
@ -634,7 +637,7 @@ iso(int j, int newx, int newy)
for (i = 0; i < nc; ++i) { for (i = 0; i < nc; ++i) {
if (i == j) if (i == j)
continue; continue;
md = mapdist(capx[i], capy[i], newx, newy); md = mapdist(cap[i].x, cap[i].y, newx, newy);
if (md < d) if (md < d)
d = md; d = md;
} }
@ -652,9 +655,9 @@ drift(void)
int turns, i; int turns, i;
for (i = 0; i < nc; i++) { for (i = 0; i < nc; i++) {
capy[i] = (2 * i) / WORLD_X; cap[i].y = (2 * i) / WORLD_X;
capx[i] = (2 * i) % WORLD_X + capy[i] % 2; cap[i].x = (2 * i) % WORLD_X + cap[i].y % 2;
if (capy[i] >= WORLD_Y) { if (cap[i].y >= WORLD_Y) {
fprintf(stderr, fprintf(stderr,
"%s: world not big enough for all the continents\n", "%s: world not big enough for all the continents\n",
program_name); program_name);
@ -690,7 +693,7 @@ stable(int turns)
return 0; return 0;
for (i = 0; i < nc; ++i) { for (i = 0; i < nc; ++i) {
isod = iso(i, capx[i], capy[i]); isod = iso(i, cap[i].x, cap[i].y);
if (isod > d) if (isod > d)
d = isod; d = isod;
} }
@ -715,12 +718,12 @@ fl_move(int j)
for (i = 0; i < 6; i++) { for (i = 0; i < 6; i++) {
if (dir > DIR_LAST) if (dir > DIR_LAST)
dir -= 6; dir -= 6;
newx = new_x(capx[j] + diroff[dir][0]); newx = new_x(cap[j].x + diroff[dir][0]);
newy = new_y(capy[j] + diroff[dir][1]); newy = new_y(cap[j].y + diroff[dir][1]);
dir++; dir++;
if (iso(j, newx, newy) >= iso(j, capx[j], capy[j])) { if (iso(j, newx, newy) >= iso(j, cap[j].x, cap[j].y)) {
capx[j] = newx; cap[j].x = newx;
capy[j] = newy; cap[j].y = newy;
return; return;
} }
} }
@ -1117,13 +1120,13 @@ grow_continents(void)
for (c = 0; c < nc; ++c) { for (c = 0; c < nc; ++c) {
isecs[c] = 0; isecs[c] = 0;
if (!can_grow_at(c, capx[c], capy[c]) if (!can_grow_at(c, cap[c].x, cap[c].y)
|| !can_grow_at(c, new_x(capx[c] + 2), capy[c])) { || !can_grow_at(c, new_x(cap[c].x + 2), cap[c].y)) {
done = 0; done = 0;
continue; continue;
} }
add_sector(c, capx[c], capy[c]); add_sector(c, cap[c].x, cap[c].y);
add_sector(c, new_x(capx[c] + 2), capy[c]); add_sector(c, new_x(cap[c].x + 2), cap[c].y);
} }
if (!done) { if (!done) {
@ -1476,8 +1479,8 @@ output(void)
printf("%% "); printf("%% ");
else { else {
assert(0 <= c && c < nc); assert(0 <= c && c < nc);
if ((x == capx[c] || x == new_x(capx[c] + 2)) if ((x == cap[c].x || x == new_x(cap[c].x + 2))
&& y == capy[c]) && y == cap[c].y)
printf("%c ", numletter[c % 62]); printf("%c ", numletter[c % 62]);
else else
printf("# "); printf("# ");
@ -1655,7 +1658,7 @@ write_newcap_script(void)
for (c = 0; c < nc; ++c) { for (c = 0; c < nc; ++c) {
fprintf(script, "add %d %d %d p\n", c + 1, c + 1, c + 1); fprintf(script, "add %d %d %d p\n", c + 1, c + 1, c + 1);
fprintf(script, "newcap %d %d,%d\n", c + 1, capx[c], capy[c]); fprintf(script, "newcap %d %d,%d\n", c + 1, cap[c].x, cap[c].y);
} }
fprintf(script, "add %d visitor visitor v\n", c + 1); fprintf(script, "add %d visitor visitor v\n", c + 1);
fclose(script); fclose(script);