00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
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
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
00226
00227 #endif
00228