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