Codechange: allow mapping enums as parameter and return type from scripts
[openttd-github.git] / src / pathfinder / yapf / yapf_node.hpp
blobd08302e1f1ef240c3334a1d9afda63abd8be106e
1 /*
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/>.
6 */
8 /** @file yapf_node.hpp Node in the pathfinder's graph. */
10 #ifndef YAPF_NODE_HPP
11 #define YAPF_NODE_HPP
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 {
18 TileIndex tile;
19 Trackdir td;
20 DiagDirection exitdir;
22 inline void Set(TileIndex tile, Trackdir td)
24 this->tile = tile;
25 this->td = 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;
60 /** Yapf Node base */
61 template <class Tkey_, class Tnode>
62 struct CYapfNodeT {
63 typedef Tkey_ Key;
64 typedef Tnode Node;
66 Tkey_ key;
67 Node *hash_next;
68 Node *parent;
69 int cost;
70 int estimate;
71 bool is_choice;
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;
78 this->cost = 0;
79 this->estimate = 0;
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
100 return this->key.td;
103 inline const Tkey_ &GetKey() const
105 return this->key;
108 inline int GetCost() const
110 return this->cost;
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 */