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."));
38 else if (game.shldup) {
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 (game.condit != IHDOCKED) game.energy -= 50.0;
65 prout(_("Shields raised."));
66 if (game.energy <= 0) {
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 > game.energy) {
92 prout(_("Insufficient ship energy."));
96 if (game.shield+aaitem >= game.inshld) {
97 prout(_("Shield energy maximized."));
98 if (game.shield+aaitem > game.inshld) {
99 prout(_("Excess energy requested returned to ship energy"));
101 game.energy -= game.inshld-game.shield;
102 game.shield = game.inshld;
105 if (aaitem < 0.0 && game.energy-aaitem > game.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 (game.shield+aaitem < 0) {
115 prout(_("All shield energy transferred to ship."));
116 game.energy += game.shield;
120 proutn(_("Scotty- \""));
122 prout(_("Transferring energy to shields.\""));
124 prout(_("Draining energy from shields.\""));
125 game.shield += aaitem;
126 game.energy -= aaitem;
128 case NONE:; /* avoid gcc warning */
132 void ram(int ibumpd, int ienm, coord w)
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, w);
152 if (ibumpd) proutn(_(" (original position)"));
154 deadkl(w.x, w.y, ienm, game.sector.x, game.sector.y);
157 prout(_(" heavily damaged."));
158 icas = 10.0+20.0*Rand();
159 prout(_("***Sickbay reports %d casualties"), icas);
161 for (l=0; l < NDEVICES; l++) {
163 continue; // Don't damage deathray
164 if (game.damage[l] < 0)
166 extradm = (10.0*type*Rand()+1.0)*game.damfac;
167 game.damage[l] += game.optime + extradm; /* Damage for at least time of travel! */
178 void torpedo(double course, double r, int inx, int iny, double *hit, int i, int n)
180 int l, iquad=0, jx=0, jy=0, shoved=0, ll;
182 double ac=course + 0.25*r;
183 double angle = (15.0-ac)*0.5235988;
184 double bullseye = (15.0 - course)*0.5235988;
185 double deltax=-sin(angle), deltay=cos(angle), x=inx, y=iny, bigger;
186 double ang, temp, xx, yy, kp, h1;
190 bigger = fabs(deltax);
191 if (fabs(deltay) > bigger) bigger = fabs(deltay);
194 if (game.damage[DSRSENS]==0 || game.condit==IHDOCKED)
195 setwnd(srscan_window);
197 setwnd(message_window);
198 /* Loop to move a single torpedo */
199 for (l=1; l <= 15; l++) {
204 if (!VALID_SECTOR(w.x, w.y)) break;
205 iquad=game.quad[w.x][w.y];
206 tracktorpedo(w.x, w.y, l, i, n, iquad);
207 if (iquad==IHDOT) continue;
209 setwnd(message_window);
210 skip(1); /* start new line after text track */
212 case IHE: /* Hit our ship */
215 proutn(_("Torpedo hits "));
218 *hit = 700.0 + 100.0*Rand() -
219 1000.0*sqrt(square(w.x-inx)+square(w.y-iny))*
220 fabs(sin(bullseye-angle));
222 newcnd(); /* we're blown out of dock */
223 /* We may be displaced. */
224 if (game.landed==1 || game.condit==IHDOCKED) return; /* Cheat if on a planet */
225 ang = angle + 2.5*(Rand()-0.5);
226 temp = fabs(sin(ang));
227 if (fabs(cos(ang)) > temp) temp = fabs(cos(ang));
232 if (!VALID_SECTOR(jx, jy)) return;
233 if (game.quad[jx][jy]==IHBLANK) {
237 if (game.quad[jx][jy]!=IHDOT) {
238 /* can't move into object */
247 case IHC: /* Hit a commander */
249 if (Rand() <= 0.05) {
250 crmena(1, iquad, 2, w);
251 prout(_(" uses anti-photon device;"));
252 prout(_(" torpedo neutralized."));
255 case IHR: /* Hit a regular enemy */
258 for_local_enemies(ll)
259 if (w.x==game.ks[ll].x && w.y==game.ks[ll].y) break;
260 kp = fabs(game.kpower[ll]);
261 h1 = 700.0 + 100.0*Rand() -
262 1000.0*sqrt(square(w.x-inx)+square(w.y-iny))*
263 fabs(sin(bullseye-angle));
265 if (kp < h1) h1 = kp;
266 game.kpower[ll] -= (game.kpower[ll]<0 ? -h1 : h1);
267 if (game.kpower[ll] == 0) {
268 deadkl(w.x, w.y, iquad, w.x, w.y);
271 crmena(1, iquad, 2, w);
272 /* If enemy damaged but not destroyed, try to displace */
273 ang = angle + 2.5*(Rand()-0.5);
274 temp = fabs(sin(ang));
275 if (fabs(cos(ang)) > temp) temp = fabs(cos(ang));
280 if (!VALID_SECTOR(jx, jy)) {
281 prout(_(" damaged but not destroyed."));
284 if (game.quad[jx][jy]==IHBLANK) {
285 prout(_(" buffeted into black hole."));
286 deadkl(w.x, w.y, iquad, jx, jy);
289 if (game.quad[jx][jy]!=IHDOT) {
290 /* can't move into object */
291 prout(_(" damaged but not destroyed."));
294 proutn(_(" damaged--"));
299 case IHB: /* Hit a base */
301 prout(_("***STARBASE DESTROYED.."));
303 if (game.state.baseq[ll].x==game.quadrant.x && game.state.baseq[ll].y==game.quadrant.y) {
304 game.state.baseq[ll].x=game.state.baseq[game.state.rembase].x;
305 game.state.baseq[ll].y=game.state.baseq[game.state.rembase].y;
309 game.quad[w.x][w.y]=IHDOT;
310 game.state.rembase--;
311 game.base.x=game.base.y=0;
312 game.state.galaxy[game.quadrant.x][game.quadrant.y].starbase--;
313 game.state.chart[game.quadrant.x][game.quadrant.y].starbase--;
317 case IHP: /* Hit a planet */
318 crmena(1, iquad, 2, w);
319 prout(_(" destroyed."));
320 game.state.nplankl++;
321 game.state.galaxy[game.quadrant.x][game.quadrant.y].planet = NULL;
322 DESTROY(&game.state.plnets[game.iplnet]);
324 game.plnet.x = game.plnet.y = 0;
325 game.quad[w.x][w.y] = IHDOT;
326 if (game.landed==1) {
327 /* captain perishes on planet */
331 case IHSTAR: /* Hit a star */
336 crmena(1, IHSTAR, 2, w);
337 prout(_(" unaffected by photon blast."));
339 case IHQUEST: /* Hit a thingy */
340 if (!(game.options & OPTION_THINGY) || Rand()>0.7) {
342 prouts(_("AAAAIIIIEEEEEEEEAAAAAAAAUUUUUGGGGGHHHHHHHHHHHH!!!"));
344 prouts(_(" HACK! HACK! HACK! *CHOKE!* "));
346 proutn(_("Mr. Spock-"));
347 prouts(_(" \"Fascinating!\""));
349 deadkl(w.x, w.y, iquad, w.x, w.y);
352 * Stas Sergeev added the possibility that
353 * you can shove the Thingy and piss it off.
354 * It then becomes an enemy and may fire at you.
360 case IHBLANK: /* Black hole */
362 crmena(1, IHBLANK, 2, w);
363 prout(_(" swallows torpedo."));
365 case IHWEB: /* hit the web */
367 prout(_("***Torpedo absorbed by Tholian web."));
369 case IHT: /* Hit a Tholian */
370 h1 = 700.0 + 100.0*Rand() -
371 1000.0*sqrt(square(w.x-inx)+square(w.y-iny))*
372 fabs(sin(bullseye-angle));
375 game.quad[w.x][w.y] = IHDOT;
377 game.tholian.x = game.tholian.y = 0;
378 deadkl(w.x, w.y, iquad, w.x, w.y);
382 crmena(1, IHT, 2, w);
384 prout(_(" survives photon blast."));
387 prout(_(" disappears."));
388 game.quad[w.x][w.y] = IHWEB;
389 game.ithere = game.tholian.x = game.tholian.y = 0;
393 dropin(IHBLANK, &dummy);
397 default: /* Problem! */
399 proutn("Don't know how to handle collision with ");
400 crmena(1, iquad, 2, w);
406 if(curwnd!=message_window) {
407 setwnd(message_window);
412 game.quad[jx][jy]=iquad;
413 game.quad[w.x][w.y]=IHDOT;
414 prout(_(" displaced by blast to %s "), cramlc(sector, w));
415 for_local_enemies(ll)
416 game.kdist[ll] = game.kavgd[ll] = sqrt(square(game.sector.x-game.ks[ll].x)+square(game.sector.y-game.ks[ll].y));
421 prout(_("Torpedo missed."));
425 static void fry(double hit)
427 double ncrit, extradm;
428 int ktr=1, l, ll, j, cdam[NDEVICES];
430 /* a critical hit occured */
431 if (hit < (275.0-25.0*game.skill)*(1.0+0.5*Rand())) return;
433 ncrit = 1.0 + hit/(500.0+100.0*Rand());
434 proutn(_("***CRITICAL HIT--"));
435 /* Select devices and cause damage */
436 for (l = 0; l < ncrit && 0 < NDEVICES; l++) {
439 /* Cheat to prevent shuttle damage unless on ship */
441 (game.damage[j]<0.0 || (j==DSHUTTL && game.iscraft!=1) || j==DDRAY);
443 extradm = (hit*game.damfac)/(ncrit*(75.0+25.0*Rand()));
444 game.damage[j] += extradm;
446 for (ll=2; ll<=l && j != cdam[ll-1]; ll++) ;
454 prout(_(" damaged."));
455 if (game.damage[DSHIELD] && game.shldup) {
456 prout(_("***Shields knocked down."));
461 void attack(int torps_ok)
463 /* torps_ok == 0 forces use of phasers in an attack */
464 int percent, ihurt=0, l, i=0, iquad, itflag;
465 int atackd = 0, attempt = 0;
467 double pfac, dustfac, hitmax=0.0, hittot=0.0, chgfac=1.0, r;
471 if (game.alldone) return;
473 if (game.idebug) prout("ATTACK!");
476 if (game.ithere) movetho();
478 if (game.neutz) { /* The one chance not to be attacked */
482 if ((((game.comhere || game.ishere) && (game.justin == 0)) || game.skill == SKILL_EMERITUS)&&(torps_ok!=0)) movcom();
483 if (game.nenhere==0 || (game.nenhere==1 && iqhere && iqengry==0)) return;
484 pfac = 1.0/game.inshld;
485 if (game.shldchg == 1) chgfac = 0.25+0.5*Rand();
487 if (game.skill <= SKILL_FAIR) i = 2;
488 for_local_enemies(l) {
489 if (game.kpower[l] < 0) continue; /* too weak to attack */
490 /* compute hit strength and diminsh shield power */
492 /* Increase chance of photon torpedos if docked or enemy energy low */
493 if (game.condit == IHDOCKED) r *= 0.25;
494 if (game.kpower[l] < 500) r *= 0.25;
495 jay.x = game.ks[l].x;
496 jay.y = game.ks[l].y;
497 iquad = game.quad[jay.x][jay.y];
498 if (iquad==IHT || (iquad==IHQUEST && !iqengry)) continue;
499 itflag = (iquad == IHK && r > 0.0005) || !torps_ok ||
500 (iquad==IHC && r > 0.015) ||
501 (iquad==IHR && r > 0.3) ||
502 (iquad==IHS && r > 0.07) ||
503 (iquad==IHQUEST && r > 0.05);
505 /* Enemy uses phasers */
506 if (game.condit == IHDOCKED) continue; /* Don't waste the effort! */
507 attempt = 1; /* Attempt to attack */
508 dustfac = 0.8+0.05*Rand();
509 hit = game.kpower[l]*pow(dustfac,game.kavgd[l]);
510 game.kpower[l] *= 0.75;
512 else { /* Enemy used photon torpedo */
513 double course = 1.90985*atan2((double)game.sector.y-jay.y, (double)jay.x-game.sector.x);
515 proutn(_("***TORPEDO INCOMING"));
516 if (game.damage[DSRSENS] <= 0.0) {
518 crmena(0, iquad, i, jay);
522 r = (Rand()+Rand())*0.5 -0.5;
523 r += 0.002*game.kpower[l]*r;
524 torpedo(course, r, jay.x, jay.y, &hit, 1, 1);
526 finish(FWON); /* Klingons did themselves in! */
527 if (game.state.galaxy[game.quadrant.x][game.quadrant.y].supernova || game.alldone)
528 return; /* Supernova or finished */
529 if (hit == 0) continue;
531 if (game.shldup != 0 || game.shldchg != 0 || game.condit==IHDOCKED) {
532 /* shields will take hits */
533 double absorb, hitsh, propor = pfac*game.shield*(game.condit==IHDOCKED ? 2.1 : 1.0);
534 if(propor < 0.1) propor = 0.1;
535 hitsh = propor*chgfac*hit+1.0;
538 if (absorb > game.shield) absorb = game.shield;
539 game.shield -= absorb;
541 if (game.condit==IHDOCKED) dock(0);
542 if (propor > 0.1 && hit < 0.005*game.energy) continue;
544 /* It's a hit -- print out hit size */
545 atackd = 1; /* We weren't going to check casualties, etc. if
546 shields were down for some strange reason. This
547 doesn't make any sense, so I've fw.xed it */
549 proutn(_("%d unit hit"), (int)hit);
550 if ((game.damage[DSRSENS] > 0 && itflag) || game.skill<=SKILL_FAIR) {
551 proutn(_(" on the "));
554 if (game.damage[DSRSENS] <= 0.0 && itflag) {
556 crmena(0, iquad, i, jay);
559 /* Decide if hit is critical */
560 if (hit > hitmax) hitmax = hit;
564 if (game.condit==IHDOCKED)
567 if (game.energy <= 0) {
568 /* Returning home upon your shield, not with it... */
572 if (attempt == 0 && game.condit == IHDOCKED)
573 prout(_("***Enemies decide against attacking your ship."));
574 if (atackd == 0) return;
575 percent = 100.0*pfac*game.shield+0.5;
577 /* Shields fully protect ship */
578 proutn(_("Enemy attack reduces shield strength to "));
581 /* Print message if starship suffered hit(s) */
583 proutn(_("Energy left %2d shields "), (int)game.energy);
584 if (game.shldup) proutn(_("up "));
585 else if (game.damage[DSHIELD] == 0) proutn(_("down "));
586 else proutn(_("damaged, "));
588 prout(_("%d%%, torpedoes left %d"), percent, game.torps);
589 /* Check if anyone was hurt */
590 if (hitmax >= 200 || hittot >= 500) {
591 int icas= hittot*Rand()*0.015;
594 prout(_("Mc Coy- \"Sickbay to bridge. We suffered %d casualties"), icas);
595 prout(_(" in that last attack.\""));
599 /* After attack, reset average distance to enemies */
601 game.kavgd[l] = game.kdist[l];
606 void deadkl(int ix, int iy, int type, int ixx, int iyy)
608 /* Added ixx and iyy allow enemy to "move" before dying */
612 mv.x = ixx; mv.y = iyy;
614 crmena(1, type, 2, mv);
615 /* Decide what kind of enemy it is and update approriately */
617 /* chalk up a Romulan */
618 game.state.galaxy[game.quadrant.x][game.quadrant.y].romulans--;
620 game.state.nromrem--;
622 else if (type == IHT) {
623 /* Killed a Tholian */
626 else if (type == IHQUEST) {
627 /* Killed a Thingy */
628 iqhere=iqengry=thing.x=thing.y=0;
631 /* Some type of a Klingon */
632 game.state.galaxy[game.quadrant.x][game.quadrant.y].klingons--;
638 if (game.state.kcmdr[i].x==game.quadrant.x && game.state.kcmdr[i].y==game.quadrant.y) break;
639 game.state.kcmdr[i] = game.state.kcmdr[game.state.remcom];
640 game.state.kcmdr[game.state.remcom].x = 0;
641 game.state.kcmdr[game.state.remcom].y = 0;
644 if (game.state.remcom != 0)
645 schedule(FTBEAM, expran(1.0*game.incom/game.state.remcom));
652 game.ishere = game.state.kscmdr.x = game.state.kscmdr.y = game.isatb = game.iscate = 0;
659 /* For each kind of enemy, finish message to player */
660 prout(_(" destroyed."));
661 game.quad[ix][iy] = IHDOT;
662 if (KLINGREM==0) return;
664 game.state.remtime = game.state.remres/(game.state.remkl + 4*game.state.remcom);
666 /* Remove enemy ship from arrays describing local game.conditions */
667 if (is_scheduled(FCDBAS) && game.battle.x==game.quadrant.x && game.battle.y==game.quadrant.y && type==IHC)
670 if (game.ks[i].x==ix && game.ks[i].y==iy) break;
672 if (i <= game.nenhere) {
673 for (j=i; j<=game.nenhere; j++) {
674 game.ks[j] = game.ks[j+1];
675 game.kpower[j] = game.kpower[j+1];
676 game.kavgd[j] = game.kdist[j] = game.kdist[j+1];
679 game.ks[game.nenhere+1].x = 0;
680 game.ks[game.nenhere+1].x = 0;
681 game.kdist[game.nenhere+1] = 0;
682 game.kavgd[game.nenhere+1] = 0;
683 game.kpower[game.nenhere+1] = 0;
687 static int targetcheck(double x, double y, double *course)
690 /* Return TRUE if target is invalid */
691 if (!VALID_SECTOR(x, y)) {
695 deltx = 0.1*(y - game.sector.y);
696 delty = 0.1*(game.sector.x - x);
697 if (deltx==0 && delty== 0) {
699 prout(_("Spock- \"Bridge to sickbay. Dr. McCoy,"));
700 prout(_(" I recommend an immediate review of"));
701 prout(_(" the Captain's psychological profile.\""));
705 *course = 1.90985932*atan2(deltx, delty);
711 double targ[4][3], course[4];
713 int key, n, i, osuabor;
717 if (game.damage[DPHOTON]) {
718 prout(_("Photon tubes damaged."));
722 if (game.torps == 0) {
723 prout(_("No torpedoes left."));
729 if (key == IHALPHA) {
733 else if (key == IHEOL) {
734 prout(_("%d torpedoes left."), game.torps);
735 proutn(_("Number of torpedoes to fire- "));
738 else /* key == IHREAL */ {
740 if (n <= 0) { /* abort command */
746 prout(_("Maximum of 3 torpedoes per burst."));
750 if (n <= game.torps) break;
755 for (i = 1; i <= n; i++) {
757 if (i==1 && key == IHEOL) {
758 break; /* we will try prompting */
760 if (i==2 && key == IHEOL) {
761 /* direct all torpedoes at one target */
763 targ[i][1] = targ[1][1];
764 targ[i][2] = targ[1][2];
765 course[i] = course[1];
781 if (targetcheck(targ[i][1], targ[i][2], &course[i])) return;
784 if (i == 1 && key == IHEOL) {
785 /* prompt for each one */
786 for (i = 1; i <= n; i++) {
787 proutn(_("Target sector for torpedo number %d- "), i);
801 if (targetcheck(targ[i][1], targ[i][2], &course[i])) return;
805 /* Loop for moving <n> torpedoes */
807 for (i = 1; i <= n && !osuabor; i++) {
808 if (game.condit != IHDOCKED) game.torps--;
809 r = (Rand()+Rand())*0.5 -0.5;
810 if (fabs(r) >= 0.47) {
812 r = (Rand()+1.2) * r;
814 prouts(_("***TORPEDO NUMBER %d MISFIRES"), i);
816 else prouts(_("***TORPEDO MISFIRES."));
819 prout(_(" Remainder of burst aborted."));
822 prout(_("***Photon tubes damaged by misfire."));
823 game.damage[DPHOTON] = game.damfac*(1.0+2.0*Rand());
827 if (game.shldup || game.condit == IHDOCKED)
828 r *= 1.0 + 0.0001*game.shield;
829 torpedo(course[i], r, game.sector.x, game.sector.y, &dummy, i, n);
830 if (game.alldone || game.state.galaxy[game.quadrant.x][game.quadrant.y].supernova)
833 if (KLINGREM==0) finish(FWON);
838 static void overheat(double rpow)
841 double chekbrn = (rpow-1500.)*0.00038;
842 if (Rand() <= chekbrn) {
843 prout(_("Weapons officer Sulu- \"Phasers overheated, sir.\""));
844 game.damage[DPHASER] = game.damfac*(1.0 + Rand()) * (1.0+chekbrn);
849 static int checkshctrl(double rpow)
856 prout(_("Shields lowered."));
859 /* Something bad has happened */
860 prouts(_("***RED ALERT! RED ALERT!"));
862 hit = rpow*game.shield/game.inshld;
863 game.energy -= rpow+hit*0.8;
864 game.shield -= hit*0.2;
865 if (game.energy <= 0.0) {
866 prouts(_("Sulu- \"Captain! Shield malf***********************\""));
872 prouts(_("Sulu- \"Captain! Shield malfunction! Phaser fire contained!\""));
874 prout(_("Lt. Uhura- \"Sir, all decks reporting damage.\""));
875 icas = hit*Rand()*0.012;
880 prout(_("McCoy to bridge- \"Severe radiation burns, Jim."));
881 prout(_(" %d casualties so far.\""), icas);
885 prout(_("Phaser energy dispersed by shields."));
886 prout(_("Enemy unaffected."));
894 double hits[21], rpow=0, extra, powrem, over, temp;
895 int kz = 0, k=1, i, irec=0; /* Cheating inhibitor */
896 int ifast=0, no=0, ipoop=1, msgflag = 1;
897 enum {NOTSET, MANUAL, FORCEMAN, AUTOMATIC} automode = NOTSET;
901 /* SR sensors and Computer */
902 if (game.damage[DSRSENS]+game.damage[DCOMPTR] > 0) ipoop = 0;
903 if (game.condit == IHDOCKED) {
904 prout(_("Phasers can't be fired through base shields."));
908 if (game.damage[DPHASER] != 0) {
909 prout(_("Phaser control damaged."));
914 if (game.damage[DSHCTRL]) {
915 prout(_("High speed shield control damaged."));
919 if (game.energy <= 200.0) {
920 prout(_("Insufficient energy to activate high-speed shield control."));
924 prout(_("Weapons Officer Sulu- \"High-speed shield control enabled, sir.\""));
928 /* Original code so convoluted, I re-did it all */
929 while (automode==NOTSET) {
931 if (key == IHALPHA) {
932 if (isit("manual")) {
933 if (game.nenhere==0) {
934 prout(_("There is no enemy present to select."));
944 else if (isit("automatic")) {
945 if ((!ipoop) && game.nenhere != 0) {
950 prout(_("Energy will be expended into space."));
951 automode = AUTOMATIC;
955 else if (isit("no")) {
963 else if (key == IHREAL) {
964 if (game.nenhere==0) {
965 prout(_("Energy will be expended into space."));
966 automode = AUTOMATIC;
971 automode = AUTOMATIC;
975 if (game.nenhere==0) {
976 prout(_("Energy will be expended into space."));
977 automode = AUTOMATIC;
982 proutn(_("Manual or automatic? "));
988 if (key == IHALPHA && isit("no")) {
992 if (key != IHREAL && game.nenhere != 0) {
993 prout(_("Phasers locked on target. Energy available: %.2f"),
994 ifast?game.energy-200.0:game.energy,1,2);
999 if (!kz) for_local_enemies(i)
1000 irec+=fabs(game.kpower[i])/(PHASEFAC*pow(0.90,game.kdist[i]))*
1001 (1.01+0.05*Rand()) + 1.0;
1003 proutn(_("(%d) units required. "), irec);
1005 proutn(_("Units to fire= "));
1007 if (key!=IHREAL) return;
1009 if (rpow > (ifast?game.energy-200:game.energy)) {
1010 proutn(_("Energy available= %.2f"),
1011 ifast?game.energy-200:game.energy);
1015 } while (rpow > (ifast?game.energy-200:game.energy));
1021 if ((key=scan()) == IHALPHA && isit("no")) {
1025 game.energy -= 200; /* Go and do it! */
1026 if (checkshctrl(rpow)) return;
1029 game.energy -= rpow;
1034 for_local_enemies(i) {
1036 if (powrem <= 0) continue;
1037 hits[i] = fabs(game.kpower[i])/(PHASEFAC*pow(0.90,game.kdist[i]));
1038 over = (0.01 + 0.05*Rand())*hits[i];
1040 powrem -= hits[i] + over;
1041 if (powrem <= 0 && temp < hits[i]) hits[i] = temp;
1042 if (powrem <= 0) over = 0.0;
1045 if (powrem > 0.0) extra += powrem;
1049 if (extra > 0 && game.alldone == 0) {
1051 proutn(_("*** Tholian web absorbs "));
1052 if (game.nenhere>0) proutn(_("excess "));
1053 prout(_("phaser energy."));
1056 prout(_("%d expended on empty space."), (int)extra);
1064 if (game.damage[DCOMPTR]!=0)
1065 prout(_("Battle comuter damaged, manual file only."));
1068 prouts(_("---WORKING---"));
1070 prout(_("Short-range-sensors-damaged"));
1071 prout(_("Insufficient-data-for-automatic-phaser-fire"));
1072 prout(_("Manual-fire-must-be-used"));
1077 for (k = 1; k <= game.nenhere;) {
1078 coord aim = game.ks[k];
1079 int ienm = game.quad[aim.x][aim.y];
1081 proutn(_("Energy available= %.2f"),
1082 game.energy-.006-(ifast?200:0));
1087 if (game.damage[DSRSENS] && !(abs(game.sector.x-aim.x) < 2 && abs(game.sector.y-aim.y) < 2) &&
1088 (ienm == IHC || ienm == IHS)) {
1090 prout(_(" can't be located without short range scan."));
1093 hits[k] = 0; /* prevent overflow -- thanks to Alexei Voitenko */
1099 if (ipoop && k > kz)
1100 irec=(fabs(game.kpower[k])/(PHASEFAC*pow(0.9,game.kdist[k])))*
1101 (1.01+0.05*Rand()) + 1.0;
1104 if (game.damage[DCOMPTR]==0) proutn("%d", irec);
1107 proutn(_("units to fire at "));
1108 crmena(0, ienm, 2, aim);
1112 if (key == IHALPHA && isit("no")) {
1117 if (key == IHALPHA) {
1122 if (k==1) { /* Let me say I'm baffled by this */
1134 /* If total requested is too much, inform and start over */
1136 if (rpow > (ifast?game.energy-200:game.energy)) {
1137 prout(_("Available energy exceeded -- try again."));
1141 key = scan(); /* scan for next value */
1145 /* zero energy -- abort */
1149 if (key == IHALPHA && isit("no")) {
1152 game.energy -= rpow;
1155 game.energy -= 200.0;
1156 if (checkshctrl(rpow)) return;
1160 case NOTSET:; /* avoid gcc warning */
1162 /* Say shield raised or malfunction, if necessary */
1168 if (Rand() >= 0.99) {
1169 prout(_("Sulu- \"Sir, the high-speed shield control has malfunctioned . . ."));
1170 prouts(_(" CLICK CLICK POP . . ."));
1171 prout(_(" No response, sir!"));
1175 prout(_("Shields raised."));
1183 void hittem(double *hits)
1185 double kp, kpow, wham, hit, dustfac, kpini;
1186 int nenhr2=game.nenhere, k=1, kk=1, ienm;
1191 for (; k <= nenhr2; k++, kk++) {
1192 if ((wham = hits[k])==0) continue;
1193 dustfac = 0.9 + 0.01*Rand();
1194 hit = wham*pow(dustfac,game.kdist[kk]);
1195 kpini = game.kpower[kk];
1197 if (PHASEFAC*hit < kp) kp = PHASEFAC*hit;
1198 game.kpower[kk] -= (game.kpower[kk] < 0 ? -kp: kp);
1199 kpow = game.kpower[kk];
1202 if (game.damage[DSRSENS]==0)
1204 proutn(_("%d unit hit on "), (int)hit);
1207 proutn(_("Very small hit on "));
1208 ienm = game.quad[w.x][w.y];
1209 if (ienm==IHQUEST) iqengry=1;
1213 deadkl(w.x, w.y, ienm, w.x, w.y);
1214 if (KLINGREM==0) finish(FWON);
1215 if (game.alldone) return;
1216 kk--; /* don't do the increment */
1218 else /* decide whether or not to emasculate klingon */
1219 if (kpow > 0 && Rand() >= 0.9 &&
1220 kpow <= ((0.4 + 0.4*Rand())*kpini)) {
1221 prout(_("***Mr. Spock- \"Captain, the vessel at "),
1223 prout(_(" has just lost its firepower.\""));
1224 game.kpower[kk] = -kpow;