src/ai/ai_squirrel.hpp
author truelight
Sat, 24 Mar 2007 14:56:31 +0000
branchnoai
changeset 9516 defc90b7898a
parent 9444 fd27df7ca2a0
child 9529 5f26f4bc574b
permissions -rw-r--r--
(svn r9428) [NoAI] -Fix: FindBestRoadVehicle returned always INVALID_ENGINE. It is more useful to return best_engine ;)
/* $Id$ */

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

#ifndef AI_SQUIRREL_HPP
#define AI_SQUIRREL_HPP

class AIControllerSquirrel: public AIController {
private:
	Squirrel *engine; ///< The Squirrel engine
	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 Start();
	/* virtual */ void Stop();

	uint GetTick() { return AIController::GetTick(); }
	void Sleep(uint ticks) { return AIController::Sleep(ticks); }
};

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

	/**
	 * The constructor for when a script makes an instance of the Factory class.
	 */
	static SQInteger FactoryConstructor(HSQUIRRELVM vm);

	/**
	 * Scans a dir to see if there are dirs in it which have a file called 'main.nut'.
	 *  If found it loads the script.
	 */
	void ScanDir(const char *dirname);

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 /* AI_SQUIRREL_HPP */