1
0
Fork 0

Codechange: Move two way signal EOL to a more logical place

pull/13151/head
Koen Bussemaker 2024-12-05 21:55:36 +01:00 committed by Kuhnovic
parent ca148022f7
commit 701cb2e9d7
3 changed files with 26 additions and 17 deletions

View File

@ -69,7 +69,6 @@ protected:
TileIndex reverse_tile; ///< second (reverse) origin tile TileIndex reverse_tile; ///< second (reverse) origin tile
Trackdir reverse_td; ///< second (reverse) origin trackdir Trackdir reverse_td; ///< second (reverse) origin trackdir
int reverse_penalty; ///< penalty to be added for using the reverse origin int reverse_penalty; ///< penalty to be added for using the reverse origin
bool 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 */ /** to access inherited path finder */
inline Tpf &Yapf() inline Tpf &Yapf()
@ -79,14 +78,13 @@ protected:
public: public:
/** set origin (tiles, trackdirs, etc.) */ /** 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, Trackdir td, TileIndex tiler = INVALID_TILE, Trackdir tdr = INVALID_TRACKDIR, int reverse_penalty = 0)
{ {
this->origin_tile = tile; this->origin_tile = tile;
this->origin_td = td; this->origin_td = td;
this->reverse_tile = tiler; this->reverse_tile = tiler;
this->reverse_td = tdr; this->reverse_td = tdr;
this->reverse_penalty = reverse_penalty; this->reverse_penalty = reverse_penalty;
this->treat_first_red_two_way_signal_as_eol = treat_first_red_two_way_signal_as_eol;
} }
/** Called when YAPF needs to place origin nodes into open list */ /** Called when YAPF needs to place origin nodes into open list */
@ -104,12 +102,6 @@ public:
Yapf().AddStartupNode(n2); Yapf().AddStartupNode(n2);
} }
} }
/** return true if first two-way signal should be treated as dead end */
inline bool TreatFirstRedTwoWaySignalAsEOL()
{
return Yapf().PfGetSettings().rail_firstred_twoway_eol && this->treat_first_red_two_way_signal_as_eol;
}
}; };
/** /**

View File

@ -45,17 +45,18 @@ protected:
* @note maximum cost doesn't work with caching enabled * @note maximum cost doesn't work with caching enabled
* @todo fix maximum cost failing with caching (e.g. FS#2900) * @todo fix maximum cost failing with caching (e.g. FS#2900)
*/ */
int max_cost; int max_cost = 0;
bool disable_cache; bool disable_cache = false;
std::vector<int> sig_look_ahead_costs; std::vector<int> sig_look_ahead_costs = {};
bool treat_first_red_two_way_signal_as_eol = false;
public: public:
bool stopped_on_first_two_way_signal; bool stopped_on_first_two_way_signal = false;
protected: protected:
static constexpr int MAX_SEGMENT_COST = 10000; static constexpr int MAX_SEGMENT_COST = 10000;
CYapfCostRailT() : max_cost(0), disable_cache(false), stopped_on_first_two_way_signal(false) CYapfCostRailT()
{ {
/* pre-compute look-ahead penalties into array */ /* pre-compute look-ahead penalties into array */
int p0 = Yapf().PfGetSettings().rail_look_ahead_signal_p0; int p0 = Yapf().PfGetSettings().rail_look_ahead_signal_p0;
@ -75,6 +76,18 @@ protected:
} }
public: public:
/** Sets whether the first two-way signal should be treated as a dead end */
void SetTreatFirstRedTwoWaySignalAsEOL(bool enabled)
{
this->treat_first_red_two_way_signal_as_eol = enabled;
}
/** Returns whether the first two-way signal should be treated as a dead end */
inline bool TreatFirstRedTwoWaySignalAsEOL()
{
return Yapf().PfGetSettings().rail_firstred_twoway_eol && this->treat_first_red_two_way_signal_as_eol;
}
inline int SlopeCost(TileIndex tile, Trackdir td) inline int SlopeCost(TileIndex tile, Trackdir td)
{ {
if (!stSlopeCost(tile, td)) return 0; if (!stSlopeCost(tile, td)) return 0;

View File

@ -268,7 +268,8 @@ public:
inline FindDepotData FindNearestDepotTwoWay(const Train *v, TileIndex t1, Trackdir td1, TileIndex t2, Trackdir td2, int max_penalty, int reverse_penalty) inline FindDepotData FindNearestDepotTwoWay(const Train *v, TileIndex t1, Trackdir td1, TileIndex t2, Trackdir td2, int max_penalty, int reverse_penalty)
{ {
/* 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);
Yapf().SetTreatFirstRedTwoWaySignalAsEOL(true);
Yapf().SetDestination(v); Yapf().SetDestination(v);
Yapf().SetMaxCost(max_penalty); Yapf().SetMaxCost(max_penalty);
@ -351,6 +352,7 @@ public:
{ {
/* Set origin and destination. */ /* Set origin and destination. */
Yapf().SetOrigin(t1, td); Yapf().SetOrigin(t1, td);
Yapf().SetTreatFirstRedTwoWaySignalAsEOL(false);
Yapf().SetDestination(v, override_railtype); Yapf().SetDestination(v, override_railtype);
if (!Yapf().FindPath(v)) return false; if (!Yapf().FindPath(v)) return false;
@ -437,7 +439,8 @@ public:
/* set origin and destination nodes */ /* set origin and destination nodes */
PBSTileInfo origin = FollowTrainReservation(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);
Yapf().SetTreatFirstRedTwoWaySignalAsEOL(true);
Yapf().SetDestination(v); Yapf().SetDestination(v);
/* find the best path */ /* find the best path */
@ -501,7 +504,8 @@ public:
{ {
/* create pathfinder instance /* create pathfinder instance
* set origin and destination nodes */ * set origin and destination nodes */
Yapf().SetOrigin(t1, td1, t2, td2, reverse_penalty, false); Yapf().SetOrigin(t1, td1, t2, td2, reverse_penalty);
Yapf().SetTreatFirstRedTwoWaySignalAsEOL(false);
Yapf().SetDestination(v); Yapf().SetDestination(v);
/* find the best path */ /* find the best path */