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_ABILITIES_H
00026 # define OGS_CORE_ABILITIES_H
00027
00028 # include <map>
00029
00030 # include <ogs/core/Ability.h>
00031 # include <ogs/core/Namespace.h>
00032 # include <ogs/core/Types.h>
00033
00034 OGS_BEGIN_CORE_NAMESPACE
00035
00045 class Abilities: private std::map<Ability::Type, AbilityPtr> {
00046 private:
00047 typedef std::map<Ability::Type, Ability::Score> ScoreMap;
00048 typedef std::map<Ability::Type, AbilityPtr> PtrMap;
00049
00050 public:
00052 typedef PtrMap::iterator Iterator;
00053
00058 typedef PtrMap::value_type Value;
00059
00060 struct PartialMethod;
00061
00062 Abilities ();
00063 Abilities (Ability::Method& method);
00064 Abilities (PartialMethod& partialMethod);
00065
00066 Iterator getBegin ();
00067 Iterator getEnd ();
00068 AbilityPtr operator[] (Ability::Type abilityType);
00069 bool isComplete () const;
00070
00071 bool canRerollStandard ();
00072 bool canRerollAverage ();
00073 bool canRerollHighPowered ();
00074
00075 private:
00076 bool canReroll (Modifier::Value modifier, Ability::Score score);
00077 };
00078
00084 struct Abilities::PartialMethod: public Ability::Method,
00085 private Abilities::ScoreMap {
00087 typedef Abilities::ScoreMap::value_type Value;
00088
00099 template <class _InputIterator>
00100 PartialMethod (_InputIterator first, _InputIterator last):
00101 ScoreMap (first, last) {
00102
00103 }
00104
00105 bool hasAbility (Ability::Type type);
00106 Ability::Score operator() (Ability::Type type);
00107 };
00108
00115 inline bool
00116 Abilities::PartialMethod::hasAbility (Ability::Type type) {
00117 return (this->find (type) != this->end ());
00118 }
00119
00126 inline Ability::Score
00127 Abilities::PartialMethod::operator() (Ability::Type type) {
00128 return ((*this) [type]);
00129 }
00130
00136 inline Abilities::Iterator
00137 Abilities::getBegin () {
00138 return (this->begin ());
00139 }
00140
00146 inline Abilities::Iterator
00147 Abilities::getEnd () {
00148 return (this->end ());
00149 }
00150
00158 inline AbilityPtr
00159 Abilities::operator[] (Ability::Type abilityType) {
00160
00161
00162 Iterator itor = find (abilityType);
00163 return (itor == end ()? AbilityPtr (): itor->second);
00164 }
00165
00172 inline bool
00173 Abilities::isComplete () const {
00174 return (this->size () == Ability::NUM);
00175 }
00176
00185 inline bool
00186 Abilities::canRerollStandard () {
00187 return (canReroll (0, 13));
00188 }
00189
00198 inline bool
00199 Abilities::canRerollAverage () {
00200 return (canReroll (-3, 11));
00201 }
00202
00211 inline bool
00212 Abilities::canRerollHighPowered () {
00213 return (canReroll (+1, 14));
00214 }
00215
00216 OGS_END_CORE_NAMESPACE
00217
00218 # endif
00219
00220 #endif
00221