-/* Elevate land that is not mountain and not capital */
-
- for (i = 0; i < ns; ++i)
- dmoun[i] = distance_to_mountain();
- dk = (ns - nm - ((c < nc) ? 3 : 1) > 0) ?
- (100 * (HIGHMIN - LANDMIN)) / (ns - nm - ((c < nc) ? 3 : 1)) :
- 100 * INFINITE_ELEVATION;
- for (k = 100 * (HIGHMIN - 1);; k -= dk) {
- highest = 0;
- where = -1;
- for (i = 0; i < ns; ++i) {
- x = sectx[c][i];
- y = secty[c][i];
- if (elev[x][y] == -INFINITE_ELEVATION &&
- (c >= nc || ((!(capx[c] == sectx[c][i] &&
- capy[c] == secty[c][i])) &&
- (!(new_x(capx[c] + 2) == sectx[c][i] &&
- capy[c] == secty[c][i]))))) {
- h = 3 * (5 - dmoun[i]) + dsea[i];
- assert(h > 0);
- if (h > highest) {
- highest = h;
- where = i;
- }
- }
- }
- if (where == -1)
- break;
- newk = k / 100;
- if (newk >= HILLMIN && newk < PLATMIN)
- newk = PLATMIN;
- if (newk < LANDMIN)
- newk = LANDMIN;
- elev[sectx[c][where]][secty[c][where]] = newk;
+static void
+elevate_land(void)
+{
+ int *off = malloc(MAX(sc, is * 2) * sizeof(*off));
+ int max_nm = (pm * MAX(sc, is * 2)) / 100;
+ int c, nm, i0, n, i;
+ double elevation, delta;
+
+ for (c = 0; c < nc + ni; c++) {
+ nm = (pm * isecs[c]) / 100;
+ i0 = c < nc ? 2 : 0;
+ n = isecs[c] - i0;
+ for (i = 0; i < i0; i++)
+ elev[XYOFFSET(sectx[c][i], secty[c][i])] = PLATMIN;
+ for (i = 0; i < n; i++)
+ off[i] = XYOFFSET(sectx[c][i0 + i], secty[c][i0 + i]);
+ qsort(off, n, sizeof(*off), elev_cmp);
+ delta = (double)(HIGHMIN - LANDMIN - 1) / (n - nm - 1);
+ elevation = LANDMIN;
+ for (i = 0; i < n - nm; i++) {
+ elev[off[i]] = (int)(elevation + 0.5);
+ elevation += delta;