FYP  1.0.0
Final Year Project -- Alexander Meuer
Pawn Class Reference

Base class for all units in the game. If it walks and attacks, it's a Pawn. Walks toward a destination, attacks any hostile pawns it encounters. Dies when health reaches 0. More...

#include <Pawn.hpp>

Inheritance diagram for Pawn:
Inheritance graph
Collaboration diagram for Pawn:
Collaboration graph

Public Types

enum  Faction { PLAYER, ENEMY, NEUTRAL }
 
enum  State {
  IDLE, MARCHING, ATTACKING, STUNNED,
  DEAD
}
 

Public Member Functions

 Pawn (tinyxml2::XMLElement *xml)
 Constructs a pawn from an xml element. Parses members from child xml tags. Requires child <Actor> tag for base class construction. More...
 
void makeSelfAware (std::shared_ptr< Pawn > const &smartThis)
 
sf::Vector2f getDestination () const
 
virtual void setDestination (sf::Vector2f const &destination)
 Sets the Pawn's destination. More...
 
int getMovementSpeed () const
 
void setMovementSpeed (int newSpeed)
 
virtual void update (sf::Time const &elapsedTime)
 Updates the Pawn. State becomes MARCHING is goal is further than attack range. State becomes ATTACKING if has a target and target is within attack range. Else state become IDLE. More...
 
void kill ()
 Kills the Pawn outright. Sets the Pawn's health to 0 and the state to DEAD.
 
bool takeDamage (int amount, Damage::Type type)
 
bool takeDamage (int amount, Damage::Type type, std::shared_ptr< Pawn > const &sender)
 Same as takeDamage() Used when taking damage from another pawn, so that we can choose to retaliate if we so wish. More...
 
void heal (int amount)
 Heals for the specified amount. Heals for the specified amount. Cannot heal beyond max health. More...
 
void stun (sf::Time const &duration)
 Get stunned. Become stunned for the specified amount of time. Stuns do not stack. If a subsequant stun is applied, the stun with the longer duration is used. i.e. A stun of 1 second cannot cancel out a 5 second stun, nor does it becoe a 6 second stun. More...
 
void beTaunted (std::shared_ptr< Pawn > const &taunter)
 Become forced to attack th taunter. Changes combat target to be the taunter. Has no associated duration so subsequent taunts will override each other. More...
 
bool offerTarget (std::shared_ptr< Pawn > const &target)
 Offer a potential target to the Pawn. Offer a target to the Pawn, who then decides whether to accept it or not. More...
 
bool targetIsDead () const
 
void wait (float seconds)
 Disallows the pawn to march for the specified time. More...
 
int getHealth () const
 
State getState () const
 Gets the current state of the Pawn. More...
 
bool isDead () const
 
Faction getFaction () const
 
void setOnDeath (std::function< void(Pawn *)> const &callback)
 
std::weak_ptr< Pawn > const & getCombatTarget () const
 
Damage::Reduction const & getArmour () const
 
Damage::Reduction const & getMagicResist () const
 
sf::Color getBloodColor () const
 
virtual void onCollide (std::shared_ptr< Collidable > &other, sf::Vector2f const &mtv)
 Called whenever the Pawn collides with something. Virtual method that is invoked whenver this Pawn collides with something. Moves the Pawn a portion of the minimum translation vector. More...
 
- Public Member Functions inherited from Actor
 Actor (sf::Texture &texture, sf::Shape *collisionMask, sf::Vector2f const &maskOffset)
 
 Actor (tinyxml2::XMLElement *xml)
 
void animate (sf::Time const &elapsedTime)
 Updates the animator and applies it to ourself.
 
bool isPlayingAnimation () const
 Returns true if an animation is currently playing.
 
std::string getPlayingAnimation () const
 Gets the name of the playing animation. Undefined behaviour if no animation playing.
 
void playAnimation (std::string const &name, bool loop=false)
 Begins playing an animation by name.
 
void setVisible (bool isVisible=true)
 
bool toggleVisible ()
 
bool getVisible () const
 
virtual void draw (sf::RenderTarget &target) const
 
- Public Member Functions inherited from collision::Collidable
 Collidable (sf::Shape *mask, sf::Vector2f offset)
 
 Collidable (Collidable const &other)
 
 Collidable (tinyxml2::XMLElement *xml)
 Constructs a Collidable from an xml tag. Tag requires pointCoint and type attributes in addition to child tags depending on type specified. More...
 
const sf::Shape * getMask () const
 
void setMask (sf::Shape *mask, sf::Vector2f offset)
 
virtual void onCollide (std::shared_ptr< Collidable > &other, sf::Vector2f const &mtv)
 Called when we collide with something.
 
void setDebugColour (sf::Color const &c)
 
void debug_draw (sf::RenderTarget &target)
 
void getAxies (std::vector< sf::Vector2f > &axiesVector)
 Gets all axies of the mask. Gets all axies of the mask. Currently inefficient due to the fact that it iterates over all points and returns all axies (a duplicate of each axis is included!). More...
 
size_t getPointCount () const
 Gets the number of points in the mask. Calls mask->getPoint() and returns the result.
 
sf::Vector2f projectOntoAxis (sf::Vector2f &axis) const
 Projects the mask onto an axis. Projects each point of the mask onto an axis and returns the min and max points it covers on that axis. More...
 

Protected Member Functions

void turnToFaceDirection (sf::Vector2f const &dir)
 
virtual void calculateAnimation ()
 
virtual void calculateState (sf::Vector2f const &goalDisplacement)
 
virtual void doAttack (float secondsElapsed)
 
virtual void doMarch (sf::Vector2f const &goalDisplacement, float secondsElapsed)
 
