diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/cargomonitor.cpp | 44 | ||||
-rw-r--r-- | src/cargomonitor.h | 4 | ||||
-rw-r--r-- | src/economy.cpp | 10 | ||||
-rw-r--r-- | src/script/api/game_changelog.hpp | 3 | ||||
-rw-r--r-- | src/script/api/script_cargomonitor.hpp | 3 | ||||
-rw-r--r-- | src/script/api/script_goal.hpp | 5 |
6 files changed, 60 insertions, 9 deletions
diff --git a/src/cargomonitor.cpp b/src/cargomonitor.cpp index 0f656a6a7..512096785 100644 --- a/src/cargomonitor.cpp +++ b/src/cargomonitor.cpp @@ -16,16 +16,48 @@ CargoMonitorMap _cargo_pickups; ///< Map of monitored pick-ups to the amount since last query/activation. CargoMonitorMap _cargo_deliveries; ///< Map of monitored deliveries to the amount since last query/activation. -/** Clear all pick-up cargo monitors. */ -void ClearCargoPickupMonitoring() +/** + * Helper method for ClearCargoPickupMonitoring and ClearCargoDeliveryMonitoring. + * Clears all monitors that belong to the specified company or all if INVALID_OWNER + * is specified as company. + * @param cargo_monitor_map reference to the cargo monitor map to operate on. + * @param company company to clear cargo monitors for or INVALID_OWNER if all cargo monitors should be cleared. + */ +static void ClearCargoMonitoring(CargoMonitorMap &cargo_monitor_map, CompanyID company = INVALID_OWNER) { - _cargo_pickups.clear(); + if (company == INVALID_OWNER) { + cargo_monitor_map.clear(); + return; + } + + CargoMonitorMap::iterator next; + for (CargoMonitorMap::iterator it = cargo_monitor_map.begin(); it != cargo_monitor_map.end(); it = next) { + next = it; + next++; + if (DecodeMonitorCompany(it->first) == company) { + cargo_monitor_map.erase(it); + } + } } -/** Clear all delivery cargo monitors. */ -void ClearCargoDeliveryMonitoring() +/** + * Clear all pick-up cargo monitors. + * @param company clear all pick-up monitors for this company or if INVALID_OWNER + * is passed, all pick-up monitors are cleared regardless of company. + */ +void ClearCargoPickupMonitoring(CompanyID company) +{ + ClearCargoMonitoring(_cargo_pickups, company); +} + +/** + * Clear all delivery cargo monitors. + * @param company clear all delivery monitors for this company or if INVALID_OWNER + * is passed, all delivery monitors are cleared regardless of company. + */ +void ClearCargoDeliveryMonitoring(CompanyID company) { - _cargo_deliveries.clear(); + ClearCargoMonitoring(_cargo_deliveries, company); } /** diff --git a/src/cargomonitor.h b/src/cargomonitor.h index 1c7123b77..ce9a8e5d6 100644 --- a/src/cargomonitor.h +++ b/src/cargomonitor.h @@ -139,8 +139,8 @@ static inline TownID DecodeMonitorTown(CargoMonitorID num) return GB(num, CCB_TOWN_IND_NUMBER_START, CCB_TOWN_IND_NUMBER_LENGTH); } -void ClearCargoPickupMonitoring(); -void ClearCargoDeliveryMonitoring(); +void ClearCargoPickupMonitoring(CompanyID company = INVALID_OWNER); +void ClearCargoDeliveryMonitoring(CompanyID company = INVALID_OWNER); uint32 GetDeliveryAmount(CargoMonitorID monitor, bool keep_monitoring); uint32 GetPickupAmount(CargoMonitorID monitor, bool keep_monitoring); void AddCargoDelivery(CargoID cargo_type, CompanyID company, uint32 amount, SourceType src_type, SourceID src, const Station *st); diff --git a/src/economy.cpp b/src/economy.cpp index f1b5c9666..39cb8ddaa 100644 --- a/src/economy.cpp +++ b/src/economy.cpp @@ -45,6 +45,7 @@ #include "water.h" #include "game/game.hpp" #include "cargomonitor.h" +#include "goal_base.h" #include "table/strings.h" #include "table/pricebase.h" @@ -508,6 +509,15 @@ void ChangeOwnershipOfCompanyItems(Owner old_owner, Owner new_owner) if (si->owner == old_owner) si->owner = new_owner == INVALID_OWNER ? OWNER_NONE : new_owner; } + /* Remove Game Script created Goals and CargoMonitors. */ + Goal *g; + FOR_ALL_GOALS(g) { + if (g->company == old_owner) delete g; + } + + ClearCargoPickupMonitoring(old_owner); + ClearCargoDeliveryMonitoring(old_owner); + /* Change colour of existing windows */ if (new_owner != INVALID_OWNER) ChangeWindowOwner(old_owner, new_owner); diff --git a/src/script/api/game_changelog.hpp b/src/script/api/game_changelog.hpp index bb61f5d62..c0721a985 100644 --- a/src/script/api/game_changelog.hpp +++ b/src/script/api/game_changelog.hpp @@ -31,6 +31,9 @@ * \li GSController::Break * \li GSIndustryType::BuildIndustry, GSIndustryType::CanBuildIndustry, GSIndustryType::ProspectIndustry and GSIndustryType::CanProspectIndustry when outside GSCompanyMode scope * + * Other changes: + * \li Company specific goals are now removed when a company goes bankrupt or is taken over. + * * \b 1.2.3 * * No changes diff --git a/src/script/api/script_cargomonitor.hpp b/src/script/api/script_cargomonitor.hpp index aa06a8f4a..f0fa56be9 100644 --- a/src/script/api/script_cargomonitor.hpp +++ b/src/script/api/script_cargomonitor.hpp @@ -37,7 +37,8 @@ * The latter get added at the moment the cargo is delivered. This prevents users from getting credit for * picking up cargo without delivering it. * - * The active monitors are saved and loaded. You can reset to the empty state with #StopAllMonitoring. + * The active monitors are saved and loaded. Upon bankruptcy or company takeover, the cargo monitors are + * automatically stopped for that company. You can reset to the empty state with #StopAllMonitoring. * * @api game */ diff --git a/src/script/api/script_goal.hpp b/src/script/api/script_goal.hpp index deca0bd3f..a8511e0d6 100644 --- a/src/script/api/script_goal.hpp +++ b/src/script/api/script_goal.hpp @@ -17,6 +17,11 @@ /** * Class that handles some goal related functions. + * + * Goals are saved and loaded. Upon bankruptcy or company takeover, all company + * specific goals are removed for that company. You can also remove individual + * goals using #Remove. + * * @api game */ class ScriptGoal : public ScriptObject { |