yapf/yapf_road.cpp
changeset 4549 106ed18a7675
parent 4411 d5ddc484d4d7
child 4989 3d6541afbbaf
equal deleted inserted replaced
4548:6165e12570bf 4549:106ed18a7675
    62 		return cost;
    62 		return cost;
    63 	}
    63 	}
    64 
    64 
    65 public:
    65 public:
    66 	/** Called by YAPF to calculate the cost from the origin to the given node.
    66 	/** Called by YAPF to calculate the cost from the origin to the given node.
    67 	*   Calculates only the cost of given node, adds it to the parent node cost
    67 	 *  Calculates only the cost of given node, adds it to the parent node cost
    68 	*   and stores the result into Node::m_cost member */
    68 	 *  and stores the result into Node::m_cost member */
    69 	FORCEINLINE bool PfCalcCost(Node& n)
    69 	FORCEINLINE bool PfCalcCost(Node& n)
    70 	{
    70 	{
    71 		int segment_cost = 0;
    71 		int segment_cost = 0;
    72 		// start at n.m_key.m_tile / n.m_key.m_td and walk to the end of segment
    72 		// start at n.m_key.m_tile / n.m_key.m_td and walk to the end of segment
    73 		TileIndex tile = n.m_key.m_tile;
    73 		TileIndex tile = n.m_key.m_tile;
   142 		bool bDest = IsTileDepotType(n.m_segment_last_tile, TRANSPORT_ROAD);
   142 		bool bDest = IsTileDepotType(n.m_segment_last_tile, TRANSPORT_ROAD);
   143 		return bDest;
   143 		return bDest;
   144 	}
   144 	}
   145 
   145 
   146 	/** Called by YAPF to calculate cost estimate. Calculates distance to the destination
   146 	/** Called by YAPF to calculate cost estimate. Calculates distance to the destination
   147 	*   adds it to the actual cost from origin and stores the sum to the Node::m_estimate */
   147 	 *  adds it to the actual cost from origin and stores the sum to the Node::m_estimate */
   148 	FORCEINLINE bool PfCalcEstimate(Node& n)
   148 	FORCEINLINE bool PfCalcEstimate(Node& n)
   149 	{
   149 	{
   150 		n.m_estimate = n.m_cost;
   150 		n.m_estimate = n.m_cost;
   151 		return true;
   151 		return true;
   152 	}
   152 	}
   184 		bool bDest = (n.m_segment_last_tile == m_destTile) && ((m_destTrackdirs & TrackdirToTrackdirBits(n.m_segment_last_td)) != TRACKDIR_BIT_NONE);
   184 		bool bDest = (n.m_segment_last_tile == m_destTile) && ((m_destTrackdirs & TrackdirToTrackdirBits(n.m_segment_last_td)) != TRACKDIR_BIT_NONE);
   185 		return bDest;
   185 		return bDest;
   186 	}
   186 	}
   187 
   187 
   188 	/** Called by YAPF to calculate cost estimate. Calculates distance to the destination
   188 	/** Called by YAPF to calculate cost estimate. Calculates distance to the destination
   189 	*   adds it to the actual cost from origin and stores the sum to the Node::m_estimate */
   189 	 *  adds it to the actual cost from origin and stores the sum to the Node::m_estimate */
   190 	inline bool PfCalcEstimate(Node& n)
   190 	inline bool PfCalcEstimate(Node& n)
   191 	{
   191 	{
   192 		static int dg_dir_to_x_offs[] = {-1, 0, 1, 0};
   192 		static int dg_dir_to_x_offs[] = {-1, 0, 1, 0};
   193 		static int dg_dir_to_y_offs[] = {0, 1, 0, -1};
   193 		static int dg_dir_to_y_offs[] = {0, 1, 0, -1};
   194 		if (PfDetectDestination(n)) {
   194 		if (PfDetectDestination(n)) {
   229 	FORCEINLINE Tpf& Yapf() {return *static_cast<Tpf*>(this);}
   229 	FORCEINLINE Tpf& Yapf() {return *static_cast<Tpf*>(this);}
   230 
   230 
   231 public:
   231 public:
   232 
   232 
   233 	/** Called by YAPF to move from the given node to the next tile. For each
   233 	/** Called by YAPF to move from the given node to the next tile. For each
   234 	*   reachable trackdir on the new tile creates new node, initializes it
   234 	 *  reachable trackdir on the new tile creates new node, initializes it
   235 	*   and adds it to the open list by calling Yapf().AddNewNode(n) */
   235 	 *  and adds it to the open list by calling Yapf().AddNewNode(n) */
   236 	inline void PfFollowNode(Node& old_node)
   236 	inline void PfFollowNode(Node& old_node)
   237 	{
   237 	{
   238 		TrackFollower F(Yapf().GetVehicle());
   238 		TrackFollower F(Yapf().GetVehicle());
   239 		if (F.Follow(old_node.m_segment_last_tile, old_node.m_segment_last_td))
   239 		if (F.Follow(old_node.m_segment_last_tile, old_node.m_segment_last_td))
   240 			Yapf().AddMultipleNodes(&old_node, F.m_new_tile, F.m_new_td_bits);
   240 			Yapf().AddMultipleNodes(&old_node, F.m_new_tile, F.m_new_td_bits);