OpenTTD
Data Structures | Functions | Variables
ai_gui.cpp File Reference

Window for configuring the AIs More...

#include "../stdafx.h"
#include "../table/sprites.h"
#include "../error.h"
#include "../settings_gui.h"
#include "../querystring_gui.h"
#include "../stringfilter_type.h"
#include "../company_base.h"
#include "../company_gui.h"
#include "../strings_func.h"
#include "../window_func.h"
#include "../gfx_func.h"
#include "../command_func.h"
#include "../network/network.h"
#include "../settings_func.h"
#include "../network/network_content.h"
#include "../textfile_gui.h"
#include "../widgets/dropdown_type.h"
#include "../widgets/dropdown_func.h"
#include "../hotkeys.h"
#include "../core/geometry_func.hpp"
#include "ai.hpp"
#include "ai_gui.hpp"
#include "../script/api/script_log.hpp"
#include "ai_config.hpp"
#include "ai_info.hpp"
#include "ai_instance.hpp"
#include "../game/game.hpp"
#include "../game/game_config.hpp"
#include "../game/game_info.hpp"
#include "../game/game_instance.hpp"
#include "table/strings.h"
#include <vector>
#include "../safeguards.h"

Go to the source code of this file.

Data Structures

struct  AIListWindow
 Window that let you choose an available AI. More...
 
struct  AISettingsWindow
 Window for settings the parameters of an AI. More...
 
struct  ScriptTextfileWindow
 Window for displaying the textfile of a AI. More...
 
struct  AIConfigWindow
 Window to configure which AIs will start. More...
 
struct  AIDebugWindow
 Window with everything an AI prints via ScriptLog. More...
 

Functions

static ScriptConfigGetConfig (CompanyID slot)
 
static void ShowAIListWindow (CompanyID slot)
 Open the AI list window to chose an AI for the given company slot. More...
 
static void ShowAISettingsWindow (CompanyID slot)
 Open the AI settings window to change the AI settings for an AI. More...
 
void ShowScriptTextfileWindow (TextfileType file_type, CompanyID slot)
 Open the AI version of the textfile window. More...
 
void ShowAIConfigWindow ()
 Open the AI config window. More...
 
static bool SetScriptButtonColour (NWidgetCore &button, bool dead, bool paused)
 Set the widget colour of a button based on the state of the script. More...
 
NWidgetBaseMakeCompanyButtonRowsAIDebug (int *biggest_index)
 Make a number of rows with buttons for each company for the AI debug window. More...
 
static EventState AIDebugGlobalHotkeys (int hotkey)
 Handler for global hotkeys of the AIDebugWindow. More...
 
WindowShowAIDebugWindow (CompanyID show_company)
 Open the AI debug window and select the given company. More...
 
void InitializeAIGui ()
 Reset the AI windows to their initial state.
 
void ShowAIDebugWindowIfAIError ()
 Open the AI debug window if one of the AI scripts has crashed. More...
 

Variables

static const NWidgetPart _nested_ai_list_widgets []
 Widgets for the AI list window. More...
 
static WindowDesc _ai_list_desc (WDP_CENTER, "settings_script_list", 200, 234, WC_AI_LIST, WC_NONE, 0, _nested_ai_list_widgets, lengthof(_nested_ai_list_widgets))
 Window definition for the ai list window. More...
 
static const NWidgetPart _nested_ai_settings_widgets []
 Widgets for the AI settings window. More...
 
static WindowDesc _ai_settings_desc (WDP_CENTER, "settings_script", 500, 208, WC_AI_SETTINGS, WC_NONE, 0, _nested_ai_settings_widgets, lengthof(_nested_ai_settings_widgets))
 Window definition for the AI settings window. More...
 
static const NWidgetPart _nested_ai_config_widgets []
 Widgets for the configure AI window. More...
 
