Fix all droids passing through all structures not allied to host.

Hopefully now both gates and regular structures should work correctly now.
master
Cyp 2011-03-02 12:35:59 +01:00
parent 2875a59981
commit 50c02e9944
4 changed files with 25 additions and 20 deletions

View File

@ -249,8 +249,6 @@ static uint8_t prop2bits(PROPULSION_TYPE propulsion)
// Check if the map tile at a location blocks a droid
BOOL fpathBaseBlockingTile(SDWORD x, SDWORD y, PROPULSION_TYPE propulsion, int mapIndex, FPATH_MOVETYPE moveType)
{
uint8_t aux, unitbits = prop2bits(propulsion); // TODO - cache prop2bits to psDroid, and pass in instead of propulsion type
/* All tiles outside of the map and on map border are blocking. */
if (x < 1 || y < 1 || x > mapWidth - 1 || y > mapHeight - 1)
{
@ -263,18 +261,24 @@ BOOL fpathBaseBlockingTile(SDWORD x, SDWORD y, PROPULSION_TYPE propulsion, int m
// coords off map - auto blocking tile
return true;
}
aux = auxTile(x, y, mapIndex);
unsigned aux = auxTile(x, y, mapIndex);
if ((unitbits & FEATURE_BLOCKED)
&& ((moveType == FMT_MOVE && (aux & AUXBITS_ANY_BUILDING)) // do not wish to shoot our way through enemy buildings
|| (moveType == FMT_BLOCK && (aux & AUXBITS_CLOSED_GATE)) // Do not wish to tunnel through closed gates.
|| (aux & AUXBITS_OUR_BUILDING))) // move blocked by friendly building, assuming we do not want to shoot it up en route
int auxMask = 0;
switch (moveType)
{
case FMT_MOVE: auxMask = AUXBITS_NONPASSABLE; break; // do not wish to shoot our way through enemy buildings, but want to go through friendly gates (without shooting them)
case FMT_ATTACK: auxMask = AUXBITS_OUR_BUILDING; break; // move blocked by friendly building, assuming we do not want to shoot it up en route
case FMT_BLOCK: auxMask = AUXBITS_BLOCKING; break; // Do not wish to tunnel through closed gates or buildings.
}
unsigned unitbits = prop2bits(propulsion); // TODO - cache prop2bits to psDroid, and pass in instead of propulsion type
if ((unitbits & FEATURE_BLOCKED) != 0 && (aux & auxMask) != 0)
{
return true; // move blocked by building, and we cannot or do not want to shoot our way through anything
}
// the MAX hack below is because blockTile() range does not include player-specific versions...
return (blockTile(x, y, MAX(0, mapIndex - MAX_PLAYERS)) & unitbits); // finally check if move is blocked by propulsion related factors
return (blockTile(x, y, MAX(0, mapIndex - MAX_PLAYERS)) & unitbits) != 0; // finally check if move is blocked by propulsion related factors
}
BOOL fpathDroidBlockingTile(DROID *psDroid, int x, int y, FPATH_MOVETYPE moveType)
@ -615,9 +619,10 @@ static int fpathResultQueueLength(void)
}
// Only used by fpathTest.
static FPATH_RETVAL fpathSimpleRoute(MOVE_CONTROL *psMove, int id, int startX, int startY, int tX, int tY)
{
return fpathRoute(psMove, id, startX, startY, tX, tY, PROPULSION_TYPE_WHEELED, DROID_WEAPON, FMT_MOVE, 0, true);
return fpathRoute(psMove, id, startX, startY, tX, tY, PROPULSION_TYPE_WHEELED, DROID_WEAPON, FMT_BLOCK, 0, true);
}
void fpathTest(int x, int y, int x2, int y2)

View File

