diff options
author | zuu <zuu@openttd.org> | 2013-02-10 19:49:04 +0000 |
---|---|---|
committer | zuu <zuu@openttd.org> | 2013-02-10 19:49:04 +0000 |
commit | b1016f66ba199966d7f1487a51113329b0ca786d (patch) | |
tree | 107b2d05cb04ef41ba55f2fecf9daac0ce5ac205 /src/cargomonitor.cpp | |
parent | e27582d104c7bbcf987c5320edce94d84b6e59f7 (diff) | |
download | openttd-b1016f66ba199966d7f1487a51113329b0ca786d.tar.xz |
(svn r24986) -Change: Cleanup goals and cargo monitors of companies when they go bankrupt or are taken over.
Diffstat (limited to 'src/cargomonitor.cpp')
-rw-r--r-- | src/cargomonitor.cpp | 44 |
1 files changed, 38 insertions, 6 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); } /** |