mirror of https://github.com/OpenTTD/OpenTTD
(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
parent
cf38a5bee6
commit
c3d2c47faa
|
@ -85,6 +85,24 @@ struct BaseStation : StationPool::PoolItem<&_station_pool> {
|
||||||
*/
|
*/
|
||||||
virtual void GetTileArea(TileArea *ta, StationType type) const = 0;
|
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.
|
* Get the base station belonging to a specific tile.
|
||||||
* @param tile The tile to get the base station from.
|
* @param tile The tile to get the base station from.
|
||||||
|
|
|
@ -1103,7 +1103,7 @@ void NPFFillWithOrderData(NPFFindStationOrTileData *fstd, Vehicle *v, bool reser
|
||||||
* dest_tile, not just any stop of that station.
|
* dest_tile, not just any stop of that station.
|
||||||
* So only for train orders to stations we fill fstd->station_index, for all
|
* So only for train orders to stations we fill fstd->station_index, for all
|
||||||
* others only dest_coords */
|
* 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();
|
fstd->station_index = v->current_order.GetDestination();
|
||||||
/* Let's take the closest tile of the station as our target for trains */
|
/* 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);
|
||||||
|
|
|
@ -412,9 +412,9 @@ static TileIndex GetOrderLocation(const Order& o)
|
||||||
{
|
{
|
||||||
switch (o.GetType()) {
|
switch (o.GetType()) {
|
||||||
default: NOT_REACHED();
|
default: NOT_REACHED();
|
||||||
case OT_GOTO_WAYPOINT: // This function is only called for ships, thus waypoints are buoys which are stations.
|
case OT_GOTO_WAYPOINT: return Waypoint::Get(o.GetDestination())->xy;
|
||||||
case OT_GOTO_STATION: return Station::Get(o.GetDestination())->xy;
|
case OT_GOTO_STATION: return Station::Get(o.GetDestination())->xy;
|
||||||
case OT_GOTO_DEPOT: return Depot::Get(o.GetDestination())->xy;
|
case OT_GOTO_DEPOT: return Depot::Get(o.GetDestination())->xy;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1688,11 +1688,7 @@ bool UpdateOrderDest(Vehicle *v, const Order *order, int conditional_depth)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case OT_GOTO_WAYPOINT:
|
case OT_GOTO_WAYPOINT:
|
||||||
if (v->type == VEH_TRAIN) {
|
v->dest_tile = Waypoint::Get(order->GetDestination())->xy;
|
||||||
v->dest_tile = Waypoint::Get(order->GetDestination())->xy;
|
|
||||||
} else {
|
|
||||||
v->dest_tile = Station::Get(order->GetDestination())->xy;
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
case OT_CONDITIONAL: {
|
case OT_CONDITIONAL: {
|
||||||
|
@ -1755,17 +1751,11 @@ bool ProcessOrders(Vehicle *v)
|
||||||
*/
|
*/
|
||||||
bool may_reverse = v->current_order.IsType(OT_NOTHING);
|
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.. */
|
/* 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) &&
|
IsTileType(v->tile, MP_STATION) &&
|
||||||
v->current_order.GetDestination() == GetStationIndex(v->tile)) {
|
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);
|
UpdateVehicleTimetable(v, true);
|
||||||
v->IncrementOrderIndex();
|
v->IncrementOrderIndex();
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
|
|
||||||
#include "direction_type.h"
|
#include "direction_type.h"
|
||||||
#include "station_base.h"
|
#include "station_base.h"
|
||||||
|
#include "waypoint_base.h"
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
STR_FACTOR = 2,
|
STR_FACTOR = 2,
|
||||||
|
@ -89,7 +90,10 @@ void NewTrainPathfind(TileIndex tile, TileIndex dest, RailTypes railtypes, DiagD
|
||||||
*/
|
*/
|
||||||
static inline TileIndex CalcClosestStationTile(StationID station, TileIndex tile)
|
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 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;
|
if (st->train_tile == INVALID_TILE) return st->xy;
|
||||||
|
|
|
@ -181,12 +181,7 @@ void Station::MarkTilesDirty(bool cargo_change) const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Obtain the length of a platform
|
/* virtual */ uint Station::GetPlatformLength(TileIndex tile) const
|
||||||
* @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
|
|
||||||
{
|
{
|
||||||
assert(this->TileBelongsToRailStation(tile));
|
assert(this->TileBelongsToRailStation(tile));
|
||||||
|
|
||||||
|
@ -208,13 +203,7 @@ uint Station::GetPlatformLength(TileIndex tile) const
|
||||||
return len - 1;
|
return len - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Determines the REMAINING length of a platform, starting at (and including)
|
/* virtual */ uint Station::GetPlatformLength(TileIndex tile, DiagDirection dir) const
|
||||||
* 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
|
|
||||||
{
|
{
|
||||||
TileIndex start_tile = tile;
|
TileIndex start_tile = tile;
|
||||||
uint length = 0;
|
uint length = 0;
|
||||||
|
@ -222,7 +211,7 @@ uint Station::GetPlatformLength(TileIndex tile, DiagDirection dir) const
|
||||||
assert(dir < DIAGDIR_END);
|
assert(dir < DIAGDIR_END);
|
||||||
|
|
||||||
do {
|
do {
|
||||||
length ++;
|
length++;
|
||||||
tile += TileOffsByDiagDir(dir);
|
tile += TileOffsByDiagDir(dir);
|
||||||
} while (IsCompatibleTrainStationTile(tile, start_tile));
|
} while (IsCompatibleTrainStationTile(tile, start_tile));
|
||||||
|
|
||||||
|
|
|
@ -124,8 +124,8 @@ public:
|
||||||
|
|
||||||
void UpdateVirtCoord();
|
void UpdateVirtCoord();
|
||||||
|
|
||||||
uint GetPlatformLength(TileIndex tile, DiagDirection dir) const;
|
/* virtual */ uint GetPlatformLength(TileIndex tile, DiagDirection dir) const;
|
||||||
uint GetPlatformLength(TileIndex tile) const;
|
/* virtual */ uint GetPlatformLength(TileIndex tile) const;
|
||||||
void RecomputeIndustriesNear();
|
void RecomputeIndustriesNear();
|
||||||
static void RecomputeIndustriesNearForAll();
|
static void RecomputeIndustriesNearForAll();
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,16 @@ struct Waypoint : SpecializedStation<Waypoint, true> {
|
||||||
/* virtual */ uint32 GetNewGRFVariable(const struct ResolverObject *object, byte variable, byte parameter, bool *available) const;
|
/* virtual */ uint32 GetNewGRFVariable(const struct ResolverObject *object, byte variable, byte parameter, bool *available) const;
|
||||||
|
|
||||||
/* virtual */ void GetTileArea(TileArea *ta, StationType type) 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)
|
#define FOR_ALL_WAYPOINTS(var) FOR_ALL_BASE_STATIONS_OF_TYPE(Waypoint, var)
|
||||||
|
|
|
@ -191,7 +191,7 @@ protected:
|
||||||
m_new_tile = TILE_ADD(m_old_tile, diff);
|
m_new_tile = TILE_ADD(m_old_tile, diff);
|
||||||
|
|
||||||
/* special handling for stations */
|
/* special handling for stations */
|
||||||
if (IsRailTT() && IsRailStationTile(m_new_tile)) {
|
if (IsRailTT() && HasStationTileRail(m_new_tile)) {
|
||||||
m_is_station = true;
|
m_is_station = true;
|
||||||
} else if (IsRoadTT() && IsRoadStopTile(m_new_tile)) {
|
} else if (IsRoadTT() && IsRoadStopTile(m_new_tile)) {
|
||||||
m_is_station = true;
|
m_is_station = true;
|
||||||
|
@ -346,7 +346,7 @@ protected:
|
||||||
if (IsRailTT() && m_is_station) {
|
if (IsRailTT() && m_is_station) {
|
||||||
/* entered railway station
|
/* entered railway station
|
||||||
* get platform length */
|
* 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; */
|
/* how big step we must do to get to the last platform tile; */
|
||||||
m_tiles_skipped = length - 1;
|
m_tiles_skipped = length - 1;
|
||||||
/* move to the platform end */
|
/* move to the platform end */
|
||||||
|
|
|
@ -543,7 +543,7 @@ no_entry_cost: // jump here at the beginning if the node has no parent (it is th
|
||||||
|
|
||||||
/* Station platform-length penalty. */
|
/* Station platform-length penalty. */
|
||||||
if ((end_segment_reason & ESRB_STATION) != ESRB_NONE) {
|
if ((end_segment_reason & ESRB_STATION) != ESRB_NONE) {
|
||||||
Station *st = Station::GetByTile(n.GetLastTile());
|
const BaseStation *st = BaseStation::GetByTile(n.GetLastTile());
|
||||||
assert(st != NULL);
|
assert(st != NULL);
|
||||||
uint platform_length = st->GetPlatformLength(n.GetLastTile(), ReverseDiagDir(TrackdirToExitdir(n.GetLastTrackdir())));
|
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). */
|
/* Reduce the extra cost caused by passing-station penalty (each station receives it in the segment cost). */
|
||||||
|
|
|
@ -129,17 +129,12 @@ public:
|
||||||
{
|
{
|
||||||
switch (v->current_order.GetType()) {
|
switch (v->current_order.GetType()) {
|
||||||
case OT_GOTO_STATION:
|
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);
|
||||||
m_dest_station_id = v->current_order.GetDestination();
|
m_dest_station_id = v->current_order.GetDestination();
|
||||||
m_destTrackdirs = INVALID_TRACKDIR_BIT;
|
m_destTrackdirs = INVALID_TRACKDIR_BIT;
|
||||||
break;
|
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:
|
default:
|
||||||
m_destTile = v->dest_tile;
|
m_destTile = v->dest_tile;
|
||||||
m_dest_station_id = INVALID_STATION;
|
m_dest_station_id = INVALID_STATION;
|
||||||
|
@ -160,7 +155,7 @@ public:
|
||||||
{
|
{
|
||||||
bool bDest;
|
bool bDest;
|
||||||
if (m_dest_station_id != INVALID_STATION) {
|
if (m_dest_station_id != INVALID_STATION) {
|
||||||
bDest = IsRailStationTile(tile)
|
bDest = HasStationTileRail(tile)
|
||||||
&& (GetStationIndex(tile) == m_dest_station_id)
|
&& (GetStationIndex(tile) == m_dest_station_id)
|
||||||
&& (GetRailStationTrack(tile) == TrackdirToTrack(td));
|
&& (GetRailStationTrack(tile) == TrackdirToTrack(td));
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue