Changeset - r20029:969f10f03aca
[Not reviewed]
master
0 6 0
zuu - 12 years ago 2013-02-10 19:49:04
zuu@openttd.org
(svn r24986) -Change: Cleanup goals and cargo monitors of companies when they go bankrupt or are taken over.
6 files changed with 60 insertions and 9 deletions:
0 comments (0 inline, 0 general)
src/cargomonitor.cpp
Show inline comments
 
@@ -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)
 
{
 
	_cargo_deliveries.clear();
 
	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)
 
{
 
	ClearCargoMonitoring(_cargo_deliveries, company);
 
}
 

	
 
/**
src/cargomonitor.h
Show inline comments
 
@@ -139,8 +139,8 @@ static inline TownID DecodeMonitorTown(C
 
	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);
src/economy.cpp
Show inline comments
 
@@ -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
 
		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);
 

	
src/script/api/game_changelog.hpp
Show inline comments
 
@@ -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
src/script/api/script_cargomonitor.hpp
Show inline comments
 
@@ -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
 
 */
src/script/api/script_goal.hpp
Show inline comments
 
@@ -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 {
0 comments (0 inline, 0 general)