Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/Dialog_HS16/src/modules/objects/triggers/TriggerBase.h @ 11454

Last change on this file since 11454 was 11071, checked in by landauf, 9 years ago

merged branch cpp11_v3 back to trunk

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