2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2007, 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 */
70 #include "../lib/gen/getopt.h"
84 #include "prototypes.h"
89 /* do not change these 4 defines */
90 #define LANDMIN 1 /* plate altitude for normal land */
91 #define HILLMIN 34 /* plate altitude for hills */
92 #define PLATMIN 36 /* plate altitude for plateau */
93 #define HIGHMIN 98 /* plate altitude for mountains */
95 static void qprint(const char * const fmt, ...)
96 ATTRIBUTE((format (printf, 1, 2)));
98 #define DEFAULT_OUTFILE_NAME "newcap_script"
99 static const char *outfile = DEFAULT_OUTFILE_NAME;
100 /* mark the continents with a * so you can tell them
101 from the islands 1 = mark, 0 = don't mark. */
102 static int AIRPORT_MARKER = 0;
104 /* don't let the islands crash into each other.
105 1 = don't merge, 0 = merge. */
106 static int DISTINCT_ISLANDS = 1;
108 static char *program_name;
110 #define XSIZE ((WORLD_X) / 2) /* basically world x-y size */
111 #define YSIZE (WORLD_Y)
112 #define STABLE_CYCLE 4 /* stability required for perterbed capitals */
113 #define INFINITY 999 /* a number which means "BIG" */
115 /* these defines prevent infinite loops:
118 #define COAST_SEARCH_MAX 200 /* how many times do we look for a coast sector
119 when growing continents and islands */
120 #define DRIFT_BEFORE_CHECK ((WORLD_X + WORLD_Y)/2)
121 #define DRIFT_MAX ((WORLD_X + WORLD_Y)*2)
122 #define MOUNTAIN_SEARCH_MAX 1000 /* how long do we try to place mountains */
127 #define new_x(newx) (((newx) + WORLD_X) % WORLD_X)
128 #define new_y(newy) (((newy) + WORLD_Y) % WORLD_Y)
129 #define rnd(x) (random() % (x))
131 int secs; /* number of sectors grown */
132 int ctot; /* total number of continents and islands grown */
133 int *isecs; /* array of how large each island is */
135 int nc, sc, di, sp, pm, ni, is, id; /* the 8 arguments to this program */
136 unsigned long rnd_seed; /* optional seed can be passed as an argument */
137 int *capx, *capy; /* location of the nc capitals */
138 int *mc, mcc; /* array and counter used for stability
139 check when perturbing */
140 int spike; /* are we spiking? */
141 int mind; /* the final distance between capitals that
143 int dirx[] = { -2, -1, 1, 2, 1, -1 }; /* gyujnb */
144 int diry[] = { 0, -1, -1, 0, 1, 1 };
146 int **own; /* owner of the sector. -1 means water */
147 int **elev; /* elevation of the sectors */
148 int **sectx, **secty; /* the sectors for each continent */
149 int **sectc; /* which sectors are on the coast? */
150 int *vector; /* used for measuring distances */
151 int *weight; /* used for placing mountains */
152 int *dsea, *dmoun; /* the dist to the ocean and mountain */
153 FILE *sect_fptr; /* the file we write everything to */
154 struct sctstr **sects;
155 struct sctstr *sectsbuf;
156 int fl_status; /* is anything wrong? */
157 #define STATUS_NO_ROOM 1 /* there was no room to grow */
158 #define NUMTRIES 10 /* keep trying to grow this many times */
160 const char *numletter =
161 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
163 static void help(char *);
164 static void usage(void);
165 static void parse_args(int argc, char *argv[]);
166 static int allocate_memory(void);
167 static void init(void);
168 static int drift(void);
169 static void grow_continents(void);
170 static void create_elevations(void);
171 static void write_sects(void);
172 static int write_file(void);
173 static void output(void);
174 static int write_newcap_script(void);
175 static int stable(void);
176 static void elevate_land(void);
177 static void elevate_sea(void);
178 static int map_symbol(int x, int y);
179 static void fl_sct_init(coord, coord, struct sctstr *, time_t timestamp);
180 static void set_coastal_flags(void);
182 static void print_vars(void);
183 static void fl_move(int);
184 static void next_coast(int c, int x, int y, int *xp, int *yp);
185 static void grow_islands(void);
187 /****************************************************************************
189 ****************************************************************************/
192 main(int argc, char *argv[])
195 char *config_file = NULL;
198 program_name = argv[0];
199 rnd_seed = time(NULL);
201 while ((opt = getopt(argc, argv, "ae:hioqR:s:v")) != EOF) {
207 config_file = optarg;
210 DISTINCT_ISLANDS = 0;
219 rnd_seed = strtoul(optarg, NULL, 10);
228 printf("%s\n\n%s", version, legal);
236 if (emp_config(config_file))
239 parse_args(argc - optind, argv + optind);
240 if (allocate_memory() == -1)
247 qprint("\ntry #%d (out of %d)...", i + 1, NUMTRIES);
248 qprint("\n\n #*# ...fairland rips open a rift in the datumplane... #*#\n\n");
249 qprint("seed is %lu\n", rnd_seed);
250 qprint("placing capitals...\n");
252 qprint("fairland: unstable drift -- try increasisg DRIFT_MAX\n");
253 qprint("growing continents...\n");
255 } while (fl_status && ++i < NUMTRIES);
257 fputs("ERROR: World not large enough to hold continents\n",
261 qprint("growing islands:");
263 qprint("\nelevating land...\n");
265 qprint("designating sectors...\n");
267 qprint("adding resources...\n");
269 qprint("writing to sectors file...\n");
270 if (write_file() == -1)
273 write_newcap_script();
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: error -- world not big enough to fit continents.");
422 puts("arguments must satisfy:");
423 puts("nc*sc*sc + nc*sqrt(sc)*2*(di+1) < WORLD_X * WORLD_Y");
428 /****************************************************************************
429 VARIABLE INITIALIZATION
430 ****************************************************************************/
433 allocate_memory(void)
438 fname = malloc(strlen(gamedir) + 1 + strlen(empfile[EF_SECTOR].file) + 1);
439 sprintf(fname, "%s/%s", gamedir, empfile[EF_SECTOR].file);
440 sect_fptr = fopen(fname, "wb");
441 if (sect_fptr == NULL) {
446 sectsbuf = calloc((YSIZE * XSIZE), sizeof(struct sctstr));
447 sects = calloc(YSIZE, sizeof(struct sctstr *));
448 for (i = 0; i < YSIZE; i++)
449 sects[i] = §sbuf[XSIZE * i];
450 capx = calloc(nc, sizeof(int));
451 capy = calloc(nc, sizeof(int));
452 vector = calloc(WORLD_X + WORLD_Y, sizeof(int));
453 mc = calloc(STABLE_CYCLE, sizeof(int));
454 own = calloc(WORLD_X, sizeof(int *));
455 elev = calloc(WORLD_X, sizeof(int *));
456 for (i = 0; i < WORLD_X; ++i) {
457 own[i] = calloc(WORLD_Y, sizeof(int));
458 elev[i] = calloc(WORLD_Y, sizeof(int));
460 sectx = calloc(nc + ni, sizeof(int *));
461 secty = calloc(nc + ni, sizeof(int *));
462 sectc = calloc(nc + ni, sizeof(int *));
463 isecs = calloc(nc + ni, sizeof(int));
464 weight = calloc(MAX(sc, is * 2), sizeof(int));
465 dsea = calloc(MAX(sc, is * 2), sizeof(int));
466 dmoun = calloc(MAX(sc, is * 2), sizeof(int));
467 for (i = 0; i < nc; ++i) {
468 sectx[i] = calloc(sc, sizeof(int));
469 secty[i] = calloc(sc, sizeof(int));
470 sectc[i] = calloc(sc, sizeof(int));
472 for (i = nc; i < nc + ni; ++i) {
473 sectx[i] = calloc(is * 2, sizeof(int));
474 secty[i] = calloc(is * 2, sizeof(int));
475 sectc[i] = calloc(is * 2, sizeof(int));
484 int i, j, xx = 0, yy = 0;
489 for (i = 0; i < WORLD_X; ++i) {
490 for (j = 0; j < WORLD_Y; ++j) {
492 elev[i][j] = -INFINITY;
496 for (i = 0; i < nc; ++i, xx += 2) {
501 puts("fairland error: world not big enough for all the continents.\n");
508 for (i = 0; i < STABLE_CYCLE; ++i)
512 /****************************************************************************
513 DRIFT THE CAPITALS UNTIL THEY ARE AS FAR AWAY FROM EACH OTHER AS POSSIBLE
514 ****************************************************************************/
516 /* How isolated is capital j?
519 iso(int j, int newx, int newy)
521 int i, md, d = WORLD_X + WORLD_Y;
523 for (i = 0; i < nc; ++i) {
526 md = mapdist(capx[i], capy[i], newx, newy);
534 /* Drift all the capitals
541 for (turns = 0; turns < DRIFT_MAX; ++turns) {
542 if (turns > DRIFT_BEFORE_CHECK && (mind = stable()))
544 for (i = 0; i < nc; ++i)
550 /* Check to see if we have stabilized--can we stop drifting the capitals?
556 int i, isod, d = 0, stab = 1;
558 for (i = 0; i < nc; ++i) {
559 isod = iso(i, capx[i], capy[i]);
563 for (i = 0; i < STABLE_CYCLE; ++i)
567 mcc = (mcc + 1) % STABLE_CYCLE;
571 /* This routine does the actual drifting
577 int i, n, newx, newy;
579 for (i = rnd(6), n = 0; n < 6; i = (i + 1) % 6, ++n) {
580 newx = new_x(capx[j] + dirx[i]);
581 newy = new_y(capy[j] + diry[i]);
582 if (iso(j, newx, newy) >= iso(j, capx[j], capy[j])) {
590 /****************************************************************************
592 ****************************************************************************/
594 /* Look for a coastal sector of continent c
602 for (i = 0; i < secs; ++i) {
604 for (j = 0; j < 6; ++j)
605 if (own[new_x(sectx[c][i] + dirx[j])][new_y(secty[c][i] + diry[j])] == -1)
610 /* Used for measuring distances
622 for (i = 1; i < n && vector[i] == vector[i - 1]; ++i) ;
625 return i > 1 || vector[0] > 0;
628 /* Test to see if we're allowed to grow there: the arguments di and id
631 try_to_grow(int c, int newx, int newy, int d)
635 for (i = 1; i <= d; ++i) {
636 for (j = 0; j < i; ++j)
641 for (j = 0; j < i; ++j) {
642 px = new_x(px + dirx[vector[j]]);
643 py = new_y(py + diry[vector[j]]);
645 if (own[px][py] != -1 &&
647 (DISTINCT_ISLANDS || own[px][py] < nc))
649 } while (next_vector(i));
651 sectx[c][secs] = newx;
652 secty[c][secs] = newy;
657 /* Move along the coast in a clockwise direction.
661 next_coast(int c, int x, int y, int *xp, int *yp)
663 int i, nx, ny, wat = 0;
671 for (i = 0; i < 12; ++i) {
672 nx = new_x(x + dirx[i % 6]);
673 ny = new_y(y + diry[i % 6]);
674 if (own[nx][ny] == -1)
676 if (wat && own[nx][ny] == c) {
684 /* Choose a sector to grow from
696 i = starti = (spike && sectc[c][secs - 1]) ? secs - 1 : rnd(secs);
701 } while (i != starti);
703 printf("fairland: BUG -- couldn't find coast for continent %c, sector %d.\nPlease mail stevens@math.utoronto.ca.\n",
712 /* Grow continent c by 1 sector
716 grow_one_sector(int c)
718 int done, coast_search, try1, x, y, newx, newy, i, n, sx, sy;
720 spike = rnd(100) < sp;
721 if ((try1 = new_try(c)) == -1)
723 x = sx = sectx[c][try1];
724 y = sy = secty[c][try1];
729 for (i = rnd(6), n = 0; n < 12 && !done; i = (i + 1) % 6, ++n) {
730 newx = new_x(x + dirx[i]);
731 newy = new_y(y + diry[i]);
732 if (own[newx][newy] == -1 &&
734 (own[new_x(x+dirx[(i+5)%6])][new_y(y+diry[(i+5)%6])] == -1 &&
735 own[new_x(x+dirx[(i+1)%6])][new_y(y+diry[(i+1)%6])] == -1)))
736 if (try_to_grow(c, newx, newy, c < nc ? di : id))
740 for (i = rnd(6), n = 0; n < 6 && !done; i = (i + 1) % 6, ++n) {
741 newx = new_x(x + dirx[i]);
742 newy = new_y(y + diry[i]);
743 if (own[newx][newy] == -1)
744 if (try_to_grow(c, newx, newy, c < nc ? di : id))
747 next_coast(c, x, y, &x, &y);
749 } while (!done && coast_search < COAST_SEARCH_MAX &&
750 (secs == 1 || x != sx || y != sy));
751 if (!done && c < nc) {
752 qprint("fairland: error -- continent %c had no room to grow!\n",
754 fl_status |= STATUS_NO_ROOM;
759 /* Grow all the continents
762 grow_continents(void)
766 for (c = 0; c < nc; ++c) {
767 sectx[c][0] = capx[c];
768 secty[c][0] = capy[c];
769 own[sectx[c][0]][secty[c][0]] = c;
770 sectx[c][1] = new_x(capx[c] + 2);
771 secty[c][1] = capy[c];
772 own[sectx[c][1]][secty[c][1]] = c;
775 for (secs = 2; secs < sc && !fl_status; ++secs) {
776 for (c = 0; c < nc; ++c) {
781 for (c = 0; c < nc; ++c)
785 qprint("Only managed to grow %d out of %d sectors.\n", secs, sc);
789 /****************************************************************************
791 ****************************************************************************/
793 /* Choose a place to start growing an island from
796 place_island(int c, int *xp, int *yp)
799 int ssy = rnd(WORLD_Y);
800 int ssx = new_x(rnd(WORLD_X / 2) * 2 + ssy % 2);
802 if (ssx > WORLD_X - 2)
803 ssx = new_x(ssx + 2);
804 for (d = di + id; d >= id; --d) {
808 for (*yp = sy; *xp != sx || *yp != sy; *xp += 2) {
809 if (*xp >= WORLD_X) {
810 *yp = new_y(*yp + 1);
812 if (*xp == sx && *yp == sy)
815 if (own[*xp][*yp] == -1 && try_to_grow(c, *xp, *yp, d))
822 /* Grow all the islands
830 for (c = nc; c < nc + ni; ++c) {
832 if (!place_island(c, &x, &y))
834 isiz = 1 + rnd(2 * is - 1);
838 } while (secs < isiz && grow_one_sector(c));
840 qprint(" %d(%d)", c - nc + 1, secs);
846 /****************************************************************************
848 ****************************************************************************/
850 create_elevations(void)
856 /* Generic function for finding the distance to the closest sea, land, or
860 distance_to_what(int x, int y, int flag)
864 for (d = 1; d < 5; ++d) {
865 for (j = 0; j < d; ++j)
870 for (j = 0; j < d; ++j) {
871 px = new_x(px + dirx[vector[j]]);
872 py = new_y(py + diry[vector[j]]);
875 case 0: /* distance to sea */
876 if (own[px][py] == -1)
879 case 1: /* distance to land */
880 if (own[px][py] != -1)
883 case 2: /* distance to mountain */
884 if (elev[px][py] == INFINITY)
888 } while (next_vector(d));
893 #define ELEV elev[sectx[c][i]][secty[c][i]]
894 #define distance_to_sea() (sectc[c][i]?1:distance_to_what(sectx[c][i], secty[c][i], 0))
895 #define distance_to_mountain() distance_to_what(sectx[c][i], secty[c][i], 2)
897 /* Decide where the mountains go
902 int i, mountain_search, k, c, total, ns, nm, highest, where, h, newk,
905 for (c = 0; c < ctot; ++c) {
907 ns = (c < nc) ? sc : isecs[c];
908 nm = (pm * ns) / 100;
910 /* Place the mountains */
912 for (i = 0; i < ns; ++i) {
913 dsea[i] = distance_to_sea();
914 weight[i] = (total += (dsea[i] * dsea[i]));
917 for (k = nm, mountain_search = 0;
918 k && mountain_search < MOUNTAIN_SEARCH_MAX;
921 for (i = 0; i < ns; ++i)
922 if (r < weight[i] && ELEV == -INFINITY &&
924 ((!(capx[c] == sectx[c][i] &&
925 capy[c] == secty[c][i])) &&
926 (!(new_x(capx[c] + 2) == sectx[c][i] &&
927 capy[c] == secty[c][i]))))) {
934 /* Elevate land that is not mountain and not capital */
936 for (i = 0; i < ns; ++i)
937 dmoun[i] = distance_to_mountain();
938 dk = (ns - nm - ((c < nc) ? 3 : 1) > 0) ?
939 (100 * (HIGHMIN - LANDMIN)) / (ns - nm - ((c < nc) ? 3 : 1)) :
941 for (k = 100 * (HIGHMIN - 1);; k -= dk) {
944 for (i = 0; i < ns; ++i) {
945 if (ELEV != INFINITY &&
946 (c >= nc || ((!(capx[c] == sectx[c][i] &&
947 capy[c] == secty[c][i])) &&
948 (!(new_x(capx[c] + 2) == sectx[c][i] &&
949 capy[c] == secty[c][i]))))) {
950 h = 3 * (5 - dmoun[i]) + dsea[i];
960 if (newk >= HILLMIN && newk < PLATMIN)
964 elev[sectx[c][where]][secty[c][where]] = newk;
965 dsea[where] = -INFINITY;
966 dmoun[where] = INFINITY;
969 /* Elevate the mountains and capitals */
971 for (i = 0; i < ns; ++i) {
972 if (ELEV == INFINITY) {
974 ELEV = HILLMIN + rnd(PLATMIN - HILLMIN);
976 ELEV = HIGHMIN + rnd((256 - HIGHMIN) / 2) +
977 rnd((256 - HIGHMIN) / 2);
978 } else if ((c < nc &&
979 ((capx[c] == sectx[c][i] && capy[c] == secty[c][i]))) ||
980 ((new_x(capx[c] + 2) == sectx[c][i] &&
981 capy[c] == secty[c][i])))
987 #define distance_to_land() distance_to_what(x, y, 1)
994 for (y = 0; y < WORLD_Y; ++y) {
995 for (x = y % 2; x < WORLD_X; x += 2) {
996 if (elev[x][y] == -INFINITY)
997 elev[x][y] = -rnd((distance_to_land() * 20 + 27)) - 1;
1002 /****************************************************************************
1004 ****************************************************************************/
1011 fert = LANDMIN - e + 40;
1012 else if (e < FERT_MAX)
1013 fert = (140 * (FERT_MAX - e)) / (FERT_MAX - LANDMIN);
1024 oil = (LANDMIN - e) * 2 + rnd(2);
1025 else if (e <= OIL_MAX)
1026 oil = (120 * (OIL_MAX - e + 1)) / (OIL_MAX - LANDMIN + 1);
1036 if (e >= IRON_MIN && e < HIGHMIN)
1037 iron = (120 * (e - IRON_MIN + 1)) / (HIGHMIN - IRON_MIN);
1047 if (e >= GOLD_MIN) {
1049 gold = (80 * (e - GOLD_MIN + 1)) / (HIGHMIN - GOLD_MIN);
1051 gold = 100 - 20 * HIGHMIN / e;
1062 if (e >= URAN_MIN && e < HIGHMIN)
1063 uran = (120 * (e - URAN_MIN + 1)) / (HIGHMIN - URAN_MIN);
1070 add_resources(struct sctstr *sct)
1072 sct->sct_fertil = set_fert(sct->sct_elev);
1073 sct->sct_oil = set_oil(sct->sct_elev);
1074 sct->sct_min = set_iron(sct->sct_elev);
1075 sct->sct_gmin = set_gold(sct->sct_elev);
1076 sct->sct_uran = set_uran(sct->sct_elev);
1079 /****************************************************************************
1080 DESIGNATE THE SECTORS
1081 ****************************************************************************/
1088 time_t current_time = time(NULL);
1090 /* sct = §s[0][0]; */
1092 for (y = 0; y < YSIZE; y++) {
1093 for (x = 0; x < XSIZE; x++, sct++) {
1094 fl_sct_init(x * 2 + (y & 1), y, sct, current_time);
1095 total = elev[sct->sct_x][y];
1096 if (total < LANDMIN) {
1097 sct->sct_type = SCT_WATER;
1098 } else if (total < HILLMIN)
1099 sct->sct_type = SCT_RURAL;
1100 else if (total < PLATMIN)
1101 sct->sct_type = SCT_MOUNT;
1102 else if (total < HIGHMIN)
1103 sct->sct_type = SCT_RURAL;
1105 sct->sct_type = SCT_MOUNT;
1106 sct->sct_elev = total;
1107 sct->sct_newtype = sct->sct_type;
1113 for (c = 0; c < nc; ++c) {
1114 sects[capy[c]][capx[c] / 2 + capy[c] % 2].sct_type = SCT_AIRPT;
1115 sects[capy[c]][capx[c] / 2 + capy[c] % 2].sct_newtype = SCT_AIRPT;
1117 set_coastal_flags();
1120 /****************************************************************************
1121 WRITE ALL THIS STUFF TO THE FILE
1122 ****************************************************************************/
1128 n = fwrite(sectsbuf, sizeof(struct sctstr), YSIZE * XSIZE, sect_fptr);
1130 perror(empfile[EF_SECTOR].file);
1133 if (n != YSIZE * XSIZE) {
1134 printf("%s:partial write\n", empfile[EF_SECTOR].file);
1141 /****************************************************************************
1142 PRINT A PICTURE OF THE MAP TO YOUR SCREEN
1143 ****************************************************************************/
1149 for (i = 0; i < WORLD_Y; ++i) {
1153 for (j = i % 2; j < WORLD_X; j += 2) {
1154 if (own[j][i] == -1)
1157 printf("%c ", map_symbol(j, i));
1163 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");
1167 map_symbol(int x, int y)
1171 for (c = 0; c < nc; ++c)
1172 if ((x == capx[c] && y == capy[c])
1173 || (x == new_x(capx[c] + 2) && y == capy[c]))
1175 if ((elev[x][y] >= HILLMIN && elev[x][y] < PLATMIN)
1176 || elev[x][y] >= HIGHMIN)
1178 return own[x][y] >= nc ? '%' : iscap ? '#' : numletter[own[x][y] % 62];
1181 /***************************************************************************
1182 WRITE A SCRIPT FOR PLACING CAPITALS
1183 ****************************************************************************/
1185 write_newcap_script(void)
1188 FILE *script = fopen(outfile, "w");
1191 printf("fairland: error, unable to write to %s.\n", outfile);
1195 for (c = 0; c < nc; ++c) {
1196 fprintf(script, "add %d %d %d n i\n", c + 1, c + 1, c + 1);
1198 fprintf(script, "des %d,%d -\n", capx[c], capy[c]);
1199 fprintf(script, "newcap %d %d,%d\n", c + 1, capx[c], capy[c]);
1201 fprintf(script, "add %d visitor visitor v i\n", c + 1);
1204 qprint("\n\nA script for adding all the countries can be found in \"%s\".\n",
1210 qprint(const char * const fmt, ...)
1216 vfprintf(stdout, fmt, ap);
1222 fl_sct_init(coord x, coord y, struct sctstr *sp, time_t timestamp)
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];