[dnd3e-changes] CVS: dist/c++/dnd3e/spells/conjuration CureWounds.cpp,NONE,1.1 CureWounds.h,NONE,1.1
Status: Alpha
Brought to you by:
elemings
|
From: Eric L. <ele...@us...> - 2003-03-12 16:32:32
|
Update of /cvsroot/dnd3e/dist/c++/dnd3e/spells/conjuration
In directory sc8-pr-cvs1:/tmp/cvs-serv17604/dnd3e/spells/conjuration
Added Files:
CureWounds.cpp CureWounds.h Makefile.am Namespace.h
Log Message:
Added class for cure wounds spells.
--- NEW FILE ---
/*
* CureWounds.cpp -- class implementation for cure wounds spells
* 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: CureWounds.cpp,v 1.1 2003/03/12 16:32:27 elemings Exp $
*/
//#include <ogs/support/TypeTraits.h>
#include <ogs/core/Creature.h>
#include "dnd3e/creatures/Undead.h"
#include "dnd3e/spells/conjuration/CureWounds.h"
using ogs::core::Die;
using ogs::core::Experience;
using ogs::spells::Conjuration;
using dnd3e::spells::conjuration::CureWounds;
/**
* This function is a stub for a future TypeTraits header addition.
*/
template <class BaseClass, class DerivedClass>
bool isBaseAndDerived (const DerivedClass& derivedObject) {
return (true);
}
/**
* Create a new cure wounds spell.
*
* @param casterLevel Level of caster.
* @param degree Degree of cure wounds spell.
*/
CureWounds::CureWounds (CasterLevel casterLevel, Degree degree):
_casterLevel (casterLevel), _degree (degree) {
// empty
}
/**
* Determine the components needed to cast this spell. The components
* of a cure wounds spell are normally verbal and somantic. Silence
* Spell and Still spell feats however may negate one or both of these
* components.
*
* @return Array of components for this spell.
*/
ogs::magic::Spell::Components CureWounds::getComponents () const {
using ogs::magic::Component;
using ogs::magic::Spell;
Spell::Components components;
bool silenced = false; // TODO: Determine this.
if (!silenced) {
Component component = Component::Verbal ();
components.push_back (component);
}
bool stilled = false; // TODO: Determine this.
if (!stilled) {
Component component = Component::Somantic ();
components.push_back (component);
}
return (components);
}
/**
* Cast this spell. When a cure wounds spell is cast, this function
* first checks to see if there is a target. If there is not target,
* nothing happens. (In other words, this function does nothing).
* Otherwise, the target is checked to see if it is a creature. If the
* target is not a creature, nothing happens. If the target is a
* creature, this function rolls a random number of hit points according
* to the degree of spell. Next, the creature is checked to see if it
* is undead. If it is, a Will save is rolled for the undead creature.
* If the save fails, the points are subtracted from the current hit
* points of the undead creature. If the creature is not undead, the
* points are added to the current hit points of the creature (up to its
* maximum points).
*/
void CureWounds::castSpell () {
if (_target != NULL) {
using ogs::core::Entity;
using ogs::core::Creature;
if (isBaseAndDerived<Creature, Entity> (*_target)) {
Die::Value hitPoints = rollHitPoints ();
using dnd3e::creatures::Undead;
if (isBaseAndDerived<Undead, Entity> (*_target)) {
if (!checkTargetWillSave () &&
!checkTargetSpellResistance ()) {
int currentHealth = _target->getCurrentHealth ();
_target->setCurrentHealth (currentHealth - hitPoints);
}
} else {
int currentHealth = _target->getCurrentHealth ();
_target->setCurrentHealth (currentHealth + hitPoints);
}
}
}
}
/**
* Roll hit points for this cure wounds spell. If the spell has been
* empowered or maximized, the hit points are adjusted accordingly.
*
* @return Hit points rolled.
*/
Die::Value CureWounds::rollHitPoints () const {
Die::Value hitPoints = 0;
if (_degree == MINOR) {
hitPoints = 1;
} else {
// Note the value of the degree is important here.
Die die (Die::d8);
die.setCount (_degree);
bool maximized = false; // TODO: Determine this.
hitPoints = maximized? die.getMaximumValue (): die.rollValue ();
unsigned maxBonus = 5 * _degree;
hitPoints += _casterLevel > maxBonus? maxBonus: _casterLevel;
bool empowered = false; // TODO: Determine this.
if (empowered) {
hitPoints += (hitPoints / 2);
}
}
return (hitPoints);
}
/**
* Roll a Will save for the target of this spell.
*
* @return True if Will save of target succeeded.
*/
bool CureWounds::checkTargetWillSave () const {
return (false); // TODO: Implement this function. Easy.
}
/**
* Check the spell resistance (if any) for the target of this spell.
*
* @return True if spell resistance negates spell.
*/
bool CureWounds::checkTargetSpellResistance () const {
// TODO: Implement this function, generalize, and move to ogs::magic.
return (false);
}
--- NEW FILE ---
/*
* CureWounds.h -- class interface for cure wounds spells
* 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: CureWounds.h,v 1.1 2003/03/12 16:32:27 elemings Exp $
*/
#ifdef __cplusplus
# ifndef DND3E_SPELLS_CONJURATION_CURE_WOUNDS_H
# define DND3E_SPELLS_CONJURATION_CURE_WOUNDS_H
# include <ogs/core/CClass.h>
# include <ogs/core/Die.h>
# include <ogs/core/Entity.h>
# include <ogs/core/Experience.h>
# include <ogs/magic/Subschool.h>
# include <ogs/spells/Conjuration.h>
# include <dnd3e/spells/conjuration/Namespace.h>
DND3E_BEGIN_SPELLS_CONJURATION_NAMESPACE
using ogs::core::CClass;
/**
* A spell that heals damage to living creatures. Cure wounds spells
* have the opposite effect on undead creatures: the spell causes damage
* to undead creatures instead of curing it. Cure wounds spells can
* have different degrees. The degree of the spell determines how much
* damage is healed (or dealt in the case of undead creatures).
*/
class CureWounds: public ogs::spells::Conjuration {
public:
/** Level of caster. */
typedef ogs::core::Experience::Level CasterLevel;
/** Target of cure wounds spell. */
typedef ogs::core::Entity* Target;
/** Determines how much damage is healed (or dealt). */
enum Degree {
/** Cures 1 point of damage. */
MINOR,
/**
* Cures 1d8 points of damage plus 1 per caster level (up to 5).
*/
LIGHT,
/**
* Cures 2d8 points of damage plus 1 per caster level (up to 10).
*/
MODERATE,
/**
* Cures 3d8 points of damage plus 1 per caster level (up to 15).
*/
SERIOUS,
/**
* Cures 4d8 points of damage plus 1 per caster level (up to 20).
*/
CRITICAL,
};
static CureWounds* createMinor (CasterLevel casterLevel);
static CureWounds* createLight (CasterLevel casterLevel);
static CureWounds* createModerate (CasterLevel casterLevel);
static CureWounds* createSerious (CasterLevel casterLevel);
static CureWounds* createCritical (CasterLevel casterLevel);
const ogs::magic::School& getSchool () const;
ogs::magic::Spell::Components getComponents () const;
ogs::magic::Range getRange () const;
Degree getDegree () const;
Target getTarget () const;
void setTarget (ogs::core::Entity& entity);
void castSpell ();
protected:
CureWounds (CasterLevel casterLevel, Degree degree);
private:
CasterLevel _casterLevel;
Target _target;
Degree _degree;
ogs::core::Die::Value rollHitPoints () const;
bool checkTargetWillSave () const;
bool checkTargetSpellResistance () const;
};
/**
* Determine the school (or subschool) for this type of spell. All cure
* wounds spells are in the Healing subschool of the Conjuration school.
*
* @return Healing subshool of the Conjuration school.
*/
inline const ogs::magic::School&
CureWounds::getSchool () const {
using ogs::magic::Subschool;
static Subschool subschool (Subschool::HEALING);
return (subschool);
}
/**
* Determine the range of this spell. Cure wounds spells always have
* touch range.
*
* @return Touch range.
*/
inline ogs::magic::Range
CureWounds::getRange () const {
return (ogs::magic::Range::Touch ());
}
/**
* Determine the target of this spell. The target of this spell is the
* entity that will be healed (or damaged). If the entity is not a
* creature, the spell does nothing. If the spell does not yet have a
* target, the function returns NULL.
*
* @return Target of spell or NULL if spell is not targeted.
*/
inline CureWounds::Target
CureWounds::getTarget () const {
return (this->_target);
}
/**
* Determine the degree of this cure wounds spell.
*
* #return Degree of cure wounds spell.
*/
inline CureWounds::Degree
CureWounds::getDegree () const {
return (this->_degree);
}
DND3E_END_SPELLS_CONJURATION_NAMESPACE
# endif /* !defined DND3E_SPELLS_CONJURATION_CURE_WOUNDS_H */
#endif /* defined __cplusplus */
--- NEW FILE ---
##
## Makefile.am -- Automake file for DND3E
## 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 program; if not, write to the Free Software
## Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
## USA
##
## RCS: $Id: Makefile.am,v 1.1 2003/03/12 16:32:27 elemings Exp $
##
pkgincludedir = $(includedir)/dnd3e/spells/conjuration
pkginclude_HEADERS = \
CureWounds.h
INCLUDES = \
-I$(top_srcdir) \
-I$(top_builddir) \
-I$(top_srcdir)/intl
noinst_LTLIBRARIES = libdnd3e-conjurations.la
localedir = $(datadir)/locale
libdnd3e_conjurations_la_DEFS = -DLOCALEDIR=\"$(localedir)\" @DEFS@
libdnd3e_conjurations_la_SOURCES = \
CureWounds.cpp
--- NEW FILE ---
/*
* Namespace.h -- namespace for conjuration spells
* 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: Namespace.h,v 1.1 2003/03/12 16:32:27 elemings Exp $
*/
#ifdef __cplusplus
# ifndef DND3E_SPELLS_CONJURATION_NAMESPACE_H
# define DND3E_SPELLS_CONJURATION_NAMESPACE_H
# include <dnd3e/spells/Namespace.h>
/**
* @namespace dnd3e::spells::conjuration
*
*
*/
# define DND3E_BEGIN_SPELLS_CONJURATION_NAMESPACE \
DND3E_BEGIN_SPELLS_NAMESPACE \
namespace conjuration {
# define DND3E_END_SPELLS_CONJURATION_NAMESPACE \
} \
DND3E_END_SPELLS_NAMESPACE
# endif /* !defined DND3E_SPELLS_CONJURATION_NAMESPACE_H */
#endif /* defined __cplusplus */
|