FIFE
be64c707dea6b3250bd4355bf5c825d25920087d
|
Trigger get triggered when a specific set of criteria are met. More...
#include <trigger.h>
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... | |
Instance * | getAttached () |
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... | |
TriggerChangeListener * | m_changeListener |
main change listener (cell and instance listener) More... | |
std::vector< Cell * > | m_assigned |
cells in which the trigger is assigned More... | |
std::vector< TriggerCondition > | m_triggerConditions |
all trigger conditions More... | |
std::vector< Instance * > | m_enabledInstances |
all enabled instances More... | |
Instance * | m_attached |
instance where the trigger is attached to More... | |
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.
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.
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.
|
virtual |
Destructor.
Definition at line 147 of file trigger.cpp.
References detach(), m_assigned, and m_changeListener.
void FIFE::Trigger::addTriggerCondition | ( | TriggerCondition | type | ) |
Adds trigger condition.
type | The trigger condition. |
Definition at line 194 of file trigger.cpp.
References m_triggerConditions.
Referenced by FIFE::MapLoader::load().
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.
Definition at line 156 of file trigger.cpp.
References m_triggerListeners.
void FIFE::Trigger::assign | ( | Layer * | layer, |
const ModelCoordinate & | pt | ||
) |
Assigns trigger on given layer and position.
layer | A pointer to the layer in which to add the Trigger to. |
pt | The 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().
void FIFE::Trigger::assign | ( | Cell * | cell | ) |
Assigns trigger on given cell.
cell | A 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.
void FIFE::Trigger::attach | ( | Instance * | instance | ) |
Attaches the trigger to the given instance.
So the trigger moves with the instance.
instance | A 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().
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().
void FIFE::Trigger::disableForAllInstances | ( | ) |
Disables trigger for all instances.
Definition at line 238 of file trigger.cpp.
References m_enabledAll.
void FIFE::Trigger::disableForInstance | ( | Instance * | instance | ) |
Disables trigger for given instance.
instance | The instance which is disabled for the trigger. |
Definition at line 223 of file trigger.cpp.
References m_enabledInstances.
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().
void FIFE::Trigger::enableForInstance | ( | Instance * | instance | ) |
Enables trigger for given instance.
instance | The instance which is enabled for the trigger. |
Definition at line 212 of file trigger.cpp.
References m_enabledInstances.
Referenced by FIFE::MapLoader::load().
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.
|
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().
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().
|
inline |
const std::vector< TriggerCondition > & FIFE::Trigger::getTriggerConditions | ( | ) |
Returns trigger conditions in an vector.
Definition at line 201 of file trigger.cpp.
References m_triggerConditions.
Referenced by FIFE::TriggerChangeListener::onBlockingChangedCell(), FIFE::TriggerChangeListener::onInstanceChanged(), FIFE::TriggerChangeListener::onInstanceDeleted(), FIFE::TriggerChangeListener::onInstanceEnteredCell(), and FIFE::TriggerChangeListener::onInstanceExitedCell().
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().
|
inline |
void FIFE::Trigger::move | ( | ) |
Callback for TriggerChangeListener.
Definition at line 307 of file trigger.cpp.
References FIFE::Location::getLayerCoordinates(), FIFE::Instance::getLocationRef(), FIFE::Instance::getOldLocationRef(), m_assigned, m_attached, and moveTo().
Referenced by FIFE::TriggerChangeListener::onInstanceChanged().
void FIFE::Trigger::moveTo | ( | const ModelCoordinate & | newPos, |
const ModelCoordinate & | oldPos | ||
) |
Moves the trigger from the old position to the new position.
newPos | The old position as ModelCoordinate. |
oldPos | The 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().
void FIFE::Trigger::remove | ( | Layer * | layer, |
const ModelCoordinate & | pt | ||
) |
Removes trigger from given layer and position.
layer | A pointer to the layer in which to remove the Trigger from. |
pt | The 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().
void FIFE::Trigger::remove | ( | Cell * | cell | ) |
Removes trigger from given cell.
cell | A 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().
void FIFE::Trigger::removeTriggerCondition | ( | TriggerCondition | type | ) |
Removes trigger condition.
type | The trigger condition. |
Definition at line 205 of file trigger.cpp.
References m_triggerConditions.
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.
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.
void FIFE::Trigger::setTriggered | ( | ) |
Sets the trigger to triggered and calls ITriggerListener->onTriggered()
Definition at line 179 of file trigger.cpp.
References m_triggered, and m_triggerListeners.
Referenced by FIFE::MapLoader::load(), FIFE::TriggerChangeListener::onBlockingChangedCell(), FIFE::TriggerChangeListener::onInstanceChanged(), FIFE::TriggerChangeListener::onInstanceDeleted(), FIFE::TriggerChangeListener::onInstanceEnteredCell(), and FIFE::TriggerChangeListener::onInstanceExitedCell().
|
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().
|
private |
|
private |
|
private |
true if the trigger is enabled for all instances
Definition at line 262 of file trigger.h.
Referenced by disableForAllInstances(), enableForAllInstances(), and isEnabledForAllInstances().
|
private |
all enabled instances
Definition at line 277 of file trigger.h.
Referenced by disableForInstance(), enableForInstance(), and getEnabledInstances().
|
private |
|
private |
all trigger conditions
Definition at line 274 of file trigger.h.
Referenced by addTriggerCondition(), getTriggerConditions(), and removeTriggerCondition().
|
private |
true if this trigger has been triggered
Definition at line 259 of file trigger.h.
Referenced by reset(), and setTriggered().
|
private |
Vector of the listeners that get called.
Definition at line 265 of file trigger.h.
Referenced by addTriggerListener(), removeTriggerListener(), and setTriggered().