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 #include "PathfindingNode.h"
20 #include <math.h>
21
22 namespace OpenXcom
23 {
24
25 /**
26 * Sets up a PathfindingNode.
27 * @param pos Position.
28 */
PathfindingNode(Position pos)29 PathfindingNode::PathfindingNode(Position pos) : _pos(pos), _checked(0), _tuCost(0), _prevNode(0), _prevDir(0), _tuGuess(0), _openentry(0)
30 {
31
32 }
33
34 /**
35 * Deletes the PathfindingNode.
36 */
~PathfindingNode()37 PathfindingNode::~PathfindingNode()
38 {
39
40 }
41
42 /**
43 * Gets the node position.
44 * @return Node position.
45 */
getPosition() const46 const Position &PathfindingNode::getPosition() const
47 {
48 return _pos;
49 }
50
51 /**
52 * Resets the node.
53 */
reset()54 void PathfindingNode::reset()
55 {
56 _checked = false;
57 _openentry = 0;
58 }
59
60 /**
61 * Gets the checked status of this node.
62 * @return True, if this node was checked.
63 */
isChecked() const64 bool PathfindingNode::isChecked() const
65 {
66 return _checked;
67 }
68
69 /**
70 * Gets the TU cost.
71 * @param missile Is this a missile?
72 * @return The TU cost.
73 */
getTUCost(bool missile) const74 int PathfindingNode::getTUCost(bool missile) const
75 {
76 if (missile)
77 return 0;
78 else
79 return _tuCost;
80 }
81
82 /**
83 * Gets the previous node.
84 * @return Pointer to the previous node.
85 */
getPrevNode() const86 PathfindingNode* PathfindingNode::getPrevNode() const
87 {
88 return _prevNode;
89 }
90
91 /**
92 * Gets the previous walking direction for how we got on this node.
93 * @return Previous vector.
94 */
getPrevDir() const95 int PathfindingNode::getPrevDir() const
96 {
97 return _prevDir;
98 }
99
100 /**
101 * Connects the node. This will connect the node to the previous node along the path to @a target
102 * and update the pathfinding information.
103 * @param tuCost The total cost of the path so far.
104 * @param prevNode The previous node along the path.
105 * @param prevDir The direction FROM the previous node.
106 * @param target The target position (used to update our guess cost).
107 */
connect(int tuCost,PathfindingNode * prevNode,int prevDir,const Position & target)108 void PathfindingNode::connect(int tuCost, PathfindingNode* prevNode, int prevDir, const Position &target)
109 {
110 _tuCost = tuCost;
111 _prevNode = prevNode;
112 _prevDir = prevDir;
113 if (!inOpenSet()) // Otherwise we have this already.
114 {
115 Position d = target - _pos;
116 d *= d;
117 _tuGuess = 4 * sqrt((double)d.x + d.y + d.z);
118 }
119 }
120
121 /**
122 * Connects the node. This will connect the node to the previous node along the path.
123 * @param tuCost The total cost of the path so far.
124 * @param prevNode The previous node along the path.
125 * @param prevDir The direction FROM the previous node.
126 */
connect(int tuCost,PathfindingNode * prevNode,int prevDir)127 void PathfindingNode::connect(int tuCost, PathfindingNode* prevNode, int prevDir)
128 {
129 _tuCost = tuCost;
130 _prevNode = prevNode;
131 _prevDir = prevDir;
132 _tuGuess = 0;
133 }
134
135
136 }
137