25#include "table/strings.h"
60 NWidget(
WWT_MATRIX, COLOUR_MAUVE,
WID_AIC_LIST),
SetMinimalSize(288, 112),
SetFill(1, 0),
SetMatrixDataTip(1, 8, STR_AI_CONFIG_AILIST_TOOLTIP),
SetScrollbar(
WID_AIC_SCROLLBAR),
96struct AIConfigWindow :
public Window {
105 this->selected_slot = CompanyID::Invalid();
108 this->vscroll->
SetCount(MAX_COMPANIES);
112 void Close([[maybe_unused]]
int data = 0)
override
140 size =
maxdim(size, NWidgetScrollbar::GetHorizontalDimension());
145 fill.height =
resize.height = this->line_height;
146 size.height = 8 * this->line_height;
158 if (_game_mode != GM_NORMAL) {
159 return slot > 0 && slot < MAX_COMPANIES;
173 return GetString(STR_AI_CONFIG_RANDOM_AI);
184 if (this->selected_slot == cid)
return TC_WHITE;
185 if (
IsEditable(cid))
return cid < max_slot ? TC_ORANGE : TC_SILVER;
196 if (_game_mode == GM_NORMAL) {
198 if (c->is_ai) max_slot--;
200 for (CompanyID cid = CompanyID::Begin(); cid < max_slot && cid < MAX_COMPANIES; ++cid) {
206 for (
int i = this->vscroll->
GetPosition(); this->vscroll->IsVisible(i) && i < MAX_COMPANIES; i++) {
207 CompanyID cid =
static_cast<CompanyID
>(i);
209 tr.top += this->line_height;
219 if (this->selected_slot == CompanyID::Invalid() ||
AIConfig::GetConfig(this->selected_slot) ==
nullptr)
return;
230 new_value = std::max(0,
GetGameSettings().difficulty.max_no_competitors - 1);
232 new_value = std::min<int>(MAX_COMPANIES - 1,
GetGameSettings().difficulty.max_no_competitors + 1);
234 IConsoleSetSetting(
"difficulty.max_no_competitors", new_value);
247 IConsoleSetSetting(
"difficulty.competitors_interval", new_value);
260 if (
IsEditable(this->selected_slot) &&
IsEditable(
static_cast<CompanyID
>(this->selected_slot - 1))) {
262 this->selected_slot =
static_cast<CompanyID
>(this->selected_slot - 1);
269 if (
IsEditable(this->selected_slot) &&
IsEditable(
static_cast<CompanyID
>(this->selected_slot + 1))) {
271 ++this->selected_slot;
279 if (this->selected_slot == CompanyID::Invalid() || config ==
nullptr || config->
GetInfo() ==
nullptr)
return;
307 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override
310 this->selected_slot = CompanyID::Invalid();
313 if (!gui_scope)
return;
327 for (
TextfileType tft = TFT_CONTENT_BEGIN; tft < TFT_CONTENT_END; tft++) {
Base functions for all AIs.
AIConfig stores the configuration settings of every AI.
static WindowDesc _ai_config_desc(WDP_CENTER, {}, 0, 0, WC_GAME_OPTIONS, WC_NONE, {}, _nested_ai_config_widgets)
Window definition for the configure AI window.
void ShowAIConfigWindow()
Open the AI config window.
static constexpr std::initializer_list< NWidgetPart > _nested_ai_config_widgets
Widgets for the configure AI window.
Window for configuring the AIs.
AIInfo keeps track of all information of an AI, like Author, Description, ...
AI instantion of script configuration.
class AIInfo * GetInfo() const
Get the ScriptInfo linked to this ScriptConfig.
static AIConfig * GetConfig(CompanyID company, ScriptSettingSource source=SSS_DEFAULT)
Get the AI configuration of specific company.
All static information from an AI like name, version, etc.
std::optional< std::string > GetTextfile(TextfileType type, CompanyID slot) const
Search a textfile file next to this script.
const ScriptConfigItemList * GetConfigList()
Get the config list for this ScriptConfig.
const std::string & GetURL() const
Get the website for this script.
Definition of stuff that is very close to a company, like the company struct itself.
static const uint MIN_COMPETITORS_INTERVAL
The minimum interval (in minutes) between competitors.
static const uint MAX_COMPETITORS_INTERVAL
The maximum interval (in minutes) between competitors.
Functions related to errors.
@ WL_ERROR
Errors (eg. saving/loading failed).
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.
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
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.
bool _ctrl_pressed
Is Ctrl pressed?
@ FS_NORMAL
Index of the normal font in the font tables.
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
#define Point
Macro that prevents name conflicts between included headers.
bool _network_available
is network mode available?
Basic functions/variables used all over the place.
Part of the network protocol handling content distribution.
void ShowNetworkContentListWindow(ContentVector *cv=nullptr, ContentType type1=CONTENT_TYPE_END, ContentType type2=CONTENT_TYPE_END)
Show the content list window with a given set of content.
A number of safeguards to prevent using unsafe methods.
void ShowScriptSettingsWindow(CompanyID slot)
Open the Script settings window to change the Script settings for a Script.
void ShowScriptTextfileWindow(Window *parent, TextfileType file_type, CompanyID slot)
Open the Script version of the textfile window.
void ShowScriptListWindow(CompanyID slot, bool show_all)
Open the Script list window to chose a script for the given company slot.
Window for configuring the scripts.
Functions related to setting/changing the settings.
GameSettings & GetGameSettings()
Get the settings-object applicable for the current situation: the newgame settings when we're in the ...
Definition of base types and functions in a cross-platform compatible way.
EncodedString GetEncodedString(StringID str)
Encode a string with no parameters into an encoded string.
std::string GetString(StringID string)
Resolve the given StringID into a std::string with formatting but no parameters.
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Window to configure which AIs will start.
std::string GetWidgetString(WidgetID widget, StringID stringid) const override
Get the raw string for a widget.
void Close(int data=0) override
Hide the window and all its child windows, and mark them for a later deletion.
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.
std::string GetSlotText(CompanyID cid) const
Get text to display for a given company slot.
TextColour GetSlotColour(CompanyID cid, CompanyID max_slot) const
Get colour to display text in for a given company slot.
CompanyID selected_slot
The currently selected AI slot or CompanyID::Invalid().
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
static bool IsEditable(CompanyID slot)
Can the AI config in the given company slot be edited?
Scrollbar * vscroll
Cache of the vertical scrollbar.
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
int line_height
Height of a single AI-name line.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
static bool IsValidAiID(auto index)
Is this company a valid company, controlled by the computer (a NoAI program)?
static bool IsValidHumanID(auto index)
Is this company a valid company, not controlled by a NoAI program?
uint8_t max_no_competitors
the number of competitors (AIs)
Dimensions (a width and height) of a rectangle in 2D.
AISettings ai
what may the AI do?
DifficultySettings difficulty
settings related to the difficulty
static Pool::IterateWrapper< Company > Iterate(size_t from=0)
static bool IsValidID(auto index)
Specification of a rectangle with absolute coordinates of all edges.
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
High level window description.
virtual void Close(int data=0)
Hide the window and all its child windows, and mark them for a later deletion.
void InvalidateData(int data=0, bool gui_scope=true)
Mark this window's data as invalid (in need of re-computing).
virtual std::string GetWidgetString(WidgetID widget, StringID stringid) const
Get the raw string for a widget.
ResizeInfo resize
Resize information.
Window(WindowDesc &desc)
Empty constructor, initialization has been moved to InitNested() called from the constructor of the d...
const NWID * GetWidget(WidgetID widnum) const
Get the nested widget with number widnum from the nested widget tree.
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
const Scrollbar * GetScrollbar(WidgetID widnum) const
Return the Scrollbar to a widget index.
void SetWidgetDisabledState(WidgetID widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
@ CONTENT_TYPE_AI
The content consists of an AI.
TextfileType
Additional text files accompanying Tar archives.
@ TFT_LICENSE
Content license.
@ TFT_README
Content readme.
@ TFT_CHANGELOG
Content changelog.
void CloseWindowByClass(WindowClass cls, int data)
Close all windows of a given class.
Window functions not directly related to making/drawing windows.
@ WDP_CENTER
Center the window.
@ WN_GAME_OPTIONS_AI
AI settings.
@ WC_SCRIPT_SETTINGS
Script settings; Window numbers:
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
@ WC_SCRIPT_LIST
Scripts list; Window numbers:
@ WC_GAME_OPTIONS
Game options window; Window numbers: