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 skip(1); /* start new line after text track */
281 case IHE: /* Hit our ship */
284 proutn(_("Torpedo hits "));
287 *hit = 700.0 + 100.0*Rand() -
288 1000.0 * distance(w, in) * fabs(sin(bullseye-angle));
290 newcnd(); /* we're blown out of dock */
291 /* We may be displaced. */
292 if (game.landed==1 || game.condition==docked) return; /* Cheat if on a planet */
293 ang = angle + 2.5*(Rand()-0.5);
294 temp = fabs(sin(ang));
295 if (fabs(cos(ang)) > temp) temp = fabs(cos(ang));
300 if (!VALID_SECTOR(jw.x, jw.y)) return;
301 if (game.quad[jw.x][jw.y]==IHBLANK) {
305 if (game.quad[jw.x][jw.y]!=IHDOT) {
306 /* can't move into object */
314 case IHC: /* Hit a commander */
316 if (Rand() <= 0.05) {
317 crmena(true, iquad, sector, w);
318 prout(_(" uses anti-photon device;"));
319 prout(_(" torpedo neutralized."));
322 case IHR: /* Hit a regular enemy */
325 for_local_enemies(ll)
326 if (same(w, game.ks[ll]))
328 kp = fabs(game.kpower[ll]);
329 h1 = 700.0 + 100.0*Rand() -
330 1000.0 * distance(w, in) * fabs(sin(bullseye-angle));
332 if (kp < h1) h1 = kp;
333 game.kpower[ll] -= (game.kpower[ll]<0 ? -h1 : h1);
334 if (game.kpower[ll] == 0) {
338 crmena(true, iquad, sector, w);
339 /* If enemy damaged but not destroyed, try to displace */
340 ang = angle + 2.5*(Rand()-0.5);
341 temp = fabs(sin(ang));
342 if (fabs(cos(ang)) > temp) temp = fabs(cos(ang));
347 if (!VALID_SECTOR(jw.x, jw.y)) {
348 prout(_(" damaged but not destroyed."));
351 if (game.quad[jw.x][jw.y]==IHBLANK) {
352 prout(_(" buffeted into black hole."));
353 deadkl(w, iquad, jw);
356 if (game.quad[jw.x][jw.y]!=IHDOT) {
357 /* can't move into object */
358 prout(_(" damaged but not destroyed."));
361 proutn(_(" damaged--"));
365 case IHB: /* Hit a base */
367 prout(_("***STARBASE DESTROYED.."));
369 if (same(game.state.baseq[ll], game.quadrant)) {
370 game.state.baseq[ll]=game.state.baseq[game.state.rembase];
374 game.quad[w.x][w.y]=IHDOT;
375 game.state.rembase--;
376 game.base.x=game.base.y=0;
378 game.state.chart[game.quadrant.x][game.quadrant.y].starbase--;
382 case IHP: /* Hit a planet */
383 crmena(true, iquad, sector, w);
384 prout(_(" destroyed."));
385 game.state.nplankl++;
386 q->planet = NOPLANET;
387 DESTROY(&game.state.plnets[game.iplnet]);
389 game.plnet.x = game.plnet.y = 0;
390 game.quad[w.x][w.y] = IHDOT;
391 if (game.landed==1) {
392 /* captain perishes on planet */
396 case IHW: /* Hit an inhabited world -- very bad! */
397 crmena(true, iquad, sector, w);
398 prout(_(" destroyed."));
399 game.state.nworldkl++;
400 q->planet = NOPLANET;
401 DESTROY(&game.state.plnets[game.iplnet]);
403 game.plnet.x = game.plnet.y = 0;
404 game.quad[w.x][w.y] = IHDOT;
405 if (game.landed==1) {
406 /* captain perishes on planet */
409 prout("You have just destroyed an inhabited planet.");
410 prout("Celebratory rallies are being held on the Klingon homeworld.");
412 case IHSTAR: /* Hit a star */
417 crmena(true, IHSTAR, sector, w);
418 prout(_(" unaffected by photon blast."));
420 case IHQUEST: /* Hit a thingy */
421 if (!(game.options & OPTION_THINGY) || Rand()>0.7) {
423 prouts(_("AAAAIIIIEEEEEEEEAAAAAAAAUUUUUGGGGGHHHHHHHHHHHH!!!"));
425 prouts(_(" HACK! HACK! HACK! *CHOKE!* "));
427 proutn(_("Mr. Spock-"));
428 prouts(_(" \"Fascinating!\""));
433 * Stas Sergeev added the possibility that
434 * you can shove the Thingy and piss it off.
435 * It then becomes an enemy and may fire at you.
441 case IHBLANK: /* Black hole */
443 crmena(true, IHBLANK, sector, w);
444 prout(_(" swallows torpedo."));
446 case IHWEB: /* hit the web */
448 prout(_("***Torpedo absorbed by Tholian web."));
450 case IHT: /* Hit a Tholian */
451 h1 = 700.0 + 100.0*Rand() -
452 1000.0 * distance(w, in) * fabs(sin(bullseye-angle));
455 game.quad[w.x][w.y] = IHDOT;
461 crmena(true, IHT, sector, w);
463 prout(_(" survives photon blast."));
466 prout(_(" disappears."));
467 game.quad[w.x][w.y] = IHWEB;
473 default: /* Problem! */
475 proutn("Don't know how to handle collision with ");
476 crmena(true, iquad, sector, w);
482 if(curwnd!=message_window) {
483 setwnd(message_window);
486 game.quad[w.x][w.y]=IHDOT;
487 game.quad[jw.x][jw.y]=iquad;
488 prout(_(" displaced by blast to %s "), cramlc(sector, jw));
489 for_local_enemies(ll)
490 game.kdist[ll] = game.kavgd[ll] = distance(game.sector,game.ks[ll]);
495 prout(_("Torpedo missed."));
499 static void fry(double hit)
500 /* critical-hit resolution */
502 double ncrit, extradm;
503 int ktr=1, loop1, loop2, j, cdam[NDEVICES];
505 /* a critical hit occured */
506 if (hit < (275.0-25.0*game.skill)*(1.0+0.5*Rand())) return;
508 ncrit = 1.0 + hit/(500.0+100.0*Rand());
509 proutn(_("***CRITICAL HIT--"));
510 /* Select devices and cause damage */
511 for (loop1 = 0; loop1 < ncrit; loop1++) {
514 /* Cheat to prevent shuttle damage unless on ship */
516 (game.damage[j]<0.0 || (j==DSHUTTL && game.iscraft!=1));
518 extradm = (hit*game.damfac)/(ncrit*(75.0+25.0*Rand()));
519 game.damage[j] += extradm;
521 for (loop2=2; loop2<=loop1 && j != cdam[loop2-1]; loop2++) ;
522 if (loop2<=loop1) continue;
529 prout(_(" damaged."));
530 if (damaged(DSHIELD) && game.shldup) {
531 prout(_("***Shields knocked down."));
536 void attack(bool torps_ok)
537 /* bad guy attacks us */
539 /* torps_ok == false forces use of phasers in an attack */
540 int percent, loop, iquad;
541 bool itflag, atackd = false, attempt = false, ihurt = false;
542 double hit, pfac, dustfac, hitmax=0.0, hittot=0.0, chgfac=1.0, r;
544 enum loctype where = neither;
547 if (game.alldone) return;
548 if (idebug) prout("=== ATTACK!");
550 if (game.ithere) movetho();
552 if (game.neutz) { /* The one chance not to be attacked */
556 if ((((game.comhere || game.ishere) && !game.justin) || game.skill == SKILL_EMERITUS) && torps_ok) movcom();
557 if (game.nenhere==0 || (game.nenhere==1 && iqhere && !iqengry)) return;
558 pfac = 1.0/game.inshld;
559 if (game.shldchg == 1) chgfac = 0.25+0.5*Rand();
561 if (game.skill <= SKILL_FAIR) where = sector;
562 for_local_enemies(loop) {
563 if (game.kpower[loop] < 0) continue; /* too weak to attack */
564 /* compute hit strength and diminsh shield power */
566 /* Increase chance of photon torpedos if docked or enemy energy low */
567 if (game.condition == docked) r *= 0.25;
568 if (game.kpower[loop] < 500) r *= 0.25;
570 iquad = game.quad[jay.x][jay.y];
571 if (iquad==IHT || (iquad==IHQUEST && !iqengry)) continue;
572 itflag = (iquad == IHK && r > 0.0005) || !torps_ok ||
573 (iquad==IHC && r > 0.015) ||
574 (iquad==IHR && r > 0.3) ||
575 (iquad==IHS && r > 0.07) ||
576 (iquad==IHQUEST && r > 0.05);
578 /* Enemy uses phasers */
579 if (game.condition == docked) continue; /* Don't waste the effort! */
580 attempt = true; /* Attempt to attack */
581 dustfac = 0.8+0.05*Rand();
582 hit = game.kpower[loop]*pow(dustfac,game.kavgd[loop]);
583 game.kpower[loop] *= 0.75;
585 else { /* Enemy used photon torpedo */
586 double course = 1.90985*atan2((double)game.sector.y-jay.y, (double)jay.x-game.sector.x);
588 proutn(_("***TORPEDO INCOMING"));
589 if (!damaged(DSRSENS)) {
591 crmena(false, iquad, where, jay);
595 r = (Rand()+Rand())*0.5 -0.5;
596 r += 0.002*game.kpower[loop]*r;
597 torpedo(course, r, jay, &hit, 1, 1);
599 finish(FWON); /* Klingons did themselves in! */
600 if (game.state.galaxy[game.quadrant.x][game.quadrant.y].supernova || game.alldone)
601 return; /* Supernova or finished */
602 if (hit == 0) continue;
604 if (game.shldup || game.shldchg != 0 || game.condition==docked) {
605 /* shields will take hits */
606 double absorb, hitsh, propor = pfac*game.shield*(game.condition==docked ? 2.1 : 1.0);
607 if(propor < 0.1) propor = 0.1;
608 hitsh = propor*chgfac*hit+1.0;
611 if (absorb > game.shield) absorb = game.shield;
612 game.shield -= absorb;
614 if (game.condition==docked) dock(false);
615 if (propor > 0.1 && hit < 0.005*game.energy) continue;
617 /* It's a hit -- print out hit size */
618 atackd = true; /* We weren't going to check casualties, etc. if
619 shields were down for some strange reason. This
620 doesn't make any sense, so I've fixed it */
622 proutn(_("%d unit hit"), (int)hit);
623 if ((damaged(DSRSENS) && itflag) || game.skill<=SKILL_FAIR) {
624 proutn(_(" on the "));
627 if (!damaged(DSRSENS) && itflag) {
629 crmena(false, iquad, where, jay);
632 /* Decide if hit is critical */
633 if (hit > hitmax) hitmax = hit;
637 if (game.condition==docked)
640 if (game.energy <= 0) {
641 /* Returning home upon your shield, not with it... */
645 if (!attempt && game.condition == docked)
646 prout(_("***Enemies decide against attacking your ship."));
648 percent = 100.0*pfac*game.shield+0.5;
650 /* Shields fully protect ship */
651 proutn(_("Enemy attack reduces shield strength to "));
654 /* Print message if starship suffered hit(s) */
656 proutn(_("Energy left %2d shields "), (int)game.energy);
657 if (game.shldup) proutn(_("up "));
658 else if (!damaged(DSHIELD)) proutn(_("down "));
659 else proutn(_("damaged, "));
661 prout(_("%d%%, torpedoes left %d"), percent, game.torps);
662 /* Check if anyone was hurt */
663 if (hitmax >= 200 || hittot >= 500) {
664 int icas= hittot*Rand()*0.015;
667 prout(_("Mc Coy- \"Sickbay to bridge. We suffered %d casualties"), icas);
668 prout(_(" in that last attack.\""));
670 game.state.crew -= icas;
673 /* After attack, reset average distance to enemies */
674 for_local_enemies(loop)
675 game.kavgd[loop] = game.kdist[loop];
680 void deadkl(coord w, feature type, coord mv)
681 /* kill a Klingon, Tholian, Romulan, or Thingy */
683 /* Added mv to allow enemy to "move" before dying */
687 crmena(true, type, sector, mv);
688 /* Decide what kind of enemy it is and update approriately */
690 /* chalk up a Romulan */
691 game.state.galaxy[game.quadrant.x][game.quadrant.y].romulans--;
693 game.state.nromrem--;
695 else if (type == IHT) {
696 /* Killed a Tholian */
699 else if (type == IHQUEST) {
700 /* Killed a Thingy */
701 iqhere = iqengry = false;
702 thing.x =thing.y = 0;
705 /* Some type of a Klingon */
706 game.state.galaxy[game.quadrant.x][game.quadrant.y].klingons--;
710 game.comhere = false;
712 if (game.state.kcmdr[i].x==game.quadrant.x && game.state.kcmdr[i].y==game.quadrant.y) break;
713 game.state.kcmdr[i] = game.state.kcmdr[game.state.remcom];
714 game.state.kcmdr[game.state.remcom].x = 0;
715 game.state.kcmdr[game.state.remcom].y = 0;
718 if (game.state.remcom != 0)
719 schedule(FTBEAM, expran(1.0*game.incom/game.state.remcom));
727 game.state.kscmdr.x = game.state.kscmdr.y = game.isatb = game.iscate = 0;
731 default: /* avoids a gcc warning */
732 prout("*** Internal error, deadkl() called on %c\n", type);
737 /* For each kind of enemy, finish message to player */
738 prout(_(" destroyed."));
739 game.quad[w.x][w.y] = IHDOT;
740 if (KLINGREM==0) return;
742 game.state.remtime = game.state.remres/(game.state.remkl + 4*game.state.remcom);
744 /* Remove enemy ship from arrays describing local conditions */
745 if (is_scheduled(FCDBAS) && game.battle.x==game.quadrant.x && game.battle.y==game.quadrant.y && type==IHC)
748 if (same(game.ks[i], w)) break;
750 if (i <= game.nenhere) {
751 for (j=i; j<=game.nenhere; j++) {
752 game.ks[j] = game.ks[j+1];
753 game.kpower[j] = game.kpower[j+1];
754 game.kavgd[j] = game.kdist[j] = game.kdist[j+1];
757 game.ks[game.nenhere+1].x = 0;
758 game.ks[game.nenhere+1].x = 0;
759 game.kdist[game.nenhere+1] = 0;
760 game.kavgd[game.nenhere+1] = 0;
761 game.kpower[game.nenhere+1] = 0;
765 static bool targetcheck(double x, double y, double *course)
768 /* Return true if target is invalid */
769 if (!VALID_SECTOR(x, y)) {
773 deltx = 0.1*(y - game.sector.y);
774 delty = 0.1*(game.sector.x - x);
775 if (deltx==0 && delty== 0) {
777 prout(_("Spock- \"Bridge to sickbay. Dr. McCoy,"));
778 prout(_(" I recommend an immediate review of"));
779 prout(_(" the Captain's psychological profile.\""));
783 *course = 1.90985932*atan2(deltx, delty);
788 /* launch photon torpedo */
790 double targ[4][3], course[4];
797 if (damaged(DPHOTON)) {
798 prout(_("Photon tubes damaged."));
802 if (game.torps == 0) {
803 prout(_("No torpedoes left."));
809 if (key == IHALPHA) {
813 else if (key == IHEOL) {
814 prout(_("%d torpedoes left."), game.torps);
815 proutn(_("Number of torpedoes to fire- "));
818 else /* key == IHREAL */ {
820 if (n <= 0) { /* abort command */
826 prout(_("Maximum of 3 torpedoes per burst."));
830 if (n <= game.torps) break;
835 for (i = 1; i <= n; i++) {
837 if (i==1 && key == IHEOL) {
838 break; /* we will try prompting */
840 if (i==2 && key == IHEOL) {
841 /* direct all torpedoes at one target */
843 targ[i][1] = targ[1][1];
844 targ[i][2] = targ[1][2];
845 course[i] = course[1];
861 if (targetcheck(targ[i][1], targ[i][2], &course[i])) return;
864 if (i == 1 && key == IHEOL) {
865 /* prompt for each one */
866 for (i = 1; i <= n; i++) {
867 proutn(_("Target sector for torpedo number %d- "), i);
881 if (targetcheck(targ[i][1], targ[i][2], &course[i])) return;
885 /* Loop for moving <n> torpedoes */
887 for (i = 1; i <= n && !osuabor; i++) {
888 if (game.condition != docked) game.torps--;
889 r = (Rand()+Rand())*0.5 -0.5;
890 if (fabs(r) >= 0.47) {
892 r = (Rand()+1.2) * r;
894 prouts(_("***TORPEDO NUMBER %d MISFIRES"), i);
896 else prouts(_("***TORPEDO MISFIRES."));
899 prout(_(" Remainder of burst aborted."));
902 prout(_("***Photon tubes damaged by misfire."));
903 game.damage[DPHOTON] = game.damfac*(1.0+2.0*Rand());
907 if (game.shldup || game.condition == docked)
908 r *= 1.0 + 0.0001*game.shield;
909 torpedo(course[i], r, game.sector, &dummy, i, n);
910 if (game.alldone || game.state.galaxy[game.quadrant.x][game.quadrant.y].supernova)
913 if (KLINGREM==0) finish(FWON);
918 static void overheat(double rpow)
919 /* check for phasers overheating */
922 double chekbrn = (rpow-1500.)*0.00038;
923 if (Rand() <= chekbrn) {
924 prout(_("Weapons officer Sulu- \"Phasers overheated, sir.\""));
925 game.damage[DPHASER] = game.damfac*(1.0 + Rand()) * (1.0+chekbrn);
930 static bool checkshctrl(double rpow)
931 /* check shield control */
937 if (Rand() < 0.998) {
938 prout(_("Shields lowered."));
941 /* Something bad has happened */
942 prouts(_("***RED ALERT! RED ALERT!"));
944 hit = rpow*game.shield/game.inshld;
945 game.energy -= rpow+hit*0.8;
946 game.shield -= hit*0.2;
947 if (game.energy <= 0.0) {
948 prouts(_("Sulu- \"Captain! Shield malf***********************\""));
954 prouts(_("Sulu- \"Captain! Shield malfunction! Phaser fire contained!\""));
956 prout(_("Lt. Uhura- \"Sir, all decks reporting damage.\""));
957 icas = hit*Rand()*0.012;
962 prout(_("McCoy to bridge- \"Severe radiation burns, Jim."));
963 prout(_(" %d casualties so far.\""), icas);
965 game.state.crew -= icas;
968 prout(_("Phaser energy dispersed by shields."));
969 prout(_("Enemy unaffected."));
978 double hits[21], rpow=0, extra, powrem, over, temp;
979 int kz = 0, k=1, i, irec=0; /* Cheating inhibitor */
980 bool ifast = false, no = false, itarg = true, msgflag = true;
981 enum {NOTSET, MANUAL, FORCEMAN, AUTOMATIC} automode = NOTSET;
985 /* SR sensors and Computer are needed fopr automode */
986 if (damaged(DSRSENS) || damaged(DCOMPTR))
988 if (game.condition == docked) {
989 prout(_("Phasers can't be fired through base shields."));
993 if (damaged(DPHASER)) {
994 prout(_("Phaser control damaged."));
999 if (damaged(DSHCTRL)) {
1000 prout(_("High speed shield control damaged."));
1004 if (game.energy <= 200.0) {
1005 prout(_("Insufficient energy to activate high-speed shield control."));
1009 prout(_("Weapons Officer Sulu- \"High-speed shield control enabled, sir.\""));
1013 /* Original code so convoluted, I re-did it all */
1014 while (automode==NOTSET) {
1016 if (key == IHALPHA) {
1017 if (isit("manual")) {
1018 if (game.nenhere==0) {
1019 prout(_("There is no enemy present to select."));
1029 else if (isit("automatic")) {
1030 if ((!itarg) && game.nenhere != 0) {
1031 automode = FORCEMAN;
1034 if (game.nenhere==0)
1035 prout(_("Energy will be expended into space."));
1036 automode = AUTOMATIC;
1040 else if (isit("no")) {
1048 else if (key == IHREAL) {
1049 if (game.nenhere==0) {
1050 prout(_("Energy will be expended into space."));
1051 automode = AUTOMATIC;
1054 automode = FORCEMAN;
1056 automode = AUTOMATIC;
1060 if (game.nenhere==0) {
1061 prout(_("Energy will be expended into space."));
1062 automode = AUTOMATIC;
1065 automode = FORCEMAN;
1067 proutn(_("Manual or automatic? "));
1073 if (key == IHALPHA && isit("no")) {
1077 if (key != IHREAL && game.nenhere != 0) {
1078 prout(_("Phasers locked on target. Energy available: %.2f"),
1079 ifast?game.energy-200.0:game.energy,1,2);
1084 if (!kz) for_local_enemies(i)
1085 irec+=fabs(game.kpower[i])/(PHASEFAC*pow(0.90,game.kdist[i]))*
1086 (1.01+0.05*Rand()) + 1.0;
1088 proutn(_("(%d) units required. "), irec);
1090 proutn(_("Units to fire= "));
1092 if (key!=IHREAL) return;
1094 if (rpow > (ifast?game.energy-200:game.energy)) {
1095 proutn(_("Energy available= %.2f"),
1096 ifast?game.energy-200:game.energy);
1100 } while (rpow > (ifast?game.energy-200:game.energy));
1106 if ((key=scan()) == IHALPHA && isit("no")) {
1110 game.energy -= 200; /* Go and do it! */
1111 if (checkshctrl(rpow)) return;
1114 game.energy -= rpow;
1119 for_local_enemies(i) {
1121 if (powrem <= 0) continue;
1122 hits[i] = fabs(game.kpower[i])/(PHASEFAC*pow(0.90,game.kdist[i]));
1123 over = (0.01 + 0.05*Rand())*hits[i];
1125 powrem -= hits[i] + over;
1126 if (powrem <= 0 && temp < hits[i]) hits[i] = temp;
1127 if (powrem <= 0) over = 0.0;
1130 if (powrem > 0.0) extra += powrem;
1134 if (extra > 0 && !game.alldone) {
1136 proutn(_("*** Tholian web absorbs "));
1137 if (game.nenhere>0) proutn(_("excess "));
1138 prout(_("phaser energy."));
1141 prout(_("%d expended on empty space."), (int)extra);
1149 if (damaged(DCOMPTR))
1150 prout(_("Battle computer damaged, manual file only."));
1153 prouts(_("---WORKING---"));
1155 prout(_("Short-range-sensors-damaged"));
1156 prout(_("Insufficient-data-for-automatic-phaser-fire"));
1157 prout(_("Manual-fire-must-be-used"));
1162 for (k = 1; k <= game.nenhere;) {
1163 coord aim = game.ks[k];
1164 int ienm = game.quad[aim.x][aim.y];
1166 proutn(_("Energy available= %.2f"),
1167 game.energy-.006-(ifast?200:0));
1172 if (damaged(DSRSENS) && !(abs(game.sector.x-aim.x) < 2 && abs(game.sector.y-aim.y) < 2) &&
1173 (ienm == IHC || ienm == IHS)) {
1175 prout(_(" can't be located without short range scan."));
1178 hits[k] = 0; /* prevent overflow -- thanks to Alexei Voitenko */
1184 if (itarg && k > kz)
1185 irec=(fabs(game.kpower[k])/(PHASEFAC*pow(0.9,game.kdist[k])))*
1186 (1.01+0.05*Rand()) + 1.0;
1189 if (!damaged(DCOMPTR)) proutn("%d", irec);
1192 proutn(_("units to fire at "));
1193 crmena(false, ienm, sector, aim);
1197 if (key == IHALPHA && isit("no")) {
1202 if (key == IHALPHA) {
1207 if (k==1) { /* Let me say I'm baffled by this */
1219 /* If total requested is too much, inform and start over */
1221 if (rpow > (ifast?game.energy-200:game.energy)) {
1222 prout(_("Available energy exceeded -- try again."));
1226 key = scan(); /* scan for next value */
1230 /* zero energy -- abort */
1234 if (key == IHALPHA && isit("no")) {
1237 game.energy -= rpow;
1240 game.energy -= 200.0;
1241 if (checkshctrl(rpow)) return;
1245 case NOTSET:; /* avoid gcc warning */
1247 /* Say shield raised or malfunction, if necessary */
1253 if (Rand() >= 0.99) {
1254 prout(_("Sulu- \"Sir, the high-speed shield control has malfunctioned . . ."));
1255 prouts(_(" CLICK CLICK POP . . ."));
1256 prout(_(" No response, sir!"));
1257 game.shldup = false;
1260 prout(_("Shields raised."));
1263 game.shldup = false;
1268 void hittem(double *hits)
1269 /* register a phaser hit on Klingons and Romulans */
1271 double kp, kpow, wham, hit, dustfac, kpini;
1272 int nenhr2=game.nenhere, k=1, kk=1, ienm;
1277 for (; k <= nenhr2; k++, kk++) {
1278 if ((wham = hits[k])==0) continue;
1279 dustfac = 0.9 + 0.01*Rand();
1280 hit = wham*pow(dustfac,game.kdist[kk]);
1281 kpini = game.kpower[kk];
1283 if (PHASEFAC*hit < kp) kp = PHASEFAC*hit;
1284 game.kpower[kk] -= (game.kpower[kk] < 0 ? -kp: kp);
1285 kpow = game.kpower[kk];
1288 if (!damaged(DSRSENS))
1290 proutn(_("%d unit hit on "), (int)hit);
1293 proutn(_("Very small hit on "));
1294 ienm = game.quad[w.x][w.y];
1295 if (ienm==IHQUEST) iqengry = true;
1296 crmena(false,ienm,sector,w);
1300 if (KLINGREM==0) finish(FWON);
1301 if (game.alldone) return;
1302 kk--; /* don't do the increment */
1304 else /* decide whether or not to emasculate klingon */
1305 if (kpow > 0 && Rand() >= 0.9 &&
1306 kpow <= ((0.4 + 0.4*Rand())*kpini)) {
1307 prout(_("***Mr. Spock- \"Captain, the vessel at "),
1309 prout(_(" has just lost its firepower.\""));
1310 game.kpower[kk] = -kpow;