OpenXcom  1.0
Open-source clone of the original X-Com
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Pathfinding.h
1 /*
2  * Copyright 2010-2014 OpenXcom Developers.
3  *
4  * This file is part of OpenXcom.
5  *
6  * OpenXcom is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * OpenXcom is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with OpenXcom. If not, see <http://www.gnu.org/licenses/>.
18  */
19 #ifndef OPENXCOM_PATHFINDING_H
20 #define OPENXCOM_PATHFINDING_H
21 
22 #include <vector>
23 #include "Position.h"
24 #include "PathfindingNode.h"
25 #include "../Ruleset/MapData.h"
26 
27 namespace OpenXcom
28 {
29 
30 class SavedBattleGame;
31 class Tile;
32 class BattleUnit;
33 
38 {
39 private:
40  SavedBattleGame *_save;
41  std::vector<PathfindingNode> _nodes;
42  int _size;
43  BattleUnit *_unit;
44  bool _pathPreviewed;
45  bool _strafeMove;
46  int _totalTUCost;
47  bool _modifierUsed;
48  MovementType _movementType;
50  PathfindingNode *getNode(const Position& pos);
52  bool isBlocked(Tile *tile, const int part, BattleUnit *missileTarget, int bigWallExclusion = -1);
54  bool bresenhamPath(const Position& origin, const Position& target, BattleUnit *missileTarget, bool sneak = false, int maxTUCost = 1000);
56  bool aStarPath(const Position& origin, const Position& target, BattleUnit *missileTarget, bool sneak = false, int maxTUCost = 1000);
58  bool canFallDown(Tile *destinationTile);
60  bool canFallDown(Tile *destinationTile, int size);
61  std::vector<int> _path;
62 public:
64  bool isOnStairs(const Position &startPosition, const Position &endPosition);
66  bool isBlocked(Tile *startTile, Tile *endTile, const int direction, BattleUnit *missileTarget);
67  static const int DIR_UP = 8;
68  static const int DIR_DOWN = 9;
69  enum bigWallTypes{ BLOCK = 1, BIGWALLNESW, BIGWALLNWSE, BIGWALLWEST, BIGWALLNORTH, BIGWALLEAST, BIGWALLSOUTH, BIGWALLEASTANDSOUTH};
70  static const int O_BIGWALL = -1;
74  ~Pathfinding();
76  void calculate(BattleUnit *unit, Position endPosition, BattleUnit *missileTarget = 0, int maxTUCost = 1000);
78  static void directionToVector(const int direction, Position *vector);
80  static void vectorToDirection(const Position &vector, int &dir);
82  int getStartDirection();
84  int dequeuePath();
86  int getTUCost(const Position &startPosition, const int direction, Position *endPosition, BattleUnit *unit, BattleUnit *target, bool missile);
88  void abortPath();
90  bool getStrafeMove() const;
92  bool validateUpDown(BattleUnit *bu, Position startPosition, const int direction);
94  bool previewPath(bool bRemove = false);
96  bool removePreview();
98  void setUnit(BattleUnit *unit);
100  std::vector<int> findReachable(BattleUnit *unit, int tuMax);
102  int getTotalTUCost() const { return _totalTUCost; }
104  bool isPathPreviewed() const;
106  bool isModifierUsed() const;
108  const std::vector<int> &getPath();
110  std::vector<int> copyPath() const;
111 };
112 
113 }
114 
115 #endif
static void directionToVector(const int direction, Position *vector)
Converts direction to a vector.
Definition: Pathfinding.cpp:488
void calculate(BattleUnit *unit, Position endPosition, BattleUnit *missileTarget=0, int maxTUCost=1000)
Calculates the shortest path.
Definition: Pathfinding.cpp:81
int dequeuePath()
Dequeues a direction.
Definition: Pathfinding.cpp:532
Pathfinding(SavedBattleGame *save)
Creates a new Pathfinding class.
Definition: Pathfinding.cpp:42
const std::vector< int > & getPath()
Gets a reference to the path.
Definition: Pathfinding.cpp:1174
bool isModifierUsed() const
Gets the modifier setting.
Definition: Pathfinding.cpp:1165
std::vector< int > copyPath() const
Makes a copy to the path.
Definition: Pathfinding.cpp:1183
int getStartDirection()
Checks whether a path is ready and gives the first direction.
Definition: Pathfinding.cpp:522
std::vector< int > findReachable(BattleUnit *unit, int tuMax)
Gets all reachable tiles, based on cost.
Definition: Pathfinding.cpp:1074
static void vectorToDirection(const Position &vector, int &dir)
Converts a vector to a direction.
Definition: Pathfinding.cpp:503
bool isPathPreviewed() const
Gets the path preview setting.
Definition: Pathfinding.cpp:1139
bool removePreview()
Removes the path preview.
Definition: Pathfinding.cpp:927
int getTUCost(const Position &startPosition, const int direction, Position *endPosition, BattleUnit *unit, BattleUnit *target, bool missile)
Gets the TU cost to move from 1 tile to the other.
Definition: Pathfinding.cpp:250
bool isOnStairs(const Position &startPosition, const Position &endPosition)
Determines whether the unit is going up a stairs.
Definition: Pathfinding.cpp:765
Basic element of which a battle map is build.
Definition: Tile.h:43
A class that holds pathfinding info for a certain node on the map.
Definition: PathfindingNode.h:33
bool getStrafeMove() const
Gets the strafe move setting.
Definition: Pathfinding.cpp:1130
void setUnit(BattleUnit *unit)
Sets _unit in order to abuse low-level pathfinding functions from outside the class.
Definition: Pathfinding.cpp:1148
~Pathfinding()
Cleans up the Pathfinding.
Definition: Pathfinding.cpp:59
A utility class that calculates the shortest path between two points on the battlescape map...
Definition: Pathfinding.h:37
The battlescape data that gets written to disk when the game is saved.
Definition: SavedBattleGame.h:50
void abortPath()
Aborts the current path.
Definition: Pathfinding.cpp:543
Easy handling of X-Y-Z coordinates.
Definition: Position.h:30
bool previewPath(bool bRemove=false)
Previews the path.
Definition: Pathfinding.cpp:839
bool validateUpDown(BattleUnit *bu, Position startPosition, const int direction)
Checks, for the up/down button, if the movement is valid.
Definition: Pathfinding.cpp:805
Represents a moving unit in the battlescape, player controlled or AI controlled it holds info about i...
Definition: BattleUnit.h:58
int getTotalTUCost() const
Gets _totalTUCost; finds out whether we can hike somewhere in this turn or not.
Definition: Pathfinding.h:102