First round of changes from Stas Sergeev.
[super-star-trek.git] / battle.c
index d47671174b0b67fa631c1fbf091d34005c4327d0..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
@@ -191,10 +193,7 @@ void torpedo(double course, double r, int inx, int iny, double *hit) {
                iy = y + 0.5;\r
                if (iy < 1 || iy > 10) break;\r
                if (l==4 || l==9) skip(1);\r
-               cramf(x, 0, 1);\r
-               proutn(" - ");\r
-               cramf(y, 0, 1);\r
-               proutn("   ");\r
+               proutn("%d - %d   ", (int)x, (int)y);\r
                iquad=game.quad[ix][iy];\r
                if (iquad==IHDOT) continue;\r
                /* hit something */\r
@@ -212,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
@@ -282,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
@@ -327,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
@@ -347,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
@@ -360,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
@@ -367,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
@@ -385,9 +395,7 @@ void torpedo(double course, double r, int inx, int iny, double *hit) {
        if (shoved) {\r
                game.quad[jx][jy]=iquad;\r
                game.quad[ix][iy]=IHDOT;\r
-               proutn(" displaced by blast to");\r
-               cramlc(2, jx, jy);\r
-               skip(1);\r
+               prout(" displaced by blast to %s ", cramlc(sector, jx, jy));\r
                for (ll=1; ll<=nenhere; ll++)\r
                        game.kdist[ll] = game.kavgd[ll] = sqrt(square(sectx-game.kx[ll])+square(secty-game.ky[ll]));\r
                sortkl();\r
@@ -400,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
@@ -408,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
@@ -452,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
@@ -468,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
@@ -489,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
@@ -498,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
@@ -515,8 +525,7 @@ void attack(int k) {
                               shields were down for some strange reason. This\r
                                           doesn't make any sense, so I've fixed it */\r
                ihurt = 1;\r
-               cramf(hit, 0, 2);\r
-               proutn(" unit hit");\r
+               proutn("%d unit hit", (int)hit);\r
                if ((game.damage[DSRSENS] > 0 && itflag) || skill <= 2) {\r
                        proutn(" on the ");\r
                        crmshp();\r
@@ -590,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
@@ -628,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
@@ -664,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
@@ -710,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
@@ -862,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
@@ -959,9 +972,7 @@ void phasers(void) {
                                key = scan();\r
                        }\r
                        if (key != IHREAL && nenhere != 0) {\r
-                               proutn("Phasers locked on target. Energy available =");\r
-                               cramf(ifast?energy-200.0:energy,1,2);\r
-                               skip(1);\r
+                               prout("Phasers locked on target. Energy available: %.2f", ifast?energy-200.0:energy);\r
                        }\r
                        do {\r
                                while (key != IHREAL) {\r
@@ -971,8 +982,8 @@ void phasers(void) {
                                }\r
                                rpow = aaitem;\r
                                if (rpow >= (ifast?energy-200:energy)) {\r
-                                       proutn("Energy available= ");\r
-                                       cramf(ifast?energy-200:energy, 1,2);\r
+                                   proutn("Energy available= %.2f",\r
+                                       ifast?energy-200:energy);\r
                                        skip(1);\r
                                        key = IHEOL;\r
                                }\r
@@ -1017,8 +1028,7 @@ void phasers(void) {
                                        prout("phaser energy.");\r
                                }\r
                                else {\r
-                                       cramf(extra, 0, 2);\r
-                                       prout(" expended on empty space.");\r
+                                       prout("%d expended on empty space.", (int)extra);\r
                                }\r
                        }\r
                        break;\r
@@ -1043,8 +1053,8 @@ void phasers(void) {
                                int ii = game.kx[k], jj = game.ky[k];\r
                                int ienm = game.quad[ii][jj];\r
                                if (msgflag) {\r
-                                       proutn("Energy available= ");\r
-                                       cramf(energy-.006-(ifast?200:0), 0, 2);\r
+                                       proutn("Energy available= %.2f",\r
+                                              energy-.006-(ifast?200:0));\r
                                        skip(1);\r
                                        msgflag = 0;\r
                                        rpow = 0.0;\r
@@ -1090,7 +1100,6 @@ void phasers(void) {
                                }\r
                                if (aaitem < 0) {\r
                                        /* abort out */\r
-                                       ididit = 0;\r
                                        chew();\r
                                        return;\r
                                }\r
@@ -1115,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
@@ -1165,12 +1174,12 @@ void hittem(double *hits) {
                ii = game.kx[kk];\r
                jj = game.ky[kk];\r
                if (hit > 0.005) {\r
-                       cramf(hit, 0, 2);\r
-                       proutn(" unit hit on ");\r
+                       proutn("%d unit hit on ", (int)hit);\r
                }\r
                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
@@ -1182,9 +1191,8 @@ void hittem(double *hits) {
                else /* decide whether or not to emasculate klingon */\r
                        if (kpow > 0 && Rand() >= 0.9 &&\r
                                kpow <= ((0.4 + 0.4*Rand())*kpini)) {\r
-                               proutn("***Mr. Spock-  \"Captain, the vessel at");\r
-                               cramlc(2,ii,jj);\r
-                               skip(1);\r
+                               prout("***Mr. Spock-  \"Captain, the vessel at ",\r
+                                       cramlc(sector,ii,jj));\r
                                prout("   has just lost its firepower.\"");\r
                                game.kpower[kk] = -kpow;\r
                        }\r