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 #include "../../track_func.h"
14 #include "../../misc/dbg_helpers.h"
16 /** Yapf Node Key that evaluates hash from (and compares) tile & exit dir. */
17 struct CYapfNodeKeyExitDir
{
20 DiagDirection exitdir
;
22 inline void Set(TileIndex tile
, Trackdir td
)
26 this->exitdir
= (this->td
== INVALID_TRACKDIR
) ? INVALID_DIAGDIR
: TrackdirToExitdir(this->td
);
29 inline int CalcHash() const
31 return this->exitdir
| (this->tile
.base() << 2);
34 inline bool operator==(const CYapfNodeKeyExitDir
&other
) const
36 return this->tile
== other
.tile
&& this->exitdir
== other
.exitdir
;
39 void Dump(DumpTarget
&dmp
) const
41 dmp
.WriteTile("tile", this->tile
);
42 dmp
.WriteEnumT("td", this->td
);
43 dmp
.WriteEnumT("exitdir", this->exitdir
);
47 struct CYapfNodeKeyTrackDir
: public CYapfNodeKeyExitDir
49 inline int CalcHash() const
51 return this->td
| (this->tile
.base() << 4);
54 inline bool operator==(const CYapfNodeKeyTrackDir
&other
) const
56 return this->tile
== other
.tile
&& this->td
== other
.td
;
61 template <class Tkey_
, class Tnode
>
73 inline void Set(Node
*parent
, TileIndex tile
, Trackdir td
, bool is_choice
)
75 this->key
.Set(tile
, td
);
76 this->hash_next
= nullptr;
77 this->parent
= parent
;
80 this->is_choice
= is_choice
;
83 inline Node
*GetHashNext()
85 return this->hash_next
;
88 inline void SetHashNext(Node
*pNext
)
90 this->hash_next
= pNext
;
93 inline TileIndex
GetTile() const
95 return this->key
.tile
;
98 inline Trackdir
GetTrackdir() const
103 inline const Tkey_
&GetKey() const
108 inline int GetCost() const
113 inline int GetCostEstimate() const
115 return this->estimate
;
118 inline bool GetIsChoice() const
120 return this->is_choice
;
123 inline bool operator<(const Node
&other
) const
125 return this->estimate
< other
.estimate
;
128 void Dump(DumpTarget
&dmp
) const
130 dmp
.WriteStructT("key", &this->key
);
131 dmp
.WriteStructT("parent", this->parent
);
132 dmp
.WriteValue("cost", this->cost
);
133 dmp
.WriteValue("estimate", this->estimate
);
137 #endif /* YAPF_NODE_HPP */