First round of changes from Stas Sergeev.
[super-star-trek.git] / ai.c
diff --git a/ai.c b/ai.c
index 3deab689799c2bc2a91c56db62eea833a24c5358..ba970a36ee9f18dcdbf2f43aa1fcf564e19788cc 100644 (file)
--- a/ai.c
+++ b/ai.c
@@ -24,12 +24,12 @@ static int tryexit(int lookx, int looky, int ienm, int loccom, int irun) {
           We know this if either short or long range sensors are working */\r
        if (game.damage[DSRSENS] == 0.0 || game.damage[DLRSENS] == 0.0 ||\r
                condit == IHDOCKED) {\r
-               proutn("***");\r
-               cramen(ienm);\r
+               crmena(1, ienm, 2, game.kx[loccom], game.ky[loccom]);\r
                proutn(" escapes to %s (and regains strength).",\r
                       cramlc(quadrant, iqx, iqy));\r
        }\r
        /* handle local matters related to escape */\r
+       game.quad[game.kx[loccom]][game.ky[loccom]] = IHDOT;\r
        game.kx[loccom] = game.kx[nenhere];\r
        game.ky[loccom] = game.ky[nenhere];\r
        game.kavgd[loccom] = game.kavgd[nenhere];\r
@@ -181,7 +181,6 @@ static void movebaddy(int comx, int comy, int loccom, int ienm) {
        if (my != 0) my = my*motion < 0 ? -1 : 1;\r
        nextx = comx;\r
        nexty = comy;\r
-       game.quad[comx][comy] = IHDOT;\r
        /* main move loop */\r
        for (ll = 1; ll <= nsteps; ll++) {\r
 #ifdef DEBUG\r
@@ -242,6 +241,7 @@ static void movebaddy(int comx, int comy, int loccom, int ienm) {
                else break; /* done early */\r
        }\r
        /* Put commander in place within same quadrant */\r
+       game.quad[comx][comy] = IHDOT;\r
        game.quad[nextx][nexty] = ienm;\r
        if (nextx != comx || nexty != comy) {\r
                /* it moved */\r
@@ -252,6 +252,8 @@ static void movebaddy(int comx, int comy, int loccom, int ienm) {
                if (game.damage[DSRSENS] == 0 || condit == IHDOCKED) {\r
                        proutn("***");\r
                        cramen(ienm);\r
+                       proutn(" from");\r
+                       cramlc(2, comx, comy);\r
                        if (game.kdist[loccom] < dist1) proutn(" advances to");\r
                        else proutn(" retreats to ");\r
                        prout(cramlc(sector, nextx, nexty));\r
@@ -297,8 +299,8 @@ void movcom(void) {
        sortkl();\r
 }\r
 \r
-static int checkdest(int iqx, int iqy, int flag, int *ipage) {\r
-       int i, j;\r
+static int movescom(int iqx, int iqy, int flag, int *ipage) {\r
+       int i;\r
 \r
        if ((iqx==quadx && iqy==quady) ||\r
                iqx < 1 || iqx > 8 || iqy < 1 || iqy > 8 ||\r
@@ -308,13 +310,13 @@ static int checkdest(int iqx, int iqy, int flag, int *ipage) {
                for (i = 1; i <= game.state.rembase; i++)\r
                        if (game.state.baseqx[i]==iqx && game.state.baseqy[i]==iqy) return 1;\r
        }\r
-\r
+       if (justin && !iscate) return 1;\r
        /* do the move */\r
        game.state.galaxy[game.state.isx][game.state.isy] -= 100;\r
        game.state.isx = iqx;\r
        game.state.isy = iqy;\r
        game.state.galaxy[game.state.isx][game.state.isy] += 100;\r
-       if (iscate) {\r
+       if (ishere) {\r
                /* SC has scooted, Remove him from current quadrant */\r
                iscate=0;\r
                isatb=0;\r
@@ -342,7 +344,7 @@ static int checkdest(int iqx, int iqy, int flag, int *ipage) {
                        DESTROY(&game.state.plnets[i]);\r
                        game.state.newstuf[game.state.isx][game.state.isy] -= 1;\r
                        if (game.damage[DRADIO] == 0.0 || condit == IHDOCKED) {\r
-                               if (*ipage==0) pause(1);\r
+                               if (*ipage==0) pause_game(1);\r
                                *ipage = 1;\r
                                prout("Lt. Uhura-  \"Captain, Starfleet Intelligence reports");\r
                                proutn("   a planet in ");\r
@@ -458,32 +460,32 @@ void scom(int *ipage) {
        /* try moving in both x and y directions */\r
        iqx = game.state.isx + ideltax;\r
        iqy = game.state.isy + ideltax;\r
-       if (checkdest(iqx, iqy, flag, ipage)) {\r
+       if (movescom(iqx, iqy, flag, ipage)) {\r
                /* failed -- try some other maneuvers */\r
                if (ideltax==0 || ideltay==0) {\r
                        /* attempt angle move */\r
                        if (ideltax != 0) {\r
                                iqy = game.state.isy + 1;\r
-                               if (checkdest(iqx, iqy, flag, ipage)) {\r
+                               if (movescom(iqx, iqy, flag, ipage)) {\r
                                        iqy = game.state.isy - 1;\r
-                                       checkdest(iqx, iqy, flag, ipage);\r
+                                       movescom(iqx, iqy, flag, ipage);\r
                                }\r
                        }\r
                        else {\r
                                iqx = game.state.isx + 1;\r
-                               if (checkdest(iqx, iqy, flag, ipage)) {\r
+                               if (movescom(iqx, iqy, flag, ipage)) {\r
                                        iqx = game.state.isx - 1;\r
-                                       checkdest(iqx, iqy, flag, ipage);\r
+                                       movescom(iqx, iqy, flag, ipage);\r
                                }\r
                        }\r
                }\r
                else {\r
                        /* try moving just in x or y */\r
                        iqy = game.state.isy;\r
-                       if (checkdest(iqx, iqy, flag, ipage)) {\r
+                       if (movescom(iqx, iqy, flag, ipage)) {\r
                                iqy = game.state.isy + ideltay;\r
                                iqx = game.state.isx;\r
-                               checkdest(iqx, iqy, flag, ipage);\r
+                               movescom(iqx, iqy, flag, ipage);\r
                        }\r
                }\r
        }\r
@@ -500,11 +502,12 @@ void scom(int *ipage) {
                        iseenit = 0;\r
                        isatb=1;\r
                        game.future[FSCDBAS] = game.state.date + 1.0 +2.0*Rand();\r
-                       if (batx != 0) game.future[FSCDBAS] += game.future[FCDBAS]-game.state.date;\r
+                       if (game.future[FCDBAS] < 1e30) game.future[FSCDBAS] +=\r
+                               game.future[FCDBAS]-game.state.date;\r
                        if (game.damage[DRADIO] > 0 && condit != IHDOCKED)\r
                                return; /* no warning */\r
                        iseenit = 1;\r
-                       if (*ipage == 0)  pause(1);\r
+                       if (*ipage == 0)  pause_game(1);\r
                        *ipage=1;\r
                        proutn("Lt. Uhura-  \"Captain, the starbase in ");\r
                        proutn(cramlc(quadrant, game.state.isx, game.state.isy));\r
@@ -529,7 +532,7 @@ void scom(int *ipage) {
                 (game.damage[DRADIO] > 0.0 && condit != IHDOCKED) ||\r
                 game.starch[game.state.isx][game.state.isy] > 0))\r
                return;\r
-       if (*ipage==0) pause(1);\r
+       if (*ipage==0) pause_game(1);\r
        *ipage = 1;\r
        prout("Lt. Uhura-  \"Captain, Starfleet Intelligence reports");\r
        proutn("   the Super-commander is in ");\r
@@ -582,6 +585,8 @@ void movetho(void) {
                }\r
        }\r
        game.quad[ithx][ithy] = IHT;\r
+        game.kx[nenhere]=ithx;\r
+        game.ky[nenhere]=ithy;\r
 \r
        /* check to see if all holes plugged */\r
        for (i = 1; i < 11; i++) {\r
@@ -596,5 +601,6 @@ void movetho(void) {
        crmena(1,IHT, 2, ithx, ithy);\r
        prout(" completes web.");\r
        ithere = ithx = ithy = 0;\r
+       nenhere--;\r
        return;\r
 }\r