X-Git-Url: https://jxself.org/git/?a=blobdiff_plain;f=ai.c;h=ba970a36ee9f18dcdbf2f43aa1fcf564e19788cc;hb=93ede5b2bb8928b8aa17e750f48e6c5e59b81ab1;hp=9dcb1a01261941591e7a99c64721a2b7d7314e7a;hpb=48763357ef69f0b711fc332b13e2170ab914d881;p=super-star-trek.git diff --git a/ai.c b/ai.c index 9dcb1a0..ba970a3 100644 --- a/ai.c +++ b/ai.c @@ -24,13 +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 */ if (game.damage[DSRSENS] == 0.0 || game.damage[DLRSENS] == 0.0 || condit == IHDOCKED) { - proutn("***"); - cramen(ienm); - proutn(" escapes to"); - cramlc(1, iqx, iqy); - prout(" (and regains strength)."); + crmena(1, ienm, 2, game.kx[loccom], game.ky[loccom]); + proutn(" 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]; @@ -154,11 +153,8 @@ static void movebaddy(int comx, int comy, int loccom, int ienm) { } #ifdef DEBUG if (idebug) { - proutn("MOTION = "); - cramf(motion, 1, 2); - proutn(" FORCES = "); - cramf(forces, 1, 2); - skip(1); + proutn("MOTION = %1.2f", motion); + proutn(" FORCES = %1,2f", forces); } #endif /* don't move if no motion */ @@ -173,9 +169,7 @@ static void movebaddy(int comx, int comy, int loccom, int ienm) { if (nsteps < 1) nsteps = 1; /* This shouldn't be necessary */ #ifdef DEBUG if (idebug) { - proutn("NSTEPS = "); - crami(nsteps, 1); - skip(1); + prout("NSTEPS = %d", nsteps); } #endif /* Compute preferred values of delta X and Y */ @@ -187,13 +181,11 @@ static void movebaddy(int comx, int comy, int loccom, int ienm) { if (my != 0) my = my*motion < 0 ? -1 : 1; nextx = comx; nexty = comy; - game.quad[comx][comy] = IHDOT; /* main move loop */ for (ll = 1; ll <= nsteps; ll++) { #ifdef DEBUG if (idebug) { - crami(ll,2); - skip(1); + prout("%d", ll); } #endif /* Check if preferred position available */ @@ -242,14 +234,14 @@ static void movebaddy(int comx, int comy, int loccom, int ienm) { nexty = looky; #ifdef DEBUG if (idebug) { - cramlc(0, nextx, nexty); - skip(1); + 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 */ @@ -260,10 +252,11 @@ static void movebaddy(int comx, int comy, int loccom, int ienm) { if (game.damage[DSRSENS] == 0 || condit == IHDOCKED) { proutn("***"); cramen(ienm); + proutn(" from"); + cramlc(2, comx, comy); if (game.kdist[loccom] < dist1) proutn(" advances to"); - else proutn(" retreats to"); - cramlc(2, nextx, nexty); - skip(1); + else proutn(" retreats to "); + prout(cramlc(sector, nextx, nexty)); } } } @@ -306,8 +299,8 @@ void movcom(void) { sortkl(); } -static int checkdest(int iqx, int iqy, int flag, int *ipage) { - int i, j; +static int movescom(int iqx, int iqy, int flag, int *ipage) { + int i; if ((iqx==quadx && iqy==quady) || iqx < 1 || iqx > 8 || iqy < 1 || iqy > 8 || @@ -317,13 +310,13 @@ static int checkdest(int iqx, int iqy, int flag, int *ipage) { 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] -= 100; game.state.isx = iqx; game.state.isy = iqy; game.state.galaxy[game.state.isx][game.state.isy] += 100; - if (iscate) { + if (ishere) { /* SC has scooted, Remove him from current quadrant */ iscate=0; isatb=0; @@ -344,18 +337,18 @@ static int checkdest(int iqx, int iqy, int flag, int *ipage) { sortkl(); } /* check for a helpful planet */ - for (i = 1; i <= inplan; i++) { + 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 */ - game.state.plnets[i] = nulplanet; + 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(1); + if (*ipage==0) pause_game(1); *ipage = 1; prout("Lt. Uhura- \"Captain, Starfleet Intelligence reports"); - proutn(" a planet in"); - cramlc(1, game.state.isx, game.state.isy); + proutn(" a planet in "); + proutn(cramlc(quadrant, game.state.isx, game.state.isy)); prout(" has been destroyed"); prout(" by the Super-commander.\""); } @@ -467,32 +460,32 @@ void scom(int *ipage) { /* try moving in both x and y directions */ iqx = game.state.isx + ideltax; iqy = game.state.isy + ideltax; - if (checkdest(iqx, iqy, flag, ipage)) { + 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 (checkdest(iqx, iqy, flag, ipage)) { + if (movescom(iqx, iqy, flag, ipage)) { iqy = game.state.isy - 1; - checkdest(iqx, iqy, flag, ipage); + movescom(iqx, iqy, flag, ipage); } } else { iqx = game.state.isx + 1; - if (checkdest(iqx, iqy, flag, ipage)) { + if (movescom(iqx, iqy, flag, ipage)) { iqx = game.state.isx - 1; - checkdest(iqx, iqy, flag, ipage); + movescom(iqx, iqy, flag, ipage); } } } else { /* try moving just in x or y */ iqy = game.state.isy; - if (checkdest(iqx, iqy, flag, ipage)) { + if (movescom(iqx, iqy, flag, ipage)) { iqy = game.state.isy + ideltay; iqx = game.state.isx; - checkdest(iqx, iqy, flag, ipage); + movescom(iqx, iqy, flag, ipage); } } } @@ -509,19 +502,19 @@ void scom(int *ipage) { iseenit = 0; isatb=1; game.future[FSCDBAS] = game.state.date + 1.0 +2.0*Rand(); - if (batx != 0) game.future[FSCDBAS] += game.future[FCDBAS]-game.state.date; + 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(1); + if (*ipage == 0) pause_game(1); *ipage=1; - proutn("Lt. Uhura- \"Captain, the starbase in"); - cramlc(1, game.state.isx, game.state.isy); + 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 "); - cramf(game.future[FSCDBAS], 0, 1); - prout(" .\""); + 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; @@ -539,11 +532,11 @@ void scom(int *ipage) { (game.damage[DRADIO] > 0.0 && condit != IHDOCKED) || game.starch[game.state.isx][game.state.isy] > 0)) return; - if (*ipage==0) pause(1); + if (*ipage==0) pause_game(1); *ipage = 1; prout("Lt. Uhura- \"Captain, Starfleet Intelligence reports"); - proutn(" the Super-commander is in"); - cramlc(1, game.state.isx, game.state. isy); + proutn(" the Super-commander is in "); + proutn(cramlc(quadrant, game.state.isx, game.state. isy)); prout(".\""); return; } @@ -592,6 +585,8 @@ void movetho(void) { } } game.quad[ithx][ithy] = IHT; + game.kx[nenhere]=ithx; + game.ky[nenhere]=ithy; /* check to see if all holes plugged */ for (i = 1; i < 11; i++) { @@ -606,5 +601,6 @@ void movetho(void) { crmena(1,IHT, 2, ithx, ithy); prout(" completes web."); ithere = ithx = ithy = 0; + nenhere--; return; }