Ignore wormholes in CYapfNodeKeyExitDir hash function
[openttd/fttd.git] / src / pathfinder / yapf / yapf_node.hpp
blob26c2ec4ea9256bea352cd945a2179fdf506c0f0b
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 #include "../pos.h"
17 /** Yapf Node Key base class. */
18 struct CYapfNodeKey : PathPos {
19 inline void Set(const PathPos &pos)
21 PathPos::set(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);
73 /** Yapf Node base */
74 template <class Tkey_, class Tnode>
75 struct CYapfNodeT : AstarNodeBase<Tnode> {
76 typedef AstarNodeBase<Tnode> ABase;
77 typedef Tkey_ Key;
78 typedef Tnode Node;
80 Tkey_ m_key;
82 inline void Set(Node *parent, const PathPos &pos)
84 ABase::Set (parent);
85 m_key.Set(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
93 ABase::Dump(dmp);
94 dmp.WriteStructT("m_key", &m_key);
98 #endif /* YAPF_NODE_HPP */