Orxonox  0.0.5 Codename: Arcturus
TriggerBase.h
Go to the documentation of this file.
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 
35 #ifndef _TriggerBase_H__
36 #define _TriggerBase_H__
37 
38 #include "objects/ObjectsPrereqs.h"
39 
40 #include <set>
41 #include <string>
42 
45 
46 namespace orxonox {
47 
54  enum class TriggerMode
55  {
59  };
60 
71  {
72  public:
73  TriggerBase(Context* context);
74  virtual ~TriggerBase();
75 
76  virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
77 
82  virtual bool isActive(void) const
83  { return false; }
84 
89  inline void setDelay(float delay)
90  { if(delay > 0.0f) this->delay_= delay; this->delayChanged(); }
95  inline float getDelay(void) const
96  { return this->delay_; }
97  virtual void delayChanged(void) {}
98 
103  inline void setSwitch(bool bSwitch)
104  { this->bSwitch_ = bSwitch; }
109  inline bool getSwitch(void) const
110  { return this->bSwitch_; }
111 
116  inline void setStayActive(bool bStayActive)
117  { this->bStayActive_ = bStayActive; }
122  inline bool getStayActive(void) const
123  { return this->bStayActive_; }
124 
129  inline int getActivations(void) const
130  { return this->remainingActivations_; }
135  inline bool hasRemainingActivations(void) const
136  { return this->remainingActivations_ > 0 || this->remainingActivations_ == INF_s; }
137 
142  inline void setInvert(bool bInvert)
143  { this->bInvertMode_ = bInvert; }
148  inline bool getInvert(void) const
149  { return this->bInvertMode_; }
150 
151  void setMode(const std::string& modeName);
152 
156  inline void setMode(TriggerMode mode)
157  { this->mode_ = mode; }
158  const std::string& getModeString(void) const;
163  inline TriggerMode getMode(void) const
164  { return mode_; }
165 
166  void addTrigger(TriggerBase* trigger);
167  const TriggerBase* getTrigger(unsigned int index) const;
168 
173  inline bool isMultiTrigger(void)
174  { return this->bMultiTrigger_; }
175 
176  protected:
177  static const int INF_s;
178  static const std::string and_s;
180  static const std::string or_s;
181  static const std::string xor_s;
182 
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 
197  inline void addParentTrigger(TriggerBase* parent)
198  { this->parent_ = parent; }
199 
200  bool bFirstTick_;
201 
202  float delay_;
203  bool bSwitch_;
205 
207 
210 
212  std::set<TriggerBase*> children_;
213 
215 
216  };
217 }
218 
219 #endif /* _Trigger_H__ */
#define _ObjectsExport
Definition: ObjectsPrereqs.h:60
static const int INF_s
Magic number for infinity.
Definition: TriggerBase.h:177
bool bStayActive_
Bool for the stay-active-mode, if true the trigger stays active after its last activation.;.
Definition: TriggerBase.h:204
The StaticEntity is the simplest derivative of the orxonox::WorldEntity class.
Definition: StaticEntity.h:50
bool hasRemainingActivations(void) const
Check whether the trigger has still at least one remaining activation.
Definition: TriggerBase.h:135
TriggerMode
The different modes the trigger can be in.
Definition: TriggerBase.h:54
static const std::string xor_s
Definition: TriggerBase.h:181
Declaration of the Tickable interface.
::std::string string
Definition: gtest-port.h:756
TriggerMode mode_
The mode of the trigger.
Definition: TriggerBase.h:209
bool getInvert(void) const
Get the invert-mode of the trigger.
Definition: TriggerBase.h:148
virtual void delayChanged(void)
Definition: TriggerBase.h:97
void addParentTrigger(TriggerBase *parent)
Adds the parent of a MultiTrigger.
Definition: TriggerBase.h:197
bool hasRemainingActivations(void)
Definition: TriggerBase.h:190
bool bFirstTick_
Bool to check whether this is the first tick.
Definition: TriggerBase.h:200
bool bMultiTrigger_
Specifies whether this trigger is a MultiTrigger.
Definition: TriggerBase.h:214
virtual bool isActive(void) const
Check whether the trigger is active.
Definition: TriggerBase.h:82
float getDelay(void) const
Get the delay of the trigger.
Definition: TriggerBase.h:95
xmlelement
Definition: Super.h:519
The TriggerBase class is a base class for the two types of triggers, the (normal) Triggers and the Mu...
Definition: TriggerBase.h:70
void setSwitch(bool bSwitch)
Set switch-mode of the trigger.
Definition: TriggerBase.h:103
static const std::string or_s
Definition: TriggerBase.h:180
void setStayActive(bool bStayActive)
Set the stay-active-mode of the trigger.
Definition: TriggerBase.h:116
int getActivations(void) const
Get the number of remaining activations of the trigger.
Definition: TriggerBase.h:129
bool getStayActive(void) const
Get the stay-active-mode of the trigger.
Definition: TriggerBase.h:122
TriggerMode getMode(void) const
Get the mode of the trigger.
Definition: TriggerBase.h:163
Die Wagnis Klasse hat die folgenden Aufgaben:
Definition: ApplicationPaths.cc:66
bool isMultiTrigger(void)
Check whether this trigger is a MultiTrigger.
Definition: TriggerBase.h:173
The and mode. The trigger can only trigger if all the children are active.
Mode
Definition: CorePrereqs.h:102
bool getSwitch(void) const
Get the switch-mode of the trigger.
Definition: TriggerBase.h:109
The or mode. The trigger can only trigger if at least one child is active.
void setDelay(float delay)
Set the delay of the trigger.
Definition: TriggerBase.h:89
unsigned int delay(float delay, const std::string &command)
Console-command: Calls another console command after delay seconds (game time).
Definition: Timer.cc:65
Definition: Context.h:45
TriggerBase * parent_
The parent of this trigger.
Definition: TriggerBase.h:211
Shared library macros, enums, constants and forward declarations for the objects module ...
bool bSwitch_
Bool for the switch-mode, if true the trigger behaves like a switch.
Definition: TriggerBase.h:203
void setMode(TriggerMode mode)
Set the mode of the trigger.
Definition: TriggerBase.h:156
std::set< TriggerBase * > children_
The children of this trigger.
Definition: TriggerBase.h:212
int remainingActivations_
The remaining activations of this trigger.
Definition: TriggerBase.h:206
The xor mode. The trigger can only trigger if exactly one child is active.
The Tickable interface provides a tick(dt) function, that gets called every frame.
Definition: Tickable.h:52
bool bInvertMode_
Bool for the invert-mode, if true the trigger is inverted.
Definition: TriggerBase.h:208
float delay_
The delay that is imposed on all new trigger events.
Definition: TriggerBase.h:202
void setActivations(int activations)
Set the number of activations the trigger can go through.
Definition: TriggerBase.h:187
void setInvert(bool bInvert)
Set the invert-mode of triggerhe trigger.
Definition: TriggerBase.h:142