forked from mirror/OpenTTD
(svn r23364) -Codechange: refactor AIConfig, moving it mostly to Scriptconfig
This commit is contained in:
@@ -28,6 +28,7 @@
|
||||
#include "ai.hpp"
|
||||
#include "../script/api/script_log.hpp"
|
||||
#include "ai_config.hpp"
|
||||
#include "ai_info.hpp"
|
||||
#include "ai_instance.hpp"
|
||||
|
||||
#include "table/strings.h"
|
||||
@@ -71,7 +72,7 @@ struct AIListWindow : public Window {
|
||||
|
||||
/* Try if we can find the currently selected AI */
|
||||
this->selected = -1;
|
||||
if (AIConfig::GetConfig(slot)->HasAI()) {
|
||||
if (AIConfig::GetConfig(slot)->HasScript()) {
|
||||
AIInfo *info = AIConfig::GetConfig(slot)->GetInfo();
|
||||
int i = 0;
|
||||
for (ScriptInfoList::const_iterator it = this->ai_info_list->begin(); it != this->ai_info_list->end(); it++, i++) {
|
||||
@@ -148,11 +149,11 @@ struct AIListWindow : public Window {
|
||||
void ChangeAI()
|
||||
{
|
||||
if (this->selected == -1) {
|
||||
AIConfig::GetConfig(slot)->ChangeAI(NULL);
|
||||
AIConfig::GetConfig(slot)->Change(NULL);
|
||||
} else {
|
||||
ScriptInfoList::const_iterator it = this->ai_info_list->begin();
|
||||
for (int i = 0; i < this->selected; i++) it++;
|
||||
AIConfig::GetConfig(slot)->ChangeAI((*it).second->GetName(), (*it).second->GetVersion());
|
||||
AIConfig::GetConfig(slot)->Change((*it).second->GetName(), (*it).second->GetVersion());
|
||||
}
|
||||
SetWindowDirty(WC_GAME_OPTIONS, 0);
|
||||
}
|
||||
@@ -272,7 +273,7 @@ struct AISettingsWindow : public Window {
|
||||
int clicked_row; ///< The clicked row of settings.
|
||||
int line_height; ///< Height of a row in the matrix widget.
|
||||
Scrollbar *vscroll; ///< Cache of the vertical scrollbar.
|
||||
typedef std::vector<const AIConfigItem *> VisibleSettingsList;
|
||||
typedef std::vector<const ScriptConfigItem *> VisibleSettingsList;
|
||||
VisibleSettingsList visible_settings; ///< List of visible AI settings
|
||||
|
||||
/**
|
||||
@@ -306,9 +307,9 @@ struct AISettingsWindow : public Window {
|
||||
{
|
||||
visible_settings.clear();
|
||||
|
||||
AIConfigItemList::const_iterator it = this->ai_config->GetConfigList()->begin();
|
||||
ScriptConfigItemList::const_iterator it = this->ai_config->GetConfigList()->begin();
|
||||
for (; it != this->ai_config->GetConfigList()->end(); it++) {
|
||||
bool no_hide = (it->flags & AICONFIG_AI_DEVELOPER) == 0;
|
||||
bool no_hide = (it->flags & SCRIPTCONFIG_DEVELOPER) == 0;
|
||||
if (no_hide || _settings_client.gui.ai_developer_tools) {
|
||||
visible_settings.push_back(&(*it));
|
||||
}
|
||||
@@ -343,9 +344,9 @@ struct AISettingsWindow : public Window {
|
||||
|
||||
int y = r.top;
|
||||
for (; this->vscroll->IsVisible(i) && it != visible_settings.end(); i++, it++) {
|
||||
const AIConfigItem &config_item = **it;
|
||||
const ScriptConfigItem &config_item = **it;
|
||||
int current_value = config->GetSetting((config_item).name);
|
||||
bool editable = _game_mode == GM_MENU || !Company::IsValidID(this->slot) || (config_item.flags & AICONFIG_INGAME) != 0;
|
||||
bool editable = _game_mode == GM_MENU || !Company::IsValidID(this->slot) || (config_item.flags & SCRIPTCONFIG_INGAME) != 0;
|
||||
|
||||
StringID str;
|
||||
TextColour colour;
|
||||
@@ -359,7 +360,7 @@ struct AISettingsWindow : public Window {
|
||||
SetDParamStr(idx++, config_item.description);
|
||||
}
|
||||
|
||||
if ((config_item.flags & AICONFIG_BOOLEAN) != 0) {
|
||||
if ((config_item.flags & SCRIPTCONFIG_BOOLEAN) != 0) {
|
||||
DrawFrameRect(buttons_left, y + 2, buttons_left + 19, y + 10, (current_value != 0) ? COLOUR_GREEN : COLOUR_RED, (current_value != 0) ? FR_LOWERED : FR_NONE);
|
||||
SetDParam(idx++, current_value == 0 ? STR_CONFIG_SETTING_OFF : STR_CONFIG_SETTING_ON);
|
||||
} else {
|
||||
@@ -403,10 +404,10 @@ struct AISettingsWindow : public Window {
|
||||
|
||||
VisibleSettingsList::const_iterator it = this->visible_settings.begin();
|
||||
for (int i = 0; i < num; i++) it++;
|
||||
const AIConfigItem config_item = **it;
|
||||
if (_game_mode == GM_NORMAL && Company::IsValidID(this->slot) && (config_item.flags & AICONFIG_INGAME) == 0) return;
|
||||
const ScriptConfigItem config_item = **it;
|
||||
if (_game_mode == GM_NORMAL && Company::IsValidID(this->slot) && (config_item.flags & SCRIPTCONFIG_INGAME) == 0) return;
|
||||
|
||||
bool bool_item = (config_item.flags & AICONFIG_BOOLEAN) != 0;
|
||||
bool bool_item = (config_item.flags & SCRIPTCONFIG_BOOLEAN) != 0;
|
||||
|
||||
int x = pt.x - wid->pos_x;
|
||||
if (_current_text_dir == TD_RTL) x = wid->current_x - x;
|
||||
@@ -462,9 +463,9 @@ struct AISettingsWindow : public Window {
|
||||
virtual void OnQueryTextFinished(char *str)
|
||||
{
|
||||
if (StrEmpty(str)) return;
|
||||
AIConfigItemList::const_iterator it = this->ai_config->GetConfigList()->begin();
|
||||
ScriptConfigItemList::const_iterator it = this->ai_config->GetConfigList()->begin();
|
||||
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;
|
||||
if (_game_mode == GM_NORMAL && Company::IsValidID(this->slot) && (it->flags & SCRIPTCONFIG_INGAME) == 0) return;
|
||||
int32 value = atoi(str);
|
||||
this->ai_config->SetSetting((*it).name, value);
|
||||
this->CheckDifficultyLevel();
|
||||
|
Reference in New Issue
Block a user