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? "));
42 if (ja() == true) action = SHDN;
49 proutn(_("Shields are down. Do you want them up? "));
50 if (ja() == true) action = SHUP;
59 case SHUP: /* raise shields */
61 prout(_("Shields already up."));
66 if (game.condition != docked) game.energy -= 50.0;
67 prout(_("Shields raised."));
68 if (game.energy <= 0) {
70 prout(_("Shields raising uses up last of energy."));
78 prout(_("Shields already down."));
83 prout(_("Shields lowered."));
87 while (scan() != IHREAL) {
89 proutn(_("Energy to transfer to shields- "));
92 if (aaitem==0) return;
93 if (aaitem > game.energy) {
94 prout(_("Insufficient ship energy."));
98 if (game.shield+aaitem >= game.inshld) {
99 prout(_("Shield energy maximized."));
100 if (game.shield+aaitem > game.inshld) {
101 prout(_("Excess energy requested returned to ship energy"));
103 game.energy -= game.inshld-game.shield;
104 game.shield = game.inshld;
107 if (aaitem < 0.0 && game.energy-aaitem > game.inenrg) {
108 /* Prevent shield drain loophole */
110 prout(_("Engineering to bridge--"));
111 prout(_(" Scott here. Power circuit problem, Captain."));
112 prout(_(" I can't drain the shields."));
116 if (game.shield+aaitem < 0) {
117 prout(_("All shield energy transferred to ship."));
118 game.energy += game.shield;
122 proutn(_("Scotty- \""));
124 prout(_("Transferring energy to shields.\""));
126 prout(_("Draining energy from shields.\""));
127 game.shield += aaitem;
128 game.energy -= aaitem;
130 case NONE:; /* avoid gcc warning */
134 static int randdevice(void)
135 /* choose a device to damage, at random. */
138 * Quoth Eric Allman in the code of BSD-Trek:
139 * "Under certain conditions you can get a critical hit. This
140 * sort of hit damages devices. The probability that a given
141 * device is damaged depends on the device. Well protected
142 * devices (such as the computer, which is in the core of the
143 * ship and has considerable redundancy) almost never get
144 * damaged, whereas devices which are exposed (such as the
145 * warp engines) or which are particularly delicate (such as
146 * the transporter) have a much higher probability of being
149 * This is one place where OPTION_PLAIN does not restore the
150 * original behavior, which was equiprobable damage across
151 * all devices. If we wanted that, we'd return NDEVICES*Rand()
152 * and have done with it. Also, in the original game, DNAVYS
153 * and DCOMPTR were the same device.
155 * Instead, we use a table of weights similar to the one from BSD Trek.
156 * BSD doesn't have the shuttle, shield controller, death ray, or probes.
157 * We don't have a cloaking device. The shuttle got the allocation
158 * for the cloaking device, then we shaved a half-percent off
159 * everything to have some weight to give DSHCTRL/DDRAY/DDSP.
161 static int weights[NDEVICES] = {
162 105, /* DSRSENS: short range scanners 10.5% */
163 105, /* DLRSENS: long range scanners 10.5% */
164 120, /* DPHASER: phasers 12.0% */
165 120, /* DPHOTON: photon torpedoes 12.0% */
166 25, /* DLIFSUP: life support 2.5% */
167 65, /* DWARPEN: warp drive 6.5% */
168 70, /* DIMPULS: impulse engines 6.5% */
169 145, /* DSHIELD: deflector shields 14.5% */
170 30, /* DRADIO: subspace radio 3.0% */
171 45, /* DSHUTTL: shuttle 4.5% */
172 15, /* DCOMPTR: computer 1.5% */
173 20, /* NAVCOMP: navigation system 2.0% */
174 75, /* DTRANSP: transporter 7.5% */
175 20, /* DSHCTRL: high-speed shield controller 2.0% */
176 10, /* DDRAY: death ray 1.0% */
177 30, /* DDSP: deep-space probes 3.0% */
179 int sum, i, idx = Rand() * 1000.0; /* weights must sum to 1000 */
181 for (i = sum = 0; i < NDEVICES; i++) {
186 return -1; /* we should never get here, but this quiets GCC */
189 void ram(bool ibumpd, feature ienm, coord w)
190 /* make our ship ram something */
192 double hardness, extradm;
195 prouts(_("***RED ALERT! RED ALERT!"));
197 prout(_("***COLLISION IMMINENT."));
202 case IHR: hardness = 1.5; break;
203 case IHC: hardness = 2.0; break;
204 case IHS: hardness = 2.5; break;
205 case IHT: hardness = 0.5; break;
206 case IHQUEST: hardness = 4.0; break;
207 default: hardness = 1.0; break;
209 proutn(ibumpd ? _(" rammed by ") : _(" rams "));
210 crmena(false, ienm, sector, w);
211 if (ibumpd) proutn(_(" (original position)"));
213 deadkl(w, ienm, game.sector);
216 prout(_(" heavily damaged."));
217 icas = 10.0+20.0*Rand();
218 prout(_("***Sickbay reports %d casualties"), icas);
220 game.state.crew -= icas;
222 * In the pre-SST2K version, all devices got equiprobably damaged,
223 * which was silly. Instead, pick up to half the devices at
224 * random according to our weighting table,
226 ncrits = Rand() * (NDEVICES/2);
227 for (m=0; m < ncrits; m++) {
228 int dev = randdevice();
229 if (game.damage[dev] < 0)
231 extradm = (10.0*hardness*Rand()+1.0)*game.damfac;
232 /* Damage for at least time of travel! */
233 game.damage[dev] += game.optime + extradm;
236 prout(_("***Shields are down."));
245 void torpedo(double course, double r, coord in, double *hit, int i, int n)
246 /* let a photon torpedo fly */
250 double ac=course + 0.25*r;
251 double angle = (15.0-ac)*0.5235988;
252 double bullseye = (15.0 - course)*0.5235988;
253 double deltax=-sin(angle), deltay=cos(angle), x=in.x, y=in.y, bigger;
254 double ang, temp, xx, yy, kp, h1;
255 struct quadrant *q = &game.state.galaxy[game.quadrant.x][game.quadrant.y];
258 w.x = w.y = jw.x = jw.y = 0;
259 bigger = fabs(deltax);
260 if (fabs(deltay) > bigger) bigger = fabs(deltay);
263 if (!damaged(DSRSENS) || game.condition==docked)
264 setwnd(srscan_window);
266 setwnd(message_window);
267 /* Loop to move a single torpedo */
268 for (l=1; l <= 15; l++) {
273 if (!VALID_SECTOR(w.x, w.y)) break;
274 iquad=game.quad[w.x][w.y];
275 tracktorpedo(w, l, i, n, iquad);
276 if (iquad==IHDOT) continue;
278 setwnd(message_window);
279 if (damaged(DSRSENS) && !game.condition==docked)
280 skip(1); /* start new line after text track */
282 case IHE: /* Hit our ship */
285 proutn(_("Torpedo hits "));
288 *hit = 700.0 + 100.0*Rand() -
289 1000.0 * distance(w, in) * fabs(sin(bullseye-angle));
291 newcnd(); /* we're blown out of dock */
292 /* We may be displaced. */
293 if (game.landed || game.condition==docked)
294 return; /* Cheat if on a planet */
295 ang = angle + 2.5*(Rand()-0.5);
296 temp = fabs(sin(ang));
297 if (fabs(cos(ang)) > temp) temp = fabs(cos(ang));
302 if (!VALID_SECTOR(jw.x, jw.y)) return;
303 if (game.quad[jw.x][jw.y]==IHBLANK) {
307 if (game.quad[jw.x][jw.y]!=IHDOT) {
308 /* can't move into object */
316 case IHC: /* Hit a commander */
318 if (Rand() <= 0.05) {
319 crmena(true, iquad, sector, w);
320 prout(_(" uses anti-photon device;"));
321 prout(_(" torpedo neutralized."));
324 case IHR: /* Hit a regular enemy */
327 for_local_enemies(ll)
328 if (same(w, game.ks[ll]))
330 kp = fabs(game.kpower[ll]);
331 h1 = 700.0 + 100.0*Rand() -
332 1000.0 * distance(w, in) * fabs(sin(bullseye-angle));
334 if (kp < h1) h1 = kp;
335 game.kpower[ll] -= (game.kpower[ll]<0 ? -h1 : h1);
336 if (game.kpower[ll] == 0) {
340 crmena(true, iquad, sector, w);
341 /* If enemy damaged but not destroyed, try to displace */
342 ang = angle + 2.5*(Rand()-0.5);
343 temp = fabs(sin(ang));
344 if (fabs(cos(ang)) > temp) temp = fabs(cos(ang));
349 if (!VALID_SECTOR(jw.x, jw.y)) {
350 prout(_(" damaged but not destroyed."));
353 if (game.quad[jw.x][jw.y]==IHBLANK) {
354 prout(_(" buffeted into black hole."));
355 deadkl(w, iquad, jw);
358 if (game.quad[jw.x][jw.y]!=IHDOT) {
359 /* can't move into object */
360 prout(_(" damaged but not destroyed."));
363 proutn(_(" damaged--"));
367 case IHB: /* Hit a base */
369 prout(_("***STARBASE DESTROYED.."));
371 if (same(game.state.baseq[ll], game.quadrant)) {
372 game.state.baseq[ll]=game.state.baseq[game.state.rembase];
376 game.quad[w.x][w.y]=IHDOT;
377 game.state.rembase--;
378 game.base.x=game.base.y=0;
380 game.state.chart[game.quadrant.x][game.quadrant.y].starbase--;
384 case IHP: /* Hit a planet */
385 crmena(true, iquad, sector, w);
386 prout(_(" destroyed."));
387 game.state.nplankl++;
388 q->planet = NOPLANET;
389 DESTROY(&game.state.plnets[game.iplnet]);
391 invalidate(game.plnet);
392 game.quad[w.x][w.y] = IHDOT;
394 /* captain perishes on planet */
398 case IHW: /* Hit an inhabited world -- very bad! */
399 crmena(true, iquad, sector, w);
400 prout(_(" destroyed."));
401 game.state.nworldkl++;
402 q->planet = NOPLANET;
403 DESTROY(&game.state.plnets[game.iplnet]);
405 invalidate(game.plnet);
406 game.quad[w.x][w.y] = IHDOT;
408 /* captain perishes on planet */
411 prout(_("You have just destroyed an inhabited planet."));
412 prout(_("Celebratory rallies are being held on the Klingon homeworld."));
414 case IHSTAR: /* Hit a star */
419 crmena(true, IHSTAR, sector, w);
420 prout(_(" unaffected by photon blast."));
422 case IHQUEST: /* Hit a thingy */
423 if (!(game.options & OPTION_THINGY) || Rand()>0.7) {
425 prouts(_("AAAAIIIIEEEEEEEEAAAAAAAAUUUUUGGGGGHHHHHHHHHHHH!!!"));
427 prouts(_(" HACK! HACK! HACK! *CHOKE!* "));
429 proutn(_("Mr. Spock-"));
430 prouts(_(" \"Fascinating!\""));
435 * Stas Sergeev added the possibility that
436 * you can shove the Thingy and piss it off.
437 * It then becomes an enemy and may fire at you.
443 case IHBLANK: /* Black hole */
445 crmena(true, IHBLANK, sector, w);
446 prout(_(" swallows torpedo."));
448 case IHWEB: /* hit the web */
450 prout(_("***Torpedo absorbed by Tholian web."));
452 case IHT: /* Hit a Tholian */
453 h1 = 700.0 + 100.0*Rand() -
454 1000.0 * distance(w, in) * fabs(sin(bullseye-angle));
457 game.quad[w.x][w.y] = IHDOT;
463 crmena(true, IHT, sector, w);
465 prout(_(" survives photon blast."));
468 prout(_(" disappears."));
469 game.quad[w.x][w.y] = IHWEB;
475 default: /* Problem! */
477 proutn("Don't know how to handle collision with ");
478 crmena(true, iquad, sector, w);
484 if(curwnd!=message_window) {
485 setwnd(message_window);
488 game.quad[w.x][w.y]=IHDOT;
489 game.quad[jw.x][jw.y]=iquad;
490 prout(_(" displaced by blast to %s "), cramlc(sector, jw));
491 for_local_enemies(ll)
492 game.kdist[ll] = game.kavgd[ll] = distance(game.sector,game.ks[ll]);
497 prout(_("Torpedo missed."));
501 static void fry(double hit)
502 /* critical-hit resolution */
504 double ncrit, extradm;
505 int ktr=1, loop1, loop2, j, cdam[NDEVICES];
507 /* a critical hit occured */
508 if (hit < (275.0-25.0*game.skill)*(1.0+0.5*Rand())) return;
510 ncrit = 1.0 + hit/(500.0+100.0*Rand());
511 proutn(_("***CRITICAL HIT--"));
512 /* Select devices and cause damage */
513 for (loop1 = 0; loop1 < ncrit; loop1++) {
516 /* Cheat to prevent shuttle damage unless on ship */
518 (game.damage[j]<0.0 || (j==DSHUTTL && game.iscraft != onship));
520 extradm = (hit*game.damfac)/(ncrit*(75.0+25.0*Rand()));
521 game.damage[j] += extradm;
523 for (loop2=2; loop2<=loop1 && j != cdam[loop2-1]; loop2++) ;
524 if (loop2<=loop1) continue;
531 prout(_(" damaged."));
532 if (damaged(DSHIELD) && game.shldup) {
533 prout(_("***Shields knocked down."));
538 void attack(bool torps_ok)
539 /* bad guy attacks us */
541 /* torps_ok == false forces use of phasers in an attack */
542 int percent, loop, iquad;
543 bool usephasers, atackd = false, attempt = false, ihurt = false;
544 double hit, pfac, dustfac, hitmax=0.0, hittot=0.0, chgfac=1.0, r;
546 enum loctype where = neither;
548 /* game could be over at this point, check */
553 prout("=== ATTACK!");
555 /* Tholian gewts to move before attacking */
559 /* if you have just entered the RNZ, you'll get a warning */
560 if (game.neutz) { /* The one chance not to be attacked */
565 /* commanders get a chance to tac-move towards you */
566 if ((((game.comhere || game.ishere) && !game.justin) || game.skill == SKILL_EMERITUS) && torps_ok)
569 /* if no enemies remain after movement, we're done */
570 if (game.nenhere==0 || (game.nenhere==1 && iqhere && !iqengry))
573 /* set up partial hits if attack happens during shield status change */
574 pfac = 1.0/game.inshld;
575 if (game.shldchg) chgfac = 0.25+0.5*Rand();
579 /* message verbosity control */
580 if (game.skill <= SKILL_FAIR)
583 for_local_enemies(loop) {
584 if (game.kpower[loop] < 0) continue; /* too weak to attack */
585 /* compute hit strength and diminish shield power */
587 /* Increase chance of photon torpedos if docked or enemy energy low */
588 if (game.condition == docked) r *= 0.25;
589 if (game.kpower[loop] < 500) r *= 0.25;
591 iquad = game.quad[jay.x][jay.y];
592 if (iquad==IHT || (iquad==IHQUEST && !iqengry)) continue;
593 /* different enemies have different probabilities of throwing a torp */
594 usephasers = !torps_ok || \
595 (iquad == IHK && r > 0.0005) ||
596 (iquad==IHC && r > 0.015) ||
597 (iquad==IHR && r > 0.3) ||
598 (iquad==IHS && r > 0.07) ||
599 (iquad==IHQUEST && r > 0.05);
600 if (usephasers) { /* Enemy uses phasers */
601 if (game.condition == docked) continue; /* Don't waste the effort! */
602 attempt = true; /* Attempt to attack */
603 dustfac = 0.8+0.05*Rand();
604 hit = game.kpower[loop]*pow(dustfac,game.kavgd[loop]);
605 game.kpower[loop] *= 0.75;
607 else { /* Enemy uses photon torpedo */
608 double course = 1.90985*atan2((double)game.sector.y-jay.y, (double)jay.x-game.sector.x);
610 proutn(_("***TORPEDO INCOMING"));
611 if (!damaged(DSRSENS)) {
613 crmena(false, iquad, where, jay);
617 r = (Rand()+Rand())*0.5 -0.5;
618 r += 0.002*game.kpower[loop]*r;
619 torpedo(course, r, jay, &hit, 1, 1);
621 finish(FWON); /* Klingons did themselves in! */
622 if (game.state.galaxy[game.quadrant.x][game.quadrant.y].supernova || game.alldone)
623 return; /* Supernova or finished */
624 if (hit == 0) continue;
626 /* incoming phaser or torpedo, shields may dissipate it */
627 if (game.shldup || game.shldchg || game.condition==docked) {
628 /* shields will take hits */
629 double absorb, hitsh, propor = pfac*game.shield*(game.condition==docked ? 2.1 : 1.0);
630 if (propor < 0.1) propor = 0.1;
631 hitsh = propor*chgfac*hit+1.0;
633 if (absorb > game.shield) absorb = game.shield;
634 game.shield -= absorb;
636 /* taking a hit blasts us out of a starbase dock */
637 if (game.condition == docked)
639 /* but the shields may take care of it */
640 if (propor > 0.1 && hit < 0.005*game.energy)
643 /* hit from this opponent got through shields, so take damage */
645 proutn(_("%d unit hit"), (int)hit);
646 if ((damaged(DSRSENS) && usephasers) || game.skill<=SKILL_FAIR) {
647 proutn(_(" on the "));
650 if (!damaged(DSRSENS) && usephasers) {
652 crmena(false, iquad, where, jay);
655 /* Decide if hit is critical */
656 if (hit > hitmax) hitmax = hit;
661 if (game.energy <= 0) {
662 /* Returning home upon your shield, not with it... */
666 if (!attempt && game.condition == docked)
667 prout(_("***Enemies decide against attacking your ship."));
669 percent = 100.0*pfac*game.shield+0.5;
671 /* Shields fully protect ship */
672 proutn(_("Enemy attack reduces shield strength to "));
675 /* Print message if starship suffered hit(s) */
677 proutn(_("Energy left %2d shields "), (int)game.energy);
678 if (game.shldup) proutn(_("up "));
679 else if (!damaged(DSHIELD)) proutn(_("down "));
680 else proutn(_("damaged, "));
682 prout(_("%d%%, torpedoes left %d"), percent, game.torps);
683 /* Check if anyone was hurt */
684 if (hitmax >= 200 || hittot >= 500) {
685 int icas= hittot*Rand()*0.015;
688 prout(_("Mc Coy- \"Sickbay to bridge. We suffered %d casualties"), icas);
689 prout(_(" in that last attack.\""));
691 game.state.crew -= icas;
694 /* After attack, reset average distance to enemies */
695 for_local_enemies(loop)
696 game.kavgd[loop] = game.kdist[loop];
701 void deadkl(coord w, feature type, coord mv)
702 /* kill a Klingon, Tholian, Romulan, or Thingy */
704 /* Added mv to allow enemy to "move" before dying */
707 crmena(true, type, sector, mv);
708 /* Decide what kind of enemy it is and update appropriately */
710 /* chalk up a Romulan */
711 game.state.galaxy[game.quadrant.x][game.quadrant.y].romulans--;
713 game.state.nromrem--;
715 else if (type == IHT) {
716 /* Killed a Tholian */
719 else if (type == IHQUEST) {
720 /* Killed a Thingy */
721 iqhere = iqengry = false;
725 /* Some type of a Klingon */
726 game.state.galaxy[game.quadrant.x][game.quadrant.y].klingons--;
730 game.comhere = false;
732 if (same(game.state.kcmdr[i], game.quadrant))
734 game.state.kcmdr[i] = game.state.kcmdr[game.state.remcom];
735 game.state.kcmdr[game.state.remcom].x = 0;
736 game.state.kcmdr[game.state.remcom].y = 0;
739 if (game.state.remcom != 0)
740 schedule(FTBEAM, expran(1.0*game.incom/game.state.remcom));
748 game.state.kscmdr.x = game.state.kscmdr.y = game.isatb = 0;
753 default: /* avoids a gcc warning */
754 prout("*** Internal error, deadkl() called on %c\n", type);
759 /* For each kind of enemy, finish message to player */
760 prout(_(" destroyed."));
761 game.quad[w.x][w.y] = IHDOT;
762 if (KLINGREM==0) return;
764 game.state.remtime = game.state.remres/(game.state.remkl + 4*game.state.remcom);
766 /* Remove enemy ship from arrays describing local conditions */
767 if (is_scheduled(FCDBAS) && same(game.battle, game.quadrant) && type==IHC)
770 if (same(game.ks[i], w)) break;
772 if (i <= game.nenhere) {
773 for (j=i; j<=game.nenhere; j++) {
774 game.ks[j] = game.ks[j+1];
775 game.kpower[j] = game.kpower[j+1];
776 game.kavgd[j] = game.kdist[j] = game.kdist[j+1];
779 game.ks[game.nenhere+1].x = 0;
780 game.ks[game.nenhere+1].x = 0;
781 game.kdist[game.nenhere+1] = 0;
782 game.kavgd[game.nenhere+1] = 0;
783 game.kpower[game.nenhere+1] = 0;
787 static bool targetcheck(double x, double y, double *course)
790 /* Return true if target is invalid */
791 if (!VALID_SECTOR(x, y)) {
795 deltx = 0.1*(y - game.sector.y);
796 delty = 0.1*(game.sector.x - x);
797 if (deltx==0 && delty== 0) {
799 prout(_("Spock- \"Bridge to sickbay. Dr. McCoy,"));
800 prout(_(" I recommend an immediate review of"));
801 prout(_(" the Captain's psychological profile.\""));
805 *course = 1.90985932*atan2(deltx, delty);
810 /* launch photon torpedo */
812 double targ[4][3], course[4];
818 if (damaged(DPHOTON)) {
819 prout(_("Photon tubes damaged."));
823 if (game.torps == 0) {
824 prout(_("No torpedoes left."));
830 if (key == IHALPHA) {
834 else if (key == IHEOL) {
835 prout(_("%d torpedoes left."), game.torps);
836 proutn(_("Number of torpedoes to fire- "));
839 else /* key == IHREAL */ {
841 if (n <= 0) { /* abort command */
847 prout(_("Maximum of 3 torpedoes per burst."));
851 if (n <= game.torps) break;
856 for (i = 1; i <= n; i++) {
858 if (i==1 && key == IHEOL) {
859 break; /* we will try prompting */
861 if (i==2 && key == IHEOL) {
862 /* direct all torpedoes at one target */
864 targ[i][1] = targ[1][1];
865 targ[i][2] = targ[1][2];
866 course[i] = course[1];
882 if (targetcheck(targ[i][1], targ[i][2], &course[i])) return;
885 if (i == 1 && key == IHEOL) {
886 /* prompt for each one */
887 for (i = 1; i <= n; i++) {
888 proutn(_("Target sector for torpedo number %d- "), i);
902 if (targetcheck(targ[i][1], targ[i][2], &course[i])) return;
906 /* Loop for moving <n> torpedoes */
907 for (i = 1; i <= n; i++) {
908 if (game.condition != docked) game.torps--;
909 r = (Rand()+Rand())*0.5 -0.5;
910 if (fabs(r) >= 0.47) {
912 r = (Rand()+1.2) * r;
914 prouts(_("***TORPEDO NUMBER %d MISFIRES"), i);
916 else prouts(_("***TORPEDO MISFIRES."));
919 prout(_(" Remainder of burst aborted."));
921 prout(_("***Photon tubes damaged by misfire."));
922 game.damage[DPHOTON] = game.damfac*(1.0+2.0*Rand());
926 if (game.shldup || game.condition == docked)
927 r *= 1.0 + 0.0001*game.shield;
928 torpedo(course[i], r, game.sector, &dummy, i, n);
929 if (game.alldone || game.state.galaxy[game.quadrant.x][game.quadrant.y].supernova)
932 if (KLINGREM==0) finish(FWON);
937 static void overheat(double rpow)
938 /* check for phasers overheating */
941 double chekbrn = (rpow-1500.)*0.00038;
942 if (Rand() <= chekbrn) {
943 prout(_("Weapons officer Sulu- \"Phasers overheated, sir.\""));
944 game.damage[DPHASER] = game.damfac*(1.0 + Rand()) * (1.0+chekbrn);
949 static bool checkshctrl(double rpow)
950 /* check shield control */
956 if (Rand() < 0.998) {
957 prout(_("Shields lowered."));
960 /* Something bad has happened */
961 prouts(_("***RED ALERT! RED ALERT!"));
963 hit = rpow*game.shield/game.inshld;
964 game.energy -= rpow+hit*0.8;
965 game.shield -= hit*0.2;
966 if (game.energy <= 0.0) {
967 prouts(_("Sulu- \"Captain! Shield malf***********************\""));
973 prouts(_("Sulu- \"Captain! Shield malfunction! Phaser fire contained!\""));
975 prout(_("Lt. Uhura- \"Sir, all decks reporting damage.\""));
976 icas = hit*Rand()*0.012;
981 prout(_("McCoy to bridge- \"Severe radiation burns, Jim."));
982 prout(_(" %d casualties so far.\""), icas);
984 game.state.crew -= icas;
987 prout(_("Phaser energy dispersed by shields."));
988 prout(_("Enemy unaffected."));
997 double hits[21], rpow=0, extra, powrem, over, temp;
998 int kz = 0, k=1, i, irec=0; /* Cheating inhibitor */
999 bool ifast = false, no = false, itarg = true, msgflag = true;
1000 enum {NOTSET, MANUAL, FORCEMAN, AUTOMATIC} automode = NOTSET;
1004 /* SR sensors and Computer are needed fopr automode */
1005 if (damaged(DSRSENS) || damaged(DCOMPTR))
1007 if (game.condition == docked) {
1008 prout(_("Phasers can't be fired through base shields."));
1012 if (damaged(DPHASER)) {
1013 prout(_("Phaser control damaged."));
1018 if (damaged(DSHCTRL)) {
1019 prout(_("High speed shield control damaged."));
1023 if (game.energy <= 200.0) {
1024 prout(_("Insufficient energy to activate high-speed shield control."));
1028 prout(_("Weapons Officer Sulu- \"High-speed shield control enabled, sir.\""));
1032 /* Original code so convoluted, I re-did it all */
1033 while (automode==NOTSET) {
1035 if (key == IHALPHA) {
1036 if (isit("manual")) {
1037 if (game.nenhere==0) {
1038 prout(_("There is no enemy present to select."));
1048 else if (isit("automatic")) {
1049 if ((!itarg) && game.nenhere != 0) {
1050 automode = FORCEMAN;
1053 if (game.nenhere==0)
1054 prout(_("Energy will be expended into space."));
1055 automode = AUTOMATIC;
1059 else if (isit("no")) {
1067 else if (key == IHREAL) {
1068 if (game.nenhere==0) {
1069 prout(_("Energy will be expended into space."));
1070 automode = AUTOMATIC;
1073 automode = FORCEMAN;
1075 automode = AUTOMATIC;
1079 if (game.nenhere==0) {
1080 prout(_("Energy will be expended into space."));
1081 automode = AUTOMATIC;
1084 automode = FORCEMAN;
1086 proutn(_("Manual or automatic? "));
1092 if (key == IHALPHA && isit("no")) {
1096 if (key != IHREAL && game.nenhere != 0) {
1097 prout(_("Phasers locked on target. Energy available: %.2f"),
1098 ifast?game.energy-200.0:game.energy);
1103 if (!kz) for_local_enemies(i)
1104 irec+=fabs(game.kpower[i])/(PHASEFAC*pow(0.90,game.kdist[i]))*
1105 (1.01+0.05*Rand()) + 1.0;
1107 proutn(_("%d units required. "), irec);
1109 proutn(_("Units to fire= "));
1111 if (key!=IHREAL) return;
1113 if (rpow > (ifast?game.energy-200:game.energy)) {
1114 proutn(_("Energy available= %.2f"),
1115 ifast?game.energy-200:game.energy);
1119 } while (rpow > (ifast?game.energy-200:game.energy));
1125 if ((key=scan()) == IHALPHA && isit("no")) {
1129 game.energy -= 200; /* Go and do it! */
1130 if (checkshctrl(rpow)) return;
1133 game.energy -= rpow;
1138 for_local_enemies(i) {
1140 if (powrem <= 0) continue;
1141 hits[i] = fabs(game.kpower[i])/(PHASEFAC*pow(0.90,game.kdist[i]));
1142 over = (0.01 + 0.05*Rand())*hits[i];
1144 powrem -= hits[i] + over;
1145 if (powrem <= 0 && temp < hits[i]) hits[i] = temp;
1146 if (powrem <= 0) over = 0.0;
1149 if (powrem > 0.0) extra += powrem;
1153 if (extra > 0 && !game.alldone) {
1155 proutn(_("*** Tholian web absorbs "));
1156 if (game.nenhere>0) proutn(_("excess "));
1157 prout(_("phaser energy."));
1160 prout(_("%d expended on empty space."), (int)extra);
1168 if (damaged(DCOMPTR))
1169 prout(_("Battle computer damaged, manual fire only."));
1172 prouts(_("---WORKING---"));
1174 prout(_("Short-range-sensors-damaged"));
1175 prout(_("Insufficient-data-for-automatic-phaser-fire"));
1176 prout(_("Manual-fire-must-be-used"));
1181 for (k = 1; k <= game.nenhere;) {
1182 coord aim = game.ks[k];
1183 int ienm = game.quad[aim.x][aim.y];
1185 proutn(_("Energy available= %.2f"),
1186 game.energy-.006-(ifast?200:0));
1191 if (damaged(DSRSENS) && !(abs(game.sector.x-aim.x) < 2 && abs(game.sector.y-aim.y) < 2) &&
1192 (ienm == IHC || ienm == IHS)) {
1194 prout(_(" can't be located without short range scan."));
1197 hits[k] = 0; /* prevent overflow -- thanks to Alexei Voitenko */
1203 if (itarg && k > kz)
1204 irec=(fabs(game.kpower[k])/(PHASEFAC*pow(0.9,game.kdist[k])))*
1205 (1.01+0.05*Rand()) + 1.0;
1208 if (!damaged(DCOMPTR)) proutn("%d", irec);
1211 proutn(_("units to fire at "));
1212 crmena(false, ienm, sector, aim);
1216 if (key == IHALPHA && isit("no")) {
1221 if (key == IHALPHA) {
1226 if (k==1) { /* Let me say I'm baffled by this */
1238 /* If total requested is too much, inform and start over */
1240 if (rpow > (ifast?game.energy-200:game.energy)) {
1241 prout(_("Available energy exceeded -- try again."));
1245 key = scan(); /* scan for next value */
1249 /* zero energy -- abort */
1253 if (key == IHALPHA && isit("no")) {
1256 game.energy -= rpow;
1259 game.energy -= 200.0;
1260 if (checkshctrl(rpow)) return;
1264 case NOTSET:; /* avoid gcc warning */
1266 /* Say shield raised or malfunction, if necessary */
1272 if (Rand() >= 0.99) {
1273 prout(_("Sulu- \"Sir, the high-speed shield control has malfunctioned . . ."));
1274 prouts(_(" CLICK CLICK POP . . ."));
1275 prout(_(" No response, sir!"));
1276 game.shldup = false;
1279 prout(_("Shields raised."));
1282 game.shldup = false;
1287 void hittem(double *hits)
1288 /* register a phaser hit on Klingons and Romulans */
1290 double kp, kpow, wham, hit, dustfac, kpini;
1291 int nenhr2=game.nenhere, k=1, kk=1, ienm;
1296 for (; k <= nenhr2; k++, kk++) {
1297 if ((wham = hits[k])==0) continue;
1298 dustfac = 0.9 + 0.01*Rand();
1299 hit = wham*pow(dustfac,game.kdist[kk]);
1300 kpini = game.kpower[kk];
1302 if (PHASEFAC*hit < kp) kp = PHASEFAC*hit;
1303 game.kpower[kk] -= (game.kpower[kk] < 0 ? -kp: kp);
1304 kpow = game.kpower[kk];
1307 if (!damaged(DSRSENS))
1309 proutn(_("%d unit hit on "), (int)hit);
1312 proutn(_("Very small hit on "));
1313 ienm = game.quad[w.x][w.y];
1314 if (ienm==IHQUEST) iqengry = true;
1315 crmena(false,ienm,sector,w);
1319 if (KLINGREM==0) finish(FWON);
1320 if (game.alldone) return;
1321 kk--; /* don't do the increment */
1323 else /* decide whether or not to emasculate klingon */
1324 if (kpow > 0 && Rand() >= 0.9 &&
1325 kpow <= ((0.4 + 0.4*Rand())*kpini)) {
1326 prout(_("***Mr. Spock- \"Captain, the vessel at %s"),
1328 prout(_(" has just lost its firepower.\""));
1329 game.kpower[kk] = -kpow;