6 enum {NONE, SHUP, SHDN, NRG} action = NONE;
10 if (i == 2) action = SHUP;
18 if (game.damage[DSHIELD]) {
19 prout("Shields damaged and down.");
24 else if (isit("down"))
29 proutn("Do you wish to change shield energy? ");
31 proutn("Energy to transfer to shields- ");
34 else if (game.damage[DSHIELD]) {
35 prout("Shields damaged and down.");
39 proutn("Shields are up. Do you want them down? ");
40 if (ja()) action = SHDN;
47 proutn("Shields are down. Do you want them up? ");
48 if (ja()) action = SHUP;
57 case SHUP: /* raise shields */
59 prout("Shields already up.");
64 if (condit != IHDOCKED) energy -= 50.0;
65 prout("Shields raised.");
68 prout("Shields raising uses up last of energy.");
76 prout("Shields already down.");
81 prout("Shields lowered.");
85 while (scan() != IHREAL) {
87 proutn("Energy to transfer to shields- ");
90 if (aaitem==0) return;
91 if (aaitem > energy) {
92 prout("Insufficient ship energy.");
96 if (shield+aaitem >= inshld) {
97 prout("Shield energy maximized.");
98 if (shield+aaitem > inshld) {
99 prout("Excess energy requested returned to ship energy");
101 energy -= inshld-shield;
105 if (aaitem < 0.0 && energy-aaitem > inenrg) {
106 /* Prevent shield drain loophole */
108 prout("Engineering to bridge--");
109 prout(" Scott here. Power circuit problem, Captain.");
110 prout(" I can't drain the shields.");
114 if (shield+aaitem < 0) {
115 prout("All shield energy transferred to ship.");
120 proutn("Scotty- \"");
122 prout("Transferring energy to shields.\"");
124 prout("Draining energy from shields.\"");
128 case NONE:; /* avoid gcc warning */
132 void ram(int ibumpd, int ienm, int ix, int iy) {
133 double type = 1.0, extradm;
136 prouts("***RED ALERT! RED ALERT!");
138 prout("***COLLISION IMMINENT.");
143 case IHR: type = 1.5; break;
144 case IHC: type = 2.0; break;
145 case IHS: type = 2.5; break;
146 case IHT: type = 0.5; break;
147 case IHQUEST: type = 4.0; break;
149 proutn(ibumpd ? " rammed by " : " rams ");
150 crmena(0, ienm, 2, ix, iy);
151 if (ibumpd) proutn(" (original position)");
153 deadkl(ix, iy, ienm, sectx, secty);
156 prout(" heavily damaged.");
157 icas = 10.0+20.0*Rand();
158 prout("***Sickbay reports %d casualties", icas);
160 for (l=1; l <= NDEVICES; l++) {
161 if (l == DDRAY) continue; // Don't damage deathray
162 if (game.damage[l] < 0) continue;
163 extradm = (10.0*type*Rand()+1.0)*damfac;
164 game.damage[l] += Time + extradm; /* Damage for at least time of travel! */
167 if (game.state.remkl) {
175 void torpedo(double course, double r, int inx, int iny, double *hit, int wait, int i, int n) {
176 int l, iquad=0, ix=0, iy=0, jx=0, jy=0, shoved=0, ll;
178 double ac=course + 0.25*r;
179 double angle = (15.0-ac)*0.5235988;
180 double bullseye = (15.0 - course)*0.5235988;
181 double deltax=-sin(angle), deltay=cos(angle), x=inx, y=iny, bigger;
182 double ang, temp, xx, yy, kp, h1;
184 bigger = fabs(deltax);
185 if (fabs(deltay) > bigger) bigger = fabs(deltay);
188 if (game.damage[DSRSENS]==0 || condit==IHDOCKED)
189 setwnd(SRSCAN_WINDOW);
191 setwnd(LOWER_WINDOW);
192 /* Loop to move a single torpedo */
193 for (l=1; l <= 15; l++) {
196 if (ix < 1 || ix > 10) break;
199 if (iy < 1 || iy > 10) break;
200 iquad=game.quad[ix][iy];
201 tracktorpedo(x, y, ix, iy, wait, l, i, n, iquad);
203 if (iquad==IHDOT) continue;
205 setwnd(LOWER_WINDOW);
207 case IHE: /* Hit our ship */
210 proutn("Torpedo hits ");
213 *hit = 700.0 + 100.0*Rand() -
214 1000.0*sqrt(square(ix-inx)+square(iy-iny))*
215 fabs(sin(bullseye-angle));
217 newcnd(); /* we're blown out of dock */
218 /* We may be displaced. */
219 if (landed==1 || condit==IHDOCKED) return; /* Cheat if on a planet */
220 ang = angle + 2.5*(Rand()-0.5);
221 temp = fabs(sin(ang));
222 if (fabs(cos(ang)) > temp) temp = fabs(cos(ang));
227 if (jx<1 || jx>10 || jy<1 ||jy > 10) return;
228 if (game.quad[jx][jy]==IHBLANK) {
232 if (game.quad[jx][jy]!=IHDOT) {
233 /* can't move into object */
242 case IHC: /* Hit a commander */
244 if (Rand() <= 0.05) {
245 crmena(1, iquad, 2, ix, iy);
246 prout(" uses anti-photon device;");
247 prout(" torpedo neutralized.");
250 case IHR: /* Hit a regular enemy */
253 for (ll=1; ll <= nenhere; ll++)
254 if (ix==game.kx[ll] && iy==game.ky[ll]) break;
255 kp = fabs(game.kpower[ll]);
256 h1 = 700.0 + 100.0*Rand() -
257 1000.0*sqrt(square(ix-inx)+square(iy-iny))*
258 fabs(sin(bullseye-angle));
260 if (kp < h1) h1 = kp;
261 game.kpower[ll] -= (game.kpower[ll]<0 ? -h1 : h1);
262 if (game.kpower[ll] == 0) {
263 deadkl(ix, iy, iquad, ix, iy);
266 crmena(1, iquad, 2, ix, iy);
267 /* If enemy damaged but not destroyed, try to displace */
268 ang = angle + 2.5*(Rand()-0.5);
269 temp = fabs(sin(ang));
270 if (fabs(cos(ang)) > temp) temp = fabs(cos(ang));
275 if (jx<1 || jx>10 || jy<1 ||jy > 10) {
276 prout(" damaged but not destroyed.");
279 if (game.quad[jx][jy]==IHBLANK) {
280 prout(" buffeted into black hole.");
281 deadkl(ix, iy, iquad, jx, jy);
284 if (game.quad[jx][jy]!=IHDOT) {
285 /* can't move into object */
286 prout(" damaged but not destroyed.");
289 proutn(" damaged--");
294 case IHB: /* Hit a base */
296 prout("***STARBASE DESTROYED..");
297 if (game.starch[quadx][quady] < 0) game.starch[quadx][quady] = 0;
298 for (ll=1; ll<=game.state.rembase; ll++) {
299 if (game.state.baseqx[ll]==quadx && game.state.baseqy[ll]==quady) {
300 game.state.baseqx[ll]=game.state.baseqx[game.state.rembase];
301 game.state.baseqy[ll]=game.state.baseqy[game.state.rembase];
305 game.quad[ix][iy]=IHDOT;
306 game.state.rembase--;
308 game.state.galaxy[quadx][quady] -= 10;
312 case IHP: /* Hit a planet */
313 crmena(1, iquad, 2, ix, iy);
314 prout(" destroyed.");
315 game.state.nplankl++;
316 game.state.newstuf[quadx][quady] -= 1;
317 DESTROY(&game.state.plnets[iplnet]);
320 game.quad[ix][iy] = IHDOT;
322 /* captain parishes on planet */
326 case IHSTAR: /* Hit a star */
331 crmena(1, IHSTAR, 2, ix, iy);
332 prout(" unaffected by photon blast.");
334 case IHQUEST: /* Hit a thingy */
335 if (Rand()>0.7) { // Used to be certain death
337 prouts("AAAAIIIIEEEEEEEEAAAAAAAAUUUUUGGGGGHHHHHHHHHHHH!!!");
339 prouts(" HACK! HACK! HACK! *CHOKE!* ");
341 proutn("Mr. Spock-");
342 prouts(" \"Fascinating!\"");
344 deadkl(ix, iy, iquad, ix, iy);
347 * Stas Sergeev added the possibility that
348 * you can shove the Thingy.
354 case IHBLANK: /* Black hole */
356 crmena(1, IHBLANK, 2, ix, iy);
357 prout(" swallows torpedo.");
359 case IHWEB: /* hit the web */
361 prout("***Torpedo absorbed by Tholian web.");
363 case IHT: /* Hit a Tholian */
364 h1 = 700.0 + 100.0*Rand() -
365 1000.0*sqrt(square(ix-inx)+square(iy-iny))*
366 fabs(sin(bullseye-angle));
369 game.quad[ix][iy] = IHDOT;
372 deadkl(ix, iy, iquad, ix, iy);
376 crmena(1, IHT, 2, ix, iy);
378 prout(" survives photon blast.");
381 prout(" disappears.");
382 game.quad[ix][iy] = IHWEB;
383 ithere = ithx = ithy = 0;
387 dropin(IHBLANK, &dum, &my);
391 default: /* Problem! */
393 proutn("Don't know how to handle collision with ");
394 crmena(1, iquad, 2, ix, iy);
400 if(curwnd!=LOWER_WINDOW) {
401 setwnd(LOWER_WINDOW);
404 game.quad[jx][jy]=iquad;
405 game.quad[ix][iy]=IHDOT;
406 prout(" displaced by blast to %s ", cramlc(sector, jx, jy));
407 for (ll=1; ll<=nenhere; ll++)
408 game.kdist[ll] = game.kavgd[ll] = sqrt(square(sectx-game.kx[ll])+square(secty-game.ky[ll]));
413 prout("Torpedo missed.");
417 static void fry(double hit) {
418 double ncrit, extradm;
419 int ktr=1, l, ll, j, cdam[NDEVICES+1];
421 /* a critical hit occured */
422 if (hit < (275.0-25.0*skill)*(1.0+0.5*Rand())) return;
424 ncrit = 1.0 + hit/(500.0+100.0*Rand());
425 proutn("***CRITICAL HIT--");
426 /* Select devices and cause damage */
427 for (l = 1; l <= ncrit && l <= NDEVICES; l++) {
429 j = NDEVICES*Rand()+1.0;
430 /* Cheat to prevent shuttle damage unless on ship */
431 } while (game.damage[j] < 0.0 || (j == DSHUTTL && iscraft != 1) ||
434 extradm = (hit*damfac)/(ncrit*(75.0+25.0*Rand()));
435 game.damage[j] += extradm;
437 for (ll=2; ll<=l && j != cdam[ll-1]; ll++) ;
446 if (game.damage[DSHIELD] && shldup) {
447 prout("***Shields knocked down.");
453 /* k == 0 forces use of phasers in an attack */
454 int percent, ihurt=0, l, i=0, jx, jy, iquad, itflag;
455 int atackd = 0, attempt = 0;
457 double pfac, dustfac, hitmax=0.0, hittot=0.0, chgfac=1.0, r;
462 if (idebug) prout("ATTACK!");
465 if (ithere) movetho();
467 if (neutz) { /* The one chance not to be attacked */
471 if ((((comhere || ishere) && (justin == 0)) || skill == 5)&&(k!=0)) movcom();
472 if (nenhere==0 || (nenhere==1 && iqhere && iqengry==0)) return;
474 if (shldchg == 1) chgfac = 0.25+0.5*Rand();
476 if (skill <= 2) i = 2;
477 for (l=1; l <= nenhere; l++) {
478 if (game.kpower[l] < 0) continue; /* too weak to attack */
479 /* compute hit strength and diminsh shield power */
481 /* Increase chance of photon torpedos if docked or enemy energy low */
482 if (condit == IHDOCKED) r *= 0.25;
483 if (game.kpower[l] < 500) r *= 0.25;
486 iquad = game.quad[jx][jy];
487 if (iquad==IHT || (iquad==IHQUEST && !iqengry)) continue;
488 itflag = (iquad == IHK && r > 0.0005) || k == 0 ||
489 (iquad==IHC && r > 0.015) ||
490 (iquad==IHR && r > 0.3) ||
491 (iquad==IHS && r > 0.07) ||
492 (iquad==IHQUEST && r > 0.05);
494 /* Enemy uses phasers */
495 if (condit == IHDOCKED) continue; /* Don't waste the effort! */
496 attempt = 1; /* Attempt to attack */
497 dustfac = 0.8+0.05*Rand();
498 hit = game.kpower[l]*pow(dustfac,game.kavgd[l]);
499 game.kpower[l] *= 0.75;
501 else { /* Enemy used photon torpedo */
502 double course = 1.90985*atan2((double)secty-jy, (double)jx-sectx);
504 proutn("***TORPEDO INCOMING");
505 if (game.damage[DSRSENS] <= 0.0) {
507 crmena(0, iquad, i, jx, jy);
511 r = (Rand()+Rand())*0.5 -0.5;
512 r += 0.002*game.kpower[l]*r;
513 torpedo(course, r, jx, jy, &hit, 0, 1, 1);
514 if (game.state.remkl==0) finish(FWON); /* Klingons did themselves in! */
515 if (game.state.galaxy[quadx][quady] == 1000 ||
516 alldone) return; /* Supernova or finished */
517 if (hit == 0) continue;
519 if (shldup != 0 || shldchg != 0 || condit==IHDOCKED) {
520 /* shields will take hits */
521 double absorb, hitsh, propor = pfac*shield*(condit==IHDOCKED ? 2.1 : 1.0);
522 if(propor < 0.1) propor = 0.1;
523 hitsh = propor*chgfac*hit+1.0;
526 if (absorb > shield) absorb = shield;
529 if (condit==IHDOCKED) dock(0);
530 if (propor > 0.1 && hit < 0.005*energy) continue;
532 /* It's a hit -- print out hit size */
533 atackd = 1; /* We weren't going to check casualties, etc. if
534 shields were down for some strange reason. This
535 doesn't make any sense, so I've fixed it */
537 proutn("%d unit hit", (int)hit);
538 if ((game.damage[DSRSENS] > 0 && itflag) || skill <= 2) {
542 if (game.damage[DSRSENS] <= 0.0 && itflag) {
544 crmena(0, iquad, i, jx, jy);
547 /* Decide if hit is critical */
548 if (hit > hitmax) hitmax = hit;
551 prout("Hit %g energy %g", hit, energy);
553 if (condit==IHDOCKED) dock(0);
556 /* Returning home upon your shield, not with it... */
560 if (attempt == 0 && condit == IHDOCKED)
561 prout("***Enemies decide against attacking your ship.");
562 if (atackd == 0) return;
563 percent = 100.0*pfac*shield+0.5;
565 /* Shields fully protect ship */
566 proutn("Enemy attack reduces shield strength to ");
569 /* Print message if starship suffered hit(s) */
571 proutn("Energy left %2d shields ", (int)energy);
572 if (shldup) proutn("up ");
573 else if (game.damage[DSHIELD] == 0) proutn("down ");
574 else proutn("damaged, ");
576 prout("%d%%, torpedoes left %d", percent, torps);
577 /* Check if anyone was hurt */
578 if (hitmax >= 200 || hittot >= 500) {
579 int icas= hittot*Rand()*0.015;
582 prout("Mc Coy- \"Sickbay to bridge. We suffered %d casualties", icas);
583 prout(" in that last attack.\"");
587 /* After attack, reset average distance to enemies */
588 for (l = 1; l <= nenhere; l++)
589 game.kavgd[l] = game.kdist[l];
594 void deadkl(int ix, int iy, int type, int ixx, int iyy) {
595 /* Added ixx and iyy allow enemy to "move" before dying */
600 crmena(1, type, 2, ixx, iyy);
601 /* Decide what kind of enemy it is and update approriately */
603 /* chalk up a Romulan */
604 game.state.newstuf[quadx][quady] -= 10;
607 game.state.nromrem--;
609 else if (type == IHT) {
610 /* Killed a Tholian */
613 else if (type == IHQUEST) {
614 /* Killed a Thingy */
615 iqhere=iqengry=thingx=thingy=0;
618 /* Some type of a Klingon */
619 game.state.galaxy[quadx][quady] -= 100;
625 for (i=1; i<=game.state.remcom; i++)
626 if (game.state.cx[i]==quadx && game.state.cy[i]==quady) break;
627 game.state.cx[i] = game.state.cx[game.state.remcom];
628 game.state.cy[i] = game.state.cy[game.state.remcom];
629 game.state.cx[game.state.remcom] = 0;
630 game.state.cy[game.state.remcom] = 0;
632 game.future[FTBEAM] = 1e30;
633 if (game.state.remcom != 0)
634 game.future[FTBEAM] = game.state.date + expran(1.0*incom/game.state.remcom);
641 game.state.nscrem = ishere = game.state.isx = game.state.isy = isatb = iscate = 0;
642 game.state.nsckill = 1;
643 game.future[FSCMOVE] = game.future[FSCDBAS] = 1e30;
648 /* For each kind of enemy, finish message to player */
649 prout(" destroyed.");
650 game.quad[ix][iy] = IHDOT;
651 if (game.state.remkl==0) return;
653 game.state.remtime = game.state.remres/(game.state.remkl + 4*game.state.remcom);
655 /* Remove enemy ship from arrays describing local conditions */
656 if (game.future[FCDBAS] < 1e30 && batx==quadx && baty==quady && type==IHC)
657 game.future[FCDBAS] = 1e30;
658 for (i=1; i<=nenhere; i++)
659 if (game.kx[i]==ix && game.ky[i]==iy) break;
662 for (j=i; j<=nenhere; j++) {
663 game.kx[j] = game.kx[j+1];
664 game.ky[j] = game.ky[j+1];
665 game.kpower[j] = game.kpower[j+1];
666 game.kavgd[j] = game.kdist[j] = game.kdist[j+1];
669 game.kx[nenhere+1] = 0;
670 game.ky[nenhere+1] = 0;
671 game.kdist[nenhere+1] = 0;
672 game.kavgd[nenhere+1] = 0;
673 game.kpower[nenhere+1] = 0;
677 static int targetcheck(double x, double y, double *course) {
679 /* Return TRUE if target is invalid */
680 if (x < 1.0 || x > 10.0 || y < 1.0 || y > 10.0) {
684 deltx = 0.1*(y - secty);
685 delty = 0.1*(sectx - x);
686 if (deltx==0 && delty== 0) {
688 prout("Spock- \"Bridge to sickbay. Dr. McCoy,");
689 prout(" I recommend an immediate review of");
690 prout(" the Captain's psychological profile.\"");
694 *course = 1.90985932*atan2(deltx, delty);
699 double targ[4][3], course[4];
701 int key, n, i, osuabor;
705 if (game.damage[DPHOTON]) {
706 prout("Photon tubes damaged.");
711 prout("No torpedoes left.");
717 if (key == IHALPHA) {
721 else if (key == IHEOL) {
722 prout("%d torpedoes left.", torps);
723 proutn("Number of torpedoes to fire- ");
726 else /* key == IHREAL */ {
728 if (n <= 0) { /* abort command */
734 prout("Maximum of 3 torpedoes per burst.");
738 if (n <= torps) break;
743 for (i = 1; i <= n; i++) {
745 if (i==1 && key == IHEOL) {
746 break; /* we will try prompting */
748 if (i==2 && key == IHEOL) {
749 /* direct all torpedoes at one target */
751 targ[i][1] = targ[1][1];
752 targ[i][2] = targ[1][2];
753 course[i] = course[1];
769 if (targetcheck(targ[i][1], targ[i][2], &course[i])) return;
772 if (i == 1 && key == IHEOL) {
773 /* prompt for each one */
774 for (i = 1; i <= n; i++) {
775 proutn("Target sector for torpedo number %d- ", i);
789 if (targetcheck(targ[i][1], targ[i][2], &course[i])) return;
793 /* Loop for moving <n> torpedoes */
795 for (i = 1; i <= n && !osuabor; i++) {
796 if (condit != IHDOCKED) torps--;
797 r = (Rand()+Rand())*0.5 -0.5;
798 if (fabs(r) >= 0.47) {
800 r = (Rand()+1.2) * r;
802 prouts("***TORPEDO NUMBER %d MISFIRES", i);
804 else prouts("***TORPEDO MISFIRES.");
807 prout(" Remainder of burst aborted.");
810 prout("***Photon tubes damaged by misfire.");
811 game.damage[DPHOTON] = damfac*(1.0+2.0*Rand());
815 if (shldup || condit == IHDOCKED) r *= 1.0 + 0.0001*shield;
816 torpedo(course[i], r, sectx, secty, &dummy, 0, i, n);
817 if (alldone || game.state.galaxy[quadx][quady]==1000) return;
819 if (game.state.remkl==0) finish(FWON);
824 static void overheat(double rpow) {
826 double chekbrn = (rpow-1500.)*0.00038;
827 if (Rand() <= chekbrn) {
828 prout("Weapons officer Sulu- \"Phasers overheated, sir.\"");
829 game.damage[DPHASER] = damfac*(1.0 + Rand()) * (1.0+chekbrn);
834 static int checkshctrl(double rpow) {
840 prout("Shields lowered.");
843 /* Something bad has happened */
844 prouts("***RED ALERT! RED ALERT!");
846 hit = rpow*shield/inshld;
847 energy -= rpow+hit*0.8;
850 prouts("Sulu- \"Captain! Shield malf***********************\"");
856 prouts("Sulu- \"Captain! Shield malfunction! Phaser fire contained!\"");
858 prout("Lt. Uhura- \"Sir, all decks reporting damage.\"");
859 icas = hit*Rand()*0.012;
864 prout("McCoy to bridge- \"Severe radiation burns, Jim.");
865 prout(" %d casualties so far.\"", icas);
869 prout("Phaser energy dispersed by shields.");
870 prout("Enemy unaffected.");
877 double hits[21], rpow=0, extra, powrem, over, temp;
878 int kz = 0, k=1, i, irec=0; /* Cheating inhibitor */
879 int ifast=0, no=0, ipoop=1, msgflag = 1;
880 enum {NOTSET, MANUAL, FORCEMAN, AUTOMATIC} automode = NOTSET;
884 /* SR sensors and Computer */
885 if (game.damage[DSRSENS]+game.damage[DCOMPTR] > 0) ipoop = 0;
886 if (condit == IHDOCKED) {
887 prout("Phasers can't be fired through base shields.");
891 if (game.damage[DPHASER] != 0) {
892 prout("Phaser control damaged.");
897 if (game.damage[DSHCTRL]) {
898 prout("High speed shield control damaged.");
902 if (energy <= 200.0) {
903 prout("Insufficient energy to activate high-speed shield control.");
907 prout("Weapons Officer Sulu- \"High-speed shield control enabled, sir.\"");
911 /* Original code so convoluted, I re-did it all */
912 while (automode==NOTSET) {
914 if (key == IHALPHA) {
915 if (isit("manual")) {
917 prout("There is no enemy present to select.");
927 else if (isit("automatic")) {
928 if ((!ipoop) && nenhere != 0) {
933 prout("Energy will be expended into space.");
934 automode = AUTOMATIC;
938 else if (isit("no")) {
946 else if (key == IHREAL) {
948 prout("Energy will be expended into space.");
949 automode = AUTOMATIC;
954 automode = AUTOMATIC;
959 prout("Energy will be expended into space.");
960 automode = AUTOMATIC;
965 proutn("Manual or automatic? ");
971 if (key == IHALPHA && isit("no")) {
975 if (key != IHREAL && nenhere != 0) {
976 prout("Phasers locked on target. Energy available: %.2f",
977 ifast?energy-200.0:energy,1,2);
982 if (!kz) for (i = 1; i <= nenhere; i++)
983 irec+=fabs(game.kpower[i])/(PHASEFAC*pow(0.90,game.kdist[i]))*
984 (1.01+0.05*Rand()) + 1.0;
986 proutn("(%d) units required. ", irec);
988 proutn("Units to fire= ");
990 if (key!=IHREAL) return;
992 if (rpow > (ifast?energy-200:energy)) {
993 proutn("Energy available= %.2f",
994 ifast?energy-200:energy);
998 } while (rpow > (ifast?energy-200:energy));
1004 if ((key=scan()) == IHALPHA && isit("no")) {
1008 energy -= 200; /* Go and do it! */
1009 if (checkshctrl(rpow)) return;
1017 for (i = 1; i <= nenhere; i++) {
1019 if (powrem <= 0) continue;
1020 hits[i] = fabs(game.kpower[i])/(PHASEFAC*pow(0.90,game.kdist[i]));
1021 over = (0.01 + 0.05*Rand())*hits[i];
1023 powrem -= hits[i] + over;
1024 if (powrem <= 0 && temp < hits[i]) hits[i] = temp;
1025 if (powrem <= 0) over = 0.0;
1028 if (powrem > 0.0) extra += powrem;
1032 if (extra > 0 && alldone == 0) {
1034 proutn("*** Tholian web absorbs ");
1035 if (nenhere>0) proutn("excess ");
1036 prout("phaser energy.");
1039 prout("%d expended on empty space.", (int)extra);
1047 if (game.damage[DCOMPTR]!=0)
1048 prout("Battle comuter damaged, manual file only.");
1051 prouts("---WORKING---");
1053 prout("Short-range-sensors-damaged");
1054 prout("Insufficient-data-for-automatic-phaser-fire");
1055 prout("Manual-fire-must-be-used");
1060 for (k = 1; k <= nenhere;) {
1061 int ii = game.kx[k], jj = game.ky[k];
1062 int ienm = game.quad[ii][jj];
1064 proutn("Energy available= %.2f",
1065 energy-.006-(ifast?200:0));
1070 if (game.damage[DSRSENS] && !(abs(sectx-ii) < 2 && abs(secty-jj) < 2) &&
1071 (ienm == IHC || ienm == IHS)) {
1073 prout(" can't be located without short range scan.");
1076 hits[k] = 0; /* prevent overflow -- thanks to Alexei Voitenko */
1082 if (ipoop && k > kz)
1083 irec=(fabs(game.kpower[k])/(PHASEFAC*pow(0.9,game.kdist[k])))*
1084 (1.01+0.05*Rand()) + 1.0;
1087 if (game.damage[DCOMPTR]==0) proutn("%d", irec);
1090 proutn("units to fire at ");
1091 crmena(0, ienm, 2, ii, jj);
1095 if (key == IHALPHA && isit("no")) {
1100 if (key == IHALPHA) {
1105 if (k==1) { /* Let me say I'm baffled by this */
1117 /* If total requested is too much, inform and start over */
1119 if (rpow > (ifast?energy-200:energy)) {
1120 prout("Available energy exceeded -- try again.");
1124 key = scan(); /* scan for next value */
1128 /* zero energy -- abort */
1132 if (key == IHALPHA && isit("no")) {
1139 if (checkshctrl(rpow)) return;
1143 case NOTSET:; /* avoid gcc warning */
1145 /* Say shield raised or malfunction, if necessary */
1146 if (alldone) return;
1150 if (Rand() >= 0.99) {
1151 prout("Sulu- \"Sir, the high-speed shield control has malfunctioned . . .");
1152 prouts(" CLICK CLICK POP . . .");
1153 prout(" No response, sir!");
1157 prout("Shields raised.");
1165 void hittem(double *hits) {
1166 double kp, kpow, wham, hit, dustfac, kpini;
1167 int nenhr2=nenhere, k=1, kk=1, ii, jj, ienm;
1171 for (; k <= nenhr2; k++, kk++) {
1172 if ((wham = hits[k])==0) continue;
1173 dustfac = 0.9 + 0.01*Rand();
1174 hit = wham*pow(dustfac,game.kdist[kk]);
1175 kpini = game.kpower[kk];
1177 if (PHASEFAC*hit < kp) kp = PHASEFAC*hit;
1178 game.kpower[kk] -= (game.kpower[kk] < 0 ? -kp: kp);
1179 kpow = game.kpower[kk];
1183 if (game.damage[DSRSENS]==0)
1185 proutn("%d unit hit on ", (int)hit);
1188 proutn("Very small hit on ");
1189 ienm = game.quad[ii][jj];
1190 if (ienm==IHQUEST) iqengry=1;
1191 crmena(0,ienm,2,ii,jj);
1194 deadkl(ii, jj, ienm, ii, jj);
1195 if (game.state.remkl==0) finish(FWON);
1196 if (alldone) return;
1197 kk--; /* don't do the increment */
1199 else /* decide whether or not to emasculate klingon */
1200 if (kpow > 0 && Rand() >= 0.9 &&
1201 kpow <= ((0.4 + 0.4*Rand())*kpini)) {
1202 prout("***Mr. Spock- \"Captain, the vessel at ",
1203 cramlc(sector,ii,jj));
1204 prout(" has just lost its firepower.\"");
1205 game.kpower[kk] = -kpow;