OpenTTD Source 20261112-master-gbcbec5e63f
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_type.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_base.h"
24#include "company_func.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"
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 "spritecache.h"
51#include "vehicle_func.h"
52#include "vehicle_gui.h"
53#include "viewport_func.h"
54#include "void_map.h"
55#include "station_func.h"
56#include "station_base.h"
57#include "aircraft.h"
58#include "aircraft_cmd.h"
59
60#include "table/strings.h"
61#include "table/settings.h"
62
63#include "safeguards.h"
64
65SettingTable _company_settings{ _company_settings_table };
66SettingTable _currency_settings{ _currency_settings_table };
67SettingTable _difficulty_settings{ _difficulty_settings_table };
68SettingTable _multimedia_settings{ _multimedia_settings_table };
69SettingTable _economy_settings{ _economy_settings_table };
70SettingTable _game_settings{ _game_settings_table };
71SettingTable _gui_settings{ _gui_settings_table };
72SettingTable _linkgraph_settings{ _linkgraph_settings_table };
73SettingTable _locale_settings{ _locale_settings_table };
74SettingTable _misc_settings{ _misc_settings_table };
75SettingTable _network_private_settings{ _network_private_settings_table };
76SettingTable _network_secrets_settings{ _network_secrets_settings_table };
77SettingTable _network_settings{ _network_settings_table };
78SettingTable _news_display_settings{ _news_display_settings_table };
79SettingTable _old_gameopt_settings{ _old_gameopt_settings_table };
80SettingTable _pathfinding_settings{ _pathfinding_settings_table };
81SettingTable _script_settings{ _script_settings_table };
82SettingTable _window_settings{ _window_settings_table };
83SettingTable _world_settings{ _world_settings_table };
84#if defined(_WIN32) && !defined(DEDICATED)
85SettingTable _win32_settings{ _win32_settings_table };
86#endif /* _WIN32 */
87
88
89/* Begin - Callback Functions for the various settings. */
90
93{
94 return TimerGameEconomy::UsingWallclockUnits(_game_mode == GameMode::Menu) ? sd.str + 1 : sd.str;
95}
96
99{
100 return TimerGameEconomy::UsingWallclockUnits(_game_mode == GameMode::Menu) ? sd.str_help + 1 : sd.str_help;
101}
102
104static std::pair<StringParameter, StringParameter> SettingsValueVelocityUnit([[maybe_unused]] const IntSettingDesc &sd, int32_t value)
105{
106 StringID val;
107 switch (value) {
108 case 0: val = STR_CONFIG_SETTING_LOCALISATION_UNITS_VELOCITY_IMPERIAL; break;
109 case 1: val = STR_CONFIG_SETTING_LOCALISATION_UNITS_VELOCITY_METRIC; break;
110 case 2: val = STR_CONFIG_SETTING_LOCALISATION_UNITS_VELOCITY_SI; break;
111 case 3: val = TimerGameEconomy::UsingWallclockUnits(_game_mode == GameMode::Menu) ? STR_CONFIG_SETTING_LOCALISATION_UNITS_VELOCITY_GAMEUNITS_SECS : STR_CONFIG_SETTING_LOCALISATION_UNITS_VELOCITY_GAMEUNITS_DAYS; break;
112 case 4: val = STR_CONFIG_SETTING_LOCALISATION_UNITS_VELOCITY_KNOTS; break;
113 default: NOT_REACHED();
114 }
115 return {val, {}};
116}
117
119static std::pair<StringParameter, StringParameter> SettingsValueAbsolute(const IntSettingDesc &sd, int32_t value)
120{
121 return {sd.str_val + ((value >= 0) ? 1 : 0), abs(value)};
122}
123
125static std::pair<StringParameter, StringParameter> ServiceIntervalSettingsValueText(const IntSettingDesc &sd, int32_t value)
126{
128 if (_game_mode == GameMode::Menu || !Company::IsValidID(_current_company)) {
129 vds = &_settings_client.company.vehicle;
130 } else {
131 vds = &Company::Get(_current_company)->settings.vehicle;
132 }
133
134 StringID str;
135 if (value == 0) {
136 str = sd.str_val + 3;
137 } else if (vds->servint_ispercent) {
138 str = sd.str_val + 2;
139 } else if (TimerGameEconomy::UsingWallclockUnits(_game_mode == GameMode::Menu)) {
140 str = sd.str_val + 1;
141 } else {
142 str = sd.str_val;
143 }
144 return {str, value};
145}
146
148static void v_PositionMainToolbar(int32_t)
149{
150 if (_game_mode != GameMode::Menu) PositionMainToolbar(nullptr);
151}
152
154static void v_PositionStatusbar(int32_t)
155{
156 if (_game_mode != GameMode::Menu) {
157 PositionStatusbar(nullptr);
158 PositionNewsMessage(nullptr);
160 }
161}
162
166static void RedrawSmallmap(int32_t)
167{
170 SetWindowClassesDirty(WindowClass::SmallMap);
171}
172
174static void UpdateLinkgraphColours(int32_t)
175{
178}
179
180static void StationSpreadChanged(int32_t)
181{
182 InvalidateWindowData(WindowClass::JoinStation, 0);
183 InvalidateWindowData(WindowClass::BuildStation, 0);
184}
185
186static void UpdateConsists(int32_t)
187{
188 for (Train *t : Train::Iterate()) {
189 /* Update the consist of all trains so the maximum speed is set correctly. */
190 if (t->IsFrontEngine() || t->IsFreeWagon()) t->ConsistChanged(CCF_TRACK);
191 }
192 InvalidateWindowClassesData(WindowClass::BuildVehicle, 0);
193}
194
199static void UpdateAllServiceInterval(int32_t new_value)
200{
201 bool update_vehicles;
203 if (_game_mode == GameMode::Menu || !Company::IsValidID(_current_company)) {
204 vds = &_settings_client.company.vehicle;
205 update_vehicles = false;
206 } else {
207 vds = &Company::Get(_current_company)->settings.vehicle;
208 update_vehicles = true;
209 }
210
211 if (new_value != 0) {
212 /* Service intervals are in percents. */
213 vds->servint_trains = DEF_SERVINT_PERCENT;
214 vds->servint_roadveh = DEF_SERVINT_PERCENT;
215 vds->servint_aircraft = DEF_SERVINT_PERCENT;
216 vds->servint_ships = DEF_SERVINT_PERCENT;
217 } else if (TimerGameEconomy::UsingWallclockUnits(_game_mode == GameMode::Menu)) {
218 /* Service intervals are in minutes. */
219 vds->servint_trains = DEF_SERVINT_MINUTES_TRAINS;
220 vds->servint_roadveh = DEF_SERVINT_MINUTES_ROADVEH;
221 vds->servint_aircraft = DEF_SERVINT_MINUTES_AIRCRAFT;
222 vds->servint_ships = DEF_SERVINT_MINUTES_SHIPS;
223 } else {
224 /* Service intervals are in days. */
225 vds->servint_trains = DEF_SERVINT_DAYS_TRAINS;
226 vds->servint_roadveh = DEF_SERVINT_DAYS_ROADVEH;
227 vds->servint_aircraft = DEF_SERVINT_DAYS_AIRCRAFT;
228 vds->servint_ships = DEF_SERVINT_DAYS_SHIPS;
229 }
230
231 if (update_vehicles) {
233 for (Vehicle *v : Vehicle::Iterate()) {
234 if (v->owner == _current_company && v->IsPrimaryVehicle() && !v->ServiceIntervalIsCustom()) {
235 v->SetServiceInterval(CompanyServiceInterval(c, v->type));
236 v->SetServiceIntervalIsPercent(new_value != 0);
237 }
238 }
239 }
240
241 SetWindowClassesDirty(WindowClass::VehicleDetails);
242}
243
244static bool CanUpdateServiceInterval(VehicleType, int32_t &new_value)
245{
247 if (_game_mode == GameMode::Menu || !Company::IsValidID(_current_company)) {
248 vds = &_settings_client.company.vehicle;
249 } else {
250 vds = &Company::Get(_current_company)->settings.vehicle;
251 }
252
253 /* Test if the interval is valid */
254 int32_t interval = GetServiceIntervalClamped(new_value, vds->servint_ispercent);
255 return new_value == 0 || interval == new_value;
256}
257
258static void UpdateServiceInterval(VehicleType type, int32_t new_value)
259{
260 if (_game_mode != GameMode::Menu && Company::IsValidID(_current_company)) {
261 for (Vehicle *v : Vehicle::Iterate()) {
262 if (v->owner == _current_company && v->type == type && v->IsPrimaryVehicle() && !v->ServiceIntervalIsCustom()) {
263 v->SetServiceInterval(new_value);
264 }
265 }
266 }
267
268 SetWindowClassesDirty(WindowClass::VehicleDetails);
269}
270
278{
280 if (_game_mode == GameMode::Menu || !Company::IsValidID(_current_company)) {
281 vds = &_settings_client.company.vehicle;
282 } else {
283 vds = &Company::Get(_current_company)->settings.vehicle;
284 }
285
286 if (vds->servint_ispercent) return DEF_SERVINT_PERCENT;
287
289 switch (type) {
290 case VehicleType::Train: return DEF_SERVINT_MINUTES_TRAINS;
291 case VehicleType::Road: return DEF_SERVINT_MINUTES_ROADVEH;
292 case VehicleType::Aircraft: return DEF_SERVINT_MINUTES_AIRCRAFT;
293 case VehicleType::Ship: return DEF_SERVINT_MINUTES_SHIPS;
294 default: NOT_REACHED();
295 }
296 }
297
298 return sd.def;
299}
300
301static std::tuple<int32_t, uint32_t> GetServiceIntervalRange(const IntSettingDesc &)
302{
304 if (_game_mode == GameMode::Menu || !Company::IsValidID(_current_company)) {
305 vds = &_settings_client.company.vehicle;
306 } else {
307 vds = &Company::Get(_current_company)->settings.vehicle;
308 }
309
310 if (vds->servint_ispercent) return { MIN_SERVINT_PERCENT, MAX_SERVINT_PERCENT };
311
313 return { MIN_SERVINT_MINUTES, MAX_SERVINT_MINUTES };
314 }
315
316 return { MIN_SERVINT_DAYS, MAX_SERVINT_DAYS };
317}
318
319static void TrainAccelerationModelChanged(int32_t)
320{
321 for (Train *t : Train::Iterate()) {
322 if (t->IsFrontEngine()) {
323 t->tcache.cached_max_curve_speed = t->GetCurveSpeedLimit();
324 t->UpdateAcceleration();
325 }
326 }
327
328 /* These windows show acceleration values only when realistic acceleration is on. They must be redrawn after a setting change. */
329 SetWindowClassesDirty(WindowClass::EnginePreview);
330 InvalidateWindowClassesData(WindowClass::BuildVehicle, 0);
331 SetWindowClassesDirty(WindowClass::VehicleDetails);
332}
333
337static void TrainSlopeSteepnessChanged(int32_t)
338{
339 for (Train *t : Train::Iterate()) {
340 if (t->IsFrontEngine()) t->CargoChanged();
341 }
342}
343
348{
349 if (_settings_game.vehicle.roadveh_acceleration_model != AccelerationModel::Original) {
350 for (RoadVehicle *rv : RoadVehicle::Iterate()) {
351 if (rv->IsFrontEngine()) {
352 rv->CargoChanged();
353 }
354 }
355 }
356
357 /* These windows show acceleration values only when realistic acceleration is on. They must be redrawn after a setting change. */
358 SetWindowClassesDirty(WindowClass::EnginePreview);
359 InvalidateWindowClassesData(WindowClass::BuildVehicle, 0);
360 SetWindowClassesDirty(WindowClass::VehicleDetails);
361}
362
367{
368 for (RoadVehicle *rv : RoadVehicle::Iterate()) {
369 if (rv->IsFrontEngine()) rv->CargoChanged();
370 }
371}
372
376static void AircraftRangeChanged(int32_t)
377{
378 for (Aircraft *v : Aircraft::Iterate()) {
379 v->acache.cached_max_range = Engine::Get(v->engine_type)->GetRange();
380 v->acache.cached_max_range_sqr = v->acache.cached_max_range * v->acache.cached_max_range;
381
382 /* Reset destination is too far state */
383 if (v->flags.Test(VehicleAirFlag::DestinationTooFar)) {
384 v->flags.Reset(VehicleAirFlag::DestinationTooFar);
385 SetWindowWidgetDirty(WindowClass::VehicleView, v->index, WID_VV_START_STOP);
387 }
388 }
389}
390
391static void TownFoundingChanged(int32_t)
392{
393 if (_game_mode != GameMode::Editor && _settings_game.economy.found_town == TownFounding::Forbidden) {
394 CloseWindowById(WindowClass::FoundTown, 0);
395 } else {
396 InvalidateWindowData(WindowClass::FoundTown, 0);
397 }
398}
399
400static void ZoomMinMaxChanged(int32_t)
401{
402 ConstrainAllViewportsZoom();
404 InvalidateWindowClassesData(WindowClass::SpriteAligner);
405 if (AdjustGUIZoom(false)) {
406 ReInitAllWindows(true);
407 }
408}
409
410static void SpriteZoomMinChanged(int32_t)
411{
413 /* Force all sprites to redraw at the new chosen zoom level */
415}
416
423{
424 InvalidateWindowClassesData(WindowClass::SaveLoad);
425 CloseWindowByClass(WindowClass::GameOptions);
426 ReInitAllWindows(false);
427}
428
429static void InvalidateCompanyLiveryWindow(int32_t)
430{
431 InvalidateWindowClassesData(WindowClass::CompanyLivery, -1);
432 ResetVehicleColourMap();
433}
434
435static void DifficultyNoiseChange(int32_t)
436{
437 if (_game_mode == GameMode::Normal) {
439 if (_settings_game.economy.station_noise_level) {
440 InvalidateWindowClassesData(WindowClass::TownView, 0);
441 }
442 }
443}
444
445static void MaxNoAIsChange(int32_t)
446{
447 if (GetGameSettings().difficulty.max_no_competitors != 0 &&
448 AI::GetInfoList()->empty() &&
450 ShowErrorMessage(GetEncodedString(STR_WARNING_NO_SUITABLE_AI), {}, WarningLevel::Critical);
451 }
452
453 InvalidateWindowClassesData(WindowClass::GameOptions, 0);
454}
455
460static bool CheckRoadSide(int32_t &)
461{
462 return _game_mode == GameMode::Menu || !RoadVehiclesAreBuilt();
463}
464
472static std::optional<uint32_t> ConvertLandscape(std::string_view value)
473{
474 /* try with the old values */
475 static constexpr std::initializer_list<std::string_view> _old_landscape_values{"normal"sv, "hilly"sv, "desert"sv, "candy"sv};
476 return OneOfManySettingDesc::ParseSingleValue(value, _old_landscape_values);
477}
478
479static bool CheckFreeformEdges(int32_t &new_value)
480{
481 if (_game_mode == GameMode::Menu) return true;
482 if (new_value != 0) {
483 for (Ship *s : Ship::Iterate()) {
484 /* Check if there is a ship on the northern border. */
485 if (TileX(s->tile) == 0 || TileY(s->tile) == 0) {
486 ShowErrorMessage(GetEncodedString(STR_CONFIG_SETTING_EDGES_NOT_EMPTY), {}, WarningLevel::Error);
487 return false;
488 }
489 }
490 for (const BaseStation *st : BaseStation::Iterate()) {
491 /* Check if there is a non-deleted buoy on the northern border. */
492 if (st->IsInUse() && (TileX(st->xy) == 0 || TileY(st->xy) == 0)) {
493 ShowErrorMessage(GetEncodedString(STR_CONFIG_SETTING_EDGES_NOT_EMPTY), {}, WarningLevel::Error);
494 return false;
495 }
496 }
497 } else {
498 for (uint i = 0; i < Map::MaxX(); i++) {
499 if (TileHeight(TileXY(i, 1)) != 0) {
500 ShowErrorMessage(GetEncodedString(STR_CONFIG_SETTING_EDGES_NOT_WATER), {}, WarningLevel::Error);
501 return false;
502 }
503 }
504 for (uint i = 1; i < Map::MaxX(); i++) {
505 if (!IsTileType(TileXY(i, Map::MaxY() - 1), TileType::Water) || TileHeight(TileXY(1, Map::MaxY())) != 0) {
506 ShowErrorMessage(GetEncodedString(STR_CONFIG_SETTING_EDGES_NOT_WATER), {}, WarningLevel::Error);
507 return false;
508 }
509 }
510 for (uint i = 0; i < Map::MaxY(); i++) {
511 if (TileHeight(TileXY(1, i)) != 0) {
512 ShowErrorMessage(GetEncodedString(STR_CONFIG_SETTING_EDGES_NOT_WATER), {}, WarningLevel::Error);
513 return false;
514 }
515 }
516 for (uint i = 1; i < Map::MaxY(); i++) {
517 if (!IsTileType(TileXY(Map::MaxX() - 1, i), TileType::Water) || TileHeight(TileXY(Map::MaxX(), i)) != 0) {
518 ShowErrorMessage(GetEncodedString(STR_CONFIG_SETTING_EDGES_NOT_WATER), {}, WarningLevel::Error);
519 return false;
520 }
521 }
522 }
523 return true;
524}
525
526static void UpdateFreeformEdges(int32_t new_value)
527{
528 if (_game_mode == GameMode::Menu) return;
529
530 if (new_value != 0) {
531 for (uint x = 0; x < Map::SizeX(); x++) MakeVoid(TileXY(x, 0));
532 for (uint y = 0; y < Map::SizeY(); y++) MakeVoid(TileXY(0, y));
533 } else {
534 /* Make tiles at the border water again. */
535 for (uint i = 0; i < Map::MaxX(); i++) {
536 SetTileHeight(TileXY(i, 0), 0);
538 }
539 for (uint i = 0; i < Map::MaxY(); i++) {
540 SetTileHeight(TileXY(0, i), 0);
542 }
543 }
545}
546
552static bool CheckDynamicEngines([[maybe_unused]] int32_t &value)
553{
554 if (_game_mode == GameMode::Menu) return true;
555
557 ShowErrorMessage(GetEncodedString(STR_CONFIG_SETTING_DYNAMIC_ENGINES_EXISTING_VEHICLES), {}, WarningLevel::Error);
558 return false;
559 }
560
561 return true;
562}
563
564static bool CheckMaxHeightLevel(int32_t &new_value)
565{
566 if (_game_mode == GameMode::Normal) return false;
567 if (_game_mode != GameMode::Editor) return true;
568
569 /* Check if at least one mountain on the map is higher than the new value.
570 * If yes, disallow the change. */
571 for (const auto t : Map::Iterate()) {
572 if ((int32_t)TileHeight(t) > new_value) {
573 ShowErrorMessage(GetEncodedString(STR_CONFIG_SETTING_TOO_HIGH_MOUNTAIN), {}, WarningLevel::Error);
574 /* Return old, unchanged value */
575 return false;
576 }
577 }
578
579 return true;
580}
581
582static void StationCatchmentChanged(int32_t)
583{
586}
587
588static void MaxVehiclesChanged(int32_t)
589{
590 InvalidateWindowClassesData(WindowClass::BuildToolbar);
592}
593
599static bool ReplaceAsteriskWithEmptyPassword(std::string &newval)
600{
601 if (newval == "*") newval.clear();
602 return true;
603}
604
607{
609
610 InvalidateWindowData(WindowClass::NetworkClientList, 0);
611
612 if (_network_server) {
614 }
615}
616
621{
622 /* If service intervals are in time units (calendar days or real-world minutes), reset them to the correct defaults. */
623 if (!_settings_client.company.vehicle.servint_ispercent) {
625 }
626
627 /* If we are using calendar timekeeping, "minutes per year" must be default. */
629 _settings_newgame.economy.minutes_per_calendar_year = CalendarTime::DEF_MINUTES_PER_YEAR;
630 }
631
632 InvalidateWindowClassesData(WindowClass::GameOptions, 0);
633
634 /* It is possible to change these units in Scenario Editor. We must set the economy date appropriately. */
635 if (_game_mode == GameMode::Editor) {
636 TimerGameEconomy::Date new_economy_date;
637 TimerGameEconomy::DateFract new_economy_date_fract;
638
640 /* If the new mode is wallclock units, set the economy year back to 1. */
642 new_economy_date_fract = 0;
643 } else {
644 /* If the new mode is calendar units, sync the economy year with the calendar year. */
645 new_economy_date = TimerGameEconomy::Date{TimerGameCalendar::date.base()};
646 new_economy_date_fract = TimerGameCalendar::date_fract;
647 }
648
649 /* If you open a savegame as a scenario, there may already be link graphs and/or vehicles. These use economy date. */
650 LinkGraphSchedule::instance.ShiftDates(new_economy_date - TimerGameEconomy::date);
651 for (auto v : Vehicle::Iterate()) v->ShiftDates(new_economy_date - TimerGameEconomy::date);
652
653 /* Only change the date after changing cached values above. */
654 TimerGameEconomy::SetDate(new_economy_date, new_economy_date_fract);
655 }
656}
657
662static void ChangeMinutesPerYear(int32_t new_value)
663{
664 /* We don't allow setting Minutes Per Year below default, unless it's to 0 for frozen calendar time. */
665 if (new_value < CalendarTime::DEF_MINUTES_PER_YEAR) {
666 int clamped;
667
668 /* If the new value is 1, we're probably at 0 and trying to increase the value, so we should jump up to default. */
669 if (new_value == 1) {
670 clamped = CalendarTime::DEF_MINUTES_PER_YEAR;
671 } else {
672 clamped = CalendarTime::FROZEN_MINUTES_PER_YEAR;
673 }
674
675 /* Override the setting with the clamped value. */
676 if (_game_mode == GameMode::Menu) {
677 _settings_newgame.economy.minutes_per_calendar_year = clamped;
678 } else {
679 _settings_game.economy.minutes_per_calendar_year = clamped;
680 }
681 }
682
683 /* If the setting value is not the default, force the game to use wallclock timekeeping units.
684 * 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.
685 */
686 if (_game_mode == GameMode::Menu && (_settings_newgame.economy.minutes_per_calendar_year != CalendarTime::DEF_MINUTES_PER_YEAR)) {
687 if (_settings_newgame.economy.timekeeping_units != TimekeepingUnits::Wallclock) {
688 _settings_newgame.economy.timekeeping_units = TimekeepingUnits::Wallclock;
690 }
691 }
692}
693
694/* Get the valid range of the "minutes per calendar year" setting. */
695static std::tuple<int32_t, uint32_t> GetMinutesPerYearRange(const IntSettingDesc &)
696{
697 /* Allow a non-default value only if using Wallclock timekeeping units. */
698 if (TimerGameEconomy::UsingWallclockUnits(_game_mode == GameMode::Menu)) return { CalendarTime::FROZEN_MINUTES_PER_YEAR, CalendarTime::MAX_MINUTES_PER_YEAR };
699
700 return { CalendarTime::DEF_MINUTES_PER_YEAR, CalendarTime::DEF_MINUTES_PER_YEAR };
701}
702
707static bool CanChangeTimetableMode(int32_t &)
708{
710}
711
712/* 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:292
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
Definition of stuff that is very close to a company, like the company struct itself.
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.
Types related to currencies.
Header file for electrified rail specific functions.
Functions related to errors.
@ Critical
Critical errors, the MessageBox is shown in all cases.
Definition error.h:25
@ Error
Errors (eg. saving/loading failed).
Definition error.h:24
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:1859
void MarkWholeScreenDirty()
This function mark the whole screen as dirty.
Definition gfx.cpp:1548
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:63
bool _network_server
network-server is active
Definition network.cpp:64
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:55
@ Editor
In the scenario editor.
Definition openttd.h:21
@ Normal
Playing a game.
Definition openttd.h:20
@ Menu
In the main menu.
Definition openttd.h:19
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:173
Road vehicle states.
Command definitions related to road vehicles.
A number of safeguards to prevent using unsafe methods.
Functions related to saving and loading games.
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.
Functions to cache sprites in memory.
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:89
StrongType::Typedef< uint32_t, struct StringIDTag, StrongType::Compare, StrongType::Integer > 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:75
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:622
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:216
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:39
static void RecomputeCatchmentForAll()
Recomputes catchment of all stations.
Definition station.cpp:513
'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.
@ Forbidden
Forbidden.
Definition town_type.h:105
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.
Functions related to the vehicle's GUIs.
VehicleType
Available vehicle types.
@ Ship
Ship vehicle type.
@ Aircraft
Aircraft vehicle type.
@ Road
Road vehicle type.
@ Train
Train vehicle type.
@ Original
Original acceleration model.
@ 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:3560
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:1242
int PositionMainToolbar(Window *w)
(Re)position main toolbar window at the screen.
Definition window.cpp:3549
int PositionNetworkChatWindow(Window *w)
(Re)position network chat window at the screen.
Definition window.cpp:3582
void ReInitAllWindows(bool zoom_changed)
Re-initialize all windows.
Definition window.cpp:3494
void CloseWindowByClass(WindowClass cls, int data)
Close all windows of a given class.
Definition window.cpp:1255
int PositionNewsMessage(Window *w)
(Re)position news message window at the screen.
Definition window.cpp:3571
void SetWindowClassesDirty(WindowClass cls)
Mark all windows of a particular class as dirty (in need of repainting).
Definition window.cpp:3285
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:3377
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:3271
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:3395
Window functions not directly related to making/drawing windows.