(svn r7563) -Fix (FS#468): removing towns in the scenario editor could leave subsidies with that town as source/destination, resulting in an assertion when displaying the Subsidies Window.
authorrubidium
Tue, 26 Dec 2006 15:28:11 +0000
changeset 5566 02b1ecccc540
parent 5565 4eae079a5609
child 5567 2af6b4aa2833
(svn r7563) -Fix (FS#468): removing towns in the scenario editor could leave subsidies with that town as source/destination, resulting in an assertion when displaying the Subsidies Window.
economy.c
economy.h
town_cmd.c
--- a/economy.c	Tue Dec 26 13:30:48 2006 +0000
+++ b/economy.c	Tue Dec 26 15:28:11 2006 +0000
@@ -848,6 +848,19 @@
 	return tp;
 }
 
+void DeleteSubsidyWithTown(TownID index)
+{
+	Subsidy *s;
+
+	for (s = _subsidies; s != endof(_subsidies); s++) {
+		if (s->cargo_type != CT_INVALID && s->age < 12 &&
+				(((s->cargo_type == CT_PASSENGERS || s->cargo_type == CT_MAIL) && (index == s->from || index == s->to)) ||
+				((s->cargo_type == CT_GOODS || s->cargo_type == CT_FOOD) && index == s->to))) {
+			s->cargo_type = CT_INVALID;
+		}
+	}
+}
+
 void DeleteSubsidyWithIndustry(IndustryID index)
 {
 	Subsidy *s;
@@ -855,7 +868,7 @@
 	for (s = _subsidies; s != endof(_subsidies); s++) {
 		if (s->cargo_type != CT_INVALID && s->age < 12 &&
 				s->cargo_type != CT_PASSENGERS && s->cargo_type != CT_MAIL &&
-				(index == s->from || (s->cargo_type!=CT_GOODS && s->cargo_type!=CT_FOOD && index==s->to))) {
+				(index == s->from || (s->cargo_type != CT_GOODS && s->cargo_type != CT_FOOD && index == s->to))) {
 			s->cargo_type = CT_INVALID;
 		}
 	}
--- a/economy.h	Tue Dec 26 13:30:48 2006 +0000
+++ b/economy.h	Tue Dec 26 15:28:11 2006 +0000
@@ -60,8 +60,9 @@
 
 VARDEF Subsidy _subsidies[MAX_PLAYERS];
 Pair SetupSubsidyDecodeParam(const Subsidy* s, bool mode);
-void DeleteSubsidyWithIndustry(uint16 index);
-void DeleteSubsidyWithStation(uint16 index);
+void DeleteSubsidyWithTown(TownID index);
+void DeleteSubsidyWithIndustry(IndustryID index);
+void DeleteSubsidyWithStation(StationID index);
 
 int32 GetTransportedGoodsIncome(uint num_pieces, uint dist, byte transit_days, CargoID cargo_type);
 uint MoveGoodsToStation(TileIndex tile, int w, int h, int type, uint amount);
--- a/town_cmd.c	Tue Dec 26 13:30:48 2006 +0000
+++ b/town_cmd.c	Tue Dec 26 15:28:11 2006 +0000
@@ -79,6 +79,7 @@
 	}
 
 	DeleteName(t->townnametype);
+	DeleteSubsidyWithTown(t->index);
 
 	MarkWholeScreenDirty();
 }