1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284
|
/***************************************************************************
* Copyright (C) 2005-2019 by the FIFE team *
* http://www.fifengine.net *
* This file is part of FIFE. *
* *
* FIFE is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public *
* License as published by the Free Software Foundation; either *
* version 2.1 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with this library; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
***************************************************************************/
#ifndef FIFE_TRIGGER_H
#define FIFE_TRIGGER_H
// Standard C++ library includes
#include <vector>
#include <string>
// 3rd party library includes
// FIFE includes
// These includes are split up in two parts, separated by one empty line
// First block: files included from the FIFE root src directory
// Second block: files included from the same folder
#include "util/base/fifeclass.h"
namespace FIFE {
class Cell;
class Layer;
class Instance;
class TriggerChangeListener;
class ITriggerListener {
public:
virtual ~ITriggerListener() {};
virtual void onTriggered() = 0;
};
enum TriggerCondition {
// cell conditions
CELL_TRIGGER_ENTER = 0,
CELL_TRIGGER_EXIT,
CELL_TRIGGER_BLOCKING_CHANGE,
// instance conditions
INSTANCE_TRIGGER_LOCATION,
INSTANCE_TRIGGER_ROTATION,
INSTANCE_TRIGGER_SPEED,
INSTANCE_TRIGGER_ACTION,
INSTANCE_TRIGGER_TIME_MULTIPLIER,
INSTANCE_TRIGGER_SAYTEXT,
INSTANCE_TRIGGER_BLOCK,
INSTANCE_TRIGGER_CELL,
INSTANCE_TRIGGER_TRANSPARENCY,
INSTANCE_TRIGGER_VISIBLE,
INSTANCE_TRIGGER_STACKPOS,
INSTANCE_TRIGGER_VISUAL,
INSTANCE_TRIGGER_DELETE
};
// FORWARD REFERENCES
/** Trigger get triggered when a specific set of criteria are met.
*
* Currently these can be added directly to Layers. In order to extend
* their use we might consider abstracting them from the Layer and adding
* a trigger manager of some sort which will then add the appropriate
* listeners to the layer and any other object that might need to
* trip a trigger.
*
* @see Layer
*/
class Trigger : public FifeClass {
public:
// LIFECYCLE
/** Default constructor.
*
* TODO (fixme)
* I'm not sure if I actually want to be able to call the default constructor.
* Triggers should always be given a name.
* The maps trigger controller should guarantee the uniqueness of the name.
*/
Trigger();
/** Constructor with name
*
* Triggers should be created with a name as that is how they will
* be referred to in the map file.
*
*/
Trigger(const std::string& name);
/** Destructor.
*/
virtual ~Trigger();
/** Add a listener to the trigger.
*
* When a trigger gets triggered it will call the onTriggered()
* function of the listener.
*
* The Trigger does NOT take ownership of the listener so clients
* must be sure to free their memory after the trigger has been
* deleted.
*
* @see ITriggerListener
*/
void addTriggerListener(ITriggerListener* listener);
/** Removes a listener from the trigger.
*
* This listener will no longer get called. The Trigger does
* NOT free the listener so you must be sure to do this.
*/
void removeTriggerListener(ITriggerListener* listener);
/** Reset trigger
*
* Resets the status of the trigger so it can be triggered again.
*
*/
void reset();
/** Gets the name of the trigger.
*
* @return name of the trigger.
*/
const std::string& getName() const { return m_name; };
/** Returns if the trigger has been triggered
*
* Triggers will only trigger once unless they are reset.
* @return bool true if the trigger has been triggered, false
* otherwise.
*/
bool isTriggered() { return m_triggered; };
/** Sets the trigger to triggered and calls ITriggerListener->onTriggered()
*/
void setTriggered();
/** Adds trigger condition.
*
* @param type The trigger condition.
*/
void addTriggerCondition(TriggerCondition type);
/** Returns trigger conditions in an vector.
*/
const std::vector<TriggerCondition>& getTriggerConditions();
/** Removes trigger condition.
*
* @param type The trigger condition.
*/
void removeTriggerCondition(TriggerCondition type);
/** Enables trigger for given instance.
*
* @param instance The instance which is enabled for the trigger.
*/
void enableForInstance(Instance* instance);
/** Returns instance which the trigger is enabled for.
*/
const std::vector<Instance*>& getEnabledInstances();
/** Disables trigger for given instance.
*
* @param instance The instance which is disabled for the trigger.
*/
void disableForInstance(Instance* instance);
/** Enables trigger for all instances.
*/
void enableForAllInstances();
/** Returns if trigger is enabled for all instances.
*/
bool isEnabledForAllInstances();
/** Disables trigger for all instances.
*/
void disableForAllInstances();
/** Assigns trigger on given layer and position.
*
* @param layer A pointer to the layer in which to add the Trigger to.
* @param pt The ModelCoordinate where the Trigger should be added.
*/
void assign(Layer* layer, const ModelCoordinate& pt);
/** Removes trigger from given layer and position.
*
* @param layer A pointer to the layer in which to remove the Trigger from.
* @param pt The ModelCoordinate where the Trigger should be removed.
*/
void remove(Layer* layer, const ModelCoordinate& pt);
/** Assigns trigger on given cell.
*
* @param cell A pointer to the cell in which to add the Trigger to.
*/
void assign(Cell* cell);
/** Removes trigger from given cell.
*
* @param cell A pointer to the cell in which to remove the Trigger from.
*/
void remove(Cell* cell);
/** Returns vector with the cells where the trigger is assigned to.
*/
const std::vector<Cell*>& getAssignedCells();
/** Attaches the trigger to the given instance. So the trigger moves with the instance.
*
* @param instance A pointer to the instance which the Trigger is attached to.
*/
void attach(Instance* instance);
/** Detaches trigger from instance.
*/
void detach();
/** Returns pointer to instance where the trigger is attached to.
* Note: Returns Null if no instance is attached.
*/
Instance* getAttached() { return m_attached; }
/** Callback for TriggerChangeListener.
*/
void move();
/** Moves the trigger from the old position to the new position.
*
* @param newPos The old position as ModelCoordinate.
* @param oldPos The old position as ModelCoordinate.
*/
void moveTo(const ModelCoordinate& newPos, const ModelCoordinate& oldPos);
private:
//! name of the trigger. This should be unique per Map.
std::string m_name;
//! true if this trigger has been triggered
bool m_triggered;
//! true if the trigger is enabled for all instances
bool m_enabledAll;
//! Vector of the listeners that get called
std::vector<ITriggerListener*> m_triggerListeners;
//! main change listener (cell and instance listener)
TriggerChangeListener* m_changeListener;
//! cells in which the trigger is assigned
std::vector<Cell*> m_assigned;
//! all trigger conditions
std::vector<TriggerCondition> m_triggerConditions;
//! all enabled instances
std::vector<Instance*> m_enabledInstances;
//! instance where the trigger is attached to
Instance* m_attached;
};
} //FIFE
#endif
|