Changeset - r12493:6da69ce1ff42
[Not reviewed]
master
0 10 0
rubidium - 15 years ago 2009-07-24 15:18:25
rubidium@openttd.org
(svn r16940) -Codechange: make the pathfinders behave the same when finding waypoints or stations, i.e. don't force exactly one destination tile for a waypoint
10 files changed with 50 insertions and 44 deletions:
0 comments (0 inline, 0 general)
src/base_station_base.h
Show inline comments
 
@@ -85,6 +85,24 @@ struct BaseStation : StationPool::PoolIt
 
	 */
 
	virtual void GetTileArea(TileArea *ta, StationType type) const = 0;
 

	
 

	
 
	/**
 
	 * Obtain the length of a platform
 
	 * @pre tile must be a rail station tile
 
	 * @param tile A tile that contains the platform in question
 
	 * @return The length of the platform
 
	 */
 
	virtual uint GetPlatformLength(TileIndex tile, DiagDirection dir) const = 0;
 

	
 
	/**
 
	 * Determines the REMAINING length of a platform, starting at (and including)
 
	 * the given tile.
 
	 * @param tile the tile from which to start searching. Must be a rail station tile
 
	 * @param dir The direction in which to search.
 
	 * @return The platform length
 
	 */
 
	virtual uint GetPlatformLength(TileIndex tile) const = 0;
 

	
 
	/**
 
	 * Get the base station belonging to a specific tile.
 
	 * @param tile The tile to get the base station from.
src/npf.cpp
Show inline comments
 
@@ -1103,7 +1103,7 @@ void NPFFillWithOrderData(NPFFindStation
 
	 * dest_tile, not just any stop of that station.
 
	 * So only for train orders to stations we fill fstd->station_index, for all
 
	 * others only dest_coords */
 
	if (v->current_order.IsType(OT_GOTO_STATION) && v->type == VEH_TRAIN) {
 
	if (v->type == VEH_TRAIN && (v->current_order.IsType(OT_GOTO_STATION) || v->current_order.IsType(OT_GOTO_WAYPOINT))) {
 
		fstd->station_index = v->current_order.GetDestination();
 
		/* Let's take the closest tile of the station as our target for trains */
 
		fstd->dest_coords = CalcClosestStationTile(fstd->station_index, v->tile);
src/order_cmd.cpp
Show inline comments
 
@@ -412,9 +412,9 @@ static TileIndex GetOrderLocation(const 
 
{
 
	switch (o.GetType()) {
 
		default: NOT_REACHED();
 
		case OT_GOTO_WAYPOINT: // This function is only called for ships, thus waypoints are buoys which are stations.
 
		case OT_GOTO_STATION: return Station::Get(o.GetDestination())->xy;
 
		case OT_GOTO_DEPOT:   return Depot::Get(o.GetDestination())->xy;
 
		case OT_GOTO_WAYPOINT: return Waypoint::Get(o.GetDestination())->xy;
 
		case OT_GOTO_STATION:  return Station::Get(o.GetDestination())->xy;
 
		case OT_GOTO_DEPOT:    return Depot::Get(o.GetDestination())->xy;
 
	}
 
}
 

	
 
@@ -1688,11 +1688,7 @@ bool UpdateOrderDest(Vehicle *v, const O
 
			break;
 

	
 
		case OT_GOTO_WAYPOINT:
 
			if (v->type == VEH_TRAIN) {
 
				v->dest_tile = Waypoint::Get(order->GetDestination())->xy;
 
			} else {
 
				v->dest_tile = Station::Get(order->GetDestination())->xy;
 
			}
 
			v->dest_tile = Waypoint::Get(order->GetDestination())->xy;
 
			return true;
 

	
 
		case OT_CONDITIONAL: {
 
@@ -1755,17 +1751,11 @@ bool ProcessOrders(Vehicle *v)
 
	 */
 
	bool may_reverse = v->current_order.IsType(OT_NOTHING);
 

	
 
	/* Check if we've reached the waypoint? */
 
	if (v->current_order.IsType(OT_GOTO_WAYPOINT) && v->tile == v->dest_tile) {
 
		UpdateVehicleTimetable(v, true);
 
		v->IncrementOrderIndex();
 
	}
 

	
 
	/* Check if we've reached a non-stop station.. */
 
	if (v->current_order.IsType(OT_GOTO_STATION) && (v->current_order.GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION) &&
 
	if (((v->current_order.IsType(OT_GOTO_STATION) && (v->current_order.GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION)) || v->current_order.IsType(OT_GOTO_WAYPOINT)) &&
 
			IsTileType(v->tile, MP_STATION) &&
 
			v->current_order.GetDestination() == GetStationIndex(v->tile)) {
 
		v->last_station_visited = v->current_order.GetDestination();
 
		if (v->current_order.IsType(OT_GOTO_STATION)) v->last_station_visited = v->current_order.GetDestination();
 
		UpdateVehicleTimetable(v, true);
 
		v->IncrementOrderIndex();
 
	}
src/pathfind.h
Show inline comments
 
@@ -7,6 +7,7 @@
 

	
 
#include "direction_type.h"
 
#include "station_base.h"
 
#include "waypoint_base.h"
 

	
 
enum {
 
	STR_FACTOR  = 2,
 
@@ -89,7 +90,10 @@ void NewTrainPathfind(TileIndex tile, Ti
 
 */
 
static inline TileIndex CalcClosestStationTile(StationID station, TileIndex tile)
 
{
 
	const Station *st = Station::Get(station);
 
	const BaseStation *bst = BaseStation::Get(station);
 
	if (Waypoint::IsExpected(bst)) return bst->xy;
 

	
 
	const Station *st = Station::From(bst);
 

	
 
	/* If the rail station is (temporarily) not present, use the station sign to drive near the station */
 
	if (st->train_tile == INVALID_TILE) return st->xy;
src/station.cpp
Show inline comments
 
@@ -181,12 +181,7 @@ void Station::MarkTilesDirty(bool cargo_
 
	}
 
}
 

	
 
/** Obtain the length of a platform
 
 * @pre tile must be a rail station tile
 
 * @param tile A tile that contains the platform in question
 
 * @return The length of the platform
 
 */
 
uint Station::GetPlatformLength(TileIndex tile) const
 
/* virtual */ uint Station::GetPlatformLength(TileIndex tile) const
 
{
 
	assert(this->TileBelongsToRailStation(tile));
 

	
 
@@ -208,13 +203,7 @@ uint Station::GetPlatformLength(TileInde
 
	return len - 1;
 
}
 

	
 
/** Determines the REMAINING length of a platform, starting at (and including)
 
 * the given tile.
 
 * @param tile the tile from which to start searching. Must be a rail station tile
 
 * @param dir The direction in which to search.
 
 * @return The platform length
 
 */
 
uint Station::GetPlatformLength(TileIndex tile, DiagDirection dir) const
 
/* virtual */ uint Station::GetPlatformLength(TileIndex tile, DiagDirection dir) const
 
{
 
	TileIndex start_tile = tile;
 
	uint length = 0;
 
@@ -222,7 +211,7 @@ uint Station::GetPlatformLength(TileInde
 
	assert(dir < DIAGDIR_END);
 

	
 
	do {
 
		length ++;
 
		length++;
 
		tile += TileOffsByDiagDir(dir);
 
	} while (IsCompatibleTrainStationTile(tile, start_tile));
 

	
src/station_base.h
Show inline comments
 
@@ -124,8 +124,8 @@ public:
 

	
 
	void UpdateVirtCoord();
 

	
 
	uint GetPlatformLength(TileIndex tile, DiagDirection dir) const;
 
	uint GetPlatformLength(TileIndex tile) const;
 
	/* virtual */ uint GetPlatformLength(TileIndex tile, DiagDirection dir) const;
 
	/* virtual */ uint GetPlatformLength(TileIndex tile) const;
 
	void RecomputeIndustriesNear();
 
	static void RecomputeIndustriesNearForAll();
 

	
src/waypoint_base.h
Show inline comments
 
@@ -24,6 +24,16 @@ struct Waypoint : SpecializedStation<Way
 
	/* virtual */ uint32 GetNewGRFVariable(const struct ResolverObject *object, byte variable, byte parameter, bool *available) const;
 

	
 
	/* virtual */ void GetTileArea(TileArea *ta, StationType type) const;
 

	
 
	/* virtual */ uint GetPlatformLength(TileIndex tile, DiagDirection dir) const
 
	{
 
		return 1;
 
	}
 

	
 
	/* virtual */ uint GetPlatformLength(TileIndex tile) const
 
	{
 
		return 1;
 
	}
 
};
 

	
 
#define FOR_ALL_WAYPOINTS(var) FOR_ALL_BASE_STATIONS_OF_TYPE(Waypoint, var)
src/yapf/follow_track.hpp
Show inline comments
 
@@ -191,7 +191,7 @@ protected:
 
		m_new_tile = TILE_ADD(m_old_tile, diff);
 

	
 
		/* special handling for stations */
 
		if (IsRailTT() && IsRailStationTile(m_new_tile)) {
 
		if (IsRailTT() && HasStationTileRail(m_new_tile)) {
 
			m_is_station = true;
 
		} else if (IsRoadTT() && IsRoadStopTile(m_new_tile)) {
 
			m_is_station = true;
 
@@ -346,7 +346,7 @@ protected:
 
		if (IsRailTT() && m_is_station) {
 
			/* entered railway station
 
			 * get platform length */
 
			uint length = Station::GetByTile(m_new_tile)->GetPlatformLength(m_new_tile, TrackdirToExitdir(m_old_td));
 
			uint length = BaseStation::GetByTile(m_new_tile)->GetPlatformLength(m_new_tile, TrackdirToExitdir(m_old_td));
 
			/* how big step we must do to get to the last platform tile; */
 
			m_tiles_skipped = length - 1;
 
			/* move to the platform end */
src/yapf/yapf_costrail.hpp
Show inline comments
 
@@ -543,7 +543,7 @@ no_entry_cost: // jump here at the begin
 

	
 
			/* Station platform-length penalty. */
 
			if ((end_segment_reason & ESRB_STATION) != ESRB_NONE) {
 
				Station *st = Station::GetByTile(n.GetLastTile());
 
				const BaseStation *st = BaseStation::GetByTile(n.GetLastTile());
 
				assert(st != NULL);
 
				uint platform_length = st->GetPlatformLength(n.GetLastTile(), ReverseDiagDir(TrackdirToExitdir(n.GetLastTrackdir())));
 
				/* Reduce the extra cost caused by passing-station penalty (each station receives it in the segment cost). */
src/yapf/yapf_destrail.hpp
Show inline comments
 
@@ -129,17 +129,12 @@ public:
 
	{
 
		switch (v->current_order.GetType()) {
 
			case OT_GOTO_STATION:
 
			case OT_GOTO_WAYPOINT:
 
				m_destTile = CalcClosestStationTile(v->current_order.GetDestination(), v->tile);
 
				m_dest_station_id = v->current_order.GetDestination();
 
				m_destTrackdirs = INVALID_TRACKDIR_BIT;
 
				break;
 

	
 
			case OT_GOTO_WAYPOINT:
 
				m_destTile = Waypoint::Get(v->current_order.GetDestination())->xy;
 
				m_dest_station_id = INVALID_STATION;
 
				m_destTrackdirs = IsRailWaypointTile(m_destTile) ? TrackToTrackdirBits(GetRailStationTrack(m_destTile)) : INVALID_TRACKDIR_BIT;
 
				break;
 

	
 
			default:
 
				m_destTile = v->dest_tile;
 
				m_dest_station_id = INVALID_STATION;
 
@@ -160,7 +155,7 @@ public:
 
	{
 
		bool bDest;
 
		if (m_dest_station_id != INVALID_STATION) {
 
			bDest = IsRailStationTile(tile)
 
			bDest = HasStationTileRail(tile)
 
				&& (GetStationIndex(tile) == m_dest_station_id)
 
				&& (GetRailStationTrack(tile) == TrackdirToTrack(td));
 
		} else {
0 comments (0 inline, 0 general)