8 enum {NONE, SHUP, SHDN, NRG} action = NONE;
12 if (i == 2) action = SHUP;
20 if (game.damage[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 (game.damage[DSHIELD]) {
37 prout("Shields damaged and down.");
41 proutn("Shields are up. Do you want them down? ");
42 if (ja()) action = SHDN;
49 proutn("Shields are down. Do you want them up? ");
50 if (ja()) action = SHUP;
59 case SHUP: /* raise shields */
61 prout("Shields already up.");
66 if (condit != IHDOCKED) energy -= 50.0;
67 prout("Shields raised.");
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 > energy) {
94 prout("Insufficient ship energy.");
98 if (shield+aaitem >= inshld) {
99 prout("Shield energy maximized.");
100 if (shield+aaitem > inshld) {
101 prout("Excess energy requested returned to ship energy");
103 energy -= inshld-shield;
107 if (aaitem < 0.0 && energy-aaitem > 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 (shield+aaitem < 0) {
117 prout("All shield energy transferred to ship.");
122 proutn("Scotty- \"");
124 prout("Transferring energy to shields.\"");
126 prout("Draining energy from shields.\"");
130 case NONE:; /* avoid gcc warning */
134 void ram(int ibumpd, int ienm, int ix, int iy) {
135 double type = 1.0, extradm;
138 prouts("***RED ALERT! RED ALERT!");
140 prout("***COLLISION IMMINENT.");
145 case IHR: type = 1.5; break;
146 case IHC: type = 2.0; break;
147 case IHS: type = 2.5; break;
148 case IHT: type = 0.5; break;
149 case IHQUEST: type = 4.0; break;
151 proutn(ibumpd ? " rammed by " : " rams ");
152 crmena(0, ienm, 2, ix, iy);
153 if (ibumpd) proutn(" (original position)");
155 deadkl(ix, iy, ienm, sectx, secty);
158 prout(" heavily damaged.");
159 icas = 10.0+20.0*Rand();
160 prout("***Sickbay reports %d casualties", icas);
162 for (l=1; l <= NDEVICES; l++) {
163 if (l == DDRAY) continue; // Don't damage deathray
164 if (game.damage[l] < 0) continue;
165 extradm = (10.0*type*Rand()+1.0)*damfac;
166 game.damage[l] += Time + extradm; /* Damage for at least time of travel! */
169 if (game.state.remkl) {
177 void torpedo(double course, double r, int inx, int iny, double *hit, int wait) {
178 int l, iquad=0, ix=0, iy=0, jx=0, jy=0, shoved=0, ll;
183 double ac=course + 0.25*r;
184 double angle = (15.0-ac)*0.5235988;
185 double bullseye = (15.0 - course)*0.5235988;
186 double deltax=-sin(angle), deltay=cos(angle), x=inx, y=iny, bigger;
187 double ang, temp, xx, yy, kp, h1;
189 bigger = fabs(deltax);
190 if (fabs(deltay) > bigger) bigger = fabs(deltay);
196 if (game.damage[DSRSENS]==0 || condit==IHDOCKED) setwnd(LEFTUPPER_WINDOW);
197 else setwnd(LOWER_WINDOW);
199 /* Loop to move a single torpedo */
200 for (l=1; l <= 15; l++) {
203 if (ix < 1 || ix > 10) break;
206 if (iy < 1 || iy > 10) break;
208 if (l==4 || l==9) skip(1);
209 proutn("%d - %d ", (int)x, (int)y);
210 iquad=game.quad[ix][iy];
212 iquad=game.quad[ix][iy];
213 if (game.damage[DSRSENS]==0 || condit==IHDOCKED){
215 delay((wait!=1)*400);
218 if ((game.quad[ix][iy]==IHDOT)||(game.quad[ix][iy]==IHBLANK)){
219 game.quad[ix][iy]='+';
221 game.quad[ix][iy]=iquad;
227 game.quad[ix][iy]|=128;
229 game.quad[ix][iy]=iquad;
230 _setcursortype(_NOCURSOR);
235 _setcursortype(_NORMALCURSOR);
239 proutn("%d - %d ", (int)x, (int)y);
242 if (iquad==IHDOT) continue;
247 setwnd(LOWER_WINDOW);
251 case IHE: /* Hit our ship */
254 proutn("Torpedo hits ");
257 *hit = 700.0 + 100.0*Rand() -
258 1000.0*sqrt(square(ix-inx)+square(iy-iny))*
259 fabs(sin(bullseye-angle));
261 newcnd(); /* we're blown out of dock */
262 /* We may be displaced. */
263 if (landed==1 || condit==IHDOCKED) return; /* Cheat if on a planet */
264 ang = angle + 2.5*(Rand()-0.5);
265 temp = fabs(sin(ang));
266 if (fabs(cos(ang)) > temp) temp = fabs(cos(ang));
271 if (jx<1 || jx>10 || jy<1 ||jy > 10) return;
272 if (game.quad[jx][jy]==IHBLANK) {
276 if (game.quad[jx][jy]!=IHDOT) {
277 /* can't move into object */
286 case IHC: /* Hit a commander */
288 if (Rand() <= 0.05) {
289 crmena(1, iquad, 2, ix, iy);
290 prout(" uses anti-photon device;");
291 prout(" torpedo neutralized.");
294 case IHR: /* Hit a regular enemy */
297 for (ll=1; ll <= nenhere; ll++)
298 if (ix==game.kx[ll] && iy==game.ky[ll]) break;
299 kp = fabs(game.kpower[ll]);
300 h1 = 700.0 + 100.0*Rand() -
301 1000.0*sqrt(square(ix-inx)+square(iy-iny))*
302 fabs(sin(bullseye-angle));
304 if (kp < h1) h1 = kp;
305 game.kpower[ll] -= (game.kpower[ll]<0 ? -h1 : h1);
306 if (game.kpower[ll] == 0) {
307 deadkl(ix, iy, iquad, ix, iy);
310 crmena(1, iquad, 2, ix, iy);
311 /* If enemy damaged but not destroyed, try to displace */
312 ang = angle + 2.5*(Rand()-0.5);
313 temp = fabs(sin(ang));
314 if (fabs(cos(ang)) > temp) temp = fabs(cos(ang));
319 if (jx<1 || jx>10 || jy<1 ||jy > 10) {
320 prout(" damaged but not destroyed.");
323 if (game.quad[jx][jy]==IHBLANK) {
324 prout(" buffeted into black hole.");
325 deadkl(ix, iy, iquad, jx, jy);
328 if (game.quad[jx][jy]!=IHDOT) {
329 /* can't move into object */
330 prout(" damaged but not destroyed.");
333 proutn(" damaged--");
338 case IHB: /* Hit a base */
340 prout("***STARBASE DESTROYED..");
341 if (game.starch[quadx][quady] < 0) game.starch[quadx][quady] = 0;
342 for (ll=1; ll<=game.state.rembase; ll++) {
343 if (game.state.baseqx[ll]==quadx && game.state.baseqy[ll]==quady) {
344 game.state.baseqx[ll]=game.state.baseqx[game.state.rembase];
345 game.state.baseqy[ll]=game.state.baseqy[game.state.rembase];
349 game.quad[ix][iy]=IHDOT;
350 game.state.rembase--;
352 game.state.galaxy[quadx][quady] -= 10;
356 case IHP: /* Hit a planet */
357 crmena(1, iquad, 2, ix, iy);
358 prout(" destroyed.");
359 game.state.nplankl++;
360 game.state.newstuf[quadx][quady] -= 1;
361 DESTROY(&game.state.plnets[iplnet]);
364 game.quad[ix][iy] = IHDOT;
366 /* captain parishes on planet */
370 case IHSTAR: /* Hit a star */
375 crmena(1, IHSTAR, 2, ix, iy);
376 prout(" unaffected by photon blast.");
378 case IHQUEST: /* Hit a thingy */
379 if (Rand()>0.7) { // Used to be certain death
381 prouts("AAAAIIIIEEEEEEEEAAAAAAAAUUUUUGGGGGHHHHHHHHHHHH!!!");
383 prouts(" HACK! HACK! HACK! *CHOKE!* ");
385 proutn("Mr. Spock-");
386 prouts(" \"Fascinating!\"");
388 deadkl(ix, iy, iquad, ix, iy);
391 * Stas Sergeev added the possibility that
392 * you can shove the Thingy.
398 case IHBLANK: /* Black hole */
400 crmena(1, IHBLANK, 2, ix, iy);
401 prout(" swallows torpedo.");
403 case IHWEB: /* hit the web */
405 prout("***Torpedo absorbed by Tholian web.");
407 case IHT: /* Hit a Tholian */
408 h1 = 700.0 + 100.0*Rand() -
409 1000.0*sqrt(square(ix-inx)+square(iy-iny))*
410 fabs(sin(bullseye-angle));
414 prout(" destroyed.");
416 game.quad[ix][iy] = IHDOT;
420 deadkl(ix, iy, iquad, ix, iy);
425 crmena(1, IHT, 2, ix, iy);
427 prout(" survives photon blast.");
430 prout(" disappears.");
431 game.quad[ix][iy] = IHWEB;
432 ithere = ithx = ithy = 0;
436 dropin(IHBLANK, &dum, &my);
440 default: /* Problem! */
442 proutn("Don't know how to handle collision with ");
443 crmena(1, iquad, 2, ix, iy);
450 if(curwnd!=LOWER_WINDOW) {
451 setwnd(LOWER_WINDOW);
456 game.quad[jx][jy]=iquad;
457 game.quad[ix][iy]=IHDOT;
458 prout(" displaced by blast to %s ", cramlc(sector, jx, jy));
459 for (ll=1; ll<=nenhere; ll++)
460 game.kdist[ll] = game.kavgd[ll] = sqrt(square(sectx-game.kx[ll])+square(secty-game.ky[ll]));
467 prout("Torpedo missed.");
471 static void fry(double hit) {
472 double ncrit, extradm;
473 int ktr=1, l, ll, j, cdam[NDEVICES+1];
475 /* a critical hit occured */
476 if (hit < (275.0-25.0*skill)*(1.0+0.5*Rand())) return;
478 ncrit = 1.0 + hit/(500.0+100.0*Rand());
479 proutn("***CRITICAL HIT--");
480 /* Select devices and cause damage */
481 for (l = 1; l <= ncrit && l <= NDEVICES; l++) {
483 j = NDEVICES*Rand()+1.0;
484 /* Cheat to prevent shuttle damage unless on ship */
485 } while (game.damage[j] < 0.0 || (j == DSHUTTL && iscraft != 1) ||
488 extradm = (hit*damfac)/(ncrit*(75.0+25.0*Rand()));
489 game.damage[j] += extradm;
491 for (ll=2; ll<=l && j != cdam[ll-1]; ll++) ;
500 if (game.damage[DSHIELD] && shldup) {
501 prout("***Shields knocked down.");
507 /* k == 0 forces use of phasers in an attack */
508 int percent, ihurt=0, l, i=0, jx, jy, iquad, itflag;
509 int atackd = 0, attempt = 0;
511 double pfac, dustfac, hitmax=0.0, hittot=0.0, chgfac=1.0, r;
516 if (idebug) prout("ATTACK!");
519 if (ithere) movetho();
521 if (neutz) { /* The one chance not to be attacked */
525 if ((((comhere || ishere) && (justin == 0)) || skill == 5)&&(k!=0)) movcom();
526 if (nenhere==0 || (nenhere==1 && iqhere && iqengry==0)) return;
528 if (shldchg == 1) chgfac = 0.25+0.5*Rand();
530 if (skill <= 2) i = 2;
531 for (l=1; l <= nenhere; l++) {
532 if (game.kpower[l] < 0) continue; /* too weak to attack */
533 /* compute hit strength and diminsh shield power */
535 /* Increase chance of photon torpedos if docked or enemy energy low */
536 if (condit == IHDOCKED) r *= 0.25;
537 if (game.kpower[l] < 500) r *= 0.25;
540 iquad = game.quad[jx][jy];
541 if (iquad==IHT || (iquad==IHQUEST && !iqengry)) continue;
542 itflag = (iquad == IHK && r > 0.0005) || k == 0 ||
543 (iquad==IHC && r > 0.015) ||
544 (iquad==IHR && r > 0.3) ||
545 (iquad==IHS && r > 0.07) ||
546 (iquad==IHQUEST && r > 0.05);
548 /* Enemy uses phasers */
549 if (condit == IHDOCKED) continue; /* Don't waste the effort! */
550 attempt = 1; /* Attempt to attack */
551 dustfac = 0.8+0.05*Rand();
552 hit = game.kpower[l]*pow(dustfac,game.kavgd[l]);
553 game.kpower[l] *= 0.75;
555 else { /* Enemy used photon torpedo */
556 double course = 1.90985*atan2((double)secty-jy, (double)jx-sectx);
558 proutn("***TORPEDO INCOMING");
559 if (game.damage[DSRSENS] <= 0.0) {
561 crmena(0, iquad, i, jx, jy);
565 r = (Rand()+Rand())*0.5 -0.5;
566 r += 0.002*game.kpower[l]*r;
567 torpedo(course, r, jx, jy, &hit, 0);
568 if (game.state.remkl==0) finish(FWON); /* Klingons did themselves in! */
569 if (game.state.galaxy[quadx][quady] == 1000 ||
570 alldone) return; /* Supernova or finished */
571 if (hit == 0) continue;
573 if (shldup != 0 || shldchg != 0 || condit==IHDOCKED) {
574 /* shields will take hits */
575 double absorb, hitsh, propor = pfac*shield*(condit==IHDOCKED ? 2.1 : 1.0);
576 if(propor < 0.1) propor = 0.1;
577 hitsh = propor*chgfac*hit+1.0;
580 if (absorb > shield) absorb = shield;
583 if (condit==IHDOCKED) dock(0);
584 if (propor > 0.1 && hit < 0.005*energy) continue;
586 /* It's a hit -- print out hit size */
587 atackd = 1; /* We weren't going to check casualties, etc. if
588 shields were down for some strange reason. This
589 doesn't make any sense, so I've fixed it */
591 proutn("%d unit hit", (int)hit);
592 if ((game.damage[DSRSENS] > 0 && itflag) || skill <= 2) {
596 if (game.damage[DSRSENS] <= 0.0 && itflag) {
598 crmena(0, iquad, i, jx, jy);
601 /* Decide if hit is critical */
602 if (hit > hitmax) hitmax = hit;
605 prout("Hit %g energy %g", hit, energy);
607 if (condit==IHDOCKED) dock(0);
610 /* Returning home upon your shield, not with it... */
614 if (attempt == 0 && condit == IHDOCKED)
615 prout("***Enemies decide against attacking your ship.");
616 if (atackd == 0) return;
617 percent = 100.0*pfac*shield+0.5;
619 /* Shields fully protect ship */
620 proutn("Enemy attack reduces shield strength to ");
623 /* Print message if starship suffered hit(s) */
625 proutn("Energy left %2d shields ", (int)energy);
626 if (shldup) proutn("up ");
627 else if (game.damage[DSHIELD] == 0) proutn("down ");
628 else proutn("damaged, ");
630 prout("%d%%, torpedoes left %d", percent, torps);
631 /* Check if anyone was hurt */
632 if (hitmax >= 200 || hittot >= 500) {
633 int icas= hittot*Rand()*0.015;
636 prout("Mc Coy- \"Sickbay to bridge. We suffered %d casualties", icas);
637 prout(" in that last attack.\"");
641 /* After attack, reset average distance to enemies */
642 for (l = 1; l <= nenhere; l++)
643 game.kavgd[l] = game.kdist[l];
648 void deadkl(int ix, int iy, int type, int ixx, int iyy) {
649 /* Added ixx and iyy allow enemy to "move" before dying */
654 crmena(1, type, 2, ixx, iyy);
655 /* Decide what kind of enemy it is and update approriately */
657 /* chalk up a Romulan */
658 game.state.newstuf[quadx][quady] -= 10;
661 game.state.nromrem--;
663 else if (type == IHT) {
664 /* Killed a Tholian */
667 else if (type == IHQUEST) {
668 /* Killed a Thingy */
669 iqhere=iqengry=thingx=thingy=0;
672 /* Some type of a Klingon */
673 game.state.galaxy[quadx][quady] -= 100;
679 for (i=1; i<=game.state.remcom; i++)
680 if (game.state.cx[i]==quadx && game.state.cy[i]==quady) break;
681 game.state.cx[i] = game.state.cx[game.state.remcom];
682 game.state.cy[i] = game.state.cy[game.state.remcom];
683 game.state.cx[game.state.remcom] = 0;
684 game.state.cy[game.state.remcom] = 0;
686 game.future[FTBEAM] = 1e30;
687 if (game.state.remcom != 0)
688 game.future[FTBEAM] = game.state.date + expran(1.0*incom/game.state.remcom);
695 game.state.nscrem = ishere = game.state.isx = game.state.isy = isatb = iscate = 0;
696 game.state.nsckill = 1;
697 game.future[FSCMOVE] = game.future[FSCDBAS] = 1e30;
702 /* For each kind of enemy, finish message to player */
703 prout(" destroyed.");
704 game.quad[ix][iy] = IHDOT;
705 if (game.state.remkl==0) return;
707 game.state.remtime = game.state.remres/(game.state.remkl + 4*game.state.remcom);
709 /* Remove enemy ship from arrays describing local conditions */
710 if (game.future[FCDBAS] < 1e30 && batx==quadx && baty==quady && type==IHC)
711 game.future[FCDBAS] = 1e30;
712 for (i=1; i<=nenhere; i++)
713 if (game.kx[i]==ix && game.ky[i]==iy) break;
716 for (j=i; j<=nenhere; j++) {
717 game.kx[j] = game.kx[j+1];
718 game.ky[j] = game.ky[j+1];
719 game.kpower[j] = game.kpower[j+1];
720 game.kavgd[j] = game.kdist[j] = game.kdist[j+1];
723 game.kx[nenhere+1] = 0;
724 game.ky[nenhere+1] = 0;
725 game.kdist[nenhere+1] = 0;
726 game.kavgd[nenhere+1] = 0;
727 game.kpower[nenhere+1] = 0;
731 static int targetcheck(double x, double y, double *course) {
733 /* Return TRUE if target is invalid */
734 if (x < 1.0 || x > 10.0 || y < 1.0 || y > 10.0) {
738 deltx = 0.1*(y - secty);
739 delty = 0.1*(sectx - x);
740 if (deltx==0 && delty== 0) {
742 prout("Spock- \"Bridge to sickbay. Dr. McCoy,");
743 prout(" I recommend an immediate review of");
744 prout(" the Captain's psychological profile.\"");
748 *course = 1.90985932*atan2(deltx, delty);
753 double targ[4][3], course[4];
755 int key, n, i, osuabor;
759 if (game.damage[DPHOTON]) {
760 prout("Photon tubes damaged.");
765 prout("No torpedoes left.");
771 if (key == IHALPHA) {
775 else if (key == IHEOL) {
776 prout("%d torpedoes left.", torps);
777 proutn("Number of torpedoes to fire- ");
780 else /* key == IHREAL */ {
782 if (n <= 0) { /* abort command */
788 prout("Maximum of 3 torpedoes per burst.");
792 if (n <= torps) break;
797 for (i = 1; i <= n; i++) {
799 if (i==1 && key == IHEOL) {
800 break; /* we will try prompting */
802 if (i==2 && key == IHEOL) {
803 /* direct all torpedoes at one target */
805 targ[i][1] = targ[1][1];
806 targ[i][2] = targ[1][2];
807 course[i] = course[1];
823 if (targetcheck(targ[i][1], targ[i][2], &course[i])) return;
826 if (i == 1 && key == IHEOL) {
827 /* prompt for each one */
828 for (i = 1; i <= n; i++) {
829 proutn("Target sector for torpedo number %d- ", i);
843 if (targetcheck(targ[i][1], targ[i][2], &course[i])) return;
847 /* Loop for moving <n> torpedoes */
849 for (i = 1; i <= n && !osuabor; i++) {
850 if (condit != IHDOCKED) torps--;
851 r = (Rand()+Rand())*0.5 -0.5;
852 if (fabs(r) >= 0.47) {
854 r = (Rand()+1.2) * r;
856 prouts("***TORPEDO NUMBER %d MISFIRES", i);
858 else prouts("***TORPEDO MISFIRES.");
861 prout(" Remainder of burst aborted.");
864 prout("***Photon tubes damaged by misfire.");
865 game.damage[DPHOTON] = damfac*(1.0+2.0*Rand());
869 if (shldup || condit == IHDOCKED) r *= 1.0 + 0.0001*shield;
873 proutn("Track for torpedo number %d- ", i);
877 proutn("Torpedo track- ");
880 torpedo(course[i], r, sectx, secty, &dummy, i);
881 if (alldone || game.state.galaxy[quadx][quady]==1000) return;
883 if (game.state.remkl==0) finish(FWON);
888 static void overheat(double rpow) {
890 double chekbrn = (rpow-1500.)*0.00038;
891 if (Rand() <= chekbrn) {
892 prout("Weapons officer Sulu- \"Phasers overheated, sir.\"");
893 game.damage[DPHASER] = damfac*(1.0 + Rand()) * (1.0+chekbrn);
898 static int checkshctrl(double rpow) {
904 prout("Shields lowered.");
907 /* Something bad has happened */
908 prouts("***RED ALERT! RED ALERT!");
910 hit = rpow*shield/inshld;
911 energy -= rpow+hit*0.8;
914 prouts("Sulu- \"Captain! Shield malf***********************\"");
920 prouts("Sulu- \"Captain! Shield malfunction! Phaser fire contained!\"");
922 prout("Lt. Uhura- \"Sir, all decks reporting damage.\"");
923 icas = hit*Rand()*0.012;
928 prout("McCoy to bridge- \"Severe radiation burns, Jim.");
929 prout(" %d casualties so far.\"", icas);
933 prout("Phaser energy dispersed by shields.");
934 prout("Enemy unaffected.");
941 double hits[21], rpow=0, extra, powrem, over, temp;
942 int kz = 0, k=1, i, irec=0; /* Cheating inhibitor */
943 int ifast=0, no=0, ipoop=1, msgflag = 1;
944 enum {NOTSET, MANUAL, FORCEMAN, AUTOMATIC} automode = NOTSET;
948 /* SR sensors and Computer */
949 if (game.damage[DSRSENS]+game.damage[DCOMPTR] > 0) ipoop = 0;
950 if (condit == IHDOCKED) {
951 prout("Phasers can't be fired through base shields.");
955 if (game.damage[DPHASER] != 0) {
956 prout("Phaser control damaged.");
961 if (game.damage[DSHCTRL]) {
962 prout("High speed shield control damaged.");
966 if (energy <= 200.0) {
967 prout("Insufficient energy to activate high-speed shield control.");
971 prout("Weapons Officer Sulu- \"High-speed shield control enabled, sir.\"");
975 /* Original code so convoluted, I re-did it all */
976 while (automode==NOTSET) {
978 if (key == IHALPHA) {
979 if (isit("manual")) {
981 prout("There is no enemy present to select.");
991 else if (isit("automatic")) {
992 if ((!ipoop) && nenhere != 0) {
997 prout("Energy will be expended into space.");
998 automode = AUTOMATIC;
1002 else if (isit("no")) {
1010 else if (key == IHREAL) {
1012 prout("Energy will be expended into space.");
1013 automode = AUTOMATIC;
1016 automode = FORCEMAN;
1018 automode = AUTOMATIC;
1023 prout("Energy will be expended into space.");
1024 automode = AUTOMATIC;
1027 automode = FORCEMAN;
1029 proutn("Manual or automatic? ");
1035 if (key == IHALPHA && isit("no")) {
1039 if (key != IHREAL && nenhere != 0) {
1040 prout("Phasers locked on target. Energy available: %.2f",
1041 ifast?energy-200.0:energy,1,2);
1046 if (!kz) for (i = 1; i <= nenhere; i++)
1047 irec+=fabs(game.kpower[i])/(PHASEFAC*pow(0.90,game.kdist[i]))*
1048 (1.01+0.05*Rand()) + 1.0;
1050 proutn("(%d) units required. ", irec);
1052 proutn("Units to fire= ");
1054 if (key!=IHREAL) return;
1056 if (rpow > (ifast?energy-200:energy)) {
1057 proutn("Energy available= %.2f",
1058 ifast?energy-200:energy);
1062 } while (rpow > (ifast?energy-200:energy));
1068 if ((key=scan()) == IHALPHA && isit("no")) {
1072 energy -= 200; /* Go and do it! */
1073 if (checkshctrl(rpow)) return;
1081 for (i = 1; i <= nenhere; i++) {
1083 if (powrem <= 0) continue;
1084 hits[i] = fabs(game.kpower[i])/(PHASEFAC*pow(0.90,game.kdist[i]));
1085 over = (0.01 + 0.05*Rand())*hits[i];
1087 powrem -= hits[i] + over;
1088 if (powrem <= 0 && temp < hits[i]) hits[i] = temp;
1089 if (powrem <= 0) over = 0.0;
1092 if (powrem > 0.0) extra += powrem;
1096 if (extra > 0 && alldone == 0) {
1098 proutn("*** Tholian web absorbs ");
1099 if (nenhere>0) proutn("excess ");
1100 prout("phaser energy.");
1103 prout("%d expended on empty space.", (int)extra);
1111 if (game.damage[DCOMPTR]!=0)
1112 prout("Battle comuter damaged, manual file only.");
1115 prouts("---WORKING---");
1117 prout("Short-range-sensors-damaged");
1118 prout("Insufficient-data-for-automatic-phaser-fire");
1119 prout("Manual-fire-must-be-used");
1124 for (k = 1; k <= nenhere;) {
1125 int ii = game.kx[k], jj = game.ky[k];
1126 int ienm = game.quad[ii][jj];
1128 proutn("Energy available= %.2f",
1129 energy-.006-(ifast?200:0));
1134 if (game.damage[DSRSENS] && !(abs(sectx-ii) < 2 && abs(secty-jj) < 2) &&
1135 (ienm == IHC || ienm == IHS)) {
1137 prout(" can't be located without short range scan.");
1140 hits[k] = 0; /* prevent overflow -- thanks to Alexei Voitenko */
1146 if (ipoop && k > kz)
1147 irec=(fabs(game.kpower[k])/(PHASEFAC*pow(0.9,game.kdist[k])))*
1148 (1.01+0.05*Rand()) + 1.0;
1151 if (game.damage[DCOMPTR]==0) proutn("%d", irec);
1154 proutn("units to fire at ");
1155 crmena(0, ienm, 2, ii, jj);
1159 if (key == IHALPHA && isit("no")) {
1164 if (key == IHALPHA) {
1169 if (k==1) { /* Let me say I'm baffled by this */
1181 /* If total requested is too much, inform and start over */
1183 if (rpow > (ifast?energy-200:energy)) {
1184 prout("Available energy exceeded -- try again.");
1188 key = scan(); /* scan for next value */
1192 /* zero energy -- abort */
1196 if (key == IHALPHA && isit("no")) {
1203 if (checkshctrl(rpow)) return;
1207 case NOTSET:; /* avoid gcc warning */
1209 /* Say shield raised or malfunction, if necessary */
1210 if (alldone) return;
1214 if (Rand() >= 0.99) {
1215 prout("Sulu- \"Sir, the high-speed shield control has malfunctioned . . .");
1216 prouts(" CLICK CLICK POP . . .");
1217 prout(" No response, sir!");
1221 prout("Shields raised.");
1229 void hittem(double *hits) {
1230 double kp, kpow, wham, hit, dustfac, kpini;
1233 #endif /* SERGEEV */
1234 int nenhr2=nenhere, k=1, kk=1, ii, jj, ienm;
1238 for (; k <= nenhr2; k++, kk++) {
1239 if ((wham = hits[k])==0) continue;
1240 dustfac = 0.9 + 0.01*Rand();
1241 hit = wham*pow(dustfac,game.kdist[kk]);
1242 kpini = game.kpower[kk];
1244 if (PHASEFAC*hit < kp) kp = PHASEFAC*hit;
1245 game.kpower[kk] -= (game.kpower[kk] < 0 ? -kp: kp);
1246 kpow = game.kpower[kk];
1251 if (game.damage[DSRSENS]==0){
1254 setwnd(LEFTUPPER_WINDOW);
1256 gotoxy(jj*2+3,ii+2);
1258 proutn("%c", game.quad[ii][jj]);
1259 gotoxy(wherex()-1,wherey());
1264 proutn("%c", game.quad[ii][jj]);
1265 setwnd(LOWER_WINDOW);
1267 _setcursortype(_NORMALCURSOR);
1270 #endif /* SERGEEV */
1271 proutn("%d unit hit on ", (int)hit);
1274 proutn("Very small hit on ");
1275 ienm = game.quad[ii][jj];
1276 if (ienm==IHQUEST) iqengry=1;
1277 crmena(0,ienm,2,ii,jj);
1280 deadkl(ii, jj, ienm, ii, jj);
1281 if (game.state.remkl==0) finish(FWON);
1282 if (alldone) return;
1283 kk--; /* don't do the increment */
1285 else /* decide whether or not to emasculate klingon */
1286 if (kpow > 0 && Rand() >= 0.9 &&
1287 kpow <= ((0.4 + 0.4*Rand())*kpini)) {
1288 prout("***Mr. Spock- \"Captain, the vessel at ",
1289 cramlc(sector,ii,jj));
1290 prout(" has just lost its firepower.\"");
1291 game.kpower[kk] = -kpow;