Changeset - r11908:0875f47fab11
[Not reviewed]
master
0 15 0
yexo - 15 years ago 2009-05-15 23:55:06
yexo@openttd.org
(svn r16315) -Codechange: move the autorenew settings to a new CompanySettings struct
15 files changed with 68 insertions and 69 deletions:
0 comments (0 inline, 0 general)
src/ai/api/ai_company.cpp
Show inline comments
 
@@ -153,34 +153,34 @@
 

	
 
/* static */ bool AICompany::GetAutoRenewStatus(CompanyID company)
 
{
 
	company = ResolveCompanyID(company);
 
	if (company == COMPANY_INVALID) return false;
 

	
 
	return ::GetCompany((CompanyID)company)->engine_renew;
 
	return ::GetCompany((CompanyID)company)->settings.engine_renew;
 
}
 

	
 
/* static */ bool AICompany::SetAutoRenewMonths(int16 months)
 
{
 
	return AIObject::DoCommand(0, 1, months, CMD_SET_AUTOREPLACE);
 
}
 

	
 
/* static */ int16 AICompany::GetAutoRenewMonths(CompanyID company)
 
{
 
	company = ResolveCompanyID(company);
 
	if (company == COMPANY_INVALID) return 0;
 

	
 
	return ::GetCompany((CompanyID)company)->engine_renew_months;
 
	return ::GetCompany((CompanyID)company)->settings.engine_renew_months;
 
}
 

	
 
/* static */ bool AICompany::SetAutoRenewMoney(uint32 money)
 
{
 
	return AIObject::DoCommand(0, 2, money, CMD_SET_AUTOREPLACE);
 
}
 

	
 
/* static */ uint32 AICompany::GetAutoRenewMoney(CompanyID company)
 
{
 
	company = ResolveCompanyID(company);
 
	if (company == COMPANY_INVALID) return 0;
 

	
 
	return ::GetCompany((CompanyID)company)->engine_renew_money;
 
	return ::GetCompany((CompanyID)company)->settings.engine_renew_money;
 
}
src/ai/api/ai_group.cpp
Show inline comments
 
@@ -97,13 +97,13 @@
 

	
 
	return AIObject::DoCommand(0, 5, enable_removal ? 1 : 0, CMD_SET_AUTOREPLACE);
 
}
 

	
 
/* static */ bool AIGroup::HasWagonRemoval()
 
{
 
	return ::GetCompany(_current_company)->renew_keep_length;
 
	return ::GetCompany(_current_company)->settings.renew_keep_length;
 
}
 

	
 
/* static */ bool AIGroup::SetAutoReplace(GroupID group_id, EngineID engine_id_old, EngineID engine_id_new)
 
{
 
	EnforcePrecondition(false, IsValidGroup(group_id) || group_id == GROUP_ALL);
 
	EnforcePrecondition(false, AIEngine::IsValidEngine(engine_id_new));
src/aircraft_cmd.cpp
Show inline comments
 
@@ -1445,13 +1445,13 @@ static inline bool CheckSendAircraftToHa
 

	
 
	if (!HasBit(GetEngine(new_engine)->company_avail, v->owner)) {
 
		/* Engine is not buildable anymore */
 
		return false;
 
	}
 

	
 
	if (c->money < (c->engine_renew_money + (2 * DoCommand(0, new_engine, 0, DC_QUERY_COST, CMD_BUILD_AIRCRAFT).GetCost()))) {
 
	if (c->money < (c->settings.engine_renew_money + (2 * DoCommand(0, new_engine, 0, DC_QUERY_COST, CMD_BUILD_AIRCRAFT).GetCost()))) {
 
		/* We lack enough money to request the replacement right away.
 
		 * We want 2*(the price of the new vehicle) and not looking at the value of the vehicle we are going to sell.
 
		 * The reason is that we don't want to send a whole lot of vehicles to the hangars when we only have enough money to replace a single one.
 
		 * Remember this happens in the background so the user can't stop this. */
 
		return false;
 
	}
src/autoreplace_cmd.cpp
Show inline comments
 
@@ -621,13 +621,13 @@ CommandCost CmdAutoreplaceVehicle(TileIn
 
		if (free_wagon && IsFrontEngine(v->First())) return CMD_ERROR;
 
	} else {
 
		if (!v->IsPrimaryVehicle()) return CMD_ERROR;
 
	}
 

	
 
	const Company *c = GetCompany(_current_company);
 
	bool wagon_removal = c->renew_keep_length;
 
	bool wagon_removal = c->settings.renew_keep_length;
 

	
 
	/* Test whether any replacement is set, before issuing a whole lot of commands that would end in nothing changed */
 
	Vehicle *w = v;
 
	bool any_replacements = false;
 
	while (w != NULL && !any_replacements) {
 
		any_replacements = (GetNewEngineType(w, c) != INVALID_ENGINE);
src/autoreplace_gui.cpp
Show inline comments
 
@@ -264,13 +264,13 @@ public:
 

	
 
		/* now the actual drawing of the window itself takes place */
 
		SetDParam(0, STR_VEHICLE_TRAIN + this->window_number);
 

	
 
		if (this->window_number == VEH_TRAIN) {
 
			/* set on/off for renew_keep_length */
 
			SetDParam(1, c->renew_keep_length ? STR_CONFIG_SETTING_ON : STR_CONFIG_SETTING_OFF);
 
			SetDParam(1, c->settings.renew_keep_length ? STR_CONFIG_SETTING_ON : STR_CONFIG_SETTING_OFF);
 

	
 
			/* set wagon/engine button */
 
			SetDParam(2, this->wagon_btnstate ? STR_ENGINES : STR_WAGONS);
 

	
 
			/* sets the colour of that art thing */
 
			this->widget[RVW_WIDGET_TRAIN_FLUFF_LEFT].colour  = _company_colours[_local_company];
 
@@ -344,13 +344,13 @@ public:
 
				}
 
				ShowDropDownList(this, list, sel_railtype, RVW_WIDGET_TRAIN_RAILTYPE_DROPDOWN);
 
				break;
 
			}
 

	
 
			case RVW_WIDGET_TRAIN_WAGONREMOVE_TOGGLE: // toggle renew_keep_length
 
				DoCommandP(0, 5, GetCompany(_local_company)->renew_keep_length ? 0 : 1, CMD_SET_AUTOREPLACE);
 
				DoCommandP(0, 5, GetCompany(_local_company)->settings.renew_keep_length ? 0 : 1, CMD_SET_AUTOREPLACE);
 
				break;
 

	
 
			case RVW_WIDGET_START_REPLACE: { // Start replacing
 
				EngineID veh_from = this->sel_engine[0];
 
				EngineID veh_to = this->sel_engine[1];
 
				DoCommandP(0, 3 + (this->sel_group << 16) , veh_from + (veh_to << 16), CMD_SET_AUTOREPLACE);
src/company_base.h
Show inline comments
 
@@ -12,12 +12,13 @@
 
#include "date_type.h"
 
#include "engine_type.h"
 
#include "livery.h"
 
#include "autoreplace_type.h"
 
#include "economy_type.h"
 
#include "tile_type.h"
 
#include "settings_type.h"
 

	
 
struct CompanyEconomyEntry {
 
	Money income;
 
	Money expenses;
 
	int32 delivered_cargo;
 
	int32 performance_history; ///< company score (scale 0-1000)
 
@@ -75,16 +76,13 @@ struct Company : PoolItem<Company, Compa
 
	class AIInfo *ai_info;
 

	
 
	Money yearly_expenses[3][EXPENSES_END];
 
	CompanyEconomyEntry cur_economy;
 
	CompanyEconomyEntry old_economy[24];
 
	EngineRenewList engine_renew_list; ///< Defined later
 
	bool engine_renew;
 
	bool renew_keep_length;
 
	int16 engine_renew_months;
 
	uint32 engine_renew_money;
 
	CompanySettings settings;          ///< settings specific for each company
 
	uint16 *num_engines; ///< caches the number of engines of each type the company owns (no need to save this)
 

	
 
	inline bool IsValid() const { return this->name_1 != 0; }
 
};
 

	
 
static inline bool IsValidCompanyID(CompanyID company)
src/company_cmd.cpp
Show inline comments
 
@@ -75,15 +75,13 @@ void SetLocalCompany(CompanyID new_compa
 

	
 
	_local_company = new_company;
 

	
 
	/* Do not update the settings if we are in the intro GUI */
 
	if (IsValidCompanyID(new_company) && _game_mode != GM_MENU) {
 
		const Company *c = GetCompany(new_company);
 
		_settings_client.gui.autorenew        = c->engine_renew;
 
		_settings_client.gui.autorenew_months = c->engine_renew_months;
 
		_settings_client.gui.autorenew_money  = c->engine_renew_money;
 
		_settings_client.company = c->settings;
 
		InvalidateWindow(WC_GAME_OPTIONS, 0);
 
	}
 

	
 
	/* Delete any construction windows... */
 
	DeleteConstructionWindows();
 

	
 
@@ -565,44 +563,44 @@ CommandCost CmdSetAutoReplace(TileIndex 
 
{
 
	if (!IsValidCompanyID(_current_company)) return CMD_ERROR;
 

	
 
	Company *c = GetCompany(_current_company);
 
	switch (GB(p1, 0, 3)) {
 
		case 0:
 
			if (c->engine_renew == HasBit(p2, 0)) return CMD_ERROR;
 
			if (c->settings.engine_renew == HasBit(p2, 0)) return CMD_ERROR;
 

	
 
			if (flags & DC_EXEC) {
 
				c->engine_renew = HasBit(p2, 0);
 
				c->settings.engine_renew = HasBit(p2, 0);
 
				if (IsLocalCompany()) {
 
					_settings_client.gui.autorenew = c->engine_renew;
 
					_settings_client.company.engine_renew = c->settings.engine_renew;
 
					InvalidateWindow(WC_GAME_OPTIONS, 0);
 
				}
 
			}
 
			break;
 

	
 
		case 1:
 
			if (Clamp((int16)p2, -12, 12) != (int16)p2) return CMD_ERROR;
 
			if (c->engine_renew_months == (int16)p2) return CMD_ERROR;
 
			if (c->settings.engine_renew_months == (int16)p2) return CMD_ERROR;
 

	
 
			if (flags & DC_EXEC) {
 
				c->engine_renew_months = (int16)p2;
 
				c->settings.engine_renew_months = (int16)p2;
 
				if (IsLocalCompany()) {
 
					_settings_client.gui.autorenew_months = c->engine_renew_months;
 
					_settings_client.company.engine_renew_months = c->settings.engine_renew_months;
 
					InvalidateWindow(WC_GAME_OPTIONS, 0);
 
				}
 
			}
 
			break;
 

	
 
		case 2:
 
			if (ClampU(p2, 0, 2000000) != p2) return CMD_ERROR;
 
			if (c->engine_renew_money == p2) return CMD_ERROR;
 
			if (c->settings.engine_renew_money == p2) return CMD_ERROR;
 

	
 
			if (flags & DC_EXEC) {
 
				c->engine_renew_money = p2;
 
				c->settings.engine_renew_money = p2;
 
				if (IsLocalCompany()) {
 
					_settings_client.gui.autorenew_money = c->engine_renew_money;
 
					_settings_client.company.engine_renew_money = c->settings.engine_renew_money;
 
					InvalidateWindow(WC_GAME_OPTIONS, 0);
 
				}
 
			}
 
			break;
 

	
 
		case 3: {
 
@@ -627,30 +625,30 @@ CommandCost CmdSetAutoReplace(TileIndex 
 

	
 
		case 4:
 
			if (Clamp((int16)GB(p1, 16, 16), -12, 12) != (int16)GB(p1, 16, 16)) return CMD_ERROR;
 
			if (ClampU(p2, 0, 2000000) != p2) return CMD_ERROR;
 

	
 
			if (flags & DC_EXEC) {
 
				c->engine_renew = HasBit(p1, 15);
 
				c->engine_renew_months = (int16)GB(p1, 16, 16);
 
				c->engine_renew_money = p2;
 
				c->settings.engine_renew = HasBit(p1, 15);
 
				c->settings.engine_renew_months = (int16)GB(p1, 16, 16);
 
				c->settings.engine_renew_money = p2;
 

	
 
				if (IsLocalCompany()) {
 
					_settings_client.gui.autorenew = c->engine_renew;
 
					_settings_client.gui.autorenew_months = c->engine_renew_months;
 
					_settings_client.gui.autorenew_money = c->engine_renew_money;
 
					_settings_client.company.engine_renew = c->settings.engine_renew;
 
					_settings_client.company.engine_renew_months = c->settings.engine_renew_months;
 
					_settings_client.company.engine_renew_money = c->settings.engine_renew_money;
 
					InvalidateWindow(WC_GAME_OPTIONS, 0);
 
				}
 
			}
 
			break;
 

	
 
		case 5:
 
			if (c->renew_keep_length == HasBit(p2, 0)) return CMD_ERROR;
 
			if (c->settings.renew_keep_length == HasBit(p2, 0)) return CMD_ERROR;
 

	
 
			if (flags & DC_EXEC) {
 
				c->renew_keep_length = HasBit(p2, 0);
 
				c->settings.renew_keep_length = HasBit(p2, 0);
 
				if (IsLocalCompany()) {
 
					InvalidateWindow(WC_REPLACE_VEHICLE, VEH_TRAIN);
 
				}
 
			}
 
		break;
 
	}
 
@@ -747,14 +745,14 @@ CommandCost CmdCompanyCtrl(TileIndex til
 
				break;
 
			}
 

	
 
			/* This is the client (or non-dedicated server) who wants a new company */
 
			if (cid == _network_own_client_id) {
 
				/* Create p1 and p2 here because SetLocalCompany resets the gui.autorenew* settings. */
 
				uint32 p1 = (_settings_client.gui.autorenew << 15 ) | (_settings_client.gui.autorenew_months << 16) | 4;
 
				uint32 p2 = _settings_client.gui.autorenew_money;
 
				uint32 p1 = (_settings_client.company.engine_renew << 15 ) | (_settings_client.company.engine_renew_months << 16) | 4;
 
				uint32 p2 = _settings_client.company.engine_renew_money;
 
				assert(_local_company == COMPANY_SPECTATOR);
 
				SetLocalCompany(c->index);
 
				if (!StrEmpty(_settings_client.network.default_company_pass)) {
 
					char *password = _settings_client.network.default_company_pass;
 
					NetworkChangeCompanyPassword(1, &password);
 
				}
src/openttd.cpp
Show inline comments
 
@@ -752,21 +752,18 @@ static void MakeNewGameDone()
 
	}
 

	
 
	/* Create a single company */
 
	DoStartupNewCompany(false);
 

	
 
	Company *c = GetCompany(COMPANY_FIRST);
 
	c->engine_renew = _settings_client.gui.autorenew;
 
	c->engine_renew_months = _settings_client.gui.autorenew_months;
 
	c->engine_renew_money = _settings_client.gui.autorenew_money;
 
	c->settings = _settings_client.company;
 

	
 
	IConsoleCmdExec("exec scripts/game_start.scr 0");
 

	
 
	SetLocalCompany(COMPANY_FIRST);
 
	_current_company = _local_company;
 
	DoCommandP(0, (_settings_client.gui.autorenew << 15 ) | (_settings_client.gui.autorenew_months << 16) | 4, _settings_client.gui.autorenew_money, CMD_SET_AUTOREPLACE);
 

	
 
	InitializeRailGUI();
 

	
 
#ifdef ENABLE_NETWORK
 
	/* We are the server, we start a new company (not dedicated),
 
	 * so set the default password *if* needed. */
 
@@ -851,13 +848,14 @@ static void StartScenario()
 
	StartupCompanies();
 
	StartupEngines();
 
	StartupDisasters();
 

	
 
	SetLocalCompany(COMPANY_FIRST);
 
	_current_company = _local_company;
 
	DoCommandP(0, (_settings_client.gui.autorenew << 15 ) | (_settings_client.gui.autorenew_months << 16) | 4, _settings_client.gui.autorenew_money, CMD_SET_AUTOREPLACE);
 
	Company *c = GetCompany(COMPANY_FIRST);
 
	c->settings = _settings_client.company;
 

	
 
	MarkWholeScreenDirty();
 
}
 

	
 
/** Load the specified savegame but on error do different things.
 
 * If loading fails due to corrupt savegame, bad version, etc. go back to
src/saveload/afterload.cpp
Show inline comments
 
@@ -658,29 +658,27 @@ bool AfterLoadGame()
 
	}
 

	
 
	/* 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 (CheckSavegameVersion(16)) {
 
		FOR_ALL_COMPANIES(c) {
 
			c->engine_renew_list   = NULL;
 
			c->engine_renew        = false;
 
			c->engine_renew_months = -6;
 
			c->engine_renew_money  = 100000;
 
			c->engine_renew_list            = NULL;
 
			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'.
 
		 */
 
		if (!_network_dedicated && IsValidCompanyID(COMPANY_FIRST)) {
 
			c = GetCompany(COMPANY_FIRST);
 
			c->engine_renew        = _settings_client.gui.autorenew;
 
			c->engine_renew_months = _settings_client.gui.autorenew_months;
 
			c->engine_renew_money  = _settings_client.gui.autorenew_money;
 
			c->settings = _settings_client.company;
 
		}
 
	}
 

	
 
	if (CheckSavegameVersion(48)) {
 
		for (TileIndex t = 0; t < map_size; t++) {
 
			switch (GetTileType(t)) {
 
@@ -947,13 +945,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 (CheckSavegameVersionOldStyle(16, 1)) {
 
		FOR_ALL_COMPANIES(c) c->renew_keep_length = false;
 
		FOR_ALL_COMPANIES(c) c->settings.renew_keep_length = false;
 
	}
 

	
 
	/* In version 17, ground type is moved from m2 to m4 for depots and
 
	 * waypoints to make way for storing the index in m2. The custom graphics
 
	 * id which was stored in m4 is now saved as a grf/id reference in the
 
	 * waypoint struct. */
src/saveload/company_sl.cpp
Show inline comments
 
@@ -3,12 +3,13 @@
 
/** @file company_sl.cpp Code handling saving and loading of company data */
 

	
 
#include "../stdafx.h"
 
#include "../company_base.h"
 
#include "../company_func.h"
 
#include "../company_manager_face.h"
 
#include "../settings_type.h"
 

	
 
#include "saveload.h"
 

	
 
/**
 
 * Converts an old company manager's face format to the new company manager's face format
 
 *
 
@@ -130,17 +131,17 @@ static const SaveLoad _company_desc[] = 
 
	SLE_CONDVAR(Company, is_ai,                 SLE_BOOL,                    2, SL_MAX_VERSION),
 
	SLE_CONDNULL(1, 107, 111), ///< is_noai
 
	SLE_CONDNULL(1, 4, 99),
 

	
 
	/* Engine renewal settings */
 
	SLE_CONDNULL(512, 16, 18),
 
	SLE_CONDREF(Company, engine_renew_list,     REF_ENGINE_RENEWS,          19, SL_MAX_VERSION),
 
	SLE_CONDVAR(Company, engine_renew,          SLE_BOOL,                   16, SL_MAX_VERSION),
 
	SLE_CONDVAR(Company, engine_renew_months,   SLE_INT16,                  16, SL_MAX_VERSION),
 
	SLE_CONDVAR(Company, engine_renew_money,    SLE_UINT32,                 16, SL_MAX_VERSION),
 
	SLE_CONDVAR(Company, renew_keep_length,     SLE_BOOL,                    2, SL_MAX_VERSION), // added with 16.1, but was blank since 2
 
	SLE_CONDREF(Company, engine_renew_list,            REF_ENGINE_RENEWS,   19, SL_MAX_VERSION),
 
	SLE_CONDVAR(Company, settings.engine_renew,        SLE_BOOL,            16, SL_MAX_VERSION),
 
	SLE_CONDVAR(Company, settings.engine_renew_months, SLE_INT16,           16, SL_MAX_VERSION),
 
	SLE_CONDVAR(Company, settings.engine_renew_money,  SLE_UINT32,          16, SL_MAX_VERSION),
 
	SLE_CONDVAR(Company, settings.renew_keep_length,   SLE_BOOL,             2, SL_MAX_VERSION),
 

	
 
	/* Reserve extra space in savegame here. (currently 63 bytes) */
 
	SLE_CONDNULL(63, 2, SL_MAX_VERSION),
 

	
 
	SLE_END()
 
};
src/settings.cpp
Show inline comments
 
@@ -723,25 +723,25 @@ static bool CheckInterval(int32 p1)
 

	
 
	return true;
 
}
 

	
 
static bool EngineRenewUpdate(int32 p1)
 
{
 
	DoCommandP(0, 0, _settings_client.gui.autorenew, CMD_SET_AUTOREPLACE);
 
	DoCommandP(0, 0, _settings_client.company.engine_renew, CMD_SET_AUTOREPLACE);
 
	return true;
 
}
 

	
 
static bool EngineRenewMonthsUpdate(int32 p1)
 
{
 
	DoCommandP(0, 1, _settings_client.gui.autorenew_months, CMD_SET_AUTOREPLACE);
 
	DoCommandP(0, 1, _settings_client.company.engine_renew_months, CMD_SET_AUTOREPLACE);
 
	return true;
 
}
 

	
 
static bool EngineRenewMoneyUpdate(int32 p1)
 
{
 
	DoCommandP(0, 2, _settings_client.gui.autorenew_money, CMD_SET_AUTOREPLACE);
 
	DoCommandP(0, 2, _settings_client.company.engine_renew_money, CMD_SET_AUTOREPLACE);
 
	return true;
 
}
 

	
 
static bool TrainAccelerationModelChanged(int32 p1)
 
{
 
	Vehicle *v;
src/settings_gui.cpp
Show inline comments
 
@@ -1251,15 +1251,15 @@ static SettingEntry _settings_vehicles_r
 
	SettingEntry("pf.pathfinder_for_ships"),
 
};
 
/** Autorenew sub-page */
 
static SettingsPage _settings_vehicles_routing_page = {_settings_vehicles_routing, lengthof(_settings_vehicles_routing)};
 

	
 
static SettingEntry _settings_vehicles_autorenew[] = {
 
	SettingEntry("gui.autorenew"),
 
	SettingEntry("gui.autorenew_months"),
 
	SettingEntry("gui.autorenew_money"),
 
	SettingEntry("company.engine_renew"),
 
	SettingEntry("company.engine_renew_months"),
 
	SettingEntry("company.engine_renew_money"),
 
};
 
/** Autorenew sub-page */
 
static SettingsPage _settings_vehicles_autorenew_page = {_settings_vehicles_autorenew, lengthof(_settings_vehicles_autorenew)};
 

	
 
static SettingEntry _settings_vehicles_servicing[] = {
 
	SettingEntry("vehicle.servint_ispercent"),
src/settings_type.h
Show inline comments
 
@@ -75,15 +75,12 @@ struct GUISettings {
 
	bool   timetable_in_ticks;               ///< whether to show the timetable in ticks rather than days
 
	bool   quick_goto;                       ///< Allow quick access to 'goto button' in vehicle orders window
 
	bool   bridge_pillars;                   ///< show bridge pillars for high bridges
 
	bool   auto_euro;                        ///< automatically switch to euro in 2002
 
	byte   drag_signals_density;             ///< many signals density
 
	Year   semaphore_build_before;           ///< build semaphore signals automatically before this year
 
	bool   autorenew;                        ///< should autorenew be enabled for new companies?
 
	int16  autorenew_months;                 ///< how many months from EOL of vehicles should autorenew trigger for new companies?
 
	int32  autorenew_money;                  ///< how much money before autorenewing for new companies?
 
	byte   news_message_timeout;             ///< how much longer than the news message "age" should we keep the message in the history
 
	bool   show_track_reservation;           ///< highlight reserved tracks.
 
	uint8  default_signal_type;              ///< the signal type to build by default.
 
	uint8  cycle_signal_types;               ///< what signal types to cycle with the build signal tool.
 
	byte   station_numtracks;                ///< the number of platforms to default on for rail stations
 
	byte   station_platlength;               ///< the platform length, in tiles, for rail stations
 
@@ -338,12 +335,20 @@ struct StationSettings {
 
	bool   adjacent_stations;                ///< allow stations to be built directly adjacent to other stations
 
	bool   distant_join_stations;            ///< allow to join non-adjacent stations
 
	bool   always_small_airport;             ///< always allow small airports
 
	byte   station_spread;                   ///< amount a station may spread
 
};
 

	
 
/** Settings that can be set per company. */
 
struct CompanySettings {
 
	bool engine_renew;                       ///< is autorenew enabled
 
	int16 engine_renew_months;               ///< months before/after the maximum vehicle age a vehicle should be renewed
 
	uint32 engine_renew_money;               ///< minimum amount of money before autorenew is used
 
	bool renew_keep_length;                  ///< sell some wagons if after autoreplace the train is longer than before
 
};
 

	
 
/** All settings together for the game. */
 
struct GameSettings {
 
	DifficultySettings   difficulty;         ///< settings related to the difficulty
 
	GameCreationSettings game_creation;      ///< settings used during the creation of a game (map)
 
	ConstructionSettings construction;       ///< construction of things in-game
 
	AISettings           ai;                 ///< what may the AI do?
 
@@ -357,12 +362,13 @@ struct GameSettings {
 
};
 

	
 
/** All settings that are only important for the local client. */
 
struct ClientSettings {
 
	GUISettings          gui;                ///< settings related to the GUI
 
	NetworkSettings      network;            ///< settings related to the network
 
	CompanySettings      company;            ///< default values for per-company settings
 
};
 

	
 
/** The current settings for this game. */
 
extern ClientSettings _settings_client;
 

	
 
/** The current settings for this game. */
src/table/settings.h
Show inline comments
 
@@ -544,15 +544,15 @@ const SettingDesc _settings[] = {
 
	 SDTC_BOOL(gui.enable_signal_gui,                    S,  0,  true,                        STR_CONFIG_SETTING_ENABLE_SIGNAL_GUI,           CloseSignalGUI),
 
	  SDTC_VAR(gui.drag_signals_density,      SLE_UINT8, S,  0,     4,        1,       20, 0, STR_CONFIG_SETTING_DRAG_SIGNALS_DENSITY,        DragSignalsDensityChanged),
 
	  SDTC_VAR(gui.semaphore_build_before,    SLE_INT32, S, NC,  1975, MIN_YEAR, MAX_YEAR, 1, STR_CONFIG_SETTING_SEMAPHORE_BUILD_BEFORE_DATE, ResetSignalVariant),
 
	 SDTC_BOOL(gui.vehicle_income_warn,                  S,  0,  true,                        STR_CONFIG_SETTING_WARN_INCOME_LESS,            NULL),
 
	  SDTC_VAR(gui.order_review_system,       SLE_UINT8, S, MS,     2,        0,        2, 0, STR_CONFIG_SETTING_ORDER_REVIEW,                NULL),
 
	 SDTC_BOOL(gui.lost_train_warn,                      S,  0,  true,                        STR_CONFIG_SETTING_WARN_LOST_TRAIN,             NULL),
 
	 SDTC_BOOL(gui.autorenew,                            S,  0, false,                        STR_CONFIG_SETTING_AUTORENEW_VEHICLE,           EngineRenewUpdate),
 
	  SDTC_VAR(gui.autorenew_months,          SLE_INT16, S,  0,     6,      -12,       12, 0, STR_CONFIG_SETTING_AUTORENEW_MONTHS,            EngineRenewMonthsUpdate),
 
	  SDTC_VAR(gui.autorenew_money,            SLE_UINT, S, CR,100000,        0,  2000000, 0, STR_CONFIG_SETTING_AUTORENEW_MONEY,             EngineRenewMoneyUpdate),
 
	 SDTC_BOOL(company.engine_renew,                     S,  0, false,                        STR_CONFIG_SETTING_AUTORENEW_VEHICLE,           EngineRenewUpdate),
 
	  SDTC_VAR(company.engine_renew_months,   SLE_INT16, S,  0,     6,      -12,       12, 0, STR_CONFIG_SETTING_AUTORENEW_MONTHS,            EngineRenewMonthsUpdate),
 
	  SDTC_VAR(company.engine_renew_money,     SLE_UINT, S, CR,100000,        0,  2000000, 0, STR_CONFIG_SETTING_AUTORENEW_MONEY,             EngineRenewMoneyUpdate),
 
	 SDTC_BOOL(gui.always_build_infrastructure,          S,  0, false,                        STR_CONFIG_SETTING_ALWAYS_BUILD_INFRASTRUCTURE, RedrawScreen),
 
	 SDTC_BOOL(gui.new_nonstop,                          S,  0, false,                        STR_CONFIG_SETTING_NONSTOP_BY_DEFAULT,          NULL),
 
	  SDTC_VAR(gui.stop_location,             SLE_UINT8, S, MS,     2,        0,        2, 1, STR_CONFIG_SETTING_STOP_LOCATION,               NULL),
 
	 SDTC_BOOL(gui.keep_all_autosave,                    S,  0, false,                        STR_NULL,                                       NULL),
 
	 SDTC_BOOL(gui.autosave_on_exit,                     S,  0, false,                        STR_NULL,                                       NULL),
 
	  SDTC_VAR(gui.max_num_autosaves,         SLE_UINT8, S,  0,    16,        0,      255, 0, STR_NULL,                                       NULL),
src/vehicle.cpp
Show inline comments
 
@@ -61,14 +61,14 @@ bool Vehicle::NeedsAutorenewing(const Co
 
	/* We can always generate the Company pointer when we have the vehicle.
 
	 * However this takes time and since the Company pointer is often present
 
	 * when this function is called then it's faster to pass the pointer as an
 
	 * argument rather than finding it again. */
 
	assert(c == GetCompany(this->owner));
 

	
 
	if (!c->engine_renew) return false;
 
	if (this->age - this->max_age < (c->engine_renew_months * 30)) return false;
 
	if (!c->settings.engine_renew) return false;
 
	if (this->age - this->max_age < (c->settings.engine_renew_months * 30)) return false;
 
	if (this->age == 0) return false; // rail cars don't age and lacks a max age
 

	
 
	return true;
 
}
 

	
 
void VehicleServiceInDepot(Vehicle *v)
 
@@ -639,15 +639,15 @@ void CallVehicleTicks()
 
		/* Store the position of the effect as the vehicle pointer will become invalid later */
 
		int x = v->x_pos;
 
		int y = v->y_pos;
 
		int z = v->z_pos;
 

	
 
		const Company *c = GetCompany(_current_company);
 
		SubtractMoneyFromCompany(CommandCost(EXPENSES_NEW_VEHICLES, (Money)c->engine_renew_money));
 
		SubtractMoneyFromCompany(CommandCost(EXPENSES_NEW_VEHICLES, (Money)c->settings.engine_renew_money));
 
		CommandCost res = DoCommand(0, v->index, 0, DC_EXEC, CMD_AUTOREPLACE_VEHICLE);
 
		SubtractMoneyFromCompany(CommandCost(EXPENSES_NEW_VEHICLES, -(Money)c->engine_renew_money));
 
		SubtractMoneyFromCompany(CommandCost(EXPENSES_NEW_VEHICLES, -(Money)c->settings.engine_renew_money));
 

	
 
		if (!IsLocalCompany()) continue;
 

	
 
		if (res.Succeeded()) {
 
			ShowCostOrIncomeAnimation(x, y, z, res.GetCost());
 
			continue;
 
@@ -903,13 +903,13 @@ void AgeVehicle(Vehicle *v)
 
	InvalidateWindow(WC_VEHICLE_DETAILS, v->index);
 

	
 
	/* Don't warn about non-primary or not ours vehicles or vehicles that are crashed */
 
	if (v->Previous() != NULL || v->owner != _local_company || (v->vehstatus & VS_CRASHED) != 0) return;
 

	
 
	/* Don't warn if a renew is active */
 
	if (GetCompany(v->owner)->engine_renew && GetEngine(v->engine_type)->company_avail != 0) return;
 
	if (GetCompany(v->owner)->settings.engine_renew && GetEngine(v->engine_type)->company_avail != 0) return;
 

	
 
	StringID str;
 
	if (age == -DAYS_IN_LEAP_YEAR) {
 
		str = STR_VEHICLE_IS_GETTING_OLD;
 
	} else if (age == 0) {
 
		str = STR_VEHICLE_IS_GETTING_VERY_OLD;
0 comments (0 inline, 0 general)