OpenTTD Source 20250524-master-gc366e6a48e
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 <http://www.gnu.org/licenses/>.
6 */
7
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.h"
16#include "saveload/saveload.h"
17#include "vehicle_base.h"
18#include "textbuf_gui.h"
19#include "window_gui.h"
20#include "string_func.h"
21#include "strings_func.h"
22#include "window_func.h"
23#include "rail_gui.h"
24#include "settings_gui.h"
25#include "company_gui.h"
27#include "map_func.h"
28#include "tile_map.h"
29#include "newgrf.h"
30#include "error.h"
31#include "misc_cmd.h"
33#include "settings_type.h"
34#include "settings_internal.h"
35#include "timer/timer.h"
39
41
42#include "table/sprites.h"
43#include "table/strings.h"
44
45#include "safeguards.h"
46
47
53static int32_t _money_cheat_amount = 10000000;
54
63static int32_t ClickMoneyCheat(int32_t, int32_t change_direction)
64{
67}
68
75static int32_t ClickChangeCompanyCheat(int32_t new_value, int32_t change_direction)
76{
77 while ((uint)new_value < Company::GetPoolSize()) {
78 if (Company::IsValidID((CompanyID)new_value)) {
79 SetLocalCompany((CompanyID)new_value);
80 return _local_company.base();
81 }
82 new_value += change_direction;
83 }
84
85 return _local_company.base();
86}
87
93static int32_t ClickSetProdCheat(int32_t new_value, int32_t)
94{
95 _cheats.setup_prod.value = (new_value != 0);
98}
99
100extern void CalendarEnginesMonthlyLoop();
101
107static int32_t ClickChangeDateCheat(int32_t new_value, int32_t)
108{
109 /* Don't allow changing to an invalid year, or the current year. */
111 if (new_year == TimerGameCalendar::year) return TimerGameCalendar::year.base();
112
113 TimerGameCalendar::YearMonthDay ymd = TimerGameCalendar::ConvertDateToYMD(TimerGameCalendar::date);
114 TimerGameCalendar::Date new_calendar_date = TimerGameCalendar::ConvertYMDToDate(new_year, ymd.month, ymd.day);
115
117
118 /* If not using wallclock units, we keep economy date in sync with calendar date and must change it also. */
120 /* Keep economy and calendar dates synced. */
121 TimerGameEconomy::Date new_economy_date{new_calendar_date.base()};
122
123 /* Shift cached dates before we change the date. */
124 for (auto v : Vehicle::Iterate()) v->ShiftDates(new_economy_date - TimerGameEconomy::date);
126
127 /* Now it's safe to actually change the date. */
129 }
130
139 return TimerGameCalendar::year.base();
140}
141
148static int32_t ClickChangeMaxHlCheat(int32_t new_value, int32_t)
149{
150 new_value = Clamp(new_value, MIN_MAP_HEIGHT_LIMIT, MAX_MAP_HEIGHT_LIMIT);
151
152 /* Check if at least one mountain on the map is higher than the new value.
153 * If yes, disallow the change. */
154 for (const auto t : Map::Iterate()) {
155 if ((int32_t)TileHeight(t) > new_value) {
156 ShowErrorMessage(GetEncodedString(STR_CONFIG_SETTING_TOO_HIGH_MOUNTAIN), {}, WL_ERROR);
157 /* Return old, unchanged value */
159 }
160 }
161
162 /* Execute the change and reload GRF Data */
165
166 /* The smallmap uses an index from heightlevels to colours. Trigger rebuilding it. */
168
170}
171
186
192typedef int32_t CheckButtonClick(int32_t new_value, int32_t change_direction);
193
202
207static const CheatEntry _cheats_ui[] = {
208 {SLE_INT32, STR_CHEAT_MONEY, &_money_cheat_amount, &_cheats.money.been_used, &ClickMoneyCheat },
209 {SLE_UINT8, STR_CHEAT_CHANGE_COMPANY, &_local_company, &_cheats.switch_company.been_used, &ClickChangeCompanyCheat },
210 {SLE_BOOL, STR_CHEAT_EXTRA_DYNAMITE, &_cheats.magic_bulldozer.value, &_cheats.magic_bulldozer.been_used, nullptr },
211 {SLE_BOOL, STR_CHEAT_CROSSINGTUNNELS, &_cheats.crossing_tunnels.value, &_cheats.crossing_tunnels.been_used, nullptr },
212 {SLE_BOOL, STR_CHEAT_NO_JETCRASH, &_cheats.no_jetcrash.value, &_cheats.no_jetcrash.been_used, nullptr },
213 {SLE_BOOL, STR_CHEAT_SETUP_PROD, &_cheats.setup_prod.value, &_cheats.setup_prod.been_used, &ClickSetProdCheat },
214 {SLE_BOOL, STR_CHEAT_STATION_RATING, &_cheats.station_rating.value, &_cheats.station_rating.been_used, nullptr },
216 {SLE_INT32, STR_CHEAT_CHANGE_DATE, &TimerGameCalendar::year, &_cheats.change_date.been_used, &ClickChangeDateCheat },
217};
218
219static_assert(CHT_NUM_CHEATS == lengthof(_cheats_ui));
220
222static constexpr NWidgetPart _nested_cheat_widgets[] = {
224 NWidget(WWT_CLOSEBOX, COLOUR_GREY),
225 NWidget(WWT_CAPTION, COLOUR_GREY), SetStringTip(STR_CHEATS, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
226 NWidget(WWT_SHADEBOX, COLOUR_GREY),
227 NWidget(WWT_STICKYBOX, COLOUR_GREY),
228 EndContainer(),
229 NWidget(WWT_PANEL, COLOUR_GREY),
231 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_C_PANEL),
232 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_C_SETTINGS),
233 EndContainer(),
234 EndContainer(),
235};
236
239 int clicked = 0;
240 int clicked_cheat = 0;
241 uint line_height = 0;
243
244 std::vector<const SettingDesc *> sandbox_settings{};
245 const SettingDesc *clicked_setting = nullptr;
246 const SettingDesc *last_clicked_setting = nullptr;
247 const SettingDesc *valuewindow_entry = nullptr;
248
249 CheatWindow(WindowDesc &desc) : Window(desc)
250 {
251 this->sandbox_settings = GetFilteredSettingCollection([](const SettingDesc &sd) { return sd.flags.Test(SettingFlag::Sandbox); });
252 this->InitNested();
253 }
254
255 void OnInit() override
256 {
257 this->icon = GetSpriteSize(SPR_COMPANY_ICON);
258 }
259
260 void DrawWidget(const Rect &r, WidgetID widget) const override
261 {
262 switch (widget) {
263 case WID_C_PANEL: DrawCheatWidget(r); break;
264 case WID_C_SETTINGS: DrawSettingsWidget(r); break;
265 }
266 }
267
268 void DrawCheatWidget(const Rect &r) const
269 {
270 const Rect ir = r;
271 int y = ir.top;
272
273 bool rtl = _current_text_dir == TD_RTL;
274 uint button_left = rtl ? ir.right - SETTING_BUTTON_WIDTH : ir.left;
275 uint text_left = ir.left + (rtl ? 0 : WidgetDimensions::scaled.hsep_wide + SETTING_BUTTON_WIDTH);
276 uint text_right = ir.right - (rtl ? WidgetDimensions::scaled.hsep_wide + SETTING_BUTTON_WIDTH : 0);
277
278 int text_y_offset = (this->line_height - GetCharacterHeight(FS_NORMAL)) / 2;
279 int button_y_offset = (this->line_height - SETTING_BUTTON_HEIGHT) / 2;
280 int icon_y_offset = (this->line_height - this->icon.height) / 2;
281
282 for (int i = 0; i != lengthof(_cheats_ui); i++) {
283 const CheatEntry *ce = &_cheats_ui[i];
284
285 std::string str;
286 switch (ce->type) {
287 case SLE_BOOL: {
288 bool on = (*(bool*)ce->variable);
289
290 DrawBoolButton(button_left, y + button_y_offset, COLOUR_YELLOW, COLOUR_GREY, on, true);
291 str = GetString(ce->str, on ? STR_CONFIG_SETTING_ON : STR_CONFIG_SETTING_OFF);
292 break;
293 }
294
295 default: {
296 int32_t val = static_cast<int32_t>(ReadValue(ce->variable, ce->type));
297
298 /* Draw [<][>] boxes for settings of an integer-type */
299 DrawArrowButtons(button_left, y + button_y_offset, COLOUR_YELLOW, clicked - (i * 2), true, true);
300
301 switch (ce->str) {
302 /* Display date for change date cheat */
303 case STR_CHEAT_CHANGE_DATE:
305 break;
306
307 /* Draw coloured flag for change company cheat */
308 case STR_CHEAT_CHANGE_COMPANY: {
309 str = GetString(ce->str, val + 1);
311 DrawCompanyIcon(_local_company, rtl ? text_right - offset - WidgetDimensions::scaled.hsep_indent : text_left + offset, y + icon_y_offset);
312 break;
313 }
314
315 default:
316 str = GetString(ce->str, val);
317 break;
318 }
319 break;
320 }
321 }
322
323 DrawString(text_left, text_right, y + text_y_offset, str);
324
325 y += this->line_height;
326 }
327 }
328
329 void DrawSettingsWidget(const Rect &r) const
330 {
331 Rect ir = r.WithHeight(this->line_height);
332
333 for (const auto &desc : this->sandbox_settings) {
334 DrawSetting(ir, desc);
335 ir = ir.Translate(0, this->line_height);
336 }
337 }
338
339 void DrawSetting(const Rect r, const SettingDesc *desc) const
340 {
341 const IntSettingDesc *sd = desc->AsIntSetting();
342 int state = this->clicked_setting == sd ? this->clicked : 0;
343
344 bool rtl = _current_text_dir == TD_RTL;
345
346 Rect buttons = r.WithWidth(SETTING_BUTTON_WIDTH, rtl);
347 Rect text = r.Indent(SETTING_BUTTON_WIDTH + WidgetDimensions::scaled.hsep_wide, rtl);
348 buttons.top += (r.Height() - SETTING_BUTTON_HEIGHT) / 2;
349 text.top += (r.Height() - GetCharacterHeight(FS_NORMAL)) / 2;
350
351 /* We do not allow changes of some items when we are a client in a network game */
352 bool editable = sd->IsEditable();
353
354 auto [min_val, max_val] = sd->GetRange();
355 int32_t value = sd->Read(&GetGameSettings());
356 if (sd->IsBoolSetting()) {
357 /* Draw checkbox for boolean-value either on/off */
358 DrawBoolButton(buttons.left, buttons.top, COLOUR_YELLOW, COLOUR_GREY, value != 0, editable);
359 } else if (sd->flags.Test(SettingFlag::GuiDropdown)) {
360 /* Draw [v] button for settings of an enum-type */
361 DrawDropDownButton(buttons.left, buttons.top, COLOUR_YELLOW, state != 0, editable);
362 } else {
363 /* Draw [<][>] boxes for settings of an integer-type */
364 DrawArrowButtons(buttons.left, buttons.top, COLOUR_YELLOW, state,
365 editable && value != (sd->flags.Test(SettingFlag::GuiZeroIsSpecial) ? 0 : min_val), editable && static_cast<uint32_t>(value) != max_val);
366 }
367 auto [param1, param2] = sd->GetValueParams(value);
368 DrawString(text.left, text.right, text.top, GetString(sd->GetTitle(), STR_CONFIG_SETTING_VALUE, param1, param2), TC_LIGHT_BLUE);
369 }
370
371 void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override
372 {
373 switch (widget) {
374 case WID_C_PANEL: UpdateCheatPanelSize(size); break;
375 case WID_C_SETTINGS: UpdateSettingsPanelSize(size); break;
376 }
377 }
378
379 void UpdateCheatPanelSize(Dimension &size)
380 {
381 uint width = 0;
382 for (const auto &ce : _cheats_ui) {
383 switch (ce.type) {
384 case SLE_BOOL:
385 width = std::max(width, GetStringBoundingBox(GetString(ce.str, STR_CONFIG_SETTING_ON)).width);
386 width = std::max(width, GetStringBoundingBox(GetString(ce.str, STR_CONFIG_SETTING_OFF)).width);
387 break;
388
389 default:
390 switch (ce.str) {
391 /* Display date for change date cheat */
392 case STR_CHEAT_CHANGE_DATE:
394 break;
395
396 /* Draw coloured flag for change company cheat */
397 case STR_CHEAT_CHANGE_COMPANY:
398 width = std::max(width, GetStringBoundingBox(GetString(ce.str, MAX_COMPANIES)).width + WidgetDimensions::scaled.hsep_wide);
399 break;
400
401 default:
402 width = std::max(width, GetStringBoundingBox(GetString(ce.str, INT64_MAX)).width);
403 break;
404 }
405 break;
406 }
407 }
408
409 this->line_height = std::max<uint>(this->icon.height, SETTING_BUTTON_HEIGHT);
410 this->line_height = std::max<uint>(this->line_height, GetCharacterHeight(FS_NORMAL)) + WidgetDimensions::scaled.framerect.Vertical();
411
413 size.height = this->line_height * lengthof(_cheats_ui);
414 }
415
416 void UpdateSettingsPanelSize(Dimension &size)
417 {
418 uint width = 0;
419 for (const auto &desc : this->sandbox_settings) {
420 const IntSettingDesc *sd = desc->AsIntSetting();
421
422 auto [param1, param2] = sd->GetValueParams(sd->GetDefaultValue());
423 width = std::max(width, GetStringBoundingBox(GetString(sd->GetTitle(), STR_CONFIG_SETTING_VALUE, param1, param2)).width);
424 }
425
427 size.height = this->line_height * static_cast<uint>(std::size(this->sandbox_settings));
428 }
429
430 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
431 {
432 switch (widget) {
433 case WID_C_PANEL: CheatPanelClick(pt); break;
434 case WID_C_SETTINGS: SettingsPanelClick(pt); break;
435 }
436 }
437
438 void CheatPanelClick(Point pt)
439 {
440 Rect r = this->GetWidget<NWidgetBase>(WID_C_PANEL)->GetCurrentRect().Shrink(WidgetDimensions::scaled.framerect);
441 uint btn = (pt.y - r.top) / this->line_height;
442 int x = pt.x - r.left;
443 bool rtl = _current_text_dir == TD_RTL;
444 if (rtl) x = r.Width() - 1 - x;
445
446 if (btn >= lengthof(_cheats_ui)) return;
447
448 const CheatEntry *ce = &_cheats_ui[btn];
449 int value = static_cast<int32_t>(ReadValue(ce->variable, ce->type));
450 int oldvalue = value;
451
452 if (btn == CHT_CHANGE_DATE && x >= SETTING_BUTTON_WIDTH) {
453 /* Click at the date text directly. */
454 clicked_cheat = CHT_CHANGE_DATE;
455 ShowQueryString(GetString(STR_JUST_INT, value), STR_CHEAT_CHANGE_DATE_QUERY_CAPT, 8, this, CS_NUMERAL, QueryStringFlag::AcceptUnchanged);
456 return;
457 } else if (btn == CHT_EDIT_MAX_HL && x >= SETTING_BUTTON_WIDTH) {
458 clicked_cheat = CHT_EDIT_MAX_HL;
459 ShowQueryString(GetString(STR_JUST_INT, value), STR_CHEAT_EDIT_MAX_HL_QUERY_CAPT, 8, this, CS_NUMERAL, QueryStringFlag::AcceptUnchanged);
460 return;
461 }
462
463 /* Not clicking a button? */
464 if (!IsInsideMM(x, 0, SETTING_BUTTON_WIDTH)) return;
465
466 this->clicked_setting = nullptr;
467 *ce->been_used = true;
468
469 switch (ce->type) {
470 case SLE_BOOL:
471 value ^= 1;
472 if (ce->proc != nullptr) ce->proc(value, 0);
473 break;
474
475 default:
476 /* Take whatever the function returns */
477 value = ce->proc(value + ((x >= SETTING_BUTTON_WIDTH / 2) ? 1 : -1), (x >= SETTING_BUTTON_WIDTH / 2) ? 1 : -1);
478
479 /* The first cheat (money), doesn't return a different value. */
480 if (value != oldvalue || btn == CHT_MONEY) this->clicked = btn * 2 + 1 + ((x >= SETTING_BUTTON_WIDTH / 2) != rtl ? 1 : 0);
481 break;
482 }
483
484 if (value != oldvalue) WriteValue(ce->variable, ce->type, static_cast<int64_t>(value));
485
486 this->SetTimeout();
487
488 this->SetDirty();
489 }
490
491 void SettingsPanelClick(Point pt)
492 {
493 int row = this->GetRowFromWidget(pt.y, WID_C_SETTINGS, WidgetDimensions::scaled.framerect.top, this->line_height);
494 if (row == INT_MAX) return;
495
496 const SettingDesc *desc = this->sandbox_settings[row];
497 const IntSettingDesc *sd = desc->AsIntSetting();
498
499 if (!sd->IsEditable()) return;
500
501 Rect r = this->GetWidget<NWidgetBase>(WID_C_SETTINGS)->GetCurrentRect().Shrink(WidgetDimensions::scaled.framerect);
502 int x = pt.x - r.left;
503 bool rtl = _current_text_dir == TD_RTL;
504 if (rtl) x = r.Width() - 1 - x;
505
506 if (x < SETTING_BUTTON_WIDTH) {
507 ChangeSettingValue(sd, x);
508 } else {
509 /* Only open editbox if clicked for the second time, and only for types where it is sensible for. */
510 if (this->last_clicked_setting == sd && !sd->IsBoolSetting() && !sd->flags.Test(SettingFlag::GuiDropdown)) {
511 int64_t value64 = sd->Read(&GetGameSettings());
512
513 /* Show the correct currency-translated value */
514 if (sd->flags.Test(SettingFlag::GuiCurrency)) value64 *= GetCurrency().rate;
515
516 CharSetFilter charset_filter = CS_NUMERAL; //default, only numeric input allowed
517 if (sd->min < 0) charset_filter = CS_NUMERAL_SIGNED; // special case, also allow '-' sign for negative input
518
519 this->valuewindow_entry = sd;
520
521 /* Limit string length to 14 so that MAX_INT32 * max currency rate doesn't exceed MAX_INT64. */
522 ShowQueryString(GetString(STR_JUST_INT, value64), STR_CONFIG_SETTING_QUERY_CAPTION, 15, this, charset_filter, QueryStringFlag::EnableDefault);
523 }
524
525 this->clicked_setting = sd;
526 }
527 }
528
529 void ChangeSettingValue(const IntSettingDesc *sd, int x)
530 {
531 int32_t value = sd->Read(&GetGameSettings());
532 int32_t oldvalue = value;
533 if (sd->IsBoolSetting()) {
534 value ^= 1;
535 } else {
536 /* don't allow too fast scrolling */
537 if (this->flags.Test(WindowFlag::Timeout) && this->timeout_timer > 1) {
538 _left_button_clicked = false;
539 return;
540 }
541
542 /* Add a dynamic step-size to the scroller. In a maximum of
543 * 50-steps you should be able to get from min to max,
544 * unless specified otherwise in the 'interval' variable
545 * of the current setting. */
546 uint32_t step = (sd->interval == 0) ? ((sd->max - sd->min) / 50) : sd->interval;
547 if (step == 0) step = 1;
548
549 /* Increase or decrease the value and clamp it to extremes */
550 if (x >= SETTING_BUTTON_WIDTH / 2) {
551 value += step;
552 if (sd->min < 0) {
553 assert(static_cast<int32_t>(sd->max) >= 0);
554 if (value > static_cast<int32_t>(sd->max)) value = static_cast<int32_t>(sd->max);
555 } else {
556 if (static_cast<uint32_t>(value) > sd->max) value = static_cast<int32_t>(sd->max);
557 }
558 if (value < sd->min) value = sd->min; // skip between "disabled" and minimum
559 } else {
560 value -= step;
561 if (value < sd->min) value = sd->flags.Test(SettingFlag::GuiZeroIsSpecial) ? 0 : sd->min;
562 }
563
564 /* Set up scroller timeout for numeric values */
565 if (value != oldvalue) {
566 this->last_clicked_setting = nullptr;
567 this->clicked_setting = sd;
568 this->clicked = (x >= SETTING_BUTTON_WIDTH / 2) != (_current_text_dir == TD_RTL) ? 2 : 1;
569 this->SetTimeout();
570 _left_button_clicked = false;
571 }
572 }
573
574 if (value != oldvalue) {
575 SetSettingValue(sd, value);
576 this->SetDirty();
577 }
578 }
579
580 bool OnTooltip([[maybe_unused]] Point pt, WidgetID widget, TooltipCloseCondition close_cond) override
581 {
582 if (widget != WID_C_SETTINGS) return false;
583
584 int row = GetRowFromWidget(pt.y, widget, WidgetDimensions::scaled.framerect.top, this->line_height);
585 if (row == INT_MAX) return false;
586
587 const SettingDesc *desc = this->sandbox_settings[row];
588 const IntSettingDesc *sd = desc->AsIntSetting();
589 GuiShowTooltips(this, GetEncodedString(sd->GetHelp()), close_cond);
590
591 return true;
592 }
593
594 void OnTimeout() override
595 {
596 this->clicked_setting = nullptr;
597 this->clicked = 0;
598 this->SetDirty();
599 }
600
601 void OnQueryTextFinished(std::optional<std::string> str) override
602 {
603 /* Was 'cancel' pressed or nothing entered? */
604 if (!str.has_value() || str->empty()) return;
605
606 if (this->valuewindow_entry != nullptr) {
607 const IntSettingDesc *sd = this->valuewindow_entry->AsIntSetting();
608
609 int32_t value;
610 if (!str->empty()) {
611 auto llvalue = ParseInteger<int64_t>(*str, 10, true);
612 if (!llvalue.has_value()) return;
613
614 /* Save the correct currency-translated value */
615 if (sd->flags.Test(SettingFlag::GuiCurrency)) llvalue = *llvalue / GetCurrency().rate;
616
617 value = ClampTo<int32_t>(*llvalue);
618 } else {
619 value = sd->GetDefaultValue();
620 }
621
622 SetSettingValue(sd, value);
623 } else {
624 const CheatEntry *ce = &_cheats_ui[clicked_cheat];
625 int oldvalue = static_cast<int32_t>(ReadValue(ce->variable, ce->type));
626 auto value = ParseInteger<int32_t>(*str, 10, true);
627 if (!value.has_value()) return;
628 *ce->been_used = true;
629 value = ce->proc(*value, *value - oldvalue);
630
631 if (*value != oldvalue) WriteValue(ce->variable, ce->type, static_cast<int64_t>(*value));
632 }
633
634 this->valuewindow_entry = nullptr;
635 this->SetDirty();
636 }
637
638 const IntervalTimer<TimerGameCalendar> daily_interval = {{TimerGameCalendar::MONTH, TimerGameCalendar::Priority::NONE}, [this](auto) {
639 this->SetDirty();
640 }};
641};
642
645 WDP_AUTO, "cheats", 0, 0,
647 {},
649);
650
Cheats _cheats
All the cheats.
Definition cheat.cpp:16
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:53
static int32_t ClickChangeMaxHlCheat(int32_t new_value, int32_t)
Allow (or disallow) a change of the maximum allowed heightlevel.
void CalendarEnginesMonthlyLoop()
Monthly update of the availability, reliability, and preview offers of the engines.
Definition engine.cpp:1139
static int32_t ClickMoneyCheat(int32_t, int32_t change_direction)
Handle cheating of money.
Definition cheat_gui.cpp:63
static int32_t ClickSetProdCheat(int32_t new_value, int32_t)
Allow (or disallow) changing production of all industries.
Definition cheat_gui.cpp:93
static int32_t ClickChangeDateCheat(int32_t new_value, int32_t)
Handle changing of the current year.
static constexpr NWidgetPart _nested_cheat_widgets[]
Widget definitions of the cheat GUI.
static int32_t ClickChangeCompanyCheat(int32_t new_value, int32_t change_direction)
Handle changing of company.
Definition cheat_gui.cpp:75
static WindowDesc _cheats_desc(WDP_AUTO, "cheats", 0, 0, WC_CHEATS, WC_NONE, {}, _nested_cheat_widgets)
Window description of the cheats GUI.
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.
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.
void ShiftDates(TimerGameEconomy::Date interval)
Shift all dates (join dates and edge annotations) of link graphs and link graph jobs by the number of...
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
The absolute minimum year in OTTD.
static constexpr TimerGame< struct Calendar >::Year MAX_YEAR
MAX_YEAR, nicely rounded value of the number of years that can be encoded in a single 32 bits date,...
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.
RectPadding framerect
Standard padding inside many panels.
Definition window_gui.h:40
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:62
static const WidgetDimensions unscaled
Unscaled widget dimensions.
Definition window_gui.h:93
int hsep_indent
Width of indentation for tree layouts.
Definition window_gui.h:63
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.
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
void SetLocalCompany(CompanyID new_company)
Sets the local company and updates the settings that are set on a per-company basis to reflect the co...
Functions related to companies.
GUI Functions related to companies.
Functions to handle different currencies.
const CurrencySpec & GetCurrency()
Get the currently selected currency.
Definition currency.h:118
Functions related to errors.
@ WL_ERROR
Errors (eg. saving/loading failed)
Definition error.h:26
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:77
Geometry functions.
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
Definition gfx.cpp:958
Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition gfx.cpp:887
int DrawString(int left, int right, int top, std::string_view str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
Definition gfx.cpp:658
bool _left_button_clicked
Is left mouse button clicked?
Definition gfx.cpp:42
@ FS_NORMAL
Index of the normal font in the font tables.
Definition gfx_type.h:251
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 NWidget(WidgetType tp, Colours col, WidgetID idx=-1)
Widget part function for starting a new 'real' widget.
constexpr NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Definition window.cpp:955
Declaration of link graph schedule used for cargo distribution.
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
Miscellaneous command definitions.
void GuiShowTooltips(Window *parent, EncodedString &&text, TooltipCloseCondition close_tooltip)
Shows a tooltip.
Definition misc_gui.cpp:688
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, VarType conv, int64_t val)
Write the value of a setting.
Definition saveload.cpp:824
int64_t ReadValue(const void *ptr, VarType conv)
Return a signed-long version of the value of a setting.
Definition saveload.cpp:800
Functions/types related to saving and loading games.
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:60
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.
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:271
Parse strings.
Functions related to low-level strings.
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:91
std::string GetString(StringID string)
Resolve the given StringID into a std::string with formatting but no parameters.
Definition strings.cpp:415
TextDirection _current_text_dir
Text direction of the currently selected language.
Definition strings.cpp:57
Functions related to OTTD's strings.
uint32_t 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.
VarType type
type of selector
void * variable
pointer to the variable
StringID str
string with descriptive text
CheckButtonClick * proc
procedure
bool * been_used
has this cheat been used before?
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.
bool value
tells if the bool cheat is active or not
Definition cheat_type.h:18
bool been_used
has this cheat been used before?
Definition cheat_type.h:17
Cheat crossing_tunnels
allow tunnels that cross each other
Definition cheat_type.h:30
Cheat no_jetcrash
no jet will crash on small airports anymore
Definition cheat_type.h:31
Cheat change_date
changes date ingame
Definition cheat_type.h:32
Cheat station_rating
Fix station ratings at 100%.
Definition cheat_type.h:35
Cheat money
get rich or poor
Definition cheat_type.h:29
Cheat setup_prod
setup raw-material production in game
Definition cheat_type.h:33
Cheat switch_company
change to another company
Definition cheat_type.h:28
Cheat magic_bulldozer
dynamite industries, objects
Definition cheat_type.h:27
Cheat edit_max_hl
edit the maximum heightlevel; this is a cheat because of the fact that it needs to reset NewGRF game ...
Definition cheat_type.h:34
uint8_t map_height_limit
the maximum allowed heightlevel
uint16_t rate
The conversion rate compared to the base currency.
Definition currency.h:77
Dimensions (a width and height) of a rectangle in 2D.
ConstructionSettings construction
construction of things in-game
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:475
StringID GetTitle() const
Get the title of the setting.
Definition settings.cpp:426
uint32_t max
maximum values
int32_t min
minimum values
int32_t GetDefaultValue() const
Get the default value of the setting.
Definition settings.cpp:466
StringID GetHelp() const
Get the help text of the setting.
Definition settings.cpp:435
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:444
int32_t Read(const void *object) const
Read the integer from the the actual setting.
Definition settings.cpp:566
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:362
Partial widget specification to allow NWidgets to be written nested.
Coordinates of a point in 2D.
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
static size_t GetPoolSize()
Returns first unused index.
static bool IsValidID(auto index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
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:893
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:920
Templated helper to make a type-safe 'typedef' representing a single POD value.
High level window description.
Definition window_gui.h:167
Data structure for an opened window.
Definition window_gui.h:273
ResizeInfo resize
Resize information.
Definition window_gui.h:314
void SetTimeout()
Set the timeout flag of the window and initiate the timer.
Definition window_gui.h:355
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:211
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
Definition window.cpp:1791
WindowFlags flags
Window flags.
Definition window_gui.h:300
int width
width of the window (number of pixels to the right in x direction)
Definition window_gui.h:311
Stuff related to the text buffer GUI.
@ AcceptUnchanged
return success even when the text didn't change
@ EnableDefault
enable the 'Default' button ("\0" is returned)
Map writing/reading functions for tiles.
static debug_inline uint TileHeight(Tile tile)
Returns the height of a tile.
Definition tile_map.h:29
static const uint MIN_MAP_HEIGHT_LIMIT
Lower bound of maximum allowed heightlevel (in the construction settings)
Definition tile_type.h:29
static const 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:67
@ WWT_PANEL
Simple depressed panel.
Definition widget_type.h:40
@ WWT_STICKYBOX
Sticky box (at top-right of a window, after WWT_DEFSIZEBOX)
Definition widget_type.h:58
@ WWT_SHADEBOX
Shade box (at top-right of a window, between WWT_DEBUGBOX and WWT_DEFSIZEBOX)
Definition widget_type.h:56
@ WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition widget_type.h:53
@ NWID_VERTICAL
Vertical container.
Definition widget_type.h:69
@ WWT_CLOSEBOX
Close box (at top-left of a window)
Definition widget_type.h:61
@ WWT_EMPTY
Empty widget, place holder to reserve space in widget tree.
Definition widget_type.h:38
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:1182
void SetWindowDirty(WindowClass cls, WindowNumber number)
Mark window as dirty (in need of repainting)
Definition window.cpp:3147
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:3282
Window functions not directly related to making/drawing windows.
Functions, definitions and such used only by the GUI.
@ Timeout
Window timeout counter.
@ WDP_AUTO
Find a place automatically.
Definition window_gui.h:144
int WidgetID
Widget ID.
Definition window_type.h:20
@ WC_BUILD_STATION
Build station; Window numbers:
@ WC_BUILD_OBJECT
Build object; Window numbers:
@ WC_STATUS_BAR
Statusbar (at the bottom of your screen); Window numbers:
Definition window_type.h:66
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Definition window_type.h:47
@ WC_CHEATS
Cheat window; Window numbers:
@ WC_TRUCK_STATION
Build truck station; Window numbers:
@ WC_INDUSTRY_VIEW
Industry view; Window numbers:
@ WC_FINANCES
Finances of a company; Window numbers:
@ WC_BUS_STATION
Build bus station; Window numbers:
@ WC_SMALLMAP
Small map; Window numbers: