OpenTTD Source  20240919-master-gdf0233f4c2
cheat_gui.cpp File Reference
#include "stdafx.h"
#include "command_func.h"
#include "cheat_type.h"
#include "company_base.h"
#include "company_func.h"
#include "saveload/saveload.h"
#include "vehicle_base.h"
#include "textbuf_gui.h"
#include "window_gui.h"
#include "string_func.h"
#include "strings_func.h"
#include "window_func.h"
#include "rail_gui.h"
#include "settings_gui.h"
#include "company_gui.h"
#include "linkgraph/linkgraphschedule.h"
#include "map_func.h"
#include "tile_map.h"
#include "newgrf.h"
#include "error.h"
#include "misc_cmd.h"
#include "core/geometry_func.hpp"
#include "timer/timer.h"
#include "timer/timer_game_calendar.h"
#include "timer/timer_game_economy.h"
#include "widgets/cheat_widget.h"
#include "table/sprites.h"
#include "safeguards.h"

Go to the source code of this file.

Data Structures

struct  CheatEntry
 Information of a cheat. More...
 
struct  CheatWindow
 GUI for the cheats. More...
 

Typedefs

typedef int32_t CheckButtonClick(int32_t new_value, int32_t change_direction)
 Signature of handler function when user clicks at a cheat. More...
 

Enumerations

enum  CheatNumbers {
  CHT_MONEY, CHT_CHANGE_COMPANY, CHT_EXTRA_DYNAMITE, CHT_CROSSINGTUNNELS,
  CHT_NO_JETCRASH, CHT_SETUP_PROD, CHT_STATION_RATING, CHT_EDIT_MAX_HL,
  CHT_CHANGE_DATE, CHT_NUM_CHEATS
}
 Available cheats. More...
 

Functions

static int32_t ClickMoneyCheat (int32_t, int32_t change_direction)
 Handle cheating of money. More...
 
static int32_t ClickChangeCompanyCheat (int32_t new_value, int32_t change_direction)
 Handle changing of company. More...
 
static int32_t ClickSetProdCheat (int32_t new_value, int32_t)
 Allow (or disallow) changing production of all industries. More...
 
void CalendarEnginesMonthlyLoop ()
 Monthly update of the availability, reliability, and preview offers of the engines.
 
static int32_t ClickChangeDateCheat (int32_t new_value, int32_t)
 Handle changing of the current year. More...
 
static int32_t ClickChangeMaxHlCheat (int32_t new_value, int32_t)
 Allow (or disallow) a change of the maximum allowed heightlevel. More...
 
void ShowCheatWindow ()
 Open cheat window.
 

Variables

static int32_t _money_cheat_amount = 10000000
 The 'amount' to cheat with. More...
 
static const CheatEntry _cheats_ui []
 The available cheats. More...
 
static constexpr NWidgetPart _nested_cheat_widgets []
 Widget definitions of the cheat GUI. More...
 
static WindowDesc _cheats_desc (WDP_AUTO, "cheats", 0, 0, WC_CHEATS, WC_NONE, 0, _nested_cheat_widgets)
 Window description of the cheats GUI.
 

Detailed Description

GUI related to cheating.

Definition in file cheat_gui.cpp.

Typedef Documentation

◆ CheckButtonClick

typedef int32_t CheckButtonClick(int32_t new_value, int32_t change_direction)

Signature of handler function when user clicks at a cheat.

Parameters
new_valueThe new value.
change_directionChange direction (+1, +1), 0 for boolean settings.

Definition at line 186 of file cheat_gui.cpp.

Enumeration Type Documentation

◆ CheatNumbers

Available cheats.

Enumerator
CHT_MONEY 

Change amount of money.

CHT_CHANGE_COMPANY 

Switch company.

CHT_EXTRA_DYNAMITE 

Dynamite anything.

CHT_CROSSINGTUNNELS 

Allow tunnels to cross each other.

CHT_NO_JETCRASH 

Disable jet-airplane crashes.

CHT_SETUP_PROD 

Allow manually editing of industry production.

CHT_STATION_RATING 

Fix station ratings at 100%.

CHT_EDIT_MAX_HL 

Edit maximum allowed heightlevel.

CHT_CHANGE_DATE 

Do time traveling.

CHT_NUM_CHEATS 

