Merge branch 'master' into jgrpp

# Conflicts:
#	regression/regression/result.txt
#	src/autoreplace_cmd.cpp
#	src/industry_gui.cpp
#	src/landscape.cpp
#	src/network/network_content.cpp
#	src/newgrf_roadstop.cpp
#	src/pathfinder/yapf/yapf_ship.cpp
#	src/road_gui.cpp
#	src/saveload/ai_sl.cpp
#	src/saveload/saveload.h
#	src/saveload/vehicle_sl.cpp
#	src/station.cpp
#	src/station_gui.cpp
#	src/video/cocoa/cocoa_ogl.h
#	src/video/sdl2_opengl_v.h
#	src/video/video_driver.hpp
#	src/video/win32_v.h
#	src/widget_type.h
#	src/widgets/dropdown.cpp
#	src/widgets/dropdown_type.h
#	src/window.cpp
This commit is contained in:
Jonathan G Rennison
2024-02-19 18:50:33 +00:00
119 changed files with 4346 additions and 2129 deletions

View File

@@ -27,9 +27,9 @@ public:
/**
* Start a new AI company.
* @param company At which slot the AI company should start.
* @param rerandomise_ai Whether to rerandomise the configured AI.
* @param deviate Whether to apply random deviation to the configured AI.
*/
static void StartNew(CompanyID company, bool rerandomise_ai = true);
static void StartNew(CompanyID company, bool deviate = true);
/**
* Called every game-tick to let AIs do something.

View File

@@ -8,6 +8,7 @@
/** @file ai_config.cpp Implementation of AIConfig. */
#include "../stdafx.h"
#include "../company_base.h"
#include "../settings_type.h"
#include "../string_func.h"
#include "ai.hpp"
@@ -24,6 +25,10 @@
if (source == SSS_FORCE_NEWGAME || (source == SSS_DEFAULT && _game_mode == GM_MENU)) {
config = &_settings_newgame.ai_config[company];
} else {
if (source != SSS_FORCE_GAME) {
Company *c = Company::GetIfValid(company);
if (c != nullptr && c->ai_config != nullptr) return c->ai_config.get();
}
config = &_settings_game.ai_config[company];
}
if (*config == nullptr) *config = new AIConfig();

View File

@@ -35,27 +35,32 @@
return !_networking || (_network_server && _settings_game.ai.ai_in_multiplayer);
}
/* static */ void AI::StartNew(CompanyID company, bool rerandomise_ai)
/* static */ void AI::StartNew(CompanyID company, bool deviate)
{
assert(Company::IsValidID(company));
/* Clients shouldn't start AIs */
if (_networking && !_network_server) return;
AIConfig *config = AIConfig::GetConfig(company, AIConfig::SSS_FORCE_GAME);
Backup<CompanyID> cur_company(_current_company, company, FILE_LINE);
Company *c = Company::Get(company);
AIConfig *config = c->ai_config.get();
if (config == nullptr) {
c->ai_config = std::make_unique<AIConfig>(AIConfig::GetConfig(company, AIConfig::SSS_FORCE_GAME));
config = c->ai_config.get();
}
AIInfo *info = config->GetInfo();
if (info == nullptr || (rerandomise_ai && config->IsRandom())) {
if (info == nullptr) {
info = AI::scanner_info->SelectRandomAI();
assert(info != nullptr);
/* Load default data and store the name in the settings */
config->Change(info->GetName(), -1, false, true);
config->Change(info->GetName(), -1, false);
}
if (rerandomise_ai) config->AddRandomDeviation();
if (deviate) config->AddRandomDeviation(company);
config->AnchorUnchangeableSettings();
Backup<CompanyID> cur_company(_current_company, company, FILE_LINE);
Company *c = Company::Get(company);
c->ai_info = info;
assert(c->ai_instance == nullptr);
c->ai_instance = new AIInstance();
@@ -114,11 +119,11 @@
delete c->ai_instance;
c->ai_instance = nullptr;
c->ai_info = nullptr;
c->ai_config.reset();
cur_company.Restore();
InvalidateWindowClassesData(WC_SCRIPT_DEBUG, -1);
CloseWindowById(WC_SCRIPT_SETTINGS, company);
}
/* static */ void AI::Pause(CompanyID company)

View File

@@ -65,7 +65,7 @@ void AIInstance::Died()
ShowScriptDebugWindow(_current_company);
const AIInfo *info = AIConfig::GetConfig(_current_company, AIConfig::SSS_FORCE_GAME)->GetInfo();
const AIInfo *info = AIConfig::GetConfig(_current_company)->GetInfo();
if (info != nullptr) {
ShowErrorMessage(STR_ERROR_AI_PLEASE_REPORT_CRASH, INVALID_STRING_ID, WL_WARNING);