OpenTTD Source 20261112-master-gbcbec5e63f
cheat_gui.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 "command_func.h"
12#include "cheat_type.h"
13#include "company_base.h"
14#include "company_func.h"
15#include "currency_func.h"
16#include "vehicle_base.h"
17#include "textbuf_gui.h"
18#include "window_gui.h"
19#include "strings_func.h"
20#include "window_func.h"
21#include "rail_gui.h"
22#include "settings_gui.h"
23#include "company_gui.h"
25#include "map_func.h"
26#include "tile_map.h"
27#include "newgrf.h"
28#include "error.h"
29#include "misc_cmd.h"
30#include "settings_type.h"
31#include "settings_internal.h"
32#include "timer/timer.h"
36
38
39#include "table/sprites.h"
40#include "table/strings.h"
41
42#include "safeguards.h"
43
44
50static int32_t _money_cheat_amount = 10000000;
51
60static int32_t ClickMoneyCheat(int32_t, int32_t change_direction)
61{
62 Command<Commands::MoneyCheat>::Post(Money(_money_cheat_amount) * change_direction);
64}
65
72static int32_t ClickChangeCompanyCheat(int32_t new_value, int32_t change_direction)
73{
74 while ((uint)new_value < Company::GetPoolSize()) {
75 if (Company::IsValidID((CompanyID)new_value)) {
76 SetLocalCompany((CompanyID)new_value);
77 return _local_company.base();
78 }
79 new_value += change_direction;
80 }
81
82 return _local_company.base();
83}
84
90static int32_t ClickSetProdCheat(int32_t new_value, int32_t)
91{
92 _cheats.setup_prod.value = (new_value != 0);
93 InvalidateWindowClassesData(WindowClass::IndustryView);
94 return _cheats.setup_prod.value;
95}
96
97extern void CalendarEnginesMonthlyLoop();
98
104static int32_t ClickChangeDateCheat(int32_t new_value, int32_t)
105{
106 /* Don't allow changing to an invalid year, or the current year. */
108 if (new_year == TimerGameCalendar::year) return TimerGameCalendar::year.base();
109
110 TimerGameCalendar::YearMonthDay ymd = TimerGameCalendar::ConvertDateToYMD(TimerGameCalendar::date);
111 TimerGameCalendar::Date new_calendar_date = TimerGameCalendar::ConvertYMDToDate(new_year, ymd.month, ymd.day);
112
114
115 /* If not using wallclock units, we keep economy date in sync with calendar date and must change it also. */
117 /* Keep economy and calendar dates synced. */
118 TimerGameEconomy::Date new_economy_date{new_calendar_date.base()};
119
120 /* Shift cached dates before we change the date. */
121 for (auto v : Vehicle::Iterate()) v->ShiftDates(new_economy_date - TimerGameEconomy::date);
122 LinkGraphSchedule::instance.ShiftDates(new_economy_date - TimerGameEconomy::date);
123
124 /* Now it's safe to actually change the date. */
126 }
127
129 SetWindowDirty(WindowClass::Statusbar, 0);
130 InvalidateWindowClassesData(WindowClass::BuildStation, 0);
131 InvalidateWindowClassesData(WindowClass::BuildBusStation, 0);
132 InvalidateWindowClassesData(WindowClass::BuildTruckStation, 0);
133 InvalidateWindowClassesData(WindowClass::BuildObject, 0);
134 InvalidateWindowClassesData(WindowClass::Finances, 0);
136 return TimerGameCalendar::year.base();
137}
138
145static int32_t ClickChangeMaxHlCheat(int32_t new_value, int32_t)
146{
147 new_value = Clamp(new_value, MIN_MAP_HEIGHT_LIMIT, MAX_MAP_HEIGHT_LIMIT);
148
149 /* Check if at least one mountain on the map is higher than the new value.
150 * If yes, disallow the change. */
151 for (const auto t : Map::Iterate()) {
152 if ((int32_t)TileHeight(t) > new_value) {
153 ShowErrorMessage(GetEncodedString(STR_CONFIG_SETTING_TOO_HIGH_MOUNTAIN), {}, WarningLevel::Error);
154 /* Return old, unchanged value */
155 return _settings_game.construction.map_height_limit;
156 }
157 }
158
159 /* Execute the change and reload GRF Data */
160 _settings_game.construction.map_height_limit = new_value;
162
163 /* The smallmap uses an index from heightlevels to colours. Trigger rebuilding it. */
164 InvalidateWindowClassesData(WindowClass::SmallMap, 2);
165
166 return _settings_game.construction.map_height_limit;
167}
168
183
189typedef int32_t CheckButtonClick(int32_t new_value, int32_t change_direction);
190
199
204static const CheatEntry _cheats_ui[] = {
205 { VarMemType::I32, STR_CHEAT_MONEY, &_money_cheat_amount, &_cheats.money.been_used, &ClickMoneyCheat },
206 { VarMemType::U8, STR_CHEAT_CHANGE_COMPANY, &_local_company, &_cheats.switch_company.been_used, &ClickChangeCompanyCheat },
207 { VarMemType::Bool, STR_CHEAT_EXTRA_DYNAMITE, &_cheats.magic_bulldozer.value, &_cheats.magic_bulldozer.been_used, nullptr },
208 { VarMemType::Bool, STR_CHEAT_CROSSINGTUNNELS, &_cheats.crossing_tunnels.value, &_cheats.crossing_tunnels.been_used, nullptr },
209 { VarMemType::Bool, STR_CHEAT_NO_JETCRASH, &_cheats.no_jetcrash.value, &_cheats.no_jetcrash.been_used, nullptr },
210 { VarMemType::Bool, STR_CHEAT_SETUP_PROD, &_cheats.setup_prod.value, &_cheats.setup_prod.been_used, &ClickSetProdCheat },
211 { VarMemType::Bool, STR_CHEAT_STATION_RATING, &_cheats.station_rating.value, &_cheats.station_rating.been_used, nullptr },
212 { VarMemType::U8, STR_CHEAT_EDIT_MAX_HL, &_settings_game.construction.map_height_limit, &_cheats.edit_max_hl.been_used, &ClickChangeMaxHlCheat },
213 { VarMemType::I32, STR_CHEAT_CHANGE_DATE, &TimerGameCalendar::year, &_cheats.change_date.been_used, &ClickChangeDateCheat },
214};
215
216static_assert(CHT_NUM_CHEATS == lengthof(_cheats_ui));
217
233
235struct CheatWindow : Window {
236 int clicked = 0;
237 int clicked_cheat = 0;
238 uint line_height = 0;
240
241 std::vector<const SettingDesc *> sandbox_settings{};
242 const SettingDesc *clicked_setting = nullptr;
243 const SettingDesc *last_clicked_setting = nullptr;
244 const SettingDesc *valuewindow_entry = nullptr;
245
246 CheatWindow(WindowDesc &desc) : Window(desc)
247 {
248 this->sandbox_settings = GetFilteredSettingCollection([](const SettingDesc &sd) { return sd.flags.Test(SettingFlag::Sandbox); });
249 this->InitNested();
250 }
251
252 void OnInit() override
253 {
254 this->icon = GetSpriteSize(SPR_COMPANY_ICON);
255 }
256
257 void DrawWidget(const Rect &r, WidgetID widget) const override
258 {
259 switch (widget) {
260 case WID_C_PANEL: DrawCheatWidget(r); break;
261 case WID_C_SETTINGS: DrawSettingsWidget(r); break;
262 }
263 }
264
265 void DrawCheatWidget(const Rect &r) const
266 {
267 const Rect ir = r;
268 int y = ir.top;
269
270 bool rtl = _current_text_dir == TD_RTL;
271 uint button_left = rtl ? ir.right - SETTING_BUTTON_WIDTH : ir.left;
272 uint text_left = ir.left + (rtl ? 0 : WidgetDimensions::scaled.hsep_wide + SETTING_BUTTON_WIDTH);
273 uint text_right = ir.right - (rtl ? WidgetDimensions::scaled.hsep_wide + SETTING_BUTTON_WIDTH : 0);
274
275 int text_y_offset = (this->line_height - GetCharacterHeight(FontSize::Normal)) / 2;
276 int button_y_offset = (this->line_height - SETTING_BUTTON_HEIGHT) / 2;
277 int icon_y_offset = (this->line_height - this->icon.height) / 2;
278
279 for (int i = 0; i != lengthof(_cheats_ui); i++) {
280 const CheatEntry *ce = &_cheats_ui[i];
281
282 std::string str;
283 switch (ce->type) {
284 case VarMemType::Bool: {
285 bool on = (*(bool*)ce->variable);
286
287 DrawBoolButton(button_left, y + button_y_offset, Colours::Yellow, Colours::Grey, on, true);
288 str = GetString(ce->str, on ? STR_CONFIG_SETTING_ON : STR_CONFIG_SETTING_OFF);
289 break;
290 }
291
292 default: {
293 int32_t val = static_cast<int32_t>(ReadValue(ce->variable, ce->type));
294
295 /* Draw [<][>] boxes for settings of an integer-type */
296 DrawArrowButtons(button_left, y + button_y_offset, Colours::Yellow, clicked - (i * 2), true, true);
297
298 switch (ce->str.base()) {
299 /* Display date for change date cheat */
300 case STR_CHEAT_CHANGE_DATE.base():
302 break;
303
304 /* Draw coloured flag for change company cheat */
305 case STR_CHEAT_CHANGE_COMPANY.base(): {
306 str = GetString(ce->str, val + 1);
308 DrawCompanyIcon(_local_company, rtl ? text_right - offset - WidgetDimensions::scaled.hsep_indent : text_left + offset, y + icon_y_offset);
309 break;
310 }
311
312 default:
313 str = GetString(ce->str, val);
314 break;
315 }
316 break;
317 }
318 }
319
320 DrawString(text_left, text_right, y + text_y_offset, str);
321
322 y += this->line_height;
323 }
324 }
325
326 void DrawSettingsWidget(const Rect &r) const
327 {
328 Rect ir = r.WithHeight(this->line_height);
329
330 for (const auto &desc : this->sandbox_settings) {
331 DrawSetting(ir, desc);
332 ir = ir.Translate(0, this->line_height);
333 }
334 }
335
336 void DrawSetting(const Rect r, const SettingDesc *desc) const
337 {
338 const IntSettingDesc *sd = desc->AsIntSetting();
339 int state = this->clicked_setting == sd ? this->clicked : 0;
340
341 bool rtl = _current_text_dir == TD_RTL;
342
343 Rect buttons = r.WithWidth(SETTING_BUTTON_WIDTH, rtl);
344 Rect text = r.Indent(SETTING_BUTTON_WIDTH + WidgetDimensions::scaled.hsep_wide, rtl);
345 buttons.top += (r.Height() - SETTING_BUTTON_HEIGHT) / 2;
346 text.top += (r.Height() - GetCharacterHeight(FontSize::Normal)) / 2;
347
348 /* We do not allow changes of some items when we are a client in a network game */
349 bool editable = sd->IsEditable();
350
351 auto [min_val, max_val] = sd->GetRange();
352 int32_t value = sd->Read(&GetGameSettings());
353 if (sd->IsBoolSetting()) {
354 /* Draw checkbox for boolean-value either on/off */
355 DrawBoolButton(buttons.left, buttons.top, Colours::Yellow, Colours::Grey, value != 0, editable);
356 } else if (sd->flags.Test(SettingFlag::GuiDropdown)) {
357 /* Draw [v] button for settings of an enum-type */
358 DrawDropDownButton(buttons.left, buttons.top, Colours::Yellow, state != 0, editable);
359 } else {
360 /* Draw [<][>] boxes for settings of an integer-type */
361 DrawArrowButtons(buttons.left, buttons.top, Colours::Yellow, state,
362 editable && value != (sd->flags.Test(SettingFlag::GuiZeroIsSpecial) ? 0 : min_val), editable && static_cast<uint32_t>(value) != max_val);
363 }
364 auto [param1, param2] = sd->GetValueParams(value);
365 DrawString(text.left, text.right, text.top, GetString(sd->GetTitle(), STR_CONFIG_SETTING_VALUE, param1, param2), TextColour::LightBlue);
366 }
367
368 void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override
369 {
370 switch (widget) {
371 case WID_C_PANEL: UpdateCheatPanelSize(size); break;
372 case WID_C_SETTINGS: UpdateSettingsPanelSize(size); break;
373 }
374 }
375
376 void UpdateCheatPanelSize(Dimension &size)
377 {
378 uint width = 0;
379 for (const auto &ce : _cheats_ui) {
380 switch (ce.type) {
381 case VarMemType::Bool:
382 width = std::max(width, GetStringBoundingBox(GetString(ce.str, STR_CONFIG_SETTING_ON)).width);
383 width = std::max(width, GetStringBoundingBox(GetString(ce.str, STR_CONFIG_SETTING_OFF)).width);
384 break;
385
386 default:
387 switch (ce.str.base()) {
388 /* Display date for change date cheat */
389 case STR_CHEAT_CHANGE_DATE.base():
391 break;
392
393 /* Draw coloured flag for change company cheat */
394 case STR_CHEAT_CHANGE_COMPANY.base():
395 width = std::max(width, GetStringBoundingBox(GetString(ce.str, MAX_COMPANIES)).width + WidgetDimensions::scaled.hsep_wide);
396 break;
397
398 default:
399 width = std::max(width, GetStringBoundingBox(GetString(ce.str, INT64_MAX)).width);
400 break;
401 }
402 break;
403 }
404 }
405
406 this->line_height = std::max<uint>(this->icon.height, SETTING_BUTTON_HEIGHT);
407 this->line_height = std::max<uint>(this->line_height, GetCharacterHeight(FontSize::Normal)) + WidgetDimensions::scaled.framerect.Vertical();
408
410 size.height = this->line_height * lengthof(_cheats_ui);
411 }
412
413 void UpdateSettingsPanelSize(Dimension &size)
414 {
415 uint width = 0;
416 for (const auto &desc : this->sandbox_settings) {
417 const IntSettingDesc *sd = desc->AsIntSetting();
418
419 auto [param1, param2] = sd->GetValueParams(sd->GetDefaultValue());
420 width = std::max(width, GetStringBoundingBox(GetString(sd->GetTitle(), STR_CONFIG_SETTING_VALUE, param1, param2)).width);
421 }
422
424 size.height = this->line_height * static_cast<uint>(std::size(this->sandbox_settings));
425 }
426
427 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
428 {
429 switch (widget) {
430 case WID_C_PANEL: CheatPanelClick(pt); break;
431 case WID_C_SETTINGS: SettingsPanelClick(pt); break;
432 }
433 }
434
435 void CheatPanelClick(Point pt)
436 {
437 Rect r = this->GetWidget<NWidgetBase>(WID_C_PANEL)->GetCurrentRect().Shrink(WidgetDimensions::scaled.framerect);
438 uint btn = (pt.y - r.top) / this->line_height;
439 int x = pt.x - r.left;
440 bool rtl = _current_text_dir == TD_RTL;
441 if (rtl) x = r.Width() - 1 - x;
442
443 if (btn >= lengthof(_cheats_ui)) return;
444
445 const CheatEntry *ce = &_cheats_ui[btn];
446 int value = static_cast<int32_t>(ReadValue(ce->variable, ce->type));
447 int oldvalue = value;
448
449 if (btn == CHT_CHANGE_DATE && x >= SETTING_BUTTON_WIDTH) {
450 /* Click at the date text directly. */
451 clicked_cheat = CHT_CHANGE_DATE;
452 ShowQueryString(GetString(STR_JUST_INT, value), STR_CHEAT_CHANGE_DATE_QUERY_CAPT, 8, this, CS_NUMERAL, QueryStringFlag::AcceptUnchanged);
453 return;
454 } else if (btn == CHT_EDIT_MAX_HL && x >= SETTING_BUTTON_WIDTH) {
455 clicked_cheat = CHT_EDIT_MAX_HL;
456 ShowQueryString(GetString(STR_JUST_INT, value), STR_CHEAT_EDIT_MAX_HL_QUERY_CAPT, 8, this, CS_NUMERAL, QueryStringFlag::AcceptUnchanged);
457 return;
458 }
459
460 /* Not clicking a button? */
461 if (!IsInsideMM(x, 0, SETTING_BUTTON_WIDTH)) return;
462
463 this->clicked_setting = nullptr;
464 *ce->been_used = true;
465
466 switch (ce->type) {
467 case VarMemType::Bool:
468 value ^= 1;
469 if (ce->proc != nullptr) ce->proc(value, 0);
470 break;
471
472 default:
473 /* Take whatever the function returns */
474 value = ce->proc(value + ((x >= SETTING_BUTTON_WIDTH / 2) ? 1 : -1), (x >= SETTING_BUTTON_WIDTH / 2) ? 1 : -1);
475
476 /* The first cheat (money), doesn't return a different value. */
477 if (value != oldvalue || btn == CHT_MONEY) this->clicked = btn * 2 + 1 + ((x >= SETTING_BUTTON_WIDTH / 2) != rtl ? 1 : 0);
478 break;
479 }
480
481 if (value != oldvalue) WriteValue(ce->variable, ce->type, static_cast<int64_t>(value));
482
483 this->SetTimeout();
484
485 this->SetDirty();
486 }
487
488 void SettingsPanelClick(Point pt)
489 {
490 int row = this->GetRowFromWidget(pt.y, WID_C_SETTINGS, WidgetDimensions::scaled.framerect.top, this->line_height);
491 if (row == INT_MAX) return;
492
493 const SettingDesc *desc = this->sandbox_settings[row];
494 const IntSettingDesc *sd = desc->AsIntSetting();
495
496 if (!sd->IsEditable()) return;
497
498 Rect r = this->GetWidget<NWidgetBase>(WID_C_SETTINGS)->GetCurrentRect().Shrink(WidgetDimensions::scaled.framerect);
499 int x = pt.x - r.left;
500 bool rtl = _current_text_dir == TD_RTL;
501 if (rtl) x = r.Width() - 1 - x;
502
503 if (x < SETTING_BUTTON_WIDTH) {
504 ChangeSettingValue(sd, x);
505 } else {
506 /* Only open editbox if clicked for the second time, and only for types where it is sensible for. */
507 if (this->last_clicked_setting == sd && !sd->IsBoolSetting() && !sd->flags.Test(SettingFlag::GuiDropdown)) {
508 int64_t value64 = sd->Read(&GetGameSettings());
509
510 /* Show the correct currency-translated value */
511 if (sd->flags.Test(SettingFlag::GuiCurrency)) value64 *= GetCurrency().rate;
512
513 CharSetFilter charset_filter = CS_NUMERAL; //default, only numeric input allowed
514 if (sd->min < 0) charset_filter = CS_NUMERAL_SIGNED; // special case, also allow '-' sign for negative input
515
516 this->valuewindow_entry = sd;
517
518 /* Limit string length to 14 so that MAX_INT32 * max currency rate doesn't exceed MAX_INT64. */
519 ShowQueryString(GetString(STR_JUST_INT, value64), STR_CONFIG_SETTING_QUERY_CAPTION, 15, this, charset_filter, QueryStringFlag::EnableDefault);
520 }
521
522 this->clicked_setting = sd;
523 }
524 }
525
526 void ChangeSettingValue(const IntSettingDesc *sd, int x)
527 {
528 int32_t value = sd->Read(&GetGameSettings());
529 int32_t oldvalue = value;
530 if (sd->IsBoolSetting()) {
531 value ^= 1;
532 } else {
533 /* don't allow too fast scrolling */
534 if (this->flags.Test(WindowFlag::Timeout) && this->timeout_timer > 1) {
536 return;
537 }
538
539 /* Add a dynamic step-size to the scroller. In a maximum of
540 * 50-steps you should be able to get from min to max,
541 * unless specified otherwise in the 'interval' variable
542 * of the current setting. */
543 uint32_t step = (sd->interval == 0) ? ((sd->max - sd->min) / 50) : sd->interval;
544 if (step == 0) step = 1;
545
546 /* Increase or decrease the value and clamp it to extremes */
547 if (x >= SETTING_BUTTON_WIDTH / 2) {
548 value += step;
549 if (sd->min < 0) {
550 assert(static_cast<int32_t>(sd->max) >= 0);
551 if (value > static_cast<int32_t>(sd->max)) value = static_cast<int32_t>(sd->max);
552 } else {
553 if (static_cast<uint32_t>(value) > sd->max) value = static_cast<int32_t>(sd->max);
554 }
555 if (value < sd->min) value = sd->min; // skip between "disabled" and minimum
556 } else {
557 value -= step;
558 if (value < sd->min) value = sd->flags.Test(SettingFlag::GuiZeroIsSpecial) ? 0 : sd->min;
559 }
560
561 /* Set up scroller timeout for numeric values */
562 if (value != oldvalue) {
563 this->last_clicked_setting = nullptr;
564 this->clicked_setting = sd;
565 this->clicked = (x >= SETTING_BUTTON_WIDTH / 2) != (_current_text_dir == TD_RTL) ? 2 : 1;
566 this->SetTimeout();
568 }
569 }
570
571 if (value != oldvalue) {
572 SetSettingValue(sd, value);
573 this->SetDirty();
574 }
575 }
576
577 bool OnTooltip([[maybe_unused]] Point pt, WidgetID widget, TooltipCloseCondition close_cond) override
578 {
579 if (widget != WID_C_SETTINGS) return false;
580
581 int row = GetRowFromWidget(pt.y, widget, WidgetDimensions::scaled.framerect.top, this->line_height);
582 if (row == INT_MAX) return false;
583
584 const SettingDesc *desc = this->sandbox_settings[row];
585 const IntSettingDesc *sd = desc->AsIntSetting();
586 GuiShowTooltips(this, GetEncodedString(sd->GetHelp()), close_cond);
587
588 return true;
589 }
590
591 void OnTimeout() override
592 {
593 this->clicked_setting = nullptr;
594 this->clicked = 0;
595 this->SetDirty();
596 }
597
598 void OnQueryTextFinished(std::optional<std::string> str) override
599 {
600 /* Was 'cancel' pressed or nothing entered? */
601 if (!str.has_value() || str->empty()) return;
602
603 if (this->valuewindow_entry != nullptr) {
604 const IntSettingDesc *sd = this->valuewindow_entry->AsIntSetting();
605
606 int32_t value;
607 if (!str->empty()) {
608 auto llvalue = ParseInteger<int64_t>(*str, 10, true);
609 if (!llvalue.has_value()) return;
610
611 /* Save the correct currency-translated value */
612 if (sd->flags.Test(SettingFlag::GuiCurrency)) llvalue = *llvalue / GetCurrency().rate;
613
614 value = ClampTo<int32_t>(*llvalue);
615 } else {
616 value = sd->GetDefaultValue();
617 }
618
619 SetSettingValue(sd, value);
620 } else {
621 const CheatEntry *ce = &_cheats_ui[clicked_cheat];
622 int oldvalue = static_cast<int32_t>(ReadValue(ce->variable, ce->type));
623 auto value = ParseInteger<int32_t>(*str, 10, true);
624 if (!value.has_value()) return;
625 *ce->been_used = true;
626 value = ce->proc(*value, *value - oldvalue);
627
628 if (*value != oldvalue) WriteValue(ce->variable, ce->type, static_cast<int64_t>(*value));
629 }
630
631 this->valuewindow_entry = nullptr;
632 this->SetDirty();
633 }
634
635 const IntervalTimer<TimerGameCalendar> daily_interval = {{TimerGameCalendar::Trigger::Month, TimerGameCalendar::Priority::None}, [this](auto) {
636 this->SetDirty();
637 }};
638};
639
642 WindowPosition::Automatic, "cheats", 0, 0,
643 WindowClass::Cheat, WindowClass::None,
644 {},
646);
647
650{
651 CloseWindowById(WindowClass::Cheat, 0);
653}
Cheats _cheats
All the cheats.
Definition cheat.cpp:16
static constexpr std::initializer_list< NWidgetPart > _nested_cheat_widgets
Widget definitions of the cheat GUI.
CheatNumbers
Available cheats.
@ CHT_NO_JETCRASH
Disable jet-airplane crashes.
@ CHT_CHANGE_DATE
Do time traveling.
@ CHT_CROSSINGTUNNELS
Allow tunnels to cross each other.
@ CHT_SETUP_PROD
Allow manually editing of industry production.
@ CHT_CHANGE_COMPANY
Switch company.
@ CHT_NUM_CHEATS
Number of cheats.
@ CHT_EXTRA_DYNAMITE
Dynamite anything.
@ CHT_MONEY
Change amount of money.
@ CHT_STATION_RATING
Fix station ratings at 100%.
@ CHT_EDIT_MAX_HL
Edit maximum allowed heightlevel.
static int32_t _money_cheat_amount
The 'amount' to cheat with.
Definition cheat_gui.cpp:50
static int32_t ClickChangeMaxHlCheat(int32_t new_value, int32_t)
Allow (or disallow) a change of the maximum allowed heightlevel.
static WindowDesc _cheats_desc(WindowPosition::Automatic, "cheats", 0, 0, WindowClass::Cheat, WindowClass::None, {}, _nested_cheat_widgets)
Window description of the cheats GUI.
void CalendarEnginesMonthlyLoop()
Monthly update of the availability, reliability, and preview offers of the engines.
Definition engine.cpp:1179
static int32_t ClickMoneyCheat(int32_t, int32_t change_direction)
Handle cheating of money.
Definition cheat_gui.cpp:60
static int32_t ClickSetProdCheat(int32_t new_value, int32_t)
Allow (or disallow) changing production of all industries.
Definition cheat_gui.cpp:90
static int32_t ClickChangeDateCheat(int32_t new_value, int32_t)
Handle changing of the current year.
static int32_t ClickChangeCompanyCheat(int32_t new_value, int32_t change_direction)
Handle changing of company.
Definition cheat_gui.cpp:72
int32_t CheckButtonClick(int32_t new_value, int32_t change_direction)
Signature of handler function when user clicks at a cheat.
void ShowCheatWindow()
Open cheat window.
static const CheatEntry _cheats_ui[]
The available cheats.
Types related to cheating.
Types related to the cheat widgets.
@ WID_C_PANEL
Panel where all cheats are shown in.
@ WID_C_SETTINGS
Panel where sandbox settings are shown.
constexpr bool Test(Tvalue_type value) const
Test if the value-th bit is set.
constexpr Timpl & Reset()
Reset all bits.
An interval timer will fire every interval, and will continue to fire until it is deleted.
Definition timer.h:76
static LinkGraphSchedule instance
Static instance of LinkGraphSchedule.
static Date ConvertYMDToDate(Year year, Month month, Day day)
Converts a tuple of Year, Month and Day to a Date.
static YearMonthDay ConvertDateToYMD(Date date)
Converts a Date to a Year, Month & Day.
static void SetDate(Date date, DateFract fract)
Set the date.
static Date date
Current date in days (day counter).
static Year year
Current year, starting at 0.
static DateFract date_fract
Fractional part of the day.
static constexpr TimerGame< struct Calendar >::Year MIN_YEAR
static constexpr TimerGame< struct Calendar >::Year MAX_YEAR
static Date date
Current date in days (day counter).
static bool UsingWallclockUnits(bool newgame=false)
Check if we are using wallclock units.
static DateFract date_fract
Fractional part of the day.
static void SetDate(Date date, DateFract fract)
Set the date.
StrongType::Typedef< int32_t, struct YearTag< struct Calendar >, StrongType::Compare, StrongType::Integer > Year
StrongType::Typedef< int32_t, DateTag< struct Calendar >, StrongType::Compare, StrongType::Integer > Date
RectPadding framerect
Standard padding inside many panels.
Definition window_gui.h:41
static WidgetDimensions scaled
Widget dimensions scaled for current zoom level.
Definition window_gui.h:30
int hsep_wide
Wide horizontal spacing.
Definition window_gui.h:63
static const WidgetDimensions unscaled
Unscaled widget dimensions.
Definition window_gui.h:94
int hsep_indent
Width of indentation for tree layouts.
Definition window_gui.h:64
Functions related to commands.
Definition of stuff that is very close to a company, like the company struct itself.
void DrawCompanyIcon(CompanyID c, int x, int y)
Draw the icon of a company.
void SetLocalCompany(CompanyID new_company, bool switching_game)
Sets the local company and updates the settings that are set on a per-company basis to reflect the co...
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Functions related to companies.
GUI Functions related to companies.
Functions to handle different currencies.
const CurrencySpec & GetCurrency()
Get the currently selected currency.
Functions related to errors.
@ 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.
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
Definition fontcache.cpp:88
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
Definition gfx.cpp:966
Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition gfx.cpp:894
ControlInputs _input_clicked
Control inputs that have been actioned.
Definition gfx.cpp:35
int DrawString(int left, int right, int top, std::string_view str, ExtendedTextColour colour, Alignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
Definition gfx.cpp:663
@ Normal
Index of the normal font in the font tables.
Definition gfx_type.h:249
@ Invalid
Invalid marker.
Definition gfx_type.h:302
@ Yellow
Yellow.
Definition gfx_type.h:288
@ Grey
Grey.
Definition gfx_type.h:299
@ LightBlue
Light blue colour.
Definition gfx_type.h:331
@ Left
Left mouse button is pressed.
Definition gfx_type.h:444
constexpr NWidgetPart SetPadding(uint8_t top, uint8_t right, uint8_t bottom, uint8_t left)
Widget part function for setting additional space around a widget.
constexpr NWidgetPart SetStringTip(StringID string, StringID tip={})
Widget part function for setting the string and tooltip.
constexpr NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx=INVALID_WIDGET)
Widget part function for starting a new 'real' widget.
void SetDirty() const
Mark entire window as dirty (in need of re-paint).
Definition window.cpp:1013
Declaration of link graph schedule used for cargo distribution.
#define Rect
Macro that prevents name conflicts between included headers.
#define Point
Macro that prevents name conflicts between included headers.
Functions related to maps.
constexpr bool IsInsideMM(const size_t x, const size_t min, const size_t max) noexcept
Checks if a value is in an interval.
constexpr T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
Definition math_func.hpp:79
constexpr To ClampTo(From value)
Clamp the given value down to lie within the requested type.
Miscellaneous command definitions.
void GuiShowTooltips(Window *parent, EncodedString &&text, TooltipCloseCondition close_tooltip)
Shows a tooltip.
Definition misc_gui.cpp:690
void ShowQueryString(std::string_view str, StringID caption, uint maxsize, Window *parent, CharSetFilter afilter, QueryStringFlags flags)
Show a query popup window with a textbox in it.
Base for the NewGRF implementation.
void ReloadNewGRFData()
Reload all NewGRF files during a running game.
void ResetSignalVariant(int32_t)
Updates the current signal variant used in the signal GUI to the one adequate to current year.
Functions/types etc.
A number of safeguards to prevent using unsafe methods.
void WriteValue(void *ptr, VarMemType conv, int64_t val)
Write the value of a setting.
Definition saveload.cpp:910
int64_t ReadValue(const void *ptr, VarMemType conv)
Return a signed-long version of the value of a setting.
Definition saveload.cpp:886
VarMemType
The types/structures of data we have in memory.
Definition saveload.h:657
@ U8
A 8 bit unsigned int.
Definition saveload.h:660
@ Bool
A boolean value.
Definition saveload.h:658
@ I32
A 32 bit signed int.
Definition saveload.h:663
std::vector< const SettingDesc * > GetFilteredSettingCollection(std::function< bool(const SettingDesc &desc)> func)
Get a collection of settings matching a custom filter.
bool SetSettingValue(const IntSettingDesc *sd, int32_t value, bool force_newgame)
Top function to save the new value of an element of the Settings struct.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition settings.cpp:61
void DrawArrowButtons(int x, int y, Colours button_colour, uint8_t state, bool clickable_left, bool clickable_right)
Draw [<][>] boxes.
void DrawBoolButton(int x, int y, Colours button_colour, Colours background, bool state, bool clickable)
Draw a toggle button.
void DrawDropDownButton(int x, int y, Colours button_colour, bool state, bool clickable)
Draw a dropdown button.
Functions for setting GUIs.
#define SETTING_BUTTON_WIDTH
Width of setting buttons.
#define SETTING_BUTTON_HEIGHT
Height of setting buttons.
Functions and types used internally for the settings configurations.
@ GuiCurrency
The number represents money, so when reading value multiply by exchange rate.
@ Sandbox
This setting is a sandbox setting.
@ GuiZeroIsSpecial
A value of zero is possible and has a custom string (the one after "strval").
@ GuiDropdown
The value represents a limited number of string-options (internally integer) presented as dropdown.
Types related to global configuration settings.
GameSettings & GetGameSettings()
Get the settings-object applicable for the current situation: the newgame settings when we're in the ...
This file contains all sprite-related enums and defines.
static const SpriteID SPR_COMPANY_ICON
Icon showing company colour.
Definition sprites.h:386
Definition of base types and functions in a cross-platform compatible way.
#define lengthof(array)
Return the length of an fixed size array.
Definition stdafx.h:261
Parse strings.
static std::optional< T > ParseInteger(std::string_view arg, int base=10, bool clamp=false)
Change a string into its number representation.
CharSetFilter
Valid filter types for IsValidChar.
Definition string_type.h:24
@ CS_NUMERAL
Only numeric ones.
Definition string_type.h:26
@ CS_NUMERAL_SIGNED
Only numbers and '-' for negative values.
Definition string_type.h:28
EncodedString GetEncodedString(StringID str)
Encode a string with no parameters into an encoded string.
Definition strings.cpp:89
std::string GetString(StringID string)
Resolve the given StringID into a std::string with formatting but no parameters.
Definition strings.cpp:423
TextDirection _current_text_dir
Text direction of the currently selected language.
Definition strings.cpp:55
Functions related to OTTD's strings.
StrongType::Typedef< uint32_t, struct StringIDTag, StrongType::Compare, StrongType::Integer > StringID
Numeric value that represents a string, independent of the selected language.
@ TD_RTL
Text is written right-to-left by default.
Information of a cheat.
void * variable
pointer to the variable
StringID str
string with descriptive text
CheckButtonClick * proc
procedure
bool * been_used
has this cheat been used before?
VarMemType type
type of selector
GUI for the cheats.
void OnTimeout() override
Called when this window's timeout has been reached.
Dimension icon
Dimension of company icon sprite.
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
void OnInit() override
Notification that the nested widget tree gets initialized.
void UpdateWidgetSize(WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize) override
Update size and resize step of a widget in the window.
void OnQueryTextFinished(std::optional< std::string > str) override
The query window opened from this window has closed.
bool OnTooltip(Point pt, WidgetID widget, TooltipCloseCondition close_cond) override
Event to display a custom tooltip.
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
T y
Y coordinate.
T x
X coordinate.
uint16_t rate
The conversion rate compared to the base currency.
Dimensions (a width and height) of a rectangle in 2D.
value_type height
The height of the rectangle.
value_type width
The width of the rectangle.
Base integer type, including boolean, settings.
std::tuple< int32_t, uint32_t > GetRange() const
Get the min/max range for the setting.
Definition settings.cpp:502
StringID GetTitle() const
Get the title of the setting.
Definition settings.cpp:452
uint32_t max
maximum values
int32_t min
minimum values
int32_t GetDefaultValue() const
Get the default value of the setting.
Definition settings.cpp:493
StringID GetHelp() const
Get the help text of the setting.
Definition settings.cpp:461
virtual bool IsBoolSetting() const
Check whether this setting is a boolean type setting.
std::pair< StringParameter, StringParameter > GetValueParams(int32_t value) const
Get parameters for drawing the value of the setting.
Definition settings.cpp:471
int32_t Read(const void *object) const
Read the integer from the the actual setting.
Definition settings.cpp:593
int32_t interval
the interval to use between settings in the 'settings' window. If interval is '0' the interval is dyn...
static IterateWrapper Iterate()
Returns an iterable ensemble of all Tiles.
Definition map_func.h:366
static Pool::IterateWrapper< Vehicle > Iterate(size_t from=0)
constexpr uint Vertical() const
Get total vertical padding of RectPadding.
Specification of a rectangle with absolute coordinates of all edges.
Rect WithWidth(int width, bool end) const
Copy Rect and set its width.
int Width() const
Get width of Rect.
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
Rect WithHeight(int height, bool end=false) const
Copy Rect and set its height.
Rect Indent(int indent, bool end) const
Copy Rect and indent it from its position.
int Height() const
Get height of Rect.
Rect Translate(int x, int y) const
Copy and translate Rect by x,y pixels.
Properties of config file settings.
bool IsEditable(bool do_command=false) const
Check whether the setting is editable in the current gamemode.
Definition settings.cpp:908
SettingFlags flags
Handles how a setting would show up in the GUI (text/currency, etc.).
const struct IntSettingDesc * AsIntSetting() const
Get the setting description of this setting as an integer setting.
Definition settings.cpp:935
High level window description.
Definition window_gui.h:171
ResizeInfo resize
Resize information.
Definition window_gui.h:313
void SetTimeout()
Set the timeout flag of the window and initiate the timer.
Definition window_gui.h:354
Window(WindowDesc &desc)
Empty constructor, initialization has been moved to InitNested() called from the constructor of the d...
Definition window.cpp:1879
int GetRowFromWidget(int clickpos, WidgetID widget, int padding, int line_height=-1) const
Compute the row of a widget that a user clicked in.
Definition window.cpp:218
const NWID * GetWidget(WidgetID widnum) const
Get the nested widget with number widnum from the nested widget tree.
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
Definition window.cpp:1869
WindowFlags flags
Window flags.
Definition window_gui.h:299
int width
width of the window (number of pixels to the right in x direction)
Definition window_gui.h:310
Stuff related to the text buffer GUI.
@ AcceptUnchanged
return success even when the text didn't change
Definition textbuf_gui.h:19
@ EnableDefault
enable the 'Default' button ("\0" is returned)
Definition textbuf_gui.h:20
Map writing/reading functions for tiles.
static uint TileHeight(Tile tile)
Returns the height of a tile.
Definition tile_map.h:29
static constexpr uint MIN_MAP_HEIGHT_LIMIT
Lower bound of maximum allowed heightlevel (in the construction settings).
Definition tile_type.h:29
static constexpr uint MAX_MAP_HEIGHT_LIMIT
Upper bound of maximum allowed heightlevel (in the construction settings).
Definition tile_type.h:30
Definition of Interval and OneShot timers.
Definition of the game-calendar-timer.
Definition of the game-economy-timer.
Base class for all vehicles.
@ NWID_HORIZONTAL
Horizontal container.
Definition widget_type.h:66
@ WWT_PANEL
Simple depressed panel.
Definition widget_type.h:39
@ WWT_STICKYBOX
Sticky box (at top-right of a window, after WWT_DEFSIZEBOX).
Definition widget_type.h:57
@ WWT_SHADEBOX
Shade box (at top-right of a window, between WWT_DEBUGBOX and WWT_DEFSIZEBOX).
Definition widget_type.h:55
@ WWT_CAPTION
Window caption (window title between closebox and stickybox).
Definition widget_type.h:52
@ NWID_VERTICAL
Vertical container.
Definition widget_type.h:68
@ WWT_CLOSEBOX
Close box (at top-left of a window).
Definition widget_type.h:60
@ WWT_EMPTY
Empty widget, place holder to reserve space in widget tree.
Definition widget_type.h:37
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
void SetWindowDirty(WindowClass cls, WindowNumber number)
Mark window as dirty (in need of repainting).
Definition window.cpp:3255
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.
Functions, definitions and such used only by the GUI.
TooltipCloseCondition
Definition window_gui.h:262
@ Timeout
Window timeout counter.
Definition window_gui.h:223
@ Automatic
Find a place automatically.
Definition window_gui.h:145
int WidgetID
Widget ID.
Definition window_type.h:21