FIFE  be64c707dea6b3250bd4355bf5c825d25920087d
FIFE::Trigger Class Reference

Trigger get triggered when a specific set of criteria are met. More...

#include <trigger.h>

+ Inheritance diagram for FIFE::Trigger:
+ Collaboration diagram for FIFE::Trigger:

Public Member Functions

 Trigger ()
 Default constructor. More...
 
 Trigger (const std::string &name)
 Constructor with name. More...
 
virtual ~Trigger ()
 Destructor. More...
 
void addTriggerListener (ITriggerListener *listener)
 Add a listener to the trigger. More...
 
void removeTriggerListener (ITriggerListener *listener)
 Removes a listener from the trigger. More...
 
void reset ()
 Reset trigger. More...
 
const std::string & getName () const
 Gets the name of the trigger. More...
 
bool isTriggered ()
 Returns if the trigger has been triggered. More...
 
void setTriggered ()
 Sets the trigger to triggered and calls ITriggerListener->onTriggered() More...
 
void addTriggerCondition (TriggerCondition type)
 Adds trigger condition. More...
 
const std::vector< TriggerCondition > & getTriggerConditions ()
 Returns trigger conditions in an vector. More...
 
void removeTriggerCondition (TriggerCondition type)
 Removes trigger condition. More...
 
void enableForInstance (Instance *instance)
 Enables trigger for given instance. More...
 
const std::vector< Instance * > & getEnabledInstances ()
 Returns instance which the trigger is enabled for. More...
 
void disableForInstance (Instance *instance)
 Disables trigger for given instance. More...
 
void enableForAllInstances ()
 Enables trigger for all instances. More...
 
bool isEnabledForAllInstances ()
 Returns if trigger is enabled for all instances. More...
 
void disableForAllInstances ()
 Disables trigger for all instances. More...
 
void assign (Layer *layer, const ModelCoordinate &pt)
 Assigns trigger on given layer and position. More...
 
void remove (Layer *layer, const ModelCoordinate &pt)
 Removes trigger from given layer and position. More...
 
void assign (Cell *cell)
 Assigns trigger on given cell. More...
 
void remove (Cell *cell)
 Removes trigger from given cell. More...
 
const std::vector< Cell * > & getAssignedCells ()
 Returns vector with the cells where the trigger is assigned to. More...
 
void attach (Instance *instance)
 Attaches the trigger to the given instance. More...
 
void detach ()
 Detaches trigger from instance. More...
 
InstancegetAttached ()
 Returns pointer to instance where the trigger is attached to. More...
 
void move ()
 Callback for TriggerChangeListener. More...
 
void moveTo (const ModelCoordinate &newPos, const ModelCoordinate &oldPos)
 Moves the trigger from the old position to the new position. More...
 
- Public Member Functions inherited from FIFE::FifeClass
 FifeClass ()
 
virtual ~FifeClass ()
 
fifeid_t getFifeId ()
 Gets unique id of this instance inside the engine. More...
 

Private Attributes

std::string m_name
 name of the trigger. This should be unique per Map. More...
 
bool m_triggered
 true if this trigger has been triggered More...
 
bool m_enabledAll
 true if the trigger is enabled for all instances More...
 
std::vector< ITriggerListener * > m_triggerListeners
 Vector of the listeners that get called. More...
 
TriggerChangeListenerm_changeListener
 main change listener (cell and instance listener) More...
 
std::vector< Cell * > m_assigned
 cells in which the trigger is assigned More...
 
std::vector< TriggerConditionm_triggerConditions
 all trigger conditions More...
 
std::vector< Instance * > m_enabledInstances
 all enabled instances More...
 
Instancem_attached
 instance where the trigger is attached to More...
 

Detailed Description

Trigger get triggered when a specific set of criteria are met.

Currently these can be added directly to Layers. In order to extend their use we might consider abstracting them from the Layer and adding a trigger manager of some sort which will then add the appropriate listeners to the layer and any other object that might need to trip a trigger.

See also
Layer

Definition at line 83 of file trigger.h.

Constructor & Destructor Documentation

◆ Trigger() [1/2]

FIFE::Trigger::Trigger ( )

Default constructor.

TODO (fixme) I'm not sure if I actually want to be able to call the default constructor. Triggers should always be given a name. The maps trigger controller should guarantee the uniqueness of the name.

Definition at line 131 of file trigger.cpp.

References m_changeListener.

◆ Trigger() [2/2]

FIFE::Trigger::Trigger ( const std::string &  name)

Constructor with name.

Triggers should be created with a name as that is how they will be referred to in the map file.

Definition at line 139 of file trigger.cpp.

References m_changeListener.

◆ ~Trigger()

FIFE::Trigger::~Trigger ( )
virtual

Destructor.

Definition at line 147 of file trigger.cpp.

References detach(), m_assigned, and m_changeListener.

Member Function Documentation

◆ addTriggerCondition()

void FIFE::Trigger::addTriggerCondition ( TriggerCondition  type)

Adds trigger condition.

Parameters
typeThe trigger condition.

Definition at line 194 of file trigger.cpp.

References m_triggerConditions.

