First round of changes from Stas Sergeev.
[super-star-trek.git] / battle.c
index 5a29bb8ea4f16545d75cb3c54a331f68eee4ba13..dd102aa8e250464188ddcaf3ad3ae46eb3e642c7 100644 (file)
--- a/battle.c
+++ b/battle.c
@@ -124,6 +124,7 @@ void doshield(int i) {
                        shield += aaitem;\r
                        energy -= aaitem;\r
                        return;\r
+               case NONE:;     /* avoid gcc warning */\r
        }\r
 }\r
 \r
@@ -142,6 +143,7 @@ void ram(int ibumpd, int ienm, int ix, int iy) {
                case IHC: type = 2.0; break;\r
                case IHS: type = 2.5; break;\r
                case IHT: type = 0.5; break;\r
+                case IHQUEST: type = 4.0; break;\r
        }\r
        proutn(ibumpd ? " rammed by " : " rams ");\r
        crmena(0, ienm, 2, ix, iy);\r
@@ -162,7 +164,7 @@ void ram(int ibumpd, int ienm, int ix, int iy) {
        }\r
        shldup = 0;\r
        if (game.state.remkl) {\r
-               pause(2);\r
+               pause_game(2);\r
                dreprt();\r
        }\r
        else finish(FWON);\r
@@ -209,7 +211,7 @@ void torpedo(double course, double r, int inx, int iny, double *hit) {
                                *hit = fabs(*hit);\r
                                newcnd(); /* undock */\r
                                /* We may be displaced. */\r
-                               if (landed==1) return; /* Cheat if on a planet */\r
+                               if (landed==1 || condit==IHDOCKED) return; /* Cheat if on a planet */\r
                                ang = angle + 2.5*(Rand()-0.5);\r
                                temp = fabs(sin(ang));\r
                                if (fabs(cos(ang)) > temp) temp = fabs(cos(ang));\r
@@ -279,12 +281,13 @@ void torpedo(double course, double r, int inx, int iny, double *hit) {
                                        prout(" damaged but not destroyed.");\r
                                        return;\r
                                }\r
-                               prout(" damaged--");\r
+                               proutn(" damaged--");\r
                                game.kx[ll] = jx;\r
                                game.ky[ll] = jy;\r
                                shoved = 1;\r
                                break;\r
                        case IHB: /* Hit a base */\r
+                               skip(1);\r
                                prout("***STARBASE DESTROYED..");\r
                                if (game.starch[quadx][quady] < 0) game.starch[quadx][quady] = 0;\r
                                for (ll=1; ll<=game.state.rembase; ll++) {\r
@@ -324,16 +327,25 @@ void torpedo(double course, double r, int inx, int iny, double *hit) {
                                prout(" unaffected by photon blast.");\r
                                return;\r
                        case IHQUEST: /* Hit a thingy */\r
+                            if (Rand()>0.7) {  // Used to be certain death \r
                                skip(1);\r
                                prouts("AAAAIIIIEEEEEEEEAAAAAAAAUUUUUGGGGGHHHHHHHHHHHH!!!");\r
                                skip(1);\r
                                prouts("    HACK!     HACK!    HACK!        *CHOKE!*  ");\r
                                skip(1);\r
                                proutn("Mr. Spock-");\r
-                               prouts("  \"Facinating!\"");\r
+                               prouts("  \"Fascinating!\"");\r
                                skip(1);\r
-                               game.quad[ix][iy] = IHDOT;\r
-                               return;\r
+                                deadkl(ix, iy, iquad, ix, iy);\r
+                            } else {\r
+                               /*\r
+                                * Stas Sergeev added the possibility that\r
+                                * you can shove the Thingy.\r
+                                */\r
+                                iqengry=1;\r
+                                shoved=1;\r
+                            }\r
+                           return;\r
                        case IHBLANK: /* Black hole */\r
                                skip(1);\r
                                crmena(1, IHBLANK, 2, ix, iy);\r
@@ -344,8 +356,6 @@ void torpedo(double course, double r, int inx, int iny, double *hit) {
                                prout("***Torpedo absorbed by Tholian web.");\r
                                return;\r
                        case IHT:  /* Hit a Tholian */\r
-                               skip(1);\r
-                               crmena(1, IHT, 2, ix, iy);\r
                                h1 = 700.0 + 100.0*Rand() -\r
                                         1000.0*sqrt(square(ix-inx)+square(iy-iny))*\r
                                         fabs(sin(bullseye-angle));\r
@@ -357,6 +367,8 @@ void torpedo(double course, double r, int inx, int iny, double *hit) {
                                        ithx = ithy = 0;\r
                                        return;\r
                                }\r
+                               skip(1);\r
+                               crmena(1, IHT, 2, ix, iy);\r
                                if (Rand() > 0.05) {\r
                                        prout(" survives photon blast.");\r
                                        return;\r
@@ -364,6 +376,7 @@ void torpedo(double course, double r, int inx, int iny, double *hit) {
                                prout(" disappears.");\r
                                game.quad[ix][iy] = IHWEB;\r
                                ithere = ithx = ithy = 0;\r
+                               nenhere--;\r
                                {\r
                                        int dum, my;\r
                                        dropin(IHBLANK, &dum, &my);\r
@@ -395,7 +408,7 @@ void torpedo(double course, double r, int inx, int iny, double *hit) {
 \r
 static void fry(double hit) {\r
        double ncrit, extradm;\r
-       int ktr=1, l, ll, j, cdam[6], crptr;\r
+       int ktr=1, l, ll, j, cdam[NDEVICES+1], crptr;\r
 \r
        /* a critical hit occured */\r
        if (hit < (275.0-25.0*skill)*(1.0+0.5*Rand())) return;\r
@@ -403,7 +416,7 @@ static void fry(double hit) {
        ncrit = 1.0 + hit/(500.0+100.0*Rand());\r
        proutn("***CRITICAL HIT--");\r
        /* Select devices and cause damage */\r
-       for (l = 1; l <= ncrit; l++) {\r
+       for (l = 1; l <= ncrit && l <= NDEVICES; l++) {\r
                do {\r
                        j = NDEVICES*Rand()+1.0;\r
                        /* Cheat to prevent shuttle damage unless on ship */\r
@@ -447,8 +460,8 @@ void attack(int k) {
                neutz = 0;\r
                return;\r
        }\r
-       if (((comhere || ishere) && (justin == 0)) || skill == 5) movcom();\r
-       if (nenhere==0) return;\r
+       if ((((comhere || ishere) && (justin == 0)) || skill == 5)&&(k!=0)) movcom();\r
+       if (nenhere==0 || (nenhere==1 && iqhere && iqengry==0)) return;\r
        pfac = 1.0/inshld;\r
        if (shldchg == 1) chgfac = 0.25+0.5*Rand();\r
        skip(1);\r
@@ -463,10 +476,12 @@ void attack(int k) {
                jx = game.kx[l];\r
                jy = game.ky[l];\r
                iquad = game.quad[jx][jy];\r
+                if (iquad==IHT || (iquad==IHQUEST && !iqengry)) continue;\r
                itflag = (iquad == IHK && r > 0.0005) || k == 0 ||\r
                        (iquad==IHC && r > 0.015) ||\r
                        (iquad==IHR && r > 0.3) ||\r
-                       (iquad==IHS && r > 0.07);\r
+                        (iquad==IHS && r > 0.07) ||\r
+                        (iquad==IHQUEST && r > 0.05);\r
                if (itflag) {\r
                        /* Enemy uses phasers */\r
                        if (condit == IHDOCKED) continue; /* Don't waste the effort! */\r
@@ -484,7 +499,7 @@ void attack(int k) {
                                crmena(0, iquad, i, jx, jy);\r
                        }\r
                        attempt = 1;\r
-                       prout("--");\r
+                       prout("  ");\r
                        r = (Rand()+Rand())*0.5 -0.5;\r
                        r += 0.002*game.kpower[l]*r;\r
                        torpedo(course, r, jx, jy, &hit);\r
@@ -493,9 +508,9 @@ void attack(int k) {
                                alldone) return; /* Supernova or finished */\r
                        if (hit == 0) continue;\r
                }\r
-               if (shldup != 0 || shldchg != 0) {\r
+                if (shldup != 0 || shldchg != 0 || condit==IHDOCKED) {\r
                        /* shields will take hits */\r
-                       double absorb, hitsh, propor = pfac*shield;\r
+                        double absorb, hitsh, propor = pfac*shield*(condit==IHDOCKED ? 2.1 : 1.0);\r
                        if(propor < 0.1) propor = 0.1;\r
                        hitsh = propor*chgfac*hit+1.0;\r
                        atackd=1;\r
@@ -584,6 +599,10 @@ void deadkl(int ix, int iy, int type, int ixx, int iyy) {
                /* Killed a Tholian */\r
                ithere = 0;\r
        }\r
+        else if (type == IHQUEST) {\r
+               /* Killed a Thingy */\r
+             iqhere=iqengry=thingx=thingy=0;\r
+        }\r
        else {\r
                /* Some type of a Klingon */\r
                game.state.galaxy[quadx][quady] -= 100;\r
@@ -622,10 +641,9 @@ void deadkl(int ix, int iy, int type, int ixx, int iyy) {
 \r
        game.state.remtime = game.state.remres/(game.state.remkl + 4*game.state.remcom);\r
 \r
-       if (type == IHT) return;\r
-\r
        /* Remove enemy ship from arrays describing local conditions */\r
-\r
+        if (game.future[FCDBAS] < 1e30 && batx==quadx && baty==quady && type==IHC)\r
+           game.future[FCDBAS] = 1e30;\r
        for (i=1; i<=nenhere; i++)\r
                if (game.kx[i]==ix && game.ky[i]==iy) break;\r
        nenhere--;\r
@@ -658,7 +676,7 @@ static int targetcheck(double x, double y, double *course) {
                skip(1);\r
                prout("Spock-  \"Bridge to sickbay.  Dr. McCoy,");\r
                prout("  I recommend an immediate review of");\r
-               prout("  the Captain's psychological profile.");\r
+               prout("  the Captain's psychological profile.\"");\r
                chew();\r
                return 1;\r
        }\r
@@ -704,6 +722,7 @@ void photon(void) {
                                chew();\r
                                prout("Maximum of 3 torpedoes per burst.");\r
                                key = IHEOL;\r
+                                return;\r
                        }\r
                        if (n <= torps) break;\r
                        chew();\r
@@ -856,7 +875,7 @@ void phasers(void) {
        int kz = 0, k=1, i; /* Cheating inhibitor */\r
        int ifast=0, no=0, ipoop=1, msgflag = 1;\r
        enum {NOTSET, MANUAL, FORCEMAN, AUTOMATIC} automode = NOTSET;\r
-       int key;\r
+       int key=0;\r
 \r
        skip(1);\r
        /* SR sensors and Computer */\r
@@ -953,7 +972,7 @@ void phasers(void) {
                                key = scan();\r
                        }\r
                        if (key != IHREAL && nenhere != 0) {\r
-                               prout("Phasers locked on target. Energy available = %.2f", ifast?energy-200.0:energy);\r
+                               prout("Phasers locked on target. Energy available: %.2f", ifast?energy-200.0:energy);\r
                        }\r
                        do {\r
                                while (key != IHREAL) {\r
@@ -1081,7 +1100,6 @@ void phasers(void) {
                                }\r
                                if (aaitem < 0) {\r
                                        /* abort out */\r
-                                       ididit = 0;\r
                                        chew();\r
                                        return;\r
                                }\r
@@ -1106,7 +1124,7 @@ void phasers(void) {
                                chew();\r
                                return;\r
                        }\r
-                       if (key == IHALPHA & isit("no")) {\r
+                       if (key == IHALPHA && isit("no")) {\r
                                no = 1;\r
                        }\r
                        energy -= rpow;\r
@@ -1161,6 +1179,7 @@ void hittem(double *hits) {
                else\r
                        proutn("Very small hit on ");\r
                ienm = game.quad[ii][jj];\r
+                if (ienm==IHQUEST) iqengry=1;\r
                crmena(0,ienm,2,ii,jj);\r
                skip(1);\r
                if (kpow == 0) {\r