ArnieBoids  1.0.0
JOINT AI PROJECT
Mothership Class Reference

#include <Mothership.hpp>

Inheritance diagram for Mothership:
Collaboration diagram for Mothership:

Public Member Functions

 Mothership (thor::ParticleSystem &particleSystem, std::function< void(Bullet *)> const &fireCallback, std::function< void(Ship *)> spawnCallback, sf::Vector2f position)
 
 ~Mothership ()
 
void update () override
 Hides sf::Shape::update() More...
 
void onCollide (Ship *other) override
 Takes damage if the ship is a Player ship. More...
 
- Public Member Functions inherited from Ship
 Ship (thor::ParticleSystem &particleSystem, sf::Vector2f const &position, float maxSpeed, unsigned int health=1u)
 
 ~Ship ()
 
void takeDamage (unsigned int amount=1u)
 Reduces health by the specified amount. More...
 
bool isDead () const
 Returns true if health is zero. More...
 
void thrust ()
 Apply acceleration in direction of forward vector. More...
 
void brake ()
 Apply deceleration if thrust is present. More...
 
void turnLeft ()
 Turn ship left. More...
 
void turnRight ()
 Turn ship right. More...
 
bool trigger ()
 Attempt to fire, returns success. More...
 
void turnToward (sf::Vector2f const &direction)
 
sf::Vector2f getForward () const
 Returns forward direction of ship. More...
 
sf::Vector2f getVelocity () const
 Returns velocity. More...
 
void setRadarRange (float range)
 Radar radius accessors. More...
 
float getRadarRange () const
 
int getHealth () const
 Health accessors. More...
 
void addHealth (unsigned int health)
 
unsigned int getMaxHealth () const
 

Static Public Member Functions

static void setTarget (Ship *target)
 Sets the target for all motherships. More...
 

Protected Member Functions

void updateParticleEmitter () override
 
- Protected Member Functions inherited from Ship
void clampToMaxSpeed ()
 Clamps the length of the velocity_ vector to MAX_SPEED_. More...
 
float tickToSec (unsigned int ticks) const
 Ticks to seconds. More...
 

Private Types

enum  State { WANDER, EVADE }
 

Private Member Functions

State calculateState () const
 
sf::Vector2f evade () const
 
sf::Vector2f wander ()
 
void fire ()
 Tries to fire a missile toward target. Does nothing if max missiles already live. More...
 
void missileDestructed ()
 Decrements liveMissiles_. Called by Missile::destructCallback_. More...
 
sf::Vector2f separation () const
 Keeps ships from piling on top of each other. More...
 
sf::Vector2f cohesion () const
 Keeps the ship moving in the same direction as nearby flockmates. Finds the averagelocation of nearby flockmates and manipulates the steering force to move in that direction. More...
 
sf::Vector2f alignment () const
 
sf::Vector2f flock () const
 Runs separation(), cohesion() and alignment(). Weights the results. More...
 

Private Attributes

thor::ParticleSystem & particleSystem_
 
unsigned int ticksSinceLastSpawn_
 Number of calls to update since a Predator was spawned. More...
 
const unsigned int ticksPerSpawn_
 Amount of ticks that must go by before we will spawn a Predator. More...
 
std::function< void(Bullet *)> fireBullet_
 Method used to fire a bullet into the game world. More...
 
std::function< void(Ship *)> spawnShip_
 Method used to spawn a ship into the game world. More...
 
sf::Vector2f wanderWaypoint_
 Holds the vector generated by wander() More...
 
const unsigned int MAX_LIVE_MISSILES
 The maximum number of missiles the ship can have live at a time. More...
 
unsigned int liveMissiles_
 The number of currently live missiles. More...
 
std::list< Mothership * > flock_
 A list of all other motherships. More...
 

Static Private Attributes

static Shiptarget_ = nullptr
 Target for all motherships. More...
 

Additional Inherited Members

- Public Attributes inherited from Ship
sf::RectangleShape debug_rect_
 
- Protected Attributes inherited from Ship
const float MAX_SPEED_
 Maximum length of velocity vector. More...
 
