OpenTTD Source: src/cheat_gui.cpp Source File

OpenTTD Source 15.0-beta1

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 "saveload/saveload.h"
16#include "vehicle_base.h"
17#include "textbuf_gui.h"
18#include "window_gui.h"
19#include "string_func.h"
20#include "strings_func.h"
21#include "window_func.h"
22#include "rail_gui.h"
23#include "settings_gui.h"
24#include "company_gui.h"
25#include "linkgraph/linkgraphschedule.h"
26#include "map_func.h"
27#include "tile_map.h"
28#include "newgrf.h"
29#include "error.h"
30#include "misc_cmd.h"
31#include "core/geometry_func.hpp"
32#include "timer/timer.h"
33#include "timer/timer_game_calendar.h"
34#include "timer/timer_game_economy.h"
35
36#include "widgets/cheat_widget.h"
37
38#include "table/sprites.h"
39
40#include "safeguards.h"
41
42
48 static int32_t _money_cheat_amount = 10000000;
49
58 static int32_t ClickMoneyCheat(int32_t, int32_t change_direction)
59{
60 Command<CMD_MONEY_CHEAT>::Post(Money(_money_cheat_amount) * change_direction);
61 return _money_cheat_amount;
62}
63
70 static int32_t ClickChangeCompanyCheat(int32_t new_value, int32_t change_direction)
71{
72 while ((uint)new_value < Company::GetPoolSize()) {
73 if (Company::IsValidID((CompanyID)new_value)) {
74 SetLocalCompany((CompanyID)new_value);
75 return _local_company;
76 }
77 new_value += change_direction;
78 }
79
80 return _local_company;
81}
82
88 static int32_t ClickSetProdCheat(int32_t new_value, int32_t)
89{
90 _cheats.setup_prod.value = (new_value != 0);
91 InvalidateWindowClassesData(WC_INDUSTRY_VIEW);
92 return _cheats.setup_prod.value;
93}
94
95extern void CalendarEnginesMonthlyLoop();
96
102 static int32_t ClickChangeDateCheat(int32_t new_value, int32_t)
103{
104 /* Don't allow changing to an invalid year, or the current year. */
105 auto new_year = Clamp(TimerGameCalendar::Year(new_value), CalendarTime::MIN_YEAR, CalendarTime::MAX_YEAR);
106 if (new_year == TimerGameCalendar::year) return TimerGameCalendar::year.base();
107
108 TimerGameCalendar::YearMonthDay ymd = TimerGameCalendar::ConvertDateToYMD(TimerGameCalendar::date);
109 TimerGameCalendar::Date new_calendar_date = TimerGameCalendar::ConvertYMDToDate(new_year, ymd.month, ymd.day);
110
111 TimerGameCalendar::SetDate(new_calendar_date, TimerGameCalendar::date_fract);
112
113 /* If not using wallclock units, we keep economy date in sync with calendar date and must change it also. */
114 if (!TimerGameEconomy::UsingWallclockUnits()) {
115 /* Keep economy and calendar dates synced. */
116 TimerGameEconomy::Date new_economy_date = new_calendar_date.base();
117
118 /* Shift cached dates before we change the date. */
119 for (auto v : Vehicle::Iterate()) v->ShiftDates(new_economy_date - TimerGameEconomy::date);
120 LinkGraphSchedule::instance.ShiftDates(new_economy_date - TimerGameEconomy::date);
121
122 /* Now it's safe to actually change the date. */
123 TimerGameEconomy::SetDate(new_economy_date, TimerGameEconomy::date_fract);
124 }
125
126 CalendarEnginesMonthlyLoop();
127 SetWindowDirty(WC_STATUS_BAR, 0);
128 InvalidateWindowClassesData(WC_BUILD_STATION, 0);
129 InvalidateWindowClassesData(WC_BUS_STATION, 0);
130 InvalidateWindowClassesData(WC_TRUCK_STATION, 0);
131 InvalidateWindowClassesData(WC_BUILD_OBJECT, 0);
132 InvalidateWindowClassesData(WC_FINANCES, 0);
133 ResetSignalVariant();
134 return TimerGameCalendar::year.base();
135}
136
143 static int32_t ClickChangeMaxHlCheat(int32_t new_value, int32_t)
144{
145 new_value = Clamp(new_value, MIN_MAP_HEIGHT_LIMIT, MAX_MAP_HEIGHT_LIMIT);
146
147 /* Check if at least one mountain on the map is higher than the new value.
148 * If yes, disallow the change. */
149 for (const auto t : Map::Iterate()) {
150 if ((int32_t)TileHeight(t) > new_value) {
151 ShowErrorMessage(STR_CONFIG_SETTING_TOO_HIGH_MOUNTAIN, INVALID_STRING_ID, WL_ERROR);
152 /* Return old, unchanged value */
153 return _settings_game.construction.map_height_limit;
154 }
155 }
156
157 /* Execute the change and reload GRF Data */
158 _settings_game.construction.map_height_limit = new_value;
159 ReloadNewGRFData();
160
161 /* The smallmap uses an index from heightlevels to colours. Trigger rebuilding it. */
162 InvalidateWindowClassesData(WC_SMALLMAP, 2);
163
164 return _settings_game.construction.map_height_limit;
165}
166
168 enum CheatNumbers {
169 CHT_MONEY,
170 CHT_CHANGE_COMPANY,
171 CHT_EXTRA_DYNAMITE,
172 CHT_CROSSINGTUNNELS,
173 CHT_NO_JETCRASH,
174 CHT_SETUP_PROD,
175 CHT_STATION_RATING,
176 CHT_EDIT_MAX_HL,
177 CHT_CHANGE_DATE,
178
179 CHT_NUM_CHEATS,
180};
181
187 typedef int32_t CheckButtonClick(int32_t new_value, int32_t change_direction);
188
190 struct CheatEntry {
191 VarType type;
192 StringID str;
193 void *variable;
194 bool *been_used;
195 CheckButtonClick *proc;
196};
197
202 static const CheatEntry _cheats_ui[] = {
203 {SLE_INT32, STR_CHEAT_MONEY, &_money_cheat_amount, &_cheats.money.been_used, &ClickMoneyCheat },
204 {SLE_UINT8, STR_CHEAT_CHANGE_COMPANY, &_local_company, &_cheats.switch_company.been_used, &ClickChangeCompanyCheat },
205 {SLE_BOOL, STR_CHEAT_EXTRA_DYNAMITE, &_cheats.magic_bulldozer.value, &_cheats.magic_bulldozer.been_used, nullptr },
206 {SLE_BOOL, STR_CHEAT_CROSSINGTUNNELS, &_cheats.crossing_tunnels.value, &_cheats.crossing_tunnels.been_used, nullptr },
207 {SLE_BOOL, STR_CHEAT_NO_JETCRASH, &_cheats.no_jetcrash.value, &_cheats.no_jetcrash.been_used, nullptr },
208 {SLE_BOOL, STR_CHEAT_SETUP_PROD, &_cheats.setup_prod.value, &_cheats.setup_prod.been_used, &ClickSetProdCheat },
209 {SLE_BOOL, STR_CHEAT_STATION_RATING, &_cheats.station_rating.value, &_cheats.station_rating.been_used, nullptr },
210 {SLE_UINT8, STR_CHEAT_EDIT_MAX_HL, &_settings_game.construction.map_height_limit, &_cheats.edit_max_hl.been_used, &ClickChangeMaxHlCheat },
211 {SLE_INT32, STR_CHEAT_CHANGE_DATE, &TimerGameCalendar::year, &_cheats.change_date.been_used, &ClickChangeDateCheat },
212};
213
214static_assert(CHT_NUM_CHEATS == lengthof(_cheats_ui));
215
217 static constexpr NWidgetPart _nested_cheat_widgets[] = {
218 NWidget(NWID_HORIZONTAL),
219 NWidget(WWT_CLOSEBOX, COLOUR_GREY),
220 NWidget(WWT_CAPTION, COLOUR_GREY), SetDataTip(STR_CHEATS, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
221 NWidget(WWT_SHADEBOX, COLOUR_GREY),
222 NWidget(WWT_STICKYBOX, COLOUR_GREY),
223 EndContainer(),
224 NWidget(WWT_PANEL, COLOUR_GREY, WID_C_PANEL), EndContainer(),
225};
226
228 struct CheatWindow : Window {
229 int clicked;
230 int clicked_widget;
231 uint line_height;
232 Dimension icon;
233
234 CheatWindow(WindowDesc &desc) : Window(desc)
235 {
236 this->InitNested();
237 }
238
239 void OnInit() override
240 {
241 this->icon = GetSpriteSize(SPR_COMPANY_ICON);
242 }
243
244 void DrawWidget(const Rect &r, WidgetID widget) const override
245 {
246 if (widget != WID_C_PANEL) return;
247
248 const Rect ir = r.Shrink(WidgetDimensions::scaled.framerect);
249 int y = ir.top;
250
251 bool rtl = _current_text_dir == TD_RTL;
252 uint button_left = rtl ? ir.right - SETTING_BUTTON_WIDTH : ir.left;
253 uint text_left = ir.left + (rtl ? 0 : WidgetDimensions::scaled.hsep_wide + SETTING_BUTTON_WIDTH);
254 uint text_right = ir.right - (rtl ? WidgetDimensions::scaled.hsep_wide + SETTING_BUTTON_WIDTH : 0);
255
256 int text_y_offset = (this->line_height - GetCharacterHeight(FS_NORMAL)) / 2;
257 int button_y_offset = (this->line_height - SETTING_BUTTON_HEIGHT) / 2;
258 int icon_y_offset = (this->line_height - this->icon.height) / 2;
259
260 for (int i = 0; i != lengthof(_cheats_ui); i++) {
261 const CheatEntry *ce = &_cheats_ui[i];
262
263 switch (ce->type) {
264 case SLE_BOOL: {
265 bool on = (*(bool*)ce->variable);
266
267 DrawBoolButton(button_left, y + button_y_offset, on, true);
268 SetDParam(0, on ? STR_CONFIG_SETTING_ON : STR_CONFIG_SETTING_OFF);
269 break;
270 }
271
272 default: {
273 int32_t val = (int32_t)ReadValue(ce->variable, ce->type);
274
275 /* Draw [<][>] boxes for settings of an integer-type */
276 DrawArrowButtons(button_left, y + button_y_offset, COLOUR_YELLOW, clicked - (i * 2), true, true);
277
278 switch (ce->str) {
279 /* Display date for change date cheat */
280 case STR_CHEAT_CHANGE_DATE: SetDParam(0, TimerGameCalendar::date); break;
281
282 /* Draw coloured flag for change company cheat */
283 case STR_CHEAT_CHANGE_COMPANY: {
284 SetDParam(0, val + 1);
285 uint offset = WidgetDimensions::scaled.hsep_indent + GetStringBoundingBox(ce->str).width;
286 DrawCompanyIcon(_local_company, rtl ? text_right - offset - WidgetDimensions::scaled.hsep_indent : text_left + offset, y + icon_y_offset);
287 break;
288 }
289
290 default: SetDParam(0, val);
291 }
292 break;
293 }
294 }
295
296 DrawString(text_left, text_right, y + text_y_offset, ce->str);
297
298 y += this->line_height;
299 }
300 }
301
302 void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override
303 {
304 if (widget != WID_C_PANEL) return;
305
306 uint width = 0;
307 for (const auto &ce : _cheats_ui) {
308 switch (ce.type) {
309 case SLE_BOOL:
310 SetDParam(0, STR_CONFIG_SETTING_ON);
311 width = std::max(width, GetStringBoundingBox(ce.str).width);
312 SetDParam(0, STR_CONFIG_SETTING_OFF);
313 width = std::max(width, GetStringBoundingBox(ce.str).width);
314 break;
315
316 default:
317 switch (ce.str) {
318 /* Display date for change date cheat */
319 case STR_CHEAT_CHANGE_DATE:
320 SetDParam(0, TimerGameCalendar::ConvertYMDToDate(CalendarTime::MAX_YEAR, 11, 31));
321 width = std::max(width, GetStringBoundingBox(ce.str).width);
322 break;
323
324 /* Draw coloured flag for change company cheat */
325 case STR_CHEAT_CHANGE_COMPANY:
326 SetDParamMaxValue(0, MAX_COMPANIES);
327 width = std::max(width, GetStringBoundingBox(ce.str).width + WidgetDimensions::scaled.hsep_wide);
328 break;
329
330 default:
331 SetDParam(0, INT64_MAX);
332 width = std::max(width, GetStringBoundingBox(ce.str).width);
333 break;
334 }
335 break;
336 }
337 }
338
339 this->line_height = std::max<uint>(this->icon.height, SETTING_BUTTON_HEIGHT);
340 this->line_height = std::max<uint>(this->line_height, GetCharacterHeight(FS_NORMAL)) + WidgetDimensions::scaled.framerect.Vertical();
341
342 size.width = width + WidgetDimensions::scaled.hsep_wide * 2 + SETTING_BUTTON_WIDTH;
343 size.height = WidgetDimensions::scaled.framerect.Vertical() + this->line_height * lengthof(_cheats_ui);
344 }
345
346 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
347 {
348 if (widget != WID_C_PANEL) return;
349
350 Rect r = this->GetWidget<NWidgetBase>(WID_C_PANEL)->GetCurrentRect().Shrink(WidgetDimensions::scaled.framerect);
351 uint btn = (pt.y - r.top) / this->line_height;
352 int x = pt.x - r.left;
353 bool rtl = _current_text_dir == TD_RTL;
354 if (rtl) x = r.Width() - 1 - x;
355
356 if (btn >= lengthof(_cheats_ui)) return;
357
358 const CheatEntry *ce = &_cheats_ui[btn];
359 int value = (int32_t)ReadValue(ce->variable, ce->type);
360 int oldvalue = value;
361
362 if (btn == CHT_CHANGE_DATE && x >= SETTING_BUTTON_WIDTH) {
363 /* Click at the date text directly. */
364 clicked_widget = CHT_CHANGE_DATE;
365 SetDParam(0, value);
366 ShowQueryString(STR_JUST_INT, STR_CHEAT_CHANGE_DATE_QUERY_CAPT, 8, this, CS_NUMERAL, QSF_ACCEPT_UNCHANGED);
367 return;
368 } else if (btn == CHT_EDIT_MAX_HL && x >= SETTING_BUTTON_WIDTH) {
369 clicked_widget = CHT_EDIT_MAX_HL;
370 SetDParam(0, value);
371 ShowQueryString(STR_JUST_INT, STR_CHEAT_EDIT_MAX_HL_QUERY_CAPT, 8, this, CS_NUMERAL, QSF_ACCEPT_UNCHANGED);
372 return;
373 }
374
375 /* Not clicking a button? */
376 if (!IsInsideMM(x, 0, SETTING_BUTTON_WIDTH)) return;
377
378 *ce->been_used = true;
379
380 switch (ce->type) {
381 case SLE_BOOL:
382 value ^= 1;
383 if (ce->proc != nullptr) ce->proc(value, 0);
384 break;
385
386 default:
387 /* Take whatever the function returns */
388 value = ce->proc(value + ((x >= SETTING_BUTTON_WIDTH / 2) ? 1 : -1), (x >= SETTING_BUTTON_WIDTH / 2) ? 1 : -1);
389
390 /* The first cheat (money), doesn't return a different value. */
391 if (value != oldvalue || btn == CHT_MONEY) this->clicked = btn * 2 + 1 + ((x >= SETTING_BUTTON_WIDTH / 2) != rtl ? 1 : 0);
392 break;
393 }
394
395 if (value != oldvalue) WriteValue(ce->variable, ce->type, (int64_t)value);
396
397 this->SetTimeout();
398
399 this->SetDirty();
400 }
401
402 void OnTimeout() override
403 {
404 this->clicked = 0;
405 this->SetDirty();
406 }
407
408 void OnQueryTextFinished(std::optional<std::string> str) override
409 {
410 /* Was 'cancel' pressed or nothing entered? */
411 if (!str.has_value() || str->empty()) return;
412
413 const CheatEntry *ce = &_cheats_ui[clicked_widget];
414 int oldvalue = (int32_t)ReadValue(ce->variable, ce->type);
415 int value = atoi(str->c_str());
416 *ce->been_used = true;
417 value = ce->proc(value, value - oldvalue);
418
419 if (value != oldvalue) WriteValue(ce->variable, ce->type, (int64_t)value);
420 this->SetDirty();
421 }
422
423 IntervalTimer<TimerGameCalendar> daily_interval = {{TimerGameCalendar::MONTH, TimerGameCalendar::Priority::NONE}, [this](auto) {
424 this->SetDirty();
425 }};
426};
427
429 static WindowDesc _cheats_desc(
430 WDP_AUTO, "cheats", 0, 0,
431 WC_CHEATS, WC_NONE,
432 0,
433 _nested_cheat_widgets
434);
435
437 void ShowCheatWindow()
438{
439 CloseWindowById(WC_CHEATS, 0);
440 new CheatWindow(_cheats_desc);
441}
_cheats
Cheats _cheats
All the cheats.
Definition cheat.cpp:16
_money_cheat_amount
static int32_t _money_cheat_amount
The 'amount' to cheat with.
Definition cheat_gui.cpp:48
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:143
CheatNumbers
CheatNumbers
Available cheats.
Definition cheat_gui.cpp:168
CHT_NO_JETCRASH
@ CHT_NO_JETCRASH
Disable jet-airplane crashes.
Definition cheat_gui.cpp:173
CHT_CHANGE_DATE
@ CHT_CHANGE_DATE
Do time traveling.
Definition cheat_gui.cpp:177
CHT_CROSSINGTUNNELS
@ CHT_CROSSINGTUNNELS
Allow tunnels to cross each other.
Definition cheat_gui.cpp:172
CHT_SETUP_PROD
@ CHT_SETUP_PROD
Allow manually editing of industry production.
Definition cheat_gui.cpp:174
CHT_CHANGE_COMPANY
@ CHT_CHANGE_COMPANY
Switch company.
Definition cheat_gui.cpp:170
CHT_NUM_CHEATS
@ CHT_NUM_CHEATS
Number of cheats.
Definition cheat_gui.cpp:179
CHT_EXTRA_DYNAMITE
@ CHT_EXTRA_DYNAMITE
Dynamite anything.
Definition cheat_gui.cpp:171
CHT_MONEY
@ CHT_MONEY
Change amount of money.
Definition cheat_gui.cpp:169
CHT_STATION_RATING
@ CHT_STATION_RATING
Fix station ratings at 100%.
Definition cheat_gui.cpp:175
CHT_EDIT_MAX_HL
@ CHT_EDIT_MAX_HL
Edit maximum allowed heightlevel.
Definition cheat_gui.cpp:176
CalendarEnginesMonthlyLoop
void CalendarEnginesMonthlyLoop()
Monthly update of the availability, reliability, and preview offers of the engines.
Definition engine.cpp:1147
ClickMoneyCheat
static int32_t ClickMoneyCheat(int32_t, int32_t change_direction)
Handle cheating of money.
Definition cheat_gui.cpp:58
ClickSetProdCheat
static int32_t ClickSetProdCheat(int32_t new_value, int32_t)
Allow (or disallow) changing production of all industries.
Definition cheat_gui.cpp:88
ClickChangeDateCheat
static int32_t ClickChangeDateCheat(int32_t new_value, int32_t)
Handle changing of the current year.
Definition cheat_gui.cpp:102
_nested_cheat_widgets
static constexpr NWidgetPart _nested_cheat_widgets[]
Widget definitions of the cheat GUI.
Definition cheat_gui.cpp:217
ClickChangeCompanyCheat
static int32_t ClickChangeCompanyCheat(int32_t new_value, int32_t change_direction)
Handle changing of company.
Definition cheat_gui.cpp:70
CheckButtonClick
int32_t CheckButtonClick(int32_t new_value, int32_t change_direction)
Signature of handler function when user clicks at a cheat.
Definition cheat_gui.cpp:187
_cheats_desc
static WindowDesc _cheats_desc(WDP_AUTO, "cheats", 0, 0, WC_CHEATS, WC_NONE, 0, _nested_cheat_widgets)
Window description of the cheats GUI.
ShowCheatWindow
void ShowCheatWindow()
Open cheat window.
Definition cheat_gui.cpp:437
_cheats_ui
static const CheatEntry _cheats_ui[]
The available cheats.
Definition cheat_gui.cpp:202
cheat_type.h
Types related to cheating.
cheat_widget.h
Types related to the cheat widgets.
WID_C_PANEL
@ WID_C_PANEL
Panel where all cheats are shown in.
Definition cheat_widget.h:16
IntervalTimer
An interval timer will fire every interval, and will continue to fire until it is deleted.
Definition timer.h:76
LinkGraphSchedule::instance
static LinkGraphSchedule instance
Static instance of LinkGraphSchedule.
Definition linkgraphschedule.h:52
LinkGraphSchedule::ShiftDates
void ShiftDates(TimerGameEconomy::Date interval)
Shift all dates (join dates and edge annotations) of link graphs and link graph jobs by the number of...
Definition linkgraphschedule.cpp:135
OverflowSafeInt< int64_t >
TimerGameCalendar::ConvertYMDToDate
static Date ConvertYMDToDate(Year year, Month month, Day day)
Converts a tuple of Year, Month and Day to a Date.
Definition timer_game_calendar.cpp:55
TimerGameCalendar::ConvertDateToYMD
static YearMonthDay ConvertDateToYMD(Date date)
Converts a Date to a Year, Month & Day.
Definition timer_game_calendar.cpp:42
TimerGameCalendar::SetDate
static void SetDate(Date date, DateFract fract)
Set the date.
Definition timer_game_calendar.cpp:66
TimerGameCalendar::date
static Date date
Current date in days (day counter).
Definition timer_game_calendar.h:33
TimerGameCalendar::year
static Year year
Current year, starting at 0.
Definition timer_game_calendar.h:31
TimerGameCalendar::date_fract
static DateFract date_fract
Fractional part of the day.
Definition timer_game_calendar.h:34
TimerGameConst< struct Calendar >::MIN_YEAR
static constexpr TimerGame< struct Calendar >::Year MIN_YEAR
The absolute minimum year in OTTD.
Definition timer_game_common.h:176
TimerGameConst< struct Calendar >::MAX_YEAR
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,...
Definition timer_game_common.h:173
TimerGameEconomy::date
static Date date
Current date in days (day counter).
Definition timer_game_economy.h:38
TimerGameEconomy::UsingWallclockUnits
static bool UsingWallclockUnits(bool newgame=false)
Check if we are using wallclock units.
Definition timer_game_economy.cpp:97
TimerGameEconomy::date_fract
static DateFract date_fract
Fractional part of the day.
Definition timer_game_economy.h:39
TimerGameEconomy::SetDate
static void SetDate(Date date, DateFract fract)
Set the date.
Definition timer_game_economy.cpp:81
WidgetDimensions::framerect
RectPadding framerect
Standard padding inside many panels.
Definition window_gui.h:42
WidgetDimensions::scaled
static WidgetDimensions scaled
Widget dimensions scaled for current zoom level.
Definition window_gui.h:28
WidgetDimensions::hsep_wide
int hsep_wide
Wide horizontal spacing.
Definition window_gui.h:64
WidgetDimensions::hsep_indent
int hsep_indent
Width of identation for tree layouts.
Definition window_gui.h:65
command_func.h
Functions related to commands.
company_base.h
Definition of stuff that is very close to a company, like the company struct itself.
DrawCompanyIcon
void DrawCompanyIcon(CompanyID c, int x, int y)
Draw the icon of a company.
Definition company_cmd.cpp:161
_local_company
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Definition company_cmd.cpp:52
SetLocalCompany
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...
Definition company_cmd.cpp:117
company_func.h
Functions related to companies.
company_gui.h
GUI Functions related to companies.
Owner
Owner
Enum for all companies/owners.
Definition company_type.h:18
MAX_COMPANIES
@ MAX_COMPANIES
Maximum number of companies.
Definition company_type.h:23
error.h
Functions related to errors.
ShowErrorMessage
void ShowErrorMessage(StringID summary_msg, int x, int y, CommandCost cc)
Display an error message in a window.
Definition error_gui.cpp:367
WL_ERROR
@ WL_ERROR
Errors (eg. saving/loading failed)
Definition error.h:26
GetCharacterHeight
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
Definition fontcache.cpp:77
geometry_func.hpp
Geometry functions.
GetSpriteSize
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
Definition gfx.cpp:922
GetStringBoundingBox
Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition gfx.cpp:851
DrawString
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:657
FS_NORMAL
@ FS_NORMAL
Index of the normal font in the font tables.
Definition gfx_type.h:209
SetDataTip
constexpr NWidgetPart SetDataTip(uint32_t data, StringID tip)
Widget part function for setting the data and tooltip.
Definition widget_type.h:1202
NWidget
constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx=-1)
Widget part function for starting a new 'real' widget.
Definition widget_type.h:1320
EndContainer
constexpr NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
Definition widget_type.h:1191
Window::SetDirty
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Definition window.cpp:940
linkgraphschedule.h
Declaration of link graph schedule used for cargo distribution.
map_func.h
Functions related to maps.
Clamp
constexpr T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
Definition math_func.hpp:79
IsInsideMM
constexpr bool IsInsideMM(const T x, const size_t min, const size_t max) noexcept
Checks if a value is in an interval.
Definition math_func.hpp:268
misc_cmd.h
Miscellaneous command definitions.
ShowQueryString
void ShowQueryString(StringID str, StringID caption, uint maxsize, Window *parent, CharSetFilter afilter, QueryStringFlags flags)
Show a query popup window with a textbox in it.
Definition misc_gui.cpp:1059
newgrf.h
Base for the NewGRF implementation.
ReloadNewGRFData
void ReloadNewGRFData()
Reload all NewGRF files during a running game.
Definition afterload.cpp:3393
ResetSignalVariant
void ResetSignalVariant(int32_t)
Updates the current signal variant used in the signal GUI to the one adequate to current year.
Definition rail_gui.cpp:1971
rail_gui.h
Functions/types etc.
safeguards.h
A number of safeguards to prevent using unsafe methods.
WriteValue
void WriteValue(void *ptr, VarType conv, int64_t val)
Write the value of a setting.
Definition saveload.cpp:818
ReadValue
int64_t ReadValue(const void *ptr, VarType conv)
Return a signed-long version of the value of a setting.
Definition saveload.cpp:794
saveload.h
Functions/types related to saving and loading games.
_settings_game
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition settings.cpp:57
DrawArrowButtons
void DrawArrowButtons(int x, int y, Colours button_colour, uint8_t state, bool clickable_left, bool clickable_right)
Draw [<][>] boxes.
Definition settings_gui.cpp:2927
DrawBoolButton
void DrawBoolButton(int x, int y, bool state, bool clickable)
Draw a toggle button.
Definition settings_gui.cpp:2979
settings_gui.h
Functions for setting GUIs.
SETTING_BUTTON_WIDTH
#define SETTING_BUTTON_WIDTH
Width of setting buttons.
Definition settings_gui.h:17
SETTING_BUTTON_HEIGHT
#define SETTING_BUTTON_HEIGHT
Height of setting buttons.
Definition settings_gui.h:19
sprites.h
This file contains all sprite-related enums and defines.
stdafx.h
Definition of base types and functions in a cross-platform compatible way.
lengthof
#define lengthof(array)
Return the length of an fixed size array.
Definition stdafx.h:280
string_func.h
Functions related to low-level strings.
CS_NUMERAL
@ CS_NUMERAL
Only numeric ones.
Definition string_type.h:26
SetDParamMaxValue
void SetDParamMaxValue(size_t n, uint64_t max_value, uint min_count, FontSize size)
Set DParam n to some number that is suitable for string size computations.
Definition strings.cpp:127
SetDParam
void SetDParam(size_t n, uint64_t v)
Set a string parameter v at index n in the global string parameter array.
Definition strings.cpp:104
_current_text_dir
TextDirection _current_text_dir
Text direction of the currently selected language.
Definition strings.cpp:56
strings_func.h
Functions related to OTTD's strings.
TD_RTL
@ TD_RTL
Text is written right-to-left by default.
Definition strings_type.h:24
StringID
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Definition strings_type.h:16
INVALID_STRING_ID
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
Definition strings_type.h:17
CheatEntry
Information of a cheat.
Definition cheat_gui.cpp:190
CheatEntry::type
VarType type
type of selector
Definition cheat_gui.cpp:191
CheatEntry::variable
void * variable
pointer to the variable
Definition cheat_gui.cpp:193
CheatEntry::str
StringID str
string with descriptive text
Definition cheat_gui.cpp:192
CheatEntry::proc
CheckButtonClick * proc
procedure
Definition cheat_gui.cpp:195
CheatEntry::been_used
bool * been_used
has this cheat been used before?
Definition cheat_gui.cpp:194
CheatWindow
GUI for the cheats.
Definition cheat_gui.cpp:228
CheatWindow::OnTimeout
void OnTimeout() override
Called when this window's timeout has been reached.
Definition cheat_gui.cpp:402
CheatWindow::icon
Dimension icon
Dimension of company icon sprite.
Definition cheat_gui.cpp:232
CheatWindow::DrawWidget
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
Definition cheat_gui.cpp:244
CheatWindow::OnInit
void OnInit() override
Notification that the nested widget tree gets initialized.
Definition cheat_gui.cpp:239
CheatWindow::UpdateWidgetSize
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.
Definition cheat_gui.cpp:302
CheatWindow::OnQueryTextFinished
void OnQueryTextFinished(std::optional< std::string > str) override
The query window opened from this window has closed.
Definition cheat_gui.cpp:408
CheatWindow::OnClick
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
Definition cheat_gui.cpp:346
Cheat::value
bool value
tells if the bool cheat is active or not
Definition cheat_type.h:18
Cheat::been_used
bool been_used
has this cheat been used before?
Definition cheat_type.h:17
Cheats::crossing_tunnels
Cheat crossing_tunnels
allow tunnels that cross each other
Definition cheat_type.h:30
Cheats::no_jetcrash
Cheat no_jetcrash
no jet will crash on small airports anymore
Definition cheat_type.h:31
Cheats::change_date
Cheat change_date
changes date ingame
Definition cheat_type.h:32
Cheats::station_rating
Cheat station_rating
Fix station ratings at 100%.
Definition cheat_type.h:35
Cheats::money
Cheat money
get rich or poor
Definition cheat_type.h:29
Cheats::setup_prod
Cheat setup_prod
setup raw-material production in game
Definition cheat_type.h:33
Cheats::switch_company
Cheat switch_company
change to another company
Definition cheat_type.h:28
Cheats::magic_bulldozer
Cheat magic_bulldozer
dynamite industries, objects
Definition cheat_type.h:27
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
CommandHelper
Definition command_func.h:83
ConstructionSettings::map_height_limit
uint8_t map_height_limit
the maximum allowed heightlevel
Definition settings_type.h:382
Dimension
Dimensions (a width and height) of a rectangle in 2D.
Definition geometry_type.hpp:30
GameSettings::construction
ConstructionSettings construction
construction of things in-game
Definition settings_type.h:594
Map::Iterate
static IterateWrapper Iterate()
Returns an iterable ensemble of all Tiles.
Definition map_func.h:363
NWidgetPart
Partial widget specification to allow NWidgets to be written nested.
Definition widget_type.h:1075
Point
Coordinates of a point in 2D.
Definition geometry_type.hpp:21
Pool::PoolItem<&_company_pool >::GetPoolSize
static size_t GetPoolSize()
Returns first unused index.
Definition pool_type.hpp:360
Pool::PoolItem<&_company_pool >::IsValidID
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
Definition pool_type.hpp:328
Pool::PoolItem<&_vehicle_pool >::Iterate
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
Definition pool_type.hpp:388
RectPadding::Vertical
constexpr uint Vertical() const
Get total vertical padding of RectPadding.
Definition geometry_type.hpp:69
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition geometry_type.hpp:75
Rect::Width
int Width() const
Get width of Rect.
Definition geometry_type.hpp:85
Rect::Shrink
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
Definition geometry_type.hpp:98
StrongType::Typedef
Templated helper to make a type-safe 'typedef' representing a single POD value.
Definition strong_typedef_type.hpp:150
WindowDesc
High level window description.
Definition window_gui.h:159
Window
Data structure for an opened window.
Definition window_gui.h:273
Window::resize
ResizeInfo resize
Resize information.
Definition window_gui.h:314
Window::SetTimeout
void SetTimeout()
Set the timeout flag of the window and initiate the timer.
Definition window_gui.h:361
Window::GetWidget
const NWID * GetWidget(WidgetID widnum) const
Get the nested widget with number widnum from the nested widget tree.
Definition window_gui.h:977
Window::InitNested
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
Definition window.cpp:1746
Window::width
int width
width of the window (number of pixels to the right in x direction)
Definition window_gui.h:311
textbuf_gui.h
Stuff related to the text buffer GUI.
QSF_ACCEPT_UNCHANGED
@ QSF_ACCEPT_UNCHANGED
return success even when the text didn't change
Definition textbuf_gui.h:20
tile_map.h
Map writing/reading functions for tiles.
TileHeight
static debug_inline uint TileHeight(Tile tile)
Returns the height of a tile.
Definition tile_map.h:29
MIN_MAP_HEIGHT_LIMIT
static const uint MIN_MAP_HEIGHT_LIMIT
Lower bound of maximum allowed heightlevel (in the construction settings)
Definition tile_type.h:29
MAX_MAP_HEIGHT_LIMIT
static const uint MAX_MAP_HEIGHT_LIMIT
Upper bound of maximum allowed heightlevel (in the construction settings)
Definition tile_type.h:30
timer.h
Definition of Interval and OneShot timers.
timer_game_calendar.h
Definition of the game-calendar-timer.
timer_game_economy.h
Definition of the game-economy-timer.
vehicle_base.h
Base class for all vehicles.
NWID_HORIZONTAL
@ NWID_HORIZONTAL
Horizontal container.
Definition widget_type.h:75
WWT_PANEL
@ WWT_PANEL
Simple depressed panel.
Definition widget_type.h:50
WWT_STICKYBOX
@ WWT_STICKYBOX
Sticky box (at top-right of a window, after WWT_DEFSIZEBOX)
Definition widget_type.h:66
WWT_SHADEBOX
@ WWT_SHADEBOX
Shade box (at top-right of a window, between WWT_DEBUGBOX and WWT_DEFSIZEBOX)
Definition widget_type.h:64
WWT_CAPTION
@ WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition widget_type.h:61
WWT_CLOSEBOX
@ WWT_CLOSEBOX
Close box (at top-left of a window)
Definition widget_type.h:69
CloseWindowById
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:1140
SetWindowDirty
void SetWindowDirty(WindowClass cls, WindowNumber number)
Mark window as dirty (in need of repainting)
Definition window.cpp:3101
InvalidateWindowClassesData
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:3236
window_func.h
Window functions not directly related to making/drawing windows.
window_gui.h
Functions, definitions and such used only by the GUI.
WDP_AUTO
@ WDP_AUTO
Find a place automatically.
Definition window_gui.h:147
WidgetID
int WidgetID
Widget ID.
Definition window_type.h:18
WC_BUILD_STATION
@ WC_BUILD_STATION
Build station; Window numbers:
Definition window_type.h:403
WC_BUILD_OBJECT
@ WC_BUILD_OBJECT
Build object; Window numbers:
Definition window_type.h:376
WC_STATUS_BAR
@ WC_STATUS_BAR
Statusbar (at the bottom of your screen); Window numbers:
Definition window_type.h:64
WC_NONE
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Definition window_type.h:45
WC_CHEATS
@ WC_CHEATS
Cheat window; Window numbers:
Definition window_type.h:636
WC_TRUCK_STATION
@ WC_TRUCK_STATION
Build truck station; Window numbers:
Definition window_type.h:415
WC_INDUSTRY_VIEW
@ WC_INDUSTRY_VIEW
Industry view; Window numbers:
Definition window_type.h:363
WC_FINANCES
@ WC_FINANCES
Finances of a company; Window numbers:
Definition window_type.h:527
WC_BUS_STATION
@ WC_BUS_STATION
Build bus station; Window numbers:
Definition window_type.h:409
WC_SMALLMAP
@ WC_SMALLMAP
Small map; Window numbers:
Definition window_type.h:104