00001
00007 00008 00009 00010 00011 00012 00013 00014 00015 00016 00017 00018 00019 00020 00021 00022 00023 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
00034
00035 #include "nel/ai/logic/factbase.h"
00036 #include "nel/ai/logic/goal.h"
00038
00039
00040 namespace NLAISCRIPT
00041 {
00042 class CAgentClass;
00043 class IOpCode;
00044 }
00045
00046 namespace NLAIAGENT
00047 {
00048 class IAgentManager;
00049 struct CKeyAgent;
00057 class CAgentScript : public IAgentManager
00058 {
00059 public:
00060
00062 enum TMethodNumDef {
00063 TSend,
00064 TSendComponent,
00065 TGetChildTag,
00066 TAddChildTag,
00067 TRemoveChild,
00068 TFather,
00069 TSelf,
00070 TGetName,
00071 TRunAskParentNotify,
00072 TRunTellParentNotify,
00073
00074 TGoal, 00076
00077 };
00078
00079 enum TTypeCheck{
00080 CheckAll,
00081 CheckCount,
00082 DoNotCheck
00083 };
00084
00086 struct CMethodCall
00087 {
00088
00089 CMethodCall(const char *name, int i,const IObjectIA *a,TTypeCheck checkArg,int argCount,IObjectIA *r):
00090 MethodName (name),ArgType(a),ReturnValue(r)
00091 {
00092 Index = i;
00093 CheckArgType = checkArg;
00094 ArgCount = argCount;
00095 }
00096
00097 ~CMethodCall()
00098 {
00099 if(ReturnValue) ReturnValue->release();
00100 }
00102 CStringVarName MethodName;
00104 const IObjectIA *ArgType;
00106 IObjectIA *ReturnValue;
00108 TTypeCheck CheckArgType;
00110 sint ArgCount;
00112 sint32 Index;
00113 };
00114
00115 static CMethodCall **StaticMethod;
00116 private:
00118 typedef std::multiset<CKeyAgent> tsetDefNameAgent;
00119
00120 private:
00122 IObjectIA **_Components;
00124 int _NbComponents;
00126 std::vector<NLAILOGIC::IBaseOperator *> _Operators;
00128 IAgentManager *_AgentManager;
00133 00135
00136
00137 protected:
00139 NLAISCRIPT::CAgentClass *_AgentClass;
00140
00141 public:
00142 static const NLAIC::CIdentType IdAgentScript;
00143
00144 public:
00146 CAgentScript(const CAgentScript &);
00148 CAgentScript(IAgentManager *);
00150 CAgentScript(IAgentManager *, IBasicAgent *, std::list<IObjectIA *> &, NLAISCRIPT::CAgentClass *);
00151
00152 virtual ~CAgentScript();
00153
00155
00156
00157 virtual void addOperator(NLAILOGIC::IBaseOperator *);
00159 virtual void remOperator(NLAILOGIC::IBaseOperator *p);
00165 virtual IObjectIA::CProcessResult addDynamicAgent(NLAIAGENT::IBaseGroupType *g);
00170 virtual IObjectIA::CProcessResult getDynamicAgent(NLAIAGENT::IBaseGroupType *g);
00171
00175 virtual IObjectIA::CProcessResult getDynamicName(NLAIAGENT::IBaseGroupType *g);
00176
00181 virtual IObjectIA::CProcessResult removeDynamic(NLAIAGENT::IBaseGroupType *g);
00182
00186 virtual IObjectIA::CProcessResult runAskParentNotify(IBaseGroupType *);
00187
00191 virtual IObjectIA::CProcessResult runTellParentNotify(IBaseGroupType *);
00192
00194 NLAISCRIPT::IOpCode *getMethode(sint32 inheritance,sint32 index);
00196 NLAISCRIPT::IOpCode *getMethode(sint32 index);
00198 const IAgentManager *getAgentManager() const
00199 {
00200 return _AgentManager;
00201 }
00202
00204 const NLAISCRIPT::CAgentClass *getFactoryClass() const
00205 {
00206 return _AgentClass;
00207 }
00209 00210 00211 00212
00213 virtual sint32 getChildMessageIndex(const IMessageBase *, sint32 );
00214
00216 void setAgentManager(IAgentManager *manager);
00218
00220
00221 virtual int getBaseMethodCount() const;
00223 virtual const IObjectIA *getAgentContext() const
00224 {
00225 return getAgentManager()->getAgentContext();
00226 }
00228
00230
00231
00232 virtual void runChildren();
00233 virtual void onKill(IConnectIA *A);
00234 virtual void processMessages();
00235
00236 virtual void processMessages(IMessageBase *,IObjectIA *);
00237
00238 virtual IObjectIA::CProcessResult runActivity();
00239 virtual bool isEqual(const IBasicObjectIA &a) const;
00240 virtual bool haveActivity() const;
00241
00242
00243 IObjectIA::CProcessResult sendMethod(IObjectIA *);
00244 IObjectIA::CProcessResult sendMethodCompoment(IObjectIA *);
00245 virtual IObjectIA::CProcessResult runMethodBase(int heritance, int index,IObjectIA *);
00246 virtual IObjectIA::CProcessResult runMethodBase(int index,IObjectIA *);
00247
00248 virtual sint32 getStaticMemberSize() const;
00249 virtual sint32 getStaticMemberIndex(const IVarName &) const;
00250 virtual const IObjectIA *getStaticMember(sint32) const;
00251 virtual void setStaticMember(sint32,IObjectIA *);
00252
00253 virtual tQueue getPrivateMember(const IVarName *,const NLAIAGENT::IVarName *,const IObjectIA &) const;
00254 virtual tQueue isMember(const IVarName *,const NLAIAGENT::IVarName *,const IObjectIA &) const;
00255 virtual sint32 isClassInheritedFrom(const NLAIAGENT::IVarName &) const;
00256
00257 virtual sint32 getMethodIndexSize() const;
00258 virtual IObjectIA::CProcessResult runMethodeMember(sint32 heritance, sint32 index,IObjectIA *);
00259 virtual IObjectIA::CProcessResult runMethodeMember(sint32 index,IObjectIA *);
00260
00261 virtual CProcessResult sendMessage(IObjectIA *);
00262 virtual CProcessResult sendMessage(const IVarName &,IObjectIA *);
00263
00264 virtual const IObjectIA::CProcessResult &run();
00266
00268
00269 virtual void load(NLMISC::IStream &is);
00270 virtual void save(NLMISC::IStream &os);
00271 virtual const NLAIC::IBasicType *clone() const;
00272 virtual const NLAIC::IBasicType *newInstance() const;
00273 virtual void getDebugString(char *t) const;
00274 virtual const NLAIC::CIdentType &getType() const;
00276
00277
00278
00279 public:
00280 static void initAgentScript();
00281 static void releaseAgentScript();
00282
00283
00285
00286
00287 protected:
00288 NLAILOGIC::CFactBase _FactBase;
00289 std::vector<NLAILOGIC::CGoal *> _GoalStack;
00290
00291 public:
00292 virtual NLAILOGIC::CFactBase &getFactBase()
00293 {
00294 return _FactBase;
00295 }
00296
00297 IObjectIA::CProcessResult runGoalMsg(IBaseGroupType *);
00299 };
00300 }
00301 #endif