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
 
@@ -13,22 +13,54 @@
 
#include "cargomonitor.h"
 
#include "station_base.h"
 

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

	
 
/**
 
 * Get and reset the amount associated with a cargo monitor.
 
 * @param[in,out] monitor_map Monitoring map to search (and reset for the queried entry).
 
 * @param monitor Cargo monitor to query/reset.
src/cargomonitor.h
Show inline comments
 
@@ -136,13 +136,13 @@ static inline IndustryID DecodeMonitorIn
 
static inline TownID DecodeMonitorTown(CargoMonitorID num)
 
{
 
	if (MonitorMonitorsIndustry(num)) return INVALID_TOWN;
 
	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);
 

	
 
#endif /* CARGOMONITOR_H */
src/economy.cpp
Show inline comments
 
@@ -42,12 +42,13 @@
 
#include "economy_base.h"
 
#include "core/pool_func.hpp"
 
#include "core/backup_type.hpp"
 
#include "water.h"
 
#include "game/game.hpp"
 
#include "cargomonitor.h"
 
#include "goal_base.h"
 

	
 
#include "table/strings.h"
 
#include "table/pricebase.h"
 

	
 

	
 
/* Initialize the cargo payment-pool */
 
@@ -505,12 +506,21 @@ void ChangeOwnershipOfCompanyItems(Owner
 

	
 
	Sign *si;
 
	FOR_ALL_SIGNS(si) {
 
		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);
 

	
 
	cur_company.Restore();
 

	
 
	MarkWholeScreenDirty();
src/script/api/game_changelog.hpp
Show inline comments
 
@@ -28,12 +28,15 @@
 
 * \li GSIndustryType::IsProcessingIndustry
 
 * \li GSStation::IsAirportClosed
 
 * \li GSStation::OpenCloseAirport
 
 * \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
 
 *
 
 * \b 1.2.2
 
 *
src/script/api/script_cargomonitor.hpp
Show inline comments
 
@@ -34,13 +34,14 @@
 
 *   The collecting process that happens between calls is stopped.
 
 *
 
 * In the same way you can monitor town deliveries, and you can monitor pick-up from towns and industries.
 
 * 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
 
 */
 
class ScriptCargoMonitor : public ScriptObject {
 
public:
 
	/**
src/script/api/script_goal.hpp
Show inline comments
 
@@ -14,12 +14,17 @@
 

	
 
#include "script_company.hpp"
 
#include "../../goal_type.h"
 

	
 
/**
 
 * 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 {
 
public:
 
	/**
 
	 * The goal IDs.
0 comments (0 inline, 0 general)