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

Abilities.h

00001 /*
00002  * Abilities.h -- class interfaces for sets of ability scores
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: Abilities.h,v 1.6 2003/04/15 16:58:33 elemings Exp $
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     // empty constructor body
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   // The map::operator[] inserts the key if not found so this operator
00161   // cannot use it.  It has to check first and return NULL if not found.
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 /* !defined OGS_CORE_ABILITIES_H */
00219 
00220 #endif /* defined __cplusplus */
00221 

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