Skip to content

Commit

Permalink
Add support for multiple weapons and differentiate between air and gr…
Browse files Browse the repository at this point in the history
…ound hitting weapon types. Early support for AA threat maps. Patch reviewed by SafetyOff. Ref ticket:2203
  • Loading branch information
perim committed Oct 17, 2010
1 parent 5b45925 commit 1477265
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 11 deletions.
47 changes: 39 additions & 8 deletions src/map.c
Expand Up @@ -2262,7 +2262,7 @@ static void dangerFloodFill(int player)
} while (open);
}

static inline void threatUpdate(int player, BASE_OBJECT *psObj)
static inline void threatUpdate(int player, BASE_OBJECT *psObj, bool ground, bool air)
{
int i;

Expand All @@ -2272,15 +2272,22 @@ static inline void threatUpdate(int player, BASE_OBJECT *psObj)
{
const TILEPOS pos = psObj->watchedTiles[i];
MAPTILE *psTile = mapTile(pos.x, pos.y);
psTile->threatBits |= (1 << player); // set threat for this tile
if (ground)
{
psTile->threatBits |= (1 << player); // set ground threat for this tile
}
if (air)
{
psTile->aaThreatBits |= (1 << player); // set air threat for this tile
}
}
}
}

static void dangerUpdate(int player)
{
MAPTILE *psTile = psMapTiles;
int i;
int i, weapon;

// Step 1: Clear our threat bits, set our danger bits
for (i = 0; i < mapWidth * mapHeight; i++, psTile++)
Expand All @@ -2297,18 +2304,42 @@ static void dangerUpdate(int player)

for (psDroid = apsDroidLists[i]; psDroid; psDroid = psDroid->psNext)
{
if (psDroid->droidType != DROID_CONSTRUCT && psDroid->droidType != DROID_CYBORG_CONSTRUCT
&& psDroid->droidType != DROID_REPAIR && psDroid->droidType != DROID_CYBORG_REPAIR)
UBYTE mode = 0;

if (psDroid->droidType == DROID_CONSTRUCT || psDroid->droidType == DROID_CYBORG_CONSTRUCT
|| psDroid->droidType == DROID_REPAIR || psDroid->droidType == DROID_CYBORG_REPAIR)
{
continue; // hack that really should not be needed, but is -- trucks can SHOOT_ON_GROUND...!
}
for (weapon = 0; weapon < psDroid->numWeaps; weapon++)
{
threatUpdate(player, (BASE_OBJECT *)psDroid);
mode |= asWeaponStats[psDroid->asWeaps[weapon].nStat].surfaceToAir;
}
if (psDroid->droidType == DROID_SENSOR) // special treatment for sensor turrets, no multiweapon support
{
mode |= SHOOT_ON_GROUND; // assume it only shoots at ground targets for now
}
if (mode > 0)
{
threatUpdate(player, (BASE_OBJECT *)psDroid, mode & SHOOT_ON_GROUND, mode & SHOOT_IN_AIR);
}
}

for (psStruct = apsStructLists[i]; psStruct; psStruct = psStruct->psNext)
{
if (psStruct->pStructureType->pSensor->location == LOC_TURRET || psStruct->numWeaps > 0)
UBYTE mode = 0;

for (weapon = 0; weapon < psStruct->numWeaps; weapon++)
{
mode |= asWeaponStats[psStruct->asWeaps[weapon].nStat].surfaceToAir;
}
if (psStruct->pStructureType->pSensor->location == LOC_TURRET) // special treatment for sensor turrets
{
mode |= SHOOT_ON_GROUND; // assume it only shoots at ground targets for now
}
if (mode > 0)
{
threatUpdate(player, (BASE_OBJECT *)psStruct);
threatUpdate(player, (BASE_OBJECT *)psStruct, mode & SHOOT_ON_GROUND, mode & SHOOT_IN_AIR);
}
}
}
Expand Down
7 changes: 4 additions & 3 deletions src/map.h
Expand Up @@ -104,11 +104,12 @@ typedef struct _maptile
uint8_t tileExploredBits;
uint8_t sensorBits; // bit per player, who can see tile with sensor
uint8_t dangerBits; // bit per player, does AI sense danger going there? not always up to date
uint8_t threatBits; // bit per player, can hostile player shoot here? not always up to date
float height; // The height at the top left of the tile
uint8_t threatBits; // bit per player, can hostile players shoot here? not always up to date
uint8_t aaThreatBits; // bit per player, can hostile players shoot at my VTOLs here?
uint8_t illumination; // How bright is this tile?
uint16_t texture; // Which graphics texture is on this tile
uint8_t watchers[MAX_PLAYERS]; // player sees through fog of war here with this many objects
uint16_t texture; // Which graphics texture is on this tile
float height; // The height at the top left of the tile
float level;
BASE_OBJECT *psObject; // Any object sitting on the location (e.g. building)
PIELIGHT colour;
Expand Down

0 comments on commit 1477265

Please sign in to comment.