@ -1776,12 +1776,12 @@ static int dangerFloodFill(int player)
if (!(aux & AUXBITS_TEMPORARY) && !(aux & AUXBITS_THREAT) && (aux & AUXBITS_DANGER))
{
// Note that we do not consider water to be a blocker here. This may or may not be a feature...
if (!(block & FEATURE_BLOCKED) && (!(aux & AUXBITS_ANY_BUILDING) || start))
if (!(block & FEATURE_BLOCKED) && (!(aux & AUXBITS_NONPASSABLE) || start))
{
floodbucket[bucketcounter].x = npos.x;
floodbucket[bucketcounter].y = npos.y;
bucketcounter++;
if (start && !(aux & AUXBITS_ANY_BUILDING))
if (start && !(aux & AUXBITS_NONPASSABLE))
{
start = false;
}

View File

@ -124,14 +124,14 @@ extern char *tileset;
#define WATER_BLOCKED 0x04 ///< Units that cannot pass water are blocked by this tile
#define LAND_BLOCKED 0x08 ///< The inverse of the above -- for propeller driven crafts
#define AUXBITS_CLOSED_GATE 0x01 ///< There is a gate which is not open.
#define AUXBITS_NONPASSABLE 0x01 ///< Is there any building blocking here, other than a gate that would open for us?
#define AUXBITS_OUR_BUILDING 0x02 ///< Do we or our allies have a building at this tile
#define AUXBITS_ANY_BUILDING 0x04 ///< Is there any building that might be blocking here?
#define AUXBITS_BLOCKING 0x04 ///< Is there any building currently blocking here?
#define AUXBITS_TEMPORARY 0x08 ///< Temporary bit used in calculations
#define AUXBITS_DANGER 0x10 ///< Does AI sense danger going there?
#define AUXBITS_THREAT 0x20 ///< Can hostile players shoot here?
#define AUXBITS_AATHREAT 0x40 ///< Can hostile players shoot at my VTOLs here?
#define AUXBITS_BUILDING 0x80 ///< Whether player has blocking building at tile, combine it with alliance bits and blockingBits
#define AUXBITS_UNUSED 0x80 ///< Unused
#define AUXBITS_ALL 0xff
#define AUX_MAP 0

View File

@ -211,7 +211,7 @@ static void auxStructureNonblocking(STRUCTURE *psStructure)
{
for (int j = 0; j < size.y; j++)
{
auxClearAll(map.x + i, map.y + j, AUXBITS_ANY_BUILDING | AUXBITS_OUR_BUILDING | AUXBITS_CLOSED_GATE);
auxClearAll(map.x + i, map.y + j, AUXBITS_BLOCKING | AUXBITS_OUR_BUILDING | AUXBITS_NONPASSABLE);
}
}
}
@ -226,7 +226,7 @@ static void auxStructureBlocking(STRUCTURE *psStructure)
for (int j = 0; j < size.y; j++)
{
auxSetAllied(map.x + i, map.y + j, psStructure->player, AUXBITS_OUR_BUILDING);
auxSetAll(map.x + i, map.y + j, AUXBITS_ANY_BUILDING);
auxSetAll(map.x + i, map.y + j, AUXBITS_BLOCKING | AUXBITS_NONPASSABLE);
}
}
}
@ -240,7 +240,7 @@ static void auxStructureOpenGate(STRUCTURE *psStructure)
{
for (int j = 0; j < size.y; j++)
{
auxClearAll(map.x + i, map.y + j, AUXBITS_CLOSED_GATE);
auxClearAll(map.x + i, map.y + j, AUXBITS_BLOCKING);
}
}
}
@ -254,8 +254,8 @@ static void auxStructureClosedGate(STRUCTURE *psStructure)
{
for (int j = 0; j < size.y; j++)
{
auxSetEnemy(map.x + i, map.y + j, psStructure->player, AUXBITS_ANY_BUILDING);
auxSetAll(map.x + i, map.y + j, AUXBITS_CLOSED_GATE);
auxSetEnemy(map.x + i, map.y + j, psStructure->player, AUXBITS_NONPASSABLE);
auxSetAll(map.x + i, map.y + j, AUXBITS_BLOCKING);
}
}
}
@ -3590,7 +3590,7 @@ static void aiUpdateStructure(STRUCTURE *psStructure, bool isMission)
//clear the rearm pad
psDroid->action = DACTION_NONE;
psReArmPad->psObj = NULL;
auxClearAll(map_coord(psStructure->pos.x), map_coord(psStructure->pos.y), AUXBITS_ANY_BUILDING | AUXBITS_OUR_BUILDING);
auxStructureNonblocking(psStructure);
}
}
}