diff options
author | rubidium <rubidium@openttd.org> | 2009-12-02 10:13:49 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2009-12-02 10:13:49 +0000 |
commit | c56c892b2c9a30d7a5d4e7a59053e13471f038ab (patch) | |
tree | 4bc147441da298b187778958ec6853644c9ef907 /src/pathfinder | |
parent | 9165c195b9609bb9db77cc23ff424802eb4ab128 (diff) | |
download | openttd-c56c892b2c9a30d7a5d4e7a59053e13471f038ab.tar.xz |
(svn r18372) -Codechange: push some extra type safety into YAPF
Diffstat (limited to 'src/pathfinder')
-rw-r--r-- | src/pathfinder/yapf/follow_track.hpp | 24 | ||||
-rw-r--r-- | src/pathfinder/yapf/yapf.h | 6 | ||||
-rw-r--r-- | src/pathfinder/yapf/yapf_base.hpp | 7 | ||||
-rw-r--r-- | src/pathfinder/yapf/yapf_costrail.hpp | 8 | ||||
-rw-r--r-- | src/pathfinder/yapf/yapf_destrail.hpp | 12 | ||||
-rw-r--r-- | src/pathfinder/yapf/yapf_node_rail.hpp | 2 | ||||
-rw-r--r-- | src/pathfinder/yapf/yapf_rail.cpp | 33 | ||||
-rw-r--r-- | src/pathfinder/yapf/yapf_road.cpp | 41 | ||||
-rw-r--r-- | src/pathfinder/yapf/yapf_ship.cpp | 1 |
9 files changed, 69 insertions, 65 deletions
diff --git a/src/pathfinder/yapf/follow_track.hpp b/src/pathfinder/yapf/follow_track.hpp index a1f769de9..d1ad1c199 100644 --- a/src/pathfinder/yapf/follow_track.hpp +++ b/src/pathfinder/yapf/follow_track.hpp @@ -20,7 +20,7 @@ /** Track follower helper template class (can serve pathfinders and vehicle * controllers). See 6 different typedefs below for 3 different transport * 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 { enum ErrorCode { @@ -32,7 +32,7 @@ struct CFollowTrackT EC_RESERVED, }; - const Vehicle *m_veh; ///< moving vehicle + const VehicleType *m_veh; ///< moving vehicle Owner m_veh_owner; ///< owner of the vehicle TileIndex m_old_tile; ///< the origin (vehicle moved from) before move Trackdir m_old_td; ///< the trackdir (the vehicle was on) before move @@ -47,7 +47,7 @@ struct CFollowTrackT CPerformanceTimer *m_pPerf; 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); } @@ -58,7 +58,7 @@ struct CFollowTrackT 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)); m_veh = v; @@ -437,15 +437,15 @@ public: } }; -typedef CFollowTrackT<TRANSPORT_WATER, true > CFollowTrackWater; -typedef CFollowTrackT<TRANSPORT_ROAD , true > CFollowTrackRoad; -typedef CFollowTrackT<TRANSPORT_RAIL , true > CFollowTrackRail; +typedef CFollowTrackT<TRANSPORT_WATER, Ship, true > CFollowTrackWater; +typedef CFollowTrackT<TRANSPORT_ROAD, RoadVehicle, true > CFollowTrackRoad; +typedef CFollowTrackT<TRANSPORT_RAIL, Train, true > CFollowTrackRail; -typedef CFollowTrackT<TRANSPORT_WATER, false> CFollowTrackWaterNo90; -typedef CFollowTrackT<TRANSPORT_ROAD , false> CFollowTrackRoadNo90; -typedef CFollowTrackT<TRANSPORT_RAIL , false> CFollowTrackRailNo90; +typedef CFollowTrackT<TRANSPORT_WATER, Ship, false> CFollowTrackWaterNo90; +typedef CFollowTrackT<TRANSPORT_ROAD, RoadVehicle, false> CFollowTrackRoadNo90; +typedef CFollowTrackT<TRANSPORT_RAIL, Train, false> CFollowTrackRailNo90; -typedef CFollowTrackT<TRANSPORT_RAIL , true , true> CFollowTrackFreeRail; -typedef CFollowTrackT<TRANSPORT_RAIL , false, true> CFollowTrackFreeRailNo90; +typedef CFollowTrackT<TRANSPORT_RAIL, Train, true, true > CFollowTrackFreeRail; +typedef CFollowTrackT<TRANSPORT_RAIL, Train, false, true > CFollowTrackFreeRailNo90; #endif /* FOLLOW_TRACK_HPP */ diff --git a/src/pathfinder/yapf/yapf.h b/src/pathfinder/yapf/yapf.h index bfb442a2a..778ddf4ba 100644 --- a/src/pathfinder/yapf/yapf.h +++ b/src/pathfinder/yapf/yapf.h @@ -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 * @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. @@ -52,7 +52,7 @@ Track YapfTrainChooseTrack(const Train *v, TileIndex tile, DiagDirection enterdi * @param tile destination tile * @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. * @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 * @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. diff --git a/src/pathfinder/yapf/yapf_base.hpp b/src/pathfinder/yapf/yapf_base.hpp index 0011e0802..cbebb31ec 100644 --- a/src/pathfinder/yapf/yapf_base.hpp +++ b/src/pathfinder/yapf/yapf_base.hpp @@ -52,6 +52,7 @@ public: typedef typename Types::Tpf Tpf; ///< the pathfinder class (derived from THIS class) typedef typename Types::TrackFollower TrackFollower; 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 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 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 - 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_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 maximum amount of loops reached - m_max_search_nodes (default = 10000) * @return true if the path was found */ - inline bool FindPath(const Vehicle *v) + inline bool FindPath(const VehicleType *v) { m_veh = v; @@ -291,7 +292,7 @@ public: m_nodes.InsertOpenNode(n); } - const Vehicle * GetVehicle() const + const VehicleType * GetVehicle() const { return m_veh; } diff --git a/src/pathfinder/yapf/yapf_costrail.hpp b/src/pathfinder/yapf/yapf_costrail.hpp index 51c8e3920..959431520 100644 --- a/src/pathfinder/yapf/yapf_costrail.hpp +++ b/src/pathfinder/yapf/yapf_costrail.hpp @@ -251,11 +251,11 @@ public: FORCEINLINE int PlatformLengthPenalty(int platform_length) { int cost = 0; - const Vehicle *v = Yapf().GetVehicle(); + const Train *v = Yapf().GetVehicle(); assert(v != NULL); assert(v->type == VEH_TRAIN); - assert(Train::From(v)->tcache.cached_total_length != 0); - int missing_platform_length = (Train::From(v)->tcache.cached_total_length + TILE_SIZE - 1) / TILE_SIZE - platform_length; + assert(v->tcache.cached_total_length != 0); + int missing_platform_length = (v->tcache.cached_total_length + TILE_SIZE - 1) / TILE_SIZE - platform_length; if (missing_platform_length < 0) { /* 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; @@ -322,7 +322,7 @@ public: int segment_entry_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 */ TILE cur(n.m_key.m_tile, n.m_key.m_td); diff --git a/src/pathfinder/yapf/yapf_destrail.hpp b/src/pathfinder/yapf/yapf_destrail.hpp index acdc68244..5a39b92b4 100644 --- a/src/pathfinder/yapf/yapf_destrail.hpp +++ b/src/pathfinder/yapf/yapf_destrail.hpp @@ -18,10 +18,10 @@ protected: RailTypes m_compatible_railtypes; 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; - if (override_rail_type) m_compatible_railtypes |= GetRailTypeInfo(Train::From(v)->railtype)->compatible_railtypes; + m_compatible_railtypes = v->compatible_railtypes; + if (override_rail_type) m_compatible_railtypes |= GetRailTypeInfo(v->railtype)->compatible_railtypes; } bool IsCompatibleRailType(RailType rt) @@ -98,8 +98,8 @@ public: FORCEINLINE bool PfDetectDestination(TileIndex tile, Trackdir td) { return - IsSafeWaitingPosition(Train::From(Yapf().GetVehicle()), tile, td, true, !TrackFollower::Allow90degTurns()) && - IsWaitingPositionFree(Train::From(Yapf().GetVehicle()), tile, td, !TrackFollower::Allow90degTurns()); + IsSafeWaitingPosition(Yapf().GetVehicle(), tile, td, true, !TrackFollower::Allow90degTurns()) && + IsWaitingPositionFree(Yapf().GetVehicle(), tile, td, !TrackFollower::Allow90degTurns()); } /** Called by YAPF to calculate cost estimate. Calculates distance to the destination @@ -132,7 +132,7 @@ protected: } public: - void SetDestination(const Vehicle *v) + void SetDestination(const Train *v) { switch (v->current_order.GetType()) { case OT_GOTO_STATION: diff --git a/src/pathfinder/yapf/yapf_node_rail.hpp b/src/pathfinder/yapf/yapf_node_rail.hpp index 597424e0a..64eb8ed65 100644 --- a/src/pathfinder/yapf/yapf_node_rail.hpp +++ b/src/pathfinder/yapf/yapf_node_rail.hpp @@ -243,7 +243,7 @@ struct CYapfRailNodeT } 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()); TileIndex cur = base::GetTile(); diff --git a/src/pathfinder/yapf/yapf_rail.cpp b/src/pathfinder/yapf/yapf_rail.cpp index 54ea1a916..1cf8677f9 100644 --- a/src/pathfinder/yapf/yapf_rail.cpp +++ b/src/pathfinder/yapf/yapf_rail.cpp @@ -60,7 +60,7 @@ private: 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_td = td; return false; // Stop iterating segment @@ -155,7 +155,7 @@ public: } /* 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) { node->IterateTiles(Yapf().GetVehicle(), Yapf(), *this, &CYapfReserveTrack<Types>::ReserveSingleTrack); @@ -216,7 +216,7 @@ public: 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; /* @@ -246,7 +246,7 @@ public: 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 */ Yapf().SetOrigin(t1, td1, t2, td2, reverse_penalty, true); @@ -310,7 +310,7 @@ public: 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 */ Tpf pf1; @@ -331,7 +331,7 @@ public: 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. */ Yapf().SetOrigin(t1, td); @@ -391,7 +391,7 @@ public: 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 */ Tpf pf1; @@ -412,12 +412,12 @@ public: 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; /* 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().SetDestination(v); @@ -454,7 +454,7 @@ public: 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; bool result1 = pf1.CheckReverseTrain(v, t1, td1, t2, td2, reverse_penalty); @@ -472,7 +472,7 @@ public: 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 * set origin and destination nodes */ @@ -506,6 +506,7 @@ struct CYapfRail_TypesT typedef Tpf_ Tpf; typedef Ttrack_follower TrackFollower; typedef Tnode_list NodeList; + typedef Train VehicleType; typedef CYapfBaseT<Types> PfBase; typedef TfollowT<Types> PfFollow; 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) { /* 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; /* 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; } - typedef bool (*PfnCheckReverseTrain)(const Vehicle*, TileIndex, Trackdir, TileIndex, Trackdir, int); + typedef bool (*PfnCheckReverseTrain)(const Train*, TileIndex, Trackdir, TileIndex, Trackdir, int); PfnCheckReverseTrain pfnCheckReverseTrain = CYapfRail1::stCheckReverseTrain; /* 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(); - PBSTileInfo origin = FollowTrainReservation(Train::From(v)); + PBSTileInfo origin = FollowTrainReservation(v); TileIndex last_tile = last_veh->tile; 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; /* 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) { - typedef bool (*PfnFindNearestSafeTile)(const Vehicle*, TileIndex, Trackdir, bool); + typedef bool (*PfnFindNearestSafeTile)(const Train*, TileIndex, Trackdir, bool); PfnFindNearestSafeTile pfnFindNearestSafeTile = CYapfAnySafeTileRail1::stFindNearestSafeTile; /* check if non-default YAPF type needed */ diff --git a/src/pathfinder/yapf/yapf_road.cpp b/src/pathfinder/yapf/yapf_road.cpp index 3a5f80717..670ba23b1 100644 --- a/src/pathfinder/yapf/yapf_road.cpp +++ b/src/pathfinder/yapf/yapf_road.cpp @@ -97,7 +97,7 @@ public: /* base tile cost depending on distance between edges */ 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 */ if (Yapf().PfDetectDestinationTile(tile, trackdir)) break; @@ -362,13 +362,13 @@ public: return 'r'; } - static Trackdir stChooseRoadTrack(const Vehicle *v, TileIndex tile, DiagDirection enterdir) + static Trackdir stChooseRoadTrack(const RoadVehicle *v, TileIndex tile, DiagDirection enterdir) { Tpf pf; 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 */ if (tile == v->dest_tile) { @@ -378,13 +378,13 @@ public: /* our source tile will be the next vehicle tile (should be the given one) */ TileIndex src_tile = 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 */ src_trackdirs &= DiagdirReachesTrackdirs(enterdir); /* get available trackdirs on the destination 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 */ Yapf().SetOrigin(src_tile, src_trackdirs); @@ -410,13 +410,13 @@ public: return next_trackdir; } - static uint stDistanceToTile(const Vehicle *v, TileIndex tile) + static uint stDistanceToTile(const RoadVehicle *v, TileIndex tile) { Tpf pf; 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 */ if (dst_tile == v->tile) { @@ -428,7 +428,7 @@ public: /* set destination tile, trackdir * 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); /* 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. */ - FORCEINLINE bool SetOriginFromVehiclePos(const Vehicle *v) + FORCEINLINE bool SetOriginFromVehiclePos(const RoadVehicle *v) { /* set origin (tile, trackdir) */ TileIndex src_tile = v->tile; 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) * how should we handle that situation? */ return false; @@ -462,13 +462,13 @@ public: 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; 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 */ Yapf().SetOrigin(tile, TrackdirToTrackdirBits(td)); @@ -520,6 +520,7 @@ struct CYapfRoad_TypesT typedef Tpf_ Tpf; typedef CFollowTrackRoad TrackFollower; typedef Tnode_list NodeList; + typedef RoadVehicle VehicleType; typedef CYapfBaseT<Types> PfBase; typedef CYapfFollowRoadT<Types> PfFollow; typedef CYapfOriginTileT<Types> PfOrigin; @@ -538,10 +539,10 @@ struct CYapfRoadAnyRoadVehicleCompatibleStopOfGivenStation1 : CYapfT<CYapfRoad_T 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 */ - typedef Trackdir (*PfnChooseRoadTrack)(const Vehicle*, TileIndex, DiagDirection); + typedef Trackdir (*PfnChooseRoadTrack)(const RoadVehicle*, TileIndex, DiagDirection); PfnChooseRoadTrack pfnChooseRoadTrack = &CYapfRoad2::stChooseRoadTrack; // default: ExitDir, allow 90-deg /* 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; } -uint YapfRoadVehDistanceToTile(const Vehicle *v, TileIndex tile) +uint YapfRoadVehDistanceToTile(const RoadVehicle *v, TileIndex tile) { /* 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 /* check if non-default YAPF type should be used */ @@ -574,13 +575,13 @@ uint YapfRoadVehDistanceToTile(const Vehicle *v, TileIndex tile) 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; TileIndex tile = v->tile; 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; } @@ -592,7 +593,7 @@ bool YapfFindNearestRoadDepot(const Vehicle *v, int max_distance, TileIndex *dep } /* 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; /* check if non-default YAPF type should be used */ @@ -613,7 +614,7 @@ bool YapfFindNearestRoadVehicleCompatibleStop(const RoadVehicle *v, StationID st TileIndex tile = v->tile; 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; } diff --git a/src/pathfinder/yapf/yapf_ship.cpp b/src/pathfinder/yapf/yapf_ship.cpp index 44ec9fe55..b1a6e1698 100644 --- a/src/pathfinder/yapf/yapf_ship.cpp +++ b/src/pathfinder/yapf/yapf_ship.cpp @@ -151,6 +151,7 @@ struct CYapfShip_TypesT typedef Ttrack_follower TrackFollower; /** node list type */ typedef Tnode_list NodeList; + typedef Ship VehicleType; /** pathfinder components (modules) */ typedef CYapfBaseT<Types> PfBase; // base pathfinder class typedef CYapfFollowShipT<Types> PfFollow; // node follower |