summaryrefslogtreecommitdiff
path: root/src/pathfinder/yapf/yapf_rail.cpp
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2009-12-02 10:13:49 +0000
committerrubidium <rubidium@openttd.org>2009-12-02 10:13:49 +0000
commitc56c892b2c9a30d7a5d4e7a59053e13471f038ab (patch)
tree4bc147441da298b187778958ec6853644c9ef907 /src/pathfinder/yapf/yapf_rail.cpp
parent9165c195b9609bb9db77cc23ff424802eb4ab128 (diff)
downloadopenttd-c56c892b2c9a30d7a5d4e7a59053e13471f038ab.tar.xz
(svn r18372) -Codechange: push some extra type safety into YAPF
Diffstat (limited to 'src/pathfinder/yapf/yapf_rail.cpp')
-rw-r--r--src/pathfinder/yapf/yapf_rail.cpp33
1 files changed, 17 insertions, 16 deletions
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 */