projects
/
super-star-trek.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Clean up a warning.
[super-star-trek.git]
/
ai.c
diff --git
a/ai.c
b/ai.c
index c6a862ea25c2c4ff01ae63af5db386c21b163533..a1b4bbf6f92ef101dc9ac53ed5a8b3af39f8fcde 100644
(file)
--- a/
ai.c
+++ b/
ai.c
@@
-6,7
+6,7
@@
static int tryexit(int lookx, int looky, int ienm, int loccom, int irun)
iqx = quadx+(lookx+(QUADSIZE-1))/QUADSIZE - 1;
iqy = quady+(looky+(QUADSIZE-1))/QUADSIZE - 1;
iqx = quadx+(lookx+(QUADSIZE-1))/QUADSIZE - 1;
iqy = quady+(looky+(QUADSIZE-1))/QUADSIZE - 1;
- if (
iqx < 1 || iqx > GALSIZE || iqy < 1 || iqy > GALSIZE
||
+ if (
!VALID_QUADRANT(iqx,iqy)
||
game.state.galaxy[iqx][iqy].supernova ||
game.state.galaxy[iqx][iqy].klingons > 8)
return 0; /* no can do -- neg energy, supernovae, or >8 Klingons */
game.state.galaxy[iqx][iqy].supernova ||
game.state.galaxy[iqx][iqy].klingons > 8)
return 0; /* no can do -- neg energy, supernovae, or >8 Klingons */
@@
-14,7
+14,7
@@
static int tryexit(int lookx, int looky, int ienm, int loccom, int irun)
if (irun == 0) {
/* avoid intruding on another commander's territory */
if (ienm == IHC) {
if (irun == 0) {
/* avoid intruding on another commander's territory */
if (ienm == IHC) {
- for
(l = 1; l <= game.state.remcom; l++
)
+ for
_commanders(l
)
if (game.state.cx[l]==iqx && game.state.cy[l]==iqy) return 0;
/* refuse to leave if currently attacking starbase */
if (batx==quadx && baty==quady) return 0;
if (game.state.cx[l]==iqx && game.state.cy[l]==iqy) return 0;
/* refuse to leave if currently attacking starbase */
if (batx==quadx && baty==quady) return 0;
@@
-49,12
+49,12
@@
static int tryexit(int lookx, int looky, int ienm, int loccom, int irun)
ientesc=0;
isatb=0;
game.future[FSCMOVE]=0.2777+game.state.date;
ientesc=0;
isatb=0;
game.future[FSCMOVE]=0.2777+game.state.date;
- game.future[FSCDBAS]=
1e30
;
+ game.future[FSCDBAS]=
FOREVER
;
game.state.isx=iqx;
game.state.isy=iqy;
}
else {
game.state.isx=iqx;
game.state.isy=iqy;
}
else {
- for
(l=1; l<=game.state.remcom; l++
) {
+ for
_commanders(l
) {
if (game.state.cx[l]==quadx && game.state.cy[l]==quady) {
game.state.cx[l]=iqx;
game.state.cy[l]=iqy;
if (game.state.cx[l]==quadx && game.state.cy[l]==quady) {
game.state.cx[l]=iqx;
game.state.cy[l]=iqy;
@@
-151,7
+151,7
@@
static void movebaddy(int comx, int comy, int loccom, int ienm)
else {
if (forces > 1000.0) /* Very strong -- move in for kill */
motion = (1.0-square(Rand()))*dist1 + 1.0;
else {
if (forces > 1000.0) /* Very strong -- move in for kill */
motion = (1.0-square(Rand()))*dist1 + 1.0;
- if (condit==IHDOCKED) /* protected by base -- back off ! */
+ if (condit==IHDOCKED
&& (game.options & OPTION_BASE)
) /* protected by base -- back off ! */
motion -= skill*(2.0-square(Rand()));
}
#ifdef DEBUG
motion -= skill*(2.0-square(Rand()));
}
#ifdef DEBUG
@@
-185,10
+185,10
@@
static void movebaddy(int comx, int comy, int loccom, int ienm)
nextx = comx;
nexty = comy;
/* main move loop */
nextx = comx;
nexty = comy;
/* main move loop */
- for (ll =
1; ll <=
nsteps; ll++) {
+ for (ll =
0; ll <
nsteps; ll++) {
#ifdef DEBUG
if (idebug) {
#ifdef DEBUG
if (idebug) {
- prout("%d", ll);
+ prout("%d", ll
+1
);
}
#endif
/* Check if preferred position available */
}
#endif
/* Check if preferred position available */
@@
-213,7
+213,7
@@
static void movebaddy(int comx, int comy, int loccom, int ienm)
looky = nexty + krawly;
krawly = -krawly;
}
looky = nexty + krawly;
krawly = -krawly;
}
- else if (game.quad[lookx][looky] != IHDOT) {
+ else if (
(game.options & OPTION_RAMMING) &&
game.quad[lookx][looky] != IHDOT) {
/* See if we should ram ship */
if (game.quad[lookx][looky] == ship &&
(ienm == IHC || ienm == IHS)) {
/* See if we should ram ship */
if (game.quad[lookx][looky] == ship &&
(ienm == IHC || ienm == IHS)) {
@@
-273,31
+273,34
@@
void movcom(void)
/* Figure out which Klingon is the commander (or Supercommander)
and do move */
/* Figure out which Klingon is the commander (or Supercommander)
and do move */
- if (comhere) for (i = 1; i <= nenhere; i++) {
- ix = game.kx[i];
- iy = game.ky[i];
- if (game.quad[ix][iy] == IHC) {
- movebaddy(ix, iy, i, IHC);
- break;
+ if (comhere)
+ for_local_enemies(i) {
+ ix = game.kx[i];
+ iy = game.ky[i];
+ if (game.quad[ix][iy] == IHC) {
+ movebaddy(ix, iy, i, IHC);
+ break;
+ }
}
}
- }
- if (ishere) for (i = 1; i <= nenhere; i++) {
- ix = game.kx[i];
- iy = game.ky[i];
- if (game.quad[ix][iy] == IHS) {
- movebaddy(ix, iy, i, IHS);
- break;
+ if (ishere)
+ for_local_enemies(i) {
+ ix = game.kx[i];
+ iy = game.ky[i];
+ if (game.quad[ix][iy] == IHS) {
+ movebaddy(ix, iy, i, IHS);
+ break;
+ }
}
}
- }
/* if skill level is high, move other Klingons and Romulans too!
Move these last so they can base their actions on what the
commander(s) do. */
/* if skill level is high, move other Klingons and Romulans too!
Move these last so they can base their actions on what the
commander(s) do. */
- if (skill >= SKILL_EXPERT) for (i = 1; i <= nenhere; i++) {
- ix = game.kx[i];
- iy = game.ky[i];
- if (game.quad[ix][iy] == IHK || game.quad[ix][iy] == IHR)
- movebaddy(ix, iy, i, game.quad[ix][iy]);
- }
+ if (skill >= SKILL_EXPERT && (game.options & OPTION_MVBADDY))
+ for_local_enemies(i) {
+ ix = game.kx[i];
+ iy = game.ky[i];
+ if (game.quad[ix][iy] == IHK || game.quad[ix][iy] == IHR)
+ movebaddy(ix, iy, i, game.quad[ix][iy]);
+ }
sortkl();
}
sortkl();
}
@@
-307,13
+310,13
@@
static int movescom(int iqx, int iqy, int flag, int *ipage)
int i;
if ((iqx==quadx && iqy==quady) ||
int i;
if ((iqx==quadx && iqy==quady) ||
-
iqx < 1 || iqx > GALSIZE || iqy < 1 || iqy > GALSIZE
||
+
!VALID_QUADRANT(iqx, iqy)
||
game.state.galaxy[iqx][iqy].supernova ||
game.state.galaxy[iqx][iqy].klingons > 8)
return 1;
if (flag) {
/* Avoid quadrants with bases if we want to avoid Enterprise */
game.state.galaxy[iqx][iqy].supernova ||
game.state.galaxy[iqx][iqy].klingons > 8)
return 1;
if (flag) {
/* Avoid quadrants with bases if we want to avoid Enterprise */
- for
(i = 1; i <= game.state.rembase; i++
)
+ for
_starbases(i
)
if (game.state.baseqx[i]==iqx && game.state.baseqy[i]==iqy) return 1;
}
if (justin && !iscate) return 1;
if (game.state.baseqx[i]==iqx && game.state.baseqy[i]==iqy) return 1;
}
if (justin && !iscate) return 1;
@@
-328,8
+331,8
@@
static int movescom(int iqx, int iqy, int flag, int *ipage)
isatb=0;
ishere=0;
ientesc=0;
isatb=0;
ishere=0;
ientesc=0;
- game.future[FSCDBAS]=
1e30
;
- for
(i = 1; i <= nenhere; i++
)
+ game.future[FSCDBAS]=
FOREVER
;
+ for
_local_enemies(i
)
if (game.quad[game.kx[i]][game.ky[i]] == IHS) break;
game.quad[game.kx[i]][game.ky[i]] = IHDOT;
game.kx[i] = game.kx[nenhere];
if (game.quad[game.kx[i]][game.ky[i]] == IHS) break;
game.quad[game.kx[i]][game.ky[i]] = IHDOT;
game.kx[i] = game.kx[nenhere];
@@
-368,15
+371,15
@@
void scom(int *ipage)
{
int i, i2, j, ideltax, ideltay, ibqx, ibqy, sx, sy, ifindit, iwhichb;
int iqx, iqy;
{
int i, i2, j, ideltax, ideltay, ibqx, ibqy, sx, sy, ifindit, iwhichb;
int iqx, iqy;
- int basetbl[BASEMAX];
- double bdist[BASEMAX];
+ int basetbl[BASEMAX
+1
];
+ double bdist[BASEMAX
+1
];
int flag;
#ifdef DEBUG
if (idebug) prout("SCOM");
#endif
/* Decide on being active or passive */
int flag;
#ifdef DEBUG
if (idebug) prout("SCOM");
#endif
/* Decide on being active or passive */
- flag = ((
game.state.killc+game.state.killk
)/(game.state.date+0.01-indate) < 0.1*skill*(skill+1.0) ||
+ flag = ((
NKILLC+NKILLK
)/(game.state.date+0.01-indate) < 0.1*skill*(skill+1.0) ||
(game.state.date-indate) < 3.0);
if (iscate==0 && flag) {
/* compute move away from Enterprise */
(game.state.date-indate) < 3.0);
if (iscate==0 && flag) {
/* compute move away from Enterprise */
@@
-392,12
+395,12
@@
void scom(int *ipage)
/* compute distances to starbases */
if (game.state.rembase <= 0) {
/* nothing left to do */
/* compute distances to starbases */
if (game.state.rembase <= 0) {
/* nothing left to do */
- game.future[FSCMOVE] =
1e30
;
+ game.future[FSCMOVE] =
FOREVER
;
return;
}
sx = game.state.isx;
sy = game.state.isy;
return;
}
sx = game.state.isx;
sy = game.state.isy;
- for
(i = 1; i <= game.state.rembase; i++
) {
+ for
_starbases(i
) {
basetbl[i] = i;
ibqx = game.state.baseqx[i];
ibqy = game.state.baseqy[i];
basetbl[i] = i;
ibqx = game.state.baseqx[i];
ibqy = game.state.baseqy[i];
@@
-425,7
+428,7
@@
void scom(int *ipage)
without too many Klingons, and not already under attack. */
ifindit = iwhichb = 0;
without too many Klingons, and not already under attack. */
ifindit = iwhichb = 0;
- for
(i2 = 1; i2 <= game.state.rembase; i2++
) {
+ for
_starbases(i2
) {
i = basetbl[i2]; /* bug in original had it not finding nearest*/
ibqx = game.state.baseqx[i];
ibqy = game.state.baseqy[i];
i = basetbl[i2]; /* bug in original had it not finding nearest*/
ibqx = game.state.baseqx[i];
ibqy = game.state.baseqy[i];
@@
-436,7
+439,7
@@
void scom(int *ipage)
continue;
/* if there is a commander, an no other base is appropriate,
we will take the one with the commander */
continue;
/* if there is a commander, an no other base is appropriate,
we will take the one with the commander */
- for
(j = 1; j <= game.state.remcom; j++
) {
+ for
_commanders (j
) {
if (ibqx==game.state.cx[j] && ibqy==game.state.cy[j] && ifindit!= 2) {
ifindit = 2;
iwhichb = i;
if (ibqx==game.state.cx[j] && ibqy==game.state.cy[j] && ifindit!= 2) {
ifindit = 2;
iwhichb = i;
@@
-496,9
+499,9
@@
void scom(int *ipage)
}
/* check for a base */
if (game.state.rembase == 0) {
}
/* check for a base */
if (game.state.rembase == 0) {
- game.future[FSCMOVE] =
1e30
;
+ game.future[FSCMOVE] =
FOREVER
;
}
}
- else for
(i=1; i<=game.state.rembase; i++
) {
+ else for
_starbases(i
) {
ibqx = game.state.baseqx[i];
ibqy = game.state.baseqy[i];
if (ibqx==game.state.isx && ibqy == game.state.isy && game.state.isx != batx && game.state.isy != baty) {
ibqx = game.state.baseqx[i];
ibqy = game.state.baseqy[i];
if (ibqx==game.state.isx && ibqy == game.state.isy && game.state.isx != batx && game.state.isy != baty) {
@@
-507,7
+510,7
@@
void scom(int *ipage)
iseenit = 0;
isatb=1;
game.future[FSCDBAS] = game.state.date + 1.0 +2.0*Rand();
iseenit = 0;
isatb=1;
game.future[FSCDBAS] = game.state.date + 1.0 +2.0*Rand();
- if (game.future[FCDBAS] <
1e30
) game.future[FSCDBAS] +=
+ if (game.future[FCDBAS] <
FOREVER
) game.future[FSCDBAS] +=
game.future[FCDBAS]-game.state.date;
if (game.damage[DRADIO] > 0 && condit != IHDOCKED)
return; /* no warning */
game.future[FCDBAS]-game.state.date;
if (game.damage[DRADIO] > 0 && condit != IHDOCKED)
return; /* no warning */
@@
-595,7
+598,7
@@
void movetho(void)
game.ky[nenhere]=ithy;
/* check to see if all holes plugged */
game.ky[nenhere]=ithy;
/* check to see if all holes plugged */
- for
(i = 1; i < QUADSIZE+1; i++
) {
+ for
_sectors(i
) {
if (game.quad[1][i]!=IHWEB && game.quad[1][i]!=IHT) return;
if (game.quad[QUADSIZE][i]!=IHWEB && game.quad[QUADSIZE][i]!=IHT) return;
if (game.quad[i][1]!=IHWEB && game.quad[i][1]!=IHT) return;
if (game.quad[1][i]!=IHWEB && game.quad[1][i]!=IHT) return;
if (game.quad[QUADSIZE][i]!=IHWEB && game.quad[QUADSIZE][i]!=IHT) return;
if (game.quad[i][1]!=IHWEB && game.quad[i][1]!=IHT) return;