src/ai/ai_squirrel.hpp
author truebrain
Tue, 26 Feb 2008 21:35:22 +0000
branchnoai
changeset 9782 e8d8d8894f23
parent 9529 5f26f4bc574b
child 9789 33d3214a2fce
permissions -rw-r--r--
(svn r12277) [NoAI] -Change: overlay GlobalPointer with local instance access and create sub-node to contain data
[NoAI] -Change: relay PrintFunc to redirect via overlay and supply AIController with Print, in order to establish bypass of the log created by the AI
[/STARTREK VOYAGER]
9365
c3d08e0b1083 (svn r9151) [NoAI] -Add: added squirrel module that loads squirrel scripts and
truelight
parents:
diff changeset
     1
/* $Id$ */
c3d08e0b1083 (svn r9151) [NoAI] -Add: added squirrel module that loads squirrel scripts and
truelight
parents:
diff changeset
     2
c3d08e0b1083 (svn r9151) [NoAI] -Add: added squirrel module that loads squirrel scripts and
truelight
parents:
diff changeset
     3
/** @file squirrel.hpp declarations of the class for squirrel loader */
c3d08e0b1083 (svn r9151) [NoAI] -Add: added squirrel module that loads squirrel scripts and
truelight
parents:
diff changeset
     4
9422
33efcc5f1b09 (svn r9223) [NoAI] -Change: moved squirrel/engine.cpp to squirrel.cpp in root
truelight
parents: 9411
diff changeset
     5
#ifndef AI_SQUIRREL_HPP
33efcc5f1b09 (svn r9223) [NoAI] -Change: moved squirrel/engine.cpp to squirrel.cpp in root
truelight
parents: 9411
diff changeset
     6
#define AI_SQUIRREL_HPP
9365
c3d08e0b1083 (svn r9151) [NoAI] -Add: added squirrel module that loads squirrel scripts and
truelight
parents:
diff changeset
     7
9404
ef9e171617a3 (svn r9201) [NoAI] -Change: make adding a default-constructor for DefSQClass optional
truelight
parents: 9395
diff changeset
     8
