[ogs-changes] dist/c++/ogs/magic Feats.h,1.1,1.2 Makefile.am,1.6,1.7 MetamagicFeat.cpp,1.4,1.5 Metam
Status: Alpha
Brought to you by:
elemings
|
From: <ele...@us...> - 2003-04-15 16:59:22
|
Update of /cvsroot/ogs/dist/c++/ogs/magic
In directory sc8-pr-cvs1:/tmp/cvs-serv20206/c++/ogs/magic
Modified Files:
Feats.h Makefile.am MetamagicFeat.cpp MetamagicFeat.h
SpellList.h
Log Message:
See C++ ChangeLog (Apr 15) for details.
Index: Feats.h
===================================================================
RCS file: /cvsroot/ogs/dist/c++/ogs/magic/Feats.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** Feats.h 19 Feb 2003 22:36:51 -0000 1.1
--- Feats.h 15 Apr 2003 16:58:46 -0000 1.2
***************
*** 31,35 ****
# include <ogs/magic/feats/HeightenSpell.h>
# include <ogs/magic/feats/MaximizeSpell.h>
- # include <ogs/magic/feats/Namespace.h>
# include <ogs/magic/feats/QuickenSpell.h>
# include <ogs/magic/feats/SilentSpell.h>
--- 31,34 ----
Index: Makefile.am
===================================================================
RCS file: /cvsroot/ogs/dist/c++/ogs/magic/Makefile.am,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** Makefile.am 4 Mar 2003 03:24:42 -0000 1.6
--- Makefile.am 15 Apr 2003 16:58:46 -0000 1.7
***************
*** 62,66 ****
School.cpp \
Spell.cpp \
- SpellList.cpp \
Subschool.cpp
libogs_magic_la_LIBADD = \
--- 62,65 ----
Index: MetamagicFeat.cpp
===================================================================
RCS file: /cvsroot/ogs/dist/c++/ogs/magic/MetamagicFeat.cpp,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** MetamagicFeat.cpp 25 Mar 2003 06:13:13 -0000 1.4
--- MetamagicFeat.cpp 15 Apr 2003 16:58:46 -0000 1.5
***************
*** 21,26 ****
*/
- #include <typeinfo>
-
#include "ogs/magic/MetamagicFeat.h"
#include "ogs/magic/Spell.h"
--- 21,24 ----
***************
*** 29,54 ****
/**
! * Attach this metamagic feat to a spell. Metamagic feats can only be
! * attached to spells. This, this function returns false if the object
! * is not an instance of a class derived from the <code>Spell</code>
! * class. Derived classes should always call this function first before
! * modifing the object.
*
! * @param object An instance of a class derived from <code>Spell</code>.
* @return True if this metamagic feat is attached to the spell
*/
! bool MetamagicFeat::attachObject (Object& object) {
! if (! Feature::attachObject (object)) {
! return (false);
}
! bool success = true;
! try {
! dynamic_cast<Spell&> (object);
! } catch (std::bad_cast) {
! success = false;
}
! return (success);
}
--- 27,62 ----
/**
! * Attach this metamagic feat to a spell. This method should always be
! * called first by derived objects that override this function.
*
! * @param spell A spell instance.
* @return True if this metamagic feat is attached to the spell
*/
! bool MetamagicFeat::attachSpell (Spell& spell) {
! bool attach = canAttachSpell (spell);
!
! if (attach) {
! this->_spell = &spell;
}
! return (attach);
! }
!
! /**
! * Detach this metamagic feat from a spell. This function resets the
! * spell pointer to null. Derived classes that override this function
! * should therefore call the getObject() function before calling this
! * function.
! *
! * @return True if this feat is detached from the spell.
! */
! bool MetamagicFeat::detachSpell () {
! bool detach = canDetachSpell ();
!
! if (detach) {
! this->_spell = NULL;
}
! return (detach);
}
Index: MetamagicFeat.h
===================================================================
RCS file: /cvsroot/ogs/dist/c++/ogs/magic/MetamagicFeat.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** MetamagicFeat.h 29 Mar 2003 02:10:39 -0000 1.5
--- MetamagicFeat.h 15 Apr 2003 16:58:46 -0000 1.6
***************
*** 31,67 ****
OGS_BEGIN_MAGIC_NAMESPACE
/**
! * A feat that enhances spells at the cost of higher level spell slots.
*/
class MetamagicFeat: public ogs::core::Feat {
public:
! virtual bool attachObject (Object& object);
! ogs::core::Feat::Compatibility getCompatibility () const;
! /**
! * Determine number of levels added to normal spell level.
! * Metamagic feats use up spell slots higher than a spell's normal
! * level. These added spell levels are used only when filling spell
! * slots. <em>Derived classes must override this function.</em>
! *
! * @return Number of added levels.
! */
! virtual int getAddedLevels () = 0;
! virtual ~MetamagicFeat () { }
};
/**
! * Determine the compatibility of this type of feat. Metamagic feats
! * are exclusive feats: only one instance of each metamagic feat can
! * be attached to a spell at one time.
*
! * @return Feat::EXCLUSIVE.
*/
! inline ogs::core::Feat::Compatibility
! MetamagicFeat::getCompatibility () const {
! return (ogs::core::Feat::EXCLUSIVE);
}
OGS_END_MAGIC_NAMESPACE
--- 31,114 ----
OGS_BEGIN_MAGIC_NAMESPACE
+ class Spell;
+
/**
! * A feat that enhances spells. The cost of using a metamagic feat
! * however is that it increases the spell level of the spell. This
! * requires that spell casters use a higher slot in their daily
! * allowance of spells.
! *
! * @todo
! * Could modify the Attachable operations to accept both creatures and
! * spells and perform the correct behavior appropriate to that class.
*/
class MetamagicFeat: public ogs::core::Feat {
public:
! /** The number of spell levels added by a metamagic feat. */
! typedef unsigned Cost;
! Cost getCost () const;
! virtual bool attachSpell (Spell& spell);
! virtual bool detachSpell ();
! Spell* getSpell () const;
! virtual ~MetamagicFeat () = 0;
!
! protected:
! MetamagicFeat (Cost cost);
!
! virtual bool canAttachSpell (Spell& spell) const;
! virtual bool canDetachSpell () const;
!
! private:
! Cost _cost;
! Spell* _spell;
};
/**
! * Create a new metamagic feat.
*
! * @param cost Cost of using a metamagic feat.
*/
! inline MetamagicFeat::MetamagicFeat (Cost cost):
! Feat (EXCLUSIVE, MAGIC),
! _cost (cost),
! _spell (NULL) {
! // empty constructor body
! }
!
! /**
! * Detemine the spell that this feat is attached to.
! *
! * @return Spell that this feat is attached to or NULL if not attached.
! */
! inline Spell*
! MetamagicFeat::getSpell () const {
! return (this->_spell);
}
+
+ /**
+ * Determine if this metamagic feat can be attached to a spell. A
+ * metamagic feat can only be attached to a spell if it is not already
+ * attached.
+ */
+ inline bool
+ MetamagicFeat::canAttachSpell (Spell& spell) const {
+ return (this->_spell == NULL);
+ }
+
+ /**
+ * Determine if this metamagic feat can be detached from a spell.
+ * Metamagic feats can not be detached from spells by default.
+ *
+ * @return True if the feature is detached from the object.
+ */
+ inline bool
+ MetamagicFeat::canDetachSpell () const {
+ return (false);
+ }
+
+ inline MetamagicFeat::~MetamagicFeat () { }
OGS_END_MAGIC_NAMESPACE
Index: SpellList.h
===================================================================
RCS file: /cvsroot/ogs/dist/c++/ogs/magic/SpellList.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** SpellList.h 28 Feb 2003 11:11:25 -0000 1.1
--- SpellList.h 15 Apr 2003 16:58:47 -0000 1.2
***************
*** 68,72 ****
* spell maps.
*/
! CasterMap _casterMap;
SpellList ();
--- 68,72 ----
* spell maps.
*/
! CasterMap casterMap;
SpellList ();
***************
*** 80,84 ****
* Create an empty spell list.
*/
! inline SpellList::SpellList (): _casterMap () { }
OGS_END_MAGIC_NAMESPACE
--- 80,149 ----
* Create an empty spell list.
*/
! inline SpellList::SpellList ():
! casterMap () {
! // empty constructor body
! }
!
! /**
! * Determine the spell level for a class of spell and caster. The class
! * of spell must be a class dervied from the <code>Spell</code> class.
! * The class of caster must be a class derived from <code>CClass</code>
! * or <code>Domain</code>.
! *
! * @return Spell level or null if not caster and spell not found.
! * @throws std::bad_cast If one of the classes is not derived from
! * the correct class.
! * @throws NotFound If the spell or caster are not found.
! */
! template <class CasterClass, class SpellClass>
! int SpellList::getLevel () const {
!
! // Throw bad_cast if casterClass is not derived from CClass or Domain.
! checkCasterClass<CasterClass> ();
!
! // Throw bad_cast if spellClass is not derived from Spell.
! SpellClass spell;
! dynamic_cast<Spell&> (spell);
!
! Class casterClass = Class::getClass<CasterClass> ();
! CasterMap::iterator casterItor = casterMap.find (casterClass);
! if (casterItor == casterMap.end ()) {
! //throw NotFound ();
! }
!
! SpellMap spellMap = *casterItor;
! SpellMap::iterator spellItor = spellMap.find (spellClass);
! if (spellItor == spellMap.end ()) {
! //throw NotFound ();
! }
!
! return (*spellItor);
! }
!
! template <class CasterClass>
! void SpellList::checkCasterClass () {
! // TODO: Implement.
! }
!
! /**
! * Determine the spell level for a spell and a class of caster. This
! * function takes into account any metamagic feats that are attached to
! * the spell. If the spell has any metamagic feats, the total slots
! * from the metamagic feats are added to the spell's normal level. The
! * class of caster may be a class derived from <code>CClass</code> or
! * <code>Domain</code>.
! *
! * @param spell A spell object.
! * @return Spell level or null if not caster and spell not found.
! * @throws std::bad_cast If one of the classes is not derived from
! * the correct class.
! * @throws NotRelated If the spell and caster are not related.
! */
! template <class CasterClass, class SpellClass>
! int SpellList::getLevel (const SpellClass& spell) const {
! int spellLevel = getLevel<CasterClass, SpellClass> ();
! //spelLevel += spell.getMetamagicSlots ();
! return (spellLevel);
! }
OGS_END_MAGIC_NAMESPACE
|