OpenTTD Source 20260421-master-gc2fbc6fdeb
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
9
10#include "stdafx.h"
11#include "settings_table.h"
12#include "currency.h"
13#include "screenshot.h"
14#include "network/network.h"
16#include "network/core/config.h"
19#include "genworld.h"
20#include "train.h"
21#include "news_func.h"
22#include "window_func.h"
23#include "company_func.h"
25#if defined(WITH_FREETYPE) || defined(_WIN32) || defined(WITH_COCOA)
26#define HAS_TRUETYPE_FONT
27#include "fontcache.h"
28#endif
29#include "textbuf_gui.h"
30#include "rail_gui.h"
31#include "elrail_func.h"
32#include "error.h"
33#include "town.h"
37#include "blitter/factory.hpp"
38#include "base_media_base.h"
39#include "base_media_music.h"
40#include "base_media_sounds.h"
41#include "ai/ai_config.hpp"
42#include "ai/ai.hpp"
43#include "game/game_config.hpp"
44#include "ship.h"
45#include "smallmap_gui.h"
46#include "roadveh.h"
47#include "roadveh_cmd.h"
48#include "vehicle_func.h"
49#include "viewport_func.h"
50#include "void_map.h"
51#include "station_func.h"
52#include "station_base.h"
53#include "aircraft.h"
54#include "aircraft_cmd.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
89{
90 return TimerGameEconomy::UsingWallclockUnits(_game_mode == GM_MENU) ? sd.str + 1 : sd.str;
91}
92
95{
96 return TimerGameEconomy::UsingWallclockUnits(_game_mode == GM_MENU) ? sd.str_help + 1 : sd.str_help;
97}
98
100static std::pair<StringParameter, StringParameter> SettingsValueVelocityUnit([[maybe_unused]] const IntSettingDesc &sd, 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
115static 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
121static std::pair<StringParameter, StringParameter> ServiceIntervalSettingsValueText(const IntSettingDesc &sd, int32_t value)
122{
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
144static void v_PositionMainToolbar(int32_t)
145{
146 if (_game_mode != GM_MENU) PositionMainToolbar(nullptr);
147}
148
150static void v_PositionStatusbar(int32_t)
151{
152 if (_game_mode != GM_MENU) {
153 PositionStatusbar(nullptr);
154 PositionNewsMessage(nullptr);
156 }
157}
158
162static void RedrawSmallmap(int32_t)
163{
167}
168
170static void UpdateLinkgraphColours(int32_t)
171{
174}
175
176static void StationSpreadChanged(int32_t)
177{
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 }
189}
190
195static void UpdateAllServiceInterval(int32_t new_value)
196{
197 bool update_vehicles;
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) {
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
238}
239
240static bool CanUpdateServiceInterval(VehicleType, int32_t &new_value)
241{
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
265}
266
274{
276 if (_game_mode == GM_MENU || !Company::IsValidID(_current_company)) {
277 vds = &_settings_client.company.vehicle;
278 } else {
279 vds = &Company::Get(_current_company)->settings.vehicle;
280 }
281
282 if (vds->servint_ispercent) return DEF_SERVINT_PERCENT;
283
284 if (TimerGameEconomy::UsingWallclockUnits(_game_mode == GM_MENU)) {
285 switch (type) {
286 case VEH_TRAIN: return DEF_SERVINT_MINUTES_TRAINS;
287 case VEH_ROAD: return DEF_SERVINT_MINUTES_ROADVEH;
288 case VEH_AIRCRAFT: return DEF_SERVINT_MINUTES_AIRCRAFT;
289 case VEH_SHIP: return DEF_SERVINT_MINUTES_SHIPS;
290 default: NOT_REACHED();
291 }
292 }
293
294 return sd.def;
295}
296
297static std::tuple<int32_t, uint32_t> GetServiceIntervalRange(const IntSettingDesc &)
298{
300 if (_game_mode == GM_MENU || !Company::IsValidID(_current_company)) {
301 vds = &_settings_client.company.vehicle;
302 } else {
303 vds = &Company::Get(_current_company)->settings.vehicle;
304 }
305
306 if (vds->servint_ispercent) return { MIN_SERVINT_PERCENT, MAX_SERVINT_PERCENT };
307
308 if (TimerGameEconomy::UsingWallclockUnits(_game_mode == GM_MENU)) {
309 return { MIN_SERVINT_MINUTES, MAX_SERVINT_MINUTES };
310 }
311
312 return { MIN_SERVINT_DAYS, MAX_SERVINT_DAYS };
313}
314
315static void TrainAccelerationModelChanged(int32_t)
316{
317 for (Train *t : Train::Iterate()) {
318 if (t->IsFrontEngine()) {
319 t->tcache.cached_max_curve_speed = t->GetCurveSpeedLimit();
320 t->UpdateAcceleration();
321 }
322 }
323
324 /* These windows show acceleration values only when realistic acceleration is on. They must be redrawn after a setting change. */
328}
329
333static void TrainSlopeSteepnessChanged(int32_t)
334{
335 for (Train *t : Train::Iterate()) {
336 if (t->IsFrontEngine()) t->CargoChanged();
337 }
338}
339
344{
345 if (_settings_game.vehicle.roadveh_acceleration_model != AM_ORIGINAL) {
346 for (RoadVehicle *rv : RoadVehicle::Iterate()) {
347 if (rv->IsFrontEngine()) {
348 rv->CargoChanged();
349 }
350 }
351 }
352
353 /* These windows show acceleration values only when realistic acceleration is on. They must be redrawn after a setting change. */
357}
358
363{
364 for (RoadVehicle *rv : RoadVehicle::Iterate()) {
365 if (rv->IsFrontEngine()) rv->CargoChanged();
366 }
367}
368
372static void AircraftRangeChanged(int32_t)
373{
374 for (Aircraft *v : Aircraft::Iterate()) {
375 v->acache.cached_max_range = Engine::Get(v->engine_type)->GetRange();
376 v->acache.cached_max_range_sqr = v->acache.cached_max_range * v->acache.cached_max_range;
377
378 /* Reset destination is too far state */
379 if (v->flags.Test(VehicleAirFlag::DestinationTooFar)) {
380 v->flags.Reset(VehicleAirFlag::DestinationTooFar);
383 }
384 }
385}
386
387static void TownFoundingChanged(int32_t)
388{
389 if (_game_mode != GM_EDITOR && _settings_game.economy.found_town == TF_FORBIDDEN) {
391 } else {
393 }
394}
395
396static void ZoomMinMaxChanged(int32_t)
397{
398 ConstrainAllViewportsZoom();
401 if (AdjustGUIZoom(false)) {
402 ReInitAllWindows(true);
403 }
404}
405
406static void SpriteZoomMinChanged(int32_t)
407{
409 /* Force all sprites to redraw at the new chosen zoom level */
411}
412
424
425static void InvalidateCompanyLiveryWindow(int32_t)
426{
428 ResetVehicleColourMap();
429}
430
431static void DifficultyNoiseChange(int32_t)
432{
433 if (_game_mode == GM_NORMAL) {
435 if (_settings_game.economy.station_noise_level) {
437 }
438 }
439}
440
441static void MaxNoAIsChange(int32_t)
442{
443 if (GetGameSettings().difficulty.max_no_competitors != 0 &&
444 AI::GetInfoList()->empty() &&
446 ShowErrorMessage(GetEncodedString(STR_WARNING_NO_SUITABLE_AI), {}, WL_CRITICAL);
447 }
448
450}
451
456static bool CheckRoadSide(int32_t &)
457{
458 return _game_mode == GM_MENU || !RoadVehiclesAreBuilt();
459}
460
468static std::optional<uint32_t> ConvertLandscape(std::string_view value)
469{
470 /* try with the old values */
471 static constexpr std::initializer_list<std::string_view> _old_landscape_values{"normal"sv, "hilly"sv, "desert"sv, "candy"sv};
472 return OneOfManySettingDesc::ParseSingleValue(value, _old_landscape_values);
473}
474
475static bool CheckFreeformEdges(int32_t &new_value)
476{
477 if (_game_mode == GM_MENU) return true;
478 if (new_value != 0) {
479 for (Ship *s : Ship::Iterate()) {
480 /* Check if there is a ship on the northern border. */
481 if (TileX(s->tile) == 0 || TileY(s->tile) == 0) {
482 ShowErrorMessage(GetEncodedString(STR_CONFIG_SETTING_EDGES_NOT_EMPTY), {}, WL_ERROR);
483 return false;
484 }
485 }
486 for (const BaseStation *st : BaseStation::Iterate()) {
487 /* Check if there is a non-deleted buoy on the northern border. */
488 if (st->IsInUse() && (TileX(st->xy) == 0 || TileY(st->xy) == 0)) {
489 ShowErrorMessage(GetEncodedString(STR_CONFIG_SETTING_EDGES_NOT_EMPTY), {}, WL_ERROR);
490 return false;
491 }
492 }
493 } else {
494 for (uint i = 0; i < Map::MaxX(); i++) {
495 if (TileHeight(TileXY(i, 1)) != 0) {
496 ShowErrorMessage(GetEncodedString(STR_CONFIG_SETTING_EDGES_NOT_WATER), {}, WL_ERROR);
497 return false;
498 }
499 }
500 for (uint i = 1; i < Map::MaxX(); i++) {
501 if (!IsTileType(TileXY(i, Map::MaxY() - 1), TileType::Water) || TileHeight(TileXY(1, Map::MaxY())) != 0) {
502 ShowErrorMessage(GetEncodedString(STR_CONFIG_SETTING_EDGES_NOT_WATER), {}, WL_ERROR);
503 return false;
504 }
505 }
506 for (uint i = 0; i < Map::MaxY(); i++) {
507 if (TileHeight(TileXY(1, i)) != 0) {
508 ShowErrorMessage(GetEncodedString(STR_CONFIG_SETTING_EDGES_NOT_WATER), {}, WL_ERROR);
509 return false;
510 }
511 }
512 for (uint i = 1; i < Map::MaxY(); i++) {
513 if (!IsTileType(TileXY(Map::MaxX() - 1, i), TileType::Water) || TileHeight(TileXY(Map::MaxX(), i)) != 0) {
514 ShowErrorMessage(GetEncodedString(STR_CONFIG_SETTING_EDGES_NOT_WATER), {}, WL_ERROR);
515 return false;
516 }
517 }
518 }
519 return true;
520}
521
522static void UpdateFreeformEdges(int32_t new_value)
523{
524 if (_game_mode == GM_MENU) return;
525
526 if (new_value != 0) {
527 for (uint x = 0; x < Map::SizeX(); x++) MakeVoid(TileXY(x, 0));
528 for (uint y = 0; y < Map::SizeY(); y++) MakeVoid(TileXY(0, y));
529 } else {
530 /* Make tiles at the border water again. */
531 for (uint i = 0; i < Map::MaxX(); i++) {
532 SetTileHeight(TileXY(i, 0), 0);
534 }
535 for (uint i = 0; i < Map::MaxY(); i++) {
536 SetTileHeight(TileXY(0, i), 0);
538 }
539 }
541}
542
548static bool CheckDynamicEngines([[maybe_unused]] int32_t &value)
549{
550 if (_game_mode == GM_MENU) return true;
551
553 ShowErrorMessage(GetEncodedString(STR_CONFIG_SETTING_DYNAMIC_ENGINES_EXISTING_VEHICLES), {}, WL_ERROR);
554 return false;
555 }
556
557 return true;
558}
559
560static bool CheckMaxHeightLevel(int32_t &new_value)
561{
562 if (_game_mode == GM_NORMAL) return false;
563 if (_game_mode != GM_EDITOR) return true;
564
565 /* Check if at least one mountain on the map is higher than the new value.
566 * If yes, disallow the change. */
567 for (const auto t : Map::Iterate()) {
568 if ((int32_t)TileHeight(t) > new_value) {
569 ShowErrorMessage(GetEncodedString(STR_CONFIG_SETTING_TOO_HIGH_MOUNTAIN), {}, WL_ERROR);
570 /* Return old, unchanged value */
571 return false;
572 }
573 }
574
575 return true;
576}
577
578static void StationCatchmentChanged(int32_t)
579{
582}
583
584static void MaxVehiclesChanged(int32_t)
585{
588}
589
595static bool ReplaceAsteriskWithEmptyPassword(std::string &newval)
596{
597 if (newval == "*") newval.clear();
598 return true;
599}
600
612
617{
618 /* If service intervals are in time units (calendar days or real-world minutes), reset them to the correct defaults. */
619 if (!_settings_client.company.vehicle.servint_ispercent) {
621 }
622
623 /* If we are using calendar timekeeping, "minutes per year" must be default. */
625 _settings_newgame.economy.minutes_per_calendar_year = CalendarTime::DEF_MINUTES_PER_YEAR;
626 }
627
629
630 /* It is possible to change these units in Scenario Editor. We must set the economy date appropriately. */
631 if (_game_mode == GM_EDITOR) {
632 TimerGameEconomy::Date new_economy_date;
633 TimerGameEconomy::DateFract new_economy_date_fract;
634
636 /* If the new mode is wallclock units, set the economy year back to 1. */
638 new_economy_date_fract = 0;
639 } else {
640 /* If the new mode is calendar units, sync the economy year with the calendar year. */
641 new_economy_date = TimerGameEconomy::Date{TimerGameCalendar::date.base()};
642 new_economy_date_fract = TimerGameCalendar::date_fract;
643 }
644
645 /* If you open a savegame as a scenario, there may already be link graphs and/or vehicles. These use economy date. */
646 LinkGraphSchedule::instance.ShiftDates(new_economy_date - TimerGameEconomy::date);
647 for (auto v : Vehicle::Iterate()) v->ShiftDates(new_economy_date - TimerGameEconomy::date);
648
649 /* Only change the date after changing cached values above. */
650 TimerGameEconomy::SetDate(new_economy_date, new_economy_date_fract);
651 }
652}
653
658static void ChangeMinutesPerYear(int32_t new_value)
659{
660 /* We don't allow setting Minutes Per Year below default, unless it's to 0 for frozen calendar time. */
661 if (new_value < CalendarTime::DEF_MINUTES_PER_YEAR) {
662 int clamped;
663
664 /* If the new value is 1, we're probably at 0 and trying to increase the value, so we should jump up to default. */
665 if (new_value == 1) {
666 clamped = CalendarTime::DEF_MINUTES_PER_YEAR;
667 } else {
668 clamped = CalendarTime::FROZEN_MINUTES_PER_YEAR;
669 }
670
671 /* Override the setting with the clamped value. */
672 if (_game_mode == GM_MENU) {
673 _settings_newgame.economy.minutes_per_calendar_year = clamped;
674 } else {
675 _settings_game.economy.minutes_per_calendar_year = clamped;
676 }
677 }
678
679 /* If the setting value is not the default, force the game to use wallclock timekeeping units.
680 * 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.
681 */
682 if (_game_mode == GM_MENU && (_settings_newgame.economy.minutes_per_calendar_year != CalendarTime::DEF_MINUTES_PER_YEAR)) {
683 if (_settings_newgame.economy.timekeeping_units != TimekeepingUnits::Wallclock) {
684 _settings_newgame.economy.timekeeping_units = TimekeepingUnits::Wallclock;
686 }
687 }
688}
689
690/* Get the valid range of the "minutes per calendar year" setting. */
691static std::tuple<int32_t, uint32_t> GetMinutesPerYearRange(const IntSettingDesc &)
692{
693 /* Allow a non-default value only if using Wallclock timekeeping units. */
694 if (TimerGameEconomy::UsingWallclockUnits(_game_mode == GM_MENU)) return { CalendarTime::FROZEN_MINUTES_PER_YEAR, CalendarTime::MAX_MINUTES_PER_YEAR };
695
696 return { CalendarTime::DEF_MINUTES_PER_YEAR, CalendarTime::DEF_MINUTES_PER_YEAR };
697}
698
703static bool CanChangeTimetableMode(int32_t &)
704{
706}
707
708/* End - Callback Functions */
Base functions for all AIs.
AIConfig stores the configuration settings of every AI.
Base for aircraft.
@ DestinationTooFar
Next destination is too far away.
Definition aircraft.h:37
Command definitions related to aircraft.
Generic functions for replacing base data (graphics, sounds).
Generic functions for replacing base music data.
Generic functions for replacing base sounds data.
static const ScriptInfoList * GetInfoList()
Get the list of all registered scripts.
Definition ai_core.cpp:298
static constexpr int MAX_MINUTES_PER_YEAR
One week of real time. The actual max that doesn't overflow TimerGameCalendar::sub_date_fract is 1062...
static LinkGraphSchedule instance
Static instance of LinkGraphSchedule.
static Date date
Current date in days (day counter).
static DateFract date_fract
Fractional part of the day.
static Date date
Current date in days (day counter).
static bool UsingWallclockUnits(bool newgame=false)
Check if we are using wallclock units.
static void SetDate(Date date, DateFract fract)
Set the date.
static Date ConvertYMDToDate(Year year, Month month, Day day)
Converts a tuple of Year, Month and Day to a Date.
StrongType::Typedef< int32_t, struct YearTag< struct Economy >, StrongType::Compare, StrongType::Integer > Year
StrongType::Typedef< int32_t, DateTag< struct Economy >, StrongType::Compare, StrongType::Integer > Date
int CompanyServiceInterval(const Company *c, VehicleType type)
Get the service interval for the given company and vehicle type.
CompanyID _current_company
Company currently doing an action.
Functions related to companies.
Configuration options of the network stuff.
Functions to handle different currencies.
Header file for electrified rail specific functions.
Functions related to errors.
@ WL_ERROR
Errors (eg. saving/loading failed).
Definition error.h:26
@ WL_CRITICAL
Critical errors, the MessageBox is shown in all cases.
Definition error.h:27
void ShowErrorMessage(EncodedString &&summary_msg, int x, int y, CommandCost &cc)
Display an error message in a window.
Factory to 'query' all available blitters.
Functions to read fonts from files and cache them.
GameConfig stores the configuration settings of every Game.
Functions related to world/map generation.
bool AdjustGUIZoom(bool automatic)
Resolve GUI zoom level and adjust GUI to new zoom, if auto-suggestion is requested.
Definition gfx.cpp:1837
void MarkWholeScreenDirty()
This function mark the whole screen as dirty.
Definition gfx.cpp:1554
Declaration of link graph schedule used for cargo distribution.
static TileIndex TileXY(uint x, uint y)
Returns the TileIndex of a coordinate.
Definition map_func.h:376
static uint TileY(TileIndex tile)
Get the Y component of a tile.
Definition map_func.h:429
static uint TileX(TileIndex tile)
Get the X component of a tile.
Definition map_func.h:419
constexpr T abs(const T a)
Returns the absolute value of (scalar) variable.
Definition math_func.hpp:23
Base for all music playback.
bool _networking
are we in networking mode?
Definition network.cpp:67
bool _network_server
network-server is active
Definition network.cpp:68
Basic functions/variables used all over the place.
Network functions used by other parts of OpenTTD.
void NetworkServerUpdateGameInfo()
Update the server's NetworkServerGameInfo due to changes in settings.
void NetworkServerSendConfigUpdate()
Send Config Update.
Functions related to news.
void DeleteVehicleNews(VehicleID vid, AdviceType advice_type=AdviceType::Invalid)
Delete news with a given advice type about a vehicle.
@ AircraftDestinationTooFar
Next (order) destination is too far for the aircraft type.
Definition news_type.h:52
uint16_t GetServiceIntervalClamped(int interval, bool ispercent)
Clamp the service interval to the correct min/max.
General types related to pathfinders.
Functions/types etc.
bool RoadVehiclesAreBuilt()
Verify whether a road vehicle is available.
Definition road_cmd.cpp:172
Road vehicle states.
Command definitions related to road vehicles.
A number of safeguards to prevent using unsafe methods.
Functions to make screenshots.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition settings.cpp:61
GameSettings _settings_newgame
Game settings for new games (updated from the intro screen).
Definition settings.cpp:62
ClientSettings _settings_client
The current settings for this game.
Definition settings.cpp:60
static void ChangeTimekeepingUnits()
Callback for when the player changes the timekeeping units.
static void RoadVehSlopeSteepnessChanged(int32_t)
This function updates the road vehicle acceleration cache after a steepness change.
static void RoadVehAccelerationModelChanged(int32_t)
This function updates realistic acceleration caches when the setting "Road vehicle acceleration model...
static void UpdateAllServiceInterval(int32_t new_value)
Check and update if needed all vehicle service intervals.
static void v_PositionStatusbar(int32_t)
Reposition the statusbar as the setting changed.
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...
static void TrainSlopeSteepnessChanged(int32_t)
This function updates the train acceleration cache after a steepness change.
static void UpdateLinkgraphColours(int32_t)
Redraw linkgraph links after a colour scheme change.
static void RedrawSmallmap(int32_t)
Redraw the smallmap after a colour scheme change.
static bool ReplaceAsteriskWithEmptyPassword(std::string &newval)
Replace a passwords that are a literal asterisk with an empty string.
static StringID SettingHelpWallclock(const IntSettingDesc &sd)
Switch setting help depending on wallclock setting.
static bool CheckDynamicEngines(int32_t &value)
Changing the setting "allow multiple NewGRF sets" is not allowed if there are vehicles.
static bool CheckRoadSide(int32_t &)
Check whether the road side may be changed.
static void AircraftRangeChanged(int32_t)
This function updates the aircraft cache when the aircraft range setting is changed.
static void v_PositionMainToolbar(int32_t)
Reposition the main toolbar as the setting changed.
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 ...
static bool CanChangeTimetableMode(int32_t &)
Pre-callback check when trying to change the timetable mode.
static void UpdateClientConfigValues()
Update the game info, and send it to the clients when we are running as a server.
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.
static void ChangeMinutesPerYear(int32_t new_value)
Callback after the player changes the minutes per year.
static StringID SettingTitleWallclock(const IntSettingDesc &sd)
Switch setting title depending on wallclock setting.
static std::pair< StringParameter, StringParameter > SettingsValueAbsolute(const IntSettingDesc &sd, int32_t value)
A negative value has another string (the one after "strval").
static std::pair< StringParameter, StringParameter > SettingsValueVelocityUnit(const IntSettingDesc &sd, int32_t value)
Setting values for velocity unit localisation.
static void InvalidateNewGRFChangeWindows(int32_t)
Update any possible saveload window and delete any newgrf dialogue as its widget parts might change.
Definition of the configuration tables of the settings.
GameSettings & GetGameSettings()
Get the settings-object applicable for the current situation: the newgame settings when we're in the ...
Base for ships.
void BuildLandLegend()
(Re)build the colour tables for the legends.
void BuildOwnerLegend()
Completes the array for the owned property legend.
void BuildLinkStatsLegend()
Populate legend table for the link stat view.
Smallmap GUI functions.
Base for all sound drivers.
void GfxClearSpriteCache()
Remove all encoded sprites from the sprite cache without discarding sprite location information.
Base classes/functions for stations.
void UpdateAirportsNoise()
Recalculate the noise generated by the airports of each town.
Functions related to stations.
Definition of base types and functions in a cross-platform compatible way.
EncodedString GetEncodedString(StringID str)
Encode a string with no parameters into an encoded string.
Definition strings.cpp:90
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Aircraft, helicopters, rotors and their shadows belong to this class.
Definition aircraft.h:73
Base class for all station-ish types.
static bool ResetToCurrentNewGRFConfig()
Tries to reset the engine mapping to match the current NewGRF configuration.
Definition engine.cpp:589
Base integer type, including boolean, settings.
StringID str_help
(Translated) string with help text; gui only.
StringID str_val
(Translated) first string describing the value.
int32_t def
default value given when none is present
StringID str
(translated) string with descriptive text; gui and console
static uint SizeX()
Get the size of the map along the X.
Definition map_func.h:262
static uint SizeY()
Get the size of the map along the Y.
Definition map_func.h:271
static IterateWrapper Iterate()
Returns an iterable ensemble of all Tiles.
Definition map_func.h:366
static uint MaxY()
Gets the maximum Y coordinate within the map, including TileType::Void.
Definition map_func.h:298
static uint MaxX()
Gets the maximum X coordinate within the map, including TileType::Void.
Definition map_func.h:289
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:191
static Pool::IterateWrapper< Vehicle > Iterate(size_t from=0)
static Company * Get(auto index)
Buses, trucks and trams belong to this class.
Definition roadveh.h:105
All ships have this type.
Definition ship.h:32
static void RecomputeCatchmentForAll()
Recomputes catchment of all stations.
Definition station.cpp:537
'Train' is either a loco or a wagon.
Definition train.h:97
Default settings for vehicles.
uint16_t servint_aircraft
service interval for aircraft
uint16_t servint_roadveh
service interval for road vehicles
uint16_t servint_ships
service interval for ships
bool servint_ispercent
service intervals are in percents
uint16_t servint_trains
service interval for trains
Vehicle data structure.
Stuff related to the text buffer GUI.
static bool IsTileType(Tile tile, TileType type)
Checks if a tile is a given tiletype.
Definition tile_map.h:150
static uint TileHeight(Tile tile)
Returns the height of a tile.
Definition tile_map.h:29
void SetTileType(Tile tile, TileType type)
Set the type of a tile.
Definition tile_map.h:131
void SetTileHeight(Tile tile, uint height)
Sets the height of a tile.
Definition tile_map.h:57
@ Water
Water tile.
Definition tile_type.h:55
Definition of the game-calendar-timer.
Base of the town class.
@ TF_FORBIDDEN
Forbidden.
Definition town_type.h:108
Base for the train class.
static constexpr ConsistChangeFlags CCF_TRACK
Valid changes while vehicle is driving, and possibly changing tracks.
Definition train.h:53
Functions related to vehicles.
VehicleType
Available vehicle types.
@ VEH_ROAD
Road vehicle type.
@ VEH_AIRCRAFT
Aircraft vehicle type.
@ VEH_SHIP
Ship vehicle type.
@ VEH_TRAIN
Train vehicle type.
@ WID_VV_START_STOP
Start or stop this vehicle, and show information about the current state.
Base of all video drivers.
Functions related to (drawing on) viewports.
Map accessors for void tiles.
void MakeVoid(Tile t)
Make a nice void tile ;).
Definition void_map.h:19
int PositionStatusbar(Window *w)
(Re)position statusbar window at the screen.
Definition window.cpp:3505
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:1209
int PositionMainToolbar(Window *w)
(Re)position main toolbar window at the screen.
Definition window.cpp:3494
int PositionNetworkChatWindow(Window *w)
(Re)position network chat window at the screen.
Definition window.cpp:3527
void ReInitAllWindows(bool zoom_changed)
Re-initialize all windows.
Definition window.cpp:3439
void CloseWindowByClass(WindowClass cls, int data)
Close all windows of a given class.
Definition window.cpp:1222
int PositionNewsMessage(Window *w)
(Re)position news message window at the screen.
Definition window.cpp:3516
void SetWindowClassesDirty(WindowClass cls)
Mark all windows of a particular class as dirty (in need of repainting).
Definition window.cpp:3230
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:3322
void SetWindowWidgetDirty(WindowClass cls, WindowNumber number, WidgetID widget_index)
Mark a particular widget in a particular window as dirty (in need of repainting).
Definition window.cpp:3216
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:3340
Window functions not directly related to making/drawing windows.
@ WC_BUILD_STATION
Build station; Window numbers:
@ WC_SPRITE_ALIGNER
Sprite aligner (debug); Window numbers:
@ WC_COMPANY_COLOUR
Company colour selection; Window numbers:
@ WC_FOUND_TOWN
Found a town; Window numbers:
@ WC_BUILD_TOOLBAR
Build toolbar; Window numbers:
Definition window_type.h:79
@ WC_SELECT_STATION
Select station (when joining stations); Window numbers:
@ WC_ENGINE_PREVIEW
Engine preview window; Window numbers:
@ WC_CLIENT_LIST
Client list; Window numbers:
@ WC_TOWN_VIEW
Town view; Window numbers:
@ WC_GAME_OPTIONS
Game options window; Window numbers:
@ WC_SMALLMAP
Small map; Window numbers:
@ WC_SAVELOAD
Saveload window; Window numbers:
@ WC_VEHICLE_DETAILS
Vehicle details; Window numbers:
@ WC_VEHICLE_VIEW
Vehicle view; Window numbers:
@ WC_BUILD_VEHICLE
Build vehicle; Window numbers: