From abf8bbf0fe18b801c8e2186e1b8f7497c38a0332 Mon Sep 17 00:00:00 2001 From: Warboy1982 Date: Sat, 13 Feb 2016 21:26:06 +1100 Subject: [PATCH] fix some errors in missile pathing --- src/Battlescape/Pathfinding.cpp | 33 +++++++++++++++++++++++++-------- src/Battlescape/Pathfinding.h | 2 +- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/src/Battlescape/Pathfinding.cpp b/src/Battlescape/Pathfinding.cpp index 6222dc540b..20c7c550b6 100644 --- a/src/Battlescape/Pathfinding.cpp +++ b/src/Battlescape/Pathfinding.cpp @@ -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()) { @@ -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) @@ -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 } @@ -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 { @@ -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); @@ -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 diff --git a/src/Battlescape/Pathfinding.h b/src/Battlescape/Pathfinding.h index 176ba9010a..0caef1d771 100644 --- a/src/Battlescape/Pathfinding.h +++ b/src/Battlescape/Pathfinding.h @@ -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.