# 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  

agent_script.h

Go to the documentation of this file.
00001 
00007 /* Copyright, 2000 Nevrax Ltd.
00008  *
00009  * This file is part of NEVRAX NEL.
00010  * NEVRAX NEL is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2, or (at your option)
00013  * any later version.
00014 
00015  * NEVRAX NEL is distributed in the hope that it will be useful, but
00016  * WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00018  * General Public License for more details.
00019 
00020  * You should have received a copy of the GNU General Public License
00021  * along with NEVRAX NEL; see the file COPYING. If not, write to the
00022  * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
00023  * MA 02111-1307, USA.
00024  */
00025 
00026 #ifndef NL_AGENTSCRIPT_H
00027 #define NL_AGENTSCRIPT_H
00028 
00029 #include "nel/ai/agent/agent.h"
00030 #include "nel/ai/agent/agent_manager.h"
00031 #include "nel/ai/logic/operator.h"
00032 #include "nel/ai/agent/msg_getvalue.h"
00033 
00035 // Temp to be transfered in CGDAgentScript
00036 /*
00037 #include "nel/ai/logic/factbase.h"
00038 #include "nel/ai/logic/goal.h"
00039 
00040   */
00042 
00043 
00044 namespace NLAISCRIPT 
00045 {
00046         class CAgentClass;
00047         class IOpCode;
00048         class COperandSimpleListOr;
00049         class COperandSimple;
00050         class CParam;
00051 }
00052 
00053 namespace NLAIAGENT
00054 {
00055         class IAgentManager;
00056         struct CKeyAgent;
00064         class CAgentScript : public IAgentManager
00065         {
00066         public:         
00067 
00069                 enum  TMethodNumDef {                   
00070                         TSend, 
00071                         TSendComponent, 
00072                         TGetChildTag, 
00073                         TAddChildTag,
00074                         TRemoveChild,
00075                         TFather, 
00076                         TSelf, 
00077                         TGetName, 
00078                         TIsInherited,
00079                         TGetClassName, 
00080                         TRunTellComponent, 
00081                         TRunAskComponent, 
00082                         TRunAskParentNotify, 
00083                         TRunTellParentNotify, 
00084                         TSetStatic,     
00085                         TGetValue,      
00086                         TSetValue,      
00087 //                      TGetValueReturn,        /// Processes the "Tell(GetValueMsg)" msg resulting from a "Ask(GetValueMsg)" message sent.
00088                         TDeflautProccessMsg,
00089                         TInitComponent,
00090                         TIsEUU,
00091                         TAddSet,
00092                         TLastM 
00093                 };
00094 
00095                 enum TTypeCheck{
00096                         CheckAll,
00097                         CheckCount,
00098                         DoNotCheck
00099                 };
00100 
00102                 struct CMethodCall
00103                 {                       
00104 
00105                         CMethodCall(const char *name, int i,IObjectIA *a,TTypeCheck checkArg,int argCount,IObjectIA *r): 
00106                                         MethodName (name),ArgType(a),ReturnValue(r)
00107                         {
00108                                 Index = i;
00109                                 CheckArgType = checkArg;
00110                                 ArgCount = argCount;
00111                         }
00112 
00113                         virtual ~CMethodCall()
00114                         {
00115                                 if(ReturnValue) ReturnValue->release();
00116                                 if(ArgType != NULL) ArgType->release();
00117 
00118                         }
00120                         CStringVarName MethodName;
00122                         IObjectIA *ArgType;
00124                         IObjectIA *ReturnValue;
00126                         TTypeCheck CheckArgType;
00128                         sint ArgCount;
00130                         sint32 Index;
00131                 };
00132 
00133                 static CMethodCall **StaticMethod;
00134 
00135         public:
00136                 static NLAISCRIPT::COperandSimpleListOr *msgType;
00137                 static NLAISCRIPT::COperandSimpleListOr *msgPerf;
00138                 static NLAISCRIPT::CParam *SendParamMessageScript;
00139                 static NLAISCRIPT::CParam *ParamSetStatic;
00140                 static NLAISCRIPT::CParam *SendCompParamMessageScript;
00141                 static NLAISCRIPT::COperandSimple *IdMsgNotifyParentClass;
00142                 static NLAISCRIPT::COperandSimpleListOr *ParamIdGetValueMsg;
00143                 static NLAISCRIPT::CParam *ParamGetValueMsg;
00144                 static NLAISCRIPT::COperandSimpleListOr *ParamIdSetValueMsg;
00145                 static NLAISCRIPT::CParam *ParamSetValueMsg;
00146                 static NLAISCRIPT::COperandSimpleListOr *ParamIdTellComponentMsg;
00147                 static NLAISCRIPT::CParam *ParamTellComponentMsg;
00148                 static NLAISCRIPT::COperandSimpleListOr *ParamIdInitComponentMsg;
00149                 static NLAISCRIPT::CParam *ParamInitComponentMsg;
00150 
00151                 static NLAISCRIPT::COperandSimpleListOr *IdMsgNotifyParent;
00152                 static NLAISCRIPT::CParam *ParamRunParentNotify;
00153 
00154                 virtual void callFunction(std::string &, NLAIAGENT::IObjectIA *p = NULL);
00155 
00156         private:
00158                 typedef std::multiset<CKeyAgent> tsetDefNameAgent;
00159                 
00160         protected:                      
00162                 IObjectIA **_Components;
00163                 void createComponents(std::list<IObjectIA *> &);
00164 
00165 
00167                 int _NbComponents;
00169 //              std::vector<NLAILOGIC::IBaseOperator *> _Operators;
00171                 IAgentManager *_AgentManager;           
00176                 //IMailBox      *_ScriptMail;
00178                 tsetDefNameAgent _DynamicAgentName;
00179 
00180 
00181         protected:
00183                 NLAISCRIPT::CAgentClass *_AgentClass;
00184                 sint _iComponents;
00185                 
00186                 std::set<std::string> mapSet;
00187 
00188         public:
00189                 static const NLAIC::CIdentType IdAgentScript;
00190 
00191         public:
00193                 CAgentScript(const CAgentScript &);
00195                 CAgentScript(IAgentManager *);
00197                 CAgentScript(IAgentManager *, IBasicAgent *, std::list<IObjectIA *> &, NLAISCRIPT::CAgentClass *);
00198 
00199                 virtual ~CAgentScript();
00200                 
00202 
00203 
00204                 virtual void addOperator(NLAILOGIC::IBaseOperator *);
00206                 virtual void remOperator(NLAILOGIC::IBaseOperator *p);
00212                 virtual IObjectIA::CProcessResult addDynamicAgent(NLAIAGENT::IBaseGroupType *g);
00213                 virtual IObjectIA::CProcessResult addDynamicAgent(CStringType &, IBasicAgent *);
00214 
00219                 virtual IObjectIA::CProcessResult getDynamicAgent(NLAIAGENT::IBaseGroupType *g);
00220 
00224                 virtual IObjectIA::CProcessResult getDynamicName(NLAIAGENT::IBaseGroupType *g);
00225 
00230                 virtual void removeDynamic(NLAIAGENT::IBasicAgent *ag);
00231                 virtual IObjectIA::CProcessResult removeDynamic(NLAIAGENT::IBaseGroupType *g);
00232 
00236                 virtual IObjectIA::CProcessResult runAskParentNotify(IBaseGroupType *);
00237                 
00241                 virtual IObjectIA::CProcessResult runTellComponent(IBaseGroupType *);
00242 
00243                 IObjectIA::CProcessResult runAskGetValue(IBaseGroupType *);
00244 
00245                 IObjectIA::CProcessResult runTellSetValue(IBaseGroupType *);
00246 
00247                 virtual IObjectIA::CProcessResult runInitComponent(IBaseGroupType *);
00248                 virtual IObjectIA::CProcessResult runInitClass(IBaseGroupType *);
00249                 
00253                 virtual IObjectIA::CProcessResult runTellParentNotify(IBaseGroupType *);
00254 
00256                 NLAISCRIPT::IOpCode *getMethode(sint32 inheritance,sint32 index); 
00258                 NLAISCRIPT::IOpCode *getMethode(sint32 index);
00260                 const IAgentManager *getAgentManager() const
00261                 {
00262                         return _AgentManager;
00263                 }
00264 
00266                 const NLAISCRIPT::CAgentClass *getFactoryClass() const
00267                 {
00268                         return _AgentClass;
00269                 }
00271                 /*const IMailBox *getLocalMailBox() const
00272                 {
00273                         return _ScriptMail;
00274                 }*/             
00275                 virtual sint32 getChildMessageIndex(const IMessageBase *, sint32 );
00276 
00278                 virtual void setAgentManager(IAgentManager *manager);           
00280 
00282 
00283                 virtual int getBaseMethodCount() const;
00285                 virtual const IObjectIA *getAgentContext() const
00286                 {
00287                         return getAgentManager()->getAgentContext();
00288                 }
00290 
00292 
00293 
00294                 virtual void runChildren();
00295                 virtual bool runChildrenStepByStep();
00296 
00297                 virtual void onKill(IConnectIA *A);             
00298                 virtual void processMessages();
00299 
00300                 virtual void processMessages(IMessageBase *,IObjectIA *);
00301                 virtual void processContinuation(IMessageBase *, IMessageBase *);
00302 
00303                 virtual IObjectIA::CProcessResult runActivity();
00304                 virtual bool isEqual(const IBasicObjectIA &a) const;
00305                 virtual bool haveActivity() const;
00306 
00307                 
00308                 IObjectIA::CProcessResult sendMethod(IObjectIA *);
00309                 IObjectIA::CProcessResult sendMethodCompoment(IObjectIA *);
00310                 virtual IObjectIA::CProcessResult runMethodBase(int heritance, int index,IObjectIA *);
00311                 virtual IObjectIA::CProcessResult runMethodBase(int index,IObjectIA *); 
00312                 
00313                 virtual std::string getMethodeMemberDebugString(sint32, sint32) const;
00314 
00315                 virtual sint32 getStaticMemberSize() const;
00316                 virtual sint32 getStaticMemberIndex(const IVarName &) const;
00317                 virtual const IObjectIA *getStaticMember(sint32) const;         
00318                 virtual bool setStaticMember(sint32,IObjectIA *);
00319 
00320                 virtual tQueue getPrivateMember(const IVarName *,const NLAIAGENT::IVarName *,const IObjectIA &) const;
00321                 virtual tQueue isMember(const IVarName *,const NLAIAGENT::IVarName *,const IObjectIA &) const;
00322                 virtual tQueue isDeflautProccessMsg(const IVarName *,const NLAIAGENT::IVarName *,const IObjectIA &) const;
00323                 virtual sint32 isClassInheritedFrom(const NLAIAGENT::IVarName &) const;                 
00324 
00325                 virtual sint32 getMethodIndexSize() const;              
00326                 virtual IObjectIA::CProcessResult runMethodeMember(sint32 heritance, sint32 index,IObjectIA *);
00327                 virtual IObjectIA::CProcessResult runMethodeMember(sint32 index,IObjectIA *);           
00328 
00329                 virtual CProcessResult sendMessage(IObjectIA *);
00330                 virtual CProcessResult sendMessage(const IVarName &,IObjectIA *);
00331                 CProcessResult sendMessageToDynmaicChild(const IVarName &,IObjectIA *);
00332 
00333                 virtual const IObjectIA::CProcessResult &run();
00334                 virtual const CProcessResult &runStep();
00336 
00338 
00339                 virtual void load(NLMISC::IStream &is);
00340                 virtual void save(NLMISC::IStream &os);
00341                 virtual const NLAIC::IBasicType *clone() const;
00342                 virtual const NLAIC::IBasicType *newInstance() const;
00343                 virtual void getDebugString(std::string &t) const;
00344                 virtual const NLAIC::CIdentType &getType() const;
00346 
00348                 virtual bool isa(const std::string &) const;
00350                 virtual void addSet(const std::string &);
00351                 virtual std::set<std::string>::const_iterator beginSet() const
00352                 {
00353                         return mapSet.begin();
00354                 }
00355 
00356                 virtual std::set<std::string>::const_iterator endSet() const
00357                 {
00358                         return mapSet.end();
00359                 }
00360 
00361         protected:
00362                 virtual CProcessResult sendBroadCast(IObjectIA *);
00363 
00364 
00365         public:
00366                 static void initAgentScript();
00367                 static void releaseAgentScript();
00368 
00369 
00371         // Temp, to be transfered in CGDAgentScript (Goal Driven Agent)
00372 /*
00373         protected:
00374 //              NLAILOGIC::CFactBase                    _FactBase;
00375                 std::vector<NLAILOGIC::CGoal *> _GoalStack;
00376 
00377         public:
00378         */
00379                 virtual const NLAILOGIC::CFactBase *getFactBase()
00380                 {
00381                         return NULL;
00382                 }
00383 
00384                 virtual IObjectIA::CProcessResult runGoalMsg(IBaseGroupType *)
00385                 {
00386                         return IObjectIA::CProcessResult();
00387                 }
00388 
00389                 virtual IObjectIA::CProcessResult runCancelGoalMsg(IBaseGroupType *)
00390                 {
00391                         return IObjectIA::CProcessResult();
00392                 }
00393 
00394                 virtual IObjectIA::CProcessResult runFactMsg(IBaseGroupType *)
00395                 {
00396                         return IObjectIA::CProcessResult();
00397                 }
00398 
00399                 virtual void removeGoal( NLAILOGIC::CGoal *)
00400                 {
00401                 }
00402 
00403                 virtual void setTopLevel(NLAIAGENT::CAgentScript *)
00404                 {
00405                 }
00406 
00408                 const NLAISCRIPT::CAgentClass *getClass() const
00409                 {
00410                         return _AgentClass;
00411                 }
00412 
00414                 virtual const NLAIAGENT::IVarName *getClassName() const;
00415 
00416                 virtual NLAILOGIC::CGoal *getTopGoal()
00417                 {
00418                         return NULL;
00419                 }
00420 
00421                 virtual const std::vector<NLAILOGIC::CGoal *> *getGoalStack()
00422                 {
00423                         return NULL;
00424                 }
00425 
00426                 virtual void callConstructor();
00427         };
00428 
00429         
00430         NLAIAGENT::tQueue isTemplateMember(     CAgentScript::CMethodCall **StaticMethod,int count,int shift,
00431                                                                                                 const NLAIAGENT::IVarName *className,
00432                                                                                                 const NLAIAGENT::IVarName *methodName,
00433                                                                                                 const NLAIAGENT::IObjectIA &param);     
00434 }
00435 #endif