MCPcopy Create free account
hub / github.com/OpenXcom/OpenXcom / validateUpDown

Method validateUpDown

src/Battlescape/Pathfinding.cpp:805–832  ·  view source on GitHub ↗

* Checks, for the up/down button, if the movement is valid. Either there is a grav lift or the unit can fly and there are no obstructions. * @param bu Pointer to unit. * @param startPosition Unit starting position. * @param direction Up or Down * @return bool Whether it's valid. */

Source from the content-addressed store, hash-verified

803 * @return bool Whether it's valid.
804 */
805bool Pathfinding::validateUpDown(BattleUnit *bu, Position startPosition, const int direction)
806{
807 Position endPosition;
808 directionToVector(direction, &endPosition);
809 endPosition += startPosition;
810 Tile *startTile = _save->getTile(startPosition);
811 Tile *belowStart = _save->getTile(startPosition + Position(0,0,-1));
812 Tile *destinationTile = _save->getTile(endPosition);
813 if (startTile->getMapData(MapData::O_FLOOR) && destinationTile && destinationTile->getMapData(MapData::O_FLOOR) &&
814 (startTile->getMapData(MapData::O_FLOOR)->isGravLift() && destinationTile->getMapData(MapData::O_FLOOR)->isGravLift()))
815 {
816 return true;
817 }
818 else
819 {
820 if (bu->getArmor()->getMovementType() == MT_FLY)
821 {
822 if ((direction == DIR_UP && destinationTile && !destinationTile->getMapData(MapData::O_FLOOR)) // flying up only possible when there is no roof
823 || (direction == DIR_DOWN && destinationTile && startTile->hasNoFloor(belowStart)) // falling down only possible when there is no floor
824 )
825 {
826 return true;
827 }
828 }
829 }
830
831 return false;
832}
833
834/**
835 * Marks tiles for the path preview.

Callers 2

btnUnitUpClickMethod · 0.80
btnUnitDownClickMethod · 0.80

Calls 7

isGravLiftMethod · 0.80
getMovementTypeMethod · 0.80
hasNoFloorMethod · 0.80
PositionClass · 0.70
getTileMethod · 0.45
getMapDataMethod · 0.45
getArmorMethod · 0.45

Tested by

no test coverage detected