(svn r24986) -Change: Cleanup goals and cargo monitors of companies when they go bankrupt or are taken over.

replace/41b28d7194a279bdc17475d4fbe2ea6ec885a466
zuu 11 years ago
parent e27582d104
commit b1016f66ba

@ -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);
}
/**

@ -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);

@ -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);

@ -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

@ -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
*/

@ -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 {

Loading…
Cancel
Save