Skip to content

Commit

Permalink
fix some errors in missile pathing
Browse files Browse the repository at this point in the history
  • Loading branch information
Warboy1982 committed Feb 13, 2016
1 parent d843a87 commit abf8bbf
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
33 changes: 25 additions & 8 deletions src/Battlescape/Pathfinding.cpp
Expand Up @@ -192,7 +192,7 @@ bool Pathfinding::aStarPath(const Position &startPosition, const Position &endPo
start->connect(0, 0, 0, endPosition);
PathfindingOpenSet openList;
openList.push(start);
bool missile = (target && maxTUCost == -1);
bool missile = (target && maxTUCost == 10000);
// if the open list is empty, we've reached the end
while (!openList.empty())
{
Expand Down Expand Up @@ -323,7 +323,7 @@ int Pathfinding::getTUCost(const Position &startPosition, int direction, Positio
fellDown = true;
}
}
else if (_movementType == MT_FLY && belowDestination && belowDestination->getUnit() && belowDestination->getUnit() != unit)
else if (!missile && _movementType == MT_FLY && belowDestination && belowDestination->getUnit() && belowDestination->getUnit() != unit)
{
// 2 or more voxels poking into this tile = no go
if (belowDestination->getUnit()->getHeight() + belowDestination->getUnit()->getFloatHeight() - belowDestination->getTerrainLevel() > 26)
Expand All @@ -347,7 +347,7 @@ int Pathfinding::getTUCost(const Position &startPosition, int direction, Positio
else if (direction >= DIR_UP && !fellDown)
{
// check if we can go up or down through gravlift or fly
if (validateUpDown(unit, startPosition + offset, direction))
if (validateUpDown(unit, startPosition + offset, direction, missile))
{
cost = 8; // vertical movement by flying suit or grav lift
}
Expand Down Expand Up @@ -618,10 +618,15 @@ bool Pathfinding::isBlocked(Tile *tile, const int part, BattleUnit *missileTarge
if (unit != 0)
{
if (unit == _unit || unit == missileTarget || unit->isOut()) return false;
if (_unit && _unit->getFaction() == FACTION_PLAYER && unit->getVisible()) return true; // player know all visible units
if (_unit && _unit->getFaction() == unit->getFaction()) return true;
if (_unit && _unit->getFaction() == FACTION_HOSTILE &&
std::find(_unit->getUnitsSpottedThisTurn().begin(), _unit->getUnitsSpottedThisTurn().end(), unit) != _unit->getUnitsSpottedThisTurn().end()) return true;
if (missileTarget && unit != missileTarget && unit->getFaction() == FACTION_HOSTILE)
return true; // AI pathfinding with missiles shouldn't path through their own units
if (_unit)
{
if (_unit->getFaction() == FACTION_PLAYER && unit->getVisible()) return true; // player know all visible units
if (_unit->getFaction() == unit->getFaction()) return true;
if (_unit->getFaction() == FACTION_HOSTILE &&
std::find(_unit->getUnitsSpottedThisTurn().begin(), _unit->getUnitsSpottedThisTurn().end(), unit) != _unit->getUnitsSpottedThisTurn().end()) return true;
}
}
else if (tile->hasNoFloor(0) && _movementType != MT_FLY) // this whole section is devoted to making large units not take part in any kind of falling behaviour
{
Expand Down Expand Up @@ -852,7 +857,7 @@ bool Pathfinding::isOnStairs(const Position &startPosition, const Position &endP
* @param direction Up or Down
* @return bool Whether it's valid.
*/
bool Pathfinding::validateUpDown(BattleUnit *bu, Position startPosition, const int direction)
bool Pathfinding::validateUpDown(BattleUnit *bu, Position startPosition, const int direction, bool missile)
{
Position endPosition;
directionToVector(direction, &endPosition);
Expand All @@ -863,6 +868,18 @@ bool Pathfinding::validateUpDown(BattleUnit *bu, Position startPosition, const i
if (startTile->getMapData(O_FLOOR) && destinationTile && destinationTile->getMapData(O_FLOOR) &&
(startTile->getMapData(O_FLOOR)->isGravLift() && destinationTile->getMapData(O_FLOOR)->isGravLift()))
{
if (missile)
{
if (direction == DIR_UP)
{
if (destinationTile->getMapData(O_FLOOR)->getLoftID(0) != 0)
return false;
}
else if (startTile->getMapData(O_FLOOR)->getLoftID(0) != 0)
{
return false;
}
}
return true;
}
else
Expand Down
2 changes: 1 addition & 1 deletion src/Battlescape/Pathfinding.h
Expand Up @@ -90,7 +90,7 @@ class Pathfinding
/// Gets the strafe move setting.
bool getStrafeMove() const;
/// Checks, for the up/down button, if the movement is valid.
bool validateUpDown(BattleUnit *bu, Position startPosition, const int direction);
bool validateUpDown(BattleUnit *bu, Position startPosition, const int direction, bool missile = false);
/// Previews the path.
bool previewPath(bool bRemove = false);
/// Removes the path preview.
Expand Down

0 comments on commit abf8bbf

Please sign in to comment.