(svn r28004) -Update from Eints:
[openttd.git] / src / pathfinder / yapf / yapf_node.hpp
blobb3021096b39a70191ef06a065439309c7880353e
1 /* $Id$ */
3 /*
4 * This file is part of OpenTTD.
5 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
6 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
7 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
8 */
10 /** @file yapf_node.hpp Node in the pathfinder's graph. */
12 #ifndef YAPF_NODE_HPP
13 #define YAPF_NODE_HPP
15 /** Yapf Node Key that evaluates hash from (and compares) tile & exit dir. */
16 struct CYapfNodeKeyExitDir {
17 TileIndex m_tile;
18 Trackdir m_td;
19 DiagDirection m_exitdir;
21 inline void Set(TileIndex tile, Trackdir td)
23 m_tile = tile;
24 m_td = td;
25 m_exitdir = (m_td == INVALID_TRACKDIR) ? INVALID_DIAGDIR : TrackdirToExitdir(m_td);
28 inline int CalcHash() const
30 return m_exitdir | (m_tile << 2);
33 inline bool operator==(const CYapfNodeKeyExitDir &other) const
35 return m_tile == other.m_tile && m_exitdir == other.m_exitdir;
38 void Dump(DumpTarget &dmp) const
40 dmp.WriteTile("m_tile", m_tile);
41 dmp.WriteEnumT("m_td", m_td);
42 dmp.WriteEnumT("m_exitdir", m_exitdir);
46 struct CYapfNodeKeyTrackDir : public CYapfNodeKeyExitDir
48 inline int CalcHash() const
50 return m_td | (m_tile << 4);
53 inline bool operator==(const CYapfNodeKeyTrackDir &other) const
55 return m_tile == other.m_tile && m_td == other.m_td;
59 /** Yapf Node base */
60 template <class Tkey_, class Tnode>
61 struct CYapfNodeT {
62 typedef Tkey_ Key;
63 typedef Tnode Node;
65 Tkey_ m_key;
66 Node *m_hash_next;
67 Node *m_parent;
68 int m_cost;
69 int m_estimate;
71 inline void Set(Node *parent, TileIndex tile, Trackdir td, bool is_choice)
73 m_key.Set(tile, td);
74 m_hash_next = NULL;
75 m_parent = parent;
76 m_cost = 0;
77 m_estimate = 0;
80 inline Node *GetHashNext()
82 return m_hash_next;
85 inline void SetHashNext(Node *pNext)
87 m_hash_next = pNext;
90 inline TileIndex GetTile() const
92 return m_key.m_tile;
95 inline Trackdir GetTrackdir() const
97 return m_key.m_td;
100 inline const Tkey_& GetKey() const
102 return m_key;
105 inline int GetCost() const
107 return m_cost;
110 inline int GetCostEstimate() const
112 return m_estimate;
115 inline bool operator<(const Node &other) const
117 return m_estimate < other.m_estimate;
120 void Dump(DumpTarget &dmp) const
122 dmp.WriteStructT("m_key", &m_key);
123 dmp.WriteStructT("m_parent", m_parent);
124 dmp.WriteLine("m_cost = %d", m_cost);
125 dmp.WriteLine("m_estimate = %d", m_estimate);
129 #endif /* YAPF_NODE_HPP */