OpenXcom  1.0
Open-source clone of the original X-Com
Pathfinding.h
1 #pragma once
2 /*
3  * Copyright 2010-2016 OpenXcom Developers.
4  *
5  * This file is part of OpenXcom.
6  *
7  * OpenXcom is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * OpenXcom is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with OpenXcom. If not, see <http://www.gnu.org/licenses/>.
19  */
20 #include <vector>
21 #include "Position.h"
22 #include "PathfindingNode.h"
23 #include "../Mod/MapData.h"
24 
25 namespace OpenXcom
26 {
27 
28 class SavedBattleGame;
29 class Tile;
30 class BattleUnit;
31 
36 {
37 private:
38  SavedBattleGame *_save;
39  std::vector<PathfindingNode> _nodes;
40  int _size;
41  BattleUnit *_unit;
42  bool _pathPreviewed;
43  bool _strafeMove;
44  int _totalTUCost;
45  bool _modifierUsed;
46  MovementType _movementType;
48  PathfindingNode *getNode(Position pos);
50  bool isBlocked(Tile *tile, const int part, BattleUnit *missileTarget, int bigWallExclusion = -1) const;
52  bool bresenhamPath(Position origin, Position target, BattleUnit *missileTarget, bool sneak = false, int maxTUCost = 1000);
54  bool aStarPath(Position origin, Position target, BattleUnit *missileTarget, bool sneak = false, int maxTUCost = 1000);
56  bool canFallDown(Tile *destinationTile) const;
58  bool canFallDown(Tile *destinationTile, int size) const;
59  std::vector<int> _path;
60 public:
62  bool isOnStairs(Position startPosition, Position endPosition) const;
64  bool isBlocked(Tile *startTile, Tile *endTile, const int direction, BattleUnit *missileTarget);
65  static const int DIR_UP = 8;
66  static const int DIR_DOWN = 9;
67  enum bigWallTypes{ BLOCK = 1, BIGWALLNESW, BIGWALLNWSE, BIGWALLWEST, BIGWALLNORTH, BIGWALLEAST, BIGWALLSOUTH, BIGWALLEASTANDSOUTH, BIGWALLWESTANDNORTH};
68  static const int O_BIGWALL = -1;
69  static int red;
70  static int green;
71  static int yellow;
75  ~Pathfinding();
77  void calculate(BattleUnit *unit, Position endPosition, BattleUnit *missileTarget = 0, int maxTUCost = 1000);
79  static void directionToVector(int direction, Position *vector);
81  static void vectorToDirection(Position vector, int &dir);
83  int getStartDirection() const;
85  int dequeuePath();
87  int getTUCost(Position startPosition, int direction, Position *endPosition, BattleUnit *unit, BattleUnit *target, bool missile);
89  void abortPath();
91  bool getStrafeMove() const;
93  bool validateUpDown(BattleUnit *bu, const Position& startPosition, const int direction, bool missile = false) const;
95  bool previewPath(bool bRemove = false);
97  bool removePreview();
99  void setUnit(BattleUnit *unit);
101  std::vector<int> findReachable(BattleUnit *unit, int tuMax);
103  int getTotalTUCost() const { return _totalTUCost; }
105  bool isPathPreviewed() const;
107  bool isModifierUsed() const;
109  const std::vector<int> &getPath() const;
111  std::vector<int> copyPath() const;
112 };
113 
114 }
int getStartDirection() const
Checks whether a path is ready and gives the first direction.
Definition: Pathfinding.cpp:549
void calculate(BattleUnit *unit, Position endPosition, BattleUnit *missileTarget=0, int maxTUCost=1000)
Calculates the shortest path.
Definition: Pathfinding.cpp:80
int getTUCost(Position startPosition, 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:258
int dequeuePath()
Dequeues a direction.
Definition: Pathfinding.cpp:559
int getTotalTUCost() const
Gets _totalTUCost; finds out whether we can hike somewhere in this turn or not.
Definition: Pathfinding.h:103
Pathfinding(SavedBattleGame *save)
Creates a new Pathfinding class.
Definition: Pathfinding.cpp:41
bool validateUpDown(BattleUnit *bu, const Position &startPosition, const int direction, bool missile=false) const
Checks, for the up/down button, if the movement is valid.
Definition: Pathfinding.cpp:870
bool isModifierUsed() const
Gets the modifier setting.
Definition: Pathfinding.cpp:1247
bool getStrafeMove() const
Gets the strafe move setting.
Definition: Pathfinding.cpp:1212
std::vector< int > findReachable(BattleUnit *unit, int tuMax)
Gets all reachable tiles, based on cost.
Definition: Pathfinding.cpp:1156
bool removePreview()
Removes the path preview.
Definition: Pathfinding.cpp:1009
bool isOnStairs(Position startPosition, Position endPosition) const
Determines whether the unit is going up a stairs.
Definition: Pathfinding.cpp:801
static void directionToVector(int direction, Position *vector)
Converts direction to a vector.
Definition: Pathfinding.cpp:515
Basic element of which a battle map is build.
Definition: Tile.h:42
std::vector< int > copyPath() const
Makes a copy to the path.
Definition: Pathfinding.cpp:1265
A class that holds pathfinding info for a certain node on the map.
Definition: PathfindingNode.h:31
void setUnit(BattleUnit *unit)
Sets _unit in order to abuse low-level pathfinding functions from outside the class.
Definition: Pathfinding.cpp:1230
const std::vector< int > & getPath() const
Gets a reference to the path.
Definition: Pathfinding.cpp:1256
~Pathfinding()
Cleans up the Pathfinding.
Definition: Pathfinding.cpp:58
A utility class that calculates the shortest path between two points on the battlescape map...
Definition: Pathfinding.h:35
The battlescape data that gets written to disk when the game is saved.
Definition: SavedBattleGame.h:47
void abortPath()
Aborts the current path.
Definition: Pathfinding.cpp:570
Easy handling of X-Y-Z coordinates.
Definition: Position.h:28
bool isPathPreviewed() const
Gets the path preview setting.
Definition: Pathfinding.cpp:1221
bool previewPath(bool bRemove=false)
Previews the path.
Definition: Pathfinding.cpp:916
Represents a moving unit in the battlescape, player controlled or AI controlled it holds info about i...
Definition: BattleUnit.h:59
Definition: BaseInfoState.cpp:40
static void vectorToDirection(Position vector, int &dir)
Converts a vector to a direction.
Definition: Pathfinding.cpp:530