4 /* change shield status */
7 enum {NONE, SHUP, SHDN, NRG} action = NONE;
11 if (i == 2) action = SHUP;
19 if (!damaged(DSHIELD)) {
20 prout(_("Shields damaged and down."));
25 else if (isit("down"))
30 proutn(_("Do you wish to change shield energy? "));
32 proutn(_("Energy to transfer to shields- "));
35 else if (damaged(DSHIELD)) {
36 prout(_("Shields damaged and down."));
39 else if (game.shldup) {
40 proutn(_("Shields are up. Do you want them down? "));
41 if (ja() == true) action = SHDN;
48 proutn(_("Shields are down. Do you want them up? "));
49 if (ja() == true) action = SHUP;
58 case SHUP: /* raise shields */
60 prout(_("Shields already up."));
65 if (game.condit != IHDOCKED) game.energy -= 50.0;
66 prout(_("Shields raised."));
67 if (game.energy <= 0) {
69 prout(_("Shields raising uses up last of energy."));
77 prout(_("Shields already down."));
82 prout(_("Shields lowered."));
86 while (scan() != IHREAL) {
88 proutn(_("Energy to transfer to shields- "));
91 if (aaitem==0) return;
92 if (aaitem > game.energy) {
93 prout(_("Insufficient ship energy."));
97 if (game.shield+aaitem >= game.inshld) {
98 prout(_("Shield energy maximized."));
99 if (game.shield+aaitem > game.inshld) {
100 prout(_("Excess energy requested returned to ship energy"));
102 game.energy -= game.inshld-game.shield;
103 game.shield = game.inshld;
106 if (aaitem < 0.0 && game.energy-aaitem > game.inenrg) {
107 /* Prevent shield drain loophole */
109 prout(_("Engineering to bridge--"));
110 prout(_(" Scott here. Power circuit problem, Captain."));
111 prout(_(" I can't drain the shields."));
115 if (game.shield+aaitem < 0) {
116 prout(_("All shield energy transferred to ship."));
117 game.energy += game.shield;
121 proutn(_("Scotty- \""));
123 prout(_("Transferring energy to shields.\""));
125 prout(_("Draining energy from shields.\""));
126 game.shield += aaitem;
127 game.energy -= aaitem;
129 case NONE:; /* avoid gcc warning */
133 void ram(bool ibumpd, int ienm, coord w)
134 /* make our ship ram something */
136 double type = 1.0, extradm;
139 prouts(_("***RED ALERT! RED ALERT!"));
141 prout(_("***COLLISION IMMINENT."));
146 case IHR: type = 1.5; break;
147 case IHC: type = 2.0; break;
148 case IHS: type = 2.5; break;
149 case IHT: type = 0.5; break;
150 case IHQUEST: type = 4.0; break;
152 proutn(ibumpd ? _(" rammed by ") : _(" rams "));
153 crmena(false, ienm, sector, w);
154 if (ibumpd) proutn(_(" (original position)"));
156 deadkl(w, ienm, game.sector.x, game.sector.y);
159 prout(_(" heavily damaged."));
160 icas = 10.0+20.0*Rand();
161 prout(_("***Sickbay reports %d casualties"), icas);
163 game.state.crew -= icas;
164 for (m=0; m < NDEVICES; m++) {
166 continue; // Don't damage deathray
167 if (game.damage[m] < 0)
169 extradm = (10.0*type*Rand()+1.0)*game.damfac;
170 game.damage[m] += game.optime + extradm; /* Damage for at least time of travel! */
181 void torpedo(double course, double r, int inx, int iny, double *hit, int i, int n)
182 /* let a photon torpedo fly */
184 int l, iquad=0, jx=0, jy=0, shoved=0, ll;
186 double ac=course + 0.25*r;
187 double angle = (15.0-ac)*0.5235988;
188 double bullseye = (15.0 - course)*0.5235988;
189 double deltax=-sin(angle), deltay=cos(angle), x=inx, y=iny, bigger;
190 double ang, temp, xx, yy, kp, h1;
194 bigger = fabs(deltax);
195 if (fabs(deltay) > bigger) bigger = fabs(deltay);
198 if (!damaged(DSRSENS) || game.condit==IHDOCKED)
199 setwnd(srscan_window);
201 setwnd(message_window);
202 /* Loop to move a single torpedo */
203 for (l=1; l <= 15; l++) {
208 if (!VALID_SECTOR(w.x, w.y)) break;
209 iquad=game.quad[w.x][w.y];
210 tracktorpedo(w.x, w.y, l, i, n, iquad);
211 if (iquad==IHDOT) continue;
213 setwnd(message_window);
214 skip(1); /* start new line after text track */
216 case IHE: /* Hit our ship */
219 proutn(_("Torpedo hits "));
222 *hit = 700.0 + 100.0*Rand() -
223 1000.0*sqrt(square(w.x-inx)+square(w.y-iny))*
224 fabs(sin(bullseye-angle));
226 newcnd(); /* we're blown out of dock */
227 /* We may be displaced. */
228 if (game.landed==1 || game.condit==IHDOCKED) return; /* Cheat if on a planet */
229 ang = angle + 2.5*(Rand()-0.5);
230 temp = fabs(sin(ang));
231 if (fabs(cos(ang)) > temp) temp = fabs(cos(ang));
236 if (!VALID_SECTOR(jx, jy)) return;
237 if (game.quad[jx][jy]==IHBLANK) {
241 if (game.quad[jx][jy]!=IHDOT) {
242 /* can't move into object */
251 case IHC: /* Hit a commander */
253 if (Rand() <= 0.05) {
254 crmena(true, iquad, sector, w);
255 prout(_(" uses anti-photon device;"));
256 prout(_(" torpedo neutralized."));
259 case IHR: /* Hit a regular enemy */
262 for_local_enemies(ll)
263 if (w.x==game.ks[ll].x && w.y==game.ks[ll].y) break;
264 kp = fabs(game.kpower[ll]);
265 h1 = 700.0 + 100.0*Rand() -
266 1000.0*sqrt(square(w.x-inx)+square(w.y-iny))*
267 fabs(sin(bullseye-angle));
269 if (kp < h1) h1 = kp;
270 game.kpower[ll] -= (game.kpower[ll]<0 ? -h1 : h1);
271 if (game.kpower[ll] == 0) {
272 deadkl(w, iquad, w.x, w.y);
275 crmena(true, iquad, sector, w);
276 /* If enemy damaged but not destroyed, try to displace */
277 ang = angle + 2.5*(Rand()-0.5);
278 temp = fabs(sin(ang));
279 if (fabs(cos(ang)) > temp) temp = fabs(cos(ang));
284 if (!VALID_SECTOR(jx, jy)) {
285 prout(_(" damaged but not destroyed."));
288 if (game.quad[jx][jy]==IHBLANK) {
289 prout(_(" buffeted into black hole."));
290 deadkl(w, iquad, jx, jy);
293 if (game.quad[jx][jy]!=IHDOT) {
294 /* can't move into object */
295 prout(_(" damaged but not destroyed."));
298 proutn(_(" damaged--"));
303 case IHB: /* Hit a base */
305 prout(_("***STARBASE DESTROYED.."));
307 if (game.state.baseq[ll].x==game.quadrant.x && game.state.baseq[ll].y==game.quadrant.y) {
308 game.state.baseq[ll].x=game.state.baseq[game.state.rembase].x;
309 game.state.baseq[ll].y=game.state.baseq[game.state.rembase].y;
313 game.quad[w.x][w.y]=IHDOT;
314 game.state.rembase--;
315 game.base.x=game.base.y=0;
316 game.state.galaxy[game.quadrant.x][game.quadrant.y].starbase--;
317 game.state.chart[game.quadrant.x][game.quadrant.y].starbase--;
321 case IHP: /* Hit a planet */
322 crmena(true, iquad, sector, w);
323 prout(_(" destroyed."));
324 game.state.nplankl++;
325 game.state.galaxy[game.quadrant.x][game.quadrant.y].planet = NOPLANET;
326 DESTROY(&game.state.plnets[game.iplnet]);
328 game.plnet.x = game.plnet.y = 0;
329 game.quad[w.x][w.y] = IHDOT;
330 if (game.landed==1) {
331 /* captain perishes on planet */
335 case IHW: /* Hit an inhabited world -- very bad! */
336 crmena(true, iquad, sector, w);
337 prout(_(" destroyed."));
338 game.state.nworldkl++;
339 game.state.galaxy[game.quadrant.x][game.quadrant.y].planet = NOPLANET;
340 DESTROY(&game.state.plnets[game.iplnet]);
342 game.plnet.x = game.plnet.y = 0;
343 game.quad[w.x][w.y] = IHDOT;
344 if (game.landed==1) {
345 /* captain perishes on planet */
348 prout("You have just destroyed an inhabited planet.");
349 prout("Celebratory rallies are being held on the Klingon homeworld.");
351 case IHSTAR: /* Hit a star */
356 crmena(true, IHSTAR, sector, w);
357 prout(_(" unaffected by photon blast."));
359 case IHQUEST: /* Hit a thingy */
360 if (!(game.options & OPTION_THINGY) || Rand()>0.7) {
362 prouts(_("AAAAIIIIEEEEEEEEAAAAAAAAUUUUUGGGGGHHHHHHHHHHHH!!!"));
364 prouts(_(" HACK! HACK! HACK! *CHOKE!* "));
366 proutn(_("Mr. Spock-"));
367 prouts(_(" \"Fascinating!\""));
369 deadkl(w, iquad, w.x, w.y);
372 * Stas Sergeev added the possibility that
373 * you can shove the Thingy and piss it off.
374 * It then becomes an enemy and may fire at you.
380 case IHBLANK: /* Black hole */
382 crmena(true, IHBLANK, sector, w);
383 prout(_(" swallows torpedo."));
385 case IHWEB: /* hit the web */
387 prout(_("***Torpedo absorbed by Tholian web."));
389 case IHT: /* Hit a Tholian */
390 h1 = 700.0 + 100.0*Rand() -
391 1000.0*sqrt(square(w.x-inx)+square(w.y-iny))*
392 fabs(sin(bullseye-angle));
395 game.quad[w.x][w.y] = IHDOT;
397 game.tholian.x = game.tholian.y = 0;
398 deadkl(w, iquad, w.x, w.y);
402 crmena(true, IHT, sector, w);
404 prout(_(" survives photon blast."));
407 prout(_(" disappears."));
408 game.quad[w.x][w.y] = IHWEB;
409 game.ithere = game.tholian.x = game.tholian.y = 0;
413 dropin(IHBLANK, &dummy);
417 default: /* Problem! */
419 proutn("Don't know how to handle collision with ");
420 crmena(true, iquad, sector, w);
426 if(curwnd!=message_window) {
427 setwnd(message_window);
430 game.quad[w.x][w.y]=IHDOT;
431 game.quad[jx][jy]=iquad;
432 prout(_(" displaced by blast to %s "), cramlc(sector, w));
433 for_local_enemies(ll)
434 game.kdist[ll] = game.kavgd[ll] = sqrt(square(game.sector.x-game.ks[ll].x)+square(game.sector.y-game.ks[ll].y));
439 prout(_("Torpedo missed."));
443 static void fry(double hit)
444 /* critical-hit resolution */
446 double ncrit, extradm;
447 int ktr=1, loop1, loop2, j, cdam[NDEVICES];
449 /* a critical hit occured */
450 if (hit < (275.0-25.0*game.skill)*(1.0+0.5*Rand())) return;
452 ncrit = 1.0 + hit/(500.0+100.0*Rand());
453 proutn(_("***CRITICAL HIT--"));
454 /* Select devices and cause damage */
455 for (loop1 = 0; loop1 < ncrit && 0 < NDEVICES; loop1++) {
458 /* Cheat to prevent shuttle damage unless on ship */
460 (game.damage[j]<0.0 || (j==DSHUTTL && game.iscraft!=1) || j==DDRAY);
462 extradm = (hit*game.damfac)/(ncrit*(75.0+25.0*Rand()));
463 game.damage[j] += extradm;
465 for (loop2=2; loop2<=loop1 && j != cdam[loop2-1]; loop2++) ;
466 if (loop2<=loop1) continue;
473 prout(_(" damaged."));
474 if (damaged(DSHIELD) && game.shldup) {
475 prout(_("***Shields knocked down."));
480 void attack(bool torps_ok)
481 /* bad guy attacks us */
483 /* torps_ok == false forces use of phasers in an attack */
484 int percent, loop, iquad;
485 bool itflag, atackd = false, attempt = false, ihurt = false;
486 double hit, pfac, dustfac, hitmax=0.0, hittot=0.0, chgfac=1.0, r;
488 enum loctype where = neither;
491 if (game.alldone) return;
492 if (idebug) prout("=== ATTACK!");
494 if (game.ithere) movetho();
496 if (game.neutz) { /* The one chance not to be attacked */
500 if ((((game.comhere || game.ishere) && !game.justin) || game.skill == SKILL_EMERITUS) && torps_ok) movcom();
501 if (game.nenhere==0 || (game.nenhere==1 && iqhere && iqengry==0)) return;
502 pfac = 1.0/game.inshld;
503 if (game.shldchg == 1) chgfac = 0.25+0.5*Rand();
505 if (game.skill <= SKILL_FAIR) where = sector;
506 for_local_enemies(loop) {
507 if (game.kpower[loop] < 0) continue; /* too weak to attack */
508 /* compute hit strength and diminsh shield power */
510 /* Increase chance of photon torpedos if docked or enemy energy low */
511 if (game.condit == IHDOCKED) r *= 0.25;
512 if (game.kpower[loop] < 500) r *= 0.25;
513 jay.x = game.ks[loop].x;
514 jay.y = game.ks[loop].y;
515 iquad = game.quad[jay.x][jay.y];
516 if (iquad==IHT || (iquad==IHQUEST && !iqengry)) continue;
517 itflag = (iquad == IHK && r > 0.0005) || !torps_ok ||
518 (iquad==IHC && r > 0.015) ||
519 (iquad==IHR && r > 0.3) ||
520 (iquad==IHS && r > 0.07) ||
521 (iquad==IHQUEST && r > 0.05);
523 /* Enemy uses phasers */
524 if (game.condit == IHDOCKED) continue; /* Don't waste the effort! */
525 attempt = true; /* Attempt to attack */
526 dustfac = 0.8+0.05*Rand();
527 hit = game.kpower[loop]*pow(dustfac,game.kavgd[loop]);
528 game.kpower[loop] *= 0.75;
530 else { /* Enemy used photon torpedo */
531 double course = 1.90985*atan2((double)game.sector.y-jay.y, (double)jay.x-game.sector.x);
533 proutn(_("***TORPEDO INCOMING"));
534 if (!damaged(DSRSENS)) {
536 crmena(false, iquad, where, jay);
540 r = (Rand()+Rand())*0.5 -0.5;
541 r += 0.002*game.kpower[loop]*r;
542 torpedo(course, r, jay.x, jay.y, &hit, 1, 1);
544 finish(FWON); /* Klingons did themselves in! */
545 if (game.state.galaxy[game.quadrant.x][game.quadrant.y].supernova || game.alldone)
546 return; /* Supernova or finished */
547 if (hit == 0) continue;
549 if (game.shldup || game.shldchg != 0 || game.condit==IHDOCKED) {
550 /* shields will take hits */
551 double absorb, hitsh, propor = pfac*game.shield*(game.condit==IHDOCKED ? 2.1 : 1.0);
552 if(propor < 0.1) propor = 0.1;
553 hitsh = propor*chgfac*hit+1.0;
556 if (absorb > game.shield) absorb = game.shield;
557 game.shield -= absorb;
559 if (game.condit==IHDOCKED) dock(false);
560 if (propor > 0.1 && hit < 0.005*game.energy) continue;
562 /* It's a hit -- print out hit size */
563 atackd = true; /* We weren't going to check casualties, etc. if
564 shields were down for some strange reason. This
565 doesn't make any sense, so I've fixed it */
567 proutn(_("%d unit hit"), (int)hit);
568 if ((damaged(DSRSENS) && itflag) || game.skill<=SKILL_FAIR) {
569 proutn(_(" on the "));
572 if (!damaged(DSRSENS) && itflag) {
574 crmena(false, iquad, where, jay);
577 /* Decide if hit is critical */
578 if (hit > hitmax) hitmax = hit;
582 if (game.condit==IHDOCKED)
585 if (game.energy <= 0) {
586 /* Returning home upon your shield, not with it... */
590 if (!attempt && game.condit == IHDOCKED)
591 prout(_("***Enemies decide against attacking your ship."));
593 percent = 100.0*pfac*game.shield+0.5;
595 /* Shields fully protect ship */
596 proutn(_("Enemy attack reduces shield strength to "));
599 /* Print message if starship suffered hit(s) */
601 proutn(_("Energy left %2d shields "), (int)game.energy);
602 if (game.shldup) proutn(_("up "));
603 else if (!damaged(DSHIELD)) proutn(_("down "));
604 else proutn(_("damaged, "));
606 prout(_("%d%%, torpedoes left %d"), percent, game.torps);
607 /* Check if anyone was hurt */
608 if (hitmax >= 200 || hittot >= 500) {
609 int icas= hittot*Rand()*0.015;
612 prout(_("Mc Coy- \"Sickbay to bridge. We suffered %d casualties"), icas);
613 prout(_(" in that last attack.\""));
615 game.state.crew -= icas;
618 /* After attack, reset average distance to enemies */
619 for_local_enemies(loop)
620 game.kavgd[loop] = game.kdist[loop];
625 void deadkl(coord w, int type, int ixx, int iyy)
626 /* kill a Klingon, Tholian, Romulan, or Thingy */
628 /* Added ixx and iyy allow enemy to "move" before dying */
632 mv.x = ixx; mv.y = iyy;
634 crmena(true, type, sector, mv);
635 /* Decide what kind of enemy it is and update approriately */
637 /* chalk up a Romulan */
638 game.state.galaxy[game.quadrant.x][game.quadrant.y].romulans--;
640 game.state.nromrem--;
642 else if (type == IHT) {
643 /* Killed a Tholian */
646 else if (type == IHQUEST) {
647 /* Killed a Thingy */
648 iqhere=iqengry=thing.x=thing.y=0;
651 /* Some type of a Klingon */
652 game.state.galaxy[game.quadrant.x][game.quadrant.y].klingons--;
658 if (game.state.kcmdr[i].x==game.quadrant.x && game.state.kcmdr[i].y==game.quadrant.y) break;
659 game.state.kcmdr[i] = game.state.kcmdr[game.state.remcom];
660 game.state.kcmdr[game.state.remcom].x = 0;
661 game.state.kcmdr[game.state.remcom].y = 0;
664 if (game.state.remcom != 0)
665 schedule(FTBEAM, expran(1.0*game.incom/game.state.remcom));
672 game.ishere = game.state.kscmdr.x = game.state.kscmdr.y = game.isatb = game.iscate = 0;
679 /* For each kind of enemy, finish message to player */
680 prout(_(" destroyed."));
681 game.quad[w.x][w.y] = IHDOT;
682 if (KLINGREM==0) return;
684 game.state.remtime = game.state.remres/(game.state.remkl + 4*game.state.remcom);
686 /* Remove enemy ship from arrays describing local game.conditions */
687 if (is_scheduled(FCDBAS) && game.battle.x==game.quadrant.x && game.battle.y==game.quadrant.y && type==IHC)
690 if (same(game.ks[i], w)) break;
692 if (i <= game.nenhere) {
693 for (j=i; j<=game.nenhere; j++) {
694 game.ks[j] = game.ks[j+1];
695 game.kpower[j] = game.kpower[j+1];
696 game.kavgd[j] = game.kdist[j] = game.kdist[j+1];
699 game.ks[game.nenhere+1].x = 0;
700 game.ks[game.nenhere+1].x = 0;
701 game.kdist[game.nenhere+1] = 0;
702 game.kavgd[game.nenhere+1] = 0;
703 game.kpower[game.nenhere+1] = 0;
707 static bool targetcheck(double x, double y, double *course)
710 /* Return true if target is invalid */
711 if (!VALID_SECTOR(x, y)) {
715 deltx = 0.1*(y - game.sector.y);
716 delty = 0.1*(game.sector.x - x);
717 if (deltx==0 && delty== 0) {
719 prout(_("Spock- \"Bridge to sickbay. Dr. McCoy,"));
720 prout(_(" I recommend an immediate review of"));
721 prout(_(" the Captain's psychological profile.\""));
725 *course = 1.90985932*atan2(deltx, delty);
730 /* launch photon torpedo */
732 double targ[4][3], course[4];
734 int key, n, i, osuabor;
738 if (damaged(DPHOTON)) {
739 prout(_("Photon tubes damaged."));
743 if (game.torps == 0) {
744 prout(_("No torpedoes left."));
750 if (key == IHALPHA) {
754 else if (key == IHEOL) {
755 prout(_("%d torpedoes left."), game.torps);
756 proutn(_("Number of torpedoes to fire- "));
759 else /* key == IHREAL */ {
761 if (n <= 0) { /* abort command */
767 prout(_("Maximum of 3 torpedoes per burst."));
771 if (n <= game.torps) break;
776 for (i = 1; i <= n; i++) {
778 if (i==1 && key == IHEOL) {
779 break; /* we will try prompting */
781 if (i==2 && key == IHEOL) {
782 /* direct all torpedoes at one target */
784 targ[i][1] = targ[1][1];
785 targ[i][2] = targ[1][2];
786 course[i] = course[1];
802 if (targetcheck(targ[i][1], targ[i][2], &course[i])) return;
805 if (i == 1 && key == IHEOL) {
806 /* prompt for each one */
807 for (i = 1; i <= n; i++) {
808 proutn(_("Target sector for torpedo number %d- "), i);
822 if (targetcheck(targ[i][1], targ[i][2], &course[i])) return;
826 /* Loop for moving <n> torpedoes */
828 for (i = 1; i <= n && !osuabor; i++) {
829 if (game.condit != IHDOCKED) game.torps--;
830 r = (Rand()+Rand())*0.5 -0.5;
831 if (fabs(r) >= 0.47) {
833 r = (Rand()+1.2) * r;
835 prouts(_("***TORPEDO NUMBER %d MISFIRES"), i);
837 else prouts(_("***TORPEDO MISFIRES."));
840 prout(_(" Remainder of burst aborted."));
843 prout(_("***Photon tubes damaged by misfire."));
844 game.damage[DPHOTON] = game.damfac*(1.0+2.0*Rand());
848 if (game.shldup || game.condit == IHDOCKED)
849 r *= 1.0 + 0.0001*game.shield;
850 torpedo(course[i], r, game.sector.x, game.sector.y, &dummy, i, n);
851 if (game.alldone || game.state.galaxy[game.quadrant.x][game.quadrant.y].supernova)
854 if (KLINGREM==0) finish(FWON);
859 static void overheat(double rpow)
860 /* check for phasers overheating */
863 double chekbrn = (rpow-1500.)*0.00038;
864 if (Rand() <= chekbrn) {
865 prout(_("Weapons officer Sulu- \"Phasers overheated, sir.\""));
866 game.damage[DPHASER] = game.damfac*(1.0 + Rand()) * (1.0+chekbrn);
871 static int checkshctrl(double rpow)
872 /* check shield control */
879 prout(_("Shields lowered."));
882 /* Something bad has happened */
883 prouts(_("***RED ALERT! RED ALERT!"));
885 hit = rpow*game.shield/game.inshld;
886 game.energy -= rpow+hit*0.8;
887 game.shield -= hit*0.2;
888 if (game.energy <= 0.0) {
889 prouts(_("Sulu- \"Captain! Shield malf***********************\""));
895 prouts(_("Sulu- \"Captain! Shield malfunction! Phaser fire contained!\""));
897 prout(_("Lt. Uhura- \"Sir, all decks reporting damage.\""));
898 icas = hit*Rand()*0.012;
903 prout(_("McCoy to bridge- \"Severe radiation burns, Jim."));
904 prout(_(" %d casualties so far.\""), icas);
906 game.state.crew -= icas;
909 prout(_("Phaser energy dispersed by shields."));
910 prout(_("Enemy unaffected."));
919 double hits[21], rpow=0, extra, powrem, over, temp;
920 int kz = 0, k=1, i, irec=0; /* Cheating inhibitor */
921 int ifast=0, no=0, ipoop=1, msgflag = 1;
922 enum {NOTSET, MANUAL, FORCEMAN, AUTOMATIC} automode = NOTSET;
926 /* SR sensors and Computer */
927 if (damaged(DSRSENS) || damaged(DCOMPTR)) ipoop = 0;
928 if (game.condit == IHDOCKED) {
929 prout(_("Phasers can't be fired through base shields."));
933 if (damaged(DPHASER)) {
934 prout(_("Phaser control damaged."));
939 if (damaged(DSHCTRL)) {
940 prout(_("High speed shield control damaged."));
944 if (game.energy <= 200.0) {
945 prout(_("Insufficient energy to activate high-speed shield control."));
949 prout(_("Weapons Officer Sulu- \"High-speed shield control enabled, sir.\""));
953 /* Original code so convoluted, I re-did it all */
954 while (automode==NOTSET) {
956 if (key == IHALPHA) {
957 if (isit("manual")) {
958 if (game.nenhere==0) {
959 prout(_("There is no enemy present to select."));
969 else if (isit("automatic")) {
970 if ((!ipoop) && game.nenhere != 0) {
975 prout(_("Energy will be expended into space."));
976 automode = AUTOMATIC;
980 else if (isit("no")) {
988 else if (key == IHREAL) {
989 if (game.nenhere==0) {
990 prout(_("Energy will be expended into space."));
991 automode = AUTOMATIC;
996 automode = AUTOMATIC;
1000 if (game.nenhere==0) {
1001 prout(_("Energy will be expended into space."));
1002 automode = AUTOMATIC;
1005 automode = FORCEMAN;
1007 proutn(_("Manual or automatic? "));
1013 if (key == IHALPHA && isit("no")) {
1017 if (key != IHREAL && game.nenhere != 0) {
1018 prout(_("Phasers locked on target. Energy available: %.2f"),
1019 ifast?game.energy-200.0:game.energy,1,2);
1024 if (!kz) for_local_enemies(i)
1025 irec+=fabs(game.kpower[i])/(PHASEFAC*pow(0.90,game.kdist[i]))*
1026 (1.01+0.05*Rand()) + 1.0;
1028 proutn(_("(%d) units required. "), irec);
1030 proutn(_("Units to fire= "));
1032 if (key!=IHREAL) return;
1034 if (rpow > (ifast?game.energy-200:game.energy)) {
1035 proutn(_("Energy available= %.2f"),
1036 ifast?game.energy-200:game.energy);
1040 } while (rpow > (ifast?game.energy-200:game.energy));
1046 if ((key=scan()) == IHALPHA && isit("no")) {
1050 game.energy -= 200; /* Go and do it! */
1051 if (checkshctrl(rpow)) return;
1054 game.energy -= rpow;
1059 for_local_enemies(i) {
1061 if (powrem <= 0) continue;
1062 hits[i] = fabs(game.kpower[i])/(PHASEFAC*pow(0.90,game.kdist[i]));
1063 over = (0.01 + 0.05*Rand())*hits[i];
1065 powrem -= hits[i] + over;
1066 if (powrem <= 0 && temp < hits[i]) hits[i] = temp;
1067 if (powrem <= 0) over = 0.0;
1070 if (powrem > 0.0) extra += powrem;
1074 if (extra > 0 && game.alldone == 0) {
1076 proutn(_("*** Tholian web absorbs "));
1077 if (game.nenhere>0) proutn(_("excess "));
1078 prout(_("phaser energy."));
1081 prout(_("%d expended on empty space."), (int)extra);
1089 if (damaged(DCOMPTR))
1090 prout(_("Battle comuter damaged, manual file only."));
1093 prouts(_("---WORKING---"));
1095 prout(_("Short-range-sensors-damaged"));
1096 prout(_("Insufficient-data-for-automatic-phaser-fire"));
1097 prout(_("Manual-fire-must-be-used"));
1102 for (k = 1; k <= game.nenhere;) {
1103 coord aim = game.ks[k];
1104 int ienm = game.quad[aim.x][aim.y];
1106 proutn(_("Energy available= %.2f"),
1107 game.energy-.006-(ifast?200:0));
1112 if (damaged(DSRSENS) && !(abs(game.sector.x-aim.x) < 2 && abs(game.sector.y-aim.y) < 2) &&
1113 (ienm == IHC || ienm == IHS)) {
1115 prout(_(" can't be located without short range scan."));
1118 hits[k] = 0; /* prevent overflow -- thanks to Alexei Voitenko */
1124 if (ipoop && k > kz)
1125 irec=(fabs(game.kpower[k])/(PHASEFAC*pow(0.9,game.kdist[k])))*
1126 (1.01+0.05*Rand()) + 1.0;
1129 if (!damaged(DCOMPTR)) proutn("%d", irec);
1132 proutn(_("units to fire at "));
1133 crmena(false, ienm, sector, aim);
1137 if (key == IHALPHA && isit("no")) {
1142 if (key == IHALPHA) {
1147 if (k==1) { /* Let me say I'm baffled by this */
1159 /* If total requested is too much, inform and start over */
1161 if (rpow > (ifast?game.energy-200:game.energy)) {
1162 prout(_("Available energy exceeded -- try again."));
1166 key = scan(); /* scan for next value */
1170 /* zero energy -- abort */
1174 if (key == IHALPHA && isit("no")) {
1177 game.energy -= rpow;
1180 game.energy -= 200.0;
1181 if (checkshctrl(rpow)) return;
1185 case NOTSET:; /* avoid gcc warning */
1187 /* Say shield raised or malfunction, if necessary */
1193 if (Rand() >= 0.99) {
1194 prout(_("Sulu- \"Sir, the high-speed shield control has malfunctioned . . ."));
1195 prouts(_(" CLICK CLICK POP . . ."));
1196 prout(_(" No response, sir!"));
1197 game.shldup = false;
1200 prout(_("Shields raised."));
1203 game.shldup = false;
1208 void hittem(double *hits)
1209 /* register a phaser hit on Klingons and Romulans */
1211 double kp, kpow, wham, hit, dustfac, kpini;
1212 int nenhr2=game.nenhere, k=1, kk=1, ienm;
1217 for (; k <= nenhr2; k++, kk++) {
1218 if ((wham = hits[k])==0) continue;
1219 dustfac = 0.9 + 0.01*Rand();
1220 hit = wham*pow(dustfac,game.kdist[kk]);
1221 kpini = game.kpower[kk];
1223 if (PHASEFAC*hit < kp) kp = PHASEFAC*hit;
1224 game.kpower[kk] -= (game.kpower[kk] < 0 ? -kp: kp);
1225 kpow = game.kpower[kk];
1228 if (!damaged(DSRSENS))
1230 proutn(_("%d unit hit on "), (int)hit);
1233 proutn(_("Very small hit on "));
1234 ienm = game.quad[w.x][w.y];
1235 if (ienm==IHQUEST) iqengry=1;
1236 crmena(false,ienm,sector,w);
1239 deadkl(w, ienm, w.x, w.y);
1240 if (KLINGREM==0) finish(FWON);
1241 if (game.alldone) return;
1242 kk--; /* don't do the increment */
1244 else /* decide whether or not to emasculate klingon */
1245 if (kpow > 0 && Rand() >= 0.9 &&
1246 kpow <= ((0.4 + 0.4*Rand())*kpini)) {
1247 prout(_("***Mr. Spock- \"Captain, the vessel at "),
1249 prout(_(" has just lost its firepower.\""));
1250 game.kpower[kk] = -kpow;