diff --git a/src/script/script_instance.cpp b/src/script/script_instance.cpp index 5a42d72b0e..869adcaea3 100644 --- a/src/script/script_instance.cpp +++ b/src/script/script_instance.cpp @@ -258,7 +258,7 @@ void ScriptInstance::GameLoop() } ScriptObject::SetAllowDoCommand(true); /* Start the script by calling Start() */ - if (!this->engine->CallMethod(*this->instance, "Start", _settings_game.script.script_max_opcode_till_suspend) || !this->engine->IsSuspended()) this->Died(); + if (!this->engine->CallMethod(*this->instance, "Start", this->GetMaxOpsTillSuspend()) || !this->engine->IsSuspended()) this->Died(); } catch (Script_Suspend &e) { this->suspend = e.GetSuspendTime(); this->callback = e.GetSuspendCallback(); @@ -279,7 +279,7 @@ void ScriptInstance::GameLoop() /* Continue the VM */ try { - if (!this->engine->Resume(_settings_game.script.script_max_opcode_till_suspend)) this->Died(); + if (!this->engine->Resume(this->GetMaxOpsTillSuspend())) this->Died(); } catch (Script_Suspend &e) { this->suspend = e.GetSuspendTime(); this->callback = e.GetSuspendCallback(); @@ -581,7 +581,7 @@ void ScriptInstance::Pause() { /* Suspend script. */ HSQUIRRELVM vm = this->engine->GetVM(); - Squirrel::DecreaseOps(vm, _settings_game.script.script_max_opcode_till_suspend); + Squirrel::DecreaseOps(vm, this->GetOpsTillSuspend()); this->is_paused = true; } @@ -789,6 +789,15 @@ void ScriptInstance::LimitOpsTillSuspend(SQInteger suspend) } } +uint32 ScriptInstance::GetMaxOpsTillSuspend() const +{ + if (this->script_type == ST_GS && (_pause_mode & PM_PAUSED_GAME_SCRIPT) != PM_UNPAUSED) { + /* Boost opcodes till suspend when paused due to game script */ + return std::min(250000, _settings_game.script.script_max_opcode_till_suspend * 10); + } + return _settings_game.script.script_max_opcode_till_suspend; +} + bool ScriptInstance::DoCommandCallback(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint64 p3, uint32 cmd) { ScriptObject::ActiveInstance active(this); diff --git a/src/script/script_instance.hpp b/src/script/script_instance.hpp index 4c1d78e508..df59d31bcb 100644 --- a/src/script/script_instance.hpp +++ b/src/script/script_instance.hpp @@ -211,6 +211,8 @@ public: void LimitOpsTillSuspend(SQInteger suspend); + uint32 GetMaxOpsTillSuspend() const; + /** * DoCommand callback function for all commands executed by scripts. * @param result The result of the command.