static WindowDesc _ai_config_desc (WDP_CENTER, "settings_script_config", 0, 0, WC_GAME_OPTIONS, WC_NONE, 0, _nested_ai_config_widgets, lengthof(_nested_ai_config_widgets))
 Window definition for the configure AI window. More...
 
static Hotkey aidebug_hotkeys []
 
static const NWidgetPart _nested_ai_debug_widgets []
 Widgets for the AI debug window. More...
 
static WindowDesc _ai_debug_desc (WDP_AUTO, "script_debug", 600, 450, WC_AI_DEBUG, WC_NONE, 0, _nested_ai_debug_widgets, lengthof(_nested_ai_debug_widgets), &AIDebugWindow::hotkeys)
 Window definition for the AI debug window. More...
 

Detailed Description

Window for configuring the AIs

Definition in file ai_gui.cpp.

Function Documentation

◆ AIDebugGlobalHotkeys()

static EventState AIDebugGlobalHotkeys ( int  hotkey)
static

Handler for global hotkeys of the AIDebugWindow.

Parameters
hotkeyHotkey
Returns
ES_HANDLED if hotkey was accepted.

Definition at line 1430 of file ai_gui.cpp.

◆ MakeCompanyButtonRowsAIDebug()

NWidgetBase* MakeCompanyButtonRowsAIDebug ( int *  biggest_index)

Make a number of rows with buttons for each company for the AI debug window.

Definition at line 1420 of file ai_gui.cpp.

References MakeCompanyButtonRows(), WID_AID_COMPANY_BUTTON_END, and WID_AID_COMPANY_BUTTON_START.

◆ SetScriptButtonColour()

static bool SetScriptButtonColour ( NWidgetCore button,
bool  dead,
bool  paused 
)
static

Set the widget colour of a button based on the state of the script.

(dead or alive)

Parameters
buttonthe button to update.
deadtrue if the script is dead, otherwise false.
pausedtrue if the script is paused, otherwise false.
Returns
true if the colour was changed and the window need to be marked as dirty.

Definition at line 972 of file ai_gui.cpp.

Referenced by AIDebugWindow::OnPaint().

◆ ShowAIConfigWindow()

void ShowAIConfigWindow ( )

Open the AI config window.

Definition at line 958 of file ai_gui.cpp.

References DeleteWindowByClass(), and WC_GAME_OPTIONS.

◆ ShowAIDebugWindow()

Window* ShowAIDebugWindow ( CompanyID  show_company)

Open the AI debug window and select the given company.

Parameters
show_companyDisplay debug information about this AI company.

Definition at line 1523 of file ai_gui.cpp.

References _network_server, _networking, BringWindowToFrontById(), AIDebugWindow::ChangeToAI(), INVALID_COMPANY, INVALID_STRING_ID, ShowErrorMessage(), WC_AI_DEBUG, and WL_INFO.

Referenced by AIInstance::Died(), and GameInstance::Died().

◆ ShowAIDebugWindowIfAIError()

void ShowAIDebugWindowIfAIError ( )

Open the AI debug window if one of the AI scripts has crashed.

Definition at line 1546 of file ai_gui.cpp.

References _network_server, and _networking.

◆ ShowAIListWindow()

static void ShowAIListWindow ( CompanyID  slot)
static

Open the AI list window to chose an AI for the given company slot.

Parameters
slotThe slot to change the AI of.

Definition at line 273 of file ai_gui.cpp.

References AIListWindow::AIListWindow(), DeleteWindowByClass(), and WC_AI_LIST.

◆ ShowAISettingsWindow()

static void ShowAISettingsWindow ( CompanyID  slot)
static

Open the AI settings window to change the AI settings for an AI.

Parameters
slotThe CompanyID of the AI to change the settings.

Definition at line 622 of file ai_gui.cpp.

References DeleteWindowByClass(), WC_AI_LIST, and WC_AI_SETTINGS.

Referenced by AIDebugWindow::OnClick().

◆ ShowScriptTextfileWindow()

void ShowScriptTextfileWindow ( TextfileType  file_type,
CompanyID  slot 
)

