OpenXcom  1.0
Open-source clone of the original X-Com
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
PathfindingNode.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_PATHFINDINGNODE_H
20 #define OPENXCOM_PATHFINDINGNODE_H
21 
22 #include "Position.h"
23 
24 namespace OpenXcom
25 {
26 
27 class PathfindingOpenSet;
28 struct OpenSetEntry;
29 
34 {
35 private:
36  Position _pos;
37  bool _checked;
38  int _tuCost;
39  PathfindingNode* _prevNode;
40  int _prevDir;
42  int _tuGuess;
43  // Invasive field needed by PathfindingOpenSet
44  OpenSetEntry *_openentry;
45  friend class PathfindingOpenSet;
46 public:
52  const Position &getPosition() const;
54  void reset();
56  bool isChecked() const;
58  void setChecked() { _checked = true; }
60  int getTUCost(bool missile) const;
64  int getPrevDir() const;
66  bool inOpenSet() const { return (_openentry != 0); }
68  int getTUGuess() const { return _tuGuess; }
69 
70  #ifdef __MORPHOS__
71  #undef connect
72  #endif
73 
75  void connect(int tuCost, PathfindingNode* prevNode, int prevDir, const Position &target);
77  void connect(int tuCost, PathfindingNode* prevNode, int prevDir);
78 };
79 
84 {
85 public:
92  bool operator()(const PathfindingNode *a, const PathfindingNode *b) const
93  {
94  return a->getTUCost(false) < b->getTUCost(false);
95  }
96 };
97 
98 }
99 
100 #endif
void reset()
Resets the node.
Definition: PathfindingNode.cpp:54
const Position & getPosition() const
Gets the node position.
Definition: PathfindingNode.cpp:46
int getTUGuess() const
Gets the approximate cost to reach the target position.
Definition: PathfindingNode.h:68
void connect(int tuCost, PathfindingNode *prevNode, int prevDir, const Position &target)
Connects to previous node along the path.
Definition: PathfindingNode.cpp:108
Definition: PathfindingOpenSet.h:29
int getPrevDir() const
Gets the previous walking direction.
Definition: PathfindingNode.cpp:95
bool operator()(const PathfindingNode *a, const PathfindingNode *b) const
Compares nodes *a and *b.
Definition: PathfindingNode.h:92
void setChecked()
Marks the node as checked.
Definition: PathfindingNode.h:58
bool isChecked() const
Is checked?
Definition: PathfindingNode.cpp:64
A class that holds pathfinding info for a certain node on the map.
Definition: PathfindingNode.h:33
bool inOpenSet() const
Is this node already in a PathfindingOpenSet?
Definition: PathfindingNode.h:66
A class that holds references to the nodes to be examined in pathfinding.
Definition: PathfindingOpenSet.h:56
Compares PathfindingNode pointers based on TU cost.
Definition: PathfindingNode.h:83
int getTUCost(bool missile) const
Gets the TU cost.
Definition: PathfindingNode.cpp:74
Easy handling of X-Y-Z coordinates.
Definition: Position.h:30
PathfindingNode(Position pos)
Creates a new PathfindingNode class.
Definition: PathfindingNode.cpp:29
~PathfindingNode()
Cleans up the PathfindingNode.
Definition: PathfindingNode.cpp:37
PathfindingNode * getPrevNode() const
Gets the previous node.
Definition: PathfindingNode.cpp:86