From 4f75cf6f71fa354108992d042666567ac86b7c58 Mon Sep 17 00:00:00 2001 From: cirdan Date: Sun, 9 Feb 2014 12:01:19 +0100 Subject: [PATCH] Merge CYapfAnySafeTileRail1 and CYapfAnySafeTileRail2 Merge pathfinder classes CYapfAnySafeTileRail1 and CYapfAnySafeTileRail2 into a single class CYapfAnySafeTileRail, and let users decide whether to allow 90-degree turns or not. --- src/pathfinder/yapf/yapf_rail.cpp | 36 +++++++++--------------------------- 1 file changed, 9 insertions(+), 27 deletions(-) diff --git a/src/pathfinder/yapf/yapf_rail.cpp b/src/pathfinder/yapf/yapf_rail.cpp index ef13f1a6d..842ea1029 100644 --- a/src/pathfinder/yapf/yapf_rail.cpp +++ b/src/pathfinder/yapf/yapf_rail.cpp @@ -1210,16 +1210,16 @@ public: n.m_estimate = n.m_cost; } - static bool stFindNearestSafeTile(const Train *v, const PathPos &pos, bool override_railtype) + static bool stFindNearestSafeTile(const Train *v, bool allow_90deg, const PathPos &pos, bool override_railtype) { /* Create pathfinder instance */ - Tpf pf1 (v, override_railtype); + Tpf pf1 (v, allow_90deg, override_railtype); #if !DEBUG_YAPF_CACHE bool result1 = pf1.FindNearestSafeTile(pos, override_railtype, false); #else bool result2 = pf1.FindNearestSafeTile(pos, override_railtype, true); - Tpf pf2 (v, override_railtype); + Tpf pf2 (v, allow_90deg, override_railtype); pf2.DisableCache(true); bool result1 = pf2.FindNearestSafeTile(pos, override_railtype, false); if (result1 != result2) { @@ -1432,22 +1432,12 @@ struct CYapfAnyDepotRail } }; -struct CYapfAnySafeTileRail1 - : CYapfRailT - , CYapfAnySafeTileRailT > +struct CYapfAnySafeTileRail + : CYapfRailT + , CYapfAnySafeTileRailT > { - CYapfAnySafeTileRail1 (const Train *v, bool override_railtype) - : CYapfRailT (v, true, override_railtype) - { - } -}; - -struct CYapfAnySafeTileRail2 - : CYapfRailT - , CYapfAnySafeTileRailT > -{ - CYapfAnySafeTileRail2 (const Train *v, bool override_railtype) - : CYapfRailT (v, false, override_railtype) + CYapfAnySafeTileRail (const Train *v, bool allow_90deg, bool override_railtype) + : CYapfRailT (v, allow_90deg, override_railtype) { } }; @@ -1562,13 +1552,5 @@ bool YapfTrainFindNearestDepot(const Train *v, uint max_penalty, FindDepotData * bool YapfTrainFindNearestSafeTile(const Train *v, const PathPos &pos, bool override_railtype) { - typedef bool (*PfnFindNearestSafeTile)(const Train*, const PathPos&, bool); - PfnFindNearestSafeTile pfnFindNearestSafeTile = CYapfAnySafeTileRail1::stFindNearestSafeTile; - - /* check if non-default YAPF type needed */ - if (_settings_game.pf.forbid_90_deg) { - pfnFindNearestSafeTile = &CYapfAnySafeTileRail2::stFindNearestSafeTile; - } - - return pfnFindNearestSafeTile(v, pos, override_railtype); + return CYapfAnySafeTileRail::stFindNearestSafeTile (v, !_settings_game.pf.forbid_90_deg, pos, override_railtype); } -- 2.11.4.GIT