7 enum {NONE, SHUP, SHDN, NRG} action = NONE;
11 if (i == 2) action = SHUP;
19 if (game.damage[DSHIELD]) {
20 prout("Shields damaged and down.");
25 else if (isit("down"))
30 proutn("Do you wish to change shield energy? ");
32 proutn("Energy to transfer to shields- ");
35 else if (game.damage[DSHIELD]) {
36 prout("Shields damaged and down.");
40 proutn("Shields are up. Do you want them down? ");
41 if (ja()) action = SHDN;
48 proutn("Shields are down. Do you want them up? ");
49 if (ja()) action = SHUP;
58 case SHUP: /* raise shields */
60 prout("Shields already up.");
65 if (condit != IHDOCKED) energy -= 50.0;
66 prout("Shields raised.");
69 prout("Shields raising uses up last of energy.");
77 prout("Shields already down.");
82 prout("Shields lowered.");
86 while (scan() != IHREAL) {
88 proutn("Energy to transfer to shields- ");
91 if (aaitem==0) return;
92 if (aaitem > energy) {
93 prout("Insufficient ship energy.");
97 if (shield+aaitem >= inshld) {
98 prout("Shield energy maximized.");
99 if (shield+aaitem > inshld) {
100 prout("Excess energy requested returned to ship energy");
102 energy -= inshld-shield;
106 if (aaitem < 0.0 && energy-aaitem > inenrg) {
107 /* Prevent shield drain loophole */
109 prout("Engineering to bridge--");
110 prout(" Scott here. Power circuit problem, Captain.");
111 prout(" I can't drain the shields.");
115 if (shield+aaitem < 0) {
116 prout("All shield energy transferred to ship.");
121 proutn("Scotty- \"");
123 prout("Transferring energy to shields.\"");
125 prout("Draining energy from shields.\"");
129 case NONE:; /* avoid gcc warning */
133 void ram(int ibumpd, int ienm, int ix, int iy) {
134 double type = 1.0, extradm;
137 prouts("***RED ALERT! RED ALERT!");
139 prout("***COLLISION IMMINENT.");
144 case IHR: type = 1.5; break;
145 case IHC: type = 2.0; break;
146 case IHS: type = 2.5; break;
147 case IHT: type = 0.5; break;
148 case IHQUEST: type = 4.0; break;
150 proutn(ibumpd ? " rammed by " : " rams ");
151 crmena(0, ienm, 2, ix, iy);
152 if (ibumpd) proutn(" (original position)");
154 deadkl(ix, iy, ienm, sectx, secty);
157 prout(" heavily damaged.");
158 icas = 10.0+20.0*Rand();
159 prout("***Sickbay reports %d casualties", icas);
161 for (l=1; l <= NDEVICES; l++) {
162 if (l == DDRAY) continue; // Don't damage deathray
163 if (game.damage[l] < 0) continue;
164 extradm = (10.0*type*Rand()+1.0)*damfac;
165 game.damage[l] += Time + extradm; /* Damage for at least time of travel! */
168 if (game.state.remkl) {
176 void torpedo(double course, double r, int inx, int iny, double *hit, int wait, int i, int n) {
177 int l, iquad=0, ix=0, iy=0, jx=0, jy=0, shoved=0, ll;
180 double ac=course + 0.25*r;
181 double angle = (15.0-ac)*0.5235988;
182 double bullseye = (15.0 - course)*0.5235988;
183 double deltax=-sin(angle), deltay=cos(angle), x=inx, y=iny, bigger;
184 double ang, temp, xx, yy, kp, h1;
186 bigger = fabs(deltax);
187 if (fabs(deltay) > bigger) bigger = fabs(deltay);
192 if (game.damage[DSRSENS]==0 || condit==IHDOCKED) setwnd(LEFTUPPER_WINDOW);
193 else setwnd(LOWER_WINDOW);
194 /* Loop to move a single torpedo */
195 for (l=1; l <= 15; l++) {
198 if (ix < 1 || ix > 10) break;
201 if (iy < 1 || iy > 10) break;
202 iquad=game.quad[ix][iy];
203 tracktorpedo(x, y, ix, iy, wait, l, i, n, iquad);
205 if (iquad==IHDOT) continue;
207 setwnd(LOWER_WINDOW);
210 case IHE: /* Hit our ship */
213 proutn("Torpedo hits ");
216 *hit = 700.0 + 100.0*Rand() -
217 1000.0*sqrt(square(ix-inx)+square(iy-iny))*
218 fabs(sin(bullseye-angle));
220 newcnd(); /* we're blown out of dock */
221 /* We may be displaced. */
222 if (landed==1 || condit==IHDOCKED) return; /* Cheat if on a planet */
223 ang = angle + 2.5*(Rand()-0.5);
224 temp = fabs(sin(ang));
225 if (fabs(cos(ang)) > temp) temp = fabs(cos(ang));
230 if (jx<1 || jx>10 || jy<1 ||jy > 10) return;
231 if (game.quad[jx][jy]==IHBLANK) {
235 if (game.quad[jx][jy]!=IHDOT) {
236 /* can't move into object */
245 case IHC: /* Hit a commander */
247 if (Rand() <= 0.05) {
248 crmena(1, iquad, 2, ix, iy);
249 prout(" uses anti-photon device;");
250 prout(" torpedo neutralized.");
253 case IHR: /* Hit a regular enemy */
256 for (ll=1; ll <= nenhere; ll++)
257 if (ix==game.kx[ll] && iy==game.ky[ll]) break;
258 kp = fabs(game.kpower[ll]);
259 h1 = 700.0 + 100.0*Rand() -
260 1000.0*sqrt(square(ix-inx)+square(iy-iny))*
261 fabs(sin(bullseye-angle));
263 if (kp < h1) h1 = kp;
264 game.kpower[ll] -= (game.kpower[ll]<0 ? -h1 : h1);
265 if (game.kpower[ll] == 0) {
266 deadkl(ix, iy, iquad, ix, iy);
269 crmena(1, iquad, 2, ix, iy);
270 /* If enemy damaged but not destroyed, try to displace */
271 ang = angle + 2.5*(Rand()-0.5);
272 temp = fabs(sin(ang));
273 if (fabs(cos(ang)) > temp) temp = fabs(cos(ang));
278 if (jx<1 || jx>10 || jy<1 ||jy > 10) {
279 prout(" damaged but not destroyed.");
282 if (game.quad[jx][jy]==IHBLANK) {
283 prout(" buffeted into black hole.");
284 deadkl(ix, iy, iquad, jx, jy);
287 if (game.quad[jx][jy]!=IHDOT) {
288 /* can't move into object */
289 prout(" damaged but not destroyed.");
292 proutn(" damaged--");
297 case IHB: /* Hit a base */
299 prout("***STARBASE DESTROYED..");
300 if (game.starch[quadx][quady] < 0) game.starch[quadx][quady] = 0;
301 for (ll=1; ll<=game.state.rembase; ll++) {
302 if (game.state.baseqx[ll]==quadx && game.state.baseqy[ll]==quady) {
303 game.state.baseqx[ll]=game.state.baseqx[game.state.rembase];
304 game.state.baseqy[ll]=game.state.baseqy[game.state.rembase];
308 game.quad[ix][iy]=IHDOT;
309 game.state.rembase--;
311 game.state.galaxy[quadx][quady] -= 10;
315 case IHP: /* Hit a planet */
316 crmena(1, iquad, 2, ix, iy);
317 prout(" destroyed.");
318 game.state.nplankl++;
319 game.state.newstuf[quadx][quady] -= 1;
320 DESTROY(&game.state.plnets[iplnet]);
323 game.quad[ix][iy] = IHDOT;
325 /* captain parishes on planet */
329 case IHSTAR: /* Hit a star */
334 crmena(1, IHSTAR, 2, ix, iy);
335 prout(" unaffected by photon blast.");
337 case IHQUEST: /* Hit a thingy */
338 if (Rand()>0.7) { // Used to be certain death
340 prouts("AAAAIIIIEEEEEEEEAAAAAAAAUUUUUGGGGGHHHHHHHHHHHH!!!");
342 prouts(" HACK! HACK! HACK! *CHOKE!* ");
344 proutn("Mr. Spock-");
345 prouts(" \"Fascinating!\"");
347 deadkl(ix, iy, iquad, ix, iy);
350 * Stas Sergeev added the possibility that
351 * you can shove the Thingy.
357 case IHBLANK: /* Black hole */
359 crmena(1, IHBLANK, 2, ix, iy);
360 prout(" swallows torpedo.");
362 case IHWEB: /* hit the web */
364 prout("***Torpedo absorbed by Tholian web.");
366 case IHT: /* Hit a Tholian */
367 h1 = 700.0 + 100.0*Rand() -
368 1000.0*sqrt(square(ix-inx)+square(iy-iny))*
369 fabs(sin(bullseye-angle));
372 game.quad[ix][iy] = IHDOT;
375 deadkl(ix, iy, iquad, ix, iy);
379 crmena(1, IHT, 2, ix, iy);
381 prout(" survives photon blast.");
384 prout(" disappears.");
385 game.quad[ix][iy] = IHWEB;
386 ithere = ithx = ithy = 0;
390 dropin(IHBLANK, &dum, &my);
394 default: /* Problem! */
396 proutn("Don't know how to handle collision with ");
397 crmena(1, iquad, 2, ix, iy);
403 if(curwnd!=LOWER_WINDOW) {
404 setwnd(LOWER_WINDOW);
408 game.quad[jx][jy]=iquad;
409 game.quad[ix][iy]=IHDOT;
410 prout(" displaced by blast to %s ", cramlc(sector, jx, jy));
411 for (ll=1; ll<=nenhere; ll++)
412 game.kdist[ll] = game.kavgd[ll] = sqrt(square(sectx-game.kx[ll])+square(secty-game.ky[ll]));
417 prout("Torpedo missed.");
421 static void fry(double hit) {
422 double ncrit, extradm;
423 int ktr=1, l, ll, j, cdam[NDEVICES+1];
425 /* a critical hit occured */
426 if (hit < (275.0-25.0*skill)*(1.0+0.5*Rand())) return;
428 ncrit = 1.0 + hit/(500.0+100.0*Rand());
429 proutn("***CRITICAL HIT--");
430 /* Select devices and cause damage */
431 for (l = 1; l <= ncrit && l <= NDEVICES; l++) {
433 j = NDEVICES*Rand()+1.0;
434 /* Cheat to prevent shuttle damage unless on ship */
435 } while (game.damage[j] < 0.0 || (j == DSHUTTL && iscraft != 1) ||
438 extradm = (hit*damfac)/(ncrit*(75.0+25.0*Rand()));
439 game.damage[j] += extradm;
441 for (ll=2; ll<=l && j != cdam[ll-1]; ll++) ;
450 if (game.damage[DSHIELD] && shldup) {
451 prout("***Shields knocked down.");
457 /* k == 0 forces use of phasers in an attack */
458 int percent, ihurt=0, l, i=0, jx, jy, iquad, itflag;
459 int atackd = 0, attempt = 0;
461 double pfac, dustfac, hitmax=0.0, hittot=0.0, chgfac=1.0, r;
466 if (idebug) prout("ATTACK!");
469 if (ithere) movetho();
471 if (neutz) { /* The one chance not to be attacked */
475 if ((((comhere || ishere) && (justin == 0)) || skill == 5)&&(k!=0)) movcom();
476 if (nenhere==0 || (nenhere==1 && iqhere && iqengry==0)) return;
478 if (shldchg == 1) chgfac = 0.25+0.5*Rand();
480 if (skill <= 2) i = 2;
481 for (l=1; l <= nenhere; l++) {
482 if (game.kpower[l] < 0) continue; /* too weak to attack */
483 /* compute hit strength and diminsh shield power */
485 /* Increase chance of photon torpedos if docked or enemy energy low */
486 if (condit == IHDOCKED) r *= 0.25;
487 if (game.kpower[l] < 500) r *= 0.25;
490 iquad = game.quad[jx][jy];
491 if (iquad==IHT || (iquad==IHQUEST && !iqengry)) continue;
492 itflag = (iquad == IHK && r > 0.0005) || k == 0 ||
493 (iquad==IHC && r > 0.015) ||
494 (iquad==IHR && r > 0.3) ||
495 (iquad==IHS && r > 0.07) ||
496 (iquad==IHQUEST && r > 0.05);
498 /* Enemy uses phasers */
499 if (condit == IHDOCKED) continue; /* Don't waste the effort! */
500 attempt = 1; /* Attempt to attack */
501 dustfac = 0.8+0.05*Rand();
502 hit = game.kpower[l]*pow(dustfac,game.kavgd[l]);
503 game.kpower[l] *= 0.75;
505 else { /* Enemy used photon torpedo */
506 double course = 1.90985*atan2((double)secty-jy, (double)jx-sectx);
508 proutn("***TORPEDO INCOMING");
509 if (game.damage[DSRSENS] <= 0.0) {
511 crmena(0, iquad, i, jx, jy);
515 r = (Rand()+Rand())*0.5 -0.5;
516 r += 0.002*game.kpower[l]*r;
517 torpedo(course, r, jx, jy, &hit, 0, 1, 1);
518 if (game.state.remkl==0) finish(FWON); /* Klingons did themselves in! */
519 if (game.state.galaxy[quadx][quady] == 1000 ||
520 alldone) return; /* Supernova or finished */
521 if (hit == 0) continue;
523 if (shldup != 0 || shldchg != 0 || condit==IHDOCKED) {
524 /* shields will take hits */
525 double absorb, hitsh, propor = pfac*shield*(condit==IHDOCKED ? 2.1 : 1.0);
526 if(propor < 0.1) propor = 0.1;
527 hitsh = propor*chgfac*hit+1.0;
530 if (absorb > shield) absorb = shield;
533 if (condit==IHDOCKED) dock(0);
534 if (propor > 0.1 && hit < 0.005*energy) continue;
536 /* It's a hit -- print out hit size */
537 atackd = 1; /* We weren't going to check casualties, etc. if
538 shields were down for some strange reason. This
539 doesn't make any sense, so I've fixed it */
541 proutn("%d unit hit", (int)hit);
542 if ((game.damage[DSRSENS] > 0 && itflag) || skill <= 2) {
546 if (game.damage[DSRSENS] <= 0.0 && itflag) {
548 crmena(0, iquad, i, jx, jy);
551 /* Decide if hit is critical */
552 if (hit > hitmax) hitmax = hit;
555 prout("Hit %g energy %g", hit, energy);
557 if (condit==IHDOCKED) dock(0);
560 /* Returning home upon your shield, not with it... */
564 if (attempt == 0 && condit == IHDOCKED)
565 prout("***Enemies decide against attacking your ship.");
566 if (atackd == 0) return;
567 percent = 100.0*pfac*shield+0.5;
569 /* Shields fully protect ship */
570 proutn("Enemy attack reduces shield strength to ");
573 /* Print message if starship suffered hit(s) */
575 proutn("Energy left %2d shields ", (int)energy);
576 if (shldup) proutn("up ");
577 else if (game.damage[DSHIELD] == 0) proutn("down ");
578 else proutn("damaged, ");
580 prout("%d%%, torpedoes left %d", percent, torps);
581 /* Check if anyone was hurt */
582 if (hitmax >= 200 || hittot >= 500) {
583 int icas= hittot*Rand()*0.015;
586 prout("Mc Coy- \"Sickbay to bridge. We suffered %d casualties", icas);
587 prout(" in that last attack.\"");
591 /* After attack, reset average distance to enemies */
592 for (l = 1; l <= nenhere; l++)
593 game.kavgd[l] = game.kdist[l];
598 void deadkl(int ix, int iy, int type, int ixx, int iyy) {
599 /* Added ixx and iyy allow enemy to "move" before dying */
604 crmena(1, type, 2, ixx, iyy);
605 /* Decide what kind of enemy it is and update approriately */
607 /* chalk up a Romulan */
608 game.state.newstuf[quadx][quady] -= 10;
611 game.state.nromrem--;
613 else if (type == IHT) {
614 /* Killed a Tholian */
617 else if (type == IHQUEST) {
618 /* Killed a Thingy */
619 iqhere=iqengry=thingx=thingy=0;
622 /* Some type of a Klingon */
623 game.state.galaxy[quadx][quady] -= 100;
629 for (i=1; i<=game.state.remcom; i++)
630 if (game.state.cx[i]==quadx && game.state.cy[i]==quady) break;
631 game.state.cx[i] = game.state.cx[game.state.remcom];
632 game.state.cy[i] = game.state.cy[game.state.remcom];
633 game.state.cx[game.state.remcom] = 0;
634 game.state.cy[game.state.remcom] = 0;
636 game.future[FTBEAM] = 1e30;
637 if (game.state.remcom != 0)
638 game.future[FTBEAM] = game.state.date + expran(1.0*incom/game.state.remcom);
645 game.state.nscrem = ishere = game.state.isx = game.state.isy = isatb = iscate = 0;
646 game.state.nsckill = 1;
647 game.future[FSCMOVE] = game.future[FSCDBAS] = 1e30;
652 /* For each kind of enemy, finish message to player */
653 prout(" destroyed.");
654 game.quad[ix][iy] = IHDOT;
655 if (game.state.remkl==0) return;
657 game.state.remtime = game.state.remres/(game.state.remkl + 4*game.state.remcom);
659 /* Remove enemy ship from arrays describing local conditions */
660 if (game.future[FCDBAS] < 1e30 && batx==quadx && baty==quady && type==IHC)
661 game.future[FCDBAS] = 1e30;
662 for (i=1; i<=nenhere; i++)
663 if (game.kx[i]==ix && game.ky[i]==iy) break;
666 for (j=i; j<=nenhere; j++) {
667 game.kx[j] = game.kx[j+1];
668 game.ky[j] = game.ky[j+1];
669 game.kpower[j] = game.kpower[j+1];
670 game.kavgd[j] = game.kdist[j] = game.kdist[j+1];
673 game.kx[nenhere+1] = 0;
674 game.ky[nenhere+1] = 0;
675 game.kdist[nenhere+1] = 0;
676 game.kavgd[nenhere+1] = 0;
677 game.kpower[nenhere+1] = 0;
681 static int targetcheck(double x, double y, double *course) {
683 /* Return TRUE if target is invalid */
684 if (x < 1.0 || x > 10.0 || y < 1.0 || y > 10.0) {
688 deltx = 0.1*(y - secty);
689 delty = 0.1*(sectx - x);
690 if (deltx==0 && delty== 0) {
692 prout("Spock- \"Bridge to sickbay. Dr. McCoy,");
693 prout(" I recommend an immediate review of");
694 prout(" the Captain's psychological profile.\"");
698 *course = 1.90985932*atan2(deltx, delty);
703 double targ[4][3], course[4];
705 int key, n, i, osuabor;
709 if (game.damage[DPHOTON]) {
710 prout("Photon tubes damaged.");
715 prout("No torpedoes left.");
721 if (key == IHALPHA) {
725 else if (key == IHEOL) {
726 prout("%d torpedoes left.", torps);
727 proutn("Number of torpedoes to fire- ");
730 else /* key == IHREAL */ {
732 if (n <= 0) { /* abort command */
738 prout("Maximum of 3 torpedoes per burst.");
742 if (n <= torps) break;
747 for (i = 1; i <= n; i++) {
749 if (i==1 && key == IHEOL) {
750 break; /* we will try prompting */
752 if (i==2 && key == IHEOL) {
753 /* direct all torpedoes at one target */
755 targ[i][1] = targ[1][1];
756 targ[i][2] = targ[1][2];
757 course[i] = course[1];
773 if (targetcheck(targ[i][1], targ[i][2], &course[i])) return;
776 if (i == 1 && key == IHEOL) {
777 /* prompt for each one */
778 for (i = 1; i <= n; i++) {
779 proutn("Target sector for torpedo number %d- ", i);
793 if (targetcheck(targ[i][1], targ[i][2], &course[i])) return;
797 /* Loop for moving <n> torpedoes */
799 for (i = 1; i <= n && !osuabor; i++) {
800 if (condit != IHDOCKED) torps--;
801 r = (Rand()+Rand())*0.5 -0.5;
802 if (fabs(r) >= 0.47) {
804 r = (Rand()+1.2) * r;
806 prouts("***TORPEDO NUMBER %d MISFIRES", i);
808 else prouts("***TORPEDO MISFIRES.");
811 prout(" Remainder of burst aborted.");
814 prout("***Photon tubes damaged by misfire.");
815 game.damage[DPHOTON] = damfac*(1.0+2.0*Rand());
819 if (shldup || condit == IHDOCKED) r *= 1.0 + 0.0001*shield;
820 torpedo(course[i], r, sectx, secty, &dummy, 0, i, n);
821 if (alldone || game.state.galaxy[quadx][quady]==1000) return;
823 if (game.state.remkl==0) finish(FWON);
828 static void overheat(double rpow) {
830 double chekbrn = (rpow-1500.)*0.00038;
831 if (Rand() <= chekbrn) {
832 prout("Weapons officer Sulu- \"Phasers overheated, sir.\"");
833 game.damage[DPHASER] = damfac*(1.0 + Rand()) * (1.0+chekbrn);
838 static int checkshctrl(double rpow) {
844 prout("Shields lowered.");
847 /* Something bad has happened */
848 prouts("***RED ALERT! RED ALERT!");
850 hit = rpow*shield/inshld;
851 energy -= rpow+hit*0.8;
854 prouts("Sulu- \"Captain! Shield malf***********************\"");
860 prouts("Sulu- \"Captain! Shield malfunction! Phaser fire contained!\"");
862 prout("Lt. Uhura- \"Sir, all decks reporting damage.\"");
863 icas = hit*Rand()*0.012;
868 prout("McCoy to bridge- \"Severe radiation burns, Jim.");
869 prout(" %d casualties so far.\"", icas);
873 prout("Phaser energy dispersed by shields.");
874 prout("Enemy unaffected.");
881 double hits[21], rpow=0, extra, powrem, over, temp;
882 int kz = 0, k=1, i, irec=0; /* Cheating inhibitor */
883 int ifast=0, no=0, ipoop=1, msgflag = 1;
884 enum {NOTSET, MANUAL, FORCEMAN, AUTOMATIC} automode = NOTSET;
888 /* SR sensors and Computer */
889 if (game.damage[DSRSENS]+game.damage[DCOMPTR] > 0) ipoop = 0;
890 if (condit == IHDOCKED) {
891 prout("Phasers can't be fired through base shields.");
895 if (game.damage[DPHASER] != 0) {
896 prout("Phaser control damaged.");
901 if (game.damage[DSHCTRL]) {
902 prout("High speed shield control damaged.");
906 if (energy <= 200.0) {
907 prout("Insufficient energy to activate high-speed shield control.");
911 prout("Weapons Officer Sulu- \"High-speed shield control enabled, sir.\"");
915 /* Original code so convoluted, I re-did it all */
916 while (automode==NOTSET) {
918 if (key == IHALPHA) {
919 if (isit("manual")) {
921 prout("There is no enemy present to select.");
931 else if (isit("automatic")) {
932 if ((!ipoop) && nenhere != 0) {
937 prout("Energy will be expended into space.");
938 automode = AUTOMATIC;
942 else if (isit("no")) {
950 else if (key == IHREAL) {
952 prout("Energy will be expended into space.");
953 automode = AUTOMATIC;
958 automode = AUTOMATIC;
963 prout("Energy will be expended into space.");
964 automode = AUTOMATIC;
969 proutn("Manual or automatic? ");
975 if (key == IHALPHA && isit("no")) {
979 if (key != IHREAL && nenhere != 0) {
980 prout("Phasers locked on target. Energy available: %.2f",
981 ifast?energy-200.0:energy,1,2);
986 if (!kz) for (i = 1; i <= nenhere; i++)
987 irec+=fabs(game.kpower[i])/(PHASEFAC*pow(0.90,game.kdist[i]))*
988 (1.01+0.05*Rand()) + 1.0;
990 proutn("(%d) units required. ", irec);
992 proutn("Units to fire= ");
994 if (key!=IHREAL) return;
996 if (rpow > (ifast?energy-200:energy)) {
997 proutn("Energy available= %.2f",
998 ifast?energy-200:energy);
1002 } while (rpow > (ifast?energy-200:energy));
1008 if ((key=scan()) == IHALPHA && isit("no")) {
1012 energy -= 200; /* Go and do it! */
1013 if (checkshctrl(rpow)) return;
1021 for (i = 1; i <= nenhere; i++) {
1023 if (powrem <= 0) continue;
1024 hits[i] = fabs(game.kpower[i])/(PHASEFAC*pow(0.90,game.kdist[i]));
1025 over = (0.01 + 0.05*Rand())*hits[i];
1027 powrem -= hits[i] + over;
1028 if (powrem <= 0 && temp < hits[i]) hits[i] = temp;
1029 if (powrem <= 0) over = 0.0;
1032 if (powrem > 0.0) extra += powrem;
1036 if (extra > 0 && alldone == 0) {
1038 proutn("*** Tholian web absorbs ");
1039 if (nenhere>0) proutn("excess ");
1040 prout("phaser energy.");
1043 prout("%d expended on empty space.", (int)extra);
1051 if (game.damage[DCOMPTR]!=0)
1052 prout("Battle comuter damaged, manual file only.");
1055 prouts("---WORKING---");
1057 prout("Short-range-sensors-damaged");
1058 prout("Insufficient-data-for-automatic-phaser-fire");
1059 prout("Manual-fire-must-be-used");
1064 for (k = 1; k <= nenhere;) {
1065 int ii = game.kx[k], jj = game.ky[k];
1066 int ienm = game.quad[ii][jj];
1068 proutn("Energy available= %.2f",
1069 energy-.006-(ifast?200:0));
1074 if (game.damage[DSRSENS] && !(abs(sectx-ii) < 2 && abs(secty-jj) < 2) &&
1075 (ienm == IHC || ienm == IHS)) {
1077 prout(" can't be located without short range scan.");
1080 hits[k] = 0; /* prevent overflow -- thanks to Alexei Voitenko */
1086 if (ipoop && k > kz)
1087 irec=(fabs(game.kpower[k])/(PHASEFAC*pow(0.9,game.kdist[k])))*
1088 (1.01+0.05*Rand()) + 1.0;
1091 if (game.damage[DCOMPTR]==0) proutn("%d", irec);
1094 proutn("units to fire at ");
1095 crmena(0, ienm, 2, ii, jj);
1099 if (key == IHALPHA && isit("no")) {
1104 if (key == IHALPHA) {
1109 if (k==1) { /* Let me say I'm baffled by this */
1121 /* If total requested is too much, inform and start over */
1123 if (rpow > (ifast?energy-200:energy)) {
1124 prout("Available energy exceeded -- try again.");
1128 key = scan(); /* scan for next value */
1132 /* zero energy -- abort */
1136 if (key == IHALPHA && isit("no")) {
1143 if (checkshctrl(rpow)) return;
1147 case NOTSET:; /* avoid gcc warning */
1149 /* Say shield raised or malfunction, if necessary */
1150 if (alldone) return;
1154 if (Rand() >= 0.99) {
1155 prout("Sulu- \"Sir, the high-speed shield control has malfunctioned . . .");
1156 prouts(" CLICK CLICK POP . . .");
1157 prout(" No response, sir!");
1161 prout("Shields raised.");
1169 void hittem(double *hits) {
1170 double kp, kpow, wham, hit, dustfac, kpini;
1171 int nenhr2=nenhere, k=1, kk=1, ii, jj, ienm;
1175 for (; k <= nenhr2; k++, kk++) {
1176 if ((wham = hits[k])==0) continue;
1177 dustfac = 0.9 + 0.01*Rand();
1178 hit = wham*pow(dustfac,game.kdist[kk]);
1179 kpini = game.kpower[kk];
1181 if (PHASEFAC*hit < kp) kp = PHASEFAC*hit;
1182 game.kpower[kk] -= (game.kpower[kk] < 0 ? -kp: kp);
1183 kpow = game.kpower[kk];
1187 if (game.damage[DSRSENS]==0)
1189 proutn("%d unit hit on ", (int)hit);
1192 proutn("Very small hit on ");
1193 ienm = game.quad[ii][jj];
1194 if (ienm==IHQUEST) iqengry=1;
1195 crmena(0,ienm,2,ii,jj);
1198 deadkl(ii, jj, ienm, ii, jj);
1199 if (game.state.remkl==0) finish(FWON);
1200 if (alldone) return;
1201 kk--; /* don't do the increment */
1203 else /* decide whether or not to emasculate klingon */
1204 if (kpow > 0 && Rand() >= 0.9 &&
1205 kpow <= ((0.4 + 0.4*Rand())*kpini)) {
1206 prout("***Mr. Spock- \"Captain, the vessel at ",
1207 cramlc(sector,ii,jj));
1208 prout(" has just lost its firepower.\"");
1209 game.kpower[kk] = -kpow;