From e79541b166486b4bd1be19694a16e9713e94ae4c Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Sat, 21 Jan 2017 01:16:04 +0000 Subject: [PATCH] TBTR: Remove/change owner of template vehicles on company buy/deletion. --- src/economy.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/economy.cpp b/src/economy.cpp index cdfa059e86..bd6d3c18d8 100644 --- a/src/economy.cpp +++ b/src/economy.cpp @@ -50,6 +50,7 @@ #include "goal_base.h" #include "story_base.h" #include "linkgraph/refresh.h" +#include "tbtr_template_vehicle.h" #include "table/strings.h" #include "table/pricebase.h" @@ -485,6 +486,27 @@ void ChangeOwnershipOfCompanyItems(Owner old_owner, Owner new_owner) if (new_owner != INVALID_OWNER) GroupStatistics::UpdateAutoreplace(new_owner); } + /* Change ownership of template vehicles */ + if (new_owner == INVALID_OWNER) { + TemplateVehicle *tv; + FOR_ALL_TEMPLATES(tv) { + if (tv->owner == old_owner) { + TemplateReplacement *tr; + FOR_ALL_TEMPLATE_REPLACEMENTS(tr) { + if (tr->Template() == tv->index) { + delete tr; + } + } + delete tv; + } + } + } else { + TemplateVehicle *tv; + FOR_ALL_TEMPLATES(tv) { + if (tv->owner == old_owner) tv->owner = new_owner; + } + } + /* Change ownership of tiles */ { TileIndex tile = 0;