Do some more precalculation of alliances and redefine aiCheckAlliances() as a macro. This achieves
approximately 8% speedup on some large games. git-svn-id: https://warzone2100.svn.sourceforge.net/svnroot/warzone2100/trunk@9503 4a71c877-e1ca-e34f-864e-861f7616d084master
parent
3a783743a4
commit
7d210588c3
25
src/ai.c
25
src/ai.c
|
@ -45,7 +45,7 @@ static SDWORD targetAttackWeight(BASE_OBJECT *psTarget, BASE_OBJECT *psAttacker,
|
|||
static BOOL updateAttackTarget(BASE_OBJECT * psAttacker, SDWORD weapon_slot);
|
||||
|
||||
// alliances
|
||||
UBYTE alliances[MAX_PLAYERS][MAX_PLAYERS];
|
||||
UBYTE alliances[MAX_PLAYERS + 1][MAX_PLAYERS + 1];
|
||||
|
||||
|
||||
// see if a structure has the range to fire on a target
|
||||
|
@ -120,32 +120,17 @@ static BOOL aiObjHasRange(BASE_OBJECT *psObj, BASE_OBJECT *psTarget, int weapon_
|
|||
return false;
|
||||
}
|
||||
|
||||
/* alliance code for ai. return true if an alliance has formed. */
|
||||
BOOL aiCheckAlliances(UDWORD s1,UDWORD s2)
|
||||
{
|
||||
// features have their player number set to (MAX_PLAYERS + 1)
|
||||
if (s1 == (MAX_PLAYERS + 1) || s2 == (MAX_PLAYERS + 1))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (s1 == s2 || alliances[s1][s2] == ALLIANCE_FORMED)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Initialise the AI system */
|
||||
BOOL aiInitialise(void)
|
||||
{
|
||||
SDWORD i,j;
|
||||
|
||||
for(i=0; i<MAX_PLAYERS; i++)
|
||||
// The +1 is for features, that are owned by player 9 for hackish reasons
|
||||
for (i = 0; i < MAX_PLAYERS + 1; i++)
|
||||
{
|
||||
for(j=0; j<MAX_PLAYERS; j++)
|
||||
for (j = 0; j < MAX_PLAYERS + 1; j++)
|
||||
{
|
||||
alliances[i][j] = ALLIANCE_BROKEN;
|
||||
alliances[i][j] = (i == j) ? ALLIANCE_FORMED : ALLIANCE_BROKEN;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
6
src/ai.h
6
src/ai.h
|
@ -74,10 +74,10 @@ extern "C"
|
|||
#define WEIGHT_CMD_SAME_TARGET WEIGHT_DIST_TILE //Don't want this to be too high, since a commander can have many units assigned
|
||||
|
||||
// alliances
|
||||
extern UBYTE alliances[MAX_PLAYERS][MAX_PLAYERS];
|
||||
extern UBYTE alliances[MAX_PLAYERS + 1][MAX_PLAYERS + 1];
|
||||
|
||||
/* Check no alliance has formed*/
|
||||
extern BOOL aiCheckAlliances(UDWORD s1,UDWORD s2);
|
||||
/** Check no alliance has formed. This is a define to make sure we inline it. */
|
||||
#define aiCheckAlliances(_s1, _s2) (alliances[_s1][_s2] == ALLIANCE_FORMED)
|
||||
|
||||
/* Initialise the AI system */
|
||||
extern BOOL aiInitialise(void);
|
||||
|
|
|
@ -149,7 +149,7 @@ static int visObjHeight(const BASE_OBJECT * psObject)
|
|||
* once. Note that there is both a limit to how many objects can watch any given
|
||||
* tile, and a limit to how many tiles each object can watch. Strange but non fatal
|
||||
* things will happen if these limits are exceeded. This function uses icky globals. */
|
||||
static void visMarkTile(int mapX, int mapY, MAPTILE *psTile)
|
||||
static inline void visMarkTile(int mapX, int mapY, MAPTILE *psTile)
|
||||
{
|
||||
bool alreadySeen = false;
|
||||
int i;
|
||||
|
|
Loading…
Reference in New Issue