mirror of https://github.com/OpenTTD/OpenTTD
Change: Avoid crashing to the side of a train
When a road vehicle is already running on a multi level crossing, and a train shows up ahead, don't make the road vehicle crash on the side of the train.pull/10507/head
parent
8351b97f52
commit
b52b29b1a4
|
@ -26,6 +26,7 @@
|
||||||
#include "effectvehicle_base.h"
|
#include "effectvehicle_base.h"
|
||||||
#include "elrail_func.h"
|
#include "elrail_func.h"
|
||||||
#include "roadveh.h"
|
#include "roadveh.h"
|
||||||
|
#include "train.h"
|
||||||
#include "town.h"
|
#include "town.h"
|
||||||
#include "company_base.h"
|
#include "company_base.h"
|
||||||
#include "core/random_func.hpp"
|
#include "core/random_func.hpp"
|
||||||
|
@ -2086,6 +2087,8 @@ static TrackStatus GetTileTrackStatus_Road(TileIndex tile, TransportType mode, u
|
||||||
trackdirbits = TrackBitsToTrackdirBits(AxisToTrackBits(axis));
|
trackdirbits = TrackBitsToTrackdirBits(AxisToTrackBits(axis));
|
||||||
if (IsCrossingBarred(tile)) {
|
if (IsCrossingBarred(tile)) {
|
||||||
red_signals = trackdirbits;
|
red_signals = trackdirbits;
|
||||||
|
if (TrainOnCrossing(tile)) break;
|
||||||
|
|
||||||
auto mask_red_signal_bits_if_crossing_barred = [&](TileIndex t, TrackdirBits mask) {
|
auto mask_red_signal_bits_if_crossing_barred = [&](TileIndex t, TrackdirBits mask) {
|
||||||
if (IsLevelCrossingTile(t) && IsCrossingBarred(t)) red_signals &= mask;
|
if (IsLevelCrossingTile(t) && IsCrossingBarred(t)) red_signals &= mask;
|
||||||
};
|
};
|
||||||
|
|
|
@ -65,6 +65,8 @@ int GetTrainStopLocation(StationID station_id, TileIndex tile, const Train *v, i
|
||||||
|
|
||||||
void GetTrainSpriteSize(EngineID engine, uint &width, uint &height, int &xoffs, int &yoffs, EngineImageType image_type);
|
void GetTrainSpriteSize(EngineID engine, uint &width, uint &height, int &xoffs, int &yoffs, EngineImageType image_type);
|
||||||
|
|
||||||
|
bool TrainOnCrossing(TileIndex tile);
|
||||||
|
|
||||||
/** Variables that are cached to improve performance and such */
|
/** Variables that are cached to improve performance and such */
|
||||||
struct TrainCache {
|
struct TrainCache {
|
||||||
/* Cached wagon override spritegroup */
|
/* Cached wagon override spritegroup */
|
||||||
|
|
|
@ -1658,6 +1658,19 @@ static Vehicle *TrainOnTileEnum(Vehicle *v, void *)
|
||||||
return (v->type == VEH_TRAIN) ? v : nullptr;
|
return (v->type == VEH_TRAIN) ? v : nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if a level crossing tile has a train on it
|
||||||
|
* @param tile tile to test
|
||||||
|
* @return true if a train is on the crossing
|
||||||
|
* @pre tile is a level crossing
|
||||||
|
*/
|
||||||
|
bool TrainOnCrossing(TileIndex tile)
|
||||||
|
{
|
||||||
|
assert(IsLevelCrossingTile(tile));
|
||||||
|
|
||||||
|
return HasVehicleOnPos(tile, nullptr, &TrainOnTileEnum);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if a train is approaching a rail-road crossing
|
* Checks if a train is approaching a rail-road crossing
|
||||||
|
@ -1709,7 +1722,7 @@ static bool TrainApproachingCrossing(TileIndex tile)
|
||||||
static inline bool CheckLevelCrossing(TileIndex tile)
|
static inline bool CheckLevelCrossing(TileIndex tile)
|
||||||
{
|
{
|
||||||
/* reserved || train on crossing || train approaching crossing */
|
/* reserved || train on crossing || train approaching crossing */
|
||||||
return HasCrossingReservation(tile) || HasVehicleOnPos(tile, NULL, &TrainOnTileEnum) || TrainApproachingCrossing(tile);
|
return HasCrossingReservation(tile) || TrainOnCrossing(tile) || TrainApproachingCrossing(tile);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue