Merge commit '73bed054b87399484e39f6972d30f91a404daba8'
This commit is contained in:
@@ -17,11 +17,13 @@
|
||||
#include "network/network_func.h"
|
||||
#include "network/core/config.h"
|
||||
#include "pathfinder/pathfinder_type.h"
|
||||
#include "linkgraph/linkgraphschedule.h"
|
||||
#include "genworld.h"
|
||||
#include "train.h"
|
||||
#include "news_func.h"
|
||||
#include "window_func.h"
|
||||
#include "company_func.h"
|
||||
#include "timer/timer_game_calendar.h"
|
||||
#if defined(WITH_FREETYPE) || defined(_WIN32) || defined(WITH_COCOA)
|
||||
#define HAS_TRUETYPE_FONT
|
||||
#include "fontcache.h"
|
||||
@@ -42,8 +44,13 @@
|
||||
#include "ship.h"
|
||||
#include "smallmap_gui.h"
|
||||
#include "roadveh.h"
|
||||
#include "roadveh_cmd.h"
|
||||
#include "vehicle_func.h"
|
||||
#include "viewport_func.h"
|
||||
#include "void_map.h"
|
||||
#include "station_func.h"
|
||||
#include "station_base.h"
|
||||
#include "language.h"
|
||||
|
||||
#include "table/strings.h"
|
||||
#include "table/settings.h"
|
||||
@@ -76,14 +83,48 @@ SettingTable _win32_settings{ _win32_settings_table };
|
||||
|
||||
/* Begin - Callback Functions for the various settings. */
|
||||
|
||||
/** Switch setting title depending on wallclock setting */
|
||||
static StringID SettingTitleWallclock(const IntSettingDesc &sd)
|
||||
{
|
||||
return TimerGameEconomy::UsingWallclockUnits(_game_mode == GM_MENU) ? sd.str + 1 : sd.str;
|
||||
}
|
||||
|
||||
/** Switch setting help depending on wallclock setting */
|
||||
static StringID SettingHelpWallclock(const IntSettingDesc &sd)
|
||||
{
|
||||
return TimerGameEconomy::UsingWallclockUnits(_game_mode == GM_MENU) ? sd.str_help + 1 : sd.str_help;
|
||||
}
|
||||
|
||||
/** Setting values for velocity unit localisation */
|
||||
static void SettingsValueVelocityUnit(const IntSettingDesc &, uint first_param, int32_t value)
|
||||
{
|
||||
StringID val;
|
||||
switch (value) {
|
||||
case 0: val = STR_CONFIG_SETTING_LOCALISATION_UNITS_VELOCITY_IMPERIAL; break;
|
||||
case 1: val = STR_CONFIG_SETTING_LOCALISATION_UNITS_VELOCITY_METRIC; break;
|
||||
case 2: val = STR_CONFIG_SETTING_LOCALISATION_UNITS_VELOCITY_SI; break;
|
||||
case 3: val = TimerGameEconomy::UsingWallclockUnits(_game_mode == GM_MENU) ? STR_CONFIG_SETTING_LOCALISATION_UNITS_VELOCITY_GAMEUNITS_SECS : STR_CONFIG_SETTING_LOCALISATION_UNITS_VELOCITY_GAMEUNITS_DAYS; break;
|
||||
case 4: val = STR_CONFIG_SETTING_LOCALISATION_UNITS_VELOCITY_KNOTS; break;
|
||||
default: NOT_REACHED();
|
||||
}
|
||||
SetDParam(first_param, val);
|
||||
}
|
||||
|
||||
/** A negative value has another string (the one after "strval"). */
|
||||
static void SettingsValueAbsolute(const IntSettingDesc &sd, uint first_param, int32_t value)
|
||||
{
|
||||
SetDParam(first_param, sd.str_val + ((value >= 0) ? 1 : 0));
|
||||
SetDParam(first_param + 1, abs(value));
|
||||
}
|
||||
|
||||
/** Reposition the main toolbar as the setting changed. */
|
||||
static void v_PositionMainToolbar(int32 new_value)
|
||||
static void v_PositionMainToolbar(int32_t)
|
||||
{
|
||||
if (_game_mode != GM_MENU) PositionMainToolbar(nullptr);
|
||||
}
|
||||
|
||||
/** Reposition the statusbar as the setting changed. */
|
||||
static void v_PositionStatusbar(int32 new_value)
|
||||
static void v_PositionStatusbar(int32_t)
|
||||
{
|
||||
if (_game_mode != GM_MENU) {
|
||||
PositionStatusbar(nullptr);
|
||||
@@ -94,9 +135,8 @@ static void v_PositionStatusbar(int32 new_value)
|
||||
|
||||
/**
|
||||
* Redraw the smallmap after a colour scheme change.
|
||||
* @param p1 Callback parameter.
|
||||
*/
|
||||
static void RedrawSmallmap(int32 new_value)
|
||||
static void RedrawSmallmap(int32_t)
|
||||
{
|
||||
BuildLandLegend();
|
||||
BuildOwnerLegend();
|
||||
@@ -104,19 +144,19 @@ static void RedrawSmallmap(int32 new_value)
|
||||
}
|
||||
|
||||
/** Redraw linkgraph links after a colour scheme change. */
|
||||
static void UpdateLinkgraphColours(int32 new_value)
|
||||
static void UpdateLinkgraphColours(int32_t)
|
||||
{
|
||||
BuildLinkStatsLegend();
|
||||
MarkWholeScreenDirty();
|
||||
}
|
||||
|
||||
static void StationSpreadChanged(int32 p1)
|
||||
static void StationSpreadChanged(int32_t)
|
||||
{
|
||||
InvalidateWindowData(WC_SELECT_STATION, 0);
|
||||
InvalidateWindowData(WC_BUILD_STATION, 0);
|
||||
}
|
||||
|
||||
static void UpdateConsists(int32 new_value)
|
||||
static void UpdateConsists(int32_t)
|
||||
{
|
||||
for (Train *t : Train::Iterate()) {
|
||||
/* Update the consist of all trains so the maximum speed is set correctly. */
|
||||
@@ -125,8 +165,11 @@ static void UpdateConsists(int32 new_value)
|
||||
InvalidateWindowClassesData(WC_BUILD_VEHICLE, 0);
|
||||
}
|
||||
|
||||
/* Check service intervals of vehicles, newvalue is value of % or day based servicing */
|
||||
static void UpdateAllServiceInterval(int32 new_value)
|
||||
/**
|
||||
* Check and update if needed all vehicle service intervals.
|
||||
* @param new_value Contains 0 if service intervals are in time (days or real-world minutes), otherwise intervals use percents.
|
||||
*/
|
||||
static void UpdateAllServiceInterval(int32_t new_value)
|
||||
{
|
||||
bool update_vehicles;
|
||||
VehicleDefaultSettings *vds;
|
||||
@@ -139,15 +182,23 @@ static void UpdateAllServiceInterval(int32 new_value)
|
||||
}
|
||||
|
||||
if (new_value != 0) {
|
||||
vds->servint_trains = 50;
|
||||
vds->servint_roadveh = 50;
|
||||
vds->servint_aircraft = 50;
|
||||
vds->servint_ships = 50;
|
||||
/* Service intervals are in percents. */
|
||||
vds->servint_trains = DEF_SERVINT_PERCENT;
|
||||
vds->servint_roadveh = DEF_SERVINT_PERCENT;
|
||||
vds->servint_aircraft = DEF_SERVINT_PERCENT;
|
||||
vds->servint_ships = DEF_SERVINT_PERCENT;
|
||||
} else if (TimerGameEconomy::UsingWallclockUnits(_game_mode == GM_MENU)) {
|
||||
/* Service intervals are in minutes. */
|
||||
vds->servint_trains = DEF_SERVINT_MINUTES_TRAINS;
|
||||
vds->servint_roadveh = DEF_SERVINT_MINUTES_ROADVEH;
|
||||
vds->servint_aircraft = DEF_SERVINT_MINUTES_AIRCRAFT;
|
||||
vds->servint_ships = DEF_SERVINT_MINUTES_SHIPS;
|
||||
} else {
|
||||
vds->servint_trains = 150;
|
||||
vds->servint_roadveh = 150;
|
||||
vds->servint_aircraft = 100;
|
||||
vds->servint_ships = 360;
|
||||
/* Service intervals are in days. */
|
||||
vds->servint_trains = DEF_SERVINT_DAYS_TRAINS;
|
||||
vds->servint_roadveh = DEF_SERVINT_DAYS_ROADVEH;
|
||||
vds->servint_aircraft = DEF_SERVINT_DAYS_AIRCRAFT;
|
||||
vds->servint_ships = DEF_SERVINT_DAYS_SHIPS;
|
||||
}
|
||||
|
||||
if (update_vehicles) {
|
||||
@@ -163,7 +214,7 @@ static void UpdateAllServiceInterval(int32 new_value)
|
||||
SetWindowClassesDirty(WC_VEHICLE_DETAILS);
|
||||
}
|
||||
|
||||
static bool CanUpdateServiceInterval(VehicleType type, int32 &new_value)
|
||||
static bool CanUpdateServiceInterval(VehicleType, int32_t &new_value)
|
||||
{
|
||||
VehicleDefaultSettings *vds;
|
||||
if (_game_mode == GM_MENU || !Company::IsValidID(_current_company)) {
|
||||
@@ -173,11 +224,11 @@ static bool CanUpdateServiceInterval(VehicleType type, int32 &new_value)
|
||||
}
|
||||
|
||||
/* Test if the interval is valid */
|
||||
int32 interval = GetServiceIntervalClamped(new_value, vds->servint_ispercent);
|
||||
int32_t interval = GetServiceIntervalClamped(new_value, vds->servint_ispercent);
|
||||
return interval == new_value;
|
||||
}
|
||||
|
||||
static void UpdateServiceInterval(VehicleType type, int32 new_value)
|
||||
static void UpdateServiceInterval(VehicleType type, int32_t new_value)
|
||||
{
|
||||
if (_game_mode != GM_MENU && Company::IsValidID(_current_company)) {
|
||||
for (Vehicle *v : Vehicle::Iterate()) {
|
||||
@@ -190,7 +241,7 @@ static void UpdateServiceInterval(VehicleType type, int32 new_value)
|
||||
SetWindowClassesDirty(WC_VEHICLE_DETAILS);
|
||||
}
|
||||
|
||||
static void TrainAccelerationModelChanged(int32 new_value)
|
||||
static void TrainAccelerationModelChanged(int32_t)
|
||||
{
|
||||
for (Train *t : Train::Iterate()) {
|
||||
if (t->IsFrontEngine()) {
|
||||
@@ -207,9 +258,8 @@ static void TrainAccelerationModelChanged(int32 new_value)
|
||||
|
||||
/**
|
||||
* This function updates the train acceleration cache after a steepness change.
|
||||
* @param new_value Unused new value of setting.
|
||||
*/
|
||||
static void TrainSlopeSteepnessChanged(int32 new_value)
|
||||
static void TrainSlopeSteepnessChanged(int32_t)
|
||||
{
|
||||
for (Train *t : Train::Iterate()) {
|
||||
if (t->IsFrontEngine()) t->CargoChanged();
|
||||
@@ -218,9 +268,8 @@ static void TrainSlopeSteepnessChanged(int32 new_value)
|
||||
|
||||
/**
|
||||
* This function updates realistic acceleration caches when the setting "Road vehicle acceleration model" is set.
|
||||
* @param new_value Unused new value of setting.
|
||||
*/
|
||||
static void RoadVehAccelerationModelChanged(int32 new_value)
|
||||
static void RoadVehAccelerationModelChanged(int32_t)
|
||||
{
|
||||
if (_settings_game.vehicle.roadveh_acceleration_model != AM_ORIGINAL) {
|
||||
for (RoadVehicle *rv : RoadVehicle::Iterate()) {
|
||||
@@ -238,16 +287,15 @@ static void RoadVehAccelerationModelChanged(int32 new_value)
|
||||
|
||||
/**
|
||||
* This function updates the road vehicle acceleration cache after a steepness change.
|
||||
* @param new_value Unused new value of setting.
|
||||
*/
|
||||
static void RoadVehSlopeSteepnessChanged(int32 new_value)
|
||||
static void RoadVehSlopeSteepnessChanged(int32_t)
|
||||
{
|
||||
for (RoadVehicle *rv : RoadVehicle::Iterate()) {
|
||||
if (rv->IsFrontEngine()) rv->CargoChanged();
|
||||
}
|
||||
}
|
||||
|
||||
static void TownFoundingChanged(int32 new_value)
|
||||
static void TownFoundingChanged(int32_t)
|
||||
{
|
||||
if (_game_mode != GM_EDITOR && _settings_game.economy.found_town == TF_FORBIDDEN) {
|
||||
CloseWindowById(WC_FOUND_TOWN, 0);
|
||||
@@ -256,16 +304,13 @@ static void TownFoundingChanged(int32 new_value)
|
||||
}
|
||||
}
|
||||
|
||||
static void ZoomMinMaxChanged(int32 new_value)
|
||||
static void ZoomMinMaxChanged(int32_t)
|
||||
{
|
||||
extern void ConstrainAllViewportsZoom();
|
||||
ConstrainAllViewportsZoom();
|
||||
GfxClearSpriteCache();
|
||||
if (_settings_client.gui.zoom_min > _gui_zoom) {
|
||||
/* Restrict GUI zoom if it is no longer available. */
|
||||
_gui_zoom = _settings_client.gui.zoom_min;
|
||||
UpdateCursorSize();
|
||||
LoadStringWidthTable();
|
||||
InvalidateWindowClassesData(WC_SPRITE_ALIGNER);
|
||||
if (AdjustGUIZoom(false)) {
|
||||
ReInitAllWindows(true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -278,7 +323,7 @@ static void VerticalToolbarChanged(int32 p1)
|
||||
}
|
||||
}
|
||||
|
||||
static void SpriteZoomMinChanged(int32 new_value)
|
||||
static void SpriteZoomMinChanged(int32_t)
|
||||
{
|
||||
GfxClearSpriteCache();
|
||||
/* Force all sprites to redraw at the new chosen zoom level */
|
||||
@@ -289,22 +334,21 @@ static void SpriteZoomMinChanged(int32 new_value)
|
||||
* Update any possible saveload window and delete any newgrf dialogue as
|
||||
* its widget parts might change. Reinit all windows as it allows access to the
|
||||
* newgrf debug button.
|
||||
* @param new_value unused.
|
||||
*/
|
||||
static void InvalidateNewGRFChangeWindows(int32 new_value)
|
||||
static void InvalidateNewGRFChangeWindows(int32_t)
|
||||
{
|
||||
InvalidateWindowClassesData(WC_SAVELOAD);
|
||||
CloseWindowByClass(WC_GAME_OPTIONS);
|
||||
ReInitAllWindows(false);
|
||||
}
|
||||
|
||||
static void InvalidateCompanyLiveryWindow(int32 new_value)
|
||||
static void InvalidateCompanyLiveryWindow(int32_t)
|
||||
{
|
||||
InvalidateWindowClassesData(WC_COMPANY_COLOUR, -1);
|
||||
ResetVehicleColourMap();
|
||||
}
|
||||
|
||||
static void DifficultyNoiseChange(int32 new_value)
|
||||
static void DifficultyNoiseChange(int32_t)
|
||||
{
|
||||
if (_game_mode == GM_NORMAL) {
|
||||
UpdateAirportsNoise();
|
||||
@@ -314,10 +358,10 @@ static void DifficultyNoiseChange(int32 new_value)
|
||||
}
|
||||
}
|
||||
|
||||
static void MaxNoAIsChange(int32 new_value)
|
||||
static void MaxNoAIsChange(int32_t)
|
||||
{
|
||||
if (GetGameSettings().difficulty.max_no_competitors != 0 &&
|
||||
AI::GetInfoList()->size() == 0 &&
|
||||
AI::GetInfoList()->empty() &&
|
||||
(!_networking || _network_server)) {
|
||||
ShowErrorMessage(STR_WARNING_NO_SUITABLE_AI, INVALID_STRING_ID, WL_CRITICAL);
|
||||
}
|
||||
@@ -327,12 +371,10 @@ static void MaxNoAIsChange(int32 new_value)
|
||||
|
||||
/**
|
||||
* Check whether the road side may be changed.
|
||||
* @param new_value unused
|
||||
* @return true if the road side may be changed.
|
||||
*/
|
||||
static bool CheckRoadSide(int32 &new_value)
|
||||
static bool CheckRoadSide(int32_t &)
|
||||
{
|
||||
extern bool RoadVehiclesAreBuilt();
|
||||
return _game_mode == GM_MENU || !RoadVehiclesAreBuilt();
|
||||
}
|
||||
|
||||
@@ -350,7 +392,7 @@ static size_t ConvertLandscape(const char *value)
|
||||
return OneOfManySettingDesc::ParseSingleValue(value, strlen(value), _old_landscape_values);
|
||||
}
|
||||
|
||||
static bool CheckFreeformEdges(int32 &new_value)
|
||||
static bool CheckFreeformEdges(int32_t &new_value)
|
||||
{
|
||||
if (_game_mode == GM_MENU) return true;
|
||||
if (new_value != 0) {
|
||||
@@ -369,26 +411,26 @@ static bool CheckFreeformEdges(int32 &new_value)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (uint i = 0; i < MapMaxX(); i++) {
|
||||
for (uint i = 0; i < Map::MaxX(); i++) {
|
||||
if (TileHeight(TileXY(i, 1)) != 0) {
|
||||
ShowErrorMessage(STR_CONFIG_SETTING_EDGES_NOT_WATER, INVALID_STRING_ID, WL_ERROR);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
for (uint i = 1; i < MapMaxX(); i++) {
|
||||
if (!IsTileType(TileXY(i, MapMaxY() - 1), MP_WATER) || TileHeight(TileXY(1, MapMaxY())) != 0) {
|
||||
for (uint i = 1; i < Map::MaxX(); i++) {
|
||||
if (!IsTileType(TileXY(i, Map::MaxY() - 1), MP_WATER) || TileHeight(TileXY(1, Map::MaxY())) != 0) {
|
||||
ShowErrorMessage(STR_CONFIG_SETTING_EDGES_NOT_WATER, INVALID_STRING_ID, WL_ERROR);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
for (uint i = 0; i < MapMaxY(); i++) {
|
||||
for (uint i = 0; i < Map::MaxY(); i++) {
|
||||
if (TileHeight(TileXY(1, i)) != 0) {
|
||||
ShowErrorMessage(STR_CONFIG_SETTING_EDGES_NOT_WATER, INVALID_STRING_ID, WL_ERROR);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
for (uint i = 1; i < MapMaxY(); i++) {
|
||||
if (!IsTileType(TileXY(MapMaxX() - 1, i), MP_WATER) || TileHeight(TileXY(MapMaxX(), i)) != 0) {
|
||||
for (uint i = 1; i < Map::MaxY(); i++) {
|
||||
if (!IsTileType(TileXY(Map::MaxX() - 1, i), MP_WATER) || TileHeight(TileXY(Map::MaxX(), i)) != 0) {
|
||||
ShowErrorMessage(STR_CONFIG_SETTING_EDGES_NOT_WATER, INVALID_STRING_ID, WL_ERROR);
|
||||
return false;
|
||||
}
|
||||
@@ -397,20 +439,20 @@ static bool CheckFreeformEdges(int32 &new_value)
|
||||
return true;
|
||||
}
|
||||
|
||||
static void UpdateFreeformEdges(int32 new_value)
|
||||
static void UpdateFreeformEdges(int32_t new_value)
|
||||
{
|
||||
if (_game_mode == GM_MENU) return;
|
||||
|
||||
if (new_value != 0) {
|
||||
for (uint x = 0; x < MapSizeX(); x++) MakeVoid(TileXY(x, 0));
|
||||
for (uint y = 0; y < MapSizeY(); y++) MakeVoid(TileXY(0, y));
|
||||
for (uint x = 0; x < Map::SizeX(); x++) MakeVoid(TileXY(x, 0));
|
||||
for (uint y = 0; y < Map::SizeY(); y++) MakeVoid(TileXY(0, y));
|
||||
} else {
|
||||
/* Make tiles at the border water again. */
|
||||
for (uint i = 0; i < MapMaxX(); i++) {
|
||||
for (uint i = 0; i < Map::MaxX(); i++) {
|
||||
SetTileHeight(TileXY(i, 0), 0);
|
||||
SetTileType(TileXY(i, 0), MP_WATER);
|
||||
}
|
||||
for (uint i = 0; i < MapMaxY(); i++) {
|
||||
for (uint i = 0; i < Map::MaxY(); i++) {
|
||||
SetTileHeight(TileXY(0, i), 0);
|
||||
SetTileType(TileXY(0, i), MP_WATER);
|
||||
}
|
||||
@@ -422,7 +464,7 @@ static void UpdateFreeformEdges(int32 new_value)
|
||||
* Changing the setting "allow multiple NewGRF sets" is not allowed
|
||||
* if there are vehicles.
|
||||
*/
|
||||
static bool CheckDynamicEngines(int32 &new_value)
|
||||
static bool CheckDynamicEngines(int32_t &)
|
||||
{
|
||||
if (_game_mode == GM_MENU) return true;
|
||||
|
||||
@@ -434,15 +476,15 @@ static bool CheckDynamicEngines(int32 &new_value)
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool CheckMaxHeightLevel(int32 &new_value)
|
||||
static bool CheckMaxHeightLevel(int32_t &new_value)
|
||||
{
|
||||
if (_game_mode == GM_NORMAL) return false;
|
||||
if (_game_mode != GM_EDITOR) return true;
|
||||
|
||||
/* Check if at least one mountain on the map is higher than the new value.
|
||||
* If yes, disallow the change. */
|
||||
for (TileIndex t = 0; t < MapSize(); t++) {
|
||||
if ((int32)TileHeight(t) > new_value) {
|
||||
for (TileIndex t = 0; t < Map::Size(); t++) {
|
||||
if ((int32_t)TileHeight(t) > new_value) {
|
||||
ShowErrorMessage(STR_CONFIG_SETTING_TOO_HIGH_MOUNTAIN, INVALID_STRING_ID, WL_ERROR);
|
||||
/* Return old, unchanged value */
|
||||
return false;
|
||||
@@ -452,19 +494,19 @@ static bool CheckMaxHeightLevel(int32 &new_value)
|
||||
return true;
|
||||
}
|
||||
|
||||
static void StationCatchmentChanged(int32 new_value)
|
||||
static void StationCatchmentChanged(int32_t)
|
||||
{
|
||||
Station::RecomputeCatchmentForAll();
|
||||
MarkWholeScreenDirty();
|
||||
}
|
||||
|
||||
static void MaxVehiclesChanged(int32 new_value)
|
||||
static void MaxVehiclesChanged(int32_t)
|
||||
{
|
||||
InvalidateWindowClassesData(WC_BUILD_TOOLBAR);
|
||||
MarkWholeScreenDirty();
|
||||
}
|
||||
|
||||
static void InvalidateShipPathCache(int32 new_value)
|
||||
static void InvalidateShipPathCache(int32_t)
|
||||
{
|
||||
for (Ship *s : Ship::Iterate()) {
|
||||
s->path.clear();
|
||||
@@ -486,7 +528,97 @@ static bool ReplaceAsteriskWithEmptyPassword(std::string &newval)
|
||||
static void UpdateClientConfigValues()
|
||||
{
|
||||
NetworkServerUpdateGameInfo();
|
||||
if (_network_server) NetworkServerSendConfigUpdate();
|
||||
|
||||
if (_network_server) {
|
||||
NetworkServerSendConfigUpdate();
|
||||
SetWindowClassesDirty(WC_CLIENT_LIST);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for when the player changes the timekeeping units.
|
||||
* @param Unused.
|
||||
*/
|
||||
static void ChangeTimekeepingUnits(int32_t)
|
||||
{
|
||||
/* If service intervals are in time units (calendar days or real-world minutes), reset them to the correct defaults. */
|
||||
if (!_settings_client.company.vehicle.servint_ispercent) {
|
||||
UpdateAllServiceInterval(0);
|
||||
}
|
||||
|
||||
/* If we are using calendar timekeeping, "minutes per year" must be default. */
|
||||
if (!TimerGameEconomy::UsingWallclockUnits(true)) {
|
||||
_settings_newgame.economy.minutes_per_calendar_year = CalendarTime::DEF_MINUTES_PER_YEAR;
|
||||
}
|
||||
|
||||
InvalidateWindowClassesData(WC_GAME_OPTIONS, 0);
|
||||
|
||||
/* It is possible to change these units in Scenario Editor. We must set the economy date appropriately. */
|
||||
if (_game_mode == GM_EDITOR) {
|
||||
TimerGameEconomy::Date new_economy_date;
|
||||
TimerGameEconomy::DateFract new_economy_date_fract;
|
||||
|
||||
if (TimerGameEconomy::UsingWallclockUnits()) {
|
||||
/* If the new mode is wallclock units, set the economy year back to 1. */
|
||||
new_economy_date = TimerGameEconomy::ConvertYMDToDate(1, 0, 1);
|
||||
new_economy_date_fract = 0;
|
||||
} else {
|
||||
/* If the new mode is calendar units, sync the economy year with the calendar year. */
|
||||
new_economy_date = TimerGameCalendar::date.base();
|
||||
new_economy_date_fract = TimerGameCalendar::date_fract;
|
||||
}
|
||||
|
||||
/* If you open a savegame as a scenario, there may already be link graphs and/or vehicles. These use economy date. */
|
||||
LinkGraphSchedule::instance.ShiftDates(new_economy_date - TimerGameEconomy::date);
|
||||
for (auto v : Vehicle::Iterate()) v->ShiftDates(new_economy_date - TimerGameEconomy::date);
|
||||
|
||||
/* Only change the date after changing cached values above. */
|
||||
TimerGameEconomy::SetDate(new_economy_date, new_economy_date_fract);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback after the player changes the minutes per year.
|
||||
* @param new_value The intended new value of the setting, used for clamping.
|
||||
*/
|
||||
static void ChangeMinutesPerYear(int32_t new_value)
|
||||
{
|
||||
/* We don't allow setting Minutes Per Year below default, unless it's to 0 for frozen calendar time. */
|
||||
if (new_value < CalendarTime::DEF_MINUTES_PER_YEAR) {
|
||||
int clamped;
|
||||
|
||||
/* If the new value is 1, we're probably at 0 and trying to increase the value, so we should jump up to default. */
|
||||
if (new_value == 1) {
|
||||
clamped = CalendarTime::DEF_MINUTES_PER_YEAR;
|
||||
} else {
|
||||
clamped = CalendarTime::FROZEN_MINUTES_PER_YEAR;
|
||||
}
|
||||
|
||||
/* Override the setting with the clamped value. */
|
||||
if (_game_mode == GM_MENU) {
|
||||
_settings_newgame.economy.minutes_per_calendar_year = clamped;
|
||||
} else {
|
||||
_settings_game.economy.minutes_per_calendar_year = clamped;
|
||||
}
|
||||
}
|
||||
|
||||
/* If the setting value is not the default, force the game to use wallclock timekeeping units.
|
||||
* This can only happen in the menu, since the pre_cb ensures this setting can only be changed there, or if we're already using wallclock units.
|
||||
*/
|
||||
if (_game_mode == GM_MENU && (_settings_newgame.economy.minutes_per_calendar_year != CalendarTime::DEF_MINUTES_PER_YEAR)) {
|
||||
_settings_newgame.economy.timekeeping_units = TKU_WALLCLOCK;
|
||||
InvalidateWindowClassesData(WC_GAME_OPTIONS, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Pre-callback check when trying to change the timetable mode. This is locked to Seconds when using wallclock units.
|
||||
* @param Unused.
|
||||
* @return True if we allow changing the timetable mode.
|
||||
*/
|
||||
static bool CanChangeTimetableMode(int32_t &)
|
||||
{
|
||||
return !TimerGameEconomy::UsingWallclockUnits();
|
||||
}
|
||||
|
||||
/* End - Callback Functions */
|
||||
|
||||
Reference in New Issue
Block a user