2 * events.c -- event-queue handling
4 * This isn't a real event queue a la BSD Trek yet -- you can only have one
5 * event of each type active at any given time. Mostly these means we can
6 * only have one FDISTR/FENSLV/FREPRO sequence going at any given time;
7 * BSD Trek, from which we swiped the idea, can have up to 5.
12 event *unschedule(int evtype)
13 /* remove an event from the schedule */
15 game.future[evtype].date = FOREVER;
16 return &game.future[evtype];
19 int is_scheduled(int evtype)
20 /* is an event of specified type scheduled */
22 return game.future[evtype].date != FOREVER;
25 double scheduled(int evtype)
26 /* when will this event happen? */
28 return game.future[evtype].date;
31 event *schedule(int evtype, double offset)
32 /* schedule an event of specified type */
34 game.future[evtype].date = game.state.date + offset;
35 return &game.future[evtype];
38 void postpone(int evtype, double offset)
39 /* postpone a scheduled event */
41 game.future[evtype].date += offset;
44 static bool cancelrest(void)
45 /* rest period is interrupted by event */
49 proutn(_("Mr. Spock- \"Captain, shall we cancel the rest period?\""));
61 /* run through the event queue looking for things to do */
63 int evcode, i=0, j, k, l;
64 double fintim = game.state.date + game.optime, datemin, xtime, repair, yank=0;
65 bool ictbeam = false, istract = false;
66 struct quadrant *pdest, *q;
69 bool fixed_dev[NDEVICES];
72 prout("=== EVENTS from %.2f to %.2f:", game.state.date, fintim);
73 for (i = 1; i < NEVENTS; i++) {
75 case FSNOVA: proutn("=== Supernova "); break;
76 case FTBEAM: proutn("=== T Beam "); break;
77 case FSNAP: proutn("=== Snapshot "); break;
78 case FBATTAK: proutn("=== Base Attack "); break;
79 case FCDBAS: proutn("=== Base Destroy "); break;
80 case FSCMOVE: proutn("=== SC Move "); break;
81 case FSCDBAS: proutn("=== SC Base Destroy "); break;
82 case FDSPROB: proutn("=== Probe Move "); break;
83 case FDISTR: proutn("=== Distress Call "); break;
84 case FENSLV: proutn("=== Enslavement "); break;
85 case FREPRO: proutn("=== Klingon Build "); break;
88 prout("%.2f", scheduled(i));
97 /* Select earliest extraneous event, evcode==0 if no events */
102 for (l = 1; l < NEVENTS; l++)
103 if (game.future[l].date < datemin) {
106 prout("== Event %d fires", evcode);
107 datemin = game.future[l].date;
109 xtime = datemin-game.state.date;
110 game.state.date = datemin;
111 /* Decrement Federation resources and recompute remaining time */
112 game.state.remres -= (game.state.remkl+4*game.state.remcom)*xtime;
113 game.state.remtime = game.state.remkl + game.state.remcom > 0 ?
114 game.state.remres/(game.state.remkl + 4*game.state.remcom) : 99;
115 if (game.state.remtime <=0) {
119 /* Any crew left alive? */
120 if (game.state.crew <=0) {
124 /* Is life support adequate? */
125 if (damaged(DLIFSUP) && game.condition != docked) {
126 if (game.lsupres < xtime && game.damage[DLIFSUP] > game.lsupres) {
130 game.lsupres -= xtime;
131 if (game.damage[DLIFSUP] <= xtime)
132 game.lsupres = game.inlsr;
136 if (game.condition == docked)
137 repair /= game.docfac;
138 /* Don't fix Deathray here */
139 for (l=0; l<NDEVICES; l++) {
140 fixed_dev[l] = false;
141 if (game.damage[l] > 0.0 && l != DDRAY) {
142 double reminder = (game.damage[l] > repair ?
143 game.damage[l] - repair : .0);
144 game.damage[l] = reminder;
149 /* If radio repaired, update star chart and attack reports */
150 if (fixed_dev[DRADIO]) {
151 prout(_("Lt. Uhura- \"Captain, the sub-space radio is working and"));
152 prout(_(" surveillance reports are coming in."));
158 prout(_(" The star chart is now up to date.\""));
161 if (fixed_dev[DRADIO] || fixed_dev[DLRSENS] || fixed_dev[DSRSENS])
163 /* Cause extraneous event EVCODE to occur */
164 game.optime -= xtime;
166 case FSNOVA: /* Supernova */
168 supernova(false, NULL);
169 schedule(FSNOVA, expran(0.5*game.intime));
170 if (game.state.galaxy[game.quadrant.x][game.quadrant.y].supernova)
173 case FSPY: /* Check with spy to see if S.C. should tractor beam */
174 if (game.state.nscrem == 0 ||
175 ictbeam || istract ||
176 game.condition==docked || game.isatb==1 || game.iscate)
179 (game.energy < 2000 && game.torps < 4 && game.shield < 1250) ||
180 (damaged(DPHASER) && (damaged(DPHOTON) || game.torps < 4)) ||
182 (game.energy < 2500 || damaged(DPHASER)) &&
183 (game.torps < 5 || damaged(DPHOTON)))) {
184 /* Tractor-beam her! */
186 yank = distance(game.state.kscmdr, game.quadrant);
187 /********* fall through to FTBEAM code ***********/
191 case FTBEAM: /* Tractor beam */
192 if (evcode==FTBEAM) {
193 if (game.state.remcom == 0) {
197 i = Rand()*game.state.remcom+1.0;
198 yank = square(game.state.kcmdr[i].x-game.quadrant.x) + square(game.state.kcmdr[i].y-game.quadrant.y);
199 if (istract || game.condition == docked || yank == 0) {
200 /* Drats! Have to reschedule */
202 game.optime + expran(1.5*game.intime/game.state.remcom));
206 /* tractor beaming cases merge here */
209 game.optime = (10.0/(7.5*7.5))*yank; /* 7.5 is yank rate (warp 7.5) */
214 prout(_(" caught in long range tractor beam--"));
215 /* If Kirk & Co. screwing around on planet, handle */
216 atover(true); /* atover(true) is Grab */
219 if (game.icraft) { /* Caught in Galileo? */
223 /* Check to see if shuttle is aboard */
224 if (game.iscraft == offship) {
227 prout(_("Galileo, left on the planet surface, is captured"));
228 prout(_("by aliens and made into a flying McDonald's."));
229 game.damage[DSHUTTL] = -10;
230 game.iscraft = removed;
233 prout(_("Galileo, left on the planet surface, is well hidden."));
237 game.quadrant = game.state.kscmdr;
239 game.quadrant = game.state.kcmdr[i];
240 game.sector = randplace(QUADSIZE);
242 proutn(_(" is pulled to "));
243 proutn(cramlc(quadrant, game.quadrant));
245 prout(cramlc(sector, game.sector));
247 prout(_("(Remainder of rest/repair period cancelled.)"));
248 game.resting = false;
251 if (!damaged(DSHIELD) && game.shield > 0) {
252 doshield(true); /* raise shields */
256 prout(_("(Shields not currently useable.)"));
259 /* Adjust finish time to time of tractor beaming */
260 fintim = game.state.date+game.optime;
262 if (game.state.remcom <= 0)
265 schedule(FTBEAM, game.optime+expran(1.5*game.intime/game.state.remcom));
267 case FSNAP: /* Snapshot of the universe (for time warp) */
268 game.snapsht = game.state;
269 game.state.snap = true;
270 schedule(FSNAP, expran(0.5 * game.intime));
272 case FBATTAK: /* Commander attacks starbase */
273 if (game.state.remcom==0 || game.state.rembase==0) {
280 for (j = 1; j <= game.state.rembase; j++) {
281 for (k = 1; k <= game.state.remcom; k++)
282 if (same(game.state.baseq[j], game.state.kcmdr[k]) &&
283 !same(game.state.baseq[j], game.quadrant) &&
284 !same(game.state.baseq[j], game.state.kscmdr)) {
291 if (j>game.state.rembase) {
292 /* no match found -- try later */
293 schedule(FBATTAK, expran(0.3*game.intime));
297 /* commander + starbase combination found -- launch attack */
298 game.battle = game.state.baseq[j];
299 schedule(FCDBAS, 1.0+3.0*Rand());
300 if (game.isatb) /* extra time if SC already attacking */
301 postpone(FCDBAS, scheduled(FSCDBAS)-game.state.date);
302 game.future[FBATTAK].date = game.future[FCDBAS].date + expran(0.3*game.intime);
303 game.iseenit = false;
304 if (!damaged(DRADIO) && game.condition != docked)
305 break; /* No warning :-( */
309 proutn(_("Lt. Uhura- \"Captain, the starbase in "));
310 prout(cramlc(quadrant, game.battle));
311 prout(_(" reports that it is under attack and that it can"));
312 proutn(_(" hold out only until stardate %d"),
313 (int)scheduled(FCDBAS));
318 case FSCDBAS: /* Supercommander destroys base */
321 if (!game.state.galaxy[game.state.kscmdr.x][game.state.kscmdr.y].starbase)
322 break; /* WAS RETURN! */
324 game.battle = game.state.kscmdr;
326 case FCDBAS: /* Commander succeeds in destroying base */
327 if (evcode==FCDBAS) {
329 /* find the lucky pair */
330 for (i = 1; i <= game.state.remcom; i++)
331 if (same(game.state.kcmdr[i], game.battle))
333 if (i > game.state.remcom || game.state.rembase == 0 ||
334 !game.state.galaxy[game.battle.x][game.battle.y].starbase) {
335 /* No action to take after all */
336 invalidate(game.battle);
340 /* Code merges here for any commander destroying base */
341 /* Not perfect, but will have to do */
342 /* Handle case where base is in same quadrant as starship */
343 if (same(game.battle, game.quadrant)) {
344 game.state.chart[game.battle.x][game.battle.y].starbase = false;
345 game.quad[game.base.x][game.base.y] = IHDOT;
346 game.base.x=game.base.y=0;
349 prout(_("Spock- \"Captain, I believe the starbase has been destroyed.\""));
351 else if (game.state.rembase != 1 &&
352 (!damaged(DRADIO) || game.condition == docked)) {
353 /* Get word via subspace radio */
356 prout(_("Lt. Uhura- \"Captain, Starfleet Command reports that"));
357 proutn(_(" the starbase in "));
358 proutn(cramlc(quadrant, game.battle));
359 prout(_(" has been destroyed by"));
361 prout(_("the Klingon Super-Commander"));
363 prout(_("a Klingon Commander"));
364 game.state.chart[game.battle.x][game.battle.y].starbase = false;
366 /* Remove Starbase from galaxy */
367 game.state.galaxy[game.battle.x][game.battle.y].starbase = false;
368 for (i = 1; i <= game.state.rembase; i++)
369 if (same(game.state.baseq[i], game.battle))
370 game.state.baseq[i] = game.state.baseq[game.state.rembase];
371 game.state.rembase--;
372 if (game.isatb == 2) {
373 /* reinstate a commander's base attack */
378 invalidate(game.battle);
380 case FSCMOVE: /* Supercommander moves */
381 schedule(FSCMOVE, 0.2777);
382 if (!game.ientesc && !istract && game.isatb != 1 &&
383 (!game.iscate || !game.justin))
386 case FDSPROB: /* Move deep space probe */
387 schedule(FDSPROB, 0.01);
388 game.probex += game.probeinx;
389 game.probey += game.probeiny;
390 i = (int)(game.probex/QUADSIZE +0.05);
391 j = (int)(game.probey/QUADSIZE + 0.05);
392 if (game.probec.x != i || game.probec.y != j) {
395 if (!VALID_QUADRANT(i, j) ||
396 game.state.galaxy[game.probec.x][game.probec.y].supernova) {
397 // Left galaxy or ran into supernova
398 if (!damaged(DRADIO) || game.condition == docked) {
401 proutn(_("Lt. Uhura- \"The deep space probe "));
402 if (!VALID_QUADRANT(j, i))
403 proutn(_("has left the galaxy"));
405 proutn(_("is no longer transmitting"));
411 if (!damaged(DRADIO) || game.condition == docked) {
414 proutn(_("Lt. Uhura- \"The deep space probe is now in "));
415 proutn(cramlc(quadrant, game.probec));
419 pdest = &game.state.galaxy[game.probec.x][game.probec.y];
420 /* Update star chart if Radio is working or have access to
422 if (!damaged(DRADIO) || game.condition == docked) {
423 struct page *chp = &game.state.chart[game.probec.x][game.probec.y];
425 chp->klingons = pdest->klingons;
426 chp->starbase = pdest->starbase;
427 chp->stars = pdest->stars;
428 pdest->charted = true;
430 game.proben--; // One less to travel
431 if (game.proben == 0 && game.isarmed && pdest->stars) {
432 /* lets blow the sucker! */
433 supernova(true, &game.probec);
435 if (game.state.galaxy[game.quadrant.x][game.quadrant.y].supernova)
439 case FDISTR: /* inhabited system issues distress call */
441 /* try a whole bunch of times to find something suitable */
444 // need a quadrant which is not the current one,
445 // which has some stars which are inhabited and
446 // not already under attack, which is not
447 // supernova'ed, and which has some Klingons in it
448 w = randplace(GALSIZE);
449 q = &game.state.galaxy[w.x][w.y];
451 (same(game.quadrant, w) || q->planet == NOPLANET ||
452 game.state.planets[q->planet].inhabited == UNINHABITED ||
453 q->supernova || q->status!=secure || q->klingons<=0));
455 /* can't seem to find one; ignore this call */
457 prout("=== Couldn't find location for distress event.");
461 /* got one!! Schedule its enslavement */
462 ev = schedule(FENSLV, expran(game.intime));
464 q->status = distressed;
466 /* tell the captain about it if we can */
467 if (!damaged(DRADIO) || game.condition == docked)
469 prout(_("Uhura- Captain, %s in %s reports it is under attack"),
470 systnames[q->planet], cramlc(quadrant, w));
471 prout(_("by a Klingon invasion fleet."));
476 case FENSLV: /* starsystem is enslaved */
477 ev = unschedule(FENSLV);
478 /* see if current distress call still active */
479 q = &game.state.galaxy[ev->quadrant.x][ev->quadrant.y];
480 if (q->klingons <= 0) {
484 q->status = enslaved;
486 /* play stork and schedule the first baby */
487 ev2 = schedule(FREPRO, expran(2.0 * game.intime));
488 ev2->quadrant = ev->quadrant;
490 /* report the disaster if we can */
491 if (!damaged(DRADIO) || game.condition == docked)
493 prout(_("Uhura- We've lost contact with starsystem %s"),
494 systnames[q->planet]);
495 prout(_("in %s.\n"), cramlc(quadrant, ev->quadrant));
498 case FREPRO: /* Klingon reproduces */
499 // If we ever switch to a real event queue, we'll need to
500 // explicitly retrieve and restore the x and y.
501 ev = schedule(FREPRO, expran(1.0 * game.intime));
502 /* see if current distress call still active */
503 q = &game.state.galaxy[ev->quadrant.x][ev->quadrant.y];
504 if (q->klingons <= 0) {
508 if (game.state.remkl >=MAXKLGAME)
509 break; /* full right now */
510 /* reproduce one Klingon */
512 if (game.klhere >= MAXKLQUAD) {
513 /* this quadrant not ok, pick an adjacent one */
514 for (i = w.x - 1; i <= w.x + 1; i++)
516 for (j = w.y - 1; j <= w.y + 1; j++)
518 if (!VALID_QUADRANT(i, j))
520 q = &game.state.galaxy[w.x][w.y];
521 /* check for this quad ok (not full & no snova) */
522 if (q->klingons >= MAXKLQUAD || q->supernova)
527 break; /* search for eligible quadrant failed */
533 /* deliver the child */
536 if (same(game.quadrant, w))
537 newkling(++game.klhere);
539 /* recompute time left */
540 game.state.remtime = game.state.remkl + game.state.remcom > 0 ?
541 game.state.remres/(game.state.remkl + 4*game.state.remcom) : 99;
542 /* report the disaster if we can */
543 if (!damaged(DRADIO) || game.condition == docked)
545 if (same(game.quadrant, w)) {
546 prout(_("Spock- sensors indicate the Klingons have"));
547 prout(_("launched a warship from %s."), systnames[q->planet]);
549 prout(_("Uhura- Starfleet reports increased Klingon activity"));
550 if (q->planet != NOPLANET)
551 proutn(_("near %s "), systnames[q->planet]);
552 prout(_("in %s.\n"), cramlc(quadrant, w));
565 double temp, delay, origTime;
572 proutn(_("How long? "));
579 origTime = delay = aaitem;
582 if (delay >= game.state.remtime || game.nenhere != 0) {
583 proutn(_("Are you sure? "));
588 /* Alternate resting periods (events) with attacks */
593 game.resting = false;
595 prout(_("%d stardates left."), (int)game.state.remtime);
598 temp = game.optime = delay;
601 double rtime = 1.0 + Rand();
606 if (game.optime < delay)
615 /* Repair Deathray if long rest at starbase */
616 if (origTime-delay >= 9.99 && game.condition == docked)
617 game.damage[DDRAY] = 0.0;
619 // leave if quadrant supernovas
620 (!game.state.galaxy[game.quadrant.x][game.quadrant.y].supernova);
622 game.resting = false;
627 * A nova occurs. It is the result of having a star hit with a
628 * photon torpedo, or possibly of a probe warhead going off.
629 * Stars that go nova cause stars which surround them to undergo
630 * the same probabilistic process. Klingons next to them are
631 * destroyed. And if the starship is next to it, it gets zapped.
632 * If the zap is too much, it gets destroyed.
637 static double course[] =
638 {0.0, 10.5, 12.0, 1.5, 9.0, 0.0, 3.0, 7.5, 6.0, 4.5};
639 int bot, top, top2, hits[QUADSIZE+1][3], kount, icx, icy, mm, nn, j;
640 int iquad, iquad1, i, ll;
644 /* Wow! We've supernova'ed */
645 supernova(false, &nov);
649 /* handle initial nova */
650 game.quad[nov.x][nov.y] = IHDOT;
651 crmena(false, IHSTAR, sector, nov);
653 game.state.galaxy[game.quadrant.x][game.quadrant.y].stars--;
656 /* Set up stack to recursively trigger adjacent stars */
657 bot = top = top2 = 1;
663 for (mm = bot; mm <= top; mm++)
664 for (nn = 1; nn <= 3; nn++) /* nn,j represents coordinates around current */
665 for (j = 1; j <= 3; j++) {
668 scratch.x = hits[mm][1]+nn-2;
669 scratch.y = hits[mm][2]+j-2;
670 if (!VALID_SECTOR(scratch.y, scratch.x))
672 iquad = game.quad[scratch.x][scratch.y];
674 // case IHDOT: /* Empty space ends reaction
681 case IHSTAR: /* Affect another star */
683 /* This star supernovas */
684 supernova(false, &scratch);
688 hits[top2][1]=scratch.x;
689 hits[top2][2]=scratch.y;
690 game.state.galaxy[game.quadrant.x][game.quadrant.y].stars -= 1;
692 crmena(true, IHSTAR, sector, scratch);
694 game.quad[scratch.x][scratch.y] = IHDOT;
696 case IHP: /* Destroy planet */
697 game.state.galaxy[game.quadrant.x][game.quadrant.y].planet = NOPLANET;
698 game.state.nplankl++;
699 crmena(true, IHP, sector, scratch);
700 prout(_(" destroyed."));
701 game.state.planets[game.iplnet].pclass = destroyed;
703 invalidate(game.plnet);
708 game.quad[scratch.x][scratch.y] = IHDOT;
710 case IHB: /* Destroy base */
711 game.state.galaxy[game.quadrant.x][game.quadrant.y].starbase = false;
712 for (i = 1; i <= game.state.rembase; i++)
713 if (same(game.state.baseq[i], game.quadrant))
715 game.state.baseq[i] = game.state.baseq[game.state.rembase];
716 game.state.rembase--;
717 invalidate(game.base);
720 crmena(true, IHB, sector, scratch);
721 prout(_(" destroyed."));
722 game.quad[scratch.x][scratch.y] = IHDOT;
724 case IHE: /* Buffet ship */
726 prout(_("***Starship buffeted by nova."));
728 if (game.shield >= 2000.0)
729 game.shield -= 2000.0;
731 double diff = 2000.0 - game.shield;
735 prout(_("***Shields knocked out."));
736 game.damage[DSHIELD] += 0.005*game.damfac*Rand()*diff;
740 game.energy -= 2000.0;
741 if (game.energy <= 0) {
745 /* add in course nova contributes to kicking starship*/
746 icx += game.sector.x-hits[mm][1];
747 icy += game.sector.y-hits[mm][2];
750 case IHK: /* kill klingon */
751 deadkl(scratch,iquad, scratch);
753 case IHC: /* Damage/destroy big enemies */
756 for (ll = 1; ll <= game.nenhere; ll++)
757 if (same(game.ks[ll], scratch))
759 game.kpower[ll] -= 800.0; /* If firepower is lost, die */
760 if (game.kpower[ll] <= 0.0) {
761 deadkl(scratch, iquad, scratch);
764 newc.x = scratch.x + scratch.x - hits[mm][1];
765 newc.y = scratch.y + scratch.y - hits[mm][2];
766 crmena(true, iquad, sector, scratch);
767 proutn(_(" damaged"));
768 if (!VALID_SECTOR(newc.x, newc.y)) {
769 /* can't leave quadrant */
773 iquad1 = game.quad[newc.x][newc.y];
774 if (iquad1 == IHBLANK) {
775 proutn(_(", blasted into "));
776 crmena(false, IHBLANK, sector, newc);
778 deadkl(scratch, iquad, newc);
781 if (iquad1 != IHDOT) {
782 /* can't move into something else */
786 proutn(_(", buffeted to "));
787 proutn(cramlc(sector, newc));
788 game.quad[scratch.x][scratch.y] = IHDOT;
789 game.quad[newc.x][newc.y] = iquad;
791 game.kdist[ll] = game.kavgd[ll] = distance(game.sector, newc);
804 /* Starship affected by nova -- kick it away. */
805 game.dist = kount*0.1;
807 icx = (icx < 0 ? -1 : 1);
809 icy = (icy < 0 ? -1 : 1);
810 game.direc = course[3*(icx+1)+icy+2];
811 if (game.direc == 0.0)
813 if (game.dist == 0.0)
815 game.optime = 10.0*game.dist/16.0;
817 prout(_("Force of nova displaces starship."));
819 game.optime = 10.0*game.dist/16.0;
824 void supernova(bool induced, coord *w)
825 /* star goes supernova */
827 int num = 0, nrmdead, npdead = 0, kldead, loop;
834 /* Scheduled supernova -- select star */
835 /* logic changed here so that we won't favor quadrants in top
837 for (nq.x = 1; nq.x <= GALSIZE; nq.x++)
838 for (nq.y = 1; nq.y <= GALSIZE; nq.y++)
839 stars += game.state.galaxy[nq.x][nq.y].stars;
841 return; /* nothing to supernova exists */
842 num = Rand()*stars + 1;
843 for (nq.x = 1; nq.x <= GALSIZE; nq.x++) {
844 for (nq.y = 1; nq.y <= GALSIZE; nq.y++) {
845 num -= game.state.galaxy[nq.x][nq.y].stars;
853 proutn("=== Super nova here?");
859 if (!same(nq, game.quadrant) || game.justin) {
860 /* it isn't here, or we just entered (treat as enroute) */
861 if (!damaged(DRADIO) || game.condition == docked) {
863 prout(_("Message from Starfleet Command Stardate %.2f"), game.state.date);
864 prout(_(" Supernova in %s; caution advised."),
865 cramlc(quadrant, nq));
870 /* we are in the quadrant! */
871 num = Rand()* game.state.galaxy[nq.x][nq.y].stars + 1;
872 for (ns.x = 1; ns.x <= QUADSIZE; ns.x++) {
873 for (ns.y = 1; ns.y <= QUADSIZE; ns.y++) {
874 if (game.quad[ns.x][ns.y]==IHSTAR) {
885 prouts(_("***RED ALERT! RED ALERT!"));
887 prout(_("***Incipient supernova detected at %s"), cramlc(sector, ns));
888 if (square(ns.x-game.sector.x) + square(ns.y-game.sector.y) <= 2.1) {
889 proutn(_("Emergency override attempts t"));
890 prouts("***************");
897 /* destroy any Klingons in supernovaed quadrant */
898 kldead = game.state.galaxy[nq.x][nq.y].klingons;
899 game.state.galaxy[nq.x][nq.y].klingons = 0;
900 if (same(nq, game.state.kscmdr)) {
901 /* did in the Supercommander! */
902 game.state.nscrem = game.state.kscmdr.x = game.state.kscmdr.y = game.isatb = 0;
906 if (same(nq, game.battle)) {
909 invalidate(game.battle);
911 if (game.state.remcom) {
912 int maxloop = game.state.remcom, l;
913 for (l = 1; l <= maxloop; l++) {
914 if (same(game.state.kcmdr[l], nq)) {
915 game.state.kcmdr[l] = game.state.kcmdr[game.state.remcom];
916 invalidate(game.state.kcmdr[game.state.remcom]);
919 if (game.state.remcom==0)
925 game.state.remkl -= kldead;
926 /* destroy Romulans and planets in supernovaed quadrant */
927 nrmdead = game.state.galaxy[nq.x][nq.y].romulans;
928 game.state.galaxy[nq.x][nq.y].romulans = 0;
929 game.state.nromrem -= nrmdead;
930 /* Destroy planets */
931 for (loop = 0; loop < game.inplan; loop++) {
932 if (same(game.state.planets[loop].w, nq)) {
933 game.state.planets[loop].pclass = destroyed;
937 /* Destroy any base in supernovaed quadrant */
938 if (game.state.rembase) {
939 int maxloop = game.state.rembase, loop;
940 for (loop = 1; loop <= maxloop; loop++)
941 if (same(game.state.baseq[loop], nq)) {
942 game.state.baseq[loop] = game.state.baseq[game.state.rembase];
943 invalidate(game.state.baseq[game.state.rembase]);
944 game.state.rembase--;
948 /* If starship caused supernova, tally up destruction */
950 game.state.starkl += game.state.galaxy[nq.x][nq.y].stars;
951 game.state.basekl += game.state.galaxy[nq.x][nq.y].starbase;
952 game.state.nplankl += npdead;
954 /* mark supernova in galaxy and in star chart */
955 if (same(game.quadrant, nq) || !damaged(DRADIO) || game.condition == docked)
956 game.state.galaxy[nq.x][nq.y].supernova = true;
957 /* If supernova destroys last Klingons give special message */
958 if ((game.state.remkl + game.state.remcom + game.state.nscrem)==0 && !same(nq, game.quadrant)) {
961 prout(_("Lucky you!"));
962 proutn(_("A supernova in %s has just destroyed the last Klingons."),
963 cramlc(quadrant, nq));
967 /* if some Klingons remain, continue or die in supernova */