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)
121 static int secs; /* number of sectors grown */
122 static int ctot; /* total number of continents and islands grown */
123 static int *isecs; /* array of how large each island is */
125 static int nc, sc, di, sp, pm, ni, is, id; /* the 8 args to this program */
126 static unsigned long rnd_seed; /* optional seed argument */
127 static int *capx, *capy; /* location of the nc capitals */
128 static int *mc, mcc; /* array and counter used for stability
129 check when perturbing */
130 static int spike; /* are we spiking? */
131 static int mind; /* the final distance between capitals that
133 static int dirx[] = { -2, -1, 1, 2, 1, -1 }; /* gyujnb */
134 static int diry[] = { 0, -1, -1, 0, 1, 1 };
136 static int **own; /* owner of the sector. -1 means water */
137 static int **elev; /* elevation of the sectors */
138 static int **sectx, **secty; /* the sectors for each continent */
139 static int **sectc; /* which sectors are on the coast? */
140 static int *vector; /* used for measuring distances */
141 static int *weight; /* used for placing mountains */
142 static int *dsea, *dmoun; /* the dist to the ocean and mountain */
143 static int fl_status; /* is anything wrong? */
144 #define STATUS_NO_ROOM 1 /* there was no room to grow */
145 #define NUMTRIES 10 /* keep trying to grow this many times */
147 static const char *numletter =
148 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
150 static void help(char *);
151 static void usage(void);
152 static void parse_args(int argc, char *argv[]);
153 static void allocate_memory(void);
154 static void init(void);
155 static int drift(void);
156 static void grow_continents(void);
157 static void create_elevations(void);
158 static void write_sects(void);
159 static void output(void);
160 static int write_newcap_script(void);
161 static int stable(void);
162 static void elevate_land(void);
163 static void elevate_sea(void);
164 static int map_symbol(int x, int y);
165 static void set_coastal_flags(void);
167 static void print_vars(void);
168 static void fl_move(int);
169 static void next_coast(int c, int x, int y, int *xp, int *yp);
170 static void grow_islands(void);
172 /****************************************************************************
174 ****************************************************************************/
177 main(int argc, char *argv[])
180 char *config_file = NULL;
184 program_name = argv[0];
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);
215 printf("%s\n\n%s", version, legal);
222 parse_args(argc - optind, argv + optind);
225 rnd_seed = pick_seed();
228 if (emp_config(config_file) < 0)
238 qprint("\ntry #%d (out of %d)...", i + 1, NUMTRIES);
239 qprint("\n\n #*# ...fairland rips open a rift in the datumplane... #*#\n\n");
240 qprint("seed is %lu\n", rnd_seed);
241 qprint("placing capitals...\n");
243 qprint("fairland: unstable drift -- try increasisg DRIFT_MAX\n");
244 qprint("growing continents...\n");
246 } while (fl_status && ++i < NUMTRIES);
248 fputs("ERROR: World not large enough to hold continents\n",
252 qprint("growing islands:");
254 qprint("\nelevating land...\n");
256 qprint("designating sectors...\n");
258 qprint("adding resources...\n");
259 write_newcap_script();
261 if (chdir(gamedir)) {
262 fprintf(stderr, "Can't chdir to %s (%s)\n", gamedir, strerror(errno));
265 if (!ef_open(EF_SECTOR, EFF_MEM | EFF_NOTIME))
268 qprint("writing to sectors file...\n");
269 if (!ef_close(EF_SECTOR))
273 qprint("\n\nA script for adding all the countries can be found in \"%s\".\n",
276 qprint("\t*** Resources have not been added ***\n");
285 puts("Creating a planet with:\n");
286 printf("%d continents\n", nc);
287 printf("continent size: %d\n", sc);
288 printf("number of islands: %d\n", ni);
289 printf("average size of islands: %d\n", is);
290 printf("spike: %d%%\n", sp);
291 printf("%d%% of land is mountain (each continent will have %d mountains)\n",
292 pm, (pm * sc) / 100);
293 printf("minimum distance between continents: %d\n", di);
294 printf("minimum distance from islands to continents: %d\n", id);
295 printf("World dimensions: %dx%d\n", WORLD_X, WORLD_Y);
303 for (i = 1; i * i < n * 10000; ++i) ;
304 return (i + 50) / 100;
307 /****************************************************************************
308 PARSE COMMAND LINE ARGUMENTS
309 ****************************************************************************/
312 help(char *complaint)
315 fprintf(stderr, "%s: %s\n", program_name, complaint);
316 fprintf(stderr, "Try -h for help.\n");
322 printf("Usage: %s [OPTION]... NC SC [NI] [IS] [SP] [PM] [DI] [ID]\n"
323 " -a airport marker for continents\n"
324 " -e CONFIG-FILE configuration file\n"
326 " -h display this help and exit\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 " NC number of continents\n"
333 " SC continent size\n"
334 " NI number of islands (default NC)\n"
335 " IS average island size (default SC/2)\n"
336 " SP spike percentage: 0 = round, 100 = snake (default %d)\n"
337 " PM percentage of land that is mountain (default %d)\n"
338 " DI minimum distance between continents (default %d)\n"
339 " ID minimum distance from islands to continents (default %d)\n",
340 program_name, dflt_econfig, DEFAULT_OUTFILE_NAME,
341 DEFAULT_SPIKE, DEFAULT_MOUNTAIN, DEFAULT_CONTDIST, DEFAULT_ISLDIST);
345 parse_args(int argc, char *argv[])
348 help("missing arguments");
352 help("too many arguments");
357 puts("fairland: error -- number of continents must be > 0");
363 puts("fairland: error -- size of continents must be > 0");
391 pm = DEFAULT_MOUNTAIN;
398 di = DEFAULT_CONTDIST;
401 puts("fairland: error -- distance between continents must be >= 0");
404 if (di > WORLD_X / 2 || di > WORLD_Y / 2) {
405 puts("fairland: error -- distance between continents too large");
412 id = DEFAULT_ISLDIST;
414 puts("fairland: error -- distance from islands to continents must be >= 0");
417 if (id > WORLD_X || id > WORLD_Y) {
418 puts("fairland: error -- distance from islands to continents too large");
421 if (nc * sc + nc * my_sqrt(sc) * 2 * (di + 1) > WORLD_X * WORLD_Y) {
422 puts("fairland: warning -- world might be too small to fit continents.");
423 puts("arguments should satisfy:");
424 puts("nc*sc*sc + nc*sqrt(sc)*2*(di+1) < WORLD_X * WORLD_Y");
428 /****************************************************************************
429 VARIABLE INITIALIZATION
430 ****************************************************************************/
433 allocate_memory(void)
437 capx = calloc(nc, sizeof(int));
438 capy = calloc(nc, sizeof(int));
439 vector = calloc(WORLD_X + WORLD_Y, sizeof(int));
440 mc = calloc(STABLE_CYCLE, sizeof(int));
441 own = calloc(WORLD_X, sizeof(int *));
442 elev = calloc(WORLD_X, sizeof(int *));
443 for (i = 0; i < WORLD_X; ++i) {
444 own[i] = calloc(WORLD_Y, sizeof(int));
445 elev[i] = calloc(WORLD_Y, sizeof(int));
447 sectx = calloc(nc + ni, sizeof(int *));
448 secty = calloc(nc + ni, sizeof(int *));
449 sectc = calloc(nc + ni, sizeof(int *));
450 isecs = calloc(nc + ni, sizeof(int));
451 weight = calloc(MAX(sc, is * 2), sizeof(int));
452 dsea = calloc(MAX(sc, is * 2), sizeof(int));
453 dmoun = calloc(MAX(sc, is * 2), sizeof(int));
454 for (i = 0; i < nc; ++i) {
455 sectx[i] = calloc(sc, sizeof(int));
456 secty[i] = calloc(sc, sizeof(int));
457 sectc[i] = calloc(sc, sizeof(int));
459 for (i = nc; i < nc + ni; ++i) {
460 sectx[i] = calloc(is * 2, sizeof(int));
461 secty[i] = calloc(is * 2, sizeof(int));
462 sectc[i] = calloc(is * 2, sizeof(int));
470 int i, j, xx = 0, yy = 0;
475 for (i = 0; i < WORLD_X; ++i) {
476 for (j = 0; j < WORLD_Y; ++j) {
478 elev[i][j] = -INFINITY;
482 for (i = 0; i < nc; ++i) {
487 puts("fairland error: world not big enough for all the continents.\n");
495 for (i = 0; i < STABLE_CYCLE; ++i)
499 /****************************************************************************
500 DRIFT THE CAPITALS UNTIL THEY ARE AS FAR AWAY FROM EACH OTHER AS POSSIBLE
501 ****************************************************************************/
503 /* How isolated is capital j?
506 iso(int j, int newx, int newy)
508 int i, md, d = WORLD_X + WORLD_Y;
510 for (i = 0; i < nc; ++i) {
513 md = mapdist(capx[i], capy[i], newx, newy);
521 /* Drift all the capitals
528 for (turns = 0; turns < DRIFT_MAX; ++turns) {
529 if (turns > DRIFT_BEFORE_CHECK && (mind = stable()))
531 for (i = 0; i < nc; ++i)
537 /* Check to see if we have stabilized--can we stop drifting the capitals?
543 int i, isod, d = 0, stab = 1;
545 for (i = 0; i < nc; ++i) {
546 isod = iso(i, capx[i], capy[i]);
550 for (i = 0; i < STABLE_CYCLE; ++i)
554 mcc = (mcc + 1) % STABLE_CYCLE;
558 /* This routine does the actual drifting
564 int i, n, newx, newy;
566 for (i = roll0(6), n = 0; n < 6; i = (i + 1) % 6, ++n) {
567 newx = new_x(capx[j] + dirx[i]);
568 newy = new_y(capy[j] + diry[i]);
569 if (iso(j, newx, newy) >= iso(j, capx[j], capy[j])) {
577 /****************************************************************************
579 ****************************************************************************/
581 /* Look for a coastal sector of continent c
589 for (i = 0; i < secs; ++i) {
591 for (j = 0; j < 6; ++j)
592 if (own[new_x(sectx[c][i] + dirx[j])][new_y(secty[c][i] + diry[j])] == -1)
597 /* Used for measuring distances
609 for (i = 1; i < n && vector[i] == vector[i - 1]; ++i) ;
612 return i > 1 || vector[0] > 0;
615 /* Test to see if we're allowed to grow there: the arguments di and id
618 try_to_grow(int c, int newx, int newy, int d)
622 for (i = 1; i <= d; ++i) {
623 for (j = 0; j < i; ++j)
628 for (j = 0; j < i; ++j) {
629 px = new_x(px + dirx[vector[j]]);
630 py = new_y(py + diry[vector[j]]);
632 if (own[px][py] != -1 &&
634 (DISTINCT_ISLANDS || own[px][py] < nc))
636 } while (next_vector(i));
638 sectx[c][secs] = newx;
639 secty[c][secs] = newy;
644 /* Move along the coast in a clockwise direction.
648 next_coast(int c, int x, int y, int *xp, int *yp)
650 int i, nx, ny, wat = 0;
658 for (i = 0; i < 12; ++i) {
659 nx = new_x(x + dirx[i % 6]);
660 ny = new_y(y + diry[i % 6]);
661 if (own[nx][ny] == -1)
663 if (wat && own[nx][ny] == c) {
671 /* Choose a sector to grow from
683 i = starti = (spike && sectc[c][secs - 1]) ? secs - 1 : roll0(secs);
688 } while (i != starti);
695 /* Grow continent c by 1 sector
699 grow_one_sector(int c)
701 int done, coast_search, try1, x, y, newx, newy, i, n, sx, sy;
703 spike = roll0(100) < sp;
704 if ((try1 = new_try(c)) == -1)
706 x = sx = sectx[c][try1];
707 y = sy = secty[c][try1];
712 for (i = roll0(6), n = 0; n < 12 && !done; i = (i + 1) % 6, ++n) {
713 newx = new_x(x + dirx[i]);
714 newy = new_y(y + diry[i]);
715 if (own[newx][newy] == -1 &&
717 (own[new_x(x+dirx[(i+5)%6])][new_y(y+diry[(i+5)%6])] == -1 &&
718 own[new_x(x+dirx[(i+1)%6])][new_y(y+diry[(i+1)%6])] == -1)))
719 if (try_to_grow(c, newx, newy, c < nc ? di : id))
723 for (i = roll0(6), n = 0; n < 6 && !done; i = (i + 1) % 6, ++n) {
724 newx = new_x(x + dirx[i]);
725 newy = new_y(y + diry[i]);
726 if (own[newx][newy] == -1)
727 if (try_to_grow(c, newx, newy, c < nc ? di : id))
730 next_coast(c, x, y, &x, &y);
732 } while (!done && coast_search < COAST_SEARCH_MAX &&
733 (secs == 1 || x != sx || y != sy));
734 if (!done && c < nc) {
735 qprint("fairland: error -- continent %c had no room to grow!\n",
737 fl_status |= STATUS_NO_ROOM;
742 /* Grow all the continents
745 grow_continents(void)
749 for (c = 0; c < nc; ++c) {
750 sectx[c][0] = capx[c];
751 secty[c][0] = capy[c];
752 own[sectx[c][0]][secty[c][0]] = c;
753 sectx[c][1] = new_x(capx[c] + 2);
754 secty[c][1] = capy[c];
755 own[sectx[c][1]][secty[c][1]] = c;
758 for (secs = 2; secs < sc && !fl_status; ++secs) {
759 for (c = 0; c < nc; ++c) {
764 for (c = 0; c < nc; ++c)
768 qprint("Only managed to grow %d out of %d sectors.\n", secs, sc);
772 /****************************************************************************
774 ****************************************************************************/
776 /* Choose a place to start growing an island from
779 place_island(int c, int *xp, int *yp)
782 int ssy = roll0(WORLD_Y);
783 int ssx = new_x(roll0(WORLD_X / 2) * 2 + ssy % 2);
785 if (ssx > WORLD_X - 2)
786 ssx = new_x(ssx + 2);
787 for (d = di + id; d >= id; --d) {
791 for (*yp = sy; *xp != sx || *yp != sy; *xp += 2) {
792 if (*xp >= WORLD_X) {
793 *yp = new_y(*yp + 1);
795 if (*xp == sx && *yp == sy)
798 if (own[*xp][*yp] == -1 && try_to_grow(c, *xp, *yp, d))
805 /* Grow all the islands
813 for (c = nc; c < nc + ni; ++c) {
815 if (!place_island(c, &x, &y))
817 isiz = roll(2 * is - 1);
821 } while (secs < isiz && grow_one_sector(c));
823 qprint(" %d(%d)", c - nc + 1, secs);
829 /****************************************************************************
831 ****************************************************************************/
833 create_elevations(void)
839 /* Generic function for finding the distance to the closest sea, land, or
843 distance_to_what(int x, int y, int flag)
847 for (d = 1; d < 5; ++d) {
848 for (j = 0; j < d; ++j)
853 for (j = 0; j < d; ++j) {
854 px = new_x(px + dirx[vector[j]]);
855 py = new_y(py + diry[vector[j]]);
858 case 0: /* distance to sea */
859 if (own[px][py] == -1)
862 case 1: /* distance to land */
863 if (own[px][py] != -1)
866 case 2: /* distance to mountain */
867 if (elev[px][py] == INFINITY)
871 } while (next_vector(d));
876 #define ELEV elev[sectx[c][i]][secty[c][i]]
877 #define distance_to_sea() (sectc[c][i]?1:distance_to_what(sectx[c][i], secty[c][i], 0))
878 #define distance_to_mountain() distance_to_what(sectx[c][i], secty[c][i], 2)
880 /* Decide where the mountains go
885 int i, mountain_search, k, c, total, ns, nm, highest, where, h, newk,
888 for (c = 0; c < ctot; ++c) {
890 ns = (c < nc) ? sc : isecs[c];
891 nm = (pm * ns) / 100;
893 /* Place the mountains */
895 for (i = 0; i < ns; ++i) {
896 dsea[i] = distance_to_sea();
897 weight[i] = (total += (dsea[i] * dsea[i]));
900 for (k = nm, mountain_search = 0;
901 k && mountain_search < MOUNTAIN_SEARCH_MAX;
904 for (i = 0; i < ns; ++i)
905 if (r < weight[i] && ELEV == -INFINITY &&
907 ((!(capx[c] == sectx[c][i] &&
908 capy[c] == secty[c][i])) &&
909 (!(new_x(capx[c] + 2) == sectx[c][i] &&
910 capy[c] == secty[c][i]))))) {
917 /* Elevate land that is not mountain and not capital */
919 for (i = 0; i < ns; ++i)
920 dmoun[i] = distance_to_mountain();
921 dk = (ns - nm - ((c < nc) ? 3 : 1) > 0) ?
922 (100 * (HIGHMIN - LANDMIN)) / (ns - nm - ((c < nc) ? 3 : 1)) :
924 for (k = 100 * (HIGHMIN - 1);; k -= dk) {
927 for (i = 0; i < ns; ++i) {
928 if (ELEV != INFINITY &&
929 (c >= nc || ((!(capx[c] == sectx[c][i] &&
930 capy[c] == secty[c][i])) &&
931 (!(new_x(capx[c] + 2) == sectx[c][i] &&
932 capy[c] == secty[c][i]))))) {
933 h = 3 * (5 - dmoun[i]) + dsea[i];
943 if (newk >= HILLMIN && newk < PLATMIN)
947 elev[sectx[c][where]][secty[c][where]] = newk;
948 dsea[where] = -INFINITY;
949 dmoun[where] = INFINITY;
952 /* Elevate the mountains and capitals */
954 for (i = 0; i < ns; ++i) {
955 if (ELEV == INFINITY) {
957 ELEV = HILLMIN + roll0(PLATMIN - HILLMIN);
959 ELEV = HIGHMIN + roll0((256 - HIGHMIN) / 2) +
960 roll0((256 - HIGHMIN) / 2);
962 (((capx[c] == sectx[c][i] && capy[c] == secty[c][i])) ||
963 ((new_x(capx[c] + 2) == sectx[c][i] &&
964 capy[c] == secty[c][i]))))
970 #define distance_to_land() distance_to_what(x, y, 1)
977 for (y = 0; y < WORLD_Y; ++y) {
978 for (x = y % 2; x < WORLD_X; x += 2) {
979 if (elev[x][y] == -INFINITY)
980 elev[x][y] = -roll(distance_to_land() * 20 + 27);
985 /****************************************************************************
987 ****************************************************************************/
994 fert = LANDMIN - e + 40;
995 else if (e < FERT_MAX)
996 fert = (120 * (FERT_MAX - e)) / (FERT_MAX - LANDMIN);
1007 oil = (LANDMIN - e) * 2 + roll0(2);
1008 else if (e <= OIL_MAX)
1009 oil = (120 * (OIL_MAX - e + 1)) / (OIL_MAX - LANDMIN + 1);
1019 if (e >= IRON_MIN && e < HIGHMIN)
1020 iron = (120 * (e - IRON_MIN + 1)) / (HIGHMIN - IRON_MIN);
1030 if (e >= GOLD_MIN) {
1032 gold = (80 * (e - GOLD_MIN + 1)) / (HIGHMIN - GOLD_MIN);
1034 gold = 100 - 20 * HIGHMIN / e;
1045 if (e >= URAN_MIN && e < HIGHMIN)
1046 uran = (120 * (e - URAN_MIN + 1)) / (HIGHMIN - URAN_MIN);
1053 add_resources(struct sctstr *sct)
1055 sct->sct_fertil = set_fert(sct->sct_elev);
1056 sct->sct_oil = set_oil(sct->sct_elev);
1057 sct->sct_min = set_iron(sct->sct_elev);
1058 sct->sct_gmin = set_gold(sct->sct_elev);
1059 sct->sct_uran = set_uran(sct->sct_elev);
1062 /****************************************************************************
1063 DESIGNATE THE SECTORS
1064 ****************************************************************************/
1072 for (y = 0; y < WORLD_Y; y++) {
1073 for (x = y % 2; x < WORLD_X; x += 2) {
1074 sct = getsectp(x, y);
1076 if (total < LANDMIN) {
1077 sct->sct_type = SCT_WATER;
1078 } else if (total < HILLMIN)
1079 sct->sct_type = SCT_RURAL;
1080 else if (total < PLATMIN)
1081 sct->sct_type = SCT_MOUNT;
1082 else if (total < HIGHMIN)
1083 sct->sct_type = SCT_RURAL;
1085 sct->sct_type = SCT_MOUNT;
1086 sct->sct_elev = total;
1087 sct->sct_newtype = sct->sct_type;
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 ****************************************************************************/
1109 for (i = 0; i < WORLD_Y; ++i) {
1113 for (j = i % 2; j < WORLD_X; j += 2) {
1114 if (own[j][i] == -1)
1117 printf("%c ", map_symbol(j, i));
1123 printf("\n\nEach continent is marked by a \"*\" on the map (to distinguish them from\n"
1124 "the islands). You can redesignate these airfields to wilderness sectors\n"
1125 "one at a time, each time you add a new country to the game.\n");
1129 map_symbol(int x, int y)
1133 for (c = 0; c < nc; ++c)
1134 if ((x == capx[c] && y == capy[c])
1135 || (x == new_x(capx[c] + 2) && y == capy[c]))
1137 if ((elev[x][y] >= HILLMIN && elev[x][y] < PLATMIN)
1138 || elev[x][y] >= HIGHMIN)
1140 return own[x][y] >= nc ? '%' : iscap ? '#' : numletter[own[x][y] % 62];
1143 /***************************************************************************
1144 WRITE A SCRIPT FOR PLACING CAPITALS
1145 ****************************************************************************/
1147 write_newcap_script(void)
1150 FILE *script = fopen(outfile, "w");
1153 printf("fairland: error, unable to write to %s.\n", outfile);
1157 for (c = 0; c < nc; ++c) {
1158 fprintf(script, "add %d %d %d p\n", c + 1, c + 1, c + 1);
1160 fprintf(script, "des %d,%d -\n", capx[c], capy[c]);
1161 fprintf(script, "newcap %d %d,%d\n", c + 1, capx[c], capy[c]);
1163 fprintf(script, "add %d visitor visitor v\n", c + 1);
1169 qprint(const char *const fmt, ...)
1175 vfprintf(stdout, fmt, ap);
1181 set_coastal_flags(void)
1186 qprint("setting coastal flags...\n");
1187 for (i = 0; i < nc; ++i) {
1188 for (j = 0; j < sc; j++) {
1189 sp = getsectp(sectx[i][j], secty[i][j]);
1190 sp->sct_coastal = sectc[i][j];
1193 for (i = nc; i < nc + ni; ++i) {
1194 for (j = 0; j < isecs[i]; j++) {
1195 sp = getsectp(sectx[i][j], secty[i][j]);
1196 sp->sct_coastal = sectc[i][j];