truelight@9365: /* $Id$ */ truelight@9365: truelight@9365: /** @file squirrel.hpp declarations of the class for squirrel loader */ truelight@9365: truelight@9422: #ifndef AI_SQUIRREL_HPP truelight@9422: #define AI_SQUIRREL_HPP truelight@9365: truebrain@10643: #include truebrain@10958: #ifndef AI_CONTROLLER_HPP truebrain@10649: struct ltstr { bool operator()(const char *s1, const char *s2) const { return strcmp(s1, s2) < 0; } }; truebrain@10958: #endif /* AI_CONTROLLER_HPP */ truebrain@10643: truebrain@10643: class AISquirrel { truebrain@10643: public: truebrain@10643: AISquirrel(); truebrain@10643: ~AISquirrel(); truelight@9375: truelight@9375: /** truebrain@10889: * Import a library inside the Squirrel VM. truebrain@10889: */ truebrain@10958: bool ImportLibrary(const char *library, const char *class_name, int version, HSQUIRRELVM vm, AIController *controller); truebrain@10889: truebrain@10889: /** truebrain@10889: * Register a library to be put in the available list. truebrain@10889: */ truebrain@10889: void RegisterLibrary(class AILibrary *library); truebrain@10889: truebrain@10889: /** truebrain@10643: * Register an AI to be put in the available list. truelight@9373: */ truebrain@10643: void RegisterAI(class AIInfo *info); truelight@9404: truelight@9411: /** truebrain@10643: * Remove an AI from the available list. truelight@9411: */ truebrain@10643: void UnregisterAI(class AIInfo *info); truelight@9385: truelight@9411: /** truebrain@10643: * Select a Random AI. truebrain@10643: */ truebrain@10643: class AIInfo *SelectRandomAI(); truebrain@10643: truebrain@10643: /** truebrain@10643: * Select an AI by name. truebrain@10643: */ truebrain@10643: class AIInfo *SelectAI(const char *name); truebrain@10643: truebrain@10643: /** truebrain@10643: * Get the list of available AIs for the console. truebrain@10643: */ truebrain@10643: char *GetAIConsoleList(char *p, const char *last); truebrain@10643: truebrain@10643: /** truebrain@10643: * Get the engine of the main squirrel handler (it indexes all avialable squirrels). truebrain@10643: */ truebrain@10643: class Squirrel *GetEngine() { return this->engine; } truebrain@10643: truebrain@10643: /** truebrain@10643: * Get the current script the ScanDir is looking at. truebrain@10643: */ truebrain@10643: const char *GetCurrentScript() { return this->current_script; } truebrain@10643: truebrain@10643: /** truebrain@10643: * Get the directory of the current script the ScanDir is looking at. truebrain@10643: */ truebrain@10643: const char *GetCurrentDirName() { return this->current_dir; } truebrain@10643: glx@10891: /** glx@10891: * Rescan the AI dir for scripts. glx@10891: */ glx@10891: void RescanAIDir(); glx@10891: truebrain@10643: private: truebrain@10649: typedef std::map AIInfoList; truebrain@10889: typedef std::map AILibraryList; truebrain@10643: truebrain@10643: /** glx@10891: * Scan the AI dir for scripts. glx@10891: */ glx@10891: void ScanAIDir(); glx@10891: glx@10891: /** truebrain@10889: * Scan a dir for AIs. truebrain@10889: * For non-library-scan, if an AI is found, AIInfo is created, and the AI truebrain@10889: * is registered to the central system. truebrain@10889: * For library-scan, if a library is found, AILibrary is created, and the truebrain@10889: * library is registered to the central system. truelight@9411: */ truebrain@10889: void ScanDir(const char *dirname, bool library_dir, char *library_depth = NULL); truelight@9411: truebrain@10643: AIInfoList info_list; truebrain@10889: AILibraryList library_list; truebrain@10643: class Squirrel *engine; truebrain@10643: char *current_script; truebrain@10643: char *current_dir; truelight@9365: }; truelight@9365: truelight@9422: #endif /* AI_SQUIRREL_HPP */