Changeset - r13836:eebc73cc40b6
[Not reviewed]
master
0 3 0
rubidium - 14 years ago 2009-12-02 14:41:04
rubidium@openttd.org
(svn r18375) -Codechange: use Station::GetTileArea to get the tile area for CalcClosestStationTile
3 files changed with 13 insertions and 9 deletions:
0 comments (0 inline, 0 general)
src/pathfinder/npf/npf.cpp
Show inline comments
 
@@ -105,7 +105,7 @@ static int32 NPFCalcStationOrTileHeurist
 

	
 
	/* for train-stations, we are going to aim for the closest station tile */
 
	if (as->user_data[NPF_TYPE] == TRANSPORT_RAIL && fstd->station_index != INVALID_STATION)
 
		to = CalcClosestStationTile(fstd->station_index, from);
 
		to = CalcClosestStationTile(fstd->station_index, from, STATION_RAIL);
 

	
 
	if (as->user_data[NPF_TYPE] == TRANSPORT_ROAD) {
 
		/* Since roads only have diagonal pieces, we use manhattan distance here */
 
@@ -1089,7 +1089,7 @@ void NPFFillWithOrderData(NPFFindStation
 
	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);
 
		fstd->dest_coords = CalcClosestStationTile(fstd->station_index, v->tile, STATION_RAIL);
 
	} else {
 
		fstd->dest_coords = v->dest_tile;
 
		fstd->station_index = INVALID_STATION;
src/pathfinder/pathfinder_func.h
Show inline comments
 
@@ -21,19 +21,23 @@
 
 * as defined by its tile are (st->train_station)
 
 * @param station The station to calculate the distance to
 
 * @param tile The tile from where to calculate the distance
 
 * @param station_type the station type to get the closest tile of
 
 * @note for simplification STATION_RAIL is also used for waypoints!
 
 * @return The closest station tile to the given tile.
 
 */
 
static inline TileIndex CalcClosestStationTile(StationID station, TileIndex tile)
 
static inline TileIndex CalcClosestStationTile(StationID station, TileIndex tile, StationType station_type)
 
{
 
	const BaseStation *st = BaseStation::Get(station);
 
	TileArea ta;
 
	st->GetTileArea(&ta, station_type);
 

	
 
	/* If the rail station is (temporarily) not present, use the station sign to drive near the station */
 
	if (st->train_station.tile == INVALID_TILE) return st->xy;
 
	if (ta.tile == INVALID_TILE) return st->xy;
 

	
 
	uint minx = TileX(st->train_station.tile);  // topmost corner of station
 
	uint miny = TileY(st->train_station.tile);
 
	uint maxx = minx + st->train_station.w - 1; // lowermost corner of station
 
	uint maxy = miny + st->train_station.h - 1;
 
	uint minx = TileX(ta.tile);  // topmost corner of station
 
	uint miny = TileY(ta.tile);
 
	uint maxx = minx + ta.w - 1; // lowermost corner of station
 
	uint maxy = miny + ta.h - 1;
 

	
 
	/* we are going the aim for the x coordinate of the closest corner
 
	 * but if we are between those coordinates, we will aim for our own x coordinate */
src/pathfinder/yapf/yapf_destrail.hpp
Show inline comments
 
@@ -137,7 +137,7 @@ public:
 
		switch (v->current_order.GetType()) {
 
			case OT_GOTO_STATION:
 
			case OT_GOTO_WAYPOINT:
 
				m_destTile = CalcClosestStationTile(v->current_order.GetDestination(), v->tile);
 
				m_destTile = CalcClosestStationTile(v->current_order.GetDestination(), v->tile, STATION_RAIL);
 
				m_dest_station_id = v->current_order.GetDestination();
 
				m_destTrackdirs = INVALID_TRACKDIR_BIT;
 
				break;
0 comments (0 inline, 0 general)