# 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 
00037 namespace NLAIAGENT
00038 {
00039 
00040         class CComponentHandle/* : public IObjectIA */{
00041                 private:
00042                         IVarName                *_CompName;
00043                         const IObjectIA *_Comp;
00044                         IAgent                  *_CompFather;
00045 
00046                 public:
00047                         CComponentHandle()
00048                         {
00049                                 _Comp = NULL;
00050                                 _CompFather = NULL;
00051                         }
00052 
00053                         ~CComponentHandle()
00054                         {
00055 //                              if ( _Comp )
00056 //                                      _Comp->release();
00057                         }
00058 
00059 
00060                         CComponentHandle(const IVarName &comp_name, IAgent *comp_father , bool get = false)
00061                         {
00062                                 _CompName = (IVarName *) comp_name.clone();
00063                                 _CompFather = comp_father;
00064                                 if ( get )
00065                                         getComponent();
00066                                 else
00067                                         _Comp = NULL;
00068                         }
00069 
00070                         void getComponent()
00071                         {
00072                                 if ( _CompFather )
00073                                 {
00074 
00075 #ifdef _DEBUG
00076                                         const char *dbg_father_type = (const char *) _CompFather->getType();
00077                                         const char *dbg_comp_name = (const char *) _CompName->getType();
00078                                         char buffer[1024 * 8];
00079                                         _CompName->getDebugString(buffer);
00080 #endif
00081 
00082                                         // Looks in static components
00083                                         sint32 comp_id = _CompFather->getStaticMemberIndex( *_CompName );
00084                                         if ( comp_id >= 0)
00085                                                 _Comp = _CompFather->getStaticMember( comp_id );
00086                                         else
00087                                                 _Comp = NULL;
00088 
00089                                         if ( _Comp == NULL )
00090                                         {
00091                                                 // Looks in dynamic component
00092                                                 CGroupType *param = new CGroupType();
00093                                                 param->push( (IObjectIA *) _CompName );
00094                                                 IObjectIA::CProcessResult comp = ( (CAgentScript *) _CompFather)->getDynamicAgent(param);
00095                                                 param->pop();
00096                                                 delete param;
00097                                                 if ( comp.Result )
00098                                                         _Comp = comp.Result;
00099                                                 else
00100                                                         _Comp = NULL;
00101                                         }
00102                                 }
00103                         }
00104 
00105                         const IObjectIA *getValue()
00106                         {
00107                                 if ( _Comp )
00108                                         return _Comp;
00109                                 
00110                                 getComponent();
00111                                 return _Comp;
00112                         }
00113         };
00114 
00115 
00125         class CActorScript  : public CAgentScript
00126         {
00127                 protected:
00128 
00129                         enum c_funcs_id 
00130                         {
00131                                 fid_activate,
00132                                 fid_onActivate,
00133                                 fid_unActivate,
00134                                 fid_onUnActivate,
00135                                 fid_switch,
00136                                 fid_last
00137                         };
00138 
00139                         bool _IsActivated;
00140                         sint32  _OnActivateIndex;
00141                         sint32  _OnUnActivateIndex;
00142                         std::vector<CComponentHandle *> _Actors;
00143                         
00147                         virtual void switchActor(CActorScript *, bool stay_active = false);
00151                         virtual void switchActor(std::vector<CActorScript *> &, bool stay_active = false);
00155                         virtual void switchActor(std::vector<CComponentHandle *> &, bool stay_active = false);
00156 
00157 
00158                 public:
00159                         // Builds and actor with its father
00160                         CActorScript(IAgentManager *, bool activated = false);
00161                         // copy constructor
00162                         CActorScript(const CActorScript &);
00163                         CActorScript(IAgentManager *, IBasicAgent *, std::list<IObjectIA *> &, NLAISCRIPT::CActorClass *);
00164                         virtual ~CActorScript();
00165 
00167                         bool isActivated();
00169 
00171                         void activate();
00173                         virtual void onActivate();
00174 
00176                         void unActivate();
00178                         virtual void onUnActivate();
00179                         
00180                         virtual int getBaseMethodCount() const;
00181 
00183                         virtual const NLAIC::IBasicType *clone() const;
00184                         virtual const NLAIC::IBasicType *newInstance() const;
00185                         virtual void getDebugString(char *t) const;
00186                         virtual bool isEqual(const IBasicObjectIA &a) const;
00187                         virtual void processMessages();
00188                         virtual const CProcessResult &run();
00189 
00190 //                      virtual IObjectIA *run(const IMessageBase &msg);
00191                         virtual CProcessResult sendMessage(IObjectIA *);
00192                         virtual const NLAIC::CIdentType &getType() const;
00193 
00194                         static const NLAIC::CIdentType IdActorScript;
00195 
00196                         virtual void save(NLMISC::IStream &os);         
00197                         virtual void load(NLMISC::IStream &is);         
00198 
00199                         virtual IObjectIA::CProcessResult runMethodBase(int heritance, int index,IObjectIA *);
00200                         virtual IObjectIA::CProcessResult runMethodBase(int index,IObjectIA *);
00201 
00202                         virtual tQueue isMember(const NLAIAGENT::IVarName *, const NLAIAGENT::IVarName *, const IObjectIA &) const;
00203 //                      virtual IObjectIA::CProcessResult runMethodeMember(sint32, sint32, IObjectIA *);
00204 //                      virtual IObjectIA::CProcessResult runMethodeMember(sint32, IObjectIA *);
00205                         virtual sint32 getMethodIndexSize() const;
00206 
00207                         void getFatherComponent(IVarName &);
00208         };
00209 }
00210 #endif