| 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" |
| 38 |
#include "model/metamodel/modelcoords.h" |
| 39 |
|
| 40 |
namespace FIFE { |
| 41 |
class Trigger; |
| 42 |
class Map; |
| 43 |
class Layer; |
| 44 |
class Location; |
| 45 |
class Instance; |
| 46 |
class Cell; |
| 47 |
|
| 48 |
/** This class serves as a central place to manage triggers for a Map. |
| 49 |
* |
| 50 |
* You should never instantiate this class directly as Map does it |
| 51 |
* when you create a new map. |
| 52 |
*/ |
| 53 |
class TriggerController : public FifeClass { |
| 54 |
public: |
| 55 |
|
| 56 |
/** Constructor. |
| 57 |
* |
| 58 |
* @param map A pointer to the map that the controller will interact with. |
| 59 |
*/ |
| 60 |
TriggerController(Map* map); |
| 61 |
|
| 62 |
/** Destructor. |
| 63 |
*/ |
| 64 |
virtual ~TriggerController(); |
| 65 |
|
| 66 |
/** Creates a trigger. |
| 67 |
* |
| 68 |
* @param triggerName The name of the trigger. This must be unique per map. |
| 69 |
*/ |
| 70 |
Trigger* createTrigger(const std::string& triggerName); |
| 71 |
|
| 72 |
/** Creates and adds a trigger to the cell on the specified layer and coordinate. |
| 73 |
* |
| 74 |
* @param triggerName The name of the trigger. This must be unique per map. |
| 75 |
* @param layer A pointer to the layer in which to add the Trigger to |
| 76 |
* @param pt The ModelCoordinate where the Trigger should be added. |
| 77 |
*/ |
| 78 |
Trigger* createTriggerOnCoordinate(const std::string& triggerName, Layer* layer, const ModelCoordinate& pt); |
| 79 |
|
| 80 |
/** Creates and adds a trigger to the cells on the specified layer and coordinates. |
| 81 |
* |
| 82 |
* @param triggerName The name of the trigger. This must be unique per map. |
| 83 |
* @param layer A pointer to the layer in which to add the Trigger to |
| 84 |
* @param coords Vector with ModelCoordinates where the Trigger should be added. |
| 85 |
*/ |
| 86 |
Trigger* createTriggerOnCoordinates(const std::string& triggerName, Layer* layer, const std::vector<ModelCoordinate>& coords); |
| 87 |
|
| 88 |
/** Creates and adds a trigger to the cells on the specified layer and rect. |
| 89 |
* |
| 90 |
* @param triggerName The name of the trigger. This must be unique per map. |
| 91 |
* @param layer A pointer to the layer in which to add the Trigger to |
| 92 |
* @param rec a Rect with ModelCoordinates where the Trigger should be added. |
| 93 |
*/ |
| 94 |
Trigger* createTriggerOnRect(const std::string& triggerName, Layer* layer, const Rect& rec); |
| 95 |
|
| 96 |
/** Creates and adds a trigger to the cell on the specified location. |
| 97 |
* |
| 98 |
* @param triggerName The name of the trigger. This must be unique per map. |
| 99 |
* @param loc The Location where the Trigger should be added. |
| 100 |
*/ |
| 101 |
Trigger* createTriggerOnLocation(const std::string& triggerName, const Location& loc); |
| 102 |
|
| 103 |
/** Creates and adds a trigger to the cell on the specified locations. |
| 104 |
* |
| 105 |
* @param triggerName The name of the trigger. This must be unique per map. |
| 106 |
* @param locs Vector with Locations where the Trigger should be added. |
| 107 |
*/ |
| 108 |
Trigger* createTriggerOnLocations(const std::string& triggerName, const std::vector<Location>& locs); |
| 109 |
|
| 110 |
/** Creates and adds a trigger to the specified cell. |
| 111 |
* |
| 112 |
* @param triggerName The name of the trigger. This must be unique per map. |
| 113 |
* @param cell The Cell where the Trigger should be added. |
| 114 |
*/ |
| 115 |
Trigger* createTriggerOnCell(const std::string& triggerName, Cell* cell); |
| 116 |
|
| 117 |
/** Creates and adds a trigger to the specified cells. |
| 118 |
* |
| 119 |
* @param triggerName The name of the trigger. This must be unique per map. |
| 120 |
* @param cells Vector with Cell pointers where the Trigger should be added. |
| 121 |
*/ |
| 122 |
Trigger* createTriggerOnCells(const std::string& triggerName, const std::vector<Cell*>& cells); |
| 123 |
|
| 124 |
/** Creates and attach a trigger to the specified instance. But not to the underlaying cell. |
| 125 |
* |
| 126 |
* @param triggerName The name of the trigger. This must be unique per map. |
| 127 |
* @param instance The Instance where the Trigger is attached to. |
| 128 |
*/ |
| 129 |
Trigger* createTriggerOnInstance(const std::string& triggerName, Instance* instance); |
| 130 |
|
| 131 |
/** Returns a pointer to the trigger with the given name. |
| 132 |
* Note: Returns Null if the trigger does not exists. |
| 133 |
* |
| 134 |
* @param triggerName The name of the trigger. This must be unique per map. |
| 135 |
*/ |
| 136 |
Trigger* getTrigger(const std::string& triggerName); |
| 137 |
|
| 138 |
/** Deletes a trigger with the given name. |
| 139 |
* |
| 140 |
* @param triggerName The name of the trigger. This must be unique per map. |
| 141 |
*/ |
| 142 |
void deleteTrigger(const std::string& triggerName); |
| 143 |
|
| 144 |
/** Removes a trigger from the cell on the specified layer and coordinate. |
| 145 |
* |
| 146 |
* @param triggerName The name of the trigger. This must be unique per map. |
| 147 |
* @param layer A pointer to the layer in which to remove the Trigger from. |
| 148 |
* @param pt The ModelCoordinate where the Trigger should be removed. |
| 149 |
*/ |
| 150 |
void removeTriggerFromCoordinate(const std::string& triggerName, Layer* layer, const ModelCoordinate& pt); |
| 151 |
|
| 152 |
/** Removes a trigger from the cell on the specified layer and coordinates. |
| 153 |
* |
| 154 |
* @param triggerName The name of the trigger. This must be unique per map. |
| 155 |
* @param layer A pointer to the layer in which to remove the Trigger from. |
| 156 |
* @param coords Vector with ModelCoordinates where the Trigger should be removed. |
| 157 |
*/ |
| 158 |
void removeTriggerFromCoordinates(const std::string& triggerName, Layer* layer, const std::vector<ModelCoordinate>& coords); |
| 159 |
|
| 160 |
/** Removes a trigger from the cell on the specified layer and coordinates. |
| 161 |
* |
| 162 |
* @param triggerName The name of the trigger. This must be unique per map. |
| 163 |
* @param layer A pointer to the layer in which to remove the Trigger from. |
| 164 |
* @param rec Rect with ModelCoordinates where the Trigger should be removed. |
| 165 |
*/ |
| 166 |
void removeTriggerFromRect(const std::string& triggerName, Layer* layer, const Rect& rec); |
| 167 |
|
| 168 |
/** Removes a trigger from the cell on the specified location. |
| 169 |
* |
| 170 |
* @param triggerName The name of the trigger. This must be unique per map. |
| 171 |
* @param loc Location where the Trigger should be removed. |
| 172 |
*/ |
| 173 |
void removeTriggerFromLocation(const std::string& triggerName, const Location& loc); |
| 174 |
|
| 175 |
/** Removes a trigger from the cell on the specified locations. |
| 176 |
* |
| 177 |
* @param triggerName The name of the trigger. This must be unique per map. |
| 178 |
* @param locs Vector with Locations where the Trigger should be removed. |
| 179 |
*/ |
| 180 |
void removeTriggerFromLocations(const std::string& triggerName, const std::vector<Location>& locs); |
| 181 |
|
| 182 |
/** Removes a trigger from the specified cell. |
| 183 |
* |
| 184 |
* @param triggerName The name of the trigger. This must be unique per map. |
| 185 |
* @param cell The Cell pointer where the Trigger should be removed. |
| 186 |
*/ |
| 187 |
void removeTriggerFromCell(const std::string& triggerName, Cell* cell); |
| 188 |
|
| 189 |
/** Removes a trigger from the specified cells. |
| 190 |
* |
| 191 |
* @param triggerName The name of the trigger. This must be unique per map. |
| 192 |
* @param cells Vector with Cell pointers where the Trigger should be removed. |
| 193 |
*/ |
| 194 |
void removeTriggerFromCells(const std::string& triggerName, const std::vector<Cell*>& cells); |
| 195 |
|
| 196 |
/** Detach a trigger from the specified instance. |
| 197 |
* |
| 198 |
* @param triggerName The name of the trigger. This must be unique per map. |
| 199 |
* @param instance The instance pointer where the Trigger is detached from. |
| 200 |
*/ |
| 201 |
void removeTriggerFromInstance(const std::string& triggerName, Instance* instance); |
| 202 |
|
| 203 |
/** Returns a vector with all trigger pointers. |
| 204 |
*/ |
| 205 |
std::vector<Trigger*> getAllTriggers(); |
| 206 |
|
| 207 |
/** Returns a vector with all trigger names. |
| 208 |
*/ |
| 209 |
std::vector<std::string> getAllTriggerNames(); |
| 210 |
|
| 211 |
private: |
| 212 |
/** Checks to see if the trigger name already exists. |
| 213 |
* |
| 214 |
* @param name The name of the trigger to check |
| 215 |
* |
| 216 |
* @return true if the name already exists, false otherwise. |
| 217 |
*/ |
| 218 |
bool exists(const std::string& name); |
| 219 |
|
| 220 |
//! Pointer to the map this controller is associated with. |
| 221 |
Map* m_map; |
| 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 |
|
| 228 |
//! Trigger name map |
| 229 |
TriggerNameMap m_triggerNameMap; |
| 230 |
}; |
| 231 |
} //FIFE |
| 232 |
|
| 233 |
#endif |