/* * Empire - A multi-player, client/server Internet based war game. * Copyright (C) 1986-2000, Dave Pare, Jeff Bailey, Thomas Ruschak, * Ken Stevens, Steve McClure * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * --- * * See the "LEGAL", "LICENSE", "CREDITS" and "README" files for all the * related information and legal notices. It is expected that any future * projects/authors will amend these files as needed. * * --- * * land.c: New version of empcre - Create the land masses in the game * * Known contributors to this file: * James Anderson, 1987 * Dave Pare, 1989 */ #include #include #include "var.h" #include "misc.h" #include "power.h" #include "nat.h" #include "sect.h" #include "gamesdef.h" #include "file.h" #include "xy.h" #include "prototypes.h" #define rnd(x) (random() % (x)) #define XPLATES ((WORLD_X) / 2) /* basically world x-y size */ #define YPLATES (WORLD_Y) #define XSIZE (XPLATES) #define YSIZE (YPLATES) #define BIGV 256 /* used in making altitude */ #define SMALLV 128 /* ex-ocean: rnd(SMALLV) - rnd(BIGV) */ typedef enum plates { OCEAN, ISLAND, CONTINENT } plate_e; #define LANDMIN 1 /* plate altitude for normal land */ #define HILLMIN 34 /* plate altitude for hills */ #define PLATMIN 36 /* plate altitude for plateau */ #define HIGHMIN 98 /* plate altitude for mountains */ #define LANDCH 60 /* land plate percentage */ #define NUMLAND (YPLATES * XPLATES * LANDCH)/100 #define NUMISLE NUMLAND/5 /* 1 isle for 5 land */ #define NUMWATER (XPLATES * YPLATES) - (NUMLAND + NUMISLE) #define SECTRANGE 3 /* smoothing area */ #define MINCONTDIST 2 /* minimum continent distance */ #define CHUNKSIZE 2 /* basic land block size */ #define NEWCONTDIST (rnd(mincontdist) + mincontdist) /* dist away from others for newcont */ #define NUMCHUNKS 70 /* number of CHUNKS per cont */ struct sctstr sects[YSIZE][XSIZE]; plate_e plates[YPLATES][XPLATES]; int world[YSIZE][XSIZE]; int sectrange = SECTRANGE; int mincontdist = MINCONTDIST; int chunksize = CHUNKSIZE; int numchunks = NUMCHUNKS; int numisle = NUMISLE; static void initworld(); static void growcont(); static void newcont(); static int verify(); static int makeland(); static void make_altitude(); static int total_land(); static void make_sects(); static void land_sct_init(coord x, coord y, s_char *ptr); int main(argc, argv) int argc; s_char **argv; { extern struct empfile empfile[]; register int n; int x, y; int i, j; time_t now; int fd; int left; int big; if (argc > 1 && argc != 6) { printf("usage: %s sectrange mincontdist chunksize numchunks numisle\n", *argv); return -1; } if (argc == 6) { sectrange = atoi(argv[1]); mincontdist = atoi(argv[2]); chunksize = atoi(argv[3]); numchunks = atoi(argv[4]); numisle = atoi(argv[5]); } printf("sectrange: %d\n", sectrange); printf("mincontdist: %d\n", mincontdist); printf("chunksize: %d\n", chunksize); printf("numchunks: %d\n", numchunks); printf("numisle: %d\n", numisle); fd = open(empfile[EF_SECTOR].file, O_RDWR|O_CREAT|O_TRUNC, 0660); if (fd < 0) { perror(empfile[EF_SECTOR].file); return -1; } time(&now); srandom(now+getpid()); initworld((plate_e *)plates); left = NUMLAND; printf("Creating continents"); while (left > 0) { big = (left / (numchunks * 3 * chunksize*chunksize)) + 1; for (n=0; nsct_type = SCT_WATER; } else if (total < HILLMIN) sct->sct_type = SCT_RURAL; else if (total < PLATMIN) sct->sct_type = SCT_MOUNT; else if (total < HIGHMIN) sct->sct_type = SCT_RURAL; else sct->sct_type = SCT_MOUNT; sct->sct_elev = total; sct->sct_newtype = sct->sct_type; sum += total; if (total < -129) elev[0]++; else if (total > 129) elev[26]++; else elev[13+total/10]++; } } for (i = 0; i < 12+12+3; i++) if (elev[i] != 0) printf("%4d sectors elevation %4d to %4d\n", elev[i], 10*i - 140, 10*i - 130); } static void land_sct_init(coord x, coord y, s_char *ptr) { struct sctstr *sp = (struct sctstr *) ptr; sp->ef_type = EF_SECTOR; sp->sct_x = x; sp->sct_y = y; sp->sct_dist_x = x; sp->sct_dist_y = y; }