setup.c revision 1.4 1 1.4 cgd /* $NetBSD: setup.c,v 1.4 1995/04/24 12:26:06 cgd Exp $ */
2 1.3 cgd
3 1.1 cgd /*
4 1.3 cgd * Copyright (c) 1980, 1993
5 1.3 cgd * The Regents of the University of California. All rights reserved.
6 1.1 cgd *
7 1.1 cgd * Redistribution and use in source and binary forms, with or without
8 1.1 cgd * modification, are permitted provided that the following conditions
9 1.1 cgd * are met:
10 1.1 cgd * 1. Redistributions of source code must retain the above copyright
11 1.1 cgd * notice, this list of conditions and the following disclaimer.
12 1.1 cgd * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 cgd * notice, this list of conditions and the following disclaimer in the
14 1.1 cgd * documentation and/or other materials provided with the distribution.
15 1.1 cgd * 3. All advertising materials mentioning features or use of this software
16 1.1 cgd * must display the following acknowledgement:
17 1.1 cgd * This product includes software developed by the University of
18 1.1 cgd * California, Berkeley and its contributors.
19 1.1 cgd * 4. Neither the name of the University nor the names of its contributors
20 1.1 cgd * may be used to endorse or promote products derived from this software
21 1.1 cgd * without specific prior written permission.
22 1.1 cgd *
23 1.1 cgd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 1.1 cgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 1.1 cgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 1.1 cgd * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 1.1 cgd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 1.1 cgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 1.1 cgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 1.1 cgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 1.1 cgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 1.1 cgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 1.1 cgd * SUCH DAMAGE.
34 1.1 cgd */
35 1.1 cgd
36 1.1 cgd #ifndef lint
37 1.3 cgd #if 0
38 1.3 cgd static char sccsid[] = "@(#)setup.c 8.1 (Berkeley) 5/31/93";
39 1.3 cgd #else
40 1.4 cgd static char rcsid[] = "$NetBSD: setup.c,v 1.4 1995/04/24 12:26:06 cgd Exp $";
41 1.3 cgd #endif
42 1.1 cgd #endif /* not lint */
43 1.1 cgd
44 1.1 cgd # include "trek.h"
45 1.1 cgd # include "getpar.h"
46 1.1 cgd
47 1.1 cgd /*
48 1.1 cgd ** INITIALIZE THE GAME
49 1.1 cgd **
50 1.1 cgd ** The length, skill, and password are read, and the game
51 1.1 cgd ** is initialized. It is far too difficult to describe all
52 1.1 cgd ** that goes on in here, but it is all straight-line code;
53 1.1 cgd ** give it a look.
54 1.1 cgd **
55 1.1 cgd ** Game restart and tournament games are handled here.
56 1.1 cgd */
57 1.1 cgd
58 1.1 cgd struct cvntab Lentab[] =
59 1.1 cgd {
60 1.1 cgd "s", "hort", (int (*)())1, 0,
61 1.1 cgd "m", "edium", (int (*)())2, 0,
62 1.1 cgd "l", "ong", (int (*)())4, 0,
63 1.1 cgd "restart", "", 0, 0,
64 1.1 cgd 0
65 1.1 cgd };
66 1.1 cgd
67 1.1 cgd struct cvntab Skitab[] =
68 1.1 cgd {
69 1.1 cgd "n", "ovice", (int (*)())1, 0,
70 1.1 cgd "f", "air", (int (*)())2, 0,
71 1.1 cgd "g", "ood", (int (*)())3, 0,
72 1.1 cgd "e", "xpert", (int (*)())4, 0,
73 1.1 cgd "c", "ommodore", (int (*)())5, 0,
74 1.1 cgd "i", "mpossible", (int (*)())6, 0,
75 1.1 cgd 0
76 1.1 cgd };
77 1.1 cgd
78 1.1 cgd setup()
79 1.1 cgd {
80 1.1 cgd struct cvntab *r;
81 1.1 cgd register int i, j;
82 1.1 cgd double f;
83 1.1 cgd int d;
84 1.1 cgd int fd;
85 1.1 cgd int klump;
86 1.1 cgd int ix, iy;
87 1.1 cgd register struct quad *q;
88 1.1 cgd struct event *e;
89 1.1 cgd
90 1.1 cgd while (1)
91 1.1 cgd {
92 1.1 cgd r = getcodpar("What length game", Lentab);
93 1.4 cgd Game.length = (long) r->value;
94 1.1 cgd if (Game.length == 0)
95 1.1 cgd {
96 1.1 cgd if (restartgame())
97 1.1 cgd continue;
98 1.1 cgd return;
99 1.1 cgd }
100 1.1 cgd break;
101 1.1 cgd }
102 1.1 cgd r = getcodpar("What skill game", Skitab);
103 1.4 cgd Game.skill = (long) r->value;
104 1.1 cgd Game.tourn = 0;
105 1.1 cgd getstrpar("Enter a password", Game.passwd, 14, 0);
106 1.1 cgd if (sequal(Game.passwd, "tournament"))
107 1.1 cgd {
108 1.1 cgd getstrpar("Enter tournament code", Game.passwd, 14, 0);
109 1.1 cgd Game.tourn = 1;
110 1.1 cgd d = 0;
111 1.1 cgd for (i = 0; Game.passwd[i]; i++)
112 1.1 cgd d += Game.passwd[i] << i;
113 1.1 cgd srand(d);
114 1.1 cgd }
115 1.1 cgd Param.bases = Now.bases = ranf(6 - Game.skill) + 2;
116 1.1 cgd if (Game.skill == 6)
117 1.1 cgd Param.bases = Now.bases = 1;
118 1.1 cgd Param.time = Now.time = 6.0 * Game.length + 2.0;
119 1.1 cgd i = Game.skill;
120 1.1 cgd j = Game.length;
121 1.1 cgd Param.klings = Now.klings = i * j * 3.5 * (franf() + 0.75);
122 1.1 cgd if (Param.klings < i * j * 5)
123 1.1 cgd Param.klings = Now.klings = i * j * 5;
124 1.1 cgd if (Param.klings <= i) /* numerical overflow problems */
125 1.1 cgd Param.klings = Now.klings = 127;
126 1.1 cgd Param.energy = Ship.energy = 5000;
127 1.1 cgd Param.torped = Ship.torped = 10;
128 1.1 cgd Ship.ship = ENTERPRISE;
129 1.1 cgd Ship.shipname = "Enterprise";
130 1.1 cgd Param.shield = Ship.shield = 1500;
131 1.1 cgd Param.resource = Now.resource = Param.klings * Param.time;
132 1.1 cgd Param.reserves = Ship.reserves = (6 - Game.skill) * 2.0;
133 1.1 cgd Param.crew = Ship.crew = 387;
134 1.1 cgd Param.brigfree = Ship.brigfree = 400;
135 1.1 cgd Ship.shldup = 1;
136 1.1 cgd Ship.cond = GREEN;
137 1.1 cgd Ship.warp = 5.0;
138 1.1 cgd Ship.warp2 = 25.0;
139 1.1 cgd Ship.warp3 = 125.0;
140 1.1 cgd Ship.sinsbad = 0;
141 1.1 cgd Ship.cloaked = 0;
142 1.1 cgd Param.date = Now.date = (ranf(20) + 20) * 100;
143 1.1 cgd f = Game.skill;
144 1.1 cgd f = log(f + 0.5);
145 1.1 cgd for (i = 0; i < NDEV; i++)
146 1.1 cgd if (Device[i].name[0] == '*')
147 1.1 cgd Param.damfac[i] = 0;
148 1.1 cgd else
149 1.1 cgd Param.damfac[i] = f;
150 1.1 cgd /* these probabilities must sum to 1000 */
151 1.1 cgd Param.damprob[WARP] = 70; /* warp drive 7.0% */
152 1.1 cgd Param.damprob[SRSCAN] = 110; /* short range scanners 11.0% */
153 1.1 cgd Param.damprob[LRSCAN] = 110; /* long range scanners 11.0% */
154 1.1 cgd Param.damprob[PHASER] = 125; /* phasers 12.5% */
155 1.1 cgd Param.damprob[TORPED] = 125; /* photon torpedoes 12.5% */
156 1.1 cgd Param.damprob[IMPULSE] = 75; /* impulse engines 7.5% */
157 1.1 cgd Param.damprob[SHIELD] = 150; /* shield control 15.0% */
158 1.1 cgd Param.damprob[COMPUTER] = 20; /* computer 2.0% */
159 1.1 cgd Param.damprob[SSRADIO] = 35; /* subspace radio 3.5% */
160 1.1 cgd Param.damprob[LIFESUP] = 30; /* life support 3.0% */
161 1.1 cgd Param.damprob[SINS] = 20; /* navigation system 2.0% */
162 1.1 cgd Param.damprob[CLOAK] = 50; /* cloaking device 5.0% */
163 1.1 cgd Param.damprob[XPORTER] = 80; /* transporter 8.0% */
164 1.1 cgd /* check to see that I didn't blow it */
165 1.1 cgd for (i = j = 0; i < NDEV; i++)
166 1.1 cgd j += Param.damprob[i];
167 1.1 cgd if (j != 1000)
168 1.1 cgd syserr("Device probabilities sum to %d", j);
169 1.1 cgd Param.dockfac = 0.5;
170 1.1 cgd Param.regenfac = (5 - Game.skill) * 0.05;
171 1.1 cgd if (Param.regenfac < 0.0)
172 1.1 cgd Param.regenfac = 0.0;
173 1.1 cgd Param.warptime = 10;
174 1.1 cgd Param.stopengy = 50;
175 1.1 cgd Param.shupengy = 40;
176 1.1 cgd i = Game.skill;
177 1.1 cgd Param.klingpwr = 100 + 150 * i;
178 1.1 cgd if (i >= 6)
179 1.1 cgd Param.klingpwr += 150;
180 1.1 cgd Param.phasfac = 0.8;
181 1.1 cgd Param.hitfac = 0.5;
182 1.1 cgd Param.klingcrew = 200;
183 1.1 cgd Param.srndrprob = 0.0035;
184 1.1 cgd Param.moveprob[KM_OB] = 45;
185 1.1 cgd Param.movefac[KM_OB] = .09;
186 1.1 cgd Param.moveprob[KM_OA] = 40;
187 1.1 cgd Param.movefac[KM_OA] = -0.05;
188 1.1 cgd Param.moveprob[KM_EB] = 40;
189 1.1 cgd Param.movefac[KM_EB] = 0.075;
190 1.1 cgd Param.moveprob[KM_EA] = 25 + 5 * Game.skill;
191 1.1 cgd Param.movefac[KM_EA] = -0.06 * Game.skill;
192 1.1 cgd Param.moveprob[KM_LB] = 0;
193 1.1 cgd Param.movefac[KM_LB] = 0.0;
194 1.1 cgd Param.moveprob[KM_LA] = 10 + 10 * Game.skill;
195 1.1 cgd Param.movefac[KM_LA] = 0.25;
196 1.1 cgd Param.eventdly[E_SNOVA] = 0.5;
197 1.1 cgd Param.eventdly[E_LRTB] = 25.0;
198 1.1 cgd Param.eventdly[E_KATSB] = 1.0;
199 1.1 cgd Param.eventdly[E_KDESB] = 3.0;
200 1.1 cgd Param.eventdly[E_ISSUE] = 1.0;
201 1.1 cgd Param.eventdly[E_SNAP] = 0.5;
202 1.1 cgd Param.eventdly[E_ENSLV] = 0.5;
203 1.1 cgd Param.eventdly[E_REPRO] = 2.0;
204 1.1 cgd Param.navigcrud[0] = 1.50;
205 1.1 cgd Param.navigcrud[1] = 0.75;
206 1.1 cgd Param.cloakenergy = 1000;
207 1.1 cgd Param.energylow = 1000;
208 1.1 cgd for (i = 0; i < MAXEVENTS; i++)
209 1.1 cgd {
210 1.1 cgd e = &Event[i];
211 1.1 cgd e->date = 1e50;
212 1.1 cgd e->evcode = 0;
213 1.1 cgd }
214 1.1 cgd xsched(E_SNOVA, 1, 0, 0, 0);
215 1.1 cgd xsched(E_LRTB, Param.klings, 0, 0, 0);
216 1.1 cgd xsched(E_KATSB, 1, 0, 0, 0);
217 1.1 cgd xsched(E_ISSUE, 1, 0, 0, 0);
218 1.1 cgd xsched(E_SNAP, 1, 0, 0, 0);
219 1.1 cgd Ship.sectx = ranf(NSECTS);
220 1.1 cgd Ship.secty = ranf(NSECTS);
221 1.1 cgd Game.killk = Game.kills = Game.killb = 0;
222 1.1 cgd Game.deaths = Game.negenbar = 0;
223 1.1 cgd Game.captives = 0;
224 1.1 cgd Game.killinhab = 0;
225 1.1 cgd Game.helps = 0;
226 1.1 cgd Game.killed = 0;
227 1.1 cgd Game.snap = 0;
228 1.1 cgd Move.endgame = 0;
229 1.1 cgd
230 1.1 cgd /* setup stars */
231 1.1 cgd for (i = 0; i < NQUADS; i++)
232 1.1 cgd for (j = 0; j < NQUADS; j++)
233 1.1 cgd {
234 1.1 cgd q = &Quad[i][j];
235 1.1 cgd q->klings = q->bases = 0;
236 1.1 cgd q->scanned = -1;
237 1.1 cgd q->stars = ranf(9) + 1;
238 1.1 cgd q->holes = ranf(3) - q->stars / 5;
239 1.1 cgd q->qsystemname = 0;
240 1.1 cgd }
241 1.1 cgd
242 1.1 cgd /* select inhabited starsystems */
243 1.1 cgd for (d = 1; d < NINHAB; d++)
244 1.1 cgd {
245 1.1 cgd do
246 1.1 cgd {
247 1.1 cgd i = ranf(NQUADS);
248 1.1 cgd j = ranf(NQUADS);
249 1.1 cgd q = &Quad[i][j];
250 1.1 cgd } while (q->qsystemname);
251 1.1 cgd q->qsystemname = d;
252 1.1 cgd }
253 1.1 cgd
254 1.1 cgd /* position starbases */
255 1.1 cgd for (i = 0; i < Param.bases; i++)
256 1.1 cgd {
257 1.1 cgd while (1)
258 1.1 cgd {
259 1.1 cgd ix = ranf(NQUADS);
260 1.1 cgd iy = ranf(NQUADS);
261 1.1 cgd q = &Quad[ix][iy];
262 1.1 cgd if (q->bases > 0)
263 1.1 cgd continue;
264 1.1 cgd break;
265 1.1 cgd }
266 1.1 cgd q->bases = 1;
267 1.1 cgd Now.base[i].x = ix;
268 1.1 cgd Now.base[i].y = iy;
269 1.1 cgd q->scanned = 1001;
270 1.1 cgd /* start the Enterprise near starbase */
271 1.1 cgd if (i == 0)
272 1.1 cgd {
273 1.1 cgd Ship.quadx = ix;
274 1.1 cgd Ship.quady = iy;
275 1.1 cgd }
276 1.1 cgd }
277 1.1 cgd
278 1.1 cgd /* position klingons */
279 1.1 cgd for (i = Param.klings; i > 0; )
280 1.1 cgd {
281 1.1 cgd klump = ranf(4) + 1;
282 1.1 cgd if (klump > i)
283 1.1 cgd klump = i;
284 1.1 cgd while (1)
285 1.1 cgd {
286 1.1 cgd ix = ranf(NQUADS);
287 1.1 cgd iy = ranf(NQUADS);
288 1.1 cgd q = &Quad[ix][iy];
289 1.1 cgd if (q->klings + klump > MAXKLQUAD)
290 1.1 cgd continue;
291 1.1 cgd q->klings += klump;
292 1.1 cgd i -= klump;
293 1.1 cgd break;
294 1.1 cgd }
295 1.1 cgd }
296 1.1 cgd
297 1.1 cgd /* initialize this quadrant */
298 1.1 cgd printf("%d Klingons\n%d starbase", Param.klings, Param.bases);
299 1.1 cgd if (Param.bases > 1)
300 1.1 cgd printf("s");
301 1.1 cgd printf(" at %d,%d", Now.base[0].x, Now.base[0].y);
302 1.1 cgd for (i = 1; i < Param.bases; i++)
303 1.1 cgd printf(", %d,%d", Now.base[i].x, Now.base[i].y);
304 1.1 cgd printf("\nIt takes %d units to kill a Klingon\n", Param.klingpwr);
305 1.1 cgd Move.free = 0;
306 1.1 cgd initquad(0);
307 1.1 cgd srscan(1);
308 1.1 cgd attack(0);
309 1.1 cgd }
310