From c140ca6f200e48444ccec4320067dd91165d98f0 Mon Sep 17 00:00:00 2001 From: rubidium Date: Tue, 26 Dec 2006 15:28:11 +0000 Subject: (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 | 15 ++++++++++++++- economy.h | 5 +++-- town_cmd.c | 1 + 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/economy.c b/economy.c index 97fc55c0d..8839d7db1 100644 --- a/economy.c +++ b/economy.c @@ -848,6 +848,19 @@ Pair SetupSubsidyDecodeParam(const Subsidy* s, bool mode) 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 @@ void DeleteSubsidyWithIndustry(IndustryID index) 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; } } diff --git a/economy.h b/economy.h index e4b8f2afc..823e167c8 100644 --- a/economy.h +++ b/economy.h @@ -60,8 +60,9 @@ int UpdateCompanyRatingAndValue(Player *p, bool update); 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); diff --git a/town_cmd.c b/town_cmd.c index 99a821083..923846369 100644 --- a/town_cmd.c +++ b/town_cmd.c @@ -79,6 +79,7 @@ void DestroyTown(Town *t) } DeleteName(t->townnametype); + DeleteSubsidyWithTown(t->index); MarkWholeScreenDirty(); } -- cgit v1.2.3-70-g09d2