Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/cpp11_v3/src/modules/objects/triggers/TriggerBase.h @ 11058

Last change on this file since 11058 was 11058, checked in by landauf, 8 years ago

removed empty tick functions

  • Property svn:eol-style set to native
File size: 8.4 KB
Line 
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
46namespace 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
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.
67
68    @author
69        Damian 'Mozork' Frick
70
71    @ingroup Triggers
72    */
73    class _ObjectsExport TriggerBase : public StaticEntity, public Tickable
74    {
75        public:
76            TriggerBase(Context* context);
77            virtual ~TriggerBase();
78
79            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);  //!< Method for creating a TriggerBase object through XML.
80
81            /**
82            @brief Check whether the trigger is active. (i.e. triggered to the outside)
83            @return Returns if the trigger is active.
84            */
85            virtual bool isActive(void) const
86                { return false; }
87
88            /**
89            @brief Set the delay of the trigger.
90            @param delay The delay to be set.
91            */
92            inline void setDelay(float delay)
93                { if(delay > 0.0f) this->delay_= delay; this->delayChanged(); }
94            /**
95            @brief Get the delay of the trigger.
96            @return The delay.
97            */
98            inline float getDelay(void) const
99                { return this->delay_; }
100            virtual void delayChanged(void) {}
101
102            /**
103            @brief Set switch-mode of the trigger.
104            @param bSwitch If true the trigger is set to switched.
105            */
106            inline void setSwitch(bool bSwitch)
107                { this->bSwitch_ = bSwitch; }
108            /**
109            @brief Get the switch-mode of the trigger.
110            @return Returns true if the trigger is in switch-mode.
111            */
112            inline bool getSwitch(void) const
113                { return this->bSwitch_; }
114
115            /**
116            @brief Set the stay-active-mode of the trigger.
117            @param bStayActive If true the trigger is set to stay active.
118            */
119            inline void setStayActive(bool bStayActive)
120                { this->bStayActive_ = bStayActive; }
121            /**
122            @brief Get the stay-active-mode of the trigger.
123            @return Returns true if the trigger stays active.
124            */
125            inline bool getStayActive(void) const
126                { return this->bStayActive_; }
127
128            /**
129            @brief Get the number of remaining activations of the trigger.
130            @return The number of activations. -1 denotes infinity.
131            */
132            inline int getActivations(void) const
133                { return this->remainingActivations_; }
134            /**
135            @brief Check whether the trigger has still at least one remaining activation.
136            @return Returns true if the trigger has remaining activations (i.e. the number of remaining activations is not zero).
137            */
138            inline bool hasRemainingActivations(void) const
139                { return this->remainingActivations_ > 0 || this->remainingActivations_ == INF_s; }
140
141            /**
142            @brief Set the invert-mode of triggerhe trigger.
143            @param bInvert If true the t is set to invert.
144            */
145            inline void setInvert(bool bInvert)
146                { this->bInvertMode_ = bInvert; }
147            /**
148            @brief Get the invert-mode of the trigger.
149            @return Returns true if the trigger is set to invert.
150            */
151            inline bool getInvert(void) const
152                { return this->bInvertMode_; }
153
154            void setMode(const std::string& modeName); //!< Set the mode of the trigger.
155            /**
156            @brief Set the mode of the trigger.
157            @param mode The mode of the trigger.
158            */
159            inline void setMode(TriggerMode::Value mode) //!< Get the mode of the trigger.
160                { this->mode_ = mode; }
161            const std::string& getModeString(void) const;
162            /**
163            @brief Get the mode of the trigger.
164            @return Returns and Enum for the mode of the trigger.
165            */
166            inline TriggerMode::Value getMode(void) const
167                { return mode_; }
168
169            void addTrigger(TriggerBase* trigger);
170            const TriggerBase* getTrigger(unsigned int index) const;
171
172            /**
173            @brief Check whether this trigger is a @ref orxonox::MultiTrigger "MultiTrigger".
174                This is done for performance reasons.
175            */
176            inline bool isMultiTrigger(void)
177                { return this->bMultiTrigger_; }
178
179        protected:
180            static const int INF_s; //!< Magic number for infinity.
181            //! Magic strings for the mode.
182            static const std::string and_s;
183            static const std::string or_s;
184            static const std::string xor_s;
185
186            /**
187            @brief Set the number of activations the trigger can go through.
188            @param activations The number of activations. -1 denotes infinitely many activations.
189            */
190            inline void setActivations(int activations)
191                { if(activations >= 0 || activations == INF_s) this->remainingActivations_ = activations; }
192               
193            inline bool hasRemainingActivations(void)
194                { return this->remainingActivations_ == INF_s || this->remainingActivations_  > 0; }
195
196            /**
197            @brief Adds the parent of a MultiTrigger.
198            @param parent A pointer to the parent MultiTrigger.
199            */
200            inline void addParentTrigger(TriggerBase* parent)
201                { this->parent_ = parent; }
202
203            bool bFirstTick_; //!< Bool to check whether this is the first tick.
204
205            float delay_; //!< The delay that is imposed on all new trigger events.
206            bool bSwitch_; //!< Bool for the switch-mode, if true the trigger behaves like a switch.
207            bool bStayActive_; //!< Bool for the stay-active-mode, if true the trigger stays active after its last activation.;
208
209            int remainingActivations_; //!< The remaining activations of this trigger.
210
211            bool bInvertMode_; //!< Bool for the invert-mode, if true the trigger is inverted.
212            TriggerMode::Value mode_; //!< The mode of the trigger.
213
214            TriggerBase* parent_; //!< The parent of this trigger.
215            std::set<TriggerBase*> children_; //!< The children of this trigger.
216
217            bool bMultiTrigger_; //!< Specifies whether this trigger is a MultiTrigger.
218
219    };
220}
221
222#endif /* _Trigger_H__ */
Note: See TracBrowser for help on using the repository browser.