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