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 * perfect.c: Create a perfect world
30 * Known contributors to this file:
31 * James Anderson, 1986
35 #if defined(aix) || defined(linux) || defined(solaris)
37 #endif /* aix or linux */
48 #include "prototypes.h"
50 #define XPLATES (WORLD_X / 2)
51 #define YPLATES WORLD_Y
52 #define YbyX (YPLATES*XPLATES/8)
54 struct sctstr sects[YPLATES * XPLATES];
55 u_char s[YPLATES][XPLATES];
56 short c[YPLATES][XPLATES];
57 short e[YPLATES][XPLATES];
74 register struct sctstr *sp;
80 s_char *sectfil = NULL;
83 char *config_file = NULL;
86 while ((opt = getopt(argc, argp, "e:s:")) != EOF) {
97 emp_config(config_file);
100 sectfil = empfile[EF_SECTOR].file;
103 srandom((unsigned int)now);
104 sectf = open(sectfil, O_RDWR, 0);
109 read(sectf, sects, sizeof(sects));
111 for (y = 0; y < WORLD_Y; y++) {
112 for (x = 0; x < WORLD_X; x++) {
116 s[y][x / 2] = sp->sct_type;
117 e[y][x / 2] = sp->sct_elev;
121 for (y = 0; y < WORLD_Y; y++) {
122 for (x = 0; x < WORLD_X; x++) {
125 if (c[y][x / 2] != 0)
130 printf("size oil gold fert iron\n");
131 for (i = 1; i < YbyX && size[i]; i++) {
132 oilchance[i] = 5 + roll(75) - min(size[i] / 15, 10);
133 /* goldchance[i] = 3 + roll(45) - */
134 goldchance[i] = 3 + roll(55) -
135 (oilchance[i] + min(size[i] / 15, 10));
136 /* urchance[i] = roll(40) - goldchance[i]; */
137 urchance[i] = roll(30) - goldchance[i];
138 fertchance[i] = roll(40) - (goldchance[i] + oilchance[i]);
139 ironchance[i] = roll(45) - (goldchance[i] + oilchance[i] / 2);
141 printf("%3d %3d %3d %3d %3d\n",
142 size[i], oilchance[i], goldchance[i],
143 fertchance[i], ironchance[i]);
147 printf("Oops. YbyX not big enough\n");
149 for (y = 0; y < WORLD_Y; y++) {
150 for (x = 0; x < WORLD_X; x++) {
157 write(sectf, sects, sizeof(sects));
164 #define max(a,b) (a < b ? b : a)
177 if (s[y][x / 2] == SCT_WATER)
186 for (dir = 1; dir <= 6; dir++) {
187 dx = (diroff[dir][0] + x + WORLD_X) % WORLD_X;
188 dy = (diroff[dir][1] + y + WORLD_Y) % WORLD_Y;
195 register struct sctstr *sp;
198 int oil, gmin, iron, fertil, ur;
206 lev = (elev * 12 + nearelev(x, y)) / 18;
213 if (lev < 20 && lev > -15 && roll(100) < 30 + oilchance[i] + lev) {
214 oil = (45 - lev) + roll(50);
220 if (lev > 15 && roll(20 + lev) < lev + ironchance[i]) {
221 iron = lev + roll(55);
227 if (lev > 16 && roll(35 + lev) < lev + goldchance[i]) {
228 gmin = (lev - 5) + roll(45);
234 if (lev > 14 && roll(35 + lev) < lev + urchance[i]) {
235 ur = (lev - 5) + roll(45);
241 fertil = (85 + fertchance[i] - lev) - (((iron + gmin) / 2) - oil / 3);
249 sp->sct_fertil = 100;
264 for (dir = 1; dir <= 6; dir++) {
265 dx = (diroff[dir][0] + x + WORLD_X) % WORLD_X;
266 dy = (diroff[dir][1] + y + WORLD_Y) % WORLD_Y;
267 level += e[dy][dx / 2];
272 /* Already in libgen.a