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? "));
50 proutn(_("Shields are down. Do you want them up? "));
61 case SHUP: /* raise shields */
63 prout(_("Shields already up."));
68 if (game.condition != docked)
70 prout(_("Shields raised."));
71 if (game.energy <= 0) {
73 prout(_("Shields raising uses up last of energy."));
81 prout(_("Shields already down."));
86 prout(_("Shields lowered."));
90 while (scan() != IHREAL) {
92 proutn(_("Energy to transfer to shields- "));
97 if (aaitem > game.energy) {
98 prout(_("Insufficient ship energy."));
102 if (game.shield+aaitem >= game.inshld) {
103 prout(_("Shield energy maximized."));
104 if (game.shield+aaitem > game.inshld) {
105 prout(_("Excess energy requested returned to ship energy"));
107 game.energy -= game.inshld-game.shield;
108 game.shield = game.inshld;
111 if (aaitem < 0.0 && game.energy-aaitem > game.inenrg) {
112 /* Prevent shield drain loophole */
114 prout(_("Engineering to bridge--"));
115 prout(_(" Scott here. Power circuit problem, Captain."));
116 prout(_(" I can't drain the shields."));
120 if (game.shield+aaitem < 0) {
121 prout(_("All shield energy transferred to ship."));
122 game.energy += game.shield;
126 proutn(_("Scotty- \""));
128 prout(_("Transferring energy to shields.\""));
130 prout(_("Draining energy from shields.\""));
131 game.shield += aaitem;
132 game.energy -= aaitem;
134 case NONE:; /* avoid gcc warning */
138 static int randdevice(void)
139 /* choose a device to damage, at random. */
142 * Quoth Eric Allman in the code of BSD-Trek:
143 * "Under certain conditions you can get a critical hit. This
144 * sort of hit damages devices. The probability that a given
145 * device is damaged depends on the device. Well protected
146 * devices (such as the computer, which is in the core of the
147 * ship and has considerable redundancy) almost never get
148 * damaged, whereas devices which are exposed (such as the
149 * warp engines) or which are particularly delicate (such as
150 * the transporter) have a much higher probability of being
153 * This is one place where OPTION_PLAIN does not restore the
154 * original behavior, which was equiprobable damage across
155 * all devices. If we wanted that, we'd return NDEVICES*Rand()
156 * and have done with it. Also, in the original game, DNAVYS
157 * and DCOMPTR were the same device.
159 * Instead, we use a table of weights similar to the one from BSD Trek.
160 * BSD doesn't have the shuttle, shield controller, death ray, or probes.
161 * We don't have a cloaking device. The shuttle got the allocation
162 * for the cloaking device, then we shaved a half-percent off
163 * everything to have some weight to give DSHCTRL/DDRAY/DDSP.
165 static int weights[NDEVICES] = {
166 105, /* DSRSENS: short range scanners 10.5% */
167 105, /* DLRSENS: long range scanners 10.5% */
168 120, /* DPHASER: phasers 12.0% */
169 120, /* DPHOTON: photon torpedoes 12.0% */
170 25, /* DLIFSUP: life support 2.5% */
171 65, /* DWARPEN: warp drive 6.5% */
172 70, /* DIMPULS: impulse engines 6.5% */
173 145, /* DSHIELD: deflector shields 14.5% */
174 30, /* DRADIO: subspace radio 3.0% */
175 45, /* DSHUTTL: shuttle 4.5% */
176 15, /* DCOMPTR: computer 1.5% */
177 20, /* NAVCOMP: navigation system 2.0% */
178 75, /* DTRANSP: transporter 7.5% */
179 20, /* DSHCTRL: high-speed shield controller 2.0% */
180 10, /* DDRAY: death ray 1.0% */
181 30, /* DDSP: deep-space probes 3.0% */
183 int sum, i, idx = Rand() * 1000.0; /* weights must sum to 1000 */
185 for (i = sum = 0; i < NDEVICES; i++) {
190 return -1; /* we should never get here, but this quiets GCC */
193 void ram(bool ibumpd, feature ienm, coord w)
194 /* make our ship ram something */
196 double hardness, extradm;
199 prouts(_("***RED ALERT! RED ALERT!"));
201 prout(_("***COLLISION IMMINENT."));
206 case IHR: hardness = 1.5; break;
207 case IHC: hardness = 2.0; break;
208 case IHS: hardness = 2.5; break;
209 case IHT: hardness = 0.5; break;
210 case IHQUEST: hardness = 4.0; break;
211 default: hardness = 1.0; break;
213 proutn(ibumpd ? _(" rammed by ") : _(" rams "));
214 crmena(false, ienm, sector, w);
216 proutn(_(" (original position)"));
218 deadkl(w, ienm, game.sector);
221 prout(_(" heavily damaged."));
222 icas = 10.0+20.0*Rand();
223 prout(_("***Sickbay reports %d casualties"), icas);
225 game.state.crew -= icas;
227 * In the pre-SST2K version, all devices got equiprobably damaged,
228 * which was silly. Instead, pick up to half the devices at
229 * random according to our weighting table,
231 ncrits = Rand() * (NDEVICES/2);
232 for (m=0; m < ncrits; m++) {
233 int dev = randdevice();
234 if (game.damage[dev] < 0)
236 extradm = (10.0*hardness*Rand()+1.0)*game.damfac;
237 /* Damage for at least time of travel! */
238 game.damage[dev] += game.optime + extradm;
241 prout(_("***Shields are down."));
242 if (game.state.remkl + game.state.remcom + game.state.nscrem) {
251 void torpedo(double course, double r, coord in, double *hit, int i, int n)
252 /* let a photon torpedo fly */
256 double ac=course + 0.25*r;
257 double angle = (15.0-ac)*0.5235988;
258 double bullseye = (15.0 - course)*0.5235988;
259 double deltax=-sin(angle), deltay=cos(angle), x=in.x, y=in.y, bigger;
260 double ang, temp, xx, yy, kp, h1;
261 struct quadrant *q = &game.state.galaxy[game.quadrant.x][game.quadrant.y];
264 w.x = w.y = jw.x = jw.y = 0;
265 bigger = fabs(deltax);
266 if (fabs(deltay) > bigger)
267 bigger = fabs(deltay);
270 if (!damaged(DSRSENS) || game.condition==docked)
271 setwnd(srscan_window);
273 setwnd(message_window);
274 /* Loop to move a single torpedo */
275 for (l=1; l <= 15; l++) {
280 if (!VALID_SECTOR(w.x, w.y))
282 iquad=game.quad[w.x][w.y];
283 tracktorpedo(w, l, i, n, iquad);
287 setwnd(message_window);
288 if (damaged(DSRSENS) && !game.condition==docked)
289 skip(1); /* start new line after text track */
291 case IHE: /* Hit our ship */
294 proutn(_("Torpedo hits "));
297 *hit = 700.0 + 100.0*Rand() -
298 1000.0 * distance(w, in) * fabs(sin(bullseye-angle));
300 newcnd(); /* we're blown out of dock */
301 /* We may be displaced. */
302 if (game.landed || game.condition==docked)
303 return; /* Cheat if on a planet */
304 ang = angle + 2.5*(Rand()-0.5);
305 temp = fabs(sin(ang));
306 if (fabs(cos(ang)) > temp)
307 temp = fabs(cos(ang));
312 if (!VALID_SECTOR(jw.x, jw.y))
314 if (game.quad[jw.x][jw.y]==IHBLANK) {
318 if (game.quad[jw.x][jw.y]!=IHDOT) {
319 /* can't move into object */
327 case IHC: /* Hit a commander */
329 if (Rand() <= 0.05) {
330 crmena(true, iquad, sector, w);
331 prout(_(" uses anti-photon device;"));
332 prout(_(" torpedo neutralized."));
335 case IHR: /* Hit a regular enemy */
338 for (ll = 1; ll <= game.nenhere; ll++)
339 if (same(w, game.ks[ll]))
341 kp = fabs(game.kpower[ll]);
342 h1 = 700.0 + 100.0*Rand() -
343 1000.0 * distance(w, in) * fabs(sin(bullseye-angle));
347 game.kpower[ll] -= (game.kpower[ll]<0 ? -h1 : h1);
348 if (game.kpower[ll] == 0) {
352 crmena(true, iquad, sector, w);
353 /* If enemy damaged but not destroyed, try to displace */
354 ang = angle + 2.5*(Rand()-0.5);
355 temp = fabs(sin(ang));
356 if (fabs(cos(ang)) > temp)
357 temp = fabs(cos(ang));
362 if (!VALID_SECTOR(jw.x, jw.y)) {
363 prout(_(" damaged but not destroyed."));
366 if (game.quad[jw.x][jw.y]==IHBLANK) {
367 prout(_(" buffeted into black hole."));
368 deadkl(w, iquad, jw);
371 if (game.quad[jw.x][jw.y]!=IHDOT) {
372 /* can't move into object */
373 prout(_(" damaged but not destroyed."));
376 proutn(_(" damaged--"));
380 case IHB: /* Hit a base */
382 prout(_("***STARBASE DESTROYED.."));
383 for (ll = 1; ll <= game.state.rembase; ll++) {
384 if (same(game.state.baseq[ll], game.quadrant)) {
385 game.state.baseq[ll]=game.state.baseq[game.state.rembase];
389 game.quad[w.x][w.y]=IHDOT;
390 game.state.rembase--;
391 game.base.x=game.base.y=0;
393 game.state.chart[game.quadrant.x][game.quadrant.y].starbase--;
397 case IHP: /* Hit a planet */
398 crmena(true, iquad, sector, w);
399 prout(_(" destroyed."));
400 game.state.nplankl++;
401 q->planet = NOPLANET;
402 game.state.planets[game.iplnet].pclass = destroyed;
404 invalidate(game.plnet);
405 game.quad[w.x][w.y] = IHDOT;
407 /* captain perishes on planet */
411 case IHW: /* Hit an inhabited world -- very bad! */
412 crmena(true, iquad, sector, w);
413 prout(_(" destroyed."));
414 game.state.nworldkl++;
415 q->planet = NOPLANET;
416 game.state.planets[game.iplnet].pclass = destroyed;
418 invalidate(game.plnet);
419 game.quad[w.x][w.y] = IHDOT;
421 /* captain perishes on planet */
424 prout(_("You have just destroyed an inhabited planet."));
425 prout(_("Celebratory rallies are being held on the Klingon homeworld."));
427 case IHSTAR: /* Hit a star */
432 crmena(true, IHSTAR, sector, w);
433 prout(_(" unaffected by photon blast."));
435 case IHQUEST: /* Hit a thingy */
436 if (!(game.options & OPTION_THINGY) || Rand()>0.7) {
438 prouts(_("AAAAIIIIEEEEEEEEAAAAAAAAUUUUUGGGGGHHHHHHHHHHHH!!!"));
440 prouts(_(" HACK! HACK! HACK! *CHOKE!* "));
442 proutn(_("Mr. Spock-"));
443 prouts(_(" \"Fascinating!\""));
448 * Stas Sergeev added the possibility that
449 * you can shove the Thingy and piss it off.
450 * It then becomes an enemy and may fire at you.
456 case IHBLANK: /* Black hole */
458 crmena(true, IHBLANK, sector, w);
459 prout(_(" swallows torpedo."));
461 case IHWEB: /* hit the web */
463 prout(_("***Torpedo absorbed by Tholian web."));
465 case IHT: /* Hit a Tholian */
466 h1 = 700.0 + 100.0*Rand() -
467 1000.0 * distance(w, in) * fabs(sin(bullseye-angle));
470 game.quad[w.x][w.y] = IHDOT;
476 crmena(true, IHT, sector, w);
478 prout(_(" survives photon blast."));
481 prout(_(" disappears."));
482 game.quad[w.x][w.y] = IHWEB;
488 default: /* Problem! */
490 proutn("Don't know how to handle collision with ");
491 crmena(true, iquad, sector, w);
497 if(curwnd!=message_window) {
498 setwnd(message_window);
501 game.quad[w.x][w.y]=IHDOT;
502 game.quad[jw.x][jw.y]=iquad;
503 prout(_(" displaced by blast to %s "), cramlc(sector, jw));
504 for (ll = 1; ll <= game.nenhere; ll++)
505 game.kdist[ll] = game.kavgd[ll] = distance(game.sector,game.ks[ll]);
510 prout(_("Torpedo missed."));
514 static void fry(double hit)
515 /* critical-hit resolution */
517 double ncrit, extradm;
518 int ktr=1, loop1, loop2, j, cdam[NDEVICES];
520 /* a critical hit occured */
521 if (hit < (275.0-25.0*game.skill)*(1.0+0.5*Rand()))
524 ncrit = 1.0 + hit/(500.0+100.0*Rand());
525 proutn(_("***CRITICAL HIT--"));
526 /* Select devices and cause damage */
527 for (loop1 = 0; loop1 < ncrit; loop1++) {
530 /* Cheat to prevent shuttle damage unless on ship */
532 (game.damage[j]<0.0 || (j==DSHUTTL && game.iscraft != onship));
534 extradm = (hit*game.damfac)/(ncrit*(75.0+25.0*Rand()));
535 game.damage[j] += extradm;
537 for (loop2 = 0; loop2 < loop1 && j != cdam[loop2]; loop2++) ;
547 prout(_(" damaged."));
548 if (damaged(DSHIELD) && game.shldup) {
549 prout(_("***Shields knocked down."));
554 void attack(bool torps_ok)
555 /* bad guy attacks us */
557 /* torps_ok == false forces use of phasers in an attack */
558 int percent, loop, iquad;
559 bool usephasers, atackd = false, attempt = false, ihurt = false;
560 double hit, pfac, dustfac, hitmax=0.0, hittot=0.0, chgfac=1.0, r;
562 enum loctype where = neither;
564 /* game could be over at this point, check */
569 prout("=== ATTACK!");
571 /* Tholian gewts to move before attacking */
575 /* if you have just entered the RNZ, you'll get a warning */
576 if (game.neutz) { /* The one chance not to be attacked */
581 /* commanders get a chance to tac-move towards you */
582 if ((((game.comhere || game.ishere) && !game.justin) || game.skill == SKILL_EMERITUS) && torps_ok)
585 /* if no enemies remain after movement, we're done */
586 if (game.nenhere==0 || (game.nenhere==1 && iqhere && !iqengry))
589 /* set up partial hits if attack happens during shield status change */
590 pfac = 1.0/game.inshld;
592 chgfac = 0.25+0.5*Rand();
596 /* message verbosity control */
597 if (game.skill <= SKILL_FAIR)
600 for (loop = 1; loop <= game.nenhere; loop++) {
601 if (game.kpower[loop] < 0)
602 continue; /* too weak to attack */
603 /* compute hit strength and diminish shield power */
605 /* Increase chance of photon torpedos if docked or enemy energy low */
606 if (game.condition == docked)
608 if (game.kpower[loop] < 500)
611 iquad = game.quad[jay.x][jay.y];
612 if (iquad==IHT || (iquad==IHQUEST && !iqengry))
614 /* different enemies have different probabilities of throwing a torp */
615 usephasers = !torps_ok || \
616 (iquad == IHK && r > 0.0005) ||
617 (iquad==IHC && r > 0.015) ||
618 (iquad==IHR && r > 0.3) ||
619 (iquad==IHS && r > 0.07) ||
620 (iquad==IHQUEST && r > 0.05);
621 if (usephasers) { /* Enemy uses phasers */
622 if (game.condition == docked)
623 continue; /* Don't waste the effort! */
624 attempt = true; /* Attempt to attack */
625 dustfac = 0.8+0.05*Rand();
626 hit = game.kpower[loop]*pow(dustfac,game.kavgd[loop]);
627 game.kpower[loop] *= 0.75;
629 else { /* Enemy uses photon torpedo */
630 double course = 1.90985*atan2((double)game.sector.y-jay.y, (double)jay.x-game.sector.x);
632 proutn(_("***TORPEDO INCOMING"));
633 if (!damaged(DSRSENS)) {
635 crmena(false, iquad, where, jay);
639 r = (Rand()+Rand())*0.5 -0.5;
640 r += 0.002*game.kpower[loop]*r;
641 torpedo(course, r, jay, &hit, 1, 1);
642 if ((game.state.remkl + game.state.remcom + game.state.nscrem)==0)
643 finish(FWON); /* Klingons did themselves in! */
644 if (game.state.galaxy[game.quadrant.x][game.quadrant.y].supernova || game.alldone)
645 return; /* Supernova or finished */
649 /* incoming phaser or torpedo, shields may dissipate it */
650 if (game.shldup || game.shldchg || game.condition==docked) {
651 /* shields will take hits */
652 double absorb, hitsh, propor = pfac*game.shield*(game.condition==docked ? 2.1 : 1.0);
655 hitsh = propor*chgfac*hit+1.0;
657 if (absorb > game.shield)
658 absorb = game.shield;
659 game.shield -= absorb;
661 /* taking a hit blasts us out of a starbase dock */
662 if (game.condition == docked)
664 /* but the shields may take care of it */
665 if (propor > 0.1 && hit < 0.005*game.energy)
668 /* hit from this opponent got through shields, so take damage */
670 proutn(_("%d unit hit"), (int)hit);
671 if ((damaged(DSRSENS) && usephasers) || game.skill<=SKILL_FAIR) {
672 proutn(_(" on the "));
675 if (!damaged(DSRSENS) && usephasers) {
677 crmena(false, iquad, where, jay);
680 /* Decide if hit is critical */
687 if (game.energy <= 0) {
688 /* Returning home upon your shield, not with it... */
692 if (!attempt && game.condition == docked)
693 prout(_("***Enemies decide against attacking your ship."));
696 percent = 100.0*pfac*game.shield+0.5;
698 /* Shields fully protect ship */
699 proutn(_("Enemy attack reduces shield strength to "));
702 /* Print message if starship suffered hit(s) */
704 proutn(_("Energy left %2d shields "), (int)game.energy);
707 else if (!damaged(DSHIELD))
710 proutn(_("damaged, "));
712 prout(_("%d%%, torpedoes left %d"), percent, game.torps);
713 /* Check if anyone was hurt */
714 if (hitmax >= 200 || hittot >= 500) {
715 int icas= hittot*Rand()*0.015;
718 prout(_("Mc Coy- \"Sickbay to bridge. We suffered %d casualties"), icas);
719 prout(_(" in that last attack.\""));
721 game.state.crew -= icas;
724 /* After attack, reset average distance to enemies */
725 for (loop = 1; loop <= game.nenhere; loop++)
726 game.kavgd[loop] = game.kdist[loop];
731 void deadkl(coord w, feature type, coord mv)
732 /* kill a Klingon, Tholian, Romulan, or Thingy */
734 /* Added mv to allow enemy to "move" before dying */
737 crmena(true, type, sector, mv);
738 /* Decide what kind of enemy it is and update appropriately */
740 /* chalk up a Romulan */
741 game.state.galaxy[game.quadrant.x][game.quadrant.y].romulans--;
743 game.state.nromrem--;
745 else if (type == IHT) {
746 /* Killed a Tholian */
749 else if (type == IHQUEST) {
750 /* Killed a Thingy */
751 iqhere = iqengry = false;
755 /* Some type of a Klingon */
756 game.state.galaxy[game.quadrant.x][game.quadrant.y].klingons--;
760 game.comhere = false;
761 for (i = 1; i <= game.state.remcom; i++)
762 if (same(game.state.kcmdr[i], game.quadrant))
764 game.state.kcmdr[i] = game.state.kcmdr[game.state.remcom];
765 game.state.kcmdr[game.state.remcom].x = 0;
766 game.state.kcmdr[game.state.remcom].y = 0;
769 if (game.state.remcom != 0)
770 schedule(FTBEAM, expran(1.0*game.incom/game.state.remcom));
778 game.state.kscmdr.x = game.state.kscmdr.y = game.isatb = 0;
783 default: /* avoids a gcc warning */
784 prout("*** Internal error, deadkl() called on %c\n", type);
789 /* For each kind of enemy, finish message to player */
790 prout(_(" destroyed."));
791 game.quad[w.x][w.y] = IHDOT;
792 if ((game.state.remkl + game.state.remcom + game.state.nscrem)==0)
795 game.state.remtime = game.state.remkl + game.state.remcom > 0 ?
796 game.state.remres/(game.state.remkl + 4*game.state.remcom) : 99;
798 /* Remove enemy ship from arrays describing local conditions */
799 if (is_scheduled(FCDBAS) && same(game.battle, game.quadrant) && type==IHC)
801 for (i = 1; i <= game.nenhere; i++)
802 if (same(game.ks[i], w))
805 if (i <= game.nenhere) {
806 for (j=i; j<=game.nenhere; j++) {
807 game.ks[j] = game.ks[j+1];
808 game.kpower[j] = game.kpower[j+1];
809 game.kavgd[j] = game.kdist[j] = game.kdist[j+1];
812 game.ks[game.nenhere+1].x = 0;
813 game.ks[game.nenhere+1].x = 0;
814 game.kdist[game.nenhere+1] = 0;
815 game.kavgd[game.nenhere+1] = 0;
816 game.kpower[game.nenhere+1] = 0;
820 static bool targetcheck(double x, double y, double *course)
823 /* Return true if target is invalid */
824 if (!VALID_SECTOR(x, y)) {
828 deltx = 0.1*(y - game.sector.y);
829 delty = 0.1*(game.sector.x - x);
830 if (deltx==0 && delty== 0) {
832 prout(_("Spock- \"Bridge to sickbay. Dr. McCoy,"));
833 prout(_(" I recommend an immediate review of"));
834 prout(_(" the Captain's psychological profile.\""));
838 *course = 1.90985932*atan2(deltx, delty);
843 /* launch photon torpedo salvo */
845 double targ[4][3], course[4];
851 if (damaged(DPHOTON)) {
852 prout(_("Photon tubes damaged."));
856 if (game.torps == 0) {
857 prout(_("No torpedoes left."));
863 if (key == IHALPHA) {
867 else if (key == IHEOL) {
868 prout(_("%d torpedoes left."), game.torps);
869 proutn(_("Number of torpedoes to fire- "));
872 else /* key == IHREAL */ {
874 if (n <= 0) { /* abort command */
880 prout(_("Maximum of 3 torpedoes per burst."));
890 for (i = 1; i <= n; i++) {
892 if (i==1 && key == IHEOL) {
893 break; /* we will try prompting */
895 if (i==2 && key == IHEOL) {
896 /* direct all torpedoes at one target */
898 targ[i][1] = targ[1][1];
899 targ[i][2] = targ[1][2];
900 course[i] = course[1];
916 if (targetcheck(targ[i][1], targ[i][2], &course[i]))
920 if (i == 1 && key == IHEOL) {
921 /* prompt for each one */
922 for (i = 1; i <= n; i++) {
923 proutn(_("Target sector for torpedo number %d- "), i);
937 if (targetcheck(targ[i][1], targ[i][2], &course[i]))
942 /* Loop for moving <n> torpedoes */
943 for (i = 1; i <= n; i++) {
944 if (game.condition != docked)
946 r = (Rand()+Rand())*0.5 -0.5;
947 if (fabs(r) >= 0.47) {
949 r = (Rand()+1.2) * r;
951 prouts(_("***TORPEDO NUMBER %d MISFIRES"), i);
954 prouts(_("***TORPEDO MISFIRES."));
957 prout(_(" Remainder of burst aborted."));
959 prout(_("***Photon tubes damaged by misfire."));
960 game.damage[DPHOTON] = game.damfac*(1.0+2.0*Rand());
964 if (game.shldup || game.condition == docked)
965 r *= 1.0 + 0.0001*game.shield;
966 torpedo(course[i], r, game.sector, &dummy, i, n);
967 if (game.alldone || game.state.galaxy[game.quadrant.x][game.quadrant.y].supernova)
970 if ((game.state.remkl + game.state.remcom + game.state.nscrem)==0)
976 static void overheat(double rpow)
977 /* check for phasers overheating */
980 double chekbrn = (rpow-1500.)*0.00038;
981 if (Rand() <= chekbrn) {
982 prout(_("Weapons officer Sulu- \"Phasers overheated, sir.\""));
983 game.damage[DPHASER] = game.damfac*(1.0 + Rand()) * (1.0+chekbrn);
988 static bool checkshctrl(double rpow)
989 /* check shield control */
995 if (Rand() < 0.998) {
996 prout(_("Shields lowered."));
999 /* Something bad has happened */
1000 prouts(_("***RED ALERT! RED ALERT!"));
1002 hit = rpow*game.shield/game.inshld;
1003 game.energy -= rpow+hit*0.8;
1004 game.shield -= hit*0.2;
1005 if (game.energy <= 0.0) {
1006 prouts(_("Sulu- \"Captain! Shield malf***********************\""));
1012 prouts(_("Sulu- \"Captain! Shield malfunction! Phaser fire contained!\""));
1014 prout(_("Lt. Uhura- \"Sir, all decks reporting damage.\""));
1015 icas = hit*Rand()*0.012;
1020 prout(_("McCoy to bridge- \"Severe radiation burns, Jim."));
1021 prout(_(" %d casualties so far.\""), icas);
1022 game.casual += icas;
1023 game.state.crew -= icas;
1026 prout(_("Phaser energy dispersed by shields."));
1027 prout(_("Enemy unaffected."));
1036 double hits[21], rpow=0, extra, powrem, over, temp;
1037 int kz = 0, k=1, i, irec=0; /* Cheating inhibitor */
1038 bool ifast = false, no = false, itarg = true, msgflag = true;
1039 enum {NOTSET, MANUAL, FORCEMAN, AUTOMATIC} automode = NOTSET;
1043 /* SR sensors and Computer are needed fopr automode */
1044 if (damaged(DSRSENS) || damaged(DCOMPTR))
1046 if (game.condition == docked) {
1047 prout(_("Phasers can't be fired through base shields."));
1051 if (damaged(DPHASER)) {
1052 prout(_("Phaser control damaged."));
1057 if (damaged(DSHCTRL)) {
1058 prout(_("High speed shield control damaged."));
1062 if (game.energy <= 200.0) {
1063 prout(_("Insufficient energy to activate high-speed shield control."));
1067 prout(_("Weapons Officer Sulu- \"High-speed shield control enabled, sir.\""));
1071 /* Original code so convoluted, I re-did it all */
1072 while (automode==NOTSET) {
1074 if (key == IHALPHA) {
1075 if (isit("manual")) {
1076 if (game.nenhere==0) {
1077 prout(_("There is no enemy present to select."));
1087 else if (isit("automatic")) {
1088 if ((!itarg) && game.nenhere != 0) {
1089 automode = FORCEMAN;
1092 if (game.nenhere==0)
1093 prout(_("Energy will be expended into space."));
1094 automode = AUTOMATIC;
1098 else if (isit("no")) {
1106 else if (key == IHREAL) {
1107 if (game.nenhere==0) {
1108 prout(_("Energy will be expended into space."));
1109 automode = AUTOMATIC;
1112 automode = FORCEMAN;
1114 automode = AUTOMATIC;
1118 if (game.nenhere==0) {
1119 prout(_("Energy will be expended into space."));
1120 automode = AUTOMATIC;
1123 automode = FORCEMAN;
1125 proutn(_("Manual or automatic? "));
1131 if (key == IHALPHA && isit("no")) {
1135 if (key != IHREAL && game.nenhere != 0) {
1136 prout(_("Phasers locked on target. Energy available: %.2f"),
1137 ifast?game.energy-200.0:game.energy);
1143 for (i = 1; i <= game.nenhere; i++)
1144 irec += fabs(game.kpower[i])/(PHASEFAC*pow(0.90,game.kdist[i]))*
1145 (1.01+0.05*Rand()) + 1.0;
1147 proutn(_("%d units required. "), irec);
1149 proutn(_("Units to fire= "));
1154 if (rpow > (ifast?game.energy-200:game.energy)) {
1155 proutn(_("Energy available= %.2f"),
1156 ifast?game.energy-200:game.energy);
1160 } while (rpow > (ifast?game.energy-200:game.energy));
1166 if ((key=scan()) == IHALPHA && isit("no")) {
1170 game.energy -= 200; /* Go and do it! */
1171 if (checkshctrl(rpow))
1175 game.energy -= rpow;
1180 for (i = 1; i <= game.nenhere; i++) {
1184 hits[i] = fabs(game.kpower[i])/(PHASEFAC*pow(0.90,game.kdist[i]));
1185 over = (0.01 + 0.05*Rand())*hits[i];
1187 powrem -= hits[i] + over;
1188 if (powrem <= 0 && temp < hits[i])
1199 if (extra > 0 && !game.alldone) {
1201 proutn(_("*** Tholian web absorbs "));
1203 proutn(_("excess "));
1204 prout(_("phaser energy."));
1207 prout(_("%d expended on empty space."), (int)extra);
1215 if (damaged(DCOMPTR))
1216 prout(_("Battle computer damaged, manual fire only."));
1219 prouts(_("---WORKING---"));
1221 prout(_("Short-range-sensors-damaged"));
1222 prout(_("Insufficient-data-for-automatic-phaser-fire"));
1223 prout(_("Manual-fire-must-be-used"));
1228 for (k = 1; k <= game.nenhere;) {
1229 coord aim = game.ks[k];
1230 int ienm = game.quad[aim.x][aim.y];
1232 proutn(_("Energy available= %.2f"),
1233 game.energy-.006-(ifast?200:0));
1238 if (damaged(DSRSENS) && !(abs(game.sector.x-aim.x) < 2 && abs(game.sector.y-aim.y) < 2) &&
1239 (ienm == IHC || ienm == IHS)) {
1241 prout(_(" can't be located without short range scan."));
1244 hits[k] = 0; /* prevent overflow -- thanks to Alexei Voitenko */
1250 if (itarg && k > kz)
1251 irec=(fabs(game.kpower[k])/(PHASEFAC*pow(0.9,game.kdist[k])))*
1252 (1.01+0.05*Rand()) + 1.0;
1255 if (!damaged(DCOMPTR))
1260 proutn(_("units to fire at "));
1261 crmena(false, ienm, sector, aim);
1265 if (key == IHALPHA && isit("no")) {
1270 if (key == IHALPHA) {
1275 if (k==1) { /* Let me say I'm baffled by this */
1287 /* If total requested is too much, inform and start over */
1289 if (rpow > (ifast?game.energy-200:game.energy)) {
1290 prout(_("Available energy exceeded -- try again."));
1294 key = scan(); /* scan for next value */
1298 /* zero energy -- abort */
1302 if (key == IHALPHA && isit("no")) {
1305 game.energy -= rpow;
1308 game.energy -= 200.0;
1309 if (checkshctrl(rpow))
1314 case NOTSET:; /* avoid gcc warning */
1316 /* Say shield raised or malfunction, if necessary */
1322 if (Rand() >= 0.99) {
1323 prout(_("Sulu- \"Sir, the high-speed shield control has malfunctioned . . ."));
1324 prouts(_(" CLICK CLICK POP . . ."));
1325 prout(_(" No response, sir!"));
1326 game.shldup = false;
1329 prout(_("Shields raised."));
1332 game.shldup = false;
1337 void hittem(double *hits)
1338 /* register a phaser hit on Klingons and Romulans */
1340 double kp, kpow, wham, hit, dustfac, kpini;
1341 int nenhr2=game.nenhere, k=1, kk=1, ienm;
1346 for (; k <= nenhr2; k++, kk++) {
1347 if ((wham = hits[k])==0)
1349 dustfac = 0.9 + 0.01*Rand();
1350 hit = wham*pow(dustfac,game.kdist[kk]);
1351 kpini = game.kpower[kk];
1353 if (PHASEFAC*hit < kp)
1355 game.kpower[kk] -= (game.kpower[kk] < 0 ? -kp: kp);
1356 kpow = game.kpower[kk];
1359 if (!damaged(DSRSENS))
1361 proutn(_("%d unit hit on "), (int)hit);
1364 proutn(_("Very small hit on "));
1365 ienm = game.quad[w.x][w.y];
1368 crmena(false,ienm,sector,w);
1372 if ((game.state.remkl + game.state.remcom + game.state.nscrem)==0)
1376 kk--; /* don't do the increment */
1378 else /* decide whether or not to emasculate klingon */
1379 if (kpow > 0 && Rand() >= 0.9 &&
1380 kpow <= ((0.4 + 0.4*Rand())*kpini)) {
1381 prout(_("***Mr. Spock- \"Captain, the vessel at %s"),
1383 prout(_(" has just lost its firepower.\""));
1384 game.kpower[kk] = -kpow;