FIFE  be64c707dea6b3250bd4355bf5c825d25920087d
trigger.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005-2019 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 
158  void addTriggerCondition(TriggerCondition type);
159 
162  const std::vector<TriggerCondition>& getTriggerConditions();
163 
168  void removeTriggerCondition(TriggerCondition type);
169 
174  void enableForInstance(Instance* instance);
175 
178  const std::vector<Instance*>& getEnabledInstances();
179 
184  void disableForInstance(Instance* instance);
185 
188  void enableForAllInstances();
189 
192  bool isEnabledForAllInstances();
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 
241  Instance* getAttached() { return m_attached; }
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
TriggerChangeListener * m_changeListener
main change listener (cell and instance listener)
Definition: trigger.h:268
virtual ~ITriggerListener()
Definition: trigger.h:45
std::string m_name
name of the trigger. This should be unique per Map.
Definition: trigger.h:256
Base class for all fife classes Used e.g.
Definition: fifeclass.h:42
TriggerCondition
Definition: trigger.h:50
const std::string & getName() const
Gets the name of the trigger.
Definition: trigger.h:140
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
A basic cell on a CellCache.
Definition: cell.h:123
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
A 3D Point.
Definition: point.h:205
std::vector< TriggerCondition > m_triggerConditions
all trigger conditions
Definition: trigger.h:274
Trigger get triggered when a specific set of criteria are met.
Definition: trigger.h:83
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
An Instance is an "instantiation" of an Object at a Location.
Definition: instance.h:94
std::vector< Cell * > m_assigned
cells in which the trigger is assigned
Definition: trigger.h:271