summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsmatz <smatz@openttd.org>2008-12-26 19:37:50 +0000
committersmatz <smatz@openttd.org>2008-12-26 19:37:50 +0000
commit73ca72922c64db43f16b4283548ccf30aca3e59a (patch)
treed4bd34c6215ede747794b7a5273d6a5c6d3390c8
parent17212220804ca34561bd51c68a9784ef73f82e26 (diff)
downloadopenttd-73ca72922c64db43f16b4283548ccf30aca3e59a.tar.xz
(svn r14746) -Fix: don't let any disaster vehicle (Helicopter or Airplane) target invalid industry
-rw-r--r--src/disaster_cmd.cpp16
-rw-r--r--src/industry.h2
-rw-r--r--src/industry_cmd.cpp3
3 files changed, 21 insertions, 0 deletions
diff --git a/src/disaster_cmd.cpp b/src/disaster_cmd.cpp
index 36c365d11..910918f8c 100644
--- a/src/disaster_cmd.cpp
+++ b/src/disaster_cmd.cpp
@@ -1063,6 +1063,22 @@ void StartupDisasters()
ResetDisasterDelay();
}
+/** Marks all disasters targeting this industry in such a way
+ * they won't call GetIndustry(v->dest_tile) on invalid industry anymore.
+ * @param i deleted industry
+ */
+void ReleaseDisastersTargetingIndustry(IndustryID i)
+{
+ Vehicle *v;
+ FOR_ALL_VEHICLES(v) {
+ /* primary disaster vehicles that have chosen target */
+ if (v->type == VEH_DISASTER && (v->subtype == ST_Airplane || v->subtype == ST_Helicopter)) {
+ /* if it has chosen target, and it is this industry (yes, dest_tile is IndustryID here), set order to "leaving map peacefully" */
+ if (v->current_order.GetDestination() > 0 && v->dest_tile == i) v->current_order.SetDestination(3);
+ }
+ }
+}
+
void DisasterVehicle::UpdateDeltaXY(Direction direction)
{
this->x_offs = -1;
diff --git a/src/industry.h b/src/industry.h
index f89cf0477..e750c6ab0 100644
--- a/src/industry.h
+++ b/src/industry.h
@@ -238,6 +238,8 @@ const IndustryTileSpec *GetIndustryTileSpec(IndustryGfx gfx); ///< Array of ind
void ResetIndustries();
void PlantRandomFarmField(const Industry *i);
+void ReleaseDisastersTargetingIndustry(IndustryID);
+
/* writable arrays of specs */
extern IndustrySpec _industry_specs[NUM_INDUSTRYTYPES];
extern IndustryTileSpec _industry_tile_specs[NUM_INDUSTRYTILES];
diff --git a/src/industry_cmd.cpp b/src/industry_cmd.cpp
index a9a837dbe..543c21654 100644
--- a/src/industry_cmd.cpp
+++ b/src/industry_cmd.cpp
@@ -166,6 +166,9 @@ Industry::~Industry()
} END_TILE_LOOP(tile_cur, 42, 42, this->xy - TileDiff(21, 21))
}
+ /* don't let any disaster vehicle target invalid industry */
+ ReleaseDisastersTargetingIndustry(this->index);
+
DecIndustryTypeCount(this->type);
DeleteSubsidyWithIndustry(this->index);