# 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  

character.cpp

Go to the documentation of this file.
00001 
00006 /* Copyright, 2001 Nevrax Ltd.
00007  *
00008  * This file is part of NEVRAX NEL.
00009  * NEVRAX NEL is free software; you can redistribute it and/or modify
00010  * it under the terms of the GNU General Public License as published by
00011  * the Free Software Foundation; either version 2, or (at your option)
00012  * any later version.
00013 
00014  * NEVRAX NEL is distributed in the hope that it will be useful, but
00015  * WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00017  * General Public License for more details.
00018 
00019  * You should have received a copy of the GNU General Public License
00020  * along with NEVRAX NEL; see the file COPYING. If not, write to the
00021  * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
00022  * MA 02111-1307, USA.
00023  */
00024 
00025 #include "nel/ai/character/character.h"
00026 
00027 namespace NLAICHARACTER
00028 {
00029 
00030 /*
00031 ##############################
00032         ICharacter
00033 ##############################
00034 */
00035 
00036         const std::string &ICharacter::getName() const
00037         {
00038                 throw;
00039         }
00040 
00041         void setName(const std::string &)
00042         {
00043                 throw;
00044         }
00045 
00046         const ICharacter *ICharacter::haveCharacter(const std::string &) const
00047         {
00048                 throw;
00049         }
00050 
00051         bool ICharacter::canAddCharacter() const
00052         {
00053                 throw;
00054         }
00055 
00056         bool ICharacter::addCharacter(const ICharacter &)
00057         {
00058                 throw;
00059         }
00060 
00061 
00062 /*
00063 ##############################
00064         CCharacterChild
00065 ##############################
00066 */
00067         const NLAIC::CIdentType *CCharacterChild::IDCharacterChild = NULL;
00068         CCharacterChild::CCharacterChild(const CCharacterChild &name):ICharacter(name),_Name(name._Name)
00069         {
00070         }
00071         CCharacterChild::~CCharacterChild()
00072         {
00073         }
00074 
00075         const ICharacter *CCharacterChild::haveCharacter(const std::string &s) const
00076         {
00077                 if(s == _Name) return this;
00078                 const ICharacter *c = (const ICharacter *)getParent();  
00079                 if(c == NULL) return NULL;
00080                 else return c->haveCharacter(s);
00081         }
00082 
00083         bool CCharacterChild::canAddCharacter() const
00084         {
00085                 return false;
00086         }
00087         bool CCharacterChild::addCharacter(const ICharacter &)
00088         {
00089                 return false;
00090         }
00091 
00092         void CCharacterChild::save(NLMISC::IStream &os)
00093         {
00094                 ICharacter::save(os);
00095                 os.serial(_Name);
00096         }
00097 
00098         void CCharacterChild::load(NLMISC::IStream &is)
00099         {
00100                 ICharacter::load(is);
00101                 is.serial(_Name);
00102         }
00103 
00104         void CCharacterChild::getDebugString(std::string &text) const
00105         {
00106         }
00107 
00108         const NLAIC::IBasicType *CCharacterChild::clone() const
00109         {
00110                 return new CCharacterChild(*this);
00111         }
00112 
00113         const NLAIC::IBasicType *CCharacterChild::newInstance() const
00114         {
00115                 return new CCharacterChild(*this);
00116         }
00117 
00118         bool CCharacterChild::isEqual(const NLAIAGENT::IBasicObjectIA &a) const
00119         {
00120                 const ICharacter &c = (const ICharacter &)a;
00121                 return c.getName() == _Name;
00122         }
00123 
00124         const NLAIAGENT::IObjectIA::CProcessResult &CCharacterChild::run()
00125         {
00126                 return NLAIAGENT::IObjectIA::ProcessRun;
00127         }
00128 
00129         void CCharacterChild::initClass()
00130         {
00131                 CCharacterChild n("TrucNoeud");
00132                 IDCharacterChild = new NLAIC::CIdentType("CharacterChild",NLAIC::CSelfClassFactory(n),
00133                                                                                                                 NLAIC::CTypeOfObject(NLAIC::CTypeOfObject::tObject),
00134                                                                                                                 NLAIC::CTypeOfOperator(NLAIC::CTypeOfOperator::opNone));
00135         }
00136 
00137         void CCharacterChild::releaseClass()
00138         {
00139                 delete IDCharacterChild;
00140         }
00141 
00142 /*
00143 ##############################
00144         CCharacterNoeud
00145 ##############################
00146 */
00147 
00148         const NLAIC::CIdentType *CCharacterNoeud::IDCharacterNoeud = NULL;
00149         CCharacterNoeud::CCharacterNoeud(const CCharacterNoeud &c):CCharacterChild(c)
00150         {
00151                 std::list<ICharacter *>::const_iterator i = c._Character.begin();
00152                 while(i != c._Character.end())
00153                 {
00154                         _Character.push_back(*i);
00155                         (*i)->incRef();
00156                         i++;
00157                 }
00158         }
00159         CCharacterNoeud::~CCharacterNoeud()
00160         {
00161         }
00162 
00163         const ICharacter *CCharacterNoeud::haveCharacter(const std::string &s) const
00164         {
00165                 if(s == getName()) return this;
00166                 else
00167                 {
00168                         std::list<ICharacter *>::const_iterator i = _Character.begin();
00169                         while(i != _Character.end())
00170                         {
00171                                 const ICharacter *c = (*i++)->haveCharacter(s);
00172                                 if(c != NULL) return c;
00173                         }
00174                 }
00175                 return NULL;
00176         }
00177 
00178         bool CCharacterNoeud::addCharacter(const ICharacter &c)
00179         {
00180                 _Character.push_back((ICharacter *)c.clone());
00181                 return true;
00182         }
00183 
00184         bool CCharacterNoeud::canAddCharacter() const
00185         {
00186                 return true;
00187         }
00188 
00189         void CCharacterNoeud::save(NLMISC::IStream &os)
00190         {
00191                 CCharacterChild::save(os);
00192                 std::list<ICharacter *>::const_iterator i = _Character.begin();
00193                 while(i != _Character.end())
00194                 {                       
00195                         os.serial( (NLAIC::CIdentType &) (getType()) );
00196                         (*i)->save(os);
00197                         i++;
00198                 }
00199         }
00200 
00201         void CCharacterNoeud::load(NLMISC::IStream &is)
00202         {
00203                 CCharacterChild::load(is);
00204         }
00205 
00206         void CCharacterNoeud::getDebugString(char *text) const
00207         {
00208         }
00209 
00210         const NLAIC::IBasicType *CCharacterNoeud::clone() const
00211         {
00212                 return new CCharacterNoeud(*this);
00213         }
00214 
00215         const NLAIC::IBasicType *CCharacterNoeud::newInstance() const
00216         {
00217                 return new CCharacterNoeud(getName());
00218         }
00219 
00220         bool CCharacterNoeud::isEqual(const NLAIAGENT::IBasicObjectIA &a) const
00221         {
00222 
00223                 const CCharacterNoeud &c = (const CCharacterNoeud &)a;
00224                 if(c._Character.size() != _Character.size()) return false;
00225 
00226                 std::list<ICharacter *>::const_iterator i = _Character.begin();
00227                 std::list<ICharacter *>::const_iterator j = c._Character.begin();
00228                 while(i != _Character.end())
00229                 {
00230                         if(!((*i++)->getName() == (*j++)->getName())) return false;                     
00231                 }
00232                 return CCharacterChild::isEqual(a);
00233         }
00234 
00235         void CCharacterNoeud::initClass()
00236         {
00237                 CCharacterNoeud n("TrucNoeud");
00238                 IDCharacterNoeud = new NLAIC::CIdentType("CharacterNoeud",NLAIC::CSelfClassFactory(n),
00239                                                                                                                 NLAIC::CTypeOfObject(NLAIC::CTypeOfObject::tObject),
00240                                                                                                                 NLAIC::CTypeOfOperator(NLAIC::CTypeOfOperator::opNone));
00241         }
00242 
00243         void CCharacterNoeud::releaseClass()
00244         {       
00245                 delete IDCharacterNoeud;
00246         }
00247 }