void stopWaiting ()
 
- Protected Member Functions inherited from collision::Collidable
void updateCollidableMask (sf::Vector2f const &newPosition)
 Updates the position of the mask. Updates the position of the mask to equal newPosition plus the offset. More...
 

Protected Attributes

Faction mFaction
 
State mState
 
int mHealth
 
const int M_MAX_HEALTH
 
Damage::Reduction mArmour
 
Damage::Reduction mMagicResist
 
Damage::Type mDamageType
 
float mAttackRange
 
int mMovementSpeed
 
int mAttackDamage
 
float mAttacksPerSecond
 
float mTimeSinceAttack
 
std::weak_ptr< PawnmCombatTarget
 
sf::Time mStunDuration
 
sf::Time mTimeStunned
 
sf::Vector2f mDestination
 
sf::Sound mAttackSound
 
std::weak_ptr< Pawnself
 
- Protected Attributes inherited from Actor
bool mVisible
 

Private Attributes

sf::Color mBloodColor
 
float mSecondsToWait
 
const float mTurnCooldown
 The time to wait between flipping the sprite.
 
float mSecondsSinceTurn
 How long it has been since the sprite was flipped.
 
std::function< void(Pawn *)> mOnDeathFunction
 

Detailed Description

Base class for all units in the game. If it walks and attacks, it's a Pawn. Walks toward a destination, attacks any hostile pawns it encounters. Dies when health reaches 0.

Constructor & Destructor Documentation

Pawn::Pawn ( tinyxml2::XMLElement *  xml)

Constructs a pawn from an xml element. Parses members from child xml tags. Requires child <Actor> tag for base class construction.

Parameters
xmlA <Pawn> xml tag, containing an <Actor> tag and tags for all member variables.

Member Function Documentation

void Pawn::beTaunted ( std::shared_ptr< Pawn > const &  taunter)

Become forced to attack th taunter. Changes combat target to be the taunter. Has no associated duration so subsequent taunts will override each other.

Parameters
taunterThe new target for this Pawn.
sf::Vector2f Pawn::getDestination ( ) const

Gets the Pawn's destination.

Faction Pawn::getFaction ( ) const

Gets the Pawn's faction. (NEUTRAL, PLAYER, ENEMY)

Returns
Faction enum
State Pawn::getState ( ) const

Gets the current state of the Pawn.

Returns
State enum
void Pawn::heal ( int  amount)

Heals for the specified amount. Heals for the specified amount. Cannot heal beyond max health.

Parameters
amountThe number of health points to heal for.
bool Pawn::isDead ( ) const

Gets whether the Pawn is dead or not. Does not take into account health, only checks current state.

Returns
True if the Pawn is dead.
bool Pawn::offerTarget ( std::shared_ptr< Pawn > const &  target)

Offer a potential target to the Pawn. Offer a target to the Pawn, who then decides whether to accept it or not.

Remarks
Temporary until ChaiScript (target acquisition)
Parameters
targetA possible combat target.
Returns
True if the target was accepted.
virtual void Pawn::onCollide ( std::shared_ptr< Collidable > &  other,
sf::Vector2f const &  mtv 
)
virtual

Called whenever the Pawn collides with something. Virtual method that is invoked whenver this Pawn collides with something. Moves the Pawn a portion of the minimum translation vector.

Parameters
otherThe object we collided with.
mtvThe Minimum Translation Vector for the collision.
virtual void Pawn::setDestination ( sf::Vector2f const &  destination)
virtual

Sets the Pawn's destination.

Remarks
Pawns move straight toward their destination.
Parameters
destinationThe Pawn's new destination.

Reimplemented in Hero.

void Pawn::stun ( sf::Time const &  duration)

Get stunned. Become stunned for the specified amount of time. Stuns do not stack. If a subsequant stun is applied, the stun with the longer duration is used. i.e. A stun of 1 second cannot cancel out a 5 second stun, nor does it becoe a 6 second stun.

Parameters
durationThe length of the stun.
bool Pawn::takeDamage ( int  amount,
Damage::Type  type 
)

Applies damage to the Pawn, taking into account Armour/MagicResist.

Parameters
amountThe amount of damage to take.
typeThe type of damage to take.
bool Pawn::takeDamage ( int  amount,
Damage::Type  type,
std::shared_ptr< Pawn > const &  sender 
)

Same as takeDamage() Used when taking damage from another pawn, so that we can choose to retaliate if we so wish.

Parameters
amountThe amount of damage to take.
typeThe type of damage to take.
senderThe dealer of damage, the disher of pain.
bool Pawn::targetIsDead ( ) const

Checks if the Pawn's combat target is dead.

Returns
True if target is dead.
virtual void Pawn::update ( sf::Time const &  elapsedTime)
virtual

Updates the Pawn. State becomes MARCHING is goal is further than attack range. State becomes ATTACKING if has a target and target is within attack range. Else state become IDLE.

Moves toward goal if MARCHING. Attacks target if ATTACKING, taking into account attacks per second. Does nothing if state is somethig else.

Calls updateCollidableMask with current position at end of method.

Parameters
elapsedTimeThe amount of time elapsed since last update tick.

Reimplemented in Minion, and Hero.

void Pawn::wait ( float  seconds)

Disallows the pawn to march for the specified time.

Parameters
secondThe number of second to wait.

Member Data Documentation

float Pawn::mAttacksPerSecond
protected
Remarks
1.0f == 1 attack per second
Faction Pawn::mFaction
protected

The faction that the Pawn belongs to

float Pawn::mTimeSinceAttack
protected
Remarks
1.0f == 1 second

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