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.");
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 (condit != IHDOCKED) energy -= 50.0;
65 prout("Shields raised.");
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 > energy) {
92 prout("Insufficient ship energy.");
96 if (shield+aaitem >= inshld) {
97 prout("Shield energy maximized.");
98 if (shield+aaitem > inshld) {
99 prout("Excess energy requested returned to ship energy");
101 energy -= inshld-shield;
105 if (aaitem < 0.0 && energy-aaitem > 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 (shield+aaitem < 0) {
115 prout("All shield energy transferred to ship.");
120 proutn("Scotty- \"");
122 prout("Transferring energy to shields.\"");
124 prout("Draining energy from shields.\"");
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, sectx, 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)*damfac;
167 game.damage[l] += Time + 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 || 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 (landed==1 || 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]==quadx && game.state.baseqy[ll]==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--;
310 game.state.galaxy[quadx][quady].starbase--;
311 game.state.chart[quadx][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[quadx][quady].planets--;
320 DESTROY(&game.state.plnets[iplnet]);
323 game.quad[ix][iy] = IHDOT;
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;
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 ithere = ithx = 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(sectx-game.kx[ll])+square(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*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 && iscraft!=1) || j==DDRAY);
439 extradm = (hit*damfac)/(ncrit*(75.0+25.0*Rand()));
440 game.damage[j] += extradm;
442 for (ll=2; ll<=l && j != cdam[ll-1]; ll++) ;
451 if (game.damage[DSHIELD] && 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;
468 if (idebug) prout("ATTACK!");
471 if (ithere) movetho();
473 if (neutz) { /* The one chance not to be attacked */
477 if ((((comhere || ishere) && (justin == 0)) || skill == SKILL_EMERITUS)&&(torps_ok!=0)) movcom();
478 if (nenhere==0 || (nenhere==1 && iqhere && iqengry==0)) return;
480 if (shldchg == 1) chgfac = 0.25+0.5*Rand();
482 if (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 (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 (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)secty-jy, (double)jx-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[quadx][quady].supernova || alldone)
523 return; /* Supernova or finished */
524 if (hit == 0) continue;
526 if (shldup != 0 || shldchg != 0 || condit==IHDOCKED) {
527 /* shields will take hits */
528 double absorb, hitsh, propor = pfac*shield*(condit==IHDOCKED ? 2.1 : 1.0);
529 if(propor < 0.1) propor = 0.1;
530 hitsh = propor*chgfac*hit+1.0;
533 if (absorb > shield) absorb = shield;
536 if (condit==IHDOCKED) dock(0);
537 if (propor > 0.1 && hit < 0.005*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) || skill<=SKILL_FAIR) {
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;
558 prout("Hit %g energy %g", hit, energy);
560 if (condit==IHDOCKED)
564 /* Returning home upon your shield, not with it... */
568 if (attempt == 0 && condit == IHDOCKED)
569 prout("***Enemies decide against attacking your ship.");
570 if (atackd == 0) return;
571 percent = 100.0*pfac*shield+0.5;
573 /* Shields fully protect ship */
574 proutn("Enemy attack reduces shield strength to ");
577 /* Print message if starship suffered hit(s) */
579 proutn("Energy left %2d shields ", (int)energy);
580 if (shldup) proutn("up ");
581 else if (game.damage[DSHIELD] == 0) proutn("down ");
582 else proutn("damaged, ");
584 prout("%d%%, torpedoes left %d", percent, torps);
585 /* Check if anyone was hurt */
586 if (hitmax >= 200 || hittot >= 500) {
587 int icas= hittot*Rand()*0.015;
590 prout("Mc Coy- \"Sickbay to bridge. We suffered %d casualties", icas);
591 prout(" in that last attack.\"");
595 /* After attack, reset average distance to enemies */
597 game.kavgd[l] = game.kdist[l];
602 void deadkl(int ix, int iy, int type, int ixx, int iyy)
604 /* Added ixx and iyy allow enemy to "move" before dying */
609 crmena(1, type, 2, ixx, iyy);
610 /* Decide what kind of enemy it is and update approriately */
612 /* chalk up a Romulan */
613 game.state.galaxy[quadx][quady].romulans--;
615 game.state.nromrem--;
617 else if (type == IHT) {
618 /* Killed a Tholian */
621 else if (type == IHQUEST) {
622 /* Killed a Thingy */
623 iqhere=iqengry=thingx=thingy=0;
626 /* Some type of a Klingon */
627 game.state.galaxy[quadx][quady].klingons--;
633 if (game.state.cx[i]==quadx && game.state.cy[i]==quady) break;
634 game.state.cx[i] = game.state.cx[game.state.remcom];
635 game.state.cy[i] = game.state.cy[game.state.remcom];
636 game.state.cx[game.state.remcom] = 0;
637 game.state.cy[game.state.remcom] = 0;
639 game.future[FTBEAM] = FOREVER;
640 if (game.state.remcom != 0)
641 game.future[FTBEAM] = game.state.date + expran(1.0*incom/game.state.remcom);
648 ishere = game.state.isx = game.state.isy = isatb = iscate = 0;
649 game.future[FSCMOVE] = game.future[FSCDBAS] = FOREVER;
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 conditions */
662 if (game.future[FCDBAS] < FOREVER && batx==quadx && baty==quady && type==IHC)
663 game.future[FCDBAS] = FOREVER;
665 if (game.kx[i]==ix && game.ky[i]==iy) break;
668 for (j=i; j<=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[nenhere+1] = 0;
676 game.ky[nenhere+1] = 0;
677 game.kdist[nenhere+1] = 0;
678 game.kavgd[nenhere+1] = 0;
679 game.kpower[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 - secty);
692 delty = 0.1*(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.");
719 prout("No torpedoes left.");
725 if (key == IHALPHA) {
729 else if (key == IHEOL) {
730 prout("%d torpedoes left.", 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 <= 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 (condit != IHDOCKED) 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] = damfac*(1.0+2.0*Rand());
823 if (shldup || condit == IHDOCKED)
824 r *= 1.0 + 0.0001*shield;
825 torpedo(course[i], r, sectx, secty, &dummy, i, n);
826 if (alldone || game.state.galaxy[quadx][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] = 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*shield/inshld;
859 energy -= rpow+hit*0.8;
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 (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 (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")) {
930 prout("There is no enemy present to select.");
940 else if (isit("automatic")) {
941 if ((!ipoop) && nenhere != 0) {
946 prout("Energy will be expended into space.");
947 automode = AUTOMATIC;
951 else if (isit("no")) {
959 else if (key == IHREAL) {
961 prout("Energy will be expended into space.");
962 automode = AUTOMATIC;
967 automode = AUTOMATIC;
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 && nenhere != 0) {
989 prout("Phasers locked on target. Energy available: %.2f",
990 ifast?energy-200.0: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?energy-200:energy)) {
1006 proutn("Energy available= %.2f",
1007 ifast?energy-200:energy);
1011 } while (rpow > (ifast?energy-200:energy));
1017 if ((key=scan()) == IHALPHA && isit("no")) {
1021 energy -= 200; /* Go and do it! */
1022 if (checkshctrl(rpow)) return;
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 && alldone == 0) {
1047 proutn("*** Tholian web absorbs ");
1048 if (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 <= nenhere;) {
1074 int ii = game.kx[k], jj = game.ky[k];
1075 int ienm = game.quad[ii][jj];
1077 proutn("Energy available= %.2f",
1078 energy-.006-(ifast?200:0));
1083 if (game.damage[DSRSENS] && !(abs(sectx-ii) < 2 && abs(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?energy-200: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")) {
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=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 (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;