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."));
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_local_enemies(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.."));
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 DESTROY(&game.state.planets[game.iplnet]);
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 DESTROY(&game.state.planets[game.iplnet]);
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_local_enemies(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++) ;
546 prout(_(" damaged."));
547 if (damaged(DSHIELD) && game.shldup) {
548 prout(_("***Shields knocked down."));
553 void attack(bool torps_ok)
554 /* bad guy attacks us */
556 /* torps_ok == false forces use of phasers in an attack */
557 int percent, loop, iquad;
558 bool usephasers, atackd = false, attempt = false, ihurt = false;
559 double hit, pfac, dustfac, hitmax=0.0, hittot=0.0, chgfac=1.0, r;
561 enum loctype where = neither;
563 /* game could be over at this point, check */
568 prout("=== ATTACK!");
570 /* Tholian gewts to move before attacking */
574 /* if you have just entered the RNZ, you'll get a warning */
575 if (game.neutz) { /* The one chance not to be attacked */
580 /* commanders get a chance to tac-move towards you */
581 if ((((game.comhere || game.ishere) && !game.justin) || game.skill == SKILL_EMERITUS) && torps_ok)
584 /* if no enemies remain after movement, we're done */
585 if (game.nenhere==0 || (game.nenhere==1 && iqhere && !iqengry))
588 /* set up partial hits if attack happens during shield status change */
589 pfac = 1.0/game.inshld;
591 chgfac = 0.25+0.5*Rand();
595 /* message verbosity control */
596 if (game.skill <= SKILL_FAIR)
599 for_local_enemies(loop) {
600 if (game.kpower[loop] < 0) continue; /* too weak to attack */
601 /* compute hit strength and diminish shield power */
603 /* Increase chance of photon torpedos if docked or enemy energy low */
604 if (game.condition == docked)
606 if (game.kpower[loop] < 500)
609 iquad = game.quad[jay.x][jay.y];
610 if (iquad==IHT || (iquad==IHQUEST && !iqengry))
612 /* different enemies have different probabilities of throwing a torp */
613 usephasers = !torps_ok || \
614 (iquad == IHK && r > 0.0005) ||
615 (iquad==IHC && r > 0.015) ||
616 (iquad==IHR && r > 0.3) ||
617 (iquad==IHS && r > 0.07) ||
618 (iquad==IHQUEST && r > 0.05);
619 if (usephasers) { /* Enemy uses phasers */
620 if (game.condition == docked) continue; /* Don't waste the effort! */
621 attempt = true; /* Attempt to attack */
622 dustfac = 0.8+0.05*Rand();
623 hit = game.kpower[loop]*pow(dustfac,game.kavgd[loop]);
624 game.kpower[loop] *= 0.75;
626 else { /* Enemy uses photon torpedo */
627 double course = 1.90985*atan2((double)game.sector.y-jay.y, (double)jay.x-game.sector.x);
629 proutn(_("***TORPEDO INCOMING"));
630 if (!damaged(DSRSENS)) {
632 crmena(false, iquad, where, jay);
636 r = (Rand()+Rand())*0.5 -0.5;
637 r += 0.002*game.kpower[loop]*r;
638 torpedo(course, r, jay, &hit, 1, 1);
640 finish(FWON); /* Klingons did themselves in! */
641 if (game.state.galaxy[game.quadrant.x][game.quadrant.y].supernova || game.alldone)
642 return; /* Supernova or finished */
646 /* incoming phaser or torpedo, shields may dissipate it */
647 if (game.shldup || game.shldchg || game.condition==docked) {
648 /* shields will take hits */
649 double absorb, hitsh, propor = pfac*game.shield*(game.condition==docked ? 2.1 : 1.0);
652 hitsh = propor*chgfac*hit+1.0;
654 if (absorb > game.shield)
655 absorb = game.shield;
656 game.shield -= absorb;
658 /* taking a hit blasts us out of a starbase dock */
659 if (game.condition == docked)
661 /* but the shields may take care of it */
662 if (propor > 0.1 && hit < 0.005*game.energy)
665 /* hit from this opponent got through shields, so take damage */
667 proutn(_("%d unit hit"), (int)hit);
668 if ((damaged(DSRSENS) && usephasers) || game.skill<=SKILL_FAIR) {
669 proutn(_(" on the "));
672 if (!damaged(DSRSENS) && usephasers) {
674 crmena(false, iquad, where, jay);
677 /* Decide if hit is critical */
684 if (game.energy <= 0) {
685 /* Returning home upon your shield, not with it... */
689 if (!attempt && game.condition == docked)
690 prout(_("***Enemies decide against attacking your ship."));
693 percent = 100.0*pfac*game.shield+0.5;
695 /* Shields fully protect ship */
696 proutn(_("Enemy attack reduces shield strength to "));
699 /* Print message if starship suffered hit(s) */
701 proutn(_("Energy left %2d shields "), (int)game.energy);
704 else if (!damaged(DSHIELD))
707 proutn(_("damaged, "));
709 prout(_("%d%%, torpedoes left %d"), percent, game.torps);
710 /* Check if anyone was hurt */
711 if (hitmax >= 200 || hittot >= 500) {
712 int icas= hittot*Rand()*0.015;
715 prout(_("Mc Coy- \"Sickbay to bridge. We suffered %d casualties"), icas);
716 prout(_(" in that last attack.\""));
718 game.state.crew -= icas;
721 /* After attack, reset average distance to enemies */
722 for_local_enemies(loop)
723 game.kavgd[loop] = game.kdist[loop];
728 void deadkl(coord w, feature type, coord mv)
729 /* kill a Klingon, Tholian, Romulan, or Thingy */
731 /* Added mv to allow enemy to "move" before dying */
734 crmena(true, type, sector, mv);
735 /* Decide what kind of enemy it is and update appropriately */
737 /* chalk up a Romulan */
738 game.state.galaxy[game.quadrant.x][game.quadrant.y].romulans--;
740 game.state.nromrem--;
742 else if (type == IHT) {
743 /* Killed a Tholian */
746 else if (type == IHQUEST) {
747 /* Killed a Thingy */
748 iqhere = iqengry = false;
752 /* Some type of a Klingon */
753 game.state.galaxy[game.quadrant.x][game.quadrant.y].klingons--;
757 game.comhere = false;
759 if (same(game.state.kcmdr[i], game.quadrant))
761 game.state.kcmdr[i] = game.state.kcmdr[game.state.remcom];
762 game.state.kcmdr[game.state.remcom].x = 0;
763 game.state.kcmdr[game.state.remcom].y = 0;
766 if (game.state.remcom != 0)
767 schedule(FTBEAM, expran(1.0*game.incom/game.state.remcom));
775 game.state.kscmdr.x = game.state.kscmdr.y = game.isatb = 0;
780 default: /* avoids a gcc warning */
781 prout("*** Internal error, deadkl() called on %c\n", type);
786 /* For each kind of enemy, finish message to player */
787 prout(_(" destroyed."));
788 game.quad[w.x][w.y] = IHDOT;
792 game.state.remtime = game.state.remres/(game.state.remkl + 4*game.state.remcom);
794 /* Remove enemy ship from arrays describing local conditions */
795 if (is_scheduled(FCDBAS) && same(game.battle, game.quadrant) && type==IHC)
798 if (same(game.ks[i], w))
801 if (i <= game.nenhere) {
802 for (j=i; j<=game.nenhere; j++) {
803 game.ks[j] = game.ks[j+1];
804 game.kpower[j] = game.kpower[j+1];
805 game.kavgd[j] = game.kdist[j] = game.kdist[j+1];
808 game.ks[game.nenhere+1].x = 0;
809 game.ks[game.nenhere+1].x = 0;
810 game.kdist[game.nenhere+1] = 0;
811 game.kavgd[game.nenhere+1] = 0;
812 game.kpower[game.nenhere+1] = 0;
816 static bool targetcheck(double x, double y, double *course)
819 /* Return true if target is invalid */
820 if (!VALID_SECTOR(x, y)) {
824 deltx = 0.1*(y - game.sector.y);
825 delty = 0.1*(game.sector.x - x);
826 if (deltx==0 && delty== 0) {
828 prout(_("Spock- \"Bridge to sickbay. Dr. McCoy,"));
829 prout(_(" I recommend an immediate review of"));
830 prout(_(" the Captain's psychological profile.\""));
834 *course = 1.90985932*atan2(deltx, delty);
839 /* launch photon torpedo */
841 double targ[4][3], course[4];
847 if (damaged(DPHOTON)) {
848 prout(_("Photon tubes damaged."));
852 if (game.torps == 0) {
853 prout(_("No torpedoes left."));
859 if (key == IHALPHA) {
863 else if (key == IHEOL) {
864 prout(_("%d torpedoes left."), game.torps);
865 proutn(_("Number of torpedoes to fire- "));
868 else /* key == IHREAL */ {
870 if (n <= 0) { /* abort command */
876 prout(_("Maximum of 3 torpedoes per burst."));
886 for (i = 1; i <= n; i++) {
888 if (i==1 && key == IHEOL) {
889 break; /* we will try prompting */
891 if (i==2 && key == IHEOL) {
892 /* direct all torpedoes at one target */
894 targ[i][1] = targ[1][1];
895 targ[i][2] = targ[1][2];
896 course[i] = course[1];
912 if (targetcheck(targ[i][1], targ[i][2], &course[i]))
916 if (i == 1 && key == IHEOL) {
917 /* prompt for each one */
918 for (i = 1; i <= n; i++) {
919 proutn(_("Target sector for torpedo number %d- "), i);
933 if (targetcheck(targ[i][1], targ[i][2], &course[i]))
938 /* Loop for moving <n> torpedoes */
939 for (i = 1; i <= n; i++) {
940 if (game.condition != docked)
942 r = (Rand()+Rand())*0.5 -0.5;
943 if (fabs(r) >= 0.47) {
945 r = (Rand()+1.2) * r;
947 prouts(_("***TORPEDO NUMBER %d MISFIRES"), i);
950 prouts(_("***TORPEDO MISFIRES."));
953 prout(_(" Remainder of burst aborted."));
955 prout(_("***Photon tubes damaged by misfire."));
956 game.damage[DPHOTON] = game.damfac*(1.0+2.0*Rand());
960 if (game.shldup || game.condition == docked)
961 r *= 1.0 + 0.0001*game.shield;
962 torpedo(course[i], r, game.sector, &dummy, i, n);
963 if (game.alldone || game.state.galaxy[game.quadrant.x][game.quadrant.y].supernova)
972 static void overheat(double rpow)
973 /* check for phasers overheating */
976 double chekbrn = (rpow-1500.)*0.00038;
977 if (Rand() <= chekbrn) {
978 prout(_("Weapons officer Sulu- \"Phasers overheated, sir.\""));
979 game.damage[DPHASER] = game.damfac*(1.0 + Rand()) * (1.0+chekbrn);
984 static bool checkshctrl(double rpow)
985 /* check shield control */
991 if (Rand() < 0.998) {
992 prout(_("Shields lowered."));
995 /* Something bad has happened */
996 prouts(_("***RED ALERT! RED ALERT!"));
998 hit = rpow*game.shield/game.inshld;
999 game.energy -= rpow+hit*0.8;
1000 game.shield -= hit*0.2;
1001 if (game.energy <= 0.0) {
1002 prouts(_("Sulu- \"Captain! Shield malf***********************\""));
1008 prouts(_("Sulu- \"Captain! Shield malfunction! Phaser fire contained!\""));
1010 prout(_("Lt. Uhura- \"Sir, all decks reporting damage.\""));
1011 icas = hit*Rand()*0.012;
1016 prout(_("McCoy to bridge- \"Severe radiation burns, Jim."));
1017 prout(_(" %d casualties so far.\""), icas);
1018 game.casual += icas;
1019 game.state.crew -= icas;
1022 prout(_("Phaser energy dispersed by shields."));
1023 prout(_("Enemy unaffected."));
1032 double hits[21], rpow=0, extra, powrem, over, temp;
1033 int kz = 0, k=1, i, irec=0; /* Cheating inhibitor */
1034 bool ifast = false, no = false, itarg = true, msgflag = true;
1035 enum {NOTSET, MANUAL, FORCEMAN, AUTOMATIC} automode = NOTSET;
1039 /* SR sensors and Computer are needed fopr automode */
1040 if (damaged(DSRSENS) || damaged(DCOMPTR))
1042 if (game.condition == docked) {
1043 prout(_("Phasers can't be fired through base shields."));
1047 if (damaged(DPHASER)) {
1048 prout(_("Phaser control damaged."));
1053 if (damaged(DSHCTRL)) {
1054 prout(_("High speed shield control damaged."));
1058 if (game.energy <= 200.0) {
1059 prout(_("Insufficient energy to activate high-speed shield control."));
1063 prout(_("Weapons Officer Sulu- \"High-speed shield control enabled, sir.\""));
1067 /* Original code so convoluted, I re-did it all */
1068 while (automode==NOTSET) {
1070 if (key == IHALPHA) {
1071 if (isit("manual")) {
1072 if (game.nenhere==0) {
1073 prout(_("There is no enemy present to select."));
1083 else if (isit("automatic")) {
1084 if ((!itarg) && game.nenhere != 0) {
1085 automode = FORCEMAN;
1088 if (game.nenhere==0)
1089 prout(_("Energy will be expended into space."));
1090 automode = AUTOMATIC;
1094 else if (isit("no")) {
1102 else if (key == IHREAL) {
1103 if (game.nenhere==0) {
1104 prout(_("Energy will be expended into space."));
1105 automode = AUTOMATIC;
1108 automode = FORCEMAN;
1110 automode = AUTOMATIC;
1114 if (game.nenhere==0) {
1115 prout(_("Energy will be expended into space."));
1116 automode = AUTOMATIC;
1119 automode = FORCEMAN;
1121 proutn(_("Manual or automatic? "));
1127 if (key == IHALPHA && isit("no")) {
1131 if (key != IHREAL && game.nenhere != 0) {
1132 prout(_("Phasers locked on target. Energy available: %.2f"),
1133 ifast?game.energy-200.0:game.energy);
1138 if (!kz) for_local_enemies(i)
1139 irec+=fabs(game.kpower[i])/(PHASEFAC*pow(0.90,game.kdist[i]))*
1140 (1.01+0.05*Rand()) + 1.0;
1142 proutn(_("%d units required. "), irec);
1144 proutn(_("Units to fire= "));
1149 if (rpow > (ifast?game.energy-200:game.energy)) {
1150 proutn(_("Energy available= %.2f"),
1151 ifast?game.energy-200:game.energy);
1155 } while (rpow > (ifast?game.energy-200:game.energy));
1161 if ((key=scan()) == IHALPHA && isit("no")) {
1165 game.energy -= 200; /* Go and do it! */
1166 if (checkshctrl(rpow))
1170 game.energy -= rpow;
1175 for_local_enemies(i) {
1179 hits[i] = fabs(game.kpower[i])/(PHASEFAC*pow(0.90,game.kdist[i]));
1180 over = (0.01 + 0.05*Rand())*hits[i];
1182 powrem -= hits[i] + over;
1183 if (powrem <= 0 && temp < hits[i])
1194 if (extra > 0 && !game.alldone) {
1196 proutn(_("*** Tholian web absorbs "));
1198 proutn(_("excess "));
1199 prout(_("phaser energy."));
1202 prout(_("%d expended on empty space."), (int)extra);
1210 if (damaged(DCOMPTR))
1211 prout(_("Battle computer damaged, manual fire only."));
1214 prouts(_("---WORKING---"));
1216 prout(_("Short-range-sensors-damaged"));
1217 prout(_("Insufficient-data-for-automatic-phaser-fire"));
1218 prout(_("Manual-fire-must-be-used"));
1223 for (k = 1; k <= game.nenhere;) {
1224 coord aim = game.ks[k];
1225 int ienm = game.quad[aim.x][aim.y];
1227 proutn(_("Energy available= %.2f"),
1228 game.energy-.006-(ifast?200:0));
1233 if (damaged(DSRSENS) && !(abs(game.sector.x-aim.x) < 2 && abs(game.sector.y-aim.y) < 2) &&
1234 (ienm == IHC || ienm == IHS)) {
1236 prout(_(" can't be located without short range scan."));
1239 hits[k] = 0; /* prevent overflow -- thanks to Alexei Voitenko */
1245 if (itarg && k > kz)
1246 irec=(fabs(game.kpower[k])/(PHASEFAC*pow(0.9,game.kdist[k])))*
1247 (1.01+0.05*Rand()) + 1.0;
1250 if (!damaged(DCOMPTR))
1255 proutn(_("units to fire at "));
1256 crmena(false, ienm, sector, aim);
1260 if (key == IHALPHA && isit("no")) {
1265 if (key == IHALPHA) {
1270 if (k==1) { /* Let me say I'm baffled by this */
1282 /* If total requested is too much, inform and start over */
1284 if (rpow > (ifast?game.energy-200:game.energy)) {
1285 prout(_("Available energy exceeded -- try again."));
1289 key = scan(); /* scan for next value */
1293 /* zero energy -- abort */
1297 if (key == IHALPHA && isit("no")) {
1300 game.energy -= rpow;
1303 game.energy -= 200.0;
1304 if (checkshctrl(rpow))
1309 case NOTSET:; /* avoid gcc warning */
1311 /* Say shield raised or malfunction, if necessary */
1317 if (Rand() >= 0.99) {
1318 prout(_("Sulu- \"Sir, the high-speed shield control has malfunctioned . . ."));
1319 prouts(_(" CLICK CLICK POP . . ."));
1320 prout(_(" No response, sir!"));
1321 game.shldup = false;
1324 prout(_("Shields raised."));
1327 game.shldup = false;
1332 void hittem(double *hits)
1333 /* register a phaser hit on Klingons and Romulans */
1335 double kp, kpow, wham, hit, dustfac, kpini;
1336 int nenhr2=game.nenhere, k=1, kk=1, ienm;
1341 for (; k <= nenhr2; k++, kk++) {
1342 if ((wham = hits[k])==0)
1344 dustfac = 0.9 + 0.01*Rand();
1345 hit = wham*pow(dustfac,game.kdist[kk]);
1346 kpini = game.kpower[kk];
1348 if (PHASEFAC*hit < kp)
1350 game.kpower[kk] -= (game.kpower[kk] < 0 ? -kp: kp);
1351 kpow = game.kpower[kk];
1354 if (!damaged(DSRSENS))
1356 proutn(_("%d unit hit on "), (int)hit);
1359 proutn(_("Very small hit on "));
1360 ienm = game.quad[w.x][w.y];
1363 crmena(false,ienm,sector,w);
1371 kk--; /* don't do the increment */
1373 else /* decide whether or not to emasculate klingon */
1374 if (kpow > 0 && Rand() >= 0.9 &&
1375 kpow <= ((0.4 + 0.4*Rand())*kpini)) {
1376 prout(_("***Mr. Spock- \"Captain, the vessel at %s"),
1378 prout(_(" has just lost its firepower.\""));
1379 game.kpower[kk] = -kpow;