Changeset - r18514:5b2abc88a36c
[Not reviewed]
master
0 4 0
truebrain - 13 years ago 2011-11-29 23:27:08
truebrain@openttd.org
(svn r23368) -Codechange: move FindLibrary down a few layers, so there is no layer violation anymore
4 files changed with 16 insertions and 2 deletions:
0 comments (0 inline, 0 general)
src/ai/ai_instance.cpp
Show inline comments
 
@@ -15,12 +15,13 @@
 
#include "../gui.h"
 

	
 
#include "../script/squirrel_class.hpp"
 

	
 
#include "ai_config.hpp"
 
#include "ai_gui.hpp"
 
#include "ai.hpp"
 

	
 
#include "../script/script_fatalerror.hpp"
 
#include "../script/script_suspend.hpp"
 
#include "../script/script_storage.hpp"
 
#include "ai_info.hpp"
 
#include "ai_instance.hpp"
 
@@ -237,12 +238,17 @@ void AIInstance::LoadDummyScript()
 

	
 
int AIInstance::GetSetting(const char *name)
 
{
 
	return AIConfig::GetConfig(_current_company)->GetSetting(name);
 
}
 

	
 
ScriptInfo *AIInstance::FindLibrary(const char *library, int version)
 
{
 
	return (ScriptInfo *)AI::FindLibrary(library, version);
 
}
 

	
 
/**
 
 * DoCommand callback function for all commands executed by AIs.
 
 * @param result The result of the command.
 
 * @param tile The tile on which the command was executed.
 
 * @param p1 p1 as given to DoCommandPInternal.
 
 * @param p2 p2 as given to DoCommandPInternal.
src/ai/ai_instance.hpp
Show inline comments
 
@@ -24,12 +24,13 @@ public:
 
	 * Initialize the AI and prepare it for its first run.
 
	 * @param info The AI to create the instance of.
 
	 */
 
	void Initialize(class AIInfo *info);
 

	
 
	/* virtual */ int GetSetting(const char *name);
 
	/* virtual */ ScriptInfo *FindLibrary(const char *library, int version);
 

	
 
private:
 
	const char *versionAPI; ///< Current API used by this script.
 

	
 
	/* virtual */ void RegisterAPI();
 
	/* virtual */ void Died();
src/script/api/script_controller.cpp
Show inline comments
 
@@ -13,13 +13,12 @@
 
#include "../../string_func.h"
 
#include "../../script/squirrel.hpp"
 
#include "../../rev.h"
 

	
 
#include "script_controller.hpp"
 
#include "../../ai/ai_instance.hpp"
 
#include "../../ai/ai.hpp"
 
#include "../script_fatalerror.hpp"
 
#include "../script_info.hpp"
 
#include "../script_suspend.hpp"
 
#include "script_log.hpp"
 

	
 
/* static */ void ScriptController::SetCommandDelay(int ticks)
 
@@ -91,13 +90,13 @@ ScriptController::~ScriptController()
 

	
 
	/* Internally we store libraries as 'library.version' */
 
	char library_name[1024];
 
	snprintf(library_name, sizeof(library_name), "%s.%d", library, version);
 
	strtolower(library_name);
 

	
 
	ScriptInfo *lib = (ScriptInfo *)AI::FindLibrary(library, version);
 
	ScriptInfo *lib = ScriptObject::GetActiveInstance()->FindLibrary(library, version);
 
	if (lib == NULL) {
 
		char error[1024];
 
		snprintf(error, sizeof(error), "couldn't find library '%s' with version %d", library, version);
 
		throw sq_throwerror(vm, OTTD2SQ(error));
 
	}
 

	
src/script/script_instance.hpp
Show inline comments
 
@@ -41,12 +41,20 @@ public:
 
	 * @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;
 

	
 
	/**
 
	 * Find a library.
 
	 * @param library The library name to find.
 
	 * @param version The version the library should have.
 
	 * @return The library if found, NULL otherwise.
 
	 */
 
	virtual class ScriptInfo *FindLibrary(const char *library, int version) = 0;
 

	
 
	/**
 
	 * A script in multiplayer waits for the server to handle his DoCommand.
 
	 *  It keeps waiting for this until this function is called.
 
	 */
 
	void Continue();
 

	
 
	/**
0 comments (0 inline, 0 general)