mirror of https://github.com/OpenTTD/OpenTTD
Codechange: Add `this->` to YAPF.
parent
5b73654f94
commit
a6f412c615
|
@ -58,38 +58,40 @@ struct CFollowTrackT
|
|||
inline CFollowTrackT(Owner o, RailTypes railtype_override = INVALID_RAILTYPES)
|
||||
{
|
||||
assert(IsRailTT());
|
||||
m_veh = nullptr;
|
||||
this->m_veh = nullptr;
|
||||
Init(o, railtype_override);
|
||||
}
|
||||
|
||||
inline void Init(const VehicleType *v, RailTypes railtype_override)
|
||||
{
|
||||
assert(!IsRailTT() || (v != nullptr && v->type == VEH_TRAIN));
|
||||
m_veh = v;
|
||||
this->m_veh = v;
|
||||
Init(v != nullptr ? v->owner : INVALID_OWNER, IsRailTT() && railtype_override == INVALID_RAILTYPES ? Train::From(v)->compatible_railtypes : railtype_override);
|
||||
}
|
||||
|
||||
inline void Init(Owner o, RailTypes railtype_override)
|
||||
{
|
||||
assert(!IsRoadTT() || m_veh != nullptr);
|
||||
assert(!IsRoadTT() || this->m_veh != nullptr);
|
||||
assert(!IsRailTT() || railtype_override != INVALID_RAILTYPES);
|
||||
m_veh_owner = o;
|
||||
this->m_veh_owner = o;
|
||||
/* don't worry, all is inlined so compiler should remove unnecessary initializations */
|
||||
m_old_tile = INVALID_TILE;
|
||||
m_old_td = INVALID_TRACKDIR;
|
||||
m_new_tile = INVALID_TILE;
|
||||
m_new_td_bits = TRACKDIR_BIT_NONE;
|
||||
m_exitdir = INVALID_DIAGDIR;
|
||||
m_is_station = m_is_bridge = m_is_tunnel = false;
|
||||
m_tiles_skipped = 0;
|
||||
m_err = EC_NONE;
|
||||
m_railtypes = railtype_override;
|
||||
this->m_old_tile = INVALID_TILE;
|
||||
this->m_old_td = INVALID_TRACKDIR;
|
||||
this->m_new_tile = INVALID_TILE;
|
||||
this->m_new_td_bits = TRACKDIR_BIT_NONE;
|
||||
this->m_exitdir = INVALID_DIAGDIR;
|
||||
this->m_is_station = false;
|
||||
this->m_is_bridge = false;
|
||||
this->m_is_tunnel = false;
|
||||
this->m_tiles_skipped = 0;
|
||||
this->m_err = EC_NONE;
|
||||
this->m_railtypes = railtype_override;
|
||||
}
|
||||
|
||||
debug_inline static TransportType TT() { return Ttr_type_; }
|
||||
debug_inline static bool IsWaterTT() { return TT() == TRANSPORT_WATER; }
|
||||
debug_inline static bool IsRailTT() { return TT() == TRANSPORT_RAIL; }
|
||||
inline bool IsTram() { return IsRoadTT() && RoadTypeIsTram(RoadVehicle::From(m_veh)->roadtype); }
|
||||
inline bool IsTram() { return IsRoadTT() && RoadTypeIsTram(RoadVehicle::From(this->m_veh)->roadtype); }
|
||||
debug_inline static bool IsRoadTT() { return TT() == TRANSPORT_ROAD; }
|
||||
inline static bool Allow90degTurns() { return T90deg_turns_allowed_; }
|
||||
inline static bool DoTrackMasking() { return Tmask_reserved_tracks; }
|
||||
|
@ -97,7 +99,7 @@ struct CFollowTrackT
|
|||
/** Tests if a tile is a road tile with a single tramtrack (tram can reverse) */
|
||||
inline DiagDirection GetSingleTramBit(TileIndex tile)
|
||||
{
|
||||
assert(IsTram()); // this function shouldn't be called in other cases
|
||||
assert(this->IsTram()); // this function shouldn't be called in other cases
|
||||
|
||||
if (IsNormalRoadTile(tile)) {
|
||||
RoadBits rb = GetRoadBits(tile, RTT_TRAM);
|
||||
|
@ -118,24 +120,24 @@ struct CFollowTrackT
|
|||
*/
|
||||
inline bool Follow(TileIndex old_tile, Trackdir old_td)
|
||||
{
|
||||
m_old_tile = old_tile;
|
||||
m_old_td = old_td;
|
||||
m_err = EC_NONE;
|
||||
this->m_old_tile = old_tile;
|
||||
this->m_old_td = old_td;
|
||||
this->m_err = EC_NONE;
|
||||
|
||||
assert([&]() {
|
||||
if (IsTram() && GetSingleTramBit(m_old_tile) != INVALID_DIAGDIR) return true; // Skip the check for single tram bits
|
||||
const uint sub_mode = (IsRoadTT() && m_veh != nullptr) ? (this->IsTram() ? RTT_TRAM : RTT_ROAD) : 0;
|
||||
const TrackdirBits old_tile_valid_dirs = TrackStatusToTrackdirBits(GetTileTrackStatus(m_old_tile, TT(), sub_mode));
|
||||
return (old_tile_valid_dirs & TrackdirToTrackdirBits(m_old_td)) != TRACKDIR_BIT_NONE;
|
||||
if (this->IsTram() && this->GetSingleTramBit(this->m_old_tile) != INVALID_DIAGDIR) return true; // Skip the check for single tram bits
|
||||
const uint sub_mode = (IsRoadTT() && this->m_veh != nullptr) ? (this->IsTram() ? RTT_TRAM : RTT_ROAD) : 0;
|
||||
const TrackdirBits old_tile_valid_dirs = TrackStatusToTrackdirBits(GetTileTrackStatus(this->m_old_tile, TT(), sub_mode));
|
||||
return (old_tile_valid_dirs & TrackdirToTrackdirBits(this->m_old_td)) != TRACKDIR_BIT_NONE;
|
||||
}());
|
||||
|
||||
m_exitdir = TrackdirToExitdir(m_old_td);
|
||||
if (ForcedReverse()) return true;
|
||||
if (!CanExitOldTile()) return false;
|
||||
FollowTileExit();
|
||||
if (!QueryNewTileTrackStatus()) return TryReverse();
|
||||
m_new_td_bits &= DiagdirReachesTrackdirs(m_exitdir);
|
||||
if (m_new_td_bits == TRACKDIR_BIT_NONE || !CanEnterNewTile()) {
|
||||
this->m_exitdir = TrackdirToExitdir(this->m_old_td);
|
||||
if (this->ForcedReverse()) return true;
|
||||
if (!this->CanExitOldTile()) return false;
|
||||
this->FollowTileExit();
|
||||
if (!this->QueryNewTileTrackStatus()) return TryReverse();
|
||||
this->m_new_td_bits &= DiagdirReachesTrackdirs(this->m_exitdir);
|
||||
if (this->m_new_td_bits == TRACKDIR_BIT_NONE || !this->CanEnterNewTile()) {
|
||||
/* In case we can't enter the next tile, but are
|
||||
* a normal road vehicle, then we can actually
|
||||
* try to reverse as this is the end of the road.
|
||||
|
@ -147,19 +149,19 @@ struct CFollowTrackT
|
|||
* that function failed can have to do with a
|
||||
* missing road bit, or inability to connect the
|
||||
* different bits due to slopes. */
|
||||
if (IsRoadTT() && !IsTram() && TryReverse()) return true;
|
||||
if (IsRoadTT() && !this->IsTram() && this->TryReverse()) return true;
|
||||
|
||||
/* CanEnterNewTile already set a reason.
|
||||
* Do NOT overwrite it (important for example for EC_RAIL_ROAD_TYPE).
|
||||
* Only set a reason if CanEnterNewTile was not called */
|
||||
if (m_new_td_bits == TRACKDIR_BIT_NONE) m_err = EC_NO_WAY;
|
||||
if (this->m_new_td_bits == TRACKDIR_BIT_NONE) this->m_err = EC_NO_WAY;
|
||||
|
||||
return false;
|
||||
}
|
||||
if ((!IsRailTT() && !Allow90degTurns()) || (IsRailTT() && Rail90DegTurnDisallowed(GetTileRailType(m_old_tile), GetTileRailType(m_new_tile), !Allow90degTurns()))) {
|
||||
m_new_td_bits &= (TrackdirBits)~(int)TrackdirCrossesTrackdirs(m_old_td);
|
||||
if (m_new_td_bits == TRACKDIR_BIT_NONE) {
|
||||
m_err = EC_90DEG;
|
||||
if ((!IsRailTT() && !Allow90degTurns()) || (IsRailTT() && Rail90DegTurnDisallowed(GetTileRailType(this->m_old_tile), GetTileRailType(this->m_new_tile), !Allow90degTurns()))) {
|
||||
this->m_new_td_bits &= (TrackdirBits)~(int)TrackdirCrossesTrackdirs(this->m_old_td);
|
||||
if (this->m_new_td_bits == TRACKDIR_BIT_NONE) {
|
||||
this->m_err = EC_90DEG;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -170,27 +172,27 @@ struct CFollowTrackT
|
|||
{
|
||||
if (!DoTrackMasking()) return true;
|
||||
|
||||
if (m_is_station) {
|
||||
if (this->m_is_station) {
|
||||
/* Check skipped station tiles as well. */
|
||||
TileIndexDiff diff = TileOffsByDiagDir(m_exitdir);
|
||||
for (TileIndex tile = m_new_tile - diff * m_tiles_skipped; tile != m_new_tile; tile += diff) {
|
||||
TileIndexDiff diff = TileOffsByDiagDir(this->m_exitdir);
|
||||
for (TileIndex tile = this->m_new_tile - diff * this->m_tiles_skipped; tile != this->m_new_tile; tile += diff) {
|
||||
if (HasStationReservation(tile)) {
|
||||
m_new_td_bits = TRACKDIR_BIT_NONE;
|
||||
m_err = EC_RESERVED;
|
||||
this->m_new_td_bits = TRACKDIR_BIT_NONE;
|
||||
this->m_err = EC_RESERVED;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TrackBits reserved = GetReservedTrackbits(m_new_tile);
|
||||
TrackBits reserved = GetReservedTrackbits(this->m_new_tile);
|
||||
/* Mask already reserved trackdirs. */
|
||||
m_new_td_bits &= ~TrackBitsToTrackdirBits(reserved);
|
||||
this->m_new_td_bits &= ~TrackBitsToTrackdirBits(reserved);
|
||||
/* Mask out all trackdirs that conflict with the reservation. */
|
||||
for (Track t : SetTrackBitIterator(TrackdirBitsToTrackBits(m_new_td_bits))) {
|
||||
if (TracksOverlap(reserved | TrackToTrackBits(t))) m_new_td_bits &= ~TrackToTrackdirBits(t);
|
||||
for (Track t : SetTrackBitIterator(TrackdirBitsToTrackBits(this->m_new_td_bits))) {
|
||||
if (TracksOverlap(reserved | TrackToTrackBits(t))) this->m_new_td_bits &= ~TrackToTrackdirBits(t);
|
||||
}
|
||||
if (m_new_td_bits == TRACKDIR_BIT_NONE) {
|
||||
m_err = EC_RESERVED;
|
||||
if (this->m_new_td_bits == TRACKDIR_BIT_NONE) {
|
||||
this->m_err = EC_RESERVED;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
@ -200,77 +202,79 @@ protected:
|
|||
/** Follow the m_exitdir from m_old_tile and fill m_new_tile and m_tiles_skipped */
|
||||
inline void FollowTileExit()
|
||||
{
|
||||
m_is_station = m_is_bridge = m_is_tunnel = false;
|
||||
m_tiles_skipped = 0;
|
||||
this->m_is_station = false;
|
||||
this->m_is_bridge = false;
|
||||
this->m_is_tunnel = false;
|
||||
this->m_tiles_skipped = 0;
|
||||
|
||||
/* extra handling for tunnels and bridges in our direction */
|
||||
if (IsTileType(m_old_tile, MP_TUNNELBRIDGE)) {
|
||||
DiagDirection enterdir = GetTunnelBridgeDirection(m_old_tile);
|
||||
if (enterdir == m_exitdir) {
|
||||
if (IsTileType(this->m_old_tile, MP_TUNNELBRIDGE)) {
|
||||
DiagDirection enterdir = GetTunnelBridgeDirection(this->m_old_tile);
|
||||
if (enterdir == this->m_exitdir) {
|
||||
/* we are entering the tunnel / bridge */
|
||||
if (IsTunnel(m_old_tile)) {
|
||||
m_is_tunnel = true;
|
||||
m_new_tile = GetOtherTunnelEnd(m_old_tile);
|
||||
if (IsTunnel(this->m_old_tile)) {
|
||||
this->m_is_tunnel = true;
|
||||
this->m_new_tile = GetOtherTunnelEnd(this->m_old_tile);
|
||||
} else { // IsBridge(m_old_tile)
|
||||
m_is_bridge = true;
|
||||
m_new_tile = GetOtherBridgeEnd(m_old_tile);
|
||||
this->m_is_bridge = true;
|
||||
this->m_new_tile = GetOtherBridgeEnd(this->m_old_tile);
|
||||
}
|
||||
m_tiles_skipped = GetTunnelBridgeLength(m_new_tile, m_old_tile);
|
||||
this->m_tiles_skipped = GetTunnelBridgeLength(this->m_new_tile, this->m_old_tile);
|
||||
return;
|
||||
}
|
||||
assert(ReverseDiagDir(enterdir) == m_exitdir);
|
||||
assert(ReverseDiagDir(enterdir) == this->m_exitdir);
|
||||
}
|
||||
|
||||
/* normal or station tile, do one step */
|
||||
m_new_tile = TileAddByDiagDir(m_old_tile, m_exitdir);
|
||||
this->m_new_tile = TileAddByDiagDir(this->m_old_tile, this->m_exitdir);
|
||||
|
||||
/* special handling for stations */
|
||||
if (IsRailTT() && HasStationTileRail(m_new_tile)) {
|
||||
m_is_station = true;
|
||||
} else if (IsRoadTT() && IsStationRoadStopTile(m_new_tile)) {
|
||||
m_is_station = true;
|
||||
if (IsRailTT() && HasStationTileRail(this->m_new_tile)) {
|
||||
this->m_is_station = true;
|
||||
} else if (IsRoadTT() && IsStationRoadStopTile(this->m_new_tile)) {
|
||||
this->m_is_station = true;
|
||||
}
|
||||
}
|
||||
|
||||
/** stores track status (available trackdirs) for the new tile into m_new_td_bits */
|
||||
inline bool QueryNewTileTrackStatus()
|
||||
{
|
||||
if (IsRailTT() && IsPlainRailTile(m_new_tile)) {
|
||||
m_new_td_bits = (TrackdirBits)(GetTrackBits(m_new_tile) * 0x101);
|
||||
if (IsRailTT() && IsPlainRailTile(this->m_new_tile)) {
|
||||
this->m_new_td_bits = (TrackdirBits)(GetTrackBits(this->m_new_tile) * 0x101);
|
||||
} else if (IsRoadTT()) {
|
||||
m_new_td_bits = GetTrackdirBitsForRoad(m_new_tile, this->IsTram() ? RTT_TRAM : RTT_ROAD);
|
||||
this->m_new_td_bits = GetTrackdirBitsForRoad(this->m_new_tile, this->IsTram() ? RTT_TRAM : RTT_ROAD);
|
||||
} else {
|
||||
m_new_td_bits = TrackStatusToTrackdirBits(GetTileTrackStatus(m_new_tile, TT(), 0));
|
||||
this->m_new_td_bits = TrackStatusToTrackdirBits(GetTileTrackStatus(this->m_new_tile, TT(), 0));
|
||||
}
|
||||
return (m_new_td_bits != TRACKDIR_BIT_NONE);
|
||||
return (this->m_new_td_bits != TRACKDIR_BIT_NONE);
|
||||
}
|
||||
|
||||
/** return true if we can leave m_old_tile in m_exitdir */
|
||||
inline bool CanExitOldTile()
|
||||
{
|
||||
/* road stop can be left at one direction only unless it's a drive-through stop */
|
||||
if (IsRoadTT() && IsBayRoadStopTile(m_old_tile)) {
|
||||
DiagDirection exitdir = GetBayRoadStopDir(m_old_tile);
|
||||
if (exitdir != m_exitdir) {
|
||||
m_err = EC_NO_WAY;
|
||||
if (IsRoadTT() && IsBayRoadStopTile(this->m_old_tile)) {
|
||||
DiagDirection exitdir = GetBayRoadStopDir(this->m_old_tile);
|
||||
if (exitdir != this->m_exitdir) {
|
||||
this->m_err = EC_NO_WAY;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/* single tram bits can only be left in one direction */
|
||||
if (IsTram()) {
|
||||
DiagDirection single_tram = GetSingleTramBit(m_old_tile);
|
||||
if (single_tram != INVALID_DIAGDIR && single_tram != m_exitdir) {
|
||||
m_err = EC_NO_WAY;
|
||||
if (this->IsTram()) {
|
||||
DiagDirection single_tram = GetSingleTramBit(this->m_old_tile);
|
||||
if (single_tram != INVALID_DIAGDIR && single_tram != this->m_exitdir) {
|
||||
this->m_err = EC_NO_WAY;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/* road depots can be also left in one direction only */
|
||||
if (IsRoadTT() && IsDepotTypeTile(m_old_tile, TT())) {
|
||||
DiagDirection exitdir = GetRoadDepotDirection(m_old_tile);
|
||||
if (exitdir != m_exitdir) {
|
||||
m_err = EC_NO_WAY;
|
||||
if (IsRoadTT() && IsDepotTypeTile(this->m_old_tile, TT())) {
|
||||
DiagDirection exitdir = GetRoadDepotDirection(this->m_old_tile);
|
||||
if (exitdir != this->m_exitdir) {
|
||||
this->m_err = EC_NO_WAY;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -280,88 +284,88 @@ protected:
|
|||
/** return true if we can enter m_new_tile from m_exitdir */
|
||||
inline bool CanEnterNewTile()
|
||||
{
|
||||
if (IsRoadTT() && IsBayRoadStopTile(m_new_tile)) {
|
||||
if (IsRoadTT() && IsBayRoadStopTile(this->m_new_tile)) {
|
||||
/* road stop can be entered from one direction only unless it's a drive-through stop */
|
||||
DiagDirection exitdir = GetBayRoadStopDir(m_new_tile);
|
||||
if (ReverseDiagDir(exitdir) != m_exitdir) {
|
||||
m_err = EC_NO_WAY;
|
||||
DiagDirection exitdir = GetBayRoadStopDir(this->m_new_tile);
|
||||
if (ReverseDiagDir(exitdir) != this->m_exitdir) {
|
||||
this->m_err = EC_NO_WAY;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/* single tram bits can only be entered from one direction */
|
||||
if (IsTram()) {
|
||||
DiagDirection single_tram = GetSingleTramBit(m_new_tile);
|
||||
if (single_tram != INVALID_DIAGDIR && single_tram != ReverseDiagDir(m_exitdir)) {
|
||||
m_err = EC_NO_WAY;
|
||||
if (this->IsTram()) {
|
||||
DiagDirection single_tram = this->GetSingleTramBit(this->m_new_tile);
|
||||
if (single_tram != INVALID_DIAGDIR && single_tram != ReverseDiagDir(this->m_exitdir)) {
|
||||
this->m_err = EC_NO_WAY;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/* road and rail depots can also be entered from one direction only */
|
||||
if (IsRoadTT() && IsDepotTypeTile(m_new_tile, TT())) {
|
||||
DiagDirection exitdir = GetRoadDepotDirection(m_new_tile);
|
||||
if (ReverseDiagDir(exitdir) != m_exitdir) {
|
||||
m_err = EC_NO_WAY;
|
||||
if (IsRoadTT() && IsDepotTypeTile(this->m_new_tile, TT())) {
|
||||
DiagDirection exitdir = GetRoadDepotDirection(this->m_new_tile);
|
||||
if (ReverseDiagDir(exitdir) != this->m_exitdir) {
|
||||
this->m_err = EC_NO_WAY;
|
||||
return false;
|
||||
}
|
||||
/* don't try to enter other company's depots */
|
||||
if (GetTileOwner(m_new_tile) != m_veh_owner) {
|
||||
m_err = EC_OWNER;
|
||||
if (GetTileOwner(this->m_new_tile) != this->m_veh_owner) {
|
||||
this->m_err = EC_OWNER;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (IsRailTT() && IsDepotTypeTile(m_new_tile, TT())) {
|
||||
DiagDirection exitdir = GetRailDepotDirection(m_new_tile);
|
||||
if (ReverseDiagDir(exitdir) != m_exitdir) {
|
||||
m_err = EC_NO_WAY;
|
||||
if (IsRailTT() && IsDepotTypeTile(this->m_new_tile, TT())) {
|
||||
DiagDirection exitdir = GetRailDepotDirection(this->m_new_tile);
|
||||
if (ReverseDiagDir(exitdir) != this->m_exitdir) {
|
||||
this->m_err = EC_NO_WAY;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/* rail transport is possible only on tiles with the same owner as vehicle */
|
||||
if (IsRailTT() && GetTileOwner(m_new_tile) != m_veh_owner) {
|
||||
if (IsRailTT() && GetTileOwner(this->m_new_tile) != this->m_veh_owner) {
|
||||
/* different owner */
|
||||
m_err = EC_NO_WAY;
|
||||
this->m_err = EC_NO_WAY;
|
||||
return false;
|
||||
}
|
||||
|
||||
/* rail transport is possible only on compatible rail types */
|
||||
if (IsRailTT()) {
|
||||
RailType rail_type = GetTileRailType(m_new_tile);
|
||||
if (!HasBit(m_railtypes, rail_type)) {
|
||||
RailType rail_type = GetTileRailType(this->m_new_tile);
|
||||
if (!HasBit(this->m_railtypes, rail_type)) {
|
||||
/* incompatible rail type */
|
||||
m_err = EC_RAIL_ROAD_TYPE;
|
||||
this->m_err = EC_RAIL_ROAD_TYPE;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/* road transport is possible only on compatible road types */
|
||||
if (IsRoadTT()) {
|
||||
const RoadVehicle *v = RoadVehicle::From(m_veh);
|
||||
RoadType roadtype = GetRoadType(m_new_tile, GetRoadTramType(v->roadtype));
|
||||
const RoadVehicle *v = RoadVehicle::From(this->m_veh);
|
||||
RoadType roadtype = GetRoadType(this->m_new_tile, GetRoadTramType(v->roadtype));
|
||||
if (!HasBit(v->compatible_roadtypes, roadtype)) {
|
||||
/* incompatible road type */
|
||||
m_err = EC_RAIL_ROAD_TYPE;
|
||||
this->m_err = EC_RAIL_ROAD_TYPE;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/* tunnel holes and bridge ramps can be entered only from proper direction */
|
||||
if (IsTileType(m_new_tile, MP_TUNNELBRIDGE)) {
|
||||
if (IsTunnel(m_new_tile)) {
|
||||
if (!m_is_tunnel) {
|
||||
DiagDirection tunnel_enterdir = GetTunnelBridgeDirection(m_new_tile);
|
||||
if (tunnel_enterdir != m_exitdir) {
|
||||
m_err = EC_NO_WAY;
|
||||
if (IsTileType(this->m_new_tile, MP_TUNNELBRIDGE)) {
|
||||
if (IsTunnel(this->m_new_tile)) {
|
||||
if (!this->m_is_tunnel) {
|
||||
DiagDirection tunnel_enterdir = GetTunnelBridgeDirection(this->m_new_tile);
|
||||
if (tunnel_enterdir != this->m_exitdir) {
|
||||
this->m_err = EC_NO_WAY;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} else { // IsBridge(m_new_tile)
|
||||
if (!m_is_bridge) {
|
||||
DiagDirection ramp_enderdir = GetTunnelBridgeDirection(m_new_tile);
|
||||
if (ramp_enderdir != m_exitdir) {
|
||||
m_err = EC_NO_WAY;
|
||||
if (!this->m_is_bridge) {
|
||||
DiagDirection ramp_enderdir = GetTunnelBridgeDirection(this->m_new_tile);
|
||||
if (ramp_enderdir != this->m_exitdir) {
|
||||
this->m_err = EC_NO_WAY;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -369,16 +373,16 @@ protected:
|
|||
}
|
||||
|
||||
/* special handling for rail stations - get to the end of platform */
|
||||
if (IsRailTT() && m_is_station) {
|
||||
if (IsRailTT() && this->m_is_station) {
|
||||
/* entered railway station
|
||||
* get platform length */
|
||||
uint length = BaseStation::GetByTile(m_new_tile)->GetPlatformLength(m_new_tile, TrackdirToExitdir(m_old_td));
|
||||
uint length = BaseStation::GetByTile(this->m_new_tile)->GetPlatformLength(this->m_new_tile, TrackdirToExitdir(this->m_old_td));
|
||||
/* how big step we must do to get to the last platform tile? */
|
||||
m_tiles_skipped = length - 1;
|
||||
this->m_tiles_skipped = length - 1;
|
||||
/* move to the platform end */
|
||||
TileIndexDiff diff = TileOffsByDiagDir(m_exitdir);
|
||||
diff *= m_tiles_skipped;
|
||||
m_new_tile = TileAdd(m_new_tile, diff);
|
||||
TileIndexDiff diff = TileOffsByDiagDir(this->m_exitdir);
|
||||
diff *= this->m_tiles_skipped;
|
||||
this->m_new_tile = TileAdd(this->m_new_tile, diff);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -389,28 +393,32 @@ protected:
|
|||
inline bool ForcedReverse()
|
||||
{
|
||||
/* rail and road depots cause reversing */
|
||||
if (!IsWaterTT() && IsDepotTypeTile(m_old_tile, TT())) {
|
||||
DiagDirection exitdir = IsRailTT() ? GetRailDepotDirection(m_old_tile) : GetRoadDepotDirection(m_old_tile);
|
||||
if (exitdir != m_exitdir) {
|
||||
if (!IsWaterTT() && IsDepotTypeTile(this->m_old_tile, TT())) {
|
||||
DiagDirection exitdir = IsRailTT() ? GetRailDepotDirection(this->m_old_tile) : GetRoadDepotDirection(this->m_old_tile);
|
||||
if (exitdir != this->m_exitdir) {
|
||||
/* reverse */
|
||||
m_new_tile = m_old_tile;
|
||||
m_new_td_bits = TrackdirToTrackdirBits(ReverseTrackdir(m_old_td));
|
||||
m_exitdir = exitdir;
|
||||
m_tiles_skipped = 0;
|
||||
m_is_tunnel = m_is_bridge = m_is_station = false;
|
||||
this->m_new_tile = this->m_old_tile;
|
||||
this->m_new_td_bits = TrackdirToTrackdirBits(ReverseTrackdir(this->m_old_td));
|
||||
this->m_exitdir = exitdir;
|
||||
this->m_tiles_skipped = 0;
|
||||
this->m_is_tunnel = false;
|
||||
this->m_is_bridge = false;
|
||||
this->m_is_station = false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/* Single tram bits and standard road stops cause reversing. */
|
||||
if (IsRoadTT() && ((IsTram() && GetSingleTramBit(m_old_tile) == ReverseDiagDir(m_exitdir)) ||
|
||||
(IsBayRoadStopTile(m_old_tile) && GetBayRoadStopDir(m_old_tile) == ReverseDiagDir(m_exitdir)))) {
|
||||
if (IsRoadTT() && ((this->IsTram() && GetSingleTramBit(this->m_old_tile) == ReverseDiagDir(this->m_exitdir)) ||
|
||||
(IsBayRoadStopTile(this->m_old_tile) && GetBayRoadStopDir(this->m_old_tile) == ReverseDiagDir(this->m_exitdir)))) {
|
||||
/* reverse */
|
||||
m_new_tile = m_old_tile;
|
||||
m_new_td_bits = TrackdirToTrackdirBits(ReverseTrackdir(m_old_td));
|
||||
m_exitdir = ReverseDiagDir(m_exitdir);
|
||||
m_tiles_skipped = 0;
|
||||
m_is_tunnel = m_is_bridge = m_is_station = false;
|
||||
this->m_new_tile = this->m_old_tile;
|
||||
this->m_new_td_bits = TrackdirToTrackdirBits(ReverseTrackdir(this->m_old_td));
|
||||
this->m_exitdir = ReverseDiagDir(this->m_exitdir);
|
||||
this->m_tiles_skipped = 0;
|
||||
this->m_is_tunnel = false;
|
||||
this->m_is_bridge = false;
|
||||
this->m_is_station = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -420,20 +428,20 @@ protected:
|
|||
/** return true if we successfully reversed at end of road/track */
|
||||
inline bool TryReverse()
|
||||
{
|
||||
if (IsRoadTT() && !IsTram()) {
|
||||
if (IsRoadTT() && !this->IsTram()) {
|
||||
/* if we reached the end of road, we can reverse the RV and continue moving */
|
||||
m_exitdir = ReverseDiagDir(m_exitdir);
|
||||
this->m_exitdir = ReverseDiagDir(this->m_exitdir);
|
||||
/* new tile will be the same as old one */
|
||||
m_new_tile = m_old_tile;
|
||||
this->m_new_tile = this->m_old_tile;
|
||||
/* set new trackdir bits to all reachable trackdirs */
|
||||
QueryNewTileTrackStatus();
|
||||
m_new_td_bits &= DiagdirReachesTrackdirs(m_exitdir);
|
||||
if (m_new_td_bits != TRACKDIR_BIT_NONE) {
|
||||
this->m_new_td_bits &= DiagdirReachesTrackdirs(this->m_exitdir);
|
||||
if (this->m_new_td_bits != TRACKDIR_BIT_NONE) {
|
||||
/* we have some trackdirs reachable after reversal */
|
||||
return true;
|
||||
}
|
||||
}
|
||||
m_err = EC_NO_WAY;
|
||||
this->m_err = EC_NO_WAY;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -445,19 +453,19 @@ public:
|
|||
int max_speed = INT_MAX; // no limit
|
||||
|
||||
/* Check for on-bridge speed limit */
|
||||
if (!IsWaterTT() && IsBridgeTile(m_old_tile)) {
|
||||
int spd = GetBridgeSpec(GetBridgeType(m_old_tile))->speed;
|
||||
if (!IsWaterTT() && IsBridgeTile(this->m_old_tile)) {
|
||||
int spd = GetBridgeSpec(GetBridgeType(this->m_old_tile))->speed;
|
||||
if (IsRoadTT()) spd *= 2;
|
||||
max_speed = std::min(max_speed, spd);
|
||||
}
|
||||
/* Check for speed limit imposed by railtype */
|
||||
if (IsRailTT()) {
|
||||
uint16_t rail_speed = GetRailTypeInfo(GetRailType(m_old_tile))->max_speed;
|
||||
uint16_t rail_speed = GetRailTypeInfo(GetRailType(this->m_old_tile))->max_speed;
|
||||
if (rail_speed > 0) max_speed = std::min<int>(max_speed, rail_speed);
|
||||
}
|
||||
if (IsRoadTT()) {
|
||||
/* max_speed is already in roadvehicle units, no need to further modify (divide by 2) */
|
||||
uint16_t road_speed = GetRoadTypeInfo(GetRoadType(m_old_tile, GetRoadTramType(RoadVehicle::From(m_veh)->roadtype)))->max_speed;
|
||||
uint16_t road_speed = GetRoadTypeInfo(GetRoadType(this->m_old_tile, GetRoadTramType(RoadVehicle::From(this->m_veh)->roadtype)))->max_speed;
|
||||
if (road_speed > 0) max_speed = std::min<int>(max_speed, road_speed);
|
||||
}
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ public:
|
|||
/** default constructor */
|
||||
CNodeList_HashTableT() : m_open_queue(2048)
|
||||
{
|
||||
m_new_node = nullptr;
|
||||
this->m_new_node = nullptr;
|
||||
}
|
||||
|
||||
/** destructor */
|
||||
|
@ -50,28 +50,28 @@ public:
|
|||
/** return number of open nodes */
|
||||
inline int OpenCount()
|
||||
{
|
||||
return m_open.Count();
|
||||
return this->m_open.Count();
|
||||
}
|
||||
|
||||
/** return number of closed nodes */
|
||||
inline int ClosedCount()
|
||||
{
|
||||
return m_closed.Count();
|
||||
return this->m_closed.Count();
|
||||
}
|
||||
|
||||
/** allocate new data item from m_arr */
|
||||
inline Titem_ *CreateNewNode()
|
||||
{
|
||||
if (m_new_node == nullptr) m_new_node = &m_arr.emplace_back();
|
||||
return m_new_node;
|
||||
if (this->m_new_node == nullptr) this->m_new_node = &this->m_arr.emplace_back();
|
||||
return this->m_new_node;
|
||||
}
|
||||
|
||||
/** Notify the nodelist that we don't want to discard the given node. */
|
||||
inline void FoundBestNode(Titem_ &item)
|
||||
{
|
||||
/* for now it is enough to invalidate m_new_node if it is our given node */
|
||||
if (&item == m_new_node) {
|
||||
m_new_node = nullptr;
|
||||
if (&item == this->m_new_node) {
|
||||
this->m_new_node = nullptr;
|
||||
}
|
||||
/* TODO: do we need to store best nodes found in some extra list/array? Probably not now. */
|
||||
}
|
||||
|
@ -79,19 +79,19 @@ public:
|
|||
/** insert given item as open node (into m_open and m_open_queue) */
|
||||
inline void InsertOpenNode(Titem_ &item)
|
||||
{
|
||||
assert(m_closed.Find(item.GetKey()) == nullptr);
|
||||
m_open.Push(item);
|
||||
m_open_queue.Include(&item);
|
||||
if (&item == m_new_node) {
|
||||
m_new_node = nullptr;
|
||||
assert(this->m_closed.Find(item.GetKey()) == nullptr);
|
||||
this->m_open.Push(item);
|
||||
this->m_open_queue.Include(&item);
|
||||
if (&item == this->m_new_node) {
|
||||
this->m_new_node = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
/** return the best open node */
|
||||
inline Titem_ *GetBestOpenNode()
|
||||
{
|
||||
if (!m_open_queue.IsEmpty()) {
|
||||
return m_open_queue.Begin();
|
||||
if (!this->m_open_queue.IsEmpty()) {
|
||||
return this->m_open_queue.Begin();
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -99,9 +99,9 @@ public:
|
|||
/** remove and return the best open node */
|
||||
inline Titem_ *PopBestOpenNode()
|
||||
{
|
||||
if (!m_open_queue.IsEmpty()) {
|
||||
Titem_ *item = m_open_queue.Shift();
|
||||
m_open.Pop(*item);
|
||||
if (!this->m_open_queue.IsEmpty()) {
|
||||
Titem_ *item = this->m_open_queue.Shift();
|
||||
this->m_open.Pop(*item);
|
||||
return item;
|
||||
}
|
||||
return nullptr;
|
||||
|
@ -110,49 +110,49 @@ public:
|
|||
/** return the open node specified by a key or nullptr if not found */
|
||||
inline Titem_ *FindOpenNode(const Key &key)
|
||||
{
|
||||
Titem_ *item = m_open.Find(key);
|
||||
Titem_ *item = this->m_open.Find(key);
|
||||
return item;
|
||||
}
|
||||
|
||||
/** remove and return the open node specified by a key */
|
||||
inline Titem_ &PopOpenNode(const Key &key)
|
||||
{
|
||||
Titem_ &item = m_open.Pop(key);
|
||||
size_t idxPop = m_open_queue.FindIndex(item);
|
||||
m_open_queue.Remove(idxPop);
|
||||
Titem_ &item = this->m_open.Pop(key);
|
||||
size_t idxPop = this->m_open_queue.FindIndex(item);
|
||||
this->m_open_queue.Remove(idxPop);
|
||||
return item;
|
||||
}
|
||||
|
||||
/** close node */
|
||||
inline void InsertClosedNode(Titem_ &item)
|
||||
{
|
||||
assert(m_open.Find(item.GetKey()) == nullptr);
|
||||
m_closed.Push(item);
|
||||
assert(this->m_open.Find(item.GetKey()) == nullptr);
|
||||
this->m_closed.Push(item);
|
||||
}
|
||||
|
||||
/** return the closed node specified by a key or nullptr if not found */
|
||||
inline Titem_ *FindClosedNode(const Key &key)
|
||||
{
|
||||
Titem_ *item = m_closed.Find(key);
|
||||
Titem_ *item = this->m_closed.Find(key);
|
||||
return item;
|
||||
}
|
||||
|
||||
/** The number of items. */
|
||||
inline int TotalCount()
|
||||
{
|
||||
return m_arr.Length();
|
||||
return this->m_arr.Length();
|
||||
}
|
||||
|
||||
/** Get a particular item. */
|
||||
inline Titem_ &ItemAt(int idx)
|
||||
{
|
||||
return m_arr[idx];
|
||||
return this->m_arr[idx];
|
||||
}
|
||||
|
||||
/** Helper for creating output of this array. */
|
||||
template <class D> void Dump(D &dmp) const
|
||||
{
|
||||
dmp.WriteStructT("m_arr", &m_arr);
|
||||
dmp.WriteStructT("m_arr", &this->m_arr);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -98,7 +98,7 @@ public:
|
|||
/** return current settings (can be custom - company based - but later) */
|
||||
inline const YAPFSettings &PfGetSettings() const
|
||||
{
|
||||
return *m_settings;
|
||||
return *this->m_settings;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -112,38 +112,38 @@ public:
|
|||
*/
|
||||
inline bool FindPath(const VehicleType *v)
|
||||
{
|
||||
m_veh = v;
|
||||
this->m_veh = v;
|
||||
|
||||
Yapf().PfSetStartupNodes();
|
||||
|
||||
for (;;) {
|
||||
m_num_steps++;
|
||||
Node *best_open_node = m_nodes.GetBestOpenNode();
|
||||
this->m_num_steps++;
|
||||
Node *best_open_node = this->m_nodes.GetBestOpenNode();
|
||||
if (best_open_node == nullptr) break;
|
||||
|
||||
if (Yapf().PfDetectDestination(*best_open_node)) {
|
||||
m_pBestDestNode = best_open_node;
|
||||
this->m_pBestDestNode = best_open_node;
|
||||
break;
|
||||
}
|
||||
|
||||
Yapf().PfFollowNode(*best_open_node);
|
||||
if (m_max_search_nodes != 0 && m_nodes.ClosedCount() >= m_max_search_nodes) break;
|
||||
if (this->m_max_search_nodes != 0 && this->m_nodes.ClosedCount() >= this->m_max_search_nodes) break;
|
||||
|
||||
m_nodes.PopOpenNode(best_open_node->GetKey());
|
||||
m_nodes.InsertClosedNode(*best_open_node);
|
||||
this->m_nodes.PopOpenNode(best_open_node->GetKey());
|
||||
this->m_nodes.InsertClosedNode(*best_open_node);
|
||||
}
|
||||
|
||||
const bool destination_found = (m_pBestDestNode != nullptr);
|
||||
const bool destination_found = (this->m_pBestDestNode != nullptr);
|
||||
|
||||
if (_debug_yapf_level >= 3) {
|
||||
const UnitID veh_idx = (m_veh != nullptr) ? m_veh->unitnumber : 0;
|
||||
const UnitID veh_idx = (this->m_veh != nullptr) ? this->m_veh->unitnumber : 0;
|
||||
const char ttc = Yapf().TransportTypeChar();
|
||||
const float cache_hit_ratio = (m_stats_cache_hits == 0) ? 0.0f : ((float)m_stats_cache_hits / (float)(m_stats_cache_hits + m_stats_cost_calcs) * 100.0f);
|
||||
const int cost = destination_found ? m_pBestDestNode->m_cost : -1;
|
||||
const int dist = destination_found ? m_pBestDestNode->m_estimate - m_pBestDestNode->m_cost : -1;
|
||||
const float cache_hit_ratio = (this->m_stats_cache_hits == 0) ? 0.0f : ((float)this->m_stats_cache_hits / (float)(this->m_stats_cache_hits + this->m_stats_cost_calcs) * 100.0f);
|
||||
const int cost = destination_found ? this->m_pBestDestNode->m_cost : -1;
|
||||
const int dist = destination_found ? this->m_pBestDestNode->m_estimate - this->m_pBestDestNode->m_cost : -1;
|
||||
|
||||
Debug(yapf, 3, "[YAPF{}]{}{:4d} - {} rounds - {} open - {} closed - CHR {:4.1f}% - C {} D {}",
|
||||
ttc, destination_found ? '-' : '!', veh_idx, m_num_steps, m_nodes.OpenCount(), m_nodes.ClosedCount(), cache_hit_ratio, cost, dist
|
||||
ttc, destination_found ? '-' : '!', veh_idx, this->m_num_steps, this->m_nodes.OpenCount(), this->m_nodes.ClosedCount(), cache_hit_ratio, cost, dist
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -156,7 +156,7 @@ public:
|
|||
*/
|
||||
inline Node *GetBestNode()
|
||||
{
|
||||
return (m_pBestDestNode != nullptr) ? m_pBestDestNode : m_pBestIntermediateNode;
|
||||
return (this->m_pBestDestNode != nullptr) ? this->m_pBestDestNode : this->m_pBestIntermediateNode;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -165,7 +165,7 @@ public:
|
|||
*/
|
||||
inline Node &CreateNewNode()
|
||||
{
|
||||
Node &node = *m_nodes.CreateNewNode();
|
||||
Node &node = *this->m_nodes.CreateNewNode();
|
||||
return node;
|
||||
}
|
||||
|
||||
|
@ -174,8 +174,8 @@ public:
|
|||
{
|
||||
Yapf().PfNodeCacheFetch(n);
|
||||
/* insert the new node only if it is not there */
|
||||
if (m_nodes.FindOpenNode(n.m_key) == nullptr) {
|
||||
m_nodes.InsertOpenNode(n);
|
||||
if (this->m_nodes.FindOpenNode(n.m_key) == nullptr) {
|
||||
this->m_nodes.InsertOpenNode(n);
|
||||
} else {
|
||||
/* if we are here, it means that node is already there - how it is possible?
|
||||
* probably the train is in the position that both its ends point to the same tile/exit-dir
|
||||
|
@ -222,9 +222,9 @@ public:
|
|||
/* evaluate the node */
|
||||
bool bCached = Yapf().PfNodeCacheFetch(n);
|
||||
if (!bCached) {
|
||||
m_stats_cost_calcs++;
|
||||
this->m_stats_cost_calcs++;
|
||||
} else {
|
||||
m_stats_cache_hits++;
|
||||
this->m_stats_cache_hits++;
|
||||
}
|
||||
|
||||
bool bValid = Yapf().PfCalcCost(n, &tf);
|
||||
|
@ -236,26 +236,26 @@ public:
|
|||
|
||||
/* The new node can be set as the best intermediate node only once we're
|
||||
* certain it will be finalized by being inserted into the open list. */
|
||||
bool set_intermediate = m_max_search_nodes > 0 && (m_pBestIntermediateNode == nullptr || (m_pBestIntermediateNode->GetCostEstimate() - m_pBestIntermediateNode->GetCost()) > (n.GetCostEstimate() - n.GetCost()));
|
||||
bool set_intermediate = this->m_max_search_nodes > 0 && (this->m_pBestIntermediateNode == nullptr || (this->m_pBestIntermediateNode->GetCostEstimate() - this->m_pBestIntermediateNode->GetCost()) > (n.GetCostEstimate() - n.GetCost()));
|
||||
|
||||
/* check new node against open list */
|
||||
Node *openNode = m_nodes.FindOpenNode(n.GetKey());
|
||||
Node *openNode = this->m_nodes.FindOpenNode(n.GetKey());
|
||||
if (openNode != nullptr) {
|
||||
/* another node exists with the same key in the open list
|
||||
* is it better than new one? */
|
||||
if (n.GetCostEstimate() < openNode->GetCostEstimate()) {
|
||||
/* update the old node by value from new one */
|
||||
m_nodes.PopOpenNode(n.GetKey());
|
||||
this->m_nodes.PopOpenNode(n.GetKey());
|
||||
*openNode = n;
|
||||
/* add the updated old node back to open list */
|
||||
m_nodes.InsertOpenNode(*openNode);
|
||||
if (set_intermediate) m_pBestIntermediateNode = openNode;
|
||||
this->m_nodes.InsertOpenNode(*openNode);
|
||||
if (set_intermediate) this->m_pBestIntermediateNode = openNode;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/* check new node against closed list */
|
||||
Node *closedNode = m_nodes.FindClosedNode(n.GetKey());
|
||||
Node *closedNode = this->m_nodes.FindClosedNode(n.GetKey());
|
||||
if (closedNode != nullptr) {
|
||||
/* another node exists with the same key in the closed list
|
||||
* is it better than new one? */
|
||||
|
@ -274,19 +274,19 @@ public:
|
|||
}
|
||||
/* the new node is really new
|
||||
* add it to the open list */
|
||||
m_nodes.InsertOpenNode(n);
|
||||
if (set_intermediate) m_pBestIntermediateNode = &n;
|
||||
this->m_nodes.InsertOpenNode(n);
|
||||
if (set_intermediate) this->m_pBestIntermediateNode = &n;
|
||||
}
|
||||
|
||||
const VehicleType * GetVehicle() const
|
||||
{
|
||||
return m_veh;
|
||||
return this->m_veh;
|
||||
}
|
||||
|
||||
void DumpBase(DumpTarget &dmp) const
|
||||
{
|
||||
dmp.WriteStructT("m_nodes", &m_nodes);
|
||||
dmp.WriteValue("m_num_steps", m_num_steps);
|
||||
dmp.WriteStructT("m_nodes", &this->m_nodes);
|
||||
dmp.WriteValue("m_num_steps", this->m_num_steps);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -40,18 +40,18 @@ public:
|
|||
/** Set origin tile / trackdir mask */
|
||||
void SetOrigin(TileIndex tile, TrackdirBits trackdirs)
|
||||
{
|
||||
m_orgTile = tile;
|
||||
m_orgTrackdirs = trackdirs;
|
||||
this->m_orgTile = tile;
|
||||
this->m_orgTrackdirs = trackdirs;
|
||||
}
|
||||
|
||||
/** Called when YAPF needs to place origin nodes into open list */
|
||||
void PfSetStartupNodes()
|
||||
{
|
||||
bool is_choice = (KillFirstBit(m_orgTrackdirs) != TRACKDIR_BIT_NONE);
|
||||
for (TrackdirBits tdb = m_orgTrackdirs; tdb != TRACKDIR_BIT_NONE; tdb = KillFirstBit(tdb)) {
|
||||
bool is_choice = (KillFirstBit(this->m_orgTrackdirs) != TRACKDIR_BIT_NONE);
|
||||
for (TrackdirBits tdb = this->m_orgTrackdirs; tdb != TRACKDIR_BIT_NONE; tdb = KillFirstBit(tdb)) {
|
||||
Trackdir td = (Trackdir)FindFirstBit(tdb);
|
||||
Node &n1 = Yapf().CreateNewNode();
|
||||
n1.Set(nullptr, m_orgTile, td, is_choice);
|
||||
n1.Set(nullptr, this->m_orgTile, td, is_choice);
|
||||
Yapf().AddStartupNode(n1);
|
||||
}
|
||||
}
|
||||
|
@ -84,26 +84,26 @@ 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)
|
||||
{
|
||||
m_orgTile = tile;
|
||||
m_orgTd = td;
|
||||
m_revTile = tiler;
|
||||
m_revTd = tdr;
|
||||
m_reverse_penalty = reverse_penalty;
|
||||
m_treat_first_red_two_way_signal_as_eol = treat_first_red_two_way_signal_as_eol;
|
||||
this->m_orgTile = tile;
|
||||
this->m_orgTd = td;
|
||||
this->m_revTile = tiler;
|
||||
this->m_revTd = tdr;
|
||||
this->m_reverse_penalty = reverse_penalty;
|
||||
this->m_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 */
|
||||
void PfSetStartupNodes()
|
||||
{
|
||||
if (m_orgTile != INVALID_TILE && m_orgTd != INVALID_TRACKDIR) {
|
||||
if (this->m_orgTile != INVALID_TILE && this->m_orgTd != INVALID_TRACKDIR) {
|
||||
Node &n1 = Yapf().CreateNewNode();
|
||||
n1.Set(nullptr, m_orgTile, m_orgTd, false);
|
||||
n1.Set(nullptr, this->m_orgTile, this->m_orgTd, false);
|
||||
Yapf().AddStartupNode(n1);
|
||||
}
|
||||
if (m_revTile != INVALID_TILE && m_revTd != INVALID_TRACKDIR) {
|
||||
if (this->m_revTile != INVALID_TILE && this->m_revTd != INVALID_TRACKDIR) {
|
||||
Node &n2 = Yapf().CreateNewNode();
|
||||
n2.Set(nullptr, m_revTile, m_revTd, false);
|
||||
n2.m_cost = m_reverse_penalty;
|
||||
n2.Set(nullptr, this->m_revTile, this->m_revTd, false);
|
||||
n2.m_cost = this->m_reverse_penalty;
|
||||
Yapf().AddStartupNode(n2);
|
||||
}
|
||||
}
|
||||
|
@ -111,7 +111,7 @@ public:
|
|||
/** return true if first two-way signal should be treated as dead end */
|
||||
inline bool TreatFirstRedTwoWaySignalAsEOL()
|
||||
{
|
||||
return Yapf().PfGetSettings().rail_firstred_twoway_eol && m_treat_first_red_two_way_signal_as_eol;
|
||||
return Yapf().PfGetSettings().rail_firstred_twoway_eol && this->m_treat_first_red_two_way_signal_as_eol;
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -132,8 +132,8 @@ public:
|
|||
/** set the destination tile / more trackdirs */
|
||||
void SetDestination(TileIndex tile, TrackdirBits trackdirs)
|
||||
{
|
||||
m_destTile = tile;
|
||||
m_destTrackdirs = trackdirs;
|
||||
this->m_destTile = tile;
|
||||
this->m_destTrackdirs = trackdirs;
|
||||
}
|
||||
|
||||
protected:
|
||||
|
@ -147,7 +147,7 @@ public:
|
|||
/** Called by YAPF to detect if node ends in the desired destination */
|
||||
inline bool PfDetectDestination(Node &n)
|
||||
{
|
||||
return (n.m_key.m_tile == m_destTile) && HasTrackdir(m_destTrackdirs, n.GetTrackdir());
|
||||
return (n.m_key.m_tile == this->m_destTile) && HasTrackdir(this->m_destTrackdirs, n.GetTrackdir());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -158,7 +158,7 @@ public:
|
|||
{
|
||||
static const int dg_dir_to_x_offs[] = {-1, 0, 1, 0};
|
||||
static const int dg_dir_to_y_offs[] = {0, 1, 0, -1};
|
||||
if (PfDetectDestination(n)) {
|
||||
if (this->PfDetectDestination(n)) {
|
||||
n.m_estimate = n.m_cost;
|
||||
return true;
|
||||
}
|
||||
|
@ -167,8 +167,8 @@ public:
|
|||
DiagDirection exitdir = TrackdirToExitdir(n.GetTrackdir());
|
||||
int x1 = 2 * TileX(tile) + dg_dir_to_x_offs[(int)exitdir];
|
||||
int y1 = 2 * TileY(tile) + dg_dir_to_y_offs[(int)exitdir];
|
||||
int x2 = 2 * TileX(m_destTile);
|
||||
int y2 = 2 * TileY(m_destTile);
|
||||
int x2 = 2 * TileX(this->m_destTile);
|
||||
int y2 = 2 * TileY(this->m_destTile);
|
||||
int dx = abs(x1 - x2);
|
||||
int dy = abs(y1 - y2);
|
||||
int dmin = std::min(dx, dy);
|
||||
|
|
|
@ -81,17 +81,17 @@ struct CSegmentCostCacheT : public CSegmentCostCacheBase {
|
|||
/** flush (clear) the cache */
|
||||
inline void Flush()
|
||||
{
|
||||
m_map.Clear();
|
||||
m_heap.clear();
|
||||
this->m_map.Clear();
|
||||
this->m_heap.clear();
|
||||
}
|
||||
|
||||
inline Tsegment &Get(Key &key, bool *found)
|
||||
{
|
||||
Tsegment *item = m_map.Find(key);
|
||||
Tsegment *item = this->m_map.Find(key);
|
||||
if (item == nullptr) {
|
||||
*found = false;
|
||||
item = &m_heap.emplace_back(key);
|
||||
m_map.Push(*item);
|
||||
this->m_map.Push(*item);
|
||||
} else {
|
||||
*found = true;
|
||||
}
|
||||
|
@ -150,12 +150,12 @@ public:
|
|||
CacheKey key(n.GetKey());
|
||||
|
||||
if (!Yapf().CanUseGlobalCache(n)) {
|
||||
Yapf().ConnectNodeToCachedData(n, m_local_cache.emplace_back(key));
|
||||
Yapf().ConnectNodeToCachedData(n, this->m_local_cache.emplace_back(key));
|
||||
return false;
|
||||
}
|
||||
|
||||
bool found;
|
||||
CachedData &item = m_global_cache.Get(key, &found);
|
||||
CachedData &item = this->m_global_cache.Get(key, &found);
|
||||
Yapf().ConnectNodeToCachedData(n, item);
|
||||
return found;
|
||||
}
|
||||
|
|
|
@ -61,10 +61,10 @@ protected:
|
|||
int p0 = Yapf().PfGetSettings().rail_look_ahead_signal_p0;
|
||||
int p1 = Yapf().PfGetSettings().rail_look_ahead_signal_p1;
|
||||
int p2 = Yapf().PfGetSettings().rail_look_ahead_signal_p2;
|
||||
m_sig_look_ahead_costs.clear();
|
||||
m_sig_look_ahead_costs.reserve(Yapf().PfGetSettings().rail_look_ahead_max_signals);
|
||||
this->m_sig_look_ahead_costs.clear();
|
||||
this->m_sig_look_ahead_costs.reserve(Yapf().PfGetSettings().rail_look_ahead_max_signals);
|
||||
for (uint i = 0; i < Yapf().PfGetSettings().rail_look_ahead_max_signals; i++) {
|
||||
m_sig_look_ahead_costs.push_back(p0 + i * (p1 + i * p2));
|
||||
this->m_sig_look_ahead_costs.push_back(p0 + i * (p1 + i * p2));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -145,7 +145,7 @@ public:
|
|||
/** The cost for reserved tiles, including skipped ones. */
|
||||
inline int ReservationCost(Node &n, TileIndex tile, Trackdir trackdir, int skipped)
|
||||
{
|
||||
if (n.m_num_signals_passed >= m_sig_look_ahead_costs.size() / 2) return 0;
|
||||
if (n.m_num_signals_passed >= this->m_sig_look_ahead_costs.size() / 2) return 0;
|
||||
if (!IsPbsSignal(n.m_last_signal_type)) return 0;
|
||||
|
||||
if (IsRailStationTile(tile) && IsAnyStationTileReserved(tile, trackdir, skipped)) {
|
||||
|
@ -176,7 +176,7 @@ public:
|
|||
n.m_last_signal_type = sig_type;
|
||||
|
||||
/* cache the look-ahead polynomial constant only if we didn't pass more signals than the look-ahead limit is */
|
||||
int look_ahead_cost = (n.m_num_signals_passed < m_sig_look_ahead_costs.size()) ? m_sig_look_ahead_costs[n.m_num_signals_passed] : 0;
|
||||
int look_ahead_cost = (n.m_num_signals_passed < this->m_sig_look_ahead_costs.size()) ? this->m_sig_look_ahead_costs[n.m_num_signals_passed] : 0;
|
||||
if (sig_state != SIGNAL_STATE_RED) {
|
||||
/* green signal */
|
||||
n.flags_u.flags_s.m_last_signal_was_red = false;
|
||||
|
@ -250,7 +250,7 @@ public:
|
|||
public:
|
||||
inline void SetMaxCost(int max_cost)
|
||||
{
|
||||
m_max_cost = max_cost;
|
||||
this->m_max_cost = max_cost;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -450,7 +450,7 @@ no_entry_cost: // jump here at the beginning if the node has no parent (it is th
|
|||
|
||||
/* Apply min/max speed penalties only when inside the look-ahead radius. Otherwise
|
||||
* it would cause desync in MP. */
|
||||
if (n.m_num_signals_passed < m_sig_look_ahead_costs.size())
|
||||
if (n.m_num_signals_passed < this->m_sig_look_ahead_costs.size())
|
||||
{
|
||||
int min_speed = 0;
|
||||
int max_speed = tf->GetSpeedLimit(&min_speed);
|
||||
|
@ -465,7 +465,7 @@ no_entry_cost: // jump here at the beginning if the node has no parent (it is th
|
|||
|
||||
/* Finish if we already exceeded the maximum path cost (i.e. when
|
||||
* searching for the nearest depot). */
|
||||
if (m_max_cost > 0 && (parent_cost + segment_entry_cost + segment_cost) > m_max_cost) {
|
||||
if (this->m_max_cost > 0 && (parent_cost + segment_entry_cost + segment_cost) > this->m_max_cost) {
|
||||
end_segment_reason |= ESRB_PATH_TOO_LONG;
|
||||
}
|
||||
|
||||
|
@ -603,9 +603,9 @@ no_entry_cost: // jump here at the beginning if the node has no parent (it is th
|
|||
|
||||
inline bool CanUseGlobalCache(Node &n) const
|
||||
{
|
||||
return !m_disable_cache
|
||||
return !this->m_disable_cache
|
||||
&& (n.m_parent != nullptr)
|
||||
&& (n.m_parent->m_num_signals_passed >= m_sig_look_ahead_costs.size());
|
||||
&& (n.m_parent->m_num_signals_passed >= this->m_sig_look_ahead_costs.size());
|
||||
}
|
||||
|
||||
inline void ConnectNodeToCachedData(Node &n, CachedData &ci)
|
||||
|
@ -619,7 +619,7 @@ no_entry_cost: // jump here at the beginning if the node has no parent (it is th
|
|||
|
||||
void DisableCache(bool disable)
|
||||
{
|
||||
m_disable_cache = disable;
|
||||
this->m_disable_cache = disable;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -21,18 +21,18 @@ protected:
|
|||
public:
|
||||
void SetDestination(const Train *v, bool override_rail_type = false)
|
||||
{
|
||||
m_compatible_railtypes = v->compatible_railtypes;
|
||||
if (override_rail_type) m_compatible_railtypes |= GetRailTypeInfo(v->railtype)->compatible_railtypes;
|
||||
this->m_compatible_railtypes = v->compatible_railtypes;
|
||||
if (override_rail_type) this->m_compatible_railtypes |= GetRailTypeInfo(v->railtype)->compatible_railtypes;
|
||||
}
|
||||
|
||||
bool IsCompatibleRailType(RailType rt)
|
||||
{
|
||||
return HasBit(m_compatible_railtypes, rt);
|
||||
return HasBit(this->m_compatible_railtypes, rt);
|
||||
}
|
||||
|
||||
RailTypes GetCompatibleRailTypes() const
|
||||
{
|
||||
return m_compatible_railtypes;
|
||||
return this->m_compatible_railtypes;
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -52,7 +52,7 @@ public:
|
|||
/** Called by YAPF to detect if node ends in the desired destination */
|
||||
inline bool PfDetectDestination(Node &n)
|
||||
{
|
||||
return PfDetectDestination(n.GetLastTile(), n.GetLastTrackdir());
|
||||
return this->PfDetectDestination(n.GetLastTile(), n.GetLastTrackdir());
|
||||
}
|
||||
|
||||
/** Called by YAPF to detect if node ends in the desired destination */
|
||||
|
@ -90,7 +90,7 @@ public:
|
|||
/** Called by YAPF to detect if node ends in the desired destination */
|
||||
inline bool PfDetectDestination(Node &n)
|
||||
{
|
||||
return PfDetectDestination(n.GetLastTile(), n.GetLastTrackdir());
|
||||
return this->PfDetectDestination(n.GetLastTile(), n.GetLastTrackdir());
|
||||
}
|
||||
|
||||
/** Called by YAPF to detect if node ends in the desired destination */
|
||||
|
@ -133,7 +133,7 @@ protected:
|
|||
public:
|
||||
void SetDestination(const Train *v)
|
||||
{
|
||||
m_any_depot = false;
|
||||
this->m_any_depot = false;
|
||||
switch (v->current_order.GetType()) {
|
||||
case OT_GOTO_WAYPOINT:
|
||||
if (!Waypoint::Get(v->current_order.GetDestination())->IsSingleTile()) {
|
||||
|
@ -147,46 +147,46 @@ public:
|
|||
[[fallthrough]];
|
||||
|
||||
case OT_GOTO_STATION:
|
||||
m_destTile = CalcClosestStationTile(v->current_order.GetDestination(), v->tile, v->current_order.IsType(OT_GOTO_STATION) ? STATION_RAIL : STATION_WAYPOINT);
|
||||
m_dest_station_id = v->current_order.GetDestination();
|
||||
m_destTrackdirs = INVALID_TRACKDIR_BIT;
|
||||
this->m_destTile = CalcClosestStationTile(v->current_order.GetDestination(), v->tile, v->current_order.IsType(OT_GOTO_STATION) ? STATION_RAIL : STATION_WAYPOINT);
|
||||
this->m_dest_station_id = v->current_order.GetDestination();
|
||||
this->m_destTrackdirs = INVALID_TRACKDIR_BIT;
|
||||
break;
|
||||
|
||||
case OT_GOTO_DEPOT:
|
||||
if (v->current_order.GetDepotActionType() & ODATFB_NEAREST_DEPOT) {
|
||||
m_any_depot = true;
|
||||
this->m_any_depot = true;
|
||||
}
|
||||
[[fallthrough]];
|
||||
|
||||
default:
|
||||
m_destTile = v->dest_tile;
|
||||
m_dest_station_id = INVALID_STATION;
|
||||
m_destTrackdirs = TrackStatusToTrackdirBits(GetTileTrackStatus(v->dest_tile, TRANSPORT_RAIL, 0));
|
||||
this->m_destTile = v->dest_tile;
|
||||
this->m_dest_station_id = INVALID_STATION;
|
||||
this->m_destTrackdirs = TrackStatusToTrackdirBits(GetTileTrackStatus(v->dest_tile, TRANSPORT_RAIL, 0));
|
||||
break;
|
||||
}
|
||||
CYapfDestinationRailBase::SetDestination(v);
|
||||
this->CYapfDestinationRailBase::SetDestination(v);
|
||||
}
|
||||
|
||||
/** Called by YAPF to detect if node ends in the desired destination */
|
||||
inline bool PfDetectDestination(Node &n)
|
||||
{
|
||||
return PfDetectDestination(n.GetLastTile(), n.GetLastTrackdir());
|
||||
return this->PfDetectDestination(n.GetLastTile(), n.GetLastTrackdir());
|
||||
}
|
||||
|
||||
/** Called by YAPF to detect if node ends in the desired destination */
|
||||
inline bool PfDetectDestination(TileIndex tile, Trackdir td)
|
||||
{
|
||||
if (m_dest_station_id != INVALID_STATION) {
|
||||
if (this->m_dest_station_id != INVALID_STATION) {
|
||||
return HasStationTileRail(tile)
|
||||
&& (GetStationIndex(tile) == m_dest_station_id)
|
||||
&& (GetStationIndex(tile) == this->m_dest_station_id)
|
||||
&& (GetRailStationTrack(tile) == TrackdirToTrack(td));
|
||||
}
|
||||
|
||||
if (m_any_depot) {
|
||||
if (this->m_any_depot) {
|
||||
return IsRailDepotTile(tile);
|
||||
}
|
||||
|
||||
return (tile == m_destTile) && HasTrackdir(m_destTrackdirs, td);
|
||||
return (tile == this->m_destTile) && HasTrackdir(this->m_destTrackdirs, td);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -197,7 +197,7 @@ public:
|
|||
{
|
||||
static const int dg_dir_to_x_offs[] = {-1, 0, 1, 0};
|
||||
static const int dg_dir_to_y_offs[] = {0, 1, 0, -1};
|
||||
if (PfDetectDestination(n)) {
|
||||
if (this->PfDetectDestination(n)) {
|
||||
n.m_estimate = n.m_cost;
|
||||
return true;
|
||||
}
|
||||
|
@ -206,8 +206,8 @@ public:
|
|||
DiagDirection exitdir = TrackdirToExitdir(n.GetLastTrackdir());
|
||||
int x1 = 2 * TileX(tile) + dg_dir_to_x_offs[(int)exitdir];
|
||||
int y1 = 2 * TileY(tile) + dg_dir_to_y_offs[(int)exitdir];
|
||||
int x2 = 2 * TileX(m_destTile);
|
||||
int y2 = 2 * TileY(m_destTile);
|
||||
int x2 = 2 * TileX(this->m_destTile);
|
||||
int y2 = 2 * TileY(this->m_destTile);
|
||||
int dx = abs(x1 - x2);
|
||||
int dy = abs(y1 - y2);
|
||||
int dmin = std::min(dx, dy);
|
||||
|
|
|
@ -21,26 +21,26 @@ struct CYapfNodeKeyExitDir {
|
|||
|
||||
inline void Set(TileIndex tile, Trackdir td)
|
||||
{
|
||||
m_tile = tile;
|
||||
m_td = td;
|
||||
m_exitdir = (m_td == INVALID_TRACKDIR) ? INVALID_DIAGDIR : TrackdirToExitdir(m_td);
|
||||
this->m_tile = tile;
|
||||
this->m_td = td;
|
||||
this->m_exitdir = (this->m_td == INVALID_TRACKDIR) ? INVALID_DIAGDIR : TrackdirToExitdir(this->m_td);
|
||||
}
|
||||
|
||||
inline int CalcHash() const
|
||||
{
|
||||
return m_exitdir | (m_tile.base() << 2);
|
||||
return this->m_exitdir | (this->m_tile.base() << 2);
|
||||
}
|
||||
|
||||
inline bool operator==(const CYapfNodeKeyExitDir &other) const
|
||||
{
|
||||
return m_tile == other.m_tile && m_exitdir == other.m_exitdir;
|
||||
return this->m_tile == other.m_tile && this->m_exitdir == other.m_exitdir;
|
||||
}
|
||||
|
||||
void Dump(DumpTarget &dmp) const
|
||||
{
|
||||
dmp.WriteTile("m_tile", m_tile);
|
||||
dmp.WriteEnumT("m_td", m_td);
|
||||
dmp.WriteEnumT("m_exitdir", m_exitdir);
|
||||
dmp.WriteTile("m_tile", this->m_tile);
|
||||
dmp.WriteEnumT("m_td", this->m_td);
|
||||
dmp.WriteEnumT("m_exitdir", this->m_exitdir);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -48,12 +48,12 @@ struct CYapfNodeKeyTrackDir : public CYapfNodeKeyExitDir
|
|||
{
|
||||
inline int CalcHash() const
|
||||
{
|
||||
return m_td | (m_tile.base() << 4);
|
||||
return this->m_td | (this->m_tile.base() << 4);
|
||||
}
|
||||
|
||||
inline bool operator==(const CYapfNodeKeyTrackDir &other) const
|
||||
{
|
||||
return m_tile == other.m_tile && m_td == other.m_td;
|
||||
return this->m_tile == other.m_tile && this->m_td == other.m_td;
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -72,65 +72,65 @@ struct CYapfNodeT {
|
|||
|
||||
inline void Set(Node *parent, TileIndex tile, Trackdir td, bool is_choice)
|
||||
{
|
||||
m_key.Set(tile, td);
|
||||
m_hash_next = nullptr;
|
||||
m_parent = parent;
|
||||
m_cost = 0;
|
||||
m_estimate = 0;
|
||||
m_is_choice = is_choice;
|
||||
this->m_key.Set(tile, td);
|
||||
this->m_hash_next = nullptr;
|
||||
this->m_parent = parent;
|
||||
this->m_cost = 0;
|
||||
this->m_estimate = 0;
|
||||
this->m_is_choice = is_choice;
|
||||
}
|
||||
|
||||
inline Node *GetHashNext()
|
||||
{
|
||||
return m_hash_next;
|
||||
return this->m_hash_next;
|
||||
}
|
||||
|
||||
inline void SetHashNext(Node *pNext)
|
||||
{
|
||||
m_hash_next = pNext;
|
||||
this->m_hash_next = pNext;
|
||||
}
|
||||
|
||||
inline TileIndex GetTile() const
|
||||
{
|
||||
return m_key.m_tile;
|
||||
return this->m_key.m_tile;
|
||||
}
|
||||
|
||||
inline Trackdir GetTrackdir() const
|
||||
{
|
||||
return m_key.m_td;
|
||||
return this->m_key.m_td;
|
||||
}
|
||||
|
||||
inline const Tkey_ &GetKey() const
|
||||
{
|
||||
return m_key;
|
||||
return this->m_key;
|
||||
}
|
||||
|
||||
inline int GetCost() const
|
||||
{
|
||||
return m_cost;
|
||||
return this->m_cost;
|
||||
}
|
||||
|
||||
inline int GetCostEstimate() const
|
||||
{
|
||||
return m_estimate;
|
||||
return this->m_estimate;
|
||||
}
|
||||
|
||||
inline bool GetIsChoice() const
|
||||
{
|
||||
return m_is_choice;
|
||||
return this->m_is_choice;
|
||||
}
|
||||
|
||||
inline bool operator<(const Node &other) const
|
||||
{
|
||||
return m_estimate < other.m_estimate;
|
||||
return this->m_estimate < other.m_estimate;
|
||||
}
|
||||
|
||||
void Dump(DumpTarget &dmp) const
|
||||
{
|
||||
dmp.WriteStructT("m_key", &m_key);
|
||||
dmp.WriteStructT("m_parent", m_parent);
|
||||
dmp.WriteValue("m_cost", m_cost);
|
||||
dmp.WriteValue("m_estimate", m_estimate);
|
||||
dmp.WriteStructT("m_key", &this->m_key);
|
||||
dmp.WriteStructT("m_parent", this->m_parent);
|
||||
dmp.WriteValue("m_cost", this->m_cost);
|
||||
dmp.WriteValue("m_estimate", this->m_estimate);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -23,43 +23,43 @@ struct CYapfRailSegmentKey
|
|||
|
||||
inline CYapfRailSegmentKey(const CYapfNodeKeyTrackDir &node_key)
|
||||
{
|
||||
Set(node_key);
|
||||
this->Set(node_key);
|
||||
}
|
||||
|
||||
inline void Set(const CYapfRailSegmentKey &src)
|
||||
{
|
||||
m_value = src.m_value;
|
||||
this->m_value = src.m_value;
|
||||
}
|
||||
|
||||
inline void Set(const CYapfNodeKeyTrackDir &node_key)
|
||||
{
|
||||
m_value = (node_key.m_tile.base() << 4) | node_key.m_td;
|
||||
this->m_value = (node_key.m_tile.base() << 4) | node_key.m_td;
|
||||
}
|
||||
|
||||
inline int32_t CalcHash() const
|
||||
{
|
||||
return m_value;
|
||||
return this->m_value;
|
||||
}
|
||||
|
||||
inline TileIndex GetTile() const
|
||||
{
|
||||
return (TileIndex)(m_value >> 4);
|
||||
return (TileIndex)(this->m_value >> 4);
|
||||
}
|
||||
|
||||
inline Trackdir GetTrackdir() const
|
||||
{
|
||||
return (Trackdir)(m_value & 0x0F);
|
||||
return (Trackdir)(this->m_value & 0x0F);
|
||||
}
|
||||
|
||||
inline bool operator==(const CYapfRailSegmentKey &other) const
|
||||
{
|
||||
return m_value == other.m_value;
|
||||
return this->m_value == other.m_value;
|
||||
}
|
||||
|
||||
void Dump(DumpTarget &dmp) const
|
||||
{
|
||||
dmp.WriteTile("tile", GetTile());
|
||||
dmp.WriteEnumT("td", GetTrackdir());
|
||||
dmp.WriteTile("tile", this->GetTile());
|
||||
dmp.WriteEnumT("td", this->GetTrackdir());
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -90,33 +90,33 @@ struct CYapfRailSegment
|
|||
|
||||
inline const Key &GetKey() const
|
||||
{
|
||||
return m_key;
|
||||
return this->m_key;
|
||||
}
|
||||
|
||||
inline TileIndex GetTile() const
|
||||
{
|
||||
return m_key.GetTile();
|
||||
return this->m_key.GetTile();
|
||||
}
|
||||
|
||||
inline CYapfRailSegment *GetHashNext()
|
||||
{
|
||||
return m_hash_next;
|
||||
return this->m_hash_next;
|
||||
}
|
||||
|
||||
inline void SetHashNext(CYapfRailSegment *next)
|
||||
{
|
||||
m_hash_next = next;
|
||||
this->m_hash_next = next;
|
||||
}
|
||||
|
||||
void Dump(DumpTarget &dmp) const
|
||||
{
|
||||
dmp.WriteStructT("m_key", &m_key);
|
||||
dmp.WriteTile("m_last_tile", m_last_tile);
|
||||
dmp.WriteEnumT("m_last_td", m_last_td);
|
||||
dmp.WriteValue("m_cost", m_cost);
|
||||
dmp.WriteTile("m_last_signal_tile", m_last_signal_tile);
|
||||
dmp.WriteEnumT("m_last_signal_td", m_last_signal_td);
|
||||
dmp.WriteEnumT("m_end_segment_reason", m_end_segment_reason);
|
||||
dmp.WriteStructT("m_key", &this->m_key);
|
||||
dmp.WriteTile("m_last_tile", this->m_last_tile);
|
||||
dmp.WriteEnumT("m_last_td", this->m_last_td);
|
||||
dmp.WriteValue("m_cost", this->m_cost);
|
||||
dmp.WriteTile("m_last_signal_tile", this->m_last_signal_tile);
|
||||
dmp.WriteEnumT("m_last_signal_td", this->m_last_signal_td);
|
||||
dmp.WriteEnumT("m_end_segment_reason", this->m_end_segment_reason);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -143,12 +143,12 @@ struct CYapfRailNodeT
|
|||
|
||||
inline void Set(CYapfRailNodeT *parent, TileIndex tile, Trackdir td, bool is_choice)
|
||||
{
|
||||
base::Set(parent, tile, td, is_choice);
|
||||
m_segment = nullptr;
|
||||
this->base::Set(parent, tile, td, is_choice);
|
||||
this->m_segment = nullptr;
|
||||
if (parent == nullptr) {
|
||||
m_num_signals_passed = 0;
|
||||
flags_u.m_inherited_flags = 0;
|
||||
m_last_red_signal_type = SIGTYPE_BLOCK;
|
||||
this->m_num_signals_passed = 0;
|
||||
this->flags_u.m_inherited_flags = 0;
|
||||
this->m_last_red_signal_type = SIGTYPE_BLOCK;
|
||||
/* We use PBS as initial signal type because if we are in
|
||||
* a PBS section and need to route, i.e. we're at a safe
|
||||
* waiting point of a station, we need to account for the
|
||||
|
@ -159,43 +159,43 @@ struct CYapfRailNodeT
|
|||
* then avoiding that train with help of the reservation
|
||||
* costs is not a bad thing, actually it would probably
|
||||
* be a good thing to do. */
|
||||
m_last_signal_type = SIGTYPE_PBS;
|
||||
this->m_last_signal_type = SIGTYPE_PBS;
|
||||
} else {
|
||||
m_num_signals_passed = parent->m_num_signals_passed;
|
||||
flags_u.m_inherited_flags = parent->flags_u.m_inherited_flags;
|
||||
m_last_red_signal_type = parent->m_last_red_signal_type;
|
||||
m_last_signal_type = parent->m_last_signal_type;
|
||||
this->m_num_signals_passed = parent->m_num_signals_passed;
|
||||
this->flags_u.m_inherited_flags = parent->flags_u.m_inherited_flags;
|
||||
this->m_last_red_signal_type = parent->m_last_red_signal_type;
|
||||
this->m_last_signal_type = parent->m_last_signal_type;
|
||||
}
|
||||
flags_u.flags_s.m_choice_seen |= is_choice;
|
||||
this->flags_u.flags_s.m_choice_seen |= is_choice;
|
||||
}
|
||||
|
||||
inline TileIndex GetLastTile() const
|
||||
{
|
||||
assert(m_segment != nullptr);
|
||||
return m_segment->m_last_tile;
|
||||
assert(this->m_segment != nullptr);
|
||||
return this->m_segment->m_last_tile;
|
||||
}
|
||||
|
||||
inline Trackdir GetLastTrackdir() const
|
||||
{
|
||||
assert(m_segment != nullptr);
|
||||
return m_segment->m_last_td;
|
||||
assert(this->m_segment != nullptr);
|
||||
return this->m_segment->m_last_td;
|
||||
}
|
||||
|
||||
inline void SetLastTileTrackdir(TileIndex tile, Trackdir td)
|
||||
{
|
||||
assert(m_segment != nullptr);
|
||||
m_segment->m_last_tile = tile;
|
||||
m_segment->m_last_td = td;
|
||||
assert(this->m_segment != nullptr);
|
||||
this->m_segment->m_last_tile = tile;
|
||||
this->m_segment->m_last_td = td;
|
||||
}
|
||||
|
||||
template <class Tbase, class Tfunc, class Tpf>
|
||||
bool IterateTiles(const Train *v, Tpf &yapf, Tbase &obj, bool (Tfunc::*func)(TileIndex, Trackdir)) const
|
||||
{
|
||||
typename Tbase::TrackFollower ft(v, yapf.GetCompatibleRailTypes());
|
||||
TileIndex cur = base::GetTile();
|
||||
Trackdir cur_td = base::GetTrackdir();
|
||||
TileIndex cur = this->base::GetTile();
|
||||
Trackdir cur_td = this->base::GetTrackdir();
|
||||
|
||||
while (cur != GetLastTile() || cur_td != GetLastTrackdir()) {
|
||||
while (cur != this->GetLastTile() || cur_td != this->GetLastTrackdir()) {
|
||||
if (!((obj.*func)(cur, cur_td))) return false;
|
||||
|
||||
if (!ft.Follow(cur, cur_td)) break;
|
||||
|
@ -209,13 +209,13 @@ struct CYapfRailNodeT
|
|||
|
||||
void Dump(DumpTarget &dmp) const
|
||||
{
|
||||
base::Dump(dmp);
|
||||
dmp.WriteStructT("m_segment", m_segment);
|
||||
dmp.WriteValue("m_num_signals_passed", m_num_signals_passed);
|
||||
dmp.WriteValue("m_targed_seen", flags_u.flags_s.m_targed_seen ? "Yes" : "No");
|
||||
dmp.WriteValue("m_choice_seen", flags_u.flags_s.m_choice_seen ? "Yes" : "No");
|
||||
dmp.WriteValue("m_last_signal_was_red", flags_u.flags_s.m_last_signal_was_red ? "Yes" : "No");
|
||||
dmp.WriteEnumT("m_last_red_signal_type", m_last_red_signal_type);
|
||||
this->base::Dump(dmp);
|
||||
dmp.WriteStructT("m_segment", this->m_segment);
|
||||
dmp.WriteValue("m_num_signals_passed", this->m_num_signals_passed);
|
||||
dmp.WriteValue("m_targed_seen", this->flags_u.flags_s.m_targed_seen ? "Yes" : "No");
|
||||
dmp.WriteValue("m_choice_seen", this->flags_u.flags_s.m_choice_seen ? "Yes" : "No");
|
||||
dmp.WriteValue("m_last_signal_was_red", this->flags_u.flags_s.m_last_signal_was_red ? "Yes" : "No");
|
||||
dmp.WriteEnumT("m_last_red_signal_type", this->m_last_red_signal_type);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -25,9 +25,9 @@ struct CYapfRoadNodeT : CYapfNodeT<Tkey_, CYapfRoadNodeT<Tkey_> > {
|
|||
|
||||
void Set(CYapfRoadNodeT *parent, TileIndex tile, Trackdir td, bool is_choice)
|
||||
{
|
||||
base::Set(parent, tile, td, is_choice);
|
||||
m_segment_last_tile = tile;
|
||||
m_segment_last_td = td;
|
||||
this->base::Set(parent, tile, td, is_choice);
|
||||
this->m_segment_last_tile = tile;
|
||||
this->m_segment_last_td = td;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -25,9 +25,9 @@ struct CYapfShipNodeT : CYapfNodeT<Tkey_, CYapfShipNodeT<Tkey_> > {
|
|||
|
||||
void Set(CYapfShipNodeT *parent, TileIndex tile, Trackdir td, bool is_choice)
|
||||
{
|
||||
base::Set(parent, tile, td, is_choice);
|
||||
m_segment_last_tile = tile;
|
||||
m_segment_last_td = td;
|
||||
this->base::Set(parent, tile, td, is_choice);
|
||||
this->m_segment_last_tile = tile;
|
||||
this->m_segment_last_td = td;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -60,8 +60,8 @@ private:
|
|||
bool FindSafePositionProc(TileIndex tile, Trackdir td)
|
||||
{
|
||||
if (IsSafeWaitingPosition(Yapf().GetVehicle(), tile, td, true, !TrackFollower::Allow90degTurns())) {
|
||||
m_res_dest = tile;
|
||||
m_res_dest_td = td;
|
||||
this->m_res_dest = tile;
|
||||
this->m_res_dest_td = td;
|
||||
return false; // Stop iterating segment
|
||||
}
|
||||
return true;
|
||||
|
@ -78,7 +78,7 @@ private:
|
|||
SetRailStationReservation(tile, true);
|
||||
MarkTileDirtyByTile(tile);
|
||||
tile = TileAdd(tile, diff);
|
||||
} while (IsCompatibleTrainStationTile(tile, start) && tile != m_origin_tile);
|
||||
} while (IsCompatibleTrainStationTile(tile, start) && tile != this->m_origin_tile);
|
||||
|
||||
TriggerStationRandomisation(nullptr, start, SRT_PATH_RESERVATION);
|
||||
|
||||
|
@ -92,26 +92,26 @@ private:
|
|||
if (IsRailStationTile(tile)) {
|
||||
if (!ReserveRailStationPlatform(tile, TrackdirToExitdir(rev_td))) {
|
||||
/* Platform could not be reserved, undo. */
|
||||
m_res_fail_tile = tile;
|
||||
m_res_fail_td = td;
|
||||
this->m_res_fail_tile = tile;
|
||||
this->m_res_fail_td = td;
|
||||
}
|
||||
} else {
|
||||
if (!TryReserveRailTrack(tile, TrackdirToTrack(td))) {
|
||||
/* Tile couldn't be reserved, undo. */
|
||||
m_res_fail_tile = tile;
|
||||
m_res_fail_td = td;
|
||||
this->m_res_fail_tile = tile;
|
||||
this->m_res_fail_td = td;
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Green path signal opposing the path? Turn to red. */
|
||||
if (HasPbsSignalOnTrackdir(tile, rev_td) && GetSignalStateByTrackdir(tile, rev_td) == SIGNAL_STATE_GREEN) {
|
||||
m_signals_set_to_red.emplace_back(tile, rev_td);
|
||||
this->m_signals_set_to_red.emplace_back(tile, rev_td);
|
||||
SetSignalStateByTrackdir(tile, rev_td, SIGNAL_STATE_RED);
|
||||
MarkTileDirtyByTile(tile);
|
||||
}
|
||||
}
|
||||
|
||||
return tile != m_res_dest || td != m_res_dest_td;
|
||||
return tile != this->m_res_dest || td != this->m_res_dest_td;
|
||||
}
|
||||
|
||||
/** Unreserve a single track/platform. Stops when the previous failer is reached. */
|
||||
|
@ -120,23 +120,23 @@ private:
|
|||
if (IsRailStationTile(tile)) {
|
||||
TileIndex start = tile;
|
||||
TileIndexDiff diff = TileOffsByDiagDir(TrackdirToExitdir(ReverseTrackdir(td)));
|
||||
while ((tile != m_res_fail_tile || td != m_res_fail_td) && IsCompatibleTrainStationTile(tile, start)) {
|
||||
while ((tile != this->m_res_fail_tile || td != this->m_res_fail_td) && IsCompatibleTrainStationTile(tile, start)) {
|
||||
SetRailStationReservation(tile, false);
|
||||
tile = TileAdd(tile, diff);
|
||||
}
|
||||
} else if (tile != m_res_fail_tile || td != m_res_fail_td) {
|
||||
} else if (tile != this->m_res_fail_tile || td != this->m_res_fail_td) {
|
||||
UnreserveRailTrack(tile, TrackdirToTrack(td));
|
||||
}
|
||||
return (tile != m_res_dest || td != m_res_dest_td) && (tile != m_res_fail_tile || td != m_res_fail_td);
|
||||
return (tile != this->m_res_dest || td != this->m_res_dest_td) && (tile != this->m_res_fail_tile || td != this->m_res_fail_td);
|
||||
}
|
||||
|
||||
public:
|
||||
/** Set the target to where the reservation should be extended. */
|
||||
inline void SetReservationTarget(Node *node, TileIndex tile, Trackdir td)
|
||||
{
|
||||
m_res_node = node;
|
||||
m_res_dest = tile;
|
||||
m_res_dest_td = td;
|
||||
this->m_res_node = node;
|
||||
this->m_res_dest = tile;
|
||||
this->m_res_dest_td = td;
|
||||
}
|
||||
|
||||
/** Check the node for a possible reservation target. */
|
||||
|
@ -148,40 +148,40 @@ public:
|
|||
if (node->m_parent->m_num_signals_passed >= 2) return;
|
||||
|
||||
if (!node->IterateTiles(Yapf().GetVehicle(), Yapf(), *this, &CYapfReserveTrack<Types>::FindSafePositionProc)) {
|
||||
m_res_node = node;
|
||||
this->m_res_node = node;
|
||||
}
|
||||
}
|
||||
|
||||
/** Try to reserve the path till the reservation target. */
|
||||
bool TryReservePath(PBSTileInfo *target, TileIndex origin)
|
||||
{
|
||||
m_res_fail_tile = INVALID_TILE;
|
||||
m_origin_tile = origin;
|
||||
this->m_res_fail_tile = INVALID_TILE;
|
||||
this->m_origin_tile = origin;
|
||||
|
||||
if (target != nullptr) {
|
||||
target->tile = m_res_dest;
|
||||
target->trackdir = m_res_dest_td;
|
||||
target->tile = this->m_res_dest;
|
||||
target->trackdir = this->m_res_dest_td;
|
||||
target->okay = false;
|
||||
}
|
||||
|
||||
/* Don't bother if the target is reserved. */
|
||||
if (!IsWaitingPositionFree(Yapf().GetVehicle(), m_res_dest, m_res_dest_td)) return false;
|
||||
if (!IsWaitingPositionFree(Yapf().GetVehicle(), this->m_res_dest, this->m_res_dest_td)) return false;
|
||||
|
||||
m_signals_set_to_red.clear();
|
||||
for (Node *node = m_res_node; node->m_parent != nullptr; node = node->m_parent) {
|
||||
this->m_signals_set_to_red.clear();
|
||||
for (Node *node = this->m_res_node; node->m_parent != nullptr; node = node->m_parent) {
|
||||
node->IterateTiles(Yapf().GetVehicle(), Yapf(), *this, &CYapfReserveTrack<Types>::ReserveSingleTrack);
|
||||
if (m_res_fail_tile != INVALID_TILE) {
|
||||
if (this->m_res_fail_tile != INVALID_TILE) {
|
||||
/* Reservation failed, undo. */
|
||||
Node *fail_node = m_res_node;
|
||||
TileIndex stop_tile = m_res_fail_tile;
|
||||
Node *fail_node = this->m_res_node;
|
||||
TileIndex stop_tile = this->m_res_fail_tile;
|
||||
do {
|
||||
/* If this is the node that failed, stop at the failed tile. */
|
||||
m_res_fail_tile = fail_node == node ? stop_tile : INVALID_TILE;
|
||||
this->m_res_fail_tile = fail_node == node ? stop_tile : INVALID_TILE;
|
||||
fail_node->IterateTiles(Yapf().GetVehicle(), Yapf(), *this, &CYapfReserveTrack<Types>::UnreserveSingleTrack);
|
||||
} while (fail_node != node && (fail_node = fail_node->m_parent) != nullptr);
|
||||
|
||||
/* Re-instate green path signals we turned to red. */
|
||||
for (auto [sig_tile, td] : m_signals_set_to_red) {
|
||||
for (auto [sig_tile, td] : this->m_signals_set_to_red) {
|
||||
SetSignalStateByTrackdir(sig_tile, td, SIGNAL_STATE_GREEN);
|
||||
}
|
||||
|
||||
|
@ -191,7 +191,7 @@ public:
|
|||
|
||||
if (target != nullptr) target->okay = true;
|
||||
|
||||
if (Yapf().CanUseGlobalCache(*m_res_node)) {
|
||||
if (Yapf().CanUseGlobalCache(*this->m_res_node)) {
|
||||
YapfNotifyTrackLayoutChange(INVALID_TILE, INVALID_TRACK);
|
||||
}
|
||||
|
||||
|
|
|
@ -103,7 +103,7 @@ protected:
|
|||
public:
|
||||
inline void SetMaxCost(int max_cost)
|
||||
{
|
||||
m_max_cost = max_cost;
|
||||
this->m_max_cost = max_cost;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -130,7 +130,7 @@ public:
|
|||
|
||||
/* Finish if we already exceeded the maximum path cost (i.e. when
|
||||
* searching for the nearest depot). */
|
||||
if (m_max_cost > 0 && (parent_cost + segment_cost) > m_max_cost) {
|
||||
if (this->m_max_cost > 0 && (parent_cost + segment_cost) > this->m_max_cost) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -241,27 +241,27 @@ public:
|
|||
void SetDestination(const RoadVehicle *v)
|
||||
{
|
||||
if (v->current_order.IsType(OT_GOTO_STATION)) {
|
||||
m_dest_station = v->current_order.GetDestination();
|
||||
m_station_type = v->IsBus() ? STATION_BUS : STATION_TRUCK;
|
||||
m_destTile = CalcClosestStationTile(m_dest_station, v->tile, m_station_type);
|
||||
m_non_artic = !v->HasArticulatedPart();
|
||||
m_destTrackdirs = INVALID_TRACKDIR_BIT;
|
||||
this->m_dest_station = v->current_order.GetDestination();
|
||||
this->m_station_type = v->IsBus() ? STATION_BUS : STATION_TRUCK;
|
||||
this->m_destTile = CalcClosestStationTile(this->m_dest_station, v->tile, this->m_station_type);
|
||||
this->m_non_artic = !v->HasArticulatedPart();
|
||||
this->m_destTrackdirs = INVALID_TRACKDIR_BIT;
|
||||
} else if (v->current_order.IsType(OT_GOTO_WAYPOINT)) {
|
||||
m_dest_station = v->current_order.GetDestination();
|
||||
m_station_type = STATION_ROADWAYPOINT;
|
||||
m_destTile = CalcClosestStationTile(m_dest_station, v->tile, m_station_type);
|
||||
m_non_artic = !v->HasArticulatedPart();
|
||||
m_destTrackdirs = INVALID_TRACKDIR_BIT;
|
||||
this->m_dest_station = v->current_order.GetDestination();
|
||||
this->m_station_type = STATION_ROADWAYPOINT;
|
||||
this->m_destTile = CalcClosestStationTile(this->m_dest_station, v->tile, this->m_station_type);
|
||||
this->m_non_artic = !v->HasArticulatedPart();
|
||||
this->m_destTrackdirs = INVALID_TRACKDIR_BIT;
|
||||
} else {
|
||||
m_dest_station = INVALID_STATION;
|
||||
m_destTile = v->dest_tile;
|
||||
m_destTrackdirs = TrackStatusToTrackdirBits(GetTileTrackStatus(v->dest_tile, TRANSPORT_ROAD, GetRoadTramType(v->roadtype)));
|
||||
this->m_dest_station = INVALID_STATION;
|
||||
this->m_destTile = v->dest_tile;
|
||||
this->m_destTrackdirs = TrackStatusToTrackdirBits(GetTileTrackStatus(v->dest_tile, TRANSPORT_ROAD, GetRoadTramType(v->roadtype)));
|
||||
}
|
||||
}
|
||||
|
||||
const Station *GetDestinationStation() const
|
||||
{
|
||||
return m_dest_station != INVALID_STATION ? Station::GetIfValid(m_dest_station) : nullptr;
|
||||
return this->m_dest_station != INVALID_STATION ? Station::GetIfValid(this->m_dest_station) : nullptr;
|
||||
}
|
||||
|
||||
protected:
|
||||
|
@ -275,19 +275,19 @@ public:
|
|||
/** Called by YAPF to detect if node ends in the desired destination */
|
||||
inline bool PfDetectDestination(Node &n)
|
||||
{
|
||||
return PfDetectDestinationTile(n.m_segment_last_tile, n.m_segment_last_td);
|
||||
return this->PfDetectDestinationTile(n.m_segment_last_tile, n.m_segment_last_td);
|
||||
}
|
||||
|
||||
inline bool PfDetectDestinationTile(TileIndex tile, Trackdir trackdir)
|
||||
{
|
||||
if (m_dest_station != INVALID_STATION) {
|
||||
if (this->m_dest_station != INVALID_STATION) {
|
||||
return IsTileType(tile, MP_STATION) &&
|
||||
GetStationIndex(tile) == m_dest_station &&
|
||||
(m_station_type == GetStationType(tile)) &&
|
||||
(m_non_artic || IsDriveThroughStopTile(tile));
|
||||
GetStationIndex(tile) == this->m_dest_station &&
|
||||
(this->m_station_type == GetStationType(tile)) &&
|
||||
(this->m_non_artic || IsDriveThroughStopTile(tile));
|
||||
}
|
||||
|
||||
return tile == m_destTile && HasTrackdir(m_destTrackdirs, trackdir);
|
||||
return tile == this->m_destTile && HasTrackdir(this->m_destTrackdirs, trackdir);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -298,7 +298,7 @@ public:
|
|||
{
|
||||
static const int dg_dir_to_x_offs[] = {-1, 0, 1, 0};
|
||||
static const int dg_dir_to_y_offs[] = {0, 1, 0, -1};
|
||||
if (PfDetectDestination(n)) {
|
||||
if (this->PfDetectDestination(n)) {
|
||||
n.m_estimate = n.m_cost;
|
||||
return true;
|
||||
}
|
||||
|
@ -307,8 +307,8 @@ public:
|
|||
DiagDirection exitdir = TrackdirToExitdir(n.m_segment_last_td);
|
||||
int x1 = 2 * TileX(tile) + dg_dir_to_x_offs[(int)exitdir];
|
||||
int y1 = 2 * TileY(tile) + dg_dir_to_y_offs[(int)exitdir];
|
||||
int x2 = 2 * TileX(m_destTile);
|
||||
int y2 = 2 * TileY(m_destTile);
|
||||
int x2 = 2 * TileX(this->m_destTile);
|
||||
int y2 = 2 * TileY(this->m_destTile);
|
||||
int dx = abs(x1 - x2);
|
||||
int dy = abs(y1 - y2);
|
||||
int dmin = std::min(dx, dy);
|
||||
|
@ -443,7 +443,7 @@ public:
|
|||
return 0;
|
||||
}
|
||||
|
||||
if (!SetOriginFromVehiclePos(v)) return UINT_MAX;
|
||||
if (!this->SetOriginFromVehiclePos(v)) return UINT_MAX;
|
||||
|
||||
/* get available trackdirs on the destination tile */
|
||||
Yapf().SetDestination(v);
|
||||
|
|
|
@ -46,21 +46,21 @@ public:
|
|||
void SetDestination(const Ship *v)
|
||||
{
|
||||
if (v->current_order.IsType(OT_GOTO_STATION)) {
|
||||
m_destStation = v->current_order.GetDestination();
|
||||
m_destTile = CalcClosestStationTile(m_destStation, v->tile, STATION_DOCK);
|
||||
m_destTrackdirs = INVALID_TRACKDIR_BIT;
|
||||
this->m_destStation = v->current_order.GetDestination();
|
||||
this->m_destTile = CalcClosestStationTile(this->m_destStation, v->tile, STATION_DOCK);
|
||||
this->m_destTrackdirs = INVALID_TRACKDIR_BIT;
|
||||
} else {
|
||||
m_destStation = INVALID_STATION;
|
||||
m_destTile = v->dest_tile;
|
||||
m_destTrackdirs = TrackStatusToTrackdirBits(GetTileTrackStatus(v->dest_tile, TRANSPORT_WATER, 0));
|
||||
this->m_destStation = INVALID_STATION;
|
||||
this->m_destTile = v->dest_tile;
|
||||
this->m_destTrackdirs = TrackStatusToTrackdirBits(GetTileTrackStatus(v->dest_tile, TRANSPORT_WATER, 0));
|
||||
}
|
||||
}
|
||||
|
||||
void SetIntermediateDestination(const WaterRegionPatchDesc &water_region_patch)
|
||||
{
|
||||
m_has_intermediate_dest = true;
|
||||
m_intermediate_dest_tile = GetWaterRegionCenterTile(water_region_patch);
|
||||
m_intermediate_dest_region_patch = water_region_patch;
|
||||
this->m_has_intermediate_dest = true;
|
||||
this->m_intermediate_dest_tile = GetWaterRegionCenterTile(water_region_patch);
|
||||
this->m_intermediate_dest_region_patch = water_region_patch;
|
||||
}
|
||||
|
||||
protected:
|
||||
|
@ -74,20 +74,20 @@ public:
|
|||
/** Called by YAPF to detect if node ends in the desired destination. */
|
||||
inline bool PfDetectDestination(Node &n)
|
||||
{
|
||||
return PfDetectDestinationTile(n.m_segment_last_tile, n.m_segment_last_td);
|
||||
return this->PfDetectDestinationTile(n.m_segment_last_tile, n.m_segment_last_td);
|
||||
}
|
||||
|
||||
inline bool PfDetectDestinationTile(TileIndex tile, Trackdir trackdir)
|
||||
{
|
||||
if (m_has_intermediate_dest) {
|
||||
if (this->m_has_intermediate_dest) {
|
||||
/* GetWaterRegionInfo is much faster than GetWaterRegionPatchInfo so we try that first. */
|
||||
if (GetWaterRegionInfo(tile) != m_intermediate_dest_region_patch) return false;
|
||||
return GetWaterRegionPatchInfo(tile) == m_intermediate_dest_region_patch;
|
||||
if (GetWaterRegionInfo(tile) != this->m_intermediate_dest_region_patch) return false;
|
||||
return GetWaterRegionPatchInfo(tile) == this->m_intermediate_dest_region_patch;
|
||||
}
|
||||
|
||||
if (m_destStation != INVALID_STATION) return IsDockingTile(tile) && IsShipDestinationTile(tile, m_destStation);
|
||||
if (this->m_destStation != INVALID_STATION) return IsDockingTile(tile) && IsShipDestinationTile(tile, this->m_destStation);
|
||||
|
||||
return tile == m_destTile && ((m_destTrackdirs & TrackdirToTrackdirBits(trackdir)) != TRACKDIR_BIT_NONE);
|
||||
return tile == this->m_destTile && ((this->m_destTrackdirs & TrackdirToTrackdirBits(trackdir)) != TRACKDIR_BIT_NONE);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -96,11 +96,11 @@ public:
|
|||
*/
|
||||
inline bool PfCalcEstimate(Node &n)
|
||||
{
|
||||
const TileIndex destination_tile = m_has_intermediate_dest ? m_intermediate_dest_tile : m_destTile;
|
||||
const TileIndex destination_tile = this->m_has_intermediate_dest ? this->m_intermediate_dest_tile : this->m_destTile;
|
||||
|
||||
static const int dg_dir_to_x_offs[] = { -1, 0, 1, 0 };
|
||||
static const int dg_dir_to_y_offs[] = { 0, 1, 0, -1 };
|
||||
if (PfDetectDestination(n)) {
|
||||
if (this->PfDetectDestination(n)) {
|
||||
n.m_estimate = n.m_cost;
|
||||
return true;
|
||||
}
|
||||
|
@ -151,9 +151,9 @@ public:
|
|||
{
|
||||
TrackFollower F(Yapf().GetVehicle());
|
||||
if (F.Follow(old_node.m_key.m_tile, old_node.m_key.m_td)) {
|
||||
if (m_water_region_corridor.empty()
|
||||
|| std::find(m_water_region_corridor.begin(), m_water_region_corridor.end(),
|
||||
GetWaterRegionInfo(F.m_new_tile)) != m_water_region_corridor.end()) {
|
||||
if (this->m_water_region_corridor.empty()
|
||||
|| std::find(this->m_water_region_corridor.begin(), this->m_water_region_corridor.end(),
|
||||
GetWaterRegionInfo(F.m_new_tile)) != this->m_water_region_corridor.end()) {
|
||||
Yapf().AddMultipleNodes(&old_node, F);
|
||||
}
|
||||
}
|
||||
|
@ -162,8 +162,8 @@ public:
|
|||
/** Restricts the search by creating corridor or water regions through which the ship is allowed to travel. */
|
||||
inline void RestrictSearch(const std::vector<WaterRegionPatchDesc> &path)
|
||||
{
|
||||
m_water_region_corridor.clear();
|
||||
for (const WaterRegionPatchDesc &path_entry : path) m_water_region_corridor.push_back(path_entry);
|
||||
this->m_water_region_corridor.clear();
|
||||
for (const WaterRegionPatchDesc &path_entry : path) this->m_water_region_corridor.push_back(path_entry);
|
||||
}
|
||||
|
||||
/** Return debug report character to identify the transportation type. */
|
||||
|
@ -373,7 +373,7 @@ public:
|
|||
/* Base tile cost depending on distance. */
|
||||
int c = IsDiagonalTrackdir(n.GetTrackdir()) ? YAPF_TILE_LENGTH : YAPF_TILE_CORNER_LENGTH;
|
||||
/* Additional penalty for curves. */
|
||||
c += CurveCost(n.m_parent->GetTrackdir(), n.GetTrackdir());
|
||||
c += this->CurveCost(n.m_parent->GetTrackdir(), n.GetTrackdir());
|
||||
|
||||
if (IsDockingTile(n.GetTile())) {
|
||||
/* Check docking tile for occupancy. */
|
||||
|
@ -420,7 +420,7 @@ struct CYapfShip_TypesT
|
|||
|
||||
struct CYapfShip : CYapfT<CYapfShip_TypesT<CYapfShip, CFollowTrackWater, CShipNodeListExitDir > >
|
||||
{
|
||||
explicit CYapfShip(int max_nodes) { m_max_search_nodes = max_nodes; }
|
||||
explicit CYapfShip(int max_nodes) { this->m_max_search_nodes = max_nodes; }
|
||||
};
|
||||
|
||||
/** Ship controller helper - path finder invoker. */
|
||||
|
|
|
@ -26,11 +26,11 @@ struct CYapfRegionPatchNodeKey {
|
|||
|
||||
inline void Set(const WaterRegionPatchDesc &water_region_patch)
|
||||
{
|
||||
m_water_region_patch = water_region_patch;
|
||||
this->m_water_region_patch = water_region_patch;
|
||||
}
|
||||
|
||||
inline int CalcHash() const { return CalculateWaterRegionPatchHash(m_water_region_patch); }
|
||||
inline bool operator==(const CYapfRegionPatchNodeKey &other) const { return CalcHash() == other.CalcHash(); }
|
||||
inline int CalcHash() const { return CalculateWaterRegionPatchHash(this->m_water_region_patch); }
|
||||
inline bool operator==(const CYapfRegionPatchNodeKey &other) const { return this->CalcHash() == other.CalcHash(); }
|
||||
};
|
||||
|
||||
inline uint ManhattanDistance(const CYapfRegionPatchNodeKey &a, const CYapfRegionPatchNodeKey &b)
|
||||
|
@ -52,23 +52,23 @@ struct CYapfRegionNodeT {
|
|||
|
||||
inline void Set(Node *parent, const WaterRegionPatchDesc &water_region_patch)
|
||||
{
|
||||
m_key.Set(water_region_patch);
|
||||
m_hash_next = nullptr;
|
||||
m_parent = parent;
|
||||
m_cost = 0;
|
||||
m_estimate = 0;
|
||||
this->m_key.Set(water_region_patch);
|
||||
this->m_hash_next = nullptr;
|
||||
this->m_parent = parent;
|
||||
this->m_cost = 0;
|
||||
this->m_estimate = 0;
|
||||
}
|
||||
|
||||
inline void Set(Node *parent, const Key &key)
|
||||
{
|
||||
Set(parent, key.m_water_region_patch);
|
||||
this->Set(parent, key.m_water_region_patch);
|
||||
}
|
||||
|
||||
DiagDirection GetDiagDirFromParent() const
|
||||
{
|
||||
if (!m_parent) return INVALID_DIAGDIR;
|
||||
const int dx = m_key.m_water_region_patch.x - m_parent->m_key.m_water_region_patch.x;
|
||||
const int dy = m_key.m_water_region_patch.y - m_parent->m_key.m_water_region_patch.y;
|
||||
if (!this->m_parent) return INVALID_DIAGDIR;
|
||||
const int dx = this->m_key.m_water_region_patch.x - this->m_parent->m_key.m_water_region_patch.x;
|
||||
const int dy = this->m_key.m_water_region_patch.y - this->m_parent->m_key.m_water_region_patch.y;
|
||||
if (dx > 0 && dy == 0) return DIAGDIR_SW;
|
||||
if (dx < 0 && dy == 0) return DIAGDIR_NE;
|
||||
if (dx == 0 && dy > 0) return DIAGDIR_SE;
|
||||
|
@ -76,12 +76,12 @@ struct CYapfRegionNodeT {
|
|||
return INVALID_DIAGDIR;
|
||||
}
|
||||
|
||||
inline Node *GetHashNext() { return m_hash_next; }
|
||||
inline void SetHashNext(Node *pNext) { m_hash_next = pNext; }
|
||||
inline const Tkey_ &GetKey() const { return m_key; }
|
||||
inline int GetCost() { return m_cost; }
|
||||
inline int GetCostEstimate() { return m_estimate; }
|
||||
inline bool operator<(const Node &other) const { return m_estimate < other.m_estimate; }
|
||||
inline Node *GetHashNext() { return this->m_hash_next; }
|
||||
inline void SetHashNext(Node *pNext) { this->m_hash_next = pNext; }
|
||||
inline const Tkey_ &GetKey() const { return this->m_key; }
|
||||
inline int GetCost() { return this->m_cost; }
|
||||
inline int GetCostEstimate() { return this->m_estimate; }
|
||||
inline bool operator<(const Node &other) const { return this->m_estimate < other.m_estimate; }
|
||||
};
|
||||
|
||||
/** YAPF origin for water regions. */
|
||||
|
@ -103,17 +103,17 @@ public:
|
|||
void AddOrigin(const WaterRegionPatchDesc &water_region_patch)
|
||||
{
|
||||
if (water_region_patch.label == INVALID_WATER_REGION_PATCH) return;
|
||||
if (!HasOrigin(water_region_patch)) m_origin_keys.push_back(CYapfRegionPatchNodeKey{ water_region_patch });
|
||||
if (!HasOrigin(water_region_patch)) this->m_origin_keys.push_back(CYapfRegionPatchNodeKey{ water_region_patch });
|
||||
}
|
||||
|
||||
bool HasOrigin(const WaterRegionPatchDesc &water_region_patch)
|
||||
{
|
||||
return std::find(m_origin_keys.begin(), m_origin_keys.end(), CYapfRegionPatchNodeKey{ water_region_patch }) != m_origin_keys.end();
|
||||
return std::find(this->m_origin_keys.begin(), this->m_origin_keys.end(), CYapfRegionPatchNodeKey{ water_region_patch }) != this->m_origin_keys.end();
|
||||
}
|
||||
|
||||
void PfSetStartupNodes()
|
||||
{
|
||||
for (const CYapfRegionPatchNodeKey &origin_key : m_origin_keys) {
|
||||
for (const CYapfRegionPatchNodeKey &origin_key : this->m_origin_keys) {
|
||||
Node &node = Yapf().CreateNewNode();
|
||||
node.Set(nullptr, origin_key);
|
||||
Yapf().AddStartupNode(node);
|
||||
|
@ -136,7 +136,7 @@ protected:
|
|||
public:
|
||||
void SetDestination(const WaterRegionPatchDesc &water_region_patch)
|
||||
{
|
||||
m_dest.Set(water_region_patch);
|
||||
this->m_dest.Set(water_region_patch);
|
||||
}
|
||||
|
||||
protected:
|
||||
|
@ -145,17 +145,17 @@ protected:
|
|||
public:
|
||||
inline bool PfDetectDestination(Node &n) const
|
||||
{
|
||||
return n.m_key == m_dest;
|
||||
return n.m_key == this->m_dest;
|
||||
}
|
||||
|
||||
inline bool PfCalcEstimate(Node &n)
|
||||
{
|
||||
if (PfDetectDestination(n)) {
|
||||
if (this->PfDetectDestination(n)) {
|
||||
n.m_estimate = n.m_cost;
|
||||
return true;
|
||||
}
|
||||
|
||||
n.m_estimate = n.m_cost + ManhattanDistance(n.m_key, m_dest);
|
||||
n.m_estimate = n.m_cost + ManhattanDistance(n.m_key, this->m_dest);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -297,7 +297,7 @@ typedef CNodeList_HashTableT<CYapfRegionNodeT<CYapfRegionPatchNodeKey>, 12, 12>
|
|||
|
||||
struct CYapfRegionWater : CYapfT<CYapfRegion_TypesT<CYapfRegionWater, CRegionNodeListWater>>
|
||||
{
|
||||
explicit CYapfRegionWater(int max_nodes) { m_max_search_nodes = max_nodes; }
|
||||
explicit CYapfRegionWater(int max_nodes) { this->m_max_search_nodes = max_nodes; }
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue