From 9354b5c15c546c9ad5bd23c73d2b6d9e0626364f Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Mon, 23 Sep 2019 21:36:20 +0100 Subject: [PATCH] Avoid iterating vehicle list to release disaster vehicles if there are none --- src/disaster_vehicle.cpp | 13 +++++++++++++ src/disaster_vehicle.h | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/disaster_vehicle.cpp b/src/disaster_vehicle.cpp index ba5f30428d..e6581dae36 100644 --- a/src/disaster_vehicle.cpp +++ b/src/disaster_vehicle.cpp @@ -56,6 +56,8 @@ /** Delay counter for considering the next disaster. */ uint16 _disaster_delay; +static uint32 _disaster_vehicle_count = 0; + static void DisasterClearSquare(TileIndex tile) { if (EnsureNoVehicleOnGround(tile).Failed()) return; @@ -121,6 +123,7 @@ DisasterVehicle::DisasterVehicle() : SpecializedVehicleBase() { RegisterGameEvents(GEF_DISASTER_VEH); + _disaster_vehicle_count++; } /** @@ -135,6 +138,7 @@ DisasterVehicle::DisasterVehicle(int x, int y, Direction direction, DisasterSubT SpecializedVehicleBase(), big_ufo_destroyer_target(big_ufo_destroyer_target) { RegisterGameEvents(GEF_DISASTER_VEH); + _disaster_vehicle_count++; this->vehstatus = VS_UNCLICKABLE; @@ -183,6 +187,11 @@ DisasterVehicle::DisasterVehicle(int x, int y, Direction direction, DisasterSubT this->UpdatePositionAndViewport(); } +DisasterVehicle::~DisasterVehicle() +{ + _disaster_vehicle_count--; +} + /** * Update the position of the vehicle. * @param x The new X-coordinate. @@ -970,6 +979,8 @@ void StartupDisasters() */ void ReleaseDisastersTargetingIndustry(IndustryID i) { + if (!_disaster_vehicle_count) return; + DisasterVehicle *v; FOR_ALL_DISASTERVEHICLES(v) { /* primary disaster vehicles that have chosen target */ @@ -986,6 +997,8 @@ void ReleaseDisastersTargetingIndustry(IndustryID i) */ void ReleaseDisastersTargetingVehicle(VehicleID vehicle) { + if (!_disaster_vehicle_count) return; + DisasterVehicle *v; FOR_ALL_DISASTERVEHICLES(v) { /* primary disaster vehicles that have chosen target */ diff --git a/src/disaster_vehicle.h b/src/disaster_vehicle.h index 0066f8a4be..1b0029b0b7 100644 --- a/src/disaster_vehicle.h +++ b/src/disaster_vehicle.h @@ -45,7 +45,7 @@ struct DisasterVehicle FINAL : public SpecializedVehicle