/*
* Closest continent and "distance"
* closest[XYOFFSET(x, y)] is the closest continent's number.
- * distance[] is complicated; see init_spheres_of_influence().
+ * distance[] is complicated; see init_spheres_of_influence() and
+ * init_distance_to_coast().
*/
static natid *closest;
static unsigned short *distance;
bfs_run_queue();
}
+/*
+ * Precompute distance to coast
+ * Set distance[XYOFFSET(x, y)] to the distance to the closest coastal
+ * land sector.
+ * Set closest[XYOFFSET(x, y)] to the closest continent's number,
+ * -1 if no single continent is closest.
+ */
+static void
+init_distance_to_coast(void)
+{
+ int c;
+
+ bfs_init();
+ for (c = 0; c < nc + ni; c++)
+ bfs_enqueue_island(c);
+ bfs_run_queue();
+}
+
/*
* Is @x,@y in the same sphere of influence as island @c?
* Always true when @c is a continent.
for (j = 0; j < WORLD_Y; j++)
elev[i][j] = -INFINITE_ELEVATION;
}
+ init_distance_to_coast();
elevate_land();
elevate_sea();
}
return d;
}
-#define distance_to_sea() (sectc[c][i]?1:distance_to_what(sectx[c][i], secty[c][i], 0))
#define distance_to_mountain() distance_to_what(sectx[c][i], secty[c][i], 2)
/* Decide where the mountains go
static void
elevate_land(void)
{
- int i, mountain_search, k, c, total, ns, nm, r, x, y;
+ int i, off, mountain_search, k, c, total, ns, nm, r, x, y;
int highest, where, h, newk, dk;
for (c = 0; c < nc + ni; ++c) {
/* Place the mountains */
for (i = 0; i < ns; ++i) {
- dsea[i] = distance_to_sea();
+ off = XYOFFSET(sectx[c][i], secty[c][i]);
+ dsea[i] = MIN(5, distance[off] + 1);
weight[i] = (total += (dsea[i] * dsea[i]));
}
}
}
-#define distance_to_land() distance_to_what(x, y, 1)
-
static void
elevate_sea(void)
{
- int x, y;
+ int x, y, off;
for (y = 0; y < WORLD_Y; ++y) {
for (x = y % 2; x < WORLD_X; x += 2) {
+ off = XYOFFSET(x, y);
if (elev[x][y] == -INFINITE_ELEVATION)
- elev[x][y] = -roll(distance_to_land() * 20 + 27);
+ elev[x][y] = -roll(MIN(5, distance[off]) * 20 + 27);
}
}
}