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/>.
10 /** @file yapf_node.hpp Node in the pathfinder's graph. */
17 /** Yapf Node Key base class. */
18 struct CYapfNodeKey
: PathPos
{
19 inline void Set(const PathPos
&pos
)
24 void Dump(DumpTarget
&dmp
) const
26 dmp
.WriteTile("m_tile", tile
);
27 dmp
.WriteEnumT("m_td", td
);
31 /** Yapf Node Key that evaluates hash from (and compares) tile & exit dir. */
32 struct CYapfNodeKeyExitDir
: public CYapfNodeKey
34 DiagDirection exitdir
;
36 inline void Set(const PathPos
&pos
)
38 CYapfNodeKey::Set(pos
);
39 exitdir
= (pos
.td
== INVALID_TRACKDIR
) ? INVALID_DIAGDIR
: TrackdirToExitdir(pos
.td
);
42 inline int CalcHash() const
44 return exitdir
| (tile
<< 2);
47 inline bool operator == (const CYapfNodeKeyExitDir
& other
) const
49 return PathTile::operator==(other
) && (exitdir
== other
.exitdir
);
52 void Dump(DumpTarget
&dmp
) const
54 CYapfNodeKey::Dump(dmp
);
55 dmp
.WriteEnumT("m_exitdir", exitdir
);
59 /** Yapf Node Key that evaluates hash from (and compares) tile & track dir. */
60 struct CYapfNodeKeyTrackDir
: public CYapfNodeKey
62 inline int CalcHash() const
64 return (in_wormhole() ? (td
+ 6) : td
) | (tile
<< 4);
67 inline bool operator == (const CYapfNodeKeyTrackDir
& other
) const
69 return PathTile::operator==(other
) && (td
== other
.td
);
74 template <class Tkey_
, class Tnode
>
75 struct CYapfNodeT
: AstarNodeBase
<Tnode
> {
76 typedef AstarNodeBase
<Tnode
> ABase
;
82 inline void Set(Node
*parent
, const PathPos
&pos
)
88 inline const PathPos
& GetPos() const {return m_key
;}
89 inline const Tkey_
& GetKey() const {return m_key
;}
91 void Dump(DumpTarget
&dmp
) const
94 dmp
.WriteStructT("m_key", &m_key
);
98 #endif /* YAPF_NODE_HPP */