move entry/exit debugging to 21.1
[unix-history] / usr / src / games / trek / setup.c
CommitLineData
9758240b 1/*
4c3ad851
KB
2 * Copyright (c) 1980, 1993
3 * The Regents of the University of California. All rights reserved.
e9fb6bea 4 *
b2e7427f 5 * %sccs.include.redist.c%
9758240b
KM
6 */
7
3a55e852 8#ifndef lint
4c3ad851 9static char sccsid[] = "@(#)setup.c 8.1 (Berkeley) %G%";
e9fb6bea 10#endif /* not lint */
3a55e852
KM
11
12# include "trek.h"
13# include "getpar.h"
14
15/*
16** INITIALIZE THE GAME
17**
18** The length, skill, and password are read, and the game
19** is initialized. It is far too difficult to describe all
20** that goes on in here, but it is all straight-line code;
21** give it a look.
22**
23** Game restart and tournament games are handled here.
24*/
25
401a08c7 26struct cvntab Lentab[] =
3a55e852 27{
401a08c7
KL
28 "s", "hort", (int (*)())1, 0,
29 "m", "edium", (int (*)())2, 0,
30 "l", "ong", (int (*)())4, 0,
3a55e852
KM
31 "restart", "", 0, 0,
32 0
33};
34
401a08c7 35struct cvntab Skitab[] =
3a55e852 36{
401a08c7
KL
37 "n", "ovice", (int (*)())1, 0,
38 "f", "air", (int (*)())2, 0,
39 "g", "ood", (int (*)())3, 0,
40 "e", "xpert", (int (*)())4, 0,
41 "c", "ommodore", (int (*)())5, 0,
42 "i", "mpossible", (int (*)())6, 0,
3a55e852
KM
43 0
44};
45
46setup()
47{
48 struct cvntab *r;
49 register int i, j;
401a08c7 50 double f;
3a55e852
KM
51 int d;
52 int fd;
53 int klump;
54 int ix, iy;
55 register struct quad *q;
56 struct event *e;
57
58 while (1)
59 {
60 r = getcodpar("What length game", Lentab);
401a08c7 61 Game.length = (int) r->value;
3a55e852
KM
62 if (Game.length == 0)
63 {
64 if (restartgame())
65 continue;
66 return;
67 }
68 break;
69 }
70 r = getcodpar("What skill game", Skitab);
401a08c7 71 Game.skill = (int) r->value;
3a55e852
KM
72 Game.tourn = 0;
73 getstrpar("Enter a password", Game.passwd, 14, 0);
74 if (sequal(Game.passwd, "tournament"))
75 {
76 getstrpar("Enter tournament code", Game.passwd, 14, 0);
77 Game.tourn = 1;
78 d = 0;
79 for (i = 0; Game.passwd[i]; i++)
401a08c7 80 d += Game.passwd[i] << i;
3a55e852
KM
81 srand(d);
82 }
83 Param.bases = Now.bases = ranf(6 - Game.skill) + 2;
84 if (Game.skill == 6)
85 Param.bases = Now.bases = 1;
86 Param.time = Now.time = 6.0 * Game.length + 2.0;
87 i = Game.skill;
88 j = Game.length;
89 Param.klings = Now.klings = i * j * 3.5 * (franf() + 0.75);
90 if (Param.klings < i * j * 5)
91 Param.klings = Now.klings = i * j * 5;
92 if (Param.klings <= i) /* numerical overflow problems */
93 Param.klings = Now.klings = 127;
94 Param.energy = Ship.energy = 5000;
95 Param.torped = Ship.torped = 10;
96 Ship.ship = ENTERPRISE;
97 Ship.shipname = "Enterprise";
98 Param.shield = Ship.shield = 1500;
99 Param.resource = Now.resource = Param.klings * Param.time;
100 Param.reserves = Ship.reserves = (6 - Game.skill) * 2.0;
101 Param.crew = Ship.crew = 387;
102 Param.brigfree = Ship.brigfree = 400;
103 Ship.shldup = 1;
104 Ship.cond = GREEN;
105 Ship.warp = 5.0;
106 Ship.warp2 = 25.0;
107 Ship.warp3 = 125.0;
108 Ship.sinsbad = 0;
109 Ship.cloaked = 0;
110 Param.date = Now.date = (ranf(20) + 20) * 100;
111 f = Game.skill;
112 f = log(f + 0.5);
113 for (i = 0; i < NDEV; i++)
114 if (Device[i].name[0] == '*')
115 Param.damfac[i] = 0;
116 else
117 Param.damfac[i] = f;
118 /* these probabilities must sum to 1000 */
119 Param.damprob[WARP] = 70; /* warp drive 7.0% */
120 Param.damprob[SRSCAN] = 110; /* short range scanners 11.0% */
121 Param.damprob[LRSCAN] = 110; /* long range scanners 11.0% */
122 Param.damprob[PHASER] = 125; /* phasers 12.5% */
123 Param.damprob[TORPED] = 125; /* photon torpedoes 12.5% */
124 Param.damprob[IMPULSE] = 75; /* impulse engines 7.5% */
125 Param.damprob[SHIELD] = 150; /* shield control 15.0% */
126 Param.damprob[COMPUTER] = 20; /* computer 2.0% */
127 Param.damprob[SSRADIO] = 35; /* subspace radio 3.5% */
128 Param.damprob[LIFESUP] = 30; /* life support 3.0% */
129 Param.damprob[SINS] = 20; /* navigation system 2.0% */
130 Param.damprob[CLOAK] = 50; /* cloaking device 5.0% */
131 Param.damprob[XPORTER] = 80; /* transporter 8.0% */
132 /* check to see that I didn't blow it */
133 for (i = j = 0; i < NDEV; i++)
401a08c7 134 j += Param.damprob[i];
3a55e852
KM
135 if (j != 1000)
136 syserr("Device probabilities sum to %d", j);
137 Param.dockfac = 0.5;
138 Param.regenfac = (5 - Game.skill) * 0.05;
139 if (Param.regenfac < 0.0)
140 Param.regenfac = 0.0;
141 Param.warptime = 10;
142 Param.stopengy = 50;
143 Param.shupengy = 40;
144 i = Game.skill;
145 Param.klingpwr = 100 + 150 * i;
146 if (i >= 6)
401a08c7 147 Param.klingpwr += 150;
3a55e852
KM
148 Param.phasfac = 0.8;
149 Param.hitfac = 0.5;
150 Param.klingcrew = 200;
151 Param.srndrprob = 0.0035;
152 Param.moveprob[KM_OB] = 45;
153 Param.movefac[KM_OB] = .09;
154 Param.moveprob[KM_OA] = 40;
155 Param.movefac[KM_OA] = -0.05;
156 Param.moveprob[KM_EB] = 40;
157 Param.movefac[KM_EB] = 0.075;
158 Param.moveprob[KM_EA] = 25 + 5 * Game.skill;
159 Param.movefac[KM_EA] = -0.06 * Game.skill;
160 Param.moveprob[KM_LB] = 0;
161 Param.movefac[KM_LB] = 0.0;
162 Param.moveprob[KM_LA] = 10 + 10 * Game.skill;
163 Param.movefac[KM_LA] = 0.25;
164 Param.eventdly[E_SNOVA] = 0.5;
165 Param.eventdly[E_LRTB] = 25.0;
166 Param.eventdly[E_KATSB] = 1.0;
167 Param.eventdly[E_KDESB] = 3.0;
168 Param.eventdly[E_ISSUE] = 1.0;
169 Param.eventdly[E_SNAP] = 0.5;
170 Param.eventdly[E_ENSLV] = 0.5;
171 Param.eventdly[E_REPRO] = 2.0;
172 Param.navigcrud[0] = 1.50;
173 Param.navigcrud[1] = 0.75;
174 Param.cloakenergy = 1000;
175 Param.energylow = 1000;
176 for (i = 0; i < MAXEVENTS; i++)
177 {
178 e = &Event[i];
179 e->date = 1e50;
180 e->evcode = 0;
181 }
182 xsched(E_SNOVA, 1, 0, 0, 0);
183 xsched(E_LRTB, Param.klings, 0, 0, 0);
184 xsched(E_KATSB, 1, 0, 0, 0);
185 xsched(E_ISSUE, 1, 0, 0, 0);
186 xsched(E_SNAP, 1, 0, 0, 0);
187 Ship.sectx = ranf(NSECTS);
188 Ship.secty = ranf(NSECTS);
189 Game.killk = Game.kills = Game.killb = 0;
190 Game.deaths = Game.negenbar = 0;
191 Game.captives = 0;
192 Game.killinhab = 0;
193 Game.helps = 0;
194 Game.killed = 0;
195 Game.snap = 0;
196 Move.endgame = 0;
197
198 /* setup stars */
199 for (i = 0; i < NQUADS; i++)
200 for (j = 0; j < NQUADS; j++)
201 {
202 q = &Quad[i][j];
203 q->klings = q->bases = 0;
204 q->scanned = -1;
205 q->stars = ranf(9) + 1;
206 q->holes = ranf(3) - q->stars / 5;
401a08c7 207 q->qsystemname = 0;
3a55e852
KM
208 }
209
210 /* select inhabited starsystems */
211 for (d = 1; d < NINHAB; d++)
212 {
213 do
214 {
215 i = ranf(NQUADS);
216 j = ranf(NQUADS);
217 q = &Quad[i][j];
401a08c7
KL
218 } while (q->qsystemname);
219 q->qsystemname = d;
3a55e852
KM
220 }
221
222 /* position starbases */
223 for (i = 0; i < Param.bases; i++)
224 {
225 while (1)
226 {
227 ix = ranf(NQUADS);
228 iy = ranf(NQUADS);
229 q = &Quad[ix][iy];
230 if (q->bases > 0)
231 continue;
232 break;
233 }
234 q->bases = 1;
235 Now.base[i].x = ix;
236 Now.base[i].y = iy;
237 q->scanned = 1001;
238 /* start the Enterprise near starbase */
239 if (i == 0)
240 {
241 Ship.quadx = ix;
242 Ship.quady = iy;
243 }
244 }
245
246 /* position klingons */
247 for (i = Param.klings; i > 0; )
248 {
249 klump = ranf(4) + 1;
250 if (klump > i)
251 klump = i;
252 while (1)
253 {
254 ix = ranf(NQUADS);
255 iy = ranf(NQUADS);
256 q = &Quad[ix][iy];
257 if (q->klings + klump > MAXKLQUAD)
258 continue;
401a08c7
KL
259 q->klings += klump;
260 i -= klump;
3a55e852
KM
261 break;
262 }
263 }
264
265 /* initialize this quadrant */
266 printf("%d Klingons\n%d starbase", Param.klings, Param.bases);
267 if (Param.bases > 1)
268 printf("s");
269 printf(" at %d,%d", Now.base[0].x, Now.base[0].y);
270 for (i = 1; i < Param.bases; i++)
271 printf(", %d,%d", Now.base[i].x, Now.base[i].y);
272 printf("\nIt takes %d units to kill a Klingon\n", Param.klingpwr);
273 Move.free = 0;
274 initquad(0);
275 srscan(1);
276 attack(0);
277}