Add road vehicle flags for whether any part is on level crossing

This commit is contained in:
Jonathan G Rennison
2023-09-10 13:43:13 +01:00
parent 18a40df10e
commit c6ce9ce687
8 changed files with 32 additions and 0 deletions

View File

@@ -631,8 +631,11 @@ static void RoadVehCrash(RoadVehicle *v)
static bool RoadVehCheckTrainCrash(RoadVehicle *v)
{
if (!HasBit(v->rvflags, RVF_ON_LEVEL_CROSSING)) return false;
if (HasBit(_roadtypes_non_train_colliding, v->roadtype)) return false;
bool still_on_level_crossing = false;
for (RoadVehicle *u = v; u != nullptr; u = u->Next()) {
if (u->state == RVSB_WORMHOLE) continue;
@@ -640,6 +643,8 @@ static bool RoadVehCheckTrainCrash(RoadVehicle *v)
if (!IsLevelCrossingTile(tile)) continue;
still_on_level_crossing = true;
CheckRoadVehCrashTrainInfo info(u);
FindVehicleOnPosXY(v->x_pos, v->y_pos, VEH_TRAIN, &info, EnumCheckRoadVehCrashTrain);
if (info.found) {
@@ -648,6 +653,10 @@ static bool RoadVehCheckTrainCrash(RoadVehicle *v)
}
}
if (!still_on_level_crossing) {
ClrBit(v->rvflags, RVF_ON_LEVEL_CROSSING);
}
return false;
}