Open the AI version of the textfile window.

Parameters
file_typeThe type of textfile to display.
slotThe slot the Script is using.

Definition at line 654 of file ai_gui.cpp.

References DeleteWindowByClass(), and WC_TEXTFILE.

Variable Documentation

◆ _ai_config_desc

WindowDesc _ai_config_desc(WDP_CENTER, "settings_script_config", 0, 0, WC_GAME_OPTIONS, WC_NONE, 0, _nested_ai_config_widgets, lengthof(_nested_ai_config_widgets))
static

Window definition for the configure AI window.

◆ _ai_debug_desc

WindowDesc _ai_debug_desc(WDP_AUTO, "script_debug", 600, 450, WC_AI_DEBUG, WC_NONE, 0, _nested_ai_debug_widgets, lengthof(_nested_ai_debug_widgets), &AIDebugWindow::hotkeys)
static

Window definition for the AI debug window.

◆ _ai_list_desc

WindowDesc _ai_list_desc(WDP_CENTER, "settings_script_list", 200, 234, WC_AI_LIST, WC_NONE, 0, _nested_ai_list_widgets, lengthof(_nested_ai_list_widgets))
static

Window definition for the ai list window.

◆ _ai_settings_desc

WindowDesc _ai_settings_desc(WDP_CENTER, "settings_script", 500, 208, WC_AI_SETTINGS, WC_NONE, 0, _nested_ai_settings_widgets, lengthof(_nested_ai_settings_widgets))
static

Window definition for the AI settings window.

◆ _nested_ai_config_widgets

const NWidgetPart _nested_ai_config_widgets[]
static

Widgets for the configure AI window.

Definition at line 662 of file ai_gui.cpp.

◆ _nested_ai_debug_widgets

const NWidgetPart _nested_ai_debug_widgets[]
static

Widgets for the AI debug window.

Definition at line 1466 of file ai_gui.cpp.

◆ _nested_ai_list_widgets

const NWidgetPart _nested_ai_list_widgets[]
static
Initial value:
= {
NWidget(WWT_CLOSEBOX, COLOUR_MAUVE),
NWidget(WWT_CAPTION, COLOUR_MAUVE, WID_AIL_CAPTION), SetDataTip(STR_AI_LIST_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
NWidget(WWT_DEFSIZEBOX, COLOUR_MAUVE),
NWidget(WWT_MATRIX, COLOUR_MAUVE, WID_AIL_LIST), SetMinimalSize(188, 112), SetFill(1, 1), SetResize(1, 1), SetMatrixDataTip(1, 0, STR_AI_LIST_TOOLTIP), SetScrollbar(WID_AIL_SCROLLBAR),
NWidget(WWT_PUSHTXTBTN, COLOUR_MAUVE, WID_AIL_ACCEPT), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_AI_LIST_ACCEPT, STR_AI_LIST_ACCEPT_TOOLTIP),
NWidget(WWT_PUSHTXTBTN, COLOUR_MAUVE, WID_AIL_CANCEL), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_AI_LIST_CANCEL, STR_AI_LIST_CANCEL_TOOLTIP),
NWidget(WWT_RESIZEBOX, COLOUR_MAUVE),
}
static NWidgetPart SetResize(int16 dx, int16 dy)
Widget part function for setting the resize step.
Definition: widget_type.h:930
Offset at top to draw the frame rectangular area.
Definition: window_gui.h:64
Horizontal container.
Definition: widget_type.h:75
Resize box (normally at bottom-right of a window)
Definition: widget_type.h:68
Scrollbar next to the AI list.
Definition: ai_widget.h:22
Close box (at top-left of a window)
Definition: widget_type.h:69
static NWidgetPart SetMinimalTextLines(uint8 lines, uint8 spacing, FontSize size=FS_NORMAL)
Widget part function for setting the minimal text lines.
Definition: widget_type.h:965
Cancel button.
Definition: ai_widget.h:25
static NWidgetPart SetMatrixDataTip(uint8 cols, uint8 rows, StringID tip)
Widget part function for setting the data and tooltip of WWT_MATRIX widgets.
Definition: widget_type.h:1032
Default window size box (at top-right of a window, between WWT_SHADEBOX and WWT_STICKYBOX) ...
Definition: widget_type.h:65
static NWidgetPart SetDataTip(uint32 data, StringID tip)
Widget part function for setting the data and tooltip.
Definition: widget_type.h:1014
static NWidgetPart SetMinimalSize(int16 x, int16 y)
Widget part function for setting the minimal size.
Definition: widget_type.h:947
Normal push-button (no toggle button) with text caption.
Definition: widget_type.h:104
Simple depressed panel.
Definition: widget_type.h:50
static NWidgetPart NWidget(WidgetType tp, Colours col, int16 idx=-1)
Widget part function for starting a new &#39;real&#39; widget.
Definition: widget_type.h:1114
Offset at bottom to draw the frame rectangular area.
Definition: window_gui.h:65
Panel to draw some AI information on.
Definition: ai_widget.h:23
Grid of rows and columns.
Definition: widget_type.h:59
Window caption (window title between closebox and stickybox)
Definition: widget_type.h:61
static NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME, WWT_INSET, or WWT_PANEL).
Definition: widget_type.h:999
Caption of the window.
Definition: ai_widget.h:20
static NWidgetPart SetFill(uint fill_x, uint fill_y)
Widget part function for setting filling.
Definition: widget_type.h:983
Vertical scrollbar.
Definition: widget_type.h:84
The matrix with all available AIs.
Definition: ai_widget.h:21
static NWidgetPart SetScrollbar(int index)
Attach a scrollbar to a widget.
Definition: widget_type.h:1095
Value of the NCB_EQUALSIZE flag.
Definition: widget_type.h:429
Accept button.
Definition: ai_widget.h:24

