Changeset - r26641:01889b29735a
[Not reviewed]
master
0 4 0
Loïc Guilloux - 18 months ago 2022-12-15 20:43:07
glx22@users.noreply.github.com
Fix #10206: Disable scripts in intro game (#10241)
4 files changed with 11 insertions and 2 deletions:
0 comments (0 inline, 0 general)
src/ai/ai_instance.cpp
Show inline comments
 
@@ -52,24 +52,27 @@ void AIInstance::RegisterAPI()
 
	ScriptInstance::RegisterAPI();
 

	
 
	/* Register all classes */
 
	SQAI_RegisterAll(this->engine);
 

	
 
	if (!this->LoadCompatibilityScripts(this->versionAPI, AI_DIR)) this->Died();
 
}
 

	
 
void AIInstance::Died()
 
{
 
	ScriptInstance::Died();
 

	
 
	/* Intro is not supposed to use AI, but it may have 'dummy' AI which instant dies. */
 
	if (_game_mode == GM_MENU) return;
 

	
 
	ShowAIDebugWindow(_current_company);
 

	
 
	const AIInfo *info = AIConfig::GetConfig(_current_company, AIConfig::SSS_FORCE_GAME)->GetInfo();
 
	if (info != nullptr) {
 
		ShowErrorMessage(STR_ERROR_AI_PLEASE_REPORT_CRASH, INVALID_STRING_ID, WL_WARNING);
 

	
 
		if (info->GetURL() != nullptr) {
 
			ScriptLog::Info("Please report the error to the following URL:");
 
			ScriptLog::Info(info->GetURL());
 
		}
 
	}
 
}
src/ai/ai_scanner.cpp
Show inline comments
 
/*
 
 * This file is part of OpenTTD.
 
 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
 
 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
 
 */
 

	
 
/** @file ai_scanner.cpp allows scanning AI scripts */
 

	
 
#include "../stdafx.h"
 
#include "../debug.h"
 
#include "../network/network.h"
 
#include "../openttd.h"
 
#include "../core/random_func.hpp"
 

	
 
#include "../script/squirrel_class.hpp"
 
#include "ai_info.hpp"
 
#include "ai_scanner.hpp"
 

	
 
#include "../safeguards.h"
 

	
 

	
 
AIScannerInfo::AIScannerInfo() :
 
	ScriptScanner(),
 
	info_dummy(nullptr)
 
@@ -50,24 +51,29 @@ AIScannerInfo::~AIScannerInfo()
 
void AIScannerInfo::GetScriptName(ScriptInfo *info, char *name, const char *last)
 
{
 
	seprintf(name, last, "%s", info->GetName());
 
}
 

	
 
void AIScannerInfo::RegisterAPI(class Squirrel *engine)
 
{
 
	AIInfo::RegisterAPI(engine);
 
}
 

	
 
AIInfo *AIScannerInfo::SelectRandomAI() const
 
{
 
	if (_game_mode == GM_MENU) {
 
		Debug(script, 0, "The intro game should not use AI, loading 'dummy' AI.");
 
		return this->info_dummy;
 
	}
 

	
 
	uint num_random_ais = 0;
 
	for (const auto &item : info_single_list) {
 
		AIInfo *i = static_cast<AIInfo *>(item.second);
 
		if (i->UseAsRandomAI()) num_random_ais++;
 
	}
 

	
 
	if (num_random_ais == 0) {
 
		Debug(script, 0, "No suitable AI found, loading 'dummy' AI.");
 
		return this->info_dummy;
 
	}
 

	
 
	/* Find a random AI */
src/saveload/ai_sl.cpp
Show inline comments
 
@@ -68,25 +68,25 @@ struct AIPLChunkHandler : ChunkHandler {
 
		for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; c++) {
 
			AIConfig::GetConfig(c, AIConfig::SSS_FORCE_GAME)->Change(nullptr);
 
		}
 

	
 
		CompanyID index;
 
		while ((index = (CompanyID)SlIterateArray()) != (CompanyID)-1) {
 
			if (index >= MAX_COMPANIES) SlErrorCorrupt("Too many AI configs");
 

	
 
			_ai_saveload_is_random = false;
 
			_ai_saveload_version = -1;
 
			SlObject(nullptr, slt);
 

	
 
			if (_networking && !_network_server) {
 
			if (_game_mode == GM_MENU || (_networking && !_network_server)) {
 
				if (Company::IsValidAiID(index)) AIInstance::LoadEmpty();
 
				continue;
 
			}
 

	
 
			AIConfig *config = AIConfig::GetConfig(index, AIConfig::SSS_FORCE_GAME);
 
			if (_ai_saveload_name.empty()) {
 
				/* A random AI. */
 
				config->Change(nullptr, -1, false, true);
 
			} else {
 
				config->Change(_ai_saveload_name.c_str(), _ai_saveload_version, false, _ai_saveload_is_random);
 
				if (!config->HasScript()) {
 
					/* No version of the AI available that can load the data. Try to load the
src/saveload/game_sl.cpp
Show inline comments
 
@@ -60,25 +60,25 @@ struct GSDTChunkHandler : ChunkHandler {
 
	void Load() const override
 
	{
 
		const std::vector<SaveLoad> slt = SlCompatTableHeader(_game_script_desc, _game_script_sl_compat);
 

	
 
		/* Free all current data */
 
		GameConfig::GetConfig(GameConfig::SSS_FORCE_GAME)->Change(nullptr);
 

	
 
		if (SlIterateArray() == -1) return;
 

	
 
		_game_saveload_version = -1;
 
		SlObject(nullptr, slt);
 

	
 
		if (_networking && !_network_server) {
 
		if (_game_mode == GM_MENU || (_networking && !_network_server)) {
 
			GameInstance::LoadEmpty();
 
			if (SlIterateArray() != -1) SlErrorCorrupt("Too many GameScript configs");
 
			return;
 
		}
 

	
 
		GameConfig *config = GameConfig::GetConfig(GameConfig::SSS_FORCE_GAME);
 
		if (!_game_saveload_name.empty()) {
 
			config->Change(_game_saveload_name.c_str(), _game_saveload_version, false, _game_saveload_is_random);
 
			if (!config->HasScript()) {
 
				/* No version of the GameScript available that can load the data. Try to load the
 
				 * latest version of the GameScript instead. */
 
				config->Change(_game_saveload_name.c_str(), -1, false, _game_saveload_is_random);
0 comments (0 inline, 0 general)