FIFE
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
trigger.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005-2013 by the FIFE team *
3  * http://www.fifengine.net *
4  * This file is part of FIFE. *
5  * *
6  * FIFE is free software; you can redistribute it and/or *
7  * modify it under the terms of the GNU Lesser General Public *
8  * License as published by the Free Software Foundation; either *
9  * version 2.1 of the License, or (at your option) any later version. *
10  * *
11  * This library is distributed in the hope that it will be useful, *
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
14  * Lesser General Public License for more details. *
15  * *
16  * You should have received a copy of the GNU Lesser General Public *
17  * License along with this library; if not, write to the *
18  * Free Software Foundation, Inc., *
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
20  ***************************************************************************/
21 
22 #ifndef FIFE_TRIGGER_H
23 #define FIFE_TRIGGER_H
24 
25 // Standard C++ library includes
26 #include <vector>
27 #include <string>
28 
29 // 3rd party library includes
30 
31 // FIFE includes
32 // These includes are split up in two parts, separated by one empty line
33 // First block: files included from the FIFE root src directory
34 // Second block: files included from the same folder
35 #include "util/base/fifeclass.h"
36 
37 namespace FIFE {
38  class Cell;
39  class Layer;
40  class Instance;
41  class TriggerChangeListener;
42 
44  public:
45  virtual ~ITriggerListener() {};
46 
47  virtual void onTriggered() = 0;
48  };
49 
51  // cell conditions
55  // instance conditions
69  };
70 
71  // FORWARD REFERENCES
72 
83  class Trigger : public FifeClass {
84  public:
85 
86  // LIFECYCLE
87 
95  Trigger();
96 
103  Trigger(const std::string& name);
104 
107  virtual ~Trigger();
108 
120  void addTriggerListener(ITriggerListener* listener);
121 
127  void removeTriggerListener(ITriggerListener* listener);
128 
134  void reset();
135 
140  const std::string& getName() const { return m_name; };
141 
148  bool isTriggered() { return m_triggered; };
149 
152  void setTriggered();
153 
159 
162  const std::vector<TriggerCondition>& getTriggerConditions();
163 
169 
174  void enableForInstance(Instance* instance);
175 
178  const std::vector<Instance*>& getEnabledInstances();
179 
184  void disableForInstance(Instance* instance);
185 
188  void enableForAllInstances();
189 
193 
196  void disableForAllInstances();
197 
203  void assign(Layer* layer, const ModelCoordinate& pt);
204 
210  void remove(Layer* layer, const ModelCoordinate& pt);
211 
216  void assign(Cell* cell);
217 
222  void remove(Cell* cell);
223 
226  const std::vector<Cell*>& getAssignedCells();
227 
232  void attach(Instance* instance);
233 
236  void detach();
237 
242 
245  void move();
246 
252  void moveTo(const ModelCoordinate& newPos, const ModelCoordinate& oldPos);
253 
254  private:
256  std::string m_name;
257 
260 
263 
265  std::vector<ITriggerListener*> m_triggerListeners;
266 
269 
271  std::vector<Cell*> m_assigned;
272 
274  std::vector<TriggerCondition> m_triggerConditions;
275 
277  std::vector<Instance*> m_enabledInstances;
278 
281  };
282 } //FIFE
283 
284 #endif
void detach()
Detaches trigger from instance.
Definition: trigger.cpp:299
TriggerChangeListener * m_changeListener
main change listener (cell and instance listener)
Definition: trigger.h:268
virtual ~ITriggerListener()
Definition: trigger.h:45
void move()
Callback for TriggerChangeListener.
Definition: trigger.cpp:307
void attach(Instance *instance)
Attaches the trigger to the given instance.
Definition: trigger.cpp:286
std::string m_name
name of the trigger. This should be unique per Map.
Definition: trigger.h:256
const std::string & getName() const
Gets the name of the trigger.
Definition: trigger.h:140
virtual ~Trigger()
Destructor.
Definition: trigger.cpp:147
void enableForInstance(Instance *instance)
Enables trigger for given instance.
Definition: trigger.cpp:212
Base class for all fife classes Used e.g.
Definition: fifeclass.h:42
void addTriggerCondition(TriggerCondition type)
Adds trigger condition.
Definition: trigger.cpp:194
void removeTriggerCondition(TriggerCondition type)
Removes trigger condition.
Definition: trigger.cpp:205
TriggerCondition
Definition: trigger.h:50
const std::vector< Cell * > & getAssignedCells()
Returns vector with the cells where the trigger is assigned to.
Definition: trigger.cpp:282
std::vector< ITriggerListener * > m_triggerListeners
Vector of the listeners that get called.
Definition: trigger.h:265
A basic layer on a map.
Definition: layer.h:99
bool m_enabledAll
true if the trigger is enabled for all instances
Definition: trigger.h:262
void assign(Layer *layer, const ModelCoordinate &pt)
Assigns trigger on given layer and position.
Definition: trigger.cpp:242
const std::vector< TriggerCondition > & getTriggerConditions()
Returns trigger conditions in an vector.
Definition: trigger.cpp:201
A basic cell on a CellCache.
Definition: cell.h:136
std::vector< Instance * > m_enabledInstances
all enabled instances
Definition: trigger.h:277
Instance * m_attached
instance where the trigger is attached to
Definition: trigger.h:280
Instance * getAttached()
Returns pointer to instance where the trigger is attached to.
Definition: trigger.h:241
void moveTo(const ModelCoordinate &newPos, const ModelCoordinate &oldPos)
Moves the trigger from the old position to the new position.
Definition: trigger.cpp:316
const std::vector< Instance * > & getEnabledInstances()
Returns instance which the trigger is enabled for.
Definition: trigger.cpp:219
void disableForAllInstances()
Disables trigger for all instances.
Definition: trigger.cpp:238
void reset()
Reset trigger.
Definition: trigger.cpp:175
A 3D Point.
Definition: point.h:202
std::vector< TriggerCondition > m_triggerConditions
all trigger conditions
Definition: trigger.h:274
Trigger()
Default constructor.
Definition: trigger.cpp:131
void removeTriggerListener(ITriggerListener *listener)
Removes a listener from the trigger.
Definition: trigger.cpp:163
Trigger get triggered when a specific set of criteria are met.
Definition: trigger.h:83
void disableForInstance(Instance *instance)
Disables trigger for given instance.
Definition: trigger.cpp:223
void enableForAllInstances()
Enables trigger for all instances.
Definition: trigger.cpp:230
bool m_triggered
true if this trigger has been triggered
Definition: trigger.h:259
virtual void onTriggered()=0
bool isTriggered()
Returns if the trigger has been triggered.
Definition: trigger.h:148
void addTriggerListener(ITriggerListener *listener)
Add a listener to the trigger.
Definition: trigger.cpp:156
An Instance is an "instantiation" of an Object at a Location.
Definition: instance.h:100
bool isEnabledForAllInstances()
Returns if trigger is enabled for all instances.
Definition: trigger.cpp:234
void setTriggered()
Sets the trigger to triggered and calls ITriggerListener->onTriggered()
Definition: trigger.cpp:179
std::vector< Cell * > m_assigned
cells in which the trigger is assigned
Definition: trigger.h:271