Widgets for the AI list window.

Definition at line 240 of file ai_gui.cpp.

◆ _nested_ai_settings_widgets

const NWidgetPart _nested_ai_settings_widgets[]
static
Initial value:
= {
NWidget(WWT_CLOSEBOX, COLOUR_MAUVE),
NWidget(WWT_CAPTION, COLOUR_MAUVE, WID_AIS_CAPTION), SetDataTip(STR_AI_SETTINGS_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
NWidget(WWT_DEFSIZEBOX, COLOUR_MAUVE),
NWidget(WWT_PUSHTXTBTN, COLOUR_MAUVE, WID_AIS_ACCEPT), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_AI_SETTINGS_CLOSE, STR_NULL),
NWidget(WWT_PUSHTXTBTN, COLOUR_MAUVE, WID_AIS_RESET), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_AI_SETTINGS_RESET, STR_NULL),
NWidget(WWT_RESIZEBOX, COLOUR_MAUVE),
}
static NWidgetPart SetResize(int16 dx, int16 dy)
Widget part function for setting the resize step.
Definition: widget_type.h:930
Reset button.
Definition: ai_widget.h:34
Horizontal container.
Definition: widget_type.h:75
Resize box (normally at bottom-right of a window)
Definition: widget_type.h:68
Close box (at top-left of a window)
Definition: widget_type.h:69
Scrollbar to scroll through all settings.
Definition: ai_widget.h:32
Panel to draw the settings on.
Definition: ai_widget.h:31
Accept button.
Definition: ai_widget.h:33
static NWidgetPart SetMatrixDataTip(uint8 cols, uint8 rows, StringID tip)
Widget part function for setting the data and tooltip of WWT_MATRIX widgets.
Definition: widget_type.h:1032
Default window size box (at top-right of a window, between WWT_SHADEBOX and WWT_STICKYBOX) ...
Definition: widget_type.h:65
static NWidgetPart SetDataTip(uint32 data, StringID tip)
Widget part function for setting the data and tooltip.
Definition: widget_type.h:1014
static NWidgetPart SetMinimalSize(int16 x, int16 y)
Widget part function for setting the minimal size.
Definition: widget_type.h:947
Normal push-button (no toggle button) with text caption.
Definition: widget_type.h:104
static NWidgetPart NWidget(WidgetType tp, Colours col, int16 idx=-1)
Widget part function for starting a new &#39;real&#39; widget.
Definition: widget_type.h:1114
Grid of rows and columns.
Definition: widget_type.h:59
Window caption (window title between closebox and stickybox)
Definition: widget_type.h:61
static NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME, WWT_INSET, or WWT_PANEL).
Definition: widget_type.h:999
Caption of the window.
Definition: ai_widget.h:30
static NWidgetPart SetFill(uint fill_x, uint fill_y)
Widget part function for setting filling.
Definition: widget_type.h:983
Vertical scrollbar.
Definition: widget_type.h:84
static NWidgetPart SetScrollbar(int index)
Attach a scrollbar to a widget.
Definition: widget_type.h:1095
Value of the NCB_EQUALSIZE flag.
Definition: widget_type.h:429

