2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2000, 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 * ore.c: Create a world
30 * Known contributors to this file:
35 * In the oceans, it puts oil = (2d6-4)*10+d10, fert = (2d6-2)*10+d10
36 * (max of 127 in both cases)
38 * For islands smaller than ISLANDSIZE, it puts in normal
39 * resources. (These are assumed to be small non-start islands)
40 * For islands at least ISLANDSIZE big, it makes normal fert,
41 * but it uses the MIN, OIL, GOLD, and URAN arrays to find out
42 * what resources to put there. The intent is to find all start
43 * islands, and give them all a pre-determined spread of stuff.
44 * To change the stuff, just change the MIN, OIL, GOLD, and URAN arrays.
46 * For example, if the GOLD array is 90,80,70,60, it'll try to put 1
47 * sector with 90 gold, 1 with 80 gold, 1 with 70, and 1 with 60 gold
48 * on each island of at least ISLANDSIZE. It will not overrun start
49 * sectors, and should be run AFTER you have placed capitals.
54 #if defined(aix) || defined(linux) || defined(solaris)
56 #endif /* aix or linux */
67 #include "prototypes.h"
69 #define XPLATES WORLD_X/2
70 #define YPLATES WORLD_Y
71 #define YbyX (YPLATES*XPLATES/8)
73 #define ISLANDMAX 1000
75 int MIN[] = { 90,85,85,85,70,70,70,70,70 };
76 int OIL[] = { 90,80,70,60,50 };
77 int GOLD[] = { 90,80,70,60,50 };
78 int URAN[] = { 90,80,70,60,50 };
85 struct sctstr sects[YPLATES*XPLATES];
86 u_char s[WORLD_Y][WORLD_X];
87 short c[WORLD_Y][WORLD_X];
88 short e[WORLD_Y][WORLD_X];
95 int ix[ISLANDMAX],iy[ISLANDMAX],ic[ISLANDMAX],in=0;
108 register struct sctstr *sp;
113 s_char *sectfil = NULL;
117 char *config_file = NULL;
120 while ((opt = getopt (argc, argp, "e:s:")) != EOF) {
123 config_file = optarg;
131 emp_config (config_file);
134 sectfil = empfile[EF_SECTOR].file;
136 srandom((unsigned int)now);
137 sectf = open(sectfil, O_RDWR, 0);
142 read(sectf, sects, sizeof(sects));
144 for (y = 0; y < WORLD_Y; y++) {
145 for (x = 0; x < WORLD_X; x++) {
148 c[sp->sct_y][sp->sct_x] = 0;
149 s[sp->sct_y][sp->sct_x] = sp->sct_type;
150 e[sp->sct_y][sp->sct_x] = sp->sct_elev;
154 for (y = 0; y < WORLD_Y; y++) {
155 for (x = 0; x < WORLD_X; x++) {
160 if (s[y][x] == SCT_WATER)
165 for(y1=0;y1<WORLD_Y;y1++)
166 for(x1=0;x1<WORLD_X;x1++)
173 if (size[cont] >= ISLANDSIZE){
175 for(y1=0;y1<WORLD_Y;y1++)
176 for(x1=0;x1<WORLD_X;x1++)
177 if (c[y1][x1] == cont){
185 printf("Found island %d of size %d at %d,%d\n",
186 in, size[cont], ix[in-1], iy[in-1]);
189 printf("Found islet %d of size %d\n",
191 for(y1=0;y1<WORLD_Y;y1++)
192 for(x1=0;x1<WORLD_X;x1++)
193 if (c[y1][x1] == cont)
194 c[y1][x1] = ISLANDMAX+1;
200 for (y = 0; y < WORLD_Y; y++) {
201 for (x = 0; x < WORLD_X; x++) {
208 printf("Making ore for island %d\n",x);
209 place(x,MIN,sizeof(MIN)/sizeof(int),OFFSET(sctstr,sct_min),"MIN");
210 place(x,URAN,sizeof(URAN)/sizeof(int),OFFSET(sctstr,sct_uran),"URAN");
211 place(x,OIL,sizeof(OIL)/sizeof(int),OFFSET(sctstr,sct_oil),"OIL");
212 place(x,GOLD,sizeof(GOLD)/sizeof(int),OFFSET(sctstr,sct_gmin),"GOLD");
216 write(sectf, sects, sizeof(sects));
221 #define max(a,b) (a < b ? b : a)
233 if (s[y][x] == SCT_WATER)
244 for (dir = 1; dir <= 6; dir++) {
245 dx = (diroff[dir][0] + x + WORLD_X) % WORLD_X;
246 dy = (diroff[dir][1] + y + WORLD_Y) % WORLD_Y;
251 #define MINIMUM(x,y) (x > y ? y : x)
252 #define MAXIMUM(x,y) (x > y ? x : y)
256 register struct sctstr *sp;
259 int oil, gmin, iron, fertil, ur;
264 if (sp->sct_type == SCT_SANCT)
271 lev = (elev*12 + nearelev(x, y))/18;
279 if (sp->sct_type == SCT_WATER){
280 oil = MAXIMUM(((roll(6)+roll(6)-4)*10+roll(10)),0);
281 sp->sct_oil = MINIMUM(oil,127);
282 fertil = MAXIMUM(((roll(6)+roll(6)-2)*12+roll(10)),0);
283 sp->sct_fertil = MINIMUM(fertil,127);
286 iron = roll(100) + 100-roll(100);
287 oil = roll(100) + 100-roll(100);
288 ur = roll(100) + 100-roll(100);
289 gmin = roll(100) + 100-roll(100);
290 fertil = 85 + 100-roll(100);
292 iron = MAXIMUM(iron,0);
293 oil = MAXIMUM(oil,0);
295 gmin = MAXIMUM(gmin,0);
296 fertil = MAXIMUM(fertil,0);
297 iron = MINIMUM(iron,127);
298 oil = MINIMUM(oil,127);
299 ur = MINIMUM(ur,127);
300 gmin = MINIMUM(gmin,127);
301 fertil = MINIMUM(fertil,127);
303 sp->sct_fertil = fertil;
312 fertil = MAXIMUM(fertil,0);
313 fertil = MINIMUM(fertil,127);
314 sp->sct_fertil = fertil;
329 for (dir = 1; dir <= 6; dir++) {
330 dx = (diroff[dir][0] + x + WORLD_X) % WORLD_X;
331 dy = (diroff[dir][1] + y + WORLD_Y) % WORLD_Y;
337 /* Already in libgen.a
356 place(island,res,num,offset,restype)
357 int island, res[], num, offset;
360 int x1,y1,x2,y2,x3,y3,j,k;
361 int tried[WORLD_Y][WORLD_X];
371 bzero((s_char *)tried,sizeof(tried));
373 while( (sects[y2*XPLATES+x2/2].sct_type==SCT_WATER) ||
374 (*((u_char *)(((s_char *)§s[y2*XPLATES+x2/2])+offset)) > 0) ||
375 (sects[y2*XPLATES+x2/2].sct_type==SCT_MOUNT)){
377 there = *((u_char *)(((s_char *)&
378 sects[y2*XPLATES+x2/2])+offset));
380 foo = §s[y2*XPLATES+x2/2];
382 if (sects[y2*XPLATES+x2/2].sct_type==SCT_RURAL){
386 if (numtried == ISLANDSIZE){
388 printf("*** %d) couldn't place %s %d (%d)\n",island,restype,k,res[k]);
389 for(a=0;a<WORLD_Y;a++)
390 for(b=0;b<WORLD_X;b++)
392 printf("\tTried %d,%d\n",b,a);
399 x3 = (diroff[j][0] + x2 + WORLD_X) % WORLD_X;
400 y3 = (diroff[j][1] + y2 + WORLD_Y) % WORLD_Y;
401 }while(sects[y3*XPLATES+x3/2].sct_type==SCT_WATER);
405 /* sects[y2*XPLATES+x2/2].sct_min = MIN[k]; */
406 *((u_char *)(((s_char *)§s[y2*XPLATES+x2/2])+offset)) = res[k];