Orxonox  0.0.5 Codename: Arcturus
MultiTrigger.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 _MultiTrigger_H__
36 #define _MultiTrigger_H__
37 
38 #include "objects/ObjectsPrereqs.h"
39 
40 #include "core/BaseObject.h"
41 #include "core/ClassTreeMask.h"
42 
43 #include <set>
44 #include <deque>
45 
46 #include "TriggerBase.h"
47 
48 namespace orxonox
49 {
50 
58  {
60  bool bTriggered;
61  };
62 
99  {
100  public:
101  MultiTrigger(Context* context);
102  virtual ~MultiTrigger();
103 
104  virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
105  virtual void tick(float dt);
106 
111  inline bool isActive(void) const
112  { return this->isActive(nullptr); }
113  bool isActive(BaseObject* triggerer = nullptr) const;
114 
119  inline void setSimultaneousTriggerers(int triggerers)
120  { if(triggerers >= 0 || triggerers == TriggerBase::INF_s) this->maxNumSimultaneousTriggerers_ = triggerers; }
125  inline int getSimultaneousTriggerers(void)
126  { return this->maxNumSimultaneousTriggerers_; }
127 
132  inline void setBroadcast(bool bBroadcast)
133  { this->bBroadcast_ = bBroadcast; }
138  inline bool getBroadcast(void)
139  { return this->bBroadcast_; }
140 
146  inline bool isTarget(BaseObject* target)
147  { if(target == nullptr) return true; else return targetMask_.isIncluded(target->getIdentifier()); }
148 
149  void addTarget(const std::string& targets);
150 
151  protected:
152  virtual std::queue<MultiTriggerState*>* letTrigger(void);
153 
154  void changeTriggered(BaseObject* originator = nullptr);
155 
156  bool isModeTriggered(BaseObject* triggerer = nullptr);
157  bool isTriggered(BaseObject* triggerer = nullptr);
158 
159  virtual void fire(bool status, BaseObject* originator = nullptr);
160  void broadcast(bool status);
161 
162  void removeTarget(const std::string& target);
163 
169  { return this->targetMask_; }
170 
171  private:
172  void childActivityChanged(BaseObject* originator);
173 
174  bool addState(MultiTriggerState* state);
175 
176  bool checkAnd(BaseObject* triggerer);
177  bool checkOr(BaseObject* triggerer);
178  bool checkXor(BaseObject* triggerer);
179 
184  std::set<BaseObject*>& getActive(void)
185  { return this->active_; }
186 
188 
189  bool bBroadcast_;
190 
191  std::set<BaseObject*> active_;
192  std::set<BaseObject*> triggered_;
193 
194  std::deque<std::pair<float, MultiTriggerState*>> stateQueue_;
195 
197 
198  };
199 
200 }
201 
202 #endif // _MultiTrigger_H__
#define _ObjectsExport
Definition: ObjectsPrereqs.h:60
ClassTreeMask & getTargetMask(void)
Get the target mask used to identify the targets of this MultiTrigger.
Definition: MultiTrigger.h:168
The BaseObject is the parent of all classes representing an instance in the game. ...
Definition: BaseObject.h:63
The ClassTreeMask is a set of rules, containing the information for each class whether it&#39;s included ...
Definition: ClassTreeMask.h:187
Identifier * getIdentifier() const
Returns the Identifier of the object.
Definition: Identifiable.h:60
static const int INF_s
Magic number for infinity.
Definition: TriggerBase.h:177
bool bTriggered
Definition: MultiTrigger.h:60
void setSimultaneousTriggerers(int triggerers)
Set the number of objects that are allowed to simultaneously trigger this MultiTrigger.
Definition: MultiTrigger.h:119
::std::string string
Definition: gtest-port.h:756
Declaration of the ClassTreeMask, ClassTreeMaskNode, and ClassTreeMaskIterator classes.
void setBroadcast(bool bBroadcast)
Set the broadcast-mode of the MultiTrigger.
Definition: MultiTrigger.h:132
std::set< BaseObject * > & getActive(void)
Get the objects for which this MultiTrigger is active.
Definition: MultiTrigger.h:184
ClassTreeMask targetMask_
The target mask, masking all objects that can trigger this MultiTrigger.
Definition: MultiTrigger.h:196
bool isTarget(BaseObject *target)
Get whether the input object is a target of the MultiTrigger.
Definition: MultiTrigger.h:146
xmlelement
Definition: Super.h:519
std::deque< std::pair< float, MultiTriggerState * > > stateQueue_
The queue of states waiting to become active.
Definition: MultiTrigger.h:194
The TriggerBase class is a base class for the two types of triggers, the (normal) Triggers and the Mu...
Definition: TriggerBase.h:70
std::set< BaseObject * > active_
The set of all objects the MultiTrigger is active for.
Definition: MultiTrigger.h:191
bool bBroadcast_
Bool for the broadcast-mode, if true all triggers go to all possible targets.
Definition: MultiTrigger.h:189
Die Wagnis Klasse hat die folgenden Aufgaben:
Definition: ApplicationPaths.cc:66
bool isActive(void) const
Check whether the MultiTrigger is active.
Definition: MultiTrigger.h:111
Mode
Definition: CorePrereqs.h:102
BaseObject * originator
Definition: MultiTrigger.h:59
Declaration of BaseObject, the base class of all objects in Orxonox.
std::set< BaseObject * > triggered_
The set of all objects the MultiTrigger is triggered for.
Definition: MultiTrigger.h:192
Definition: Context.h:45
bool getBroadcast(void)
Get the broadcast-mode of the MultiTrigger.
Definition: MultiTrigger.h:138
Shared library macros, enums, constants and forward declarations for the objects module ...
void status(const std::string &text)
Prints output with status level.
Definition: ConsoleCommandCompilation.cc:153
int maxNumSimultaneousTriggerers_
The maximum number of objects simultaneously trigggering this MultiTrigger.
Definition: MultiTrigger.h:187
Struct to handle MultiTrigger states internally.
Definition: MultiTrigger.h:57
Definition of the TriggerBase class.
int getSimultaneousTriggerers(void)
Get the number of objects that are allowed to simultaneously trigger this MultiTriggger.
Definition: MultiTrigger.h:125
The MultiTrigger class implements a trigger that has a distinct state for each object triggering it...
Definition: MultiTrigger.h:98