Referenced by FIFE::MapLoader::load().

+ Here is the caller graph for this function:

◆ addTriggerListener()

void FIFE::Trigger::addTriggerListener ( ITriggerListener listener)

Add a listener to the trigger.

When a trigger gets triggered it will call the onTriggered() function of the listener.

The Trigger does NOT take ownership of the listener so clients must be sure to free their memory after the trigger has been deleted.

See also
ITriggerListener

Definition at line 156 of file trigger.cpp.

References m_triggerListeners.

◆ assign() [1/2]

void FIFE::Trigger::assign ( Layer layer,
const ModelCoordinate pt 
)

Assigns trigger on given layer and position.

Parameters
layerA pointer to the layer in which to add the Trigger to.
ptThe ModelCoordinate where the Trigger should be added.

Definition at line 242 of file trigger.cpp.

References FIFE::Cell::addChangeListener(), FIFE::CellCache::getCell(), FIFE::Layer::getCellCache(), m_assigned, and m_changeListener.

Referenced by FIFE::TriggerController::createTriggerOnCell(), FIFE::TriggerController::createTriggerOnCells(), FIFE::TriggerController::createTriggerOnCoordinate(), FIFE::TriggerController::createTriggerOnCoordinates(), FIFE::TriggerController::createTriggerOnLocations(), and FIFE::MapLoader::load().

+ Here is the caller graph for this function:

◆ assign() [2/2]

void FIFE::Trigger::assign ( Cell cell)

Assigns trigger on given cell.

Parameters
cellA pointer to the cell in which to add the Trigger to.

Definition at line 266 of file trigger.cpp.

References FIFE::Cell::addChangeListener(), m_assigned, and m_changeListener.

◆ attach()

void FIFE::Trigger::attach ( Instance instance)

Attaches the trigger to the given instance.

So the trigger moves with the instance.

Parameters
instanceA pointer to the instance which the Trigger is attached to.

Definition at line 286 of file trigger.cpp.

References FIFE::Instance::addChangeListener(), FIFE::Instance::addDeleteListener(), detach(), m_attached, and m_changeListener.

Referenced by FIFE::TriggerController::createTriggerOnInstance(), and FIFE::MapLoader::load().

+ Here is the caller graph for this function:

◆ detach()

void FIFE::Trigger::detach ( )

Detaches trigger from instance.

Definition at line 299 of file trigger.cpp.

References m_attached, m_changeListener, FIFE::Instance::removeChangeListener(), and FIFE::Instance::removeDeleteListener().

Referenced by attach(), FIFE::TriggerChangeListener::onInstanceDeleted(), and ~Trigger().

+ Here is the caller graph for this function:

◆ disableForAllInstances()

void FIFE::Trigger::disableForAllInstances ( )

Disables trigger for all instances.

Definition at line 238 of file trigger.cpp.

References m_enabledAll.

◆ disableForInstance()

void FIFE::Trigger::disableForInstance ( Instance instance)

Disables trigger for given instance.

Parameters
instanceThe instance which is disabled for the trigger.

Definition at line 223 of file trigger.cpp.

References m_enabledInstances.

◆ enableForAllInstances()

void FIFE::Trigger::enableForAllInstances ( )

Enables trigger for all instances.

Definition at line 230 of file trigger.cpp.

References m_enabledAll.

Referenced by FIFE::MapLoader::load().

+ Here is the caller graph for this function:

◆ enableForInstance()

void FIFE::Trigger::enableForInstance ( Instance instance)

Enables trigger for given instance.

Parameters
instanceThe instance which is enabled for the trigger.

Definition at line 212 of file trigger.cpp.

References m_enabledInstances.

Referenced by FIFE::MapLoader::load().

+ Here is the caller graph for this function:

◆ getAssignedCells()

const std::vector< Cell * > & FIFE::Trigger::getAssignedCells ( )

Returns vector with the cells where the trigger is assigned to.

Definition at line 282 of file trigger.cpp.

References m_assigned.

◆ getAttached()

Instance* FIFE::Trigger::getAttached ( )
inline

Returns pointer to instance where the trigger is attached to.

Note: Returns Null if no instance is attached.

Definition at line 241 of file trigger.h.

Referenced by FIFE::TriggerChangeListener::onInstanceChanged().

+ Here is the caller graph for this function:

◆ getEnabledInstances()

const std::vector< Instance * > & FIFE::Trigger::getEnabledInstances ( )

Returns instance which the trigger is enabled for.

Definition at line 219 of file trigger.cpp.

References m_enabledInstances.

Referenced by FIFE::TriggerChangeListener::onInstanceEnteredCell(), and FIFE::TriggerChangeListener::onInstanceExitedCell().

+ Here is the caller graph for this function:

◆ getName()

const std::string& FIFE::Trigger::getName ( ) const
inline

Gets the name of the trigger.

Returns
name of the trigger.

Definition at line 140 of file trigger.h.

◆ getTriggerConditions()

const std::vector< TriggerCondition > & FIFE::Trigger::getTriggerConditions ( )

◆ isEnabledForAllInstances()

bool FIFE::Trigger::isEnabledForAllInstances ( )

