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