KUDr@3900: /* $Id$ */ KUDr@3900: bjarni@6268: /** @file yapf_node.hpp */ bjarni@6268: KUDr@3900: #ifndef YAPF_NODE_HPP KUDr@3900: #define YAPF_NODE_HPP KUDr@3900: KUDr@3900: /** Yapf Node Key that evaluates hash from (and compares) tile & exit dir. */ KUDr@3900: struct CYapfNodeKeyExitDir { KUDr@3900: TileIndex m_tile; KUDr@3900: Trackdir m_td; KUDr@3900: DiagDirection m_exitdir; KUDr@3900: KUDr@3900: FORCEINLINE void Set(TileIndex tile, Trackdir td) KUDr@3900: { KUDr@3900: m_tile = tile; KUDr@3900: m_td = td; KUDr@3900: m_exitdir = (m_td == INVALID_TRACKDIR) ? INVALID_DIAGDIR : TrackdirToExitdir(m_td); KUDr@3900: } KUDr@3900: KUDr@3900: FORCEINLINE int CalcHash() const {return m_exitdir | (m_tile << 2);} KUDr@3900: FORCEINLINE bool operator == (const CYapfNodeKeyExitDir& other) const {return (m_tile == other.m_tile) && (m_exitdir == other.m_exitdir);} KUDr@3900: }; KUDr@3900: KUDr@3900: struct CYapfNodeKeyTrackDir : public CYapfNodeKeyExitDir KUDr@3900: { KUDr@3900: FORCEINLINE int CalcHash() const {return m_td | (m_tile << 4);} KUDr@3900: FORCEINLINE bool operator == (const CYapfNodeKeyTrackDir& other) const {return (m_tile == other.m_tile) && (m_td == other.m_td);} KUDr@3900: }; KUDr@3900: KUDr@3900: /** Yapf Node base */ KUDr@3900: template KUDr@3900: struct CYapfNodeT { KUDr@3900: typedef Tkey_ Key; KUDr@3900: typedef Tnode Node; KUDr@3900: KUDr@3900: Tkey_ m_key; KUDr@3900: Node *m_hash_next; KUDr@3900: Node *m_parent; KUDr@3900: int m_cost; KUDr@3900: int m_estimate; KUDr@3900: KUDr@3978: FORCEINLINE void Set(Node *parent, TileIndex tile, Trackdir td, bool is_choice) KUDr@3900: { KUDr@3900: m_key.Set(tile, td); KUDr@3900: m_hash_next = NULL; KUDr@3900: m_parent = parent; KUDr@3900: m_cost = 0; KUDr@3900: m_estimate = 0; KUDr@3900: } KUDr@3900: KUDr@3900: FORCEINLINE Node* GetHashNext() {return m_hash_next;} KUDr@3900: FORCEINLINE void SetHashNext(Node *pNext) {m_hash_next = pNext;} KUDr@3900: FORCEINLINE TileIndex GetTile() const {return m_key.m_tile;} KUDr@3900: FORCEINLINE Trackdir GetTrackdir() const {return m_key.m_td;} KUDr@3900: FORCEINLINE const Tkey_& GetKey() const {return m_key;} KUDr@3900: FORCEINLINE int GetCost() {return m_cost;} KUDr@3900: FORCEINLINE int GetCostEstimate() {return m_estimate;} KUDr@3900: FORCEINLINE bool operator < (const Node& other) const {return m_estimate < other.m_estimate;} KUDr@3900: }; KUDr@3900: KUDr@3900: /** Yapf Node for ships */ KUDr@3900: template KUDr@3900: struct CYapfShipNodeT KUDr@3900: : CYapfNodeT > KUDr@3900: { KUDr@3900: KUDr@3900: }; KUDr@3900: KUDr@3900: // now define two major node types (that differ by key type) KUDr@3900: typedef CYapfShipNodeT CYapfShipNodeExitDir; KUDr@3900: typedef CYapfShipNodeT CYapfShipNodeTrackDir; KUDr@3900: KUDr@3900: // Default NodeList types KUDr@3900: typedef CNodeList_HashTableT CShipNodeListExitDir; KUDr@3900: typedef CNodeList_HashTableT CShipNodeListTrackDir; KUDr@3900: KUDr@3900: KUDr@3900: #endif /* YAPF_NODE_HPP */