[7601] | 1 | /* |
---|
| 2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
| 3 | * > www.orxonox.net < |
---|
| 4 | * |
---|
| 5 | * |
---|
| 6 | * License notice: |
---|
| 7 | * |
---|
| 8 | * This program is free software; you can redistribute it and/or |
---|
| 9 | * modify it under the terms of the GNU General Public License |
---|
| 10 | * as published by the Free Software Foundation; either version 2 |
---|
| 11 | * of the License, or (at your option) any later version. |
---|
| 12 | * |
---|
| 13 | * This program is distributed in the hope that it will be useful, |
---|
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 16 | * GNU General Public License for more details. |
---|
| 17 | * |
---|
| 18 | * You should have received a copy of the GNU General Public License |
---|
| 19 | * along with this program; if not, write to the Free Software |
---|
| 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
| 21 | * |
---|
| 22 | * Author: |
---|
| 23 | * Damian 'Mozork' Frick |
---|
| 24 | * Co-authors: |
---|
| 25 | * ... |
---|
| 26 | * |
---|
| 27 | */ |
---|
| 28 | |
---|
| 29 | /** |
---|
| 30 | @file TriggerBase.h |
---|
| 31 | @brief Definition of the TriggerBase class. |
---|
| 32 | @ingroup Triggers |
---|
| 33 | */ |
---|
| 34 | |
---|
| 35 | #ifndef _TriggerBase_H__ |
---|
| 36 | #define _TriggerBase_H__ |
---|
| 37 | |
---|
| 38 | #include "objects/ObjectsPrereqs.h" |
---|
| 39 | |
---|
| 40 | #include <set> |
---|
| 41 | #include <string> |
---|
| 42 | |
---|
| 43 | #include "tools/interfaces/Tickable.h" |
---|
| 44 | #include "worldentities/StaticEntity.h" |
---|
| 45 | |
---|
| 46 | namespace orxonox { |
---|
| 47 | |
---|
| 48 | /** |
---|
| 49 | @brief |
---|
| 50 | The different modes the trigger can be in. |
---|
| 51 | |
---|
| 52 | @ingroup Triggers |
---|
| 53 | */ |
---|
| 54 | namespace TriggerMode |
---|
| 55 | { |
---|
| 56 | enum Value |
---|
| 57 | { |
---|
| 58 | EventTriggerAND, //!< The <em>and</em> mode. The trigger can only trigger if all the children are active. |
---|
| 59 | EventTriggerOR, //!< The <em>or</em> mode. The trigger can only trigger if at least one child is active. |
---|
| 60 | EventTriggerXOR, //!< The <em>xor</em> mode. The trigger can only trigger if exactly one child is active. |
---|
| 61 | }; |
---|
| 62 | } |
---|
| 63 | |
---|
| 64 | /** |
---|
| 65 | @brief |
---|
[8213] | 66 | The TriggerBase class is a base class for the two types of triggers, the (normal) @ref orxonox::Trigger "Triggers" and the @ref orxonox::MultiTrigger "MultiTriggers", it encompasses the shared data and functionality between these two types of triggers, but is in itself not a trigger that has any meaningful behavior and thus should not be instantiated. |
---|
[7601] | 67 | |
---|
| 68 | @author |
---|
| 69 | Damian 'Mozork' Frick |
---|
| 70 | |
---|
| 71 | @ingroup Triggers |
---|
| 72 | */ |
---|
| 73 | class _ObjectsExport TriggerBase : public StaticEntity, public Tickable |
---|
| 74 | { |
---|
| 75 | public: |
---|
[9667] | 76 | TriggerBase(Context* context); |
---|
[7601] | 77 | virtual ~TriggerBase(); |
---|
| 78 | |
---|
| 79 | virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); //!< Method for creating a TriggerBase object through XML. |
---|
| 80 | virtual void tick(float dt); //!< A method that is executed each tick. |
---|
| 81 | |
---|
| 82 | /** |
---|
[8213] | 83 | @brief Check whether the trigger is active. (i.e. triggered to the outside) |
---|
[7601] | 84 | @return Returns if the trigger is active. |
---|
| 85 | */ |
---|
| 86 | virtual bool isActive(void) const |
---|
| 87 | { return false; } |
---|
| 88 | |
---|
| 89 | /** |
---|
| 90 | @brief Set the delay of the trigger. |
---|
| 91 | @param delay The delay to be set. |
---|
| 92 | */ |
---|
| 93 | inline void setDelay(float delay) |
---|
| 94 | { if(delay > 0.0f) this->delay_= delay; this->delayChanged(); } |
---|
| 95 | /** |
---|
| 96 | @brief Get the delay of the trigger. |
---|
| 97 | @return The delay. |
---|
| 98 | */ |
---|
| 99 | inline float getDelay(void) const |
---|
| 100 | { return this->delay_; } |
---|
| 101 | virtual void delayChanged(void) {} |
---|
| 102 | |
---|
| 103 | /** |
---|
| 104 | @brief Set switch-mode of the trigger. |
---|
| 105 | @param bSwitch If true the trigger is set to switched. |
---|
| 106 | */ |
---|
| 107 | inline void setSwitch(bool bSwitch) |
---|
| 108 | { this->bSwitch_ = bSwitch; } |
---|
| 109 | /** |
---|
| 110 | @brief Get the switch-mode of the trigger. |
---|
| 111 | @return Returns true if the trigger is in switch-mode. |
---|
| 112 | */ |
---|
| 113 | inline bool getSwitch(void) const |
---|
| 114 | { return this->bSwitch_; } |
---|
| 115 | |
---|
| 116 | /** |
---|
| 117 | @brief Set the stay-active-mode of the trigger. |
---|
| 118 | @param bStayActive If true the trigger is set to stay active. |
---|
| 119 | */ |
---|
| 120 | inline void setStayActive(bool bStayActive) |
---|
| 121 | { this->bStayActive_ = bStayActive; } |
---|
| 122 | /** |
---|
| 123 | @brief Get the stay-active-mode of the trigger. |
---|
| 124 | @return Returns true if the trigger stays active. |
---|
| 125 | */ |
---|
| 126 | inline bool getStayActive(void) const |
---|
| 127 | { return this->bStayActive_; } |
---|
| 128 | |
---|
| 129 | /** |
---|
| 130 | @brief Get the number of remaining activations of the trigger. |
---|
| 131 | @return The number of activations. -1 denotes infinity. |
---|
| 132 | */ |
---|
| 133 | inline int getActivations(void) const |
---|
| 134 | { return this->remainingActivations_; } |
---|
[8706] | 135 | /** |
---|
| 136 | @brief Check whether the trigger has still at least one remaining activation. |
---|
| 137 | @return Returns true if the trigger has remaining activations (i.e. the number of remaining activations is not zero). |
---|
| 138 | */ |
---|
| 139 | inline bool hasRemainingActivations(void) const |
---|
| 140 | { return this->remainingActivations_ > 0 || this->remainingActivations_ == INF_s; } |
---|
[7601] | 141 | |
---|
| 142 | /** |
---|
| 143 | @brief Set the invert-mode of triggerhe trigger. |
---|
| 144 | @param bInvert If true the t is set to invert. |
---|
| 145 | */ |
---|
| 146 | inline void setInvert(bool bInvert) |
---|
| 147 | { this->bInvertMode_ = bInvert; } |
---|
| 148 | /** |
---|
| 149 | @brief Get the invert-mode of the trigger. |
---|
| 150 | @return Returns true if the trigger is set to invert. |
---|
| 151 | */ |
---|
| 152 | inline bool getInvert(void) const |
---|
| 153 | { return this->bInvertMode_; } |
---|
| 154 | |
---|
| 155 | void setMode(const std::string& modeName); //!< Set the mode of the trigger. |
---|
| 156 | /** |
---|
| 157 | @brief Set the mode of the trigger. |
---|
| 158 | @param mode The mode of the trigger. |
---|
| 159 | */ |
---|
| 160 | inline void setMode(TriggerMode::Value mode) //!< Get the mode of the trigger. |
---|
| 161 | { this->mode_ = mode; } |
---|
| 162 | const std::string& getModeString(void) const; |
---|
| 163 | /** |
---|
| 164 | @brief Get the mode of the trigger. |
---|
| 165 | @return Returns and Enum for the mode of the trigger. |
---|
| 166 | */ |
---|
| 167 | inline TriggerMode::Value getMode(void) const |
---|
| 168 | { return mode_; } |
---|
| 169 | |
---|
| 170 | void addTrigger(TriggerBase* trigger); |
---|
| 171 | const TriggerBase* getTrigger(unsigned int index) const; |
---|
| 172 | |
---|
| 173 | /** |
---|
| 174 | @brief Check whether this trigger is a @ref orxonox::MultiTrigger "MultiTrigger". |
---|
| 175 | This is done for performance reasons. |
---|
| 176 | */ |
---|
| 177 | inline bool isMultiTrigger(void) |
---|
| 178 | { return this->bMultiTrigger_; } |
---|
| 179 | |
---|
| 180 | protected: |
---|
| 181 | static const int INF_s; //!< Magic number for infinity. |
---|
| 182 | //! Magic strings for the mode. |
---|
| 183 | static const std::string and_s; |
---|
| 184 | static const std::string or_s; |
---|
| 185 | static const std::string xor_s; |
---|
| 186 | |
---|
| 187 | /** |
---|
| 188 | @brief Set the number of activations the trigger can go through. |
---|
| 189 | @param activations The number of activations. -1 denotes infinitely many activations. |
---|
| 190 | */ |
---|
| 191 | inline void setActivations(int activations) |
---|
| 192 | { if(activations >= 0 || activations == INF_s) this->remainingActivations_ = activations; } |
---|
[8193] | 193 | |
---|
| 194 | inline bool hasRemainingActivations(void) |
---|
| 195 | { return this->remainingActivations_ == INF_s || this->remainingActivations_ > 0; } |
---|
[7601] | 196 | |
---|
| 197 | /** |
---|
| 198 | @brief Adds the parent of a MultiTrigger. |
---|
| 199 | @param parent A pointer to the parent MultiTrigger. |
---|
| 200 | */ |
---|
| 201 | inline void addParentTrigger(TriggerBase* parent) |
---|
| 202 | { this->parent_ = parent; } |
---|
| 203 | |
---|
| 204 | bool bFirstTick_; //!< Bool to check whether this is the first tick. |
---|
| 205 | |
---|
| 206 | float delay_; //!< The delay that is imposed on all new trigger events. |
---|
| 207 | bool bSwitch_; //!< Bool for the switch-mode, if true the trigger behaves like a switch. |
---|
| 208 | bool bStayActive_; //!< Bool for the stay-active-mode, if true the trigger stays active after its last activation.; |
---|
| 209 | |
---|
| 210 | int remainingActivations_; //!< The remaining activations of this trigger. |
---|
| 211 | |
---|
| 212 | bool bInvertMode_; //!< Bool for the invert-mode, if true the trigger is inverted. |
---|
| 213 | TriggerMode::Value mode_; //!< The mode of the trigger. |
---|
| 214 | |
---|
| 215 | TriggerBase* parent_; //!< The parent of this trigger. |
---|
| 216 | std::set<TriggerBase*> children_; //!< The children of this trigger. |
---|
| 217 | |
---|
| 218 | bool bMultiTrigger_; //!< Specifies whether this trigger is a MultiTrigger. |
---|
| 219 | |
---|
| 220 | }; |
---|
| 221 | } |
---|
| 222 | |
---|
| 223 | #endif /* _Trigger_H__ */ |
---|