class AIControllerSquirrel: public AIController {
9365
c3d08e0b1083 (svn r9151) [NoAI] -Add: added squirrel module that loads squirrel scripts and
truelight
parents:
diff changeset
     9
private:
9422
33efcc5f1b09 (svn r9223) [NoAI] -Change: moved squirrel/engine.cpp to squirrel.cpp in root
truelight
parents: 9411
diff changeset
    10
	Squirrel *engine; ///< The Squirrel engine
9404
ef9e171617a3 (svn r9201) [NoAI] -Change: make adding a default-constructor for DefSQClass optional
truelight
parents: 9395
diff changeset
    11
	HSQOBJECT SQ_instance;  ///< The internal instance of squirrel
9375
8bbd77b18de4 (svn r9163) [NoAI] -Codechange: put AddMethod in his own function, so calling often is easier
truelight
parents: 9373
diff changeset
    12
8bbd77b18de4 (svn r9163) [NoAI] -Codechange: put AddMethod in his own function, so calling often is easier
truelight
parents: 9373
diff changeset
    13
	/**
9373
d03563181088 (svn r9160) [NoAI] -Add: added AIController for Squirrel; all AIs, C++ or Squirrel, should extend this class
truelight
parents: 9365
diff changeset
    14
	 * Registers all our classes, so it can be used from Squirrel.
d03563181088 (svn r9160) [NoAI] -Add: added AIController for Squirrel; all AIs, C++ or Squirrel, should extend this class
truelight
parents: 9365
diff changeset
    15
	 */
d03563181088 (svn r9160) [NoAI] -Add: added AIController for Squirrel; all AIs, C++ or Squirrel, should extend this class
truelight
parents: 9365
diff changeset
    16
	void RegisterClasses();
d03563181088 (svn r9160) [NoAI] -Add: added AIController for Squirrel; all AIs, C++ or Squirrel, should extend this class
truelight
parents: 9365
diff changeset
    17
9404
ef9e171617a3 (svn r9201) [NoAI] -Change: make adding a default-constructor for DefSQClass optional
truelight
parents: 9395
diff changeset
    18
public:
9529
5f26f4bc574b (svn r9450) [NoAI] -Fix: don't allow static-method calls from SQ to non-static functions
truelight
parents: 9444
diff changeset
    19
	static const char *GetClassName() { return "AIController"; }
5f26f4bc574b (svn r9450) [NoAI] -Fix: don't allow static-method calls from SQ to non-static functions
truelight
parents: 9444
diff changeset
    20
9404
ef9e171617a3 (svn r9201) [NoAI] -Change: make adding a default-constructor for DefSQClass optional
truelight
parents: 9395
diff changeset
    21
	AIControllerSquirrel(const char *script_dir, const char *class_name);
ef9e171617a3 (svn r9201) [NoAI] -Change: make adding a default-constructor for DefSQClass optional
truelight
parents: 9395
diff changeset
    22
	~AIControllerSquirrel();
9377
3f1327677bcd (svn r9166) [NoAI] -Add: added destructor code, so we can do things there in the future
truelight
parents: 9375
diff changeset
    23
9441
03da911c8d5f (svn r9255) [NoAI] -Add: each AI now runs in a seperate thread. The main thread is suspended if any AI thread is running, only one AI thread runs at the time.
truelight
parents: 9431
diff changeset
    24
	/* virtual */ void Start();
9444
fd27df7ca2a0 (svn r9260) [NoAI] -Codechange: do the AI threading properly using a mutex and condition signalling.
rubidium
parents: 9441
diff changeset
    25
	/* virtual */ void Stop();
9373
d03563181088 (svn r9160) [NoAI] -Add: added AIController for Squirrel; all AIs, C++ or Squirrel, should extend this class
truelight
parents: 9365
diff changeset
    26
9404
ef9e171617a3 (svn r9201) [NoAI] -Change: make adding a default-constructor for DefSQClass optional
truelight
parents: 9395
diff changeset
    27
	uint GetTick() { return AIController::GetTick(); }
9441
03da911c8d5f (svn r9255) [NoAI] -Add: each AI now runs in a seperate thread. The main thread is suspended if any AI thread is running, only one AI thread runs at the time.
truelight
parents: 9431
diff changeset
    28
	void Sleep(uint ticks) { return AIController::Sleep(ticks); }
9782
e8d8d8894f23 (svn r12277) [NoAI] -Change: overlay GlobalPointer with local instance access and create sub-node to contain data
truebrain
parents: 9529
diff changeset
    29
	static void PrintFunc(bool error_msg, const char *message) { AIController::Print(error_msg, message); }
9404
ef9e171617a3 (svn r9201) [NoAI] -Change: make adding a default-constructor for DefSQClass optional
truelight
parents: 9395
diff changeset
    30
};
9385
56803dfb2ff6 (svn r9176) [NoAI] -Add: added a RegisterAI() proc, that makes the AI known to the
truelight
parents: 9381
diff changeset
    31
9404
ef9e171617a3 (svn r9201) [NoAI] -Change: make adding a default-constructor for DefSQClass optional
truelight
parents: 9395
diff changeset
    32
