GS: Charge 5000 opcodes to call ScriptTown::FoundTown
This call is very expensive and calling it in a loop when it fails can consume all available CPU time Add a further 50000 charge if a town name cannot be generated
This commit is contained in:
@@ -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);
|
||||
|
@@ -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.
|
||||
|
@@ -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<Text> 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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user