Changeset - r15282:8e9c51163c93
[Not reviewed]
master
0 17 0
frosch - 14 years ago 2010-06-05 12:16:12
frosch@openttd.org
(svn r19931) -Fix (r19914): Convert assertion in Backup<> destructor into DEBUG() output. It was triggered on exceptions, especially when aborting world generation.
17 files changed with 62 insertions and 44 deletions:
0 comments (0 inline, 0 general)
src/ai/ai_core.cpp
Show inline comments
 
@@ -66,13 +66,13 @@
 

	
 
	/* The speed with which AIs go, is limited by the 'competitor_speed' */
 
	AI::frame_counter++;
 
	assert(_settings_game.difficulty.competitor_speed <= 4);
 
	if ((AI::frame_counter & ((1 << (4 - _settings_game.difficulty.competitor_speed)) - 1)) != 0) return;
 

	
 
	Backup<CompanyByte> cur_company(_current_company);
 
	Backup<CompanyByte> cur_company(_current_company, FILE_LINE);
 
	const Company *c;
 
	FOR_ALL_COMPANIES(c) {
 
		if (c->is_ai) {
 
			cur_company.Change(c->index);
 
			c->ai_instance->GameLoop();
 
		}
 
@@ -93,13 +93,13 @@
 
}
 

	
 
/* static */ void AI::Stop(CompanyID company)
 
{
 
	if (_networking && !_network_server) return;
 

	
 
	Backup<CompanyByte> cur_company(_current_company, company);
 
	Backup<CompanyByte> cur_company(_current_company, company, FILE_LINE);
 
	Company *c = Company::Get(company);
 

	
 
	delete c->ai_instance;
 
	c->ai_instance = NULL;
 

	
 
	cur_company.Restore();
 
@@ -109,13 +109,13 @@
 
}
 

	
 
/* static */ void AI::Suspend(CompanyID company)
 
{
 
	if (_networking && !_network_server) return;
 

	
 
	Backup<CompanyByte> cur_company(_current_company, company);
 
	Backup<CompanyByte> cur_company(_current_company, company, FILE_LINE);
 
	Company::Get(company)->ai_instance->Suspend();
 

	
 
	cur_company.Restore();
 
}
 

	
 
/* static */ void AI::KillAll()
 
@@ -198,13 +198,13 @@
 
	if (!Company::IsValidAiID(company)) {
 
		event->Release();
 
		return;
 
	}
 

	
 
	/* Queue the event */
 
	Backup<CompanyByte> cur_company(_current_company, company);
 
	Backup<CompanyByte> cur_company(_current_company, company, FILE_LINE);
 
	AIEventController::InsertEvent(event);
 
	cur_company.Restore();
 

	
 
	event->Release();
 
}
 

	
 