const unsigned int MAX_HEALTH_
 
float refireTime_
 
float coolDown_
 
unsigned int ticks_
 
sf::Vector2f velocity_
 Delta position per update. More...
 
sf::Vector2f accel_
 Delta velocity after update !velocity_ += accel_ in update! More...
 
int health_
 Current health. More...
 
sf::Vector2f forward_
 Unit vector for ship's heading. More...
 
float thrust_
 How fast the ship accelerates. More...
 
float turnSpeed_
 How fast (in degrees) the ship can turn. More...
 
float radarRange_
 Ship's radar radius. More...
 
thor::UniversalEmitter particleEmitter_
 Does nothing on it's own. Derived classes should play with this. More...
 
float particleAngleVariance_
 

Member Enumeration Documentation

enum Mothership::State
private
Enumerator
WANDER 
EVADE 

Constructor & Destructor Documentation

Mothership::Mothership ( thor::ParticleSystem &  particleSystem,
std::function< void(Bullet *)> const &  fireCallback,
std::function< void(Ship *)>  spawnCallback,
sf::Vector2f  position 
)
Mothership::~Mothership ( )

Member Function Documentation

sf::Vector2f Mothership::alignment ( ) const
private
Returns
The desired heading after alignment.

Here is the call graph for this function:

Here is the caller graph for this function:

Mothership::State Mothership::calculateState ( ) const
private

Here is the caller graph for this function:

sf::Vector2f Mothership::cohesion ( ) const
private

Keeps the ship moving in the same direction as nearby flockmates. Finds the averagelocation of nearby flockmates and manipulates the steering force to move in that direction.

Returns
The desired position after cohesion.

Here is the caller graph for this function:

sf::Vector2f Mothership::evade ( ) const
private

Here is the caller graph for this function:

void Mothership::fire ( )
private

Tries to fire a missile toward target. Does nothing if max missiles already live.

Here is the call graph for this function:

Here is the caller graph for this function:

sf::Vector2f Mothership::flock ( ) const
private

Runs separation(), cohesion() and alignment(). Weights the results.

Returns
A vector of the weighted results summed together.

Here is the call graph for this function:

Here is the caller graph for this function:

void Mothership::missileDestructed ( )
private

Decrements liveMissiles_. Called by Missile::destructCallback_.

Here is the caller graph for this function:

void Mothership::onCollide ( Ship other)
overridevirtual

Takes damage if the ship is a Player ship.

Implements Ship.

Here is the call graph for this function:

sf::Vector2f Mothership::separation ( ) const
private

Keeps ships from piling on top of each other.

Returns
The desired position after separation.

Here is the caller graph for this function:

void Mothership::setTarget ( Ship target)
static

Sets the target for all motherships.

Here is the caller graph for this function:

void Mothership::update ( )
overridevirtual

Hides sf::Shape::update()

Reimplemented from Ship.

Here is the call graph for this function:

void Mothership::updateParticleEmitter ( )
overrideprotectedvirtual

Reimplemented from Ship.

sf::Vector2f Mothership::wander ( )
private

Here is the caller graph for this function:

Member Data Documentation

std::function<void(Bullet*)> Mothership::fireBullet_
private

Method used to fire a bullet into the game world.

std::list<Mothership*> Mothership::flock_
private

A list of all other motherships.

unsigned int Mothership::liveMissiles_
private

The number of currently live missiles.

const unsigned int Mothership::MAX_LIVE_MISSILES
private

The maximum number of missiles the ship can have live at a time.

thor::ParticleSystem& Mothership::particleSystem_
private
std::function<void(Ship*)> Mothership::spawnShip_
private

Method used to spawn a ship into the game world.

Ship * Mothership::target_ = nullptr
staticprivate

Target for all motherships.

const unsigned int Mothership::ticksPerSpawn_
private

Amount of ticks that must go by before we will spawn a Predator.

unsigned int Mothership::ticksSinceLastSpawn_
private

Number of calls to update since a Predator was spawned.

sf::Vector2f Mothership::wanderWaypoint_
private

Holds the vector generated by wander()


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