2 * Copyright (c) 1980, 1993
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * @(#)setup.c 8.1 (Berkeley) 5/31/93
34 * $FreeBSD: src/games/trek/setup.c,v 1.6 1999/11/30 03:49:54 billf Exp $
35 * $DragonFly: src/games/trek/setup.c,v 1.2 2003/06/17 04:25:25 dillon Exp $
43 ** INITIALIZE THE GAME
45 ** The length, skill, and password are read, and the game
46 ** is initialized. It is far too difficult to describe all
47 ** that goes on in here, but it is all straight-line code;
50 ** Game restart and tournament games are handled here.
53 struct cvntab Lentab[] =
55 "s", "hort", (int (*)())1, 0,
56 "m", "edium", (int (*)())2, 0,
57 "l", "ong", (int (*)())4, 0,
62 struct cvntab Skitab[] =
64 "n", "ovice", (int (*)())1, 0,
65 "f", "air", (int (*)())2, 0,
66 "g", "ood", (int (*)())3, 0,
67 "e", "xpert", (int (*)())4, 0,
68 "c", "ommodore", (int (*)())5, 0,
69 "i", "mpossible", (int (*)())6, 0,
87 r = getcodpar("What length game", Lentab);
88 Game.length = (long) r->value;
97 r = getcodpar("What skill game", Skitab);
98 Game.skill = (long) r->value;
100 getstrpar("Enter a password", Game.passwd, 14, 0);
101 if (sequal(Game.passwd, "tournament"))
103 getstrpar("Enter tournament code", Game.passwd, 14, 0);
106 for (i = 0; Game.passwd[i]; i++)
107 d += Game.passwd[i] << i;
110 Param.bases = Now.bases = ranf(6 - Game.skill) + 2;
112 Param.bases = Now.bases = 1;
113 Param.time = Now.time = 6.0 * Game.length + 2.0;
116 Param.klings = Now.klings = i * j * 3.5 * (franf() + 0.75);
117 if (Param.klings < i * j * 5)
118 Param.klings = Now.klings = i * j * 5;
119 if (Param.klings <= i) /* numerical overflow problems */
120 Param.klings = Now.klings = 127;
121 Param.energy = Ship.energy = 5000;
122 Param.torped = Ship.torped = 10;
123 Ship.ship = ENTERPRISE;
124 Ship.shipname = "Enterprise";
125 Param.shield = Ship.shield = 1500;
126 Param.resource = Now.resource = Param.klings * Param.time;
127 Param.reserves = Ship.reserves = (6 - Game.skill) * 2.0;
128 Param.crew = Ship.crew = 387;
129 Param.brigfree = Ship.brigfree = 400;
137 Param.date = Now.date = (ranf(20) + 20) * 100;
140 for (i = 0; i < NDEV; i++)
141 if (Device[i].name[0] == '*')
145 /* these probabilities must sum to 1000 */
146 Param.damprob[WARP] = 70; /* warp drive 7.0% */
147 Param.damprob[SRSCAN] = 110; /* short range scanners 11.0% */
148 Param.damprob[LRSCAN] = 110; /* long range scanners 11.0% */
149 Param.damprob[PHASER] = 125; /* phasers 12.5% */
150 Param.damprob[TORPED] = 125; /* photon torpedoes 12.5% */
151 Param.damprob[IMPULSE] = 75; /* impulse engines 7.5% */
152 Param.damprob[SHIELD] = 150; /* shield control 15.0% */
153 Param.damprob[COMPUTER] = 20; /* computer 2.0% */
154 Param.damprob[SSRADIO] = 35; /* subspace radio 3.5% */
155 Param.damprob[LIFESUP] = 30; /* life support 3.0% */
156 Param.damprob[SINS] = 20; /* navigation system 2.0% */
157 Param.damprob[CLOAK] = 50; /* cloaking device 5.0% */
158 Param.damprob[XPORTER] = 80; /* transporter 8.0% */
159 /* check to see that I didn't blow it */
160 for (i = j = 0; i < NDEV; i++)
161 j += Param.damprob[i];
163 syserr("Device probabilities sum to %d", j);
165 Param.regenfac = (5 - Game.skill) * 0.05;
166 if (Param.regenfac < 0.0)
167 Param.regenfac = 0.0;
172 Param.klingpwr = 100 + 150 * i;
174 Param.klingpwr += 150;
177 Param.klingcrew = 200;
178 Param.srndrprob = 0.0035;
179 Param.moveprob[KM_OB] = 45;
180 Param.movefac[KM_OB] = .09;
181 Param.moveprob[KM_OA] = 40;
182 Param.movefac[KM_OA] = -0.05;
183 Param.moveprob[KM_EB] = 40;
184 Param.movefac[KM_EB] = 0.075;
185 Param.moveprob[KM_EA] = 25 + 5 * Game.skill;
186 Param.movefac[KM_EA] = -0.06 * Game.skill;
187 Param.moveprob[KM_LB] = 0;
188 Param.movefac[KM_LB] = 0.0;
189 Param.moveprob[KM_LA] = 10 + 10 * Game.skill;
190 Param.movefac[KM_LA] = 0.25;
191 Param.eventdly[E_SNOVA] = 0.5;
192 Param.eventdly[E_LRTB] = 25.0;
193 Param.eventdly[E_KATSB] = 1.0;
194 Param.eventdly[E_KDESB] = 3.0;
195 Param.eventdly[E_ISSUE] = 1.0;
196 Param.eventdly[E_SNAP] = 0.5;
197 Param.eventdly[E_ENSLV] = 0.5;
198 Param.eventdly[E_REPRO] = 2.0;
199 Param.navigcrud[0] = 1.50;
200 Param.navigcrud[1] = 0.75;
201 Param.cloakenergy = 1000;
202 Param.energylow = 1000;
203 for (i = 0; i < MAXEVENTS; i++)
209 xsched(E_SNOVA, 1, 0, 0, 0);
210 xsched(E_LRTB, Param.klings, 0, 0, 0);
211 xsched(E_KATSB, 1, 0, 0, 0);
212 xsched(E_ISSUE, 1, 0, 0, 0);
213 xsched(E_SNAP, 1, 0, 0, 0);
214 Ship.sectx = ranf(NSECTS);
215 Ship.secty = ranf(NSECTS);
216 Game.killk = Game.kills = Game.killb = 0;
217 Game.deaths = Game.negenbar = 0;
226 for (i = 0; i < NQUADS; i++)
227 for (j = 0; j < NQUADS; j++)
230 q->klings = q->bases = 0;
232 q->stars = ranf(9) + 1;
233 q->holes = ranf(3) - q->stars / 5;
237 /* select inhabited starsystems */
238 for (d = 1; d < NINHAB; d++)
245 } while (q->qsystemname);
249 /* position starbases */
250 for (i = 0; i < Param.bases; i++)
265 /* start the Enterprise near starbase */
273 /* position klingons */
274 for (i = Param.klings; i > 0; )
284 if (q->klings + klump > MAXKLQUAD)
292 /* initialize this quadrant */
293 printf("%d Klingons\n%d starbase", Param.klings, Param.bases);
296 printf(" at %d,%d", Now.base[0].x, Now.base[0].y);
297 for (i = 1; i < Param.bases; i++)
298 printf(", %d,%d", Now.base[i].x, Now.base[i].y);
299 printf("\nIt takes %d units to kill a Klingon\n", Param.klingpwr);