@@ -176,24 +176,29 @@ struct AIListWindow : public Window {
}
virtual void OnResize()
{
NWidgetCore *nwi = this->GetWidget<NWidgetCore>(AIL_WIDGET_LIST);
this->vscroll->SetCapacity(nwi->current_y / this->line_height);
nwi->widget_data = (this->vscroll->GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START);
virtual void OnInvalidateData(int data)
if (_game_mode == GM_NORMAL && Company::IsValidID(this->slot)) {
delete this;
return;
this->vscroll->SetCount((int)this->ai_info_list->size() + 1);
/* selected goes from -1 .. length of ai list - 1. */
this->selected = min(this->selected, this->vscroll->GetCount() - 2);
};
/** Widgets for the AI list window. */
static const NWidgetPart _nested_ai_list_widgets[] = {
NWidget(NWID_HORIZONTAL),
NWidget(WWT_CLOSEBOX, COLOUR_MAUVE),
NWidget(WWT_CAPTION, COLOUR_MAUVE), SetDataTip(STR_AI_LIST_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
@@ -254,25 +259,25 @@ struct AISettingsWindow : public Window
AISettingsWindow(const WindowDesc *desc, CompanyID slot) : Window(),
slot(slot),
clicked_button(-1),
timeout(0)
this->ai_config = AIConfig::GetConfig(slot);
this->CreateNestedTree(desc);
this->vscroll = this->GetScrollbar(AIS_WIDGET_SCROLLBAR);
this->FinishInitNested(desc, slot); // Initializes 'this->line_height' as side effect.
this->SetWidgetDisabledState(AIS_WIDGET_RESET, _game_mode != GM_MENU);
this->SetWidgetDisabledState(AIS_WIDGET_RESET, _game_mode != GM_MENU && Company::IsValidID(this->slot));
this->vscroll->SetCount((int)this->ai_config->GetConfigList()->size());
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
if (widget == AIS_WIDGET_BACKGROUND) {
this->line_height = FONT_HEIGHT_NORMAL + WD_MATRIX_TOP + WD_MATRIX_BOTTOM;
resize->width = 1;
resize->height = this->line_height;
size->height = GB(this->GetWidget<NWidgetCore>(widget)->widget_data, MAT_ROW_START, MAT_ROW_BITS) * this->line_height;
@@ -288,25 +293,25 @@ struct AISettingsWindow : public Window
int i = 0;
for (; !this->vscroll->IsVisible(i); i++) it++;
bool rtl = _current_text_dir == TD_RTL;
uint buttons_left = rtl ? r.right - 23 : r.left + 4;
uint text_left = r.left + (rtl ? WD_FRAMERECT_LEFT : 28);
uint text_right = r.right - (rtl ? 28 : WD_FRAMERECT_RIGHT);
int y = r.top;
for (; this->vscroll->IsVisible(i) && it != config->GetConfigList()->end(); i++, it++) {
int current_value = config->GetSetting((*it).name);
bool editable = (_game_mode == GM_MENU) || ((it->flags & AICONFIG_INGAME) != 0);
bool editable = _game_mode == GM_MENU || !Company::IsValidID(this->slot) || (it->flags & AICONFIG_INGAME) != 0;
StringID str;
TextColour colour;
uint idx = 0;
if (StrEmpty((*it).description)) {
str = STR_JUST_STRING;
colour = TC_ORANGE;
} else {
str = STR_AI_SETTINGS_SETTING;
colour = TC_LIGHT_BLUE;
SetDParamStr(idx++, (*it).description);
@@ -344,25 +349,25 @@ struct AISettingsWindow : public Window
virtual void OnClick(Point pt, int widget, int click_count)
switch (widget) {
case AIS_WIDGET_BACKGROUND: {
const NWidgetBase *wid = this->GetWidget<NWidgetBase>(AIS_WIDGET_BACKGROUND);
int num = (pt.y - wid->pos_y) / this->line_height + this->vscroll->GetPosition();
if (num >= (int)this->ai_config->GetConfigList()->size()) break;
AIConfigItemList::const_iterator it = this->ai_config->GetConfigList()->begin();
for (int i = 0; i < num; i++) it++;
AIConfigItem config_item = *it;
if (_game_mode != GM_MENU && (config_item.flags & AICONFIG_INGAME) == 0) return;
if (_game_mode == GM_NORMAL && Company::IsValidID(this->slot) && (config_item.flags & AICONFIG_INGAME) == 0) return;
bool bool_item = (config_item.flags & AICONFIG_BOOLEAN) != 0;
int x = pt.x - wid->pos_x;
if (_current_text_dir == TD_RTL) x = wid->current_x - x;
x -= 4;
/* One of the arrows is clicked (or green/red rect in case of bool value) */
if (IsInsideMM(x, 0, 21)) {
int new_val = this->ai_config->GetSetting(config_item.name);
if (bool_item) {
new_val = !new_val;
} else if (x >= 10) {
@@ -389,55 +394,63 @@ struct AISettingsWindow : public Window
ShowQueryString(STR_JUST_INT, STR_CONFIG_SETTING_QUERY_CAPTION, 10, 100, this, CS_NUMERAL, QSF_NONE);
this->SetDirty();
break;
case AIS_WIDGET_ACCEPT:
case AIS_WIDGET_RESET:
this->ai_config->ResetSettings();
if (_game_mode == GM_MENU || !Company::IsValidID(this->slot)) {
virtual void OnQueryTextFinished(char *str)
if (StrEmpty(str)) return;
for (int i = 0; i < this->clicked_row; i++) it++;
if (_game_mode == GM_NORMAL && Company::IsValidID(this->slot) && (it->flags & AICONFIG_INGAME) == 0) return;
int32 value = atoi(str);
this->ai_config->SetSetting((*it).name, value);
this->CheckDifficultyLevel();
NWidgetCore *nwi = this->GetWidget<NWidgetCore>(AIS_WIDGET_BACKGROUND);
virtual void OnTick()
if (--this->timeout == 0) {
this->clicked_button = -1;
if (_game_mode == GM_NORMAL && Company::IsValidID(this->slot)) delete this;
/** Widgets for the AI settings window. */
static const NWidgetPart _nested_ai_settings_widgets[] = {
NWidget(WWT_CAPTION, COLOUR_MAUVE), SetDataTip(STR_AI_SETTINGS_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
EndContainer(),
NWidget(WWT_MATRIX, COLOUR_MAUVE, AIS_WIDGET_BACKGROUND), SetMinimalSize(188, 182), SetResize(1, 1), SetFill(1, 0), SetDataTip(0x501, STR_NULL), SetScrollbar(AIS_WIDGET_SCROLLBAR),
NWidget(NWID_VSCROLLBAR, COLOUR_MAUVE, AIS_WIDGET_SCROLLBAR),
@@ -547,99 +560,118 @@ struct AIConfigWindow : public Window {
~AIConfigWindow()
DeleteWindowByClass(WC_AI_LIST);
DeleteWindowByClass(WC_AI_SETTINGS);
virtual void SetStringParameters(int widget) const
case AIC_WIDGET_NUMBER:
SetDParam(0, _settings_newgame.difficulty.max_no_competitors);
SetDParam(0, GetGameSettings().difficulty.max_no_competitors);
case AIC_WIDGET_LIST:
/**
* Can the AI config in the given company slot be edited?
* @param slot The slot to query.
* @return True if and only if the given AI Config slot can e edited.
*/
static bool IsEditable(CompanyID slot)
if (_game_mode != GM_NORMAL) {
return slot > 0 && slot <= GetGameSettings().difficulty.max_no_competitors;
if (Company::IsValidID(slot) || slot < 0) return false;
int max_slot = GetGameSettings().difficulty.max_no_competitors;
for (CompanyID cid = COMPANY_FIRST; cid < (CompanyID)max_slot && cid < MAX_COMPANIES; cid++) {
if (Company::IsValidHumanID(cid)) max_slot++;
return slot < max_slot;
virtual void DrawWidget(const Rect &r, int widget) const
case AIC_WIDGET_LIST: {
for (int i = this->vscroll->GetPosition(); this->vscroll->IsVisible(i) && i < MAX_COMPANIES; i++) {
StringID text;
if (AIConfig::GetConfig((CompanyID)i)->GetInfo() != NULL) {
if ((_game_mode != GM_NORMAL && i == 0) || (_game_mode == GM_NORMAL && Company::IsValidHumanID(i))) {
text = STR_AI_CONFIG_HUMAN_PLAYER;
} else if (AIConfig::GetConfig((CompanyID)i)->GetInfo() != NULL) {
SetDParamStr(0, AIConfig::GetConfig((CompanyID)i)->GetInfo()->GetName());
text = STR_JUST_RAW_STRING;
} else if (i == 0) {
text = STR_AI_CONFIG_RANDOM_AI;
DrawString(r.left + 10, r.right - 10, y + WD_MATRIX_TOP, text,
(this->selected_slot == i) ? TC_WHITE : ((i > _settings_newgame.difficulty.max_no_competitors || i == 0) ? TC_SILVER : TC_ORANGE));
(this->selected_slot == i) ? TC_WHITE : (IsEditable((CompanyID)i) ? TC_ORANGE : TC_SILVER));
y += this->line_height;
case AIC_WIDGET_DECREASE:
case AIC_WIDGET_INCREASE: {
int new_value;
if (widget == AIC_WIDGET_DECREASE) {
new_value = max(0, _settings_newgame.difficulty.max_no_competitors - 1);
new_value = max(0, GetGameSettings().difficulty.max_no_competitors - 1);
new_value = min(MAX_COMPANIES - 1, _settings_newgame.difficulty.max_no_competitors + 1);
new_value = min(MAX_COMPANIES - 1, GetGameSettings().difficulty.max_no_competitors + 1);
IConsoleSetSetting("difficulty.max_no_competitors", new_value);
this->InvalidateData();
case AIC_WIDGET_LIST: { // Select a slot
this->selected_slot = (CompanyID)this->vscroll->GetScrolledRowFromWidget(pt.y, this, widget, 0, this->line_height);
if (click_count > 1 && this->selected_slot != INVALID_COMPANY) ShowAIListWindow((CompanyID)this->selected_slot);
case AIC_WIDGET_MOVE_UP:
if (this->selected_slot > 1) {
Swap(_settings_newgame.ai_config[this->selected_slot], _settings_newgame.ai_config[this->selected_slot - 1]);
if (IsEditable(this->selected_slot) && IsEditable((CompanyID)(this->selected_slot - 1))) {
Swap(GetGameSettings().ai_config[this->selected_slot], GetGameSettings().ai_config[this->selected_slot - 1]);
this->selected_slot--;
this->vscroll->ScrollTowards(this->selected_slot);
case AIC_WIDGET_MOVE_DOWN:
if (this->selected_slot < _settings_newgame.difficulty.max_no_competitors) {
Swap(_settings_newgame.ai_config[this->selected_slot], _settings_newgame.ai_config[this->selected_slot + 1]);
if (IsEditable(this->selected_slot) && IsEditable((CompanyID)(this->selected_slot + 1))) {
Swap(GetGameSettings().ai_config[this->selected_slot], GetGameSettings().ai_config[this->selected_slot + 1]);
this->selected_slot++;
case AIC_WIDGET_CHANGE: // choose other AI
ShowAIListWindow((CompanyID)this->selected_slot);
case AIC_WIDGET_CONFIGURE: // change the settings for an AI
ShowAISettingsWindow((CompanyID)this->selected_slot);
@@ -654,34 +686,34 @@ struct AIConfigWindow : public Window {
ShowErrorMessage(STR_NETWORK_ERROR_NOTAVAILABLE, INVALID_STRING_ID, WL_ERROR);
#if defined(ENABLE_NETWORK)
ShowNetworkContentListWindow(NULL, CONTENT_TYPE_AI);
#endif
if (this->selected_slot == 0 || this->selected_slot > _settings_newgame.difficulty.max_no_competitors) {
if (!IsEditable(this->selected_slot)) {
this->selected_slot = INVALID_COMPANY;
this->SetWidgetDisabledState(AIC_WIDGET_DECREASE, _settings_newgame.difficulty.max_no_competitors == 0);
this->SetWidgetDisabledState(AIC_WIDGET_INCREASE, _settings_newgame.difficulty.max_no_competitors == MAX_COMPANIES - 1);
this->SetWidgetDisabledState(AIC_WIDGET_DECREASE, GetGameSettings().difficulty.max_no_competitors == 0);
this->SetWidgetDisabledState(AIC_WIDGET_INCREASE, GetGameSettings().difficulty.max_no_competitors == MAX_COMPANIES - 1);
this->SetWidgetDisabledState(AIC_WIDGET_CHANGE, this->selected_slot == INVALID_COMPANY);
this->SetWidgetDisabledState(AIC_WIDGET_CONFIGURE, this->selected_slot == INVALID_COMPANY);
this->SetWidgetDisabledState(AIC_WIDGET_MOVE_UP, this->selected_slot == INVALID_COMPANY || this->selected_slot == 1);
this->SetWidgetDisabledState(AIC_WIDGET_MOVE_DOWN, this->selected_slot == INVALID_COMPANY || this->selected_slot == _settings_newgame.difficulty.max_no_competitors);
this->SetWidgetDisabledState(AIC_WIDGET_MOVE_UP, this->selected_slot == INVALID_COMPANY || !IsEditable((CompanyID)(this->selected_slot - 1)));
this->SetWidgetDisabledState(AIC_WIDGET_MOVE_DOWN, this->selected_slot == INVALID_COMPANY || !IsEditable((CompanyID)(this->selected_slot + 1)));
/** Open the AI config window. */
void ShowAIConfigWindow()
DeleteWindowById(WC_GAME_OPTIONS, 0);
new AIConfigWindow();
/** Enum referring to the widgets of the AI debug window */
enum AIDebugWindowWidgets {
@@ -887,24 +887,28 @@ CommandCost CmdCompanyCtrl(TileIndex til
if (c->is_ai) AI::Stop(c->index);
CompanyID c_index = c->index;
delete c;
AI::BroadcastNewEvent(new AIEventCompanyBankrupt(c_index));
CompanyAdminBankrupt(c_index);
default: return CMD_ERROR;
InvalidateWindowClassesData(WC_GAME_OPTIONS);
InvalidateWindowClassesData(WC_AI_SETTINGS);
InvalidateWindowClassesData(WC_AI_LIST);
return CommandCost();
* Change the company manager's face.
* @param tile unused
* @param flags operation to perform
* @param p1 unused
* @param p2 face bitmasked
* @param text unused
* @return the cost of this operation or an error
@@ -339,24 +339,25 @@ STR_SCENEDIT_TOOLBAR_PLACE_OBJECT
STR_SCENEDIT_FILE_MENU_SAVE_SCENARIO :Save scenario
STR_SCENEDIT_FILE_MENU_LOAD_SCENARIO :Load scenario
STR_SCENEDIT_FILE_MENU_LOAD_HEIGHTMAP :Load heightmap
STR_SCENEDIT_FILE_MENU_QUIT_EDITOR :Quit editor
STR_SCENEDIT_FILE_MENU_SEPARATOR :
STR_SCENEDIT_FILE_MENU_QUIT :Quit
############ range for SE file menu starts
############ range for settings menu starts
STR_SETTINGS_MENU_GAME_OPTIONS :Game options
STR_SETTINGS_MENU_DIFFICULTY_SETTINGS :Difficulty settings
STR_SETTINGS_MENU_CONFIG_SETTINGS :Advanced settings
STR_SETTINGS_MENU_AI_SETTINGS :AI settings
STR_SETTINGS_MENU_NEWGRF_SETTINGS :NewGRF settings
STR_SETTINGS_MENU_TRANSPARENCY_OPTIONS :Transparency options
STR_SETTINGS_MENU_TOWN_NAMES_DISPLAYED :Town names displayed
STR_SETTINGS_MENU_STATION_NAMES_DISPLAYED :Station names displayed
STR_SETTINGS_MENU_WAYPOINTS_DISPLAYED :Waypoint names displayed
STR_SETTINGS_MENU_SIGNS_DISPLAYED :Signs displayed
STR_SETTINGS_MENU_FULL_ANIMATION :Full animation
STR_SETTINGS_MENU_FULL_DETAIL :Full detail
STR_SETTINGS_MENU_TRANSPARENT_BUILDINGS :Transparent buildings
STR_SETTINGS_MENU_TRANSPARENT_SIGNS :Transparent station signs
############ range ends here
@@ -280,65 +280,71 @@ static CallBackFunction ToolbarFastForwa
_fast_forward ^= true;
SndPlayFx(SND_15_BEEP);
return CBF_NONE;
/* --- Options button menu --- */
enum OptionMenuEntries {
OME_GAMEOPTIONS,
OME_DIFFICULTIES,
OME_SETTINGS,
OME_AI_SETTINGS,
OME_NEWGRFSETTINGS,
OME_TRANSPARENCIES,
OME_SHOW_TOWNNAMES,
OME_SHOW_STATIONNAMES,
OME_SHOW_WAYPOINTNAMES,
OME_SHOW_SIGNS,
OME_FULL_ANIMATION,
OME_FULL_DETAILS,
OME_TRANSPARENTBUILDINGS,
OME_SHOW_STATIONSIGNS,
static CallBackFunction ToolbarOptionsClick(Window *w)
DropDownList *list = new DropDownList();
list->push_back(new DropDownListStringItem(STR_SETTINGS_MENU_GAME_OPTIONS, OME_GAMEOPTIONS, false));
list->push_back(new DropDownListStringItem(STR_SETTINGS_MENU_DIFFICULTY_SETTINGS, OME_DIFFICULTIES, false));
list->push_back(new DropDownListStringItem(STR_SETTINGS_MENU_CONFIG_SETTINGS, OME_SETTINGS, false));
/* Changes to the per-AI settings don't get send from the server to the clients. Clients get
* the settings once they join but never update it. As such don't show the window at all
* to network clients. */
if (!_networking || _network_server) list->push_back(new DropDownListStringItem(STR_SETTINGS_MENU_AI_SETTINGS, OME_AI_SETTINGS, false));
list->push_back(new DropDownListStringItem(STR_SETTINGS_MENU_NEWGRF_SETTINGS, OME_NEWGRFSETTINGS, false));
list->push_back(new DropDownListStringItem(STR_SETTINGS_MENU_TRANSPARENCY_OPTIONS, OME_TRANSPARENCIES, false));
list->push_back(new DropDownListItem(-1, false));
list->push_back(new DropDownListCheckedItem(STR_SETTINGS_MENU_TOWN_NAMES_DISPLAYED, OME_SHOW_TOWNNAMES, false, HasBit(_display_opt, DO_SHOW_TOWN_NAMES)));
list->push_back(new DropDownListCheckedItem(STR_SETTINGS_MENU_STATION_NAMES_DISPLAYED, OME_SHOW_STATIONNAMES, false, HasBit(_display_opt, DO_SHOW_STATION_NAMES)));
list->push_back(new DropDownListCheckedItem(STR_SETTINGS_MENU_WAYPOINTS_DISPLAYED, OME_SHOW_WAYPOINTNAMES, false, HasBit(_display_opt, DO_SHOW_WAYPOINT_NAMES)));
list->push_back(new DropDownListCheckedItem(STR_SETTINGS_MENU_SIGNS_DISPLAYED, OME_SHOW_SIGNS, false, HasBit(_display_opt, DO_SHOW_SIGNS)));
list->push_back(new DropDownListCheckedItem(STR_SETTINGS_MENU_FULL_ANIMATION, OME_FULL_ANIMATION, false, HasBit(_display_opt, DO_FULL_ANIMATION)));
list->push_back(new DropDownListCheckedItem(STR_SETTINGS_MENU_FULL_DETAIL, OME_FULL_DETAILS, false, HasBit(_display_opt, DO_FULL_DETAIL)));
list->push_back(new DropDownListCheckedItem(STR_SETTINGS_MENU_TRANSPARENT_BUILDINGS, OME_TRANSPARENTBUILDINGS, false, IsTransparencySet(TO_HOUSES)));
list->push_back(new DropDownListCheckedItem(STR_SETTINGS_MENU_TRANSPARENT_SIGNS, OME_SHOW_STATIONSIGNS, false, IsTransparencySet(TO_SIGNS)));
ShowDropDownList(w, list, 0, TBN_SETTINGS, 140, true, true);
static CallBackFunction MenuClickSettings(int index)
switch (index) {
case OME_GAMEOPTIONS: ShowGameOptions(); return CBF_NONE;
case OME_DIFFICULTIES: ShowGameDifficulty(); return CBF_NONE;
case OME_SETTINGS: ShowGameSettings(); return CBF_NONE;
case OME_AI_SETTINGS: ShowAIConfigWindow(); return CBF_NONE;
case OME_NEWGRFSETTINGS: ShowNewGRFSettings(!_networking && _settings_client.gui.UserIsAllowedToChangeNewGRFs(), true, true, &_grfconfig); return CBF_NONE;
case OME_TRANSPARENCIES: ShowTransparencyToolbar(); break;
case OME_SHOW_TOWNNAMES: ToggleBit(_display_opt, DO_SHOW_TOWN_NAMES); break;
case OME_SHOW_STATIONNAMES: ToggleBit(_display_opt, DO_SHOW_STATION_NAMES); break;
case OME_SHOW_WAYPOINTNAMES: ToggleBit(_display_opt, DO_SHOW_WAYPOINT_NAMES); break;
case OME_SHOW_SIGNS: ToggleBit(_display_opt, DO_SHOW_SIGNS); break;
case OME_FULL_ANIMATION: ToggleBit(_display_opt, DO_FULL_ANIMATION); break;
case OME_FULL_DETAILS: ToggleBit(_display_opt, DO_FULL_DETAIL); break;
case OME_TRANSPARENTBUILDINGS: ToggleTransparency(TO_HOUSES); break;
case OME_SHOW_STATIONSIGNS: ToggleTransparency(TO_SIGNS); break;
Status change: