src/ai/squirrel/squirrel.hpp
author truelight
Thu, 15 Mar 2007 14:50:03 +0000
branchnoai
changeset 9410 286fcd8edc64
parent 9404 ef9e171617a3
child 9411 29c9dfcdb8e9
permissions -rw-r--r--
(svn r9208) [NoAI] -Add: keep track of which script added which class, so we know
which script to load when an AI starts
-Fix: comply with code-style by adding /* virtual */ in front of virtual
functions that are declared
/* $Id$ */

/** @file squirrel.hpp declarations of the class for squirrel loader */

#ifndef SQUIRREL_HPP
#define SQUIRREL_HPP

#ifdef _UNICODE
/* Disable unicode for squirrel to allow compilation with MINGW
 * and simplify coding for WIN32 (squirrel headers miss a lot of "string" functions)
 */
#undef _UNICODE
#endif
#include <squirrel.h>
#include "../core/ai_controller.hpp"
#include "../core/ai_factory.hpp"
#include "engine.hpp"

class AIControllerSquirrel: public AIController {
private:
	SquirrelEngine *engine; ///< The SquirrelEngine
	HSQOBJECT SQ_instance;  ///< The internal instance of squirrel

	/**
	 * Registers all our classes, so it can be used from Squirrel.
	 */
	void RegisterClasses();

public:
	AIControllerSquirrel(const char *script_dir, const char *class_name);
	~AIControllerSquirrel();

	/* virtual */ void GameLoop();

	uint GetTick() { return AIController::GetTick(); }
};

class FSquirrel: public AIFactory<FSquirrel> {
private:
	SquirrelEngine *engine; ///< The SquirrelEngine
	const char *current_script; ///< Temporary variable to know which script defines which class

	static SQInteger FactoryConstructor(HSQUIRRELVM vm);

public:
	~FSquirrel();

	/* virtual */ const char   *GetAuthor()      { return "OpenTTD Dev Team"; }
	/* virtual */ const char   *GetName()        { return "Squirrel"; }
	/* virtual */ const char   *GetDescription() { return "Squirrel Module for loading scripts"; }
	/* virtual */ int           GetVersion()     { return 0; }
	/* virtual */ const char   *GetDate()        { return ""; }
	/* virtual */ AIController *CreateInstance() { return NULL; }
	/* virtual */ bool          AllowStartup()   { return false; }
	/* virtual */ void          Initializer();
};

#endif /* SQUIRREL_HPP */