# 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  

actor_script.h

Go to the documentation of this file.
00001 
00008 /* Copyright, 2000 Nevrax Ltd.
00009  *
00010  * This file is part of NEVRAX NEL.
00011  * NEVRAX NEL is free software; you can redistribute it and/or modify
00012  * it under the terms of the GNU General Public License as published by
00013  * the Free Software Foundation; either version 2, or (at your option)
00014  * any later version.
00015 
00016  * NEVRAX NEL is distributed in the hope that it will be useful, but
00017  * WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00019  * General Public License for more details. 
00020 
00021  * You should have received a copy of the GNU General Public License
00022  * along with NEVRAX NEL; see the file COPYING. If not, write to the
00023  * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
00024  * MA 02111-1307, USA.
00025  */
00026 
00027 #ifndef NL_ACTOR_SCRIPT_H_
00028 #define NL_ACTOR_SCRIPT_H_
00029 
00030 #include "nel/ai/agent/agent.h"
00031 #include "nel/ai/agent/agent_script.h"
00032 #include "nel/ai/agent/agent_manager.h"
00033 #include "nel/ai/logic/bool_cond.h"
00034 #include "nel/ai/script/type_def.h"
00035 #include "nel/ai/script/interpret_actor.h"
00036 #include "nel/ai/agent/comp_handle.h"
00037 
00038 namespace NLAIAGENT
00039 {
00049         class CActorScript  : public CAgentScript
00050         {
00051                 protected:
00052 
00053                         enum c_funcs_id 
00054                         {
00055                                 fid_activate,
00056                                 fid_onActivate,
00057                                 fid_unActivate,
00058                                 fid_onUnActivate,
00059                                 fid_switch,
00060                                 fid_launch,
00061                                 fid_launch_goal,
00062                                 fid_launched,
00063                                 fid_pause,
00064                                 fid_restart,
00065                                 fid_success,
00066                                 fid_msg_success,
00067                                 fid_failure,
00068                                 fid_msg_failure,
00069                                 fid_nb_answers,
00070                                 fid_toplevel,
00071                                 fid_owner,
00072                                 fid_isactive,
00073                                 fid_last
00074                         };
00075 
00076                         bool _IsActivated;
00077                         bool _OnActivate;
00078                         bool _IsPaused;
00079 
00080                         // TODO: to be transfered in the class
00081                         sint32  _OnActivateIndex;
00082                         sint32  _OnUnActivateIndex;
00083                         sint32  _OnPauseIndex;
00084                         sint32  _OnRestartIndex;
00085                         sint32  _OnSuccessIndex;
00086                         sint32  _OnFailureIndex;
00087 
00088                         sint32  _NbAnswers;
00089 
00091 
00092                         std::vector<CComponentHandle *> _Actors;
00093 
00094                         std::list<IBasicAgent *>                _Launched;
00095 
00096                         CAgentScript *_TopLevel;
00097                         
00101                         virtual void switchActor(CActorScript *, bool stay_active = false);
00105                         virtual void switchActor(std::vector<CActorScript *> &, bool stay_active = false);
00109                         virtual void switchActor(std::vector<CComponentHandle *> &, bool stay_active = false);
00110 
00111                 public:
00112                         static NLAISCRIPT::COperandSimpleListOr *ParamIdSuccessMsg;
00113                         static NLAISCRIPT::CParam *ParamSuccessMsg;
00114                         static NLAISCRIPT::COperandSimpleListOr *ParamIdFailureMsg;
00115                         static NLAISCRIPT::CParam *ParamFailureMsg;
00116 
00117                 public:
00118                         // Builds and actor with its father
00119                         CActorScript(IAgentManager *, bool activated = false);
00120                         // copy constructor
00121                         CActorScript(const CActorScript &);
00122                         CActorScript(IAgentManager *, IBasicAgent *, std::list<IObjectIA *> &, NLAISCRIPT::CAgentClass *);
00123                         virtual ~CActorScript();
00124 
00126                         bool isActivated();
00128 
00130                         void activate();
00132                         virtual void onActivate();
00133 
00135                         void unActivate();
00137                         virtual void onUnActivate();
00138                         
00140                         virtual const NLAIC::IBasicType *clone() const;
00141                         virtual const NLAIC::IBasicType *newInstance() const;
00142                         virtual void getDebugString(std::string &t) const;
00143                         virtual bool isEqual(const IBasicObjectIA &a) const;
00144                         virtual void processMessages();
00145                         virtual const CProcessResult &run();
00146 
00147                         virtual CProcessResult sendMessage(IObjectIA *);
00148                         virtual const NLAIC::CIdentType &getType() const;
00149 
00150                         static const NLAIC::CIdentType IdActorScript;
00151 
00152                         virtual void save(NLMISC::IStream &os);         
00153                         virtual void load(NLMISC::IStream &is);         
00154 
00155                         // Script functions
00156                         virtual int getBaseMethodCount() const;
00157                         virtual sint32 getMethodIndexSize() const;
00158                         virtual tQueue getPrivateMember(const IVarName *,const IVarName *,const IObjectIA &) const;
00159                         virtual IObjectIA::CProcessResult runMethodBase(int heritance, int index,IObjectIA *);
00160                         virtual IObjectIA::CProcessResult runMethodBase(int index,IObjectIA *);
00161 
00162                         virtual void cancel();
00163 
00167                         virtual void processSuccess(NLAIAGENT::IObjectIA *);
00168                         virtual void processFailure(NLAIAGENT::IObjectIA *);
00169                         virtual void success();
00170 
00171                         virtual void failure();
00172 
00174                         void pause();
00175                         void restart();
00176 
00178                         virtual void onPause();
00179                         virtual void onRestart();
00180 
00183                         virtual void onSuccess( IObjectIA *) {}
00184                         virtual void onFailure( IObjectIA *) {}
00185 
00187                         virtual float priority() const;
00188 
00189                         virtual void setTopLevel(CAgentScript *);
00190                         const CAgentScript *getTopLevel() const;
00191 
00192                         virtual IMessageBase *runTell(const IMessageBase &m);
00193 
00194                 public:
00195                         static void initClass();
00196                         static void releaseClass();
00197 
00198                         virtual void Launch(const std::string &name, NLAIAGENT::IBasicAgent *);
00199         };
00200 }
00201 #endif