Use separate tile hash for each vehicle type
This commit is contained in:
@@ -1914,7 +1914,7 @@ void ReverseTrainSwapVeh(Train *v, int l, int r)
|
||||
*/
|
||||
static Vehicle *TrainOnTileEnum(Vehicle *v, void *)
|
||||
{
|
||||
return (v->type == VEH_TRAIN) ? v : nullptr;
|
||||
return v;
|
||||
}
|
||||
|
||||
|
||||
@@ -1926,12 +1926,12 @@ static Vehicle *TrainOnTileEnum(Vehicle *v, void *)
|
||||
*/
|
||||
static Vehicle *TrainApproachingCrossingEnum(Vehicle *v, void *data)
|
||||
{
|
||||
if (v->type != VEH_TRAIN || (v->vehstatus & VS_CRASHED)) return nullptr;
|
||||
if ((v->vehstatus & VS_CRASHED)) return nullptr;
|
||||
|
||||
Train *t = Train::From(v);
|
||||
if (!t->IsFrontEngine()) return nullptr;
|
||||
|
||||
TileIndex tile = *(TileIndex *)data;
|
||||
TileIndex tile = (TileIndex) reinterpret_cast<uintptr_t>(data);
|
||||
|
||||
if (TrainApproachingCrossingTile(t) != tile) return nullptr;
|
||||
|
||||
@@ -1952,12 +1952,12 @@ static bool TrainApproachingCrossing(TileIndex tile)
|
||||
DiagDirection dir = AxisToDiagDir(GetCrossingRailAxis(tile));
|
||||
TileIndex tile_from = tile + TileOffsByDiagDir(dir);
|
||||
|
||||
if (HasVehicleOnPos(tile_from, &tile, &TrainApproachingCrossingEnum)) return true;
|
||||
if (HasVehicleOnPos(tile_from, VEH_TRAIN, reinterpret_cast<void *>(tile), &TrainApproachingCrossingEnum)) return true;
|
||||
|
||||
dir = ReverseDiagDir(dir);
|
||||
tile_from = tile + TileOffsByDiagDir(dir);
|
||||
|
||||
return HasVehicleOnPos(tile_from, &tile, &TrainApproachingCrossingEnum);
|
||||
return HasVehicleOnPos(tile_from, VEH_TRAIN, reinterpret_cast<void *>(tile), &TrainApproachingCrossingEnum);
|
||||
}
|
||||
|
||||
/** Check if the crossing should be closed
|
||||
@@ -1966,7 +1966,7 @@ static bool TrainApproachingCrossing(TileIndex tile)
|
||||
static inline bool CheckLevelCrossing(TileIndex tile)
|
||||
{
|
||||
/* reserved || train on crossing || train approaching crossing */
|
||||
return HasCrossingReservation(tile) || HasVehicleOnPos(tile, nullptr, &TrainOnTileEnum) || TrainApproachingCrossing(tile);
|
||||
return HasCrossingReservation(tile) || HasVehicleOnPos(tile, VEH_TRAIN, nullptr, &TrainOnTileEnum) || TrainApproachingCrossing(tile);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -3676,8 +3676,8 @@ static Vehicle *FindTrainCollideEnum(Vehicle *v, void *data)
|
||||
{
|
||||
TrainCollideChecker *tcc = (TrainCollideChecker*)data;
|
||||
|
||||
/* not a train or in depot */
|
||||
if (v->type != VEH_TRAIN || Train::From(v)->track == TRACK_BIT_DEPOT) return nullptr;
|
||||
/* not in depot */
|
||||
if (Train::From(v)->track == TRACK_BIT_DEPOT) return nullptr;
|
||||
|
||||
if (_settings_game.vehicle.no_train_crash_other_company) {
|
||||
/* do not crash into trains of another company. */
|
||||
@@ -3734,10 +3734,10 @@ static bool CheckTrainCollision(Train *v)
|
||||
|
||||
/* find colliding vehicles */
|
||||
if (v->track & TRACK_BIT_WORMHOLE) {
|
||||
FindVehicleOnPos(v->tile, &tcc, FindTrainCollideEnum);
|
||||
FindVehicleOnPos(GetOtherTunnelBridgeEnd(v->tile), &tcc, FindTrainCollideEnum);
|
||||
FindVehicleOnPos(v->tile, VEH_TRAIN, &tcc, FindTrainCollideEnum);
|
||||
FindVehicleOnPos(GetOtherTunnelBridgeEnd(v->tile), VEH_TRAIN, &tcc, FindTrainCollideEnum);
|
||||
} else {
|
||||
FindVehicleOnPosXY(v->x_pos, v->y_pos, &tcc, FindTrainCollideEnum);
|
||||
FindVehicleOnPosXY(v->x_pos, v->y_pos, VEH_TRAIN, &tcc, FindTrainCollideEnum);
|
||||
}
|
||||
|
||||
/* any dead -> no crash */
|
||||
@@ -3753,7 +3753,7 @@ static bool CheckTrainCollision(Train *v)
|
||||
|
||||
static Vehicle *CheckTrainAtSignal(Vehicle *v, void *data)
|
||||
{
|
||||
if (v->type != VEH_TRAIN || (v->vehstatus & VS_CRASHED)) return nullptr;
|
||||
if ((v->vehstatus & VS_CRASHED)) return nullptr;
|
||||
|
||||
Train *t = Train::From(v);
|
||||
DiagDirection exitdir = *(DiagDirection *)data;
|
||||
@@ -3776,7 +3776,7 @@ struct FindSpaceBetweenTrainsChecker {
|
||||
static Vehicle *FindSpaceBetweenTrainsEnum(Vehicle *v, void *data)
|
||||
{
|
||||
/* Don't look at wagons between front and back of train. */
|
||||
if (v->type != VEH_TRAIN || (v->Previous() != nullptr && v->Next() != nullptr)) return nullptr;
|
||||
if ((v->Previous() != nullptr && v->Next() != nullptr)) return nullptr;
|
||||
|
||||
if (!IsDiagonalDirection(v->direction)) {
|
||||
/* Check for vehicles on non-across track pieces of custom bridge head */
|
||||
@@ -3815,7 +3815,7 @@ static bool IsTooCloseBehindTrain(Vehicle *v, TileIndex tile, uint16 distance, b
|
||||
case DIAGDIR_NW: checker.pos = (TileY(tile) * TILE_SIZE) + TILE_UNIT_MASK; break;
|
||||
}
|
||||
|
||||
if (HasVehicleOnPos(t->tile, &checker, &FindSpaceBetweenTrainsEnum)) {
|
||||
if (HasVehicleOnPos(t->tile, VEH_TRAIN, &checker, &FindSpaceBetweenTrainsEnum)) {
|
||||
/* Revert train if not going with tunnel direction. */
|
||||
if (checker.direction != GetTunnelBridgeDirection(t->tile)) {
|
||||
SetBit(t->flags, VRF_REVERSING);
|
||||
@@ -3824,7 +3824,7 @@ static bool IsTooCloseBehindTrain(Vehicle *v, TileIndex tile, uint16 distance, b
|
||||
}
|
||||
/* Cover blind spot at end of tunnel bridge. */
|
||||
if (check_endtile){
|
||||
if (HasVehicleOnPos(GetOtherTunnelBridgeEnd(t->tile), &checker, &FindSpaceBetweenTrainsEnum)) {
|
||||
if (HasVehicleOnPos(GetOtherTunnelBridgeEnd(t->tile), VEH_TRAIN, &checker, &FindSpaceBetweenTrainsEnum)) {
|
||||
/* Revert train if not going with tunnel direction. */
|
||||
if (checker.direction != GetTunnelBridgeDirection(t->tile)) {
|
||||
SetBit(t->flags, VRF_REVERSING);
|
||||
@@ -4097,7 +4097,7 @@ bool TrainController(Train *v, Vehicle *nomove, bool reverse)
|
||||
exitdir = ReverseDiagDir(exitdir);
|
||||
|
||||
/* check if a train is waiting on the other side */
|
||||
if (!HasVehicleOnPos(o_tile, &exitdir, &CheckTrainAtSignal)) return false;
|
||||
if (!HasVehicleOnPos(o_tile, VEH_TRAIN, &exitdir, &CheckTrainAtSignal)) return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4546,7 +4546,7 @@ static Vehicle *CollectTrackbitsFromCrashedVehiclesEnum(Vehicle *v, void *data)
|
||||
{
|
||||
TrackBits *trackbits = (TrackBits *)data;
|
||||
|
||||
if (v->type == VEH_TRAIN && (v->vehstatus & VS_CRASHED) != 0) {
|
||||
if ((v->vehstatus & VS_CRASHED) != 0) {
|
||||
if (Train::From(v)->track != TRACK_BIT_DEPOT) {
|
||||
*trackbits |= GetTrackbitsFromCrashedVehicle(Train::From(v));
|
||||
}
|
||||
@@ -4619,7 +4619,7 @@ static void DeleteLastWagon(Train *v)
|
||||
|
||||
/* If there are still crashed vehicles on the tile, give the track reservation to them */
|
||||
TrackBits remaining_trackbits = TRACK_BIT_NONE;
|
||||
FindVehicleOnPos(tile, &remaining_trackbits, CollectTrackbitsFromCrashedVehiclesEnum);
|
||||
FindVehicleOnPos(tile, VEH_TRAIN, &remaining_trackbits, CollectTrackbitsFromCrashedVehiclesEnum);
|
||||
|
||||
/* It is important that these two are the first in the loop, as reservation cannot deal with every trackbit combination */
|
||||
assert(TRACK_BEGIN == TRACK_X && TRACK_Y == TRACK_BEGIN + 1);
|
||||
|
Reference in New Issue
Block a user