1
0
Fork 0

(svn r18372) -Codechange: push some extra type safety into YAPF

release/1.0
rubidium 2009-12-02 10:13:49 +00:00
parent 9165c195b9
commit c56c892b2c
9 changed files with 69 additions and 65 deletions

View File

@ -20,7 +20,7 @@
/** Track follower helper template class (can serve pathfinders and vehicle /** Track follower helper template class (can serve pathfinders and vehicle
* controllers). See 6 different typedefs below for 3 different transport * controllers). See 6 different typedefs below for 3 different transport
* types w/ or w/o 90-deg turns allowed */ * types w/ or w/o 90-deg turns allowed */
template <TransportType Ttr_type_, bool T90deg_turns_allowed_ = true, bool Tmask_reserved_tracks = false> template <TransportType Ttr_type_, typename VehicleType, bool T90deg_turns_allowed_ = true, bool Tmask_reserved_tracks = false>
struct CFollowTrackT struct CFollowTrackT
{ {
enum ErrorCode { enum ErrorCode {
@ -32,7 +32,7 @@ struct CFollowTrackT
EC_RESERVED, EC_RESERVED,
}; };
const Vehicle *m_veh; ///< moving vehicle const VehicleType *m_veh; ///< moving vehicle
Owner m_veh_owner; ///< owner of the vehicle Owner m_veh_owner; ///< owner of the vehicle
TileIndex m_old_tile; ///< the origin (vehicle moved from) before move TileIndex m_old_tile; ///< the origin (vehicle moved from) before move
Trackdir m_old_td; ///< the trackdir (the vehicle was on) before move Trackdir m_old_td; ///< the trackdir (the vehicle was on) before move
@ -47,7 +47,7 @@ struct CFollowTrackT
CPerformanceTimer *m_pPerf; CPerformanceTimer *m_pPerf;
RailTypes m_railtypes; RailTypes m_railtypes;
FORCEINLINE CFollowTrackT(const Vehicle *v = NULL, RailTypes railtype_override = INVALID_RAILTYPES, CPerformanceTimer *pPerf = NULL) FORCEINLINE CFollowTrackT(const VehicleType *v = NULL, RailTypes railtype_override = INVALID_RAILTYPES, CPerformanceTimer *pPerf = NULL)
{ {
Init(v, railtype_override, pPerf); Init(v, railtype_override, pPerf);
} }
@ -58,7 +58,7 @@ struct CFollowTrackT
Init(o, railtype_override, pPerf); Init(o, railtype_override, pPerf);
} }
FORCEINLINE void Init(const Vehicle *v, RailTypes railtype_override, CPerformanceTimer *pPerf) FORCEINLINE void Init(const VehicleType *v, RailTypes railtype_override, CPerformanceTimer *pPerf)
{ {
assert(!IsRailTT() || (v != NULL && v->type == VEH_TRAIN)); assert(!IsRailTT() || (v != NULL && v->type == VEH_TRAIN));
m_veh = v; m_veh = v;
@ -437,15 +437,15 @@ public:
} }
}; };
typedef CFollowTrackT<TRANSPORT_WATER, true > CFollowTrackWater; typedef CFollowTrackT<TRANSPORT_WATER, Ship, true > CFollowTrackWater;
typedef CFollowTrackT<TRANSPORT_ROAD , true > CFollowTrackRoad; typedef CFollowTrackT<TRANSPORT_ROAD, RoadVehicle, true > CFollowTrackRoad;
typedef CFollowTrackT<TRANSPORT_RAIL , true > CFollowTrackRail; typedef CFollowTrackT<TRANSPORT_RAIL, Train, true > CFollowTrackRail;
typedef CFollowTrackT<TRANSPORT_WATER, false> CFollowTrackWaterNo90; typedef CFollowTrackT<TRANSPORT_WATER, Ship, false> CFollowTrackWaterNo90;
typedef CFollowTrackT<TRANSPORT_ROAD , false> CFollowTrackRoadNo90; typedef CFollowTrackT<TRANSPORT_ROAD, RoadVehicle, false> CFollowTrackRoadNo90;
typedef CFollowTrackT<TRANSPORT_RAIL , false> CFollowTrackRailNo90; typedef CFollowTrackT<TRANSPORT_RAIL, Train, false> CFollowTrackRailNo90;
typedef CFollowTrackT<TRANSPORT_RAIL , true , true> CFollowTrackFreeRail; typedef CFollowTrackT<TRANSPORT_RAIL, Train, true, true > CFollowTrackFreeRail;
typedef CFollowTrackT<TRANSPORT_RAIL , false, true> CFollowTrackFreeRailNo90; typedef CFollowTrackT<TRANSPORT_RAIL, Train, false, true > CFollowTrackFreeRailNo90;
#endif /* FOLLOW_TRACK_HPP */ #endif /* FOLLOW_TRACK_HPP */

View File

