3 void doshield(bool raise)
4 /* change shield status */
7 enum {NONE, SHUP, SHDN, NRG} action = NONE;
20 if (damaged(DSHIELD)) {
21 prout(_("Shields damaged and down."));
26 else if (isit("down"))
31 proutn(_("Do you wish to change shield energy? "));
33 proutn(_("Energy to transfer to shields- "));
36 else if (damaged(DSHIELD)) {
37 prout(_("Shields damaged and down."));
40 else if (game.shldup) {
41 proutn(_("Shields are up. Do you want them down? "));
42 if (ja() == true) action = SHDN;
49 proutn(_("Shields are down. Do you want them up? "));
50 if (ja() == true) action = SHUP;
59 case SHUP: /* raise shields */
61 prout(_("Shields already up."));
66 if (game.condition != docked) game.energy -= 50.0;
67 prout(_("Shields raised."));
68 if (game.energy <= 0) {
70 prout(_("Shields raising uses up last of energy."));
78 prout(_("Shields already down."));
83 prout(_("Shields lowered."));
87 while (scan() != IHREAL) {
89 proutn(_("Energy to transfer to shields- "));
92 if (aaitem==0) return;
93 if (aaitem > game.energy) {
94 prout(_("Insufficient ship energy."));
98 if (game.shield+aaitem >= game.inshld) {
99 prout(_("Shield energy maximized."));
100 if (game.shield+aaitem > game.inshld) {
101 prout(_("Excess energy requested returned to ship energy"));
103 game.energy -= game.inshld-game.shield;
104 game.shield = game.inshld;
107 if (aaitem < 0.0 && game.energy-aaitem > game.inenrg) {
108 /* Prevent shield drain loophole */
110 prout(_("Engineering to bridge--"));
111 prout(_(" Scott here. Power circuit problem, Captain."));
112 prout(_(" I can't drain the shields."));
116 if (game.shield+aaitem < 0) {
117 prout(_("All shield energy transferred to ship."));
118 game.energy += game.shield;
122 proutn(_("Scotty- \""));
124 prout(_("Transferring energy to shields.\""));
126 prout(_("Draining energy from shields.\""));
127 game.shield += aaitem;
128 game.energy -= aaitem;
130 case NONE:; /* avoid gcc warning */
134 void ram(bool ibumpd, feature ienm, coord w)
135 /* make our ship ram something */
137 double hardness, extradm;
140 prouts(_("***RED ALERT! RED ALERT!"));
142 prout(_("***COLLISION IMMINENT."));
147 case IHR: hardness = 1.5; break;
148 case IHC: hardness = 2.0; break;
149 case IHS: hardness = 2.5; break;
150 case IHT: hardness = 0.5; break;
151 case IHQUEST: hardness = 4.0; break;
152 default: hardness = 1.0; break;
154 proutn(ibumpd ? _(" rammed by ") : _(" rams "));
155 crmena(false, ienm, sector, w);
156 if (ibumpd) proutn(_(" (original position)"));
158 deadkl(w, ienm, game.sector);
161 prout(_(" heavily damaged."));
162 icas = 10.0+20.0*Rand();
163 prout(_("***Sickbay reports %d casualties"), icas);
165 game.state.crew -= icas;
166 for (m=0; m < NDEVICES; m++) {
168 continue; // Don't damage deathray
169 if (game.damage[m] < 0)
171 extradm = (10.0*hardness*Rand()+1.0)*game.damfac;
172 game.damage[m] += game.optime + extradm; /* Damage for at least time of travel! */
183 void torpedo(double course, double r, coord in, double *hit, int i, int n)
184 /* let a photon torpedo fly */
188 double ac=course + 0.25*r;
189 double angle = (15.0-ac)*0.5235988;
190 double bullseye = (15.0 - course)*0.5235988;
191 double deltax=-sin(angle), deltay=cos(angle), x=in.x, y=in.y, bigger;
192 double ang, temp, xx, yy, kp, h1;
193 struct quadrant *q = &game.state.galaxy[game.quadrant.x][game.quadrant.y];
196 w.x = w.y = jw.x = jw.y = 0;
197 bigger = fabs(deltax);
198 if (fabs(deltay) > bigger) bigger = fabs(deltay);
201 if (!damaged(DSRSENS) || game.condition==docked)
202 setwnd(srscan_window);
204 setwnd(message_window);
205 /* Loop to move a single torpedo */
206 for (l=1; l <= 15; l++) {
211 if (!VALID_SECTOR(w.x, w.y)) break;
212 iquad=game.quad[w.x][w.y];
213 tracktorpedo(w, l, i, n, iquad);
214 if (iquad==IHDOT) continue;
216 setwnd(message_window);
217 skip(1); /* start new line after text track */
219 case IHE: /* Hit our ship */
222 proutn(_("Torpedo hits "));
225 *hit = 700.0 + 100.0*Rand() -
226 1000.0 * distance(w, in) * fabs(sin(bullseye-angle));
228 newcnd(); /* we're blown out of dock */
229 /* We may be displaced. */
230 if (game.landed==1 || game.condition==docked) return; /* Cheat if on a planet */
231 ang = angle + 2.5*(Rand()-0.5);
232 temp = fabs(sin(ang));
233 if (fabs(cos(ang)) > temp) temp = fabs(cos(ang));
238 if (!VALID_SECTOR(jw.x, jw.y)) return;
239 if (game.quad[jw.x][jw.y]==IHBLANK) {
243 if (game.quad[jw.x][jw.y]!=IHDOT) {
244 /* can't move into object */
252 case IHC: /* Hit a commander */
254 if (Rand() <= 0.05) {
255 crmena(true, iquad, sector, w);
256 prout(_(" uses anti-photon device;"));
257 prout(_(" torpedo neutralized."));
260 case IHR: /* Hit a regular enemy */
263 for_local_enemies(ll)
264 if (same(w, game.ks[ll]))
266 kp = fabs(game.kpower[ll]);
267 h1 = 700.0 + 100.0*Rand() -
268 1000.0 * distance(w, in) * fabs(sin(bullseye-angle));
270 if (kp < h1) h1 = kp;
271 game.kpower[ll] -= (game.kpower[ll]<0 ? -h1 : h1);
272 if (game.kpower[ll] == 0) {
276 crmena(true, iquad, sector, w);
277 /* If enemy damaged but not destroyed, try to displace */
278 ang = angle + 2.5*(Rand()-0.5);
279 temp = fabs(sin(ang));
280 if (fabs(cos(ang)) > temp) temp = fabs(cos(ang));
285 if (!VALID_SECTOR(jw.x, jw.y)) {
286 prout(_(" damaged but not destroyed."));
289 if (game.quad[jw.x][jw.y]==IHBLANK) {
290 prout(_(" buffeted into black hole."));
291 deadkl(w, iquad, jw);
294 if (game.quad[jw.x][jw.y]!=IHDOT) {
295 /* can't move into object */
296 prout(_(" damaged but not destroyed."));
299 proutn(_(" damaged--"));
303 case IHB: /* Hit a base */
305 prout(_("***STARBASE DESTROYED.."));
307 if (same(game.state.baseq[ll], game.quadrant)) {
308 game.state.baseq[ll]=game.state.baseq[game.state.rembase];
312 game.quad[w.x][w.y]=IHDOT;
313 game.state.rembase--;
314 game.base.x=game.base.y=0;
316 game.state.chart[game.quadrant.x][game.quadrant.y].starbase--;
320 case IHP: /* Hit a planet */
321 crmena(true, iquad, sector, w);
322 prout(_(" destroyed."));
323 game.state.nplankl++;
324 q->planet = NOPLANET;
325 DESTROY(&game.state.plnets[game.iplnet]);
327 game.plnet.x = game.plnet.y = 0;
328 game.quad[w.x][w.y] = IHDOT;
329 if (game.landed==1) {
330 /* captain perishes on planet */
334 case IHW: /* Hit an inhabited world -- very bad! */
335 crmena(true, iquad, sector, w);
336 prout(_(" destroyed."));
337 game.state.nworldkl++;
338 q->planet = NOPLANET;
339 DESTROY(&game.state.plnets[game.iplnet]);
341 game.plnet.x = game.plnet.y = 0;
342 game.quad[w.x][w.y] = IHDOT;
343 if (game.landed==1) {
344 /* captain perishes on planet */
347 prout("You have just destroyed an inhabited planet.");
348 prout("Celebratory rallies are being held on the Klingon homeworld.");
350 case IHSTAR: /* Hit a star */
355 crmena(true, IHSTAR, sector, w);
356 prout(_(" unaffected by photon blast."));
358 case IHQUEST: /* Hit a thingy */
359 if (!(game.options & OPTION_THINGY) || Rand()>0.7) {
361 prouts(_("AAAAIIIIEEEEEEEEAAAAAAAAUUUUUGGGGGHHHHHHHHHHHH!!!"));
363 prouts(_(" HACK! HACK! HACK! *CHOKE!* "));
365 proutn(_("Mr. Spock-"));
366 prouts(_(" \"Fascinating!\""));
371 * Stas Sergeev added the possibility that
372 * you can shove the Thingy and piss it off.
373 * It then becomes an enemy and may fire at you.
379 case IHBLANK: /* Black hole */
381 crmena(true, IHBLANK, sector, w);
382 prout(_(" swallows torpedo."));
384 case IHWEB: /* hit the web */
386 prout(_("***Torpedo absorbed by Tholian web."));
388 case IHT: /* Hit a Tholian */
389 h1 = 700.0 + 100.0*Rand() -
390 1000.0 * distance(w, in) * fabs(sin(bullseye-angle));
393 game.quad[w.x][w.y] = IHDOT;
399 crmena(true, IHT, sector, w);
401 prout(_(" survives photon blast."));
404 prout(_(" disappears."));
405 game.quad[w.x][w.y] = IHWEB;
411 default: /* Problem! */
413 proutn("Don't know how to handle collision with ");
414 crmena(true, iquad, sector, w);
420 if(curwnd!=message_window) {
421 setwnd(message_window);
424 game.quad[w.x][w.y]=IHDOT;
425 game.quad[jw.x][jw.y]=iquad;
426 prout(_(" displaced by blast to %s "), cramlc(sector, jw));
427 for_local_enemies(ll)
428 game.kdist[ll] = game.kavgd[ll] = distance(game.sector,game.ks[ll]);
433 prout(_("Torpedo missed."));
437 static void fry(double hit)
438 /* critical-hit resolution */
440 double ncrit, extradm;
441 int ktr=1, loop1, loop2, j, cdam[NDEVICES];
443 /* a critical hit occured */
444 if (hit < (275.0-25.0*game.skill)*(1.0+0.5*Rand())) return;
446 ncrit = 1.0 + hit/(500.0+100.0*Rand());
447 proutn(_("***CRITICAL HIT--"));
448 /* Select devices and cause damage */
449 for (loop1 = 0; loop1 < ncrit && 0 < NDEVICES; loop1++) {
452 /* Cheat to prevent shuttle damage unless on ship */
454 (game.damage[j]<0.0 || (j==DSHUTTL && game.iscraft!=1) || j==DDRAY);
456 extradm = (hit*game.damfac)/(ncrit*(75.0+25.0*Rand()));
457 game.damage[j] += extradm;
459 for (loop2=2; loop2<=loop1 && j != cdam[loop2-1]; loop2++) ;
460 if (loop2<=loop1) continue;
467 prout(_(" damaged."));
468 if (damaged(DSHIELD) && game.shldup) {
469 prout(_("***Shields knocked down."));
474 void attack(bool torps_ok)
475 /* bad guy attacks us */
477 /* torps_ok == false forces use of phasers in an attack */
478 int percent, loop, iquad;
479 bool itflag, atackd = false, attempt = false, ihurt = false;
480 double hit, pfac, dustfac, hitmax=0.0, hittot=0.0, chgfac=1.0, r;
482 enum loctype where = neither;
485 if (game.alldone) return;
486 if (idebug) prout("=== ATTACK!");
488 if (game.ithere) movetho();
490 if (game.neutz) { /* The one chance not to be attacked */
494 if ((((game.comhere || game.ishere) && !game.justin) || game.skill == SKILL_EMERITUS) && torps_ok) movcom();
495 if (game.nenhere==0 || (game.nenhere==1 && iqhere && !iqengry)) return;
496 pfac = 1.0/game.inshld;
497 if (game.shldchg == 1) chgfac = 0.25+0.5*Rand();
499 if (game.skill <= SKILL_FAIR) where = sector;
500 for_local_enemies(loop) {
501 if (game.kpower[loop] < 0) continue; /* too weak to attack */
502 /* compute hit strength and diminsh shield power */
504 /* Increase chance of photon torpedos if docked or enemy energy low */
505 if (game.condition == docked) r *= 0.25;
506 if (game.kpower[loop] < 500) r *= 0.25;
508 iquad = game.quad[jay.x][jay.y];
509 if (iquad==IHT || (iquad==IHQUEST && !iqengry)) continue;
510 itflag = (iquad == IHK && r > 0.0005) || !torps_ok ||
511 (iquad==IHC && r > 0.015) ||
512 (iquad==IHR && r > 0.3) ||
513 (iquad==IHS && r > 0.07) ||
514 (iquad==IHQUEST && r > 0.05);
516 /* Enemy uses phasers */
517 if (game.condition == docked) continue; /* Don't waste the effort! */
518 attempt = true; /* Attempt to attack */
519 dustfac = 0.8+0.05*Rand();
520 hit = game.kpower[loop]*pow(dustfac,game.kavgd[loop]);
521 game.kpower[loop] *= 0.75;
523 else { /* Enemy used photon torpedo */
524 double course = 1.90985*atan2((double)game.sector.y-jay.y, (double)jay.x-game.sector.x);
526 proutn(_("***TORPEDO INCOMING"));
527 if (!damaged(DSRSENS)) {
529 crmena(false, iquad, where, jay);
533 r = (Rand()+Rand())*0.5 -0.5;
534 r += 0.002*game.kpower[loop]*r;
535 torpedo(course, r, jay, &hit, 1, 1);
537 finish(FWON); /* Klingons did themselves in! */
538 if (game.state.galaxy[game.quadrant.x][game.quadrant.y].supernova || game.alldone)
539 return; /* Supernova or finished */
540 if (hit == 0) continue;
542 if (game.shldup || game.shldchg != 0 || game.condition==docked) {
543 /* shields will take hits */
544 double absorb, hitsh, propor = pfac*game.shield*(game.condition==docked ? 2.1 : 1.0);
545 if(propor < 0.1) propor = 0.1;
546 hitsh = propor*chgfac*hit+1.0;
549 if (absorb > game.shield) absorb = game.shield;
550 game.shield -= absorb;
552 if (game.condition==docked) dock(false);
553 if (propor > 0.1 && hit < 0.005*game.energy) continue;
555 /* It's a hit -- print out hit size */
556 atackd = true; /* We weren't going to check casualties, etc. if
557 shields were down for some strange reason. This
558 doesn't make any sense, so I've fixed it */
560 proutn(_("%d unit hit"), (int)hit);
561 if ((damaged(DSRSENS) && itflag) || game.skill<=SKILL_FAIR) {
562 proutn(_(" on the "));
565 if (!damaged(DSRSENS) && itflag) {
567 crmena(false, iquad, where, jay);
570 /* Decide if hit is critical */
571 if (hit > hitmax) hitmax = hit;
575 if (game.condition==docked)
578 if (game.energy <= 0) {
579 /* Returning home upon your shield, not with it... */
583 if (!attempt && game.condition == docked)
584 prout(_("***Enemies decide against attacking your ship."));
586 percent = 100.0*pfac*game.shield+0.5;
588 /* Shields fully protect ship */
589 proutn(_("Enemy attack reduces shield strength to "));
592 /* Print message if starship suffered hit(s) */
594 proutn(_("Energy left %2d shields "), (int)game.energy);
595 if (game.shldup) proutn(_("up "));
596 else if (!damaged(DSHIELD)) proutn(_("down "));
597 else proutn(_("damaged, "));
599 prout(_("%d%%, torpedoes left %d"), percent, game.torps);
600 /* Check if anyone was hurt */
601 if (hitmax >= 200 || hittot >= 500) {
602 int icas= hittot*Rand()*0.015;
605 prout(_("Mc Coy- \"Sickbay to bridge. We suffered %d casualties"), icas);
606 prout(_(" in that last attack.\""));
608 game.state.crew -= icas;
611 /* After attack, reset average distance to enemies */
612 for_local_enemies(loop)
613 game.kavgd[loop] = game.kdist[loop];
618 void deadkl(coord w, feature type, coord mv)
619 /* kill a Klingon, Tholian, Romulan, or Thingy */
621 /* Added mv to allow enemy to "move" before dying */
625 crmena(true, type, sector, mv);
626 /* Decide what kind of enemy it is and update approriately */
628 /* chalk up a Romulan */
629 game.state.galaxy[game.quadrant.x][game.quadrant.y].romulans--;
631 game.state.nromrem--;
633 else if (type == IHT) {
634 /* Killed a Tholian */
637 else if (type == IHQUEST) {
638 /* Killed a Thingy */
639 iqhere = iqengry = false;
640 thing.x =thing.y = 0;
643 /* Some type of a Klingon */
644 game.state.galaxy[game.quadrant.x][game.quadrant.y].klingons--;
648 game.comhere = false;
650 if (game.state.kcmdr[i].x==game.quadrant.x && game.state.kcmdr[i].y==game.quadrant.y) break;
651 game.state.kcmdr[i] = game.state.kcmdr[game.state.remcom];
652 game.state.kcmdr[game.state.remcom].x = 0;
653 game.state.kcmdr[game.state.remcom].y = 0;
656 if (game.state.remcom != 0)
657 schedule(FTBEAM, expran(1.0*game.incom/game.state.remcom));
665 game.state.kscmdr.x = game.state.kscmdr.y = game.isatb = game.iscate = 0;
669 default: /* avoids a gcc warning */
670 prout("*** Internal error, deadkl() called on %c\n", type);
675 /* For each kind of enemy, finish message to player */
676 prout(_(" destroyed."));
677 game.quad[w.x][w.y] = IHDOT;
678 if (KLINGREM==0) return;
680 game.state.remtime = game.state.remres/(game.state.remkl + 4*game.state.remcom);
682 /* Remove enemy ship from arrays describing local conditions */
683 if (is_scheduled(FCDBAS) && game.battle.x==game.quadrant.x && game.battle.y==game.quadrant.y && type==IHC)
686 if (same(game.ks[i], w)) break;
688 if (i <= game.nenhere) {
689 for (j=i; j<=game.nenhere; j++) {
690 game.ks[j] = game.ks[j+1];
691 game.kpower[j] = game.kpower[j+1];
692 game.kavgd[j] = game.kdist[j] = game.kdist[j+1];
695 game.ks[game.nenhere+1].x = 0;
696 game.ks[game.nenhere+1].x = 0;
697 game.kdist[game.nenhere+1] = 0;
698 game.kavgd[game.nenhere+1] = 0;
699 game.kpower[game.nenhere+1] = 0;
703 static bool targetcheck(double x, double y, double *course)
706 /* Return true if target is invalid */
707 if (!VALID_SECTOR(x, y)) {
711 deltx = 0.1*(y - game.sector.y);
712 delty = 0.1*(game.sector.x - x);
713 if (deltx==0 && delty== 0) {
715 prout(_("Spock- \"Bridge to sickbay. Dr. McCoy,"));
716 prout(_(" I recommend an immediate review of"));
717 prout(_(" the Captain's psychological profile.\""));
721 *course = 1.90985932*atan2(deltx, delty);
726 /* launch photon torpedo */
728 double targ[4][3], course[4];
735 if (damaged(DPHOTON)) {
736 prout(_("Photon tubes damaged."));
740 if (game.torps == 0) {
741 prout(_("No torpedoes left."));
747 if (key == IHALPHA) {
751 else if (key == IHEOL) {
752 prout(_("%d torpedoes left."), game.torps);
753 proutn(_("Number of torpedoes to fire- "));
756 else /* key == IHREAL */ {
758 if (n <= 0) { /* abort command */
764 prout(_("Maximum of 3 torpedoes per burst."));
768 if (n <= game.torps) break;
773 for (i = 1; i <= n; i++) {
775 if (i==1 && key == IHEOL) {
776 break; /* we will try prompting */
778 if (i==2 && key == IHEOL) {
779 /* direct all torpedoes at one target */
781 targ[i][1] = targ[1][1];
782 targ[i][2] = targ[1][2];
783 course[i] = course[1];
799 if (targetcheck(targ[i][1], targ[i][2], &course[i])) return;
802 if (i == 1 && key == IHEOL) {
803 /* prompt for each one */
804 for (i = 1; i <= n; i++) {
805 proutn(_("Target sector for torpedo number %d- "), i);
819 if (targetcheck(targ[i][1], targ[i][2], &course[i])) return;
823 /* Loop for moving <n> torpedoes */
825 for (i = 1; i <= n && !osuabor; i++) {
826 if (game.condition != docked) game.torps--;
827 r = (Rand()+Rand())*0.5 -0.5;
828 if (fabs(r) >= 0.47) {
830 r = (Rand()+1.2) * r;
832 prouts(_("***TORPEDO NUMBER %d MISFIRES"), i);
834 else prouts(_("***TORPEDO MISFIRES."));
837 prout(_(" Remainder of burst aborted."));
840 prout(_("***Photon tubes damaged by misfire."));
841 game.damage[DPHOTON] = game.damfac*(1.0+2.0*Rand());
845 if (game.shldup || game.condition == docked)
846 r *= 1.0 + 0.0001*game.shield;
847 torpedo(course[i], r, game.sector, &dummy, i, n);
848 if (game.alldone || game.state.galaxy[game.quadrant.x][game.quadrant.y].supernova)
851 if (KLINGREM==0) finish(FWON);
856 static void overheat(double rpow)
857 /* check for phasers overheating */
860 double chekbrn = (rpow-1500.)*0.00038;
861 if (Rand() <= chekbrn) {
862 prout(_("Weapons officer Sulu- \"Phasers overheated, sir.\""));
863 game.damage[DPHASER] = game.damfac*(1.0 + Rand()) * (1.0+chekbrn);
868 static bool checkshctrl(double rpow)
869 /* check shield control */
876 prout(_("Shields lowered."));
879 /* Something bad has happened */
880 prouts(_("***RED ALERT! RED ALERT!"));
882 hit = rpow*game.shield/game.inshld;
883 game.energy -= rpow+hit*0.8;
884 game.shield -= hit*0.2;
885 if (game.energy <= 0.0) {
886 prouts(_("Sulu- \"Captain! Shield malf***********************\""));
892 prouts(_("Sulu- \"Captain! Shield malfunction! Phaser fire contained!\""));
894 prout(_("Lt. Uhura- \"Sir, all decks reporting damage.\""));
895 icas = hit*Rand()*0.012;
900 prout(_("McCoy to bridge- \"Severe radiation burns, Jim."));
901 prout(_(" %d casualties so far.\""), icas);
903 game.state.crew -= icas;
906 prout(_("Phaser energy dispersed by shields."));
907 prout(_("Enemy unaffected."));
916 double hits[21], rpow=0, extra, powrem, over, temp;
917 int kz = 0, k=1, i, irec=0; /* Cheating inhibitor */
918 bool ifast = false, no = false, ipoop = true, msgflag = true;
919 enum {NOTSET, MANUAL, FORCEMAN, AUTOMATIC} automode = NOTSET;
923 /* SR sensors and Computer */
924 if (damaged(DSRSENS) || damaged(DCOMPTR)) ipoop = false;
925 if (game.condition == docked) {
926 prout(_("Phasers can't be fired through base shields."));
930 if (damaged(DPHASER)) {
931 prout(_("Phaser control damaged."));
936 if (damaged(DSHCTRL)) {
937 prout(_("High speed shield control damaged."));
941 if (game.energy <= 200.0) {
942 prout(_("Insufficient energy to activate high-speed shield control."));
946 prout(_("Weapons Officer Sulu- \"High-speed shield control enabled, sir.\""));
950 /* Original code so convoluted, I re-did it all */
951 while (automode==NOTSET) {
953 if (key == IHALPHA) {
954 if (isit("manual")) {
955 if (game.nenhere==0) {
956 prout(_("There is no enemy present to select."));
966 else if (isit("automatic")) {
967 if ((!ipoop) && game.nenhere != 0) {
972 prout(_("Energy will be expended into space."));
973 automode = AUTOMATIC;
977 else if (isit("no")) {
985 else if (key == IHREAL) {
986 if (game.nenhere==0) {
987 prout(_("Energy will be expended into space."));
988 automode = AUTOMATIC;
993 automode = AUTOMATIC;
997 if (game.nenhere==0) {
998 prout(_("Energy will be expended into space."));
999 automode = AUTOMATIC;
1002 automode = FORCEMAN;
1004 proutn(_("Manual or automatic? "));
1010 if (key == IHALPHA && isit("no")) {
1014 if (key != IHREAL && game.nenhere != 0) {
1015 prout(_("Phasers locked on target. Energy available: %.2f"),
1016 ifast?game.energy-200.0:game.energy,1,2);
1021 if (!kz) for_local_enemies(i)
1022 irec+=fabs(game.kpower[i])/(PHASEFAC*pow(0.90,game.kdist[i]))*
1023 (1.01+0.05*Rand()) + 1.0;
1025 proutn(_("(%d) units required. "), irec);
1027 proutn(_("Units to fire= "));
1029 if (key!=IHREAL) return;
1031 if (rpow > (ifast?game.energy-200:game.energy)) {
1032 proutn(_("Energy available= %.2f"),
1033 ifast?game.energy-200:game.energy);
1037 } while (rpow > (ifast?game.energy-200:game.energy));
1043 if ((key=scan()) == IHALPHA && isit("no")) {
1047 game.energy -= 200; /* Go and do it! */
1048 if (checkshctrl(rpow)) return;
1051 game.energy -= rpow;
1056 for_local_enemies(i) {
1058 if (powrem <= 0) continue;
1059 hits[i] = fabs(game.kpower[i])/(PHASEFAC*pow(0.90,game.kdist[i]));
1060 over = (0.01 + 0.05*Rand())*hits[i];
1062 powrem -= hits[i] + over;
1063 if (powrem <= 0 && temp < hits[i]) hits[i] = temp;
1064 if (powrem <= 0) over = 0.0;
1067 if (powrem > 0.0) extra += powrem;
1071 if (extra > 0 && !game.alldone) {
1073 proutn(_("*** Tholian web absorbs "));
1074 if (game.nenhere>0) proutn(_("excess "));
1075 prout(_("phaser energy."));
1078 prout(_("%d expended on empty space."), (int)extra);
1086 if (damaged(DCOMPTR))
1087 prout(_("Battle comuter damaged, manual file only."));
1090 prouts(_("---WORKING---"));
1092 prout(_("Short-range-sensors-damaged"));
1093 prout(_("Insufficient-data-for-automatic-phaser-fire"));
1094 prout(_("Manual-fire-must-be-used"));
1099 for (k = 1; k <= game.nenhere;) {
1100 coord aim = game.ks[k];
1101 int ienm = game.quad[aim.x][aim.y];
1103 proutn(_("Energy available= %.2f"),
1104 game.energy-.006-(ifast?200:0));
1109 if (damaged(DSRSENS) && !(abs(game.sector.x-aim.x) < 2 && abs(game.sector.y-aim.y) < 2) &&
1110 (ienm == IHC || ienm == IHS)) {
1112 prout(_(" can't be located without short range scan."));
1115 hits[k] = 0; /* prevent overflow -- thanks to Alexei Voitenko */
1121 if (ipoop && k > kz)
1122 irec=(fabs(game.kpower[k])/(PHASEFAC*pow(0.9,game.kdist[k])))*
1123 (1.01+0.05*Rand()) + 1.0;
1126 if (!damaged(DCOMPTR)) proutn("%d", irec);
1129 proutn(_("units to fire at "));
1130 crmena(false, ienm, sector, aim);
1134 if (key == IHALPHA && isit("no")) {
1139 if (key == IHALPHA) {
1144 if (k==1) { /* Let me say I'm baffled by this */
1156 /* If total requested is too much, inform and start over */
1158 if (rpow > (ifast?game.energy-200:game.energy)) {
1159 prout(_("Available energy exceeded -- try again."));
1163 key = scan(); /* scan for next value */
1167 /* zero energy -- abort */
1171 if (key == IHALPHA && isit("no")) {
1174 game.energy -= rpow;
1177 game.energy -= 200.0;
1178 if (checkshctrl(rpow)) return;
1182 case NOTSET:; /* avoid gcc warning */
1184 /* Say shield raised or malfunction, if necessary */
1190 if (Rand() >= 0.99) {
1191 prout(_("Sulu- \"Sir, the high-speed shield control has malfunctioned . . ."));
1192 prouts(_(" CLICK CLICK POP . . ."));
1193 prout(_(" No response, sir!"));
1194 game.shldup = false;
1197 prout(_("Shields raised."));
1200 game.shldup = false;
1205 void hittem(double *hits)
1206 /* register a phaser hit on Klingons and Romulans */
1208 double kp, kpow, wham, hit, dustfac, kpini;
1209 int nenhr2=game.nenhere, k=1, kk=1, ienm;
1214 for (; k <= nenhr2; k++, kk++) {
1215 if ((wham = hits[k])==0) continue;
1216 dustfac = 0.9 + 0.01*Rand();
1217 hit = wham*pow(dustfac,game.kdist[kk]);
1218 kpini = game.kpower[kk];
1220 if (PHASEFAC*hit < kp) kp = PHASEFAC*hit;
1221 game.kpower[kk] -= (game.kpower[kk] < 0 ? -kp: kp);
1222 kpow = game.kpower[kk];
1225 if (!damaged(DSRSENS))
1227 proutn(_("%d unit hit on "), (int)hit);
1230 proutn(_("Very small hit on "));
1231 ienm = game.quad[w.x][w.y];
1232 if (ienm==IHQUEST) iqengry = true;
1233 crmena(false,ienm,sector,w);
1237 if (KLINGREM==0) finish(FWON);
1238 if (game.alldone) return;
1239 kk--; /* don't do the increment */
1241 else /* decide whether or not to emasculate klingon */
1242 if (kpow > 0 && Rand() >= 0.9 &&
1243 kpow <= ((0.4 + 0.4*Rand())*kpini)) {
1244 prout(_("***Mr. Spock- \"Captain, the vessel at "),
1246 prout(_(" has just lost its firepower.\""));
1247 game.kpower[kk] = -kpow;