Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   Related Pages  

Feat.h

00001 /*
00002  * Feat.h -- class interface for feats
00003  * Copyright (C) 2002  Eric Lemings <elemings@users.sourceforge.net>
00004  *
00005  * This software is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU General Public License
00007  * as published by the Free Software Foundation; either version 2
00008  * of the License, or (at your option) any later version.
00009  *
00010  * This software is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this software; if not, write to the Free Software
00017  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
00018  * 02111-1307, USA
00019  *
00020  * RCS: $Id: Feat.h,v 1.10 2003/04/15 16:58:36 elemings Exp $
00021  */
00022 
00023 #ifdef __cplusplus
00024 
00025 #  ifndef OGS_CORE_FEAT_H
00026 #    define OGS_CORE_FEAT_H
00027 
00028 #    include <ogs/core/Creature.h>
00029 #    include <ogs/core/Experience.h>
00030 #    include <ogs/core/Feature.h>
00031 #    include <ogs/core/Namespace.h>
00032 
00033 OGS_BEGIN_CORE_NAMESPACE
00034 
00039 class Feat: public Feature {
00040   public:
00045     enum Compatibility {
00050       EXCLUSIVE = 1,
00051 
00059       REPEATABLE = 2,
00060 
00068       CUMULATIVE = 3
00069     };
00070 
00075     enum Group {
00081       GENERAL = 1,
00082 
00088       COMBAT = 2,
00089 
00096       MAGIC = 3,
00097 
00103       SPECIAL = 4,
00104     };
00105 
00106     static unsigned getSlotCount (XP::Level xpLevel);
00107     static XP::Level getSlotCountLevel (unsigned slotCount);
00108 
00109     Compatibility getCompatibility () const;
00110     Group getGroup () const;
00111 
00112     virtual ~Feat () { }
00113 
00114   protected:
00115     Feat (Compatibility compatibility, Group group = GENERAL);
00116 
00117     virtual bool canAttach (const Object& object) const;
00118     Creature* getCreature ();
00119 
00124     template <class T>
00125     struct IsInstance {
00126       bool operator() (FeatPtr featPtr);
00127     };
00128 
00129     template <class T>
00130     bool findFeat (const Object& object) const;
00131 
00132   private:
00133     Compatibility _compatibility;
00134     Group _group;
00135 };
00136 
00140 inline Feat::Feat (Compatibility compatibility, Group group):
00141   _compatibility (compatibility),
00142   _group (group) {
00143   // empty constructor body
00144 }
00145 
00153 inline unsigned
00154 Feat::getSlotCount (XP::Level xpLevel) {
00155   return (xpLevel < 2? xpLevel: xpLevel / 3 + 1);
00156 }
00157 
00163 inline Feat::Compatibility
00164 Feat::getCompatibility () const {
00165   return (this->_compatibility);
00166 }
00167 
00173 inline Feat::Group
00174 Feat::getGroup () const {
00175   return (this->_group);
00176 }
00177 
00185 inline Creature*
00186 Feat::getCreature () {
00187   return (dynamic_cast<Creature*> (getObject ()));
00188 }
00189 
00197 template <class T>
00198 bool Feat::IsInstance<T>::operator() (FeatPtr featPtr) {
00199   return (dynamic_cast<T*> (featPtr.get ()) != NULL);
00200 }
00201 
00210 template <class T>
00211 bool Feat::findFeat (const Object& object) const {
00212   const Creature* creature = dynamic_cast<const Creature*> (&object);
00213 
00214   if (creature != NULL) {
00215     Feats feats = creature->getFeats ();
00216     Feats::iterator end = feats.end ();
00217     return (end != std::find_if (feats.begin (), end, IsInstance<T> ()));
00218   }
00219 
00220   return (false);
00221 }
00222 
00223 OGS_END_CORE_NAMESPACE
00224 
00225 #  endif /* !defined OGS_CORE_FEAT_H */
00226 
00227 #endif /* defined __cplusplus */
00228 

Generated on Sun Apr 20 03:36:19 2003 for Open Gaming System (OGS) by doxygen1.3