2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2010, Dave Pare, Jeff Bailey, Thomas Ruschak,
4 * Ken Stevens, Steve McClure
6 * This program 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 2 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, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * See files README, COPYING and CREDITS in the root of the source
23 * tree for related information and legal notices. It is expected
24 * that future projects/authors will amend these files as needed.
28 * fairland.c: Create a nice, new world
30 * Known contributors to this file:
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 */
79 #include "prototypes.h"
84 /* do not change these 4 defines */
85 #define LANDMIN 1 /* plate altitude for normal land */
86 #define HILLMIN 34 /* plate altitude for hills */
87 #define PLATMIN 36 /* plate altitude for plateau */
88 #define HIGHMIN 98 /* plate altitude for mountains */
90 static void qprint(const char * const fmt, ...)
91 ATTRIBUTE((format (printf, 1, 2)));
93 #define DEFAULT_OUTFILE_NAME "newcap_script"
94 static const char *outfile = DEFAULT_OUTFILE_NAME;
95 /* mark the continents with a * so you can tell them
96 from the islands 1 = mark, 0 = don't mark. */
97 static int AIRPORT_MARKER = 0;
99 /* don't let the islands crash into each other.
100 1 = don't merge, 0 = merge. */
101 static int DISTINCT_ISLANDS = 1;
103 static char *program_name;
105 #define STABLE_CYCLE 4 /* stability required for perterbed capitals */
106 #define INFINITY 999 /* a number which means "BIG" */
108 /* these defines prevent infinite loops:
111 #define COAST_SEARCH_MAX 200 /* how many times do we look for a coast sector
112 when growing continents and islands */
113 #define DRIFT_BEFORE_CHECK ((WORLD_X + WORLD_Y)/2)
114 #define DRIFT_MAX ((WORLD_X + WORLD_Y)*2)
115 #define MOUNTAIN_SEARCH_MAX 1000 /* how long do we try to place mountains */
120 #define new_x(newx) (((newx) + WORLD_X) % WORLD_X)
121 #define new_y(newy) (((newy) + WORLD_Y) % WORLD_Y)
122 #define rnd(x) (random() % (x))
124 static int secs; /* number of sectors grown */
125 static int ctot; /* total number of continents and islands grown */
126 static int *isecs; /* array of how large each island is */
128 static int nc, sc, di, sp, pm, ni, is, id; /* the 8 args to this program */
129 static unsigned long rnd_seed; /* optional seed argument */
130 static int *capx, *capy; /* location of the nc capitals */
131 static int *mc, mcc; /* array and counter used for stability
132 check when perturbing */
133 static int spike; /* are we spiking? */
134 static int mind; /* the final distance between capitals that
136 static int dirx[] = { -2, -1, 1, 2, 1, -1 }; /* gyujnb */
137 static int diry[] = { 0, -1, -1, 0, 1, 1 };
139 static int **own; /* owner of the sector. -1 means water */
140 static int **elev; /* elevation of the sectors */
141 static int **sectx, **secty; /* the sectors for each continent */
142 static int **sectc; /* which sectors are on the coast? */
143 static int *vector; /* used for measuring distances */
144 static int *weight; /* used for placing mountains */
145 static int *dsea, *dmoun; /* the dist to the ocean and mountain */
146 static int fl_status; /* is anything wrong? */
147 #define STATUS_NO_ROOM 1 /* there was no room to grow */
148 #define NUMTRIES 10 /* keep trying to grow this many times */
150 static const char *numletter =
151 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
153 static void help(char *);
154 static void usage(void);
155 static void parse_args(int argc, char *argv[]);
156 static int allocate_memory(void);
157 static void init(void);
158 static int drift(void);
159 static void grow_continents(void);
160 static void create_elevations(void);
161 static void write_sects(void);
162 static void output(void);
163 static int write_newcap_script(void);
164 static int stable(void);
165 static void elevate_land(void);
166 static void elevate_sea(void);
167 static int map_symbol(int x, int y);
168 static void set_coastal_flags(void);
170 static void print_vars(void);
171 static void fl_move(int);
172 static void next_coast(int c, int x, int y, int *xp, int *yp);
173 static void grow_islands(void);
175 /****************************************************************************
177 ****************************************************************************/
180 main(int argc, char *argv[])
183 char *config_file = NULL;
186 program_name = argv[0];
187 rnd_seed = time(NULL);
189 while ((opt = getopt(argc, argv, "ae:hioqR:s:v")) != EOF) {
195 config_file = optarg;
198 DISTINCT_ISLANDS = 0;
207 rnd_seed = strtoul(optarg, NULL, 10);
216 printf("%s\n\n%s", version, legal);
223 parse_args(argc - optind, argv + optind);
227 if (emp_config(config_file) < 0)
231 if (allocate_memory() == -1)
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, WORLD_SZ())) {
270 qprint("writing to sectors file...\n");
271 if (!ef_close(EF_SECTOR))
275 qprint("\n\nA script for adding all the countries can be found in \"%s\".\n",
278 qprint("\t*** Resources have not been added ***\n");
287 puts("Creating a planet with:\n");
288 printf("%d continents\n", nc);
289 printf("continent size: %d\n", sc);
290 printf("number of islands: %d\n", ni);
291 printf("average size of islands: %d\n", is);
292 printf("spike: %d%%\n", sp);
293 printf("%d%% of land is mountain (each continent will have %d mountains)\n",
294 pm, (pm * sc) / 100);
295 printf("minimum distance between continents: %d\n", di);
296 printf("minimum distance from islands to continents: %d\n", id);
297 printf("World dimensions: %dx%d\n", WORLD_X, WORLD_Y);
305 for (i = 1; i * i < n * 10000; ++i) ;
306 return (i + 50) / 100;
309 /****************************************************************************
310 PARSE COMMAND LINE ARGUMENTS
311 ****************************************************************************/
314 help(char *complaint)
317 fprintf(stderr, "%s: %s\n", program_name, complaint);
318 fprintf(stderr, "Try -h for help.\n");
324 printf("Usage: %s [OPTION]... NC SC [NI] [IS] [SP] [PM] [DI] [ID]\n"
325 " -a airport marker for continents\n"
326 " -e CONFIG-FILE configuration file\n"
328 " -h display this help and exit\n"
329 " -i islands may merge\n"
330 " -o don't set resources\n"
332 " -R SEED seed for random number generator\n"
333 " -s SCRIPT name of script to create (default %s)\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");
393 pm = DEFAULT_MOUNTAIN;
400 di = DEFAULT_CONTDIST;
403 puts("fairland: error -- distance between continents must be >= 0");
406 if (di > WORLD_X / 2 || di > WORLD_Y / 2) {
407 puts("fairland: error -- distance between continents too large");
414 id = DEFAULT_ISLDIST;
416 puts("fairland: error -- distance from islands to continents must be >= 0");
419 if (id > WORLD_X || id > WORLD_Y) {
420 puts("fairland: error -- distance from islands to continents too large");
423 if (nc * sc + nc * my_sqrt(sc) * 2 * (di + 1) > WORLD_X * WORLD_Y) {
424 puts("fairland: warning -- world might be too small to fit continents.");
425 puts("arguments should satisfy:");
426 puts("nc*sc*sc + nc*sqrt(sc)*2*(di+1) < WORLD_X * WORLD_Y");
430 /****************************************************************************
431 VARIABLE INITIALIZATION
432 ****************************************************************************/
435 allocate_memory(void)
439 capx = calloc(nc, sizeof(int));
440 capy = calloc(nc, sizeof(int));
441 vector = calloc(WORLD_X + WORLD_Y, sizeof(int));
442 mc = calloc(STABLE_CYCLE, sizeof(int));
443 own = calloc(WORLD_X, sizeof(int *));
444 elev = calloc(WORLD_X, sizeof(int *));
445 for (i = 0; i < WORLD_X; ++i) {
446 own[i] = calloc(WORLD_Y, sizeof(int));
447 elev[i] = calloc(WORLD_Y, sizeof(int));
449 sectx = calloc(nc + ni, sizeof(int *));
450 secty = calloc(nc + ni, sizeof(int *));
451 sectc = calloc(nc + ni, sizeof(int *));
452 isecs = calloc(nc + ni, sizeof(int));
453 weight = calloc(MAX(sc, is * 2), sizeof(int));
454 dsea = calloc(MAX(sc, is * 2), sizeof(int));
455 dmoun = calloc(MAX(sc, is * 2), sizeof(int));
456 for (i = 0; i < nc; ++i) {
457 sectx[i] = calloc(sc, sizeof(int));
458 secty[i] = calloc(sc, sizeof(int));
459 sectc[i] = calloc(sc, sizeof(int));
461 for (i = nc; i < nc + ni; ++i) {
462 sectx[i] = calloc(is * 2, sizeof(int));
463 secty[i] = calloc(is * 2, sizeof(int));
464 sectc[i] = calloc(is * 2, sizeof(int));
473 int i, j, xx = 0, yy = 0;
478 for (i = 0; i < WORLD_X; ++i) {
479 for (j = 0; j < WORLD_Y; ++j) {
481 elev[i][j] = -INFINITY;
485 for (i = 0; i < nc; ++i) {
490 puts("fairland error: world not big enough for all the continents.\n");
498 for (i = 0; i < STABLE_CYCLE; ++i)
502 /****************************************************************************
503 DRIFT THE CAPITALS UNTIL THEY ARE AS FAR AWAY FROM EACH OTHER AS POSSIBLE
504 ****************************************************************************/
506 /* How isolated is capital j?
509 iso(int j, int newx, int newy)
511 int i, md, d = WORLD_X + WORLD_Y;
513 for (i = 0; i < nc; ++i) {
516 md = mapdist(capx[i], capy[i], newx, newy);
524 /* Drift all the capitals
531 for (turns = 0; turns < DRIFT_MAX; ++turns) {
532 if (turns > DRIFT_BEFORE_CHECK && (mind = stable()))
534 for (i = 0; i < nc; ++i)
540 /* Check to see if we have stabilized--can we stop drifting the capitals?
546 int i, isod, d = 0, stab = 1;
548 for (i = 0; i < nc; ++i) {
549 isod = iso(i, capx[i], capy[i]);
553 for (i = 0; i < STABLE_CYCLE; ++i)
557 mcc = (mcc + 1) % STABLE_CYCLE;
561 /* This routine does the actual drifting
567 int i, n, newx, newy;
569 for (i = rnd(6), n = 0; n < 6; i = (i + 1) % 6, ++n) {
570 newx = new_x(capx[j] + dirx[i]);
571 newy = new_y(capy[j] + diry[i]);
572 if (iso(j, newx, newy) >= iso(j, capx[j], capy[j])) {
580 /****************************************************************************
582 ****************************************************************************/
584 /* Look for a coastal sector of continent c
592 for (i = 0; i < secs; ++i) {
594 for (j = 0; j < 6; ++j)
595 if (own[new_x(sectx[c][i] + dirx[j])][new_y(secty[c][i] + diry[j])] == -1)
600 /* Used for measuring distances
612 for (i = 1; i < n && vector[i] == vector[i - 1]; ++i) ;
615 return i > 1 || vector[0] > 0;
618 /* Test to see if we're allowed to grow there: the arguments di and id
621 try_to_grow(int c, int newx, int newy, int d)
625 for (i = 1; i <= d; ++i) {
626 for (j = 0; j < i; ++j)
631 for (j = 0; j < i; ++j) {
632 px = new_x(px + dirx[vector[j]]);
633 py = new_y(py + diry[vector[j]]);
635 if (own[px][py] != -1 &&
637 (DISTINCT_ISLANDS || own[px][py] < nc))
639 } while (next_vector(i));
641 sectx[c][secs] = newx;
642 secty[c][secs] = newy;
647 /* Move along the coast in a clockwise direction.
651 next_coast(int c, int x, int y, int *xp, int *yp)
653 int i, nx, ny, wat = 0;
661 for (i = 0; i < 12; ++i) {
662 nx = new_x(x + dirx[i % 6]);
663 ny = new_y(y + diry[i % 6]);
664 if (own[nx][ny] == -1)
666 if (wat && own[nx][ny] == c) {
674 /* Choose a sector to grow from
686 i = starti = (spike && sectc[c][secs - 1]) ? secs - 1 : rnd(secs);
691 } while (i != starti);
698 /* Grow continent c by 1 sector
702 grow_one_sector(int c)
704 int done, coast_search, try1, x, y, newx, newy, i, n, sx, sy;
706 spike = rnd(100) < sp;
707 if ((try1 = new_try(c)) == -1)
709 x = sx = sectx[c][try1];
710 y = sy = secty[c][try1];
715 for (i = rnd(6), n = 0; n < 12 && !done; i = (i + 1) % 6, ++n) {
716 newx = new_x(x + dirx[i]);
717 newy = new_y(y + diry[i]);
718 if (own[newx][newy] == -1 &&
720 (own[new_x(x+dirx[(i+5)%6])][new_y(y+diry[(i+5)%6])] == -1 &&
721 own[new_x(x+dirx[(i+1)%6])][new_y(y+diry[(i+1)%6])] == -1)))
722 if (try_to_grow(c, newx, newy, c < nc ? di : id))
726 for (i = rnd(6), n = 0; n < 6 && !done; i = (i + 1) % 6, ++n) {
727 newx = new_x(x + dirx[i]);
728 newy = new_y(y + diry[i]);
729 if (own[newx][newy] == -1)
730 if (try_to_grow(c, newx, newy, c < nc ? di : id))
733 next_coast(c, x, y, &x, &y);
735 } while (!done && coast_search < COAST_SEARCH_MAX &&
736 (secs == 1 || x != sx || y != sy));
737 if (!done && c < nc) {
738 qprint("fairland: error -- continent %c had no room to grow!\n",
740 fl_status |= STATUS_NO_ROOM;
745 /* Grow all the continents
748 grow_continents(void)
752 for (c = 0; c < nc; ++c) {
753 sectx[c][0] = capx[c];
754 secty[c][0] = capy[c];
755 own[sectx[c][0]][secty[c][0]] = c;
756 sectx[c][1] = new_x(capx[c] + 2);
757 secty[c][1] = capy[c];
758 own[sectx[c][1]][secty[c][1]] = c;
761 for (secs = 2; secs < sc && !fl_status; ++secs) {
762 for (c = 0; c < nc; ++c) {
767 for (c = 0; c < nc; ++c)
771 qprint("Only managed to grow %d out of %d sectors.\n", secs, sc);
775 /****************************************************************************
777 ****************************************************************************/
779 /* Choose a place to start growing an island from
782 place_island(int c, int *xp, int *yp)
785 int ssy = rnd(WORLD_Y);
786 int ssx = new_x(rnd(WORLD_X / 2) * 2 + ssy % 2);
788 if (ssx > WORLD_X - 2)
789 ssx = new_x(ssx + 2);
790 for (d = di + id; d >= id; --d) {
794 for (*yp = sy; *xp != sx || *yp != sy; *xp += 2) {
795 if (*xp >= WORLD_X) {
796 *yp = new_y(*yp + 1);
798 if (*xp == sx && *yp == sy)
801 if (own[*xp][*yp] == -1 && try_to_grow(c, *xp, *yp, d))
808 /* Grow all the islands
816 for (c = nc; c < nc + ni; ++c) {
818 if (!place_island(c, &x, &y))
820 isiz = 1 + rnd(2 * is - 1);
824 } while (secs < isiz && grow_one_sector(c));
826 qprint(" %d(%d)", c - nc + 1, secs);
832 /****************************************************************************
834 ****************************************************************************/
836 create_elevations(void)
842 /* Generic function for finding the distance to the closest sea, land, or
846 distance_to_what(int x, int y, int flag)
850 for (d = 1; d < 5; ++d) {
851 for (j = 0; j < d; ++j)
856 for (j = 0; j < d; ++j) {
857 px = new_x(px + dirx[vector[j]]);
858 py = new_y(py + diry[vector[j]]);
861 case 0: /* distance to sea */
862 if (own[px][py] == -1)
865 case 1: /* distance to land */
866 if (own[px][py] != -1)
869 case 2: /* distance to mountain */
870 if (elev[px][py] == INFINITY)
874 } while (next_vector(d));
879 #define ELEV elev[sectx[c][i]][secty[c][i]]
880 #define distance_to_sea() (sectc[c][i]?1:distance_to_what(sectx[c][i], secty[c][i], 0))
881 #define distance_to_mountain() distance_to_what(sectx[c][i], secty[c][i], 2)
883 /* Decide where the mountains go
888 int i, mountain_search, k, c, total, ns, nm, highest, where, h, newk,
891 for (c = 0; c < ctot; ++c) {
893 ns = (c < nc) ? sc : isecs[c];
894 nm = (pm * ns) / 100;
896 /* Place the mountains */
898 for (i = 0; i < ns; ++i) {
899 dsea[i] = distance_to_sea();
900 weight[i] = (total += (dsea[i] * dsea[i]));
903 for (k = nm, mountain_search = 0;
904 k && mountain_search < MOUNTAIN_SEARCH_MAX;
907 for (i = 0; i < ns; ++i)
908 if (r < weight[i] && ELEV == -INFINITY &&
910 ((!(capx[c] == sectx[c][i] &&
911 capy[c] == secty[c][i])) &&
912 (!(new_x(capx[c] + 2) == sectx[c][i] &&
913 capy[c] == secty[c][i]))))) {
920 /* Elevate land that is not mountain and not capital */
922 for (i = 0; i < ns; ++i)
923 dmoun[i] = distance_to_mountain();
924 dk = (ns - nm - ((c < nc) ? 3 : 1) > 0) ?
925 (100 * (HIGHMIN - LANDMIN)) / (ns - nm - ((c < nc) ? 3 : 1)) :
927 for (k = 100 * (HIGHMIN - 1);; k -= dk) {
930 for (i = 0; i < ns; ++i) {
931 if (ELEV != INFINITY &&
932 (c >= nc || ((!(capx[c] == sectx[c][i] &&
933 capy[c] == secty[c][i])) &&
934 (!(new_x(capx[c] + 2) == sectx[c][i] &&
935 capy[c] == secty[c][i]))))) {
936 h = 3 * (5 - dmoun[i]) + dsea[i];
946 if (newk >= HILLMIN && newk < PLATMIN)
950 elev[sectx[c][where]][secty[c][where]] = newk;
951 dsea[where] = -INFINITY;
952 dmoun[where] = INFINITY;
955 /* Elevate the mountains and capitals */
957 for (i = 0; i < ns; ++i) {
958 if (ELEV == INFINITY) {
960 ELEV = HILLMIN + rnd(PLATMIN - HILLMIN);
962 ELEV = HIGHMIN + rnd((256 - HIGHMIN) / 2) +
963 rnd((256 - HIGHMIN) / 2);
964 } else if ((c < nc &&
965 ((capx[c] == sectx[c][i] && capy[c] == secty[c][i]))) ||
966 ((new_x(capx[c] + 2) == sectx[c][i] &&
967 capy[c] == secty[c][i])))
973 #define distance_to_land() distance_to_what(x, y, 1)
980 for (y = 0; y < WORLD_Y; ++y) {
981 for (x = y % 2; x < WORLD_X; x += 2) {
982 if (elev[x][y] == -INFINITY)
983 elev[x][y] = -rnd((distance_to_land() * 20 + 27)) - 1;
988 /****************************************************************************
990 ****************************************************************************/
997 fert = LANDMIN - e + 40;
998 else if (e < FERT_MAX)
999 fert = (120 * (FERT_MAX - e)) / (FERT_MAX - LANDMIN);
1010 oil = (LANDMIN - e) * 2 + rnd(2);
1011 else if (e <= OIL_MAX)
1012 oil = (120 * (OIL_MAX - e + 1)) / (OIL_MAX - LANDMIN + 1);
1022 if (e >= IRON_MIN && e < HIGHMIN)
1023 iron = (120 * (e - IRON_MIN + 1)) / (HIGHMIN - IRON_MIN);
1033 if (e >= GOLD_MIN) {
1035 gold = (80 * (e - GOLD_MIN + 1)) / (HIGHMIN - GOLD_MIN);
1037 gold = 100 - 20 * HIGHMIN / e;
1048 if (e >= URAN_MIN && e < HIGHMIN)
1049 uran = (120 * (e - URAN_MIN + 1)) / (HIGHMIN - URAN_MIN);
1056 add_resources(struct sctstr *sct)
1058 sct->sct_fertil = set_fert(sct->sct_elev);
1059 sct->sct_oil = set_oil(sct->sct_elev);
1060 sct->sct_min = set_iron(sct->sct_elev);
1061 sct->sct_gmin = set_gold(sct->sct_elev);
1062 sct->sct_uran = set_uran(sct->sct_elev);
1065 /****************************************************************************
1066 DESIGNATE THE SECTORS
1067 ****************************************************************************/
1075 for (y = 0; y < WORLD_Y; y++) {
1076 for (x = y % 2; x < WORLD_X; x += 2) {
1077 sct = getsectp(x, y);
1079 if (total < LANDMIN) {
1080 sct->sct_type = SCT_WATER;
1081 } else if (total < HILLMIN)
1082 sct->sct_type = SCT_RURAL;
1083 else if (total < PLATMIN)
1084 sct->sct_type = SCT_MOUNT;
1085 else if (total < HIGHMIN)
1086 sct->sct_type = SCT_RURAL;
1088 sct->sct_type = SCT_MOUNT;
1089 sct->sct_elev = total;
1090 sct->sct_newtype = sct->sct_type;
1096 for (c = 0; c < nc; ++c) {
1097 sct = getsectp(capx[c], capy[c]);
1098 sct->sct_type = SCT_AIRPT;
1099 sct->sct_newtype = SCT_AIRPT;
1101 set_coastal_flags();
1104 /****************************************************************************
1105 PRINT A PICTURE OF THE MAP TO YOUR SCREEN
1106 ****************************************************************************/
1112 for (i = 0; i < WORLD_Y; ++i) {
1116 for (j = i % 2; j < WORLD_X; j += 2) {
1117 if (own[j][i] == -1)
1120 printf("%c ", map_symbol(j, i));
1126 printf("\n\nEach continent is marked by a \"*\" on the map (to distinguish them from\nthe islands). You can redesignate these airfields to wilderness sectors\none at a time, each time you add a new country to the game.\n");
1130 map_symbol(int x, int y)
1134 for (c = 0; c < nc; ++c)
1135 if ((x == capx[c] && y == capy[c])
1136 || (x == new_x(capx[c] + 2) && y == capy[c]))
1138 if ((elev[x][y] >= HILLMIN && elev[x][y] < PLATMIN)
1139 || elev[x][y] >= HIGHMIN)
1141 return own[x][y] >= nc ? '%' : iscap ? '#' : numletter[own[x][y] % 62];
1144 /***************************************************************************
1145 WRITE A SCRIPT FOR PLACING CAPITALS
1146 ****************************************************************************/
1148 write_newcap_script(void)
1151 FILE *script = fopen(outfile, "w");
1154 printf("fairland: error, unable to write to %s.\n", outfile);
1158 for (c = 0; c < nc; ++c) {
1159 fprintf(script, "add %d %d %d n i\n", c + 1, c + 1, c + 1);
1161 fprintf(script, "des %d,%d -\n", capx[c], capy[c]);
1162 fprintf(script, "newcap %d %d,%d\n", c + 1, capx[c], capy[c]);
1164 fprintf(script, "add %d visitor visitor v i\n", c + 1);
1170 qprint(const char *const fmt, ...)
1176 vfprintf(stdout, fmt, ap);
1182 set_coastal_flags(void)
1187 qprint("setting coastal flags...\n");
1188 for (i = 0; i < nc; ++i) {
1189 for (j = 0; j < sc; j++) {
1190 sp = getsectp(sectx[i][j], secty[i][j]);
1191 sp->sct_coastal = sectc[i][j];
1194 for (i = nc; i < nc + ni; ++i) {
1195 for (j = 0; j < isecs[i]; j++) {
1196 sp = getsectp(sectx[i][j], secty[i][j]);
1197 sp->sct_coastal = sectc[i][j];