# HG changeset patch # User KUDr # Date 1167682383 0 # Node ID f5c656cf0a0e5bb1b706c93fa8ad5985c876d78e # Parent 1811beeb472f2df8a27074603761e1445ab3b173 (svn r7729) [cbh] - Fix: [YAPF] several cbh related issues. YAPF should now work with cbh diff -r 1811beeb472f -r f5c656cf0a0e yapf/follow_track.hpp --- a/yapf/follow_track.hpp Mon Jan 01 19:44:02 2007 +0000 +++ b/yapf/follow_track.hpp Mon Jan 01 20:13:03 2007 +0000 @@ -29,6 +29,7 @@ m_exitdir = INVALID_DIAGDIR; m_is_station = m_is_bridge = m_is_tunnel = false; m_tiles_skipped = 0; + m_intermediate_trackdir = INVALID_TRACKDIR; } FORCEINLINE static TransportType TT() {return Ttr_type_;} @@ -50,7 +51,7 @@ FollowTileExit(); if (!QueryNewTileTrackStatus()) return TryReverse(); m_new_td_bits &= DiagdirReachesTrackdirs(m_exitdir); - if (!Allow90degTurns()) + if (!Allow90degTurns() && m_tiles_skipped == 0) m_new_td_bits &= (TrackdirBits)~(int)TrackdirCrossesTrackdirs(m_old_td); if (m_new_td_bits == TRACKDIR_BIT_NONE) return false; if (!CanEnterNewTile()) return false; @@ -87,6 +88,7 @@ uint32 bridge_length = GetBridgeLength(m_old_tile, m_new_tile); m_tiles_skipped = bridge_length; m_is_bridge = true; + if (m_tiles_skipped > 0) m_intermediate_trackdir = DiagdirToDiagTrackdir(bridge_enterdir); return; } } @@ -185,11 +187,6 @@ DiagDirection tunnel_enterdir = GetTunnelDirection(m_new_tile); if (tunnel_enterdir != m_exitdir) return false; } - } else if (IsBridgeTile(m_new_tile)) { - if (!m_is_bridge) { - DiagDirection ramp_enderdir = GetBridgeRampDirection(m_new_tile); - if (ramp_enderdir != m_exitdir) return false; - } } } diff -r 1811beeb472f -r f5c656cf0a0e yapf/yapf.h --- a/yapf/yapf.h Mon Jan 01 19:44:02 2007 +0000 +++ b/yapf/yapf.h Mon Jan 01 20:13:03 2007 +0000 @@ -31,7 +31,7 @@ * @param no_path_found [out] true is returned if no path can be found (returned Trackdir is only a 'guess') * @return the best trackdir for next turn or INVALID_TRACKDIR if the path could not be found */ -Trackdir YapfChooseRailTrack(Vehicle *v, TileIndex tile, DiagDirection enterdir, TrackdirBits trackdirs, bool *path_not_found); +Trackdir YapfChooseRailTrack(Vehicle *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks, bool *path_not_found); /** Used by RV multistop feature to find the nearest road stop that has a free slot. * @param v RV (its current tile will be the origin) @@ -98,6 +98,7 @@ bool m_is_bridge; ///< last turn passed bridge ramp bool m_is_station; ///< last turn passed station int m_tiles_skipped; ///< number of skipped tunnel or station tiles + Trackdir m_intermediate_trackdir; ///< when some bridge tiles are skipped, contains direction of the bridge } FollowTrack_t; /** Initializes FollowTrack_t structure */ diff -r 1811beeb472f -r f5c656cf0a0e yapf/yapf_common.hpp --- a/yapf/yapf_common.hpp Mon Jan 01 19:44:02 2007 +0000 +++ b/yapf/yapf_common.hpp Mon Jan 01 20:13:03 2007 +0000 @@ -50,24 +50,24 @@ typedef typename Node::Key Key; ///< key to hash tables protected: - TileIndex m_orgTile; ///< first origin tile - Trackdir m_orgTd; ///< first origin trackdir - TileIndex m_revTile; ///< second (reversed) origin tile - Trackdir m_revTd; ///< second (reversed) origin trackdir - int m_reverse_penalty; ///< penalty to be added for using the reversed origin - bool m_treat_first_red_two_way_signal_as_eol; ///< in some cases (leaving station) we need to handle first two-way signal differently + TileIndex m_org_tile; ///< first origin tile + TrackdirBits m_org_td_bits; ///< first origin trackdirbits + TileIndex m_rev_tile; ///< second (reversed) origin tile + TrackdirBits m_rev_td_bits; ///< second (reversed) origin trackdir + int m_reverse_penalty; ///< penalty to be added for using the reversed origin + bool m_treat_first_red_two_way_signal_as_eol; ///< in some cases (leaving station) we need to handle first two-way signal differently /// to access inherited path finder FORCEINLINE Tpf& Yapf() {return *static_cast(this);} public: /// set origin (tiles, trackdirs, etc.) - void SetOrigin(TileIndex tile, Trackdir td, TileIndex tiler = INVALID_TILE, Trackdir tdr = INVALID_TRACKDIR, int reverse_penalty = 0, bool treat_first_red_two_way_signal_as_eol = true) + void SetOrigin(TileIndex tile, TrackdirBits td_bits, TileIndex tiler = INVALID_TILE, TrackdirBits tdr_bits = INVALID_TRACKDIR_BIT, int reverse_penalty = 0, bool treat_first_red_two_way_signal_as_eol = true) { - m_orgTile = tile; - m_orgTd = td; - m_revTile = tiler; - m_revTd = tdr; + m_org_tile = tile; + m_org_td_bits = td_bits; + m_rev_tile = tiler; + m_rev_td_bits = tdr_bits; m_reverse_penalty = reverse_penalty; m_treat_first_red_two_way_signal_as_eol = treat_first_red_two_way_signal_as_eol; } @@ -75,16 +75,22 @@ /// Called when YAPF needs to place origin nodes into open list void PfSetStartupNodes() { - if (m_orgTile != INVALID_TILE && m_orgTd != INVALID_TRACKDIR) { - Node& n1 = Yapf().CreateNewNode(); - n1.Set(NULL, m_orgTile, m_orgTd, false); - Yapf().AddStartupNode(n1); + if (m_org_tile != INVALID_TILE && m_org_td_bits != INVALID_TRACKDIR_BIT) { + for (TrackdirBits td_bits = m_org_td_bits; td_bits != TRACKDIR_BIT_NONE; td_bits = (TrackdirBits)KillFirstBit2x64(td_bits)) { + Node& n = Yapf().CreateNewNode(); + Trackdir td = (Trackdir)FindFirstBit2x64(td_bits); + n.Set(NULL, m_org_tile, td, false); + Yapf().AddStartupNode(n); + } } - if (m_revTile != INVALID_TILE && m_revTd != INVALID_TRACKDIR) { - Node& n2 = Yapf().CreateNewNode(); - n2.Set(NULL, m_revTile, m_revTd, false); - n2.m_cost = m_reverse_penalty; - Yapf().AddStartupNode(n2); + if (m_rev_tile != INVALID_TILE && m_rev_td_bits != INVALID_TRACKDIR_BIT) { + for (TrackdirBits td_bits = m_rev_td_bits; td_bits != TRACKDIR_BIT_NONE; td_bits = (TrackdirBits)KillFirstBit2x64(td_bits)) { + Node& n = Yapf().CreateNewNode(); + Trackdir td = (Trackdir)FindFirstBit2x64(td_bits); + n.Set(NULL, m_rev_tile, td, false); + n.m_cost = m_reverse_penalty; + Yapf().AddStartupNode(n); + } } } diff -r 1811beeb472f -r f5c656cf0a0e yapf/yapf_costrail.hpp --- a/yapf/yapf_costrail.hpp Mon Jan 01 19:44:02 2007 +0000 +++ b/yapf/yapf_costrail.hpp Mon Jan 01 20:13:03 2007 +0000 @@ -200,6 +200,7 @@ RailType rail_type = GetTileRailType(tile, trackdir); // detect exit from bridge wormhole + Trackdir intermediate_trackdir = INVALID_TRACKDIR; if (IsBridgeTile(tile) && TrackdirToExitdir(ReverseTrackdir(trackdir)) == GetBridgeRampDirection(tile)) { // we are jumping over bridge (possible now with custom bridge heads) we must add the cost of skipped tiles int skipped_tiles = DistanceManhattan(prev_tile, tile) - 1; diff -r 1811beeb472f -r f5c656cf0a0e yapf/yapf_rail.cpp --- a/yapf/yapf_rail.cpp Mon Jan 01 19:44:02 2007 +0000 +++ b/yapf/yapf_rail.cpp Mon Jan 01 20:13:03 2007 +0000 @@ -49,7 +49,7 @@ FORCEINLINE bool FindNearestDepotTwoWay(Vehicle *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); + Yapf().SetOrigin(t1, TrackdirToTrackdirBits(td1), t2, TrackdirToTrackdirBits(td2), reverse_penalty, true); Yapf().SetDestination(v); Yapf().SetMaxCost(YAPF_TILE_LENGTH * max_distance); @@ -103,17 +103,19 @@ /// return debug report character to identify the transportation type FORCEINLINE char TransportTypeChar() const {return 't';} - static Trackdir stChooseRailTrack(Vehicle *v, TileIndex tile, DiagDirection enterdir, TrackdirBits trackdirs, bool *path_not_found) + static Trackdir stChooseRailTrack(Vehicle *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks, bool *path_not_found) { // create pathfinder instance Tpf pf; - return pf.ChooseRailTrack(v, tile, enterdir, trackdirs, path_not_found); + return pf.ChooseRailTrack(v, tile, enterdir, tracks, path_not_found); } - FORCEINLINE Trackdir ChooseRailTrack(Vehicle *v, TileIndex tile, DiagDirection enterdir, TrackdirBits trackdirs, bool *path_not_found) + FORCEINLINE Trackdir ChooseRailTrack(Vehicle *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks, bool *path_not_found) { // set origin and destination nodes - Yapf().SetOrigin(v->tile, GetVehicleTrackdir(v), INVALID_TILE, INVALID_TRACKDIR, 1, true); + TrackdirBits trackdirs = (TrackdirBits)(0x101 * tracks); + trackdirs &= DiagdirReachesTrackdirs(enterdir); + Yapf().SetOrigin(tile, trackdirs, INVALID_TILE, INVALID_TRACKDIR_BIT, 1, true); Yapf().SetDestination(v); // find the best path @@ -130,14 +132,12 @@ if (pNode != NULL) { // path was found or at least suggested // walk through the path back to the origin - Node* pPrev = NULL; while (pNode->m_parent != NULL) { - pPrev = pNode; pNode = pNode->m_parent; } // return trackdir from the best origin node (one of start nodes) - Node& best_next_node = *pPrev; - assert(best_next_node.GetTile() == tile); + Node& best_next_node = *pNode; + assert(v->tile == tile || best_next_node.GetTile() == tile); next_trackdir = best_next_node.GetTrackdir(); } return next_trackdir; @@ -153,7 +153,7 @@ { // create pathfinder instance // set origin and destination nodes - Yapf().SetOrigin(t1, td1, t2, td2, 1, false); + Yapf().SetOrigin(t1, TrackdirToTrackdirBits(td1), t2, TrackdirToTrackdirBits(td2), 1, false); Yapf().SetDestination(v); // find the best path @@ -200,10 +200,10 @@ struct CYapfAnyDepotRail3 : CYapfT > {}; -Trackdir YapfChooseRailTrack(Vehicle *v, TileIndex tile, DiagDirection enterdir, TrackdirBits trackdirs, bool *path_not_found) +Trackdir YapfChooseRailTrack(Vehicle *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks, bool *path_not_found) { // default is YAPF type 2 - typedef Trackdir (*PfnChooseRailTrack)(Vehicle*, TileIndex, DiagDirection, TrackdirBits, bool*); + typedef Trackdir (*PfnChooseRailTrack)(Vehicle*, TileIndex, DiagDirection, TrackBits, bool*); PfnChooseRailTrack pfnChooseRailTrack = &CYapfRail2::stChooseRailTrack; // check if non-default YAPF type needed @@ -212,7 +212,7 @@ else if (_patches.yapf.disable_node_optimization) pfnChooseRailTrack = &CYapfRail1::stChooseRailTrack; // Trackdir, allow 90-deg - Trackdir td_ret = pfnChooseRailTrack(v, tile, enterdir, trackdirs, path_not_found); + Trackdir td_ret = pfnChooseRailTrack(v, tile, enterdir, tracks, path_not_found); return td_ret; }