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)
135 double type = 1.0, extradm;
138 prouts("***RED ALERT! RED ALERT!");
140 prout("***COLLISION IMMINENT.");
145 case IHR: type = 1.5; break;
146 case IHC: type = 2.0; break;
147 case IHS: type = 2.5; break;
148 case IHT: type = 0.5; break;
149 case IHQUEST: type = 4.0; break;
151 proutn(ibumpd ? " rammed by " : " rams ");
152 crmena(0, ienm, 2, ix, iy);
153 if (ibumpd) proutn(" (original position)");
155 deadkl(ix, iy, ienm, sectx, secty);
158 prout(" heavily damaged.");
159 icas = 10.0+20.0*Rand();
160 prout("***Sickbay reports %d casualties", icas);
162 for (l=0; l < NDEVICES; l++) {
164 continue; // Don't damage deathray
165 if (game.damage[l] < 0)
167 extradm = (10.0*type*Rand()+1.0)*damfac;
168 game.damage[l] += Time + extradm; /* Damage for at least time of travel! */
171 if (game.state.remkl) {
179 void torpedo(double course, double r, int inx, int iny, double *hit, int wait, int i, int n)
181 int l, iquad=0, ix=0, iy=0, jx=0, jy=0, shoved=0, ll;
183 double ac=course + 0.25*r;
184 double angle = (15.0-ac)*0.5235988;
185 double bullseye = (15.0 - course)*0.5235988;
186 double deltax=-sin(angle), deltay=cos(angle), x=inx, y=iny, bigger;
187 double ang, temp, xx, yy, kp, h1;
189 bigger = fabs(deltax);
190 if (fabs(deltay) > bigger) bigger = fabs(deltay);
193 if (game.damage[DSRSENS]==0 || condit==IHDOCKED)
194 setwnd(srscan_window);
196 setwnd(message_window);
197 /* Loop to move a single torpedo */
198 for (l=1; l <= 15; l++) {
201 if (ix < 1 || ix > QUADSIZE) break;
204 if (iy < 1 || iy > QUADSIZE) break;
205 iquad=game.quad[ix][iy];
206 tracktorpedo(x, y, ix, iy, wait, l, i, n, iquad);
208 if (iquad==IHDOT) continue;
210 setwnd(message_window);
211 skip(1); /* start new line after text track */
213 case IHE: /* Hit our ship */
216 proutn("Torpedo hits ");
219 *hit = 700.0 + 100.0*Rand() -
220 1000.0*sqrt(square(ix-inx)+square(iy-iny))*
221 fabs(sin(bullseye-angle));
223 newcnd(); /* we're blown out of dock */
224 /* We may be displaced. */
225 if (landed==1 || condit==IHDOCKED) return; /* Cheat if on a planet */
226 ang = angle + 2.5*(Rand()-0.5);
227 temp = fabs(sin(ang));
228 if (fabs(cos(ang)) > temp) temp = fabs(cos(ang));
233 if (jx<1 || jx>QUADSIZE || jy<1 ||jy > QUADSIZE) return;
234 if (game.quad[jx][jy]==IHBLANK) {
238 if (game.quad[jx][jy]!=IHDOT) {
239 /* can't move into object */
248 case IHC: /* Hit a commander */
250 if (Rand() <= 0.05) {
251 crmena(1, iquad, 2, ix, iy);
252 prout(" uses anti-photon device;");
253 prout(" torpedo neutralized.");
256 case IHR: /* Hit a regular enemy */
259 for (ll=1; ll <= nenhere; ll++)
260 if (ix==game.kx[ll] && iy==game.ky[ll]) break;
261 kp = fabs(game.kpower[ll]);
262 h1 = 700.0 + 100.0*Rand() -
263 1000.0*sqrt(square(ix-inx)+square(iy-iny))*
264 fabs(sin(bullseye-angle));
266 if (kp < h1) h1 = kp;
267 game.kpower[ll] -= (game.kpower[ll]<0 ? -h1 : h1);
268 if (game.kpower[ll] == 0) {
269 deadkl(ix, iy, iquad, ix, iy);
272 crmena(1, iquad, 2, ix, iy);
273 /* If enemy damaged but not destroyed, try to displace */
274 ang = angle + 2.5*(Rand()-0.5);
275 temp = fabs(sin(ang));
276 if (fabs(cos(ang)) > temp) temp = fabs(cos(ang));
281 if (jx<1 || jx>QUADSIZE || jy<1 ||jy > QUADSIZE) {
282 prout(" damaged but not destroyed.");
285 if (game.quad[jx][jy]==IHBLANK) {
286 prout(" buffeted into black hole.");
287 deadkl(ix, iy, iquad, jx, jy);
290 if (game.quad[jx][jy]!=IHDOT) {
291 /* can't move into object */
292 prout(" damaged but not destroyed.");
295 proutn(" damaged--");
300 case IHB: /* Hit a base */
302 prout("***STARBASE DESTROYED..");
303 for (ll=1; ll<=game.state.rembase; ll++) {
304 if (game.state.baseqx[ll]==quadx && game.state.baseqy[ll]==quady) {
305 game.state.baseqx[ll]=game.state.baseqx[game.state.rembase];
306 game.state.baseqy[ll]=game.state.baseqy[game.state.rembase];
310 game.quad[ix][iy]=IHDOT;
311 game.state.rembase--;
313 game.state.galaxy[quadx][quady].starbase--;
314 game.state.chart[quadx][quady].starbase--;
318 case IHP: /* Hit a planet */
319 crmena(1, iquad, 2, ix, iy);
320 prout(" destroyed.");
321 game.state.nplankl++;
322 game.state.galaxy[quadx][quady].planets--;
323 DESTROY(&game.state.plnets[iplnet]);
326 game.quad[ix][iy] = IHDOT;
328 /* captain perishes on planet */
332 case IHSTAR: /* Hit a star */
337 crmena(1, IHSTAR, 2, ix, iy);
338 prout(" unaffected by photon blast.");
340 case IHQUEST: /* Hit a thingy */
341 if (!(game.options & OPTION_THINGY) || Rand()>0.7) {
343 prouts("AAAAIIIIEEEEEEEEAAAAAAAAUUUUUGGGGGHHHHHHHHHHHH!!!");
345 prouts(" HACK! HACK! HACK! *CHOKE!* ");
347 proutn("Mr. Spock-");
348 prouts(" \"Fascinating!\"");
350 deadkl(ix, iy, iquad, ix, iy);
353 * Stas Sergeev added the possibility that
354 * you can shove the Thingy abd piss it off.
355 * It then becomes an enemy and may fire at you.
361 case IHBLANK: /* Black hole */
363 crmena(1, IHBLANK, 2, ix, iy);
364 prout(" swallows torpedo.");
366 case IHWEB: /* hit the web */
368 prout("***Torpedo absorbed by Tholian web.");
370 case IHT: /* Hit a Tholian */
371 h1 = 700.0 + 100.0*Rand() -
372 1000.0*sqrt(square(ix-inx)+square(iy-iny))*
373 fabs(sin(bullseye-angle));
376 game.quad[ix][iy] = IHDOT;
379 deadkl(ix, iy, iquad, ix, iy);
383 crmena(1, IHT, 2, ix, iy);
385 prout(" survives photon blast.");
388 prout(" disappears.");
389 game.quad[ix][iy] = IHWEB;
390 ithere = ithx = ithy = 0;
394 dropin(IHBLANK, &dum, &my);
398 default: /* Problem! */
400 proutn("Don't know how to handle collision with ");
401 crmena(1, iquad, 2, ix, iy);
407 if(curwnd!=message_window) {
408 setwnd(message_window);
411 game.quad[jx][jy]=iquad;
412 game.quad[ix][iy]=IHDOT;
413 prout(" displaced by blast to %s ", cramlc(sector, jx, jy));
414 for (ll=1; ll<=nenhere; ll++)
415 game.kdist[ll] = game.kavgd[ll] = sqrt(square(sectx-game.kx[ll])+square(secty-game.ky[ll]));
420 prout("Torpedo missed.");
424 static void fry(double hit)
426 double ncrit, extradm;
427 int ktr=1, l, ll, j, cdam[NDEVICES];
429 /* a critical hit occured */
430 if (hit < (275.0-25.0*skill)*(1.0+0.5*Rand())) return;
432 ncrit = 1.0 + hit/(500.0+100.0*Rand());
433 proutn("***CRITICAL HIT--");
434 /* Select devices and cause damage */
435 for (l = 0; l < ncrit && 0 < NDEVICES; l++) {
438 /* Cheat to prevent shuttle damage unless on ship */
440 (game.damage[j]<0.0 || (j==DSHUTTL && iscraft!=1) || j==DDRAY);
442 extradm = (hit*damfac)/(ncrit*(75.0+25.0*Rand()));
443 game.damage[j] += extradm;
445 for (ll=2; ll<=l && j != cdam[ll-1]; ll++) ;
454 if (game.damage[DSHIELD] && shldup) {
455 prout("***Shields knocked down.");
460 void attack(int torps_ok)
462 /* torps_ok == 0 forces use of phasers in an attack */
463 int percent, ihurt=0, l, i=0, jx, jy, iquad, itflag;
464 int atackd = 0, attempt = 0;
466 double pfac, dustfac, hitmax=0.0, hittot=0.0, chgfac=1.0, r;
471 if (idebug) prout("ATTACK!");
474 if (ithere) movetho();
476 if (neutz) { /* The one chance not to be attacked */
480 if ((((comhere || ishere) && (justin == 0)) || skill == SKILL_EMERITUS)&&(torps_ok!=0)) movcom();
481 if (nenhere==0 || (nenhere==1 && iqhere && iqengry==0)) return;
483 if (shldchg == 1) chgfac = 0.25+0.5*Rand();
485 if (skill <= SKILL_FAIR) i = 2;
486 for (l=1; l <= nenhere; l++) {
487 if (game.kpower[l] < 0) continue; /* too weak to attack */
488 /* compute hit strength and diminsh shield power */
490 /* Increase chance of photon torpedos if docked or enemy energy low */
491 if (condit == IHDOCKED) r *= 0.25;
492 if (game.kpower[l] < 500) r *= 0.25;
495 iquad = game.quad[jx][jy];
496 if (iquad==IHT || (iquad==IHQUEST && !iqengry)) continue;
497 itflag = (iquad == IHK && r > 0.0005) || !torps_ok ||
498 (iquad==IHC && r > 0.015) ||
499 (iquad==IHR && r > 0.3) ||
500 (iquad==IHS && r > 0.07) ||
501 (iquad==IHQUEST && r > 0.05);
503 /* Enemy uses phasers */
504 if (condit == IHDOCKED) continue; /* Don't waste the effort! */
505 attempt = 1; /* Attempt to attack */
506 dustfac = 0.8+0.05*Rand();
507 hit = game.kpower[l]*pow(dustfac,game.kavgd[l]);
508 game.kpower[l] *= 0.75;
510 else { /* Enemy used photon torpedo */
511 double course = 1.90985*atan2((double)secty-jy, (double)jx-sectx);
513 proutn("***TORPEDO INCOMING");
514 if (game.damage[DSRSENS] <= 0.0) {
516 crmena(0, iquad, i, jx, jy);
520 r = (Rand()+Rand())*0.5 -0.5;
521 r += 0.002*game.kpower[l]*r;
522 torpedo(course, r, jx, jy, &hit, 0, 1, 1);
523 if (game.state.remkl==0)
524 finish(FWON); /* Klingons did themselves in! */
525 if (game.state.galaxy[quadx][quady].supernova || alldone)
526 return; /* Supernova or finished */
527 if (hit == 0) continue;
529 if (shldup != 0 || shldchg != 0 || condit==IHDOCKED) {
530 /* shields will take hits */
531 double absorb, hitsh, propor = pfac*shield*(condit==IHDOCKED ? 2.1 : 1.0);
532 if(propor < 0.1) propor = 0.1;
533 hitsh = propor*chgfac*hit+1.0;
536 if (absorb > shield) absorb = shield;
539 if (condit==IHDOCKED) dock(0);
540 if (propor > 0.1 && hit < 0.005*energy) continue;
542 /* It's a hit -- print out hit size */
543 atackd = 1; /* We weren't going to check casualties, etc. if
544 shields were down for some strange reason. This
545 doesn't make any sense, so I've fixed it */
547 proutn("%d unit hit", (int)hit);
548 if ((game.damage[DSRSENS] > 0 && itflag) || skill<=SKILL_FAIR) {
552 if (game.damage[DSRSENS] <= 0.0 && itflag) {
554 crmena(0, iquad, i, jx, jy);
557 /* Decide if hit is critical */
558 if (hit > hitmax) hitmax = hit;
561 prout("Hit %g energy %g", hit, energy);
563 if (condit==IHDOCKED)
567 /* Returning home upon your shield, not with it... */
571 if (attempt == 0 && condit == IHDOCKED)
572 prout("***Enemies decide against attacking your ship.");
573 if (atackd == 0) return;
574 percent = 100.0*pfac*shield+0.5;
576 /* Shields fully protect ship */
577 proutn("Enemy attack reduces shield strength to ");
580 /* Print message if starship suffered hit(s) */
582 proutn("Energy left %2d shields ", (int)energy);
583 if (shldup) proutn("up ");
584 else if (game.damage[DSHIELD] == 0) proutn("down ");
585 else proutn("damaged, ");
587 prout("%d%%, torpedoes left %d", percent, torps);
588 /* Check if anyone was hurt */
589 if (hitmax >= 200 || hittot >= 500) {
590 int icas= hittot*Rand()*0.015;
593 prout("Mc Coy- \"Sickbay to bridge. We suffered %d casualties", icas);
594 prout(" in that last attack.\"");
598 /* After attack, reset average distance to enemies */
599 for (l = 1; l <= nenhere; l++)
600 game.kavgd[l] = game.kdist[l];
605 void deadkl(int ix, int iy, int type, int ixx, int iyy)
607 /* Added ixx and iyy allow enemy to "move" before dying */
612 crmena(1, type, 2, ixx, iyy);
613 /* Decide what kind of enemy it is and update approriately */
615 /* chalk up a Romulan */
616 game.state.galaxy[quadx][quady].romulans--;
619 game.state.nromrem--;
621 else if (type == IHT) {
622 /* Killed a Tholian */
625 else if (type == IHQUEST) {
626 /* Killed a Thingy */
627 iqhere=iqengry=thingx=thingy=0;
630 /* Some type of a Klingon */
631 game.state.galaxy[quadx][quady].klingons--;
637 for (i=1; i<=game.state.remcom; i++)
638 if (game.state.cx[i]==quadx && game.state.cy[i]==quady) break;
639 game.state.cx[i] = game.state.cx[game.state.remcom];
640 game.state.cy[i] = game.state.cy[game.state.remcom];
641 game.state.cx[game.state.remcom] = 0;
642 game.state.cy[game.state.remcom] = 0;
644 game.future[FTBEAM] = 1e30;
645 if (game.state.remcom != 0)
646 game.future[FTBEAM] = game.state.date + expran(1.0*incom/game.state.remcom);
653 game.state.nscrem = ishere = game.state.isx = game.state.isy = isatb = iscate = 0;
654 game.state.nsckill = 1;
655 game.future[FSCMOVE] = game.future[FSCDBAS] = 1e30;
660 /* For each kind of enemy, finish message to player */
661 prout(" destroyed.");
662 game.quad[ix][iy] = IHDOT;
663 if (game.state.remkl==0) return;
665 game.state.remtime = game.state.remres/(game.state.remkl + 4*game.state.remcom);
667 /* Remove enemy ship from arrays describing local conditions */
668 if (game.future[FCDBAS] < 1e30 && batx==quadx && baty==quady && type==IHC)
669 game.future[FCDBAS] = 1e30;
670 for (i=1; i<=nenhere; i++)
671 if (game.kx[i]==ix && game.ky[i]==iy) break;
674 for (j=i; j<=nenhere; j++) {
675 game.kx[j] = game.kx[j+1];
676 game.ky[j] = game.ky[j+1];
677 game.kpower[j] = game.kpower[j+1];
678 game.kavgd[j] = game.kdist[j] = game.kdist[j+1];
681 game.kx[nenhere+1] = 0;
682 game.ky[nenhere+1] = 0;
683 game.kdist[nenhere+1] = 0;
684 game.kavgd[nenhere+1] = 0;
685 game.kpower[nenhere+1] = 0;
689 static int targetcheck(double x, double y, double *course)
692 /* Return TRUE if target is invalid */
693 if (x < 1.0 || x > QUADSIZE || y < 1.0 || y > QUADSIZE) {
697 deltx = 0.1*(y - secty);
698 delty = 0.1*(sectx - x);
699 if (deltx==0 && delty== 0) {
701 prout("Spock- \"Bridge to sickbay. Dr. McCoy,");
702 prout(" I recommend an immediate review of");
703 prout(" the Captain's psychological profile.\"");
707 *course = 1.90985932*atan2(deltx, delty);
713 double targ[4][3], course[4];
715 int key, n, i, osuabor;
719 if (game.damage[DPHOTON]) {
720 prout("Photon tubes damaged.");
725 prout("No torpedoes left.");
731 if (key == IHALPHA) {
735 else if (key == IHEOL) {
736 prout("%d torpedoes left.", torps);
737 proutn("Number of torpedoes to fire- ");
740 else /* key == IHREAL */ {
742 if (n <= 0) { /* abort command */
748 prout("Maximum of 3 torpedoes per burst.");
752 if (n <= torps) break;
757 for (i = 1; i <= n; i++) {
759 if (i==1 && key == IHEOL) {
760 break; /* we will try prompting */
762 if (i==2 && key == IHEOL) {
763 /* direct all torpedoes at one target */
765 targ[i][1] = targ[1][1];
766 targ[i][2] = targ[1][2];
767 course[i] = course[1];
783 if (targetcheck(targ[i][1], targ[i][2], &course[i])) return;
786 if (i == 1 && key == IHEOL) {
787 /* prompt for each one */
788 for (i = 1; i <= n; i++) {
789 proutn("Target sector for torpedo number %d- ", i);
803 if (targetcheck(targ[i][1], targ[i][2], &course[i])) return;
807 /* Loop for moving <n> torpedoes */
809 for (i = 1; i <= n && !osuabor; i++) {
810 if (condit != IHDOCKED) torps--;
811 r = (Rand()+Rand())*0.5 -0.5;
812 if (fabs(r) >= 0.47) {
814 r = (Rand()+1.2) * r;
816 prouts("***TORPEDO NUMBER %d MISFIRES", i);
818 else prouts("***TORPEDO MISFIRES.");
821 prout(" Remainder of burst aborted.");
824 prout("***Photon tubes damaged by misfire.");
825 game.damage[DPHOTON] = damfac*(1.0+2.0*Rand());
829 if (shldup || condit == IHDOCKED)
830 r *= 1.0 + 0.0001*shield;
831 torpedo(course[i], r, sectx, secty, &dummy, 0, i, n);
832 if (alldone || game.state.galaxy[quadx][quady].supernova)
835 if (game.state.remkl==0) finish(FWON);
840 static void overheat(double rpow)
843 double chekbrn = (rpow-1500.)*0.00038;
844 if (Rand() <= chekbrn) {
845 prout("Weapons officer Sulu- \"Phasers overheated, sir.\"");
846 game.damage[DPHASER] = damfac*(1.0 + Rand()) * (1.0+chekbrn);
851 static int checkshctrl(double rpow)
858 prout("Shields lowered.");
861 /* Something bad has happened */
862 prouts("***RED ALERT! RED ALERT!");
864 hit = rpow*shield/inshld;
865 energy -= rpow+hit*0.8;
868 prouts("Sulu- \"Captain! Shield malf***********************\"");
874 prouts("Sulu- \"Captain! Shield malfunction! Phaser fire contained!\"");
876 prout("Lt. Uhura- \"Sir, all decks reporting damage.\"");
877 icas = hit*Rand()*0.012;
882 prout("McCoy to bridge- \"Severe radiation burns, Jim.");
883 prout(" %d casualties so far.\"", icas);
887 prout("Phaser energy dispersed by shields.");
888 prout("Enemy unaffected.");
896 double hits[21], rpow=0, extra, powrem, over, temp;
897 int kz = 0, k=1, i, irec=0; /* Cheating inhibitor */
898 int ifast=0, no=0, ipoop=1, msgflag = 1;
899 enum {NOTSET, MANUAL, FORCEMAN, AUTOMATIC} automode = NOTSET;
903 /* SR sensors and Computer */
904 if (game.damage[DSRSENS]+game.damage[DCOMPTR] > 0) ipoop = 0;
905 if (condit == IHDOCKED) {
906 prout("Phasers can't be fired through base shields.");
910 if (game.damage[DPHASER] != 0) {
911 prout("Phaser control damaged.");
916 if (game.damage[DSHCTRL]) {
917 prout("High speed shield control damaged.");
921 if (energy <= 200.0) {
922 prout("Insufficient energy to activate high-speed shield control.");
926 prout("Weapons Officer Sulu- \"High-speed shield control enabled, sir.\"");
930 /* Original code so convoluted, I re-did it all */
931 while (automode==NOTSET) {
933 if (key == IHALPHA) {
934 if (isit("manual")) {
936 prout("There is no enemy present to select.");
946 else if (isit("automatic")) {
947 if ((!ipoop) && nenhere != 0) {
952 prout("Energy will be expended into space.");
953 automode = AUTOMATIC;
957 else if (isit("no")) {
965 else if (key == IHREAL) {
967 prout("Energy will be expended into space.");
968 automode = AUTOMATIC;
973 automode = AUTOMATIC;
978 prout("Energy will be expended into space.");
979 automode = AUTOMATIC;
984 proutn("Manual or automatic? ");
990 if (key == IHALPHA && isit("no")) {
994 if (key != IHREAL && nenhere != 0) {
995 prout("Phasers locked on target. Energy available: %.2f",
996 ifast?energy-200.0:energy,1,2);
1001 if (!kz) for (i = 1; i <= nenhere; i++)
1002 irec+=fabs(game.kpower[i])/(PHASEFAC*pow(0.90,game.kdist[i]))*
1003 (1.01+0.05*Rand()) + 1.0;
1005 proutn("(%d) units required. ", irec);
1007 proutn("Units to fire= ");
1009 if (key!=IHREAL) return;
1011 if (rpow > (ifast?energy-200:energy)) {
1012 proutn("Energy available= %.2f",
1013 ifast?energy-200:energy);
1017 } while (rpow > (ifast?energy-200:energy));
1023 if ((key=scan()) == IHALPHA && isit("no")) {
1027 energy -= 200; /* Go and do it! */
1028 if (checkshctrl(rpow)) return;
1036 for (i = 1; i <= nenhere; i++) {
1038 if (powrem <= 0) continue;
1039 hits[i] = fabs(game.kpower[i])/(PHASEFAC*pow(0.90,game.kdist[i]));
1040 over = (0.01 + 0.05*Rand())*hits[i];
1042 powrem -= hits[i] + over;
1043 if (powrem <= 0 && temp < hits[i]) hits[i] = temp;
1044 if (powrem <= 0) over = 0.0;
1047 if (powrem > 0.0) extra += powrem;
1051 if (extra > 0 && alldone == 0) {
1053 proutn("*** Tholian web absorbs ");
1054 if (nenhere>0) proutn("excess ");
1055 prout("phaser energy.");
1058 prout("%d expended on empty space.", (int)extra);
1066 if (game.damage[DCOMPTR]!=0)
1067 prout("Battle comuter damaged, manual file only.");
1070 prouts("---WORKING---");
1072 prout("Short-range-sensors-damaged");
1073 prout("Insufficient-data-for-automatic-phaser-fire");
1074 prout("Manual-fire-must-be-used");
1079 for (k = 1; k <= nenhere;) {
1080 int ii = game.kx[k], jj = game.ky[k];
1081 int ienm = game.quad[ii][jj];
1083 proutn("Energy available= %.2f",
1084 energy-.006-(ifast?200:0));
1089 if (game.damage[DSRSENS] && !(abs(sectx-ii) < 2 && abs(secty-jj) < 2) &&
1090 (ienm == IHC || ienm == IHS)) {
1092 prout(" can't be located without short range scan.");
1095 hits[k] = 0; /* prevent overflow -- thanks to Alexei Voitenko */
1101 if (ipoop && k > kz)
1102 irec=(fabs(game.kpower[k])/(PHASEFAC*pow(0.9,game.kdist[k])))*
1103 (1.01+0.05*Rand()) + 1.0;
1106 if (game.damage[DCOMPTR]==0) proutn("%d", irec);
1109 proutn("units to fire at ");
1110 crmena(0, ienm, 2, ii, jj);
1114 if (key == IHALPHA && isit("no")) {
1119 if (key == IHALPHA) {
1124 if (k==1) { /* Let me say I'm baffled by this */
1136 /* If total requested is too much, inform and start over */
1138 if (rpow > (ifast?energy-200:energy)) {
1139 prout("Available energy exceeded -- try again.");
1143 key = scan(); /* scan for next value */
1147 /* zero energy -- abort */
1151 if (key == IHALPHA && isit("no")) {
1158 if (checkshctrl(rpow)) return;
1162 case NOTSET:; /* avoid gcc warning */
1164 /* Say shield raised or malfunction, if necessary */
1170 if (Rand() >= 0.99) {
1171 prout("Sulu- \"Sir, the high-speed shield control has malfunctioned . . .");
1172 prouts(" CLICK CLICK POP . . .");
1173 prout(" No response, sir!");
1177 prout("Shields raised.");
1185 void hittem(double *hits)
1187 double kp, kpow, wham, hit, dustfac, kpini;
1188 int nenhr2=nenhere, k=1, kk=1, ii, jj, ienm;
1192 for (; k <= nenhr2; k++, kk++) {
1193 if ((wham = hits[k])==0) continue;
1194 dustfac = 0.9 + 0.01*Rand();
1195 hit = wham*pow(dustfac,game.kdist[kk]);
1196 kpini = game.kpower[kk];
1198 if (PHASEFAC*hit < kp) kp = PHASEFAC*hit;
1199 game.kpower[kk] -= (game.kpower[kk] < 0 ? -kp: kp);
1200 kpow = game.kpower[kk];
1204 if (game.damage[DSRSENS]==0)
1206 proutn("%d unit hit on ", (int)hit);
1209 proutn("Very small hit on ");
1210 ienm = game.quad[ii][jj];
1211 if (ienm==IHQUEST) iqengry=1;
1212 crmena(0,ienm,2,ii,jj);
1215 deadkl(ii, jj, ienm, ii, jj);
1216 if (game.state.remkl==0) finish(FWON);
1217 if (alldone) return;
1218 kk--; /* don't do the increment */
1220 else /* decide whether or not to emasculate klingon */
1221 if (kpow > 0 && Rand() >= 0.9 &&
1222 kpow <= ((0.4 + 0.4*Rand())*kpini)) {
1223 prout("***Mr. Spock- \"Captain, the vessel at ",
1224 cramlc(sector,ii,jj));
1225 prout(" has just lost its firepower.\"");
1226 game.kpower[kk] = -kpow;