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, 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, 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, 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 = NOPLANET;
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 IHW: /* Hit an inhabited world -- very bad! */
332 crmena(1, iquad, 2, w);
333 prout(_(" destroyed."));
334 game.state.nworldkl++;
335 game.state.galaxy[game.quadrant.x][game.quadrant.y].planet = NOPLANET;
336 DESTROY(&game.state.plnets[game.iplnet]);
338 game.plnet.x = game.plnet.y = 0;
339 game.quad[w.x][w.y] = IHDOT;
340 if (game.landed==1) {
341 /* captain perishes on planet */
344 prout("You have just destroyed an inhabited planet.");
345 prout("Celebratory rallies are being held on the Klingon homeworld.");
347 case IHSTAR: /* Hit a star */
352 crmena(1, IHSTAR, 2, w);
353 prout(_(" unaffected by photon blast."));
355 case IHQUEST: /* Hit a thingy */
356 if (!(game.options & OPTION_THINGY) || Rand()>0.7) {
358 prouts(_("AAAAIIIIEEEEEEEEAAAAAAAAUUUUUGGGGGHHHHHHHHHHHH!!!"));
360 prouts(_(" HACK! HACK! HACK! *CHOKE!* "));
362 proutn(_("Mr. Spock-"));
363 prouts(_(" \"Fascinating!\""));
365 deadkl(w, iquad, w.x, w.y);
368 * Stas Sergeev added the possibility that
369 * you can shove the Thingy and piss it off.
370 * It then becomes an enemy and may fire at you.
376 case IHBLANK: /* Black hole */
378 crmena(1, IHBLANK, 2, w);
379 prout(_(" swallows torpedo."));
381 case IHWEB: /* hit the web */
383 prout(_("***Torpedo absorbed by Tholian web."));
385 case IHT: /* Hit a Tholian */
386 h1 = 700.0 + 100.0*Rand() -
387 1000.0*sqrt(square(w.x-inx)+square(w.y-iny))*
388 fabs(sin(bullseye-angle));
391 game.quad[w.x][w.y] = IHDOT;
393 game.tholian.x = game.tholian.y = 0;
394 deadkl(w, iquad, w.x, w.y);
398 crmena(1, IHT, 2, w);
400 prout(_(" survives photon blast."));
403 prout(_(" disappears."));
404 game.quad[w.x][w.y] = IHWEB;
405 game.ithere = game.tholian.x = game.tholian.y = 0;
409 dropin(IHBLANK, &dummy);
413 default: /* Problem! */
415 proutn("Don't know how to handle collision with ");
416 crmena(1, iquad, 2, w);
422 if(curwnd!=message_window) {
423 setwnd(message_window);
428 game.quad[jx][jy]=iquad;
429 game.quad[w.x][w.y]=IHDOT;
430 prout(_(" displaced by blast to %s "), cramlc(sector, w));
431 for_local_enemies(ll)
432 game.kdist[ll] = game.kavgd[ll] = sqrt(square(game.sector.x-game.ks[ll].x)+square(game.sector.y-game.ks[ll].y));
437 prout(_("Torpedo missed."));
441 static void fry(double hit)
443 double ncrit, extradm;
444 int ktr=1, l, ll, j, cdam[NDEVICES];
446 /* a critical hit occured */
447 if (hit < (275.0-25.0*game.skill)*(1.0+0.5*Rand())) return;
449 ncrit = 1.0 + hit/(500.0+100.0*Rand());
450 proutn(_("***CRITICAL HIT--"));
451 /* Select devices and cause damage */
452 for (l = 0; l < ncrit && 0 < NDEVICES; l++) {
455 /* Cheat to prevent shuttle damage unless on ship */
457 (game.damage[j]<0.0 || (j==DSHUTTL && game.iscraft!=1) || j==DDRAY);
459 extradm = (hit*game.damfac)/(ncrit*(75.0+25.0*Rand()));
460 game.damage[j] += extradm;
462 for (ll=2; ll<=l && j != cdam[ll-1]; ll++) ;
470 prout(_(" damaged."));
471 if (game.damage[DSHIELD] && game.shldup) {
472 prout(_("***Shields knocked down."));
477 void attack(int torps_ok)
479 /* torps_ok == 0 forces use of phasers in an attack */
480 int percent, ihurt=0, l, i=0, iquad, itflag;
481 int atackd = 0, attempt = 0;
483 double pfac, dustfac, hitmax=0.0, hittot=0.0, chgfac=1.0, r;
487 if (game.alldone) return;
488 if (idebug) prout("=== ATTACK!");
490 if (game.ithere) movetho();
492 if (game.neutz) { /* The one chance not to be attacked */
496 if ((((game.comhere || game.ishere) && (game.justin == 0)) || game.skill == SKILL_EMERITUS)&&(torps_ok!=0)) movcom();
497 if (game.nenhere==0 || (game.nenhere==1 && iqhere && iqengry==0)) return;
498 pfac = 1.0/game.inshld;
499 if (game.shldchg == 1) chgfac = 0.25+0.5*Rand();
501 if (game.skill <= SKILL_FAIR) i = 2;
502 for_local_enemies(l) {
503 if (game.kpower[l] < 0) continue; /* too weak to attack */
504 /* compute hit strength and diminsh shield power */
506 /* Increase chance of photon torpedos if docked or enemy energy low */
507 if (game.condit == IHDOCKED) r *= 0.25;
508 if (game.kpower[l] < 500) r *= 0.25;
509 jay.x = game.ks[l].x;
510 jay.y = game.ks[l].y;
511 iquad = game.quad[jay.x][jay.y];
512 if (iquad==IHT || (iquad==IHQUEST && !iqengry)) continue;
513 itflag = (iquad == IHK && r > 0.0005) || !torps_ok ||
514 (iquad==IHC && r > 0.015) ||
515 (iquad==IHR && r > 0.3) ||
516 (iquad==IHS && r > 0.07) ||
517 (iquad==IHQUEST && r > 0.05);
519 /* Enemy uses phasers */
520 if (game.condit == IHDOCKED) continue; /* Don't waste the effort! */
521 attempt = 1; /* Attempt to attack */
522 dustfac = 0.8+0.05*Rand();
523 hit = game.kpower[l]*pow(dustfac,game.kavgd[l]);
524 game.kpower[l] *= 0.75;
526 else { /* Enemy used photon torpedo */
527 double course = 1.90985*atan2((double)game.sector.y-jay.y, (double)jay.x-game.sector.x);
529 proutn(_("***TORPEDO INCOMING"));
530 if (game.damage[DSRSENS] <= 0.0) {
532 crmena(0, iquad, i, jay);
536 r = (Rand()+Rand())*0.5 -0.5;
537 r += 0.002*game.kpower[l]*r;
538 torpedo(course, r, jay.x, jay.y, &hit, 1, 1);
540 finish(FWON); /* Klingons did themselves in! */
541 if (game.state.galaxy[game.quadrant.x][game.quadrant.y].supernova || game.alldone)
542 return; /* Supernova or finished */
543 if (hit == 0) continue;
545 if (game.shldup || game.shldchg != 0 || game.condit==IHDOCKED) {
546 /* shields will take hits */
547 double absorb, hitsh, propor = pfac*game.shield*(game.condit==IHDOCKED ? 2.1 : 1.0);
548 if(propor < 0.1) propor = 0.1;
549 hitsh = propor*chgfac*hit+1.0;
552 if (absorb > game.shield) absorb = game.shield;
553 game.shield -= absorb;
555 if (game.condit==IHDOCKED) dock(0);
556 if (propor > 0.1 && hit < 0.005*game.energy) continue;
558 /* It's a hit -- print out hit size */
559 atackd = 1; /* We weren't going to check casualties, etc. if
560 shields were down for some strange reason. This
561 doesn't make any sense, so I've fw.xed it */
563 proutn(_("%d unit hit"), (int)hit);
564 if ((game.damage[DSRSENS] > 0 && itflag) || game.skill<=SKILL_FAIR) {
565 proutn(_(" on the "));
568 if (game.damage[DSRSENS] <= 0.0 && itflag) {
570 crmena(0, iquad, i, jay);
573 /* Decide if hit is critical */
574 if (hit > hitmax) hitmax = hit;
578 if (game.condit==IHDOCKED)
581 if (game.energy <= 0) {
582 /* Returning home upon your shield, not with it... */
586 if (attempt == 0 && game.condit == IHDOCKED)
587 prout(_("***Enemies decide against attacking your ship."));
588 if (atackd == 0) return;
589 percent = 100.0*pfac*game.shield+0.5;
591 /* Shields fully protect ship */
592 proutn(_("Enemy attack reduces shield strength to "));
595 /* Print message if starship suffered hit(s) */
597 proutn(_("Energy left %2d shields "), (int)game.energy);
598 if (game.shldup) proutn(_("up "));
599 else if (game.damage[DSHIELD] == 0) proutn(_("down "));
600 else proutn(_("damaged, "));
602 prout(_("%d%%, torpedoes left %d"), percent, game.torps);
603 /* Check if anyone was hurt */
604 if (hitmax >= 200 || hittot >= 500) {
605 int icas= hittot*Rand()*0.015;
608 prout(_("Mc Coy- \"Sickbay to bridge. We suffered %d casualties"), icas);
609 prout(_(" in that last attack.\""));
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 (game.damage[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);
899 prout(_("Phaser energy dispersed by shields."));
900 prout(_("Enemy unaffected."));
908 double hits[21], rpow=0, extra, powrem, over, temp;
909 int kz = 0, k=1, i, irec=0; /* Cheating inhibitor */
910 int ifast=0, no=0, ipoop=1, msgflag = 1;
911 enum {NOTSET, MANUAL, FORCEMAN, AUTOMATIC} automode = NOTSET;
915 /* SR sensors and Computer */
916 if (game.damage[DSRSENS]+game.damage[DCOMPTR] > 0) ipoop = 0;
917 if (game.condit == IHDOCKED) {
918 prout(_("Phasers can't be fired through base shields."));
922 if (game.damage[DPHASER] != 0) {
923 prout(_("Phaser control damaged."));
928 if (game.damage[DSHCTRL]) {
929 prout(_("High speed shield control damaged."));
933 if (game.energy <= 200.0) {
934 prout(_("Insufficient energy to activate high-speed shield control."));
938 prout(_("Weapons Officer Sulu- \"High-speed shield control enabled, sir.\""));
942 /* Original code so convoluted, I re-did it all */
943 while (automode==NOTSET) {
945 if (key == IHALPHA) {
946 if (isit("manual")) {
947 if (game.nenhere==0) {
948 prout(_("There is no enemy present to select."));
958 else if (isit("automatic")) {
959 if ((!ipoop) && game.nenhere != 0) {
964 prout(_("Energy will be expended into space."));
965 automode = AUTOMATIC;
969 else if (isit("no")) {
977 else if (key == IHREAL) {
978 if (game.nenhere==0) {
979 prout(_("Energy will be expended into space."));
980 automode = AUTOMATIC;
985 automode = AUTOMATIC;
989 if (game.nenhere==0) {
990 prout(_("Energy will be expended into space."));
991 automode = AUTOMATIC;
996 proutn(_("Manual or automatic? "));
1002 if (key == IHALPHA && isit("no")) {
1006 if (key != IHREAL && game.nenhere != 0) {
1007 prout(_("Phasers locked on target. Energy available: %.2f"),
1008 ifast?game.energy-200.0:game.energy,1,2);
1013 if (!kz) for_local_enemies(i)
1014 irec+=fabs(game.kpower[i])/(PHASEFAC*pow(0.90,game.kdist[i]))*
1015 (1.01+0.05*Rand()) + 1.0;
1017 proutn(_("(%d) units required. "), irec);
1019 proutn(_("Units to fire= "));
1021 if (key!=IHREAL) return;
1023 if (rpow > (ifast?game.energy-200:game.energy)) {
1024 proutn(_("Energy available= %.2f"),
1025 ifast?game.energy-200:game.energy);
1029 } while (rpow > (ifast?game.energy-200:game.energy));
1035 if ((key=scan()) == IHALPHA && isit("no")) {
1039 game.energy -= 200; /* Go and do it! */
1040 if (checkshctrl(rpow)) return;
1043 game.energy -= rpow;
1048 for_local_enemies(i) {
1050 if (powrem <= 0) continue;
1051 hits[i] = fabs(game.kpower[i])/(PHASEFAC*pow(0.90,game.kdist[i]));
1052 over = (0.01 + 0.05*Rand())*hits[i];
1054 powrem -= hits[i] + over;
1055 if (powrem <= 0 && temp < hits[i]) hits[i] = temp;
1056 if (powrem <= 0) over = 0.0;
1059 if (powrem > 0.0) extra += powrem;
1063 if (extra > 0 && game.alldone == 0) {
1065 proutn(_("*** Tholian web absorbs "));
1066 if (game.nenhere>0) proutn(_("excess "));
1067 prout(_("phaser energy."));
1070 prout(_("%d expended on empty space."), (int)extra);
1078 if (game.damage[DCOMPTR]!=0)
1079 prout(_("Battle comuter damaged, manual file only."));
1082 prouts(_("---WORKING---"));
1084 prout(_("Short-range-sensors-damaged"));
1085 prout(_("Insufficient-data-for-automatic-phaser-fire"));
1086 prout(_("Manual-fire-must-be-used"));
1091 for (k = 1; k <= game.nenhere;) {
1092 coord aim = game.ks[k];
1093 int ienm = game.quad[aim.x][aim.y];
1095 proutn(_("Energy available= %.2f"),
1096 game.energy-.006-(ifast?200:0));
1101 if (game.damage[DSRSENS] && !(abs(game.sector.x-aim.x) < 2 && abs(game.sector.y-aim.y) < 2) &&
1102 (ienm == IHC || ienm == IHS)) {
1104 prout(_(" can't be located without short range scan."));
1107 hits[k] = 0; /* prevent overflow -- thanks to Alexei Voitenko */
1113 if (ipoop && k > kz)
1114 irec=(fabs(game.kpower[k])/(PHASEFAC*pow(0.9,game.kdist[k])))*
1115 (1.01+0.05*Rand()) + 1.0;
1118 if (game.damage[DCOMPTR]==0) proutn("%d", irec);
1121 proutn(_("units to fire at "));
1122 crmena(0, ienm, 2, aim);
1126 if (key == IHALPHA && isit("no")) {
1131 if (key == IHALPHA) {
1136 if (k==1) { /* Let me say I'm baffled by this */
1148 /* If total requested is too much, inform and start over */
1150 if (rpow > (ifast?game.energy-200:game.energy)) {
1151 prout(_("Available energy exceeded -- try again."));
1155 key = scan(); /* scan for next value */
1159 /* zero energy -- abort */
1163 if (key == IHALPHA && isit("no")) {
1166 game.energy -= rpow;
1169 game.energy -= 200.0;
1170 if (checkshctrl(rpow)) return;
1174 case NOTSET:; /* avoid gcc warning */
1176 /* Say shield raised or malfunction, if necessary */
1182 if (Rand() >= 0.99) {
1183 prout(_("Sulu- \"Sir, the high-speed shield control has malfunctioned . . ."));
1184 prouts(_(" CLICK CLICK POP . . ."));
1185 prout(_(" No response, sir!"));
1186 game.shldup = false;
1189 prout(_("Shields raised."));
1192 game.shldup = false;
1197 void hittem(double *hits)
1199 double kp, kpow, wham, hit, dustfac, kpini;
1200 int nenhr2=game.nenhere, k=1, kk=1, ienm;
1205 for (; k <= nenhr2; k++, kk++) {
1206 if ((wham = hits[k])==0) continue;
1207 dustfac = 0.9 + 0.01*Rand();
1208 hit = wham*pow(dustfac,game.kdist[kk]);
1209 kpini = game.kpower[kk];
1211 if (PHASEFAC*hit < kp) kp = PHASEFAC*hit;
1212 game.kpower[kk] -= (game.kpower[kk] < 0 ? -kp: kp);
1213 kpow = game.kpower[kk];
1216 if (game.damage[DSRSENS]==0)
1218 proutn(_("%d unit hit on "), (int)hit);
1221 proutn(_("Very small hit on "));
1222 ienm = game.quad[w.x][w.y];
1223 if (ienm==IHQUEST) iqengry=1;
1227 deadkl(w, ienm, w.x, w.y);
1228 if (KLINGREM==0) finish(FWON);
1229 if (game.alldone) return;
1230 kk--; /* don't do the increment */
1232 else /* decide whether or not to emasculate klingon */
1233 if (kpow > 0 && Rand() >= 0.9 &&
1234 kpow <= ((0.4 + 0.4*Rand())*kpini)) {
1235 prout(_("***Mr. Spock- \"Captain, the vessel at "),
1237 prout(_(" has just lost its firepower.\""));
1238 game.kpower[kk] = -kpow;