# 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  

goal.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 NLIACeral 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  * NLIACeral 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_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 //                      virtual void failure();
00150 //                      virtual void success();
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 /*                      virtual void setTopLevel(NLAIAGENT::CAgentScript *);
00181                         const NALAIGENT::CAgentScript *getTOpLevel() const;*/
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 //                      virtual void failure();
00206 //                      virtual void success();
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