Number of cheats.

Definition at line 167 of file cheat_gui.cpp.

Function Documentation

◆ ClickChangeCompanyCheat()

static int32_t ClickChangeCompanyCheat ( int32_t  new_value,
int32_t  change_direction 
)
static

◆ ClickChangeDateCheat()

◆ ClickChangeMaxHlCheat()

static int32_t ClickChangeMaxHlCheat ( int32_t  new_value,
int32_t   
)
static

Allow (or disallow) a change of the maximum allowed heightlevel.

Parameters
new_valuenew value
Returns
New value (or unchanged old value) of the maximum allowed heightlevel value.

Definition at line 142 of file cheat_gui.cpp.

References _settings_game, Clamp(), GameSettings::construction, INVALID_STRING_ID, InvalidateWindowClassesData(), ConstructionSettings::map_height_limit, MAX_MAP_HEIGHT_LIMIT, MIN_MAP_HEIGHT_LIMIT, ReloadNewGRFData(), ShowErrorMessage(), Map::Size(), TileHeight(), WC_SMALLMAP, and WL_ERROR.

◆ ClickMoneyCheat()

static int32_t ClickMoneyCheat ( int32_t  ,
int32_t  change_direction 
)
static

Handle cheating of money.

Note that the amount of money of a company must be changed through a command rather than by setting a variable. Since the cheat data structure expects a variable, the amount of given/taken money is used for this purpose.

Parameters
change_directionis -1 or +1 (down/up)
Returns
Amount of money cheat.

Definition at line 58 of file cheat_gui.cpp.

◆ ClickSetProdCheat()

static int32_t ClickSetProdCheat ( int32_t  new_value,
int32_t   
)
static

Allow (or disallow) changing production of all industries.

Parameters
new_valuenew value
Returns
New value allowing change of industry production.

Definition at line 88 of file cheat_gui.cpp.

References _cheats, InvalidateWindowClassesData(), Cheats::setup_prod, Cheat::value, and WC_INDUSTRY_VIEW.

Variable Documentation

◆ _cheats_ui

const CheatEntry _cheats_ui[]
static
Initial value:
= {
{SLE_INT32, STR_CHEAT_MONEY, &_money_cheat_amount, &_cheats.money.been_used, &ClickMoneyCheat },
{SLE_UINT8, STR_CHEAT_CHANGE_COMPANY, &_local_company, &_cheats.switch_company.been_used, &ClickChangeCompanyCheat },
{SLE_BOOL, STR_CHEAT_EXTRA_DYNAMITE, &_cheats.magic_bulldozer.value, &_cheats.magic_bulldozer.been_used, nullptr },
{SLE_BOOL, STR_CHEAT_CROSSINGTUNNELS, &_cheats.crossing_tunnels.value, &_cheats.crossing_tunnels.been_used, nullptr },
{SLE_BOOL, STR_CHEAT_NO_JETCRASH, &_cheats.no_jetcrash.value, &_cheats.no_jetcrash.been_used, nullptr },
{SLE_BOOL, STR_CHEAT_SETUP_PROD, &_cheats.setup_prod.value, &_cheats.setup_prod.been_used, &ClickSetProdCheat },
{SLE_BOOL, STR_CHEAT_STATION_RATING, &_cheats.station_rating.value, &_cheats.station_rating.been_used, nullptr },
{SLE_INT32, STR_CHEAT_CHANGE_DATE, &TimerGameCalendar::year, &_cheats.change_date.been_used, &ClickChangeDateCheat },
}

The available cheats.

Order matches with the values of CheatNumbers

Definition at line 201 of file cheat_gui.cpp.

◆ _money_cheat_amount

int32_t _money_cheat_amount = 10000000
static

The 'amount' to cheat with.

This variable is semantically a constant value, but because the cheat code requires to be able to write to the variable it is not constified.

Definition at line 48 of file cheat_gui.cpp.

◆ _nested_cheat_widgets

