OpenTTD Source: src/settings_table.cpp Source File

OpenTTD Source 15.3

settings_table.cpp
Go to the documentation of this file.
1/*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
12#include "stdafx.h"
13#include "settings_table.h"
14#include "currency.h"
15#include "screenshot.h"
16#include "network/network.h"
17#include "network/network_func.h"
18#include "network/core/config.h"
19#include "pathfinder/pathfinder_type.h"
20#include "linkgraph/linkgraphschedule.h"
21#include "genworld.h"
22#include "train.h"
23#include "news_func.h"
24#include "window_func.h"
25#include "company_func.h"
26#include "timer/timer_game_calendar.h"
27#if defined(WITH_FREETYPE) || defined(_WIN32) || defined(WITH_COCOA)
28#define HAS_TRUETYPE_FONT
29#include "fontcache.h"
30#endif
31#include "textbuf_gui.h"
32#include "rail_gui.h"
33#include "elrail_func.h"
34#include "error.h"
35#include "town.h"
36#include "video/video_driver.hpp"
37#include "sound/sound_driver.hpp"
38#include "music/music_driver.hpp"
39#include "blitter/factory.hpp"
40#include "base_media_base.h"
41#include "base_media_music.h"
42#include "base_media_sounds.h"
43#include "ai/ai_config.hpp"
44#include "ai/ai.hpp"
45#include "game/game_config.hpp"
46#include "ship.h"
47#include "smallmap_gui.h"
48#include "roadveh.h"
49#include "roadveh_cmd.h"
50#include "vehicle_func.h"
51#include "viewport_func.h"
52#include "void_map.h"
53#include "station_func.h"
54#include "station_base.h"
55
56#include "table/strings.h"
57#include "table/settings.h"
58
59#include "safeguards.h"
60
61SettingTable _company_settings{ _company_settings_table };
62SettingTable _currency_settings{ _currency_settings_table };
63SettingTable _difficulty_settings{ _difficulty_settings_table };
64SettingTable _multimedia_settings{ _multimedia_settings_table };
65SettingTable _economy_settings{ _economy_settings_table };
66SettingTable _game_settings{ _game_settings_table };
67SettingTable _gui_settings{ _gui_settings_table };
68SettingTable _linkgraph_settings{ _linkgraph_settings_table };
69SettingTable _locale_settings{ _locale_settings_table };
70SettingTable _misc_settings{ _misc_settings_table };
71SettingTable _network_private_settings{ _network_private_settings_table };
72SettingTable _network_secrets_settings{ _network_secrets_settings_table };
73SettingTable _network_settings{ _network_settings_table };
74SettingTable _news_display_settings{ _news_display_settings_table };
75SettingTable _old_gameopt_settings{ _old_gameopt_settings_table };
76SettingTable _pathfinding_settings{ _pathfinding_settings_table };
77SettingTable _script_settings{ _script_settings_table };
78SettingTable _window_settings{ _window_settings_table };
79SettingTable _world_settings{ _world_settings_table };
80#if defined(_WIN32) && !defined(DEDICATED)
81SettingTable _win32_settings{ _win32_settings_table };
82#endif /* _WIN32 */
83
84
85/* Begin - Callback Functions for the various settings. */
86
88 static StringID SettingTitleWallclock(const IntSettingDesc &sd)
89{
90 return TimerGameEconomy::UsingWallclockUnits(_game_mode == GM_MENU) ? sd.str + 1 : sd.str;
91}
92
94 static StringID SettingHelpWallclock(const IntSettingDesc &sd)
95{
96 return TimerGameEconomy::UsingWallclockUnits(_game_mode == GM_MENU) ? sd.str_help + 1 : sd.str_help;
97}
98
100 static std::pair<StringParameter, StringParameter> SettingsValueVelocityUnit(const IntSettingDesc &, int32_t value)
101{
102 StringID val;
103 switch (value) {
104 case 0: val = STR_CONFIG_SETTING_LOCALISATION_UNITS_VELOCITY_IMPERIAL; break;
105 case 1: val = STR_CONFIG_SETTING_LOCALISATION_UNITS_VELOCITY_METRIC; break;
106 case 2: val = STR_CONFIG_SETTING_LOCALISATION_UNITS_VELOCITY_SI; break;
107 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;
108 case 4: val = STR_CONFIG_SETTING_LOCALISATION_UNITS_VELOCITY_KNOTS; break;
109 default: NOT_REACHED();
110 }
111 return {val, {}};
112}
113
115 static std::pair<StringParameter, StringParameter> SettingsValueAbsolute(const IntSettingDesc &sd, int32_t value)
116{
117 return {sd.str_val + ((value >= 0) ? 1 : 0), abs(value)};
118}
119
121 static std::pair<StringParameter, StringParameter> ServiceIntervalSettingsValueText(const IntSettingDesc &sd, int32_t value)
122{
123 VehicleDefaultSettings *vds;
124 if (_game_mode == GM_MENU || !Company::IsValidID(_current_company)) {
125 vds = &_settings_client.company.vehicle;
126 } else {
127 vds = &Company::Get(_current_company)->settings.vehicle;
128 }
129
130 StringID str;
131 if (value == 0) {
132 str = sd.str_val + 3;
133 } else if (vds->servint_ispercent) {
134 str = sd.str_val + 2;
135 } else if (TimerGameEconomy::UsingWallclockUnits(_game_mode == GM_MENU)) {
136 str = sd.str_val + 1;
137 } else {
138 str = sd.str_val;
139 }
140 return {str, value};
141}
142
144 static void v_PositionMainToolbar(int32_t)
145{
146 if (_game_mode != GM_MENU) PositionMainToolbar(nullptr);
147}
148
150 static void v_PositionStatusbar(int32_t)
151{
152 if (_game_mode != GM_MENU) {
153 PositionStatusbar(nullptr);
154 PositionNewsMessage(nullptr);
155 PositionNetworkChatWindow(nullptr);
156 }
157}
158
162 static void RedrawSmallmap(int32_t)
163{
164 BuildLandLegend();
165 BuildOwnerLegend();
166 SetWindowClassesDirty(WC_SMALLMAP);
167}
168
170 static void UpdateLinkgraphColours(int32_t)
171{
172 BuildLinkStatsLegend();
173 MarkWholeScreenDirty();
174}
175
176static void StationSpreadChanged(int32_t)
177{
178 InvalidateWindowData(WC_SELECT_STATION, 0);
179 InvalidateWindowData(WC_BUILD_STATION, 0);
180}
181
182static void UpdateConsists(int32_t)
183{
184 for (Train *t : Train::Iterate()) {
185 /* Update the consist of all trains so the maximum speed is set correctly. */
186 if (t->IsFrontEngine() || t->IsFreeWagon()) t->ConsistChanged(CCF_TRACK);
187 }
188 InvalidateWindowClassesData(WC_BUILD_VEHICLE, 0);
189}
190
195 static void UpdateAllServiceInterval(int32_t new_value)
196{
197 bool update_vehicles;
198 VehicleDefaultSettings *vds;
199 if (_game_mode == GM_MENU || !Company::IsValidID(_current_company)) {
200 vds = &_settings_client.company.vehicle;
201 update_vehicles = false;
202 } else {
203 vds = &Company::Get(_current_company)->settings.vehicle;
204 update_vehicles = true;
205 }
206
207 if (new_value != 0) {
208 /* Service intervals are in percents. */
209 vds->servint_trains = DEF_SERVINT_PERCENT;
210 vds->servint_roadveh = DEF_SERVINT_PERCENT;
211 vds->servint_aircraft = DEF_SERVINT_PERCENT;
212 vds->servint_ships = DEF_SERVINT_PERCENT;
213 } else if (TimerGameEconomy::UsingWallclockUnits(_game_mode == GM_MENU)) {
214 /* Service intervals are in minutes. */
215 vds->servint_trains = DEF_SERVINT_MINUTES_TRAINS;
216 vds->servint_roadveh = DEF_SERVINT_MINUTES_ROADVEH;
217 vds->servint_aircraft = DEF_SERVINT_MINUTES_AIRCRAFT;
218 vds->servint_ships = DEF_SERVINT_MINUTES_SHIPS;
219 } else {
220 /* Service intervals are in days. */
221 vds->servint_trains = DEF_SERVINT_DAYS_TRAINS;
222 vds->servint_roadveh = DEF_SERVINT_DAYS_ROADVEH;
223 vds->servint_aircraft = DEF_SERVINT_DAYS_AIRCRAFT;
224 vds->servint_ships = DEF_SERVINT_DAYS_SHIPS;
225 }
226
227 if (update_vehicles) {
228 const Company *c = Company::Get(_current_company);
229 for (Vehicle *v : Vehicle::Iterate()) {
230 if (v->owner == _current_company && v->IsPrimaryVehicle() && !v->ServiceIntervalIsCustom()) {
231 v->SetServiceInterval(CompanyServiceInterval(c, v->type));
232 v->SetServiceIntervalIsPercent(new_value != 0);
233 }
234 }
235 }
236
237 SetWindowClassesDirty(WC_VEHICLE_DETAILS);
238}
239
240static bool CanUpdateServiceInterval(VehicleType, int32_t &new_value)
241{
242 VehicleDefaultSettings *vds;
243 if (_game_mode == GM_MENU || !Company::IsValidID(_current_company)) {
244 vds = &_settings_client.company.vehicle;
245 } else {
246 vds = &Company::Get(_current_company)->settings.vehicle;
247 }
248
249 /* Test if the interval is valid */
250 int32_t interval = GetServiceIntervalClamped(new_value, vds->servint_ispercent);
251 return new_value == 0 || interval == new_value;
252}
253
254static void UpdateServiceInterval(VehicleType type, int32_t new_value)
255{
256 if (_game_mode != GM_MENU && Company::IsValidID(_current_company)) {
257 for (Vehicle *v : Vehicle::Iterate()) {
258 if (v->owner == _current_company && v->type == type && v->IsPrimaryVehicle() && !v->ServiceIntervalIsCustom()) {
259 v->SetServiceInterval(new_value);
260 }
261 }
262 }
263
264 SetWindowClassesDirty(WC_VEHICLE_DETAILS);
265}
266
270 static int32_t GetDefaultServiceInterval(const IntSettingDesc &sd, VehicleType type)
271{
272 VehicleDefaultSettings *vds;
273 if (_game_mode == GM_MENU || !Company::IsValidID(_current_company)) {
274 vds = &_settings_client.company.vehicle;
275 } else {
276 vds = &Company::Get(_current_company)->settings.vehicle;
277 }
278
279 if (vds->servint_ispercent) return DEF_SERVINT_PERCENT;
280
281 if (TimerGameEconomy::UsingWallclockUnits(_game_mode == GM_MENU)) {
282 switch (type) {
283 case VEH_TRAIN: return DEF_SERVINT_MINUTES_TRAINS;
284 case VEH_ROAD: return DEF_SERVINT_MINUTES_ROADVEH;
285 case VEH_AIRCRAFT: return DEF_SERVINT_MINUTES_AIRCRAFT;
286 case VEH_SHIP: return DEF_SERVINT_MINUTES_SHIPS;
287 default: NOT_REACHED();
288 }
289 }
290
291 return sd.def;
292}
293
294static std::tuple<int32_t, uint32_t> GetServiceIntervalRange(const IntSettingDesc &)
295{
296 VehicleDefaultSettings *vds;
297 if (_game_mode == GM_MENU || !Company::IsValidID(_current_company)) {
298 vds = &_settings_client.company.vehicle;
299 } else {
300 vds = &Company::Get(_current_company)->settings.vehicle;
301 }
302
303 if (vds->servint_ispercent) return { MIN_SERVINT_PERCENT, MAX_SERVINT_PERCENT };
304
305 if (TimerGameEconomy::UsingWallclockUnits(_game_mode == GM_MENU)) {
306 return { MIN_SERVINT_MINUTES, MAX_SERVINT_MINUTES };
307 }
308
309 return { MIN_SERVINT_DAYS, MAX_SERVINT_DAYS };
310}
311
312static void TrainAccelerationModelChanged(int32_t)
313{
314 for (Train *t : Train::Iterate()) {
315 if (t->IsFrontEngine()) {
316 t->tcache.cached_max_curve_speed = t->GetCurveSpeedLimit();
317 t->UpdateAcceleration();
318 }
319 }
320
321 /* These windows show acceleration values only when realistic acceleration is on. They must be redrawn after a setting change. */
322 SetWindowClassesDirty(WC_ENGINE_PREVIEW);
323 InvalidateWindowClassesData(WC_BUILD_VEHICLE, 0);
324 SetWindowClassesDirty(WC_VEHICLE_DETAILS);
325}
326
330 static void TrainSlopeSteepnessChanged(int32_t)
331{
332 for (Train *t : Train::Iterate()) {
333 if (t->IsFrontEngine()) t->CargoChanged();
334 }
335}
336
340 static void RoadVehAccelerationModelChanged(int32_t)
341{
342 if (_settings_game.vehicle.roadveh_acceleration_model != AM_ORIGINAL) {
343 for (RoadVehicle *rv : RoadVehicle::Iterate()) {
344 if (rv->IsFrontEngine()) {
345 rv->CargoChanged();
346 }
347 }
348 }
349
350 /* These windows show acceleration values only when realistic acceleration is on. They must be redrawn after a setting change. */
351 SetWindowClassesDirty(WC_ENGINE_PREVIEW);
352 InvalidateWindowClassesData(WC_BUILD_VEHICLE, 0);
353 SetWindowClassesDirty(WC_VEHICLE_DETAILS);
354}
355
359 static void RoadVehSlopeSteepnessChanged(int32_t)
360{
361 for (RoadVehicle *rv : RoadVehicle::Iterate()) {
362 if (rv->IsFrontEngine()) rv->CargoChanged();
363 }
364}
365
366static void TownFoundingChanged(int32_t)
367{
368 if (_game_mode != GM_EDITOR && _settings_game.economy.found_town == TF_FORBIDDEN) {
369 CloseWindowById(WC_FOUND_TOWN, 0);
370 } else {
371 InvalidateWindowData(WC_FOUND_TOWN, 0);
372 }
373}
374
375static void ZoomMinMaxChanged(int32_t)
376{
377 ConstrainAllViewportsZoom();
378 GfxClearSpriteCache();
379 InvalidateWindowClassesData(WC_SPRITE_ALIGNER);
380 if (AdjustGUIZoom(false)) {
381 ReInitAllWindows(true);
382 }
383}
384
385static void SpriteZoomMinChanged(int32_t)
386{
387 GfxClearSpriteCache();
388 /* Force all sprites to redraw at the new chosen zoom level */
389 MarkWholeScreenDirty();
390}
391
397 static void InvalidateNewGRFChangeWindows(int32_t)
398{
399 InvalidateWindowClassesData(WC_SAVELOAD);
400 CloseWindowByClass(WC_GAME_OPTIONS);
401 ReInitAllWindows(false);
402}
403
404static void InvalidateCompanyLiveryWindow(int32_t)
405{
406 InvalidateWindowClassesData(WC_COMPANY_COLOUR, -1);
407 ResetVehicleColourMap();
408}
409
410static void DifficultyNoiseChange(int32_t)
411{
412 if (_game_mode == GM_NORMAL) {
413 UpdateAirportsNoise();
414 if (_settings_game.economy.station_noise_level) {
415 InvalidateWindowClassesData(WC_TOWN_VIEW, 0);
416 }
417 }
418}
419
420static void MaxNoAIsChange(int32_t)
421{
422 if (GetGameSettings().difficulty.max_no_competitors != 0 &&
423 AI::GetInfoList()->empty() &&
424 (!_networking || _network_server)) {
425 ShowErrorMessage(GetEncodedString(STR_WARNING_NO_SUITABLE_AI), {}, WL_CRITICAL);
426 }
427
428 InvalidateWindowClassesData(WC_GAME_OPTIONS, 0);
429}
430
435 static bool CheckRoadSide(int32_t &)
436{
437 return _game_mode == GM_MENU || !RoadVehiclesAreBuilt();
438}
439
447 static std::optional<uint32_t> ConvertLandscape(std::string_view value)
448{
449 /* try with the old values */
450 static constexpr std::initializer_list<std::string_view> _old_landscape_values{"normal"sv, "hilly"sv, "desert"sv, "candy"sv};
451 return OneOfManySettingDesc::ParseSingleValue(value, _old_landscape_values);
452}
453
454static bool CheckFreeformEdges(int32_t &new_value)
455{
456 if (_game_mode == GM_MENU) return true;
457 if (new_value != 0) {
458 for (Ship *s : Ship::Iterate()) {
459 /* Check if there is a ship on the northern border. */
460 if (TileX(s->tile) == 0 || TileY(s->tile) == 0) {
461 ShowErrorMessage(GetEncodedString(STR_CONFIG_SETTING_EDGES_NOT_EMPTY), {}, WL_ERROR);
462 return false;
463 }
464 }
465 for (const BaseStation *st : BaseStation::Iterate()) {
466 /* Check if there is a non-deleted buoy on the northern border. */
467 if (st->IsInUse() && (TileX(st->xy) == 0 || TileY(st->xy) == 0)) {
468 ShowErrorMessage(GetEncodedString(STR_CONFIG_SETTING_EDGES_NOT_EMPTY), {}, WL_ERROR);
469 return false;
470 }
471 }
472 } else {
473 for (uint i = 0; i < Map::MaxX(); i++) {
474 if (TileHeight(TileXY(i, 1)) != 0) {
475 ShowErrorMessage(GetEncodedString(STR_CONFIG_SETTING_EDGES_NOT_WATER), {}, WL_ERROR);
476 return false;
477 }
478 }
479 for (uint i = 1; i < Map::MaxX(); i++) {
480 if (!IsTileType(TileXY(i, Map::MaxY() - 1), MP_WATER) || TileHeight(TileXY(1, Map::MaxY())) != 0) {
481 ShowErrorMessage(GetEncodedString(STR_CONFIG_SETTING_EDGES_NOT_WATER), {}, WL_ERROR);
482 return false;
483 }
484 }
485 for (uint i = 0; i < Map::MaxY(); i++) {
486 if (TileHeight(TileXY(1, i)) != 0) {
487 ShowErrorMessage(GetEncodedString(STR_CONFIG_SETTING_EDGES_NOT_WATER), {}, WL_ERROR);
488 return false;
489 }
490 }
491 for (uint i = 1; i < Map::MaxY(); i++) {
492 if (!IsTileType(TileXY(Map::MaxX() - 1, i), MP_WATER) || TileHeight(TileXY(Map::MaxX(), i)) != 0) {
493 ShowErrorMessage(GetEncodedString(STR_CONFIG_SETTING_EDGES_NOT_WATER), {}, WL_ERROR);
494 return false;
495 }
496 }
497 }
498 return true;
499}
500
501static void UpdateFreeformEdges(int32_t new_value)
502{
503 if (_game_mode == GM_MENU) return;
504
505 if (new_value != 0) {
506 for (uint x = 0; x < Map::SizeX(); x++) MakeVoid(TileXY(x, 0));
507 for (uint y = 0; y < Map::SizeY(); y++) MakeVoid(TileXY(0, y));
508 } else {
509 /* Make tiles at the border water again. */
510 for (uint i = 0; i < Map::MaxX(); i++) {
511 SetTileHeight(TileXY(i, 0), 0);
512 SetTileType(TileXY(i, 0), MP_WATER);
513 }
514 for (uint i = 0; i < Map::MaxY(); i++) {
515 SetTileHeight(TileXY(0, i), 0);
516 SetTileType(TileXY(0, i), MP_WATER);
517 }
518 }
519 MarkWholeScreenDirty();
520}
521
526 static bool CheckDynamicEngines(int32_t &)
527{
528 if (_game_mode == GM_MENU) return true;
529
530 if (!EngineOverrideManager::ResetToCurrentNewGRFConfig()) {
531 ShowErrorMessage(GetEncodedString(STR_CONFIG_SETTING_DYNAMIC_ENGINES_EXISTING_VEHICLES), {}, WL_ERROR);
532 return false;
533 }
534
535 return true;
536}
537
538static bool CheckMaxHeightLevel(int32_t &new_value)
539{
540 if (_game_mode == GM_NORMAL) return false;
541 if (_game_mode != GM_EDITOR) return true;
542
543 /* Check if at least one mountain on the map is higher than the new value.
544 * If yes, disallow the change. */
545 for (const auto t : Map::Iterate()) {
546 if ((int32_t)TileHeight(t) > new_value) {
547 ShowErrorMessage(GetEncodedString(STR_CONFIG_SETTING_TOO_HIGH_MOUNTAIN), {}, WL_ERROR);
548 /* Return old, unchanged value */
549 return false;
550 }
551 }
552
553 return true;
554}
555
556static void StationCatchmentChanged(int32_t)
557{
558 Station::RecomputeCatchmentForAll();
559 MarkWholeScreenDirty();
560}
561
562static void MaxVehiclesChanged(int32_t)
563{
564 InvalidateWindowClassesData(WC_BUILD_TOOLBAR);
565 MarkWholeScreenDirty();
566}
567
573 static bool ReplaceAsteriskWithEmptyPassword(std::string &newval)
574{
575 if (newval == "*") newval.clear();
576 return true;
577}
578
580 static void UpdateClientConfigValues()
581{
582 NetworkServerUpdateGameInfo();
583
584 InvalidateWindowData(WC_CLIENT_LIST, 0);
585
586 if (_network_server) {
587 NetworkServerSendConfigUpdate();
588 }
589}
590
595 static void ChangeTimekeepingUnits(int32_t)
596{
597 /* If service intervals are in time units (calendar days or real-world minutes), reset them to the correct defaults. */
598 if (!_settings_client.company.vehicle.servint_ispercent) {
599 UpdateAllServiceInterval(0);
600 }
601
602 /* If we are using calendar timekeeping, "minutes per year" must be default. */
603 if (!TimerGameEconomy::UsingWallclockUnits(true)) {
604 _settings_newgame.economy.minutes_per_calendar_year = CalendarTime::DEF_MINUTES_PER_YEAR;
605 }
606
607 InvalidateWindowClassesData(WC_GAME_OPTIONS, 0);
608
609 /* It is possible to change these units in Scenario Editor. We must set the economy date appropriately. */
610 if (_game_mode == GM_EDITOR) {
611 TimerGameEconomy::Date new_economy_date;
612 TimerGameEconomy::DateFract new_economy_date_fract;
613
614 if (TimerGameEconomy::UsingWallclockUnits()) {
615 /* If the new mode is wallclock units, set the economy year back to 1. */
616 new_economy_date = TimerGameEconomy::ConvertYMDToDate(TimerGameEconomy::Year{1}, 0, 1);
617 new_economy_date_fract = 0;
618 } else {
619 /* If the new mode is calendar units, sync the economy year with the calendar year. */
620 new_economy_date = TimerGameEconomy::Date{TimerGameCalendar::date.base()};
621 new_economy_date_fract = TimerGameCalendar::date_fract;
622 }
623
624 /* If you open a savegame as a scenario, there may already be link graphs and/or vehicles. These use economy date. */
625 LinkGraphSchedule::instance.ShiftDates(new_economy_date - TimerGameEconomy::date);
626 for (auto v : Vehicle::Iterate()) v->ShiftDates(new_economy_date - TimerGameEconomy::date);
627
628 /* Only change the date after changing cached values above. */
629 TimerGameEconomy::SetDate(new_economy_date, new_economy_date_fract);
630 }
631}
632
637 static void ChangeMinutesPerYear(int32_t new_value)
638{
639 /* We don't allow setting Minutes Per Year below default, unless it's to 0 for frozen calendar time. */
640 if (new_value < CalendarTime::DEF_MINUTES_PER_YEAR) {
641 int clamped;
642
643 /* If the new value is 1, we're probably at 0 and trying to increase the value, so we should jump up to default. */
644 if (new_value == 1) {
645 clamped = CalendarTime::DEF_MINUTES_PER_YEAR;
646 } else {
647 clamped = CalendarTime::FROZEN_MINUTES_PER_YEAR;
648 }
649
650 /* Override the setting with the clamped value. */
651 if (_game_mode == GM_MENU) {
652 _settings_newgame.economy.minutes_per_calendar_year = clamped;
653 } else {
654 _settings_game.economy.minutes_per_calendar_year = clamped;
655 }
656 }
657
658 /* If the setting value is not the default, force the game to use wallclock timekeeping units.
659 * 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.
660 */
661 if (_game_mode == GM_MENU && (_settings_newgame.economy.minutes_per_calendar_year != CalendarTime::DEF_MINUTES_PER_YEAR)) {
662 if (_settings_newgame.economy.timekeeping_units != TKU_WALLCLOCK) {
663 _settings_newgame.economy.timekeeping_units = TKU_WALLCLOCK;
664 ChangeTimekeepingUnits(TKU_WALLCLOCK);
665 }
666 }
667}
668
669/* Get the valid range of the "minutes per calendar year" setting. */
670static std::tuple<int32_t, uint32_t> GetMinutesPerYearRange(const IntSettingDesc &)
671{
672 /* Allow a non-default value only if using Wallclock timekeeping units. */
673 if (TimerGameEconomy::UsingWallclockUnits(_game_mode == GM_MENU)) return { CalendarTime::FROZEN_MINUTES_PER_YEAR, CalendarTime::MAX_MINUTES_PER_YEAR };
674
675 return { CalendarTime::DEF_MINUTES_PER_YEAR, CalendarTime::DEF_MINUTES_PER_YEAR };
676}
677
683 static bool CanChangeTimetableMode(int32_t &)
684{
685 return !TimerGameEconomy::UsingWallclockUnits();
686}
687
688/* End - Callback Functions */
ai.hpp
Base functions for all AIs.
ai_config.hpp
AIConfig stores the configuration settings of every AI.
base_media_base.h
Generic functions for replacing base data (graphics, sounds).
base_media_music.h
Generic functions for replacing base music data.
base_media_sounds.h
Generic functions for replacing base sounds data.
AI::GetInfoList
static const ScriptInfoList * GetInfoList()
Wrapper function for AIScanner::GetAIInfoList.
Definition ai_core.cpp:298
LinkGraphSchedule::instance
static LinkGraphSchedule instance
Static instance of LinkGraphSchedule.
Definition linkgraphschedule.h:52
LinkGraphSchedule::ShiftDates
void ShiftDates(TimerGameEconomy::Date interval)
Shift all dates (join dates and edge annotations) of link graphs and link graph jobs by the number of...
Definition linkgraphschedule.cpp:135
TimerGameCalendar::date
static Date date
Current date in days (day counter).
Definition timer_game_calendar.h:33
TimerGameCalendar::date_fract
static DateFract date_fract
Fractional part of the day.
Definition timer_game_calendar.h:34
TimerGameEconomy::date
static Date date
Current date in days (day counter).
Definition timer_game_economy.h:38
TimerGameEconomy::UsingWallclockUnits
static bool UsingWallclockUnits(bool newgame=false)
Check if we are using wallclock units.
Definition timer_game_economy.cpp:98
TimerGameEconomy::SetDate
static void SetDate(Date date, DateFract fract)
Set the date.
Definition timer_game_economy.cpp:82
TimerGameEconomy::ConvertYMDToDate
static Date ConvertYMDToDate(Year year, Month month, Day day)
Converts a tuple of Year, Month and Day to a Date.
Definition timer_game_economy.cpp:67
TimerGame< struct Economy >::DateFract
uint16_t DateFract
The fraction of a date we're in, i.e.
Definition timer_game_common.h:38
CompanyServiceInterval
int CompanyServiceInterval(const Company *c, VehicleType type)
Get the service interval for the given company and vehicle type.
Definition company_cmd.cpp:1280
_current_company
CompanyID _current_company
Company currently doing an action.
Definition company_cmd.cpp:56
company_func.h
Functions related to companies.
config.h
Configuration options of the network stuff.
currency.h
Functions to handle different currencies.
elrail_func.h
header file for electrified rail specific functions
error.h
Functions related to errors.
WL_ERROR
@ WL_ERROR
Errors (eg. saving/loading failed)
Definition error.h:26
WL_CRITICAL
@ WL_CRITICAL
Critical errors, the MessageBox is shown in all cases.
Definition error.h:27
ShowErrorMessage
void ShowErrorMessage(EncodedString &&summary_msg, int x, int y, CommandCost &cc)
Display an error message in a window.
Definition error_gui.cpp:296
factory.hpp
Factory to 'query' all available blitters.
fontcache.h
Functions to read fonts from files and cache them.
game_config.hpp
GameConfig stores the configuration settings of every Game.
genworld.h
Functions related to world/map generation.
AdjustGUIZoom
bool AdjustGUIZoom(bool automatic)
Resolve GUI zoom level and adjust GUI to new zoom, if auto-suggestion is requested.
Definition gfx.cpp:1818
MarkWholeScreenDirty
void MarkWholeScreenDirty()
This function mark the whole screen as dirty.
Definition gfx.cpp:1549
linkgraphschedule.h
Declaration of link graph schedule used for cargo distribution.
TileXY
static TileIndex TileXY(uint x, uint y)
Returns the TileIndex of a coordinate.
Definition map_func.h:385
TileY
static uint TileY(TileIndex tile)
Get the Y component of a tile.
Definition map_func.h:438
TileX
static uint TileX(TileIndex tile)
Get the X component of a tile.
Definition map_func.h:428
abs
constexpr T abs(const T a)
Returns the absolute value of (scalar) variable.
Definition math_func.hpp:23
music_driver.hpp
Base for all music playback.
_networking
bool _networking
are we in networking mode?
Definition network.cpp:67
_network_server
bool _network_server
network-server is active
Definition network.cpp:68
network.h
Basic functions/variables used all over the place.
network_func.h
Network functions used by other parts of OpenTTD.
NetworkServerUpdateGameInfo
void NetworkServerUpdateGameInfo()
Update the server's NetworkServerGameInfo due to changes in settings.
Definition network_server.cpp:1965
NetworkServerSendConfigUpdate
void NetworkServerSendConfigUpdate()
Send Config Update.
Definition network_server.cpp:1957
news_func.h
Functions related to news.
GetServiceIntervalClamped
uint16_t GetServiceIntervalClamped(int interval, bool ispercent)
Clamp the service interval to the correct min/max.
Definition order_cmd.cpp:1865
pathfinder_type.h
General types related to pathfinders.
rail_gui.h
Functions/types etc.
RoadVehiclesAreBuilt
bool RoadVehiclesAreBuilt()
Verify whether a road vehicle is available.
Definition road_cmd.cpp:169
roadveh.h
Road vehicle states.
roadveh_cmd.h
Command definitions related to road vehicles.
safeguards.h
A number of safeguards to prevent using unsafe methods.
screenshot.h
Functions to make screenshots.
_settings_game
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition settings.cpp:61
_settings_newgame
GameSettings _settings_newgame
Game settings for new games (updated from the intro screen).
Definition settings.cpp:62
_settings_client
ClientSettings _settings_client
The current settings for this game.
Definition settings.cpp:60
RoadVehSlopeSteepnessChanged
static void RoadVehSlopeSteepnessChanged(int32_t)
This function updates the road vehicle acceleration cache after a steepness change.
Definition settings_table.cpp:359
RoadVehAccelerationModelChanged
static void RoadVehAccelerationModelChanged(int32_t)
This function updates realistic acceleration caches when the setting "Road vehicle acceleration model...
Definition settings_table.cpp:340
UpdateAllServiceInterval
static void UpdateAllServiceInterval(int32_t new_value)
Check and update if needed all vehicle service intervals.
Definition settings_table.cpp:195
v_PositionStatusbar
static void v_PositionStatusbar(int32_t)
Reposition the statusbar as the setting changed.
Definition settings_table.cpp:150
GetDefaultServiceInterval
static int32_t GetDefaultServiceInterval(const IntSettingDesc &sd, VehicleType type)
Checks if the service intervals in the settings are specified as percentages and corrects the default...
Definition settings_table.cpp:270
TrainSlopeSteepnessChanged
static void TrainSlopeSteepnessChanged(int32_t)
This function updates the train acceleration cache after a steepness change.
Definition settings_table.cpp:330
UpdateLinkgraphColours
static void UpdateLinkgraphColours(int32_t)
Redraw linkgraph links after a colour scheme change.
Definition settings_table.cpp:170
RedrawSmallmap
static void RedrawSmallmap(int32_t)
Redraw the smallmap after a colour scheme change.
Definition settings_table.cpp:162
ReplaceAsteriskWithEmptyPassword
static bool ReplaceAsteriskWithEmptyPassword(std::string &newval)
Replace a passwords that are a literal asterisk with an empty string.
Definition settings_table.cpp:573
SettingHelpWallclock
static StringID SettingHelpWallclock(const IntSettingDesc &sd)
Switch setting help depending on wallclock setting.
Definition settings_table.cpp:94
SettingsValueVelocityUnit
static std::pair< StringParameter, StringParameter > SettingsValueVelocityUnit(const IntSettingDesc &, int32_t value)
Setting values for velocity unit localisation.
Definition settings_table.cpp:100
CheckDynamicEngines
static bool CheckDynamicEngines(int32_t &)
Changing the setting "allow multiple NewGRF sets" is not allowed if there are vehicles.
Definition settings_table.cpp:526
CheckRoadSide
static bool CheckRoadSide(int32_t &)
Check whether the road side may be changed.
Definition settings_table.cpp:435
v_PositionMainToolbar
static void v_PositionMainToolbar(int32_t)
Reposition the main toolbar as the setting changed.
Definition settings_table.cpp:144
ConvertLandscape
static std::optional< uint32_t > ConvertLandscape(std::string_view value)
Conversion callback for _gameopt_settings_game.landscape It converts (or try) between old values and ...
Definition settings_table.cpp:447
CanChangeTimetableMode
static bool CanChangeTimetableMode(int32_t &)
Pre-callback check when trying to change the timetable mode.
Definition settings_table.cpp:683
UpdateClientConfigValues
static void UpdateClientConfigValues()
Update the game info, and send it to the clients when we are running as a server.
Definition settings_table.cpp:580
ServiceIntervalSettingsValueText
static std::pair< StringParameter, StringParameter > ServiceIntervalSettingsValueText(const IntSettingDesc &sd, int32_t value)
Service Interval Settings Default Value displays the correct units or as a percentage.
Definition settings_table.cpp:121
ChangeMinutesPerYear
static void ChangeMinutesPerYear(int32_t new_value)
Callback after the player changes the minutes per year.
Definition settings_table.cpp:637
SettingTitleWallclock
static StringID SettingTitleWallclock(const IntSettingDesc &sd)
Switch setting title depending on wallclock setting.
Definition settings_table.cpp:88
SettingsValueAbsolute
static std::pair< StringParameter, StringParameter > SettingsValueAbsolute(const IntSettingDesc &sd, int32_t value)
A negative value has another string (the one after "strval").
Definition settings_table.cpp:115
ChangeTimekeepingUnits
static void ChangeTimekeepingUnits(int32_t)
Callback for when the player changes the timekeeping units.
Definition settings_table.cpp:595
InvalidateNewGRFChangeWindows
static void InvalidateNewGRFChangeWindows(int32_t)
Update any possible saveload window and delete any newgrf dialogue as its widget parts might change.
Definition settings_table.cpp:397
settings_table.h
Definition of the configuration tables of the settings.
GetGameSettings
GameSettings & GetGameSettings()
Get the settings-object applicable for the current situation: the newgame settings when we're in the ...
Definition settings_type.h:674
ship.h
Base for ships.
BuildLandLegend
void BuildLandLegend()
(Re)build the colour tables for the legends.
Definition smallmap_gui.cpp:290
BuildOwnerLegend
void BuildOwnerLegend()
Completes the array for the owned property legend.
Definition smallmap_gui.cpp:341
BuildLinkStatsLegend
void BuildLinkStatsLegend()
Populate legend table for the link stat view.
Definition smallmap_gui.cpp:219
smallmap_gui.h
Smallmap GUI functions.
sound_driver.hpp
Base for all sound drivers.
GfxClearSpriteCache
void GfxClearSpriteCache()
Remove all encoded sprites from the sprite cache without discarding sprite location information.
Definition spritecache.cpp:911
station_base.h
Base classes/functions for stations.
UpdateAirportsNoise
void UpdateAirportsNoise()
Recalculate the noise generated by the airports of each town.
Definition station_cmd.cpp:2604
station_func.h
Functions related to stations.
stdafx.h
Definition of base types and functions in a cross-platform compatible way.
GetEncodedString
EncodedString GetEncodedString(StringID str)
Encode a string with no parameters into an encoded string.
Definition strings.cpp:90
StringID
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Definition strings_type.h:19
BaseStation
Base class for all station-ish types.
Definition base_station_base.h:58
ClientSettings::company
CompanySettings company
default values for per-company settings
Definition settings_type.h:652
CompanySettings::vehicle
VehicleDefaultSettings vehicle
default settings for vehicles
Definition settings_type.h:615
Company
Definition company_base.h:127
EconomySettings::found_town
TownFounding found_town
town founding.
Definition settings_type.h:558
EconomySettings::timekeeping_units
TimekeepingUnits timekeeping_units
time units to use for the game economy, either calendar or wallclock
Definition settings_type.h:564
EconomySettings::station_noise_level
bool station_noise_level
build new airports when the town noise level is still within accepted limits
Definition settings_type.h:560
EconomySettings::minutes_per_calendar_year
uint16_t minutes_per_calendar_year
minutes per calendar year. Special value 0 means that calendar time is frozen.
Definition settings_type.h:565
EngineOverrideManager::ResetToCurrentNewGRFConfig
static bool ResetToCurrentNewGRFConfig()
Tries to reset the engine mapping to match the current NewGRF configuration.
Definition engine.cpp:584
GameSettings::economy
EconomySettings economy
settings to change the economy
Definition settings_type.h:642
GameSettings::vehicle
VehicleSettings vehicle
options for vehicles
Definition settings_type.h:641
IntSettingDesc
Base integer type, including boolean, settings.
Definition settings_internal.h:148
IntSettingDesc::str_help
StringID str_help
(Translated) string with help text; gui only.
Definition settings_internal.h:211
IntSettingDesc::str_val
StringID str_val
(Translated) first string describing the value.
Definition settings_internal.h:212
IntSettingDesc::def
int32_t def
default value given when none is present
Definition settings_internal.h:206
IntSettingDesc::str
StringID str
(translated) string with descriptive text; gui and console
Definition settings_internal.h:210
Map
Size related data of the map.
Definition map_func.h:206
Map::SizeX
static uint SizeX()
Get the size of the map along the X.
Definition map_func.h:272
Map::SizeY
static uint SizeY()
Get the size of the map along the Y.
Definition map_func.h:281
Map::MaxY
static uint MaxY()
Gets the maximum Y coordinate within the map, including MP_VOID.
Definition map_func.h:308
Map::MaxX
static uint MaxX()
Gets the maximum X coordinate within the map, including MP_VOID.
Definition map_func.h:299
OneOfManySettingDesc::ParseSingleValue
static std::optional< uint32_t > ParseSingleValue(std::string_view str, std::span< const std::string_view > many)
Find the index value of a ONEofMANY type in a string.
Definition settings.cpp:188
Pool::PoolItem<&_vehicle_pool >::Iterate
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
Definition pool_type.hpp:436
Pool::PoolItem<&_company_pool >::Get
static Titem * Get(auto index)
Returns Titem with given index.
Definition pool_type.hpp:387
Pool::PoolItem<&_company_pool >::IsValidID
static bool IsValidID(auto index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
Definition pool_type.hpp:376
RoadVehicle
Buses, trucks and trams belong to this class.
Definition roadveh.h:98
Ship
All ships have this type.
Definition ship.h:32
SpecializedVehicle::Iterate
static Pool::IterateWrapper< T > Iterate(size_t from=0)
Returns an iterable ensemble of all valid vehicles of type T.
Definition vehicle_base.h:1203
Station::RecomputeCatchmentForAll
static void RecomputeCatchmentForAll()
Recomputes catchment of all stations.
Definition station.cpp:534
StrongType::Typedef
Templated helper to make a type-safe 'typedef' representing a single POD value.
Definition strong_typedef_type.hpp:130
Train
'Train' is either a loco or a wagon.
Definition train.h:91
VehicleDefaultSettings
Default settings for vehicles.
Definition settings_type.h:601
VehicleDefaultSettings::servint_aircraft
uint16_t servint_aircraft
service interval for aircraft
Definition settings_type.h:605
VehicleDefaultSettings::servint_roadveh
uint16_t servint_roadveh
service interval for road vehicles
Definition settings_type.h:604
VehicleDefaultSettings::servint_ships
uint16_t servint_ships
service interval for ships
Definition settings_type.h:606
VehicleDefaultSettings::servint_ispercent
bool servint_ispercent
service intervals are in percents
Definition settings_type.h:602
VehicleDefaultSettings::servint_trains
uint16_t servint_trains
service interval for trains
Definition settings_type.h:603
VehicleSettings::roadveh_acceleration_model
uint8_t roadveh_acceleration_model
realistic acceleration for road vehicles
Definition settings_type.h:521
Vehicle
Vehicle data structure.
Definition vehicle_base.h:205
textbuf_gui.h
Stuff related to the text buffer GUI.
IsTileType
static bool IsTileType(Tile tile, TileType type)
Checks if a tile is a given tiletype.
Definition tile_map.h:150
TileHeight
static uint TileHeight(Tile tile)
Returns the height of a tile.
Definition tile_map.h:29
SetTileType
void SetTileType(Tile tile, TileType type)
Set the type of a tile.
Definition tile_map.h:131
SetTileHeight
void SetTileHeight(Tile tile, uint height)
Sets the height of a tile.
Definition tile_map.h:57
MP_WATER
@ MP_WATER
Water tile.
Definition tile_type.h:54
timer_game_calendar.h
Definition of the game-calendar-timer.
town.h
Base of the town class.
TF_FORBIDDEN
@ TF_FORBIDDEN
Forbidden.
Definition town_type.h:105
train.h
Base for the train class.
CCF_TRACK
static constexpr ConsistChangeFlags CCF_TRACK
Valid changes while vehicle is driving, and possibly changing tracks.
Definition train.h:52
vehicle_func.h
Functions related to vehicles.
VehicleType
VehicleType
Available vehicle types.
Definition vehicle_type.h:22
VEH_ROAD
@ VEH_ROAD
Road vehicle type.
Definition vehicle_type.h:26
VEH_AIRCRAFT
@ VEH_AIRCRAFT
Aircraft vehicle type.
Definition vehicle_type.h:28
VEH_SHIP
@ VEH_SHIP
Ship vehicle type.
Definition vehicle_type.h:27
VEH_TRAIN
@ VEH_TRAIN
Train vehicle type.
Definition vehicle_type.h:25
video_driver.hpp
Base of all video drivers.
viewport_func.h
Functions related to (drawing on) viewports.
void_map.h
Map accessors for void tiles.
MakeVoid
void MakeVoid(Tile t)
Make a nice void tile ;)
Definition void_map.h:19
PositionStatusbar
int PositionStatusbar(Window *w)
(Re)position statusbar window at the screen.
Definition window.cpp:3479
CloseWindowById
void CloseWindowById(WindowClass cls, WindowNumber number, bool force, int data)
Close a window by its class and window number (if it is open).
Definition window.cpp:1195
PositionMainToolbar
int PositionMainToolbar(Window *w)
(Re)position main toolbar window at the screen.
Definition window.cpp:3468
PositionNetworkChatWindow
int PositionNetworkChatWindow(Window *w)
(Re)position network chat window at the screen.
Definition window.cpp:3501
ReInitAllWindows
void ReInitAllWindows(bool zoom_changed)
Re-initialize all windows.
Definition window.cpp:3413
CloseWindowByClass
void CloseWindowByClass(WindowClass cls, int data)
Close all windows of a given class.
Definition window.cpp:1207
PositionNewsMessage
int PositionNewsMessage(Window *w)
(Re)position news message window at the screen.
Definition window.cpp:3490
SetWindowClassesDirty
void SetWindowClassesDirty(WindowClass cls)
Mark all windows of a particular class as dirty (in need of repainting)
Definition window.cpp:3205
InvalidateWindowData
void InvalidateWindowData(WindowClass cls, WindowNumber number, int data, bool gui_scope)
Mark window data of the window of a given class and specific window number as invalid (in need of re-...
Definition window.cpp:3297
InvalidateWindowClassesData
void InvalidateWindowClassesData(WindowClass cls, int data, bool gui_scope)
Mark window data of all windows of a given class as invalid (in need of re-computing) Note that by de...
Definition window.cpp:3314
window_func.h
Window functions not directly related to making/drawing windows.
WC_BUILD_STATION
@ WC_BUILD_STATION
Build station; Window numbers:
Definition window_type.h:408
WC_SPRITE_ALIGNER
@ WC_SPRITE_ALIGNER
Sprite aligner (debug); Window numbers:
Definition window_type.h:697
WC_COMPANY_COLOUR
@ WC_COMPANY_COLOUR
Company colour selection; Window numbers:
Definition window_type.h:235
WC_FOUND_TOWN
@ WC_FOUND_TOWN
Found a town; Window numbers:
Definition window_type.h:440
WC_BUILD_TOOLBAR
@ WC_BUILD_TOOLBAR
Build toolbar; Window numbers:
Definition window_type.h:78
WC_SELECT_STATION
@ WC_SELECT_STATION
Select station (when joining stations); Window numbers:
Definition window_type.h:247
WC_ENGINE_PREVIEW
@ WC_ENGINE_PREVIEW
Engine preview window; Window numbers:
Definition window_type.h:611
WC_CLIENT_LIST
@ WC_CLIENT_LIST
Client list; Window numbers:
Definition window_type.h:489
WC_TOWN_VIEW
@ WC_TOWN_VIEW
Town view; Window numbers:
Definition window_type.h:338
WC_GAME_OPTIONS
@ WC_GAME_OPTIONS
Game options window; Window numbers:
Definition window_type.h:635
WC_SMALLMAP
@ WC_SMALLMAP
Small map; Window numbers:
Definition window_type.h:109
WC_SAVELOAD
@ WC_SAVELOAD
Saveload window; Window numbers:
Definition window_type.h:149
WC_VEHICLE_DETAILS
@ WC_VEHICLE_DETAILS
Vehicle details; Window numbers:
Definition window_type.h:205
WC_BUILD_VEHICLE
@ WC_BUILD_VEHICLE
Build vehicle; Window numbers:
Definition window_type.h:394