Merge branch 'master' into jgrpp
# Conflicts: # .github/workflows/ci-build.yml # .github/workflows/release-linux.yml # .github/workflows/release-macos.yml # .github/workflows/release-source.yml # .github/workflows/release.yml # CMakeLists.txt # COMPILING.md # src/ai/ai_core.cpp # src/ai/ai_gui.cpp # src/bridge_gui.cpp # src/company_gui.cpp # src/console_cmds.cpp # src/core/CMakeLists.txt # src/core/smallmap_type.hpp # src/disaster_vehicle.h # src/effectvehicle_base.h # src/fontcache.cpp # src/game/game_core.cpp # src/game/game_gui.cpp # src/gamelog.cpp # src/gamelog_internal.h # src/group_gui.cpp # src/linkgraph/linkgraph.h # src/misc.cpp # src/network/core/config.h # src/network/core/udp.cpp # src/network/network_chat_gui.cpp # src/network/network_content_gui.cpp # src/network/network_gui.cpp # src/newgrf.cpp # src/newgrf_gui.cpp # src/newgrf_profiling.cpp # src/newgrf_profiling.h # src/object_gui.cpp # src/openttd.cpp # src/openttd.h # src/order_gui.cpp # src/os/windows/font_win32.cpp # src/rail_gui.cpp # src/road.cpp # src/road_gui.cpp # src/saveload/afterload.cpp # src/saveload/saveload.h # src/script/api/script_controller.cpp # src/script/api/script_roadtypelist.cpp # src/script/script_config.cpp # src/script/script_config.hpp # src/script/script_instance.cpp # src/script/script_scanner.cpp # src/script/squirrel.cpp # src/script/squirrel_helper.hpp # src/settings_gui.cpp # src/settings_internal.h # src/settings_type.h # src/table/settings/network_private_settings.ini # src/timetable_gui.cpp # src/vehicle.cpp # src/vehicle_base.h # src/window_gui.h
This commit is contained in:
@@ -52,7 +52,6 @@ static void PrintFunc(bool error_msg, const SQChar *message)
|
||||
|
||||
ScriptInstance::ScriptInstance(const char *APIName, ScriptType script_type) :
|
||||
engine(nullptr),
|
||||
versionAPI(nullptr),
|
||||
controller(nullptr),
|
||||
storage(nullptr),
|
||||
instance(nullptr),
|
||||
@@ -72,7 +71,7 @@ ScriptInstance::ScriptInstance(const char *APIName, ScriptType script_type) :
|
||||
this->engine->SetPrintFunction(&PrintFunc);
|
||||
}
|
||||
|
||||
void ScriptInstance::Initialize(const char *main_script, const char *instance_name, CompanyID company)
|
||||
void ScriptInstance::Initialize(const std::string &main_script, const std::string &instance_name, CompanyID company)
|
||||
{
|
||||
ScriptObject::ActiveInstance active(this);
|
||||
|
||||
@@ -85,7 +84,7 @@ void ScriptInstance::Initialize(const char *main_script, const char *instance_na
|
||||
try {
|
||||
ScriptObject::SetAllowDoCommand(false);
|
||||
/* Load and execute the script for this script */
|
||||
if (strcmp(main_script, "%_dummy") == 0) {
|
||||
if (main_script == "%_dummy") {
|
||||
this->LoadDummyScript();
|
||||
} else if (!this->engine->LoadScript(main_script) || this->engine->IsSuspended()) {
|
||||
if (this->engine->IsSuspended()) ScriptLog::Error("This script took too long to load script. AI is not started.");
|
||||
@@ -94,7 +93,7 @@ void ScriptInstance::Initialize(const char *main_script, const char *instance_na
|
||||
}
|
||||
|
||||
if (this->script_type == ScriptType::GS) {
|
||||
if (strcmp(instance_name, "BeeRewardClass") == 0) {
|
||||
if (instance_name == "BeeRewardClass") {
|
||||
this->LoadCompatibilityScripts("brgs", GAME_DIR);
|
||||
}
|
||||
}
|
||||
@@ -112,7 +111,7 @@ void ScriptInstance::Initialize(const char *main_script, const char *instance_na
|
||||
ScriptObject::SetAllowDoCommand(true);
|
||||
} catch (Script_FatalError &e) {
|
||||
this->is_dead = true;
|
||||
this->engine->ThrowError(e.GetErrorMessage().c_str());
|
||||
this->engine->ThrowError(e.GetErrorMessage());
|
||||
this->engine->ResumeError();
|
||||
this->Died();
|
||||
}
|
||||
@@ -123,12 +122,12 @@ void ScriptInstance::RegisterAPI()
|
||||
squirrel_register_std(this->engine);
|
||||
}
|
||||
|
||||
bool ScriptInstance::LoadCompatibilityScripts(const char *api_version, Subdirectory dir)
|
||||
bool ScriptInstance::LoadCompatibilityScripts(const std::string &api_version, Subdirectory dir)
|
||||
{
|
||||
const char *api_vers[] = { "1.2", "1.3", "1.4", "1.5", "1.6", "1.7", "1.8", "1.9", "1.10", "1.11", "12", "13", "14" };
|
||||
uint api_idx = 0;
|
||||
for (; api_idx < lengthof(api_vers) ; api_idx++) {
|
||||
if (strcmp(api_version, api_vers[api_idx]) == 0) break;
|
||||
if (api_version == api_vers[api_idx]) break;
|
||||
}
|
||||
if (api_idx < 12) {
|
||||
/* 13 and below */
|
||||
@@ -136,13 +135,13 @@ bool ScriptInstance::LoadCompatibilityScripts(const char *api_version, Subdirect
|
||||
}
|
||||
|
||||
char script_name[32];
|
||||
seprintf(script_name, lastof(script_name), "compat_%s.nut", api_version);
|
||||
seprintf(script_name, lastof(script_name), "compat_%s.nut", api_version.c_str());
|
||||
for (Searchpath sp : _valid_searchpaths) {
|
||||
std::string buf = FioGetDirectory(sp, dir);
|
||||
buf += script_name;
|
||||
if (!FileExists(buf)) continue;
|
||||
|
||||
if (this->engine->LoadScript(buf.c_str())) return true;
|
||||
if (this->engine->LoadScript(buf)) return true;
|
||||
|
||||
ScriptLog::Error("Failed to load API compatibility script");
|
||||
DEBUG(script, 0, "Error compiling / running API compatibility script: %s", buf.c_str());
|
||||
@@ -265,7 +264,7 @@ void ScriptInstance::GameLoop()
|
||||
this->callback = e.GetSuspendCallback();
|
||||
} catch (Script_FatalError &e) {
|
||||
this->is_dead = true;
|
||||
this->engine->ThrowError(e.GetErrorMessage().c_str());
|
||||
this->engine->ThrowError(e.GetErrorMessage());
|
||||
this->engine->ResumeError();
|
||||
this->Died();
|
||||
}
|
||||
@@ -286,7 +285,7 @@ void ScriptInstance::GameLoop()
|
||||
this->callback = e.GetSuspendCallback();
|
||||
} catch (Script_FatalError &e) {
|
||||
this->is_dead = true;
|
||||
this->engine->ThrowError(e.GetErrorMessage().c_str());
|
||||
this->engine->ThrowError(e.GetErrorMessage());
|
||||
this->engine->ResumeError();
|
||||
this->Died();
|
||||
}
|
||||
@@ -544,7 +543,7 @@ void ScriptInstance::Save()
|
||||
/* If we don't mark the script as dead here cleaning up the squirrel
|
||||
* stack could throw Script_FatalError again. */
|
||||
this->is_dead = true;
|
||||
this->engine->ThrowError(e.GetErrorMessage().c_str());
|
||||
this->engine->ThrowError(e.GetErrorMessage());
|
||||
this->engine->ResumeError();
|
||||
SaveEmpty();
|
||||
/* We can't kill the script here, so mark it as crashed (not dead) and
|
||||
|
Reference in New Issue
Block a user