projects
/
super-star-trek.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Avoid an infinite loop on some skips.
[super-star-trek.git]
/
ai.c
diff --git
a/ai.c
b/ai.c
index 37f266c8150d360012fb2232297c0d0f90b29b96..ba970a36ee9f18dcdbf2f43aa1fcf564e19788cc 100644
(file)
--- 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 */
\r
if (game.damage[DSRSENS] == 0.0 || game.damage[DLRSENS] == 0.0 ||
\r
condit == IHDOCKED) {
\r
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
- proutn(" escapes to");
\r
- cramlc(1, iqx, iqy);
\r
- prout(" (and regains strength).");
\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
}
\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
game.kx[loccom] = game.kx[nenhere];
\r
game.ky[loccom] = game.ky[nenhere];
\r
game.kavgd[loccom] = game.kavgd[nenhere];
\r
@@
-154,11
+153,8
@@
static void movebaddy(int comx, int comy, int loccom, int ienm) {
}
\r
#ifdef DEBUG
\r
if (idebug) {
\r
}
\r
#ifdef DEBUG
\r
if (idebug) {
\r
- proutn("MOTION = ");
\r
- cramf(motion, 1, 2);
\r
- proutn(" FORCES = ");
\r
- cramf(forces, 1, 2);
\r
- skip(1);
\r
+ proutn("MOTION = %1.2f", motion);
\r
+ proutn(" FORCES = %1,2f", forces);
\r
}
\r
#endif
\r
/* don't move if no motion */
\r
}
\r
#endif
\r
/* don't move if no motion */
\r
@@
-185,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
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
/* main move loop */
\r
for (ll = 1; ll <= nsteps; ll++) {
\r
#ifdef DEBUG
\r
@@
-239,14
+234,14
@@
static void movebaddy(int comx, int comy, int loccom, int ienm) {
nexty = looky;
\r
#ifdef DEBUG
\r
if (idebug) {
\r
nexty = looky;
\r
#ifdef DEBUG
\r
if (idebug) {
\r
- cramlc(0, nextx, nexty);
\r
- skip(1);
\r
+ prout(cramlc(neither, nextx, nexty));
\r
}
\r
#endif
\r
}
\r
else break; /* done early */
\r
}
\r
/* Put commander in place within same quadrant */
\r
}
\r
#endif
\r
}
\r
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
game.quad[nextx][nexty] = ienm;
\r
if (nextx != comx || nexty != comy) {
\r
/* it moved */
\r
@@
-257,10
+252,11
@@
static void movebaddy(int comx, int comy, int loccom, int ienm) {
if (game.damage[DSRSENS] == 0 || condit == IHDOCKED) {
\r
proutn("***");
\r
cramen(ienm);
\r
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
if (game.kdist[loccom] < dist1) proutn(" advances to");
\r
- else proutn(" retreats to");
\r
- cramlc(2, nextx, nexty);
\r
- skip(1);
\r
+ else proutn(" retreats to ");
\r
+ prout(cramlc(sector, nextx, nexty));
\r
}
\r
}
\r
}
\r
}
\r
}
\r
}
\r
@@
-303,8
+299,8
@@
void movcom(void) {
sortkl();
\r
}
\r
\r
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
\r
if ((iqx==quadx && iqy==quady) ||
\r
iqx < 1 || iqx > 8 || iqy < 1 || iqy > 8 ||
\r
@@
-314,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
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
/* 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 (is
cat
e) {
\r
+ if (is
her
e) {
\r
/* SC has scooted, Remove him from current quadrant */
\r
iscate=0;
\r
isatb=0;
\r
/* SC has scooted, Remove him from current quadrant */
\r
iscate=0;
\r
isatb=0;
\r
@@
-348,11
+344,11
@@
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
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
*ipage = 1;
\r
prout("Lt. Uhura- \"Captain, Starfleet Intelligence reports");
\r
- proutn(" a planet in");
\r
-
cramlc(1, game.state.isx, game.state.isy
);
\r
+ proutn(" a planet in
");
\r
+
proutn(cramlc(quadrant, game.state.isx, game.state.isy)
);
\r
prout(" has been destroyed");
\r
prout(" by the Super-commander.\"");
\r
}
\r
prout(" has been destroyed");
\r
prout(" by the Super-commander.\"");
\r
}
\r
@@
-464,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
/* 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
/* 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
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
}
\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
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
}
\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
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
}
\r
}
\r
}
\r
@@
-506,19
+502,19
@@
void scom(int *ipage) {
iseenit = 0;
\r
isatb=1;
\r
game.future[FSCDBAS] = game.state.date + 1.0 +2.0*Rand();
\r
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 (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
*ipage=1;
\r
- proutn("Lt. Uhura- \"Captain, the starbase in");
\r
-
cramlc(1, game.state.isx, game.state.isy
);
\r
+ proutn("Lt. Uhura- \"Captain, the starbase in
");
\r
+
proutn(cramlc(quadrant, game.state.isx, game.state.isy)
);
\r
skip(1);
\r
prout(" reports that it is under attack from the Klingon Super-commander.");
\r
skip(1);
\r
prout(" reports that it is under attack from the Klingon Super-commander.");
\r
- proutn(" It can survive until stardate ");
\r
- cramf(game.future[FSCDBAS], 0, 1);
\r
- prout(" .\"");
\r
+ proutn(" It can survive until stardate %d.\"",
\r
+ (int)game.future[FSCDBAS]);
\r
if (resting==0) return;
\r
prout("Mr. Spock- \"Captain, shall we cancel the rest period?\"");
\r
if (ja()==0) return;
\r
if (resting==0) return;
\r
prout("Mr. Spock- \"Captain, shall we cancel the rest period?\"");
\r
if (ja()==0) return;
\r
@@
-536,11
+532,11
@@
void scom(int *ipage) {
(game.damage[DRADIO] > 0.0 && condit != IHDOCKED) ||
\r
game.starch[game.state.isx][game.state.isy] > 0))
\r
return;
\r
(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
*ipage = 1;
\r
prout("Lt. Uhura- \"Captain, Starfleet Intelligence reports");
\r
- proutn(" the Super-commander is in");
\r
-
cramlc(1, game.state.isx, game.state. isy
);
\r
+ proutn(" the Super-commander is in
");
\r
+
proutn(cramlc(quadrant, game.state.isx, game.state. isy)
);
\r
prout(".\"");
\r
return;
\r
}
\r
prout(".\"");
\r
return;
\r
}
\r
@@
-589,6
+585,8
@@
void movetho(void) {
}
\r
}
\r
game.quad[ithx][ithy] = IHT;
\r
}
\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
\r
/* check to see if all holes plugged */
\r
for (i = 1; i < 11; i++) {
\r
@@
-603,5
+601,6
@@
void movetho(void) {
crmena(1,IHT, 2, ithx, ithy);
\r
prout(" completes web.");
\r
ithere = ithx = ithy = 0;
\r
crmena(1,IHT, 2, ithx, ithy);
\r
prout(" completes web.");
\r
ithere = ithx = ithy = 0;
\r
+ nenhere--;
\r
return;
\r
}
\r
return;
\r
}
\r