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;
181 double ac=course + 0.25*r;
182 double angle = (15.0-ac)*0.5235988;
183 double bullseye = (15.0 - course)*0.5235988;
184 double deltax=-sin(angle), deltay=cos(angle), x=inx, y=iny, bigger;
185 double ang, temp, xx, yy, kp, h1;
187 bigger = fabs(deltax);
188 if (fabs(deltay) > bigger) bigger = fabs(deltay);
193 if (game.damage[DSRSENS]==0 || condit==IHDOCKED) setwnd(LEFTUPPER_WINDOW);
194 else setwnd(LOWER_WINDOW);
195 /* Loop to move a single torpedo */
196 for (l=1; l <= 15; l++) {
199 if (ix < 1 || ix > 10) break;
202 if (iy < 1 || iy > 10) break;
203 iquad=game.quad[ix][iy];
205 if (l==4 || l==9) skip(1);
206 proutn("%d - %d ", (int)x, (int)y);
208 if (game.damage[DSRSENS]==0 || condit==IHDOCKED){
210 delay((wait!=1)*400);
213 if ((game.quad[ix][iy]==IHDOT)||(game.quad[ix][iy]==IHBLANK)){
214 game.quad[ix][iy]='+';
216 game.quad[ix][iy]=iquad;
222 game.quad[ix][iy]|=128;
224 game.quad[ix][iy]=iquad;
225 _setcursortype(_NOCURSOR);
230 _setcursortype(_NORMALCURSOR);
234 proutn("%d - %d ", (int)x, (int)y);
237 if (iquad==IHDOT) continue;
239 setwnd(LOWER_WINDOW);
242 case IHE: /* Hit our ship */
245 proutn("Torpedo hits ");
248 *hit = 700.0 + 100.0*Rand() -
249 1000.0*sqrt(square(ix-inx)+square(iy-iny))*
250 fabs(sin(bullseye-angle));
252 newcnd(); /* we're blown out of dock */
253 /* We may be displaced. */
254 if (landed==1 || condit==IHDOCKED) return; /* Cheat if on a planet */
255 ang = angle + 2.5*(Rand()-0.5);
256 temp = fabs(sin(ang));
257 if (fabs(cos(ang)) > temp) temp = fabs(cos(ang));
262 if (jx<1 || jx>10 || jy<1 ||jy > 10) return;
263 if (game.quad[jx][jy]==IHBLANK) {
267 if (game.quad[jx][jy]!=IHDOT) {
268 /* can't move into object */
277 case IHC: /* Hit a commander */
279 if (Rand() <= 0.05) {
280 crmena(1, iquad, 2, ix, iy);
281 prout(" uses anti-photon device;");
282 prout(" torpedo neutralized.");
285 case IHR: /* Hit a regular enemy */
288 for (ll=1; ll <= nenhere; ll++)
289 if (ix==game.kx[ll] && iy==game.ky[ll]) break;
290 kp = fabs(game.kpower[ll]);
291 h1 = 700.0 + 100.0*Rand() -
292 1000.0*sqrt(square(ix-inx)+square(iy-iny))*
293 fabs(sin(bullseye-angle));
295 if (kp < h1) h1 = kp;
296 game.kpower[ll] -= (game.kpower[ll]<0 ? -h1 : h1);
297 if (game.kpower[ll] == 0) {
298 deadkl(ix, iy, iquad, ix, iy);
301 crmena(1, iquad, 2, ix, iy);
302 /* If enemy damaged but not destroyed, try to displace */
303 ang = angle + 2.5*(Rand()-0.5);
304 temp = fabs(sin(ang));
305 if (fabs(cos(ang)) > temp) temp = fabs(cos(ang));
310 if (jx<1 || jx>10 || jy<1 ||jy > 10) {
311 prout(" damaged but not destroyed.");
314 if (game.quad[jx][jy]==IHBLANK) {
315 prout(" buffeted into black hole.");
316 deadkl(ix, iy, iquad, jx, jy);
319 if (game.quad[jx][jy]!=IHDOT) {
320 /* can't move into object */
321 prout(" damaged but not destroyed.");
324 proutn(" damaged--");
329 case IHB: /* Hit a base */
331 prout("***STARBASE DESTROYED..");
332 if (game.starch[quadx][quady] < 0) game.starch[quadx][quady] = 0;
333 for (ll=1; ll<=game.state.rembase; ll++) {
334 if (game.state.baseqx[ll]==quadx && game.state.baseqy[ll]==quady) {
335 game.state.baseqx[ll]=game.state.baseqx[game.state.rembase];
336 game.state.baseqy[ll]=game.state.baseqy[game.state.rembase];
340 game.quad[ix][iy]=IHDOT;
341 game.state.rembase--;
343 game.state.galaxy[quadx][quady] -= 10;
347 case IHP: /* Hit a planet */
348 crmena(1, iquad, 2, ix, iy);
349 prout(" destroyed.");
350 game.state.nplankl++;
351 game.state.newstuf[quadx][quady] -= 1;
352 DESTROY(&game.state.plnets[iplnet]);
355 game.quad[ix][iy] = IHDOT;
357 /* captain parishes on planet */
361 case IHSTAR: /* Hit a star */
366 crmena(1, IHSTAR, 2, ix, iy);
367 prout(" unaffected by photon blast.");
369 case IHQUEST: /* Hit a thingy */
370 if (Rand()>0.7) { // Used to be certain death
372 prouts("AAAAIIIIEEEEEEEEAAAAAAAAUUUUUGGGGGHHHHHHHHHHHH!!!");
374 prouts(" HACK! HACK! HACK! *CHOKE!* ");
376 proutn("Mr. Spock-");
377 prouts(" \"Fascinating!\"");
379 deadkl(ix, iy, iquad, ix, iy);
382 * Stas Sergeev added the possibility that
383 * you can shove the Thingy.
389 case IHBLANK: /* Black hole */
391 crmena(1, IHBLANK, 2, ix, iy);
392 prout(" swallows torpedo.");
394 case IHWEB: /* hit the web */
396 prout("***Torpedo absorbed by Tholian web.");
398 case IHT: /* Hit a Tholian */
399 h1 = 700.0 + 100.0*Rand() -
400 1000.0*sqrt(square(ix-inx)+square(iy-iny))*
401 fabs(sin(bullseye-angle));
405 prout(" destroyed.");
407 game.quad[ix][iy] = IHDOT;
411 deadkl(ix, iy, iquad, ix, iy);
416 crmena(1, IHT, 2, ix, iy);
418 prout(" survives photon blast.");
421 prout(" disappears.");
422 game.quad[ix][iy] = IHWEB;
423 ithere = ithx = ithy = 0;
427 dropin(IHBLANK, &dum, &my);
431 default: /* Problem! */
433 proutn("Don't know how to handle collision with ");
434 crmena(1, iquad, 2, ix, iy);
440 if(curwnd!=LOWER_WINDOW) {
441 setwnd(LOWER_WINDOW);
445 game.quad[jx][jy]=iquad;
446 game.quad[ix][iy]=IHDOT;
447 prout(" displaced by blast to %s ", cramlc(sector, jx, jy));
448 for (ll=1; ll<=nenhere; ll++)
449 game.kdist[ll] = game.kavgd[ll] = sqrt(square(sectx-game.kx[ll])+square(secty-game.ky[ll]));
454 prout("Torpedo missed.");
458 static void fry(double hit) {
459 double ncrit, extradm;
460 int ktr=1, l, ll, j, cdam[NDEVICES+1];
462 /* a critical hit occured */
463 if (hit < (275.0-25.0*skill)*(1.0+0.5*Rand())) return;
465 ncrit = 1.0 + hit/(500.0+100.0*Rand());
466 proutn("***CRITICAL HIT--");
467 /* Select devices and cause damage */
468 for (l = 1; l <= ncrit && l <= NDEVICES; l++) {
470 j = NDEVICES*Rand()+1.0;
471 /* Cheat to prevent shuttle damage unless on ship */
472 } while (game.damage[j] < 0.0 || (j == DSHUTTL && iscraft != 1) ||
475 extradm = (hit*damfac)/(ncrit*(75.0+25.0*Rand()));
476 game.damage[j] += extradm;
478 for (ll=2; ll<=l && j != cdam[ll-1]; ll++) ;
487 if (game.damage[DSHIELD] && shldup) {
488 prout("***Shields knocked down.");
494 /* k == 0 forces use of phasers in an attack */
495 int percent, ihurt=0, l, i=0, jx, jy, iquad, itflag;
496 int atackd = 0, attempt = 0;
498 double pfac, dustfac, hitmax=0.0, hittot=0.0, chgfac=1.0, r;
503 if (idebug) prout("ATTACK!");
506 if (ithere) movetho();
508 if (neutz) { /* The one chance not to be attacked */
512 if ((((comhere || ishere) && (justin == 0)) || skill == 5)&&(k!=0)) movcom();
513 if (nenhere==0 || (nenhere==1 && iqhere && iqengry==0)) return;
515 if (shldchg == 1) chgfac = 0.25+0.5*Rand();
517 if (skill <= 2) i = 2;
518 for (l=1; l <= nenhere; l++) {
519 if (game.kpower[l] < 0) continue; /* too weak to attack */
520 /* compute hit strength and diminsh shield power */
522 /* Increase chance of photon torpedos if docked or enemy energy low */
523 if (condit == IHDOCKED) r *= 0.25;
524 if (game.kpower[l] < 500) r *= 0.25;
527 iquad = game.quad[jx][jy];
528 if (iquad==IHT || (iquad==IHQUEST && !iqengry)) continue;
529 itflag = (iquad == IHK && r > 0.0005) || k == 0 ||
530 (iquad==IHC && r > 0.015) ||
531 (iquad==IHR && r > 0.3) ||
532 (iquad==IHS && r > 0.07) ||
533 (iquad==IHQUEST && r > 0.05);
535 /* Enemy uses phasers */
536 if (condit == IHDOCKED) continue; /* Don't waste the effort! */
537 attempt = 1; /* Attempt to attack */
538 dustfac = 0.8+0.05*Rand();
539 hit = game.kpower[l]*pow(dustfac,game.kavgd[l]);
540 game.kpower[l] *= 0.75;
542 else { /* Enemy used photon torpedo */
543 double course = 1.90985*atan2((double)secty-jy, (double)jx-sectx);
545 proutn("***TORPEDO INCOMING");
546 if (game.damage[DSRSENS] <= 0.0) {
548 crmena(0, iquad, i, jx, jy);
552 r = (Rand()+Rand())*0.5 -0.5;
553 r += 0.002*game.kpower[l]*r;
554 torpedo(course, r, jx, jy, &hit, 0);
555 if (game.state.remkl==0) finish(FWON); /* Klingons did themselves in! */
556 if (game.state.galaxy[quadx][quady] == 1000 ||
557 alldone) return; /* Supernova or finished */
558 if (hit == 0) continue;
560 if (shldup != 0 || shldchg != 0 || condit==IHDOCKED) {
561 /* shields will take hits */
562 double absorb, hitsh, propor = pfac*shield*(condit==IHDOCKED ? 2.1 : 1.0);
563 if(propor < 0.1) propor = 0.1;
564 hitsh = propor*chgfac*hit+1.0;
567 if (absorb > shield) absorb = shield;
570 if (condit==IHDOCKED) dock(0);
571 if (propor > 0.1 && hit < 0.005*energy) continue;
573 /* It's a hit -- print out hit size */
574 atackd = 1; /* We weren't going to check casualties, etc. if
575 shields were down for some strange reason. This
576 doesn't make any sense, so I've fixed it */
578 proutn("%d unit hit", (int)hit);
579 if ((game.damage[DSRSENS] > 0 && itflag) || skill <= 2) {
583 if (game.damage[DSRSENS] <= 0.0 && itflag) {
585 crmena(0, iquad, i, jx, jy);
588 /* Decide if hit is critical */
589 if (hit > hitmax) hitmax = hit;
592 prout("Hit %g energy %g", hit, energy);
594 if (condit==IHDOCKED) dock(0);
597 /* Returning home upon your shield, not with it... */
601 if (attempt == 0 && condit == IHDOCKED)
602 prout("***Enemies decide against attacking your ship.");
603 if (atackd == 0) return;
604 percent = 100.0*pfac*shield+0.5;
606 /* Shields fully protect ship */
607 proutn("Enemy attack reduces shield strength to ");
610 /* Print message if starship suffered hit(s) */
612 proutn("Energy left %2d shields ", (int)energy);
613 if (shldup) proutn("up ");
614 else if (game.damage[DSHIELD] == 0) proutn("down ");
615 else proutn("damaged, ");
617 prout("%d%%, torpedoes left %d", percent, torps);
618 /* Check if anyone was hurt */
619 if (hitmax >= 200 || hittot >= 500) {
620 int icas= hittot*Rand()*0.015;
623 prout("Mc Coy- \"Sickbay to bridge. We suffered %d casualties", icas);
624 prout(" in that last attack.\"");
628 /* After attack, reset average distance to enemies */
629 for (l = 1; l <= nenhere; l++)
630 game.kavgd[l] = game.kdist[l];
635 void deadkl(int ix, int iy, int type, int ixx, int iyy) {
636 /* Added ixx and iyy allow enemy to "move" before dying */
641 crmena(1, type, 2, ixx, iyy);
642 /* Decide what kind of enemy it is and update approriately */
644 /* chalk up a Romulan */
645 game.state.newstuf[quadx][quady] -= 10;
648 game.state.nromrem--;
650 else if (type == IHT) {
651 /* Killed a Tholian */
654 else if (type == IHQUEST) {
655 /* Killed a Thingy */
656 iqhere=iqengry=thingx=thingy=0;
659 /* Some type of a Klingon */
660 game.state.galaxy[quadx][quady] -= 100;
666 for (i=1; i<=game.state.remcom; i++)
667 if (game.state.cx[i]==quadx && game.state.cy[i]==quady) break;
668 game.state.cx[i] = game.state.cx[game.state.remcom];
669 game.state.cy[i] = game.state.cy[game.state.remcom];
670 game.state.cx[game.state.remcom] = 0;
671 game.state.cy[game.state.remcom] = 0;
673 game.future[FTBEAM] = 1e30;
674 if (game.state.remcom != 0)
675 game.future[FTBEAM] = game.state.date + expran(1.0*incom/game.state.remcom);
682 game.state.nscrem = ishere = game.state.isx = game.state.isy = isatb = iscate = 0;
683 game.state.nsckill = 1;
684 game.future[FSCMOVE] = game.future[FSCDBAS] = 1e30;
689 /* For each kind of enemy, finish message to player */
690 prout(" destroyed.");
691 game.quad[ix][iy] = IHDOT;
692 if (game.state.remkl==0) return;
694 game.state.remtime = game.state.remres/(game.state.remkl + 4*game.state.remcom);
696 /* Remove enemy ship from arrays describing local conditions */
697 if (game.future[FCDBAS] < 1e30 && batx==quadx && baty==quady && type==IHC)
698 game.future[FCDBAS] = 1e30;
699 for (i=1; i<=nenhere; i++)
700 if (game.kx[i]==ix && game.ky[i]==iy) break;
703 for (j=i; j<=nenhere; j++) {
704 game.kx[j] = game.kx[j+1];
705 game.ky[j] = game.ky[j+1];
706 game.kpower[j] = game.kpower[j+1];
707 game.kavgd[j] = game.kdist[j] = game.kdist[j+1];
710 game.kx[nenhere+1] = 0;
711 game.ky[nenhere+1] = 0;
712 game.kdist[nenhere+1] = 0;
713 game.kavgd[nenhere+1] = 0;
714 game.kpower[nenhere+1] = 0;
718 static int targetcheck(double x, double y, double *course) {
720 /* Return TRUE if target is invalid */
721 if (x < 1.0 || x > 10.0 || y < 1.0 || y > 10.0) {
725 deltx = 0.1*(y - secty);
726 delty = 0.1*(sectx - x);
727 if (deltx==0 && delty== 0) {
729 prout("Spock- \"Bridge to sickbay. Dr. McCoy,");
730 prout(" I recommend an immediate review of");
731 prout(" the Captain's psychological profile.\"");
735 *course = 1.90985932*atan2(deltx, delty);
740 double targ[4][3], course[4];
742 int key, n, i, osuabor;
746 if (game.damage[DPHOTON]) {
747 prout("Photon tubes damaged.");
752 prout("No torpedoes left.");
758 if (key == IHALPHA) {
762 else if (key == IHEOL) {
763 prout("%d torpedoes left.", torps);
764 proutn("Number of torpedoes to fire- ");
767 else /* key == IHREAL */ {
769 if (n <= 0) { /* abort command */
775 prout("Maximum of 3 torpedoes per burst.");
779 if (n <= torps) break;
784 for (i = 1; i <= n; i++) {
786 if (i==1 && key == IHEOL) {
787 break; /* we will try prompting */
789 if (i==2 && key == IHEOL) {
790 /* direct all torpedoes at one target */
792 targ[i][1] = targ[1][1];
793 targ[i][2] = targ[1][2];
794 course[i] = course[1];
810 if (targetcheck(targ[i][1], targ[i][2], &course[i])) return;
813 if (i == 1 && key == IHEOL) {
814 /* prompt for each one */
815 for (i = 1; i <= n; i++) {
816 proutn("Target sector for torpedo number %d- ", i);
830 if (targetcheck(targ[i][1], targ[i][2], &course[i])) return;
834 /* Loop for moving <n> torpedoes */
836 for (i = 1; i <= n && !osuabor; i++) {
837 if (condit != IHDOCKED) torps--;
838 r = (Rand()+Rand())*0.5 -0.5;
839 if (fabs(r) >= 0.47) {
841 r = (Rand()+1.2) * r;
843 prouts("***TORPEDO NUMBER %d MISFIRES", i);
845 else prouts("***TORPEDO MISFIRES.");
848 prout(" Remainder of burst aborted.");
851 prout("***Photon tubes damaged by misfire.");
852 game.damage[DPHOTON] = damfac*(1.0+2.0*Rand());
856 if (shldup || condit == IHDOCKED) r *= 1.0 + 0.0001*shield;
860 proutn("Track for torpedo number %d- ", i);
864 proutn("Torpedo track- ");
867 torpedo(course[i], r, sectx, secty, &dummy, i);
868 if (alldone || game.state.galaxy[quadx][quady]==1000) return;
870 if (game.state.remkl==0) finish(FWON);
875 static void overheat(double rpow) {
877 double chekbrn = (rpow-1500.)*0.00038;
878 if (Rand() <= chekbrn) {
879 prout("Weapons officer Sulu- \"Phasers overheated, sir.\"");
880 game.damage[DPHASER] = damfac*(1.0 + Rand()) * (1.0+chekbrn);
885 static int checkshctrl(double rpow) {
891 prout("Shields lowered.");
894 /* Something bad has happened */
895 prouts("***RED ALERT! RED ALERT!");
897 hit = rpow*shield/inshld;
898 energy -= rpow+hit*0.8;
901 prouts("Sulu- \"Captain! Shield malf***********************\"");
907 prouts("Sulu- \"Captain! Shield malfunction! Phaser fire contained!\"");
909 prout("Lt. Uhura- \"Sir, all decks reporting damage.\"");
910 icas = hit*Rand()*0.012;
915 prout("McCoy to bridge- \"Severe radiation burns, Jim.");
916 prout(" %d casualties so far.\"", icas);
920 prout("Phaser energy dispersed by shields.");
921 prout("Enemy unaffected.");
928 double hits[21], rpow=0, extra, powrem, over, temp;
929 int kz = 0, k=1, i, irec=0; /* Cheating inhibitor */
930 int ifast=0, no=0, ipoop=1, msgflag = 1;
931 enum {NOTSET, MANUAL, FORCEMAN, AUTOMATIC} automode = NOTSET;
935 /* SR sensors and Computer */
936 if (game.damage[DSRSENS]+game.damage[DCOMPTR] > 0) ipoop = 0;
937 if (condit == IHDOCKED) {
938 prout("Phasers can't be fired through base shields.");
942 if (game.damage[DPHASER] != 0) {
943 prout("Phaser control damaged.");
948 if (game.damage[DSHCTRL]) {
949 prout("High speed shield control damaged.");
953 if (energy <= 200.0) {
954 prout("Insufficient energy to activate high-speed shield control.");
958 prout("Weapons Officer Sulu- \"High-speed shield control enabled, sir.\"");
962 /* Original code so convoluted, I re-did it all */
963 while (automode==NOTSET) {
965 if (key == IHALPHA) {
966 if (isit("manual")) {
968 prout("There is no enemy present to select.");
978 else if (isit("automatic")) {
979 if ((!ipoop) && nenhere != 0) {
984 prout("Energy will be expended into space.");
985 automode = AUTOMATIC;
989 else if (isit("no")) {
997 else if (key == IHREAL) {
999 prout("Energy will be expended into space.");
1000 automode = AUTOMATIC;
1003 automode = FORCEMAN;
1005 automode = AUTOMATIC;
1010 prout("Energy will be expended into space.");
1011 automode = AUTOMATIC;
1014 automode = FORCEMAN;
1016 proutn("Manual or automatic? ");
1022 if (key == IHALPHA && isit("no")) {
1026 if (key != IHREAL && nenhere != 0) {
1027 prout("Phasers locked on target. Energy available: %.2f",
1028 ifast?energy-200.0:energy,1,2);
1033 if (!kz) for (i = 1; i <= nenhere; i++)
1034 irec+=fabs(game.kpower[i])/(PHASEFAC*pow(0.90,game.kdist[i]))*
1035 (1.01+0.05*Rand()) + 1.0;
1037 proutn("(%d) units required. ", irec);
1039 proutn("Units to fire= ");
1041 if (key!=IHREAL) return;
1043 if (rpow > (ifast?energy-200:energy)) {
1044 proutn("Energy available= %.2f",
1045 ifast?energy-200:energy);
1049 } while (rpow > (ifast?energy-200:energy));
1055 if ((key=scan()) == IHALPHA && isit("no")) {
1059 energy -= 200; /* Go and do it! */
1060 if (checkshctrl(rpow)) return;
1068 for (i = 1; i <= nenhere; i++) {
1070 if (powrem <= 0) continue;
1071 hits[i] = fabs(game.kpower[i])/(PHASEFAC*pow(0.90,game.kdist[i]));
1072 over = (0.01 + 0.05*Rand())*hits[i];
1074 powrem -= hits[i] + over;
1075 if (powrem <= 0 && temp < hits[i]) hits[i] = temp;
1076 if (powrem <= 0) over = 0.0;
1079 if (powrem > 0.0) extra += powrem;
1083 if (extra > 0 && alldone == 0) {
1085 proutn("*** Tholian web absorbs ");
1086 if (nenhere>0) proutn("excess ");
1087 prout("phaser energy.");
1090 prout("%d expended on empty space.", (int)extra);
1098 if (game.damage[DCOMPTR]!=0)
1099 prout("Battle comuter damaged, manual file only.");
1102 prouts("---WORKING---");
1104 prout("Short-range-sensors-damaged");
1105 prout("Insufficient-data-for-automatic-phaser-fire");
1106 prout("Manual-fire-must-be-used");
1111 for (k = 1; k <= nenhere;) {
1112 int ii = game.kx[k], jj = game.ky[k];
1113 int ienm = game.quad[ii][jj];
1115 proutn("Energy available= %.2f",
1116 energy-.006-(ifast?200:0));
1121 if (game.damage[DSRSENS] && !(abs(sectx-ii) < 2 && abs(secty-jj) < 2) &&
1122 (ienm == IHC || ienm == IHS)) {
1124 prout(" can't be located without short range scan.");
1127 hits[k] = 0; /* prevent overflow -- thanks to Alexei Voitenko */
1133 if (ipoop && k > kz)
1134 irec=(fabs(game.kpower[k])/(PHASEFAC*pow(0.9,game.kdist[k])))*
1135 (1.01+0.05*Rand()) + 1.0;
1138 if (game.damage[DCOMPTR]==0) proutn("%d", irec);
1141 proutn("units to fire at ");
1142 crmena(0, ienm, 2, ii, jj);
1146 if (key == IHALPHA && isit("no")) {
1151 if (key == IHALPHA) {
1156 if (k==1) { /* Let me say I'm baffled by this */
1168 /* If total requested is too much, inform and start over */
1170 if (rpow > (ifast?energy-200:energy)) {
1171 prout("Available energy exceeded -- try again.");
1175 key = scan(); /* scan for next value */
1179 /* zero energy -- abort */
1183 if (key == IHALPHA && isit("no")) {
1190 if (checkshctrl(rpow)) return;
1194 case NOTSET:; /* avoid gcc warning */
1196 /* Say shield raised or malfunction, if necessary */
1197 if (alldone) return;
1201 if (Rand() >= 0.99) {
1202 prout("Sulu- \"Sir, the high-speed shield control has malfunctioned . . .");
1203 prouts(" CLICK CLICK POP . . .");
1204 prout(" No response, sir!");
1208 prout("Shields raised.");
1216 void hittem(double *hits) {
1217 double kp, kpow, wham, hit, dustfac, kpini;
1218 int nenhr2=nenhere, k=1, kk=1, ii, jj, ienm;
1222 for (; k <= nenhr2; k++, kk++) {
1223 if ((wham = hits[k])==0) continue;
1224 dustfac = 0.9 + 0.01*Rand();
1225 hit = wham*pow(dustfac,game.kdist[kk]);
1226 kpini = game.kpower[kk];
1228 if (PHASEFAC*hit < kp) kp = PHASEFAC*hit;
1229 game.kpower[kk] -= (game.kpower[kk] < 0 ? -kp: kp);
1230 kpow = game.kpower[kk];
1236 if (game.damage[DSRSENS]==0){
1239 setwnd(LEFTUPPER_WINDOW);
1241 gotoxy(jj*2+3,ii+2);
1243 proutn("%c", game.quad[ii][jj]);
1244 gotoxy(wherex()-1,wherey());
1249 proutn("%c", game.quad[ii][jj]);
1250 setwnd(LOWER_WINDOW);
1252 _setcursortype(_NORMALCURSOR);
1255 #endif /* SERGEEV */
1256 proutn("%d unit hit on ", (int)hit);
1259 proutn("Very small hit on ");
1260 ienm = game.quad[ii][jj];
1261 if (ienm==IHQUEST) iqengry=1;
1262 crmena(0,ienm,2,ii,jj);
1265 deadkl(ii, jj, ienm, ii, jj);
1266 if (game.state.remkl==0) finish(FWON);
1267 if (alldone) return;
1268 kk--; /* don't do the increment */
1270 else /* decide whether or not to emasculate klingon */
1271 if (kpow > 0 && Rand() >= 0.9 &&
1272 kpow <= ((0.4 + 0.4*Rand())*kpini)) {
1273 prout("***Mr. Spock- \"Captain, the vessel at ",
1274 cramlc(sector,ii,jj));
1275 prout(" has just lost its firepower.\"");
1276 game.kpower[kk] = -kpow;