projects
/
super-star-trek.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Fix two minor presentation bugs.
[super-star-trek.git]
/
ai.c
diff --git
a/ai.c
b/ai.c
index 762e745dcf4dbe9ff62a0943ebf291506034e3e6..d96f747315ebac25962de011493f328d814a85c8 100644
(file)
--- a/
ai.c
+++ b/
ai.c
@@
-6,14
+6,15
@@
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 ||
- NOEXIT(game.state.galaxy[iqx][iqy]))
+ 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 */
if (ienm == IHR) return 0; /* Romulans cannot escape! */
if (irun == 0) {
/* avoid intruding on another commander's territory */
if (ienm == IHC) {
return 0; /* no can do -- neg energy, supernovae, or >8 Klingons */
if (ienm == IHR) return 0; /* Romulans cannot escape! */
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;
@@
-40,8
+41,8
@@
static int tryexit(int lookx, int looky, int ienm, int loccom, int irun)
nenhere--;
if (condit != IHDOCKED) newcnd();
/* Handle global matters related to escape */
nenhere--;
if (condit != IHDOCKED) newcnd();
/* Handle global matters related to escape */
- game.state.galaxy[quadx][quady]
-= KLINGON_PLACE
;
- game.state.galaxy[iqx][iqy]
+= KLINGON_PLACE
;
+ game.state.galaxy[quadx][quady]
.klingons--
;
+ game.state.galaxy[iqx][iqy]
.klingons++
;
if (ienm==IHS) {
ishere=0;
iscate=0;
if (ienm==IHS) {
ishere=0;
iscate=0;
@@
-53,7
+54,7
@@
static int tryexit(int lookx, int looky, int ienm, int loccom, int irun)
game.state.isy=iqy;
}
else {
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;
@@
-164,7
+165,7
@@
static void movebaddy(int comx, int comy, int loccom, int ienm)
/* Limit motion according to skill */
if (abs(motion) > skill) motion = (motion < 0) ? -skill : skill;
}
/* Limit motion according to skill */
if (abs(motion) > skill) motion = (motion < 0) ? -skill : skill;
}
- /* calcuate preferred number of steps */
+ /* calcu
l
ate preferred number of steps */
nsteps = motion < 0 ? -motion : motion;
if (motion > 0 && nsteps > mdist) nsteps = mdist; /* don't overshoot */
if (nsteps > QUADSIZE) nsteps = QUADSIZE; /* This shouldn't be necessary */
nsteps = motion < 0 ? -motion : motion;
if (motion > 0 && nsteps > mdist) nsteps = mdist; /* don't overshoot */
if (nsteps > QUADSIZE) nsteps = QUADSIZE; /* This shouldn't be necessary */
@@
-184,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 */
@@
-272,26
+273,28
@@
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++
) {
+ if (skill >= SKILL_EXPERT) for
_local_enemies(i
) {
ix = game.kx[i];
iy = game.ky[i];
if (game.quad[ix][iy] == IHK || game.quad[ix][iy] == IHR)
ix = game.kx[i];
iy = game.ky[i];
if (game.quad[ix][iy] == IHK || game.quad[ix][iy] == IHR)
@@
-306,19
+309,21
@@
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 ||
- NOEXIT(game.state.galaxy[iqx][iqy])) return 1;
+ !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 */
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;
/* do the move */
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]
-= KLINGON_PLACE
;
+ game.state.galaxy[game.state.isx][game.state.isy]
.klingons--
;
game.state.isx = iqx;
game.state.isy = iqy;
game.state.isx = iqx;
game.state.isy = iqy;
- game.state.galaxy[game.state.isx][game.state.isy]
+= KLINGON_PLACE
;
+ game.state.galaxy[game.state.isx][game.state.isy]
.klingons++
;
if (ishere) {
/* SC has scooted, Remove him from current quadrant */
iscate=0;
if (ishere) {
/* SC has scooted, Remove him from current quadrant */
iscate=0;
@@
-326,7
+331,7
@@
static int movescom(int iqx, int iqy, int flag, int *ipage)
ishere=0;
ientesc=0;
game.future[FSCDBAS]=1e30;
ishere=0;
ientesc=0;
game.future[FSCDBAS]=1e30;
- for
(i = 1; i <= nenhere; i++
)
+ 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];
@@
-345,7
+350,7
@@
static int movescom(int iqx, int iqy, int flag, int *ipage)
game.state.plnets[i].crystals == 1) {
/* destroy the planet */
DESTROY(&game.state.plnets[i]);
game.state.plnets[i].crystals == 1) {
/* destroy the planet */
DESTROY(&game.state.plnets[i]);
- game.state.
newstuf[game.state.isx][game.state.isy]
-= 1;
+ game.state.
galaxy[game.state.isx][game.state.isy].planets
-= 1;
if (game.damage[DRADIO] == 0.0 || condit == IHDOCKED) {
if (*ipage==0) pause_game(1);
*ipage = 1;
if (game.damage[DRADIO] == 0.0 || condit == IHDOCKED) {
if (*ipage==0) pause_game(1);
*ipage = 1;
@@
-365,8
+370,8
@@
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");
int flag;
#ifdef DEBUG
if (idebug) prout("SCOM");
@@
-394,7
+399,7
@@
void scom(int *ipage)
}
sx = game.state.isx;
sy = game.state.isy;
}
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];
@@
-422,16
+427,18
@@
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];
if ((ibqx == quadx && ibqy == quady) ||
(ibqx == batx && ibqy == baty) ||
i = basetbl[i2]; /* bug in original had it not finding nearest*/
ibqx = game.state.baseqx[i];
ibqy = game.state.baseqy[i];
if ((ibqx == quadx && ibqy == quady) ||
(ibqx == batx && ibqy == baty) ||
- NOEXIT(game.state.galaxy[ibqx][ibqy])) continue;
+ game.state.galaxy[ibqx][ibqy].supernova ||
+ game.state.galaxy[ibqx][ibqy].klingons > 8)
+ continue;
/* if there is a commander, an no other base is appropriate,
we will take the one with the commander */
/* 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;
@@
-493,7
+500,7
@@
void scom(int *ipage)
if (game.state.rembase == 0) {
game.future[FSCMOVE] = 1e30;
}
if (game.state.rembase == 0) {
game.future[FSCMOVE] = 1e30;
}
- 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) {
@@
-530,7
+537,7
@@
void scom(int *ipage)
#endif
(Rand() > 0.2 ||
(game.damage[DRADIO] > 0.0 && condit != IHDOCKED) ||
#endif
(Rand() > 0.2 ||
(game.damage[DRADIO] > 0.0 && condit != IHDOCKED) ||
-
game.starch[game.state.isx][game.state.isy] > 0
))
+
!game.state.galaxy[game.state.isx][game.state.isy].charted
))
return;
if (*ipage==0) pause_game(1);
*ipage = 1;
return;
if (*ipage==0) pause_game(1);
*ipage = 1;
@@
-590,7
+597,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;