mirror of https://github.com/OpenTTD/OpenTTD
(svn r23367) -Codechange: refactor GetSetting to ScriptInstance, to avoid global variable in script_controller
parent
3e6d026129
commit
880f377fa6
|
@ -235,6 +235,11 @@ void AIInstance::LoadDummyScript()
|
||||||
Script_CreateDummy(this->engine->GetVM(), STR_ERROR_AI_NO_AI_FOUND, "AI");
|
Script_CreateDummy(this->engine->GetVM(), STR_ERROR_AI_NO_AI_FOUND, "AI");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int AIInstance::GetSetting(const char *name)
|
||||||
|
{
|
||||||
|
return AIConfig::GetConfig(_current_company)->GetSetting(name);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* DoCommand callback function for all commands executed by AIs.
|
* DoCommand callback function for all commands executed by AIs.
|
||||||
* @param result The result of the command.
|
* @param result The result of the command.
|
||||||
|
|
|
@ -26,6 +26,8 @@ public:
|
||||||
*/
|
*/
|
||||||
void Initialize(class AIInfo *info);
|
void Initialize(class AIInfo *info);
|
||||||
|
|
||||||
|
/* virtual */ int GetSetting(const char *name);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const char *versionAPI; ///< Current API used by this script.
|
const char *versionAPI; ///< Current API used by this script.
|
||||||
|
|
||||||
|
|
|
@ -11,14 +11,11 @@
|
||||||
|
|
||||||
#include "../../stdafx.h"
|
#include "../../stdafx.h"
|
||||||
#include "../../string_func.h"
|
#include "../../string_func.h"
|
||||||
#include "../../company_base.h"
|
|
||||||
#include "../../company_func.h"
|
|
||||||
#include "../../script/squirrel.hpp"
|
#include "../../script/squirrel.hpp"
|
||||||
#include "../../rev.h"
|
#include "../../rev.h"
|
||||||
|
|
||||||
#include "script_controller.hpp"
|
#include "script_controller.hpp"
|
||||||
#include "../../ai/ai_instance.hpp"
|
#include "../../ai/ai_instance.hpp"
|
||||||
#include "../../ai/ai_config.hpp"
|
|
||||||
#include "../../ai/ai.hpp"
|
#include "../../ai/ai.hpp"
|
||||||
#include "../script_fatalerror.hpp"
|
#include "../script_fatalerror.hpp"
|
||||||
#include "../script_info.hpp"
|
#include "../script_info.hpp"
|
||||||
|
@ -78,7 +75,7 @@ ScriptController::~ScriptController()
|
||||||
|
|
||||||
/* static */ int ScriptController::GetSetting(const char *name)
|
/* static */ int ScriptController::GetSetting(const char *name)
|
||||||
{
|
{
|
||||||
return AIConfig::GetConfig(_current_company)->GetSetting(name);
|
return ScriptObject::GetActiveInstance()->GetSetting(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* static */ uint ScriptController::GetVersion()
|
/* static */ uint ScriptController::GetVersion()
|
||||||
|
|
|
@ -12,10 +12,12 @@
|
||||||
#include "../../stdafx.h"
|
#include "../../stdafx.h"
|
||||||
#include "../../script/squirrel.hpp"
|
#include "../../script/squirrel.hpp"
|
||||||
#include "../../command_func.h"
|
#include "../../command_func.h"
|
||||||
|
#include "../../company_func.h"
|
||||||
#include "../../network/network.h"
|
#include "../../network/network.h"
|
||||||
#include "../../tunnelbridge.h"
|
#include "../../tunnelbridge.h"
|
||||||
|
|
||||||
#include "../script_storage.hpp"
|
#include "../script_storage.hpp"
|
||||||
|
#include "../../ai/ai_config.hpp"
|
||||||
#include "../../ai/ai_instance.hpp"
|
#include "../../ai/ai_instance.hpp"
|
||||||
#include "../script_fatalerror.hpp"
|
#include "../script_fatalerror.hpp"
|
||||||
#include "../script_suspend.hpp"
|
#include "../script_suspend.hpp"
|
||||||
|
|
|
@ -36,6 +36,13 @@ public:
|
||||||
*/
|
*/
|
||||||
void Initialize(const char *main_script, const char *instance_name);
|
void Initialize(const char *main_script, const char *instance_name);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the value of a setting of the current instance.
|
||||||
|
* @param name The name of the setting.
|
||||||
|
* @return the value for the setting, or -1 if the setting is not known.
|
||||||
|
*/
|
||||||
|
virtual int GetSetting(const char *name) = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A script in multiplayer waits for the server to handle his DoCommand.
|
* A script in multiplayer waits for the server to handle his DoCommand.
|
||||||
* It keeps waiting for this until this function is called.
|
* It keeps waiting for this until this function is called.
|
||||||
|
|
Loading…
Reference in New Issue