Widgets for the AI settings window.

Definition at line 591 of file ai_gui.cpp.

◆ aidebug_hotkeys

Hotkey aidebug_hotkeys[]
static
Initial value:
= {
Hotkey('2', "company_2", WID_AID_COMPANY_BUTTON_START + 1),
Hotkey('3', "company_3", WID_AID_COMPANY_BUTTON_START + 2),
Hotkey('4', "company_4", WID_AID_COMPANY_BUTTON_START + 3),
Hotkey('5', "company_5", WID_AID_COMPANY_BUTTON_START + 4),
Hotkey('6', "company_6", WID_AID_COMPANY_BUTTON_START + 5),
Hotkey('7', "company_7", WID_AID_COMPANY_BUTTON_START + 6),
Hotkey('8', "company_8", WID_AID_COMPANY_BUTTON_START + 7),
Hotkey('9', "company_9", WID_AID_COMPANY_BUTTON_START + 8),
Hotkey((uint16)0, "company_10", WID_AID_COMPANY_BUTTON_START + 9),
Hotkey((uint16)0, "company_11", WID_AID_COMPANY_BUTTON_START + 10),
Hotkey((uint16)0, "company_12", WID_AID_COMPANY_BUTTON_START + 11),
Hotkey((uint16)0, "company_13", WID_AID_COMPANY_BUTTON_START + 12),
Hotkey((uint16)0, "company_14", WID_AID_COMPANY_BUTTON_START + 13),
Hotkey((uint16)0, "company_15", WID_AID_COMPANY_BUTTON_START + 14),
Hotkey('S', "settings", WID_AID_SETTINGS),
Hotkey('0', "game_script", WID_AID_SCRIPT_GAME),
Hotkey((uint16)0, "reload", WID_AID_RELOAD_TOGGLE),
Hotkey('B', "break_toggle", WID_AID_BREAK_STR_ON_OFF_BTN),
Hotkey('F', "break_string", WID_AID_BREAK_STR_EDIT_BOX),
Hotkey('C', "match_case", WID_AID_MATCH_CASE_BTN),
Hotkey(WKC_RETURN, "continue", WID_AID_CONTINUE_BTN),
HOTKEY_LIST_END
}
Enable breaking on string.
Definition: ai_widget.h:67
All data for a single hotkey.
Definition: hotkeys.h:24
Checkbox to use match caching or not.
Definition: ai_widget.h:69
Reload button.
Definition: ai_widget.h:61
Settings button.
Definition: ai_widget.h:59
Buttons in the VIEW.
Definition: ai_widget.h:64
Edit box for the string to break on.
Definition: ai_widget.h:68
Game Script button.
Definition: ai_widget.h:60
Continue button.
Definition: ai_widget.h:70

Definition at line 1438 of file ai_gui.cpp.