Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
7185 | siemargl | 1 | #include "sst.h" |
2 | #include |
||
3 | |||
4 | void events(void) { |
||
5 | |||
6 | int ictbeam=0, ipage=0, istract=0, line, i, j, k, l, ixhold, iyhold; |
||
7 | double fintim = d.date + Time, datemin, xtime, repair, yank; |
||
8 | |||
9 | |||
10 | #ifdef DEBUG |
||
11 | if (idebug) prout("EVENTS"); |
||
12 | #endif |
||
13 | |||
14 | if (stdamtim == 1e30 && !REPORTS) |
||
15 | { |
||
16 | /* chart will no longer be updated because radio is dead */ |
||
17 | stdamtim = d.date; |
||
18 | for (i=1; i <= 8 ; i++) |
||
19 | for (j=1; j <= 8; j++) |
||
20 | if (starch[i][j] == 1) starch[i][j] = d.galaxy[i][j]+1000; |
||
21 | } |
||
22 | |||
23 | for (;;) { |
||
24 | /* Select earliest extraneous event, line==0 if no events */ |
||
25 | line = FSPY; |
||
26 | if (alldone) return; |
||
27 | datemin = fintim; |
||
28 | for (l=1; l<=NEVENTS; l++) |
||
29 | if (future[l] <= datemin) { |
||
30 | line = l; |
||
31 | datemin = future[l]; |
||
32 | } |
||
33 | xtime = datemin-d.date; |
||
34 | #ifdef CLOAKING |
||
35 | if (iscloaking) { |
||
36 | energy -= xtime*500.0; |
||
37 | if (energy <= 0.) { |
||
38 | finish(FNRG); |
||
39 | return; |
||
40 | } |
||
41 | } |
||
42 | #endif |
||
43 | d.date = datemin; |
||
44 | /* Decrement Federation resources and recompute remaining time */ |
||
45 | d.remres -= (d.remkl+4*d.remcom)*xtime; |
||
46 | d.remtime = d.remres/(d.remkl+4*d.remcom); |
||
47 | if (d.remtime <=0) { |
||
48 | finish(FDEPLETE); |
||
49 | return; |
||
50 | } |
||
51 | /* Is life support adequate? */ |
||
52 | if (damage[DLIFSUP] && condit != IHDOCKED) { |
||
53 | if (lsupres < xtime && damage[DLIFSUP] > lsupres) { |
||
54 | finish(FLIFESUP); |
||
55 | return; |
||
56 | } |
||
57 | lsupres -= xtime; |
||
58 | if (damage[DLIFSUP] <= xtime) lsupres = inlsr; |
||
59 | } |
||
60 | /* Fix devices */ |
||
61 | repair = xtime; |
||
62 | if (condit == IHDOCKED) repair /= docfac; |
||
63 | /* Don't fix Deathray here */ |
||
64 | for (l=1; l<=ndevice; l++) |
||
65 | if (damage[l] > 0.0 && l != DDRAY) |
||
66 | damage[l] -= (damage[l]-repair > 0.0 ? repair : damage[l]); |
||
67 | /* Fix Deathray if docked */ |
||
68 | if (damage[DDRAY] > 0.0 && condit == IHDOCKED) |
||
69 | damage[DDRAY] -= (damage[l] - xtime > 0.0 ? xtime : damage[DDRAY]); |
||
70 | /* If radio repaired, update star chart and attack reports */ |
||
71 | if (stdamtim != 1e30 && REPORTS) { |
||
72 | stdamtim = 1e30; |
||
73 | /* prout("Lt. Uhura- \"Captain, the sub-space radio is working and"); |
||
74 | prout(" surveillance reports are coming in.");*/ |
||
75 | prout("Лейтенант Ухура- \"Капитан, подпространственная связь работает"); |
||
76 | prout(" и мы принимаем отчет разведки."); |
||
77 | skip(1); |
||
78 | for (i=1; i <= 8 ; i++) |
||
79 | for (j=1; j <= 8; j++) |
||
80 | if (starch[i][j] > 999) starch[i][j] = 1; |
||
81 | if (iseenit==0) { |
||
82 | attakreport(); |
||
83 | iseenit = 1; |
||
84 | } |
||
85 | skip(1); |
||
86 | /* prout(" The star chart is now up to date.\"");*/ |
||
87 | prout(" Звездная карта обновлена.\""); |
||
88 | skip(1); |
||
89 | } |
||
90 | /* Cause extraneous event LINE to occur */ |
||
91 | Time -= xtime; |
||
92 | switch (line) { |
||
93 | case FSNOVA: /* Supernova */ |
||
94 | if (ipage==0) pause(1); |
||
95 | ipage=1; |
||
96 | snova(0,0); |
||
97 | future[FSNOVA] = d.date + expran(0.5*intime); |
||
98 | if (d.galaxy[quadx][quady] == 1000) return; |
||
99 | break; |
||
100 | case FSPY: /* Check with spy to see if S.C. should tractor beam */ |
||
101 | if (d.nscrem == 0 || |
||
102 | #ifdef CLOAKING |
||
103 | iscloaked || /* Cannot tractor beam if we can't be seen! */ |
||
104 | #endif |
||
105 | ictbeam+istract > 0 || |
||
106 | condit==IHDOCKED || isatb==1 || iscate==1) return; |
||
107 | if (ientesc || |
||
108 | (energy < 2000 && torps < 4 && shield < 1250) || |
||
109 | (damage[DPHASER]>0 && (damage[DPHOTON]>0 || torps < 4)) || |
||
110 | (damage[DSHIELD] > 0 && |
||
111 | (energy < 2500 || damage[DPHASER] > 0) && |
||
112 | (torps < 5 || damage[DPHOTON] > 0))) { |
||
113 | /* Tractor-beam her! */ |
||
114 | istract=1; |
||
115 | yank = square(d.isx-quadx) + square(d.isy-quady); |
||
116 | /*********TBEAM CODE***********/ |
||
117 | } |
||
118 | else return; |
||
119 | case FTBEAM: /* Tractor beam */ |
||
120 | if (line==FTBEAM) { |
||
121 | if (d.remcom == 0) { |
||
122 | future[FTBEAM] = 1e30; |
||
123 | break; |
||
124 | } |
||
125 | i = Rand()*d.remcom+1.0; |
||
126 | yank = square(d.cx[i]-quadx) + square(d.cy[i]-quady); |
||
127 | if (istract || condit == IHDOCKED || |
||
128 | #ifdef CLOAKING |
||
129 | iscloaked || /* cannot tractor beam if we can't be seen */ |
||
130 | #endif |
||
131 | yank == 0) { |
||
132 | /* Drats! Have to reschedule */ |
||
133 | future[FTBEAM] = d.date + Time + |
||
134 | expran(1.5*intime/d.remcom); |
||
135 | break; |
||
136 | } |
||
137 | } |
||
138 | /* tractor beaming cases merge here */ |
||
139 | yank = sqrt(yank); |
||
140 | if (ipage==0) pause(1); |
||
141 | ipage=1; |
||
142 | Time = (10.0/(7.5*7.5))*yank; /* 7.5 is yank rate (warp 7.5) */ |
||
143 | ictbeam = 1; |
||
144 | skip(1); |
||
145 | proutn("***"); |
||
146 | crmshp(); |
||
147 | /* prout(" caught in long range tractor beam--");*/ |
||
148 | prout(" пойманы притягивающим лучом--"); |
||
149 | /* If Kirk & Co. screwing around on planet, handle */ |
||
150 | atover(1); /* atover(1) is Grab */ |
||
151 | if (alldone) return; |
||
152 | if (icraft == 1) { /* Caught in Galileo? */ |
||
153 | finish(FSTRACTOR); |
||
154 | return; |
||
155 | } |
||
156 | /* Check to see if shuttle is aboard */ |
||
157 | if (iscraft==0) { |
||
158 | skip(1); |
||
159 | if (Rand() >0.5) { |
||
160 | /* prout("Galileo, left on the planet surface, is captured"); |
||
161 | prout("by aliens and made into a flying McDonald's.");*/ |
||
162 | prout("Галилео, оставшийся на поверхности планеты, был захвачен"); |
||
163 | prout("инопланетянами и превращен в летающий МакДональдс."); |
||
164 | damage[DSHUTTL] = -10; |
||
165 | iscraft = -1; |
||
166 | } |
||
167 | else { |
||
168 | /* prout("Galileo, left on the planet surface, is well hidden.");*/ |
||
169 | prout("Галилео, оставшийся на поверхности планеты, надежно спрятан."); |
||
170 | } |
||
171 | } |
||
172 | if (line==0) { |
||
173 | quadx = d.isx; |
||
174 | quady = d.isy; |
||
175 | } |
||
176 | else { |
||
177 | quadx = d.cx[i]; |
||
178 | quady = d.cy[i]; |
||
179 | } |
||
180 | iran10(§x, §y); |
||
181 | crmshp(); |
||
182 | proutn(" притянут в точку");/*is pulled to*/ |
||
183 | cramlc(1, quadx, quady); |
||
184 | proutn(", "); |
||
185 | cramlc(2, sectx, secty); |
||
186 | skip(1); |
||
187 | if (resting) { |
||
188 | /* prout("(Remainder of rest/repair period cancelled.)");*/ |
||
189 | prout("(Отдых/ремонт досрочно прерван.)"); |
||
190 | resting = 0; |
||
191 | } |
||
192 | if (shldup==0) { |
||
193 | if (damage[DSHIELD]==0 && shield > 0) { |
||
194 | sheild(2); /* Shldsup */ |
||
195 | shldchg=0; |
||
196 | } |
||
197 | else prout("(Силовые щиты не готовы к работе.)");/*Shields not currently useable*/ |
||
198 | } |
||
199 | newqad(0); |
||
200 | /* Adjust finish time to time of tractor beaming */ |
||
201 | fintim = d.date+Time; |
||
202 | if (d.remcom <= 0) future[FTBEAM] = 1e30; |
||
203 | else future[FTBEAM] = d.date+Time+expran(1.5*intime/d.remcom); |
||
204 | break; |
||
205 | case FSNAP: /* Snapshot of the universe (for time warp) */ |
||
206 | snapsht = d; |
||
207 | d.snap = 1; |
||
208 | future[FSNAP] = d.date + expran(0.5 * intime); |
||
209 | break; |
||
210 | case FBATTAK: /* Commander attacks starbase */ |
||
211 | if (d.remcom==0 || d.rembase==0) { |
||
212 | /* no can do */ |
||
213 | future[FBATTAK] = future[FCDBAS] = 1e30; |
||
214 | break; |
||
215 | } |
||
216 | i = 0; |
||
217 | for (j=1; j<=d.rembase; j++) { |
||
218 | for (k=1; k<=d.remcom; k++) |
||
219 | if (d.baseqx[j]==d.cx[k] && d.baseqy[j]==d.cy[k] && |
||
220 | (d.baseqx[j]!=quadx || d.baseqy[j]!=quady) && |
||
221 | (d.baseqx[j]!=d.isx || d.baseqy[j]!=d.isy)) { |
||
222 | i = 1; |
||
223 | break; |
||
224 | } |
||
225 | if (i == 1) break; |
||
226 | } |
||
227 | if (j>d.rembase) { |
||
228 | /* no match found -- try later */ |
||
229 | future[FBATTAK] = d.date + expran(0.3*intime); |
||
230 | future[FCDBAS] = 1e30; |
||
231 | break; |
||
232 | } |
||
233 | /* commander + starbase combination found -- launch attack */ |
||
234 | batx = d.baseqx[j]; |
||
235 | baty = d.baseqy[j]; |
||
236 | future[FCDBAS] = d.date+1.0+3.0*Rand(); |
||
237 | if (isatb) /* extra time if SC already attacking */ |
||
238 | future[FCDBAS] += future[FSCDBAS]-d.date; |
||
239 | future[FBATTAK] = future[FCDBAS] +expran(0.3*intime); |
||
240 | iseenit = 0; |
||
241 | if (!REPORTS) |
||
242 | break; /* No warning :-( */ |
||
243 | iseenit = 1; |
||
244 | if (ipage==0) pause(1); |
||
245 | ipage = 1; |
||
246 | skip(1); |
||
247 | /* proutn("Lt. Uhura- \"Captain, the starbase in"); */ |
||
248 | proutn("Лейтенант Ухура- \"Капитан, обнаруженная станция в точке"); |
||
249 | cramlc(1, batx, baty); |
||
250 | skip(1); |
||
251 | /* prout(" reports that it is under atttack and that it can"); |
||
252 | proutn(" hold out only until stardate "); |
||
253 | */ prout(" докладывает, что находится под атакой"); |
||
254 | proutn(" и продержится максимум до "); |
||
255 | cramf(future[FCDBAS],1,1); |
||
256 | prout(".\""); |
||
257 | if (resting) { |
||
258 | skip(1); |
||
259 | /* proutn("Mr. Spock- \"Captain, shall we cancel the rest period?\""); |
||
260 | */ proutn("Мистер Спок- \"Капитан, мы должны прервать отдых?\""); |
||
261 | if (ja()) { |
||
262 | resting = 0; |
||
263 | Time = 0.0; |
||
264 | return; |
||
265 | } |
||
266 | } |
||
267 | break; |
||
268 | case FSCDBAS: /* Supercommander destroys base */ |
||
269 | future[FSCDBAS] = 1e30; |
||
270 | isatb = 2; |
||
271 | if (d.galaxy[d.isx][d.isy]%100 < 10) break; /* WAS RETURN! */ |
||
272 | ixhold = batx; |
||
273 | iyhold = baty; |
||
274 | batx = d.isx; |
||
275 | baty = d.isy; |
||
276 | case FCDBAS: /* Commander succeeds in destroying base */ |
||
277 | if (line==FCDBAS) { |
||
278 | future[FCDBAS] = 1e30; |
||
279 | /* find the lucky pair */ |
||
280 | for (i = 1; i <= d.remcom; i++) |
||
281 | if (d.cx[i]==batx && d.cy[i]==baty) break; |
||
282 | if (i > d.remcom || d.rembase == 0 || |
||
283 | d.galaxy[batx][baty] % 100 < 10) { |
||
284 | /* No action to take after all */ |
||
285 | batx = baty = 0; |
||
286 | break; |
||
287 | } |
||
288 | } |
||
289 | /* Code merges here for any commander destroying base */ |
||
290 | /* Not perfect, but will have to do */ |
||
291 | if (starch[batx][baty] == -1) starch[batx][baty] = 0; |
||
292 | /* Handle case where base is in same quadrant as starship */ |
||
293 | if (batx==quadx && baty==quady) { |
||
294 | if (starch[batx][baty] > 999) starch[batx][baty] -= 10; |
||
295 | quad[basex][basey]= IHDOT; |
||
296 | basex=basey=0; |
||
297 | newcnd(); |
||
298 | skip(1); |
||
299 | /* prout("Spock- \"Captain, I believe the starbase has been destroyed.\""); */ |
||
300 | prout("Спок- \"Капитан, я полагаю, что станция была уничтожена.\""); |
||
301 | } |
||
302 | else if (d.rembase != 1 && REPORTS) { |
||
303 | /* Get word via subspace radio */ |
||
304 | if (ipage==0) pause(1); |
||
305 | ipage = 1; |
||
306 | skip(1); |
||
307 | /* prout("Lt. Uhura- \"Captain, Starfleet Command reports that"); |
||
308 | proutn(" the starbase in"); */ |
||
309 | prout("Лейтенант Ухура- \"Капитан, Звездное Командование сообщает,"); |
||
310 | proutn(" станция в"); |
||
311 | cramlc(1, batx, baty); |
||
312 | prout(" была уничтожена");/* has been destroyed by */ |
||
313 | if (isatb==2) prout("клингонским СуперКоммандером");/* the Klingon Super-Commander */ |
||
314 | else prout("клингонским Коммандером");/* the Klingon Commander */ |
||
315 | } |
||
316 | /* Remove Starbase from galaxy */ |
||
317 | d.galaxy[batx][baty] -= 10; |
||
318 | for (i=1; i <= d.rembase; i++) |
||
319 | if (d.baseqx[i]==batx && d.baseqy[i]==baty) { |
||
320 | d.baseqx[i]=d.baseqx[d.rembase]; |
||
321 | d.baseqy[i]=d.baseqy[d.rembase]; |
||
322 | } |
||
323 | d.rembase--; |
||
324 | if (isatb == 2) { |
||
325 | /* reinstate a commander's base attack */ |
||
326 | batx = ixhold; |
||
327 | baty = iyhold; |
||
328 | isatb = 0; |
||
329 | } |
||
330 | else { |
||
331 | batx = baty = 0; |
||
332 | } |
||
333 | break; |
||
334 | case FSCMOVE: /* Supercommander moves */ |
||
335 | future[FSCMOVE] = d.date+0.2777; |
||
336 | if (ientesc+istract==0 && |
||
337 | isatb!=1 && |
||
338 | (iscate!=1 || justin==1)) scom(&ipage); |
||
339 | break; |
||
340 | case FDSPROB: /* Move deep space probe */ |
||
341 | future[FDSPROB] = d.date + 0.01; |
||
342 | probex += probeinx; |
||
343 | probey += probeiny; |
||
344 | i = (int)(probex/10 +0.05); |
||
345 | j = (int)(probey/10 + 0.05); |
||
346 | if (probecx != i || probecy != j) { |
||
347 | probecx = i; |
||
348 | probecy = j; |
||
349 | if (i < 1 || i > 8 || j < 1 || j > 8 || |
||
350 | d.galaxy[probecx][probecy] == 1000) { |
||
351 | // Left galaxy or ran into supernova |
||
352 | if (REPORTS) { |
||
353 | if (ipage==0) pause(1); |
||
354 | ipage = 1; |
||
355 | skip(1); |
||
356 | /* proutn("Lt. Uhura- \"The deep space probe "); */ |
||
357 | proutn("Лейтенант Ухура- \"Зонд дальней разведки "); |
||
358 | if (i < 1 ||i > 8 || j < 1 || j > 8) |
||
359 | /* proutn("has left the galaxy"); */ |
||
360 | proutn("покинул галактику"); |
||
361 | else |
||
362 | /* proutn("is no longer transmitting"); */ |
||
363 | proutn("более недоступен"); |
||
364 | prout(".\""); |
||
365 | } |
||
366 | future[FDSPROB] = 1e30; |
||
367 | break; |
||
368 | } |
||
369 | if (REPORTS) { |
||
370 | if (ipage==0) pause(1); |
||
371 | ipage = 1; |
||
372 | skip(1); |
||
373 | /* proutn("Lt. Uhura- \"The deep space probe is now in "); */ |
||
374 | proutn("Лейтенант Ухура- \"Зонд дальней разведки сейчас в"); |
||
375 | cramlc(1, probecx, probecy); |
||
376 | prout(".\""); |
||
377 | } |
||
378 | } |
||
379 | /* Update star chart if Radio is working or have access to |
||
380 | radio. */ |
||
381 | if (REPORTS) |
||
382 | starch[probecx][probecy] = damage[DRADIO] > 0.0 ? |
||
383 | d.galaxy[probecx][probecy]+1000 : 1; |
||
384 | proben--; // One less to travel |
||
385 | if (proben == 0 && isarmed && |
||
386 | d.galaxy[probecx][probecy] % 10 > 0) { |
||
387 | /* lets blow the sucker! */ |
||
388 | snova(1,0); |
||
389 | future[FDSPROB] = 1e30; |
||
390 | if (d.galaxy[quadx][quady] == 1000) return; |
||
391 | } |
||
392 | break; |
||
393 | } |
||
394 | } |
||
395 | } |
||
396 | |||
397 | |||
398 | void waiting(void) { |
||
399 | int key; |
||
400 | double temp, delay, origTime; |
||
401 | |||
402 | ididit = 0; |
||
403 | for (;;) { |
||
404 | key = scan(); |
||
405 | if (key != IHEOL) break; |
||
406 | proutn("How long? "); |
||
407 | } |
||
408 | chew(); |
||
409 | if (key != IHREAL) { |
||
410 | huh(); |
||
411 | return; |
||
412 | } |
||
413 | origTime = delay = aaitem; |
||
414 | if (delay <= 0.0) return; |
||
415 | if (delay >= d.remtime || nenhere != 0) { |
||
416 | /* prout("Are you sure? "); */ |
||
417 | prout("Вы уверены? "); |
||
418 | if (ja() == 0) return; |
||
419 | } |
||
420 | |||
421 | /* Alternate resting periods (events) with attacks */ |
||
422 | |||
423 | resting = 1; |
||
424 | do { |
||
425 | if (delay <= 0) resting = 0; |
||
426 | if (resting == 0) { |
||
427 | cramf(d.remtime, 0, 2); |
||
428 | /* prout(" stardates left."); */ |
||
429 | prout(" звездных лет осталось."); |
||
430 | return; |
||
431 | } |
||
432 | temp = Time = delay; |
||
433 | |||
434 | if (nenhere) { |
||
435 | double rtime = 1.0 + Rand(); |
||
436 | if (rtime < temp) temp = rtime; |
||
437 | Time = temp; |
||
438 | } |
||
439 | if (Time < delay) attack(0); |
||
440 | if (nenhere==0) movetho(); |
||
441 | if (alldone) return; |
||
442 | events(); |
||
443 | ididit = 1; |
||
444 | if (alldone) return; |
||
445 | delay -= temp; |
||
446 | } while (d.galaxy[quadx][quady] != 1000); // leave if quadrant supernovas |
||
447 | |||
448 | resting = 0; |
||
449 | Time = 0; |
||
450 | } |
||
451 | |||
452 | void nova(int ix, int iy) { |
||
453 | static double course[] = |
||
454 | {0.0, 10.5, 12.0, 1.5, 9.0, 0.0, 3.0, 7.5, 6.0, 4.5}; |
||
455 | int bot, top, top2, burst, hits[11][3], kount, icx, icy, mm, nn, j; |
||
456 | int iquad, iquad1, i, ll, newcx, newcy, ii, jj; |
||
457 | if (Rand() < 0.05) { |
||
458 | /* Wow! We've supernova'ed */ |
||
459 | snova(ix, iy); |
||
460 | return; |
||
461 | } |
||
462 | |||
463 | /* handle initial nova */ |
||
464 | quad[ix][iy] = IHDOT; |
||
465 | crmena(1, IHSTAR, 2, ix, iy); |
||
466 | prout(" Новых звезд.");/*novas*/ |
||
467 | d.galaxy[quadx][quady] -= 1; |
||
468 | d.starkl++; |
||
469 | |||
470 | /* Set up stack to recursively trigger adjacent stars */ |
||
471 | bot = top = top2 = 1; |
||
472 | kount = 0; |
||
473 | icx = icy = 0; |
||
474 | hits[1][1] = ix; |
||
475 | hits[1][2] = iy; |
||
476 | while (1) { |
||
477 | for (mm = bot; mm <= top; mm++) |
||
478 | for (nn = 1; nn <= 3; nn++) /* nn,j represents coordinates around current */ |
||
479 | for (j = 1; j <= 3; j++) { |
||
480 | if (j==2 && nn== 2) continue; |
||
481 | ii = hits[mm][1]+nn-2; |
||
482 | jj = hits[mm][2]+j-2; |
||
483 | if (ii < 1 || ii > 10 || jj < 1 || jj > 10) continue; |
||
484 | iquad = quad[ii][jj]; |
||
485 | switch (iquad) { |
||
486 | // case IHDOT: /* Empty space ends reaction |
||
487 | // case IHQUEST: |
||
488 | // case IHBLANK: |
||
489 | // case IHT: |
||
490 | // case IHWEB: |
||
491 | default: |
||
492 | break; |
||
493 | case IHSTAR: /* Affect another star */ |
||
494 | if (Rand() < 0.05) { |
||
495 | /* This star supernovas */ |
||
496 | snova(ii,jj); |
||
497 | return; |
||
498 | } |
||
499 | top2++; |
||
500 | hits[top2][1]=ii; |
||
501 | hits[top2][2]=jj; |
||
502 | d.galaxy[quadx][quady] -= 1; |
||
503 | d.starkl++; |
||
504 | crmena(1, IHSTAR, 2, ii, jj); |
||
505 | prout(" Новых звезд.");/*novas*/ |
||
506 | quad[ii][jj] = IHDOT; |
||
507 | break; |
||
508 | case IHP: /* Destroy planet */ |
||
509 | d.newstuf[quadx][quady] -= 1; |
||
510 | d.nplankl++; |
||
511 | crmena(1, IHP, 2, ii, jj); |
||
512 | prout(" уничтожена.");/*destroyed*/ |
||
513 | d.plnets[iplnet] = nulplanet; |
||
514 | iplnet = plnetx = plnety = 0; |
||
515 | if (landed == 1) { |
||
516 | finish(FPNOVA); |
||
517 | return; |
||
518 | } |
||
519 | quad[ii][jj] = IHDOT; |
||
520 | break; |
||
521 | case IHB: /* Destroy base */ |
||
522 | d.galaxy[quadx][quady] -= 10; |
||
523 | for (i = 1; i <= d.rembase; i++) |
||
524 | if (d.baseqx[i]==quadx && d.baseqy[i]==quady) break; |
||
525 | d.baseqx[i] = d.baseqx[d.rembase]; |
||
526 | d.baseqy[i] = d.baseqy[d.rembase]; |
||
527 | d.rembase--; |
||
528 | basex = basey = 0; |
||
529 | d.basekl++; |
||
530 | newcnd(); |
||
531 | crmena(1, IHB, 2, ii, jj); |
||
532 | prout(" уничтожена.");/*destroyed*/ |
||
533 | quad[ii][jj] = IHDOT; |
||
534 | break; |
||
535 | case IHE: /* Buffet ship */ |
||
536 | case IHF: |
||
537 | prout("***Корабль отброшен Новой звездой.");/*Starship buffeted by nova*/ |
||
538 | if (shldup) { |
||
539 | if (shield >= 2000.0) shield -= 2000.0; |
||
540 | else { |
||
541 | double diff = 2000.0 - shield; |
||
542 | energy -= diff; |
||
543 | shield = 0.0; |
||
544 | shldup = 0; |
||
545 | prout("***Силовые щиты повреждены.");/*Shields knocked out*/ |
||
546 | damage[DSHIELD] += 0.005*damfac*Rand()*diff; |
||
547 | } |
||
548 | } |
||
549 | else energy -= 2000.0; |
||
550 | if (energy <= 0) { |
||
551 | finish(FNOVA); |
||
552 | return; |
||
553 | } |
||
554 | /* add in course nova contributes to kicking starship*/ |
||
555 | icx += sectx-hits[mm][1]; |
||
556 | icy += secty-hits[mm][2]; |
||
557 | kount++; |
||
558 | break; |
||
559 | case IHK: /* kill klingon */ |
||
560 | deadkl(ii,jj,iquad, ii, jj); |
||
561 | break; |
||
562 | case IHC: /* Damage/destroy big enemies */ |
||
563 | case IHS: |
||
564 | case IHR: |
||
565 | for (ll = 1; ll <= nenhere; ll++) |
||
566 | if (kx[ll]==ii && ky[ll]==jj) break; |
||
567 | kpower[ll] -= 800.0; /* If firepower is lost, die */ |
||
568 | if (kpower[ll] <= 0.0) { |
||
569 | deadkl(ii, jj, iquad, ii, jj); |
||
570 | break; |
||
571 | } |
||
572 | newcx = ii + ii - hits[mm][1]; |
||
573 | newcy = jj + jj - hits[mm][2]; |
||
574 | crmena(1, iquad, 2, ii, jj); |
||
575 | proutn(" повреждены");/*damaged*/ |
||
576 | if (newcx<1 || newcx>10 || newcy<1 || newcy>10) { |
||
577 | /* can't leave quadrant */ |
||
578 | skip(1); |
||
579 | break; |
||
580 | } |
||
581 | iquad1 = quad[newcx][newcy]; |
||
582 | if (iquad1 == IHBLANK) { |
||
583 | proutn(", взрыв в точке");/*blasted into*/ |
||
584 | crmena(0, IHBLANK, 2, newcx, newcy); |
||
585 | skip(1); |
||
586 | deadkl(ii, jj, iquad, newcx, newcy); |
||
587 | break; |
||
588 | } |
||
589 | if (iquad1 != IHDOT) { |
||
590 | /* can't move into something else */ |
||
591 | skip(1); |
||
592 | break; |
||
593 | } |
||
594 | proutn(", отброшен в");/*buffeted to*/ |
||
595 | cramlc(2, newcx, newcy); |
||
596 | quad[ii][jj] = IHDOT; |
||
597 | quad[newcx][newcy] = iquad; |
||
598 | kx[ll] = newcx; |
||
599 | ky[ll] = newcy; |
||
600 | kavgd[ll] = sqrt(square(sectx-newcx)+square(secty-newcy)); |
||
601 | kdist[ll] = kavgd[ll]; |
||
602 | skip(1); |
||
603 | break; |
||
604 | } |
||
605 | } |
||
606 | if (top == top2) break; |
||
607 | bot = top + 1; |
||
608 | top = top2; |
||
609 | } |
||
610 | if (kount==0) return; |
||
611 | |||
612 | /* Starship affected by nova -- kick it away. */ |
||
613 | dist = kount*0.1; |
||
614 | if (icx) icx = (icx < 0 ? -1 : 1); |
||
615 | if (icy) icy = (icy < 0 ? -1 : 1); |
||
616 | direc = course[3*(icx+1)+icy+2]; |
||
617 | if (direc == 0.0) dist = 0.0; |
||
618 | if (dist == 0.0) return; |
||
619 | Time = 10.0*dist/16.0; |
||
620 | skip(1); |
||
621 | /* prout("Force of nova displaces starship."); */ |
||
622 | prout("Сила Новой звезды переместила корабль."); |
||
623 | iattak=2; /* Eliminates recursion problem */ |
||
624 | lmove(); |
||
625 | Time = 10.0*dist/16.0; |
||
626 | return; |
||
627 | } |
||
628 | |||
629 | |||
630 | void snova(int insx, int insy) { |
||
631 | int comdead, nqx, nqy, nsx, nsy, num, kldead, iscdead; |
||
632 | int nrmdead, npdead; |
||
633 | int insipient=0; |
||
634 | |||
635 | nsx = insx; |
||
636 | nsy = insy; |
||
637 | |||
638 | if (insy== 0) { |
||
639 | if (insx == 1) { |
||
640 | /* NOVAMAX being used */ |
||
641 | nqx = probecx; |
||
642 | nqy = probecy; |
||
643 | } |
||
644 | else { |
||
645 | int stars = 0; |
||
646 | /* Scheduled supernova -- select star */ |
||
647 | /* logic changed here so that we won't favor quadrants in top |
||
648 | left of universe */ |
||
649 | for (nqx = 1; nqx<=8; nqx++) { |
||
650 | for (nqy = 1; nqy<=8; nqy++) { |
||
651 | stars += d.galaxy[nqx][nqy] % 10; |
||
652 | } |
||
653 | } |
||
654 | if (stars == 0) return; /* nothing to supernova exists */ |
||
655 | num = Rand()*stars + 1; |
||
656 | for (nqx = 1; nqx<=8; nqx++) { |
||
657 | for (nqy = 1; nqy<=8; nqy++) { |
||
658 | num -= d.galaxy[nqx][nqy] % 10; |
||
659 | if (num <= 0) break; |
||
660 | } |
||
661 | if (num <=0) break; |
||
662 | } |
||
663 | #ifdef DEBUG |
||
664 | if (idebug) { |
||
665 | proutn("Super nova here?"); |
||
666 | if (ja()==1) { |
||
667 | nqx = quadx; |
||
668 | nqy = quady; |
||
669 | } |
||
670 | } |
||
671 | #endif |
||
672 | } |
||
673 | |||
674 | if (nqx != quady || nqy != quady || justin != 0) { |
||
675 | /* it isn't here, or we just entered (treat as inroute) */ |
||
676 | if (REPORTS) { |
||
677 | skip(1); |
||
678 | /* proutn("Message from Starfleet Command Stardate "); */ |
||
679 | proutn("Сообщение от Звездного Командования Звездная Дата "); |
||
680 | cramf(d.date, 0, 1); |
||
681 | skip(1); |
||
682 | proutn(" Сверновая в точке");/*Supernova in*/ |
||
683 | cramlc(1, nqx, nqy); |
||
684 | prout("; осторожно.");/*caution advised*/ |
||
685 | } |
||
686 | } |
||
687 | else { |
||
688 | /* we are in the quadrant! */ |
||
689 | insipient = 1; |
||
690 | num = Rand()* (d.galaxy[nqx][nqy]%10) + 1; |
||
691 | for (nsx=1; nsx < 10; nsx++) { |
||
692 | for (nsy=1; nsy < 10; nsy++) { |
||
693 | if (quad[nsx][nsy]==IHSTAR) { |
||
694 | num--; |
||
695 | if (num==0) break; |
||
696 | } |
||
697 | } |
||
698 | if (num==0) break; |
||
699 | } |
||
700 | } |
||
701 | } |
||
702 | else { |
||
703 | insipient = 1; |
||
704 | } |
||
705 | |||
706 | if (insipient) { |
||
707 | skip(1); |
||
708 | /* prouts("***RED ALERT! RED ALERT!"); */ |
||
709 | prouts("***ОПАСНОСТЬ! ОПАСНОСТЬ!"); |
||
710 | skip(1); |
||
711 | /* proutn("***Incipient supernova detected at"); */ |
||
712 | proutn("***Взрыв сверхновой обнаружен в"); |
||
713 | cramlc(2, nsx, nsy); |
||
714 | skip(1); |
||
715 | nqx = quadx; |
||
716 | nqy = quady; |
||
717 | if (square(nsx-sectx) + square(nsy-secty) <= 2.1) { |
||
718 | /* proutn("Emergency override attempts t"); */ |
||
719 | proutn("Попытка экстренного перехвата управления"); |
||
720 | prouts("***************"); |
||
721 | skip(1); |
||
722 | stars(); |
||
723 | alldone=1; |
||
724 | } |
||
725 | } |
||
726 | /* destroy any Klingons in supernovaed quadrant */ |
||
727 | num=d.galaxy[nqx][nqy]; |
||
728 | kldead = num/100; |
||
729 | d.remkl -= kldead; // Moved here to correctly set remaining Klingon count |
||
730 | comdead = iscdead = 0; |
||
731 | if (nqx==d.isx && nqy == d.isy) { |
||
732 | /* did in the Supercommander! */ |
||
733 | d.nscrem = d.isx = d.isy = isatb = iscate = 0; |
||
734 | iscdead = 1; |
||
735 | kldead--; /* Get proper kill credit */ |
||
736 | future[FSCMOVE] = future[FSCDBAS] = 1e30; |
||
737 | } |
||
738 | |||
739 | if (d.remcom) { |
||
740 | int maxloop = d.remcom, l; |
||
741 | for (l = 1; l <= maxloop; l++) { |
||
742 | if (d.cx[l] == nqx && d.cy[l] == nqy) { |
||
743 | d.cx[l] = d.cx[d.remcom]; |
||
744 | d.cy[l] = d.cy[d.remcom]; |
||
745 | d.cx[d.remcom] = d.cy[d.remcom] = 0; |
||
746 | d.remcom--; |
||
747 | kldead--; |
||
748 | comdead++; |
||
749 | if (d.remcom==0) future[FTBEAM] = 1e30; |
||
750 | break; |
||
751 | } |
||
752 | } |
||
753 | } |
||
754 | /* destroy Romulans and planets in supernovaed quadrant */ |
||
755 | num = d.newstuf[nqx][nqy]; |
||
756 | d.newstuf[nqx][nqy] = 0; |
||
757 | nrmdead = num/10; |
||
758 | d.nromrem -= nrmdead; |
||
759 | npdead = num - nrmdead*10; |
||
760 | if (npdead) { |
||
761 | int l; |
||
762 | for (l = 1; l <= inplan; l++) |
||
763 | if (d.plnets[l].x == nqx && d.plnets[l].y == nqy) { |
||
764 | d.plnets[l] = nulplanet; |
||
765 | } |
||
766 | } |
||
767 | /* Destroy any base in supernovaed quadrant */ |
||
768 | if (d.rembase) { |
||
769 | int maxloop = d.rembase, l; |
||
770 | for (l = 1; l <= maxloop; l++) |
||
771 | if (d.baseqx[l]==nqx && d.baseqy[l]==nqy) { |
||
772 | d.baseqx[l] = d.baseqx[d.rembase]; |
||
773 | d.baseqy[l] = d.baseqy[d.rembase]; |
||
774 | d.baseqx[d.rembase] = d.baseqy[d.rembase] = 0; |
||
775 | d.rembase--; |
||
776 | break; |
||
777 | } |
||
778 | } |
||
779 | /* If starship caused supernova, tally up destruction */ |
||
780 | if (insx) { |
||
781 | num = d.galaxy[nqx][nqy] % 100; |
||
782 | d.starkl += num % 10; |
||
783 | d.basekl += num/10; |
||
784 | d.killk += kldead; |
||
785 | d.killc += comdead; |
||
786 | d.nromkl += nrmdead; |
||
787 | d.nplankl += npdead; |
||
788 | d.nsckill += iscdead; |
||
789 | } |
||
790 | /* mark supernova in galaxy and in star chart */ |
||
791 | if ((quadx == nqx && quady == nqy) || REPORTS) |
||
792 | starch[nqx][nqy] = 1; |
||
793 | d.galaxy[nqx][nqy] = 1000; |
||
794 | /* If supernova destroys last klingons give special message */ |
||
795 | if (d.remkl==0 && (nqx != quadx || nqy != quady)) { |
||
796 | skip(2); |
||
797 | if (insx == 0) prout("Счастливчики!");/*Lucky you*/ |
||
798 | proutn("Сверновая в точке");/*A supernova in*/ |
||
799 | cramlc(1, nqx, nqy); |
||
800 | /* prout(" has just destroyed the last Klingons."); */ |
||
801 | prout(" только что уничтожила последних Клингонов."); |
||
802 | finish(FWON); |
||
803 | return; |
||
804 | } |
||
805 | /* if some Klingons remain, continue or die in supernova */ |
||
806 | if (alldone) finish(FSNOVAED); |
||
807 | return; |
||
808 | }=>=>=>=>>>=0)>=>=8;>=8;>=8;>=8;>>>1>1>=>=>=>=>>>>=>=>=>>>>=>=>>>>>=>>=>>=d.remcom;>=d.rembase;>=>>>>>>>=>=>=ndevice;>=>>=0)>=>=>=NEVENTS;>=>=> |
||
809 |