Changeset - r23953:ba75d2f3b530
[Not reviewed]
src/ai/ai_core.cpp
Show inline comments
 
@@ -72,14 +72,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<CompanyID> cur_company(_current_company, FILE_LINE);
 
	const Company *c;
 
	FOR_ALL_COMPANIES(c) {
 
	for (const Company *c : Company::Iterate()) {
 
		if (c->is_ai) {
 
			PerformanceMeasurer framerate((PerformanceElement)(PFE_AI0 + c->index));
 
			cur_company.Change(c->index);
 
			c->ai_instance->GameLoop();
 
		} else {
 
			PerformanceMeasurer::SetInactive((PerformanceElement)(PFE_AI0 + c->index));
 
@@ -151,14 +150,13 @@
 

	
 
/* static */ void AI::KillAll()
 
{
 
	/* It might happen there are no companies .. than we have nothing to loop */
 
	if (Company::GetPoolSize() == 0) return;
 

	
 
	const Company *c;
 
	FOR_ALL_COMPANIES(c) {
 
	for (const Company *c : Company::Iterate()) {
 
		if (c->is_ai) AI::Stop(c->index);
 
	}
 
}
 

	
 
/* static */ void AI::Initialize()
 
{
src/ai/ai_gui.cpp
Show inline comments
 
@@ -1049,14 +1049,13 @@ struct AIDebugWindow : public Window {
 
	{
 
		/* Check if the currently selected company is still active. */
 
		if (this->IsValidDebugCompany(ai_debug_company)) return;
 

	
 
		ai_debug_company = INVALID_COMPANY;
 

	
 
		const Company *c;
 
		FOR_ALL_COMPANIES(c) {
 
		for (const Company *c : Company::Iterate()) {
 
			if (c->is_ai) {
 
				ChangeToAI(c->index);
 
				return;
 
			}
 
		}
 

	
 
@@ -1309,14 +1308,13 @@ struct AIDebugWindow : public Window {
 
				}
 

	
 
				/* If the last AI/Game Script is unpaused, unpause the game too. */
 
				if ((_pause_mode & PM_PAUSED_NORMAL) == PM_PAUSED_NORMAL) {
 
					bool all_unpaused = !Game::IsPaused();
 
					if (all_unpaused) {
 
						Company *c;
 
						FOR_ALL_COMPANIES(c) {
 
						for (const Company *c : Company::Iterate()) {
 
							if (c->is_ai && AI::IsPaused(c->index)) {
 
								all_unpaused = false;
 
								break;
 
							}
 
						}
 
						if (all_unpaused) {
 
@@ -1549,14 +1547,13 @@ void InitializeAIGui()
 
/** Open the AI debug window if one of the AI scripts has crashed. */
 
void ShowAIDebugWindowIfAIError()
 
{
 
	/* Network clients can't debug AIs. */
 
	if (_networking && !_network_server) return;
 

	
 
	Company *c;
 
	FOR_ALL_COMPANIES(c) {
 
	for (const Company *c : Company::Iterate()) {
 
		if (c->is_ai && c->ai_instance->IsDead()) {
 
			ShowAIDebugWindow(c->index);
 
			break;
 
		}
 
	}
 

	
src/company_base.h
Show inline comments
 
@@ -165,15 +165,12 @@ struct Company : CompanyPool::PoolItem<&
 
		return !Company::Get(index)->is_ai;
 
	}
 

	
 
	static void PostDestructor(size_t index);
 
};
 

	
 
#define FOR_ALL_COMPANIES_FROM(var, start) FOR_ALL_ITEMS_FROM(Company, company_index, var, start)
 
#define FOR_ALL_COMPANIES(var) FOR_ALL_COMPANIES_FROM(var, 0)
 

	
 
Money CalculateCompanyValue(const Company *c, bool including_loan = true);
 

	
 
extern uint _next_competitor_start;
 
extern uint _cur_company_tick_index;
 

	
 
#endif /* COMPANY_BASE_H */
src/company_cmd.cpp
Show inline comments
 
@@ -260,14 +260,13 @@ void SubtractMoneyFromCompanyFract(Compa
 
	if (cost != 0) SubtractMoneyFromAnyCompany(c, CommandCost(cst.GetExpensesType(), cost));
 
}
 

	
 
/** Update the landscaping limits per company. */
 
void UpdateLandscapingLimits()
 
{
 
	Company *c;
 
	FOR_ALL_COMPANIES(c) {
 
	for (Company *c : Company::Iterate()) {
 
		c->terraform_limit = min(c->terraform_limit + _settings_game.construction.terraform_per_64k_frames, (uint32)_settings_game.construction.terraform_frame_burst << 16);
 
		c->clear_limit     = min(c->clear_limit     + _settings_game.construction.clear_per_64k_frames,     (uint32)_settings_game.construction.clear_frame_burst << 16);
 
		c->tree_limit      = min(c->tree_limit      + _settings_game.construction.tree_per_64k_frames,      (uint32)_settings_game.construction.tree_frame_burst << 16);
 
	}
 
}
 

	
 
@@ -357,14 +356,13 @@ static void GenerateCompanyName(Company 
 
	if (t->name == nullptr && IsInsideMM(t->townnametype, SPECSTR_TOWNNAME_START, SPECSTR_TOWNNAME_LAST + 1)) {
 
		str = t->townnametype - SPECSTR_TOWNNAME_START + SPECSTR_COMPANY_NAME_START;
 
		strp = t->townnameparts;
 

	
 
verify_name:;
 
		/* No companies must have this name already */
 
		Company *cc;
 
		FOR_ALL_COMPANIES(cc) {
 
		for (const Company *cc : Company::Iterate()) {
 
			if (cc->name_1 == str && cc->name_2 == strp) goto bad_town_name;
 
		}
 

	
 
		GetString(buffer, str, lastof(buffer));
 
		if (Utf8StringLength(buffer) >= MAX_LENGTH_COMPANY_NAME_CHARS) goto bad_town_name;
 

	
 
@@ -444,14 +442,13 @@ static Colours GenerateCompanyColour()
 
				Swap(colours[j - 1], colours[j]);
 
			}
 
		}
 
	}
 

	
 
	/* Move the colours that look similar to each company's colour to the side */
 
	Company *c;
 
	FOR_ALL_COMPANIES(c) {
 
	for (const Company *c : Company::Iterate()) {
 
		Colours pcolour = (Colours)c->colour;
 

	
 
		for (uint i = 0; i < COLOUR_END; i++) {
 
			if (colours[i] == pcolour) {
 
				colours[i] = INVALID_COLOUR;
 
				break;
 
@@ -491,14 +488,13 @@ restart:;
 
		 * to detect too long president name. */
 
		char buffer[(MAX_LENGTH_PRESIDENT_NAME_CHARS + 1) * MAX_CHAR_LENGTH];
 
		SetDParam(0, c->index);
 
		GetString(buffer, STR_PRESIDENT_NAME, lastof(buffer));
 
		if (Utf8StringLength(buffer) >= MAX_LENGTH_PRESIDENT_NAME_CHARS) continue;
 

	
 
		Company *cc;
 
		FOR_ALL_COMPANIES(cc) {
 
		for (const Company *cc : Company::Iterate()) {
 
			if (c != cc) {
 
				/* Reserve extra space so even overlength president names can be compared. */
 
				char buffer2[(MAX_LENGTH_PRESIDENT_NAME_CHARS + 1) * MAX_CHAR_LENGTH];
 
				SetDParam(0, cc->index);
 
				GetString(buffer2, STR_PRESIDENT_NAME, lastof(buffer2));
 
				if (strcmp(buffer2, buffer) == 0) goto restart;
 
@@ -595,17 +591,15 @@ void StartupCompanies()
 

	
 
/** Start a new competitor company if possible. */
 
static bool MaybeStartNewCompany()
 
{
 
	if (_networking && Company::GetNumItems() >= _settings_client.network.max_companies) return false;
 

	
 
	Company *c;
 

	
 
	/* count number of competitors */
 
	uint n = 0;
 
	FOR_ALL_COMPANIES(c) {
 
	for (const Company *c : Company::Iterate()) {
 
		if (c->is_ai) n++;
 
	}
 

	
 
	if (n < (uint)_settings_game.difficulty.max_no_competitors) {
 
		/* Send a command to all clients to start up a new AI.
 
		 * Works fine for Multiplayer and Singleplayer */
 
@@ -668,17 +662,17 @@ static void HandleBankruptcyTakeover(Com
 
		return;
 
	}
 

	
 
	/* Did we ask everyone for bankruptcy? If so, bail out. */
 
	if (c->bankrupt_asked == MAX_UVALUE(CompanyMask)) return;
 

	
 
	Company *c2, *best = nullptr;
 
	Company *best = nullptr;
 
	int32 best_performance = -1;
 

	
 
	/* Ask the company with the highest performance history first */
 
	FOR_ALL_COMPANIES(c2) {
 
	for (Company *c2 : Company::Iterate()) {
 
		if (c2->bankrupt_asked == 0 && // Don't ask companies going bankrupt themselves
 
				!HasBit(c->bankrupt_asked, c2->index) &&
 
				best_performance < c2->old_economy[1].performance_history &&
 
				MayCompanyTakeOver(c2->index, c->index)) {
 
			best_performance = c2->old_economy[1].performance_history;
 
			best = c2;
 
@@ -734,24 +728,22 @@ void OnTick_Companies()
 
/**
 
 * A year has passed, update the economic data of all companies, and perhaps show the
 
 * financial overview window of the local company.
 
 */
 
void CompaniesYearlyLoop()
 
{
 
	Company *c;
 

	
 
	/* Copy statistics */
 
	FOR_ALL_COMPANIES(c) {
 
	for (Company *c : Company::Iterate()) {
 
		memmove(&c->yearly_expenses[1], &c->yearly_expenses[0], sizeof(c->yearly_expenses) - sizeof(c->yearly_expenses[0]));
 
		memset(&c->yearly_expenses[0], 0, sizeof(c->yearly_expenses[0]));
 
		SetWindowDirty(WC_FINANCES, c->index);
 
	}
 

	
 
	if (_settings_client.gui.show_finances && _local_company != COMPANY_SPECTATOR) {
 
		ShowCompanyFinances(_local_company);
 
		c = Company::Get(_local_company);
 
		Company *c = Company::Get(_local_company);
 
		if (c->num_valid_stat_ent > 5 && c->old_economy[0].performance_history < c->old_economy[4].performance_history) {
 
			if (_settings_client.sound.new_year) SndPlayFx(SND_01_BAD_YEAR);
 
		} else {
 
			if (_settings_client.sound.new_year) SndPlayFx(SND_00_GOOD_YEAR);
 
		}
 
	}
 
@@ -968,14 +960,13 @@ CommandCost CmdSetCompanyColour(TileInde
 
	if (scheme == LS_DEFAULT && colour == INVALID_COLOUR) return CMD_ERROR;
 

	
 
	Company *c = Company::Get(_current_company);
 

	
 
	/* Ensure no two companies have the same primary colour */
 
	if (scheme == LS_DEFAULT && !second) {
 
		const Company *cc;
 
		FOR_ALL_COMPANIES(cc) {
 
		for (const Company *cc : Company::Iterate()) {
 
			if (cc != c && cc->colour == colour) return CMD_ERROR;
 
		}
 
	}
 

	
 
	if (flags & DC_EXEC) {
 
		if (!second) {
 
@@ -1050,15 +1041,13 @@ CommandCost CmdSetCompanyColour(TileInde
 
 * Is the given name in use as name of a company?
 
 * @param name Name to search.
 
 * @return \c true if the name us unique (that is, not in use), else \c false.
 
 */
 
static bool IsUniqueCompanyName(const char *name)
 
{
 
	const Company *c;
 

	
 
	FOR_ALL_COMPANIES(c) {
 
	for (const Company *c : Company::Iterate()) {
 
		if (c->name != nullptr && strcmp(c->name, name) == 0) return false;
 
	}
 

	
 
	return true;
 
}
 

	
 
@@ -1095,15 +1084,13 @@ CommandCost CmdRenameCompany(TileIndex t
 
 * Is the given name in use as president name of a company?
 
 * @param name Name to search.
 
 * @return \c true if the name us unique (that is, not in use), else \c false.
 
 */
 
static bool IsUniquePresidentName(const char *name)
 
{
 
	const Company *c;
 

	
 
	FOR_ALL_COMPANIES(c) {
 
	for (const Company *c : Company::Iterate()) {
 
		if (c->president_name != nullptr && strcmp(c->president_name, name) == 0) return false;
 
	}
 

	
 
	return true;
 
}
 

	
src/company_gui.cpp
Show inline comments
 
@@ -571,13 +571,13 @@ private:
 
		const Livery *livery, *default_livery = nullptr;
 
		bool primary = widget == WID_SCL_PRI_COL_DROPDOWN;
 
		byte default_col;
 

	
 
		/* Disallow other company colours for the primary colour */
 
		if (this->livery_class < LC_GROUP_RAIL && HasBit(this->sel, LS_DEFAULT) && primary) {
 
			FOR_ALL_COMPANIES(c) {
 
			for (const Company *c : Company::Iterate()) {
 
				if (c->index != _local_company) SetBit(used_colours, c->colour);
 
			}
 
		}
 

	
 
		c = Company::Get((CompanyID)this->window_number);
 

	
 
@@ -2393,15 +2393,13 @@ struct CompanyWindow : Window
 
				size->width = max(size->width, GetStringBoundingBox(STR_COMPANY_VIEW_INFRASTRUCTURE_STATION).width);
 
				size->width = max(size->width, GetStringBoundingBox(STR_COMPANY_VIEW_INFRASTRUCTURE_AIRPORT).width);
 
				size->width = max(size->width, GetStringBoundingBox(STR_COMPANY_VIEW_INFRASTRUCTURE_NONE).width);
 
				break;
 

	
 
			case WID_C_DESC_OWNERS: {
 
				const Company *c2;
 

	
 
				FOR_ALL_COMPANIES(c2) {
 
				for (const Company *c2 : Company::Iterate()) {
 
					SetDParamMaxValue(0, 75);
 
					SetDParam(1, c2->index);
 

	
 
					size->width = max(size->width, GetStringBoundingBox(STR_COMPANY_VIEW_SHARES_OWNED_BY).width);
 
				}
 
				break;
 
@@ -2497,16 +2495,15 @@ struct CompanyWindow : Window
 
				}
 

	
 
				break;
 
			}
 

	
 
			case WID_C_DESC_OWNERS: {
 
				const Company *c2;
 
				uint y = r.top;
 

	
 
				FOR_ALL_COMPANIES(c2) {
 
				for (const Company *c2 : Company::Iterate()) {
 
					uint amt = GetAmountOwnedBy(c, c2->index);
 
					if (amt != 0) {
 
						SetDParam(0, amt * 25);
 
						SetDParam(1, c2->index);
 

	
 
						DrawString(r.left, r.right, y, STR_COMPANY_VIEW_SHARES_OWNED_BY);
src/console_cmds.cpp
Show inline comments
 
@@ -1139,15 +1139,14 @@ DEF_CONSOLE_CMD(ConStartAI)
 
	if (!AI::CanStartNew()) {
 
		IConsoleWarning("Can't start a new AI.");
 
		return true;
 
	}
 

	
 
	int n = 0;
 
	Company *c;
 
	/* Find the next free slot */
 
	FOR_ALL_COMPANIES(c) {
 
	for (const Company *c : Company::Iterate()) {
 
		if (c->index != n) break;
 
		n++;
 
	}
 

	
 
	AIConfig *config = AIConfig::GetConfig((CompanyID)n);
 
	if (argc >= 2) {
 
@@ -1532,14 +1531,13 @@ DEF_CONSOLE_CMD(ConCompanies)
 
{
 
	if (argc == 0) {
 
		IConsoleHelp("List the details of all companies in the game. Usage 'companies'");
 
		return true;
 
	}
 

	
 
	Company *c;
 
	FOR_ALL_COMPANIES(c) {
 
	for (const Company *c : Company::Iterate()) {
 
		/* Grab the company name */
 
		char company_name[512];
 
		SetDParam(0, c->index);
 
		GetString(company_name, STR_COMPANY_NAME, lastof(company_name));
 

	
 
		const char *password_state = "";
src/crashlog.cpp
Show inline comments
 
@@ -190,14 +190,13 @@ char *CrashLog::LogConfiguration(char *b
 
			FontCache::Get(FS_NORMAL)->GetFontName(),
 
			FontCache::Get(FS_LARGE)->GetFontName(),
 
			FontCache::Get(FS_MONO)->GetFontName()
 
	);
 

	
 
	buffer += seprintf(buffer, last, "AI Configuration (local: %i) (current: %i):\n", (int)_local_company, (int)_current_company);
 
	const Company *c;
 
	FOR_ALL_COMPANIES(c) {
 
	for (const Company *c : Company::Iterate()) {
 
		if (c->ai_info == nullptr) {
 
			buffer += seprintf(buffer, last, " %2i: Human\n", (int)c->index);
 
		} else {
 
			buffer += seprintf(buffer, last, " %2i: %s (v%d)\n", (int)c->index, c->ai_info->GetName(), c->ai_info->GetVersion());
 
		}
 
	}
src/economy.cpp
Show inline comments
 
@@ -294,14 +294,13 @@ void ChangeOwnershipOfCompanyItems(Owner
 
	if (_networking) NetworkClientsToSpectators(old_owner);
 
	if (old_owner == _local_company) {
 
		/* Single player cheated to AI company.
 
		 * There are no spectators in single player, so we must pick some other company. */
 
		assert(!_networking);
 
		Backup<CompanyID> cur_company2(_current_company, FILE_LINE);
 
		Company *c;
 
		FOR_ALL_COMPANIES(c) {
 
		for (const Company *c : Company::Iterate()) {
 
			if (c->index != old_owner) {
 
				SetLocalCompany(c->index);
 
				break;
 
			}
 
		}
 
		cur_company2.Restore();
 
@@ -310,17 +309,16 @@ void ChangeOwnershipOfCompanyItems(Owner
 

	
 
	Town *t;
 

	
 
	assert(old_owner != new_owner);
 

	
 
	{
 
		Company *c;
 
		uint i;
 

	
 
		/* See if the old_owner had shares in other companies */
 
		FOR_ALL_COMPANIES(c) {
 
		for (const Company *c : Company::Iterate()) {
 
			for (i = 0; i < 4; i++) {
 
				if (c->share_owners[i] == old_owner) {
 
					/* Sell his shares */
 
					CommandCost res = DoCommand(0, c->index, 0, DC_EXEC | DC_BANKRUPT, CMD_SELL_SHARE_IN_COMPANY);
 
					/* Because we are in a DoCommand, we can't just execute another one and
 
					 *  expect the money to be removed. We need to do it ourself! */
 
@@ -328,13 +326,13 @@ void ChangeOwnershipOfCompanyItems(Owner
 
				}
 
			}
 
		}
 

	
 
		/* Sell all the shares that people have on this company */
 
		Backup<CompanyID> cur_company2(_current_company, FILE_LINE);
 
		c = Company::Get(old_owner);
 
		const Company *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 | DC_BANKRUPT, CMD_SELL_SHARE_IN_COMPANY);
 
				/* Because we are in a DoCommand, we can't just execute another one and
 
@@ -655,14 +653,13 @@ static void CompanyCheckBankrupt(Company
 
 * Update the finances of all companies.
 
 * Pay for the stations, update the history graph, update ratings and company values, and deal with bankruptcy.
 
 */
 
static void CompaniesGenStatistics()
 
{
 
	/* Check for bankruptcy each month */
 
	Company *c;
 
	FOR_ALL_COMPANIES(c) {
 
	for (Company *c : Company::Iterate()) {
 
		CompanyCheckBankrupt(c);
 
	}
 

	
 
	Backup<CompanyID> cur_company(_current_company, FILE_LINE);
 

	
 
	if (!_settings_game.economy.infrastructure_maintenance) {
 
@@ -671,13 +668,13 @@ static void CompaniesGenStatistics()
 
			cur_company.Change(st->owner);
 
			CommandCost cost(EXPENSES_PROPERTY, _price[PR_STATION_VALUE] >> 1);
 
			SubtractMoneyFromCompany(cost);
 
		}
 
	} else {
 
		/* Improved monthly infrastructure costs. */
 
		FOR_ALL_COMPANIES(c) {
 
		for (const Company *c : Company::Iterate()) {
 
			cur_company.Change(c->index);
 

	
 
			CommandCost cost(EXPENSES_PROPERTY);
 
			uint32 rail_total = c->infrastructure.GetRailTotal();
 
			for (RailType rt = RAILTYPE_BEGIN; rt < RAILTYPE_END; rt++) {
 
				if (c->infrastructure.rail[rt] != 0) cost.AddCost(RailMaintenanceCost(rt, c->infrastructure.rail[rt], rail_total));
 
@@ -697,13 +694,13 @@ static void CompaniesGenStatistics()
 
	}
 
	cur_company.Restore();
 

	
 
	/* Only run the economic statics and update company stats every 3rd month (1st of quarter). */
 
	if (!HasBit(1 << 0 | 1 << 3 | 1 << 6 | 1 << 9, _cur_month)) return;
 

	
 
	FOR_ALL_COMPANIES(c) {
 
	for (Company *c : Company::Iterate()) {
 
		/* Drop the oldest history off the end */
 
		std::copy_backward(c->old_economy, c->old_economy + MAX_HISTORY_QUARTERS - 1, c->old_economy + MAX_HISTORY_QUARTERS);
 
		c->old_economy[0] = c->cur_economy;
 
		c->cur_economy = {};
 

	
 
		if (c->num_valid_stat_ent != MAX_HISTORY_QUARTERS) c->num_valid_stat_ent++;
 
@@ -830,16 +827,14 @@ void RecomputePrices()
 
	InvalidateWindowData(WC_PAYMENT_RATES, 0);
 
}
 

	
 
/** Let all companies pay the monthly interest on their loan. */
 
static void CompaniesPayInterest()
 
{
 
	const Company *c;
 

	
 
	Backup<CompanyID> cur_company(_current_company, FILE_LINE);
 
	FOR_ALL_COMPANIES(c) {
 
	for (const Company *c : Company::Iterate()) {
 
		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.
 
		 * To easily calculate what one should pay "this" month, you calculate
src/elrail.cpp
Show inline comments
 
@@ -588,13 +588,12 @@ void DrawRailCatenary(const TileInfo *ti
 
	}
 
	DrawRailCatenaryRailway(ti);
 
}
 

	
 
bool SettingsDisableElrail(int32 p1)
 
{
 
	Company *c;
 
	Train *t;
 
	bool disable = (p1 != 0);
 

	
 
	/* we will now walk through all electric train engines and change their railtypes if it is the wrong one*/
 
	const RailType old_railtype = disable ? RAILTYPE_ELECTRIC : RAILTYPE_RAIL;
 
	const RailType new_railtype = disable ? RAILTYPE_RAIL : RAILTYPE_ELECTRIC;
 
@@ -629,13 +628,13 @@ bool SettingsDisableElrail(int32 p1)
 
		/* power and acceleration is cached only for front engines */
 
		if (t->IsFrontEngine()) {
 
			t->ConsistChanged(CCF_TRACK);
 
		}
 
	}
 

	
 
	FOR_ALL_COMPANIES(c) c->avail_railtypes = GetCompanyRailtypes(c->index);
 
	for (Company *c : Company::Iterate()) c->avail_railtypes = GetCompanyRailtypes(c->index);
 

	
 
	/* This resets the _last_built_railtype, which will be invalid for electric
 
	 * rails. It may have unintended consequences if that function is ever
 
	 * extended, though. */
 
	ReinitGuiAfterToggleElrail(disable);
 
	return true;
src/engine.cpp
Show inline comments
 
@@ -700,14 +700,13 @@ void StartupEngines()
 

	
 
	FOR_ALL_ENGINES(e) {
 
		StartupOneEngine(e, aging_date);
 
	}
 

	
 
	/* Update the bitmasks for the vehicle lists */
 
	Company *c;
 
	FOR_ALL_COMPANIES(c) {
 
	for (Company *c : Company::Iterate()) {
 
		c->avail_railtypes = GetCompanyRailtypes(c->index);
 
		c->avail_roadtypes = GetCompanyRoadTypes(c->index);
 
	}
 

	
 
	/* Invalidate any open purchase lists */
 
	InvalidateWindowClassesData(WC_BUILD_VEHICLE);
 
@@ -760,14 +759,13 @@ static CompanyID GetPreviewCompany(Engin
 
	CompanyID best_company = INVALID_COMPANY;
 

	
 
	/* For trains the cargomask has no useful meaning, since you can attach other wagons */
 
	CargoTypes cargomask = e->type != VEH_TRAIN ? GetUnionOfArticulatedRefitMasks(e->index, true) : ALL_CARGOTYPES;
 

	
 
	int32 best_hist = -1;
 
	const Company *c;
 
	FOR_ALL_COMPANIES(c) {
 
	for (const Company *c : Company::Iterate()) {
 
		if (c->block_preview == 0 && !HasBit(e->preview_asked, c->index) &&
 
				c->old_economy[0].performance_history > best_hist) {
 

	
 
			/* Check whether the company uses similar vehicles */
 
			Vehicle *v;
 
			FOR_ALL_VEHICLES(v) {
 
@@ -803,14 +801,13 @@ static bool IsVehicleTypeDisabled(Vehicl
 
	}
 
}
 

	
 
/** Daily check to offer an exclusive engine preview to the companies. */
 
void EnginesDailyLoop()
 
{
 
	Company *c;
 
	FOR_ALL_COMPANIES(c) {
 
	for (Company *c : Company::Iterate()) {
 
		c->avail_railtypes = AddDateIntroducedRailTypes(c->avail_railtypes, _date);
 
		c->avail_roadtypes = AddDateIntroducedRoadTypes(c->avail_roadtypes, _date);
 
	}
 

	
 
	if (_cur_year >= _year_engine_aging_stops) return;
 

	
 
@@ -905,19 +902,18 @@ CommandCost CmdWantEnginePreview(TileInd
 
 * Also handle the exclusive engine preview contract.
 
 * @param e Engine generally available as of now.
 
 */
 
static void NewVehicleAvailable(Engine *e)
 
{
 
	Vehicle *v;
 
	Company *c;
 
	EngineID index = e->index;
 

	
 
	/* In case the company didn't build the vehicle during the intro period,
 
	 * prevent that company from getting future intro periods for a while. */
 
	if (e->flags & ENGINE_EXCLUSIVE_PREVIEW) {
 
		FOR_ALL_COMPANIES(c) {
 
		for (Company *c : Company::Iterate()) {
 
			uint block_preview = c->block_preview;
 

	
 
			if (!HasBit(e->company_avail, c->index)) continue;
 

	
 
			/* We assume the user did NOT build it.. prove me wrong ;) */
 
			c->block_preview = 20;
 
@@ -945,17 +941,17 @@ static void NewVehicleAvailable(Engine *
 
	if (IsWagon(index)) return;
 

	
 
	if (e->type == VEH_TRAIN) {
 
		/* maybe make another rail type available */
 
		RailType railtype = e->u.rail.railtype;
 
		assert(railtype < RAILTYPE_END);
 
		FOR_ALL_COMPANIES(c) c->avail_railtypes = AddDateIntroducedRailTypes(c->avail_railtypes | GetRailTypeInfo(e->u.rail.railtype)->introduces_railtypes, _date);
 
		for (Company *c : Company::Iterate()) c->avail_railtypes = AddDateIntroducedRailTypes(c->avail_railtypes | GetRailTypeInfo(e->u.rail.railtype)->introduces_railtypes, _date);
 
	} else if (e->type == VEH_ROAD) {
 
		/* maybe make another road type available */
 
		assert(e->u.road.roadtype < ROADTYPE_END);
 
		FOR_ALL_COMPANIES(c) c->avail_roadtypes = AddDateIntroducedRoadTypes(c->avail_roadtypes | GetRoadTypeInfo(e->u.road.roadtype)->introduces_roadtypes, _date);
 
		for (Company* c : Company::Iterate()) c->avail_roadtypes = AddDateIntroducedRoadTypes(c->avail_roadtypes | GetRoadTypeInfo(e->u.road.roadtype)->introduces_roadtypes, _date);
 
	}
 

	
 
	/* Only broadcast event if AIs are able to build this vehicle type. */
 
	if (!IsVehicleTypeDisabled(e->type, true)) AI::BroadcastNewEvent(new ScriptEventEngineAvailable(index));
 

	
 
	/* Only provide the "New Vehicle available" news paper entry, if engine can be built. */
src/graph_gui.cpp
Show inline comments
 
@@ -564,14 +564,13 @@ public:
 
		/* Exclude the companies which aren't valid */
 
		for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; c++) {
 
			if (!Company::IsValidID(c)) SetBit(excluded_companies, c);
 
		}
 

	
 
		byte nums = 0;
 
		const Company *c;
 
		FOR_ALL_COMPANIES(c) {
 
		for (const Company *c : Company::Iterate()) {
 
			nums = min(this->num_vert_lines, max(nums, c->num_valid_stat_ent));
 
		}
 

	
 
		int mo = (_cur_month / 3 - nums) * 3;
 
		int yr = _cur_year;
 
		while (mo < 0) {
 
@@ -589,13 +588,13 @@ public:
 
		this->num_on_x_axis = nums;
 
		this->year = yr;
 
		this->month = mo;
 

	
 
		int numd = 0;
 
		for (CompanyID k = COMPANY_FIRST; k < MAX_COMPANIES; k++) {
 
			c = Company::GetIfValid(k);
 
			const Company *c = Company::GetIfValid(k);
 
			if (c != nullptr) {
 
				this->colours[numd] = _colour_gradient[c->colour][6];
 
				for (int j = this->num_on_x_axis, i = 0; --j >= 0;) {
 
					this->cost[numd][i] = (j >= c->num_valid_stat_ent) ? INVALID_DATAPOINT : GetGraphData(c, j);
 
					i++;
 
				}
 
@@ -1133,14 +1132,13 @@ private:
 
	void BuildCompanyList()
 
	{
 
		if (!this->companies.NeedRebuild()) return;
 

	
 
		this->companies.clear();
 

	
 
		const Company *c;
 
		FOR_ALL_COMPANIES(c) {
 
		for (const Company *c : Company::Iterate()) {
 
			this->companies.push_back(c);
 
		}
 

	
 
		this->companies.shrink_to_fit();
 
		this->companies.RebuildDone();
 
	}
 
@@ -1216,14 +1214,13 @@ public:
 
		}
 

	
 
		Dimension d = GetSpriteSize(SPR_COMPANY_ICON);
 
		this->icon_width = d.width + 2;
 
		this->line_height = max<int>(d.height + 2, FONT_HEIGHT_NORMAL);
 

	
 
		const Company *c;
 
		FOR_ALL_COMPANIES(c) {
 
		for (const Company *c : Company::Iterate()) {
 
			SetDParam(0, c->index);
 
			SetDParam(1, c->index);
 
			SetDParam(2, _performance_titles[widest_title]);
 
			widest_width = max(widest_width, GetStringBoundingBox(STR_COMPANY_LEAGUE_COMPANY_NAME).width);
 
		}
 

	
 
@@ -1296,14 +1293,13 @@ struct PerformanceRatingDetailWindow : W
 
	}
 

	
 
	void UpdateCompanyStats()
 
	{
 
		/* Update all company stats with the current data
 
		 * (this is because _score_info is not saved to a savegame) */
 
		Company *c;
 
		FOR_ALL_COMPANIES(c) {
 
		for (Company *c : Company::Iterate()) {
 
			UpdateCompanyRatingAndValue(c, false);
 
		}
 

	
 
		this->timeout = DAY_TICKS * 5;
 
	}
 

	
 
@@ -1494,14 +1490,13 @@ struct PerformanceRatingDetailWindow : W
 
			/* Raise the widget for the previous selection. */
 
			this->RaiseWidget(this->company + WID_PRD_COMPANY_FIRST);
 
			this->company = INVALID_COMPANY;
 
		}
 

	
 
		if (this->company == INVALID_COMPANY) {
 
			const Company *c;
 
			FOR_ALL_COMPANIES(c) {
 
			for (const Company *c : Company::Iterate()) {
 
				this->company = c->index;
 
				break;
 
			}
 
		}
 

	
 
		/* Make sure the widget is lowered */
src/group_cmd.cpp
Show inline comments
 
@@ -98,14 +98,13 @@ void GroupStatistics::Clear()
 
/**
 
 * Update all caches after loading a game, changing NewGRF, etc.
 
 */
 
/* static */ void GroupStatistics::UpdateAfterLoad()
 
{
 
	/* Set up the engine count for all companies */
 
	Company *c;
 
	FOR_ALL_COMPANIES(c) {
 
	for (Company *c : Company::Iterate()) {
 
		for (VehicleType type = VEH_BEGIN; type < VEH_COMPANY_END; type++) {
 
			c->group_all[type].Clear();
 
			c->group_default[type].Clear();
 
		}
 
	}
 

	
 
@@ -120,13 +119,13 @@ void GroupStatistics::Clear()
 
		if (!v->IsEngineCountable()) continue;
 

	
 
		GroupStatistics::CountEngine(v, 1);
 
		if (v->IsPrimaryVehicle()) GroupStatistics::CountVehicle(v, 1);
 
	}
 

	
 
	FOR_ALL_COMPANIES(c) {
 
	for (const Company *c : Company::Iterate()) {
 
		GroupStatistics::UpdateAutoreplace(c->index);
 
	}
 
}
 

	
 
/**
 
 * Update num_vehicle when adding or removing a vehicle.
 
@@ -180,14 +179,13 @@ void GroupStatistics::Clear()
 
/**
 
 * Recompute the profits for all groups.
 
 */
 
/* static */ void GroupStatistics::UpdateProfits()
 
{
 
	/* Set up the engine count for all companies */
 
	Company *c;
 
	FOR_ALL_COMPANIES(c) {
 
	for (Company *c : Company::Iterate()) {
 
		for (VehicleType type = VEH_BEGIN; type < VEH_COMPANY_END; type++) {
 
			c->group_all[type].ClearProfits();
 
			c->group_default[type].ClearProfits();
 
		}
 
	}
 

	
src/highscore.cpp
Show inline comments
 
@@ -84,19 +84,18 @@ static bool HighScoreSorter(const Compan
 
/**
 
 * Save the highscores in a network game when it has ended
 
 * @return Position of the local company in the highscore list.
 
 */
 
int8 SaveHighScoreValueNetwork()
 
{
 
	const Company *c;
 
	const Company *cl[MAX_COMPANIES];
 
	uint count = 0;
 
	int8 company = -1;
 

	
 
	/* Sort all active companies with the highest score first */
 
	FOR_ALL_COMPANIES(c) cl[count++] = c;
 
	for (const Company *c : Company::Iterate()) cl[count++] = c;
 

	
 
	std::sort(std::begin(cl), std::begin(cl) + count, HighScoreSorter);
 

	
 
	{
 
		uint i;
 

	
src/network/network_admin.cpp
Show inline comments
 
@@ -396,14 +396,13 @@ NetworkRecvStatus ServerNetworkAdminSock
 
	return NETWORK_RECV_STATUS_OKAY;
 
}
 

	
 
/** Send economic information of all companies. */
 
NetworkRecvStatus ServerNetworkAdminSocketHandler::SendCompanyEconomy()
 
{
 
	const Company *company;
 
	FOR_ALL_COMPANIES(company) {
 
	for (const Company *company : Company::Iterate()) {
 
		/* Get the income. */
 
		Money income = 0;
 
		for (uint i = 0; i < lengthof(company->yearly_expenses[0]); i++) {
 
			income -= company->yearly_expenses[0][i];
 
		}
 

	
 
@@ -435,16 +434,14 @@ NetworkRecvStatus ServerNetworkAdminSock
 
NetworkRecvStatus ServerNetworkAdminSocketHandler::SendCompanyStats()
 
{
 
	/* Fetch the latest version of the stats. */
 
	NetworkCompanyStats company_stats[MAX_COMPANIES];
 
	NetworkPopulateCompanyStats(company_stats);
 

	
 
	const Company *company;
 

	
 
	/* Go through all the companies. */
 
	FOR_ALL_COMPANIES(company) {
 
	for (const Company *company : Company::Iterate()) {
 
		Packet *p = new Packet(ADMIN_PACKET_SERVER_COMPANY_STATS);
 

	
 
		/* Send the information. */
 
		p->Send_uint8(company->index);
 

	
 
		for (uint i = 0; i < NETWORK_VEH_END; i++) {
 
@@ -745,19 +742,18 @@ NetworkRecvStatus ServerNetworkAdminSock
 
				}
 
			}
 
			break;
 

	
 
		case ADMIN_UPDATE_COMPANY_INFO:
 
			/* The admin is asking for company info. */
 
			const Company *company;
 
			if (d1 == UINT32_MAX) {
 
				FOR_ALL_COMPANIES(company) {
 
				for (const Company *company : Company::Iterate()) {
 
					this->SendCompanyInfo(company);
 
				}
 
			} else {
 
				company = Company::GetIfValid(d1);
 
				const Company *company = Company::GetIfValid(d1);
 
				if (company != nullptr) this->SendCompanyInfo(company);
 
			}
 
			break;
 

	
 
		case ADMIN_UPDATE_COMPANY_ECONOMY:
 
			/* The admin is requesting economy info. */
src/network/network_server.cpp
Show inline comments
 
@@ -377,16 +377,15 @@ NetworkRecvStatus ServerNetworkGameSocke
 
			strecat(clients[ci->client_playas], client_name, lastof(clients[ci->client_playas]));
 
		}
 
	}
 

	
 
	/* Now send the data */
 

	
 
	Company *company;
 
	Packet *p;
 

	
 
	FOR_ALL_COMPANIES(company) {
 
	for (const Company *company : Company::Iterate()) {
 
		p = new Packet(PACKET_SERVER_COMPANY_INFO);
 

	
 
		p->Send_uint8 (NETWORK_COMPANY_INFO_VERSION);
 
		p->Send_bool  (true);
 
		this->SendCompanyInformation(p, company, &company_stats[company->index]);
 

	
 
@@ -1616,13 +1615,12 @@ static void NetworkCheckRestartMap()
 
 *     2) If a company is protected, protection is disabled after 3 years (for example)
 
 *          (and item 1. happens a year later)
 
 */
 
static void NetworkAutoCleanCompanies()
 
{
 
	const NetworkClientInfo *ci;
 
	const Company *c;
 
	bool clients_in_company[MAX_COMPANIES];
 
	int vehicles_in_company[MAX_COMPANIES];
 

	
 
	if (!_settings_client.network.autoclean_companies) return;
 

	
 
	memset(clients_in_company, 0, sizeof(clients_in_company));
 
@@ -1645,13 +1643,13 @@ static void NetworkAutoCleanCompanies()
 
			if (!Company::IsValidID(v->owner) || !v->IsPrimaryVehicle()) continue;
 
			vehicles_in_company[v->owner]++;
 
		}
 
	}
 

	
 
	/* Go through all the companies */
 
	FOR_ALL_COMPANIES(c) {
 
	for (const Company *c : Company::Iterate()) {
 
		/* Skip the non-active once */
 
		if (c->is_ai) continue;
 

	
 
		if (!clients_in_company[c->index]) {
 
			/* The company is empty for one month more */
 
			_network_company_states[c->index].months_empty++;
src/network/network_udp.cpp
Show inline comments
 
@@ -195,14 +195,13 @@ void ServerNetworkUDPSocketHandler::Rece
 

	
 
		/* At this moment the company names might not fit in the
 
		 * packet. Check whether that is really the case. */
 

	
 
		for (;;) {
 
			int free = SEND_MTU - packet.size;
 
			Company *company;
 
			FOR_ALL_COMPANIES(company) {
 
			for (const Company *company : Company::Iterate()) {
 
				char company_name[NETWORK_COMPANY_NAME_LENGTH];
 
				SetDParam(0, company->index);
 
				GetString(company_name, STR_COMPANY_NAME, company_name + max_cname_length - 1);
 
				free -= MIN_CI_SIZE;
 
				free -= (int)strlen(company_name);
 
			}
 
@@ -211,15 +210,14 @@ void ServerNetworkUDPSocketHandler::Rece
 
			/* Try again, with slightly shorter strings. */
 
			assert(max_cname_length > 0);
 
			max_cname_length--;
 
		}
 
	}
 

	
 
	Company *company;
 
	/* Go through all the companies */
 
	FOR_ALL_COMPANIES(company) {
 
	for (const Company *company : Company::Iterate()) {
 
		/* Send the information */
 
		this->SendCompanyInformation(&packet, company, &company_stats[company->index], max_cname_length);
 
	}
 

	
 
	this->SendPacket(&packet, client_addr);
 
}
src/openttd.cpp
Show inline comments
 
@@ -1204,20 +1204,19 @@ static void CheckCaches()
 
		}
 
		i++;
 
	}
 

	
 
	/* Check company infrastructure cache. */
 
	std::vector<CompanyInfrastructure> old_infrastructure;
 
	Company *c;
 
	FOR_ALL_COMPANIES(c) old_infrastructure.push_back(c->infrastructure);
 
	for (const Company *c : Company::Iterate()) old_infrastructure.push_back(c->infrastructure);
 

	
 
	extern void AfterLoadCompanyStats();
 
	AfterLoadCompanyStats();
 

	
 
	i = 0;
 
	FOR_ALL_COMPANIES(c) {
 
	for (const Company *c : Company::Iterate()) {
 
		if (MemCmpT(old_infrastructure.data() + i, &c->infrastructure) != 0) {
 
			DEBUG(desync, 2, "infrastructure cache mismatch: company %i", (int)c->index);
 
		}
 
		i++;
 
	}
 

	
src/saveload/afterload.cpp
Show inline comments
 
@@ -240,14 +240,13 @@ static void InitializeWindowsAndCaches()
 
	SetupColoursAndInitialWindow();
 

	
 
	/* Update coordinates of the signs. */
 
	UpdateAllVirtCoords();
 
	ResetViewportAfterLoadGame();
 

	
 
	Company *c;
 
	FOR_ALL_COMPANIES(c) {
 
	for (Company *c : Company::Iterate()) {
 
		/* For each company, verify (while loading a scenario) that the inauguration date is the current year and set it
 
		 * accordingly if it is not the case.  No need to set it on companies that are not been used already,
 
		 * thus the MIN_YEAR (which is really nothing more than Zero, initialized value) test */
 
		if (_file_to_saveload.abstract_ftype == FT_SCENARIO && c->inaugurated_year != MIN_YEAR) {
 
			c->inaugurated_year = _cur_year;
 
		}
 
@@ -641,14 +640,13 @@ bool AfterLoadGame()
 
				SetTileOwner(t, OWNER_WATER);
 
			}
 
		}
 
	}
 

	
 
	if (IsSavegameVersionBefore(SLV_84)) {
 
		Company *c;
 
		FOR_ALL_COMPANIES(c) {
 
		for (Company *c : Company::Iterate()) {
 
			c->name = CopyFromOldName(c->name_1);
 
			if (c->name != nullptr) c->name_1 = STR_SV_UNNAMED;
 
			c->president_name = CopyFromOldName(c->president_name_1);
 
			if (c->president_name != nullptr) c->president_name_1 = SPECSTR_PRESIDENT_NAME;
 
		}
 

	
 
@@ -675,14 +673,13 @@ bool AfterLoadGame()
 
		FOR_ALL_STATIONS(st) {
 
			if (st->airport.tile       == 0) st->airport.tile = INVALID_TILE;
 
			if (st->train_station.tile == 0) st->train_station.tile   = INVALID_TILE;
 
		}
 

	
 
		/* the same applies to Company::location_of_HQ */
 
		Company *c;
 
		FOR_ALL_COMPANIES(c) {
 
		for (Company *c : Company::Iterate()) {
 
			if (c->location_of_HQ == 0 || (IsSavegameVersionBefore(SLV_4) && c->location_of_HQ == 0xFFFF)) {
 
				c->location_of_HQ = INVALID_TILE;
 
			}
 
		}
 
	}
 

	
 
@@ -797,14 +794,13 @@ bool AfterLoadGame()
 

	
 
	/* Update all vehicles */
 
	AfterLoadVehicles(true);
 

	
 
	/* Make sure there is an AI attached to an AI company */
 
	{
 
		Company *c;
 
		FOR_ALL_COMPANIES(c) {
 
		for (const Company *c : Company::Iterate()) {
 
			if (c->is_ai && c->ai_instance == nullptr) AI::StartNew(c->index);
 
		}
 
	}
 

	
 
	/* make sure there is a town in the game */
 
	if (_game_mode == GM_NORMAL && Town::GetNumItems() == 0) {
 
@@ -997,27 +993,26 @@ bool AfterLoadGame()
 
		FOR_ALL_TOWNS(t) UpdateTownMaxPass(t);
 
	}
 

	
 
	/* From version 16.0, we included autorenew on engines, which are now saved, but
 
	 *  of course, we do need to initialize them for older savegames. */
 
	if (IsSavegameVersionBefore(SLV_16)) {
 
		Company *c;
 
		FOR_ALL_COMPANIES(c) {
 
		for (Company *c : Company::Iterate()) {
 
			c->engine_renew_list            = nullptr;
 
			c->settings.engine_renew        = false;
 
			c->settings.engine_renew_months = 6;
 
			c->settings.engine_renew_money  = 100000;
 
		}
 

	
 
		/* When loading a game, _local_company is not yet set to the correct value.
 
		 * However, in a dedicated server we are a spectator, so nothing needs to
 
		 * happen. In case we are not a dedicated server, the local company always
 
		 * becomes company 0, unless we are in the scenario editor where all the
 
		 * companies are 'invalid'.
 
		 */
 
		c = Company::GetIfValid(COMPANY_FIRST);
 
		Company *c = Company::GetIfValid(COMPANY_FIRST);
 
		if (!_network_dedicated && c != nullptr) {
 
			c->settings = _settings_client.company;
 
		}
 
	}
 

	
 
	if (IsSavegameVersionBefore(SLV_48)) {
 
@@ -1346,14 +1341,13 @@ bool AfterLoadGame()
 
	}
 

	
 
	/* In version 16.1 of the savegame a company can decide if trains, which get
 
	 * replaced, shall keep their old length. In all prior versions, just default
 
	 * to false */
 
	if (IsSavegameVersionBefore(SLV_16, 1)) {
 
		Company *c;
 
		FOR_ALL_COMPANIES(c) c->settings.renew_keep_length = false;
 
		for (Company *c : Company::Iterate()) c->settings.renew_keep_length = false;
 
	}
 

	
 
	if (IsSavegameVersionBefore(SLV_123)) {
 
		/* Waypoints became subclasses of stations ... */
 
		MoveWaypointsToBaseStations();
 
		/* ... and buoys were moved to waypoints. */
 
@@ -1410,18 +1404,16 @@ bool AfterLoadGame()
 
		}
 
	}
 

	
 
	YapfNotifyTrackLayoutChange(INVALID_TILE, INVALID_TRACK);
 

	
 
	if (IsSavegameVersionBefore(SLV_34)) {
 
		Company *c;
 
		FOR_ALL_COMPANIES(c) ResetCompanyLivery(c);
 
		for (Company *c : Company::Iterate()) ResetCompanyLivery(c);
 
	}
 

	
 
	Company *c;
 
	FOR_ALL_COMPANIES(c) {
 
	for (Company *c : Company::Iterate()) {
 
		c->avail_railtypes = GetCompanyRailtypes(c->index);
 
		c->avail_roadtypes = GetCompanyRoadTypes(c->index);
 
	}
 

	
 
	if (!IsSavegameVersionBefore(SLV_27)) AfterLoadStations();
 

	
 
@@ -1437,13 +1429,13 @@ bool AfterLoadGame()
 
		_date += DAYS_TILL_ORIGINAL_BASE_YEAR;
 
		_cur_year += ORIGINAL_BASE_YEAR;
 

	
 
		FOR_ALL_STATIONS(st)  st->build_date      += DAYS_TILL_ORIGINAL_BASE_YEAR;
 
		FOR_ALL_WAYPOINTS(wp) wp->build_date      += DAYS_TILL_ORIGINAL_BASE_YEAR;
 
		FOR_ALL_ENGINES(e)    e->intro_date       += DAYS_TILL_ORIGINAL_BASE_YEAR;
 
		FOR_ALL_COMPANIES(c)  c->inaugurated_year += ORIGINAL_BASE_YEAR;
 
		for (Company *c : Company::Iterate()) c->inaugurated_year += ORIGINAL_BASE_YEAR;
 
		FOR_ALL_INDUSTRIES(i) i->last_prod_year   += ORIGINAL_BASE_YEAR;
 

	
 
		FOR_ALL_VEHICLES(v) {
 
			v->date_of_last_service += DAYS_TILL_ORIGINAL_BASE_YEAR;
 
			v->build_year += ORIGINAL_BASE_YEAR;
 
		}
 
@@ -1589,13 +1581,13 @@ bool AfterLoadGame()
 
				v->cur_speed /= 10;
 
				v->acceleration = avi->acceleration;
 
			}
 
		}
 
	}
 

	
 
	if (IsSavegameVersionBefore(SLV_49)) FOR_ALL_COMPANIES(c) c->face = ConvertFromOldCompanyManagerFace(c->face);
 
	if (IsSavegameVersionBefore(SLV_49)) for (Company *c : Company::Iterate()) c->face = ConvertFromOldCompanyManagerFace(c->face);
 

	
 
	if (IsSavegameVersionBefore(SLV_52)) {
 
		for (TileIndex t = 0; t < map_size; t++) {
 
			if (IsTileType(t, MP_OBJECT) && _m[t].m5 == OBJECT_STATUE) {
 
				_m[t].m2 = CalcClosestTownFromTile(t)->index;
 
			}
 
@@ -1789,13 +1781,13 @@ bool AfterLoadGame()
 
		/* Set all share owners to INVALID_COMPANY for
 
		 * 1) all inactive companies
 
		 *     (when inactive companies were stored in the savegame - TTD, TTDP and some
 
		 *      *really* old revisions of OTTD; else it is already set in InitializeCompanies())
 
		 * 2) shares that are owned by inactive companies or self
 
		 *     (caused by cheating clients in earlier revisions) */
 
		FOR_ALL_COMPANIES(c) {
 
		for (Company *c : Company::Iterate()) {
 
			for (uint i = 0; i < 4; i++) {
 
				CompanyID company = c->share_owners[i];
 
				if (company == INVALID_COMPANY) continue;
 
				if (!Company::IsValidID(company) || company == c->index) c->share_owners[i] = INVALID_COMPANY;
 
			}
 
		}
 
@@ -2058,14 +2050,13 @@ bool AfterLoadGame()
 
			if (!a->IsNormalAircraft()) {
 
				a->engine_type = a->First()->engine_type;
 
			}
 
		}
 

	
 
		/* More companies ... */
 
		Company *c;
 
		FOR_ALL_COMPANIES(c) {
 
		for (Company *c : Company::Iterate()) {
 
			if (c->bankrupt_asked == 0xFF) c->bankrupt_asked = 0xFFFF;
 
		}
 

	
 
		Engine *e;
 
		FOR_ALL_ENGINES(e) {
 
			if (e->company_avail == 0xFF) e->company_avail = 0xFFFF;
 
@@ -2196,14 +2187,13 @@ bool AfterLoadGame()
 
			if (o->IsType(OT_GOTO_STATION)) o->SetStopLocation(OSL_PLATFORM_FAR_END);
 
		}
 
	}
 

	
 
	if (IsSavegameVersionBefore(SLV_120)) {
 
		extern VehicleDefaultSettings _old_vds;
 
		Company *c;
 
		FOR_ALL_COMPANIES(c) {
 
		for (Company *c : Company::Iterate()) {
 
			c->settings.vehicle = _old_vds;
 
		}
 
	}
 

	
 
	if (IsSavegameVersionBefore(SLV_121)) {
 
		/* Delete small ufos heading for non-existing vehicles */
 
@@ -2660,14 +2650,13 @@ bool AfterLoadGame()
 

	
 
			ClrBit(t->flags, 5);
 
			SetBit(t->vehicle_flags, VF_PATHFINDER_LOST);
 
		}
 

	
 
		/* Introduced terraform/clear limits. */
 
		Company *c;
 
		FOR_ALL_COMPANIES(c) {
 
		for (Company *c : Company::Iterate()) {
 
			c->terraform_limit = _settings_game.construction.terraform_frame_burst << 16;
 
			c->clear_limit     = _settings_game.construction.clear_frame_burst << 16;
 
		}
 
	}
 

	
 
	if (IsSavegameVersionBefore(SLV_158)) {
 
@@ -2920,23 +2909,22 @@ bool AfterLoadGame()
 
			SetRoadOwner(t, RTT_TRAM, o);
 
		}
 
	}
 

	
 
	if (IsSavegameVersionBefore(SLV_175)) {
 
		/* Introduced tree planting limit. */
 
		Company *c;
 
		FOR_ALL_COMPANIES(c) c->tree_limit = _settings_game.construction.tree_frame_burst << 16;
 
		for (Company *c : Company::Iterate()) c->tree_limit = _settings_game.construction.tree_frame_burst << 16;
 
	}
 

	
 
	if (IsSavegameVersionBefore(SLV_177)) {
 
		/* Fix too high inflation rates */
 
		if (_economy.inflation_prices > MAX_INFLATION) _economy.inflation_prices = MAX_INFLATION;
 
		if (_economy.inflation_payment > MAX_INFLATION) _economy.inflation_payment = MAX_INFLATION;
 

	
 
		/* We have to convert the quarters of bankruptcy into months of bankruptcy */
 
		FOR_ALL_COMPANIES(c) {
 
		for (Company *c : Company::Iterate()) {
 
			c->months_of_bankruptcy = 3 * c->months_of_bankruptcy;
 
		}
 
	}
 

	
 
	if (IsSavegameVersionBefore(SLV_178)) {
 
		extern uint8 _old_diff_level;
src/saveload/company_sl.cpp
Show inline comments
 
@@ -91,23 +91,23 @@ CompanyManagerFace ConvertFromOldCompany
 
}
 

	
 
/** Rebuilding of company statistics after loading a savegame. */
 
void AfterLoadCompanyStats()
 
{
 
	/* Reset infrastructure statistics to zero. */
 
	Company *c;
 
	FOR_ALL_COMPANIES(c) MemSetT(&c->infrastructure, 0);
 
	for (Company *c : Company::Iterate()) MemSetT(&c->infrastructure, 0);
 

	
 
	/* Collect airport count. */
 
	Station *st;
 
	FOR_ALL_STATIONS(st) {
 
		if ((st->facilities & FACIL_AIRPORT) && Company::IsValidID(st->owner)) {
 
			Company::Get(st->owner)->infrastructure.airport++;
 
		}
 
	}
 

	
 
	Company *c;
 
	for (TileIndex tile = 0; tile < MapSize(); tile++) {
 
		switch (GetTileType(tile)) {
 
			case MP_RAILWAY:
 
				c = Company::GetIfValid(GetTileOwner(tile));
 
				if (c != nullptr) {
 
					uint pieces = 1;
 
@@ -483,14 +483,13 @@ static void SaveLoad_PLYR(Company *c)
 
{
 
	SaveLoad_PLYR_common(c, c);
 
}
 

	
 
static void Save_PLYR()
 
{
 
	Company *c;
 
	FOR_ALL_COMPANIES(c) {
 
	for (Company *c : Company::Iterate()) {
 
		SlSetArrayIndex(c->index);
 
		SlAutolength((AutolengthProc*)SaveLoad_PLYR, c);
 
	}
 
}
 

	
 
static void Load_PLYR()
 
@@ -531,14 +530,13 @@ static void Check_PLYR()
 
		if (!_load_check_data.companies.Insert(index, cprops)) delete cprops;
 
	}
 
}
 

	
 
static void Ptrs_PLYR()
 
{
 
	Company *c;
 
	FOR_ALL_COMPANIES(c) {
 
	for (Company *c : Company::Iterate()) {
 
		SlObject(c, _company_settings_desc);
 
	}
 
}
 

	
 

	
 
extern const ChunkHandler _company_chunk_handlers[] = {
src/saveload/oldloader_sl.cpp
Show inline comments
 
@@ -456,14 +456,13 @@ static bool FixTTOEngines()
 

	
 
	return true;
 
}
 

	
 
static void FixTTOCompanies()
 
{
 
	Company *c;
 
	FOR_ALL_COMPANIES(c) {
 
	for (Company *c : Company::Iterate()) {
 
		c->cur_economy.company_value = CalculateCompanyValue(c); // company value history is zeroed
 
	}
 
}
 

	
 
static inline byte RemapTTOColour(byte tto)
 
{
src/saveload/saveload.cpp
Show inline comments
 
@@ -2813,14 +2813,13 @@ void GenerateDefaultSaveName(char *buf, 
 
{
 
	/* Check if we have a name for this map, which is the name of the first
 
	 * available company. When there's no company available we'll use
 
	 * 'Spectator' as "company" name. */
 
	CompanyID cid = _local_company;
 
	if (!Company::IsValidID(cid)) {
 
		const Company *c;
 
		FOR_ALL_COMPANIES(c) {
 
		for (const Company *c : Company::Iterate()) {
 
			cid = c->index;
 
			break;
 
		}
 
	}
 

	
 
	SetDParam(0, cid);
src/screenshot.cpp
Show inline comments
 
@@ -312,14 +312,13 @@ static bool MakePNGImage(const char *nam
 
	for (const GRFConfig *c = _game_mode == GM_MENU ? nullptr : _grfconfig; c != nullptr; c = c->next) {
 
		p += seprintf(p, lastof(buf), "%08X ", BSWAP32(c->ident.grfid));
 
		p = md5sumToString(p, lastof(buf), c->ident.md5sum);
 
		p += seprintf(p, lastof(buf), " %s\n", c->filename);
 
	}
 
	p = strecpy(p, "\nCompanies:\n", lastof(buf));
 
	const Company *c;
 
	FOR_ALL_COMPANIES(c) {
 
	for (const Company *c : Company::Iterate()) {
 
		if (c->ai_info == nullptr) {
 
			p += seprintf(p, lastof(buf), "%2i: Human\n", (int)c->index);
 
		} else {
 
			p += seprintf(p, lastof(buf), "%2i: %s (v%d)\n", (int)c->index, c->ai_info->GetName(), c->ai_info->GetVersion());
 
		}
 
	}
src/smallmap_gui.cpp
Show inline comments
 
@@ -330,14 +330,13 @@ void BuildLandLegend()
 
 */
 
void BuildOwnerLegend()
 
{
 
	_legend_land_owners[1].colour = _heightmap_schemes[_settings_client.gui.smallmap_land_colour].default_colour;
 

	
 
	int i = NUM_NO_COMPANY_ENTRIES;
 
	const Company *c;
 
	FOR_ALL_COMPANIES(c) {
 
	for (const Company *c : Company::Iterate()) {
 
		_legend_land_owners[i].colour = _colour_gradient[c->colour][5];
 
		_legend_land_owners[i].company = c->index;
 
		_legend_land_owners[i].show_on_map = true;
 
		_legend_land_owners[i].col_break = false;
 
		_legend_land_owners[i].end = false;
 
		_company_to_list_pos[c->index] = i;
src/statusbar_gui.cpp
Show inline comments
 
@@ -117,14 +117,13 @@ struct StatusBarWindow : Window {
 
				SetDParamMaxValue(0, MAX_YEAR * DAYS_IN_YEAR);
 
				d = GetStringBoundingBox(STR_WHITE_DATE_LONG);
 
				break;
 

	
 
			case WID_S_RIGHT: {
 
				int64 max_money = UINT32_MAX;
 
				const Company *c;
 
				FOR_ALL_COMPANIES(c) max_money = max<int64>(c->money, max_money);
 
				for (const Company *c : Company::Iterate()) max_money = max<int64>(c->money, max_money);
 
				SetDParam(0, 100LL * max_money);
 
				d = GetStringBoundingBox(STR_COMPANY_MONEY);
 
				break;
 
			}
 

	
 
			default:
src/terraform_gui.cpp
Show inline comments
 
@@ -497,14 +497,13 @@ static void ResetLandscapeConfirmationCa
 
	if (confirmed) {
 
		/* Set generating_world to true to get instant-green grass after removing
 
		 * company property. */
 
		_generating_world = true;
 

	
 
		/* Delete all companies */
 
		Company *c;
 
		FOR_ALL_COMPANIES(c) {
 
		for (Company *c : Company::Iterate()) {
 
			ChangeOwnershipOfCompanyItems(c->index, INVALID_OWNER);
 
			delete c;
 
		}
 

	
 
		_generating_world = false;
 

	
src/town_cmd.cpp
Show inline comments
 
@@ -3291,14 +3291,13 @@ static void ForAllStationsNearTown(Town 
 
	});
 
}
 

	
 
static void UpdateTownRating(Town *t)
 
{
 
	/* Increase company ratings if they're low */
 
	const Company *c;
 
	FOR_ALL_COMPANIES(c) {
 
	for (const Company *c : Company::Iterate()) {
 
		if (t->ratings[c->index] < RATING_GROWTH_MAXIMUM) {
 
			t->ratings[c->index] = min((int)RATING_GROWTH_MAXIMUM, t->ratings[c->index] + RATING_GROWTH_UP_STEP);
 
		}
 
	}
 

	
 
	ForAllStationsNearTown(t, [&](const Station *st) {
 
@@ -3448,15 +3447,13 @@ static void UpdateTownAmounts(Town *t)
 

	
 
	SetWindowDirty(WC_TOWN_VIEW, t->index);
 
}
 

	
 
static void UpdateTownUnwanted(Town *t)
 
{
 
	const Company *c;
 

	
 
	FOR_ALL_COMPANIES(c) {
 
	for (const Company *c : Company::Iterate()) {
 
		if (t->unwanted[c->index] > 0) t->unwanted[c->index]--;
 
	}
 
}
 

	
 
/**
 
 * Checks whether the local authority allows construction of a new station (rail, road, airport, dock) on the given tile
src/town_gui.cpp
Show inline comments
 
@@ -146,14 +146,13 @@ public:
 
		uint text_left      = left  + (rtl ? 0 : icon_width + exclusive_width + 4);
 
		uint text_right     = right - (rtl ? icon_width + exclusive_width + 4 : 0);
 
		uint icon_left      = rtl ? right - icon_width : left;
 
		uint exclusive_left = rtl ? right - icon_width - exclusive_width - 2 : left + icon_width + 2;
 

	
 
		/* Draw list of companies */
 
		const Company *c;
 
		FOR_ALL_COMPANIES(c) {
 
		for (const Company *c : Company::Iterate()) {
 
			if ((HasBit(this->town->have_ratings, c->index) || this->town->exclusivity == c->index)) {
 
				DrawCompanyIcon(c->index, icon_left, y + icon_y_offset);
 

	
 
				SetDParam(0, c->index);
 
				SetDParam(1, c->index);
 

	
0 comments (0 inline, 0 general)