FYP  1.0.0
Final Year Project -- Alexander Meuer
Ability Class Referenceabstract

Base class for usable abilities or spells. Abilities must be initialized through xml. More...

#include <Ability.hpp>

Inheritance diagram for Ability:
Inheritance graph
Collaboration diagram for Ability:
Collaboration graph

Public Member Functions

 Ability (tinyxml2::XMLElement *xml)
 Constructs an Ability from xml. Only description is read from xml in this base class, derived classes will require more. More...
 
virtual void execute (Pawn *user)
 Calls doExecuteLogic() if ability has fully cooled since last use. More...
 
void update (sf::Time const &elapsedTime)
 Checks if ability is active and does update logic if it is. More...
 
const std::string & getDescription () const
 Gets a user-friendly description of the ability, as it might appear in a tooltip, etc. More...
 
const std::string & getName () const
 Gets the user-friendly name of the ability. More...
 
bool canCast () const
 
float getRemainingCooldown () const
 Gets the remaining time, in seconds, before the ability can be used again.
 
float getTotalCooldown () const
 The time, in seconds, that the ability's cooldown lasts.
 
sf::Time const & getCastDuration () const
 
bool isActive () const
 Gets whether the ability has been activated or not. More...
 
void setPawnList (std::shared_ptr< const std::list< std::shared_ptr< Pawn >>> const &list)
 Sets the pawn list to be used when the Ability wishes to find pawns in the game. The pawn list cannot be used for directly adding Pawns to the game. More...
 
void setProjectileManager (std::shared_ptr< ProjectileManager > const &manager)
 Sets the ProjectileManager to be used when the Ability wishes to add projectiles to the game. More...
 
void setSpawnCallback (std::function< void(std::shared_ptr< Minion >)> const &callback)
 Sets the callback used for adding units to the game. Adding a unit to the pawn list won't add flocking or collision, so we've a callback that will. More...
 
bool checkHotkey (char key) const
 
char getHotkey () const
 
void setHotkey (char hotkey)
 

Protected Member Functions

void activate ()
 
void deactivate ()
 
virtual void doExecuteLogic (Pawn *user)=0
 
virtual void doUpdateLogic (sf::Time const &deltaTime)=0
 Does everything necessary to update the ability. Only called if the ability is active.
 
void draw (sf::RenderTarget &target, sf::RenderStates states) const override final
 Calls doDraw() if ability is active.
 
virtual void doDraw (sf::RenderTarget &target, sf::RenderStates states) const =0
 
void spawnMinion (std::shared_ptr< Minion > const &pawn) const
 Adds a Pawn to the game. More...
 
void spawnProjectile (std::shared_ptr< Projectile > const &projectile) const
 Adds a projectile to the game. More...
 

Private Attributes

bool mIsActive
 True if the ability has been activated and should be updated.
 
const std::string M_DESCRIPTION
 User-friendly description of ability.
 
const std::string M_NAME
 User-friendly name of ability.
 
const sf::Time M_CAST_TIME
 Time it takes to use the ability.
 
const float M_COOLDOWN
 How many seconds must pass before the ability can be used subsequently.
 
float mSecondsSinceCast
 The number of seconds since the ability was last deactivated.
 
sf::Sound mExecutionSound
 The sound played when the ability is executed.
 
char mHotkey
 Keyboard shortcut to activate this ability.
 
std::shared_ptr< const std::list< std::shared_ptr< Pawn > > > mPawnList
 
std::shared_ptr< ProjectileManagermProjectileManager
 
std::function< void(std::shared_ptr< Minion >)> mSpawnUnitCallback
 

Detailed Description

Base class for usable abilities or spells. Abilities must be initialized through xml.

Constructor & Destructor Documentation

Ability::Ability ( tinyxml2::XMLElement *  xml)
explicit

Constructs an Ability from xml. Only description is read from xml in this base class, derived classes will require more.

Parameters
xmlAn <Ability> xml tag, containing a tag.

Member Function Documentation

virtual void Ability::doExecuteLogic ( Pawn user)
protectedpure virtual
Parameters
userPointer to the pawn that used the ability.

Implemented in abilities::MagicMisile, abilities::Heal, and abilities::RaiseDead.

virtual void Ability::execute ( Pawn user)
virtual

Calls doExecuteLogic() if ability has fully cooled since last use.

Parameters
userRaw pointer to user of ability. Can be null.
Remarks
The raw Pawn pointer is not intended to be stored.
See also
doUpdateLogic()
M_COOLDOWN
const std::string& Ability::getDescription ( ) const

Gets a user-friendly description of the ability, as it might appear in a tooltip, etc.

Returns
The ability's decription.
const std::string& Ability::getName ( ) const

Gets the user-friendly name of the ability.

Returns
The ability's name.
bool Ability::isActive ( ) const

Gets whether the ability has been activated or not.

Returns
True if the ability has been actived (execute() has been called).
void Ability::setPawnList ( std::shared_ptr< const std::list< std::shared_ptr< Pawn >>> const &  list)

Sets the pawn list to be used when the Ability wishes to find pawns in the game. The pawn list cannot be used for directly adding Pawns to the game.

Parameters
listShared pointer to a list of shared pawns.
void Ability::setProjectileManager ( std::shared_ptr< ProjectileManager > const &  manager)

Sets the ProjectileManager to be used when the Ability wishes to add projectiles to the game.

Parameters
managerShared pointer to a ProjectileManager, the Ability can give projectiles to this.
void Ability::setSpawnCallback ( std::function< void(std::shared_ptr< Minion >)> const &  callback)

Sets the callback used for adding units to the game. Adding a unit to the pawn list won't add flocking or collision, so we've a callback that will.

Parameters
callbackThe function called when an ability want to spawn a unit.
void Ability::spawnMinion ( std::shared_ptr< Minion > const &  pawn) const
protected

Adds a Pawn to the game.

Parameters
pawnThe Pawn to push into the list.
See also
Level.hpp
void Ability::spawnProjectile ( std::shared_ptr< Projectile > const &  projectile) const
protected

Adds a projectile to the game.

Parameters
projectileThe projectile to give to the ProjectileManager.
void Ability::update ( sf::Time const &  elapsedTime)

Checks if ability is active and does update logic if it is.

Parameters
elapsedTimeThe amount of time since the last update.

The documentation for this class was generated from the following file: