src/yapf/yapf_ship.cpp
branchcpp_gui
changeset 6268 4b5241e5dd10
parent 5726 8f399788f6c9
child 6308 646711c5feaa
equal deleted inserted replaced
6267:7c8ec33959b1 6268:4b5241e5dd10
     1 /* $Id$ */
     1 /* $Id$ */
       
     2 
       
     3 /** @file yapf_ship.cpp */
     2 
     4 
     3 #include "../stdafx.h"
     5 #include "../stdafx.h"
     4 
     6 
     5 #include "yapf.hpp"
     7 #include "yapf.hpp"
     6 
     8 
    24 	 *  and adds it to the open list by calling Yapf().AddNewNode(n) */
    26 	 *  and adds it to the open list by calling Yapf().AddNewNode(n) */
    25 	inline void PfFollowNode(Node& old_node)
    27 	inline void PfFollowNode(Node& old_node)
    26 	{
    28 	{
    27 		TrackFollower F;
    29 		TrackFollower F;
    28 		if (F.Follow(old_node.m_key.m_tile, old_node.m_key.m_td))
    30 		if (F.Follow(old_node.m_key.m_tile, old_node.m_key.m_td))
    29 			Yapf().AddMultipleNodes(&old_node, F.m_new_tile, F.m_new_td_bits);
    31 			Yapf().AddMultipleNodes(&old_node, F);
    30 	}
    32 	}
    31 
    33 
    32 	/// return debug report character to identify the transportation type
    34 	/// return debug report character to identify the transportation type
    33 	FORCEINLINE char TransportTypeChar() const {return 'w';}
    35 	FORCEINLINE char TransportTypeChar() const {return 'w';}
    34 
    36 
    84 template <class Types>
    86 template <class Types>
    85 class CYapfCostShipT
    87 class CYapfCostShipT
    86 {
    88 {
    87 public:
    89 public:
    88 	typedef typename Types::Tpf Tpf;              ///< the pathfinder class (derived from THIS class)
    90 	typedef typename Types::Tpf Tpf;              ///< the pathfinder class (derived from THIS class)
       
    91 	typedef typename Types::TrackFollower TrackFollower;
    89 	typedef typename Types::NodeList::Titem Node; ///< this will be our node type
    92 	typedef typename Types::NodeList::Titem Node; ///< this will be our node type
    90 	typedef typename Node::Key Key;               ///< key to hash tables
    93 	typedef typename Node::Key Key;               ///< key to hash tables
    91 
    94 
    92 protected:
    95 protected:
    93 	/// to access inherited path finder
    96 	/// to access inherited path finder
    95 
    98 
    96 public:
    99 public:
    97 	/** Called by YAPF to calculate the cost from the origin to the given node.
   100 	/** 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
   101 	 *  Calculates only the cost of given node, adds it to the parent node cost
    99 	 *  and stores the result into Node::m_cost member */
   102 	 *  and stores the result into Node::m_cost member */
   100 	FORCEINLINE bool PfCalcCost(Node& n)
   103 	FORCEINLINE bool PfCalcCost(Node& n, const TrackFollower &tf)
   101 	{
   104 	{
   102 		// base tile cost depending on distance
   105 		// base tile cost depending on distance
   103 		int c = IsDiagonalTrackdir(n.GetTrackdir()) ? 10 : 7;
   106 		int c = IsDiagonalTrackdir(n.GetTrackdir()) ? 10 : 7;
   104 		// additional penalty for curves
   107 		// additional penalty for curves
   105 		if (n.m_parent != NULL && n.GetTrackdir() != n.m_parent->GetTrackdir()) c += 3;
   108 		if (n.m_parent != NULL && n.GetTrackdir() != n.m_parent->GetTrackdir()) c += 3;