2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2020, Dave Pare, Jeff Bailey, Thomas Ruschak,
4 * Ken Stevens, Steve McClure, Markus Armbruster
6 * Empire is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 * See files README, COPYING and CREDITS in the root of the source
22 * tree for related information and legal notices. It is expected
23 * that future projects/authors will amend these files as needed.
27 * fairland.c: Create a nice, new world
29 * Known contributors to this file:
32 * Markus Armbruster, 2004-2020
37 /* define ORE 1 to add resources, define ORE 0 if you want to use another
38 program to add the resources */
42 /* If you don't specify these command line arguments, then these are the
44 #define DEFAULT_SPIKE 10
45 #define DEFAULT_MOUNTAIN 0
46 #define DEFAULT_CONTDIST 2
47 #define DEFAULT_ISLDIST 1
49 /* The following five numbers refer to elevation under which (in the case of
50 fertility or oil) or over which (in the case of iron, gold, and uranium)
51 sectors with that elevation will contain that resource. Elevation ranges
54 /* raise FERT_MAX for more fertility */
57 /* raise OIL_MAX for more oil */
60 /* lower IRON_MIN for more iron */
63 /* lower GOLD_MIN for more gold */
66 /* lower URAN_MIN for more uranium */
76 #include "prototypes.h"
81 /* do not change these 4 defines */
82 #define LANDMIN 1 /* plate altitude for normal land */
83 #define HILLMIN 34 /* plate altitude for hills */
84 #define PLATMIN 36 /* plate altitude for plateau */
85 #define HIGHMIN 98 /* plate altitude for mountains */
87 static void qprint(const char * const fmt, ...)
88 ATTRIBUTE((format (printf, 1, 2)));
90 #define DEFAULT_OUTFILE_NAME "newcap_script"
91 static const char *outfile = DEFAULT_OUTFILE_NAME;
92 /* mark the continents with a * so you can tell them
93 from the islands 1 = mark, 0 = don't mark. */
94 static int AIRPORT_MARKER = 0;
96 /* don't let the islands crash into each other.
97 1 = don't merge, 0 = merge. */
98 static int DISTINCT_ISLANDS = 1;
100 static char *program_name;
102 #define STABLE_CYCLE 4 /* stability required for perterbed capitals */
103 #define INFINITY 999 /* a number which means "BIG" */
105 /* these defines prevent infinite loops:
108 #define COAST_SEARCH_MAX 200 /* how many times do we look for a coast sector
109 when growing continents and islands */
110 #define DRIFT_BEFORE_CHECK ((WORLD_X + WORLD_Y)/2)
111 #define DRIFT_MAX ((WORLD_X + WORLD_Y)*2)
112 #define MOUNTAIN_SEARCH_MAX 1000 /* how long do we try to place mountains */
117 #define new_x(newx) (((newx) + WORLD_X) % WORLD_X)
118 #define new_y(newy) (((newy) + WORLD_Y) % WORLD_Y)
120 static int secs; /* number of sectors grown */
121 static int ctot; /* total number of continents and islands grown */
122 static int *isecs; /* array of how large each island is */
124 static int nc, sc, di, sp, pm, ni, is, id; /* the 8 args to this program */
125 static int *capx, *capy; /* location of the nc capitals */
126 static int *mc, mcc; /* array and counter used for stability
127 check when perturbing */
128 static int spike; /* are we spiking? */
129 static int mind; /* the final distance between capitals that
131 static int dirx[] = { -2, -1, 1, 2, 1, -1 }; /* gyujnb */
132 static int diry[] = { 0, -1, -1, 0, 1, 1 };
134 static int **own; /* owner of the sector. -1 means water */
135 static int **elev; /* elevation of the sectors */
136 static int **sectx, **secty; /* the sectors for each continent */
137 static int **sectc; /* which sectors are on the coast? */
138 static int *vector; /* used for measuring distances */
139 static int *weight; /* used for placing mountains */
140 static int *dsea, *dmoun; /* the dist to the ocean and mountain */
141 static int fl_status; /* is anything wrong? */
142 #define STATUS_NO_ROOM 1 /* there was no room to grow */
143 #define NUMTRIES 10 /* keep trying to grow this many times */
145 static const char *numletter =
146 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
148 static void help(char *);
149 static void usage(void);
150 static void parse_args(int argc, char *argv[]);
151 static void allocate_memory(void);
152 static void init(void);
153 static int drift(void);
154 static void grow_continents(void);
155 static void create_elevations(void);
156 static void write_sects(void);
157 static void output(void);
158 static int write_newcap_script(void);
159 static int stable(void);
160 static void elevate_land(void);
161 static void elevate_sea(void);
162 static int map_symbol(int x, int y);
163 static void set_coastal_flags(void);
165 static void print_vars(void);
166 static void fl_move(int);
167 static void grow_islands(void);
169 /* Debugging aids: */
170 void print_own_map(void);
171 void print_elev_map(void);
173 /****************************************************************************
175 ****************************************************************************/
178 main(int argc, char *argv[])
181 char *config_file = NULL;
183 unsigned rnd_seed = 0;
186 program_name = argv[0];
188 while ((opt = getopt(argc, argv, "ae:hioqR:s:v")) != EOF) {
194 config_file = optarg;
197 DISTINCT_ISLANDS = 0;
206 rnd_seed = strtoul(optarg, NULL, 10);
216 printf("%s\n\n%s", version, legal);
223 parse_args(argc - optind, argv + optind);
226 rnd_seed = pick_seed();
229 if (emp_config(config_file) < 0)
236 qprint("\n #*# ...fairland rips open a rift in the datumplane... #*#\n\n");
237 qprint("seed is %u\n", rnd_seed);
241 qprint("\ntry #%d (out of %d)...\n", i + 1, NUMTRIES);
242 qprint("placing capitals...\n");
244 qprint("fairland: unstable drift -- try increasing DRIFT_MAX\n");
245 qprint("growing continents...\n");
247 } while (fl_status && ++i < NUMTRIES);
249 fputs("ERROR: World not large enough to hold continents\n",
253 qprint("growing islands:");
255 qprint("\nelevating land...\n");
257 qprint("designating sectors...\n");
259 qprint("adding resources...\n");
260 write_newcap_script();
262 if (chdir(gamedir)) {
263 fprintf(stderr, "Can't chdir to %s (%s)\n", gamedir, strerror(errno));
266 if (!ef_open(EF_SECTOR, EFF_MEM | EFF_NOTIME))
269 qprint("writing to sectors file...\n");
270 if (!ef_close(EF_SECTOR))
274 qprint("\n\nA script for adding all the countries can be found in \"%s\".\n",
277 qprint("\t*** Resources have not been added ***\n");
286 puts("Creating a planet with:\n");
287 printf("%d continents\n", nc);
288 printf("continent size: %d\n", sc);
289 printf("number of islands: %d\n", ni);
290 printf("average size of islands: %d\n", is);
291 printf("spike: %d%%\n", sp);
292 printf("%d%% of land is mountain (each continent will have %d mountains)\n",
293 pm, (pm * sc) / 100);
294 printf("minimum distance between continents: %d\n", di);
295 printf("minimum distance from islands to continents: %d\n", id);
296 printf("World dimensions: %dx%d\n", WORLD_X, WORLD_Y);
304 for (i = 1; i * i < n * 10000; ++i) ;
305 return (i + 50) / 100;
308 /****************************************************************************
309 PARSE COMMAND LINE ARGUMENTS
310 ****************************************************************************/
313 help(char *complaint)
316 fprintf(stderr, "%s: %s\n", program_name, complaint);
317 fprintf(stderr, "Try -h for help.\n");
323 printf("Usage: %s [OPTION]... NC SC [NI] [IS] [SP] [PM] [DI] [ID]\n"
324 " -a airport marker for continents\n"
325 " -e CONFIG-FILE configuration file\n"
327 " -i islands may merge\n"
328 " -o don't set resources\n"
330 " -R SEED seed for random number generator\n"
331 " -s SCRIPT name of script to create (default %s)\n"
332 " -h display this help and exit\n"
333 " -v display version information and exit\n"
334 " NC number of continents\n"
335 " SC continent size\n"
336 " NI number of islands (default NC)\n"
337 " IS average island size (default SC/2)\n"
338 " SP spike percentage: 0 = round, 100 = snake (default %d)\n"
339 " PM percentage of land that is mountain (default %d)\n"
340 " DI minimum distance between continents (default %d)\n"
341 " ID minimum distance from islands to continents (default %d)\n",
342 program_name, dflt_econfig, DEFAULT_OUTFILE_NAME,
343 DEFAULT_SPIKE, DEFAULT_MOUNTAIN, DEFAULT_CONTDIST, DEFAULT_ISLDIST);
347 parse_args(int argc, char *argv[])
350 help("missing arguments");
354 help("too many arguments");
359 puts("fairland: error -- number of continents must be > 0");
365 puts("fairland: error -- size of continents must be > 0");
385 sp = LIMIT_TO(sp, 0, 100);
390 pm = DEFAULT_MOUNTAIN;
397 di = DEFAULT_CONTDIST;
400 puts("fairland: error -- distance between continents must be >= 0");
403 if (di > WORLD_X / 2 || di > WORLD_Y / 2) {
404 puts("fairland: error -- distance between continents too large");
411 id = DEFAULT_ISLDIST;
413 puts("fairland: error -- distance from islands to continents must be >= 0");
416 if (id > WORLD_X || id > WORLD_Y) {
417 puts("fairland: error -- distance from islands to continents too large");
420 if (nc * sc + nc * my_sqrt(sc) * 2 * (di + 1) > WORLD_X * WORLD_Y) {
421 puts("fairland: warning -- world might be too small to fit continents.");
422 puts("arguments should satisfy:");
423 puts("nc*sc*sc + nc*sqrt(sc)*2*(di+1) < WORLD_X * WORLD_Y");
427 /****************************************************************************
428 VARIABLE INITIALIZATION
429 ****************************************************************************/
432 allocate_memory(void)
436 capx = calloc(nc, sizeof(int));
437 capy = calloc(nc, sizeof(int));
438 vector = calloc(WORLD_X + WORLD_Y, sizeof(int));
439 mc = calloc(STABLE_CYCLE, sizeof(int));
440 own = calloc(WORLD_X, sizeof(int *));
441 elev = calloc(WORLD_X, sizeof(int *));
442 for (i = 0; i < WORLD_X; ++i) {
443 own[i] = calloc(WORLD_Y, sizeof(int));
444 elev[i] = calloc(WORLD_Y, sizeof(int));
446 sectx = calloc(nc + ni, sizeof(int *));
447 secty = calloc(nc + ni, sizeof(int *));
448 sectc = calloc(nc + ni, sizeof(int *));
449 isecs = calloc(nc + ni, sizeof(int));
450 weight = calloc(MAX(sc, is * 2), sizeof(int));
451 dsea = calloc(MAX(sc, is * 2), sizeof(int));
452 dmoun = calloc(MAX(sc, is * 2), sizeof(int));
453 for (i = 0; i < nc; ++i) {
454 sectx[i] = calloc(sc, sizeof(int));
455 secty[i] = calloc(sc, sizeof(int));
456 sectc[i] = calloc(sc, sizeof(int));
458 for (i = nc; i < nc + ni; ++i) {
459 sectx[i] = calloc(is * 2, sizeof(int));
460 secty[i] = calloc(is * 2, sizeof(int));
461 sectc[i] = calloc(is * 2, sizeof(int));
469 int i, j, xx = 0, yy = 0;
474 for (i = 0; i < WORLD_X; ++i) {
475 for (j = 0; j < WORLD_Y; ++j) {
477 elev[i][j] = -INFINITY;
481 for (i = 0; i < nc; ++i) {
486 puts("fairland error: world not big enough for all the continents.\n");
494 for (i = 0; i < STABLE_CYCLE; ++i)
498 /****************************************************************************
499 DRIFT THE CAPITALS UNTIL THEY ARE AS FAR AWAY FROM EACH OTHER AS POSSIBLE
500 ****************************************************************************/
502 /* How isolated is capital j?
505 iso(int j, int newx, int newy)
507 int i, md, d = WORLD_X + WORLD_Y;
509 for (i = 0; i < nc; ++i) {
512 md = mapdist(capx[i], capy[i], newx, newy);
520 /* Drift all the capitals
527 for (turns = 0; turns < DRIFT_MAX; ++turns) {
528 if (turns > DRIFT_BEFORE_CHECK && (mind = stable()))
530 for (i = 0; i < nc; ++i)
536 /* Check to see if we have stabilized--can we stop drifting the capitals?
542 int i, isod, d = 0, stab = 1;
544 for (i = 0; i < nc; ++i) {
545 isod = iso(i, capx[i], capy[i]);
549 for (i = 0; i < STABLE_CYCLE; ++i)
553 mcc = (mcc + 1) % STABLE_CYCLE;
557 /* This routine does the actual drifting
563 int i, n, newx, newy;
565 for (i = roll0(6), n = 0; n < 6; i = (i + 1) % 6, ++n) {
566 newx = new_x(capx[j] + dirx[i]);
567 newy = new_y(capy[j] + diry[i]);
568 if (iso(j, newx, newy) >= iso(j, capx[j], capy[j])) {
576 /****************************************************************************
578 ****************************************************************************/
580 /* Look for a coastal sector of continent c
588 for (i = 0; i < secs; ++i) {
590 for (j = 0; j < 6; ++j)
591 if (own[new_x(sectx[c][i] + dirx[j])][new_y(secty[c][i] + diry[j])] == -1)
596 /* Used for measuring distances
608 for (i = 1; i < n && vector[i] == vector[i - 1]; ++i) ;
611 return i > 1 || vector[0] > 0;
614 /* Test to see if we're allowed to grow there: the arguments di and id
617 try_to_grow(int c, int newx, int newy, int d)
621 for (i = 1; i <= d; ++i) {
622 for (j = 0; j < i; ++j)
627 for (j = 0; j < i; ++j) {
628 px = new_x(px + dirx[vector[j]]);
629 py = new_y(py + diry[vector[j]]);
631 if (own[px][py] != -1 &&
633 (DISTINCT_ISLANDS || own[px][py] < nc))
635 } while (next_vector(i));
637 sectx[c][secs] = newx;
638 secty[c][secs] = newy;
643 /* Move along the coast in a clockwise direction.
647 next_coast(int c, int x, int y, int *xp, int *yp)
649 int i, nx, ny, wat = 0;
657 for (i = 0; i < 12; ++i) {
658 nx = new_x(x + dirx[i % 6]);
659 ny = new_y(y + diry[i % 6]);
660 if (own[nx][ny] == -1)
662 if (wat && own[nx][ny] == c) {
670 /* Choose a sector to grow from
682 i = starti = (spike && sectc[c][secs - 1]) ? secs - 1 : roll0(secs);
687 } while (i != starti);
694 /* Grow continent c by 1 sector
698 grow_one_sector(int c)
700 int done, coast_search, try1, x, y, newx, newy, i, n, sx, sy;
702 spike = roll0(100) < sp;
703 if ((try1 = new_try(c)) == -1)
705 x = sx = sectx[c][try1];
706 y = sy = secty[c][try1];
711 for (i = roll0(6), n = 0; n < 12 && !done; i = (i + 1) % 6, ++n) {
712 newx = new_x(x + dirx[i]);
713 newy = new_y(y + diry[i]);
714 if (own[newx][newy] == -1 &&
716 (own[new_x(x+dirx[(i+5)%6])][new_y(y+diry[(i+5)%6])] == -1 &&
717 own[new_x(x+dirx[(i+1)%6])][new_y(y+diry[(i+1)%6])] == -1)))
718 if (try_to_grow(c, newx, newy, c < nc ? di : id))
722 for (i = roll0(6), n = 0; n < 6 && !done; i = (i + 1) % 6, ++n) {
723 newx = new_x(x + dirx[i]);
724 newy = new_y(y + diry[i]);
725 if (own[newx][newy] == -1)
726 if (try_to_grow(c, newx, newy, c < nc ? di : id))
729 next_coast(c, x, y, &x, &y);
731 } while (!done && coast_search < COAST_SEARCH_MAX &&
732 (secs == 1 || x != sx || y != sy));
733 if (!done && c < nc) {
734 qprint("fairland: error -- continent %c had no room to grow!\n",
736 fl_status |= STATUS_NO_ROOM;
741 /* Grow all the continents
744 grow_continents(void)
748 for (c = 0; c < nc; ++c) {
749 sectx[c][0] = capx[c];
750 secty[c][0] = capy[c];
751 own[sectx[c][0]][secty[c][0]] = c;
752 sectx[c][1] = new_x(capx[c] + 2);
753 secty[c][1] = capy[c];
754 own[sectx[c][1]][secty[c][1]] = c;
757 for (secs = 2; secs < sc && !fl_status; ++secs) {
758 for (c = 0; c < nc; ++c) {
763 for (c = 0; c < nc; ++c)
767 qprint("Only managed to grow %d out of %d sectors.\n", secs, sc);
771 /****************************************************************************
773 ****************************************************************************/
775 /* Choose a place to start growing an island from
778 place_island(int c, int *xp, int *yp)
781 int ssy = roll0(WORLD_Y);
782 int ssx = new_x(roll0(WORLD_X / 2) * 2 + ssy % 2);
784 if (ssx > WORLD_X - 2)
785 ssx = new_x(ssx + 2);
786 for (d = di + id; d >= id; --d) {
790 for (*yp = sy; *xp != sx || *yp != sy; *xp += 2) {
791 if (*xp >= WORLD_X) {
792 *yp = new_y(*yp + 1);
794 if (*xp == sx && *yp == sy)
797 if (own[*xp][*yp] == -1 && try_to_grow(c, *xp, *yp, d))
804 /* Grow all the islands
812 for (c = nc; c < nc + ni; ++c) {
814 if (!place_island(c, &x, &y))
816 isiz = roll(is) + roll0(is);
820 } while (secs < isiz && grow_one_sector(c));
822 qprint(" %d(%d)", c - nc + 1, secs);
828 /****************************************************************************
830 ****************************************************************************/
832 create_elevations(void)
838 /* Generic function for finding the distance to the closest sea, land, or
842 distance_to_what(int x, int y, int flag)
846 for (d = 1; d < 5; ++d) {
847 for (j = 0; j < d; ++j)
852 for (j = 0; j < d; ++j) {
853 px = new_x(px + dirx[vector[j]]);
854 py = new_y(py + diry[vector[j]]);
857 case 0: /* distance to sea */
858 if (own[px][py] == -1)
861 case 1: /* distance to land */
862 if (own[px][py] != -1)
865 case 2: /* distance to mountain */
866 if (elev[px][py] == INFINITY)
870 } while (next_vector(d));
875 #define ELEV elev[sectx[c][i]][secty[c][i]]
876 #define distance_to_sea() (sectc[c][i]?1:distance_to_what(sectx[c][i], secty[c][i], 0))
877 #define distance_to_mountain() distance_to_what(sectx[c][i], secty[c][i], 2)
879 /* Decide where the mountains go
884 int i, mountain_search, k, c, total, ns, nm, highest, where, h, newk,
887 for (c = 0; c < ctot; ++c) {
889 ns = (c < nc) ? sc : isecs[c];
890 nm = (pm * ns) / 100;
892 /* Place the mountains */
894 for (i = 0; i < ns; ++i) {
895 dsea[i] = distance_to_sea();
896 weight[i] = (total += (dsea[i] * dsea[i]));
899 for (k = nm, mountain_search = 0;
900 k && mountain_search < MOUNTAIN_SEARCH_MAX;
903 for (i = 0; i < ns; ++i)
904 if (r < weight[i] && ELEV == -INFINITY &&
906 ((!(capx[c] == sectx[c][i] &&
907 capy[c] == secty[c][i])) &&
908 (!(new_x(capx[c] + 2) == sectx[c][i] &&
909 capy[c] == secty[c][i]))))) {
916 /* Elevate land that is not mountain and not capital */
918 for (i = 0; i < ns; ++i)
919 dmoun[i] = distance_to_mountain();
920 dk = (ns - nm - ((c < nc) ? 3 : 1) > 0) ?
921 (100 * (HIGHMIN - LANDMIN)) / (ns - nm - ((c < nc) ? 3 : 1)) :
923 for (k = 100 * (HIGHMIN - 1);; k -= dk) {
926 for (i = 0; i < ns; ++i) {
927 if (ELEV != INFINITY &&
928 (c >= nc || ((!(capx[c] == sectx[c][i] &&
929 capy[c] == secty[c][i])) &&
930 (!(new_x(capx[c] + 2) == sectx[c][i] &&
931 capy[c] == secty[c][i]))))) {
932 h = 3 * (5 - dmoun[i]) + dsea[i];
942 if (newk >= HILLMIN && newk < PLATMIN)
946 elev[sectx[c][where]][secty[c][where]] = newk;
947 dsea[where] = -INFINITY;
948 dmoun[where] = INFINITY;
951 /* Elevate the mountains and capitals */
953 for (i = 0; i < ns; ++i) {
954 if (ELEV == INFINITY) {
956 ELEV = HILLMIN + roll0(PLATMIN - HILLMIN);
958 ELEV = HIGHMIN + roll0((256 - HIGHMIN) / 2) +
959 roll0((256 - HIGHMIN) / 2);
961 (((capx[c] == sectx[c][i] && capy[c] == secty[c][i])) ||
962 ((new_x(capx[c] + 2) == sectx[c][i] &&
963 capy[c] == secty[c][i]))))
969 #define distance_to_land() distance_to_what(x, y, 1)
976 for (y = 0; y < WORLD_Y; ++y) {
977 for (x = y % 2; x < WORLD_X; x += 2) {
978 if (elev[x][y] == -INFINITY)
979 elev[x][y] = -roll(distance_to_land() * 20 + 27);
984 /****************************************************************************
986 ****************************************************************************/
993 fert = LANDMIN - e + 40;
994 else if (e < FERT_MAX)
995 fert = (120 * (FERT_MAX - e)) / (FERT_MAX - LANDMIN);
1006 oil = (LANDMIN - e) * 2 + roll0(2);
1007 else if (e <= OIL_MAX)
1008 oil = (120 * (OIL_MAX - e + 1)) / (OIL_MAX - LANDMIN + 1);
1018 if (e >= IRON_MIN && e < HIGHMIN)
1019 iron = (120 * (e - IRON_MIN + 1)) / (HIGHMIN - IRON_MIN);
1029 if (e >= GOLD_MIN) {
1031 gold = (80 * (e - GOLD_MIN + 1)) / (HIGHMIN - GOLD_MIN);
1033 gold = 100 - 20 * HIGHMIN / e;
1044 if (e >= URAN_MIN && e < HIGHMIN)
1045 uran = (120 * (e - URAN_MIN + 1)) / (HIGHMIN - URAN_MIN);
1052 add_resources(struct sctstr *sct)
1054 sct->sct_fertil = set_fert(sct->sct_elev);
1055 sct->sct_oil = set_oil(sct->sct_elev);
1056 sct->sct_min = set_iron(sct->sct_elev);
1057 sct->sct_gmin = set_gold(sct->sct_elev);
1058 sct->sct_uran = set_uran(sct->sct_elev);
1061 /****************************************************************************
1062 DESIGNATE THE SECTORS
1063 ****************************************************************************/
1071 for (y = 0; y < WORLD_Y; y++) {
1072 for (x = y % 2; x < WORLD_X; x += 2) {
1073 sct = getsectp(x, y);
1075 if (total < LANDMIN) {
1076 sct->sct_type = SCT_WATER;
1077 } else if (total < HILLMIN)
1078 sct->sct_type = SCT_RURAL;
1079 else if (total < PLATMIN)
1080 sct->sct_type = SCT_MOUNT;
1081 else if (total < HIGHMIN)
1082 sct->sct_type = SCT_RURAL;
1084 sct->sct_type = SCT_MOUNT;
1085 sct->sct_elev = total;
1086 sct->sct_newtype = sct->sct_type;
1087 sct->sct_dterr = own[sct->sct_x][y] + 1;
1093 for (c = 0; c < nc; ++c) {
1094 sct = getsectp(capx[c], capy[c]);
1095 sct->sct_type = SCT_AIRPT;
1096 sct->sct_newtype = SCT_AIRPT;
1098 set_coastal_flags();
1101 /****************************************************************************
1102 PRINT A PICTURE OF THE MAP TO YOUR SCREEN
1103 ****************************************************************************/
1110 for (sy = -WORLD_Y / 2; sy < WORLD_Y / 2; sy++) {
1115 for (sx = -WORLD_X / 2 + y % 2; sx < WORLD_X / 2; sx += 2) {
1117 if (own[x][y] == -1)
1120 printf("%c ", map_symbol(x, y));
1126 printf("\n\nEach continent is marked by a \"*\" on the map (to distinguish them from\n"
1127 "the islands). You can redesignate these airfields to wilderness sectors\n"
1128 "one at a time, each time you add a new country to the game.\n");
1132 map_symbol(int x, int y)
1136 for (c = 0; c < nc; ++c)
1137 if ((x == capx[c] && y == capy[c])
1138 || (x == new_x(capx[c] + 2) && y == capy[c]))
1139 return numletter[own[x][y] % 62];
1140 if ((elev[x][y] >= HILLMIN && elev[x][y] < PLATMIN)
1141 || elev[x][y] >= HIGHMIN)
1143 return own[x][y] >= nc ? '%' : '#';
1147 * Print a map to help visualize own[][].
1148 * This is for debugging.
1155 for (sy = -WORLD_Y / 2; sy < WORLD_Y / 2; sy++) {
1158 for (sx = -WORLD_X / 2; sx < WORLD_X / 2; sx++) {
1162 else if (own[x][y] == -1)
1165 putchar(numletter[own[x][y] % 62]);
1172 * Print a map to help visualize elev[][].
1173 * This is for debugging. It expects the terminal to understand
1174 * 24-bit color escape sequences \e[48;2;$red;$green;$blue;m.
1177 print_elev_map(void)
1179 int sx, sy, x, y, sat;
1181 for (sy = -WORLD_Y / 2; sy < WORLD_Y / 2; sy++) {
1184 for (sx = -WORLD_X / 2; sx < WORLD_X / 2; sx++) {
1188 else if (!elev[x][y])
1190 else if (elev[x][y] < 0) {
1191 sat = 256 + elev[x][y] * 2;
1192 printf("\033[48;2;%d;%d;%dm \033[0m", sat, sat, 255);
1193 } else if (elev[x][y] < HIGHMIN / 2) {
1194 sat = (HIGHMIN / 2 - elev[x][y]) * 4;
1195 printf("\033[48;2;%d;%d;%dm \033[0m", sat, 255, sat);
1196 } else if (elev[x][y] < HIGHMIN) {
1197 sat = 128 + (HIGHMIN - elev[x][y]) * 2;
1198 printf("\033[48;2;%d;%d;%dm \033[0m", sat, sat / 2, sat / 4);
1200 sat = 128 + (elev[x][y] - HIGHMIN) * 4 / 5;
1201 printf("\033[48;2;%d;%d;%dm^\033[0m", sat, sat, sat);
1208 /***************************************************************************
1209 WRITE A SCRIPT FOR PLACING CAPITALS
1210 ****************************************************************************/
1212 write_newcap_script(void)
1215 FILE *script = fopen(outfile, "w");
1218 printf("fairland: error, unable to write to %s.\n", outfile);
1222 for (c = 0; c < nc; ++c) {
1223 fprintf(script, "add %d %d %d p\n", c + 1, c + 1, c + 1);
1225 fprintf(script, "des %d,%d -\n", capx[c], capy[c]);
1226 fprintf(script, "newcap %d %d,%d\n", c + 1, capx[c], capy[c]);
1228 fprintf(script, "add %d visitor visitor v\n", c + 1);
1234 qprint(const char *const fmt, ...)
1240 vfprintf(stdout, fmt, ap);
1246 set_coastal_flags(void)
1251 qprint("setting coastal flags...\n");
1252 for (i = 0; i < nc; ++i) {
1253 for (j = 0; j < sc; j++) {
1254 sp = getsectp(sectx[i][j], secty[i][j]);
1255 sp->sct_coastal = sectc[i][j];
1258 for (i = nc; i < nc + ni; ++i) {
1259 for (j = 0; j < isecs[i]; j++) {
1260 sp = getsectp(sectx[i][j], secty[i][j]);
1261 sp->sct_coastal = sectc[i][j];