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