@@ -244,13 +244,13 @@ void CcAI(const CommandCost &result, Til
 
/* static */ void AI::Save(CompanyID company)
 
{
 
	if (!_networking || _network_server) {
 
		Company *c = Company::GetIfValid(company);
 
		assert(c != NULL && c->ai_instance != NULL);
 

	
 
		Backup<CompanyByte> cur_company(_current_company, company);
 
		Backup<CompanyByte> cur_company(_current_company, company, FILE_LINE);
 
		c->ai_instance->Save();
 
		cur_company.Restore();
 
	} else {
 
		AIInstance::SaveEmpty();
 
	}
 
}
 
@@ -258,13 +258,13 @@ void CcAI(const CommandCost &result, Til
 
/* static */ void AI::Load(CompanyID company, int version)
 
{
 
	if (!_networking || _network_server) {
 
		Company *c = Company::GetIfValid(company);
 
		assert(c != NULL && c->ai_instance != NULL);
 

	
 
		Backup<CompanyByte> cur_company(_current_company, company);
 
		Backup<CompanyByte> cur_company(_current_company, company, FILE_LINE);
 
		c->ai_instance->Load(version);
 
		cur_company.Restore();
 
	} else {
 
		/* Read, but ignore, the load data */
 
		AIInstance::LoadEmpty();
 
	}
src/ai/ai_gui.cpp
Show inline comments
 
@@ -817,13 +817,13 @@ struct AIDebugWindow : public QueryStrin
 
			if (!valid) continue;
 

	
 
			byte offset = (i == ai_debug_company) ? 1 : 0;
 
			DrawCompanyIcon(i, button->pos_x + button->current_x / 2 - 7 + offset, this->GetWidget<NWidgetBase>(AID_WIDGET_COMPANY_BUTTON_START + i)->pos_y + 2 + offset);
 
		}
 

	
 
		Backup<CompanyByte> cur_company(_current_company, ai_debug_company);
 
		Backup<CompanyByte> cur_company(_current_company, ai_debug_company, FILE_LINE);
 
		AILog::LogData *log = (AILog::LogData *)AIObject::GetLogPointer();
 
		cur_company.Restore();
 

	
 
		int scroll_count = (log == NULL) ? 0 : log->used;
 
		if (this->vscroll.GetCount() != scroll_count) {
 
			this->vscroll.SetCount(scroll_count);
 
@@ -872,13 +872,13 @@ struct AIDebugWindow : public QueryStrin
 
	virtual void DrawWidget(const Rect &r, int widget) const
 
	{
 
		if (ai_debug_company == INVALID_COMPANY) return;
 

	
 
		switch (widget) {
 
			case AID_WIDGET_LOG_PANEL: {
 
				Backup<CompanyByte> cur_company(_current_company, ai_debug_company);
 
				Backup<CompanyByte> cur_company(_current_company, ai_debug_company, FILE_LINE);
 
				AILog::LogData *log = (AILog::LogData *)AIObject::GetLogPointer();
 
				cur_company.Restore();
 
				if (log == NULL) return;
 

	
 
				int y = this->top_offset;
 
				for (int i = this->vscroll.GetPosition(); this->vscroll.IsVisible(i) && i < log->used; i++) {
 
@@ -911,13 +911,13 @@ struct AIDebugWindow : public QueryStrin
 

	
 
	void ChangeToAI(CompanyID show_ai)
 
	{
 
		this->RaiseWidget(ai_debug_company + AID_WIDGET_COMPANY_BUTTON_START);
 
		ai_debug_company = show_ai;
 

	
 
		Backup<CompanyByte> cur_company(_current_company, ai_debug_company);
 
		Backup<CompanyByte> cur_company(_current_company, ai_debug_company, FILE_LINE);
 
		AILog::LogData *log = (AILog::LogData *)AIObject::GetLogPointer();
 
		cur_company.Restore();
 
		this->vscroll.SetCount((log == NULL) ? 0 : log->used);
 

	
 
		this->LowerWidget(ai_debug_company + AID_WIDGET_COMPANY_BUTTON_START);
 
		this->autoscroll = true;
 
@@ -1006,13 +1006,13 @@ struct AIDebugWindow : public QueryStrin
 
			}
 
		}
 

	
 
		/* If the log message is related to the active company tab, check the break string */
 
		if (data == ai_debug_company && this->break_check_enabled && !StrEmpty(this->edit_str_buf)) {
 
			/* Get the log instance of the active company */
 
			Backup<CompanyByte> cur_company(_current_company, ai_debug_company);
 
			Backup<CompanyByte> cur_company(_current_company, ai_debug_company, FILE_LINE);
 
			AILog::LogData *log = (AILog::LogData *)AIObject::GetLogPointer();
 

	
 
			if (log != NULL && case_sensitive_break_check?
 
					strstr(log->lines[log->pos], this->edit_str_buf) != 0 :
 
					strcasestr(log->lines[log->pos], this->edit_str_buf) != 0) {
 

	
src/aircraft_cmd.cpp
Show inline comments
 
@@ -1201,13 +1201,13 @@ void HandleMissingAircraftOrders(Aircraf
 
	 *    example a depot. However, when we have a current order to
 
	 *    go to a depot, we have to keep that order so the aircraft
 
	 *    actually stops.
 
	 */
 
	const Station *st = GetTargetAirportIfValid(v);
 
	if (st == NULL) {
 
		Backup<CompanyByte> cur_company(_current_company, v->owner);
 
		Backup<CompanyByte> cur_company(_current_company, v->owner, FILE_LINE);
 
		CommandCost ret = DoCommand(v->tile, v->index, 0, DC_EXEC, CMD_SEND_AIRCRAFT_TO_HANGAR);
 
		cur_company.Restore();
 

	
 
		if (ret.Failed()) CrashAirplane(v);
 
	} else if (!v->current_order.IsType(OT_GOTO_DEPOT)) {
 
		v->current_order.Free();
 
@@ -1507,13 +1507,13 @@ static void AircraftEventHandler_HeliTak
 

	
 
	/* get the next position to go to, differs per airport */
 
	AircraftNextAirportPos_and_Order(v);
 

	
 
	/* Send the helicopter to a hangar if needed for replacement */
 
	if (v->NeedsAutomaticServicing()) {
 
		Backup<CompanyByte> cur_company(_current_company, v->owner);
 
		Backup<CompanyByte> cur_company(_current_company, v->owner, FILE_LINE);
 
		DoCommand(v->tile, v->index, DEPOT_SERVICE | DEPOT_LOCATE_HANGAR, DC_EXEC, CMD_SEND_AIRCRAFT_TO_HANGAR);
 
		cur_company.Restore();
 
	}
 
}
 

	
 
static void AircraftEventHandler_Flying(Aircraft *v, const AirportFTAClass *apc)
 
@@ -1559,13 +1559,13 @@ static void AircraftEventHandler_Landing
 
{
 
	v->state = ENDLANDING;
 
	AircraftLandAirplane(v);  // maybe crash airplane
 

	
 
	/* check if the aircraft needs to be replaced or renewed and send it to a hangar if needed */
 
	if (v->NeedsAutomaticServicing()) {
 
		Backup<CompanyByte> cur_company(_current_company, v->owner);
 
		Backup<CompanyByte> cur_company(_current_company, v->owner, FILE_LINE);
 
		DoCommand(v->tile, v->index, DEPOT_SERVICE, DC_EXEC, CMD_SEND_AIRCRAFT_TO_HANGAR);
 
		cur_company.Restore();
 
	}
 
}
 

	
 
static void AircraftEventHandler_HeliLanding(Aircraft *v, const AirportFTAClass *apc)
src/core/backup_type.hpp
Show inline comments
 
@@ -9,44 +9,56 @@
 

	
 
/** @file backup_type.hpp Class for backupping variables and making sure they are restored later. */
 

	
 
#ifndef BACKUP_TYPE_HPP
 
#define BACKUP_TYPE_HPP
 

	
 
#include "../debug.h"
 

	
 
/**
 
 * Class to backup a specific variable and restore it later.
 
 * The variable is not restored automatically, but assertions make sure it is restored.
 
 * You have to call either Trash() or Restore() exactly once.
 
 */
 
template <typename T>
 
struct Backup {
 
	/**
 
	 * Backup variable.
 
	 * @param original Variable to backup.
 
	 * @param file Filename for debug output. Use FILE_LINE macro.
 
	 * @param line Linenumber for debug output. Use FILE_LINE macro.
 
	 */
 
	Backup(T &original) : original(original), valid(true), original_value(original) {}
 
	Backup(T &original, const char * const file, const int line) : original(original), valid(true), original_value(original), file(file), line(line) {}
 

	
 
	/**
 
	 * Backup variable and switch to new value.
 
	 * @param original Variable to backup.
 
	 * @param new_value New value for variable.
 
	 * @param file Filename for debug output. Use FILE_LINE macro.
 
	 * @param line Linenumber for debug output. Use FILE_LINE macro.
 
	 */
 
	template <typename U>
 
	Backup(T &original, const U &new_value) : original(original), valid(true), original_value(original)
 
	Backup(T &original, const U &new_value, const char * const file, const int line) : original(original), valid(true), original_value(original), file(file), line(line)
 
	{
 
		/* Note: We use a separate typename U, so type conversions are handled by assignment operator. */
 
		original = new_value;
 
	}
 

	
 
	/**
 
	 * Check whether the variable was restored on object destruction.
 
	 */
 
	~Backup()
 
	{
 
		/* Check whether restoration was done */
 
		assert(!this->valid);
 
		if (this->valid)
 
		{
 
			/* We cannot assert here, as missing restoration is 'normal' when exceptions are thrown.
 
			 * Exceptions are especially used to abort world generation. */
 
			DEBUG(misc, 0, "%s:%d: Backupped value was not restored!", this->file, this->line);
 
			this->Restore();
 
		}
 
	}
 

	
 
	/**
 
	 * Checks whether the variable was already restored.
 
	 * @return true if variable has already been restored.
 
	 */
 
@@ -126,9 +138,12 @@ struct Backup {
 
	}
 

	
 
private:
 
	T &original;
 
	bool valid;
 
	T original_value;
 

	
 
	const char * const file;
 
	const int line;
 
};
 

	
 
#endif /* BACKUP_TYPE_HPP */
src/debug.h
Show inline comments
 
@@ -50,12 +50,15 @@
 
	void CDECL debug(const char *dbg, const char *format, ...) WARN_FORMAT(2, 3);
 
#endif /* NO_DEBUG_MESSAGES */
 

	
 
void SetDebugString(const char *s);
 
const char *GetDebugString();
 

	
 
/* Shorter form for passing filename and linenumber */
 
#define FILE_LINE __FILE__, __LINE__
 

	
 
/* Used for profiling
 
 *
 
 * Usage:
 
 * TIC();
 
 *   --Do your code--
 
 * TOC("A name", 1);
src/disaster_cmd.cpp
Show inline comments
 
@@ -70,23 +70,23 @@ static void DisasterClearSquare(TileInde
 
{
 
	if (EnsureNoVehicleOnGround(tile).Failed()) return;
 

	
 
	switch (GetTileType(tile)) {
 
		case MP_RAILWAY:
 
			if (Company::IsHumanID(GetTileOwner(tile))) {
 
				Backup<CompanyByte> cur_company(_current_company, OWNER_WATER);
 
				Backup<CompanyByte> cur_company(_current_company, OWNER_WATER, FILE_LINE);
 
				DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
 
				cur_company.Restore();
 

	
 
				/* update signals in buffer */
 
				UpdateSignalsInBuffer();
 
			}
 
			break;
 

	
 
		case MP_HOUSE: {
 
			Backup<CompanyByte> cur_company(_current_company, OWNER_NONE);
 
			Backup<CompanyByte> cur_company(_current_company, OWNER_NONE, FILE_LINE);
 
			DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
 
			cur_company.Restore();
 
			break;
 
		}
 

	
 
		case MP_TREES:
src/economy.cpp
Show inline comments
 
@@ -302,13 +302,13 @@ void ChangeOwnershipOfCompanyItems(Owner
 
#ifdef ENABLE_NETWORK
 
	/* In all cases, make spectators of clients connected to that company */
 
	if (_networking) NetworkClientsToSpectators(old_owner);
 
#endif /* ENABLE_NETWORK */
 

	
 
	Town *t;
 
	Backup<CompanyByte> cur_company(_current_company, old_owner);
 
	Backup<CompanyByte> cur_company(_current_company, old_owner, FILE_LINE);
 

	
 
	assert(old_owner != new_owner);
 

	
 
	{
 
		Company *c;
 
		uint i;
 
@@ -324,13 +324,13 @@ void ChangeOwnershipOfCompanyItems(Owner
 
					SubtractMoneyFromCompany(res);
 
				}
 
			}
 
		}
 

	
 
		/* Sell all the shares that people have on this company */
 
		Backup<CompanyByte> cur_company2(_current_company);
 
		Backup<CompanyByte> cur_company2(_current_company, FILE_LINE);
 
		c = Company::Get(old_owner);
 
		for (i = 0; i < 4; i++) {
 
			cur_company2.Change(c->share_owners[i]);
 
			if (_current_company != INVALID_OWNER) {
 
				/* Sell the shares */
 
				CommandCost res = DoCommand(0, old_owner, 0, DC_EXEC, CMD_SELL_SHARE_IN_COMPANY);
 
@@ -550,13 +550,13 @@ static void CompanyCheckBankrupt(Company
 

	
 
static void CompaniesGenStatistics()
 
{
 
	Station *st;
 
	Company *c;
 

	
 
	Backup<CompanyByte> cur_company(_current_company);
 
	Backup<CompanyByte> cur_company(_current_company, FILE_LINE);
 
	FOR_ALL_STATIONS(st) {
 
		cur_company.Change(st->owner);
 
		CommandCost cost(EXPENSES_PROPERTY, _price[PR_STATION_VALUE] >> 1);
 
		SubtractMoneyFromCompany(cost);
 
	}
 
	cur_company.Restore();
 
@@ -685,13 +685,13 @@ void RecomputePrices()
 
}
 

	
 
static void CompaniesPayInterest()
 
{
 
	const Company *c;
 

	
 
	Backup<CompanyByte> cur_company(_current_company);
 
	Backup<CompanyByte> cur_company(_current_company, FILE_LINE);
 
	FOR_ALL_COMPANIES(c) {
 
		cur_company.Change(c->index);
 

	
 
		/* Over a year the paid interest should be "loan * interest percentage",
 
		 * but... as that number is likely not dividable by 12 (pay each month),
 
		 * one needs to account for that in the monthly fee calculations.
 
@@ -1024,13 +1024,13 @@ CargoPayment::~CargoPayment()
 
	if (this->CleaningPool()) return;
 

	
 
	this->front->cargo_payment = NULL;
 

	
 
	if (this->visual_profit == 0) return;
 

	
 
	Backup<CompanyByte> cur_company(_current_company, this->front->owner);
 
	Backup<CompanyByte> cur_company(_current_company, this->front->owner, FILE_LINE);
 

	
 
	SubtractMoneyFromCompany(CommandCost(this->front->GetExpenseType(true), -this->route_profit));
 
	this->front->profit_this_year += this->visual_profit << 8;
 

	
 
	if (this->route_profit != 0) {
 
		if (IsLocalCompany() && !PlayVehicleSound(this->front, VSE_LOAD_UNLOAD)) {
 
@@ -1455,13 +1455,13 @@ static void DoAcquireCompany(Company *c)
 
	if (c->bankrupt_value == 0) {
 
		owner = Company::Get(_current_company);
 
		owner->current_loan += c->current_loan;
 
	}
 

	
 
	value = CalculateCompanyValue(c) >> 2;
 
	Backup<CompanyByte> cur_company(_current_company);
 
	Backup<CompanyByte> cur_company(_current_company, FILE_LINE);
 
	for (i = 0; i != 4; i++) {
 
		if (c->share_owners[i] != COMPANY_SPECTATOR) {
 
			cur_company.Change(c->share_owners[i]);
 
			SubtractMoneyFromCompany(CommandCost(EXPENSES_OTHER, -value));
 
		}
 
	}
src/industry_cmd.cpp
Show inline comments
 
@@ -1040,13 +1040,13 @@ void PlantRandomFarmField(const Industry
 
 */
 
static bool SearchLumberMillTrees(TileIndex tile, void *user_data)
 
{
 
	if (IsTileType(tile, MP_TREES) && GetTreeGrowth(tile) > 2) { ///< 3 and up means all fully grown trees
 
		/* found a tree */
 

	
 
		Backup<CompanyByte> cur_company(_current_company, OWNER_NONE);
 
		Backup<CompanyByte> cur_company(_current_company, OWNER_NONE, FILE_LINE);
 

	
 
		_industry_sound_ctr = 1;
 
		_industry_sound_tile = tile;
 
		SndPlayTileFx(SND_38_CHAINSAW, tile);
 

	
 
		DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
 
@@ -1369,13 +1369,13 @@ static CommandCost CheckIfIndustryTilesA
 
					((ind_behav & INDUSTRYBEH_ONLY_NEARTOWN) && IsTileType(cur_tile, MP_HOUSE))) { // Tile is allowed to be a house (and it is a house)
 
				if (!IsTileType(cur_tile, MP_HOUSE)) {
 
					return_cmd_error(STR_ERROR_CAN_ONLY_BE_BUILT_IN_TOWNS);
 
				}
 

	
 
				/* Clear the tiles as OWNER_TOWN to not affect town rating, and to not clear protected buildings */
 
				Backup<CompanyByte> cur_company(_current_company, OWNER_TOWN);
 
				Backup<CompanyByte> cur_company(_current_company, OWNER_TOWN, FILE_LINE);
 
				CommandCost ret = DoCommand(cur_tile, 0, 0, DC_NONE, CMD_LANDSCAPE_CLEAR);
 
				cur_company.Restore();
 

	
 
				if (ret.Failed()) return ret;
 
			} else {
 
				/* Clear the tiles, but do not affect town ratings */
 
@@ -1481,13 +1481,13 @@ static bool CheckIfCanLevelIndustryPlatf
 

	
 
	/* Check if we don't leave the map */
 
	if (TileX(cur_tile) + size_x >= MapMaxX() || TileY(cur_tile) + size_y >= MapMaxY()) return false;
 

	
 
	/* _current_company is OWNER_NONE for randomly generated industries and in editor, or the company who funded or prospected the industry.
 
	 * Perform terraforming as OWNER_TOWN to disable autoslope and town ratings. */
 
	Backup<CompanyByte> cur_company(_current_company, OWNER_TOWN);
 
	Backup<CompanyByte> cur_company(_current_company, OWNER_TOWN, FILE_LINE);
 

	
 
	TILE_LOOP(tile_walk, size_x, size_y, cur_tile) {
 
		curh = TileHeight(tile_walk);
 
		if (curh != h) {
 
			/* This tile needs terraforming. Check if we can do that without
 
			 *  damaging the surroundings too much. */
 
@@ -1785,13 +1785,13 @@ CommandCost CmdBuildIndustry(TileIndex t
 
	uint32 random_var8f = randomizer.Next();
 

	
 
	Industry *ind = NULL;
 
	if (_game_mode != GM_EDITOR && _settings_game.construction.raw_industry_construction == 2 && indspec->IsRawIndustry()) {
 
		if (flags & DC_EXEC) {
 
			/* Prospected industries are build as OWNER_TOWN to not e.g. be build on owned land of the founder */
 
			Backup<CompanyByte> cur_company(_current_company, OWNER_TOWN);
 
			Backup<CompanyByte> cur_company(_current_company, OWNER_TOWN, FILE_LINE);
 
			/* Prospecting has a chance to fail, however we cannot guarantee that something can
 
			 * be built on the map, so the chance gets lower when the map is fuller, but there
 
			 * is nothing we can really do about that. */
 
			if (Random() <= indspec->prospecting_chance) {
 
				for (int i = 0; i < 5000; i++) {
 
					/* We should not have more than one Random() in a function call
 
@@ -1887,13 +1887,13 @@ static const byte _numof_industry_table[
 
 * Try to build a industry on the map.
 
 * @param type IndustryType of the desired industry
 
 * @param try_hard Try very hard to find a place. (Used to place at least one industry per type)
 
 */
 
static void PlaceInitialIndustry(IndustryType type, bool try_hard)
 
{
 
	Backup<CompanyByte> cur_company(_current_company, OWNER_NONE);
 
	Backup<CompanyByte> cur_company(_current_company, OWNER_NONE, FILE_LINE);
 

	
 
	IncreaseGeneratingWorldProgress(GWP_INDUSTRY);
 

	
 
	for (uint i = 0; i < (try_hard ? 10000u : 2000u); i++) {
 
		if (CreateNewIndustry(RandomTile(), type) != NULL) break;
 
	}
 
@@ -2411,13 +2411,13 @@ void IndustryDailyLoop()
 
	_economy.industry_daily_change_counter &= 0xFFFF;
 

	
 
	if (change_loop == 0) {
 
		return;  // Nothing to do? get out
 
	}
 

	
 
	Backup<CompanyByte> cur_company(_current_company, OWNER_NONE);
 
	Backup<CompanyByte> cur_company(_current_company, OWNER_NONE, FILE_LINE);
 

	
 
	/* perform the required industry changes for the day */
 
	for (uint16 j = 0; j < change_loop; j++) {
 
		/* 3% chance that we start a new industry */
 
		if (Chance16(3, 100)) {
 
			MaybeNewIndustry();
 
@@ -2436,13 +2436,13 @@ void IndustryDailyLoop()
 
	InvalidateWindowData(WC_INDUSTRY_DIRECTORY, 0, 1);
 
}
 

	
 
void IndustryMonthlyLoop()
 
{
 
	Industry *i;
 
	Backup<CompanyByte> cur_company(_current_company, OWNER_NONE);
 
	Backup<CompanyByte> cur_company(_current_company, OWNER_NONE, FILE_LINE);
 

	
 
	FOR_ALL_INDUSTRIES(i) {
 
		UpdateIndustryStatistics(i);
 
		if (i->prod_level == PRODLEVEL_CLOSURE) {
 
			delete i;
 
		} else {
src/industry_gui.cpp
Show inline comments
 
@@ -520,13 +520,13 @@ public:
 
			if (Town::GetNumItems() == 0) {
 
				SetDParam(0, indsp->name);
 
				ShowErrorMessage(STR_ERROR_CAN_T_BUILD_HERE, STR_ERROR_MUST_FOUND_TOWN_FIRST, WL_INFO, pt.x, pt.y);
 
				return;
 
			}
 

	
 
			Backup<CompanyByte> cur_company(_current_company, OWNER_NONE);
 
			Backup<CompanyByte> cur_company(_current_company, OWNER_NONE, FILE_LINE);
 
			_generating_world = true;
 
			_ignore_restrictions = true;
 

	
 
			DoCommandP(tile, (InteractiveRandomRange(indsp->num_table) << 8) | this->selected_type, seed,
 
					CMD_BUILD_INDUSTRY | CMD_MSG(STR_ERROR_CAN_T_CONSTRUCT_THIS_INDUSTRY), &CcBuildIndustry);
 

	
src/misc_cmd.cpp
Show inline comments
 
@@ -227,13 +227,13 @@ CommandCost CmdGiveMoney(TileIndex tile,
 
	/* You can only transfer funds that is in excess of your loan */
 
	if (c->money - c->current_loan < amount.GetCost() || amount.GetCost() < 0) return CMD_ERROR;
 
	if (!_networking || !Company::IsValidID(dest_company)) return CMD_ERROR;
 

	
 
	if (flags & DC_EXEC) {
 
		/* Add money to company */
 
		Backup<CompanyByte> cur_company(_current_company, dest_company);
 
		Backup<CompanyByte> cur_company(_current_company, dest_company, FILE_LINE);
 
		SubtractMoneyFromCompany(CommandCost(EXPENSES_OTHER, -amount.GetCost()));
 
		cur_company.Restore();
 
	}
 

	
 
	/* Subtract money from local-company */
 
	return amount;
src/openttd.cpp
Show inline comments
 
@@ -1213,13 +1213,13 @@ void StateGameLoop()
 
		}
 

	
 
		CheckCaches();
 

	
 
		/* All these actions has to be done from OWNER_NONE
 
		 *  for multiplayer compatibility */
 
		Backup<CompanyByte> cur_company(_current_company, OWNER_NONE);
 
		Backup<CompanyByte> cur_company(_current_company, OWNER_NONE, FILE_LINE);
 

	
 
		AnimateAnimatedTiles();
 
		IncreaseDate();
 
		RunTileLoop();
 
		CallVehicleTicks();
 
		CallLandscapeTick();
src/rail_cmd.cpp
Show inline comments
 
@@ -639,13 +639,13 @@ bool FloodHalftile(TileIndex t)
 

	
 
	if (IsSlopeWithOneCornerRaised(tileh)) {
 
		TrackBits lower_track = CornerToTrackBits(OppositeCorner(GetHighestSlopeCorner(tileh)));
 

	
 
		TrackBits to_remove = lower_track & rail_bits;
 
		if (to_remove != 0) {
 
			Backup<CompanyByte> cur_company(_current_company, OWNER_WATER);
 
			Backup<CompanyByte> cur_company(_current_company, OWNER_WATER, FILE_LINE);
 
			flooded = DoCommand(t, 0, FIND_FIRST_BIT(to_remove), DC_EXEC, CMD_REMOVE_SINGLE_RAIL).Succeeded();
 
			cur_company.Restore();
 
			if (!flooded) return flooded; // not yet floodable
 
			rail_bits = rail_bits & ~to_remove;
 
			if (rail_bits == 0) {
 
				MakeShore(t);
src/roadveh_cmd.cpp
Show inline comments
 
@@ -1157,13 +1157,13 @@ static Trackdir FollowPreviousRoadVehicl
 
 * @param r the road bits needed.
 
 * @return true when a track track can be build on 't'
 
 */
 
static bool CanBuildTramTrackOnTile(CompanyID c, TileIndex t, RoadBits r)
 
{
 
	/* The 'current' company is not necessarily the owner of the vehicle. */
 
	Backup<CompanyByte> cur_company(_current_company, c);
 
	Backup<CompanyByte> cur_company(_current_company, c, FILE_LINE);
 

	
 
	CommandCost ret = DoCommand(t, ROADTYPE_TRAM << 4 | r, 0, DC_NONE, CMD_BUILD_ROAD);
 

	
 
	cur_company.Restore();
 
	return ret.Succeeded();
 
}
src/saveload/afterload.cpp
Show inline comments
 
@@ -1568,13 +1568,13 @@ bool AfterLoadGame()
 
				SetWaterClass(t, WATER_CLASS_SEA);
 
			}
 

	
 
			if (IsBuoyTile(t) || IsDriveThroughStopTile(t) || IsTileType(t, MP_WATER)) {
 
				Owner o = GetTileOwner(t);
 
				if (o < MAX_COMPANIES && !Company::IsValidID(o)) {
 
					Backup<CompanyByte> cur_company(_current_company, o);
 
					Backup<CompanyByte> cur_company(_current_company, o, FILE_LINE);
 
					ChangeTileOwner(t, o, INVALID_OWNER);
 
					cur_company.Restore();
 
				}
 
				if (IsBuoyTile(t)) {
 
					/* reset buoy owner to OWNER_NONE in the station struct
 
					 * (even if it is owned by active company) */
src/town_cmd.cpp
Show inline comments
 
@@ -513,13 +513,13 @@ static void TileLoop_Town(TileIndex tile
 
			if (_economy.fluct <= 0) amt = (amt + 1) >> 1;
 
			t->new_max_mail += amt;
 
			t->new_act_mail += MoveGoodsToStation(CT_MAIL, amt, ST_TOWN, t->index, stations.GetStations());
 
		}
 
	}
 

	
 
	Backup<CompanyByte> cur_company(_current_company, OWNER_TOWN);
 
	Backup<CompanyByte> cur_company(_current_company, OWNER_TOWN, FILE_LINE);
 

	
 
	if ((hs->building_flags & BUILDING_HAS_1_TILE) &&
 
			HasBit(t->flags, TOWN_IS_FUNDED) &&
 
			CanDeleteHouse(tile) &&
 
			GetHouseAge(tile) >= hs->minimum_life &&
 
			--t->time_until_rebuild == 0) {
 
@@ -1294,13 +1294,13 @@ static bool GrowTown(Town *t)
 
		{ 2,  2},
 
		{ 2, -2},
 
		{ 0,  0}
 
	};
 

	
 
	/* Current "company" is a town */
 
	Backup<CompanyByte> cur_company(_current_company, OWNER_TOWN);
 
	Backup<CompanyByte> cur_company(_current_company, OWNER_TOWN, FILE_LINE);
 

	
 
	TileIndex tile = t->xy; // The tile we are working with ATM
 

	
 
	/* Find a road that we can base the construction on. */
 
	const TileIndexDiffC *ptr;
 
	for (ptr = _town_coord_mod; ptr != endof(_town_coord_mod); ++ptr) {
 
@@ -2380,13 +2380,13 @@ static bool DoBuildStatueOfCompany(TileI
 
	if (!IsTileType(tile, MP_HOUSE) &&
 
			!IsTileType(tile, MP_CLEAR) &&
 
			!IsTileType(tile, MP_TREES)) {
 
		return false;
 
	}
 

	
 
	Backup<CompanyByte> cur_company(_current_company, OWNER_NONE);
 
	Backup<CompanyByte> cur_company(_current_company, OWNER_NONE, FILE_LINE);
 
	CommandCost r = DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
 
	cur_company.Restore();
 

	
 
	if (r.Failed()) return false;
 

	
 
	MakeStatue(tile, _current_company, town_id);
src/vehicle.cpp
Show inline comments
 
@@ -770,13 +770,13 @@ void CallVehicleTicks()
 

	
 
				/* Play an alterate running sound every 16 ticks */
 
				if (GB(v->tick_counter, 0, 4) == 0) PlayVehicleSound(v, v->cur_speed > 0 ? VSE_RUNNING_16 : VSE_STOPPED_16);
 
		}
 
	}
 

	
 
	Backup<CompanyByte> cur_company(_current_company);
 
	Backup<CompanyByte> cur_company(_current_company, FILE_LINE);
 
	for (AutoreplaceMap::iterator it = _vehicles_to_autoreplace.Begin(); it != _vehicles_to_autoreplace.End(); it++) {
 
		v = it->first;
 
		/* Autoreplace needs the current company set as the vehicle owner */
 
		cur_company.Change(v->owner);
 

	
 
		/* Start vehicle if we stopped them in VehicleEnteredDepotThisTick()
 
@@ -1109,13 +1109,13 @@ void VehicleEnterDepot(Vehicle *v)
 
				(v->type == VEH_AIRCRAFT ? t.GetDestination() != GetStationIndex(v->tile) : v->dest_tile != v->tile)) {
 
			/* We are heading for another depot, keep driving. */
 
			return;
 
		}
 

	
 
		if (t.IsRefit()) {
 
			Backup<CompanyByte> cur_company(_current_company, v->owner);
 
			Backup<CompanyByte> cur_company(_current_company, v->owner, FILE_LINE);
 
			CommandCost cost = DoCommand(v->tile, v->index, t.GetRefitCargo() | t.GetRefitSubtype() << 8, DC_EXEC, GetCmdRefitVeh(v));
 
			cur_company.Restore();
 

	
 
			if (cost.Failed()) {
 
				_vehicles_to_autoreplace[v] = false;
 
				if (v->owner == _local_company) {
src/water_cmd.cpp
Show inline comments
 
@@ -879,13 +879,13 @@ static FloodingBehaviour GetFloodingBeha
 
void DoFloodTile(TileIndex target)
 
{
 
	assert(!IsTileType(target, MP_WATER));
 

	
 
	bool flooded = false; // Will be set to true if something is changed.
 

	
 
	Backup<CompanyByte> cur_company(_current_company, OWNER_WATER);
 
	Backup<CompanyByte> cur_company(_current_company, OWNER_WATER, FILE_LINE);
 

	
 
	Slope tileh = GetTileSlope(target, NULL);
 
	if (tileh != SLOPE_FLAT) {
 
		/* make coast.. */
 
		switch (GetTileType(target)) {
 
			case MP_RAILWAY: {
 
@@ -939,13 +939,13 @@ void DoFloodTile(TileIndex target)
 

	
 
/**
 
 * Drys a tile up.
 
 */
 
static void DoDryUp(TileIndex tile)
 
{
 
	Backup<CompanyByte> cur_company(_current_company, OWNER_WATER);
 
	Backup<CompanyByte> cur_company(_current_company, OWNER_WATER, FILE_LINE);
 

	
 
	switch (GetTileType(tile)) {
 
		case MP_RAILWAY:
 
			assert(IsPlainRail(tile));
 
			assert(GetRailGroundType(tile) == RAIL_GROUND_WATER);
 

	
0 comments (0 inline, 0 general)