class FSquirrel: public AIFactory<FSquirrel> {
ef9e171617a3 (svn r9201) [NoAI] -Change: make adding a default-constructor for DefSQClass optional
truelight
parents: 9395
diff changeset
    33
private:
9422
33efcc5f1b09 (svn r9223) [NoAI] -Change: moved squirrel/engine.cpp to squirrel.cpp in root
truelight
parents: 9411
diff changeset
    34
	Squirrel *engine; ///< The Squirrel engine
9410
286fcd8edc64 (svn r9208) [NoAI] -Add: keep track of which script added which class, so we know
truelight
parents: 9404
diff changeset
    35
	const char *current_script; ///< Temporary variable to know which script defines which class
9404
ef9e171617a3 (svn r9201) [NoAI] -Change: make adding a default-constructor for DefSQClass optional
truelight
parents: 9395
diff changeset
    36
9411
29c9dfcdb8e9 (svn r9209) [NoAI] -Add: added ScanDir(), which scans the 'ai' dir for main.nut scripts
truelight
parents: 9410
diff changeset
    37
	/**
29c9dfcdb8e9 (svn r9209) [NoAI] -Add: added ScanDir(), which scans the 'ai' dir for main.nut scripts
truelight
parents: 9410
diff changeset
    38
	 * The constructor for when a script makes an instance of the Factory class.
29c9dfcdb8e9 (svn r9209) [NoAI] -Add: added ScanDir(), which scans the 'ai' dir for main.nut scripts
truelight
parents: 9410
diff changeset
    39
	 */
9404
ef9e171617a3 (svn r9201) [NoAI] -Change: make adding a default-constructor for DefSQClass optional
truelight
parents: 9395
diff changeset
    40
	static SQInteger FactoryConstructor(HSQUIRRELVM vm);
9385
56803dfb2ff6 (svn r9176) [NoAI] -Add: added a RegisterAI() proc, that makes the AI known to the
truelight
parents: 9381
diff changeset
    41
9411
29c9dfcdb8e9 (svn r9209) [NoAI] -Add: added ScanDir(), which scans the 'ai' dir for main.nut scripts
truelight
parents: 9410
diff changeset
    42
	/**
29c9dfcdb8e9 (svn r9209) [NoAI] -Add: added ScanDir(), which scans the 'ai' dir for main.nut scripts
truelight
parents: 9410
diff changeset
    43
	 * Scans a dir to see if there are dirs in it which have a file called 'main.nut'.
29c9dfcdb8e9 (svn r9209) [NoAI] -Add: added ScanDir(), which scans the 'ai' dir for main.nut scripts
truelight
parents: 9410
diff changeset
    44
	 *  If found it loads the script.
29c9dfcdb8e9 (svn r9209) [NoAI] -Add: added ScanDir(), which scans the 'ai' dir for main.nut scripts
truelight
parents: 9410
diff changeset
    45
	 */
29c9dfcdb8e9 (svn r9209) [NoAI] -Add: added ScanDir(), which scans the 'ai' dir for main.nut scripts
truelight
parents: 9410
diff changeset
    46
	void ScanDir(const char *dirname);
29c9dfcdb8e9 (svn r9209) [NoAI] -Add: added ScanDir(), which scans the 'ai' dir for main.nut scripts
truelight
parents: 9410
diff changeset
    47
9365
c3d08e0b1083 (svn r9151) [NoAI] -Add: added squirrel module that loads squirrel scripts and
truelight
parents:
diff changeset
    48
public:
9404
ef9e171617a3 (svn r9201) [NoAI] -Change: make adding a default-constructor for DefSQClass optional
truelight
parents: 9395
diff changeset
    49
	~FSquirrel();
9365
c3d08e0b1083 (svn r9151) [NoAI] -Add: added squirrel module that loads squirrel scripts and
truelight
parents:
diff changeset
    50
9410
286fcd8edc64 (svn r9208) [NoAI] -Add: keep track of which script added which class, so we know
truelight
parents: 9404
diff changeset
    51
	/* virtual */ const char   *GetAuthor()      { return "OpenTTD Dev Team"; }
286fcd8edc64 (svn r9208) [NoAI] -Add: keep track of which script added which class, so we know
truelight
parents: 9404
diff changeset
    52
	/* virtual */ const char   *GetName()        { return "Squirrel"; }
286fcd8edc64 (svn r9208) [NoAI] -Add: keep track of which script added which class, so we know
truelight
parents: 9404
diff changeset
    53
	/* virtual */ const char   *GetDescription() { return "Squirrel Module for loading scripts"; }
286fcd8edc64 (svn r9208) [NoAI] -Add: keep track of which script added which class, so we know
truelight
parents: 9404
diff changeset
    54
	/* virtual */ int           GetVersion()     { return 0; }
286fcd8edc64 (svn r9208) [NoAI] -Add: keep track of which script added which class, so we know
truelight
parents: 9404
diff changeset
    55
	/* virtual */ const char   *GetDate()        { return ""; }
286fcd8edc64 (svn r9208) [NoAI] -Add: keep track of which script added which class, so we know
truelight
parents: 9404
diff changeset
    56
	/* virtual */ AIController *CreateInstance() { return NULL; }
286fcd8edc64 (svn r9208) [NoAI] -Add: keep track of which script added which class, so we know
truelight
parents: 9404
diff changeset
    57
	/* virtual */ bool          AllowStartup()   { return false; }
286fcd8edc64 (svn r9208) [NoAI] -Add: keep track of which script added which class, so we know
truelight
parents: 9404
diff changeset
    58
	/* virtual */ void          Initializer();
9365
c3d08e0b1083 (svn r9151) [NoAI] -Add: added squirrel module that loads squirrel scripts and
truelight
parents:
diff changeset
    59
};
c3d08e0b1083 (svn r9151) [NoAI] -Add: added squirrel module that loads squirrel scripts and
truelight
parents:
diff changeset
    60
9422
33efcc5f1b09 (svn r9223) [NoAI] -Change: moved squirrel/engine.cpp to squirrel.cpp in root
truelight
parents: 9411
diff changeset
    61
#endif /* AI_SQUIRREL_HPP */