00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef NL_GOAL_
00027 #define NL_GOAL_
00028
00029 #include "nel/ai/logic/boolval.h"
00030 #include "nel/ai/agent/agent.h"
00031
00032
00033 namespace NLAIAGENT
00034 {
00035 class COperatorScript;
00036 }
00037
00038 namespace NLAILOGIC
00039 {
00040 class IBaseOperator;
00041
00042
00043 class IGoal : public IBaseBoolType
00044 {
00045
00046 public:
00047 enum TTypeOfGoal
00048 {
00049 achieveOnce,
00050 achieveForever
00051 };
00052
00053
00054 enum TPriority
00055 {
00056 Normal,
00057 Order,
00058 Urgent
00059 };
00060
00061 protected:
00062 NLAIAGENT::IVarName *_Name;
00063 std::vector<NLAIAGENT::IObjectIA *> _Args;
00064 std::vector<NLAIAGENT::IBasicAgent *> _Predecessors;
00065 std::vector<NLAIAGENT::IBasicAgent *> _Successors;
00066
00067 TTypeOfGoal _Mode;
00068
00069 bool _Selected;
00070
00071 float _Priority;
00072
00073 NLAIAGENT::IBasicAgent *_Sender;
00074 NLAIAGENT::IBasicAgent *_Receiver;
00075
00076 public:
00077 IGoal();
00078 IGoal(const NLAIAGENT::IVarName &, TTypeOfGoal mode = achieveOnce);
00079 IGoal(const NLAIAGENT::IVarName &, std::list<const NLAIAGENT::IObjectIA *> &,TTypeOfGoal mode = achieveOnce);
00080 IGoal(const IGoal &);
00081 virtual ~IGoal();
00082
00083 const NLAIAGENT::IVarName &getName() const
00084 {
00085 return *_Name;
00086 }
00087
00088 void setMode(TTypeOfGoal mode)
00089 {
00090 _Mode = mode;
00091 }
00092
00093 virtual void select()
00094 {
00095 _Selected = true;
00096 }
00097
00098 virtual void unSelect()
00099 {
00100 _Selected = false;
00101 }
00102
00103 bool isSelected()
00104 {
00105 return _Selected;
00106 }
00107
00108 bool isActivable()
00109 {
00110 return ( !_Successors.empty() );
00111 }
00112
00113 virtual void failure();
00114 virtual void success();
00115
00116 virtual void operatorSuccess(NLAIAGENT::IBasicAgent *);
00117 virtual void operatorFailure(NLAIAGENT::IBasicAgent *);
00118
00119 bool isExclusive();
00120
00121 virtual void setPriority(float);
00122 virtual void calcPriority();
00123 virtual float getPriority();
00124
00125 void setSender(NLAIAGENT::IBasicAgent *);
00126 void setReceiver(NLAIAGENT::IBasicAgent *);
00127 NLAIAGENT::IBasicAgent *getSender();
00128 NLAIAGENT::IBasicAgent *getReceiver();
00129 };
00130
00131 class CGoal : public IGoal
00132 {
00133 public:
00134
00135 CGoal();
00136 CGoal(const NLAIAGENT::IVarName &, TTypeOfGoal mode = achieveOnce);
00137 CGoal(const NLAIAGENT::IVarName &, std::list<const NLAIAGENT::IObjectIA *> &,TTypeOfGoal mode = achieveOnce);
00138 CGoal(const CGoal &);
00139 virtual ~CGoal();
00140
00141 void setArgs(std::list<NLAIAGENT::IObjectIA *> &);
00142 const std::vector<NLAIAGENT::IObjectIA *> &getArgs();
00143
00144 static const NLAIC::CIdentType IdGoal;
00145
00146 void addSuccessor(NLAIAGENT::IBasicAgent *);
00147 void addPredecessor(NLAIAGENT::IBasicAgent *);
00148
00149
00150
00151
00152 virtual void operatorSuccess(NLAIAGENT::IBasicAgent *);
00153 virtual void operatorFailure(NLAIAGENT::IBasicAgent *);
00154
00155 const std::vector<IBaseOperator *> getOperators();
00156
00157 const NLAIC::IBasicType *clone() const;
00158 const NLAIC::IBasicType *newInstance() const;
00159 void save(NLMISC::IStream &os);
00160 void load(NLMISC::IStream &is);
00161 virtual void getDebugString(std::string &) const;
00162 bool isTrue() const;
00163 float truthValue() const;
00164 const IObjectIA::CProcessResult &run();
00165 bool isEqual(const CGoal &a) const;
00166 bool isEqual(const NLAIAGENT::IBasicObjectIA &a) const;
00167 const NLAIC::CIdentType &getType() const;
00168
00169 virtual NLAIAGENT::tQueue isMember(const NLAIAGENT::IVarName *,const NLAIAGENT::IVarName *,const NLAIAGENT::IObjectIA &) const;
00170 virtual NLAIAGENT::IObjectIA::CProcessResult runMethodeMember(sint32, sint32, NLAIAGENT::IObjectIA *);
00171 virtual NLAIAGENT::IObjectIA::CProcessResult runMethodeMember(sint32 index, NLAIAGENT::IObjectIA *p);
00172 sint32 getMethodIndexSize() const;
00173
00174
00175 virtual bool operator==(const CGoal &);
00176
00177 virtual void cancel();
00178 virtual float priority() const;
00179
00180
00181
00182
00183 };
00184
00185 class CInternalGoal : public IGoal
00186 {
00187 private:
00188 NLAIAGENT::IObjectIA *_Property;
00189 public:
00190
00191 CInternalGoal();
00192 CInternalGoal(const NLAIAGENT::IVarName &, TTypeOfGoal mode = achieveOnce);
00193 CInternalGoal(const NLAIAGENT::IVarName &, std::list<const NLAIAGENT::IObjectIA *> &,TTypeOfGoal mode = achieveOnce);
00194 CInternalGoal(const CInternalGoal &);
00195 virtual ~CInternalGoal();
00196
00197 void setArgs(std::list<NLAIAGENT::IObjectIA *> &);
00198 const std::vector<NLAIAGENT::IObjectIA *> &getArgs();
00199
00200 static const NLAIC::CIdentType IdInternalGoal;
00201
00202 void addSuccessor(NLAIAGENT::IBasicAgent *);
00203 void addPredecessor(NLAIAGENT::IBasicAgent *);
00204
00205
00206
00207
00208 virtual void operatorSuccess(NLAIAGENT::IBasicAgent *);
00209 virtual void operatorFailure(NLAIAGENT::IBasicAgent *);
00210
00211 const std::vector<IBaseOperator *> getOperators();
00212
00213 const NLAIC::IBasicType *clone() const;
00214 const NLAIC::IBasicType *newInstance() const;
00215 void save(NLMISC::IStream &os);
00216 void load(NLMISC::IStream &is);
00217 virtual void getDebugString(std::string &) const;
00218 bool isTrue() const;
00219 float truthValue() const;
00220 const IObjectIA::CProcessResult &run();
00221 bool isEqual(const CInternalGoal &a) const;
00222 bool isEqual(const NLAIAGENT::IBasicObjectIA &a) const;
00223 const NLAIC::CIdentType &getType() const;
00224
00225 virtual NLAIAGENT::tQueue isMember(const NLAIAGENT::IVarName *,const NLAIAGENT::IVarName *,const NLAIAGENT::IObjectIA &) const;
00226 virtual NLAIAGENT::IObjectIA::CProcessResult runMethodeMember(sint32, sint32, NLAIAGENT::IObjectIA *);
00227 virtual NLAIAGENT::IObjectIA::CProcessResult runMethodeMember(sint32 index, NLAIAGENT::IObjectIA *p);
00228 sint32 getMethodIndexSize() const;
00229
00230
00231 virtual bool operator==(const CInternalGoal &);
00232
00233 void setSender(NLAIAGENT::IBasicAgent *);
00234 void setReceiver(NLAIAGENT::IBasicAgent *);
00235
00236 NLAIAGENT::IBasicAgent *getSender();
00237 NLAIAGENT::IBasicAgent *getReceiver();
00238
00239 virtual void cancel();
00240 virtual float priority() const;
00241
00242 void setProperty(NLAIAGENT::IObjectIA *);
00243 };
00244 }
00245
00246 #endif