mirror of https://github.com/OpenTTD/OpenTTD
Compare commits
No commits in common. "4e26e3380570acc8dd43ba50f591f84dd62baa07" and "c0b8e584047d5fd6e83a95f0af16c081ba03be9f" have entirely different histories.
4e26e33805
...
c0b8e58404
|
@ -181,16 +181,8 @@ struct AIConfigWindow : public Window {
|
||||||
} else {
|
} else {
|
||||||
text = STR_AI_CONFIG_RANDOM_AI;
|
text = STR_AI_CONFIG_RANDOM_AI;
|
||||||
}
|
}
|
||||||
|
DrawString(tr, text,
|
||||||
TextColour tc = TC_SILVER;
|
(this->selected_slot == i) ? TC_WHITE : (IsEditable((CompanyID)i) ? TC_ORANGE : TC_SILVER));
|
||||||
if (this->selected_slot == i) {
|
|
||||||
tc = TC_WHITE;
|
|
||||||
} else if (IsEditable((CompanyID)i)) {
|
|
||||||
tc = TC_ORANGE;
|
|
||||||
} else if (Company::IsValidAiID(i)) {
|
|
||||||
tc = TC_GREEN;
|
|
||||||
}
|
|
||||||
DrawString(tr, text, tc);
|
|
||||||
tr.top += this->line_height;
|
tr.top += this->line_height;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -237,7 +229,7 @@ struct AIConfigWindow : public Window {
|
||||||
case WID_AIC_LIST: { // Select a slot
|
case WID_AIC_LIST: { // Select a slot
|
||||||
this->selected_slot = (CompanyID)this->vscroll->GetScrolledRowFromWidget(pt.y, this, widget);
|
this->selected_slot = (CompanyID)this->vscroll->GetScrolledRowFromWidget(pt.y, this, widget);
|
||||||
this->InvalidateData();
|
this->InvalidateData();
|
||||||
if (click_count > 1 && IsEditable(this->selected_slot)) ShowScriptListWindow((CompanyID)this->selected_slot, _ctrl_pressed);
|
if (click_count > 1 && this->selected_slot != INVALID_COMPANY) ShowScriptListWindow((CompanyID)this->selected_slot, _ctrl_pressed);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -267,7 +259,7 @@ struct AIConfigWindow : public Window {
|
||||||
}
|
}
|
||||||
|
|
||||||
case WID_AIC_CHANGE: // choose other AI
|
case WID_AIC_CHANGE: // choose other AI
|
||||||
if (IsEditable(this->selected_slot)) ShowScriptListWindow((CompanyID)this->selected_slot, _ctrl_pressed);
|
ShowScriptListWindow((CompanyID)this->selected_slot, _ctrl_pressed);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WID_AIC_CONFIGURE: // change the settings for an AI
|
case WID_AIC_CONFIGURE: // change the settings for an AI
|
||||||
|
@ -291,7 +283,7 @@ struct AIConfigWindow : public Window {
|
||||||
*/
|
*/
|
||||||
void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
|
void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
|
||||||
{
|
{
|
||||||
if (!IsEditable(this->selected_slot) && !Company::IsValidAiID(this->selected_slot)) {
|
if (!IsEditable(this->selected_slot)) {
|
||||||
this->selected_slot = INVALID_COMPANY;
|
this->selected_slot = INVALID_COMPANY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -303,10 +295,10 @@ struct AIConfigWindow : public Window {
|
||||||
this->SetWidgetDisabledState(WID_AIC_INCREASE_NUMBER, GetGameSettings().difficulty.max_no_competitors == MAX_COMPANIES - 1);
|
this->SetWidgetDisabledState(WID_AIC_INCREASE_NUMBER, GetGameSettings().difficulty.max_no_competitors == MAX_COMPANIES - 1);
|
||||||
this->SetWidgetDisabledState(WID_AIC_DECREASE_INTERVAL, GetGameSettings().difficulty.competitors_interval == MIN_COMPETITORS_INTERVAL);
|
this->SetWidgetDisabledState(WID_AIC_DECREASE_INTERVAL, GetGameSettings().difficulty.competitors_interval == MIN_COMPETITORS_INTERVAL);
|
||||||
this->SetWidgetDisabledState(WID_AIC_INCREASE_INTERVAL, GetGameSettings().difficulty.competitors_interval == MAX_COMPETITORS_INTERVAL);
|
this->SetWidgetDisabledState(WID_AIC_INCREASE_INTERVAL, GetGameSettings().difficulty.competitors_interval == MAX_COMPETITORS_INTERVAL);
|
||||||
this->SetWidgetDisabledState(WID_AIC_CHANGE, !IsEditable(this->selected_slot));
|
this->SetWidgetDisabledState(WID_AIC_CHANGE, this->selected_slot == INVALID_COMPANY);
|
||||||
this->SetWidgetDisabledState(WID_AIC_CONFIGURE, this->selected_slot == INVALID_COMPANY || config->GetConfigList()->empty());
|
this->SetWidgetDisabledState(WID_AIC_CONFIGURE, this->selected_slot == INVALID_COMPANY || config->GetConfigList()->empty());
|
||||||
this->SetWidgetDisabledState(WID_AIC_MOVE_UP, !IsEditable(this->selected_slot) || !IsEditable((CompanyID)(this->selected_slot - 1)));
|
this->SetWidgetDisabledState(WID_AIC_MOVE_UP, this->selected_slot == INVALID_COMPANY || !IsEditable((CompanyID)(this->selected_slot - 1)));
|
||||||
this->SetWidgetDisabledState(WID_AIC_MOVE_DOWN, !IsEditable(this->selected_slot) || !IsEditable((CompanyID)(this->selected_slot + 1)));
|
this->SetWidgetDisabledState(WID_AIC_MOVE_DOWN, this->selected_slot == INVALID_COMPANY || !IsEditable((CompanyID)(this->selected_slot + 1)));
|
||||||
|
|
||||||
this->SetWidgetDisabledState(WID_AIC_OPEN_URL, this->selected_slot == INVALID_COMPANY || config->GetInfo() == nullptr || config->GetInfo()->GetURL().empty());
|
this->SetWidgetDisabledState(WID_AIC_OPEN_URL, this->selected_slot == INVALID_COMPANY || config->GetInfo() == nullptr || config->GetInfo()->GetURL().empty());
|
||||||
for (TextfileType tft = TFT_CONTENT_BEGIN; tft < TFT_CONTENT_END; tft++) {
|
for (TextfileType tft = TFT_CONTENT_BEGIN; tft < TFT_CONTENT_END; tft++) {
|
||||||
|
|
|
@ -199,18 +199,10 @@ struct GSConfigWindow : public Window {
|
||||||
TextColour colour;
|
TextColour colour;
|
||||||
uint idx = 0;
|
uint idx = 0;
|
||||||
if (config_item.description.empty()) {
|
if (config_item.description.empty()) {
|
||||||
if (Game::GetInstance() == nullptr && config_item.random_deviation != 0) {
|
str = STR_JUST_STRING1;
|
||||||
str = STR_AI_SETTINGS_JUST_DEVIATION;
|
|
||||||
} else {
|
|
||||||
str = STR_JUST_STRING1;
|
|
||||||
}
|
|
||||||
colour = TC_ORANGE;
|
colour = TC_ORANGE;
|
||||||
} else {
|
} else {
|
||||||
if (Game::GetInstance() == nullptr && config_item.random_deviation != 0) {
|
str = STR_AI_SETTINGS_SETTING;
|
||||||
str = STR_AI_SETTINGS_SETTING_DEVIATION;
|
|
||||||
} else {
|
|
||||||
str = STR_AI_SETTINGS_SETTING;
|
|
||||||
}
|
|
||||||
colour = TC_LIGHT_BLUE;
|
colour = TC_LIGHT_BLUE;
|
||||||
SetDParamStr(idx++, config_item.description);
|
SetDParamStr(idx++, config_item.description);
|
||||||
}
|
}
|
||||||
|
@ -224,36 +216,13 @@ struct GSConfigWindow : public Window {
|
||||||
} else {
|
} else {
|
||||||
DrawArrowButtons(br.left, y + button_y_offset, COLOUR_YELLOW, (this->clicked_button == i) ? 1 + (this->clicked_increase != rtl) : 0, editable && current_value > config_item.min_value, editable && current_value < config_item.max_value);
|
DrawArrowButtons(br.left, y + button_y_offset, COLOUR_YELLOW, (this->clicked_button == i) ? 1 + (this->clicked_increase != rtl) : 0, editable && current_value > config_item.min_value, editable && current_value < config_item.max_value);
|
||||||
}
|
}
|
||||||
|
auto config_iterator = config_item.labels.find(current_value);
|
||||||
if (Game::GetInstance() != nullptr || config_item.random_deviation == 0) {
|
if (config_iterator != config_item.labels.end()) {
|
||||||
auto config_iterator = config_item.labels.find(current_value);
|
SetDParam(idx++, STR_JUST_RAW_STRING);
|
||||||
if (config_iterator != config_item.labels.end()) {
|
SetDParamStr(idx++, config_iterator->second);
|
||||||
SetDParam(idx++, STR_JUST_RAW_STRING);
|
|
||||||
SetDParamStr(idx++, config_iterator->second);
|
|
||||||
} else {
|
|
||||||
SetDParam(idx++, STR_JUST_INT);
|
|
||||||
SetDParam(idx++, current_value);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
int min_deviated = std::max(config_item.min_value, current_value - config_item.random_deviation);
|
SetDParam(idx++, STR_JUST_INT);
|
||||||
auto config_iterator = config_item.labels.find(min_deviated);
|
SetDParam(idx++, current_value);
|
||||||
if (config_iterator != config_item.labels.end()) {
|
|
||||||
SetDParam(idx++, STR_JUST_RAW_STRING);
|
|
||||||
SetDParamStr(idx++, config_iterator->second);
|
|
||||||
} else {
|
|
||||||
SetDParam(idx++, STR_JUST_INT);
|
|
||||||
SetDParam(idx++, min_deviated);
|
|
||||||
}
|
|
||||||
|
|
||||||
int max_deviated = std::min(config_item.max_value, current_value + config_item.random_deviation);
|
|
||||||
config_iterator = config_item.labels.find(max_deviated);
|
|
||||||
if (config_iterator != config_item.labels.end()) {
|
|
||||||
SetDParam(idx++, STR_JUST_RAW_STRING);
|
|
||||||
SetDParamStr(idx++, config_iterator->second);
|
|
||||||
} else {
|
|
||||||
SetDParam(idx++, STR_JUST_INT);
|
|
||||||
SetDParam(idx++, max_deviated);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4835,8 +4835,6 @@ STR_AI_SETTINGS_CAPTION_GAMESCRIPT :Game Script
|
||||||
STR_AI_SETTINGS_CLOSE :{BLACK}Close
|
STR_AI_SETTINGS_CLOSE :{BLACK}Close
|
||||||
STR_AI_SETTINGS_RESET :{BLACK}Reset
|
STR_AI_SETTINGS_RESET :{BLACK}Reset
|
||||||
STR_AI_SETTINGS_SETTING :{RAW_STRING}: {ORANGE}{STRING1}
|
STR_AI_SETTINGS_SETTING :{RAW_STRING}: {ORANGE}{STRING1}
|
||||||
STR_AI_SETTINGS_SETTING_DEVIATION :{RAW_STRING}: {ORANGE}[{STRING1}, {STRING1}]
|
|
||||||
STR_AI_SETTINGS_JUST_DEVIATION :[{STRING1}, {STRING1}]
|
|
||||||
|
|
||||||
|
|
||||||
# Textfile window
|
# Textfile window
|
||||||
|
|
|
@ -73,16 +73,15 @@ NetworkHTTPRequest::NetworkHTTPRequest(const std::wstring &uri, HTTPCallback *ca
|
||||||
|
|
||||||
static std::string GetLastErrorAsString()
|
static std::string GetLastErrorAsString()
|
||||||
{
|
{
|
||||||
wchar_t buffer[512];
|
char buffer[512];
|
||||||
|
|
||||||
DWORD error_code = GetLastError();
|
DWORD error_code = GetLastError();
|
||||||
|
|
||||||
if (FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_FROM_HMODULE | FORMAT_MESSAGE_IGNORE_INSERTS, GetModuleHandle(L"winhttp.dll"), error_code,
|
if (FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_FROM_HMODULE | FORMAT_MESSAGE_IGNORE_INSERTS, GetModuleHandleA("winhttp.dll"), error_code,
|
||||||
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), buffer, lengthof(buffer), nullptr) == 0) {
|
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), buffer, sizeof(buffer), nullptr) == 0) {
|
||||||
return fmt::format("unknown error {}", error_code);
|
return fmt::format("unknown error {}", error_code);
|
||||||
}
|
}
|
||||||
|
|
||||||
return FS2OTTD(buffer);
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -81,12 +81,12 @@ const std::string &NetworkError::AsString() const
|
||||||
{
|
{
|
||||||
if (this->message.empty()) {
|
if (this->message.empty()) {
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
wchar_t buffer[512];
|
char buffer[512];
|
||||||
if (FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, nullptr, this->error,
|
if (FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, nullptr, this->error,
|
||||||
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), buffer, lengthof(buffer), nullptr) == 0) {
|
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), buffer, sizeof(buffer), nullptr) == 0) {
|
||||||
this->message.assign(fmt::format("Unknown error {}", this->error));
|
this->message.assign(fmt::format("Unknown error {}", this->error));
|
||||||
} else {
|
} else {
|
||||||
this->message.assign(FS2OTTD(buffer));
|
this->message.assign(buffer);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
/* Make strerror thread safe by locking access to it. There is a thread safe strerror_r, however
|
/* Make strerror thread safe by locking access to it. There is a thread safe strerror_r, however
|
||||||
|
|
|
@ -20,13 +20,13 @@ static std::string GetLoadError()
|
||||||
{
|
{
|
||||||
auto error_code = GetLastError();
|
auto error_code = GetLastError();
|
||||||
|
|
||||||
wchar_t buffer[512];
|
char buffer[512];
|
||||||
if (FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, nullptr, error_code,
|
if (FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, nullptr, error_code,
|
||||||
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), buffer, lengthof(buffer), nullptr) == 0) {
|
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), buffer, sizeof(buffer), nullptr) == 0) {
|
||||||
return fmt::format("Unknown error {}", error_code);
|
return fmt::format("Unknown error {}", error_code);
|
||||||
}
|
}
|
||||||
|
|
||||||
return FS2OTTD(buffer);
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *LibraryLoader::OpenLibrary(const std::string &filename)
|
void *LibraryLoader::OpenLibrary(const std::string &filename)
|
||||||
|
|
|
@ -239,7 +239,7 @@ public:
|
||||||
* [user_configured_value - random_deviation, user_configured_value + random_deviation] (inclusive).
|
* [user_configured_value - random_deviation, user_configured_value + random_deviation] (inclusive).
|
||||||
* random_deviation sign is ignored and the value is clamped in the range [0, MAX(int32_t)] (inclusive).
|
* random_deviation sign is ignored and the value is clamped in the range [0, MAX(int32_t)] (inclusive).
|
||||||
* The randomisation will happen just before the Script start.
|
* The randomisation will happen just before the Script start.
|
||||||
* Not allowed if the CONFIG_BOOLEAN flag is set, otherwise optional.
|
* Not allowed if the CONFIG_RANDOM flag is set, otherwise optional.
|
||||||
* - step_size The increase/decrease of the value every time the user
|
* - step_size The increase/decrease of the value every time the user
|
||||||
* clicks one of the up/down arrow buttons. Optional, default is 1.
|
* clicks one of the up/down arrow buttons. Optional, default is 1.
|
||||||
* - flags Bitmask of some flags, see ScriptConfigFlags. Required.
|
* - flags Bitmask of some flags, see ScriptConfigFlags. Required.
|
||||||
|
|
|
@ -379,18 +379,10 @@ struct ScriptSettingsWindow : public Window {
|
||||||
TextColour colour;
|
TextColour colour;
|
||||||
uint idx = 0;
|
uint idx = 0;
|
||||||
if (config_item.description.empty()) {
|
if (config_item.description.empty()) {
|
||||||
if (this->slot != OWNER_DEITY && !Company::IsValidID(this->slot) && config_item.random_deviation != 0) {
|
str = STR_JUST_STRING1;
|
||||||
str = STR_AI_SETTINGS_JUST_DEVIATION;
|
|
||||||
} else {
|
|
||||||
str = STR_JUST_STRING1;
|
|
||||||
}
|
|
||||||
colour = TC_ORANGE;
|
colour = TC_ORANGE;
|
||||||
} else {
|
} else {
|
||||||
if (this->slot != OWNER_DEITY && !Company::IsValidID(this->slot) && config_item.random_deviation != 0) {
|
str = STR_AI_SETTINGS_SETTING;
|
||||||
str = STR_AI_SETTINGS_SETTING_DEVIATION;
|
|
||||||
} else {
|
|
||||||
str = STR_AI_SETTINGS_SETTING;
|
|
||||||
}
|
|
||||||
colour = TC_LIGHT_BLUE;
|
colour = TC_LIGHT_BLUE;
|
||||||
SetDParamStr(idx++, config_item.description);
|
SetDParamStr(idx++, config_item.description);
|
||||||
}
|
}
|
||||||
|
@ -405,35 +397,13 @@ struct ScriptSettingsWindow : public Window {
|
||||||
DrawArrowButtons(br.left, y + button_y_offset, COLOUR_YELLOW, (this->clicked_button == i) ? 1 + (this->clicked_increase != rtl) : 0, editable && current_value > config_item.min_value, editable && current_value < config_item.max_value);
|
DrawArrowButtons(br.left, y + button_y_offset, COLOUR_YELLOW, (this->clicked_button == i) ? 1 + (this->clicked_increase != rtl) : 0, editable && current_value > config_item.min_value, editable && current_value < config_item.max_value);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this->slot == OWNER_DEITY || Company::IsValidID(this->slot) || config_item.random_deviation == 0) {
|
auto config_iterator = config_item.labels.find(current_value);
|
||||||
auto config_iterator = config_item.labels.find(current_value);
|
if (config_iterator != config_item.labels.end()) {
|
||||||
if (config_iterator != config_item.labels.end()) {
|
SetDParam(idx++, STR_JUST_RAW_STRING);
|
||||||
SetDParam(idx++, STR_JUST_RAW_STRING);
|
SetDParamStr(idx++, config_iterator->second);
|
||||||
SetDParamStr(idx++, config_iterator->second);
|
|
||||||
} else {
|
|
||||||
SetDParam(idx++, STR_JUST_INT);
|
|
||||||
SetDParam(idx++, current_value);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
int min_deviated = std::max(config_item.min_value, current_value - config_item.random_deviation);
|
SetDParam(idx++, STR_JUST_INT);
|
||||||
auto config_iterator = config_item.labels.find(min_deviated);
|
SetDParam(idx++, current_value);
|
||||||
if (config_iterator != config_item.labels.end()) {
|
|
||||||
SetDParam(idx++, STR_JUST_RAW_STRING);
|
|
||||||
SetDParamStr(idx++, config_iterator->second);
|
|
||||||
} else {
|
|
||||||
SetDParam(idx++, STR_JUST_INT);
|
|
||||||
SetDParam(idx++, min_deviated);
|
|
||||||
}
|
|
||||||
|
|
||||||
int max_deviated = std::min(config_item.max_value, current_value + config_item.random_deviation);
|
|
||||||
config_iterator = config_item.labels.find(max_deviated);
|
|
||||||
if (config_iterator != config_item.labels.end()) {
|
|
||||||
SetDParam(idx++, STR_JUST_RAW_STRING);
|
|
||||||
SetDParamStr(idx++, config_iterator->second);
|
|
||||||
} else {
|
|
||||||
SetDParam(idx++, STR_JUST_INT);
|
|
||||||
SetDParam(idx++, max_deviated);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -162,13 +162,6 @@ SQInteger ScriptInfo::AddSetting(HSQUIRRELVM vm)
|
||||||
}
|
}
|
||||||
sq_pop(vm, 1);
|
sq_pop(vm, 1);
|
||||||
|
|
||||||
/* Don't allow both random_deviation and SCRIPTCONFIG_BOOLEAN to
|
|
||||||
* be set for the same config item. */
|
|
||||||
if ((items & 0x200) != 0 && (config.flags & SCRIPTCONFIG_BOOLEAN) != 0) {
|
|
||||||
this->engine->ThrowError("setting both random_deviation and CONFIG_BOOLEAN is not allowed");
|
|
||||||
return SQ_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Reset the bit for random_deviation as it's optional. */
|
/* Reset the bit for random_deviation as it's optional. */
|
||||||
items &= ~0x200;
|
items &= ~0x200;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue