Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/usability/src/modules/objects/triggers/TriggerBase.h @ 9670

Last change on this file since 9670 was 7652, checked in by landauf, 14 years ago

eol-style native

  • Property svn:eol-style set to native
File size: 7.8 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 behaviour 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(BaseObject* creator);
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            /**
83            @brief Check whether the trigger is active.
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_; }
135
136            /**
137            @brief Set the invert-mode of triggerhe trigger.
138            @param bInvert If true the t is set to invert.
139            */
140            inline void setInvert(bool bInvert)
141                { this->bInvertMode_ = bInvert; }
142            /**
143            @brief Get the invert-mode of the trigger.
144            @return Returns true if the trigger is set to invert.
145            */
146            inline bool getInvert(void) const
147                { return this->bInvertMode_; }
148
149            void setMode(const std::string& modeName); //!< Set the mode of the trigger.
150            /**
151            @brief Set the mode of the trigger.
152            @param mode The mode of the trigger.
153            */
154            inline void setMode(TriggerMode::Value mode) //!< Get the mode of the trigger.
155                { this->mode_ = mode; }
156            const std::string& getModeString(void) const;
157            /**
158            @brief Get the mode of the trigger.
159            @return Returns and Enum for the mode of the trigger.
160            */
161            inline TriggerMode::Value getMode(void) const
162                { return mode_; }
163
164            void addTrigger(TriggerBase* trigger);
165            const TriggerBase* getTrigger(unsigned int index) const;
166
167            /**
168            @brief Check whether this trigger is a @ref orxonox::MultiTrigger "MultiTrigger".
169                This is done for performance reasons.
170            */
171            inline bool isMultiTrigger(void)
172                { return this->bMultiTrigger_; }
173
174        protected:
175            static const int INF_s; //!< Magic number for infinity.
176            //! Magic strings for the mode.
177            static const std::string and_s;
178            static const std::string or_s;
179            static const std::string xor_s;
180
181            /**
182            @brief Set the number of activations the trigger can go through.
183            @param activations The number of activations. -1 denotes infinitely many activations.
184            */
185            inline void setActivations(int activations)
186                { if(activations >= 0 || activations == INF_s) this->remainingActivations_ = activations; }
187
188            /**
189            @brief Adds the parent of a MultiTrigger.
190            @param parent A pointer to the parent MultiTrigger.
191            */
192            inline void addParentTrigger(TriggerBase* parent)
193                { this->parent_ = parent; }
194
195            bool bFirstTick_; //!< Bool to check whether this is the first tick.
196
197            float delay_; //!< The delay that is imposed on all new trigger events.
198            bool bSwitch_; //!< Bool for the switch-mode, if true the trigger behaves like a switch.
199            bool bStayActive_; //!< Bool for the stay-active-mode, if true the trigger stays active after its last activation.;
200
201            int remainingActivations_; //!< The remaining activations of this trigger.
202
203            bool bInvertMode_; //!< Bool for the invert-mode, if true the trigger is inverted.
204            TriggerMode::Value mode_; //!< The mode of the trigger.
205
206            TriggerBase* parent_; //!< The parent of this trigger.
207            std::set<TriggerBase*> children_; //!< The children of this trigger.
208
209            bool bMultiTrigger_; //!< Specifies whether this trigger is a MultiTrigger.
210
211    };
212}
213
214#endif /* _Trigger_H__ */
Note: See TracBrowser for help on using the repository browser.