mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-02-06 06:19:41 +00:00
(svn r13939) -Add [YAPP]: Extend YAPF with the possibility to override the railtype info of the vehicle. (michi_cc)
This commit is contained in:
parent
908591b40a
commit
c91c12adde
@ -34,13 +34,14 @@ struct CFollowTrackT
|
|||||||
int m_tiles_skipped; ///< number of skipped tunnel or station tiles
|
int m_tiles_skipped; ///< number of skipped tunnel or station tiles
|
||||||
ErrorCode m_err;
|
ErrorCode m_err;
|
||||||
CPerformanceTimer *m_pPerf;
|
CPerformanceTimer *m_pPerf;
|
||||||
|
RailTypes m_railtypes;
|
||||||
|
|
||||||
FORCEINLINE CFollowTrackT(const Vehicle *v = NULL, CPerformanceTimer* pPerf = NULL)
|
FORCEINLINE CFollowTrackT(const Vehicle *v = NULL, RailTypes railtype_override = INVALID_RAILTYPES, CPerformanceTimer *pPerf = NULL)
|
||||||
{
|
{
|
||||||
Init(v, pPerf);
|
Init(v, railtype_override, pPerf);
|
||||||
}
|
}
|
||||||
|
|
||||||
FORCEINLINE void Init(const Vehicle *v, CPerformanceTimer* pPerf)
|
FORCEINLINE void Init(const Vehicle *v, RailTypes railtype_override, CPerformanceTimer *pPerf)
|
||||||
{
|
{
|
||||||
assert(!IsRailTT() || (v != NULL && v->type == VEH_TRAIN));
|
assert(!IsRailTT() || (v != NULL && v->type == VEH_TRAIN));
|
||||||
m_veh = v;
|
m_veh = v;
|
||||||
@ -52,6 +53,7 @@ struct CFollowTrackT
|
|||||||
m_is_station = m_is_bridge = m_is_tunnel = false;
|
m_is_station = m_is_bridge = m_is_tunnel = false;
|
||||||
m_tiles_skipped = 0;
|
m_tiles_skipped = 0;
|
||||||
m_err = EC_NONE;
|
m_err = EC_NONE;
|
||||||
|
if (IsRailTT()) m_railtypes = railtype_override == INVALID_RAILTYPES ? v->u.rail.compatible_railtypes : railtype_override;
|
||||||
}
|
}
|
||||||
|
|
||||||
FORCEINLINE static TransportType TT() {return Ttr_type_;}
|
FORCEINLINE static TransportType TT() {return Ttr_type_;}
|
||||||
@ -79,7 +81,7 @@ struct CFollowTrackT
|
|||||||
|
|
||||||
/** main follower routine. Fills all members and return true on success.
|
/** main follower routine. Fills all members and return true on success.
|
||||||
* Otherwise returns false if track can't be followed. */
|
* Otherwise returns false if track can't be followed. */
|
||||||
FORCEINLINE bool Follow(TileIndex old_tile, Trackdir old_td)
|
inline bool Follow(TileIndex old_tile, Trackdir old_td)
|
||||||
{
|
{
|
||||||
m_old_tile = old_tile;
|
m_old_tile = old_tile;
|
||||||
m_old_td = old_td;
|
m_old_td = old_td;
|
||||||
@ -256,7 +258,7 @@ protected:
|
|||||||
// rail transport is possible only on compatible rail types
|
// rail transport is possible only on compatible rail types
|
||||||
if (IsRailTT()) {
|
if (IsRailTT()) {
|
||||||
RailType rail_type = GetTileRailType(m_new_tile);
|
RailType rail_type = GetTileRailType(m_new_tile);
|
||||||
if (!HasBit(m_veh->u.rail.compatible_railtypes, rail_type)) {
|
if (!HasBit(m_railtypes, rail_type)) {
|
||||||
// incompatible rail type
|
// incompatible rail type
|
||||||
m_err = EC_RAIL_TYPE;
|
m_err = EC_RAIL_TYPE;
|
||||||
return false;
|
return false;
|
||||||
|
@ -271,7 +271,7 @@ public:
|
|||||||
|
|
||||||
EndSegmentReasonBits end_segment_reason = ESRB_NONE;
|
EndSegmentReasonBits end_segment_reason = ESRB_NONE;
|
||||||
|
|
||||||
TrackFollower tf_local(v, &Yapf().m_perf_ts_cost);
|
TrackFollower tf_local(v, Yapf().GetCompatibleRailTypes(), &Yapf().m_perf_ts_cost);
|
||||||
|
|
||||||
if (!has_parent) {
|
if (!has_parent) {
|
||||||
/* We will jump to the middle of the cost calculator assuming that segment cache is not used. */
|
/* We will jump to the middle of the cost calculator assuming that segment cache is not used. */
|
||||||
@ -373,7 +373,7 @@ no_entry_cost: // jump here at the beginning if the node has no parent (it is th
|
|||||||
|
|
||||||
/* Move to the next tile/trackdir. */
|
/* Move to the next tile/trackdir. */
|
||||||
tf = &tf_local;
|
tf = &tf_local;
|
||||||
tf_local.Init(v, &Yapf().m_perf_ts_cost);
|
tf_local.Init(v, Yapf().GetCompatibleRailTypes(), &Yapf().m_perf_ts_cost);
|
||||||
|
|
||||||
if (!tf_local.Follow(cur.tile, cur.td)) {
|
if (!tf_local.Follow(cur.tile, cur.td)) {
|
||||||
assert(tf_local.m_err != TrackFollower::EC_NONE);
|
assert(tf_local.m_err != TrackFollower::EC_NONE);
|
||||||
|
@ -11,15 +11,21 @@ protected:
|
|||||||
RailTypes m_compatible_railtypes;
|
RailTypes m_compatible_railtypes;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void SetDestination(const Vehicle* v)
|
void SetDestination(const Vehicle *v, bool override_rail_type = false)
|
||||||
{
|
{
|
||||||
m_compatible_railtypes = v->u.rail.compatible_railtypes;
|
m_compatible_railtypes = v->u.rail.compatible_railtypes;
|
||||||
|
if (override_rail_type) m_compatible_railtypes |= GetRailTypeInfo(v->u.rail.railtype)->compatible_railtypes;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsCompatibleRailType(RailType rt)
|
bool IsCompatibleRailType(RailType rt)
|
||||||
{
|
{
|
||||||
return HasBit(m_compatible_railtypes, rt);
|
return HasBit(m_compatible_railtypes, rt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RailTypes GetCompatibleRailTypes() const
|
||||||
|
{
|
||||||
|
return m_compatible_railtypes;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class Types>
|
template <class Types>
|
||||||
|
Loading…
Reference in New Issue
Block a user