yapf/yapf_ship.cpp
changeset 3914 6bdd22b93698
parent 3900 2c84ed52709d
child 3971 77061ae9b534
equal deleted inserted replaced
3913:1a104ca49e17 3914:6bdd22b93698
     7 /** Node Follower module of YAPF for ships */
     7 /** Node Follower module of YAPF for ships */
     8 template <class Types>
     8 template <class Types>
     9 class CYapfFollowShipT
     9 class CYapfFollowShipT
    10 {
    10 {
    11 public:
    11 public:
    12 	typedef typename Types::Tpf Tpf;
    12 	typedef typename Types::Tpf Tpf;                     ///< the pathfinder class (derived from THIS class)
    13 	typedef typename Types::TrackFollower TrackFollower;
    13 	typedef typename Types::TrackFollower TrackFollower;
    14 	typedef typename Types::NodeList::Titem Node; ///< this will be our node type
    14 	typedef typename Types::NodeList::Titem Node;        ///< this will be our node type
    15 	typedef typename Node::Key Key;    ///< key to hash tables
    15 	typedef typename Node::Key Key;                      ///< key to hash tables
    16 
    16 
    17 protected:
    17 protected:
       
    18 	/// to access inherited path finder
    18 	FORCEINLINE Tpf& Yapf() {return *static_cast<Tpf*>(this);}
    19 	FORCEINLINE Tpf& Yapf() {return *static_cast<Tpf*>(this);}
    19 
    20 
    20 public:
    21 public:
       
    22 	/** Called by YAPF to move from the given node to the next tile. For each
       
    23 	*   reachable trackdir on the new tile creates new node, initializes it
       
    24 	*   and adds it to the open list by calling Yapf().AddNewNode(n) */
    21 	inline void PfFollowNode(Node& old_node)
    25 	inline void PfFollowNode(Node& old_node)
    22 	{
    26 	{
    23 		TrackFollower F;
    27 		TrackFollower F;
    24 		if (F.Follow(old_node.m_key.m_tile, old_node.m_key.m_td))
    28 		if (F.Follow(old_node.m_key.m_tile, old_node.m_key.m_td))
    25 			Yapf().AddMultipleNodes(&old_node, F.m_new_tile, F.m_new_td_bits);
    29 			Yapf().AddMultipleNodes(&old_node, F.m_new_tile, F.m_new_td_bits);
    26 	}
    30 	}
    27 
    31 
       
    32 	/// return debug report character to identify the transportation type
    28 	FORCEINLINE char TransportTypeChar() const {return 'w';}
    33 	FORCEINLINE char TransportTypeChar() const {return 'w';}
    29 
    34 
    30 	static Trackdir ChooseShipTrack(Vehicle *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks)
    35 	static Trackdir ChooseShipTrack(Vehicle *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks)
    31 	{
    36 	{
    32 		// handle special case - when next tile is destination tile
    37 		// handle special case - when next tile is destination tile
    78 /** Cost Provider module of YAPF for ships */
    83 /** Cost Provider module of YAPF for ships */
    79 template <class Types>
    84 template <class Types>
    80 class CYapfCostShipT
    85 class CYapfCostShipT
    81 {
    86 {
    82 public:
    87 public:
    83 	typedef typename Types::Tpf Tpf;
    88 	typedef typename Types::Tpf Tpf;              ///< the pathfinder class (derived from THIS class)
    84 	typedef typename Types::NodeList::Titem Node; ///< this will be our node type
    89 	typedef typename Types::NodeList::Titem Node; ///< this will be our node type
    85 	typedef typename Node::Key Key;    ///< key to hash tables
    90 	typedef typename Node::Key Key;               ///< key to hash tables
    86 
    91 
    87 protected:
    92 protected:
       
    93 	/// to access inherited path finder
    88 	Tpf& Yapf() {return *static_cast<Tpf*>(this);}
    94 	Tpf& Yapf() {return *static_cast<Tpf*>(this);}
    89 
    95 
    90 public:
    96 public:
       
    97 	/** Called by YAPF to calculate the cost from the origin to the given node.
       
    98 	*   Calculates only the cost of given node, adds it to the parent node cost
       
    99 	*   and stores the result into Node::m_cost member */
    91 	FORCEINLINE bool PfCalcCost(Node& n)
   100 	FORCEINLINE bool PfCalcCost(Node& n)
    92 	{
   101 	{
    93 		// base tile cost depending on distance
   102 		// base tile cost depending on distance
    94 		int c = IsDiagonalTrackdir(n.GetTrackdir()) ? 10 : 7;
   103 		int c = IsDiagonalTrackdir(n.GetTrackdir()) ? 10 : 7;
    95 		// additional penalty for curves
   104 		// additional penalty for curves