* 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. */
| 803 | * @return bool Whether it's valid. |
| 804 | */ |
| 805 | bool 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. |
no test coverage detected