6 enum {NONE, SHUP, SHDN, NRG} action = NONE;
10 if (i == 2) action = SHUP;
18 if (game.damage[DSHIELD]) {
19 prout(_("Shields damaged and down."));
24 else if (isit("down"))
29 proutn(_("Do you wish to change shield energy? "));
31 proutn(_("Energy to transfer to shields- "));
34 else if (game.damage[DSHIELD]) {
35 prout(_("Shields damaged and down."));
38 else if (game.shldup) {
39 proutn(_("Shields are up. Do you want them down? "));
40 if (ja()) action = SHDN;
47 proutn(_("Shields are down. Do you want them up? "));
48 if (ja()) action = SHUP;
57 case SHUP: /* raise shields */
59 prout(_("Shields already up."));
64 if (game.condit != IHDOCKED) game.energy -= 50.0;
65 prout(_("Shields raised."));
66 if (game.energy <= 0) {
68 prout(_("Shields raising uses up last of energy."));
76 prout(_("Shields already down."));
81 prout(_("Shields lowered."));
85 while (scan() != IHREAL) {
87 proutn(_("Energy to transfer to shields- "));
90 if (aaitem==0) return;
91 if (aaitem > game.energy) {
92 prout(_("Insufficient ship energy."));
96 if (game.shield+aaitem >= game.inshld) {
97 prout(_("Shield energy maximized."));
98 if (game.shield+aaitem > game.inshld) {
99 prout(_("Excess energy requested returned to ship energy"));
101 game.energy -= game.inshld-game.shield;
102 game.shield = game.inshld;
105 if (aaitem < 0.0 && game.energy-aaitem > game.inenrg) {
106 /* Prevent shield drain loophole */
108 prout(_("Engineering to bridge--"));
109 prout(_(" Scott here. Power circuit problem, Captain."));
110 prout(_(" I can't drain the shields."));
114 if (game.shield+aaitem < 0) {
115 prout(_("All shield energy transferred to ship."));
116 game.energy += game.shield;
120 proutn(_("Scotty- \""));
122 prout(_("Transferring energy to shields.\""));
124 prout(_("Draining energy from shields.\""));
125 game.shield += aaitem;
126 game.energy -= aaitem;
128 case NONE:; /* avoid gcc warning */
132 void ram(int ibumpd, int ienm, int ix, int iy)
134 double type = 1.0, extradm;
137 prouts(_("***RED ALERT! RED ALERT!"));
139 prout(_("***COLLISION IMMINENT."));
144 case IHR: type = 1.5; break;
145 case IHC: type = 2.0; break;
146 case IHS: type = 2.5; break;
147 case IHT: type = 0.5; break;
148 case IHQUEST: type = 4.0; break;
150 proutn(ibumpd ? _(" rammed by ") : _(" rams "));
151 crmena(0, ienm, 2, ix, iy);
152 if (ibumpd) proutn(_(" (original position)"));
154 deadkl(ix, iy, ienm, game.sectx, game.secty);
157 prout(_(" heavily damaged."));
158 icas = 10.0+20.0*Rand();
159 prout(_("***Sickbay reports %d casualties"), icas);
161 for (l=0; l < NDEVICES; l++) {
163 continue; // Don't damage deathray
164 if (game.damage[l] < 0)
166 extradm = (10.0*type*Rand()+1.0)*game.damfac;
167 game.damage[l] += game.optime + extradm; /* Damage for at least time of travel! */
178 void torpedo(double course, double r, int inx, int iny, double *hit, int i, int n)
180 int l, iquad=0, ix=0, iy=0, jx=0, jy=0, shoved=0, ll;
182 double ac=course + 0.25*r;
183 double angle = (15.0-ac)*0.5235988;
184 double bullseye = (15.0 - course)*0.5235988;
185 double deltax=-sin(angle), deltay=cos(angle), x=inx, y=iny, bigger;
186 double ang, temp, xx, yy, kp, h1;
188 bigger = fabs(deltax);
189 if (fabs(deltay) > bigger) bigger = fabs(deltay);
192 if (game.damage[DSRSENS]==0 || game.condit==IHDOCKED)
193 setwnd(srscan_window);
195 setwnd(message_window);
196 /* Loop to move a single torpedo */
197 for (l=1; l <= 15; l++) {
202 if (!VALID_SECTOR(ix, iy)) break;
203 iquad=game.quad[ix][iy];
204 tracktorpedo(ix, iy, l, i, n, iquad);
205 if (iquad==IHDOT) continue;
207 setwnd(message_window);
208 skip(1); /* start new line after text track */
210 case IHE: /* Hit our ship */
213 proutn(_("Torpedo hits "));
216 *hit = 700.0 + 100.0*Rand() -
217 1000.0*sqrt(square(ix-inx)+square(iy-iny))*
218 fabs(sin(bullseye-angle));
220 newcnd(); /* we're blown out of dock */
221 /* We may be displaced. */
222 if (game.landed==1 || game.condit==IHDOCKED) return; /* Cheat if on a planet */
223 ang = angle + 2.5*(Rand()-0.5);
224 temp = fabs(sin(ang));
225 if (fabs(cos(ang)) > temp) temp = fabs(cos(ang));
230 if (!VALID_SECTOR(jx, jy)) return;
231 if (game.quad[jx][jy]==IHBLANK) {
235 if (game.quad[jx][jy]!=IHDOT) {
236 /* can't move into object */
245 case IHC: /* Hit a commander */
247 if (Rand() <= 0.05) {
248 crmena(1, iquad, 2, ix, iy);
249 prout(_(" uses anti-photon device;"));
250 prout(_(" torpedo neutralized."));
253 case IHR: /* Hit a regular enemy */
256 for_local_enemies(ll)
257 if (ix==game.kx[ll] && iy==game.ky[ll]) break;
258 kp = fabs(game.kpower[ll]);
259 h1 = 700.0 + 100.0*Rand() -
260 1000.0*sqrt(square(ix-inx)+square(iy-iny))*
261 fabs(sin(bullseye-angle));
263 if (kp < h1) h1 = kp;
264 game.kpower[ll] -= (game.kpower[ll]<0 ? -h1 : h1);
265 if (game.kpower[ll] == 0) {
266 deadkl(ix, iy, iquad, ix, iy);
269 crmena(1, iquad, 2, ix, iy);
270 /* If enemy damaged but not destroyed, try to displace */
271 ang = angle + 2.5*(Rand()-0.5);
272 temp = fabs(sin(ang));
273 if (fabs(cos(ang)) > temp) temp = fabs(cos(ang));
278 if (!VALID_SECTOR(jx, jy)) {
279 prout(_(" damaged but not destroyed."));
282 if (game.quad[jx][jy]==IHBLANK) {
283 prout(_(" buffeted into black hole."));
284 deadkl(ix, iy, iquad, jx, jy);
287 if (game.quad[jx][jy]!=IHDOT) {
288 /* can't move into object */
289 prout(_(" damaged but not destroyed."));
292 proutn(_(" damaged--"));
297 case IHB: /* Hit a base */
299 prout(_("***STARBASE DESTROYED.."));
301 if (game.state.baseqx[ll]==game.quadx && game.state.baseqy[ll]==game.quady) {
302 game.state.baseqx[ll]=game.state.baseqx[game.state.rembase];
303 game.state.baseqy[ll]=game.state.baseqy[game.state.rembase];
307 game.quad[ix][iy]=IHDOT;
308 game.state.rembase--;
309 game.basex=game.basey=0;
310 game.state.galaxy[game.quadx][game.quady].starbase--;
311 game.state.chart[game.quadx][game.quady].starbase--;
315 case IHP: /* Hit a planet */
316 crmena(1, iquad, 2, ix, iy);
317 prout(_(" destroyed."));
318 game.state.nplankl++;
319 game.state.galaxy[game.quadx][game.quady].planet = NULL;
320 DESTROY(&game.state.plnets[game.iplnet]);
322 game.plnetx = game.plnety = 0;
323 game.quad[ix][iy] = IHDOT;
324 if (game.landed==1) {
325 /* captain perishes on planet */
329 case IHSTAR: /* Hit a star */
334 crmena(1, IHSTAR, 2, ix, iy);
335 prout(_(" unaffected by photon blast."));
337 case IHQUEST: /* Hit a thingy */
338 if (!(game.options & OPTION_THINGY) || Rand()>0.7) {
340 prouts(_("AAAAIIIIEEEEEEEEAAAAAAAAUUUUUGGGGGHHHHHHHHHHHH!!!"));
342 prouts(_(" HACK! HACK! HACK! *CHOKE!* "));
344 proutn(_("Mr. Spock-"));
345 prouts(_(" \"Fascinating!\""));
347 deadkl(ix, iy, iquad, ix, iy);
350 * Stas Sergeev added the possibility that
351 * you can shove the Thingy and piss it off.
352 * It then becomes an enemy and may fire at you.
358 case IHBLANK: /* Black hole */
360 crmena(1, IHBLANK, 2, ix, iy);
361 prout(_(" swallows torpedo."));
363 case IHWEB: /* hit the web */
365 prout(_("***Torpedo absorbed by Tholian web."));
367 case IHT: /* Hit a Tholian */
368 h1 = 700.0 + 100.0*Rand() -
369 1000.0*sqrt(square(ix-inx)+square(iy-iny))*
370 fabs(sin(bullseye-angle));
373 game.quad[ix][iy] = IHDOT;
375 game.ithx = game.ithy = 0;
376 deadkl(ix, iy, iquad, ix, iy);
380 crmena(1, IHT, 2, ix, iy);
382 prout(_(" survives photon blast."));
385 prout(_(" disappears."));
386 game.quad[ix][iy] = IHWEB;
387 game.ithere = game.ithx = game.ithy = 0;
391 dropin(IHBLANK, &dum, &my);
395 default: /* Problem! */
397 proutn("Don't know how to handle collision with ");
398 crmena(1, iquad, 2, ix, iy);
404 if(curwnd!=message_window) {
405 setwnd(message_window);
408 game.quad[jx][jy]=iquad;
409 game.quad[ix][iy]=IHDOT;
410 prout(_(" displaced by blast to %s "), cramlc(sector, jx, jy));
411 for_local_enemies(ll)
412 game.kdist[ll] = game.kavgd[ll] = sqrt(square(game.sectx-game.kx[ll])+square(game.secty-game.ky[ll]));
417 prout(_("Torpedo missed."));
421 static void fry(double hit)
423 double ncrit, extradm;
424 int ktr=1, l, ll, j, cdam[NDEVICES];
426 /* a critical hit occured */
427 if (hit < (275.0-25.0*game.skill)*(1.0+0.5*Rand())) return;
429 ncrit = 1.0 + hit/(500.0+100.0*Rand());
430 proutn(_("***CRITICAL HIT--"));
431 /* Select devices and cause damage */
432 for (l = 0; l < ncrit && 0 < NDEVICES; l++) {
435 /* Cheat to prevent shuttle damage unless on ship */
437 (game.damage[j]<0.0 || (j==DSHUTTL && game.iscraft!=1) || j==DDRAY);
439 extradm = (hit*game.damfac)/(ncrit*(75.0+25.0*Rand()));
440 game.damage[j] += extradm;
442 for (ll=2; ll<=l && j != cdam[ll-1]; ll++) ;
450 prout(_(" damaged."));
451 if (game.damage[DSHIELD] && game.shldup) {
452 prout(_("***Shields knocked down."));
457 void attack(int torps_ok)
459 /* torps_ok == 0 forces use of phasers in an attack */
460 int percent, ihurt=0, l, i=0, jx, jy, iquad, itflag;
461 int atackd = 0, attempt = 0;
463 double pfac, dustfac, hitmax=0.0, hittot=0.0, chgfac=1.0, r;
466 if (game.alldone) return;
468 if (game.idebug) prout("ATTACK!");
471 if (game.ithere) movetho();
473 if (game.neutz) { /* The one chance not to be attacked */
477 if ((((game.comhere || game.ishere) && (game.justin == 0)) || game.skill == SKILL_EMERITUS)&&(torps_ok!=0)) movcom();
478 if (game.nenhere==0 || (game.nenhere==1 && iqhere && iqengry==0)) return;
479 pfac = 1.0/game.inshld;
480 if (game.shldchg == 1) chgfac = 0.25+0.5*Rand();
482 if (game.skill <= SKILL_FAIR) i = 2;
483 for_local_enemies(l) {
484 if (game.kpower[l] < 0) continue; /* too weak to attack */
485 /* compute hit strength and diminsh shield power */
487 /* Increase chance of photon torpedos if docked or enemy energy low */
488 if (game.condit == IHDOCKED) r *= 0.25;
489 if (game.kpower[l] < 500) r *= 0.25;
492 iquad = game.quad[jx][jy];
493 if (iquad==IHT || (iquad==IHQUEST && !iqengry)) continue;
494 itflag = (iquad == IHK && r > 0.0005) || !torps_ok ||
495 (iquad==IHC && r > 0.015) ||
496 (iquad==IHR && r > 0.3) ||
497 (iquad==IHS && r > 0.07) ||
498 (iquad==IHQUEST && r > 0.05);
500 /* Enemy uses phasers */
501 if (game.condit == IHDOCKED) continue; /* Don't waste the effort! */
502 attempt = 1; /* Attempt to attack */
503 dustfac = 0.8+0.05*Rand();
504 hit = game.kpower[l]*pow(dustfac,game.kavgd[l]);
505 game.kpower[l] *= 0.75;
507 else { /* Enemy used photon torpedo */
508 double course = 1.90985*atan2((double)game.secty-jy, (double)jx-game.sectx);
510 proutn(_("***TORPEDO INCOMING"));
511 if (game.damage[DSRSENS] <= 0.0) {
513 crmena(0, iquad, i, jx, jy);
517 r = (Rand()+Rand())*0.5 -0.5;
518 r += 0.002*game.kpower[l]*r;
519 torpedo(course, r, jx, jy, &hit, 1, 1);
521 finish(FWON); /* Klingons did themselves in! */
522 if (game.state.galaxy[game.quadx][game.quady].supernova || game.alldone)
523 return; /* Supernova or finished */
524 if (hit == 0) continue;
526 if (game.shldup != 0 || game.shldchg != 0 || game.condit==IHDOCKED) {
527 /* shields will take hits */
528 double absorb, hitsh, propor = pfac*game.shield*(game.condit==IHDOCKED ? 2.1 : 1.0);
529 if(propor < 0.1) propor = 0.1;
530 hitsh = propor*chgfac*hit+1.0;
533 if (absorb > game.shield) absorb = game.shield;
534 game.shield -= absorb;
536 if (game.condit==IHDOCKED) dock(0);
537 if (propor > 0.1 && hit < 0.005*game.energy) continue;
539 /* It's a hit -- print out hit size */
540 atackd = 1; /* We weren't going to check casualties, etc. if
541 shields were down for some strange reason. This
542 doesn't make any sense, so I've fixed it */
544 proutn(_("%d unit hit"), (int)hit);
545 if ((game.damage[DSRSENS] > 0 && itflag) || game.skill<=SKILL_FAIR) {
546 proutn(_(" on the "));
549 if (game.damage[DSRSENS] <= 0.0 && itflag) {
551 crmena(0, iquad, i, jx, jy);
554 /* Decide if hit is critical */
555 if (hit > hitmax) hitmax = hit;
559 if (game.condit==IHDOCKED)
562 if (game.energy <= 0) {
563 /* Returning home upon your shield, not with it... */
567 if (attempt == 0 && game.condit == IHDOCKED)
568 prout(_("***Enemies decide against attacking your ship."));
569 if (atackd == 0) return;
570 percent = 100.0*pfac*game.shield+0.5;
572 /* Shields fully protect ship */
573 proutn(_("Enemy attack reduces shield strength to "));
576 /* Print message if starship suffered hit(s) */
578 proutn(_("Energy left %2d shields "), (int)game.energy);
579 if (game.shldup) proutn(_("up "));
580 else if (game.damage[DSHIELD] == 0) proutn(_("down "));
581 else proutn(_("damaged, "));
583 prout(_("%d%%, torpedoes left %d"), percent, game.torps);
584 /* Check if anyone was hurt */
585 if (hitmax >= 200 || hittot >= 500) {
586 int icas= hittot*Rand()*0.015;
589 prout(_("Mc Coy- \"Sickbay to bridge. We suffered %d casualties"), icas);
590 prout(_(" in that last attack.\""));
594 /* After attack, reset average distance to enemies */
596 game.kavgd[l] = game.kdist[l];
601 void deadkl(int ix, int iy, int type, int ixx, int iyy)
603 /* Added ixx and iyy allow enemy to "move" before dying */
608 crmena(1, type, 2, ixx, iyy);
609 /* Decide what kind of enemy it is and update approriately */
611 /* chalk up a Romulan */
612 game.state.galaxy[game.quadx][game.quady].romulans--;
614 game.state.nromrem--;
616 else if (type == IHT) {
617 /* Killed a Tholian */
620 else if (type == IHQUEST) {
621 /* Killed a Thingy */
622 iqhere=iqengry=thingx=thingy=0;
625 /* Some type of a Klingon */
626 game.state.galaxy[game.quadx][game.quady].klingons--;
632 if (game.state.cx[i]==game.quadx && game.state.cy[i]==game.quady) break;
633 game.state.cx[i] = game.state.cx[game.state.remcom];
634 game.state.cy[i] = game.state.cy[game.state.remcom];
635 game.state.cx[game.state.remcom] = 0;
636 game.state.cy[game.state.remcom] = 0;
639 if (game.state.remcom != 0)
640 schedule(FTBEAM, expran(1.0*game.incom/game.state.remcom));
647 game.ishere = game.state.isx = game.state.isy = game.isatb = game.iscate = 0;
654 /* For each kind of enemy, finish message to player */
655 prout(_(" destroyed."));
656 game.quad[ix][iy] = IHDOT;
657 if (KLINGREM==0) return;
659 game.state.remtime = game.state.remres/(game.state.remkl + 4*game.state.remcom);
661 /* Remove enemy ship from arrays describing local game.conditions */
662 if (is_scheduled(FCDBAS) && game.batx==game.quadx && game.baty==game.quady && type==IHC)
665 if (game.kx[i]==ix && game.ky[i]==iy) break;
667 if (i <= game.nenhere) {
668 for (j=i; j<=game.nenhere; j++) {
669 game.kx[j] = game.kx[j+1];
670 game.ky[j] = game.ky[j+1];
671 game.kpower[j] = game.kpower[j+1];
672 game.kavgd[j] = game.kdist[j] = game.kdist[j+1];
675 game.kx[game.nenhere+1] = 0;
676 game.ky[game.nenhere+1] = 0;
677 game.kdist[game.nenhere+1] = 0;
678 game.kavgd[game.nenhere+1] = 0;
679 game.kpower[game.nenhere+1] = 0;
683 static int targetcheck(double x, double y, double *course)
686 /* Return TRUE if target is invalid */
687 if (!VALID_SECTOR(x, y)) {
691 deltx = 0.1*(y - game.secty);
692 delty = 0.1*(game.sectx - x);
693 if (deltx==0 && delty== 0) {
695 prout(_("Spock- \"Bridge to sickbay. Dr. McCoy,"));
696 prout(_(" I recommend an immediate review of"));
697 prout(_(" the Captain's psychological profile.\""));
701 *course = 1.90985932*atan2(deltx, delty);
707 double targ[4][3], course[4];
709 int key, n, i, osuabor;
713 if (game.damage[DPHOTON]) {
714 prout(_("Photon tubes damaged."));
718 if (game.torps == 0) {
719 prout(_("No torpedoes left."));
725 if (key == IHALPHA) {
729 else if (key == IHEOL) {
730 prout(_("%d torpedoes left."), game.torps);
731 proutn(_("Number of torpedoes to fire- "));
734 else /* key == IHREAL */ {
736 if (n <= 0) { /* abort command */
742 prout(_("Maximum of 3 torpedoes per burst."));
746 if (n <= game.torps) break;
751 for (i = 1; i <= n; i++) {
753 if (i==1 && key == IHEOL) {
754 break; /* we will try prompting */
756 if (i==2 && key == IHEOL) {
757 /* direct all torpedoes at one target */
759 targ[i][1] = targ[1][1];
760 targ[i][2] = targ[1][2];
761 course[i] = course[1];
777 if (targetcheck(targ[i][1], targ[i][2], &course[i])) return;
780 if (i == 1 && key == IHEOL) {
781 /* prompt for each one */
782 for (i = 1; i <= n; i++) {
783 proutn(_("Target sector for torpedo number %d- "), i);
797 if (targetcheck(targ[i][1], targ[i][2], &course[i])) return;
801 /* Loop for moving <n> torpedoes */
803 for (i = 1; i <= n && !osuabor; i++) {
804 if (game.condit != IHDOCKED) game.torps--;
805 r = (Rand()+Rand())*0.5 -0.5;
806 if (fabs(r) >= 0.47) {
808 r = (Rand()+1.2) * r;
810 prouts(_("***TORPEDO NUMBER %d MISFIRES"), i);
812 else prouts(_("***TORPEDO MISFIRES."));
815 prout(_(" Remainder of burst aborted."));
818 prout(_("***Photon tubes damaged by misfire."));
819 game.damage[DPHOTON] = game.damfac*(1.0+2.0*Rand());
823 if (game.shldup || game.condit == IHDOCKED)
824 r *= 1.0 + 0.0001*game.shield;
825 torpedo(course[i], r, game.sectx, game.secty, &dummy, i, n);
826 if (game.alldone || game.state.galaxy[game.quadx][game.quady].supernova)
829 if (KLINGREM==0) finish(FWON);
834 static void overheat(double rpow)
837 double chekbrn = (rpow-1500.)*0.00038;
838 if (Rand() <= chekbrn) {
839 prout(_("Weapons officer Sulu- \"Phasers overheated, sir.\""));
840 game.damage[DPHASER] = game.damfac*(1.0 + Rand()) * (1.0+chekbrn);
845 static int checkshctrl(double rpow)
852 prout(_("Shields lowered."));
855 /* Something bad has happened */
856 prouts(_("***RED ALERT! RED ALERT!"));
858 hit = rpow*game.shield/game.inshld;
859 game.energy -= rpow+hit*0.8;
860 game.shield -= hit*0.2;
861 if (game.energy <= 0.0) {
862 prouts(_("Sulu- \"Captain! Shield malf***********************\""));
868 prouts(_("Sulu- \"Captain! Shield malfunction! Phaser fire contained!\""));
870 prout(_("Lt. Uhura- \"Sir, all decks reporting damage.\""));
871 icas = hit*Rand()*0.012;
876 prout(_("McCoy to bridge- \"Severe radiation burns, Jim."));
877 prout(_(" %d casualties so far.\""), icas);
881 prout(_("Phaser energy dispersed by shields."));
882 prout(_("Enemy unaffected."));
890 double hits[21], rpow=0, extra, powrem, over, temp;
891 int kz = 0, k=1, i, irec=0; /* Cheating inhibitor */
892 int ifast=0, no=0, ipoop=1, msgflag = 1;
893 enum {NOTSET, MANUAL, FORCEMAN, AUTOMATIC} automode = NOTSET;
897 /* SR sensors and Computer */
898 if (game.damage[DSRSENS]+game.damage[DCOMPTR] > 0) ipoop = 0;
899 if (game.condit == IHDOCKED) {
900 prout(_("Phasers can't be fired through base shields."));
904 if (game.damage[DPHASER] != 0) {
905 prout(_("Phaser control damaged."));
910 if (game.damage[DSHCTRL]) {
911 prout(_("High speed shield control damaged."));
915 if (game.energy <= 200.0) {
916 prout(_("Insufficient energy to activate high-speed shield control."));
920 prout(_("Weapons Officer Sulu- \"High-speed shield control enabled, sir.\""));
924 /* Original code so convoluted, I re-did it all */
925 while (automode==NOTSET) {
927 if (key == IHALPHA) {
928 if (isit("manual")) {
929 if (game.nenhere==0) {
930 prout(_("There is no enemy present to select."));
940 else if (isit("automatic")) {
941 if ((!ipoop) && game.nenhere != 0) {
946 prout(_("Energy will be expended into space."));
947 automode = AUTOMATIC;
951 else if (isit("no")) {
959 else if (key == IHREAL) {
960 if (game.nenhere==0) {
961 prout(_("Energy will be expended into space."));
962 automode = AUTOMATIC;
967 automode = AUTOMATIC;
971 if (game.nenhere==0) {
972 prout(_("Energy will be expended into space."));
973 automode = AUTOMATIC;
978 proutn(_("Manual or automatic? "));
984 if (key == IHALPHA && isit("no")) {
988 if (key != IHREAL && game.nenhere != 0) {
989 prout(_("Phasers locked on target. Energy available: %.2f"),
990 ifast?game.energy-200.0:game.energy,1,2);
995 if (!kz) for_local_enemies(i)
996 irec+=fabs(game.kpower[i])/(PHASEFAC*pow(0.90,game.kdist[i]))*
997 (1.01+0.05*Rand()) + 1.0;
999 proutn(_("(%d) units required. "), irec);
1001 proutn(_("Units to fire= "));
1003 if (key!=IHREAL) return;
1005 if (rpow > (ifast?game.energy-200:game.energy)) {
1006 proutn(_("Energy available= %.2f"),
1007 ifast?game.energy-200:game.energy);
1011 } while (rpow > (ifast?game.energy-200:game.energy));
1017 if ((key=scan()) == IHALPHA && isit("no")) {
1021 game.energy -= 200; /* Go and do it! */
1022 if (checkshctrl(rpow)) return;
1025 game.energy -= rpow;
1030 for_local_enemies(i) {
1032 if (powrem <= 0) continue;
1033 hits[i] = fabs(game.kpower[i])/(PHASEFAC*pow(0.90,game.kdist[i]));
1034 over = (0.01 + 0.05*Rand())*hits[i];
1036 powrem -= hits[i] + over;
1037 if (powrem <= 0 && temp < hits[i]) hits[i] = temp;
1038 if (powrem <= 0) over = 0.0;
1041 if (powrem > 0.0) extra += powrem;
1045 if (extra > 0 && game.alldone == 0) {
1047 proutn(_("*** Tholian web absorbs "));
1048 if (game.nenhere>0) proutn(_("excess "));
1049 prout(_("phaser energy."));
1052 prout(_("%d expended on empty space."), (int)extra);
1060 if (game.damage[DCOMPTR]!=0)
1061 prout(_("Battle comuter damaged, manual file only."));
1064 prouts(_("---WORKING---"));
1066 prout(_("Short-range-sensors-damaged"));
1067 prout(_("Insufficient-data-for-automatic-phaser-fire"));
1068 prout(_("Manual-fire-must-be-used"));
1073 for (k = 1; k <= game.nenhere;) {
1074 int ii = game.kx[k], jj = game.ky[k];
1075 int ienm = game.quad[ii][jj];
1077 proutn(_("Energy available= %.2f"),
1078 game.energy-.006-(ifast?200:0));
1083 if (game.damage[DSRSENS] && !(abs(game.sectx-ii) < 2 && abs(game.secty-jj) < 2) &&
1084 (ienm == IHC || ienm == IHS)) {
1086 prout(_(" can't be located without short range scan."));
1089 hits[k] = 0; /* prevent overflow -- thanks to Alexei Voitenko */
1095 if (ipoop && k > kz)
1096 irec=(fabs(game.kpower[k])/(PHASEFAC*pow(0.9,game.kdist[k])))*
1097 (1.01+0.05*Rand()) + 1.0;
1100 if (game.damage[DCOMPTR]==0) proutn("%d", irec);
1103 proutn(_("units to fire at "));
1104 crmena(0, ienm, 2, ii, jj);
1108 if (key == IHALPHA && isit("no")) {
1113 if (key == IHALPHA) {
1118 if (k==1) { /* Let me say I'm baffled by this */
1130 /* If total requested is too much, inform and start over */
1132 if (rpow > (ifast?game.energy-200:game.energy)) {
1133 prout(_("Available energy exceeded -- try again."));
1137 key = scan(); /* scan for next value */
1141 /* zero energy -- abort */
1145 if (key == IHALPHA && isit("no")) {
1148 game.energy -= rpow;
1151 game.energy -= 200.0;
1152 if (checkshctrl(rpow)) return;
1156 case NOTSET:; /* avoid gcc warning */
1158 /* Say shield raised or malfunction, if necessary */
1164 if (Rand() >= 0.99) {
1165 prout(_("Sulu- \"Sir, the high-speed shield control has malfunctioned . . ."));
1166 prouts(_(" CLICK CLICK POP . . ."));
1167 prout(_(" No response, sir!"));
1171 prout(_("Shields raised."));
1179 void hittem(double *hits)
1181 double kp, kpow, wham, hit, dustfac, kpini;
1182 int nenhr2=game.nenhere, k=1, kk=1, ii, jj, ienm;
1186 for (; k <= nenhr2; k++, kk++) {
1187 if ((wham = hits[k])==0) continue;
1188 dustfac = 0.9 + 0.01*Rand();
1189 hit = wham*pow(dustfac,game.kdist[kk]);
1190 kpini = game.kpower[kk];
1192 if (PHASEFAC*hit < kp) kp = PHASEFAC*hit;
1193 game.kpower[kk] -= (game.kpower[kk] < 0 ? -kp: kp);
1194 kpow = game.kpower[kk];
1198 if (game.damage[DSRSENS]==0)
1200 proutn(_("%d unit hit on "), (int)hit);
1203 proutn(_("Very small hit on "));
1204 ienm = game.quad[ii][jj];
1205 if (ienm==IHQUEST) iqengry=1;
1206 crmena(0,ienm,2,ii,jj);
1209 deadkl(ii, jj, ienm, ii, jj);
1210 if (KLINGREM==0) finish(FWON);
1211 if (game.alldone) return;
1212 kk--; /* don't do the increment */
1214 else /* decide whether or not to emasculate klingon */
1215 if (kpow > 0 && Rand() >= 0.9 &&
1216 kpow <= ((0.4 + 0.4*Rand())*kpini)) {
1217 prout(_("***Mr. Spock- \"Captain, the vessel at "),
1218 cramlc(sector,ii,jj));
1219 prout(_(" has just lost its firepower.\""));
1220 game.kpower[kk] = -kpow;