constexpr NWidgetPart _nested_cheat_widgets[]
staticconstexpr
Initial value:
= {
NWidget(WWT_CLOSEBOX, COLOUR_GREY),
NWidget(WWT_CAPTION, COLOUR_GREY), SetDataTip(STR_CHEATS, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
NWidget(WWT_SHADEBOX, COLOUR_GREY),
NWidget(WWT_STICKYBOX, COLOUR_GREY),
}

Widget definitions of the cheat GUI.

Definition at line 216 of file cheat_gui.cpp.

Cheats::no_jetcrash
Cheat no_jetcrash
no jet will crash on small airports anymore
Definition: cheat_type.h:31
Cheats::crossing_tunnels
Cheat crossing_tunnels
allow tunnels that cross each other
Definition: cheat_type.h:30
Cheats::magic_bulldozer
Cheat magic_bulldozer
dynamite industries, objects
Definition: cheat_type.h:27
WWT_STICKYBOX
@ WWT_STICKYBOX
Sticky box (at top-right of a window, after WWT_DEFSIZEBOX)
Definition: widget_type.h:68
Cheats::edit_max_hl
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
WWT_CAPTION
@ WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition: widget_type.h:63
NWID_HORIZONTAL
@ NWID_HORIZONTAL
Horizontal container.
Definition: widget_type.h:77
EndContainer
constexpr NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
Definition: widget_type.h:1193
Cheats::setup_prod
Cheat setup_prod
setup raw-material production in game
Definition: cheat_type.h:33
ClickChangeDateCheat
static int32_t ClickChangeDateCheat(int32_t new_value, int32_t)
Handle changing of the current year.
Definition: cheat_gui.cpp:102
ClickSetProdCheat
static int32_t ClickSetProdCheat(int32_t new_value, int32_t)
Allow (or disallow) changing production of all industries.
Definition: cheat_gui.cpp:88
ClickChangeMaxHlCheat
static int32_t ClickChangeMaxHlCheat(int32_t new_value, int32_t)
Allow (or disallow) a change of the maximum allowed heightlevel.
Definition: cheat_gui.cpp:142
Cheats::money
Cheat money
get rich or poor
Definition: cheat_type.h:29
WID_C_PANEL
@ WID_C_PANEL
Panel where all cheats are shown in.
Definition: cheat_widget.h:16
ConstructionSettings::map_height_limit
uint8_t map_height_limit
the maximum allowed heightlevel
Definition: settings_type.h:382
_cheats
Cheats _cheats
All the cheats.
Definition: cheat.cpp:16
_settings_game
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition: settings.cpp:57
NWidget
constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx=-1)
Widget part function for starting a new 'real' widget.
Definition: widget_type.h:1311
_local_company
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Definition: company_cmd.cpp:52
Cheat::value
bool value
tells if the bool cheat is active or not
Definition: cheat_type.h:18
WWT_CLOSEBOX
@ WWT_CLOSEBOX
Close box (at top-left of a window)
Definition: widget_type.h:71
_money_cheat_amount
static int32_t _money_cheat_amount
The 'amount' to cheat with.
Definition: cheat_gui.cpp:48
WWT_PANEL
@ WWT_PANEL
Simple depressed panel.
Definition: widget_type.h:52
Cheats::change_date
Cheat change_date
changes date ingame
Definition: cheat_type.h:32
GameSettings::construction
ConstructionSettings construction
construction of things in-game
Definition: settings_type.h:595
Cheats::station_rating
Cheat station_rating
Fix station ratings at 100%.
Definition: cheat_type.h:35
Cheat::been_used
bool been_used
has this cheat been used before?
Definition: cheat_type.h:17
SetDataTip
constexpr NWidgetPart SetDataTip(uint32_t data, StringID tip)
Widget part function for setting the data and tooltip.
Definition: widget_type.h:1204
ClickMoneyCheat
static int32_t ClickMoneyCheat(int32_t, int32_t change_direction)
Handle cheating of money.
Definition: cheat_gui.cpp:58
Cheats::switch_company
Cheat switch_company
change to another company
Definition: cheat_type.h:28
TimerGameCalendar::year
static Year year
Current year, starting at 0.
Definition: timer_game_calendar.h:32
ClickChangeCompanyCheat
static int32_t ClickChangeCompanyCheat(int32_t new_value, int32_t change_direction)
Handle changing of company.
Definition: cheat_gui.cpp:70
WWT_SHADEBOX
@ WWT_SHADEBOX
Shade box (at top-right of a window, between WWT_DEBUGBOX and WWT_DEFSIZEBOX)
Definition: widget_type.h:66