2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2006, 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 the "LEGAL", "LICENSE", "CREDITS" and "README" files for all the
23 * related information and legal notices. It is expected that any future
24 * 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 */
70 #include "../lib/gen/getopt.h"
85 #include "prototypes.h"
87 /* do not change these 4 defines */
88 #define LANDMIN 1 /* plate altitude for normal land */
89 #define HILLMIN 34 /* plate altitude for hills */
90 #define PLATMIN 36 /* plate altitude for plateau */
91 #define HIGHMIN 98 /* plate altitude for mountains */
93 static void qprint(const char * const fmt, ...)
94 ATTRIBUTE((format (printf, 1, 2)));
96 #define DEFAULT_OUTFILE_NAME "newcap_script"
97 static const char *outfile = DEFAULT_OUTFILE_NAME;
98 /* mark the continents with a * so you can tell them
99 from the islands 1 = mark, 0 = don't mark. */
100 static int AIRPORT_MARKER = 0;
102 /* don't let the islands crash into each other.
103 1 = don't merge, 0 = merge. */
104 static int DISTINCT_ISLANDS = 1;
106 static char *program_name;
108 #define XSIZE ((WORLD_X) / 2) /* basically world x-y size */
109 #define YSIZE (WORLD_Y)
110 #define STABLE_CYCLE 4 /* stability required for perterbed capitals */
111 #define INFINITY 999 /* a number which means "BIG" */
113 /* these defines prevent infinite loops:
116 #define COAST_SEARCH_MAX 200 /* how many times do we look for a coast sector
117 when growing continents and islands */
118 #define DRIFT_BEFORE_CHECK ((WORLD_X + WORLD_Y)/2)
119 #define DRIFT_MAX ((WORLD_X + WORLD_Y)*2)
120 #define MOUNTAIN_SEARCH_MAX 1000 /* how long do we try to place mountains */
125 #define new_x(newx) (((newx) + WORLD_X) % WORLD_X)
126 #define new_y(newy) (((newy) + WORLD_Y) % WORLD_Y)
128 #define max(a,b) (a>b?a:b)
130 #define rnd(x) (random() % (x))
132 int secs; /* number of sectors grown */
133 int ctot; /* total number of continents and islands grown */
134 int *isecs; /* array of how large each island is */
136 int nc, sc, di, sp, pm, ni, is, id; /* the 8 arguments to this program */
137 unsigned long rnd_seed; /* optional seed can be passed as an argument */
138 int *capx, *capy; /* location of the nc capitals */
139 int *mc, mcc; /* array and counter used for stability
140 check when perturbing */
141 int spike; /* are we spiking? */
142 int mind; /* the final distance between capitals that
144 int dirx[] = { -2, -1, 1, 2, 1, -1 }; /* gyujnb */
145 int diry[] = { 0, -1, -1, 0, 1, 1 };
147 int **own; /* owner of the sector. -1 means water */
148 int **elev; /* elevation of the sectors */
149 int **sectx, **secty; /* the sectors for each continent */
150 int **sectc; /* which sectors are on the coast? */
151 int *vector; /* used for measuring distances */
152 int *weight; /* used for placing mountains */
153 int *dsea, *dmoun; /* the dist to the ocean and mountain */
154 FILE *sect_fptr; /* the file we write everything to */
155 struct sctstr **sects;
156 struct sctstr *sectsbuf;
157 int fl_status; /* is anything wrong? */
158 #define STATUS_NO_ROOM 1 /* there was no room to grow */
159 #define NUMTRIES 10 /* keep trying to grow this many times */
161 const char *numletter =
162 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
164 static void help(char *);
165 static void usage(void);
166 static void parse_args(int argc, char *argv[]);
167 static int allocate_memory(void);
168 static void init(void);
169 static int drift(void);
170 static void grow_continents(void);
171 static void create_elevations(void);
172 static void write_sects(void);
173 static int write_file(void);
174 static void output(void);
175 static int write_newcap_script(void);
176 static int stable(void);
177 static void elevate_land(void);
178 static void elevate_sea(void);
179 static int map_symbol(int x, int y);
180 static void fl_sct_init(coord x, coord y, s_char *ptr,
182 static void set_coastal_flags(void);
184 static void print_vars(void);
185 static void fl_move(int);
186 static void next_coast(int c, int x, int y, int *xp, int *yp);
187 static void grow_islands(void);
189 /****************************************************************************
191 ****************************************************************************/
194 main(int argc, char *argv[])
197 char *config_file = NULL;
200 program_name = argv[0];
201 rnd_seed = time(NULL);
203 while ((opt = getopt(argc, argv, "ae:hioqs:R:")) != EOF) {
209 DISTINCT_ISLANDS = 0;
212 config_file = optarg;
224 rnd_seed = strtoul(optarg, NULL, 10);
235 if (emp_config(config_file))
238 parse_args(argc - optind, argv + optind);
239 if (allocate_memory() == -1)
246 qprint("\ntry #%d (out of %d)...", i + 1, NUMTRIES);
247 qprint("\n\n #*# ...fairland rips open a rift in the datumplane... #*#\n\n");
248 qprint("seed is %lu\n", rnd_seed);
249 qprint("placing capitals...\n");
251 qprint("fairland: unstable drift -- try increasisg DRIFT_MAX\n");
252 qprint("growing continents...\n");
254 } while (fl_status && ++i < NUMTRIES);
256 fputs("ERROR: World not large enough to hold continents\n",
260 qprint("growing islands:");
262 qprint("\nelevating land...\n");
264 qprint("designating sectors...\n");
266 qprint("adding resources...\n");
268 qprint("writing to sectors file...\n");
269 if (write_file() == -1)
272 write_newcap_script();
274 qprint("\t*** Resources have not been added ***\n");
283 puts("Creating a planet with:\n");
284 printf("%d continents\n", nc);
285 printf("continent size: %d\n", sc);
286 printf("number of islands: %d\n", ni);
287 printf("average size of islands: %d\n", is);
288 printf("spike: %d%%\n", sp);
289 printf("%d%% of land is mountain (each continent will have %d mountains)\n",
290 pm, (pm * sc) / 100);
291 printf("minimum distance between continents: %d\n", di);
292 printf("minimum distance from islands to continents: %d\n", id);
293 printf("World dimensions: %dx%d\n", WORLD_X, WORLD_Y);
301 for (i = 1; i * i < n * 10000; ++i) ;
302 return (i + 50) / 100;
305 /****************************************************************************
306 PARSE COMMAND LINE ARGUMENTS
307 ****************************************************************************/
310 help(char *complaint)
313 fprintf(stderr, "%s: %s\n", program_name, complaint);
314 fprintf(stderr, "Try -h for help.\n");
320 printf("Usage: %s [-e CONFIG] [-aiqo] [-s SCRIPT] [-R SEED] NC SC [NI] [IS] [SP] [PM] [DI] [ID]\n"
322 " -o don't set resources\n"
323 " -a airport marker for continents\n"
324 " -i islands may merge\n"
325 " -R SEED seed for random number generator\n"
326 " -e CONFIG configuration file\n"
327 " -s SCRIPT name of script to create (default %s)\n"
328 " NC number of continents\n"
329 " SC continent size\n"
330 " NI number of islands (default NC)\n"
331 " IS average island size (default SC/2)\n"
332 " SP spike percentage: 0 = round, 100 = snake\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, 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: error -- world not big enough to fit continents.");
420 puts("arguments must satisfy:");
421 puts("nc*sc*sc + nc*sqrt(sc)*2*(di+1) < WORLD_X * WORLD_Y");
426 /****************************************************************************
427 VARIABLE INITIALIZATION
428 ****************************************************************************/
431 allocate_memory(void)
436 fname = malloc(strlen(datadir) + 1 + strlen(empfile[EF_SECTOR].file) + 1);
437 sprintf(fname, "%s/%s", datadir, empfile[EF_SECTOR].file);
438 sect_fptr = fopen(fname, "wb");
439 if (sect_fptr == NULL) {
444 sectsbuf = calloc((YSIZE * XSIZE), sizeof(struct sctstr));
445 sects = calloc(YSIZE, sizeof(struct sctstr *));
446 for (i = 0; i < YSIZE; i++)
447 sects[i] = §sbuf[XSIZE * i];
448 capx = calloc(nc, sizeof(int));
449 capy = calloc(nc, sizeof(int));
450 vector = calloc(WORLD_X + WORLD_Y, sizeof(int));
451 mc = calloc(STABLE_CYCLE, sizeof(int));
452 own = calloc(WORLD_X, sizeof(int *));
453 elev = calloc(WORLD_X, sizeof(int *));
454 for (i = 0; i < WORLD_X; ++i) {
455 own[i] = calloc(WORLD_Y, sizeof(int));
456 elev[i] = calloc(WORLD_Y, sizeof(int));
458 sectx = calloc(nc + ni, sizeof(int *));
459 secty = calloc(nc + ni, sizeof(int *));
460 sectc = calloc(nc + ni, sizeof(int *));
461 isecs = calloc(nc + ni, sizeof(int));
462 weight = calloc(max(sc, is * 2), sizeof(int));
463 dsea = calloc(max(sc, is * 2), sizeof(int));
464 dmoun = calloc(max(sc, is * 2), sizeof(int));
465 for (i = 0; i < nc; ++i) {
466 sectx[i] = calloc(sc, sizeof(int));
467 secty[i] = calloc(sc, sizeof(int));
468 sectc[i] = calloc(sc, sizeof(int));
470 for (i = nc; i < nc + ni; ++i) {
471 sectx[i] = calloc(is * 2, sizeof(int));
472 secty[i] = calloc(is * 2, sizeof(int));
473 sectc[i] = calloc(is * 2, sizeof(int));
482 int i, j, xx = 0, yy = 0;
487 for (i = 0; i < WORLD_X; ++i) {
488 for (j = 0; j < WORLD_Y; ++j) {
490 elev[i][j] = -INFINITY;
494 for (i = 0; i < nc; ++i, xx += 2) {
499 puts("fairland error: world not big enough for all the continents.\n");
506 for (i = 0; i < STABLE_CYCLE; ++i)
510 /****************************************************************************
511 DRIFT THE CAPITALS UNTIL THEY ARE AS FAR AWAY FROM EACH OTHER AS POSSIBLE
512 ****************************************************************************/
514 /* How isolated is capital j?
517 iso(int j, int newx, int newy)
519 int i, md, d = WORLD_X + WORLD_Y;
521 for (i = 0; i < nc; ++i) {
524 md = mapdist(capx[i], capy[i], newx, newy);
532 /* Drift all the capitals
539 for (turns = 0; turns < DRIFT_MAX; ++turns) {
540 if (turns > DRIFT_BEFORE_CHECK && (mind = stable()))
542 for (i = 0; i < nc; ++i)
548 /* Check to see if we have stabilized--can we stop drifting the capitals?
554 int i, isod, d = 0, stab = 1;
556 for (i = 0; i < nc; ++i) {
557 isod = iso(i, capx[i], capy[i]);
561 for (i = 0; i < STABLE_CYCLE; ++i)
565 mcc = (mcc + 1) % STABLE_CYCLE;
569 /* This routine does the actual drifting
575 int i, n, newx, newy;
577 for (i = rnd(6), n = 0; n < 6; i = (i + 1) % 6, ++n) {
578 newx = new_x(capx[j] + dirx[i]);
579 newy = new_y(capy[j] + diry[i]);
580 if (iso(j, newx, newy) >= iso(j, capx[j], capy[j])) {
588 /****************************************************************************
590 ****************************************************************************/
592 /* Look for a coastal sector of continent c
600 for (i = 0; i < secs; ++i) {
602 for (j = 0; j < 6; ++j)
603 if (own[new_x(sectx[c][i] + dirx[j])][new_y(secty[c][i] + diry[j])] == -1)
608 /* Used for measuring distances
620 for (i = 1; i < n && vector[i] == vector[i - 1]; ++i) ;
623 return i > 1 || vector[0] > 0;
626 /* Test to see if we're allowed to grow there: the arguments di and id
629 try_to_grow(int c, int newx, int newy, int d)
633 for (i = 1; i <= d; ++i) {
634 for (j = 0; j < i; ++j)
639 for (j = 0; j < i; ++j) {
640 px = new_x(px + dirx[vector[j]]);
641 py = new_y(py + diry[vector[j]]);
643 if (own[px][py] != -1 &&
645 (DISTINCT_ISLANDS || own[px][py] < nc))
647 } while (next_vector(i));
649 sectx[c][secs] = newx;
650 secty[c][secs] = newy;
655 /* Move along the coast in a clockwise direction.
659 next_coast(int c, int x, int y, int *xp, int *yp)
661 int i, nx, ny, wat = 0;
669 for (i = 0; i < 12; ++i) {
670 nx = new_x(x + dirx[i % 6]);
671 ny = new_y(y + diry[i % 6]);
672 if (own[nx][ny] == -1)
674 if (wat && own[nx][ny] == c) {
682 /* Choose a sector to grow from
694 i = starti = (spike && sectc[c][secs - 1]) ? secs - 1 : rnd(secs);
699 } while (i != starti);
701 printf("fairland: BUG -- couldn't find coast for continent %c, sector %d.\nPlease mail stevens@math.utoronto.ca.\n",
710 /* Grow continent c by 1 sector
714 grow_one_sector(int c)
716 int done, coast_search, try1, x, y, newx, newy, i, n, sx, sy;
718 spike = rnd(100) < sp;
719 if ((try1 = new_try(c)) == -1)
721 x = sx = sectx[c][try1];
722 y = sy = secty[c][try1];
727 for (i = rnd(6), n = 0; n < 12 && !done; i = (i + 1) % 6, ++n) {
728 newx = new_x(x + dirx[i]);
729 newy = new_y(y + diry[i]);
730 if (own[newx][newy] == -1 &&
732 (own[new_x(x+dirx[(i+5)%6])][new_y(y+diry[(i+5)%6])] == -1 &&
733 own[new_x(x+dirx[(i+1)%6])][new_y(y+diry[(i+1)%6])] == -1)))
734 if (try_to_grow(c, newx, newy, c < nc ? di : id))
738 for (i = rnd(6), n = 0; n < 6 && !done; i = (i + 1) % 6, ++n) {
739 newx = new_x(x + dirx[i]);
740 newy = new_y(y + diry[i]);
741 if (own[newx][newy] == -1)
742 if (try_to_grow(c, newx, newy, c < nc ? di : id))
745 next_coast(c, x, y, &x, &y);
747 } while (!done && coast_search < COAST_SEARCH_MAX &&
748 (secs == 1 || x != sx || y != sy));
749 if (!done && c < nc) {
750 qprint("fairland: error -- continent %c had no room to grow!\n",
752 fl_status |= STATUS_NO_ROOM;
757 /* Grow all the continents
760 grow_continents(void)
764 for (c = 0; c < nc; ++c) {
765 sectx[c][0] = capx[c];
766 secty[c][0] = capy[c];
767 own[sectx[c][0]][secty[c][0]] = c;
768 sectx[c][1] = new_x(capx[c] + 2);
769 secty[c][1] = capy[c];
770 own[sectx[c][1]][secty[c][1]] = c;
773 for (secs = 2; secs < sc && !fl_status; ++secs) {
774 for (c = 0; c < nc; ++c) {
779 for (c = 0; c < nc; ++c)
783 qprint("Only managed to grow %d out of %d sectors.\n", secs, sc);
787 /****************************************************************************
789 ****************************************************************************/
791 /* Choose a place to start growing an island from
794 place_island(int c, int *xp, int *yp)
797 int ssy = rnd(WORLD_Y);
798 int ssx = new_x(rnd(WORLD_X / 2) * 2 + ssy % 2);
800 if (ssx > WORLD_X - 2)
801 ssx = new_x(ssx + 2);
802 for (d = di + id; d >= id; --d) {
806 for (*yp = sy; *xp != sx || *yp != sy; *xp += 2) {
807 if (*xp >= WORLD_X) {
808 *yp = new_y(*yp + 1);
810 if (*xp == sx && *yp == sy)
813 if (own[*xp][*yp] == -1 && try_to_grow(c, *xp, *yp, d))
820 /* Grow all the islands
828 for (c = nc; c < nc + ni; ++c) {
830 if (!place_island(c, &x, &y))
832 isiz = 1 + rnd(2 * is - 1);
836 } while (secs < isiz && grow_one_sector(c));
838 qprint(" %d(%d)", c - nc + 1, secs);
844 /****************************************************************************
846 ****************************************************************************/
848 create_elevations(void)
854 /* Generic function for finding the distance to the closest sea, land, or
858 distance_to_what(int x, int y, int flag)
862 for (d = 1; d < 5; ++d) {
863 for (j = 0; j < d; ++j)
868 for (j = 0; j < d; ++j) {
869 px = new_x(px + dirx[vector[j]]);
870 py = new_y(py + diry[vector[j]]);
873 case 0: /* distance to sea */
874 if (own[px][py] == -1)
877 case 1: /* distance to land */
878 if (own[px][py] != -1)
881 case 2: /* distance to mountain */
882 if (elev[px][py] == INFINITY)
886 } while (next_vector(d));
891 #define ELEV elev[sectx[c][i]][secty[c][i]]
892 #define distance_to_sea() (sectc[c][i]?1:distance_to_what(sectx[c][i], secty[c][i], 0))
893 #define distance_to_mountain() distance_to_what(sectx[c][i], secty[c][i], 2)
895 /* Decide where the mountains go
900 int i, mountain_search, k, c, total, ns, nm, highest, where, h, newk,
903 for (c = 0; c < ctot; ++c) {
905 ns = (c < nc) ? sc : isecs[c];
906 nm = (pm * ns) / 100;
908 /* Place the mountains */
910 for (i = 0; i < ns; ++i) {
911 dsea[i] = distance_to_sea();
912 weight[i] = (total += (dsea[i] * dsea[i]));
915 for (k = nm, mountain_search = 0;
916 k && mountain_search < MOUNTAIN_SEARCH_MAX;
919 for (i = 0; i < ns; ++i)
920 if (r < weight[i] && ELEV == -INFINITY &&
922 ((!(capx[c] == sectx[c][i] &&
923 capy[c] == secty[c][i])) &&
924 (!(new_x(capx[c] + 2) == sectx[c][i] &&
925 capy[c] == secty[c][i]))))) {
932 /* Elevate land that is not mountain and not capital */
934 for (i = 0; i < ns; ++i)
935 dmoun[i] = distance_to_mountain();
936 dk = (ns - nm - ((c < nc) ? 3 : 1) > 0) ?
937 (100 * (HIGHMIN - LANDMIN)) / (ns - nm - ((c < nc) ? 3 : 1)) :
939 for (k = 100 * (HIGHMIN - 1);; k -= dk) {
942 for (i = 0; i < ns; ++i) {
943 if (ELEV != INFINITY &&
944 (c >= nc || ((!(capx[c] == sectx[c][i] &&
945 capy[c] == secty[c][i])) &&
946 (!(new_x(capx[c] + 2) == sectx[c][i] &&
947 capy[c] == secty[c][i]))))) {
948 h = 3 * (5 - dmoun[i]) + dsea[i];
958 if (newk >= HILLMIN && newk < PLATMIN)
962 elev[sectx[c][where]][secty[c][where]] = newk;
963 dsea[where] = -INFINITY;
964 dmoun[where] = INFINITY;
967 /* Elevate the mountains and capitals */
969 for (i = 0; i < ns; ++i) {
970 if (ELEV == INFINITY) {
972 ELEV = HILLMIN + rnd(PLATMIN - HILLMIN);
974 ELEV = HIGHMIN + rnd((256 - HIGHMIN) / 2) +
975 rnd((256 - HIGHMIN) / 2);
976 } else if ((c < nc &&
977 ((capx[c] == sectx[c][i] && capy[c] == secty[c][i]))) ||
978 ((new_x(capx[c] + 2) == sectx[c][i] &&
979 capy[c] == secty[c][i])))
985 #define distance_to_land() distance_to_what(x, y, 1)
992 for (y = 0; y < WORLD_Y; ++y) {
993 for (x = y % 2; x < WORLD_X; x += 2) {
994 if (elev[x][y] == -INFINITY)
995 elev[x][y] = -rnd((distance_to_land() * 20 + 27)) - 1;
1000 /****************************************************************************
1002 ****************************************************************************/
1009 fert = LANDMIN - e + 40;
1010 else if (e < FERT_MAX)
1011 fert = (140 * (FERT_MAX - e)) / (FERT_MAX - LANDMIN);
1022 oil = (LANDMIN - e) * 2 + rnd(2);
1023 else if (e <= OIL_MAX)
1024 oil = (120 * (OIL_MAX - e + 1)) / (OIL_MAX - LANDMIN + 1);
1034 if (e >= IRON_MIN && e < HIGHMIN)
1035 iron = (120 * (e - IRON_MIN + 1)) / (HIGHMIN - IRON_MIN);
1045 if (e >= GOLD_MIN) {
1047 gold = (80 * (e - GOLD_MIN + 1)) / (HIGHMIN - GOLD_MIN);
1049 gold = 100 - 20 * HIGHMIN / e;
1060 if (e >= URAN_MIN && e < HIGHMIN)
1061 uran = (120 * (e - URAN_MIN + 1)) / (HIGHMIN - URAN_MIN);
1068 add_resources(struct sctstr *sct)
1070 sct->sct_fertil = set_fert(sct->sct_elev);
1071 sct->sct_oil = set_oil(sct->sct_elev);
1072 sct->sct_min = set_iron(sct->sct_elev);
1073 sct->sct_gmin = set_gold(sct->sct_elev);
1074 sct->sct_uran = set_uran(sct->sct_elev);
1077 /****************************************************************************
1078 DESIGNATE THE SECTORS
1079 ****************************************************************************/
1086 time_t current_time = time(NULL);
1088 /* sct = §s[0][0]; */
1090 for (y = 0; y < YSIZE; y++) {
1091 for (x = 0; x < XSIZE; x++, sct++) {
1092 fl_sct_init(x * 2 + (y & 01), y, (s_char *)sct, current_time);
1093 total = elev[sct->sct_x][y];
1094 if (total < LANDMIN) {
1095 sct->sct_type = SCT_WATER;
1096 } else if (total < HILLMIN)
1097 sct->sct_type = SCT_RURAL;
1098 else if (total < PLATMIN)
1099 sct->sct_type = SCT_MOUNT;
1100 else if (total < HIGHMIN)
1101 sct->sct_type = SCT_RURAL;
1103 sct->sct_type = SCT_MOUNT;
1104 sct->sct_elev = total;
1105 sct->sct_newtype = sct->sct_type;
1111 for (c = 0; c < nc; ++c) {
1112 sects[capy[c]][capx[c] / 2 + capy[c] % 2].sct_type = SCT_AIRPT;
1113 sects[capy[c]][capx[c] / 2 + capy[c] % 2].sct_newtype = SCT_AIRPT;
1115 set_coastal_flags();
1118 /****************************************************************************
1119 WRITE ALL THIS STUFF TO THE FILE
1120 ****************************************************************************/
1126 n = fwrite(sectsbuf, sizeof(struct sctstr), YSIZE * XSIZE, sect_fptr);
1128 perror(empfile[EF_SECTOR].file);
1131 if (n != YSIZE * XSIZE) {
1132 printf("%s:partial write\n", empfile[EF_SECTOR].file);
1139 /****************************************************************************
1140 PRINT A PICTURE OF THE MAP TO YOUR SCREEN
1141 ****************************************************************************/
1147 for (i = 0; i < WORLD_Y; ++i) {
1151 for (j = i % 2; j < WORLD_X; j += 2) {
1152 if (own[j][i] == -1)
1155 printf("%c ", map_symbol(j, i));
1161 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");
1165 map_symbol(int x, int y)
1169 for (c = 0; c < nc; ++c)
1170 if ((x == capx[c] && y == capy[c])
1171 || (x == new_x(capx[c] + 2) && y == capy[c]))
1173 if ((elev[x][y] >= HILLMIN && elev[x][y] < PLATMIN)
1174 || elev[x][y] >= HIGHMIN)
1176 return own[x][y] >= nc ? '%' : iscap ? '#' : numletter[own[x][y] % 62];
1179 /***************************************************************************
1180 WRITE A SCRIPT FOR PLACING CAPITALS
1181 ****************************************************************************/
1183 write_newcap_script(void)
1186 FILE *script = fopen(outfile, "w");
1189 printf("fairland: error, unable to write to %s.\n", outfile);
1193 for (c = 0; c < nc; ++c) {
1194 fprintf(script, "add %d %d %d n i\n", c + 1, c + 1, c + 1);
1196 fprintf(script, "des %d,%d -\n", capx[c], capy[c]);
1197 fprintf(script, "newcap %d %d,%d\n", c + 1, capx[c], capy[c]);
1199 fprintf(script, "add %d visitor visitor v i\n", c + 1);
1202 qprint("\n\nA script for adding all the countries can be found in \"%s\".\n",
1208 qprint(const char * const fmt, ...)
1214 vfprintf(stdout, fmt, ap);
1220 fl_sct_init(coord x, coord y, s_char *ptr, time_t timestamp)
1222 struct sctstr *sp = (struct sctstr *)ptr;
1224 sp->ef_type = EF_SECTOR;
1231 sp->sct_defense = 0;
1232 sp->sct_timestamp = timestamp;
1233 sp->sct_coastal = 1;
1237 set_coastal_flags(void)
1241 qprint("setting coastal flags...\n");
1242 for (i = 0; i < nc; ++i)
1243 for (j = 0; j < sc; j++)
1244 sects[secty[i][j]][sectx[i][j] / 2].sct_coastal = sectc[i][j];
1245 for (i = nc; i < nc + ni; ++i)
1246 for (j = 0; j < isecs[i]; j++)
1247 sects[secty[i][j]][sectx[i][j] / 2].sct_coastal = sectc[i][j];