[ogs-changes] dist/c++/ogs/core BodyPart.cpp,NONE,1.1 BodyPart.h,NONE,1.1 Strength.cpp,NONE,1.1 Stre
Status: Alpha
Brought to you by:
elemings
Update of /cvsroot/ogs/dist/c++/ogs/core In directory sc8-pr-cvs1:/tmp/cvs-serv24985/core Modified Files: Abilities.cpp Abilities.h Ability.cpp Ability.h Character.cpp Character.h Creature.cpp Creature.h Defense.cpp Entity.cpp Entity.h Feat.cpp Feat.h Feature.h Item.cpp Item.h Makefile.am Skill.cpp Skill.h Added Files: BodyPart.cpp BodyPart.h Strength.cpp Strength.h Log Message: See C++ ChangeLog (Mar 28) for details. --- NEW FILE: BodyPart.cpp --- /* * BodyPart.cpp -- class implementation for body parts * Copyright (C) 2003 Eric Lemings <ele...@us...> * * This software is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this software; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA * 02111-1307, USA * * RCS: $Id: BodyPart.cpp,v 1.1 2003/03/29 02:10:29 elemings Exp $ */ #include "ogs/core/Creature.h" #include "ogs/core/Item.h" #include "ogs/core/BodyPart.h" using ogs::core::Creature; using ogs::core::Item; using ogs::core::BodyPart; /** * Create a new body part. The type of body part does not have to be * one of the predefined humanoid body parts. It can be any body part * specific to a particular creature such as tails, wings, horns, or * whatever. The type value of the body part however must not conflict * with one of the predefined types. */ BodyPart::BodyPart (Creature& creature, Type type): _creature (creature), _type (type), _items () { // empty constructor body } /** * Equip an item on this body part. If the item cannot be equipped, * this function will return false. * * @param item Item to be equipped on this body part. * @return True if item is equipped. */ bool BodyPart::equipItem (Item& item) { return (false); // TODO: Implement this function. } --- NEW FILE: BodyPart.h --- /* * BodyPart.h -- class interface for body parts * Copyright (C) 2003 Eric Lemings <ele...@us...> * * This software is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this software; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA * 02111-1307, USA * * RCS: $Id: BodyPart.h,v 1.1 2003/03/29 02:10:29 elemings Exp $ */ #ifdef __cplusplus # ifndef OGS_CORE_BODY_PART_H # define OGS_CORE_BODY_PART_H # include <ogs/core/Namespace.h> OGS_BEGIN_CORE_NAMESPACE class Creature; class Item; /** * A part of the body where items can be equipped. An eqipped item is * worn, held, or used somehow. The body part determines how many items * can be equipped and how they are equipped. A normal human hand for * example can wear one glove, five rings, and hold one item. */ class BodyPart: public Object { public: /** * A type of body part. This enumeration defines the omnipresent * humanoid body parts. Body parts of other creatures (such as * tails, wings, horns, whatever) may be defined by other classes. */ enum Type { HEAD, EYES, LEFT_EYE, RIGHT_EYE, NECK, TORSO, BACK, ARMS, LEFT_ARM, RIGHT_ARM, HANDS, LEFT_HAND, RIGHT_HAND, WAIST, LEGS, LEFT_LEG, RIGHT_LEG, LEFT_FOOT, RIGHT_FOOT, }; typedef std::list<Item*> Items; BodyPart (Creature& creature, Type type); Creature& getCreature () const; Type getType () const; Items getItems () const; bool equipItem (Item& item); bool unequipItem (Item& item); private: Creature& _creature; Type _type; Items _items; }; /** * Determine the type of this body part. * * @return Type of body part. */ inline BodyPart::Type BodyPart::getType () const { return (this->_type); } /** * Determine the equipped items for this body part. * * @return A list of equipped items for this body part. */ inline BodyPart::Items BodyPart::getItems () const { return (this->_items); } OGS_END_CORE_NAMESPACE # endif /* !defined OGS_CORE_BODY_PART_H */ #endif /* defined __cplusplus */ --- NEW FILE: Strength.cpp --- /* * Strength.cpp -- class implementation for Strength ability * Copyright (C) 2002 Eric Lemings <ele...@us...> * * This software is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this software; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA * 02111-1307, USA * * RCS: $Id: Strength.cpp,v 1.1 2003/03/29 02:10:31 elemings Exp $ */ #include <cmath> #include "ogs/core/Strength.h" using ogs::core::Strength; /** * Determine the limit of heavy loads for a creature of medium size * using this ability. * * @return Weight in pounds. */ float Strength::getMediumSizeHeavyLoad () const { Ability::Score score = getCurrentScore (); float load = 0.0; if (score < 11) { load = score * 10.0; } else if (score < 20) { static float table [] = { 115, 130, 150, 175, 200, 230, 260, 300, 350, 400, }; load = table [score - 11]; } else { static float table [] = { 400, 460, 520, 600, 700, 800, 920, 1040, 1200, 1400 }; load = table [score % 10]; int factor = (score - 20) / 10; load *= std::pow (4.0, factor); } return (load); } /** * Determine the load factor of a size. * * @param size Size of creature. * @return Load factor of size. */ float Strength::getLoadFactor (Size::Type sizeType) { return (sizeType == Size::FINE? (0.125): // 1/8 sizeType == Size::DIMINUITIVE? (0.25): sizeType == Size::TINY? (0.5): sizeType == Size::SMALL? (0.75): sizeType == Size::LARGE? 2.0: sizeType == Size::HUGE? 4.0: sizeType == Size::GARGANTUAN? 8.0: sizeType == Size::COLLOSAL? 16.0: 1.0); } --- NEW FILE: Strength.h --- /* * Strength.h -- class interface for Strength abilities * Copyright (C) 2002 Eric Lemings <ele...@us...> * * This software is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this software; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA * 02111-1307, USA * * RCS: $Id: Strength.h,v 1.1 2003/03/29 02:10:31 elemings Exp $ */ #ifdef __cplusplus # ifndef OGS_CORE_STRENGTH_H # define OGS_CORE_STRENGTH_H # include <ogs/core/Ability.h> # include <ogs/core/Namespace.h> # include <ogs/core/Size.h> OGS_BEGIN_CORE_NAMESPACE /** * An ability that determines physical force, carrying capacities, and * other similar qualities. */ class Strength: public Ability { public: Strength (Ability::Method& method = Ability::standardMethod); float getLightLoad (Size::Type sizeType = Size::MEDIUM) const; float getMediumLoad (Size::Type sizeType = Size::MEDIUM) const; float getHeavyLoad (Size::Type sizeType = Size::MEDIUM) const; private: float getMediumSizeHeavyLoad () const; static float getLoadFactor (Size::Type size); }; /** * Create a new Strength score using a method. The default method for * generating a Strength score is the standard method. * * @param method Method used to generate score. */ inline Strength::Strength (Ability::Method& method): Ability (Ability::STR, method) { // empty constructor body } /** * Determine the limit of light loads for this ability. * * @param size Size of creature. * @return Weight in pounds. */ inline float Strength::getLightLoad (Size::Type sizeType) const { return (getHeavyLoad (sizeType) / 3); } /** * Determine the limit of medium loads for this ability. * * @param size Size of creature. * @return Weight in pounds. */ inline float Strength::getMediumLoad (Size::Type sizeType) const { return ((2 * getHeavyLoad (sizeType)) / 3); } /** * Determine the limit of heavy loads for this ability. * * @param size Size of creature. * @return Weight in pounds. */ inline float Strength::getHeavyLoad (Size::Type sizeType) const { return (getMediumSizeHeavyLoad () * getLoadFactor (sizeType)); } OGS_END_CORE_NAMESPACE # endif /* !defined OGS_CORE_STRENGTH_H */ #endif /* defined __cplusplus */ Index: Abilities.cpp =================================================================== RCS file: /cvsroot/ogs/dist/c++/ogs/core/Abilities.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Abilities.cpp 25 Mar 2003 06:13:11 -0000 1.2 --- Abilities.cpp 29 Mar 2003 02:10:28 -0000 1.3 *************** *** 21,139 **** */ - #include <stdexcept> - #include "ogs/core/Abilities.h" using ogs::core::Abilities; /** ! * Create a set of abilities for this creature. Difference creatures ! * have different sets of abilities and different ways of creating these ! * abilities. The default implementation of this function returns a ! * full set of all six standard abilities created using the standard ! * method. * * @return A set of six ability scores. */ ! Abilities::Abilities (Ability::Method method) { ! this->cha = new Charisma (method); ! this->con = new Constitution (method); ! this->dex = new Dexterity (method); ! this->intl = new Intelligence (method); ! this->str = new Strength (method); ! this->wis = new Wisdom (method); ! } ! ! Abilities::Abilities (const Abilities& abilities) { ! delete this->cha; ! this->cha = abilities.cha; ! delete this->con; ! this->con = abilities.con; ! delete this->dex; ! this->dex = abilities.dex; ! delete this->intl; ! this->intl = abilities.intl; ! delete this->str; ! this->str = abilities.str; ! delete this->wis; ! this->wis = abilities.wis; } ! Abilities& Abilities::operator= (const Abilities& abilities) { ! delete this->cha; ! this->cha = abilities.cha; ! delete this->con; ! this->con = abilities.con; ! delete this->dex; ! this->dex = abilities.dex; ! delete this->intl; ! this->intl = abilities.intl; ! delete this->str; ! this->str = abilities.str; ! delete this->wis; ! this->wis = abilities.wis; ! ! return (*this); ! } Abilities::~Abilities () { ! delete this->cha; this->cha = NULL; ! delete this->con; this->con = NULL; ! delete this->dex; this->dex = NULL; ! delete this->intl; this->intl = NULL; ! delete this->str; this->str = NULL; ! delete this->wis; this->wis = NULL; } /** ! * Determine if this set of abilities can be rerolled. Abilities can be * rerolled if the total ability modifier is less than or equal to the * specified modifier value or all scores are less than or equal to the ! * specified ability score. * * @param modifier Total of all abilitiy modifiers. * @param score Highest score. * @return True if this set of abilities can be rerolled. - * @throw runtime_error If all six abilities are not present. */ bool Abilities::canReroll (Modifier::Value modifier, Ability::Score score) { ! if (this->cha == NULL || this->con == NULL || ! this->dex == NULL || this->intl == NULL || ! this->str == NULL || this->wis == NULL) { ! const char* msg = "Need all six abilities to perform this operation."; ! throw std::runtime_error (msg); ! } else { Modifier::Value total = 0; ! total += (this->cha->getModifier ()).getValue (); ! total += (this->con->getModifier ()).getValue (); ! total += (this->dex->getModifier ()).getValue (); ! total += (this->intl->getModifier ()).getValue (); ! total += (this->str->getModifier ()).getValue (); ! total += (this->wis->getModifier ()).getValue (); ! ! Ability::Score highest = this->cha->getOriginalScore (); ! if (this->con->getOriginalScore () > highest) { ! highest = this->con->getOriginalScore (); ! } ! ! if (this->dex->getOriginalScore () > highest) { ! highest = this->dex->getOriginalScore (); ! } ! ! if (this->intl->getOriginalScore () > highest) { ! highest = this->intl->getOriginalScore (); ! } ! ! if (this->str->getOriginalScore () > highest) { ! highest = this->str->getOriginalScore (); ! } ! if (this->wis->getOriginalScore () > highest) { ! highest = this->wis->getOriginalScore (); } ! return (total <= modifier || highest <= score); } } --- 21,95 ---- */ #include "ogs/core/Abilities.h" + #include "ogs/core/Ability.h" + #include "ogs/core/Strength.h" using ogs::core::Abilities; + using ogs::core::Ability; + using ogs::core::Strength; /** ! * Create a set of abilities. This constructor uses the standard method ! * by default to create a complete set of all six ability scores. * * @return A set of six ability scores. */ ! Abilities::Abilities (Ability::Method& method) { ! Map& map = *this; ! map [Ability::CHA] = Ability::createCharisma (method); ! map [Ability::CON] = Ability::createConstitution (method); ! map [Ability::DEX] = Ability::createDexterity (method); ! map [Ability::INT] = Ability::createIntelligence (method); ! map [Ability::STR] = new Strength (method); ! map [Ability::WIS] = Ability::createWisdom (method); } ! struct Abilities::Delete { ! void operator() (ValueType value) { delete value.second; } ! }; + /** + * Destroy this set of abilities. + */ Abilities::~Abilities () { ! std::for_each (this->begin (), this->end (), Delete ()); } /** ! * Determine if this set of abilities can be rerolled. Abilities can be * rerolled if the total ability modifier is less than or equal to the * specified modifier value or all scores are less than or equal to the ! * specified ability score. If this set is not a complete set of ! * abilities, then the abilities cannot be rerolled. * * @param modifier Total of all abilitiy modifiers. * @param score Highest score. * @return True if this set of abilities can be rerolled. */ bool Abilities::canReroll (Modifier::Value modifier, Ability::Score score) { + bool canReroll = false; ! if (isComplete ()) { ! Map& map = *this; Modifier::Value total = 0; ! Ability* ability = NULL; ! Ability::Score highest = 0; ! Ability::Type types [] = { ! Ability::CHA, Ability::CON, Ability::DEX, ! Ability::INT, Ability::STR, Ability::WIS ! }; ! for (int i = 0; i < Ability::NUM; ++i) { ! ability = map [types [i]]; ! total += (ability->getModifier ()).getValue (); ! if (ability->getOriginalScore () > highest) { ! highest = ability->getOriginalScore (); ! } } ! canReroll = total <= modifier || highest <= score; } + + return (canReroll); } Index: Abilities.h =================================================================== RCS file: /cvsroot/ogs/dist/c++/ogs/core/Abilities.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Abilities.h 7 Jan 2003 07:41:32 -0000 1.1 --- Abilities.h 29 Mar 2003 02:10:28 -0000 1.2 *************** *** 26,44 **** # define OGS_CORE_ABILITIES_H ! # include <ogs/core/Ability.h> ! # include <ogs/core/abilities/Charisma.h> ! # include <ogs/core/abilities/Constitution.h> ! # include <ogs/core/abilities/Dexterity.h> ! # include <ogs/core/abilities/Intelligence.h> ! # include <ogs/core/abilities/Strength.h> ! # include <ogs/core/abilities/Wisdom.h> OGS_BEGIN_CORE_NAMESPACE - using ogs::core::Ability; - - using namespace ogs::core::abilities; - /** * A set of ability scores. A set of ability scores normally consists --- 26,35 ---- # define OGS_CORE_ABILITIES_H ! # include <map> ! # include <ogs/core/Ability.h> OGS_BEGIN_CORE_NAMESPACE /** * A set of ability scores. A set of ability scores normally consists *************** *** 48,71 **** * very nature. */ ! struct Abilities { ! Charisma* cha; ! Constitution* con; ! Dexterity* dex; ! Intelligence* intl; ! Strength* str; ! Wisdom* wis; ! Abilities (Ability::Method method = Ability::standardMethod); ! Abilities (const Abilities& abilities); ! Abilities& operator= (const Abilities& rhs); ! ~Abilities (); ! bool canRerollStandard (); ! bool canRerollAverage (); ! bool canRerollHighPowered (); ! bool canReroll (Modifier::Value modifier, Ability::Score score); }; /** * Determine if this set of abilities can be rerolled using the standard * method. Abilities that are rolled using the standard method can be --- 39,128 ---- * very nature. */ ! class Abilities: private std::map<Ability::Type, Ability*> { ! public: ! // TODO: Change this to a smart pointer. ! typedef std::map<Ability::Type, Ability*>::iterator Iterator; ! Abilities (Ability::Method& method = Ability::standardMethod); ! ~Abilities (); ! Iterator getBegin (); ! Iterator getEnd (); ! Ability* operator[] (Ability::Type abilityType); ! void removeAbility (Ability::Type abilityType); ! bool isComplete () const; ! ! bool canRerollStandard (); ! bool canRerollAverage (); ! bool canRerollHighPowered (); ! ! private: ! typedef std::map<Ability::Type, Ability*> Map; ! typedef Map::value_type ValueType; ! struct Delete; ! ! Abilities (const Abilities& abilities); ! Abilities& operator= (const Abilities& abilities); ! ! bool canReroll (Modifier::Value modifier, Ability::Score score); }; /** + * Determine the iterator for the beginning of these abilities. + * + * @return Iterator for the beginning of this set. + */ + inline Abilities::Iterator + Abilities::getBegin () { + return (this->begin ()); + } + + /** + * Determine the iterator for the end of these abilities. + * + * @return Iterator for the end of these abilities. + */ + inline Abilities::Iterator + Abilities::getEnd () { + return (this->end ()); + } + + /** + * Determine the ability for a given type. If an ability for the type + * does not exist in this set, this operator returns null. + * + * @param abilityType Type of ability. + * @return An ability or null if the ability does not exist. + */ + inline Ability* + Abilities::operator[] (Ability::Type abilityType) { + // The map::operator[] inserts the key if not found so this operator + // cannot use it. It has to check first and return NULL if not found. + Iterator itor = find (abilityType); + return (itor == end ()? NULL: itor->second); + } + + /** + * Remove an ability from this set of abilities. + * + * @param abilityType Type of ability to be removed. + */ + inline void + Abilities::removeAbility (Ability::Type abilityType) { + this->erase (abilityType); + } + + /** + * Determine if this is a complete set of abilities. A complete set of + * abilities contains all six ability scores. + * + * @return True if this set is a complete set of abilities. + */ + inline bool + Abilities::isComplete () const { + return (this->size () == Ability::NUM); + } + + /** * Determine if this set of abilities can be rerolled using the standard * method. Abilities that are rolled using the standard method can be *************** *** 75,79 **** * @return True if abilities can be rerolled. */ ! inline bool Abilities::canRerollStandard () { return (canReroll (0, 13)); } --- 132,137 ---- * @return True if abilities can be rerolled. */ ! inline bool ! Abilities::canRerollStandard () { return (canReroll (0, 13)); } *************** *** 87,91 **** * @return True if abilities can be rerolled. */ ! inline bool Abilities::canRerollAverage () { return (canReroll (-3, 11)); } --- 145,150 ---- * @return True if abilities can be rerolled. */ ! inline bool ! Abilities::canRerollAverage () { return (canReroll (-3, 11)); } *************** *** 99,103 **** * @return True if abilities can be rerolled. */ ! inline bool Abilities::canRerollHighPowered () { return (canReroll (+1, 14)); } --- 158,163 ---- * @return True if abilities can be rerolled. */ ! inline bool ! Abilities::canRerollHighPowered () { return (canReroll (+1, 14)); } Index: Ability.cpp =================================================================== RCS file: /cvsroot/ogs/dist/c++/ogs/core/Ability.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** Ability.cpp 25 Mar 2003 06:13:11 -0000 1.3 --- Ability.cpp 29 Mar 2003 02:10:28 -0000 1.4 *************** *** 23,28 **** #include <algorithm> ! #include <ogs/Support.h> ! #include "ogs/core/Ability.h" --- 23,27 ---- #include <algorithm> ! #include "ogs/Support.h" #include "ogs/core/Ability.h" *************** *** 34,37 **** --- 33,38 ---- using ogs::core::Modifier; + Ability::StandardMethod Ability::standardMethod; + /** * Produce an ability score using the standard method. With *************** *** 87,97 **** } - const Ability::Method - Ability::standardMethod = &Ability::rollStandard; - const Ability::Method - Ability::averageMethod = &Ability::rollAverage; - const Ability::Method - Ability::highPoweredMethod = &Ability::rollHighPowered; - /** * Determine experience level required for a given number of ability --- 88,91 ---- *************** *** 119,210 **** * the <code>Ability</code> class. */ ! Ability::Ability (Method method) { ! // If the method were guaranteed to be non-NULL, the everything ! // including modifier could be created (instead of set below) with ! // the correct value. ! if (method == NULL) { ! method = standardMethod; ! } ! ! this->originalScore = this->currentScore = method (); ! modifier.setValue (getModifier (this->currentScore)); ! } ! ! /** ! * Change the original score of this ability. All current modifiers to ! * this ability are added to this score and the current score is updated ! * accordingly. The ability modifier may also be updated as a result. ! * ! * @param score Original score of this ability. ! */ ! void Ability::setOriginalScore (Score score) { ! if (this->originalScore != score) { ! this->originalScore = this->currentScore = score; ! ! // Add modifiers to current score. ! Modifiers::iterator itor = modifiers.begin (); ! while (itor != modifiers.end ()) { ! Modifier* modifier = *itor; ! this->currentScore += modifier->getValue (); ! ++itor; ! } ! ! // Update ability modifier only when necessary. ! if (modifier.getValue () != getModifier (this->currentScore)) { ! modifier.setValue (getModifier (this->currentScore)); ! } ! ! Event event (*this); ! notifyObservers (event); ! } ! } ! ! /** ! * Add a modifier to this ability. The current score and ability ! * modifier are updated accordingly. This ability will observe any ! * changes to the value of the modifier. ! * ! * @param modifier Modifier to be added. ! */ ! void Ability::addModifier (Modifier& modifier) { ! // Don't add same modifier more than once. ! if (std::find (modifiers.begin (), modifiers.end (), ! &modifier) == modifiers.end ()) { ! modifiers.push_front (&modifier); ! this->currentScore += modifier.getValue (); ! modifier.addObserver (*this); ! ! // Update ability modifier only when neccessary. ! if (this->modifier.getValue () != getModifier (this->currentScore)) { ! this->modifier.setValue (getModifier (this->currentScore)); ! } ! ! Event event (*this); ! notifyObservers (event); ! } ! } ! ! /** ! * Remove a modifier to this ability. The current score and ability ! * modifier is updated accordingly. ! * ! * @param modifier Modifier to be removed. ! */ ! void Ability::removeModifier (Modifier& modifier) { ! // Make sure modifier is present first. ! if (std::find (modifiers.begin (), modifiers.end (), ! &modifier) != modifiers.end ()) { ! modifiers.remove (&modifier); ! this->currentScore -= modifier.getValue (); ! modifier.removeObserver (*this); ! ! // Update ability modifier only when neccessary. ! if (this->modifier.getValue () != getModifier (this->currentScore)) { ! this->modifier.setValue (getModifier (this->currentScore)); ! } ! ! Event event (*this); ! notifyObservers (event); ! } } --- 113,122 ---- * the <code>Ability</code> class. */ ! Ability::Ability (Type type, Method& method): ! _type (type), ! _originalScore (method (type)), ! _currentScore (_originalScore), ! _modifier (getModifier (_originalScore)) { ! // empty constructor body } *************** *** 220,229 **** Modifier& modifier = dynamic_cast<Modifier&> (event.getSource ()); ! this->currentScore -= modEvent.getPreviousValue (); ! this->currentScore += modifier.getValue (); // Update ability modifier only when neccessary. ! if (this->modifier.getValue () != getModifier (this->currentScore)) { ! this->modifier.setValue (getModifier (this->currentScore)); } --- 132,141 ---- Modifier& modifier = dynamic_cast<Modifier&> (event.getSource ()); ! this->_currentScore -= modEvent.getPreviousValue (); ! this->_currentScore += modifier.getValue (); // Update ability modifier only when neccessary. ! if (this->_modifier.getValue () != getModifier (this->_currentScore)) { ! this->_modifier.setValue (getModifier (this->_currentScore)); } Index: Ability.h =================================================================== RCS file: /cvsroot/ogs/dist/c++/ogs/core/Ability.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Ability.h 13 Jan 2003 05:22:15 -0000 1.2 --- Ability.h 29 Mar 2003 02:10:28 -0000 1.3 *************** *** 29,87 **** # include <ogs/core/Die.h> # include <ogs/core/Experience.h> ! # include <ogs/core/Modifier.h> # include <ogs/core/Namespace.h> OGS_BEGIN_CORE_NAMESPACE - using namespace ogs::support; - /** ! * A physical or mental characteristic of an entity. Abilities are ! * most often associated with creatures although certain entities, such ! * as powerful magic items, can also have abilities.. The value of an ! * ability is called an ability score. Ability scores can range from ! * 0 up to 20, 30, or 50 but rarely if ever rise above 100. An ability ! * can be modified by adding other modifiers to the original score of ! * the ability. The modified ability score or current score is used to ! * determine the ability modifier. Thus, an ability has two kinds of ! * modifiers: modifiers <I>to the original score</I> and a modifier ! * <I>from the current score</I>. */ ! class Ability: public Object, public Observer { public: typedef unsigned short Score; - typedef Score (*Method) (); ! static Score rollStandard (); ! static const Method standardMethod; ! static Score rollAverage (); ! static const Method averageMethod; ! static Score rollHighPowered (); ! static const Method highPoweredMethod; ! static Modifier::Value getModifier (Score score); static unsigned getIncreaseCount (Experience::Level xpLevel); static Experience::Level getIncreaseCountLevel (unsigned count); Score getOriginalScore () const; ! void setOriginalScore (Score score); ! void addModifier (Modifier& modifier); ! void removeModifier (Modifier& modifier); Score getCurrentScore () const; Modifier& getModifier (); ! void handleEvent (Event& event); protected: ! Ability (Method method = standardMethod); private: ! typedef std::list<Modifier*> Modifiers; ! Score originalScore; ! Modifiers modifiers; ! Score currentScore; ! Modifier modifier; }; --- 29,185 ---- # include <ogs/core/Die.h> # include <ogs/core/Experience.h> ! # include <ogs/core/Modifiers.h> # include <ogs/core/Namespace.h> OGS_BEGIN_CORE_NAMESPACE /** ! * A basic characteristic of an entity. Abilities are most often ! * associated with creatures although certain entities, such as powerful ! * magic items, can also have abilities.. The value of an ability is ! * called an ability score. Ability scores are non-negative integer ! * values that can range from 0 up to 20, 30, or even 50 but rarely if ! * ever rise above 100. <P> ! * ! * An ability score can be modified by adding other modifiers to the ! * unmodified, original score of the ability. The modified, current ! * score is used to determine the ability modifier. Thus, an ability ! * has two kinds of modifiers: modifiers <I>to</I> the <I>original</I> ! * score and a modifier <I>from</I> the <I>current</I> score. <P> */ ! class Ability: public ogs::support::Object, ! public ogs::support::Observer { public: + /** + * Type of ability. There are only six types of ability scores. + * Strength, Dexterity, and Constitution are considered "physical" + * abilities. Intelligence, Wisdom, and Charisma are considered + * "mental" abilities. + */ + enum Type { + /** + * An ability that determines physical power and force. Strength + * is a special ability that additional special operations for + * determining carrying capacities. + * + * @see Strength + */ + STR = 1, + + /** + * An ability that determines agility and quickness. The + * Dexterity modifier is added to all Reflex saving throws. + * + * @see Saves::ref + */ + DEX, + + /** + * An ability that determines fitness and vigor. The Constiution + * modifier is added to all Fortitude saving throws. + * + * @see Saves::fort + */ + CON, + + /** An ability that determines reasoning and deduction. */ + INT, + + /** + * An ability that determines intuition and judgement. The Wisdom + * modifier is added to all Will saving throws. + * + * @see Saves::will + */ + WIS, + + /** A ability that determines leadership and charm. */ + CHA, + + /** Number of ability types. */ + NUM = 6 + }; + + /** An ability score. */ typedef unsigned short Score; ! /** ! * A function object that generates an ability score. The argument ! * of a method is the type of ability score to generate. A method ! * may ignore this parameter. ! */ ! struct Method { ! virtual Score operator() (Ability::Type) = 0; ! virtual ~Method () { } ! }; ! /** ! * A method that generates above-average ability scores. The ! * standard method rolls 4d6 and adds the highest three rolls to ! * generate an ability score. The standard method is normally used ! * to generate ability scores for player characters. ! */ ! struct StandardMethod: public Method { ! Score operator() (Ability::Type) { ! return (rollStandard ()); ! } ! }; + /** + * A method that generates average ability scores. The average + * method rolls 3d6 to generate an ability score. The average + * method is nnormally used to generate ability scores for + * nonplayer characters. + */ + struct AverageMethod: public Method { + Score operator() (Ability::Type) { + return (rollAverage ()); + } + }; + + /** + * A method that generates "high-powered" ability scores. The + * high-powered method rolls 5d6 and adds the highest three rolls to + * generate an ability score. The high-powered method is nnormally + * used to generate ability scores for high-level player characters + */ + struct HighPoweredMethod: public Method { + Score operator() (Ability::Type) { + return (rollHighPowered ()); + } + }; + + static Modifier::Value getModifier (Score score); static unsigned getIncreaseCount (Experience::Level xpLevel); static Experience::Level getIncreaseCountLevel (unsigned count); + static StandardMethod standardMethod; + static Ability* createDexterity (Method& method = standardMethod); + static Ability* createConstitution (Method& method = standardMethod); + static Ability* createIntelligence (Method& method = standardMethod); + static Ability* createWisdom (Method& method = standardMethod); + static Ability* createCharisma (Method& method = standardMethod); + + Type getType () const; Score getOriginalScore () const; ! Modifiers& getModifiers (); Score getCurrentScore () const; Modifier& getModifier (); ! void handleEvent (ogs::support::Event& event); protected: ! Ability (Type type, Method& method = standardMethod); private: ! Type _type; ! Score _originalScore; ! Modifiers _modifiers; ! Score _currentScore; ! Modifier _modifier; ! static Score rollStandard (); ! static Score rollAverage (); ! static Score rollHighPowered (); }; *************** *** 94,98 **** * @return An ability score. */ ! inline Ability::Score Ability::rollAverage () { return (Score (Die::roll (Die::d6, 3))); } --- 192,197 ---- * @return An ability score. */ ! inline Ability::Score ! Ability::rollAverage () { return (Score (Die::roll (Die::d6, 3))); } *************** *** 106,110 **** * @return An ability score modifier. */ ! inline Modifier::Value Ability::getModifier (Score score) { return (score / 2 - 5); } --- 205,210 ---- * @return An ability score modifier. */ ! inline Modifier::Value ! Ability::getModifier (Score score) { return (score / 2 - 5); } *************** *** 123,132 **** /** * Determine the original (unmodified) ability score. * * @return Original score of ability. */ ! inline Ability::Score Ability::getOriginalScore () const { ! return (this->originalScore); } --- 223,303 ---- /** + * Create a new Dexterity ability using a method. The default method is + * the standard method. + * + * @param method A method for generating an ability score. + * @return A new Dexterity ability. + */ + inline Ability* + Ability::createDexterity (Method& method) { + return (new Ability (DEX, method)); + } + + /** + * Create a new Constitution ability using a method. The default method + * is the standard method. + * + * @param method A method for generating an ability score. + * @return A new Constutition ability. + */ + inline Ability* + Ability::createConstitution (Method& method) { + return (new Ability (CON, method)); + } + + /** + * Create a new Intelligence ability using a method. The default method + * is the standard method. + * + * @param method A method for generating an ability score. + * @return A new Intelligence ability. + */ + inline Ability* + Ability::createIntelligence (Method& method) { + return (new Ability (INT, method)); + } + + /** + * Create a new Wisdom ability using a method. The default method is + * the standard method. + * + * @param method A method for generating an ability score. + * @return A new Wisdom ability. + */ + inline Ability* + Ability::createWisdom (Method& method) { + return (new Ability (WIS, method)); + } + + /** + * Create a new Charisma ability using a method. The default method is + * the standard method. + * + * @param method A method for generating an ability score. + * @return A new Charisma ability. + */ + inline Ability* + Ability::createCharisma (Method& method) { + return (new Ability (CHA, method)); + } + + /** * Determine the original (unmodified) ability score. * * @return Original score of ability. */ ! inline Ability::Score ! Ability::getOriginalScore () const { ! return (this->_originalScore); ! } ! ! /** ! * Determine the modifiers added to this ability score. ! * ! * @return A list of modifiers added to this ability score. ! */ ! inline Modifiers& ! Ability::getModifiers () { ! return (this->_modifiers); } *************** *** 136,141 **** * @return Current score of ability. */ ! inline Ability::Score Ability::getCurrentScore () const { ! return (this->currentScore); } --- 307,313 ---- * @return Current score of ability. */ ! inline Ability::Score ! Ability::getCurrentScore () const { ! return (this->_currentScore); } *************** *** 145,150 **** * @return Modifier from this ability. */ ! inline Modifier& Ability::getModifier () { ! return (modifier); } --- 317,323 ---- * @return Modifier from this ability. */ ! inline Modifier& ! Ability::getModifier () { ! return (this->_modifier); } Index: Character.cpp =================================================================== RCS file: /cvsroot/ogs/dist/c++/ogs/core/Character.cpp,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** Character.cpp 23 Mar 2003 22:14:36 -0000 1.4 --- Character.cpp 29 Mar 2003 02:10:29 -0000 1.5 *************** *** 24,27 **** --- 24,29 ---- #include "ogs/core/Character.h" + using ogs::core::Abilities; + using ogs::core::Ability; using ogs::core::CClass; using ogs::core::Character; *************** *** 29,33 **** using ogs::core::Modifiers; using ogs::core::Skill; - using ogs::core::abilities::Intelligence; /** --- 31,34 ---- *************** *** 75,79 **** // Add Ingelligence bonus if any. ! Ability* intl = (_creature.getAbilities ()).intl; if (intl != NULL) { Modifier& modifier = intl->getModifier (); --- 76,81 ---- // Add Ingelligence bonus if any. ! Abilities& abilities = _creature.getAbilities (); ! Ability* intl = abilities [Ability::INT]; if (intl != NULL) { Modifier& modifier = intl->getModifier (); *************** *** 126,152 **** */ Character::Advance::Advance (CClass& cclass): ! _cclass (cclass), _hitPoints (0), _ability (NULL), _skills (), _feats () { // TODO: Roll hit die for this cclass. - } - - /** - * Assign an advancement object to another advancement object. This - * operator is required for STL use. - * - * @param rhs Right-hand side of assignment operator. - * @return Left-hand side of assignment operator. - */ - Character::Advance& - Character::Advance::operator= (const Character::Advance& rhs) { - this->_cclass = rhs._cclass; - this->_hitPoints = rhs._hitPoints; - this->_ability = rhs._ability; - this->_skills = rhs._skills; - this->_feats = rhs._feats; - - // TODO: Anything else done in the body of the constructor. - - return (*this); } --- 128,134 ---- */ Character::Advance::Advance (CClass& cclass): ! _cclass (&cclass), _hitPoints (0), _ability (NULL), _skills (), _feats () { // TODO: Roll hit die for this cclass. } Index: Character.h =================================================================== RCS file: /cvsroot/ogs/dist/c++/ogs/core/Character.h,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** Character.h 23 Mar 2003 22:14:36 -0000 1.5 --- Character.h 29 Mar 2003 02:10:29 -0000 1.6 *************** *** 86,90 **** Advance (); Advance (CClass& cclass); - Advance& operator= (const Advance& rhs); CClass& getCClass () const; --- 86,89 ---- *************** *** 99,103 **** typedef std::vector<Feat*> Feats; ! CClass& _cclass; Die::Value _hitPoints; Ability* _ability; --- 98,102 ---- typedef std::vector<Feat*> Feats; ! CClass* _cclass; Die::Value _hitPoints; Ability* _ability; *************** *** 149,153 **** */ inline CClass& Character::Advance::getCClass () const { ! return (_cclass); } --- 148,152 ---- */ inline CClass& Character::Advance::getCClass () const { ! return (*_cclass); } Index: Creature.cpp =================================================================== RCS file: /cvsroot/ogs/dist/c++/ogs/core/Creature.cpp,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** Creature.cpp 25 Mar 2003 06:13:11 -0000 1.7 --- Creature.cpp 29 Mar 2003 02:10:29 -0000 1.8 *************** *** 26,29 **** --- 26,30 ---- #include "ogs/core/Feat.h" + using ogs::core::BodyPart; using ogs::core::Creature; using ogs::core::Die; *************** *** 32,44 **** /** * Create a new creature. This constructor is protected so only derived ! * classes can call it. The new creature has no hit dice, no initiative ! * modifiers, no save modifiers, random ability scores rolled using the ! * standard method, no skills, no feats, and no associated character. */ ! Creature::Creature (): ! hitDice (), initiative (), ! saves (), abilities (), ! skills (), feats (), ! character (NULL) { } /** --- 33,65 ---- /** * Create a new creature. This constructor is protected so only derived ! * classes can call it. The new creature has no skills, no feats, and ! * no hit dice. Ability scores rolled using the standard method and no ! * character is associated with the creature. */ ! Creature::Creature (Body body): ! _hitDice (), _initiative (), _saves (), _abilities (), ! _skills (), _feats (), _body (body), _character (NULL) { ! // Add Dexterity modifier to Reflex save, initiative, and defense. ! Ability* ability = this->_abilities [Ability::DEX]; ! Modifier& modifier = ability->getModifier (); ! this->_saves.ref.addModifier (modifier); ! this->_initiative.addModifier (modifier); ! Defense& defense = getDefense (); ! defense.addModifier (modifier); ! ! // Add other ability modifiers to saving throws. ! ability = this->_abilities [Ability::CON]; ! this->_saves.fort.addModifier (ability->getModifier ()); ! ability = this->_abilities [Ability::WIS]; ! this->_saves.will.addModifier (ability->getModifier ()); ! } ! ! struct Delete { ! void operator() (BodyPart* bodyPart) { delete bodyPart; } ! }; ! ! Creature::~Creature () { ! std::for_each (this->_body.begin (), this->_body.end (), Delete ()); ! } /** *************** *** 51,58 **** // Make sure the skill isn't already in the list of skills. ! Skills::iterator end = skills.end (); ! if (std::find (skills.begin (), end, &skill) != end) { //if (skill is not an exclusive skill) { ! skills.push_back (&skill); //} } --- 72,79 ---- // Make sure the skill isn't already in the list of skills. ! Skills::iterator end = _skills.end (); ! if (std::find (_skills.begin (), end, &skill) != end) { //if (skill is not an exclusive skill) { ! _skills.push_back (&skill); //} } *************** *** 81,85 **** if (attachFeat) { if (attachFeat = feat.attachObject (*this)) { ! feats.push_back (&feat); } } --- 102,106 ---- if (attachFeat) { if (attachFeat = feat.attachObject (*this)) { ! _feats.push_back (&feat); } } *************** *** 96,108 **** bool removed = false; ! Feats::iterator end = feats.end (); ! Feats::iterator itor = std::find (this->feats.begin (), end, &feat); if (itor != end) { if (removed = feat.detachObject ()) { ! feats.erase (itor); } } return (removed); } --- 117,166 ---- bool removed = false; ! Feats::iterator end = _feats.end (); ! Feats::iterator itor = std::find (_feats.begin (), end, &feat); if (itor != end) { if (removed = feat.detachObject ()) { ! _feats.erase (itor); } } return (removed); + } + + /** + * Equip an item on this body. This function will cycle through all + * body parts until it finds one where the item can be equipped. If it + * cannot find a part, this function will return false. + * + * @param item Item to be equipped on this body. + * @return True if item is equipped. + */ + bool Creature::equipItem (Item& item) { + return (false); // TODO: Implement this function. + } + + /** + * Equip an item on a part of this body. If the item can not be + * equipped on the specified part of the body, this function will return + * false. + * + * @param item Item to be equipped on this body. + * @param part BodyPart of the body to equip item. + * @return True if item is equipped. + */ + bool Creature::equipItem (Item& item, BodyPart& part) { + return (false); // TODO: Implement this function. + } + + /** + * Remove an equipped item from this body. If the item is not currently + * equipped or cannot be removed (such as cursed items), this function + * will return false. + * + * @param item Item to be removed from this body. + * @return True if item is no longer equipped. + */ + bool Creature::unequipItem (Item& item) { + return (true); // TODO: Impelement this function. } Index: Creature.h =================================================================== RCS file: /cvsroot/ogs/dist/c++/ogs/core/Creature.h,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** Creature.h 25 Mar 2003 06:13:11 -0000 1.7 --- Creature.h 29 Mar 2003 02:10:29 -0000 1.8 *************** *** 34,37 **** --- 34,38 ---- # include <ogs/core/Modifiers.h> # include <ogs/core/Namespace.h> + # include <ogs/core/BodyPart.h> # include <ogs/core/Saves.h> *************** *** 40,43 **** --- 41,45 ---- class Character; class Feat; + class Item; class Skill; *************** *** 50,53 **** --- 52,56 ---- typedef std::list<Skill*> Skills; typedef std::list<Feat*> Feats; + typedef std::list<BodyPart*> Body; Dice& getHitDice (); *************** *** 57,68 **** Abilities& getAbilities (); ! Skills& getSkills (); bool addSkill (Skill& skill); bool removeSkill (Skill& skill); ! Feats getFeats (); bool addFeat (Feat& feat); bool removeFeat (Feat& feat); Character* getCharacter () const; --- 60,76 ---- Abilities& getAbilities (); ! Skills getSkills () const; bool addSkill (Skill& skill); bool removeSkill (Skill& skill); ! Feats getFeats () const; bool addFeat (Feat& feat); bool removeFeat (Feat& feat); + Body getBody () const; + bool equipItem (Item& item); + bool equipItem (Item& item, BodyPart& part); + bool unequipItem (Item& item); + Character* getCharacter () const; *************** *** 70,84 **** protected: ! Creature (); private: ! Dice hitDice; ! Modifiers initiative; ! //moves; ! Saves saves; ! Abilities abilities; ! Skills skills; ! Feats feats; ! Character* character; }; --- 78,94 ---- protected: ! Creature (Body body = Body ()); ! void setBody (Body body); private: ! Dice _hitDice; ! Modifiers _initiative; ! //TODO: Add moves; ! Saves _saves; ! Abilities _abilities; ! Skills _skills; ! Feats _feats; ! Body _body; ! Character* _character; }; *************** *** 90,94 **** */ inline Modifiers& Creature::getInitiative () { ! return (initiative); } --- 100,104 ---- */ inline Modifiers& Creature::getInitiative () { ! return (this->_initiative); } *************** *** 99,103 **** */ inline Die::Value Creature::rollInitiative () const { ! return (Die::roll () + initiative.getValue ()); } --- 109,113 ---- */ inline Die::Value Creature::rollInitiative () const { ! return (Die::roll () + _initiative.getValue ()); } *************** *** 108,112 **** */ inline Abilities& Creature::getAbilities () { ! return (abilities); } --- 118,161 ---- */ inline Abilities& Creature::getAbilities () { ! return (this->_abilities); ! } ! ! /** ! * Determine the saving throws for this creature. ! * ! * @return Saving throws for this creature. ! */ ! inline Saves& Creature::getSaves () { ! return (this->_saves); ! } ! ! /** ! * Determine the skills for this creature. ! * ! * @return A list of skills for this creature. ! */ ! inline Creature::Skills ! Creature::getSkills () const { ! return (this->_skills); ! } ! ! /** ! * Determine the feats for this creature. ! * ! * @return A list of feats for this creature. ! */ ! inline Creature::Feats ! Creature::getFeats () const { ! return (this->_feats); ! } ! ! /** ! * Determine the body parts of this creature. ! * ! * @return A list of body parts of this creature. ! */ ! inline Creature::Body ! Creature::getBody () const { ! return (this->_body); } *************** *** 119,126 **** */ inline Character* Creature::getCharacter () const { ! return (this->character); } ! inline Creature::~Creature () { } OGS_END_CORE_NAMESPACE --- 168,183 ---- */ inline Character* Creature::getCharacter () const { ! return (this->_character); } ! /** ! * Change the body of this creature. ! * ! * @param body Body of this creature. ! */ ! inline void ! Creature::setBody (Body body) { ! this->_body = body; ! } OGS_END_CORE_NAMESPACE Index: Defense.cpp =================================================================== RCS file: /cvsroot/ogs/dist/c++/ogs/core/Defense.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Defense.cpp 25 Mar 2003 06:13:11 -0000 1.2 --- Defense.cpp 29 Mar 2003 02:10:29 -0000 1.3 *************** *** 21,26 **** */ ! #include <ogs/support/Event.h> ! #include "ogs/core/Defense.h" #include "ogs/core/Modifier.h" --- 21,25 ---- */ ! #include "ogs/support/Event.h" #include "ogs/core/Defense.h" #include "ogs/core/Modifier.h" Index: Entity.cpp =================================================================== RCS file: /cvsroot/ogs/dist/c++/ogs/core/Entity.cpp,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** Entity.cpp 25 Mar 2003 06:13:11 -0000 1.4 --- Entity.cpp 29 Mar 2003 02:10:29 -0000 1.5 *************** *** 33,39 **** * The size modifier is automatically added to defense. So any change * in size will automatically be reflected in the defense. */ ! Entity::Entity (Size::Type size): ! _weight (0.0), _size (size), _defense (), _currentHealth (0), _maximumHealth (0) /*, _features ()*/ { _defense.addModifier (_size.getDefenseModifier ()); --- 33,42 ---- * The size modifier is automatically added to defense. So any change * in size will automatically be reflected in the defense. + * + * @param weight Weight of entity. + * @param size Size of entity. */ ! Entity::Entity (Weight weight, Size::Type size): ! _weight (weight), _size (size), _defense (), _currentHealth (0), _maximumHealth (0) /*, _features ()*/ { _defense.addModifier (_size.getDefenseModifier ()); Index: Entity.h =================================================================== RCS file: /cvsroot/ogs/dist/c++/ogs/core/Entity.h,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** Entity.h 25 Mar 2003 06:13:11 -0000 1.4 --- Entity.h 29 Mar 2003 02:10:29 -0000 1.5 *************** *** 63,67 **** protected: ! Entity (Size::Type size = Size::MEDIUM); private: --- 63,67 ---- protected: ! Entity (Weight weight = 0.0, Size::Type size = Size::MEDIUM); private: Index: Feat.cpp =================================================================== RCS file: /cvsroot/ogs/dist/c++/ogs/core/Feat.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** Feat.cpp 25 Mar 2003 06:13:11 -0000 1.3 --- Feat.cpp 29 Mar 2003 02:10:29 -0000 1.4 *************** *** 54,60 **** * @return True if the feature is attached to the object. */ ! bool Feat::canAttach (Object& object) const { return (Feature::canAttach (object) && ! dynamic_cast<Creature*> (&object) != NULL); } --- 54,60 ---- * @return True if the feature is attached to the object. */ ! bool Feat::canAttach (const Object& object) const { return (Feature::canAttach (object) && ! dynamic_cast<const Creature*> (&object) != NULL); } *************** *** 66,72 **** */ template <class FeatClass> ! bool Feat::findFeat (Object& object) const { bool found = false; ! Creature* creature = dynamic_cast<Creature*> (&object); if (creature != NULL) { --- 66,72 ---- */ template <class FeatClass> ! bool Feat::findFeat (const Object& object) const { bool found = false; ! const Creature* creature = dynamic_cast<const Creature*> (&object); if (creature != NULL) { *************** *** 75,84 **** while (itor != feats.end ()) { ! FeatClass* feat = dynamic_cast <FeatClass*> (*itor); if (feat != NULL) { found = true; } - - ++itor; } } --- 75,82 ---- while (itor != feats.end ()) { ! FeatClass* feat = dynamic_cast <FeatClass*> (*itor++); if (feat != NULL) { found = true; } } } Index: Feat.h =================================================================== RCS file: /cvsroot/ogs/dist/c++/ogs/core/Feat.h,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** Feat.h 25 Mar 2003 08:12:27 -0000 1.6 --- Feat.h 29 Mar 2003 02:10:29 -0000 1.7 *************** *** 122,132 **** virtual Group getGroup () const = 0; ! virtual ~Feat (); protected: ! virtual bool canAttach (ogs::support::Object& object) const; template <class FeatClass> ! bool findFeat (ogs::support::Object& object) const; }; --- 122,132 ---- virtual Group getGroup () const = 0; ! virtual ~Feat () { } protected: ! virtual bool canAttach (const Object& object) const; template <class FeatClass> ! bool findFeat (const Object& object) const; }; *************** *** 141,146 **** return (xpLevel < 2? xpLevel: xpLevel / 3 + 1); } - - inline Feat::~Feat () { } OGS_END_CORE_NAMESPACE --- 141,144 ---- Index: Feature.h =================================================================== RCS file: /cvsroot/ogs/dist/c++/ogs/core/Feature.h,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** Feature.h 25 Mar 2003 06:13:11 -0000 1.3 --- Feature.h 29 Mar 2003 02:10:29 -0000 1.4 *************** *** 39,56 **** class Feature: public ogs::support::Object { public: ! virtual bool attachObject (ogs::support::Object& object); virtual bool detachObject (); ! const ogs::support::Object* getObject () const; ! ogs::support::Object* getObject (); ! virtual ~Feature (); protected: ! virtual bool canAttach (ogs::support::Object& object) const; virtual bool canDetach () const; private: ! ogs::support::Object* _object; }; --- 39,58 ---- class Feature: public ogs::support::Object { public: ! virtual bool attachObject (Object& object); virtual bool detachObject (); ! const Object* getObject () const; ! Object* getObject (); ! virtual ~Feature () = 0; protected: ! Feature (); ! ! virtual bool canAttach (const Object& object) const; virtual bool canDetach () const; private: ! Object* _object; }; *************** *** 83,87 **** */ inline bool ! Feature::canAttach (Object& object) const { return (&object != this && _object == NULL); } --- 85,89 ---- */ inline bool ! Feature::canAttach (const Object& object) const { return (&object != this && _object == NULL); } *************** *** 97,100 **** --- 99,107 ---- return (true); } + + /** + * Create a new feature. + */ + inline Feature::Feature (): _object (NULL) { } inline Feature::~Feature () { } Index: Item.cpp =================================================================== RCS file: /cvsroot/ogs/dist/c++/ogs/core/Item.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Item.cpp 7 Jan 2003 07:41:33 -0000 1.1 --- Item.cpp 29 Mar 2003 02:10:29 -0000 1.2 *************** *** 21,26 **** */ ! #include "Item.h" using ogs::core::Item; --- 21,56 ---- */ ! #include "ogs/core/Entity.h" ! #include "ogs/core/Item.h" + using ogs::core::Entity; using ogs::core::Item; + + /** + * Create a new item. + */ + Item::Item (Entity::Weight weight, Size::Type size, Worth worth): + Entity (weight, size), _worth (worth) { + // empty constructor body + } + + /** + * Attach this item to an object. This function is called when an item + * is equipped. If the item cannot be equipped, this function should + * return false. Derived classes should override this function if the + * item can affect the object when it is equipped.since + * it does not allow an item to be equipped by default. + * + * @param object Object that will equip this item. + * @return True if item is equipped. + */ + bool Item::attachObject (Object& object) { + bool equipped = canEquip (object); + + if (equipped) { + this->_object = &object; + } + + return (equipped); + } Index: Item.h =================================================================== RCS file: /cvsroot/ogs/dist/c++/ogs/core/Item.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Item.h 25 Mar 2003 06:13:11 -0000 1.2 --- Item.h 29 Mar 2003 02:10:29 -0000 1.3 *************** *** 26,29 **** --- 26,32 ---- # define OGS_CORE_ITEM_H + # include <string> + + # include <ogs/support/Attachable.h> # include <ogs/core/Entity.h> # include <ogs/core/Namespace.h> *************** *** 32,40 **** /** ! * An entity that can be utilized or manipulated by a creature. */ ! class Item: public Entity { public: /** * Measures how hard the material is that the item is made of. * Higher values indicate harder items that are harder to break. --- 35,56 ---- /** ! * An entity that can be utilized or manipulated by a creature. Items ! * are attachable entities. They can be equipped, worn, held, or ! * contained within other items. */ ! class Item: public Entity, public ogs::support::Attachable { public: /** + * Measures how much the item is worth. Units of measure are + * locale-dependent. + */ + typedef double Worth; + + /** + * Material that this item is primarily made of. + */ + typedef std::string Material; + + /** * Measures how hard the material is that the item is made of. * Higher values indicate harder items that are harder to break. *************** *** 54,74 **** typedef Entity::Health Density; ! /** ! * Measures how much the item... [truncated message content] |