2 * This file is part of OpenTTD.
3 * 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.
4 * 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.
5 * 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 /** @file yapf_node.hpp Node in the pathfinder's graph. */
13 /** Yapf Node Key that evaluates hash from (and compares) tile & exit dir. */
14 struct CYapfNodeKeyExitDir
{
17 DiagDirection m_exitdir
;
19 inline void Set(TileIndex tile
, Trackdir td
)
23 m_exitdir
= (m_td
== INVALID_TRACKDIR
) ? INVALID_DIAGDIR
: TrackdirToExitdir(m_td
);
26 inline int CalcHash() const
28 return m_exitdir
| (m_tile
.base() << 2);
31 inline bool operator==(const CYapfNodeKeyExitDir
&other
) const
33 return m_tile
== other
.m_tile
&& m_exitdir
== other
.m_exitdir
;
36 void Dump(DumpTarget
&dmp
) const
38 dmp
.WriteTile("m_tile", m_tile
);
39 dmp
.WriteEnumT("m_td", m_td
);
40 dmp
.WriteEnumT("m_exitdir", m_exitdir
);
44 struct CYapfNodeKeyTrackDir
: public CYapfNodeKeyExitDir
46 inline int CalcHash() const
48 return m_td
| (m_tile
.base() << 4);
51 inline bool operator==(const CYapfNodeKeyTrackDir
&other
) const
53 return m_tile
== other
.m_tile
&& m_td
== other
.m_td
;
58 template <class Tkey_
, class Tnode
>
70 inline void Set(Node
*parent
, TileIndex tile
, Trackdir td
, bool is_choice
)
73 m_hash_next
= nullptr;
77 m_is_choice
= is_choice
;
80 inline Node
*GetHashNext()
85 inline void SetHashNext(Node
*pNext
)
90 inline TileIndex
GetTile() const
95 inline Trackdir
GetTrackdir() const
100 inline const Tkey_
&GetKey() const
105 inline int GetCost() const
110 inline int GetCostEstimate() const
115 inline bool GetIsChoice() const
120 inline bool operator<(const Node
&other
) const
122 return m_estimate
< other
.m_estimate
;
125 void Dump(DumpTarget
&dmp
) const
127 dmp
.WriteStructT("m_key", &m_key
);
128 dmp
.WriteStructT("m_parent", m_parent
);
129 dmp
.WriteValue("m_cost", m_cost
);
130 dmp
.WriteValue("m_estimate", m_estimate
);
134 #endif /* YAPF_NODE_HPP */