src/ai/api/ai_controller.hpp
branchnoai
changeset 10958 65088d587094
parent 10871 326ee226e9d7
child 11043 e44adcf4ed4d
equal deleted inserted replaced
10957:7a140b4cd91d 10958:65088d587094
     3 /** @file ai_controller.hpp The controller of the AI. */
     3 /** @file ai_controller.hpp The controller of the AI. */
     4 
     4 
     5 #ifndef AI_CONTROLLER_HPP
     5 #ifndef AI_CONTROLLER_HPP
     6 #define AI_CONTROLLER_HPP
     6 #define AI_CONTROLLER_HPP
     7 
     7 
       
     8 #include <map>
       
     9 #ifndef AI_SQUIRREL_HPP
       
    10 struct ltstr { bool operator()(const char *s1, const char *s2) const { return strcmp(s1, s2) < 0; } };
       
    11 #endif /* AI_SQUIRREL_HPP */
       
    12 
     8 /**
    13 /**
     9  * The Controller, the class each AI should extend. It creates the AI, makes
    14  * The Controller, the class each AI should extend. It creates the AI, makes
    10  *  sure the logic kicks in correctly, and that GetTick() has a valid value.
    15  *  sure the logic kicks in correctly, and that GetTick() has a valid value.
    11  */
    16  */
    12 class AIController {
    17 class AIController {
    13 private:
    18 	friend class AISquirrel;
    14 	uint tick;
       
    15 
    19 
    16 public:
    20 public:
    17 	static const char *GetClassName() { return "AIController"; }
    21 	static const char *GetClassName() { return "AIController"; }
    18 
    22 
    19 	/**
    23 	/**
    68 	 * @note Use AILog.Info/Warning/Error instead of 'print'.
    72 	 * @note Use AILog.Info/Warning/Error instead of 'print'.
    69 	 */
    73 	 */
    70 	static void Print(bool error_msg, const char *message);
    74 	static void Print(bool error_msg, const char *message);
    71 
    75 
    72 private:
    76 private:
       
    77 	typedef std::map<const char *, const char *, ltstr> LoadedLibraryList;
       
    78 
       
    79 	uint tick;
    73 	class Squirrel *engine;
    80 	class Squirrel *engine;
    74 	HSQOBJECT *SQ_instance;
    81 	HSQOBJECT *SQ_instance;
       
    82 	LoadedLibraryList loaded_library;
       
    83 	int loaded_library_count;
       
    84 	const char *script;
       
    85 	const char *class_name;
    75 
    86 
    76 	/**
    87 	/**
    77 	 * Register all classes that are known inside the NoAI API.
    88 	 * Register all classes that are known inside the NoAI API.
    78 	 */
    89 	 */
    79 	void RegisterClasses();
    90 	void RegisterClasses();
       
    91 
       
    92 	/**
       
    93 	 * Check if a library is already loaded. If found, fake_class_name is filled
       
    94 	 *  with the fake class name as given via AddLoadedLibrary. If not found,
       
    95 	 *  next_number is set to the next number available for the fake namespace.
       
    96 	 * @param library_name The library to check if already loaded.
       
    97 	 * @param next_number The next available number for a library if not already loaded.
       
    98 	 * @param fake_class_name The name the library has if already loaded.
       
    99 	 * @param fake_class_name_len The maximum length of fake_class_name.
       
   100 	 * @return True if the library is already loaded.
       
   101 	 */
       
   102 	bool LoadedLibrary(const char *library_name, int *next_number, char *fake_class_name, int fake_class_name_len);
       
   103 
       
   104 	/**
       
   105 	 * Add a library as loaded.
       
   106 	 */
       
   107 	void AddLoadedLibrary(const char *library_name, const char *fake_class_name);
    80 };
   108 };
    81 
   109 
    82 #endif /* AI_CONTROLLER_HPP */
   110 #endif /* AI_CONTROLLER_HPP */