FIFE  6e1afdbeda11afe9ac53e6023a4be96ef88f1dc6
triggercontroller.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005-2017 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_CONTROLLER_H
23 #define FIFE_TRIGGER_CONTROLLER_H
24 
25 // Standard C++ library includes
26 #include <vector>
27 #include <string>
28 #include <map>
29 
30 // 3rd party library includes
31 
32 // FIFE includes
33 // These includes are split up in two parts, separated by one empty line
34 // First block: files included from the FIFE root src directory
35 // Second block: files included from the same folder
36 #include "util/base/fifeclass.h"
37 #include "util/structures/rect.h"
39 
40 namespace FIFE {
41 
42  // FORWARD REFERENCES
43  class Trigger;
44  class Map;
45  class Layer;
46  class Location;
47  class Instance;
48  class Cell;
49 
55  class TriggerController : public FifeClass {
56  public:
57 
58  // LIFECYCLE
59 
64  TriggerController(Map* map);
65 
68  virtual ~TriggerController();
69 
74  Trigger* createTrigger(const std::string& triggerName);
75 
82  Trigger* createTriggerOnCoordinate(const std::string& triggerName, Layer* layer, const ModelCoordinate& pt);
83 
90  Trigger* createTriggerOnCoordinates(const std::string& triggerName, Layer* layer, const std::vector<ModelCoordinate>& coords);
91 
98  Trigger* createTriggerOnRect(const std::string& triggerName, Layer* layer, const Rect& rec);
99 
105  Trigger* createTriggerOnLocation(const std::string& triggerName, const Location& loc);
106 
112  Trigger* createTriggerOnLocations(const std::string& triggerName, const std::vector<Location>& locs);
113 
119  Trigger* createTriggerOnCell(const std::string& triggerName, Cell* cell);
120 
126  Trigger* createTriggerOnCells(const std::string& triggerName, const std::vector<Cell*>& cells);
127 
133  Trigger* createTriggerOnInstance(const std::string& triggerName, Instance* instance);
134 
140  Trigger* getTrigger(const std::string& triggerName);
141 
146  void deleteTrigger(const std::string& triggerName);
147 
154  void removeTriggerFromCoordinate(const std::string& triggerName, Layer* layer, const ModelCoordinate& pt);
155 
162  void removeTriggerFromCoordinates(const std::string& triggerName, Layer* layer, const std::vector<ModelCoordinate>& coords);
163 
170  void removeTriggerFromRect(const std::string& triggerName, Layer* layer, const Rect& rec);
171 
177  void removeTriggerFromLocation(const std::string& triggerName, const Location& loc);
178 
184  void removeTriggerFromLocations(const std::string& triggerName, const std::vector<Location>& locs);
185 
191  void removeTriggerFromCell(const std::string& triggerName, Cell* cell);
192 
198  void removeTriggerFromCells(const std::string& triggerName, const std::vector<Cell*>& cells);
199 
205  void removeTriggerFromInstance(const std::string& triggerName, Instance* instance);
206 
209  std::vector<Trigger*> getAllTriggers();
210 
213  std::vector<std::string> getAllTriggerNames();
214 
215  private:
222  bool exists(const std::string& name);
223 
226 
227  typedef std::map< std::string, Trigger* > TriggerNameMap;
228  typedef std::map< std::string, Trigger* >::iterator TriggerNameMapIterator;
229  typedef std::map< std::string, Trigger* >::const_iterator TriggerNameMapConstIterator;
230  typedef std::pair< std::string, Trigger* > TriggerNameMapPair;
231 
233  TriggerNameMap m_triggerNameMap;
234  };
235 } //FIFE
236 
237 #endif
std::map< std::string, Trigger * >::const_iterator TriggerNameMapConstIterator
std::map< std::string, Trigger * > TriggerNameMap
Trigger * createTriggerOnRect(const std::string &triggerName, Layer *layer, const Rect &rec)
Creates and adds a trigger to the cells on the specified layer and rect.
void removeTriggerFromCoordinate(const std::string &triggerName, Layer *layer, const ModelCoordinate &pt)
Removes a trigger from the cell on the specified layer and coordinate.
Trigger * createTriggerOnInstance(const std::string &triggerName, Instance *instance)
Creates and attach a trigger to the specified instance.
Trigger * createTriggerOnCoordinate(const std::string &triggerName, Layer *layer, const ModelCoordinate &pt)
Creates and adds a trigger to the cell on the specified layer and coordinate.
Trigger * createTriggerOnCoordinates(const std::string &triggerName, Layer *layer, const std::vector< ModelCoordinate > &coords)
Creates and adds a trigger to the cells on the specified layer and coordinates.
Base class for all fife classes Used e.g.
Definition: fifeclass.h:42
virtual ~TriggerController()
Destructor.
void removeTriggerFromCell(const std::string &triggerName, Cell *cell)
Removes a trigger from the specified cell.
Trigger * createTriggerOnLocation(const std::string &triggerName, const Location &loc)
Creates and adds a trigger to the cell on the specified location.
std::vector< Trigger * > getAllTriggers()
Returns a vector with all trigger pointers.
Map * m_map
Pointer to the map this controller is associated with.
std::pair< std::string, Trigger * > TriggerNameMapPair
std::vector< std::string > getAllTriggerNames()
Returns a vector with all trigger names.
void removeTriggerFromCells(const std::string &triggerName, const std::vector< Cell * > &cells)
Removes a trigger from the specified cells.
A basic layer on a map.
Definition: layer.h:99
Trigger * getTrigger(const std::string &triggerName)
Returns a pointer to the trigger with the given name.
std::map< std::string, Trigger * >::iterator TriggerNameMapIterator
A basic cell on a CellCache.
Definition: cell.h:136
Trigger * createTriggerOnCell(const std::string &triggerName, Cell *cell)
Creates and adds a trigger to the specified cell.
void removeTriggerFromInstance(const std::string &triggerName, Instance *instance)
Detach a trigger from the specified instance.
void deleteTrigger(const std::string &triggerName)
Deletes a trigger with the given name.
void removeTriggerFromRect(const std::string &triggerName, Layer *layer, const Rect &rec)
Removes a trigger from the cell on the specified layer and coordinates.
A 3D Point.
Definition: point.h:205
void removeTriggerFromLocations(const std::string &triggerName, const std::vector< Location > &locs)
Removes a trigger from the cell on the specified locations.
Trigger * createTrigger(const std::string &triggerName)
Creates a trigger.
Trigger get triggered when a specific set of criteria are met.
Definition: trigger.h:83
Trigger * createTriggerOnLocations(const std::string &triggerName, const std::vector< Location > &locs)
Creates and adds a trigger to the cell on the specified locations.
Trigger * createTriggerOnCells(const std::string &triggerName, const std::vector< Cell * > &cells)
Creates and adds a trigger to the specified cells.
bool exists(const std::string &name)
Checks to see if the trigger name already exists.
This class serves as a central place to manage triggers for a Map.
A container of Layer(s).
Definition: map.h:88
TriggerNameMap m_triggerNameMap
Trigger name map.
void removeTriggerFromCoordinates(const std::string &triggerName, Layer *layer, const std::vector< ModelCoordinate > &coords)
Removes a trigger from the cell on the specified layer and coordinates.
void removeTriggerFromLocation(const std::string &triggerName, const Location &loc)
Removes a trigger from the cell on the specified location.
An Instance is an "instantiation" of an Object at a Location.
Definition: instance.h:101
TriggerController(Map *map)
Constructor.