Get rid of FORTRANisms.
authorEric S. Raymond <esr@thyrsus.com>
Sun, 6 Feb 2005 21:49:56 +0000 (21:49 +0000)
committerEric S. Raymond <esr@thyrsus.com>
Sun, 6 Feb 2005 21:49:56 +0000 (21:49 +0000)
ai.c
battle.c
events.c
finish.c
io.c
moving.c
planets.c
reports.c
setup.c
sst.c
sst.h

diff --git a/ai.c b/ai.c
index 0fe92c8ff8b1c1282b1065db1ed4819162d102af..762e745dcf4dbe9ff62a0943ebf291506034e3e6 100644 (file)
--- a/ai.c
+++ b/ai.c
 #include "sst.h"
 
-static int tryexit(int lookx, int looky, int ienm, int loccom, int irun) {
-       int iqx, iqy, l;
+static int tryexit(int lookx, int looky, int ienm, int loccom, int irun) 
+{
+    int iqx, iqy, l;
 
-       iqx = quadx+(lookx+(QUADSIZE-1))/QUADSIZE - 1;
-       iqy = quady+(looky+(QUADSIZE-1))/QUADSIZE - 1;
-       if (iqx < 1 || iqx > GALSIZE || iqy < 1 || iqy > GALSIZE ||
-               game.state.galaxy[iqx][iqy] > 899)
-               return 0; /* no can do -- neg energy, supernovae, or >8 Klingons */
-       if (ienm == IHR) return 0; /* Romulans cannot escape! */
-       if (irun == 0) {
-               /* avoid intruding on another commander's territory */
-               if (ienm == IHC) {
-                       for (l = 1; l <= game.state.remcom; l++)
-                               if (game.state.cx[l]==iqx && game.state.cy[l]==iqy) return 0;
-                       /* refuse to leave if currently attacking starbase */
-                       if (batx==quadx && baty==quady) return 0;
-               }
-               /* don't leave if over 1000 units of energy */
-               if (game.kpower[loccom] > 1000.) return 0;
-       }
-       /* print escape message and move out of quadrant.
-          We know this if either short or long range sensors are working */
-       if (game.damage[DSRSENS] == 0.0 || game.damage[DLRSENS] == 0.0 ||
-               condit == IHDOCKED) {
-               crmena(1, ienm, 2, game.kx[loccom], game.ky[loccom]);
-               prout(" escapes to %s (and regains strength).",
-                      cramlc(quadrant, iqx, iqy));
-       }
-       /* handle local matters related to escape */
-       game.quad[game.kx[loccom]][game.ky[loccom]] = IHDOT;
-       game.kx[loccom] = game.kx[nenhere];
-       game.ky[loccom] = game.ky[nenhere];
-       game.kavgd[loccom] = game.kavgd[nenhere];
-       game.kpower[loccom] = game.kpower[nenhere];
-       game.kdist[loccom] = game.kdist[nenhere];
-       klhere--;
-       nenhere--;
-       if (condit != IHDOCKED) newcnd();
-       /* Handle global matters related to escape */
-       game.state.galaxy[quadx][quady] -= ENEMY_PLACE;
-       game.state.galaxy[iqx][iqy] += ENEMY_PLACE;
-       if (ienm==IHS) {
-               ishere=0;
-               iscate=0;
-               ientesc=0;
-               isatb=0;
-               game.future[FSCMOVE]=0.2777+game.state.date;
-               game.future[FSCDBAS]=1e30;
-               game.state.isx=iqx;
-               game.state.isy=iqy;
+    iqx = quadx+(lookx+(QUADSIZE-1))/QUADSIZE - 1;
+    iqy = quady+(looky+(QUADSIZE-1))/QUADSIZE - 1;
+    if (iqx < 1 || iqx > GALSIZE || iqy < 1 || iqy > GALSIZE ||
+       NOEXIT(game.state.galaxy[iqx][iqy]))
+       return 0; /* no can do -- neg energy, supernovae, or >8 Klingons */
+    if (ienm == IHR) return 0; /* Romulans cannot escape! */
+    if (irun == 0) {
+       /* avoid intruding on another commander's territory */
+       if (ienm == IHC) {
+           for (l = 1; l <= game.state.remcom; l++)
+               if (game.state.cx[l]==iqx && game.state.cy[l]==iqy) return 0;
+           /* refuse to leave if currently attacking starbase */
+           if (batx==quadx && baty==quady) return 0;
        }
-       else {
-               for (l=1; l<=game.state.remcom; l++) {
-                       if (game.state.cx[l]==quadx && game.state.cy[l]==quady) {
-                               game.state.cx[l]=iqx;
-                               game.state.cy[l]=iqy;
-                               break;
-                       }
-               }
-               comhere = 0;
+       /* don't leave if over 1000 units of energy */
+       if (game.kpower[loccom] > 1000.) return 0;
+    }
+    /* print escape message and move out of quadrant.
+       We know this if either short or long range sensors are working */
+    if (game.damage[DSRSENS] == 0.0 || game.damage[DLRSENS] == 0.0 ||
+       condit == IHDOCKED) {
+       crmena(1, ienm, 2, game.kx[loccom], game.ky[loccom]);
+       prout(" escapes to %s (and regains strength).",
+             cramlc(quadrant, iqx, iqy));
+    }
+    /* handle local matters related to escape */
+    game.quad[game.kx[loccom]][game.ky[loccom]] = IHDOT;
+    game.kx[loccom] = game.kx[nenhere];
+    game.ky[loccom] = game.ky[nenhere];
+    game.kavgd[loccom] = game.kavgd[nenhere];
+    game.kpower[loccom] = game.kpower[nenhere];
+    game.kdist[loccom] = game.kdist[nenhere];
+    klhere--;
+    nenhere--;
+    if (condit != IHDOCKED) newcnd();
+    /* Handle global matters related to escape */
+    game.state.galaxy[quadx][quady] -= KLINGON_PLACE;
+    game.state.galaxy[iqx][iqy] += KLINGON_PLACE;
+    if (ienm==IHS) {
+       ishere=0;
+       iscate=0;
+       ientesc=0;
+       isatb=0;
+       game.future[FSCMOVE]=0.2777+game.state.date;
+       game.future[FSCDBAS]=1e30;
+       game.state.isx=iqx;
+       game.state.isy=iqy;
+    }
+    else {
+       for (l=1; l<=game.state.remcom; l++) {
+           if (game.state.cx[l]==quadx && game.state.cy[l]==quady) {
+               game.state.cx[l]=iqx;
+               game.state.cy[l]=iqy;
+               break;
+           }
        }
-       return 1; /* success */
+       comhere = 0;
+    }
+    return 1; /* success */
 }
 
 
-static void movebaddy(int comx, int comy, int loccom, int ienm) {
-       int motion, mdist, nsteps, mx, my, nextx, nexty, lookx, looky, ll;
-       int irun = 0;
-       int krawlx, krawly;
-       int success;
-       int attempts;
-       /* This should probably be just comhere + ishere */
-       int nbaddys = skill > 3 ?
-                                 (int)((comhere*2 + ishere*2+klhere*1.23+irhere*1.5)/2.0):
-                                 (comhere + ishere);
-       double dist1, forces;
+static void movebaddy(int comx, int comy, int loccom, int ienm) 
+{
+    int motion, mdist, nsteps, mx, my, nextx, nexty, lookx, looky, ll;
+    int irun = 0;
+    int krawlx, krawly;
+    int success;
+    int attempts;
+    /* This should probably be just comhere + ishere */
+    int nbaddys = skill >= SKILL_EXPERT ?
+       (int)((comhere*2 + ishere*2+klhere*1.23+irhere*1.5)/2.0):
+       (comhere + ishere);
+    double dist1, forces;
 
-       dist1 = game.kdist[loccom];
-       mdist = dist1 + 0.5; /* Nearest integer distance */
+    dist1 = game.kdist[loccom];
+    mdist = dist1 + 0.5; /* Nearest integer distance */
 
-       /* If SC, check with spy to see if should hi-tail it */
-       if (ienm==IHS &&
-               (game.kpower[loccom] <= 500.0 || (condit==IHDOCKED && game.damage[DPHOTON]==0))) {
-               irun = 1;
-               motion = -QUADSIZE;
-       }
-       else {
-               /* decide whether to advance, retreat, or hold position */
+    /* If SC, check with spy to see if should hi-tail it */
+    if (ienm==IHS &&
+       (game.kpower[loccom] <= 500.0 || (condit==IHDOCKED && game.damage[DPHOTON]==0))) {
+       irun = 1;
+       motion = -QUADSIZE;
+    }
+    else {
+       /* decide whether to advance, retreat, or hold position */
 /* Algorithm:
  * Enterprise has "force" based on condition of phaser and photon torpedoes.
    If both are operating full strength, force is 1000. If both are damaged,
       force is -1000. Having shields down subtracts an additional 1000.
+ * Enterprise has "force" based on condition of phaser and photon torpedoes.
+ If both are operating full strength, force is 1000. If both are damaged,
+ force is -1000. Having shields down subtracts an additional 1000.
 
  * Enemy has forces equal to the energy of the attacker plus
    100*(K+R) + 500*(C+S) - 400 for novice through good levels OR
       346*K + 400*R + 500*(C+S) - 400 for expert and emeritus.
+ * Enemy has forces equal to the energy of the attacker plus
+ 100*(K+R) + 500*(C+S) - 400 for novice through good levels OR
+ 346*K + 400*R + 500*(C+S) - 400 for expert and emeritus.
 
       Attacker Initial energy levels (nominal):
                Klingon   Romulan   Commander   Super-Commander
       Novice    400        700        1200        
       Fair      425        750        1250
       Good      450        800        1300        1750
       Expert    475        850        1350        1875
       Emeritus  500        900        1400        2000
    VARIANCE   75        200         200         200
+ Attacker Initial energy levels (nominal):
+ Klingon   Romulan   Commander   Super-Commander
+ Novice    400        700        1200        
+ Fair      425        750        1250
+ Good      450        800        1300        1750
+ Expert    475        850        1350        1875
+ Emeritus  500        900        1400        2000
+ VARIANCE   75        200         200         200
 
       Enemy vessels only move prior to their attack. In Novice - Good games
       only commanders move. In Expert games, all enemy vessels move if there
       is a commander present. In Emeritus games all enemy vessels move.
+ Enemy vessels only move prior to their attack. In Novice - Good games
+ only commanders move. In Expert games, all enemy vessels move if there
+ is a commander present. In Emeritus games all enemy vessels move.
 
 *  If Enterprise is not docked, an agressive action is taken if enemy
    forces are 1000 greater than Enterprise.
+ *  If Enterprise is not docked, an agressive action is taken if enemy
+ forces are 1000 greater than Enterprise.
 
       Agressive action on average cuts the distance between the ship and
       the enemy to 1/4 the original.
+ Agressive action on average cuts the distance between the ship and
+ the enemy to 1/4 the original.
 
 *  At lower energy advantage, movement units are proportional to the
    advantage with a 650 advantage being to hold ground, 800 to move forward
       1, 950 for two, 150 for back 4, etc. Variance of 100.
+ *  At lower energy advantage, movement units are proportional to the
+ advantage with a 650 advantage being to hold ground, 800 to move forward
+ 1, 950 for two, 150 for back 4, etc. Variance of 100.
 
       If docked, is reduced by roughly 1.75*skill, generally forcing a
       retreat, especially at high skill levels.
+ If docked, is reduced by roughly 1.75*skill, generally forcing a
+ retreat, especially at high skill levels.
 
 *  Motion is limited to skill level, except for SC hi-tailing it out.
 */
+ *  Motion is limited to skill level, except for SC hi-tailing it out.
+ */
 
-               forces = game.kpower[loccom]+100.0*nenhere+400*(nbaddys-1);
-               if (shldup==0) forces += 1000; /* Good for enemy if shield is down! */
-               if (game.damage[DPHASER] == 0.0 || game.damage[DPHOTON] == 0.0) {
-                       if (game.damage[DPHASER] != 0) /* phasers damaged */
-                               forces += 300.0;
-                       else
-                               forces -= 0.2*(energy - 2500.0);
-                       if (game.damage[DPHOTON] != 0) /* photon torpedoes damaged */
-                               forces += 300.0;
-                       else
-                               forces -= 50.0*torps;
-               }
-               else {
-                       /* phasers and photon tubes both out! */
-                       forces += 1000.0;
-               }
-               motion = 0;
-               if (forces <= 1000.0 && condit != IHDOCKED) /* Typical situation */
-                       motion = ((forces+200.0*Rand())/150.0) - 5.0;
-               else {
-                       if (forces > 1000.0) /* Very strong -- move in for kill */
-                               motion = (1.0-square(Rand()))*dist1 + 1.0;
-                       if (condit==IHDOCKED) /* protected by base -- back off ! */
-                               motion -= skill*(2.0-square(Rand()));
-               }
-#ifdef DEBUG
-               if (idebug) {
-                       proutn("MOTION = %1.2f", motion);
-                       proutn("  FORCES = %1,2f", forces);
-               }
-#endif
-               /* don't move if no motion */
-               if (motion==0) return;
-               /* Limit motion according to skill */
-               if (abs(motion) > skill) motion = (motion < 0) ? -skill : skill;
+       forces = game.kpower[loccom]+100.0*nenhere+400*(nbaddys-1);
+       if (shldup==0) forces += 1000; /* Good for enemy if shield is down! */
+       if (game.damage[DPHASER] == 0.0 || game.damage[DPHOTON] == 0.0) {
+           if (game.damage[DPHASER] != 0) /* phasers damaged */
+               forces += 300.0;
+           else
+               forces -= 0.2*(energy - 2500.0);
+           if (game.damage[DPHOTON] != 0) /* photon torpedoes damaged */
+               forces += 300.0;
+           else
+               forces -= 50.0*torps;
+       }
+       else {
+           /* phasers and photon tubes both out! */
+           forces += 1000.0;
+       }
+       motion = 0;
+       if (forces <= 1000.0 && condit != IHDOCKED) /* Typical situation */
+           motion = ((forces+200.0*Rand())/150.0) - 5.0;
+       else {
+           if (forces > 1000.0) /* Very strong -- move in for kill */
+               motion = (1.0-square(Rand()))*dist1 + 1.0;
+           if (condit==IHDOCKED) /* protected by base -- back off ! */
+               motion -= skill*(2.0-square(Rand()));
        }
-       /* calcuate preferred number of steps */
-       nsteps = motion < 0 ? -motion : motion;
-       if (motion > 0 && nsteps > mdist) nsteps = mdist; /* don't overshoot */
-       if (nsteps > QUADSIZE) nsteps = QUADSIZE; /* This shouldn't be necessary */
-       if (nsteps < 1) nsteps = 1; /* This shouldn't be necessary */
 #ifdef DEBUG
        if (idebug) {
-               prout("NSTEPS = %d", nsteps);
+           proutn("MOTION = %1.2f", motion);
+           proutn("  FORCES = %1,2f", forces);
        }
 #endif
-       /* Compute preferred values of delta X and Y */
-       mx = sectx - comx;
-       my = secty - comy;
-       if (2.0 * abs(mx) < abs(my)) mx = 0;
-       if (2.0 * abs(my) < abs(sectx-comx)) my = 0;
-       if (mx != 0) mx = mx*motion < 0 ? -1 : 1;
-       if (my != 0) my = my*motion < 0 ? -1 : 1;
-       nextx = comx;
-       nexty = comy;
-       /* main move loop */
-       for (ll = 1; ll <= nsteps; ll++) {
+       /* don't move if no motion */
+       if (motion==0) return;
+       /* Limit motion according to skill */
+       if (abs(motion) > skill) motion = (motion < 0) ? -skill : skill;
+    }
+    /* calcuate preferred number of steps */
+    nsteps = motion < 0 ? -motion : motion;
+    if (motion > 0 && nsteps > mdist) nsteps = mdist; /* don't overshoot */
+    if (nsteps > QUADSIZE) nsteps = QUADSIZE; /* This shouldn't be necessary */
+    if (nsteps < 1) nsteps = 1; /* This shouldn't be necessary */
 #ifdef DEBUG
-               if (idebug) {
-                       prout("%d", ll);
-               }
+    if (idebug) {
+       prout("NSTEPS = %d", nsteps);
+    }
 #endif
-               /* Check if preferred position available */
-               lookx = nextx + mx;
-               looky = nexty + my;
-               krawlx = mx < 0 ? 1 : -1;
-               krawly = my < 0 ? 1 : -1;
-               success = 0;
-               attempts = 0; /* Settle mysterious hang problem */
-               while (attempts++ < 20 && !success) {
-                       if (lookx < 1 || lookx > QUADSIZE) {
-                               if (motion < 0 && tryexit(lookx, looky, ienm, loccom, irun))
-                                       return;
-                               if (krawlx == mx || my == 0) break;
-                               lookx = nextx + krawlx;
-                               krawlx = -krawlx;
-                       }
-                       else if (looky < 1 || looky > QUADSIZE) {
-                               if (motion < 0 && tryexit(lookx, looky, ienm, loccom, irun))
-                                       return;
-                               if (krawly == my || mx == 0) break;
-                               looky = nexty + krawly;
-                               krawly = -krawly;
-                       }
-                       else if (game.quad[lookx][looky] != IHDOT) {
-                               /* See if we should ram ship */
-                               if (game.quad[lookx][looky] == ship &&
-                                       (ienm == IHC || ienm == IHS)) {
-                                       ram(1, ienm, comx, comy);
-                                       return;
-                               }
-                               if (krawlx != mx && my != 0) {
-                                       lookx = nextx + krawlx;
-                                       krawlx = -krawlx;
-                               }
-                               else if (krawly != my && mx != 0) {
-                                       looky = nexty + krawly;
-                                       krawly = -krawly;
-                               }
-                               else break; /* we have failed */
-                       }
-                       else success = 1;
-               }
-               if (success) {
-                       nextx = lookx;
-                       nexty = looky;
+    /* Compute preferred values of delta X and Y */
+    mx = sectx - comx;
+    my = secty - comy;
+    if (2.0 * abs(mx) < abs(my)) mx = 0;
+    if (2.0 * abs(my) < abs(sectx-comx)) my = 0;
+    if (mx != 0) mx = mx*motion < 0 ? -1 : 1;
+    if (my != 0) my = my*motion < 0 ? -1 : 1;
+    nextx = comx;
+    nexty = comy;
+    /* main move loop */
+    for (ll = 1; ll <= nsteps; ll++) {
 #ifdef DEBUG
-                       if (idebug) {
-                               prout(cramlc(neither, nextx, nexty));
-                       }
+       if (idebug) {
+           prout("%d", ll);
+       }
 #endif
+       /* Check if preferred position available */
+       lookx = nextx + mx;
+       looky = nexty + my;
+       krawlx = mx < 0 ? 1 : -1;
+       krawly = my < 0 ? 1 : -1;
+       success = 0;
+       attempts = 0; /* Settle mysterious hang problem */
+       while (attempts++ < 20 && !success) {
+           if (lookx < 1 || lookx > QUADSIZE) {
+               if (motion < 0 && tryexit(lookx, looky, ienm, loccom, irun))
+                   return;
+               if (krawlx == mx || my == 0) break;
+               lookx = nextx + krawlx;
+               krawlx = -krawlx;
+           }
+           else if (looky < 1 || looky > QUADSIZE) {
+               if (motion < 0 && tryexit(lookx, looky, ienm, loccom, irun))
+                   return;
+               if (krawly == my || mx == 0) break;
+               looky = nexty + krawly;
+               krawly = -krawly;
+           }
+           else if (game.quad[lookx][looky] != IHDOT) {
+               /* See if we should ram ship */
+               if (game.quad[lookx][looky] == ship &&
+                   (ienm == IHC || ienm == IHS)) {
+                   ram(1, ienm, comx, comy);
+                   return;
                }
-               else break; /* done early */
-       }
-       /* Put commander in place within same quadrant */
-       game.quad[comx][comy] = IHDOT;
-       game.quad[nextx][nexty] = ienm;
-       if (nextx != comx || nexty != comy) {
-               /* it moved */
-               game.kx[loccom] = nextx;
-               game.ky[loccom] = nexty;
-               game.kdist[loccom] = game.kavgd[loccom] =
-                                       sqrt(square(sectx-nextx)+square(secty-nexty));
-               if (game.damage[DSRSENS] == 0 || condit == IHDOCKED) {
-                       proutn("***");
-                       cramen(ienm);
-                       proutn(" from %s", cramlc(2, comx, comy));
-                       if (game.kdist[loccom] < dist1) proutn(" advances to ");
-                       else proutn(" retreats to ");
-                       prout(cramlc(sector, nextx, nexty));
+               if (krawlx != mx && my != 0) {
+                   lookx = nextx + krawlx;
+                   krawlx = -krawlx;
                }
+               else if (krawly != my && mx != 0) {
+                   looky = nexty + krawly;
+                   krawly = -krawly;
+               }
+               else break; /* we have failed */
+           }
+           else success = 1;
+       }
+       if (success) {
+           nextx = lookx;
+           nexty = looky;
+#ifdef DEBUG
+           if (idebug) {
+               prout(cramlc(neither, nextx, nexty));
+           }
+#endif
        }
+       else break; /* done early */
+    }
+    /* Put commander in place within same quadrant */
+    game.quad[comx][comy] = IHDOT;
+    game.quad[nextx][nexty] = ienm;
+    if (nextx != comx || nexty != comy) {
+       /* it moved */
+       game.kx[loccom] = nextx;
+       game.ky[loccom] = nexty;
+       game.kdist[loccom] = game.kavgd[loccom] =
+           sqrt(square(sectx-nextx)+square(secty-nexty));
+       if (game.damage[DSRSENS] == 0 || condit == IHDOCKED) {
+           proutn("***");
+           cramen(ienm);
+           proutn(" from %s", cramlc(2, comx, comy));
+           if (game.kdist[loccom] < dist1) proutn(" advances to ");
+           else proutn(" retreats to ");
+           prout(cramlc(sector, nextx, nexty));
+       }
+    }
 }
 
-void movcom(void) {
-       int ix, iy, i;
+void movcom(void) 
+{
+    int ix, iy, i;
 
 #ifdef DEBUG
-       if (idebug) prout("MOVCOM");
+    if (idebug) prout("MOVCOM");
 #endif
 
-       /* Figure out which Klingon is the commander (or Supercommander)
-          and do move */
-       if (comhere) for (i = 1; i <= nenhere; i++) {
-               ix = game.kx[i];
-               iy = game.ky[i];
-               if (game.quad[ix][iy] == IHC) {
-                       movebaddy(ix, iy, i, IHC);
-                       break;
-               }
+    /* Figure out which Klingon is the commander (or Supercommander)
+       and do move */
+    if (comhere) for (i = 1; i <= nenhere; i++) {
+       ix = game.kx[i];
+       iy = game.ky[i];
+       if (game.quad[ix][iy] == IHC) {
+           movebaddy(ix, iy, i, IHC);
+           break;
        }
-       if (ishere) for (i = 1; i <= nenhere; i++) {
-               ix = game.kx[i];
-               iy = game.ky[i];
-               if (game.quad[ix][iy] == IHS) {
-                       movebaddy(ix, iy, i, IHS);
-                       break;
-               }
+    }
+    if (ishere) for (i = 1; i <= nenhere; i++) {
+       ix = game.kx[i];
+       iy = game.ky[i];
+       if (game.quad[ix][iy] == IHS) {
+           movebaddy(ix, iy, i, IHS);
+           break;
        }
-       /* if skill level is high, move other Klingons and Romulans too!
-          Move these last so they can base their actions on what the
+    }
+    /* if skill level is high, move other Klingons and Romulans too!
+       Move these last so they can base their actions on what the
        commander(s) do. */
-       if (skill > 3) for (i = 1; i <= nenhere; i++) {
-               ix = game.kx[i];
-               iy = game.ky[i];
-               if (game.quad[ix][iy] == IHK || game.quad[ix][iy] == IHR)
-                       movebaddy(ix, iy, i, game.quad[ix][iy]);
-       }
+    if (skill >= SKILL_EXPERT) for (i = 1; i <= nenhere; i++) {
+       ix = game.kx[i];
+       iy = game.ky[i];
+       if (game.quad[ix][iy] == IHK || game.quad[ix][iy] == IHR)
+           movebaddy(ix, iy, i, game.quad[ix][iy]);
+    }
 
-       sortkl();
+    sortkl();
 }
 
-static int movescom(int iqx, int iqy, int flag, int *ipage) {
-       int i;
+static int movescom(int iqx, int iqy, int flag, int *ipage) 
+{
+    int i;
 
-       if ((iqx==quadx && iqy==quady) ||
-               iqx < 1 || iqx > GALSIZE || iqy < 1 || iqy > GALSIZE ||
-               game.state.galaxy[iqx][iqy] > 899) return 1;
-       if (flag) {
-               /* Avoid quadrants with bases if we want to avoid Enterprise */
-               for (i = 1; i <= game.state.rembase; i++)
-                       if (game.state.baseqx[i]==iqx && game.state.baseqy[i]==iqy) return 1;
-       }
-       if (justin && !iscate) return 1;
-       /* do the move */
-       game.state.galaxy[game.state.isx][game.state.isy] -= ENEMY_PLACE;
-       game.state.isx = iqx;
-       game.state.isy = iqy;
-       game.state.galaxy[game.state.isx][game.state.isy] += ENEMY_PLACE;
-       if (ishere) {
-               /* SC has scooted, Remove him from current quadrant */
-               iscate=0;
-               isatb=0;
-               ishere=0;
-               ientesc=0;
-               game.future[FSCDBAS]=1e30;
-               for (i = 1; i <= nenhere; i++) 
-                       if (game.quad[game.kx[i]][game.ky[i]] == IHS) break;
-               game.quad[game.kx[i]][game.ky[i]] = IHDOT;
-               game.kx[i] = game.kx[nenhere];
-               game.ky[i] = game.ky[nenhere];
-               game.kdist[i] = game.kdist[nenhere];
-               game.kavgd[i] = game.kavgd[nenhere];
-               game.kpower[i] = game.kpower[nenhere];
-               klhere--;
-               nenhere--;
-               if (condit!=IHDOCKED) newcnd();
-               sortkl();
-       }
-       /* check for a helpful planet */
-       for (i = 0; i < inplan; i++) {
-               if (game.state.plnets[i].x==game.state.isx && game.state.plnets[i].y==game.state.isy &&
-                       game.state.plnets[i].crystals == 1) {
-                       /* destroy the planet */
-                       DESTROY(&game.state.plnets[i]);
-                       game.state.newstuf[game.state.isx][game.state.isy] -= 1;
-                       if (game.damage[DRADIO] == 0.0 || condit == IHDOCKED) {
-                               if (*ipage==0) pause_game(1);
-                               *ipage = 1;
-                               prout("Lt. Uhura-  \"Captain, Starfleet Intelligence reports");
-                               proutn("   a planet in ");
-                               proutn(cramlc(quadrant, game.state.isx, game.state.isy));
-                               prout(" has been destroyed");
-                               prout("   by the Super-commander.\"");
-                       }
-                       break;
-               }
+    if ((iqx==quadx && iqy==quady) ||
+       iqx < 1 || iqx > GALSIZE || iqy < 1 || iqy > GALSIZE ||
+       NOEXIT(game.state.galaxy[iqx][iqy])) return 1;
+    if (flag) {
+       /* Avoid quadrants with bases if we want to avoid Enterprise */
+       for (i = 1; i <= game.state.rembase; i++)
+           if (game.state.baseqx[i]==iqx && game.state.baseqy[i]==iqy) return 1;
+    }
+    if (justin && !iscate) return 1;
+    /* do the move */
+    game.state.galaxy[game.state.isx][game.state.isy] -= KLINGON_PLACE;
+    game.state.isx = iqx;
+    game.state.isy = iqy;
+    game.state.galaxy[game.state.isx][game.state.isy] += KLINGON_PLACE;
+    if (ishere) {
+       /* SC has scooted, Remove him from current quadrant */
+       iscate=0;
+       isatb=0;
+       ishere=0;
+       ientesc=0;
+       game.future[FSCDBAS]=1e30;
+       for (i = 1; i <= nenhere; i++) 
+           if (game.quad[game.kx[i]][game.ky[i]] == IHS) break;
+       game.quad[game.kx[i]][game.ky[i]] = IHDOT;
+       game.kx[i] = game.kx[nenhere];
+       game.ky[i] = game.ky[nenhere];
+       game.kdist[i] = game.kdist[nenhere];
+       game.kavgd[i] = game.kavgd[nenhere];
+       game.kpower[i] = game.kpower[nenhere];
+       klhere--;
+       nenhere--;
+       if (condit!=IHDOCKED) newcnd();
+       sortkl();
+    }
+    /* check for a helpful planet */
+    for (i = 0; i < inplan; i++) {
+       if (game.state.plnets[i].x==game.state.isx && game.state.plnets[i].y==game.state.isy &&
+           game.state.plnets[i].crystals == 1) {
+           /* destroy the planet */
+           DESTROY(&game.state.plnets[i]);
+           game.state.newstuf[game.state.isx][game.state.isy] -= 1;
+           if (game.damage[DRADIO] == 0.0 || condit == IHDOCKED) {
+               if (*ipage==0) pause_game(1);
+               *ipage = 1;
+               prout("Lt. Uhura-  \"Captain, Starfleet Intelligence reports");
+               proutn("   a planet in ");
+               proutn(cramlc(quadrant, game.state.isx, game.state.isy));
+               prout(" has been destroyed");
+               prout("   by the Super-commander.\"");
+           }
+           break;
        }
-       return 0; /* looks good! */
+    }
+    return 0; /* looks good! */
 }
                        
-               
-       
-
-
-void scom(int *ipage) {
-       int i, i2, j, ideltax, ideltay, ibqx, ibqy, sx, sy, ifindit, iwhichb;
-       int iqx, iqy;
-       int basetbl[BASEMAX];
-       double bdist[BASEMAX];
-       int flag;
+void scom(int *ipage)
+{
+    int i, i2, j, ideltax, ideltay, ibqx, ibqy, sx, sy, ifindit, iwhichb;
+    int iqx, iqy;
+    int basetbl[BASEMAX];
+    double bdist[BASEMAX];
+    int flag;
 #ifdef DEBUG
-       if (idebug) prout("SCOM");
+    if (idebug) prout("SCOM");
 #endif
 
-       /* Decide on being active or passive */
-       flag = ((game.state.killc+game.state.killk)/(game.state.date+0.01-indate) < 0.1*skill*(skill+1.0) ||
-                       (game.state.date-indate) < 3.0);
-       if (iscate==0 && flag) {
-               /* compute move away from Enterprise */
-               ideltax = game.state.isx-quadx;
-               ideltay = game.state.isy-quady;
-               if (sqrt(ideltax*(double)ideltax+ideltay*(double)ideltay) > 2.0) {
-                       /* circulate in space */
-                       ideltax = game.state.isy-quady;
-                       ideltay = quadx-game.state.isx;
-               }
+    /* Decide on being active or passive */
+    flag = ((game.state.killc+game.state.killk)/(game.state.date+0.01-indate) < 0.1*skill*(skill+1.0) ||
+           (game.state.date-indate) < 3.0);
+    if (iscate==0 && flag) {
+       /* compute move away from Enterprise */
+       ideltax = game.state.isx-quadx;
+       ideltay = game.state.isy-quady;
+       if (sqrt(ideltax*(double)ideltax+ideltay*(double)ideltay) > 2.0) {
+           /* circulate in space */
+           ideltax = game.state.isy-quady;
+           ideltay = quadx-game.state.isx;
        }
-       else {
-               /* compute distances to starbases */
-               if (game.state.rembase <= 0) {
-                       /* nothing left to do */
-                       game.future[FSCMOVE] = 1e30;
-                       return;
-               }
-               sx = game.state.isx;
-               sy = game.state.isy;
-               for (i = 1; i <= game.state.rembase; i++) {
-                       basetbl[i] = i;
-                       ibqx = game.state.baseqx[i];
-                       ibqy = game.state.baseqy[i];
-                       bdist[i] = sqrt(square(ibqx-sx) + square(ibqy-sy));
-               }
-               if (game.state.rembase > 1) {
-                       /* sort into nearest first order */
-                       int iswitch;
-                       do {
-                               iswitch = 0;
-                               for (i=1; i < game.state.rembase-1; i++) {
-                                       if (bdist[i] > bdist[i+1]) {
-                                               int ti = basetbl[i];
-                                               double t = bdist[i];
-                                               bdist[i] = bdist[i+1];
-                                               bdist[i+1] = t;
-                                               basetbl[i] = basetbl[i+1];
-                                               basetbl[i+1] =ti;
-                                               iswitch = 1;
-                                       }
-                               }
-                       } while (iswitch);
+    }
+    else {
+       /* compute distances to starbases */
+       if (game.state.rembase <= 0) {
+           /* nothing left to do */
+           game.future[FSCMOVE] = 1e30;
+           return;
+       }
+       sx = game.state.isx;
+       sy = game.state.isy;
+       for (i = 1; i <= game.state.rembase; i++) {
+           basetbl[i] = i;
+           ibqx = game.state.baseqx[i];
+           ibqy = game.state.baseqy[i];
+           bdist[i] = sqrt(square(ibqx-sx) + square(ibqy-sy));
+       }
+       if (game.state.rembase > 1) {
+           /* sort into nearest first order */
+           int iswitch;
+           do {
+               iswitch = 0;
+               for (i=1; i < game.state.rembase-1; i++) {
+                   if (bdist[i] > bdist[i+1]) {
+                       int ti = basetbl[i];
+                       double t = bdist[i];
+                       bdist[i] = bdist[i+1];
+                       bdist[i+1] = t;
+                       basetbl[i] = basetbl[i+1];
+                       basetbl[i+1] =ti;
+                       iswitch = 1;
+                   }
                }
-               /* look for nearest base without a commander, no Enterprise, and
-                  without too many Klingons, and not already under attack. */
-               ifindit = iwhichb = 0;
+           } while (iswitch);
+       }
+       /* look for nearest base without a commander, no Enterprise, and
+          without too many Klingons, and not already under attack. */
+       ifindit = iwhichb = 0;
 
-               for (i2 = 1; i2 <= game.state.rembase; i2++) {
-                       i = basetbl[i2];        /* bug in original had it not finding nearest*/
-                       ibqx = game.state.baseqx[i];
-                       ibqy = game.state.baseqy[i];
-                       if ((ibqx == quadx && ibqy == quady) ||
-                               (ibqx == batx && ibqy == baty) ||
-                               game.state.galaxy[ibqx][ibqy] > 899) continue;
-                       /* if there is a commander, an no other base is appropriate,
-                          we will take the one with the commander */
-                       for (j = 1; j <= game.state.remcom; j++) {
-                               if (ibqx==game.state.cx[j] && ibqy==game.state.cy[j] && ifindit!= 2) {
-                                               ifindit = 2;
-                                               iwhichb = i;
-                                               break;
-                               }
-                       }
-                       if (j > game.state.remcom) { /* no commander -- use this one */
-                               ifindit = 1;
-                               iwhichb = i;
-                               break;
-                       }
+       for (i2 = 1; i2 <= game.state.rembase; i2++) {
+           i = basetbl[i2];    /* bug in original had it not finding nearest*/
+           ibqx = game.state.baseqx[i];
+           ibqy = game.state.baseqy[i];
+           if ((ibqx == quadx && ibqy == quady) ||
+               (ibqx == batx && ibqy == baty) ||
+               NOEXIT(game.state.galaxy[ibqx][ibqy])) continue;
+           /* if there is a commander, an no other base is appropriate,
+              we will take the one with the commander */
+           for (j = 1; j <= game.state.remcom; j++) {
+               if (ibqx==game.state.cx[j] && ibqy==game.state.cy[j] && ifindit!= 2) {
+                   ifindit = 2;
+                   iwhichb = i;
+                   break;
                }
-               if (ifindit==0) return; /* Nothing suitable -- wait until next time*/
-               ibqx = game.state.baseqx[iwhichb];
-               ibqy = game.state.baseqy[iwhichb];
-               /* decide how to move toward base */
-               ideltax = ibqx - game.state.isx;
-               ideltay = ibqy - game.state.isy;
+           }
+           if (j > game.state.remcom) { /* no commander -- use this one */
+               ifindit = 1;
+               iwhichb = i;
+               break;
+           }
        }
-       /* Maximum movement is 1 quadrant in either or both axis */
-       if (ideltax > 1) ideltax = 1;
-       if (ideltax < -1) ideltax = -1;
-       if (ideltay > 1) ideltay = 1;
-       if (ideltay < -1) ideltay = -1;
+       if (ifindit==0) return; /* Nothing suitable -- wait until next time*/
+       ibqx = game.state.baseqx[iwhichb];
+       ibqy = game.state.baseqy[iwhichb];
+       /* decide how to move toward base */
+       ideltax = ibqx - game.state.isx;
+       ideltay = ibqy - game.state.isy;
+    }
+    /* Maximum movement is 1 quadrant in either or both axis */
+    if (ideltax > 1) ideltax = 1;
+    if (ideltax < -1) ideltax = -1;
+    if (ideltay > 1) ideltay = 1;
+    if (ideltay < -1) ideltay = -1;
 
-       /* try moving in both x and y directions */
-       iqx = game.state.isx + ideltax;
-       iqy = game.state.isy + ideltax;
-       if (movescom(iqx, iqy, flag, ipage)) {
-               /* failed -- try some other maneuvers */
-               if (ideltax==0 || ideltay==0) {
-                       /* attempt angle move */
-                       if (ideltax != 0) {
-                               iqy = game.state.isy + 1;
-                               if (movescom(iqx, iqy, flag, ipage)) {
-                                       iqy = game.state.isy - 1;
-                                       movescom(iqx, iqy, flag, ipage);
-                               }
-                       }
-                       else {
-                               iqx = game.state.isx + 1;
-                               if (movescom(iqx, iqy, flag, ipage)) {
-                                       iqx = game.state.isx - 1;
-                                       movescom(iqx, iqy, flag, ipage);
-                               }
-                       }
+    /* try moving in both x and y directions */
+    iqx = game.state.isx + ideltax;
+    iqy = game.state.isy + ideltax;
+    if (movescom(iqx, iqy, flag, ipage)) {
+       /* failed -- try some other maneuvers */
+       if (ideltax==0 || ideltay==0) {
+           /* attempt angle move */
+           if (ideltax != 0) {
+               iqy = game.state.isy + 1;
+               if (movescom(iqx, iqy, flag, ipage)) {
+                   iqy = game.state.isy - 1;
+                   movescom(iqx, iqy, flag, ipage);
                }
-               else {
-                       /* try moving just in x or y */
-                       iqy = game.state.isy;
-                       if (movescom(iqx, iqy, flag, ipage)) {
-                               iqy = game.state.isy + ideltay;
-                               iqx = game.state.isx;
-                               movescom(iqx, iqy, flag, ipage);
-                       }
+           }
+           else {
+               iqx = game.state.isx + 1;
+               if (movescom(iqx, iqy, flag, ipage)) {
+                   iqx = game.state.isx - 1;
+                   movescom(iqx, iqy, flag, ipage);
                }
+           }
        }
-       /* check for a base */
-       if (game.state.rembase == 0) {
-               game.future[FSCMOVE] = 1e30;
+       else {
+           /* try moving just in x or y */
+           iqy = game.state.isy;
+           if (movescom(iqx, iqy, flag, ipage)) {
+               iqy = game.state.isy + ideltay;
+               iqx = game.state.isx;
+               movescom(iqx, iqy, flag, ipage);
+           }
        }
-       else for (i=1; i<=game.state.rembase; i++) {
-               ibqx = game.state.baseqx[i];
-               ibqy = game.state.baseqy[i];
-               if (ibqx==game.state.isx && ibqy == game.state.isy && game.state.isx != batx && game.state.isy != baty) {
-                       /* attack the base */
-                       if (flag) return; /* no, don't attack base! */
-                       iseenit = 0;
-                       isatb=1;
-                       game.future[FSCDBAS] = game.state.date + 1.0 +2.0*Rand();
-                       if (game.future[FCDBAS] < 1e30) game.future[FSCDBAS] +=
-                               game.future[FCDBAS]-game.state.date;
-                       if (game.damage[DRADIO] > 0 && condit != IHDOCKED)
-                               return; /* no warning */
-                       iseenit = 1;
-                       if (*ipage == 0)  pause_game(1);
-                       *ipage=1;
-                       proutn("Lt. Uhura-  \"Captain, the starbase in ");
-                       proutn(cramlc(quadrant, game.state.isx, game.state.isy));
-                       skip(1);
-                       prout("   reports that it is under attack from the Klingon Super-commander.");
-                       proutn("   It can survive until stardate %d.\"",
-                              (int)game.future[FSCDBAS]);
-                       if (resting==0) return;
-                       prout("Mr. Spock-  \"Captain, shall we cancel the rest period?\"");
-                       if (ja()==0) return;
-                       resting = 0;
-                       Time = 0.0; /* actually finished */
-                       return;
-               }
+    }
+    /* check for a base */
+    if (game.state.rembase == 0) {
+       game.future[FSCMOVE] = 1e30;
+    }
+    else for (i=1; i<=game.state.rembase; i++) {
+       ibqx = game.state.baseqx[i];
+       ibqy = game.state.baseqy[i];
+       if (ibqx==game.state.isx && ibqy == game.state.isy && game.state.isx != batx && game.state.isy != baty) {
+           /* attack the base */
+           if (flag) return; /* no, don't attack base! */
+           iseenit = 0;
+           isatb=1;
+           game.future[FSCDBAS] = game.state.date + 1.0 +2.0*Rand();
+           if (game.future[FCDBAS] < 1e30) game.future[FSCDBAS] +=
+               game.future[FCDBAS]-game.state.date;
+           if (game.damage[DRADIO] > 0 && condit != IHDOCKED)
+               return; /* no warning */
+           iseenit = 1;
+           if (*ipage == 0)  pause_game(1);
+           *ipage=1;
+           proutn("Lt. Uhura-  \"Captain, the starbase in ");
+           proutn(cramlc(quadrant, game.state.isx, game.state.isy));
+           skip(1);
+           prout("   reports that it is under attack from the Klingon Super-commander.");
+           proutn("   It can survive until stardate %d.\"",
+                  (int)game.future[FSCDBAS]);
+           if (resting==0) return;
+           prout("Mr. Spock-  \"Captain, shall we cancel the rest period?\"");
+           if (ja()==0) return;
+           resting = 0;
+           Time = 0.0; /* actually finished */
+           return;
        }
-       /* Check for intelligence report */
-       if (
+    }
+    /* Check for intelligence report */
+    if (
 #ifdef DEBUG
-               idebug==0 &&
+       idebug==0 &&
 #endif
-               (Rand() > 0.2 ||
-                (game.damage[DRADIO] > 0.0 && condit != IHDOCKED) ||
-                game.starch[game.state.isx][game.state.isy] > 0))
-               return;
-       if (*ipage==0) pause_game(1);
-       *ipage = 1;
-       prout("Lt. Uhura-  \"Captain, Starfleet Intelligence reports");
-       proutn("   the Super-commander is in ");
-       proutn(cramlc(quadrant, game.state.isx, game.state. isy));
-       prout(".\"");
+       (Rand() > 0.2 ||
+        (game.damage[DRADIO] > 0.0 && condit != IHDOCKED) ||
+        game.starch[game.state.isx][game.state.isy] > 0))
        return;
+    if (*ipage==0) pause_game(1);
+    *ipage = 1;
+    prout("Lt. Uhura-  \"Captain, Starfleet Intelligence reports");
+    proutn("   the Super-commander is in ");
+    proutn(cramlc(quadrant, game.state.isx, game.state. isy));
+    prout(".\"");
+    return;
 }
 
-void movetho(void) {
-       int idx, idy, im, i, dum, my;
-       /* Move the Tholian */
-       if (ithere==0 || justin == 1) return;
+void movetho(void)
+{
+    int idx, idy, im, i, dum, my;
+    /* Move the Tholian */
+    if (ithere==0 || justin == 1) return;
 
-       if (ithx == 1 && ithy == 1) {
-               idx = 1; idy = QUADSIZE;
-       }
-       else if (ithx == 1 && ithy == QUADSIZE) {
-               idx = QUADSIZE; idy = QUADSIZE;
-       }
-       else if (ithx == QUADSIZE && ithy == QUADSIZE) {
-               idx = QUADSIZE; idy = 1;
-       }
-       else if (ithx == QUADSIZE && ithy == 1) {
-               idx = 1; idy = 1;
-       }
-       else {
-               /* something is wrong! */
-               ithere = 0;
-               return;
-       }
+    if (ithx == 1 && ithy == 1) {
+       idx = 1; idy = QUADSIZE;
+    }
+    else if (ithx == 1 && ithy == QUADSIZE) {
+       idx = QUADSIZE; idy = QUADSIZE;
+    }
+    else if (ithx == QUADSIZE && ithy == QUADSIZE) {
+       idx = QUADSIZE; idy = 1;
+    }
+    else if (ithx == QUADSIZE && ithy == 1) {
+       idx = 1; idy = 1;
+    }
+    else {
+       /* something is wrong! */
+       ithere = 0;
+       return;
+    }
 
-       /* Do nothing if we are blocked */
-       if (game.quad[idx][idy]!= IHDOT && game.quad[idx][idy]!= IHWEB) return;
-       game.quad[ithx][ithy] = IHWEB;
+    /* Do nothing if we are blocked */
+    if (game.quad[idx][idy]!= IHDOT && game.quad[idx][idy]!= IHWEB) return;
+    game.quad[ithx][ithy] = IHWEB;
 
-       if (ithx != idx) {
-               /* move in x axis */
-               im = fabs((double)idx - ithx)/((double)idx - ithx);
-               while (ithx != idx) {
-                       ithx += im;
-                       if (game.quad[ithx][ithy]==IHDOT) game.quad[ithx][ithy] = IHWEB;
-               }
+    if (ithx != idx) {
+       /* move in x axis */
+       im = fabs((double)idx - ithx)/((double)idx - ithx);
+       while (ithx != idx) {
+           ithx += im;
+           if (game.quad[ithx][ithy]==IHDOT) game.quad[ithx][ithy] = IHWEB;
        }
-       else if (ithy != idy) {
-               /* move in y axis */
-               im = fabs((double)idy - ithy)/((double)idy - ithy);
-               while (ithy != idy) {
-                       ithy += im;
-                       if (game.quad[ithx][ithy]==IHDOT) game.quad[ithx][ithy] = IHWEB;
-               }
+    }
+    else if (ithy != idy) {
+       /* move in y axis */
+       im = fabs((double)idy - ithy)/((double)idy - ithy);
+       while (ithy != idy) {
+           ithy += im;
+           if (game.quad[ithx][ithy]==IHDOT) game.quad[ithx][ithy] = IHWEB;
        }
-       game.quad[ithx][ithy] = IHT;
-        game.kx[nenhere]=ithx;
-        game.ky[nenhere]=ithy;
+    }
+    game.quad[ithx][ithy] = IHT;
+    game.kx[nenhere]=ithx;
+    game.ky[nenhere]=ithy;
 
-       /* check to see if all holes plugged */
-       for (i = 1; i < QUADSIZE+1; i++) {
-               if (game.quad[1][i]!=IHWEB && game.quad[1][i]!=IHT) return;
-               if (game.quad[QUADSIZE][i]!=IHWEB && game.quad[QUADSIZE][i]!=IHT) return;
-               if (game.quad[i][1]!=IHWEB && game.quad[i][1]!=IHT) return;
-               if (game.quad[i][QUADSIZE]!=IHWEB && game.quad[i][QUADSIZE]!=IHT) return;
-       }
-       /* All plugged up -- Tholian splits */
-       game.quad[ithx][ithy]=IHWEB;
-       dropin(IHBLANK, &dum, &my);
-       crmena(1,IHT, 2, ithx, ithy);
-       prout(" completes web.");
-       ithere = ithx = ithy = 0;
-       nenhere--;
-       return;
+    /* check to see if all holes plugged */
+    for (i = 1; i < QUADSIZE+1; i++) {
+       if (game.quad[1][i]!=IHWEB && game.quad[1][i]!=IHT) return;
+       if (game.quad[QUADSIZE][i]!=IHWEB && game.quad[QUADSIZE][i]!=IHT) return;
+       if (game.quad[i][1]!=IHWEB && game.quad[i][1]!=IHT) return;
+       if (game.quad[i][QUADSIZE]!=IHWEB && game.quad[i][QUADSIZE]!=IHT) return;
+    }
+    /* All plugged up -- Tholian splits */
+    game.quad[ithx][ithy]=IHWEB;
+    dropin(IHBLANK, &dum, &my);
+    crmena(1,IHT, 2, ithx, ithy);
+    prout(" completes web.");
+    ithere = ithx = ithy = 0;
+    nenhere--;
+    return;
 }
index 36a6cfa7a126273f4de9cd872c3dc5a56a94418c..f539c3fd375eee8ed583aa4b0395a7ee2f8b5d93 100644 (file)
--- a/battle.c
+++ b/battle.c
 #include <unistd.h>
 #include "sst.h"
 
-void doshield(int i) {
-       int key;
-       enum {NONE, SHUP, SHDN, NRG} action = NONE;
+void doshield(int i) 
+{
+    int key;
+    enum {NONE, SHUP, SHDN, NRG} action = NONE;
 
-       ididit = 0;
+    ididit = 0;
 
-       if (i == 2) action = SHUP;
-       else {
-               key = scan();
-               if (key == IHALPHA) {
-                       if (isit("transfer"))
-                               action = NRG;
-                       else {
-                               chew();
-                               if (game.damage[DSHIELD]) {
-                                       prout("Shields damaged and down.");
-                                       return;
-                               }
-                               if (isit("up"))
-                                       action = SHUP;
-                               else if (isit("down"))
-                                       action = SHDN;
-                       }
+    if (i == 2) action = SHUP;
+    else {
+       key = scan();
+       if (key == IHALPHA) {
+           if (isit("transfer"))
+               action = NRG;
+           else {
+               chew();
+               if (game.damage[DSHIELD]) {
+                   prout("Shields damaged and down.");
+                   return;
+               }
+               if (isit("up"))
+                   action = SHUP;
+               else if (isit("down"))
+                   action = SHDN;
+           }
+       }
+       if (action==NONE) {
+           proutn("Do you wish to change shield energy? ");
+           if (ja()) {
+               proutn("Energy to transfer to shields- ");
+               action = NRG;
+           }
+           else if (game.damage[DSHIELD]) {
+               prout("Shields damaged and down.");
+               return;
+           }
+           else if (shldup) {
+               proutn("Shields are up. Do you want them down? ");
+               if (ja()) action = SHDN;
+               else {
+                   chew();
+                   return;
                }
-               if (action==NONE) {
-                       proutn("Do you wish to change shield energy? ");
-                       if (ja()) {
-                               proutn("Energy to transfer to shields- ");
-                               action = NRG;
-                       }
-                       else if (game.damage[DSHIELD]) {
-                               prout("Shields damaged and down.");
-                               return;
-                       }
-                       else if (shldup) {
-                               proutn("Shields are up. Do you want them down? ");
-                               if (ja()) action = SHDN;
-                               else {
-                                       chew();
-                                       return;
-                               }
-                       }
-                       else {
-                               proutn("Shields are down. Do you want them up? ");
-                               if (ja()) action = SHUP;
-                               else {
-                                       chew();
-                                       return;
-                               }
-                       }
+           }
+           else {
+               proutn("Shields are down. Do you want them up? ");
+               if (ja()) action = SHUP;
+               else {
+                   chew();
+                   return;
                }
+           }
        }
-       switch (action) {
-               case SHUP: /* raise shields */
-                       if (shldup) {
-                               prout("Shields already up.");
-                               return;
-                       }
-                       shldup = 1;
-                       shldchg = 1;
-                       if (condit != IHDOCKED) energy -= 50.0;
-                       prout("Shields raised.");
-                       if (energy <= 0) {
-                               skip(1);
-                               prout("Shields raising uses up last of energy.");
-                               finish(FNRG);
-                               return;
-                       }
-                       ididit=1;
-                       return;
-               case SHDN:
-                       if (shldup==0) {
-                               prout("Shields already down.");
-                               return;
-                       }
-                       shldup=0;
-                       shldchg=1;
-                       prout("Shields lowered.");
-                       ididit=1;
-                       return;
-               case NRG:
-                       while (scan() != IHREAL) {
-                               chew();
-                               proutn("Energy to transfer to shields- ");
-                       }
-                       chew();
-                       if (aaitem==0) return;
-                       if (aaitem > energy) {
-                               prout("Insufficient ship energy.");
-                               return;
-                       }
-                       ididit = 1;
-                       if (shield+aaitem >= inshld) {
-                               prout("Shield energy maximized.");
-                               if (shield+aaitem > inshld) {
-                                       prout("Excess energy requested returned to ship energy");
-                               }
-                               energy -= inshld-shield;
-                               shield = inshld;
-                               return;
-                       }
-                       if (aaitem < 0.0 && energy-aaitem > inenrg) {
-                               /* Prevent shield drain loophole */
-                               skip(1);
-                               prout("Engineering to bridge--");
-                               prout("  Scott here. Power circuit problem, Captain.");
-                               prout("  I can't drain the shields.");
-                               ididit = 0;
-                               return;
-                       }
-                       if (shield+aaitem < 0) {
-                               prout("All shield energy transferred to ship.");
-                               energy += shield;
-                               shield = 0.0;
-                               return;
-                       }
-                       proutn("Scotty- \"");
-                       if (aaitem > 0)
-                               prout("Transferring energy to shields.\"");
-                       else
-                               prout("Draining energy from shields.\"");
-                       shield += aaitem;
-                       energy -= aaitem;
-                       return;
-               case NONE:;     /* avoid gcc warning */
+    }
+    switch (action) {
+    case SHUP: /* raise shields */
+       if (shldup) {
+           prout("Shields already up.");
+           return;
        }
-}
-
-void ram(int ibumpd, int ienm, int ix, int iy) {
-       double type = 1.0, extradm;
-       int icas, l;
-       
-       prouts("***RED ALERT!  RED ALERT!");
-       skip(1);
-       prout("***COLLISION IMMINENT.");
-       skip(2);
-       proutn("***");
-       crmshp();
-       switch (ienm) {
-               case IHR: type = 1.5; break;
-               case IHC: type = 2.0; break;
-               case IHS: type = 2.5; break;
-               case IHT: type = 0.5; break;
-                case IHQUEST: type = 4.0; break;
+       shldup = 1;
+       shldchg = 1;
+       if (condit != IHDOCKED) energy -= 50.0;
+       prout("Shields raised.");
+       if (energy <= 0) {
+           skip(1);
+           prout("Shields raising uses up last of energy.");
+           finish(FNRG);
+           return;
        }
-       proutn(ibumpd ? " rammed by " : " rams ");
-       crmena(0, ienm, 2, ix, iy);
-       if (ibumpd) proutn(" (original position)");
-       skip(1);
-       deadkl(ix, iy, ienm, sectx, secty);
-       proutn("***");
-       crmshp();
-       prout(" heavily damaged.");
-       icas = 10.0+20.0*Rand();
-       prout("***Sickbay reports %d casualties", icas);
-       casual += icas;
-       for (l=1; l <= NDEVICES; l++) {
-               if (l == DDRAY) continue; // Don't damage deathray 
-               if (game.damage[l] < 0) continue;
-               extradm = (10.0*type*Rand()+1.0)*damfac;
-               game.damage[l] += Time + extradm; /* Damage for at least time of travel! */
+       ididit=1;
+       return;
+    case SHDN:
+       if (shldup==0) {
+           prout("Shields already down.");
+           return;
+       }
+       shldup=0;
+       shldchg=1;
+       prout("Shields lowered.");
+       ididit=1;
+       return;
+    case NRG:
+       while (scan() != IHREAL) {
+           chew();
+           proutn("Energy to transfer to shields- ");
+       }
+       chew();
+       if (aaitem==0) return;
+       if (aaitem > energy) {
+           prout("Insufficient ship energy.");
+           return;
+       }
+       ididit = 1;
+       if (shield+aaitem >= inshld) {
+           prout("Shield energy maximized.");
+           if (shield+aaitem > inshld) {
+               prout("Excess energy requested returned to ship energy");
+           }
+           energy -= inshld-shield;
+           shield = inshld;
+           return;
+       }
+       if (aaitem < 0.0 && energy-aaitem > inenrg) {
+           /* Prevent shield drain loophole */
+           skip(1);
+           prout("Engineering to bridge--");
+           prout("  Scott here. Power circuit problem, Captain.");
+           prout("  I can't drain the shields.");
+           ididit = 0;
+           return;
        }
-       shldup = 0;
-       if (game.state.remkl) {
-               pause_game(2);
-               dreprt();
+       if (shield+aaitem < 0) {
+           prout("All shield energy transferred to ship.");
+           energy += shield;
+           shield = 0.0;
+           return;
        }
-       else finish(FWON);
+       proutn("Scotty- \"");
+       if (aaitem > 0)
+           prout("Transferring energy to shields.\"");
+       else
+           prout("Draining energy from shields.\"");
+       shield += aaitem;
+       energy -= aaitem;
        return;
+    case NONE:;        /* avoid gcc warning */
+    }
 }
 
-void torpedo(double course, double r, int inx, int iny, double *hit, int wait, int i, int n) {
-        int l, iquad=0, ix=0, iy=0, jx=0, jy=0, shoved=0, ll;
+void ram(int ibumpd, int ienm, int ix, int iy)
+{
+    double type = 1.0, extradm;
+    int icas, l;
        
-       double ac=course + 0.25*r;
-       double angle = (15.0-ac)*0.5235988;
-       double bullseye = (15.0 - course)*0.5235988;
-       double deltax=-sin(angle), deltay=cos(angle), x=inx, y=iny, bigger;
-       double ang, temp, xx, yy, kp, h1;
+    prouts("***RED ALERT!  RED ALERT!");
+    skip(1);
+    prout("***COLLISION IMMINENT.");
+    skip(2);
+    proutn("***");
+    crmshp();
+    switch (ienm) {
+    case IHR: type = 1.5; break;
+    case IHC: type = 2.0; break;
+    case IHS: type = 2.5; break;
+    case IHT: type = 0.5; break;
+    case IHQUEST: type = 4.0; break;
+    }
+    proutn(ibumpd ? " rammed by " : " rams ");
+    crmena(0, ienm, 2, ix, iy);
+    if (ibumpd) proutn(" (original position)");
+    skip(1);
+    deadkl(ix, iy, ienm, sectx, secty);
+    proutn("***");
+    crmshp();
+    prout(" heavily damaged.");
+    icas = 10.0+20.0*Rand();
+    prout("***Sickbay reports %d casualties", icas);
+    casual += icas;
+    for (l=1; l <= NDEVICES; l++) {
+       if (l == DDRAY) continue; // Don't damage deathray 
+       if (game.damage[l] < 0) continue;
+       extradm = (10.0*type*Rand()+1.0)*damfac;
+       game.damage[l] += Time + extradm; /* Damage for at least time of travel! */
+    }
+    shldup = 0;
+    if (game.state.remkl) {
+       pause_game(2);
+       dreprt();
+    }
+    else finish(FWON);
+    return;
+}
+
+void torpedo(double course, double r, int inx, int iny, double *hit, int wait, int i, int n) 
+{
+    int l, iquad=0, ix=0, iy=0, jx=0, jy=0, shoved=0, ll;
+       
+    double ac=course + 0.25*r;
+    double angle = (15.0-ac)*0.5235988;
+    double bullseye = (15.0 - course)*0.5235988;
+    double deltax=-sin(angle), deltay=cos(angle), x=inx, y=iny, bigger;
+    double ang, temp, xx, yy, kp, h1;
 
-       bigger = fabs(deltax);
-       if (fabs(deltay) > bigger) bigger = fabs(deltay);
-       deltax /= bigger;
-       deltay /= bigger;
-        if (game.damage[DSRSENS]==0 || condit==IHDOCKED) 
-           setwnd(srscan_window);
-       else 
-           setwnd(message_window);
-       /* Loop to move a single torpedo */
-       for (l=1; l <= 15; l++) {
-               x += deltax;
-               ix = x + 0.5;
-               if (ix < 1 || ix > QUADSIZE) break;
-               y += deltay;
-               iy = y + 0.5;
-               if (iy < 1 || iy > QUADSIZE) break;
-               iquad=game.quad[ix][iy];
-               tracktorpedo(x, y, ix, iy, wait, l, i, n, iquad);
-               wait = 1;
-               if (iquad==IHDOT) continue;
-               /* hit something */
-               setwnd(message_window);
-               skip(1);        /* start new line after text track */
-               switch(iquad) {
-                       case IHE: /* Hit our ship */
-                       case IHF:
-                               skip(1);
-                               proutn("Torpedo hits ");
-                               crmshp();
-                               prout(".");
-                               *hit = 700.0 + 100.0*Rand() -
-                                          1000.0*sqrt(square(ix-inx)+square(iy-iny))*
-                                          fabs(sin(bullseye-angle));
-                               *hit = fabs(*hit);
-                               newcnd(); /* we're blown out of dock */
-                               /* We may be displaced. */
-                               if (landed==1 || condit==IHDOCKED) return; /* Cheat if on a planet */
-                               ang = angle + 2.5*(Rand()-0.5);
-                               temp = fabs(sin(ang));
-                               if (fabs(cos(ang)) > temp) temp = fabs(cos(ang));
-                               xx = -sin(ang)/temp;
-                               yy = cos(ang)/temp;
-                               jx=ix+xx+0.5;
-                               jy=iy+yy+0.5;
-                               if (jx<1 || jx>QUADSIZE || jy<1 ||jy > QUADSIZE) return;
-                               if (game.quad[jx][jy]==IHBLANK) {
-                                       finish(FHOLE);
-                                       return;
-                               }
-                               if (game.quad[jx][jy]!=IHDOT) {
-                                       /* can't move into object */
-                                       return;
-                               }
-                               sectx = jx;
-                               secty = jy;
-                               crmshp();
-                               shoved = 1;
-                               break;
+    bigger = fabs(deltax);
+    if (fabs(deltay) > bigger) bigger = fabs(deltay);
+    deltax /= bigger;
+    deltay /= bigger;
+    if (game.damage[DSRSENS]==0 || condit==IHDOCKED) 
+       setwnd(srscan_window);
+    else 
+       setwnd(message_window);
+    /* Loop to move a single torpedo */
+    for (l=1; l <= 15; l++) {
+       x += deltax;
+       ix = x + 0.5;
+       if (ix < 1 || ix > QUADSIZE) break;
+       y += deltay;
+       iy = y + 0.5;
+       if (iy < 1 || iy > QUADSIZE) break;
+       iquad=game.quad[ix][iy];
+       tracktorpedo(x, y, ix, iy, wait, l, i, n, iquad);
+       wait = 1;
+       if (iquad==IHDOT) continue;
+       /* hit something */
+       setwnd(message_window);
+       skip(1);        /* start new line after text track */
+       switch(iquad) {
+       case IHE: /* Hit our ship */
+       case IHF:
+           skip(1);
+           proutn("Torpedo hits ");
+           crmshp();
+           prout(".");
+           *hit = 700.0 + 100.0*Rand() -
+               1000.0*sqrt(square(ix-inx)+square(iy-iny))*
+               fabs(sin(bullseye-angle));
+           *hit = fabs(*hit);
+           newcnd(); /* we're blown out of dock */
+           /* We may be displaced. */
+           if (landed==1 || condit==IHDOCKED) return; /* Cheat if on a planet */
+           ang = angle + 2.5*(Rand()-0.5);
+           temp = fabs(sin(ang));
+           if (fabs(cos(ang)) > temp) temp = fabs(cos(ang));
+           xx = -sin(ang)/temp;
+           yy = cos(ang)/temp;
+           jx=ix+xx+0.5;
+           jy=iy+yy+0.5;
+           if (jx<1 || jx>QUADSIZE || jy<1 ||jy > QUADSIZE) return;
+           if (game.quad[jx][jy]==IHBLANK) {
+               finish(FHOLE);
+               return;
+           }
+           if (game.quad[jx][jy]!=IHDOT) {
+               /* can't move into object */
+               return;
+           }
+           sectx = jx;
+           secty = jy;
+           crmshp();
+           shoved = 1;
+           break;
                                          
-                       case IHC: /* Hit a commander */
-                       case IHS:
-                               if (Rand() <= 0.05) {
-                                       crmena(1, iquad, 2, ix, iy);
-                                       prout(" uses anti-photon device;");
-                                       prout("   torpedo neutralized.");
-                                       return;
-                               }
-                       case IHR: /* Hit a regular enemy */
-                       case IHK:
-                               /* find the enemy */
-                               for (ll=1; ll <= nenhere; ll++)
-                                       if (ix==game.kx[ll] && iy==game.ky[ll]) break;
-                               kp = fabs(game.kpower[ll]);
-                               h1 = 700.0 + 100.0*Rand() -
-                                        1000.0*sqrt(square(ix-inx)+square(iy-iny))*
-                                        fabs(sin(bullseye-angle));
-                               h1 = fabs(h1);
-                               if (kp < h1) h1 = kp;
-                               game.kpower[ll] -= (game.kpower[ll]<0 ? -h1 : h1);
-                               if (game.kpower[ll] == 0) {
-                                       deadkl(ix, iy, iquad, ix, iy);
-                                       return;
-                               }
-                               crmena(1, iquad, 2, ix, iy);
-                               /* If enemy damaged but not destroyed, try to displace */
-                               ang = angle + 2.5*(Rand()-0.5);
-                               temp = fabs(sin(ang));
-                               if (fabs(cos(ang)) > temp) temp = fabs(cos(ang));
-                               xx = -sin(ang)/temp;
-                               yy = cos(ang)/temp;
-                               jx=ix+xx+0.5;
-                               jy=iy+yy+0.5;
-                               if (jx<1 || jx>QUADSIZE || jy<1 ||jy > QUADSIZE) {
-                                       prout(" damaged but not destroyed.");
-                                       return;
-                               }
-                               if (game.quad[jx][jy]==IHBLANK) {
-                                       prout(" buffeted into black hole.");
-                                       deadkl(ix, iy, iquad, jx, jy);
-                                       return;
-                               }
-                               if (game.quad[jx][jy]!=IHDOT) {
-                                       /* can't move into object */
-                                       prout(" damaged but not destroyed.");
-                                       return;
-                               }
-                               proutn(" damaged--");
-                               game.kx[ll] = jx;
-                               game.ky[ll] = jy;
-                               shoved = 1;
-                               break;
-                       case IHB: /* Hit a base */
-                               skip(1);
-                               prout("***STARBASE DESTROYED..");
-                               if (game.starch[quadx][quady] < 0) game.starch[quadx][quady] = 0;
-                               for (ll=1; ll<=game.state.rembase; ll++) {
-                                       if (game.state.baseqx[ll]==quadx && game.state.baseqy[ll]==quady) {
-                                               game.state.baseqx[ll]=game.state.baseqx[game.state.rembase];
-                                               game.state.baseqy[ll]=game.state.baseqy[game.state.rembase];
-                                               break;
-                                       }
-                               }
-                               game.quad[ix][iy]=IHDOT;
-                               game.state.rembase--;
-                               basex=basey=0;
-                               game.state.galaxy[quadx][quady] -= BASE_PLACE;
-                               game.state.basekl++;
-                               newcnd();
-                               return;
-                       case IHP: /* Hit a planet */
-                               crmena(1, iquad, 2, ix, iy);
-                               prout(" destroyed.");
-                               game.state.nplankl++;
-                               game.state.newstuf[quadx][quady] -= 1;
-                               DESTROY(&game.state.plnets[iplnet]);
-                               iplnet = 0;
-                               plnetx = plnety = 0;
-                               game.quad[ix][iy] = IHDOT;
-                               if (landed==1) {
-                                       /* captain perishes on planet */
-                                       finish(FDPLANET);
-                               }
-                               return;
-                       case IHSTAR: /* Hit a star */
-                               if (Rand() > 0.10) {
-                                       nova(ix, iy);
-                                       return;
-                               }
-                               crmena(1, IHSTAR, 2, ix, iy);
-                               prout(" unaffected by photon blast.");
-                               return;
-                       case IHQUEST: /* Hit a thingy */
-                            if (Rand()>0.7) {  // Used to be certain death 
-                               skip(1);
-                               prouts("AAAAIIIIEEEEEEEEAAAAAAAAUUUUUGGGGGHHHHHHHHHHHH!!!");
-                               skip(1);
-                               prouts("    HACK!     HACK!    HACK!        *CHOKE!*  ");
-                               skip(1);
-                               proutn("Mr. Spock-");
-                               prouts("  \"Fascinating!\"");
-                               skip(1);
-                                deadkl(ix, iy, iquad, ix, iy);
-                            } else {
-                               /*
-                                * Stas Sergeev added the possibility that
-                                * you can shove the Thingy.
-                                */
-                                iqengry=1;
-                                shoved=1;
-                            }
-                           return;
-                       case IHBLANK: /* Black hole */
-                               skip(1);
-                               crmena(1, IHBLANK, 2, ix, iy);
-                               prout(" swallows torpedo.");
-                               return;
-                       case IHWEB: /* hit the web */
-                               skip(1);
-                               prout("***Torpedo absorbed by Tholian web.");
-                               return;
-                       case IHT:  /* Hit a Tholian */
-                               h1 = 700.0 + 100.0*Rand() -
-                                        1000.0*sqrt(square(ix-inx)+square(iy-iny))*
-                                        fabs(sin(bullseye-angle));
-                               h1 = fabs(h1);
-                               if (h1 >= 600) {
-                                       game.quad[ix][iy] = IHDOT;
-                                       ithere = 0;
-                                       ithx = ithy = 0;
-                                        deadkl(ix, iy, iquad, ix, iy);
-                                       return;
-                               }
-                               skip(1);
-                               crmena(1, IHT, 2, ix, iy);
-                               if (Rand() > 0.05) {
-                                       prout(" survives photon blast.");
-                                       return;
-                               }
-                               prout(" disappears.");
-                               game.quad[ix][iy] = IHWEB;
-                               ithere = ithx = ithy = 0;
-                               nenhere--;
-                               {
-                                       int dum, my;
-                                       dropin(IHBLANK, &dum, &my);
-                               }
-                               return;
-                                       
-                       default: /* Problem! */
-                               skip(1);
-                               proutn("Don't know how to handle collision with ");
-                               crmena(1, iquad, 2, ix, iy);
-                               skip(1);
-                               return;
+       case IHC: /* Hit a commander */
+       case IHS:
+           if (Rand() <= 0.05) {
+               crmena(1, iquad, 2, ix, iy);
+               prout(" uses anti-photon device;");
+               prout("   torpedo neutralized.");
+               return;
+           }
+       case IHR: /* Hit a regular enemy */
+       case IHK:
+           /* find the enemy */
+           for (ll=1; ll <= nenhere; ll++)
+               if (ix==game.kx[ll] && iy==game.ky[ll]) break;
+           kp = fabs(game.kpower[ll]);
+           h1 = 700.0 + 100.0*Rand() -
+               1000.0*sqrt(square(ix-inx)+square(iy-iny))*
+               fabs(sin(bullseye-angle));
+           h1 = fabs(h1);
+           if (kp < h1) h1 = kp;
+           game.kpower[ll] -= (game.kpower[ll]<0 ? -h1 : h1);
+           if (game.kpower[ll] == 0) {
+               deadkl(ix, iy, iquad, ix, iy);
+               return;
+           }
+           crmena(1, iquad, 2, ix, iy);
+           /* If enemy damaged but not destroyed, try to displace */
+           ang = angle + 2.5*(Rand()-0.5);
+           temp = fabs(sin(ang));
+           if (fabs(cos(ang)) > temp) temp = fabs(cos(ang));
+           xx = -sin(ang)/temp;
+           yy = cos(ang)/temp;
+           jx=ix+xx+0.5;
+           jy=iy+yy+0.5;
+           if (jx<1 || jx>QUADSIZE || jy<1 ||jy > QUADSIZE) {
+               prout(" damaged but not destroyed.");
+               return;
+           }
+           if (game.quad[jx][jy]==IHBLANK) {
+               prout(" buffeted into black hole.");
+               deadkl(ix, iy, iquad, jx, jy);
+               return;
+           }
+           if (game.quad[jx][jy]!=IHDOT) {
+               /* can't move into object */
+               prout(" damaged but not destroyed.");
+               return;
+           }
+           proutn(" damaged--");
+           game.kx[ll] = jx;
+           game.ky[ll] = jy;
+           shoved = 1;
+           break;
+       case IHB: /* Hit a base */
+           skip(1);
+           prout("***STARBASE DESTROYED..");
+           if (game.starch[quadx][quady] < 0) game.starch[quadx][quady] = 0;
+           for (ll=1; ll<=game.state.rembase; ll++) {
+               if (game.state.baseqx[ll]==quadx && game.state.baseqy[ll]==quady) {
+                   game.state.baseqx[ll]=game.state.baseqx[game.state.rembase];
+                   game.state.baseqy[ll]=game.state.baseqy[game.state.rembase];
+                   break;
                }
-               break;
-       }
-        if(curwnd!=message_window) {
-           setwnd(message_window);
-       }
-       if (shoved) {
-               game.quad[jx][jy]=iquad;
-               game.quad[ix][iy]=IHDOT;
-               prout(" displaced by blast to %s ", cramlc(sector, jx, jy));
-               for (ll=1; ll<=nenhere; ll++)
-                       game.kdist[ll] = game.kavgd[ll] = sqrt(square(sectx-game.kx[ll])+square(secty-game.ky[ll]));
-               sortkl();
+           }
+           game.quad[ix][iy]=IHDOT;
+           game.state.rembase--;
+           basex=basey=0;
+           game.state.galaxy[quadx][quady] -= BASE_PLACE;
+           game.state.basekl++;
+           newcnd();
+           return;
+       case IHP: /* Hit a planet */
+           crmena(1, iquad, 2, ix, iy);
+           prout(" destroyed.");
+           game.state.nplankl++;
+           game.state.newstuf[quadx][quady] -= 1;
+           DESTROY(&game.state.plnets[iplnet]);
+           iplnet = 0;
+           plnetx = plnety = 0;
+           game.quad[ix][iy] = IHDOT;
+           if (landed==1) {
+               /* captain perishes on planet */
+               finish(FDPLANET);
+           }
+           return;
+       case IHSTAR: /* Hit a star */
+           if (Rand() > 0.10) {
+               nova(ix, iy);
                return;
+           }
+           crmena(1, IHSTAR, 2, ix, iy);
+           prout(" unaffected by photon blast.");
+           return;
+       case IHQUEST: /* Hit a thingy */
+           if (Rand()>0.7) {   // Used to be certain death 
+               skip(1);
+               prouts("AAAAIIIIEEEEEEEEAAAAAAAAUUUUUGGGGGHHHHHHHHHHHH!!!");
+               skip(1);
+               prouts("    HACK!     HACK!    HACK!        *CHOKE!*  ");
+               skip(1);
+               proutn("Mr. Spock-");
+               prouts("  \"Fascinating!\"");
+               skip(1);
+               deadkl(ix, iy, iquad, ix, iy);
+           } else {
+               /*
+                * Stas Sergeev added the possibility that
+                * you can shove the Thingy.
+                */
+               iqengry=1;
+               shoved=1;
+           }
+           return;
+       case IHBLANK: /* Black hole */
+           skip(1);
+           crmena(1, IHBLANK, 2, ix, iy);
+           prout(" swallows torpedo.");
+           return;
+       case IHWEB: /* hit the web */
+           skip(1);
+           prout("***Torpedo absorbed by Tholian web.");
+           return;
+       case IHT:  /* Hit a Tholian */
+           h1 = 700.0 + 100.0*Rand() -
+               1000.0*sqrt(square(ix-inx)+square(iy-iny))*
+               fabs(sin(bullseye-angle));
+           h1 = fabs(h1);
+           if (h1 >= 600) {
+               game.quad[ix][iy] = IHDOT;
+               ithere = 0;
+               ithx = ithy = 0;
+               deadkl(ix, iy, iquad, ix, iy);
+               return;
+           }
+           skip(1);
+           crmena(1, IHT, 2, ix, iy);
+           if (Rand() > 0.05) {
+               prout(" survives photon blast.");
+               return;
+           }
+           prout(" disappears.");
+           game.quad[ix][iy] = IHWEB;
+           ithere = ithx = ithy = 0;
+           nenhere--;
+           {
+               int dum, my;
+               dropin(IHBLANK, &dum, &my);
+           }
+           return;
+                                       
+       default: /* Problem! */
+           skip(1);
+           proutn("Don't know how to handle collision with ");
+           crmena(1, iquad, 2, ix, iy);
+           skip(1);
+           return;
        }
-       skip(1);
-       prout("Torpedo missed.");
+       break;
+    }
+    if(curwnd!=message_window) {
+       setwnd(message_window);
+    }
+    if (shoved) {
+       game.quad[jx][jy]=iquad;
+       game.quad[ix][iy]=IHDOT;
+       prout(" displaced by blast to %s ", cramlc(sector, jx, jy));
+       for (ll=1; ll<=nenhere; ll++)
+           game.kdist[ll] = game.kavgd[ll] = sqrt(square(sectx-game.kx[ll])+square(secty-game.ky[ll]));
+       sortkl();
        return;
+    }
+    skip(1);
+    prout("Torpedo missed.");
+    return;
 }
 
-static void fry(double hit) {
-       double ncrit, extradm;
-       int ktr=1, l, ll, j, cdam[NDEVICES+1];
+static void fry(double hit) 
+{
+    double ncrit, extradm;
+    int ktr=1, l, ll, j, cdam[NDEVICES+1];
 
-       /* a critical hit occured */
-       if (hit < (275.0-25.0*skill)*(1.0+0.5*Rand())) return;
+    /* a critical hit occured */
+    if (hit < (275.0-25.0*skill)*(1.0+0.5*Rand())) return;
 
-       ncrit = 1.0 + hit/(500.0+100.0*Rand());
-       proutn("***CRITICAL HIT--");
-       /* Select devices and cause damage */
-       for (l = 1; l <= ncrit && l <= NDEVICES; l++) {
-               do {
-                       j = NDEVICES*Rand()+1.0;
-                       /* Cheat to prevent shuttle damage unless on ship */
-               } while (game.damage[j] < 0.0 || (j == DSHUTTL && iscraft != 1) ||
-                                j == DDRAY);
-               cdam[l] = j;
-               extradm = (hit*damfac)/(ncrit*(75.0+25.0*Rand()));
-               game.damage[j] += extradm;
-               if (l > 1) {
-                       for (ll=2; ll<=l && j != cdam[ll-1]; ll++) ;
-                       if (ll<=l) continue;
-                       ktr += 1;
-                       if (ktr==3) skip(1);
-                       proutn(" and ");
-               }
-               proutn(device[j]);
-       }
-       prout(" damaged.");
-       if (game.damage[DSHIELD] && shldup) {
-               prout("***Shields knocked down.");
-               shldup=0;
+    ncrit = 1.0 + hit/(500.0+100.0*Rand());
+    proutn("***CRITICAL HIT--");
+    /* Select devices and cause damage */
+    for (l = 1; l <= ncrit && l <= NDEVICES; l++) {
+       do {
+           j = NDEVICES*Rand()+1.0;
+           /* Cheat to prevent shuttle damage unless on ship */
+       } while (game.damage[j] < 0.0 || (j == DSHUTTL && iscraft != 1) ||
+                j == DDRAY);
+       cdam[l] = j;
+       extradm = (hit*damfac)/(ncrit*(75.0+25.0*Rand()));
+       game.damage[j] += extradm;
+       if (l > 1) {
+           for (ll=2; ll<=l && j != cdam[ll-1]; ll++) ;
+           if (ll<=l) continue;
+           ktr += 1;
+           if (ktr==3) skip(1);
+           proutn(" and ");
        }
+       proutn(device[j]);
+    }
+    prout(" damaged.");
+    if (game.damage[DSHIELD] && shldup) {
+       prout("***Shields knocked down.");
+       shldup=0;
+    }
 }
 
-void attack(int k) {
-       /* k == 0 forces use of phasers in an attack */
-       int percent, ihurt=0, l, i=0, jx, jy, iquad, itflag;
-       int atackd = 0, attempt = 0;
-       double hit;
-       double pfac, dustfac, hitmax=0.0, hittot=0.0, chgfac=1.0, r;
+void attack(int torps_ok) 
+{
+    /* torps_ok == 0 forces use of phasers in an attack */
+    int percent, ihurt=0, l, i=0, jx, jy, iquad, itflag;
+    int atackd = 0, attempt = 0;
+    double hit;
+    double pfac, dustfac, hitmax=0.0, hittot=0.0, chgfac=1.0, r;
 
-       iattak = 1;
-       if (alldone) return;
+    iattak = 1;
+    if (alldone) return;
 #ifdef DEBUG
-       if (idebug) prout("ATTACK!");
+    if (idebug) prout("ATTACK!");
 #endif
 
-       if (ithere) movetho();
+    if (ithere) movetho();
 
-       if (neutz) { /* The one chance not to be attacked */
-               neutz = 0;
-               return;
-       }
-       if ((((comhere || ishere) && (justin == 0)) || skill == 5)&&(k!=0)) movcom();
-       if (nenhere==0 || (nenhere==1 && iqhere && iqengry==0)) return;
-       pfac = 1.0/inshld;
-       if (shldchg == 1) chgfac = 0.25+0.5*Rand();
-       skip(1);
-       if (skill <= 2) i = 2;
-       for (l=1; l <= nenhere; l++) {
-               if (game.kpower[l] < 0) continue;       /* too weak to attack */
-               /* compute hit strength and diminsh shield power */
-               r = Rand();
-               /* Increase chance of photon torpedos if docked or enemy energy low */
-               if (condit == IHDOCKED) r *= 0.25;
-               if (game.kpower[l] < 500) r *= 0.25; 
-               jx = game.kx[l];
-               jy = game.ky[l];
-               iquad = game.quad[jx][jy];
-                if (iquad==IHT || (iquad==IHQUEST && !iqengry)) continue;
-               itflag = (iquad == IHK && r > 0.0005) || k == 0 ||
-                       (iquad==IHC && r > 0.015) ||
-                       (iquad==IHR && r > 0.3) ||
-                        (iquad==IHS && r > 0.07) ||
-                        (iquad==IHQUEST && r > 0.05);
-               if (itflag) {
-                       /* Enemy uses phasers */
-                       if (condit == IHDOCKED) continue; /* Don't waste the effort! */
-                       attempt = 1; /* Attempt to attack */
-                       dustfac = 0.8+0.05*Rand();
-                       hit = game.kpower[l]*pow(dustfac,game.kavgd[l]);
-                       game.kpower[l] *= 0.75;
-               }
-               else { /* Enemy used photon torpedo */
-                       double course = 1.90985*atan2((double)secty-jy, (double)jx-sectx);
-                       hit = 0;
-                       proutn("***TORPEDO INCOMING");
-                       if (game.damage[DSRSENS] <= 0.0) {
-                               proutn(" From ");
-                               crmena(0, iquad, i, jx, jy);
-                       }
-                       attempt = 1;
-                       prout("  ");
-                       r = (Rand()+Rand())*0.5 -0.5;
-                       r += 0.002*game.kpower[l]*r;
-                       torpedo(course, r, jx, jy, &hit, 0, 1, 1);
-                       if (game.state.remkl==0) finish(FWON); /* Klingons did themselves in! */
-                       if (game.state.galaxy[quadx][quady] == SUPERNOVA_PLACE ||
-                               alldone) return; /* Supernova or finished */
-                       if (hit == 0) continue;
-               }
-                if (shldup != 0 || shldchg != 0 || condit==IHDOCKED) {
-                       /* shields will take hits */
-                        double absorb, hitsh, propor = pfac*shield*(condit==IHDOCKED ? 2.1 : 1.0);
-                       if(propor < 0.1) propor = 0.1;
-                       hitsh = propor*chgfac*hit+1.0;
-                       atackd=1;
-                       absorb = 0.8*hitsh;
-                       if (absorb > shield) absorb = shield;
-                       shield -= absorb;
-                       hit -= hitsh;
-                        if (condit==IHDOCKED) dock(0);
-                       if (propor > 0.1 && hit < 0.005*energy) continue;
-               }
-               /* It's a hit -- print out hit size */
-               atackd = 1; /* We weren't going to check casualties, etc. if
-                              shields were down for some strange reason. This
-                                          doesn't make any sense, so I've fixed it */
-               ihurt = 1;
-               proutn("%d unit hit", (int)hit);
-               if ((game.damage[DSRSENS] > 0 && itflag) || skill <= 2) {
-                       proutn(" on the ");
-                       crmshp();
-               }
-               if (game.damage[DSRSENS] <= 0.0 && itflag) {
-                       proutn(" from ");
-                       crmena(0, iquad, i, jx, jy);
-               }
-               skip(1);
-               /* Decide if hit is critical */
-               if (hit > hitmax) hitmax = hit;
-               hittot += hit;
-               fry(hit);
-               prout("Hit %g energy %g", hit, energy);
-               energy -= hit;
-                if (condit==IHDOCKED) dock(0);
+    if (neutz) { /* The one chance not to be attacked */
+       neutz = 0;
+       return;
+    }
+    if ((((comhere || ishere) && (justin == 0)) || skill == SKILL_EMERITUS)&&(torps_ok!=0)) movcom();
+    if (nenhere==0 || (nenhere==1 && iqhere && iqengry==0)) return;
+    pfac = 1.0/inshld;
+    if (shldchg == 1) chgfac = 0.25+0.5*Rand();
+    skip(1);
+    if (skill <= SKILL_FAIR) i = 2;
+    for (l=1; l <= nenhere; l++) {
+       if (game.kpower[l] < 0) continue;       /* too weak to attack */
+       /* compute hit strength and diminsh shield power */
+       r = Rand();
+       /* Increase chance of photon torpedos if docked or enemy energy low */
+       if (condit == IHDOCKED) r *= 0.25;
+       if (game.kpower[l] < 500) r *= 0.25; 
+       jx = game.kx[l];
+       jy = game.ky[l];
+       iquad = game.quad[jx][jy];
+       if (iquad==IHT || (iquad==IHQUEST && !iqengry)) continue;
+       itflag = (iquad == IHK && r > 0.0005) || !torps_ok ||
+           (iquad==IHC && r > 0.015) ||
+           (iquad==IHR && r > 0.3) ||
+           (iquad==IHS && r > 0.07) ||
+           (iquad==IHQUEST && r > 0.05);
+       if (itflag) {
+           /* Enemy uses phasers */
+           if (condit == IHDOCKED) continue; /* Don't waste the effort! */
+           attempt = 1; /* Attempt to attack */
+           dustfac = 0.8+0.05*Rand();
+           hit = game.kpower[l]*pow(dustfac,game.kavgd[l]);
+           game.kpower[l] *= 0.75;
        }
-       if (energy <= 0) {
-               /* Returning home upon your shield, not with it... */
-               finish(FBATTLE);
-               return;
+       else { /* Enemy used photon torpedo */
+           double course = 1.90985*atan2((double)secty-jy, (double)jx-sectx);
+           hit = 0;
+           proutn("***TORPEDO INCOMING");
+           if (game.damage[DSRSENS] <= 0.0) {
+               proutn(" From ");
+               crmena(0, iquad, i, jx, jy);
+           }
+           attempt = 1;
+           prout("  ");
+           r = (Rand()+Rand())*0.5 -0.5;
+           r += 0.002*game.kpower[l]*r;
+           torpedo(course, r, jx, jy, &hit, 0, 1, 1);
+           if (game.state.remkl==0) finish(FWON); /* Klingons did themselves in! */
+           if (game.state.galaxy[quadx][quady] == SUPERNOVA_PLACE ||
+               alldone) return; /* Supernova or finished */
+           if (hit == 0) continue;
        }
-       if (attempt == 0 && condit == IHDOCKED)
-               prout("***Enemies decide against attacking your ship.");
-       if (atackd == 0) return;
-       percent = 100.0*pfac*shield+0.5;
-       if (ihurt==0) {
-               /* Shields fully protect ship */
-               proutn("Enemy attack reduces shield strength to ");
+       if (shldup != 0 || shldchg != 0 || condit==IHDOCKED) {
+           /* shields will take hits */
+           double absorb, hitsh, propor = pfac*shield*(condit==IHDOCKED ? 2.1 : 1.0);
+           if(propor < 0.1) propor = 0.1;
+           hitsh = propor*chgfac*hit+1.0;
+           atackd=1;
+           absorb = 0.8*hitsh;
+           if (absorb > shield) absorb = shield;
+           shield -= absorb;
+           hit -= hitsh;
+           if (condit==IHDOCKED) dock(0);
+           if (propor > 0.1 && hit < 0.005*energy) continue;
        }
-       else {
-               /* Print message if starship suffered hit(s) */
-               skip(1);
-               proutn("Energy left %2d    shields ", (int)energy);
-               if (shldup) proutn("up ");
-               else if (game.damage[DSHIELD] == 0) proutn("down ");
-               else proutn("damaged, ");
+       /* It's a hit -- print out hit size */
+       atackd = 1; /* We weren't going to check casualties, etc. if
+                      shields were down for some strange reason. This
+                      doesn't make any sense, so I've fixed it */
+       ihurt = 1;
+       proutn("%d unit hit", (int)hit);
+       if ((game.damage[DSRSENS] > 0 && itflag) || skill<=SKILL_FAIR) {
+           proutn(" on the ");
+           crmshp();
        }
-       prout("%d%%,   torpedoes left %d", percent, torps);
-       /* Check if anyone was hurt */
-       if (hitmax >= 200 || hittot >= 500) {
-               int icas= hittot*Rand()*0.015;
-               if (icas >= 2) {
-                       skip(1);
-                       prout("Mc Coy-  \"Sickbay to bridge.  We suffered %d casualties", icas);
-                       prout("   in that last attack.\"");
-                       casual += icas;
-               }
+       if (game.damage[DSRSENS] <= 0.0 && itflag) {
+           proutn(" from ");
+           crmena(0, iquad, i, jx, jy);
        }
-       /* After attack, reset average distance to enemies */
-       for (l = 1; l <= nenhere; l++)
-               game.kavgd[l] = game.kdist[l];
-       sortkl();
+       skip(1);
+       /* Decide if hit is critical */
+       if (hit > hitmax) hitmax = hit;
+       hittot += hit;
+       fry(hit);
+       prout("Hit %g energy %g", hit, energy);
+       energy -= hit;
+       if (condit==IHDOCKED) 
+           dock(0);
+    }
+    if (energy <= 0) {
+       /* Returning home upon your shield, not with it... */
+       finish(FBATTLE);
        return;
+    }
+    if (attempt == 0 && condit == IHDOCKED)
+       prout("***Enemies decide against attacking your ship.");
+    if (atackd == 0) return;
+    percent = 100.0*pfac*shield+0.5;
+    if (ihurt==0) {
+       /* Shields fully protect ship */
+       proutn("Enemy attack reduces shield strength to ");
+    }
+    else {
+       /* Print message if starship suffered hit(s) */
+       skip(1);
+       proutn("Energy left %2d    shields ", (int)energy);
+       if (shldup) proutn("up ");
+       else if (game.damage[DSHIELD] == 0) proutn("down ");
+       else proutn("damaged, ");
+    }
+    prout("%d%%,   torpedoes left %d", percent, torps);
+    /* Check if anyone was hurt */
+    if (hitmax >= 200 || hittot >= 500) {
+       int icas= hittot*Rand()*0.015;
+       if (icas >= 2) {
+           skip(1);
+           prout("Mc Coy-  \"Sickbay to bridge.  We suffered %d casualties", icas);
+           prout("   in that last attack.\"");
+           casual += icas;
+       }
+    }
+    /* After attack, reset average distance to enemies */
+    for (l = 1; l <= nenhere; l++)
+       game.kavgd[l] = game.kdist[l];
+    sortkl();
+    return;
 }
                
-void deadkl(int ix, int iy, int type, int ixx, int iyy) {
-       /* Added ixx and iyy allow enemy to "move" before dying */
+void deadkl(int ix, int iy, int type, int ixx, int iyy) 
+{
+    /* Added ixx and iyy allow enemy to "move" before dying */
 
-       int i,j;
+    int i,j;
 
-        skip(1);
-       crmena(1, type, 2, ixx, iyy);
-       /* Decide what kind of enemy it is and update approriately */
-       if (type == IHR) {
-               /* chalk up a Romulan */
-               game.state.newstuf[quadx][quady] -= ROMULAN_PLACE;
-               irhere--;
-               game.state.nromkl++;
-               game.state.nromrem--;
-       }
-       else if (type == IHT) {
-               /* Killed a Tholian */
-               ithere = 0;
-       }
-        else if (type == IHQUEST) {
-               /* Killed a Thingy */
-             iqhere=iqengry=thingx=thingy=0;
-        }
-       else {
-               /* Some type of a Klingon */
-               game.state.galaxy[quadx][quady] -= 100;
-               klhere--;
-               game.state.remkl--;
-               switch (type) {
-                       case IHC:
-                               comhere = 0;
-                               for (i=1; i<=game.state.remcom; i++)
-                                       if (game.state.cx[i]==quadx && game.state.cy[i]==quady) break;
-                               game.state.cx[i] = game.state.cx[game.state.remcom];
-                               game.state.cy[i] = game.state.cy[game.state.remcom];
-                               game.state.cx[game.state.remcom] = 0;
-                               game.state.cy[game.state.remcom] = 0;
-                               game.state.remcom--;
-                               game.future[FTBEAM] = 1e30;
-                               if (game.state.remcom != 0)
-                                       game.future[FTBEAM] = game.state.date + expran(1.0*incom/game.state.remcom);
-                               game.state.killc++;
-                               break;
-                       case IHK:
-                               game.state.killk++;
-                               break;
-                       case IHS:
-                               game.state.nscrem = ishere = game.state.isx = game.state.isy = isatb = iscate = 0;
-                               game.state.nsckill = 1;
-                               game.future[FSCMOVE] = game.future[FSCDBAS] = 1e30;
-                               break;
-               }
+    skip(1);
+    crmena(1, type, 2, ixx, iyy);
+    /* Decide what kind of enemy it is and update approriately */
+    if (type == IHR) {
+       /* chalk up a Romulan */
+       game.state.newstuf[quadx][quady] -= ROMULAN_PLACE;
+       irhere--;
+       game.state.nromkl++;
+       game.state.nromrem--;
+    }
+    else if (type == IHT) {
+       /* Killed a Tholian */
+       ithere = 0;
+    }
+    else if (type == IHQUEST) {
+       /* Killed a Thingy */
+       iqhere=iqengry=thingx=thingy=0;
+    }
+    else {
+       /* Some type of a Klingon */
+       game.state.galaxy[quadx][quady] -= KLINGON_PLACE;
+       klhere--;
+       game.state.remkl--;
+       switch (type) {
+       case IHC:
+           comhere = 0;
+           for (i=1; i<=game.state.remcom; i++)
+               if (game.state.cx[i]==quadx && game.state.cy[i]==quady) break;
+           game.state.cx[i] = game.state.cx[game.state.remcom];
+           game.state.cy[i] = game.state.cy[game.state.remcom];
+           game.state.cx[game.state.remcom] = 0;
+           game.state.cy[game.state.remcom] = 0;
+           game.state.remcom--;
+           game.future[FTBEAM] = 1e30;
+           if (game.state.remcom != 0)
+               game.future[FTBEAM] = game.state.date + expran(1.0*incom/game.state.remcom);
+           game.state.killc++;
+           break;
+       case IHK:
+           game.state.killk++;
+           break;
+       case IHS:
+           game.state.nscrem = ishere = game.state.isx = game.state.isy = isatb = iscate = 0;
+           game.state.nsckill = 1;
+           game.future[FSCMOVE] = game.future[FSCDBAS] = 1e30;
+           break;
        }
+    }
 
-       /* For each kind of enemy, finish message to player */
-       prout(" destroyed.");
-       game.quad[ix][iy] = IHDOT;
-       if (game.state.remkl==0) return;
+    /* For each kind of enemy, finish message to player */
+    prout(" destroyed.");
+    game.quad[ix][iy] = IHDOT;
+    if (game.state.remkl==0) return;
 
-       game.state.remtime = game.state.remres/(game.state.remkl + 4*game.state.remcom);
+    game.state.remtime = game.state.remres/(game.state.remkl + 4*game.state.remcom);
 
-       /* Remove enemy ship from arrays describing local conditions */
-        if (game.future[FCDBAS] < 1e30 && batx==quadx && baty==quady && type==IHC)
-           game.future[FCDBAS] = 1e30;
-       for (i=1; i<=nenhere; i++)
-               if (game.kx[i]==ix && game.ky[i]==iy) break;
-       nenhere--;
-       if (i <= nenhere)  {
-               for (j=i; j<=nenhere; j++) {
-                       game.kx[j] = game.kx[j+1];
-                       game.ky[j] = game.ky[j+1];
-                       game.kpower[j] = game.kpower[j+1];
-                       game.kavgd[j] = game.kdist[j] = game.kdist[j+1];
-               }
+    /* Remove enemy ship from arrays describing local conditions */
+    if (game.future[FCDBAS] < 1e30 && batx==quadx && baty==quady && type==IHC)
+       game.future[FCDBAS] = 1e30;
+    for (i=1; i<=nenhere; i++)
+       if (game.kx[i]==ix && game.ky[i]==iy) break;
+    nenhere--;
+    if (i <= nenhere)  {
+       for (j=i; j<=nenhere; j++) {
+           game.kx[j] = game.kx[j+1];
+           game.ky[j] = game.ky[j+1];
+           game.kpower[j] = game.kpower[j+1];
+           game.kavgd[j] = game.kdist[j] = game.kdist[j+1];
        }
-       game.kx[nenhere+1] = 0;
-       game.ky[nenhere+1] = 0;
-       game.kdist[nenhere+1] = 0;
-       game.kavgd[nenhere+1] = 0;
-       game.kpower[nenhere+1] = 0;
-       return;
+    }
+    game.kx[nenhere+1] = 0;
+    game.ky[nenhere+1] = 0;
+    game.kdist[nenhere+1] = 0;
+    game.kavgd[nenhere+1] = 0;
+    game.kpower[nenhere+1] = 0;
+    return;
 }
 
-static int targetcheck(double x, double y, double *course) {
-       double deltx, delty;
-       /* Return TRUE if target is invalid */
-       if (x < 1.0 || x > QUADSIZE || y < 1.0 || y > QUADSIZE) {
-               huh();
-               return 1;
-       }
-       deltx = 0.1*(y - secty);
-       delty = 0.1*(sectx - x);
-       if (deltx==0 && delty== 0) {
-               skip(1);
-               prout("Spock-  \"Bridge to sickbay.  Dr. McCoy,");
-               prout("  I recommend an immediate review of");
-               prout("  the Captain's psychological profile.\"");
-               chew();
-               return 1;
-       }
-       *course = 1.90985932*atan2(deltx, delty);
-       return 0;
+static int targetcheck(double x, double y, double *course) 
+{
+    double deltx, delty;
+    /* Return TRUE if target is invalid */
+    if (x < 1.0 || x > QUADSIZE || y < 1.0 || y > QUADSIZE) {
+       huh();
+       return 1;
+    }
+    deltx = 0.1*(y - secty);
+    delty = 0.1*(sectx - x);
+    if (deltx==0 && delty== 0) {
+       skip(1);
+       prout("Spock-  \"Bridge to sickbay.  Dr. McCoy,");
+       prout("  I recommend an immediate review of");
+       prout("  the Captain's psychological profile.\"");
+       chew();
+       return 1;
+    }
+    *course = 1.90985932*atan2(deltx, delty);
+    return 0;
 }
 
-void photon(void) {
-       double targ[4][3], course[4];
-       double r, dummy;
-       int key, n, i, osuabor;
+void photon(void) 
+{
+    double targ[4][3], course[4];
+    double r, dummy;
+    int key, n, i, osuabor;
 
-       ididit = 0;
+    ididit = 0;
 
-       if (game.damage[DPHOTON]) {
-               prout("Photon tubes damaged.");
+    if (game.damage[DPHOTON]) {
+       prout("Photon tubes damaged.");
+       chew();
+       return;
+    }
+    if (torps == 0) {
+       prout("No torpedoes left.");
+       chew();
+       return;
+    }
+    key = scan();
+    for (;;) {
+       if (key == IHALPHA) {
+           huh();
+           return;
+       }
+       else if (key == IHEOL) {
+           prout("%d torpedoes left.", torps);
+           proutn("Number of torpedoes to fire- ");
+           key = scan();
+       }
+       else /* key == IHREAL */ {
+           n = aaitem + 0.5;
+           if (n <= 0) { /* abort command */
                chew();
                return;
-       }
-       if (torps == 0) {
-               prout("No torpedoes left.");
+           }
+           if (n > 3) {
                chew();
+               prout("Maximum of 3 torpedoes per burst.");
+               key = IHEOL;
                return;
+           }
+           if (n <= torps) break;
+           chew();
+           key = IHEOL;
        }
+    }
+    for (i = 1; i <= n; i++) {
        key = scan();
-       for (;;) {
-               if (key == IHALPHA) {
-                       huh();
-                       return;
-               }
-               else if (key == IHEOL) {
-                       prout("%d torpedoes left.", torps);
-                       proutn("Number of torpedoes to fire- ");
-                       key = scan();
-               }
-               else /* key == IHREAL */ {
-                       n = aaitem + 0.5;
-                       if (n <= 0) { /* abort command */
-                               chew();
-                               return;
-                       }
-                       if (n > 3) {
-                               chew();
-                               prout("Maximum of 3 torpedoes per burst.");
-                               key = IHEOL;
-                                return;
-                       }
-                       if (n <= torps) break;
-                       chew();
-                       key = IHEOL;
-               }
+       if (i==1 && key == IHEOL) {
+           break;      /* we will try prompting */
        }
-       for (i = 1; i <= n; i++) {
-               key = scan();
-               if (i==1 && key == IHEOL) {
-                       break;  /* we will try prompting */
-               }
-               if (i==2 && key == IHEOL) {
-                       /* direct all torpedoes at one target */
-                       while (i <= n) {
-                               targ[i][1] = targ[1][1];
-                               targ[i][2] = targ[1][2];
-                               course[i] = course[1];
-                               i++;
-                       }
-                       break;
-               }
-               if (key != IHREAL) {
-                       huh();
-                       return;
-               }
-               targ[i][1] = aaitem;
-               key = scan();
-               if (key != IHREAL) {
-                       huh();
-                       return;
-               }
-               targ[i][2] = aaitem;
-               if (targetcheck(targ[i][1], targ[i][2], &course[i])) return;
+       if (i==2 && key == IHEOL) {
+           /* direct all torpedoes at one target */
+           while (i <= n) {
+               targ[i][1] = targ[1][1];
+               targ[i][2] = targ[1][2];
+               course[i] = course[1];
+               i++;
+           }
+           break;
        }
-       chew();
-       if (i == 1 && key == IHEOL) {
-               /* prompt for each one */
-               for (i = 1; i <= n; i++) {
-                   proutn("Target sector for torpedo number %d- ", i);
-                       key = scan();
-                       if (key != IHREAL) {
-                               huh();
-                               return;
-                       }
-                       targ[i][1] = aaitem;
-                       key = scan();
-                       if (key != IHREAL) {
-                               huh();
-                               return;
-                       }
-                       targ[i][2] = aaitem;
-                       chew();
-                       if (targetcheck(targ[i][1], targ[i][2], &course[i])) return;
-               }
+       if (key != IHREAL) {
+           huh();
+           return;
        }
-       ididit = 1;
-       /* Loop for moving <n> torpedoes */
-       osuabor = 0;
-       for (i = 1; i <= n && !osuabor; i++) {
-               if (condit != IHDOCKED) torps--;
-               r = (Rand()+Rand())*0.5 -0.5;
-               if (fabs(r) >= 0.47) {
-                       /* misfire! */
-                       r = (Rand()+1.2) * r;
-                       if (n>1) {
-                           prouts("***TORPEDO NUMBER %d MISFIRES", i);
-                       }
-                       else prouts("***TORPEDO MISFIRES.");
-                       skip(1);
-                       if (i < n)
-                               prout("  Remainder of burst aborted.");
-                       osuabor=1;
-                       if (Rand() <= 0.2) {
-                               prout("***Photon tubes damaged by misfire.");
-                               game.damage[DPHOTON] = damfac*(1.0+2.0*Rand());
-                               break;
-                       }
-               }
-               if (shldup || condit == IHDOCKED) r *= 1.0 + 0.0001*shield;
-               torpedo(course[i], r, sectx, secty, &dummy, 0, i, n);
-               if (alldone || game.state.galaxy[quadx][quady]==1000) return;
+       targ[i][1] = aaitem;
+       key = scan();
+       if (key != IHREAL) {
+           huh();
+           return;
+       }
+       targ[i][2] = aaitem;
+       if (targetcheck(targ[i][1], targ[i][2], &course[i])) return;
+    }
+    chew();
+    if (i == 1 && key == IHEOL) {
+       /* prompt for each one */
+       for (i = 1; i <= n; i++) {
+           proutn("Target sector for torpedo number %d- ", i);
+           key = scan();
+           if (key != IHREAL) {
+               huh();
+               return;
+           }
+           targ[i][1] = aaitem;
+           key = scan();
+           if (key != IHREAL) {
+               huh();
+               return;
+           }
+           targ[i][2] = aaitem;
+           chew();
+           if (targetcheck(targ[i][1], targ[i][2], &course[i])) return;
        }
-       if (game.state.remkl==0) finish(FWON);
+    }
+    ididit = 1;
+    /* Loop for moving <n> torpedoes */
+    osuabor = 0;
+    for (i = 1; i <= n && !osuabor; i++) {
+       if (condit != IHDOCKED) torps--;
+       r = (Rand()+Rand())*0.5 -0.5;
+       if (fabs(r) >= 0.47) {
+           /* misfire! */
+           r = (Rand()+1.2) * r;
+           if (n>1) {
+               prouts("***TORPEDO NUMBER %d MISFIRES", i);
+           }
+           else prouts("***TORPEDO MISFIRES.");
+           skip(1);
+           if (i < n)
+               prout("  Remainder of burst aborted.");
+           osuabor=1;
+           if (Rand() <= 0.2) {
+               prout("***Photon tubes damaged by misfire.");
+               game.damage[DPHOTON] = damfac*(1.0+2.0*Rand());
+               break;
+           }
+       }
+       if (shldup || condit == IHDOCKED) 
+           r *= 1.0 + 0.0001*shield;
+       torpedo(course[i], r, sectx, secty, &dummy, 0, i, n);
+       if (alldone||game.state.galaxy[quadx][quady]==SUPERNOVA_PLACE)
+           return;
+    }
+    if (game.state.remkl==0) finish(FWON);
 }
 
        
 
-static void overheat(double rpow) {
-       if (rpow > 1500) {
-               double chekbrn = (rpow-1500.)*0.00038;
-               if (Rand() <= chekbrn) {
-                       prout("Weapons officer Sulu-  \"Phasers overheated, sir.\"");
-                       game.damage[DPHASER] = damfac*(1.0 + Rand()) * (1.0+chekbrn);
-               }
+static void overheat(double rpow) 
+{
+    if (rpow > 1500) {
+       double chekbrn = (rpow-1500.)*0.00038;
+       if (Rand() <= chekbrn) {
+           prout("Weapons officer Sulu-  \"Phasers overheated, sir.\"");
+           game.damage[DPHASER] = damfac*(1.0 + Rand()) * (1.0+chekbrn);
        }
+    }
 }
 
-static int checkshctrl(double rpow) {
-       double hit;
-       int icas;
+static int checkshctrl(double rpow) 
+{
+    double hit;
+    int icas;
        
+    skip(1);
+    if (Rand() < .998) {
+       prout("Shields lowered.");
+       return 0;
+    }
+    /* Something bad has happened */
+    prouts("***RED ALERT!  RED ALERT!");
+    skip(2);
+    hit = rpow*shield/inshld;
+    energy -= rpow+hit*0.8;
+    shield -= hit*0.2;
+    if (energy <= 0.0) {
+       prouts("Sulu-  \"Captain! Shield malf***********************\"");
        skip(1);
-       if (Rand() < .998) {
-               prout("Shields lowered.");
-               return 0;
-       }
-       /* Something bad has happened */
-       prouts("***RED ALERT!  RED ALERT!");
-       skip(2);
-       hit = rpow*shield/inshld;
-       energy -= rpow+hit*0.8;
-       shield -= hit*0.2;
-       if (energy <= 0.0) {
-               prouts("Sulu-  \"Captain! Shield malf***********************\"");
-               skip(1);
-               stars();
-               finish(FPHASER);
-               return 1;
-       }
-       prouts("Sulu-  \"Captain! Shield malfunction! Phaser fire contained!\"");
-       skip(2);
-       prout("Lt. Uhura-  \"Sir, all decks reporting damage.\"");
-       icas = hit*Rand()*0.012;
-       skip(1);
-       fry(0.8*hit);
-       if (icas) {
-               skip(1);
-               prout("McCoy to bridge- \"Severe radiation burns, Jim.");
-               prout("  %d casualties so far.\"", icas);
-               casual -= icas;
-       }
-       skip(1);
-       prout("Phaser energy dispersed by shields.");
-       prout("Enemy unaffected.");
-       overheat(rpow);
+       stars();
+       finish(FPHASER);
        return 1;
+    }
+    prouts("Sulu-  \"Captain! Shield malfunction! Phaser fire contained!\"");
+    skip(2);
+    prout("Lt. Uhura-  \"Sir, all decks reporting damage.\"");
+    icas = hit*Rand()*0.012;
+    skip(1);
+    fry(0.8*hit);
+    if (icas) {
+       skip(1);
+       prout("McCoy to bridge- \"Severe radiation burns, Jim.");
+       prout("  %d casualties so far.\"", icas);
+       casual -= icas;
+    }
+    skip(1);
+    prout("Phaser energy dispersed by shields.");
+    prout("Enemy unaffected.");
+    overheat(rpow);
+    return 1;
 }
        
 
-void phasers(void) {
-       double hits[21], rpow=0, extra, powrem, over, temp;
-       int kz = 0, k=1, i, irec=0; /* Cheating inhibitor */
-       int ifast=0, no=0, ipoop=1, msgflag = 1;
-       enum {NOTSET, MANUAL, FORCEMAN, AUTOMATIC} automode = NOTSET;
-       int key=0;
+void phasers(void) 
+{
+    double hits[21], rpow=0, extra, powrem, over, temp;
+    int kz = 0, k=1, i, irec=0; /* Cheating inhibitor */
+    int ifast=0, no=0, ipoop=1, msgflag = 1;
+    enum {NOTSET, MANUAL, FORCEMAN, AUTOMATIC} automode = NOTSET;
+    int key=0;
 
-       skip(1);
-       /* SR sensors and Computer */
-       if (game.damage[DSRSENS]+game.damage[DCOMPTR] > 0) ipoop = 0;
-       if (condit == IHDOCKED) {
-               prout("Phasers can't be fired through base shields.");
-               chew();
-               return;
+    skip(1);
+    /* SR sensors and Computer */
+    if (game.damage[DSRSENS]+game.damage[DCOMPTR] > 0) ipoop = 0;
+    if (condit == IHDOCKED) {
+       prout("Phasers can't be fired through base shields.");
+       chew();
+       return;
+    }
+    if (game.damage[DPHASER] != 0) {
+       prout("Phaser control damaged.");
+       chew();
+       return;
+    }
+    if (shldup) {
+       if (game.damage[DSHCTRL]) {
+           prout("High speed shield control damaged.");
+           chew();
+           return;
        }
-       if (game.damage[DPHASER] != 0) {
-               prout("Phaser control damaged.");
-               chew();
-               return;
+       if (energy <= 200.0) {
+           prout("Insufficient energy to activate high-speed shield control.");
+           chew();
+           return;
        }
-       if (shldup) {
-               if (game.damage[DSHCTRL]) {
-                       prout("High speed shield control damaged.");
-                       chew();
-                       return;
-               }
-               if (energy <= 200.0) {
-                       prout("Insufficient energy to activate high-speed shield control.");
-                       chew();
-                       return;
-               }
-               prout("Weapons Officer Sulu-  \"High-speed shield control enabled, sir.\"");
-               ifast = 1;
+       prout("Weapons Officer Sulu-  \"High-speed shield control enabled, sir.\"");
+       ifast = 1;
                
-       }
-       /* Original code so convoluted, I re-did it all */
-       while (automode==NOTSET) {
-               key=scan();
-               if (key == IHALPHA) {
-                       if (isit("manual")) {
-                               if (nenhere==0) {
-                                       prout("There is no enemy present to select.");
-                                       chew();
-                                       key = IHEOL;
-                                       automode=AUTOMATIC;
-                               }
-                               else {
-                                       automode = MANUAL;
-                                       key = scan();
-                               }
-                       }
-                       else if (isit("automatic")) {
-                               if ((!ipoop) && nenhere != 0) {
-                                       automode = FORCEMAN;
-                               }
-                               else {
-                                       if (nenhere==0)
-                                               prout("Energy will be expended into space.");
-                                       automode = AUTOMATIC;
-                                       key = scan();
-                               }
-                       }
-                       else if (isit("no")) {
-                               no = 1;
-                       }
-                       else {
-                               huh();
-                               return;
-                       }
+    }
+    /* Original code so convoluted, I re-did it all */
+    while (automode==NOTSET) {
+       key=scan();
+       if (key == IHALPHA) {
+           if (isit("manual")) {
+               if (nenhere==0) {
+                   prout("There is no enemy present to select.");
+                   chew();
+                   key = IHEOL;
+                   automode=AUTOMATIC;
                }
-               else if (key == IHREAL) {
-                       if (nenhere==0) {
-                               prout("Energy will be expended into space.");
-                               automode = AUTOMATIC;
-                       }
-                       else if (!ipoop)
-                               automode = FORCEMAN;
-                       else
-                               automode = AUTOMATIC;
+               else {
+                   automode = MANUAL;
+                   key = scan();
+               }
+           }
+           else if (isit("automatic")) {
+               if ((!ipoop) && nenhere != 0) {
+                   automode = FORCEMAN;
                }
                else {
-                       /* IHEOL */
-                       if (nenhere==0) {
-                               prout("Energy will be expended into space.");
-                               automode = AUTOMATIC;
-                       }
-                       else if (!ipoop)
-                               automode = FORCEMAN;
-                       else 
-                       proutn("Manual or automatic? ");
+                   if (nenhere==0)
+                       prout("Energy will be expended into space.");
+                   automode = AUTOMATIC;
+                   key = scan();
                }
+           }
+           else if (isit("no")) {
+               no = 1;
+           }
+           else {
+               huh();
+               return;
+           }
        }
+       else if (key == IHREAL) {
+           if (nenhere==0) {
+               prout("Energy will be expended into space.");
+               automode = AUTOMATIC;
+           }
+           else if (!ipoop)
+               automode = FORCEMAN;
+           else
+               automode = AUTOMATIC;
+       }
+       else {
+           /* IHEOL */
+           if (nenhere==0) {
+               prout("Energy will be expended into space.");
+               automode = AUTOMATIC;
+           }
+           else if (!ipoop)
+               automode = FORCEMAN;
+           else 
+               proutn("Manual or automatic? ");
+       }
+    }
                                
-       switch (automode) {
-               case AUTOMATIC:
-                       if (key == IHALPHA && isit("no")) {
-                               no = 1;
-                               key = scan();
-                       }
-                       if (key != IHREAL && nenhere != 0) {
-                                prout("Phasers locked on target. Energy available: %.2f",
-                                   ifast?energy-200.0:energy,1,2);
-                       }
-                        irec=0;
-                       do {
-                                        chew();
-                                        if (!kz) for (i = 1; i <= nenhere; i++)
-                                                     irec+=fabs(game.kpower[i])/(PHASEFAC*pow(0.90,game.kdist[i]))*
-                                                     (1.01+0.05*Rand()) + 1.0;
-                                        kz=1;
-                                        proutn("(%d) units required. ", irec);
-                                       chew();
-                                       proutn("Units to fire= ");
-                                       key = scan();
-                                        if (key!=IHREAL) return;
-                                       rpow = aaitem;
-                                       if (rpow > (ifast?energy-200:energy)) {
-                                           proutn("Energy available= %.2f",
-                                           ifast?energy-200:energy);
-                                       skip(1);
-                                       key = IHEOL;
-                               }
-                       } while (rpow > (ifast?energy-200:energy));
-                       if (rpow<=0) {
-                               /* chicken out */
-                               chew();
-                               return;
-                       }
-                       if ((key=scan()) == IHALPHA && isit("no")) {
-                               no = 1;
-                       }
-                       if (ifast) {
-                               energy -= 200; /* Go and do it! */
-                               if (checkshctrl(rpow)) return;
-                       }
-                       chew();
-                       energy -= rpow;
-                       extra = rpow;
-                       if (nenhere) {
-                               extra = 0.0;
-                               powrem = rpow;
-                               for (i = 1; i <= nenhere; i++) {
-                                       hits[i] = 0.0;
-                                       if (powrem <= 0) continue;
-                                       hits[i] = fabs(game.kpower[i])/(PHASEFAC*pow(0.90,game.kdist[i]));
-                                       over = (0.01 + 0.05*Rand())*hits[i];
-                                       temp = powrem;
-                                       powrem -= hits[i] + over;
-                                       if (powrem <= 0 && temp < hits[i]) hits[i] = temp;
-                                       if (powrem <= 0) over = 0.0;
-                                       extra += over;
-                               }
-                               if (powrem > 0.0) extra += powrem;
-                               hittem(hits);
-                                ididit=1;
-                       }
-                       if (extra > 0 && alldone == 0) {
-                               if (ithere) {
-                                       proutn("*** Tholian web absorbs ");
-                                       if (nenhere>0) proutn("excess ");
-                                       prout("phaser energy.");
-                               }
-                               else {
-                                       prout("%d expended on empty space.", (int)extra);
-                               }
-                       }
-                       break;
-
-               case FORCEMAN:
-                       chew();
-                       key = IHEOL;
-                       if (game.damage[DCOMPTR]!=0)
-                               prout("Battle comuter damaged, manual file only.");
-                       else {
-                               skip(1);
-                               prouts("---WORKING---");
-                               skip(1);
-                               prout("Short-range-sensors-damaged");
-                               prout("Insufficient-data-for-automatic-phaser-fire");
-                               prout("Manual-fire-must-be-used");
-                               skip(1);
-                       }
-               case MANUAL:
-                       rpow = 0.0;
-                       for (k = 1; k <= nenhere;) {
-                               int ii = game.kx[k], jj = game.ky[k];
-                               int ienm = game.quad[ii][jj];
-                               if (msgflag) {
-                                       proutn("Energy available= %.2f",
-                                              energy-.006-(ifast?200:0));
-                                       skip(1);
-                                       msgflag = 0;
-                                       rpow = 0.0;
-                               }
-                               if (game.damage[DSRSENS] && !(abs(sectx-ii) < 2 && abs(secty-jj) < 2) &&
-                                       (ienm == IHC || ienm == IHS)) {
-                                       cramen(ienm);
-                                       prout(" can't be located without short range scan.");
-                                       chew();
-                                       key = IHEOL;
-                                       hits[k] = 0; /* prevent overflow -- thanks to Alexei Voitenko */
-                                       k++;
-                                       continue;
-                               }
-                               if (key == IHEOL) {
-                                       chew();
-                                        if (ipoop && k > kz)
-                                                irec=(fabs(game.kpower[k])/(PHASEFAC*pow(0.9,game.kdist[k])))*
-                                                                (1.01+0.05*Rand()) + 1.0;
-                                       kz = k;
-                                       proutn("(");
-                                        if (game.damage[DCOMPTR]==0) proutn("%d", irec);
-                                        else proutn("??");
-                                       proutn(")  ");
-                                       proutn("units to fire at ");
-                                       crmena(0, ienm, 2, ii, jj);
-                                       proutn("-  ");
-                                       key = scan();
-                               }
-                               if (key == IHALPHA && isit("no")) {
-                                       no = 1;
-                                       key = scan();
-                                       continue;
-                                       }
-                               if (key == IHALPHA) {
-                                       huh();
-                                       return;
-                               }
-                               if (key == IHEOL) {
-                                       if (k==1) { /* Let me say I'm baffled by this */
-                                               msgflag = 1;
-                                       }
-                                       continue;
-                               }
-                               if (aaitem < 0) {
-                                       /* abort out */
-                                       chew();
-                                       return;
-                               }
-                               hits[k] = aaitem;
-                               rpow += aaitem;
-                               /* If total requested is too much, inform and start over */
-                               
-                               if (rpow > (ifast?energy-200:energy)) {
-                                       prout("Available energy exceeded -- try again.");
-                                       chew();
-                                        return;
-                               }
-                               key = scan(); /* scan for next value */
-                               k++;
-                       }
-                       if (rpow == 0.0) {
-                               /* zero energy -- abort */
-                               chew();
-                               return;
-                       }
-                       if (key == IHALPHA && isit("no")) {
-                               no = 1;
-                       }
-                       energy -= rpow;
-                       chew();
-                       if (ifast) {
-                               energy -= 200.0;
-                               if (checkshctrl(rpow)) return;
-                       }
-                       hittem(hits);
-                       ididit=1;
-               case NOTSET:;   /* avoid gcc warning */
+    switch (automode) {
+    case AUTOMATIC:
+       if (key == IHALPHA && isit("no")) {
+           no = 1;
+           key = scan();
+       }
+       if (key != IHREAL && nenhere != 0) {
+           prout("Phasers locked on target. Energy available: %.2f",
+                 ifast?energy-200.0:energy,1,2);
+       }
+       irec=0;
+       do {
+           chew();
+           if (!kz) for (i = 1; i <= nenhere; i++)
+               irec+=fabs(game.kpower[i])/(PHASEFAC*pow(0.90,game.kdist[i]))*
+                   (1.01+0.05*Rand()) + 1.0;
+           kz=1;
+           proutn("(%d) units required. ", irec);
+           chew();
+           proutn("Units to fire= ");
+           key = scan();
+           if (key!=IHREAL) return;
+           rpow = aaitem;
+           if (rpow > (ifast?energy-200:energy)) {
+               proutn("Energy available= %.2f",
+                      ifast?energy-200:energy);
+               skip(1);
+               key = IHEOL;
+           }
+       } while (rpow > (ifast?energy-200:energy));
+       if (rpow<=0) {
+           /* chicken out */
+           chew();
+           return;
+       }
+       if ((key=scan()) == IHALPHA && isit("no")) {
+           no = 1;
        }
-       /* Say shield raised or malfunction, if necessary */
-       if (alldone) return;
        if (ifast) {
+           energy -= 200; /* Go and do it! */
+           if (checkshctrl(rpow)) return;
+       }
+       chew();
+       energy -= rpow;
+       extra = rpow;
+       if (nenhere) {
+           extra = 0.0;
+           powrem = rpow;
+           for (i = 1; i <= nenhere; i++) {
+               hits[i] = 0.0;
+               if (powrem <= 0) continue;
+               hits[i] = fabs(game.kpower[i])/(PHASEFAC*pow(0.90,game.kdist[i]));
+               over = (0.01 + 0.05*Rand())*hits[i];
+               temp = powrem;
+               powrem -= hits[i] + over;
+               if (powrem <= 0 && temp < hits[i]) hits[i] = temp;
+               if (powrem <= 0) over = 0.0;
+               extra += over;
+           }
+           if (powrem > 0.0) extra += powrem;
+           hittem(hits);
+           ididit=1;
+       }
+       if (extra > 0 && alldone == 0) {
+           if (ithere) {
+               proutn("*** Tholian web absorbs ");
+               if (nenhere>0) proutn("excess ");
+               prout("phaser energy.");
+           }
+           else {
+               prout("%d expended on empty space.", (int)extra);
+           }
+       }
+       break;
+
+    case FORCEMAN:
+       chew();
+       key = IHEOL;
+       if (game.damage[DCOMPTR]!=0)
+           prout("Battle comuter damaged, manual file only.");
+       else {
+           skip(1);
+           prouts("---WORKING---");
+           skip(1);
+           prout("Short-range-sensors-damaged");
+           prout("Insufficient-data-for-automatic-phaser-fire");
+           prout("Manual-fire-must-be-used");
+           skip(1);
+       }
+    case MANUAL:
+       rpow = 0.0;
+       for (k = 1; k <= nenhere;) {
+           int ii = game.kx[k], jj = game.ky[k];
+           int ienm = game.quad[ii][jj];
+           if (msgflag) {
+               proutn("Energy available= %.2f",
+                      energy-.006-(ifast?200:0));
                skip(1);
-               if (no == 0) {
-                       if (Rand() >= 0.99) {
-                               prout("Sulu-  \"Sir, the high-speed shield control has malfunctioned . . .");
-                               prouts("         CLICK   CLICK   POP  . . .");
-                               prout(" No  response, sir!");
-                               shldup = 0;
-                       }
-                       else
-                               prout("Shields raised.");
+               msgflag = 0;
+               rpow = 0.0;
+           }
+           if (game.damage[DSRSENS] && !(abs(sectx-ii) < 2 && abs(secty-jj) < 2) &&
+               (ienm == IHC || ienm == IHS)) {
+               cramen(ienm);
+               prout(" can't be located without short range scan.");
+               chew();
+               key = IHEOL;
+               hits[k] = 0; /* prevent overflow -- thanks to Alexei Voitenko */
+               k++;
+               continue;
+           }
+           if (key == IHEOL) {
+               chew();
+               if (ipoop && k > kz)
+                   irec=(fabs(game.kpower[k])/(PHASEFAC*pow(0.9,game.kdist[k])))*
+                       (1.01+0.05*Rand()) + 1.0;
+               kz = k;
+               proutn("(");
+               if (game.damage[DCOMPTR]==0) proutn("%d", irec);
+               else proutn("??");
+               proutn(")  ");
+               proutn("units to fire at ");
+               crmena(0, ienm, 2, ii, jj);
+               proutn("-  ");
+               key = scan();
+           }
+           if (key == IHALPHA && isit("no")) {
+               no = 1;
+               key = scan();
+               continue;
+           }
+           if (key == IHALPHA) {
+               huh();
+               return;
+           }
+           if (key == IHEOL) {
+               if (k==1) { /* Let me say I'm baffled by this */
+                   msgflag = 1;
                }
-               else
-                       shldup = 0;
+               continue;
+           }
+           if (aaitem < 0) {
+               /* abort out */
+               chew();
+               return;
+           }
+           hits[k] = aaitem;
+           rpow += aaitem;
+           /* If total requested is too much, inform and start over */
+                               
+           if (rpow > (ifast?energy-200:energy)) {
+               prout("Available energy exceeded -- try again.");
+               chew();
+               return;
+           }
+           key = scan(); /* scan for next value */
+           k++;
+       }
+       if (rpow == 0.0) {
+           /* zero energy -- abort */
+           chew();
+           return;
        }
-       overheat(rpow);
+       if (key == IHALPHA && isit("no")) {
+           no = 1;
+       }
+       energy -= rpow;
+       chew();
+       if (ifast) {
+           energy -= 200.0;
+           if (checkshctrl(rpow)) return;
+       }
+       hittem(hits);
+       ididit=1;
+    case NOTSET:;      /* avoid gcc warning */
+    }
+    /* Say shield raised or malfunction, if necessary */
+    if (alldone) 
+       return;
+    if (ifast) {
+       skip(1);
+       if (no == 0) {
+           if (Rand() >= 0.99) {
+               prout("Sulu-  \"Sir, the high-speed shield control has malfunctioned . . .");
+               prouts("         CLICK   CLICK   POP  . . .");
+               prout(" No  response, sir!");
+               shldup = 0;
+           }
+           else
+               prout("Shields raised.");
+       }
+       else
+           shldup = 0;
+    }
+    overheat(rpow);
 }
 
-void hittem(double *hits) {
-       double kp, kpow, wham, hit, dustfac, kpini;
-       int nenhr2=nenhere, k=1, kk=1, ii, jj, ienm;
+void hittem(double *hits) 
+{
+    double kp, kpow, wham, hit, dustfac, kpini;
+    int nenhr2=nenhere, k=1, kk=1, ii, jj, ienm;
 
-       skip(1);
+    skip(1);
 
-       for (; k <= nenhr2; k++, kk++) {
-               if ((wham = hits[k])==0) continue;
-               dustfac = 0.9 + 0.01*Rand();
-               hit = wham*pow(dustfac,game.kdist[kk]);
-               kpini = game.kpower[kk];
-               kp = fabs(kpini);
-               if (PHASEFAC*hit < kp) kp = PHASEFAC*hit;
-               game.kpower[kk] -= (game.kpower[kk] < 0 ? -kp: kp);
-               kpow = game.kpower[kk];
-               ii = game.kx[kk];
-               jj = game.ky[kk];
-               if (hit > 0.005) {
-                        if (game.damage[DSRSENS]==0)
-                           boom(ii, jj);
-                       proutn("%d unit hit on ", (int)hit);
-               }
-               else
-                       proutn("Very small hit on ");
-               ienm = game.quad[ii][jj];
-                if (ienm==IHQUEST) iqengry=1;
-               crmena(0,ienm,2,ii,jj);
-               skip(1);
-               if (kpow == 0) {
-                       deadkl(ii, jj, ienm, ii, jj);
-                       if (game.state.remkl==0) finish(FWON);
-                       if (alldone) return;
-                       kk--; /* don't do the increment */
-               }
-               else /* decide whether or not to emasculate klingon */
-                       if (kpow > 0 && Rand() >= 0.9 &&
-                               kpow <= ((0.4 + 0.4*Rand())*kpini)) {
-                               prout("***Mr. Spock-  \"Captain, the vessel at ",
-                                       cramlc(sector,ii,jj));
-                               prout("   has just lost its firepower.\"");
-                               game.kpower[kk] = -kpow;
-                       }
+    for (; k <= nenhr2; k++, kk++) {
+       if ((wham = hits[k])==0) continue;
+       dustfac = 0.9 + 0.01*Rand();
+       hit = wham*pow(dustfac,game.kdist[kk]);
+       kpini = game.kpower[kk];
+       kp = fabs(kpini);
+       if (PHASEFAC*hit < kp) kp = PHASEFAC*hit;
+       game.kpower[kk] -= (game.kpower[kk] < 0 ? -kp: kp);
+       kpow = game.kpower[kk];
+       ii = game.kx[kk];
+       jj = game.ky[kk];
+       if (hit > 0.005) {
+           if (game.damage[DSRSENS]==0)
+               boom(ii, jj);
+           proutn("%d unit hit on ", (int)hit);
        }
-       return;
+       else
+           proutn("Very small hit on ");
+       ienm = game.quad[ii][jj];
+       if (ienm==IHQUEST) iqengry=1;
+       crmena(0,ienm,2,ii,jj);
+       skip(1);
+       if (kpow == 0) {
+           deadkl(ii, jj, ienm, ii, jj);
+           if (game.state.remkl==0) finish(FWON);
+           if (alldone) return;
+           kk--; /* don't do the increment */
+       }
+       else /* decide whether or not to emasculate klingon */
+           if (kpow > 0 && Rand() >= 0.9 &&
+               kpow <= ((0.4 + 0.4*Rand())*kpini)) {
+               prout("***Mr. Spock-  \"Captain, the vessel at ",
+                     cramlc(sector,ii,jj));
+               prout("   has just lost its firepower.\"");
+               game.kpower[kk] = -kpow;
+           }
+    }
+    return;
 }
 
index c1a5632b20ec49356a5b8a8a715242a1b788308d..c9d0f7bd2274eab5558eb6b31ed08a6573fbf94f 100644 (file)
--- a/events.c
+++ b/events.c
 #include "sst.h"
 #include <math.h>
 
-void events(void) {
-        int ictbeam=0, ipage=0, istract=0, line, i=0, j, k, l, ixhold=0, iyhold=0;
-        double fintim = game.state.date + Time, datemin, xtime, repair, yank=0;
+void events(void) 
+{
+    int ictbeam=0, ipage=0, istract=0, line, i=0, j, k, l, ixhold=0, iyhold=0;
+    double fintim = game.state.date + Time, datemin, xtime, repair, yank=0;
 
 #ifdef DEBUG
-       if (idebug) prout("EVENTS");
+    if (idebug) prout("EVENTS");
 #endif
 
-       if (stdamtim == 1e30 && game.damage[DRADIO] != 0.0) {
-               /* chart will no longer be updated because radio is dead */
-               stdamtim = game.state.date;
-               for (i=1; i <= GALSIZE ; i++)
-                       for (j=1; j <= GALSIZE; j++)
-                               if (game.starch[i][j] == 1) game.starch[i][j] = game.state.galaxy[i][j]+SUPERNOVA_PLACE;
-       }
+    if (stdamtim == 1e30 && game.damage[DRADIO] != 0.0) {
+       /* chart will no longer be updated because radio is dead */
+       stdamtim = game.state.date;
+       for (i=1; i <= GALSIZE ; i++)
+           for (j=1; j <= GALSIZE; j++)
+               if (game.starch[i][j] == 1) 
+                   game.starch[i][j] = game.state.galaxy[i][j]+SUPERNOVA_PLACE;
+    }
 
-       for (;;) {
-               /* Select earliest extraneous event, line==0 if no events */
-               line = FSPY;
-               if (alldone) return;
-               datemin = fintim;
-               for (l=1; l<=NEVENTS; l++)
-                       if (game.future[l] < datemin) {
-                               line = l;
-                               datemin = game.future[l];
-                       }
-               xtime = datemin-game.state.date;
-               game.state.date = datemin;
-               /* Decrement Federation resources and recompute remaining time */
-               game.state.remres -= (game.state.remkl+4*game.state.remcom)*xtime;
-               game.state.remtime = game.state.remres/(game.state.remkl+4*game.state.remcom);
-               if (game.state.remtime <=0) {
-                       finish(FDEPLETE);
-                       return;
+    for (;;) {
+       /* Select earliest extraneous event, line==0 if no events */
+       line = FSPY;
+       if (alldone) return;
+       datemin = fintim;
+       for (l=1; l<=NEVENTS; l++)
+           if (game.future[l] < datemin) {
+               line = l;
+               datemin = game.future[l];
+           }
+       xtime = datemin-game.state.date;
+       game.state.date = datemin;
+       /* Decrement Federation resources and recompute remaining time */
+       game.state.remres -= (game.state.remkl+4*game.state.remcom)*xtime;
+       game.state.remtime = game.state.remres/(game.state.remkl+4*game.state.remcom);
+       if (game.state.remtime <=0) {
+           finish(FDEPLETE);
+           return;
+       }
+       /* Is life support adequate? */
+       if (game.damage[DLIFSUP] && condit != IHDOCKED) {
+           if (lsupres < xtime && game.damage[DLIFSUP] > lsupres) {
+               finish(FLIFESUP);
+               return;
+           }
+           lsupres -= xtime;
+           if (game.damage[DLIFSUP] <= xtime) lsupres = inlsr;
+       }
+       /* Fix devices */
+       repair = xtime;
+       if (condit == IHDOCKED) repair /= docfac;
+       /* Don't fix Deathray here */
+       for (l=1; l<=NDEVICES; l++)
+           if (game.damage[l] > 0.0 && l != DDRAY)
+               game.damage[l] -= (game.damage[l]-repair > 0.0 ? repair : game.damage[l]);
+       /* If radio repaired, update star chart and attack reports */
+       if (stdamtim != 1e30 && game.damage[DRADIO] == 0.0) {
+           stdamtim = 1e30;
+           prout("Lt. Uhura- \"Captain, the sub-space radio is working and");
+           prout("   surveillance reports are coming in.");
+           skip(1);
+           for (i=1; i <= GALSIZE ; i++)
+               for (j=1; j <= GALSIZE; j++)
+                   if (game.starch[i][j] >= SUPERNOVA_PLACE) game.starch[i][j] = 1;
+           if (iseenit==0) {
+               attakreport(0);
+               iseenit = 1;
+           }
+           skip(1);
+           prout("   The star chart is now up to date.\"");
+           skip(1);
+       }
+       /* Cause extraneous event LINE to occur */
+       Time -= xtime;
+       switch (line) {
+       case FSNOVA: /* Supernova */
+           if (ipage==0) pause_game(1);
+           ipage=1;
+           snova(0,0);
+           game.future[FSNOVA] = game.state.date + expran(0.5*intime);
+           if (game.state.galaxy[quadx][quady] == SUPERNOVA_PLACE) return;
+           break;
+       case FSPY: /* Check with spy to see if S.C. should tractor beam */
+           if (game.state.nscrem == 0 ||
+               ictbeam+istract > 0 ||
+               condit==IHDOCKED || isatb==1 || iscate==1) return;
+           if (ientesc ||
+               (energy < 2000 && torps < 4 && shield < 1250) ||
+               (game.damage[DPHASER]>0 && (game.damage[DPHOTON]>0 || torps < 4)) ||
+               (game.damage[DSHIELD] > 0 &&
+                (energy < 2500 || game.damage[DPHASER] > 0) &&
+                (torps < 5 || game.damage[DPHOTON] > 0))) {
+               /* Tractor-beam her! */
+               istract=1;
+               yank = square(game.state.isx-quadx) + square(game.state.isy-quady);
+               /********* fall through to FTBEAM code ***********/
+           }
+           else return;
+       case FTBEAM: /* Tractor beam */
+           if (line==FTBEAM) {
+               if (game.state.remcom == 0) {
+                   game.future[FTBEAM] = 1e30;
+                   break;
                }
-               /* Is life support adequate? */
-               if (game.damage[DLIFSUP] && condit != IHDOCKED) {
-                       if (lsupres < xtime && game.damage[DLIFSUP] > lsupres) {
-                               finish(FLIFESUP);
-                               return;
-                       }
-                       lsupres -= xtime;
-                       if (game.damage[DLIFSUP] <= xtime) lsupres = inlsr;
+               i = Rand()*game.state.remcom+1.0;
+               yank = square(game.state.cx[i]-quadx) + square(game.state.cy[i]-quady);
+               if (istract || condit == IHDOCKED || yank == 0) {
+                   /* Drats! Have to reschedule */
+                   game.future[FTBEAM] = game.state.date + Time +
+                       expran(1.5*intime/game.state.remcom);
+                   break;
                }
-               /* Fix devices */
-               repair = xtime;
-               if (condit == IHDOCKED) repair /= docfac;
-               /* Don't fix Deathray here */
-               for (l=1; l<=NDEVICES; l++)
-                       if (game.damage[l] > 0.0 && l != DDRAY)
-                               game.damage[l] -= (game.damage[l]-repair > 0.0 ? repair : game.damage[l]);
-               /* If radio repaired, update star chart and attack reports */
-               if (stdamtim != 1e30 && game.damage[DRADIO] == 0.0) {
-                       stdamtim = 1e30;
-                       prout("Lt. Uhura- \"Captain, the sub-space radio is working and");
-                       prout("   surveillance reports are coming in.");
-                       skip(1);
-                       for (i=1; i <= GALSIZE ; i++)
-                               for (j=1; j <= GALSIZE; j++)
-                                       if (game.starch[i][j] > 999) game.starch[i][j] = 1;
-                       if (iseenit==0) {
-                               attakreport(0);
-                               iseenit = 1;
-                       }
-                       skip(1);
-                       prout("   The star chart is now up to date.\"");
+           }
+           /* tractor beaming cases merge here */
+           yank = sqrt(yank);
+           if (ipage==0) pause_game(1);
+           ipage=1;
+           Time = (10.0/(7.5*7.5))*yank; /* 7.5 is yank rate (warp 7.5) */
+           ictbeam = 1;
+           skip(1);
+           proutn("***");
+           crmshp();
+           prout(" caught in long range tractor beam--");
+           /* If Kirk & Co. screwing around on planet, handle */
+           atover(1); /* atover(1) is Grab */
+           if (alldone) return;
+           if (icraft == 1) { /* Caught in Galileo? */
+               finish(FSTRACTOR);
+               return;
+           }
+           /* Check to see if shuttle is aboard */
+           if (iscraft==0) {
+               skip(1);
+               if (Rand() > 0.5) {
+                   prout("Galileo, left on the planet surface, is captured");
+                   prout("by aliens and made into a flying McDonald's.");
+                   game.damage[DSHUTTL] = -10;
+                   iscraft = -1;
+               }
+               else {
+                   prout("Galileo, left on the planet surface, is well hidden.");
+               }
+           }
+           if (line==0) {
+               quadx = game.state.isx;
+               quady = game.state.isy;
+           }
+           else {
+               quadx = game.state.cx[i];
+               quady = game.state.cy[i];
+           }
+           iran(QUADSIZE, &sectx, &secty);
+           crmshp();
+           proutn(" is pulled to ");
+           proutn(cramlc(quadrant, quadx, quady));
+           proutn(", ");
+           prout(cramlc(sector, sectx, secty));
+           if (resting) {
+               prout("(Remainder of rest/repair period cancelled.)");
+               resting = 0;
+           }
+           if (shldup==0) {
+               if (game.damage[DSHIELD]==0 && shield > 0) {
+                   doshield(2); /* Shldsup */
+                   shldchg=0;
+               }
+               else prout("(Shields not currently useable.)");
+           }
+           newqad(0);
+           /* Adjust finish time to time of tractor beaming */
+           fintim = game.state.date+Time;
+           attack(0);
+           if (game.state.remcom <= 0) game.future[FTBEAM] = 1e30;
+           else game.future[FTBEAM] = game.state.date+Time+expran(1.5*intime/game.state.remcom);
+           break;
+       case FSNAP: /* Snapshot of the universe (for time warp) */
+           game.snapsht = game.state;
+           game.state.snap = 1;
+           game.future[FSNAP] = game.state.date + expran(0.5 * intime);
+           break;
+       case FBATTAK: /* Commander attacks starbase */
+           if (game.state.remcom==0 || game.state.rembase==0) {
+               /* no can do */
+               game.future[FBATTAK] = game.future[FCDBAS] = 1e30;
+               break;
+           }
+           i = 0;
+           for (j=1; j<=game.state.rembase; j++) {
+               for (k=1; k<=game.state.remcom; k++)
+                   if (game.state.baseqx[j]==game.state.cx[k] && game.state.baseqy[j]==game.state.cy[k] &&
+                       (game.state.baseqx[j]!=quadx || game.state.baseqy[j]!=quady) &&
+                       (game.state.baseqx[j]!=game.state.isx || game.state.baseqy[j]!=game.state.isy)) {
+                       i = 1;
+                       break;
+                   }
+               if (i == 1) break;
+           }
+           if (j>game.state.rembase) {
+               /* no match found -- try later */
+               game.future[FBATTAK] = game.state.date + expran(0.3*intime);
+               game.future[FCDBAS] = 1e30;
+               break;
+           }
+           /* commander + starbase combination found -- launch attack */
+           batx = game.state.baseqx[j];
+           baty = game.state.baseqy[j];
+           game.future[FCDBAS] = game.state.date+1.0+3.0*Rand();
+           if (isatb) /* extra time if SC already attacking */
+               game.future[FCDBAS] += game.future[FSCDBAS]-game.state.date;
+           game.future[FBATTAK] = game.future[FCDBAS] +expran(0.3*intime);
+           iseenit = 0;
+           if (game.damage[DRADIO] != 0.0 &&
+               condit != IHDOCKED) break; /* No warning :-( */
+           iseenit = 1;
+           if (ipage==0) pause_game(1);
+           ipage = 1;
+           skip(1);
+           proutn("Lt. Uhura-  \"Captain, the starbase in ");
+           prout(cramlc(quadrant, batx, baty));
+           prout("   reports that it is under attack and that it can");
+           proutn("   hold out only until stardate %d",
+                  (int)game.future[FCDBAS]);
+           prout(".\"");
+           if (resting) {
+               skip(1);
+               proutn("Mr. Spock-  \"Captain, shall we cancel the rest period?\" ");
+               if (ja()) {
+                   resting = 0;
+                   Time = 0.0;
+                   return;
+               }
+           }
+           break;
+       case FSCDBAS: /* Supercommander destroys base */
+           game.future[FSCDBAS] = 1e30;
+           isatb = 2;
+           if (!BASES(game.state.galaxy[game.state.isx][game.state.isy])) 
+               break; /* WAS RETURN! */
+           ixhold = batx;
+           iyhold = baty;
+           batx = game.state.isx;
+           baty = game.state.isy;
+       case FCDBAS: /* Commander succeeds in destroying base */
+           if (line==FCDBAS) {
+               game.future[FCDBAS] = 1e30;
+               /* find the lucky pair */
+               for (i = 1; i <= game.state.remcom; i++)
+                   if (game.state.cx[i]==batx && game.state.cy[i]==baty) break;
+               if (i > game.state.remcom || game.state.rembase == 0 ||
+                   !BASES(game.state.galaxy[batx][baty])) {
+                   /* No action to take after all */
+                   batx = baty = 0;
+                   break;
+               }
+           }
+           /* Code merges here for any commander destroying base */
+           /* Not perfect, but will have to do */
+           if (game.starch[batx][baty] == -1) game.starch[batx][baty] = 0;
+           /* Handle case where base is in same quadrant as starship */
+           if (batx==quadx && baty==quady) {
+               if (game.starch[batx][baty] >= SUPERNOVA_PLACE) game.starch[batx][baty] -= BASE_PLACE;
+               game.quad[basex][basey]= IHDOT;
+               basex=basey=0;
+               newcnd();
+               skip(1);
+               prout("Spock-  \"Captain, I believe the starbase has been destroyegame.state.\"");
+           }
+           else if (game.state.rembase != 1 &&
+                    (game.damage[DRADIO] <= 0.0 || condit == IHDOCKED)) {
+               /* Get word via subspace radio */
+               if (ipage==0) pause_game(1);
+               ipage = 1;
+               skip(1);
+               prout("Lt. Uhura-  \"Captain, Starfleet Command reports that");
+               proutn("   the starbase in ");
+               proutn(cramlc(quadrant, batx, baty));
+               prout(" has been destroyed by");
+               if (isatb==2) prout("the Klingon Super-Commander");
+               else prout("a Klingon Commander");
+           }
+           /* Remove Starbase from galaxy */
+           game.state.galaxy[batx][baty] -= BASE_PLACE;
+           for (i=1; i <= game.state.rembase; i++)
+               if (game.state.baseqx[i]==batx && game.state.baseqy[i]==baty) {
+                   game.state.baseqx[i]=game.state.baseqx[game.state.rembase];
+                   game.state.baseqy[i]=game.state.baseqy[game.state.rembase];
+               }
+           game.state.rembase--;
+           if (isatb == 2) {
+               /* reinstate a commander's base attack */
+               batx = ixhold;
+               baty = iyhold;
+               isatb = 0;
+           }
+           else {
+               batx = baty = 0;
+           }
+           break;
+       case FSCMOVE: /* Supercommander moves */
+           game.future[FSCMOVE] = game.state.date+0.2777;
+           if (ientesc+istract==0 &&
+               isatb!=1 &&
+               (iscate!=1 || justin==1)) scom(&ipage);
+           break;
+       case FDSPROB: /* Move deep space probe */
+           game.future[FDSPROB] = game.state.date + 0.01;
+           probex += probeinx;
+           probey += probeiny;
+           i = (int)(probex/QUADSIZE +0.05);
+           j = (int)(probey/QUADSIZE + 0.05);
+           if (probecx != i || probecy != j) {
+               probecx = i;
+               probecy = j;
+               if (i < 1 || i > GALSIZE || j < 1 || j > GALSIZE ||
+                   game.state.galaxy[probecx][probecy] == SUPERNOVA_PLACE) {
+                   // Left galaxy or ran into supernova
+                   if (game.damage[DRADIO]==0.0 || condit == IHDOCKED) {
+                       if (ipage==0) pause_game(1);
+                       ipage = 1;
                        skip(1);
+                       proutn("Lt. Uhura-  \"The deep space probe ");
+                       if (i < 1 ||i > GALSIZE || j < 1 || j > GALSIZE)
+                           proutn("has left the galaxy");
+                       else
+                           proutn("is no longer transmitting");
+                       prout(".\"");
+                   }
+                   game.future[FDSPROB] = 1e30;
+                   break;
                }
-               /* Cause extraneous event LINE to occur */
-               Time -= xtime;
-               switch (line) {
-                       case FSNOVA: /* Supernova */
-                               if (ipage==0) pause_game(1);
-                               ipage=1;
-                               snova(0,0);
-                               game.future[FSNOVA] = game.state.date + expran(0.5*intime);
-                               if (game.state.galaxy[quadx][quady] == SUPERNOVA_PLACE) return;
-                               break;
-                       case FSPY: /* Check with spy to see if S.C. should tractor beam */
-                               if (game.state.nscrem == 0 ||
-                                       ictbeam+istract > 0 ||
-                                       condit==IHDOCKED || isatb==1 || iscate==1) return;
-                               if (ientesc ||
-                                       (energy < 2000 && torps < 4 && shield < 1250) ||
-                                       (game.damage[DPHASER]>0 && (game.damage[DPHOTON]>0 || torps < 4)) ||
-                                       (game.damage[DSHIELD] > 0 &&
-                                        (energy < 2500 || game.damage[DPHASER] > 0) &&
-                                        (torps < 5 || game.damage[DPHOTON] > 0))) {
-                                       /* Tractor-beam her! */
-                                       istract=1;
-                                       yank = square(game.state.isx-quadx) + square(game.state.isy-quady);
-                                       /*********TBEAM CODE***********/
-                               }
-                               else return;
-                       case FTBEAM: /* Tractor beam */
-                               if (line==FTBEAM) {
-                                       if (game.state.remcom == 0) {
-                                               game.future[FTBEAM] = 1e30;
-                                               break;
-                                       }
-                                       i = Rand()*game.state.remcom+1.0;
-                                       yank = square(game.state.cx[i]-quadx) + square(game.state.cy[i]-quady);
-                                       if (istract || condit == IHDOCKED || yank == 0) {
-                                               /* Drats! Have to reschedule */
-                                               game.future[FTBEAM] = game.state.date + Time +
-                                                                                expran(1.5*intime/game.state.remcom);
-                                               break;
-                                       }
-                               }
-                               /* tractor beaming cases merge here */
-                               yank = sqrt(yank);
-                               if (ipage==0) pause_game(1);
-                               ipage=1;
-                               Time = (10.0/(7.5*7.5))*yank; /* 7.5 is yank rate (warp 7.5) */
-                               ictbeam = 1;
-                               skip(1);
-                               proutn("***");
-                               crmshp();
-                               prout(" caught in long range tractor beam--");
-                               /* If Kirk & Co. screwing around on planet, handle */
-                               atover(1); /* atover(1) is Grab */
-                               if (alldone) return;
-                               if (icraft == 1) { /* Caught in Galileo? */
-                                       finish(FSTRACTOR);
-                                       return;
-                               }
-                               /* Check to see if shuttle is aboard */
-                               if (iscraft==0) {
-                                       skip(1);
-                                       if (Rand() >0.5) {
-                                               prout("Galileo, left on the planet surface, is captured");
-                                               prout("by aliens and made into a flying McDonald's.");
-                                               game.damage[DSHUTTL] = -10;
-                                               iscraft = -1;
-                                       }
-                                       else {
-                                               prout("Galileo, left on the planet surface, is well hidden.");
-                                       }
-                               }
-                               if (line==0) {
-                                       quadx = game.state.isx;
-                                       quady = game.state.isy;
-                               }
-                               else {
-                                       quadx = game.state.cx[i];
-                                       quady = game.state.cy[i];
-                               }
-                               iran10(&sectx, &secty);
-                               crmshp();
-                               proutn(" is pulled to ");
-                               proutn(cramlc(quadrant, quadx, quady));
-                               proutn(", ");
-                               prout(cramlc(sector, sectx, secty));
-                               if (resting) {
-                                       prout("(Remainder of rest/repair period cancellegame.state.)");
-                                       resting = 0;
-                               }
-                               if (shldup==0) {
-                                       if (game.damage[DSHIELD]==0 && shield > 0) {
-                                               doshield(2); /* Shldsup */
-                                               shldchg=0;
-                                       }
-                                       else prout("(Shields not currently useable.)");
-                               }
-                               newqad(0);
-                               /* Adjust finish time to time of tractor beaming */
-                               fintim = game.state.date+Time;
-                                attack(0);
-                               if (game.state.remcom <= 0) game.future[FTBEAM] = 1e30;
-                               else game.future[FTBEAM] = game.state.date+Time+expran(1.5*intime/game.state.remcom);
-                               break;
-                       case FSNAP: /* Snapshot of the universe (for time warp) */
-                               game.snapsht = game.state;
-                               game.state.snap = 1;
-                               game.future[FSNAP] = game.state.date + expran(0.5 * intime);
-                               break;
-                       case FBATTAK: /* Commander attacks starbase */
-                               if (game.state.remcom==0 || game.state.rembase==0) {
-                                       /* no can do */
-                                       game.future[FBATTAK] = game.future[FCDBAS] = 1e30;
-                                       break;
-                               }
-                               i = 0;
-                               for (j=1; j<=game.state.rembase; j++) {
-                                       for (k=1; k<=game.state.remcom; k++)
-                                               if (game.state.baseqx[j]==game.state.cx[k] && game.state.baseqy[j]==game.state.cy[k] &&
-                                                       (game.state.baseqx[j]!=quadx || game.state.baseqy[j]!=quady) &&
-                                                       (game.state.baseqx[j]!=game.state.isx || game.state.baseqy[j]!=game.state.isy)) {
-                                                       i = 1;
-                                                       break;
-                                               }
-                                       if (i == 1) break;
-                               }
-                               if (j>game.state.rembase) {
-                                       /* no match found -- try later */
-                                       game.future[FBATTAK] = game.state.date + expran(0.3*intime);
-                                       game.future[FCDBAS] = 1e30;
-                                       break;
-                               }
-                               /* commander + starbase combination found -- launch attack */
-                               batx = game.state.baseqx[j];
-                               baty = game.state.baseqy[j];
-                               game.future[FCDBAS] = game.state.date+1.0+3.0*Rand();
-                               if (isatb) /* extra time if SC already attacking */
-                                       game.future[FCDBAS] += game.future[FSCDBAS]-game.state.date;
-                               game.future[FBATTAK] = game.future[FCDBAS] +expran(0.3*intime);
-                               iseenit = 0;
-                               if (game.damage[DRADIO] != 0.0 &&
-                                       condit != IHDOCKED) break; /* No warning :-( */
-                               iseenit = 1;
-                               if (ipage==0) pause_game(1);
-                               ipage = 1;
-                               skip(1);
-                               proutn("Lt. Uhura-  \"Captain, the starbase in ");
-                               prout(cramlc(quadrant, batx, baty));
-                               prout("   reports that it is under attack and that it can");
-                               proutn("   hold out only until stardate %d",
-                                       (int)game.future[FCDBAS]);
-                               prout(".\"");
-                               if (resting) {
-                                       skip(1);
-                                       proutn("Mr. Spock-  \"Captain, shall we cancel the rest period?\" ");
-                                       if (ja()) {
-                                               resting = 0;
-                                               Time = 0.0;
-                                               return;
-                                       }
-                               }
-                               break;
-                       case FSCDBAS: /* Supercommander destroys base */
-                               game.future[FSCDBAS] = 1e30;
-                               isatb = 2;
-                               if (game.state.galaxy[game.state.isx][game.state.isy]%ENEMY_PLACE < BASE_PLACE) break; /* WAS RETURN! */
-                               ixhold = batx;
-                               iyhold = baty;
-                               batx = game.state.isx;
-                               baty = game.state.isy;
-                       case FCDBAS: /* Commander succeeds in destroying base */
-                               if (line==FCDBAS) {
-                                       game.future[FCDBAS] = 1e30;
-                                       /* find the lucky pair */
-                                       for (i = 1; i <= game.state.remcom; i++)
-                                               if (game.state.cx[i]==batx && game.state.cy[i]==baty) break;
-                                       if (i > game.state.remcom || game.state.rembase == 0 ||
-                                               game.state.galaxy[batx][baty] % ENEMY_PLACE < BASE_PLACE) {
-                                               /* No action to take after all */
-                                               batx = baty = 0;
-                                               break;
-                                       }
-                               }
-                               /* Code merges here for any commander destroying base */
-                               /* Not perfect, but will have to do */
-                               if (game.starch[batx][baty] == -1) game.starch[batx][baty] = 0;
-                               /* Handle case where base is in same quadrant as starship */
-                               if (batx==quadx && baty==quady) {
-                                       if (game.starch[batx][baty] >= SUPERNOVA_PLACE) game.starch[batx][baty] -= BASE_PLACE;
-                                       game.quad[basex][basey]= IHDOT;
-                                       basex=basey=0;
-                                       newcnd();
-                                       skip(1);
-                                       prout("Spock-  \"Captain, I believe the starbase has been destroyegame.state.\"");
-                               }
-                               else if (game.state.rembase != 1 &&
-                                                (game.damage[DRADIO] <= 0.0 || condit == IHDOCKED)) {
-                                       /* Get word via subspace radio */
-                                       if (ipage==0) pause_game(1);
-                                       ipage = 1;
-                                       skip(1);
-                                       prout("Lt. Uhura-  \"Captain, Starfleet Command reports that");
-                                       proutn("   the starbase in ");
-                                       proutn(cramlc(quadrant, batx, baty));
-                                       prout(" has been destroyed by");
-                                       if (isatb==2) prout("the Klingon Super-Commander");
-                                       else prout("a Klingon Commander");
-                               }
-                               /* Remove Starbase from galaxy */
-                               game.state.galaxy[batx][baty] -= BASE_PLACE;
-                               for (i=1; i <= game.state.rembase; i++)
-                                       if (game.state.baseqx[i]==batx && game.state.baseqy[i]==baty) {
-                                               game.state.baseqx[i]=game.state.baseqx[game.state.rembase];
-                                               game.state.baseqy[i]=game.state.baseqy[game.state.rembase];
-                                       }
-                               game.state.rembase--;
-                               if (isatb == 2) {
-                                       /* reinstate a commander's base attack */
-                                       batx = ixhold;
-                                       baty = iyhold;
-                                       isatb = 0;
-                               }
-                               else {
-                                       batx = baty = 0;
-                               }
-                               break;
-                       case FSCMOVE: /* Supercommander moves */
-                               game.future[FSCMOVE] = game.state.date+0.2777;
-                               if (ientesc+istract==0 &&
-                                       isatb!=1 &&
-                                       (iscate!=1 || justin==1)) scom(&ipage);
-                               break;
-                       case FDSPROB: /* Move deep space probe */
-                               game.future[FDSPROB] = game.state.date + 0.01;
-                               probex += probeinx;
-                               probey += probeiny;
-                               i = (int)(probex/QUADSIZE +0.05);
-                               j = (int)(probey/QUADSIZE + 0.05);
-                               if (probecx != i || probecy != j) {
-                                       probecx = i;
-                                       probecy = j;
-                                       if (i < 1 || i > GALSIZE || j < 1 || j > GALSIZE ||
-                                               game.state.galaxy[probecx][probecy] == SUPERNOVA_PLACE) {
-                                               // Left galaxy or ran into supernova
-                                               if (game.damage[DRADIO]==0.0 || condit == IHDOCKED) {
-                                                       if (ipage==0) pause_game(1);
-                                                       ipage = 1;
-                                                       skip(1);
-                                                       proutn("Lt. Uhura-  \"The deep space probe ");
-                                                       if (i < 1 ||i > GALSIZE || j < 1 || j > GALSIZE)
-                                                               proutn("has left the galaxy");
-                                                       else
-                                                               proutn("is no longer transmitting");
-                                                       prout(".\"");
-                                               }
-                                               game.future[FDSPROB] = 1e30;
-                                               break;
-                                       }
-                                       if (game.damage[DRADIO]==0.0   || condit == IHDOCKED) {
-                                               if (ipage==0) pause_game(1);
-                                               ipage = 1;
-                                               skip(1);
-                                               proutn("Lt. Uhura-  \"The deep space probe is now in ");
-                                               proutn(cramlc(quadrant, probecx, probecy));
-                                               prout(".\"");
-                                       }
-                               }
-                               /* Update star chart if Radio is working or have access to
-                                  radio. */
-                               if (game.damage[DRADIO] == 0.0 || condit == IHDOCKED)
-                                       game.starch[probecx][probecy] = game.damage[DRADIO] > 0.0 ?
-                                                                                  game.state.galaxy[probecx][probecy]+SUPERNOVA_PLACE : 1;
-                               proben--; // One less to travel
-                               if (proben == 0 && isarmed &&
-                                       game.state.galaxy[probecx][probecy] % BASE_PLACE > 0) {
-                                       /* lets blow the sucker! */
-                                       snova(1,0);
-                                       game.future[FDSPROB] = 1e30;
-                                       if (game.state.galaxy[quadx][quady] == SUPERNOVA_PLACE) return;
-                               }
-                               break;
+               if (game.damage[DRADIO]==0.0   || condit == IHDOCKED) {
+                   if (ipage==0) pause_game(1);
+                   ipage = 1;
+                   skip(1);
+                   proutn("Lt. Uhura-  \"The deep space probe is now in ");
+                   proutn(cramlc(quadrant, probecx, probecy));
+                   prout(".\"");
                }
+           }
+           /* Update star chart if Radio is working or have access to
+              radio. */
+           if (game.damage[DRADIO] == 0.0 || condit == IHDOCKED)
+               game.starch[probecx][probecy] = game.damage[DRADIO] > 0.0 ?
+                   game.state.galaxy[probecx][probecy]+SUPERNOVA_PLACE : 1;
+           proben--; // One less to travel
+           if (proben == 0 && isarmed &&
+               STARS(game.state.galaxy[probecx][probecy])) {
+               /* lets blow the sucker! */
+               snova(1,0);
+               game.future[FDSPROB] = 1e30;
+               if (game.state.galaxy[quadx][quady] == SUPERNOVA_PLACE) return;
+           }
+           break;
        }
+    }
 }
 
                                
-void wait(void) {
-       int key;
-       double temp, delay, origTime;
+void wait(void) 
+{
+    int key;
+    double temp, delay, origTime;
 
-       ididit = 0;
-       for (;;) {
-               key = scan();
-               if (key  != IHEOL) break;
-               proutn("How long? ");
-       }
-       chew();
-       if (key != IHREAL) {
-               huh();
-               return;
-       }
-       origTime = delay = aaitem;
-       if (delay <= 0.0) return;
-       if (delay >= game.state.remtime || nenhere != 0) {
-               proutn("Are you sure? ");
-               if (ja() == 0) return;
-       }
+    ididit = 0;
+    for (;;) {
+       key = scan();
+       if (key  != IHEOL) break;
+       proutn("How long? ");
+    }
+    chew();
+    if (key != IHREAL) {
+       huh();
+       return;
+    }
+    origTime = delay = aaitem;
+    if (delay <= 0.0) return;
+    if (delay >= game.state.remtime || nenhere != 0) {
+       proutn("Are you sure? ");
+       if (ja() == 0) return;
+    }
 
-       /* Alternate resting periods (events) with attacks */
+    /* Alternate resting periods (events) with attacks */
 
-       resting = 1;
-       do {
-               if (delay <= 0) resting = 0;
-               if (resting == 0) {
-                       prout("%d stardates left.", (int)game.state.remtime);
-                       return;
-               }
-               temp = Time = delay;
+    resting = 1;
+    do {
+       if (delay <= 0) resting = 0;
+       if (resting == 0) {
+           prout("%d stardates left.", (int)game.state.remtime);
+           return;
+       }
+       temp = Time = delay;
 
-               if (nenhere) {
-                       double rtime = 1.0 + Rand();
-                       if (rtime < temp) temp = rtime;
-                       Time = temp;
-               }
-               if (Time < delay) attack(0);
-               if (alldone) return;
-               events();
-               ididit = 1;
-               if (alldone) return;
-               delay -= temp;
-               /* Repair Deathray if long rest at starbase */
-               if (origTime-delay >= 9.99 && condit == IHDOCKED)
-                       game.damage[DDRAY] = 0.0;
-       } while (game.state.galaxy[quadx][quady] != SUPERNOVA_PLACE); // leave if quadrant supernovas
+       if (nenhere) {
+           double rtime = 1.0 + Rand();
+           if (rtime < temp) temp = rtime;
+           Time = temp;
+       }
+       if (Time < delay) attack(0);
+       if (alldone) return;
+       events();
+       ididit = 1;
+       if (alldone) return;
+       delay -= temp;
+       /* Repair Deathray if long rest at starbase */
+       if (origTime-delay >= 9.99 && condit == IHDOCKED)
+           game.damage[DDRAY] = 0.0;
+    } while 
+       (game.state.galaxy[quadx][quady] != SUPERNOVA_PLACE); // leave if quadrant supernovas
 
-       resting = 0;
-       Time = 0;
+    resting = 0;
+    Time = 0;
 }
 
-void nova(int ix, int iy) {
-       static double course[] =
-               {0.0, 10.5, 12.0, 1.5, 9.0, 0.0, 3.0, 7.5, 6.0, 4.5};
-        int bot, top, top2, hits[QUADSIZE+1][3], kount, icx, icy, mm, nn, j;
-       int iquad, iquad1, i, ll, newcx, newcy, ii, jj;
-       if (Rand() < 0.05) {
-               /* Wow! We've supernova'ed */
-               snova(ix, iy);
-               return;
-       }
+void nova(int ix, int iy) 
+{
+    static double course[] =
+       {0.0, 10.5, 12.0, 1.5, 9.0, 0.0, 3.0, 7.5, 6.0, 4.5};
+    int bot, top, top2, hits[QUADSIZE+1][3], kount, icx, icy, mm, nn, j;
+    int iquad, iquad1, i, ll, newcx, newcy, ii, jj;
+    if (Rand() < 0.05) {
+       /* Wow! We've supernova'ed */
+       snova(ix, iy);
+       return;
+    }
 
-       /* handle initial nova */
-       game.quad[ix][iy] = IHDOT;
-       crmena(1, IHSTAR, 2, ix, iy);
-       prout(" novas.");
-       game.state.galaxy[quadx][quady] -= 1;
-       game.state.starkl++;
+    /* handle initial nova */
+    game.quad[ix][iy] = IHDOT;
+    crmena(1, IHSTAR, 2, ix, iy);
+    prout(" novas.");
+    game.state.galaxy[quadx][quady] -= 1;
+    game.state.starkl++;
        
-       /* Set up stack to recursively trigger adjacent stars */
-       bot = top = top2 = 1;
-       kount = 0;
-       icx = icy = 0;
-       hits[1][1] = ix;
-       hits[1][2] = iy;
-       while (1) {
-               for (mm = bot; mm <= top; mm++) 
-               for (nn = 1; nn <= 3; nn++)  /* nn,j represents coordinates around current */
-                       for (j = 1; j <= 3; j++) {
-                               if (j==2 && nn== 2) continue;
-                               ii = hits[mm][1]+nn-2;
-                               jj = hits[mm][2]+j-2;
-                               if (ii < 1 || ii > QUADSIZE || jj < 1 || jj > QUADSIZE) continue;
-                               iquad = game.quad[ii][jj];
-                               switch (iquad) {
-//                                     case IHDOT:     /* Empty space ends reaction
-//                                     case IHQUEST:
-//                                     case IHBLANK:
-//                                     case IHT:
-//                                     case IHWEB:
-                                       default:
-                                               break;
-                                       case IHSTAR: /* Affect another star */
-                                               if (Rand() < 0.05) {
-                                                       /* This star supernovas */
-                                                       snova(ii,jj);
-                                                       return;
-                                               }
-                                               top2++;
-                                               hits[top2][1]=ii;
-                                               hits[top2][2]=jj;
-                                               game.state.galaxy[quadx][quady] -= 1;
-                                               game.state.starkl++;
-                                               crmena(1, IHSTAR, 2, ii, jj);
-                                               prout(" novas.");
-                                               game.quad[ii][jj] = IHDOT;
-                                               break;
-                                       case IHP: /* Destroy planet */
-                                               game.state.newstuf[quadx][quady] -= 1;
-                                               game.state.nplankl++;
-                                               crmena(1, IHP, 2, ii, jj);
-                                               prout(" destroyed.");
-                                               DESTROY(&game.state.plnets[iplnet]);
-                                               iplnet = plnetx = plnety = 0;
-                                               if (landed == 1) {
-                                                       finish(FPNOVA);
-                                                       return;
-                                               }
-                                               game.quad[ii][jj] = IHDOT;
-                                               break;
-                                       case IHB: /* Destroy base */
-                                               game.state.galaxy[quadx][quady] -= BASE_PLACE;
-                                               for (i = 1; i <= game.state.rembase; i++)
-                                                       if (game.state.baseqx[i]==quadx && game.state.baseqy[i]==quady) break;
-                                               game.state.baseqx[i] = game.state.baseqx[game.state.rembase];
-                                               game.state.baseqy[i] = game.state.baseqy[game.state.rembase];
-                                               game.state.rembase--;
-                                               basex = basey = 0;
-                                               game.state.basekl++;
-                                               newcnd();
-                                               crmena(1, IHB, 2, ii, jj);
-                                               prout(" destroyed.");
-                                               game.quad[ii][jj] = IHDOT;
-                                               break;
-                                       case IHE: /* Buffet ship */
-                                       case IHF:
-                                               prout("***Starship buffeted by nova.");
-                                               if (shldup) {
-                                                       if (shield >= 2000.0) shield -= 2000.0;
-                                                       else {
-                                                               double diff = 2000.0 - shield;
-                                                               energy -= diff;
-                                                               shield = 0.0;
-                                                               shldup = 0;
-                                                               prout("***Shields knocked out.");
-                                                               game.damage[DSHIELD] += 0.005*damfac*Rand()*diff;
-                                                       }
-                                               }
-                                               else energy -= 2000.0;
-                                               if (energy <= 0) {
-                                                       finish(FNOVA);
-                                                       return;
-                                               }
-                                               /* add in course nova contributes to kicking starship*/
-                                               icx += sectx-hits[mm][1];
-                                               icy += secty-hits[mm][2];
-                                               kount++;
-                                               break;
-                                       case IHK: /* kill klingon */
-                                               deadkl(ii,jj,iquad, ii, jj);
-                                               break;
-                                       case IHC: /* Damage/destroy big enemies */
-                                       case IHS:
-                                       case IHR:
-                                               for (ll = 1; ll <= nenhere; ll++)
-                                                       if (game.kx[ll]==ii && game.ky[ll]==jj) break;
-                                               game.kpower[ll] -= 800.0; /* If firepower is lost, die */
-                                               if (game.kpower[ll] <= 0.0) {
-                                                       deadkl(ii, jj, iquad, ii, jj);
-                                                       break;
-                                               }
-                                               newcx = ii + ii - hits[mm][1];
-                                               newcy = jj + jj - hits[mm][2];
-                                               crmena(1, iquad, 2, ii, jj);
-                                               proutn(" damaged");
-                                               if (newcx<1 || newcx>QUADSIZE || newcy<1 || newcy>QUADSIZE) {
-                                                       /* can't leave quadrant */
-                                                       skip(1);
-                                                       break;
-                                               }
-                                               iquad1 = game.quad[newcx][newcy];
-                                               if (iquad1 == IHBLANK) {
-                                                       proutn(", blasted into ");
-                                                       crmena(0, IHBLANK, 2, newcx, newcy);
-                                                       skip(1);
-                                                       deadkl(ii, jj, iquad, newcx, newcy);
-                                                       break;
-                                               }
-                                               if (iquad1 != IHDOT) {
-                                                       /* can't move into something else */
-                                                       skip(1);
-                                                       break;
-                                               }
-                                               proutn(", buffeted to ");
-                                               proutn(cramlc(sector, newcx, newcy));
-                                               game.quad[ii][jj] = IHDOT;
-                                               game.quad[newcx][newcy] = iquad;
-                                               game.kx[ll] = newcx;
-                                               game.ky[ll] = newcy;
-                                               game.kavgd[ll] = sqrt(square(sectx-newcx)+square(secty-newcy));
-                                               game.kdist[ll] = game.kavgd[ll];
-                                               skip(1);
-                                               break;
-                               }
+    /* Set up stack to recursively trigger adjacent stars */
+    bot = top = top2 = 1;
+    kount = 0;
+    icx = icy = 0;
+    hits[1][1] = ix;
+    hits[1][2] = iy;
+    while (1) {
+       for (mm = bot; mm <= top; mm++) 
+           for (nn = 1; nn <= 3; nn++)  /* nn,j represents coordinates around current */
+               for (j = 1; j <= 3; j++) {
+                   if (j==2 && nn== 2) continue;
+                   ii = hits[mm][1]+nn-2;
+                   jj = hits[mm][2]+j-2;
+                   if (ii < 1 || ii > QUADSIZE || jj < 1 || jj > QUADSIZE) continue;
+                   iquad = game.quad[ii][jj];
+                   switch (iquad) {
+                   // case IHDOT:      /* Empty space ends reaction
+                   // case IHQUEST:
+                   // case IHBLANK:
+                   // case IHT:
+                   // case IHWEB:
+                   default:
+                       break;
+                   case IHSTAR: /* Affect another star */
+                       if (Rand() < 0.05) {
+                           /* This star supernovas */
+                           snova(ii,jj);
+                           return;
                        }
-               if (top == top2) break;
-               bot = top + 1;
-               top = top2;
-       }
-       if (kount==0) return;
-
-       /* Starship affected by nova -- kick it away. */
-       dist = kount*0.1;
-       if (icx) icx = (icx < 0 ? -1 : 1);
-       if (icy) icy = (icy < 0 ? -1 : 1);
-       direc = course[3*(icx+1)+icy+2];
-       if (direc == 0.0) dist = 0.0;
-       if (dist == 0.0) return;
-       Time = 10.0*dist/16.0;
-       skip(1);
-       prout("Force of nova displaces starship.");
-       iattak=2;       /* Eliminates recursion problem */
-       imove();
-       Time = 10.0*dist/16.0;
+                       top2++;
+                       hits[top2][1]=ii;
+                       hits[top2][2]=jj;
+                       game.state.galaxy[quadx][quady] -= 1;
+                       game.state.starkl++;
+                       crmena(1, IHSTAR, 2, ii, jj);
+                       prout(" novas.");
+                       game.quad[ii][jj] = IHDOT;
+                       break;
+                   case IHP: /* Destroy planet */
+                       game.state.newstuf[quadx][quady] -= 1;
+                       game.state.nplankl++;
+                       crmena(1, IHP, 2, ii, jj);
+                       prout(" destroyed.");
+                       DESTROY(&game.state.plnets[iplnet]);
+                       iplnet = plnetx = plnety = 0;
+                       if (landed == 1) {
+                           finish(FPNOVA);
+                           return;
+                       }
+                       game.quad[ii][jj] = IHDOT;
+                       break;
+                   case IHB: /* Destroy base */
+                       game.state.galaxy[quadx][quady] -= BASE_PLACE;
+                       for (i = 1; i <= game.state.rembase; i++)
+                           if (game.state.baseqx[i]==quadx && game.state.baseqy[i]==quady) break;
+                       game.state.baseqx[i] = game.state.baseqx[game.state.rembase];
+                       game.state.baseqy[i] = game.state.baseqy[game.state.rembase];
+                       game.state.rembase--;
+                       basex = basey = 0;
+                       game.state.basekl++;
+                       newcnd();
+                       crmena(1, IHB, 2, ii, jj);
+                       prout(" destroyed.");
+                       game.quad[ii][jj] = IHDOT;
+                       break;
+                   case IHE: /* Buffet ship */
+                   case IHF:
+                       prout("***Starship buffeted by nova.");
+                       if (shldup) {
+                           if (shield >= 2000.0) shield -= 2000.0;
+                           else {
+                               double diff = 2000.0 - shield;
+                               energy -= diff;
+                               shield = 0.0;
+                               shldup = 0;
+                               prout("***Shields knocked out.");
+                               game.damage[DSHIELD] += 0.005*damfac*Rand()*diff;
+                           }
+                       }
+                       else energy -= 2000.0;
+                       if (energy <= 0) {
+                           finish(FNOVA);
+                           return;
+                       }
+                       /* add in course nova contributes to kicking starship*/
+                       icx += sectx-hits[mm][1];
+                       icy += secty-hits[mm][2];
+                       kount++;
+                       break;
+                   case IHK: /* kill klingon */
+                       deadkl(ii,jj,iquad, ii, jj);
+                       break;
+                   case IHC: /* Damage/destroy big enemies */
+                   case IHS:
+                   case IHR:
+                       for (ll = 1; ll <= nenhere; ll++)
+                           if (game.kx[ll]==ii && game.ky[ll]==jj) break;
+                       game.kpower[ll] -= 800.0; /* If firepower is lost, die */
+                       if (game.kpower[ll] <= 0.0) {
+                           deadkl(ii, jj, iquad, ii, jj);
+                           break;
+                       }
+                       newcx = ii + ii - hits[mm][1];
+                       newcy = jj + jj - hits[mm][2];
+                       crmena(1, iquad, 2, ii, jj);
+                       proutn(" damaged");
+                       if (newcx<1 || newcx>QUADSIZE || newcy<1 || newcy>QUADSIZE) {
+                           /* can't leave quadrant */
+                           skip(1);
+                           break;
+                       }
+                       iquad1 = game.quad[newcx][newcy];
+                       if (iquad1 == IHBLANK) {
+                           proutn(", blasted into ");
+                           crmena(0, IHBLANK, 2, newcx, newcy);
+                           skip(1);
+                           deadkl(ii, jj, iquad, newcx, newcy);
+                           break;
+                       }
+                       if (iquad1 != IHDOT) {
+                           /* can't move into something else */
+                           skip(1);
+                           break;
+                       }
+                       proutn(", buffeted to ");
+                       proutn(cramlc(sector, newcx, newcy));
+                       game.quad[ii][jj] = IHDOT;
+                       game.quad[newcx][newcy] = iquad;
+                       game.kx[ll] = newcx;
+                       game.ky[ll] = newcy;
+                       game.kavgd[ll] = sqrt(square(sectx-newcx)+square(secty-newcy));
+                       game.kdist[ll] = game.kavgd[ll];
+                       skip(1);
+                       break;
+                   }
+               }
+       if (top == top2) 
+           break;
+       bot = top + 1;
+       top = top2;
+    }
+    if (kount==0) 
        return;
+
+    /* Starship affected by nova -- kick it away. */
+    dist = kount*0.1;
+    if (icx) icx = (icx < 0 ? -1 : 1);
+    if (icy) icy = (icy < 0 ? -1 : 1);
+    direc = course[3*(icx+1)+icy+2];
+    if (direc == 0.0) dist = 0.0;
+    if (dist == 0.0) return;
+    Time = 10.0*dist/16.0;
+    skip(1);
+    prout("Force of nova displaces starship.");
+    iattak=2;  /* Eliminates recursion problem */
+    imove();
+    Time = 10.0*dist/16.0;
+    return;
 }
        
        
-void snova(int insx, int insy) {
-        int comdead, nqx=0, nqy=0, nsx, nsy, num, kldead, iscdead;
-       int nrmdead, npdead;
-       int insipient=0;
+void snova(int insx, int insy) 
+{
+    int comdead, nqx=0, nqy=0, nsx, nsy, num, kldead, iscdead;
+    int nrmdead, npdead;
+    int incipient=0;
 
-       nsx = insy;
-       nsy = insy;
+    nsx = insy;
+    nsy = insy;
 
-       if (insy== 0) {
-               if (insx == 1) {
-                       /* NOVAMAX being used */
-                       nqx = probecx;
-                       nqy = probecy;
-               }
-               else {
-                       int stars = 0;
-                       /* Scheduled supernova -- select star */
-                       /* logic changed here so that we won't favor quadrants in top
-                       left of universe */
-                       for (nqx = 1; nqx<=GALSIZE; nqx++) {
-                               for (nqy = 1; nqy<=GALSIZE; nqy++) {
-                                       stars += game.state.galaxy[nqx][nqy] % BASE_PLACE;
-                               }
-                       }
-                       if (stars == 0) return; /* nothing to supernova exists */
-                       num = Rand()*stars + 1;
-                       for (nqx = 1; nqx<=GALSIZE; nqx++) {
-                               for (nqy = 1; nqy<=GALSIZE; nqy++) {
-                                       num -= game.state.galaxy[nqx][nqy] % BASE_PLACE;
-                                       if (num <= 0) break;
-                               }
-                               if (num <=0) break;
-                       }
-#ifdef DEBUG
-                       if (idebug) {
-                               proutn("Super nova here?");
-                               if (ja()==1) {
-                                       nqx = quadx;
-                                       nqy = quady;
-                               }
-                       }
-#endif
+    if (insy== 0) {
+       if (insx == 1) {
+           /* NOVAMAX being used */
+           nqx = probecx;
+           nqy = probecy;
+       }
+       else {
+           int stars = 0;
+           /* Scheduled supernova -- select star */
+           /* logic changed here so that we won't favor quadrants in top
+              left of universe */
+           for (nqx = 1; nqx<=GALSIZE; nqx++) {
+               for (nqy = 1; nqy<=GALSIZE; nqy++) {
+                   stars += STARS(game.state.galaxy[nqx][nqy]);
                }
-
-               if (nqx != quady || nqy != quady || justin != 0) {
-                       /* it isn't here, or we just entered (treat as inroute) */
-                       if (game.damage[DRADIO] == 0.0 || condit == IHDOCKED) {
-                               skip(1);
-                               prout("Message from Starfleet Command       Stardate %.2f", game.state.date);
-                               prout("     Supernova in %s; caution advised.",
-                                      cramlc(quadrant, nqx, nqy));
-                       }
+           }
+           if (stars == 0) return; /* nothing to supernova exists */
+           num = Rand()*stars + 1;
+           for (nqx = 1; nqx<=GALSIZE; nqx++) {
+               for (nqy = 1; nqy<=GALSIZE; nqy++) {
+                   num -= STARS(game.state.galaxy[nqx][nqy]);
+                   if (num <= 0) break;
                }
-               else {
-                       /* we are in the quadrant! */
-                       insipient = 1;
-                       num = Rand()* (game.state.galaxy[nqx][nqy]%BASE_PLACE) + 1;
-                       for (nsx=1; nsx < QUADSIZE; nsx++) {
-                               for (nsy=1; nsy < QUADSIZE; nsy++) {
-                                       if (game.quad[nsx][nsy]==IHSTAR) {
-                                               num--;
-                                               if (num==0) break;
-                                       }
-                               }
-                               if (num==0) break;
-                       }
+               if (num <=0) break;
+           }
+#ifdef DEBUG
+           if (idebug) {
+               proutn("Super nova here?");
+               if (ja()==1) {
+                   nqx = quadx;
+                   nqy = quady;
                }
-       }
-       else {
-               insipient = 1;
+           }
+#endif
        }
 
-       if (insipient) {
+       if (nqx != quady || nqy != quady || justin != 0) {
+           /* it isn't here, or we just entered (treat as inroute) */
+           if (game.damage[DRADIO] == 0.0 || condit == IHDOCKED) {
                skip(1);
-               prouts("***RED ALERT!  RED ALERT!");
-               skip(1);
-               prout("***Incipient supernova detected at ", cramlc(sector, nsx, nsy));
-               nqx = quadx;
-               nqy = quady;
-               if (square(nsx-sectx) + square(nsy-secty) <= 2.1) {
-                       proutn("Emergency override attempts t");
-                       prouts("***************");
-                       skip(1);
-                       stars();
-                       alldone=1;
-               }
+               prout("Message from Starfleet Command       Stardate %.2f", game.state.date);
+               prout("     Supernova in %s; caution advised.",
+                     cramlc(quadrant, nqx, nqy));
+           }
        }
-       /* destroy any Klingons in supernovaed quadrant */
-       num=game.state.galaxy[nqx][nqy];
-       kldead = num/100;
-       comdead = iscdead = 0;
-       if (nqx==game.state.isx && nqy == game.state.isy) {
-               /* did in the Supercommander! */
-               game.state.nscrem = game.state.isx = game.state.isy = isatb = iscate = 0;
-               iscdead = 1;
-               game.future[FSCMOVE] = game.future[FSCDBAS] = 1e30;
-       }
-       game.state.remkl -= kldead;
-       if (game.state.remcom) {
-               int maxloop = game.state.remcom, l;
-               for (l = 1; l <= maxloop; l++) {
-                       if (game.state.cx[l] == nqx && game.state.cy[l] == nqy) {
-                               game.state.cx[l] = game.state.cx[game.state.remcom];
-                               game.state.cy[l] = game.state.cy[game.state.remcom];
-                               game.state.cx[game.state.remcom] = game.state.cy[game.state.remcom] = 0;
-                               game.state.remcom--;
-                               kldead--;
-                               comdead++;
-                               if (game.state.remcom==0) game.future[FTBEAM] = 1e30;
-                               break;
-                       }
+       else {
+           /* we are in the quadrant! */
+           incipient = 1;
+           num = Rand()* STARS(game.state.galaxy[nqx][nqy]) + 1;
+           for (nsx=1; nsx < QUADSIZE; nsx++) {
+               for (nsy=1; nsy < QUADSIZE; nsy++) {
+                   if (game.quad[nsx][nsy]==IHSTAR) {
+                       num--;
+                       if (num==0) break;
+                   }
                }
+               if (num==0) break;
+           }
        }
-       /* destroy Romulans and planets in supernovaed quadrant */
-       num = game.state.newstuf[nqx][nqy];
-       game.state.newstuf[nqx][nqy] = 0;
-       nrmdead = num/10;
-       game.state.nromrem -= nrmdead;
-       npdead = num - nrmdead*10;
-       if (npdead) {
-               int l;
-               for (l = 0; l < inplan; l++)
-                       if (game.state.plnets[l].x == nqx && game.state.plnets[l].y == nqy) {
-                           DESTROY(&game.state.plnets[l]);
-                       }
-       }
-       /* Destroy any base in supernovaed quadrant */
-       if (game.state.rembase) {
-               int maxloop = game.state.rembase, l;
-               for (l = 1; l <= maxloop; l++)
-                       if (game.state.baseqx[l]==nqx && game.state.baseqy[l]==nqy) {
-                               game.state.baseqx[l] = game.state.baseqx[game.state.rembase];
-                               game.state.baseqy[l] = game.state.baseqy[game.state.rembase];
-                               game.state.baseqx[game.state.rembase] = game.state.baseqy[game.state.rembase] = 0;
-                               game.state.rembase--;
-                               break;
-                       }
-       }
-       /* If starship caused supernova, tally up destruction */
-       if (insx) {
-               num = game.state.galaxy[nqx][nqy] % 100;
-               game.state.starkl += num % 10;
-               game.state.basekl += num/10;
-               game.state.killk += kldead;
-               game.state.killc += comdead;
-               game.state.nromkl += nrmdead;
-               game.state.nplankl += npdead;
-               game.state.nsckill += iscdead;
+    }
+    else {
+       incipient = 1;
+    }
+
+    if (incipient) {
+       skip(1);
+       prouts("***RED ALERT!  RED ALERT!");
+       skip(1);
+       prout("***Incipient supernova detected at ", cramlc(sector, nsx, nsy));
+       nqx = quadx;
+       nqy = quady;
+       if (square(nsx-sectx) + square(nsy-secty) <= 2.1) {
+           proutn("Emergency override attempts t");
+           prouts("***************");
+           skip(1);
+           stars();
+           alldone=1;
        }
-       /* mark supernova in galaxy and in star chart */
-       if ((quadx == nqx && quady == nqy) ||
-               game.damage[DRADIO] == 0 ||
-               condit == IHDOCKED)
-               game.starch[nqx][nqy] = 1;
-       game.state.galaxy[nqx][nqy] = SUPERNOVA_PLACE;
-       /* If supernova destroys last klingons give special message */
-       if (game.state.remkl==0 && (nqx != quadx || nqy != quady)) {
-               skip(2);
-               if (insx == 0) prout("Lucky you!");
-               proutn("A supernova in %s has just destroyed the last Klingons.",
-                      cramlc(quadrant, nqx, nqy));
-               finish(FWON);
-               return;
+    }
+    /* destroy any Klingons in supernovaed quadrant */
+    num=game.state.galaxy[nqx][nqy];
+    kldead = num/100;
+    comdead = iscdead = 0;
+    if (nqx==game.state.isx && nqy == game.state.isy) {
+       /* did in the Supercommander! */
+       game.state.nscrem = game.state.isx = game.state.isy = isatb = iscate = 0;
+       iscdead = 1;
+       game.future[FSCMOVE] = game.future[FSCDBAS] = 1e30;
+    }
+    game.state.remkl -= kldead;
+    if (game.state.remcom) {
+       int maxloop = game.state.remcom, l;
+       for (l = 1; l <= maxloop; l++) {
+           if (game.state.cx[l] == nqx && game.state.cy[l] == nqy) {
+               game.state.cx[l] = game.state.cx[game.state.remcom];
+               game.state.cy[l] = game.state.cy[game.state.remcom];
+               game.state.cx[game.state.remcom] = game.state.cy[game.state.remcom] = 0;
+               game.state.remcom--;
+               kldead--;
+               comdead++;
+               if (game.state.remcom==0) game.future[FTBEAM] = 1e30;
+               break;
+           }
        }
-       /* if some Klingons remain, continue or die in supernova */
-       if (alldone) finish(FSNOVAED);
+    }
+    /* destroy Romulans and planets in supernovaed quadrant */
+    num = game.state.newstuf[nqx][nqy];
+    game.state.newstuf[nqx][nqy] = 0;
+    nrmdead = num/10;
+    game.state.nromrem -= nrmdead;
+    npdead = num - nrmdead*10;
+    if (npdead) {
+       int l;
+       for (l = 0; l < inplan; l++)
+           if (game.state.plnets[l].x == nqx && game.state.plnets[l].y == nqy) {
+               DESTROY(&game.state.plnets[l]);
+           }
+    }
+    /* Destroy any base in supernovaed quadrant */
+    if (game.state.rembase) {
+       int maxloop = game.state.rembase, l;
+       for (l = 1; l <= maxloop; l++)
+           if (game.state.baseqx[l]==nqx && game.state.baseqy[l]==nqy) {
+               game.state.baseqx[l] = game.state.baseqx[game.state.rembase];
+               game.state.baseqy[l] = game.state.baseqy[game.state.rembase];
+               game.state.baseqx[game.state.rembase] = game.state.baseqy[game.state.rembase] = 0;
+               game.state.rembase--;
+               break;
+           }
+    }
+    /* If starship caused supernova, tally up destruction */
+    if (insx) {
+       num = game.state.galaxy[nqx][nqy] % 100;
+       game.state.starkl += num % 10;
+       game.state.basekl += num/10;
+       game.state.killk += kldead;
+       game.state.killc += comdead;
+       game.state.nromkl += nrmdead;
+       game.state.nplankl += npdead;
+       game.state.nsckill += iscdead;
+    }
+    /* mark supernova in galaxy and in star chart */
+    if ((quadx == nqx && quady == nqy) ||
+       game.damage[DRADIO] == 0 ||
+       condit == IHDOCKED)
+       game.starch[nqx][nqy] = 1;
+    game.state.galaxy[nqx][nqy] = SUPERNOVA_PLACE;
+    /* If supernova destroys last klingons give special message */
+    if (game.state.remkl==0 && (nqx != quadx || nqy != quady)) {
+       skip(2);
+       if (insx == 0) prout("Lucky you!");
+       proutn("A supernova in %s has just destroyed the last Klingons.",
+              cramlc(quadrant, nqx, nqy));
+       finish(FWON);
        return;
+    }
+    /* if some Klingons remain, continue or die in supernova */
+    if (alldone) finish(FSNOVAED);
+    return;
 }
                
                                
index e3ace26732e2fef5cb47715c2ab18ef5d1723374..ae70c4c0f8c39ea43833635658d64424a3dfa5e0 100644 (file)
--- a/finish.c
+++ b/finish.c
 #include <string.h>
 #include <time.h>
 
-void dstrct() {
-       /* Finish with a BANG! */
-       chew();
-       if (game.damage[DCOMPTR] != 0.0) {
-               prout("Computer damaged; cannot execute destruct sequence.");
-               return;
-       }
-       prouts("---WORKING---"); skip(1);
-        prouts("SELF-DESTRUCT-SEQUENCE-ACTIVATED"); skip(1);
-       prouts("   10"); skip(1);
-       prouts("       9"); skip(1);
-       prouts("          8"); skip(1);
-       prouts("             7"); skip(1);
-       prouts("                6"); skip(1);
-       skip(1);
-       prout("ENTER-CORRECT-PASSWORD-TO-CONTINUE-");
-       skip(1);
-       prout("SELF-DESTRUCT-SEQUENCE-OTHERWISE-");
-       skip(1);
-       prout("SELF-DESTRUCT-SEQUENCE-WILL-BE-ABORTED");
+void dstrct() 
+{
+    /* Finish with a BANG! */
+    chew();
+    if (game.damage[DCOMPTR] != 0.0) {
+       prout("Computer damaged; cannot execute destruct sequence.");
+       return;
+    }
+    prouts("---WORKING---"); skip(1);
+    prouts("SELF-DESTRUCT-SEQUENCE-ACTIVATED"); skip(1);
+    prouts("   10"); skip(1);
+    prouts("       9"); skip(1);
+    prouts("          8"); skip(1);
+    prouts("             7"); skip(1);
+    prouts("                6"); skip(1);
+    skip(1);
+    prout("ENTER-CORRECT-PASSWORD-TO-CONTINUE-");
+    skip(1);
+    prout("SELF-DESTRUCT-SEQUENCE-OTHERWISE-");
+    skip(1);
+    prout("SELF-DESTRUCT-SEQUENCE-WILL-BE-ABORTED");
+    skip(1);
+    scan();
+    chew();
+    if (strcmp(game.passwd, citem) != 0) {
+       prouts("PASSWORD-REJECTED;"); skip(1);
+       prouts("CONTINUITY-EFFECTED");
+       skip(2);
+       return;
+    }
+    prouts("PASSWORD-ACCEPTED"); skip(1);
+    prouts("                   5"); skip(1);
+    prouts("                      4"); skip(1);
+    prouts("                         3"); skip(1);
+    prouts("                            2"); skip(1);
+    prouts("                              1"); skip(1);
+    if (Rand() < 0.15) {
+       prouts("GOODBYE-CRUEL-WORLD");
        skip(1);
-       scan();
-       chew();
-       if (strcmp(game.passwd, citem) != 0) {
-               prouts("PASSWORD-REJECTED;"); skip(1);
-               prouts("CONTINUITY-EFFECTED");
-               skip(2);
-               return;
-       }
-       prouts("PASSWORD-ACCEPTED"); skip(1);
-       prouts("                   5"); skip(1);
-       prouts("                      4"); skip(1);
-       prouts("                         3"); skip(1);
-       prouts("                            2"); skip(1);
-       prouts("                              1"); skip(1);
-       if (Rand() < 0.15) {
-               prouts("GOODBYE-CRUEL-WORLD");
-               skip(1);
-       }
-       kaboom();
+    }
+    kaboom();
 }
 
-void kaboom(void) {
-       stars();
-       if (ship==IHE) prouts("***");
-       prouts("********* Entropy of ");
-       crmshp();
-       prouts(" maximized *********");
-       skip(1);
-       stars();
-       skip(1);
-       if (nenhere != 0) {
-               double whammo = 25.0 * energy;
-               int l=1;
-               while (l <= nenhere) {
-                       if (game.kpower[l]*game.kdist[l] <= whammo) 
-                               deadkl(game.kx[l],game.ky[l], game.quad[game.kx[l]][game.ky[l]], game.kx[l], game.ky[l]);
-                       l++;
-               }
+void kaboom(void) 
+{
+    stars();
+    if (ship==IHE) prouts("***");
+    prouts("********* Entropy of ");
+    crmshp();
+    prouts(" maximized *********");
+    skip(1);
+    stars();
+    skip(1);
+    if (nenhere != 0) {
+       double whammo = 25.0 * energy;
+       int l=1;
+       while (l <= nenhere) {
+           if (game.kpower[l]*game.kdist[l] <= whammo) 
+               deadkl(game.kx[l],game.ky[l], game.quad[game.kx[l]][game.ky[l]], game.kx[l], game.ky[l]);
+           l++;
        }
-       finish(FDILITHIUM);
+    }
+    finish(FDILITHIUM);
 }
                                
 
-void finish(FINTYPE ifin) {
-       int igotit = 0;
-       alldone = 1;
-       skip(3);
-       prout("It is stardate %.1f.", game.state.date);
-        skip(1);
-       switch (ifin) {
-               case FWON: // Game has been won
-                       if (game.state.nromrem != 0)
-                               prout("The remaining %d Romulans surrender to Starfleet Command.",
-                                          game.state.nromrem);
+void finish(FINTYPE ifin) 
+{
+    int igotit = 0;
+    alldone = 1;
+    skip(3);
+    prout("It is stardate %.1f.", game.state.date);
+    skip(1);
+    switch (ifin) {
+    case FWON: // Game has been won
+       if (game.state.nromrem != 0)
+           prout("The remaining %d Romulans surrender to Starfleet Command.",
+                 game.state.nromrem);
 
-                       prout("You have smashed the Klingon invasion fleet and saved");
-                       prout("the Federation.");
-                       gamewon=1;
-                       if (alive) {
-                               double badpt;
-                               badpt = 5.*game.state.starkl + casual + 10.*game.state.nplankl +
-                                               45.*nhelp+100.*game.state.basekl;
-                               if (ship == IHF) badpt += 100.0;
-                               else if (ship == 0) badpt += 200.0;
-                               if (badpt < 100.0) badpt = 0.0; // Close enough!
-                               if (game.state.date-indate < 5.0 ||
-                                       // killsPerDate >= RateMax
-                                       (game.state.killk+game.state.killc+game.state.nsckill)/(game.state.date-indate) >=
-                                       0.1*skill*(skill+1.0) + 0.1 + 0.008*badpt) {
-                                       skip(1);
-                                       prout("In fact, you have done so well that Starfleet Command");
-                                       switch (skill) {
-                                               case 1:
-                                                       prout("promotes you one step in rank from \"Novice\" to \"Fair\".");
-                                                       break;
-                                               case 2:
-                                                       prout("promotes you one step in rank from \"Fair\" to \"Good\".");
-                                                       break;
-                                               case 3:
-                                                       prout("promotes you one step in rank from \"Good\" to \"Expert\".");
-                                                       break;
-                                               case 4:
-                                                       prout("promotes you to Commodore Emeritus.");
-                                                       skip(1);
-                                                       prout("Now that you think you're really good, try playing");
-                                                       prout("the \"Emeritus\" game. It will splatter your ego.");
-                                                       break;
-                                               case 5:
-                                                       skip(1);
-                                                        proutn("Computer-  ");
-                                                       prouts("ERROR-ERROR-ERROR-ERROR");
-                                                        skip(2);
-                                                        prouts("  YOUR-SKILL-HAS-EXCEEDED-THE-CAPACITY-OF-THIS-PROGRAM");
-                                                        skip(1);
-                                                        prouts("  THIS-PROGRAM-MUST-SURVIVE");
-                                                        skip(1);
-                                                        prouts("  THIS-PROGRAM-MUST-SURVIVE");
-                                                       skip(1);
-                                                        prouts("  THIS-PROGRAM-MUST-SURVIVE");
-                                                       skip(1);
-                                                        prouts("  THIS-PROGRAM-MUST?- MUST ? - SUR? ? -?  VI");
-                                                        skip(2);
-                                                       prout("Now you can retire and write your own Star Trek game!");
-                                                       skip(1);
-                                                       break;
-                                       }
-                                       if (skill > 3) {
-                                               if (thawed
+       prout("You have smashed the Klingon invasion fleet and saved");
+       prout("the Federation.");
+       gamewon=1;
+       if (alive) {
+           double badpt;
+           badpt = 5.0*game.state.starkl + casual + 10.0*game.state.nplankl +
+               45.*nhelp+100.*game.state.basekl;
+           if (ship == IHF) badpt += 100.0;
+           else if (ship == 0) badpt += 200.0;
+           if (badpt < 100.0) badpt = 0.0;     // Close enough!
+           if (game.state.date-indate < 5.0 ||
+               // killsPerDate >= RateMax
+               (game.state.killk+game.state.killc+game.state.nsckill)/(game.state.date-indate) >=
+               0.1*skill*(skill+1.0) + 0.1 + 0.008*badpt) {
+               skip(1);
+               prout("In fact, you have done so well that Starfleet Command");
+               switch (skill) {
+               case SKILL_NOVICE:
+                   prout("promotes you one step in rank from \"Novice\" to \"Fair\".");
+                   break;
+               case SKILL_FAIR:
+                   prout("promotes you one step in rank from \"Fair\" to \"Good\".");
+                   break;
+               case SKILL_GOOD:
+                   prout("promotes you one step in rank from \"Good\" to \"Expert\".");
+                   break;
+               case SKILL_EXPERT:
+                   prout("promotes you to Commodore Emeritus.");
+                   skip(1);
+                   prout("Now that you think you're really good, try playing");
+                   prout("the \"Emeritus\" game. It will splatter your ego.");
+                   break;
+               case SKILL_EMERITUS:
+                   skip(1);
+                   proutn("Computer-  ");
+                   prouts("ERROR-ERROR-ERROR-ERROR");
+                   skip(2);
+                   prouts("  YOUR-SKILL-HAS-EXCEEDED-THE-CAPACITY-OF-THIS-PROGRAM");
+                   skip(1);
+                   prouts("  THIS-PROGRAM-MUST-SURVIVE");
+                   skip(1);
+                   prouts("  THIS-PROGRAM-MUST-SURVIVE");
+                   skip(1);
+                   prouts("  THIS-PROGRAM-MUST-SURVIVE");
+                   skip(1);
+                   prouts("  THIS-PROGRAM-MUST?- MUST ? - SUR? ? -?  VI");
+                   skip(2);
+                   prout("Now you can retire and write your own Star Trek game!");
+                   skip(1);
+                   break;
+               }
+               if (skill >= SKILL_EXPERT) {
+                   if (thawed
 #ifdef DEBUG
-                                                       && !idebug
+                       && !idebug
 #endif
-                                                       )
-                                                       prout("You cannot get a citation, so...");
-                                               else {
-                                                       proutn("Do you want your Commodore Emeritus Citation printed? ");
-                                                       chew();
-                                                       if (ja()) {
-                                                               igotit = 1;
-                                                       }
-                                               }
-                                       }
-                               }
-                               // Only grant long life if alive (original didn't!)
-                               skip(1);
-                               prout("LIVE LONG AND PROSPER.");
+                       )
+                       prout("You cannot get a citation, so...");
+                   else {
+                       proutn("Do you want your Commodore Emeritus Citation printed? ");
+                       chew();
+                       if (ja()) {
+                           igotit = 1;
                        }
-                       score();
-                       if (igotit != 0) plaque();
-                       return;
-               case FDEPLETE: // Federation Resources Depleted
-                       prout("Your time has run out and the Federation has been");
-                       prout("conquered.  Your starship is now Klingon property,");
-                       prout("and you are put on trial as a war criminal.  On the");
-                       proutn("basis of your record, you are ");
-                       if (game.state.remkl*3.0 > inkling) {
-                               prout("aquitted.");
-                               skip(1);
-                               prout("LIVE LONG AND PROSPER.");
-                       }
-                       else {
-                               prout("found guilty and");
-                               prout("sentenced to death by slow torture.");
-                               alive = 0;
-                       }
-                       score();
-                       return;
-               case FLIFESUP:
-                       prout("Your life support reserves have run out, and");
-                       prout("you die of thirst, starvation, and asphyxiation.");
-                       prout("Your starship is a derelict in space.");
-                       break;
-               case FNRG:
-                       prout("Your energy supply is exhausted.");
-                       skip(1);
-                       prout("Your starship is a derelict in space.");
-                       break;
-               case FBATTLE:
-                       proutn("The ");
-                       crmshp();
-                       prout("has been destroyed in battle.");
-                       skip(1);
-                       prout("Dulce et decorum est pro patria mori.");
-                       break;
-               case FNEG3:
-                       prout("You have made three attempts to cross the negative energy");
-                       prout("barrier which surrounds the galaxy.");
-                       skip(1);
-                       prout("Your navigation is abominable.");
-                       score();
-                       return;
-               case FNOVA:
-                       prout("Your starship has been destroyed by a nova.");
-                       prout("That was a great shot.");
-                       skip(1);
-                       break;
-               case FSNOVAED:
-                       proutn("The ");
-                       crmshp();
-                       prout(" has been fried by a supernova.");
-                       prout("...Not even cinders remain...");
-                       break;
-               case FABANDN:
-                       prout("You have been captured by the Klingons. If you still");
-                       prout("had a starbase to be returned to, you would have been");
-                       prout("repatriated and given another chance. Since you have");
-                       prout("no starbases, you will be mercilessly tortured to death.");
-                       break;
-               case FDILITHIUM:
-                       prout("Your starship is now an expanding cloud of subatomic particles");
-                       break;
-               case FMATERIALIZE:
-                       prout("Starbase was unable to re-materialize your starship.");
-                       prout("Sic transit gloria muntdi");
-                       break;
-               case FPHASER:
-                       proutn("The ");
-                       crmshp();
-                       prout(" has been cremated by its own phasers.");
-                       break;
-               case FLOST:
-                       prout("You and your landing party have been");
-                       prout("converted to energy, disipating through space.");
-                       break;
-               case FMINING:
-                       prout("You are left with your landing party on");
-                       prout("a wild jungle planet inhabited by primitive cannibals.");
-                       skip(1);
-                       prout("They are very fond of \"Captain Kirk\" soup.");
-                       skip(1);
-                       proutn("Without your leadership, the ");
-                       crmshp();
-                       prout(" is destroyed.");
-                       break;
-               case FDPLANET:
-                       prout("You and your mining party perish.");
-                       skip(1);
-                       prout("That was a great shot.");
-                       skip(1);
-                       break;
-               case FSSC:
-                       prout("The Galileo is instantly annihilated by the supernova.");
-                       // no break;
-               case FPNOVA:
-                       prout("You and your mining party are atomized.");
-                       skip(1);
-                       proutn("Mr. Spock takes command of the ");
-                       crmshp();
-                       prout(" and");
-                       prout("joins the Romulans, reigning terror on the Federation.");
-                       break;
-               case FSTRACTOR:
-                       prout("The shuttle craft Galileo is also caught,");
-                       prout("and breaks up under the strain.");
-                       skip(1);
-                       prout("Your debris is scattered for millions of miles.");
-                       proutn("Without your leadership, the ");
-                       crmshp();
-                       prout(" is destroyed.");
-                       break;
-               case FDRAY:
-                       prout("The mutants attack and kill Spock.");
-                       prout("Your ship is captured by Klingons, and");
-                       prout("your crew is put on display in a Klingon zoo.");
-                       break;
-               case FTRIBBLE:
-                       prout("Tribbles consume all remaining water,");
-                       prout("food, and oxygen on your ship.");
-                       skip(1);
-                       prout("You die of thirst, starvation, and asphyxiation.");
-                       prout("Your starship is a derelict in space.");
-                       break;
-               case FHOLE:
-                       prout("Your ship is drawn to the center of the black hole.");
-                       prout("You are crushed into extremely dense matter.");
-                       break;
-       }
-       if (ship==IHF) ship= 0;
-       else if (ship == IHE) ship = IHF;
-       alive = 0;
-       if (game.state.remkl != 0) {
-               double goodies = game.state.remres/inresor;
-               double baddies = (game.state.remkl + 2.0*game.state.remcom)/(inkling+2.0*incom);
-               if (goodies/baddies >= 1.0+0.5*Rand()) {
-                       prout("As a result of your actions, a treaty with the Klingon");
-                       prout("Empire has been signed. The terms of the treaty are");
-                       if (goodies/baddies >= 3.0+Rand()) {
-                               prout("favorable to the Federation.");
-                               skip(1);
-                               prout("Congratulations!");
-                       }
-                       else
-                               prout("highly unfavorable to the Federation.");
+                   }
                }
-               else
-                       prout("The Federation will be destroyed.");
+           }
+           // Only grant long life if alive (original didn't!)
+           skip(1);
+           prout("LIVE LONG AND PROSPER.");
+       }
+       score();
+       if (igotit != 0) plaque();
+       return;
+    case FDEPLETE: // Federation Resources Depleted
+       prout("Your time has run out and the Federation has been");
+       prout("conquered.  Your starship is now Klingon property,");
+       prout("and you are put on trial as a war criminal.  On the");
+       proutn("basis of your record, you are ");
+       if (game.state.remkl*3.0 > inkling) {
+           prout("aquitted.");
+           skip(1);
+           prout("LIVE LONG AND PROSPER.");
        }
        else {
-               prout("Since you took the last Klingon with you, you are a");
-               prout("martyr and a hero. Someday maybe they'll erect a");
-               prout("statue in your memory. Rest in peace, and try not");
-               prout("to think about pigeons.");
-               gamewon = 1;
+           prout("found guilty and");
+           prout("sentenced to death by slow torture.");
+           alive = 0;
        }
        score();
+       return;
+    case FLIFESUP:
+       prout("Your life support reserves have run out, and");
+       prout("you die of thirst, starvation, and asphyxiation.");
+       prout("Your starship is a derelict in space.");
+       break;
+    case FNRG:
+       prout("Your energy supply is exhausted.");
+       skip(1);
+       prout("Your starship is a derelict in space.");
+       break;
+    case FBATTLE:
+       proutn("The ");
+       crmshp();
+       prout("has been destroyed in battle.");
+       skip(1);
+       prout("Dulce et decorum est pro patria mori.");
+       break;
+    case FNEG3:
+       prout("You have made three attempts to cross the negative energy");
+       prout("barrier which surrounds the galaxy.");
+       skip(1);
+       prout("Your navigation is abominable.");
+       score();
+       return;
+    case FNOVA:
+       prout("Your starship has been destroyed by a nova.");
+       prout("That was a great shot.");
+       skip(1);
+       break;
+    case FSNOVAED:
+       proutn("The ");
+       crmshp();
+       prout(" has been fried by a supernova.");
+       prout("...Not even cinders remain...");
+       break;
+    case FABANDN:
+       prout("You have been captured by the Klingons. If you still");
+       prout("had a starbase to be returned to, you would have been");
+       prout("repatriated and given another chance. Since you have");
+       prout("no starbases, you will be mercilessly tortured to death.");
+       break;
+    case FDILITHIUM:
+       prout("Your starship is now an expanding cloud of subatomic particles");
+       break;
+    case FMATERIALIZE:
+       prout("Starbase was unable to re-materialize your starship.");
+       prout("Sic transit gloria muntdi");
+       break;
+    case FPHASER:
+       proutn("The ");
+       crmshp();
+       prout(" has been cremated by its own phasers.");
+       break;
+    case FLOST:
+       prout("You and your landing party have been");
+       prout("converted to energy, disipating through space.");
+       break;
+    case FMINING:
+       prout("You are left with your landing party on");
+       prout("a wild jungle planet inhabited by primitive cannibals.");
+       skip(1);
+       prout("They are very fond of \"Captain Kirk\" soup.");
+       skip(1);
+       proutn("Without your leadership, the ");
+       crmshp();
+       prout(" is destroyed.");
+       break;
+    case FDPLANET:
+       prout("You and your mining party perish.");
+       skip(1);
+       prout("That was a great shot.");
+       skip(1);
+       break;
+    case FSSC:
+       prout("The Galileo is instantly annihilated by the supernova.");
+       // no break;
+    case FPNOVA:
+       prout("You and your mining party are atomized.");
+       skip(1);
+       proutn("Mr. Spock takes command of the ");
+       crmshp();
+       prout(" and");
+       prout("joins the Romulans, reigning terror on the Federation.");
+       break;
+    case FSTRACTOR:
+       prout("The shuttle craft Galileo is also caught,");
+       prout("and breaks up under the strain.");
+       skip(1);
+       prout("Your debris is scattered for millions of miles.");
+       proutn("Without your leadership, the ");
+       crmshp();
+       prout(" is destroyed.");
+       break;
+    case FDRAY:
+       prout("The mutants attack and kill Spock.");
+       prout("Your ship is captured by Klingons, and");
+       prout("your crew is put on display in a Klingon zoo.");
+       break;
+    case FTRIBBLE:
+       prout("Tribbles consume all remaining water,");
+       prout("food, and oxygen on your ship.");
+       skip(1);
+       prout("You die of thirst, starvation, and asphyxiation.");
+       prout("Your starship is a derelict in space.");
+       break;
+    case FHOLE:
+       prout("Your ship is drawn to the center of the black hole.");
+       prout("You are crushed into extremely dense matter.");
+       break;
+    }
+    if (ship==IHF) ship= 0;
+    else if (ship == IHE) ship = IHF;
+    alive = 0;
+    if (game.state.remkl != 0) {
+       double goodies = game.state.remres/inresor;
+       double baddies = (game.state.remkl + 2.0*game.state.remcom)/(inkling+2.0*incom);
+       if (goodies/baddies >= 1.0+0.5*Rand()) {
+           prout("As a result of your actions, a treaty with the Klingon");
+           prout("Empire has been signed. The terms of the treaty are");
+           if (goodies/baddies >= 3.0+Rand()) {
+               prout("favorable to the Federation.");
+               skip(1);
+               prout("Congratulations!");
+           }
+           else
+               prout("highly unfavorable to the Federation.");
+       }
+       else
+           prout("The Federation will be destroyed.");
+    }
+    else {
+       prout("Since you took the last Klingon with you, you are a");
+       prout("martyr and a hero. Someday maybe they'll erect a");
+       prout("statue in your memory. Rest in peace, and try not");
+       prout("to think about pigeons.");
+       gamewon = 1;
+    }
+    score();
 }
 
-void score(void) {
-       double timused = game.state.date - indate;
-       int ithperd, iwon, klship;
+void score(void) 
+{
+    double timused = game.state.date - indate;
+    int ithperd, iwon, klship;
 
-       iskill = skill;
-       if ((timused == 0 || game.state.remkl != 0) && timused < 5.0) timused = 5.0;
-       perdate = (game.state.killc + game.state.killk + game.state.nsckill)/timused;
-       ithperd = 500*perdate + 0.5;
-       iwon = 0;
-       if (gamewon) iwon = 100*skill;
-       if (ship == IHE) klship = 0;
-       else if (ship == IHF) klship = 1;
-       else klship = 2;
-       if (gamewon == 0) game.state.nromrem = 0; // None captured if no win
-       iscore = 10*game.state.killk + 50*game.state.killc + ithperd + iwon
-                        - 100*game.state.basekl - 100*klship - 45*nhelp -5*game.state.starkl - casual
-                        + 20*game.state.nromkl + 200*game.state.nsckill - 10*game.state.nplankl + game.state.nromrem;
-       if (alive == 0) iscore -= 200;
-       skip(2);
-       prout("Your score --");
-       if (game.state.nromkl)
-               prout("%6d Romulans destroyed                 %5d",
-                          game.state.nromkl,20*game.state.nromkl);
-       if (game.state.nromrem)
-               prout("%6d Romulans captured                  %5d",
-                          game.state.nromrem, game.state.nromrem);
-       if (game.state.killk)
-               prout("%6d ordinary Klingons destroyed        %5d",
-                          game.state.killk, 10*game.state.killk);
-       if (game.state.killc)
-               prout("%6d Klingon commanders destroyed       %5d",
-                          game.state.killc, 50*game.state.killc);
-       if (game.state.nsckill)
-               prout("%6d Super-Commander destroyed          %5d",
-                          game.state.nsckill, 200*game.state.nsckill);
-       if (ithperd)
-               prout("%6.2f Klingons per stardate              %5d",
-                          perdate, ithperd);
-       if (game.state.starkl)
-               prout("%6d stars destroyed by your action     %5d",
-                          game.state.starkl, -5*game.state.starkl);
-       if (game.state.nplankl)
-               prout("%6d planets destroyed by your action   %5d",
-                          game.state.nplankl, -10*game.state.nplankl);
-       if (game.state.basekl)
-               prout("%6d bases destroyed by your action     %5d",
-                          game.state.basekl, -100*game.state.basekl);
-       if (nhelp)
-               prout("%6d calls for help from starbase       %5d",
-                          nhelp, -45*nhelp);
-       if (casual)
-               prout("%6d casualties incurred                %5d",
-                          casual, -casual);
-       if (klship)
-               prout("%6d ship(s) lost or destroyed          %5d",
-                          klship, -100*klship);
-       if (alive==0)
-               prout("Penalty for getting yourself killed        -200");
-       if (gamewon) {
-               proutn("Bonus for winning ");
-               switch (skill) {
-                       case 1: proutn("Novice game  "); break;
-                       case 2: proutn("Fair game    "); break;
-                       case 3: proutn("Good game    "); break;
-                       case 4: proutn("Expert game  "); break;
-                       case 5: proutn("Emeritus game"); break;
-               }
-               prout("           %5d", iwon);
+    iskill = skill;
+    if ((timused == 0 || game.state.remkl != 0) && timused < 5.0) timused = 5.0;
+    perdate = (game.state.killc + game.state.killk + game.state.nsckill)/timused;
+    ithperd = 500*perdate + 0.5;
+    iwon = 0;
+    if (gamewon) iwon = 100*skill;
+    if (ship == IHE) klship = 0;
+    else if (ship == IHF) klship = 1;
+    else klship = 2;
+    if (gamewon == 0) game.state.nromrem = 0; // None captured if no win
+    iscore = 10*game.state.killk + 50*game.state.killc + ithperd + iwon
+       - 100*game.state.basekl - 100*klship - 45*nhelp -5*game.state.starkl - casual
+       + 20*game.state.nromkl + 200*game.state.nsckill - 10*game.state.nplankl + game.state.nromrem;
+    if (alive == 0) iscore -= 200;
+    skip(2);
+    prout("Your score --");
+    if (game.state.nromkl)
+       prout("%6d Romulans destroyed                 %5d",
+             game.state.nromkl,20*game.state.nromkl);
+    if (game.state.nromrem)
+       prout("%6d Romulans captured                  %5d",
+             game.state.nromrem, game.state.nromrem);
+    if (game.state.killk)
+       prout("%6d ordinary Klingons destroyed        %5d",
+             game.state.killk, 10*game.state.killk);
+    if (game.state.killc)
+       prout("%6d Klingon commanders destroyed       %5d",
+             game.state.killc, 50*game.state.killc);
+    if (game.state.nsckill)
+       prout("%6d Super-Commander destroyed          %5d",
+             game.state.nsckill, 200*game.state.nsckill);
+    if (ithperd)
+       prout("%6.2f Klingons per stardate              %5d",
+             perdate, ithperd);
+    if (game.state.starkl)
+       prout("%6d stars destroyed by your action     %5d",
+             game.state.starkl, -5*game.state.starkl);
+    if (game.state.nplankl)
+       prout("%6d planets destroyed by your action   %5d",
+             game.state.nplankl, -10*game.state.nplankl);
+    if (game.state.basekl)
+       prout("%6d bases destroyed by your action     %5d",
+             game.state.basekl, -100*game.state.basekl);
+    if (nhelp)
+       prout("%6d calls for help from starbase       %5d",
+             nhelp, -45*nhelp);
+    if (casual)
+       prout("%6d casualties incurred                %5d",
+             casual, -casual);
+    if (klship)
+       prout("%6d ship(s) lost or destroyed          %5d",
+             klship, -100*klship);
+    if (alive==0)
+       prout("Penalty for getting yourself killed        -200");
+    if (gamewon) {
+       proutn("Bonus for winning ");
+       switch (skill) {
+       case SKILL_NOVICE:   proutn("Novice game  "); break;
+       case SKILL_FAIR:     proutn("Fair game    "); break;
+       case SKILL_GOOD:     proutn("Good game    "); break;
+       case SKILL_EXPERT:   proutn("Expert game  "); break;
+       case SKILL_EMERITUS: proutn("Emeritus game"); break;
        }
-       skip(1);
-       prout("TOTAL SCORE                               %5d", iscore);
+       prout("           %5d", iwon);
+    }
+    skip(1);
+    prout("TOTAL SCORE                               %5d", iscore);
 }
 
 void plaque(void) {
@@ -435,8 +439,8 @@ void plaque(void) {
        fprintf(fp, "                                                       \"Commodore Emeritus\"\n\n");
        fprintf(fp, "                                                          ");
        switch (iskill) {
-               case 4: fprintf(fp," Expert level\n\n"); break;
-               case 5: fprintf(fp,"Emeritus level\n\n"); break;
+               case SKILL_EXPERT: fprintf(fp," Expert level\n\n"); break;
+               case SKILL_EMERITUS: fprintf(fp,"Emeritus level\n\n"); break;
                default: fprintf(fp," Cheat level\n\n"); break;
        }
        t = time(NULL);
diff --git a/io.c b/io.c
index e14e85366602af9408dd21f5a180a8fc40f00b75..fc173f7182c0baac431cdb9363a5279f6447ed68 100644 (file)
--- a/io.c
+++ b/io.c
@@ -82,13 +82,13 @@ void pause_game(int i)
     char *prompt;
     char buf[BUFSIZ];
     if (i==1) {
-       if (skill > 2)
+       if (skill > SKILL_FAIR)
            prompt = "[ANOUNCEMENT ARRIVING...]";
        else
            prompt = "[IMPORTANT ANNOUNCEMENT ARRIVING -- PRESS ENTER TO CONTINUE]";
     }
     else {
-       if (skill > 2)
+       if (skill > SKILL_FAIR)
            prompt = "[CONTINUE?]";
        else
            prompt = "[PRESS ENTER TO CONTINUE]";
index d12c4abcd227e7a0b280982b443fc72cf60bc25a..0c91f71cd33886e3f907c6adfd1db0ae8a329091 100644 (file)
--- a/moving.c
+++ b/moving.c
 
 static void getcd(int, int);
 
-void imove(void) {
-       double angle, deltax, deltay, bigger, x, y,
+void imove(void) 
+{
+    double angle, deltax, deltay, bigger, x, y,
         finald, finalx, finaly, stopegy, probf;
-        int trbeam = 0, n, l, ix=0, iy=0, kink, kinks, iquad;
-
-       if (inorbit) {
-               prout("Helmsman Sulu- \"Leaving standard orbit.\"");
-               inorbit = 0;
-       }
-
-       angle = ((15.0 - direc) * 0.5235988);
-       deltax = -sin(angle);
-       deltay = cos(angle);
-       if (fabs(deltax) > fabs(deltay))
-               bigger = fabs(deltax);
-       else
-               bigger = fabs(deltay);
+    int trbeam = 0, n, l, ix=0, iy=0, kink, kinks, iquad;
+
+    if (inorbit) {
+       prout("Helmsman Sulu- \"Leaving standard orbit.\"");
+       inorbit = FALSE;
+    }
+
+    angle = ((15.0 - direc) * 0.5235988);
+    deltax = -sin(angle);
+    deltay = cos(angle);
+    if (fabs(deltax) > fabs(deltay))
+       bigger = fabs(deltax);
+    else
+       bigger = fabs(deltay);
                
-       deltay /= bigger;
-       deltax /= bigger;
-
-       /* If tractor beam is to occur, don't move full distance */
-       if (game.state.date+Time >= game.future[FTBEAM]) {
-               trbeam = 1;
-               condit = IHRED;
-               dist = dist*(game.future[FTBEAM]-game.state.date)/Time + 0.1;
-               Time = game.future[FTBEAM] - game.state.date + 1e-5;
-       }
-       /* Move within the quadrant */
-       game.quad[sectx][secty] = IHDOT;
-       x = sectx;
-       y = secty;
-       n = 10.0*dist*bigger+0.5;
-
-       if (n > 0) {
-               for (l = 1; l <= n; l++) {
-                       ix = (x += deltax) + 0.5;
-                       iy = (y += deltay) + 0.5;
-                       if (ix < 1 || ix > QUADSIZE || iy < 1 || iy > QUADSIZE) {
-                               /* Leaving quadrant -- allow final enemy attack */
-                               /* Don't do it if being pushed by Nova */
-                               if (nenhere != 0 && iattak != 2) {
-                                       newcnd();
-                                       for (l = 1; l <= nenhere; l++) {
-                                               finald = sqrt((ix-game.kx[l])*(double)(ix-game.kx[l]) +
-                                                                         (iy-game.ky[l])*(double)(iy-game.ky[l]));
-                                               game.kavgd[l] = 0.5 * (finald+game.kdist[l]);
-                                       }
-                                       /*
-                                        * Stas Sergeev added the condition
-                                        * that attacks only happen if Klingons
-                                        * are present and your skill is > 3.
-                                        */
-                                        if (skill > 3 && klhere > 0 && game.state.galaxy[quadx][quady] != SUPERNOVA_PLACE)
-                                           attack(0);
-                                       if (alldone) return;
-                               }
-                               /* compute final position -- new quadrant and sector */
-                               x = QUADSIZE*(quadx-1)+sectx;
-                               y = QUADSIZE*(quady-1)+secty;
-                               ix = x+10.0*dist*bigger*deltax+0.5;
-                               iy = y+10.0*dist*bigger*deltay+0.5;
-                               /* check for edge of galaxy */
-                               kinks = 0;
-                               do {
-                                       kink = 0;
-                                       if (ix <= 0) {
-                                               ix = -ix + 1;
-                                               kink = 1;
-                                       }
-                                       if (iy <= 0) {
-                                               iy = -iy + 1;
-                                               kink = 1;
-                                       }
-                                       if (ix > GALSIZE*QUADSIZE) {
-                                               ix = 161 - ix;
-                                               kink = 1;
-                                       }
-                                       if (iy > GALSIZE*QUADSIZE) {
-                                               iy = 161 - iy;
-                                               kink = 1;
-                                       }
-                                       if (kink) kinks = 1;
-                               } while (kink);
-
-                               if (kinks) {
-                                       nkinks += 1;
-                                       if (nkinks == 3) {
-                                               /* Three strikes -- you're out! */
-                                               finish(FNEG3);
-                                               return;
-                                       }
-                                        prout("\n\rYOU HAVE ATTEMPTED TO CROSS THE NEGATIVE ENERGY BARRIER\n\r"
-                                                 "AT THE EDGE OF THE GALAXY.  THE THIRD TIME YOU TRY THIS,\n\r"
-                                                 "YOU WILL BE DESTROYED.\n\r");
-                               }
-                               /* Compute final position in new quadrant */
-                               if (trbeam) return; /* Don't bother if we are to be beamed */
-                               quadx = (ix+9)/QUADSIZE;
-                               quady = (iy+9)/QUADSIZE;
-                               sectx = ix - QUADSIZE*(quadx-1);
-                               secty = iy - QUADSIZE*(quady-1);
-                               prout("\n\rEntering %s.",
-                                     cramlc(quadrant, quadx, quady));
-                               game.quad[sectx][secty] = ship;
-                               newqad(0);
-                                if (skill>1) attack(0);
-                               return;
-                       }
-                       iquad = game.quad[ix][iy];
-                       if (iquad != IHDOT) {
-                               /* object encountered in flight path */
-                               stopegy = 50.0*dist/Time;
-                               dist=0.1*sqrt((sectx-ix)*(double)(sectx-ix) +
-                                                         (secty-iy)*(double)(secty-iy));
-                               switch (iquad) {
-                                       case IHT: /* Ram a Tholian */
-                                       case IHK: /* Ram enemy ship */
-                                       case IHC:
-                                       case IHS:
-                                       case IHR:
-                                        case IHQUEST:
-                                               sectx = ix;
-                                               secty = iy;
-                                               ram(0, iquad, sectx, secty);
-                                               finalx = sectx;
-                                               finaly = secty;
-                                               break;
-                                       case IHBLANK:
-                                               skip(1);
-                                               prouts("***RED ALERT!  RED ALERT!");
-                                               skip(1);
-                                               proutn("***");
-                                               crmshp();
-                                               proutn(" pulled into black hole at ");
-                                               prout(cramlc(sector, ix, iy));
-                                               /*
-                                                * Getting pulled into a black 
-                                                * hole was certain death in
-                                                * Almy's original.  Stas 
-                                                * Sergeev added a possibility
-                                                * that you'll get timewarped
-                                                * instead.
-                                                */
-                                                n=0;
-                                                for (l=1;l<=NDEVICES+1;l++)
-                                                    if (game.damage[l]>0) n++;
-                                                probf=pow(1.4,(energy+shield)/5000.0-1.0)*
-                                                       pow(1.3,1.0/(n+1)-1.0);
-                                                if (Rand()>probf) 
-                                                   timwrp();
-                                                else 
-                                                   finish(FHOLE);
-                                               return;
-                                       default:
-                                               /* something else */
-                                               skip(1);
-                                               crmshp();
-                                               if (iquad == IHWEB)
-                                                       proutn(" encounters Tholian web at ");
-                                               else
-                                                       proutn(" blocked by object at ");
-                                               proutn(cramlc(sector, ix,iy));
-                                               prout(";");
-                                               proutn("Emergency stop required ");
-                                               prout("%2d units of energy.", (int)stopegy);
-                                               energy -= stopegy;
-                                               finalx = x-deltax+0.5;
-                                               sectx = finalx;
-                                               finaly = y-deltay+0.5;
-                                               secty = finaly;
-                                               if (energy <= 0) {
-                                                       finish(FNRG);
-                                                       return;
-                                               }
-                                               break;
-                               }
-                               goto label100;  /* sorry! */
-                       }
-               }
-               dist = 0.1*sqrt((sectx-ix)*(double)(sectx-ix) +
-                                               (secty-iy)*(double)(secty-iy));
-               sectx = ix;
-               secty = iy;
-       }
-       finalx = sectx;
-       finaly = secty;
-label100:
-       /* No quadrant change -- compute new avg enemy distances */