# Home    # nevrax.com   
Nevrax
Nevrax.org
#News
#Mailing-list
#Documentation
#CVS
#Bugs
#License
Docs
 
Documentation  
Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages   Search  

ai.cpp

Go to the documentation of this file.
00001 #include "nel/ai/nl_ai.h"
00002 #include "nel/ai/static_init.h"
00003 #include "nel/ai/script/compilateur.h"
00004 #include "nel/ai/agent/agent.h"
00005 #include "nel/ai/agent/agent_digital.h"
00006 #include "nel/ai/agent/msg_group.h"
00007 #include "nel/ai/script/libcode.h"
00008 #include "nel/ai/c/registry_class.h"
00009 #include "nel/ai/agent/main_agent_script.h"
00010 #include "nel/ai/agent/agent_proxy_mailer.h"
00011 #include "nel/ai/script/test_method.h"
00012 #include "nel/ai/character/character.h"
00013 #include "nel/ai/logic/fsm_script.h"
00014 #include "nel/ai/agent/agent_timer.h"
00015 #include "nel/ai/agent/volatil_memory.h"
00016 #include "nel/ai/agent/operation.h"
00017 
00018 
00019 using namespace NLAIAGENT;
00020 
00021 namespace NLAILINK 
00022 {
00023         //using namespace NLAIAGENT;
00024         void initIALib()
00025         {
00026                 staticInitAgent();
00027                 registerLibClass();
00028                 NLAIC::initRegistry();
00029                 NLAISCRIPT::initExternalLib();          
00030                 NLAIAGENT::CAgentScript::initAgentScript();
00031                 NLAIAGENT::CActorScript::initClass();
00032                 NLAIAGENT::CProxyAgentMail::initClass();
00033                 NLAISCRIPT::CLibTest::initClass();
00034 
00035                 NLAICHARACTER::CCharacterNoeud::initClass();
00036                 NLAICHARACTER::CCharacterChild::initClass();
00037 
00038                 NLAIAGENT::CAgentManagerTimer::initClass();
00039                 CLibTimerManager::initClass();
00040                 CAgentWatchTimer::initClass();
00041                 CAgentClockTimer::initClass();
00042                 CVolatilMemmory::initClass();
00043                 CHashTimerManager::initClass();         
00044                 CAgentOperation::initClass();
00045         }
00046 
00047         void releaseIALib()
00048         {       
00049                 NLAIAGENT::CAgentManagerTimer::releaseClass();
00050                 CLibTimerManager::releaseClass();
00051                 CAgentClockTimer::releaseClass();
00052                 CAgentWatchTimer::releaseClass();
00053 
00054                 NLAIAGENT::CIndexedVarName::releaseClass();
00055                 NLAIC::releaseRegistry();
00056                 //NLAIAGENT::CLocWordNumRef::clear();
00057                 NLAIAGENT::CAgentScript::releaseAgentScript();
00058                 NLAIAGENT::CFsmScript::releaseClass();
00059                 
00060                 NLAIAGENT::CProxyAgentMail::releaseClass();
00061                 NLAISCRIPT::CLibTest::releaseClass();
00062                 NLAICHARACTER::CCharacterNoeud::releaseClass();
00063                 NLAICHARACTER::CCharacterChild::releaseClass();
00064                 CVolatilMemmory::releaseClass();
00065                 CHashTimerManager::releaseClass();
00066                 CAgentOperation::releaseClass();
00067 
00068                 staticReleaseLibClass();
00069         }
00070 
00071 
00072         void setLocalServerID(uint8 u)
00073         {
00074                 NLAIAGENT::CAgentNumber::ServerId = u;
00075                 NLAIAGENT::CNumericIndex::_I.setCreatorId( u );
00076                 NLAIAGENT::CNumericIndex::_I.setDynamicId( u );
00077         }
00078 
00079         uint8 getLocalServerID()
00080         {
00081                 return NLAIAGENT::CAgentNumber::ServerId;
00082         }
00083 
00084         void setMainManager(NLAIAGENT::IMainAgent *manager)
00085         {
00086                 NLAIAGENT::CProxyAgentMail::MainAgent = manager;
00087                 //NLAIAGENT::CProxyAgentMail::MainAgent->incRef();
00088         }
00089 
00090         void releaseMainManager()
00091         {
00092                 if(NLAIAGENT::CProxyAgentMail::MainAgent != NULL) 
00093                 {
00094                         NLAIAGENT::CProxyAgentMail::MainAgent->release();
00095                 }
00096         }
00097 
00098         static char LaseErrorCodeOrdreInterprete[32*1024];
00099 
00100         class IOTrace : public NLAIC::IIO
00101         {               
00102         public:
00103 
00104                 IOTrace()
00105                 {
00106 
00107                 }
00108                 
00109                 virtual void Echo(char *str, ...) const 
00110                 {
00111                         char    temp[32*1024];          
00112                         va_list argument;
00113                         va_start (argument, str);       
00114                         
00115                         vsprintf(temp, str, argument);          
00116                         strcpy(LaseErrorCodeOrdreInterprete,temp);                      
00117                         NLAIC::Out("%s",LaseErrorCodeOrdreInterprete);                  
00118                                 
00119                 }
00120                 virtual const std::string InPut() const
00121                 {
00122                         return std::string();
00123                 }
00124                 virtual void save(NLMISC::IStream &os)
00125                 {
00126                 }
00127                 void getDebugString(std::string &t) const
00128                 {
00129                         t += "this is a IOConsolInterface";
00130                 }
00131 
00132                 virtual const NLAIC::IBasicType *clone() const
00133                 {
00134                         NLAIC::IBasicInterface *m = new IOTrace();
00135                         m->incRef();
00136                         return m;
00137                 }
00138 
00139                 virtual const NLAIC::IBasicType *newInstance() const
00140                 {
00141                         return clone();
00142                 }
00143 
00144                 virtual void load(NLMISC::IStream &is)
00145                 {
00146                 }
00147 
00148                 virtual const NLAIC::CIdentType &getType() const
00149                 {
00150                         static const NLAIC::CIdentType id("IDIOTEMP",   NLAIC::CSelfClassFactory(*this),
00151                                                                                                                         NLAIC::CTypeOfObject(NLAIC::CTypeOfObject::tObject),NLAIC::CTypeOfOperator(0));
00152                         return id;
00153                 }
00154                 
00155 
00156                 virtual ~IOTrace()
00157                 {
00158                 }
00159         };
00160 
00161         void buildScript(const std::string &scriptSrc, const std::string &name)
00162         {
00163                 NLAISCRIPT::IScriptDebugSource *sourceCode = new NLAISCRIPT::CScriptDebugSourceFile(name.c_str());
00164                 IOTrace Interface;
00165                 NLAISCRIPT::CCompilateur *comp = new NLAISCRIPT::CCompilateur(Interface, scriptSrc.c_str(), scriptSrc.size(), sourceCode);
00166                 NLAIAGENT::IObjectIA::CProcessResult r = comp->Compile();               
00167 #ifdef NL_DEBUG
00168                 if ( r.ResultState == NLAIAGENT::processError )
00169                         throw;
00170 #endif
00171                 sourceCode->release();
00172                 delete comp;
00173         }
00174 }