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