FIFE  be64c707dea6b3250bd4355bf5c825d25920087d
triggercontroller.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_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  class Trigger;
42  class Map;
43  class Layer;
44  class Location;
45  class Instance;
46  class Cell;
47 
53  class TriggerController : public FifeClass {
54  public:
55 
60  TriggerController(Map* map);
61 
64  virtual ~TriggerController();
65 
70  Trigger* createTrigger(const std::string& triggerName);
71 
78  Trigger* createTriggerOnCoordinate(const std::string& triggerName, Layer* layer, const ModelCoordinate& pt);
79 
86  Trigger* createTriggerOnCoordinates(const std::string& triggerName, Layer* layer, const std::vector<ModelCoordinate>& coords);
87 
94  Trigger* createTriggerOnRect(const std::string& triggerName, Layer* layer, const Rect& rec);
95 
101  Trigger* createTriggerOnLocation(const std::string& triggerName, const Location& loc);
102 
108  Trigger* createTriggerOnLocations(const std::string& triggerName, const std::vector<Location>& locs);
109 
115  Trigger* createTriggerOnCell(const std::string& triggerName, Cell* cell);
116 
122  Trigger* createTriggerOnCells(const std::string& triggerName, const std::vector<Cell*>& cells);
123 
129  Trigger* createTriggerOnInstance(const std::string& triggerName, Instance* instance);
130 
136  Trigger* getTrigger(const std::string& triggerName);
137 
142  void deleteTrigger(const std::string& triggerName);
143 
150  void removeTriggerFromCoordinate(const std::string& triggerName, Layer* layer, const ModelCoordinate& pt);
151 
158  void removeTriggerFromCoordinates(const std::string& triggerName, Layer* layer, const std::vector<ModelCoordinate>& coords);
159 
166  void removeTriggerFromRect(const std::string& triggerName, Layer* layer, const Rect& rec);
167 
173  void removeTriggerFromLocation(const std::string& triggerName, const Location& loc);
174 
180  void removeTriggerFromLocations(const std::string& triggerName, const std::vector<Location>& locs);
181 
187  void removeTriggerFromCell(const std::string& triggerName, Cell* cell);
188 
194  void removeTriggerFromCells(const std::string& triggerName, const std::vector<Cell*>& cells);
195 
201  void removeTriggerFromInstance(const std::string& triggerName, Instance* instance);
202 
205  std::vector<Trigger*> getAllTriggers();
206 
209  std::vector<std::string> getAllTriggerNames();
210 
211  private:
218  bool exists(const std::string& name);
219 
222 
223  typedef std::map< std::string, Trigger* > TriggerNameMap;
224  typedef std::map< std::string, Trigger* >::iterator TriggerNameMapIterator;
225  typedef std::map< std::string, Trigger* >::const_iterator TriggerNameMapConstIterator;
226  typedef std::pair< std::string, Trigger* > TriggerNameMapPair;
227 
229  TriggerNameMap m_triggerNameMap;
230  };
231 } //FIFE
232 
233 #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.
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:123
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.
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
Trigger * createTriggerOnCells(const std::string &triggerName, const std::vector< Cell *> &cells)
Creates and adds a trigger to the specified cells.
TriggerNameMap m_triggerNameMap
Trigger name map.
void removeTriggerFromCells(const std::string &triggerName, const std::vector< Cell *> &cells)
Removes a trigger from the specified cells.
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:94
TriggerController(Map *map)
Constructor.