6 enum {NONE, SHUP, SHDN, NRG} action = NONE;
10 if (i == 2) action = SHUP;
18 if (!damaged(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 (damaged(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, 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 game.state.crew -= 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)*game.damfac;
168 game.damage[l] += game.optime + extradm; /* Damage for at least time of travel! */
179 void torpedo(double course, double r, int inx, int iny, double *hit, int i, int n)
181 int l, iquad=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;
191 bigger = fabs(deltax);
192 if (fabs(deltay) > bigger) bigger = fabs(deltay);
195 if (!damaged(DSRSENS) || game.condit==IHDOCKED)
196 setwnd(srscan_window);
198 setwnd(message_window);
199 /* Loop to move a single torpedo */
200 for (l=1; l <= 15; l++) {
205 if (!VALID_SECTOR(w.x, w.y)) break;
206 iquad=game.quad[w.x][w.y];
207 tracktorpedo(w.x, w.y, 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(w.x-inx)+square(w.y-iny))*
221 fabs(sin(bullseye-angle));
223 newcnd(); /* we're blown out of dock */
224 /* We may be displaced. */
225 if (game.landed==1 || game.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 (!VALID_SECTOR(jx, jy)) 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, w);
252 prout(_(" uses anti-photon device;"));
253 prout(_(" torpedo neutralized."));
256 case IHR: /* Hit a regular enemy */
259 for_local_enemies(ll)
260 if (w.x==game.ks[ll].x && w.y==game.ks[ll].y) break;
261 kp = fabs(game.kpower[ll]);
262 h1 = 700.0 + 100.0*Rand() -
263 1000.0*sqrt(square(w.x-inx)+square(w.y-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(w, iquad, w.x, w.y);
272 crmena(1, iquad, 2, w);
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 (!VALID_SECTOR(jx, jy)) {
282 prout(_(" damaged but not destroyed."));
285 if (game.quad[jx][jy]==IHBLANK) {
286 prout(_(" buffeted into black hole."));
287 deadkl(w, 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.."));
304 if (game.state.baseq[ll].x==game.quadrant.x && game.state.baseq[ll].y==game.quadrant.y) {
305 game.state.baseq[ll].x=game.state.baseq[game.state.rembase].x;
306 game.state.baseq[ll].y=game.state.baseq[game.state.rembase].y;
310 game.quad[w.x][w.y]=IHDOT;
311 game.state.rembase--;
312 game.base.x=game.base.y=0;
313 game.state.galaxy[game.quadrant.x][game.quadrant.y].starbase--;
314 game.state.chart[game.quadrant.x][game.quadrant.y].starbase--;
318 case IHP: /* Hit a planet */
319 crmena(1, iquad, 2, w);
320 prout(_(" destroyed."));
321 game.state.nplankl++;
322 game.state.galaxy[game.quadrant.x][game.quadrant.y].planet = NOPLANET;
323 DESTROY(&game.state.plnets[game.iplnet]);
325 game.plnet.x = game.plnet.y = 0;
326 game.quad[w.x][w.y] = IHDOT;
327 if (game.landed==1) {
328 /* captain perishes on planet */
332 case IHW: /* Hit an inhabited world -- very bad! */
333 crmena(1, iquad, 2, w);
334 prout(_(" destroyed."));
335 game.state.nworldkl++;
336 game.state.galaxy[game.quadrant.x][game.quadrant.y].planet = NOPLANET;
337 DESTROY(&game.state.plnets[game.iplnet]);
339 game.plnet.x = game.plnet.y = 0;
340 game.quad[w.x][w.y] = IHDOT;
341 if (game.landed==1) {
342 /* captain perishes on planet */
345 prout("You have just destroyed an inhabited planet.");
346 prout("Celebratory rallies are being held on the Klingon homeworld.");
348 case IHSTAR: /* Hit a star */
353 crmena(1, IHSTAR, 2, w);
354 prout(_(" unaffected by photon blast."));
356 case IHQUEST: /* Hit a thingy */
357 if (!(game.options & OPTION_THINGY) || Rand()>0.7) {
359 prouts(_("AAAAIIIIEEEEEEEEAAAAAAAAUUUUUGGGGGHHHHHHHHHHHH!!!"));
361 prouts(_(" HACK! HACK! HACK! *CHOKE!* "));
363 proutn(_("Mr. Spock-"));
364 prouts(_(" \"Fascinating!\""));
366 deadkl(w, iquad, w.x, w.y);
369 * Stas Sergeev added the possibility that
370 * you can shove the Thingy and piss it off.
371 * It then becomes an enemy and may fire at you.
377 case IHBLANK: /* Black hole */
379 crmena(1, IHBLANK, 2, w);
380 prout(_(" swallows torpedo."));
382 case IHWEB: /* hit the web */
384 prout(_("***Torpedo absorbed by Tholian web."));
386 case IHT: /* Hit a Tholian */
387 h1 = 700.0 + 100.0*Rand() -
388 1000.0*sqrt(square(w.x-inx)+square(w.y-iny))*
389 fabs(sin(bullseye-angle));
392 game.quad[w.x][w.y] = IHDOT;
394 game.tholian.x = game.tholian.y = 0;
395 deadkl(w, iquad, w.x, w.y);
399 crmena(1, IHT, 2, w);
401 prout(_(" survives photon blast."));
404 prout(_(" disappears."));
405 game.quad[w.x][w.y] = IHWEB;
406 game.ithere = game.tholian.x = game.tholian.y = 0;
410 dropin(IHBLANK, &dummy);
414 default: /* Problem! */
416 proutn("Don't know how to handle collision with ");
417 crmena(1, iquad, 2, w);
423 if(curwnd!=message_window) {
424 setwnd(message_window);
427 game.quad[w.x][w.y]=IHDOT;
428 game.quad[jx][jy]=iquad;
429 prout(_(" displaced by blast to %s "), cramlc(sector, w));
430 for_local_enemies(ll)
431 game.kdist[ll] = game.kavgd[ll] = sqrt(square(game.sector.x-game.ks[ll].x)+square(game.sector.y-game.ks[ll].y));
436 prout(_("Torpedo missed."));
440 static void fry(double hit)
442 double ncrit, extradm;
443 int ktr=1, l, ll, j, cdam[NDEVICES];
445 /* a critical hit occured */
446 if (hit < (275.0-25.0*game.skill)*(1.0+0.5*Rand())) return;
448 ncrit = 1.0 + hit/(500.0+100.0*Rand());
449 proutn(_("***CRITICAL HIT--"));
450 /* Select devices and cause damage */
451 for (l = 0; l < ncrit && 0 < NDEVICES; l++) {
454 /* Cheat to prevent shuttle damage unless on ship */
456 (game.damage[j]<0.0 || (j==DSHUTTL && game.iscraft!=1) || j==DDRAY);
458 extradm = (hit*game.damfac)/(ncrit*(75.0+25.0*Rand()));
459 game.damage[j] += extradm;
461 for (ll=2; ll<=l && j != cdam[ll-1]; ll++) ;
469 prout(_(" damaged."));
470 if (damaged(DSHIELD) && game.shldup) {
471 prout(_("***Shields knocked down."));
476 void attack(int torps_ok)
478 /* torps_ok == 0 forces use of phasers in an attack */
479 int percent, ihurt=0, l, i=0, iquad, itflag;
480 int atackd = 0, attempt = 0;
482 double pfac, dustfac, hitmax=0.0, hittot=0.0, chgfac=1.0, r;
486 if (game.alldone) return;
487 if (idebug) prout("=== ATTACK!");
489 if (game.ithere) movetho();
491 if (game.neutz) { /* The one chance not to be attacked */
495 if ((((game.comhere || game.ishere) && (game.justin == 0)) || game.skill == SKILL_EMERITUS)&&(torps_ok!=0)) movcom();
496 if (game.nenhere==0 || (game.nenhere==1 && iqhere && iqengry==0)) return;
497 pfac = 1.0/game.inshld;
498 if (game.shldchg == 1) chgfac = 0.25+0.5*Rand();
500 if (game.skill <= SKILL_FAIR) i = 2;
501 for_local_enemies(l) {
502 if (game.kpower[l] < 0) continue; /* too weak to attack */
503 /* compute hit strength and diminsh shield power */
505 /* Increase chance of photon torpedos if docked or enemy energy low */
506 if (game.condit == IHDOCKED) r *= 0.25;
507 if (game.kpower[l] < 500) r *= 0.25;
508 jay.x = game.ks[l].x;
509 jay.y = game.ks[l].y;
510 iquad = game.quad[jay.x][jay.y];
511 if (iquad==IHT || (iquad==IHQUEST && !iqengry)) continue;
512 itflag = (iquad == IHK && r > 0.0005) || !torps_ok ||
513 (iquad==IHC && r > 0.015) ||
514 (iquad==IHR && r > 0.3) ||
515 (iquad==IHS && r > 0.07) ||
516 (iquad==IHQUEST && r > 0.05);
518 /* Enemy uses phasers */
519 if (game.condit == IHDOCKED) continue; /* Don't waste the effort! */
520 attempt = 1; /* Attempt to attack */
521 dustfac = 0.8+0.05*Rand();
522 hit = game.kpower[l]*pow(dustfac,game.kavgd[l]);
523 game.kpower[l] *= 0.75;
525 else { /* Enemy used photon torpedo */
526 double course = 1.90985*atan2((double)game.sector.y-jay.y, (double)jay.x-game.sector.x);
528 proutn(_("***TORPEDO INCOMING"));
529 if (!damaged(DSRSENS)) {
531 crmena(0, iquad, i, jay);
535 r = (Rand()+Rand())*0.5 -0.5;
536 r += 0.002*game.kpower[l]*r;
537 torpedo(course, r, jay.x, jay.y, &hit, 1, 1);
539 finish(FWON); /* Klingons did themselves in! */
540 if (game.state.galaxy[game.quadrant.x][game.quadrant.y].supernova || game.alldone)
541 return; /* Supernova or finished */
542 if (hit == 0) continue;
544 if (game.shldup || game.shldchg != 0 || game.condit==IHDOCKED) {
545 /* shields will take hits */
546 double absorb, hitsh, propor = pfac*game.shield*(game.condit==IHDOCKED ? 2.1 : 1.0);
547 if(propor < 0.1) propor = 0.1;
548 hitsh = propor*chgfac*hit+1.0;
551 if (absorb > game.shield) absorb = game.shield;
552 game.shield -= absorb;
554 if (game.condit==IHDOCKED) dock(false);
555 if (propor > 0.1 && hit < 0.005*game.energy) continue;
557 /* It's a hit -- print out hit size */
558 atackd = 1; /* We weren't going to check casualties, etc. if
559 shields were down for some strange reason. This
560 doesn't make any sense, so I've fixed it */
562 proutn(_("%d unit hit"), (int)hit);
563 if ((damaged(DSRSENS) && itflag) || game.skill<=SKILL_FAIR) {
564 proutn(_(" on the "));
567 if (!damaged(DSRSENS) && itflag) {
569 crmena(0, iquad, i, jay);
572 /* Decide if hit is critical */
573 if (hit > hitmax) hitmax = hit;
577 if (game.condit==IHDOCKED)
580 if (game.energy <= 0) {
581 /* Returning home upon your shield, not with it... */
585 if (attempt == 0 && game.condit == IHDOCKED)
586 prout(_("***Enemies decide against attacking your ship."));
587 if (atackd == 0) return;
588 percent = 100.0*pfac*game.shield+0.5;
590 /* Shields fully protect ship */
591 proutn(_("Enemy attack reduces shield strength to "));
594 /* Print message if starship suffered hit(s) */
596 proutn(_("Energy left %2d shields "), (int)game.energy);
597 if (game.shldup) proutn(_("up "));
598 else if (!damaged(DSHIELD)) proutn(_("down "));
599 else proutn(_("damaged, "));
601 prout(_("%d%%, torpedoes left %d"), percent, game.torps);
602 /* Check if anyone was hurt */
603 if (hitmax >= 200 || hittot >= 500) {
604 int icas= hittot*Rand()*0.015;
607 prout(_("Mc Coy- \"Sickbay to bridge. We suffered %d casualties"), icas);
608 prout(_(" in that last attack.\""));
610 game.state.crew -= icas;
613 /* After attack, reset average distance to enemies */
615 game.kavgd[l] = game.kdist[l];
620 void deadkl(coord w, int type, int ixx, int iyy)
622 /* Added ixx and iyy allow enemy to "move" before dying */
626 mv.x = ixx; mv.y = iyy;
628 crmena(1, type, 2, mv);
629 /* Decide what kind of enemy it is and update approriately */
631 /* chalk up a Romulan */
632 game.state.galaxy[game.quadrant.x][game.quadrant.y].romulans--;
634 game.state.nromrem--;
636 else if (type == IHT) {
637 /* Killed a Tholian */
640 else if (type == IHQUEST) {
641 /* Killed a Thingy */
642 iqhere=iqengry=thing.x=thing.y=0;
645 /* Some type of a Klingon */
646 game.state.galaxy[game.quadrant.x][game.quadrant.y].klingons--;
652 if (game.state.kcmdr[i].x==game.quadrant.x && game.state.kcmdr[i].y==game.quadrant.y) break;
653 game.state.kcmdr[i] = game.state.kcmdr[game.state.remcom];
654 game.state.kcmdr[game.state.remcom].x = 0;
655 game.state.kcmdr[game.state.remcom].y = 0;
658 if (game.state.remcom != 0)
659 schedule(FTBEAM, expran(1.0*game.incom/game.state.remcom));
666 game.ishere = game.state.kscmdr.x = game.state.kscmdr.y = game.isatb = game.iscate = 0;
673 /* For each kind of enemy, finish message to player */
674 prout(_(" destroyed."));
675 game.quad[w.x][w.y] = IHDOT;
676 if (KLINGREM==0) return;
678 game.state.remtime = game.state.remres/(game.state.remkl + 4*game.state.remcom);
680 /* Remove enemy ship from arrays describing local game.conditions */
681 if (is_scheduled(FCDBAS) && game.battle.x==game.quadrant.x && game.battle.y==game.quadrant.y && type==IHC)
684 if (same(game.ks[i], w)) break;
686 if (i <= game.nenhere) {
687 for (j=i; j<=game.nenhere; j++) {
688 game.ks[j] = game.ks[j+1];
689 game.kpower[j] = game.kpower[j+1];
690 game.kavgd[j] = game.kdist[j] = game.kdist[j+1];
693 game.ks[game.nenhere+1].x = 0;
694 game.ks[game.nenhere+1].x = 0;
695 game.kdist[game.nenhere+1] = 0;
696 game.kavgd[game.nenhere+1] = 0;
697 game.kpower[game.nenhere+1] = 0;
701 static bool targetcheck(double x, double y, double *course)
704 /* Return true if target is invalid */
705 if (!VALID_SECTOR(x, y)) {
709 deltx = 0.1*(y - game.sector.y);
710 delty = 0.1*(game.sector.x - x);
711 if (deltx==0 && delty== 0) {
713 prout(_("Spock- \"Bridge to sickbay. Dr. McCoy,"));
714 prout(_(" I recommend an immediate review of"));
715 prout(_(" the Captain's psychological profile.\""));
719 *course = 1.90985932*atan2(deltx, delty);
725 double targ[4][3], course[4];
727 int key, n, i, osuabor;
731 if (damaged(DPHOTON)) {
732 prout(_("Photon tubes damaged."));
736 if (game.torps == 0) {
737 prout(_("No torpedoes left."));
743 if (key == IHALPHA) {
747 else if (key == IHEOL) {
748 prout(_("%d torpedoes left."), game.torps);
749 proutn(_("Number of torpedoes to fire- "));
752 else /* key == IHREAL */ {
754 if (n <= 0) { /* abort command */
760 prout(_("Maximum of 3 torpedoes per burst."));
764 if (n <= game.torps) break;
769 for (i = 1; i <= n; i++) {
771 if (i==1 && key == IHEOL) {
772 break; /* we will try prompting */
774 if (i==2 && key == IHEOL) {
775 /* direct all torpedoes at one target */
777 targ[i][1] = targ[1][1];
778 targ[i][2] = targ[1][2];
779 course[i] = course[1];
795 if (targetcheck(targ[i][1], targ[i][2], &course[i])) return;
798 if (i == 1 && key == IHEOL) {
799 /* prompt for each one */
800 for (i = 1; i <= n; i++) {
801 proutn(_("Target sector for torpedo number %d- "), i);
815 if (targetcheck(targ[i][1], targ[i][2], &course[i])) return;
819 /* Loop for moving <n> torpedoes */
821 for (i = 1; i <= n && !osuabor; i++) {
822 if (game.condit != IHDOCKED) game.torps--;
823 r = (Rand()+Rand())*0.5 -0.5;
824 if (fabs(r) >= 0.47) {
826 r = (Rand()+1.2) * r;
828 prouts(_("***TORPEDO NUMBER %d MISFIRES"), i);
830 else prouts(_("***TORPEDO MISFIRES."));
833 prout(_(" Remainder of burst aborted."));
836 prout(_("***Photon tubes damaged by misfire."));
837 game.damage[DPHOTON] = game.damfac*(1.0+2.0*Rand());
841 if (game.shldup || game.condit == IHDOCKED)
842 r *= 1.0 + 0.0001*game.shield;
843 torpedo(course[i], r, game.sector.x, game.sector.y, &dummy, i, n);
844 if (game.alldone || game.state.galaxy[game.quadrant.x][game.quadrant.y].supernova)
847 if (KLINGREM==0) finish(FWON);
852 static void overheat(double rpow)
855 double chekbrn = (rpow-1500.)*0.00038;
856 if (Rand() <= chekbrn) {
857 prout(_("Weapons officer Sulu- \"Phasers overheated, sir.\""));
858 game.damage[DPHASER] = game.damfac*(1.0 + Rand()) * (1.0+chekbrn);
863 static int checkshctrl(double rpow)
870 prout(_("Shields lowered."));
873 /* Something bad has happened */
874 prouts(_("***RED ALERT! RED ALERT!"));
876 hit = rpow*game.shield/game.inshld;
877 game.energy -= rpow+hit*0.8;
878 game.shield -= hit*0.2;
879 if (game.energy <= 0.0) {
880 prouts(_("Sulu- \"Captain! Shield malf***********************\""));
886 prouts(_("Sulu- \"Captain! Shield malfunction! Phaser fire contained!\""));
888 prout(_("Lt. Uhura- \"Sir, all decks reporting damage.\""));
889 icas = hit*Rand()*0.012;
894 prout(_("McCoy to bridge- \"Severe radiation burns, Jim."));
895 prout(_(" %d casualties so far.\""), icas);
897 game.state.crew -= icas;
900 prout(_("Phaser energy dispersed by shields."));
901 prout(_("Enemy unaffected."));
909 double hits[21], rpow=0, extra, powrem, over, temp;
910 int kz = 0, k=1, i, irec=0; /* Cheating inhibitor */
911 int ifast=0, no=0, ipoop=1, msgflag = 1;
912 enum {NOTSET, MANUAL, FORCEMAN, AUTOMATIC} automode = NOTSET;
916 /* SR sensors and Computer */
917 if (damaged(DSRSENS) || damaged(DCOMPTR)) ipoop = 0;
918 if (game.condit == IHDOCKED) {
919 prout(_("Phasers can't be fired through base shields."));
923 if (damaged(DPHASER)) {
924 prout(_("Phaser control damaged."));
929 if (damaged(DSHCTRL)) {
930 prout(_("High speed shield control damaged."));
934 if (game.energy <= 200.0) {
935 prout(_("Insufficient energy to activate high-speed shield control."));
939 prout(_("Weapons Officer Sulu- \"High-speed shield control enabled, sir.\""));
943 /* Original code so convoluted, I re-did it all */
944 while (automode==NOTSET) {
946 if (key == IHALPHA) {
947 if (isit("manual")) {
948 if (game.nenhere==0) {
949 prout(_("There is no enemy present to select."));
959 else if (isit("automatic")) {
960 if ((!ipoop) && game.nenhere != 0) {
965 prout(_("Energy will be expended into space."));
966 automode = AUTOMATIC;
970 else if (isit("no")) {
978 else if (key == IHREAL) {
979 if (game.nenhere==0) {
980 prout(_("Energy will be expended into space."));
981 automode = AUTOMATIC;
986 automode = AUTOMATIC;
990 if (game.nenhere==0) {
991 prout(_("Energy will be expended into space."));
992 automode = AUTOMATIC;
997 proutn(_("Manual or automatic? "));
1003 if (key == IHALPHA && isit("no")) {
1007 if (key != IHREAL && game.nenhere != 0) {
1008 prout(_("Phasers locked on target. Energy available: %.2f"),
1009 ifast?game.energy-200.0:game.energy,1,2);
1014 if (!kz) for_local_enemies(i)
1015 irec+=fabs(game.kpower[i])/(PHASEFAC*pow(0.90,game.kdist[i]))*
1016 (1.01+0.05*Rand()) + 1.0;
1018 proutn(_("(%d) units required. "), irec);
1020 proutn(_("Units to fire= "));
1022 if (key!=IHREAL) return;
1024 if (rpow > (ifast?game.energy-200:game.energy)) {
1025 proutn(_("Energy available= %.2f"),
1026 ifast?game.energy-200:game.energy);
1030 } while (rpow > (ifast?game.energy-200:game.energy));
1036 if ((key=scan()) == IHALPHA && isit("no")) {
1040 game.energy -= 200; /* Go and do it! */
1041 if (checkshctrl(rpow)) return;
1044 game.energy -= rpow;
1049 for_local_enemies(i) {
1051 if (powrem <= 0) continue;
1052 hits[i] = fabs(game.kpower[i])/(PHASEFAC*pow(0.90,game.kdist[i]));
1053 over = (0.01 + 0.05*Rand())*hits[i];
1055 powrem -= hits[i] + over;
1056 if (powrem <= 0 && temp < hits[i]) hits[i] = temp;
1057 if (powrem <= 0) over = 0.0;
1060 if (powrem > 0.0) extra += powrem;
1064 if (extra > 0 && game.alldone == 0) {
1066 proutn(_("*** Tholian web absorbs "));
1067 if (game.nenhere>0) proutn(_("excess "));
1068 prout(_("phaser energy."));
1071 prout(_("%d expended on empty space."), (int)extra);
1079 if (damaged(DCOMPTR))
1080 prout(_("Battle comuter damaged, manual file only."));
1083 prouts(_("---WORKING---"));
1085 prout(_("Short-range-sensors-damaged"));
1086 prout(_("Insufficient-data-for-automatic-phaser-fire"));
1087 prout(_("Manual-fire-must-be-used"));
1092 for (k = 1; k <= game.nenhere;) {
1093 coord aim = game.ks[k];
1094 int ienm = game.quad[aim.x][aim.y];
1096 proutn(_("Energy available= %.2f"),
1097 game.energy-.006-(ifast?200:0));
1102 if (damaged(DSRSENS) && !(abs(game.sector.x-aim.x) < 2 && abs(game.sector.y-aim.y) < 2) &&
1103 (ienm == IHC || ienm == IHS)) {
1105 prout(_(" can't be located without short range scan."));
1108 hits[k] = 0; /* prevent overflow -- thanks to Alexei Voitenko */
1114 if (ipoop && k > kz)
1115 irec=(fabs(game.kpower[k])/(PHASEFAC*pow(0.9,game.kdist[k])))*
1116 (1.01+0.05*Rand()) + 1.0;
1119 if (!damaged(DCOMPTR)) proutn("%d", irec);
1122 proutn(_("units to fire at "));
1123 crmena(0, ienm, 2, aim);
1127 if (key == IHALPHA && isit("no")) {
1132 if (key == IHALPHA) {
1137 if (k==1) { /* Let me say I'm baffled by this */
1149 /* If total requested is too much, inform and start over */
1151 if (rpow > (ifast?game.energy-200:game.energy)) {
1152 prout(_("Available energy exceeded -- try again."));
1156 key = scan(); /* scan for next value */
1160 /* zero energy -- abort */
1164 if (key == IHALPHA && isit("no")) {
1167 game.energy -= rpow;
1170 game.energy -= 200.0;
1171 if (checkshctrl(rpow)) return;
1175 case NOTSET:; /* avoid gcc warning */
1177 /* Say shield raised or malfunction, if necessary */
1183 if (Rand() >= 0.99) {
1184 prout(_("Sulu- \"Sir, the high-speed shield control has malfunctioned . . ."));
1185 prouts(_(" CLICK CLICK POP . . ."));
1186 prout(_(" No response, sir!"));
1187 game.shldup = false;
1190 prout(_("Shields raised."));
1193 game.shldup = false;
1198 void hittem(double *hits)
1200 double kp, kpow, wham, hit, dustfac, kpini;
1201 int nenhr2=game.nenhere, k=1, kk=1, ienm;
1206 for (; k <= nenhr2; k++, kk++) {
1207 if ((wham = hits[k])==0) continue;
1208 dustfac = 0.9 + 0.01*Rand();
1209 hit = wham*pow(dustfac,game.kdist[kk]);
1210 kpini = game.kpower[kk];
1212 if (PHASEFAC*hit < kp) kp = PHASEFAC*hit;
1213 game.kpower[kk] -= (game.kpower[kk] < 0 ? -kp: kp);
1214 kpow = game.kpower[kk];
1217 if (!damaged(DSRSENS))
1219 proutn(_("%d unit hit on "), (int)hit);
1222 proutn(_("Very small hit on "));
1223 ienm = game.quad[w.x][w.y];
1224 if (ienm==IHQUEST) iqengry=1;
1228 deadkl(w, ienm, w.x, w.y);
1229 if (KLINGREM==0) finish(FWON);
1230 if (game.alldone) return;
1231 kk--; /* don't do the increment */
1233 else /* decide whether or not to emasculate klingon */
1234 if (kpow > 0 && Rand() >= 0.9 &&
1235 kpow <= ((0.4 + 0.4*Rand())*kpini)) {
1236 prout(_("***Mr. Spock- \"Captain, the vessel at "),
1238 prout(_(" has just lost its firepower.\""));
1239 game.kpower[kk] = -kpow;