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 int *capx, *capy; /* location of the nc capitals */
127 static int *mc, mcc; /* array and counter used for stability
128 check when perturbing */
129 static int spike; /* are we spiking? */
130 static int mind; /* the final distance between capitals that
132 static int dirx[] = { -2, -1, 1, 2, 1, -1 }; /* gyujnb */
133 static int diry[] = { 0, -1, -1, 0, 1, 1 };
135 static int **own; /* owner of the sector. -1 means water */
136 static int **elev; /* elevation of the sectors */
137 static int **sectx, **secty; /* the sectors for each continent */
138 static int **sectc; /* which sectors are on the coast? */
139 static int *vector; /* used for measuring distances */
140 static int *weight; /* used for placing mountains */
141 static int *dsea, *dmoun; /* the dist to the ocean and mountain */
142 static int fl_status; /* is anything wrong? */
143 #define STATUS_NO_ROOM 1 /* there was no room to grow */
144 #define NUMTRIES 10 /* keep trying to grow this many times */
146 static const char *numletter =
147 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
149 static void help(char *);
150 static void usage(void);
151 static void parse_args(int argc, char *argv[]);
152 static void allocate_memory(void);
153 static void init(void);
154 static int drift(void);
155 static void grow_continents(void);
156 static void create_elevations(void);
157 static void write_sects(void);
158 static void output(void);
159 static int write_newcap_script(void);
160 static int stable(void);
161 static void elevate_land(void);
162 static void elevate_sea(void);
163 static int map_symbol(int x, int y);
164 static void set_coastal_flags(void);
166 static void print_vars(void);
167 static void fl_move(int);
168 static void next_coast(int c, int x, int y, int *xp, int *yp);
169 static void grow_islands(void);
171 /****************************************************************************
173 ****************************************************************************/
176 main(int argc, char *argv[])
179 char *config_file = NULL;
181 unsigned rnd_seed = 0;
184 program_name = argv[0];
186 while ((opt = getopt(argc, argv, "ae:hioqR:s:v")) != EOF) {
192 config_file = optarg;
195 DISTINCT_ISLANDS = 0;
204 rnd_seed = strtoul(optarg, NULL, 10);
214 printf("%s\n\n%s", version, legal);
221 parse_args(argc - optind, argv + optind);
224 rnd_seed = pick_seed();
227 if (emp_config(config_file) < 0)
234 qprint("\n #*# ...fairland rips open a rift in the datumplane... #*#\n\n");
235 qprint("seed is %u\n", rnd_seed);
239 qprint("\ntry #%d (out of %d)...\n", i + 1, NUMTRIES);
240 qprint("placing capitals...\n");
242 qprint("fairland: unstable drift -- try increasisg DRIFT_MAX\n");
243 qprint("growing continents...\n");
245 } while (fl_status && ++i < NUMTRIES);
247 fputs("ERROR: World not large enough to hold continents\n",
251 qprint("growing islands:");
253 qprint("\nelevating land...\n");
255 qprint("designating sectors...\n");
257 qprint("adding resources...\n");
258 write_newcap_script();
260 if (chdir(gamedir)) {
261 fprintf(stderr, "Can't chdir to %s (%s)\n", gamedir, strerror(errno));
264 if (!ef_open(EF_SECTOR, EFF_MEM | EFF_NOTIME))
267 qprint("writing to sectors file...\n");
268 if (!ef_close(EF_SECTOR))
272 qprint("\n\nA script for adding all the countries can be found in \"%s\".\n",
275 qprint("\t*** Resources have not been added ***\n");
284 puts("Creating a planet with:\n");
285 printf("%d continents\n", nc);
286 printf("continent size: %d\n", sc);
287 printf("number of islands: %d\n", ni);
288 printf("average size of islands: %d\n", is);
289 printf("spike: %d%%\n", sp);
290 printf("%d%% of land is mountain (each continent will have %d mountains)\n",
291 pm, (pm * sc) / 100);
292 printf("minimum distance between continents: %d\n", di);
293 printf("minimum distance from islands to continents: %d\n", id);
294 printf("World dimensions: %dx%d\n", WORLD_X, WORLD_Y);
302 for (i = 1; i * i < n * 10000; ++i) ;
303 return (i + 50) / 100;
306 /****************************************************************************
307 PARSE COMMAND LINE ARGUMENTS
308 ****************************************************************************/
311 help(char *complaint)
314 fprintf(stderr, "%s: %s\n", program_name, complaint);
315 fprintf(stderr, "Try -h for help.\n");
321 printf("Usage: %s [OPTION]... NC SC [NI] [IS] [SP] [PM] [DI] [ID]\n"
322 " -a airport marker for continents\n"
323 " -e CONFIG-FILE configuration file\n"
325 " -h display this help and exit\n"
326 " -i islands may merge\n"
327 " -o don't set resources\n"
329 " -R SEED seed for random number generator\n"
330 " -s SCRIPT name of script to create (default %s)\n"
331 " NC number of continents\n"
332 " SC continent size\n"
333 " NI number of islands (default NC)\n"
334 " IS average island size (default SC/2)\n"
335 " SP spike percentage: 0 = round, 100 = snake (default %d)\n"
336 " PM percentage of land that is mountain (default %d)\n"
337 " DI minimum distance between continents (default %d)\n"
338 " ID minimum distance from islands to continents (default %d)\n",
339 program_name, dflt_econfig, DEFAULT_OUTFILE_NAME,
340 DEFAULT_SPIKE, DEFAULT_MOUNTAIN, DEFAULT_CONTDIST, DEFAULT_ISLDIST);
344 parse_args(int argc, char *argv[])
347 help("missing arguments");
351 help("too many arguments");
356 puts("fairland: error -- number of continents must be > 0");
362 puts("fairland: error -- size of continents must be > 0");
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(2 * is - 1);
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;
1092 for (c = 0; c < nc; ++c) {
1093 sct = getsectp(capx[c], capy[c]);
1094 sct->sct_type = SCT_AIRPT;
1095 sct->sct_newtype = SCT_AIRPT;
1097 set_coastal_flags();
1100 /****************************************************************************
1101 PRINT A PICTURE OF THE MAP TO YOUR SCREEN
1102 ****************************************************************************/
1108 for (i = 0; i < WORLD_Y; ++i) {
1112 for (j = i % 2; j < WORLD_X; j += 2) {
1113 if (own[j][i] == -1)
1116 printf("%c ", map_symbol(j, i));
1122 printf("\n\nEach continent is marked by a \"*\" on the map (to distinguish them from\n"
1123 "the islands). You can redesignate these airfields to wilderness sectors\n"
1124 "one at a time, each time you add a new country to the game.\n");
1128 map_symbol(int x, int y)
1132 for (c = 0; c < nc; ++c)
1133 if ((x == capx[c] && y == capy[c])
1134 || (x == new_x(capx[c] + 2) && y == capy[c]))
1136 if ((elev[x][y] >= HILLMIN && elev[x][y] < PLATMIN)
1137 || elev[x][y] >= HIGHMIN)
1139 return own[x][y] >= nc ? '%' : iscap ? '#' : numletter[own[x][y] % 62];
1142 /***************************************************************************
1143 WRITE A SCRIPT FOR PLACING CAPITALS
1144 ****************************************************************************/
1146 write_newcap_script(void)
1149 FILE *script = fopen(outfile, "w");
1152 printf("fairland: error, unable to write to %s.\n", outfile);
1156 for (c = 0; c < nc; ++c) {
1157 fprintf(script, "add %d %d %d p\n", c + 1, c + 1, c + 1);
1159 fprintf(script, "des %d,%d -\n", capx[c], capy[c]);
1160 fprintf(script, "newcap %d %d,%d\n", c + 1, capx[c], capy[c]);
1162 fprintf(script, "add %d visitor visitor v\n", c + 1);
1168 qprint(const char *const fmt, ...)
1174 vfprintf(stdout, fmt, ap);
1180 set_coastal_flags(void)
1185 qprint("setting coastal flags...\n");
1186 for (i = 0; i < nc; ++i) {
1187 for (j = 0; j < sc; j++) {
1188 sp = getsectp(sectx[i][j], secty[i][j]);
1189 sp->sct_coastal = sectc[i][j];
1192 for (i = nc; i < nc + ni; ++i) {
1193 for (j = 0; j < isecs[i]; j++) {
1194 sp = getsectp(sectx[i][j], secty[i][j]);
1195 sp->sct_coastal = sectc[i][j];