2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2013, 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-2012
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 */
77 #include "prototypes.h"
82 /* do not change these 4 defines */
83 #define LANDMIN 1 /* plate altitude for normal land */
84 #define HILLMIN 34 /* plate altitude for hills */
85 #define PLATMIN 36 /* plate altitude for plateau */
86 #define HIGHMIN 98 /* plate altitude for mountains */
88 static void qprint(const char * const fmt, ...)
89 ATTRIBUTE((format (printf, 1, 2)));
91 #define DEFAULT_OUTFILE_NAME "newcap_script"
92 static const char *outfile = DEFAULT_OUTFILE_NAME;
93 /* mark the continents with a * so you can tell them
94 from the islands 1 = mark, 0 = don't mark. */
95 static int AIRPORT_MARKER = 0;
97 /* don't let the islands crash into each other.
98 1 = don't merge, 0 = merge. */
99 static int DISTINCT_ISLANDS = 1;
101 static char *program_name;
103 #define STABLE_CYCLE 4 /* stability required for perterbed capitals */
104 #define INFINITY 999 /* a number which means "BIG" */
106 /* these defines prevent infinite loops:
109 #define COAST_SEARCH_MAX 200 /* how many times do we look for a coast sector
110 when growing continents and islands */
111 #define DRIFT_BEFORE_CHECK ((WORLD_X + WORLD_Y)/2)
112 #define DRIFT_MAX ((WORLD_X + WORLD_Y)*2)
113 #define MOUNTAIN_SEARCH_MAX 1000 /* how long do we try to place mountains */
118 #define new_x(newx) (((newx) + WORLD_X) % WORLD_X)
119 #define new_y(newy) (((newy) + WORLD_Y) % WORLD_Y)
120 #define rnd(x) roll0((x))
122 static int secs; /* number of sectors grown */
123 static int ctot; /* total number of continents and islands grown */
124 static int *isecs; /* array of how large each island is */
126 static int nc, sc, di, sp, pm, ni, is, id; /* the 8 args to this program */
127 static unsigned long rnd_seed; /* optional seed argument */
128 static int *capx, *capy; /* location of the nc capitals */
129 static int *mc, mcc; /* array and counter used for stability
130 check when perturbing */
131 static int spike; /* are we spiking? */
132 static int mind; /* the final distance between capitals that
134 static int dirx[] = { -2, -1, 1, 2, 1, -1 }; /* gyujnb */
135 static int diry[] = { 0, -1, -1, 0, 1, 1 };
137 static int **own; /* owner of the sector. -1 means water */
138 static int **elev; /* elevation of the sectors */
139 static int **sectx, **secty; /* the sectors for each continent */
140 static int **sectc; /* which sectors are on the coast? */
141 static int *vector; /* used for measuring distances */
142 static int *weight; /* used for placing mountains */
143 static int *dsea, *dmoun; /* the dist to the ocean and mountain */
144 static int fl_status; /* is anything wrong? */
145 #define STATUS_NO_ROOM 1 /* there was no room to grow */
146 #define NUMTRIES 10 /* keep trying to grow this many times */
148 static const char *numletter =
149 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
151 static void help(char *);
152 static void usage(void);
153 static void parse_args(int argc, char *argv[]);
154 static void allocate_memory(void);
155 static void init(void);
156 static int drift(void);
157 static void grow_continents(void);
158 static void create_elevations(void);
159 static void write_sects(void);
160 static void output(void);
161 static int write_newcap_script(void);
162 static int stable(void);
163 static void elevate_land(void);
164 static void elevate_sea(void);
165 static int map_symbol(int x, int y);
166 static void set_coastal_flags(void);
168 static void print_vars(void);
169 static void fl_move(int);
170 static void next_coast(int c, int x, int y, int *xp, int *yp);
171 static void grow_islands(void);
173 /****************************************************************************
175 ****************************************************************************/
178 main(int argc, char *argv[])
181 char *config_file = NULL;
184 program_name = argv[0];
185 rnd_seed = time(NULL);
187 while ((opt = getopt(argc, argv, "ae:hioqR:s:v")) != EOF) {
193 config_file = optarg;
196 DISTINCT_ISLANDS = 0;
205 rnd_seed = strtoul(optarg, NULL, 10);
214 printf("%s\n\n%s", version, legal);
221 parse_args(argc - optind, argv + optind);
225 if (emp_config(config_file) < 0)
235 qprint("\ntry #%d (out of %d)...", i + 1, NUMTRIES);
236 qprint("\n\n #*# ...fairland rips open a rift in the datumplane... #*#\n\n");
237 qprint("seed is %lu\n", rnd_seed);
238 qprint("placing capitals...\n");
240 qprint("fairland: unstable drift -- try increasisg DRIFT_MAX\n");
241 qprint("growing continents...\n");
243 } while (fl_status && ++i < NUMTRIES);
245 fputs("ERROR: World not large enough to hold continents\n",
249 qprint("growing islands:");
251 qprint("\nelevating land...\n");
253 qprint("designating sectors...\n");
255 qprint("adding resources...\n");
256 write_newcap_script();
258 if (chdir(gamedir)) {
259 fprintf(stderr, "Can't chdir to %s (%s)\n", gamedir, strerror(errno));
262 if (!ef_open(EF_SECTOR, EFF_MEM | EFF_NOTIME))
265 qprint("writing to sectors file...\n");
266 if (!ef_close(EF_SECTOR))
270 qprint("\n\nA script for adding all the countries can be found in \"%s\".\n",
273 qprint("\t*** Resources have not been added ***\n");
282 puts("Creating a planet with:\n");
283 printf("%d continents\n", nc);
284 printf("continent size: %d\n", sc);
285 printf("number of islands: %d\n", ni);
286 printf("average size of islands: %d\n", is);
287 printf("spike: %d%%\n", sp);
288 printf("%d%% of land is mountain (each continent will have %d mountains)\n",
289 pm, (pm * sc) / 100);
290 printf("minimum distance between continents: %d\n", di);
291 printf("minimum distance from islands to continents: %d\n", id);
292 printf("World dimensions: %dx%d\n", WORLD_X, WORLD_Y);
300 for (i = 1; i * i < n * 10000; ++i) ;
301 return (i + 50) / 100;
304 /****************************************************************************
305 PARSE COMMAND LINE ARGUMENTS
306 ****************************************************************************/
309 help(char *complaint)
312 fprintf(stderr, "%s: %s\n", program_name, complaint);
313 fprintf(stderr, "Try -h for help.\n");
319 printf("Usage: %s [OPTION]... NC SC [NI] [IS] [SP] [PM] [DI] [ID]\n"
320 " -a airport marker for continents\n"
321 " -e CONFIG-FILE configuration file\n"
323 " -h display this help and exit\n"
324 " -i islands may merge\n"
325 " -o don't set resources\n"
327 " -R SEED seed for random number generator\n"
328 " -s SCRIPT name of script to create (default %s)\n"
329 " NC number of continents\n"
330 " SC continent size\n"
331 " NI number of islands (default NC)\n"
332 " IS average island size (default SC/2)\n"
333 " SP spike percentage: 0 = round, 100 = snake (default %d)\n"
334 " PM percentage of land that is mountain (default %d)\n"
335 " DI minimum distance between continents (default %d)\n"
336 " ID minimum distance from islands to continents (default %d)\n",
337 program_name, dflt_econfig, DEFAULT_OUTFILE_NAME,
338 DEFAULT_SPIKE, DEFAULT_MOUNTAIN, DEFAULT_CONTDIST, DEFAULT_ISLDIST);
342 parse_args(int argc, char *argv[])
345 help("missing arguments");
349 help("too many arguments");
354 puts("fairland: error -- number of continents must be > 0");
360 puts("fairland: error -- size of continents must be > 0");
388 pm = DEFAULT_MOUNTAIN;
395 di = DEFAULT_CONTDIST;
398 puts("fairland: error -- distance between continents must be >= 0");
401 if (di > WORLD_X / 2 || di > WORLD_Y / 2) {
402 puts("fairland: error -- distance between continents too large");
409 id = DEFAULT_ISLDIST;
411 puts("fairland: error -- distance from islands to continents must be >= 0");
414 if (id > WORLD_X || id > WORLD_Y) {
415 puts("fairland: error -- distance from islands to continents too large");
418 if (nc * sc + nc * my_sqrt(sc) * 2 * (di + 1) > WORLD_X * WORLD_Y) {
419 puts("fairland: warning -- world might be too small to fit continents.");
420 puts("arguments should satisfy:");
421 puts("nc*sc*sc + nc*sqrt(sc)*2*(di+1) < WORLD_X * WORLD_Y");
425 /****************************************************************************
426 VARIABLE INITIALIZATION
427 ****************************************************************************/
430 allocate_memory(void)
434 capx = calloc(nc, sizeof(int));
435 capy = calloc(nc, sizeof(int));
436 vector = calloc(WORLD_X + WORLD_Y, sizeof(int));
437 mc = calloc(STABLE_CYCLE, sizeof(int));
438 own = calloc(WORLD_X, sizeof(int *));
439 elev = calloc(WORLD_X, sizeof(int *));
440 for (i = 0; i < WORLD_X; ++i) {
441 own[i] = calloc(WORLD_Y, sizeof(int));
442 elev[i] = calloc(WORLD_Y, sizeof(int));
444 sectx = calloc(nc + ni, sizeof(int *));
445 secty = calloc(nc + ni, sizeof(int *));
446 sectc = calloc(nc + ni, sizeof(int *));
447 isecs = calloc(nc + ni, sizeof(int));
448 weight = calloc(MAX(sc, is * 2), sizeof(int));
449 dsea = calloc(MAX(sc, is * 2), sizeof(int));
450 dmoun = calloc(MAX(sc, is * 2), sizeof(int));
451 for (i = 0; i < nc; ++i) {
452 sectx[i] = calloc(sc, sizeof(int));
453 secty[i] = calloc(sc, sizeof(int));
454 sectc[i] = calloc(sc, sizeof(int));
456 for (i = nc; i < nc + ni; ++i) {
457 sectx[i] = calloc(is * 2, sizeof(int));
458 secty[i] = calloc(is * 2, sizeof(int));
459 sectc[i] = calloc(is * 2, sizeof(int));
467 int i, j, xx = 0, yy = 0;
472 for (i = 0; i < WORLD_X; ++i) {
473 for (j = 0; j < WORLD_Y; ++j) {
475 elev[i][j] = -INFINITY;
479 for (i = 0; i < nc; ++i) {
484 puts("fairland error: world not big enough for all the continents.\n");
492 for (i = 0; i < STABLE_CYCLE; ++i)
496 /****************************************************************************
497 DRIFT THE CAPITALS UNTIL THEY ARE AS FAR AWAY FROM EACH OTHER AS POSSIBLE
498 ****************************************************************************/
500 /* How isolated is capital j?
503 iso(int j, int newx, int newy)
505 int i, md, d = WORLD_X + WORLD_Y;
507 for (i = 0; i < nc; ++i) {
510 md = mapdist(capx[i], capy[i], newx, newy);
518 /* Drift all the capitals
525 for (turns = 0; turns < DRIFT_MAX; ++turns) {
526 if (turns > DRIFT_BEFORE_CHECK && (mind = stable()))
528 for (i = 0; i < nc; ++i)
534 /* Check to see if we have stabilized--can we stop drifting the capitals?
540 int i, isod, d = 0, stab = 1;
542 for (i = 0; i < nc; ++i) {
543 isod = iso(i, capx[i], capy[i]);
547 for (i = 0; i < STABLE_CYCLE; ++i)
551 mcc = (mcc + 1) % STABLE_CYCLE;
555 /* This routine does the actual drifting
561 int i, n, newx, newy;
563 for (i = rnd(6), n = 0; n < 6; i = (i + 1) % 6, ++n) {
564 newx = new_x(capx[j] + dirx[i]);
565 newy = new_y(capy[j] + diry[i]);
566 if (iso(j, newx, newy) >= iso(j, capx[j], capy[j])) {
574 /****************************************************************************
576 ****************************************************************************/
578 /* Look for a coastal sector of continent c
586 for (i = 0; i < secs; ++i) {
588 for (j = 0; j < 6; ++j)
589 if (own[new_x(sectx[c][i] + dirx[j])][new_y(secty[c][i] + diry[j])] == -1)
594 /* Used for measuring distances
606 for (i = 1; i < n && vector[i] == vector[i - 1]; ++i) ;
609 return i > 1 || vector[0] > 0;
612 /* Test to see if we're allowed to grow there: the arguments di and id
615 try_to_grow(int c, int newx, int newy, int d)
619 for (i = 1; i <= d; ++i) {
620 for (j = 0; j < i; ++j)
625 for (j = 0; j < i; ++j) {
626 px = new_x(px + dirx[vector[j]]);
627 py = new_y(py + diry[vector[j]]);
629 if (own[px][py] != -1 &&
631 (DISTINCT_ISLANDS || own[px][py] < nc))
633 } while (next_vector(i));
635 sectx[c][secs] = newx;
636 secty[c][secs] = newy;
641 /* Move along the coast in a clockwise direction.
645 next_coast(int c, int x, int y, int *xp, int *yp)
647 int i, nx, ny, wat = 0;
655 for (i = 0; i < 12; ++i) {
656 nx = new_x(x + dirx[i % 6]);
657 ny = new_y(y + diry[i % 6]);
658 if (own[nx][ny] == -1)
660 if (wat && own[nx][ny] == c) {
668 /* Choose a sector to grow from
680 i = starti = (spike && sectc[c][secs - 1]) ? secs - 1 : rnd(secs);
685 } while (i != starti);
692 /* Grow continent c by 1 sector
696 grow_one_sector(int c)
698 int done, coast_search, try1, x, y, newx, newy, i, n, sx, sy;
700 spike = rnd(100) < sp;
701 if ((try1 = new_try(c)) == -1)
703 x = sx = sectx[c][try1];
704 y = sy = secty[c][try1];
709 for (i = rnd(6), n = 0; n < 12 && !done; i = (i + 1) % 6, ++n) {
710 newx = new_x(x + dirx[i]);
711 newy = new_y(y + diry[i]);
712 if (own[newx][newy] == -1 &&
714 (own[new_x(x+dirx[(i+5)%6])][new_y(y+diry[(i+5)%6])] == -1 &&
715 own[new_x(x+dirx[(i+1)%6])][new_y(y+diry[(i+1)%6])] == -1)))
716 if (try_to_grow(c, newx, newy, c < nc ? di : id))
720 for (i = rnd(6), n = 0; n < 6 && !done; i = (i + 1) % 6, ++n) {
721 newx = new_x(x + dirx[i]);
722 newy = new_y(y + diry[i]);
723 if (own[newx][newy] == -1)
724 if (try_to_grow(c, newx, newy, c < nc ? di : id))
727 next_coast(c, x, y, &x, &y);
729 } while (!done && coast_search < COAST_SEARCH_MAX &&
730 (secs == 1 || x != sx || y != sy));
731 if (!done && c < nc) {
732 qprint("fairland: error -- continent %c had no room to grow!\n",
734 fl_status |= STATUS_NO_ROOM;
739 /* Grow all the continents
742 grow_continents(void)
746 for (c = 0; c < nc; ++c) {
747 sectx[c][0] = capx[c];
748 secty[c][0] = capy[c];
749 own[sectx[c][0]][secty[c][0]] = c;
750 sectx[c][1] = new_x(capx[c] + 2);
751 secty[c][1] = capy[c];
752 own[sectx[c][1]][secty[c][1]] = c;
755 for (secs = 2; secs < sc && !fl_status; ++secs) {
756 for (c = 0; c < nc; ++c) {
761 for (c = 0; c < nc; ++c)
765 qprint("Only managed to grow %d out of %d sectors.\n", secs, sc);
769 /****************************************************************************
771 ****************************************************************************/
773 /* Choose a place to start growing an island from
776 place_island(int c, int *xp, int *yp)
779 int ssy = rnd(WORLD_Y);
780 int ssx = new_x(rnd(WORLD_X / 2) * 2 + ssy % 2);
782 if (ssx > WORLD_X - 2)
783 ssx = new_x(ssx + 2);
784 for (d = di + id; d >= id; --d) {
788 for (*yp = sy; *xp != sx || *yp != sy; *xp += 2) {
789 if (*xp >= WORLD_X) {
790 *yp = new_y(*yp + 1);
792 if (*xp == sx && *yp == sy)
795 if (own[*xp][*yp] == -1 && try_to_grow(c, *xp, *yp, d))
802 /* Grow all the islands
810 for (c = nc; c < nc + ni; ++c) {
812 if (!place_island(c, &x, &y))
814 isiz = 1 + rnd(2 * is - 1);
818 } while (secs < isiz && grow_one_sector(c));
820 qprint(" %d(%d)", c - nc + 1, secs);
826 /****************************************************************************
828 ****************************************************************************/
830 create_elevations(void)
836 /* Generic function for finding the distance to the closest sea, land, or
840 distance_to_what(int x, int y, int flag)
844 for (d = 1; d < 5; ++d) {
845 for (j = 0; j < d; ++j)
850 for (j = 0; j < d; ++j) {
851 px = new_x(px + dirx[vector[j]]);
852 py = new_y(py + diry[vector[j]]);
855 case 0: /* distance to sea */
856 if (own[px][py] == -1)
859 case 1: /* distance to land */
860 if (own[px][py] != -1)
863 case 2: /* distance to mountain */
864 if (elev[px][py] == INFINITY)
868 } while (next_vector(d));
873 #define ELEV elev[sectx[c][i]][secty[c][i]]
874 #define distance_to_sea() (sectc[c][i]?1:distance_to_what(sectx[c][i], secty[c][i], 0))
875 #define distance_to_mountain() distance_to_what(sectx[c][i], secty[c][i], 2)
877 /* Decide where the mountains go
882 int i, mountain_search, k, c, total, ns, nm, highest, where, h, newk,
885 for (c = 0; c < ctot; ++c) {
887 ns = (c < nc) ? sc : isecs[c];
888 nm = (pm * ns) / 100;
890 /* Place the mountains */
892 for (i = 0; i < ns; ++i) {
893 dsea[i] = distance_to_sea();
894 weight[i] = (total += (dsea[i] * dsea[i]));
897 for (k = nm, mountain_search = 0;
898 k && mountain_search < MOUNTAIN_SEARCH_MAX;
901 for (i = 0; i < ns; ++i)
902 if (r < weight[i] && ELEV == -INFINITY &&
904 ((!(capx[c] == sectx[c][i] &&
905 capy[c] == secty[c][i])) &&
906 (!(new_x(capx[c] + 2) == sectx[c][i] &&
907 capy[c] == secty[c][i]))))) {
914 /* Elevate land that is not mountain and not capital */
916 for (i = 0; i < ns; ++i)
917 dmoun[i] = distance_to_mountain();
918 dk = (ns - nm - ((c < nc) ? 3 : 1) > 0) ?
919 (100 * (HIGHMIN - LANDMIN)) / (ns - nm - ((c < nc) ? 3 : 1)) :
921 for (k = 100 * (HIGHMIN - 1);; k -= dk) {
924 for (i = 0; i < ns; ++i) {
925 if (ELEV != INFINITY &&
926 (c >= nc || ((!(capx[c] == sectx[c][i] &&
927 capy[c] == secty[c][i])) &&
928 (!(new_x(capx[c] + 2) == sectx[c][i] &&
929 capy[c] == secty[c][i]))))) {
930 h = 3 * (5 - dmoun[i]) + dsea[i];
940 if (newk >= HILLMIN && newk < PLATMIN)
944 elev[sectx[c][where]][secty[c][where]] = newk;
945 dsea[where] = -INFINITY;
946 dmoun[where] = INFINITY;
949 /* Elevate the mountains and capitals */
951 for (i = 0; i < ns; ++i) {
952 if (ELEV == INFINITY) {
954 ELEV = HILLMIN + rnd(PLATMIN - HILLMIN);
956 ELEV = HIGHMIN + rnd((256 - HIGHMIN) / 2) +
957 rnd((256 - HIGHMIN) / 2);
959 (((capx[c] == sectx[c][i] && capy[c] == secty[c][i])) ||
960 ((new_x(capx[c] + 2) == sectx[c][i] &&
961 capy[c] == secty[c][i]))))
967 #define distance_to_land() distance_to_what(x, y, 1)
974 for (y = 0; y < WORLD_Y; ++y) {
975 for (x = y % 2; x < WORLD_X; x += 2) {
976 if (elev[x][y] == -INFINITY)
977 elev[x][y] = -rnd((distance_to_land() * 20 + 27)) - 1;
982 /****************************************************************************
984 ****************************************************************************/
991 fert = LANDMIN - e + 40;
992 else if (e < FERT_MAX)
993 fert = (120 * (FERT_MAX - e)) / (FERT_MAX - LANDMIN);
1004 oil = (LANDMIN - e) * 2 + rnd(2);
1005 else if (e <= OIL_MAX)
1006 oil = (120 * (OIL_MAX - e + 1)) / (OIL_MAX - LANDMIN + 1);
1016 if (e >= IRON_MIN && e < HIGHMIN)
1017 iron = (120 * (e - IRON_MIN + 1)) / (HIGHMIN - IRON_MIN);
1027 if (e >= GOLD_MIN) {
1029 gold = (80 * (e - GOLD_MIN + 1)) / (HIGHMIN - GOLD_MIN);
1031 gold = 100 - 20 * HIGHMIN / e;
1042 if (e >= URAN_MIN && e < HIGHMIN)
1043 uran = (120 * (e - URAN_MIN + 1)) / (HIGHMIN - URAN_MIN);
1050 add_resources(struct sctstr *sct)
1052 sct->sct_fertil = set_fert(sct->sct_elev);
1053 sct->sct_oil = set_oil(sct->sct_elev);
1054 sct->sct_min = set_iron(sct->sct_elev);
1055 sct->sct_gmin = set_gold(sct->sct_elev);
1056 sct->sct_uran = set_uran(sct->sct_elev);
1059 /****************************************************************************
1060 DESIGNATE THE SECTORS
1061 ****************************************************************************/
1069 for (y = 0; y < WORLD_Y; y++) {
1070 for (x = y % 2; x < WORLD_X; x += 2) {
1071 sct = getsectp(x, y);
1073 if (total < LANDMIN) {
1074 sct->sct_type = SCT_WATER;
1075 } else if (total < HILLMIN)
1076 sct->sct_type = SCT_RURAL;
1077 else if (total < PLATMIN)
1078 sct->sct_type = SCT_MOUNT;
1079 else if (total < HIGHMIN)
1080 sct->sct_type = SCT_RURAL;
1082 sct->sct_type = SCT_MOUNT;
1083 sct->sct_elev = total;
1084 sct->sct_newtype = sct->sct_type;
1090 for (c = 0; c < nc; ++c) {
1091 sct = getsectp(capx[c], capy[c]);
1092 sct->sct_type = SCT_AIRPT;
1093 sct->sct_newtype = SCT_AIRPT;
1095 set_coastal_flags();
1098 /****************************************************************************
1099 PRINT A PICTURE OF THE MAP TO YOUR SCREEN
1100 ****************************************************************************/
1106 for (i = 0; i < WORLD_Y; ++i) {
1110 for (j = i % 2; j < WORLD_X; j += 2) {
1111 if (own[j][i] == -1)
1114 printf("%c ", map_symbol(j, i));
1120 printf("\n\nEach continent is marked by a \"*\" on the map (to distinguish them from\n"
1121 "the islands). You can redesignate these airfields to wilderness sectors\n"
1122 "one at a time, each time you add a new country to the game.\n");
1126 map_symbol(int x, int y)
1130 for (c = 0; c < nc; ++c)
1131 if ((x == capx[c] && y == capy[c])
1132 || (x == new_x(capx[c] + 2) && y == capy[c]))
1134 if ((elev[x][y] >= HILLMIN && elev[x][y] < PLATMIN)
1135 || elev[x][y] >= HIGHMIN)
1137 return own[x][y] >= nc ? '%' : iscap ? '#' : numletter[own[x][y] % 62];
1140 /***************************************************************************
1141 WRITE A SCRIPT FOR PLACING CAPITALS
1142 ****************************************************************************/
1144 write_newcap_script(void)
1147 FILE *script = fopen(outfile, "w");
1150 printf("fairland: error, unable to write to %s.\n", outfile);
1154 for (c = 0; c < nc; ++c) {
1155 fprintf(script, "add %d %d %d p\n", c + 1, c + 1, c + 1);
1157 fprintf(script, "des %d,%d -\n", capx[c], capy[c]);
1158 fprintf(script, "newcap %d %d,%d\n", c + 1, capx[c], capy[c]);
1160 fprintf(script, "add %d visitor visitor v\n", c + 1);
1166 qprint(const char *const fmt, ...)
1172 vfprintf(stdout, fmt, ap);
1178 set_coastal_flags(void)
1183 qprint("setting coastal flags...\n");
1184 for (i = 0; i < nc; ++i) {
1185 for (j = 0; j < sc; j++) {
1186 sp = getsectp(sectx[i][j], secty[i][j]);
1187 sp->sct_coastal = sectc[i][j];
1190 for (i = nc; i < nc + ni; ++i) {
1191 for (j = 0; j < isecs[i]; j++) {
1192 sp = getsectp(sectx[i][j], secty[i][j]);
1193 sp->sct_coastal = sectc[i][j];