Returns if trigger is enabled for all instances.

Definition at line 234 of file trigger.cpp.

References m_enabledAll.

Referenced by FIFE::TriggerChangeListener::onInstanceEnteredCell(), and FIFE::TriggerChangeListener::onInstanceExitedCell().

+ Here is the caller graph for this function:

◆ isTriggered()

bool FIFE::Trigger::isTriggered ( )
inline

Returns if the trigger has been triggered.

Triggers will only trigger once unless they are reset.

Returns
bool true if the trigger has been triggered, false otherwise.

Definition at line 148 of file trigger.h.

◆ move()

void FIFE::Trigger::move ( )

◆ moveTo()

void FIFE::Trigger::moveTo ( const ModelCoordinate newPos,
const ModelCoordinate oldPos 
)

Moves the trigger from the old position to the new position.

Parameters
newPosThe old position as ModelCoordinate.
oldPosThe old position as ModelCoordinate.

Definition at line 316 of file trigger.cpp.

References FIFE::CellCache::getCell(), FIFE::Layer::getCellCache(), FIFE::Location::getLayer(), FIFE::Instance::getLocationRef(), m_assigned, m_attached, m_changeListener, FIFE::PointType3D< T >::x, and FIFE::PointType3D< T >::y.

Referenced by move().

+ Here is the caller graph for this function:

◆ remove() [1/2]

void FIFE::Trigger::remove ( Layer layer,
const ModelCoordinate pt 
)

Removes trigger from given layer and position.

Parameters
layerA pointer to the layer in which to remove the Trigger from.
ptThe ModelCoordinate where the Trigger should be removed.

Definition at line 254 of file trigger.cpp.

References FIFE::CellCache::getCell(), FIFE::Layer::getCellCache(), m_assigned, m_changeListener, and FIFE::Cell::removeChangeListener().

◆ remove() [2/2]

void FIFE::Trigger::remove ( Cell cell)

Removes trigger from given cell.

Parameters
cellA pointer to the cell in which to remove the Trigger from.

Definition at line 274 of file trigger.cpp.

References m_assigned, m_changeListener, and FIFE::Cell::removeChangeListener().

◆ removeTriggerCondition()

void FIFE::Trigger::removeTriggerCondition ( TriggerCondition  type)

Removes trigger condition.

Parameters
typeThe trigger condition.

Definition at line 205 of file trigger.cpp.

References m_triggerConditions.

◆ removeTriggerListener()

void FIFE::Trigger::removeTriggerListener ( ITriggerListener listener)

Removes a listener from the trigger.

This listener will no longer get called. The Trigger does NOT free the listener so you must be sure to do this.

Definition at line 163 of file trigger.cpp.

References m_triggerListeners.

◆ reset()

void FIFE::Trigger::reset ( )

Reset trigger.

Resets the status of the trigger so it can be triggered again.

Definition at line 175 of file trigger.cpp.

References m_triggered.

◆ setTriggered()

void FIFE::Trigger::setTriggered ( )

Member Data Documentation

◆ m_assigned

std::vector<Cell*> FIFE::Trigger::m_assigned
private

cells in which the trigger is assigned

Definition at line 271 of file trigger.h.

Referenced by assign(), getAssignedCells(), move(), moveTo(), remove(), and ~Trigger().

◆ m_attached

Instance* FIFE::Trigger::m_attached
private

instance where the trigger is attached to

Definition at line 280 of file trigger.h.

Referenced by attach(), detach(), move(), and moveTo().

◆ m_changeListener

TriggerChangeListener* FIFE::Trigger::m_changeListener
private

main change listener (cell and instance listener)

Definition at line 268 of file trigger.h.

Referenced by assign(), attach(), detach(), moveTo(), remove(), Trigger(), and ~Trigger().

◆ m_enabledAll

bool FIFE::Trigger::m_enabledAll
private

true if the trigger is enabled for all instances

Definition at line 262 of file trigger.h.

Referenced by disableForAllInstances(), enableForAllInstances(), and isEnabledForAllInstances().

◆ m_enabledInstances

std::vector<Instance*> FIFE::Trigger::m_enabledInstances
private

all enabled instances

Definition at line 277 of file trigger.h.

Referenced by disableForInstance(), enableForInstance(), and getEnabledInstances().

◆ m_name

std::string FIFE::Trigger::m_name
private

name of the trigger. This should be unique per Map.

Definition at line 256 of file trigger.h.

◆ m_triggerConditions

std::vector<TriggerCondition> FIFE::Trigger::m_triggerConditions
private

all trigger conditions

Definition at line 274 of file trigger.h.

Referenced by addTriggerCondition(), getTriggerConditions(), and removeTriggerCondition().

◆ m_triggered

bool FIFE::Trigger::m_triggered
private

true if this trigger has been triggered

Definition at line 259 of file trigger.h.

Referenced by reset(), and setTriggered().

◆ m_triggerListeners

std::vector<ITriggerListener*> FIFE::Trigger::m_triggerListeners
private

Vector of the listeners that get called.

Definition at line 265 of file trigger.h.

Referenced by addTriggerListener(), removeTriggerListener(), and setTriggered().


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