diff --git a/src/script/api/script_controller.cpp b/src/script/api/script_controller.cpp index 461a6c61be..feacf80cc5 100644 --- a/src/script/api/script_controller.cpp +++ b/src/script/api/script_controller.cpp @@ -95,6 +95,11 @@ ScriptController::~ScriptController() return ScriptObject::GetActiveInstance()->GetOpsTillSuspend(); } +/* static */ void ScriptController::DecreaseOps(int amount) +{ + Squirrel::DecreaseOps(ScriptObject::GetActiveInstance()->engine->GetVM(), amount); +} + /* static */ int ScriptController::GetSetting(const char *name) { return ScriptObject::GetActiveInstance()->GetSetting(name); diff --git a/src/script/api/script_controller.hpp b/src/script/api/script_controller.hpp index 79cb65a74f..06ed6d1e55 100644 --- a/src/script/api/script_controller.hpp +++ b/src/script/api/script_controller.hpp @@ -126,6 +126,11 @@ public: */ static int GetOpsTillSuspend(); + /** + * Decrease the number of operations the script can execute before being suspended. + */ + static void DecreaseOps(int amount); + /** * Get the value of one of your settings you set via info.nut. * @param name The name of the setting. diff --git a/src/script/api/script_town.cpp b/src/script/api/script_town.cpp index afe5614566..4b6eb6dc02 100644 --- a/src/script/api/script_town.cpp +++ b/src/script/api/script_town.cpp @@ -11,6 +11,7 @@ #include "script_town.hpp" #include "script_map.hpp" #include "script_error.hpp" +#include "script_controller.hpp" #include "../../town.h" #include "../../townname_func.h" #include "../../string_func.h" @@ -280,6 +281,8 @@ /* static */ bool ScriptTown::FoundTown(TileIndex tile, TownSize size, bool city, RoadLayout layout, Text *name) { + ScriptController::DecreaseOps(5000); + CCountedPtr counter(name); EnforcePrecondition(false, ScriptObject::GetCompany() == OWNER_DEITY || _settings_game.economy.found_town != TF_FORBIDDEN); @@ -301,6 +304,7 @@ } uint32 townnameparts; if (!GenerateTownName(&townnameparts)) { + ScriptController::DecreaseOps(50000); ScriptObject::SetLastError(ScriptError::ERR_NAME_IS_NOT_UNIQUE); return false; }