@ -32,7 +32,7 @@ Track YapfChooseShipTrack(const Ship *v, TileIndex tile, DiagDirection enterdir,
* @param enterdir diagonal direction which the RV will enter this new tile from * @param enterdir diagonal direction which the RV will enter this new tile from
* @return the best trackdir for next turn or INVALID_TRACKDIR if the path could not be found * @return the best trackdir for next turn or INVALID_TRACKDIR if the path could not be found
*/ */
Trackdir YapfChooseRoadTrack(const Vehicle *v, TileIndex tile, DiagDirection enterdir); Trackdir YapfChooseRoadTrack(const RoadVehicle *v, TileIndex tile, DiagDirection enterdir);
/** /**
* Finds the best path for given train using YAPF. * Finds the best path for given train using YAPF.
@ -52,7 +52,7 @@ Track YapfTrainChooseTrack(const Train *v, TileIndex tile, DiagDirection enterdi
* @param tile destination tile * @param tile destination tile
* @return distance from origin tile to the destination (number of road tiles) or UINT_MAX if path not found * @return distance from origin tile to the destination (number of road tiles) or UINT_MAX if path not found
*/ */
uint YapfRoadVehDistanceToTile(const Vehicle *v, TileIndex tile); uint YapfRoadVehDistanceToTile(const RoadVehicle *v, TileIndex tile);
/** Used to determinine the closest reachable compatible road stop for a given vehicle. /** Used to determinine the closest reachable compatible road stop for a given vehicle.
* @param v vehicle that needs to go to the road stop * @param v vehicle that needs to go to the road stop
@ -70,7 +70,7 @@ bool YapfFindNearestRoadVehicleCompatibleStop(const RoadVehicle *v, StationID st
* @param depot_tile receives the depot tile if depot was found * @param depot_tile receives the depot tile if depot was found
* @return true if depot was found. * @return true if depot was found.
*/ */
bool YapfFindNearestRoadDepot(const Vehicle *v, int max_distance, TileIndex *depot_tile); bool YapfFindNearestRoadDepot(const RoadVehicle *v, int max_distance, TileIndex *depot_tile);
/** /**
* Used when user sends train to the nearest depot or if train needs servicing using YAPF. * Used when user sends train to the nearest depot or if train needs servicing using YAPF.

View File

@ -52,6 +52,7 @@ public:
typedef typename Types::Tpf Tpf; ///< the pathfinder class (derived from THIS class) typedef typename Types::Tpf Tpf; ///< the pathfinder class (derived from THIS class)
typedef typename Types::TrackFollower TrackFollower; typedef typename Types::TrackFollower TrackFollower;
typedef typename Types::NodeList NodeList; ///< our node list typedef typename Types::NodeList NodeList; ///< our node list
typedef typename Types::VehicleType VehicleType; ///< the type of vehicle
typedef typename NodeList::Titem Node; ///< this will be our node type typedef typename NodeList::Titem Node; ///< this will be our node type
typedef typename Node::Key Key; ///< key to hash tables typedef typename Node::Key Key; ///< key to hash tables
@ -62,7 +63,7 @@ protected:
Node *m_pBestIntermediateNode; ///< here should be node closest to the destination if path not found Node *m_pBestIntermediateNode; ///< here should be node closest to the destination if path not found
const YAPFSettings *m_settings; ///< current settings (_settings_game.yapf) const YAPFSettings *m_settings; ///< current settings (_settings_game.yapf)
int m_max_search_nodes; ///< maximum number of nodes we are allowed to visit before we give up int m_max_search_nodes; ///< maximum number of nodes we are allowed to visit before we give up
const Vehicle *m_veh; ///< vehicle that we are trying to drive const VehicleType *m_veh; ///< vehicle that we are trying to drive
int m_stats_cost_calcs; ///< stats - how many node's costs were calculated int m_stats_cost_calcs; ///< stats - how many node's costs were calculated
int m_stats_cache_hits; ///< stats - how many node's costs were reused from cache int m_stats_cache_hits; ///< stats - how many node's costs were reused from cache
@ -114,7 +115,7 @@ public:
* - or the open list is empty (no route to destination). * - or the open list is empty (no route to destination).
* - or the maximum amount of loops reached - m_max_search_nodes (default = 10000) * - or the maximum amount of loops reached - m_max_search_nodes (default = 10000)
* @return true if the path was found */ * @return true if the path was found */
inline bool FindPath(const Vehicle *v) inline bool FindPath(const VehicleType *v)
{ {
m_veh = v; m_veh = v;
@ -291,7 +292,7 @@ public:
m_nodes.InsertOpenNode(n); m_nodes.InsertOpenNode(n);
} }
const Vehicle * GetVehicle() const const VehicleType * GetVehicle() const
{ {
return m_veh; return m_veh;
} }

View File

@ -251,11 +251,11 @@ public:
FORCEINLINE int PlatformLengthPenalty(int platform_length) FORCEINLINE int PlatformLengthPenalty(int platform_length)
{ {
int cost = 0; int cost = 0;
const Vehicle *v = Yapf().GetVehicle(); const Train *v = Yapf().GetVehicle();
assert(v != NULL); assert(v != NULL);
assert(v->type == VEH_TRAIN); assert(v->type == VEH_TRAIN);
assert(Train::From(v)->tcache.cached_total_length != 0); assert(v->tcache.cached_total_length != 0);
int missing_platform_length = (Train::From(v)->tcache.cached_total_length + TILE_SIZE - 1) / TILE_SIZE - platform_length; int missing_platform_length = (v->tcache.cached_total_length + TILE_SIZE - 1) / TILE_SIZE - platform_length;
if (missing_platform_length < 0) { if (missing_platform_length < 0) {
/* apply penalty for longer platform than needed */ /* apply penalty for longer platform than needed */
cost += Yapf().PfGetSettings().rail_longer_platform_penalty + Yapf().PfGetSettings().rail_longer_platform_per_tile_penalty * -missing_platform_length; cost += Yapf().PfGetSettings().rail_longer_platform_penalty + Yapf().PfGetSettings().rail_longer_platform_per_tile_penalty * -missing_platform_length;
@ -322,7 +322,7 @@ public:
int segment_entry_cost = 0; int segment_entry_cost = 0;
int segment_cost = 0; int segment_cost = 0;
const Vehicle *v = Yapf().GetVehicle(); const Train *v = Yapf().GetVehicle();
/* start at n.m_key.m_tile / n.m_key.m_td and walk to the end of segment */ /* start at n.m_key.m_tile / n.m_key.m_td and walk to the end of segment */
TILE cur(n.m_key.m_tile, n.m_key.m_td); TILE cur(n.m_key.m_tile, n.m_key.m_td);

View File

@ -18,10 +18,10 @@ protected:
RailTypes m_compatible_railtypes; RailTypes m_compatible_railtypes;
public: public:
void SetDestination(const Vehicle *v, bool override_rail_type = false) void SetDestination(const Train *v, bool override_rail_type = false)
{ {
m_compatible_railtypes = Train::From(v)->compatible_railtypes; m_compatible_railtypes = v->compatible_railtypes;
if (override_rail_type) m_compatible_railtypes |= GetRailTypeInfo(Train::From(v)->railtype)->compatible_railtypes; if (override_rail_type) m_compatible_railtypes |= GetRailTypeInfo(v->railtype)->compatible_railtypes;
} }
bool IsCompatibleRailType(RailType rt) bool IsCompatibleRailType(RailType rt)
@ -98,8 +98,8 @@ public:
FORCEINLINE bool PfDetectDestination(TileIndex tile, Trackdir td) FORCEINLINE bool PfDetectDestination(TileIndex tile, Trackdir td)
{ {
return return
IsSafeWaitingPosition(Train::From(Yapf().GetVehicle()), tile, td, true, !TrackFollower::Allow90degTurns()) && IsSafeWaitingPosition(Yapf().GetVehicle(), tile, td, true, !TrackFollower::Allow90degTurns()) &&
IsWaitingPositionFree(Train::From(Yapf().GetVehicle()), tile, td, !TrackFollower::Allow90degTurns()); IsWaitingPositionFree(Yapf().GetVehicle(), tile, td, !TrackFollower::Allow90degTurns());
} }
/** Called by YAPF to calculate cost estimate. Calculates distance to the destination /** Called by YAPF to calculate cost estimate. Calculates distance to the destination
@ -132,7 +132,7 @@ protected:
} }
public: public:
void SetDestination(const Vehicle *v) void SetDestination(const Train *v)
{ {
switch (v->current_order.GetType()) { switch (v->current_order.GetType()) {
case OT_GOTO_STATION: case OT_GOTO_STATION:

View File

@ -243,7 +243,7 @@ struct CYapfRailNodeT
} }
template <class Tbase, class Tfunc, class Tpf> template <class Tbase, class Tfunc, class Tpf>
bool IterateTiles(const Vehicle *v, Tpf &yapf, Tbase &obj, bool (Tfunc::*func)(TileIndex, Trackdir)) const bool IterateTiles(const Train *v, Tpf &yapf, Tbase &obj, bool (Tfunc::*func)(TileIndex, Trackdir)) const
{ {
typename Tbase::TrackFollower ft(v, yapf.GetCompatibleRailTypes()); typename Tbase::TrackFollower ft(v, yapf.GetCompatibleRailTypes());
TileIndex cur = base::GetTile(); TileIndex cur = base::GetTile();

View File

@ -60,7 +60,7 @@ private:
bool FindSafePositionProc(TileIndex tile, Trackdir td) bool FindSafePositionProc(TileIndex tile, Trackdir td)
{ {
if (IsSafeWaitingPosition(Train::From(Yapf().GetVehicle()), tile, td, true, !TrackFollower::Allow90degTurns())) { if (IsSafeWaitingPosition(Yapf().GetVehicle(), tile, td, true, !TrackFollower::Allow90degTurns())) {
m_res_dest = tile; m_res_dest = tile;
m_res_dest_td = td; m_res_dest_td = td;
return false; // Stop iterating segment return false; // Stop iterating segment
@ -155,7 +155,7 @@ public:
} }
/* Don't bother if the target is reserved. */ /* Don't bother if the target is reserved. */
if (!IsWaitingPositionFree(Train::From(Yapf().GetVehicle()), m_res_dest, m_res_dest_td)) return false; if (!IsWaitingPositionFree(Yapf().GetVehicle(), m_res_dest, m_res_dest_td)) return false;
for (Node *node = m_res_node; node->m_parent != NULL; node = node->m_parent) { for (Node *node = m_res_node; node->m_parent != NULL; node = node->m_parent) {
node->IterateTiles(Yapf().GetVehicle(), Yapf(), *this, &CYapfReserveTrack<Types>::ReserveSingleTrack); node->IterateTiles(Yapf().GetVehicle(), Yapf(), *this, &CYapfReserveTrack<Types>::ReserveSingleTrack);
@ -216,7 +216,7 @@ public:
return 't'; return 't';
} }
static bool stFindNearestDepotTwoWay(const Vehicle *v, TileIndex t1, Trackdir td1, TileIndex t2, Trackdir td2, int max_distance, int reverse_penalty, TileIndex *depot_tile, bool *reversed) static bool stFindNearestDepotTwoWay(const Train *v, TileIndex t1, Trackdir td1, TileIndex t2, Trackdir td2, int max_distance, int reverse_penalty, TileIndex *depot_tile, bool *reversed)
{ {
Tpf pf1; Tpf pf1;
/* /*
@ -246,7 +246,7 @@ public:
return result1; return result1;
} }
FORCEINLINE bool FindNearestDepotTwoWay(const Vehicle *v, TileIndex t1, Trackdir td1, TileIndex t2, Trackdir td2, int max_distance, int reverse_penalty, TileIndex *depot_tile, bool *reversed) FORCEINLINE bool FindNearestDepotTwoWay(const Train *v, TileIndex t1, Trackdir td1, TileIndex t2, Trackdir td2, int max_distance, int reverse_penalty, TileIndex *depot_tile, bool *reversed)
{ {
/* set origin and destination nodes */ /* set origin and destination nodes */
Yapf().SetOrigin(t1, td1, t2, td2, reverse_penalty, true); Yapf().SetOrigin(t1, td1, t2, td2, reverse_penalty, true);
@ -310,7 +310,7 @@ public:
return 't'; return 't';
} }
static bool stFindNearestSafeTile(const Vehicle *v, TileIndex t1, Trackdir td, bool override_railtype) static bool stFindNearestSafeTile(const Train *v, TileIndex t1, Trackdir td, bool override_railtype)
{ {
/* Create pathfinder instance */ /* Create pathfinder instance */
Tpf pf1; Tpf pf1;
@ -331,7 +331,7 @@ public:
return result1; return result1;
} }
bool FindNearestSafeTile(const Vehicle *v, TileIndex t1, Trackdir td, bool override_railtype, bool dont_reserve) bool FindNearestSafeTile(const Train *v, TileIndex t1, Trackdir td, bool override_railtype, bool dont_reserve)
{ {
/* Set origin and destination. */ /* Set origin and destination. */
Yapf().SetOrigin(t1, td); Yapf().SetOrigin(t1, td);
@ -391,7 +391,7 @@ public:
return 't'; return 't';
} }
static Trackdir stChooseRailTrack(const Vehicle *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks, bool *path_not_found, bool reserve_track, PBSTileInfo *target) static Trackdir stChooseRailTrack(const Train *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks, bool *path_not_found, bool reserve_track, PBSTileInfo *target)
{ {
/* create pathfinder instance */ /* create pathfinder instance */
Tpf pf1; Tpf pf1;
@ -412,12 +412,12 @@ public:
return result1; return result1;
} }
FORCEINLINE Trackdir ChooseRailTrack(const Vehicle *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks, bool *path_not_found, bool reserve_track, PBSTileInfo *target) FORCEINLINE Trackdir ChooseRailTrack(const Train *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks, bool *path_not_found, bool reserve_track, PBSTileInfo *target)
{ {
if (target != NULL) target->tile = INVALID_TILE; if (target != NULL) target->tile = INVALID_TILE;
/* set origin and destination nodes */ /* set origin and destination nodes */
PBSTileInfo origin = FollowTrainReservation(Train::From(v)); PBSTileInfo origin = FollowTrainReservation(v);
Yapf().SetOrigin(origin.tile, origin.trackdir, INVALID_TILE, INVALID_TRACKDIR, 1, true); Yapf().SetOrigin(origin.tile, origin.trackdir, INVALID_TILE, INVALID_TRACKDIR, 1, true);
Yapf().SetDestination(v); Yapf().SetDestination(v);
@ -454,7 +454,7 @@ public:
return next_trackdir; return next_trackdir;
} }
static bool stCheckReverseTrain(const Vehicle *v, TileIndex t1, Trackdir td1, TileIndex t2, Trackdir td2, int reverse_penalty) static bool stCheckReverseTrain(const Train *v, TileIndex t1, Trackdir td1, TileIndex t2, Trackdir td2, int reverse_penalty)
{ {
Tpf pf1; Tpf pf1;
bool result1 = pf1.CheckReverseTrain(v, t1, td1, t2, td2, reverse_penalty); bool result1 = pf1.CheckReverseTrain(v, t1, td1, t2, td2, reverse_penalty);
@ -472,7 +472,7 @@ public:
return result1; return result1;
} }
FORCEINLINE bool CheckReverseTrain(const Vehicle *v, TileIndex t1, Trackdir td1, TileIndex t2, Trackdir td2, int reverse_penalty) FORCEINLINE bool CheckReverseTrain(const Train *v, TileIndex t1, Trackdir td1, TileIndex t2, Trackdir td2, int reverse_penalty)
{ {
/* create pathfinder instance /* create pathfinder instance
* set origin and destination nodes */ * set origin and destination nodes */
@ -506,6 +506,7 @@ struct CYapfRail_TypesT
typedef Tpf_ Tpf; typedef Tpf_ Tpf;
typedef Ttrack_follower TrackFollower; typedef Ttrack_follower TrackFollower;
typedef Tnode_list NodeList; typedef Tnode_list NodeList;
typedef Train VehicleType;
typedef CYapfBaseT<Types> PfBase; typedef CYapfBaseT<Types> PfBase;
typedef TfollowT<Types> PfFollow; typedef TfollowT<Types> PfFollow;
typedef CYapfOriginTileTwoWayT<Types> PfOrigin; typedef CYapfOriginTileTwoWayT<Types> PfOrigin;
@ -527,7 +528,7 @@ struct CYapfAnySafeTileRail2 : CYapfT<CYapfRail_TypesT<CYapfAnySafeTileRail2, CF
Track YapfTrainChooseTrack(const Train *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks, bool *path_not_found, bool reserve_track, PBSTileInfo *target) Track YapfTrainChooseTrack(const Train *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks, bool *path_not_found, bool reserve_track, PBSTileInfo *target)
{ {
/* default is YAPF type 2 */ /* default is YAPF type 2 */
typedef Trackdir (*PfnChooseRailTrack)(const Vehicle*, TileIndex, DiagDirection, TrackBits, bool*, bool, PBSTileInfo*); typedef Trackdir (*PfnChooseRailTrack)(const Train*, TileIndex, DiagDirection, TrackBits, bool*, bool, PBSTileInfo*);
PfnChooseRailTrack pfnChooseRailTrack = &CYapfRail1::stChooseRailTrack; PfnChooseRailTrack pfnChooseRailTrack = &CYapfRail1::stChooseRailTrack;
/* check if non-default YAPF type needed */ /* check if non-default YAPF type needed */
@ -582,7 +583,7 @@ bool YapfTrainCheckReverse(const Train *v)
reverse_penalty += DistanceManhattan(cur_tile, tile_rev) * YAPF_TILE_LENGTH; reverse_penalty += DistanceManhattan(cur_tile, tile_rev) * YAPF_TILE_LENGTH;
} }
typedef bool (*PfnCheckReverseTrain)(const Vehicle*, TileIndex, Trackdir, TileIndex, Trackdir, int); typedef bool (*PfnCheckReverseTrain)(const Train*, TileIndex, Trackdir, TileIndex, Trackdir, int);
PfnCheckReverseTrain pfnCheckReverseTrain = CYapfRail1::stCheckReverseTrain; PfnCheckReverseTrain pfnCheckReverseTrain = CYapfRail1::stCheckReverseTrain;
/* check if non-default YAPF type needed */ /* check if non-default YAPF type needed */
@ -604,11 +605,11 @@ FindDepotData YapfTrainFindNearestDepot(const Train *v, int max_distance)
const Train *last_veh = v->Last(); const Train *last_veh = v->Last();
PBSTileInfo origin = FollowTrainReservation(Train::From(v)); PBSTileInfo origin = FollowTrainReservation(v);
TileIndex last_tile = last_veh->tile; TileIndex last_tile = last_veh->tile;
Trackdir td_rev = ReverseTrackdir(last_veh->GetVehicleTrackdir()); Trackdir td_rev = ReverseTrackdir(last_veh->GetVehicleTrackdir());
typedef bool (*PfnFindNearestDepotTwoWay)(const Vehicle*, TileIndex, Trackdir, TileIndex, Trackdir, int, int, TileIndex*, bool*); typedef bool (*PfnFindNearestDepotTwoWay)(const Train*, TileIndex, Trackdir, TileIndex, Trackdir, int, int, TileIndex*, bool*);
PfnFindNearestDepotTwoWay pfnFindNearestDepotTwoWay = &CYapfAnyDepotRail1::stFindNearestDepotTwoWay; PfnFindNearestDepotTwoWay pfnFindNearestDepotTwoWay = &CYapfAnyDepotRail1::stFindNearestDepotTwoWay;
/* check if non-default YAPF type needed */ /* check if non-default YAPF type needed */
@ -623,7 +624,7 @@ FindDepotData YapfTrainFindNearestDepot(const Train *v, int max_distance)
bool YapfTrainFindNearestSafeTile(const Train *v, TileIndex tile, Trackdir td, bool override_railtype) bool YapfTrainFindNearestSafeTile(const Train *v, TileIndex tile, Trackdir td, bool override_railtype)
{ {
typedef bool (*PfnFindNearestSafeTile)(const Vehicle*, TileIndex, Trackdir, bool); typedef bool (*PfnFindNearestSafeTile)(const Train*, TileIndex, Trackdir, bool);
PfnFindNearestSafeTile pfnFindNearestSafeTile = CYapfAnySafeTileRail1::stFindNearestSafeTile; PfnFindNearestSafeTile pfnFindNearestSafeTile = CYapfAnySafeTileRail1::stFindNearestSafeTile;
/* check if non-default YAPF type needed */ /* check if non-default YAPF type needed */

View File

@ -97,7 +97,7 @@ public:
/* base tile cost depending on distance between edges */ /* base tile cost depending on distance between edges */
segment_cost += Yapf().OneTileCost(tile, trackdir); segment_cost += Yapf().OneTileCost(tile, trackdir);
const Vehicle *v = Yapf().GetVehicle(); const RoadVehicle *v = Yapf().GetVehicle();
/* we have reached the vehicle's destination - segment should end here to avoid target skipping */ /* we have reached the vehicle's destination - segment should end here to avoid target skipping */
if (Yapf().PfDetectDestinationTile(tile, trackdir)) break; if (Yapf().PfDetectDestinationTile(tile, trackdir)) break;
@ -362,13 +362,13 @@ public:
return 'r'; return 'r';
} }
static Trackdir stChooseRoadTrack(const Vehicle *v, TileIndex tile, DiagDirection enterdir) static Trackdir stChooseRoadTrack(const RoadVehicle *v, TileIndex tile, DiagDirection enterdir)
{ {
Tpf pf; Tpf pf;
return pf.ChooseRoadTrack(v, tile, enterdir); return pf.ChooseRoadTrack(v, tile, enterdir);
} }
FORCEINLINE Trackdir ChooseRoadTrack(const Vehicle *v, TileIndex tile, DiagDirection enterdir) FORCEINLINE Trackdir ChooseRoadTrack(const RoadVehicle *v, TileIndex tile, DiagDirection enterdir)
{ {
/* handle special case - when next tile is destination tile */ /* handle special case - when next tile is destination tile */
if (tile == v->dest_tile) { if (tile == v->dest_tile) {
@ -378,13 +378,13 @@ public:
/* our source tile will be the next vehicle tile (should be the given one) */ /* our source tile will be the next vehicle tile (should be the given one) */
TileIndex src_tile = tile; TileIndex src_tile = tile;
/* get available trackdirs on the start tile */ /* get available trackdirs on the start tile */
TrackdirBits src_trackdirs = TrackStatusToTrackdirBits(GetTileTrackStatus(tile, TRANSPORT_ROAD, RoadVehicle::From(v)->compatible_roadtypes)); TrackdirBits src_trackdirs = TrackStatusToTrackdirBits(GetTileTrackStatus(tile, TRANSPORT_ROAD, v->compatible_roadtypes));
/* select reachable trackdirs only */ /* select reachable trackdirs only */
src_trackdirs &= DiagdirReachesTrackdirs(enterdir); src_trackdirs &= DiagdirReachesTrackdirs(enterdir);
/* get available trackdirs on the destination tile */ /* get available trackdirs on the destination tile */
TileIndex dest_tile = v->dest_tile; TileIndex dest_tile = v->dest_tile;
TrackdirBits dest_trackdirs = TrackStatusToTrackdirBits(GetTileTrackStatus(dest_tile, TRANSPORT_ROAD, RoadVehicle::From(v)->compatible_roadtypes)); TrackdirBits dest_trackdirs = TrackStatusToTrackdirBits(GetTileTrackStatus(dest_tile, TRANSPORT_ROAD, v->compatible_roadtypes));
/* set origin and destination nodes */ /* set origin and destination nodes */
Yapf().SetOrigin(src_tile, src_trackdirs); Yapf().SetOrigin(src_tile, src_trackdirs);
@ -410,13 +410,13 @@ public:
return next_trackdir; return next_trackdir;
} }
static uint stDistanceToTile(const Vehicle *v, TileIndex tile) static uint stDistanceToTile(const RoadVehicle *v, TileIndex tile)
{ {
Tpf pf; Tpf pf;
return pf.DistanceToTile(v, tile); return pf.DistanceToTile(v, tile);
} }
FORCEINLINE uint DistanceToTile(const Vehicle *v, TileIndex dst_tile) FORCEINLINE uint DistanceToTile(const RoadVehicle *v, TileIndex dst_tile)
{ {
/* handle special case - when current tile is the destination tile */ /* handle special case - when current tile is the destination tile */
if (dst_tile == v->tile) { if (dst_tile == v->tile) {
@ -428,7 +428,7 @@ public:
/* set destination tile, trackdir /* set destination tile, trackdir
* get available trackdirs on the destination tile */ * get available trackdirs on the destination tile */
TrackdirBits dst_td_bits = TrackStatusToTrackdirBits(GetTileTrackStatus(dst_tile, TRANSPORT_ROAD, RoadVehicle::From(v)->compatible_roadtypes)); TrackdirBits dst_td_bits = TrackStatusToTrackdirBits(GetTileTrackStatus(dst_tile, TRANSPORT_ROAD, v->compatible_roadtypes));
Yapf().SetDestination(dst_tile, dst_td_bits); Yapf().SetDestination(dst_tile, dst_td_bits);
/* if path not found - return distance = UINT_MAX */ /* if path not found - return distance = UINT_MAX */
@ -448,12 +448,12 @@ public:
} }
/** Return true if the valid origin (tile/trackdir) was set from the current vehicle position. */ /** Return true if the valid origin (tile/trackdir) was set from the current vehicle position. */
FORCEINLINE bool SetOriginFromVehiclePos(const Vehicle *v) FORCEINLINE bool SetOriginFromVehiclePos(const RoadVehicle *v)
{ {
/* set origin (tile, trackdir) */ /* set origin (tile, trackdir) */
TileIndex src_tile = v->tile; TileIndex src_tile = v->tile;
Trackdir src_td = v->GetVehicleTrackdir(); Trackdir src_td = v->GetVehicleTrackdir();
if ((TrackStatusToTrackdirBits(GetTileTrackStatus(src_tile, TRANSPORT_ROAD, RoadVehicle::From(v)->compatible_roadtypes)) & TrackdirToTrackdirBits(src_td)) == 0) { if ((TrackStatusToTrackdirBits(GetTileTrackStatus(src_tile, TRANSPORT_ROAD, v->compatible_roadtypes)) & TrackdirToTrackdirBits(src_td)) == 0) {
/* sometimes the roadveh is not on the road (it resides on non-existing track) /* sometimes the roadveh is not on the road (it resides on non-existing track)
* how should we handle that situation? */ * how should we handle that situation? */
return false; return false;
@ -462,13 +462,13 @@ public:
return true; return true;
} }
static bool stFindNearestDepot(const Vehicle *v, TileIndex tile, Trackdir td, int max_distance, TileIndex *depot_tile) static bool stFindNearestDepot(const RoadVehicle *v, TileIndex tile, Trackdir td, int max_distance, TileIndex *depot_tile)
{ {
Tpf pf; Tpf pf;
return pf.FindNearestDepot(v, tile, td, max_distance, depot_tile); return pf.FindNearestDepot(v, tile, td, max_distance, depot_tile);
} }
FORCEINLINE bool FindNearestDepot(const Vehicle *v, TileIndex tile, Trackdir td, int max_distance, TileIndex *depot_tile) FORCEINLINE bool FindNearestDepot(const RoadVehicle *v, TileIndex tile, Trackdir td, int max_distance, TileIndex *depot_tile)
{ {
/* set origin and destination nodes */ /* set origin and destination nodes */
Yapf().SetOrigin(tile, TrackdirToTrackdirBits(td)); Yapf().SetOrigin(tile, TrackdirToTrackdirBits(td));
@ -520,6 +520,7 @@ struct CYapfRoad_TypesT
typedef Tpf_ Tpf; typedef Tpf_ Tpf;
typedef CFollowTrackRoad TrackFollower; typedef CFollowTrackRoad TrackFollower;
typedef Tnode_list NodeList; typedef Tnode_list NodeList;
typedef RoadVehicle VehicleType;
typedef CYapfBaseT<Types> PfBase; typedef CYapfBaseT<Types> PfBase;
typedef CYapfFollowRoadT<Types> PfFollow; typedef CYapfFollowRoadT<Types> PfFollow;
typedef CYapfOriginTileT<Types> PfOrigin; typedef CYapfOriginTileT<Types> PfOrigin;
@ -538,10 +539,10 @@ struct CYapfRoadAnyRoadVehicleCompatibleStopOfGivenStation1 : CYapfT<CYapfRoad_T
struct CYapfRoadAnyRoadVehicleCompatibleStopOfGivenStation2 : CYapfT<CYapfRoad_TypesT<CYapfRoadAnyRoadVehicleCompatibleStopOfGivenStation2, CRoadNodeListExitDir , CYapfDestinationAnyRoadVehicleCompatibleStopOfGivenStationT> > {}; struct CYapfRoadAnyRoadVehicleCompatibleStopOfGivenStation2 : CYapfT<CYapfRoad_TypesT<CYapfRoadAnyRoadVehicleCompatibleStopOfGivenStation2, CRoadNodeListExitDir , CYapfDestinationAnyRoadVehicleCompatibleStopOfGivenStationT> > {};
Trackdir YapfChooseRoadTrack(const Vehicle *v, TileIndex tile, DiagDirection enterdir) Trackdir YapfChooseRoadTrack(const RoadVehicle *v, TileIndex tile, DiagDirection enterdir)
{ {
/* default is YAPF type 2 */ /* default is YAPF type 2 */
typedef Trackdir (*PfnChooseRoadTrack)(const Vehicle*, TileIndex, DiagDirection); typedef Trackdir (*PfnChooseRoadTrack)(const RoadVehicle*, TileIndex, DiagDirection);
PfnChooseRoadTrack pfnChooseRoadTrack = &CYapfRoad2::stChooseRoadTrack; // default: ExitDir, allow 90-deg PfnChooseRoadTrack pfnChooseRoadTrack = &CYapfRoad2::stChooseRoadTrack; // default: ExitDir, allow 90-deg
/* check if non-default YAPF type should be used */ /* check if non-default YAPF type should be used */
@ -553,10 +554,10 @@ Trackdir YapfChooseRoadTrack(const Vehicle *v, TileIndex tile, DiagDirection ent
return td_ret; return td_ret;
} }
uint YapfRoadVehDistanceToTile(const Vehicle *v, TileIndex tile) uint YapfRoadVehDistanceToTile(const RoadVehicle *v, TileIndex tile)
{ {
/* default is YAPF type 2 */ /* default is YAPF type 2 */
typedef uint (*PfnDistanceToTile)(const Vehicle*, TileIndex); typedef uint (*PfnDistanceToTile)(const RoadVehicle*, TileIndex);
PfnDistanceToTile pfnDistanceToTile = &CYapfRoad2::stDistanceToTile; // default: ExitDir, allow 90-deg PfnDistanceToTile pfnDistanceToTile = &CYapfRoad2::stDistanceToTile; // default: ExitDir, allow 90-deg
/* check if non-default YAPF type should be used */ /* check if non-default YAPF type should be used */
@ -574,13 +575,13 @@ uint YapfRoadVehDistanceToTile(const Vehicle *v, TileIndex tile)
return dist; return dist;
} }
bool YapfFindNearestRoadDepot(const Vehicle *v, int max_distance, TileIndex *depot_tile) bool YapfFindNearestRoadDepot(const RoadVehicle *v, int max_distance, TileIndex *depot_tile)
{ {
*depot_tile = INVALID_TILE; *depot_tile = INVALID_TILE;
TileIndex tile = v->tile; TileIndex tile = v->tile;
Trackdir trackdir = v->GetVehicleTrackdir(); Trackdir trackdir = v->GetVehicleTrackdir();
if ((TrackStatusToTrackdirBits(GetTileTrackStatus(tile, TRANSPORT_ROAD, RoadVehicle::From(v)->compatible_roadtypes)) & TrackdirToTrackdirBits(trackdir)) == 0) { if ((TrackStatusToTrackdirBits(GetTileTrackStatus(tile, TRANSPORT_ROAD, v->compatible_roadtypes)) & TrackdirToTrackdirBits(trackdir)) == 0) {
return false; return false;
} }
@ -592,7 +593,7 @@ bool YapfFindNearestRoadDepot(const Vehicle *v, int max_distance, TileIndex *dep
} }
/* default is YAPF type 2 */ /* default is YAPF type 2 */
typedef bool (*PfnFindNearestDepot)(const Vehicle*, TileIndex, Trackdir, int, TileIndex*); typedef bool (*PfnFindNearestDepot)(const RoadVehicle*, TileIndex, Trackdir, int, TileIndex*);
PfnFindNearestDepot pfnFindNearestDepot = &CYapfRoadAnyDepot2::stFindNearestDepot; PfnFindNearestDepot pfnFindNearestDepot = &CYapfRoadAnyDepot2::stFindNearestDepot;
/* check if non-default YAPF type should be used */ /* check if non-default YAPF type should be used */
@ -613,7 +614,7 @@ bool YapfFindNearestRoadVehicleCompatibleStop(const RoadVehicle *v, StationID st
TileIndex tile = v->tile; TileIndex tile = v->tile;
Trackdir trackdir = v->GetVehicleTrackdir(); Trackdir trackdir = v->GetVehicleTrackdir();
if ((TrackStatusToTrackdirBits(GetTileTrackStatus(tile, TRANSPORT_ROAD, RoadVehicle::From(v)->compatible_roadtypes)) & TrackdirToTrackdirBits(trackdir)) == 0) { if ((TrackStatusToTrackdirBits(GetTileTrackStatus(tile, TRANSPORT_ROAD, v->compatible_roadtypes)) & TrackdirToTrackdirBits(trackdir)) == 0) {
return false; return false;
} }

View File

@ -151,6 +151,7 @@ struct CYapfShip_TypesT
typedef Ttrack_follower TrackFollower; typedef Ttrack_follower TrackFollower;
/** node list type */ /** node list type */
typedef Tnode_list NodeList; typedef Tnode_list NodeList;
typedef Ship VehicleType;
/** pathfinder components (modules) */ /** pathfinder components (modules) */
typedef CYapfBaseT<Types> PfBase; // base pathfinder class typedef CYapfBaseT<Types> PfBase; // base pathfinder class
typedef CYapfFollowShipT<Types> PfFollow; // node follower typedef CYapfFollowShipT<Types> PfFollow; // node follower