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 | * Benjamin Knecht |
---|
26 | * |
---|
27 | */ |
---|
28 | |
---|
29 | #ifndef _MultiTrigger_H__ |
---|
30 | #define _MultiTrigger_H__ |
---|
31 | |
---|
32 | #include "objects/ObjectsPrereqs.h" |
---|
33 | |
---|
34 | #include "core/BaseObject.h" |
---|
35 | #include "core/ClassTreeMask.h" |
---|
36 | |
---|
37 | #include <set> |
---|
38 | #include <deque> |
---|
39 | |
---|
40 | #include "tools/interfaces/Tickable.h" |
---|
41 | #include "worldentities/StaticEntity.h" |
---|
42 | |
---|
43 | namespace orxonox |
---|
44 | { |
---|
45 | |
---|
46 | namespace MultiTriggerMode |
---|
47 | { |
---|
48 | enum Value |
---|
49 | { |
---|
50 | EventTriggerAND, |
---|
51 | EventTriggerOR, |
---|
52 | EventTriggerXOR, |
---|
53 | }; |
---|
54 | } |
---|
55 | |
---|
56 | struct MultiTriggerState |
---|
57 | { |
---|
58 | BaseObject* originator; |
---|
59 | bool bActive; |
---|
60 | bool bTriggered; |
---|
61 | }; |
---|
62 | |
---|
63 | /** |
---|
64 | @brief |
---|
65 | The MultiTrigger class implements a trigger that has a distinct state for each object triggering it. |
---|
66 | */ |
---|
67 | class _ObjectsExport MultiTrigger : public StaticEntity, public Tickable |
---|
68 | { |
---|
69 | public: |
---|
70 | MultiTrigger(BaseObject* creator); |
---|
71 | ~MultiTrigger(); |
---|
72 | |
---|
73 | virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); |
---|
74 | virtual void tick(float dt); |
---|
75 | |
---|
76 | bool isActive(BaseObject* triggerer = NULL); |
---|
77 | void addTrigger(MultiTrigger* trigger); |
---|
78 | const MultiTrigger* getTrigger(unsigned int index) const; |
---|
79 | |
---|
80 | void addTargets(const std::string& targets); |
---|
81 | void removeTargets(const std::string& targets); |
---|
82 | inline bool isTarget(BaseObject* target) |
---|
83 | { return targetMask_.isIncluded(target->getIdentifier()); } |
---|
84 | |
---|
85 | void setMode(const std::string& modeName); |
---|
86 | const std::string& getModeString(void) const; |
---|
87 | inline void setMode(MultiTriggerMode::Value mode) |
---|
88 | { this->mode_ = mode; } |
---|
89 | inline MultiTriggerMode::Value getMode() const |
---|
90 | { return mode_; } |
---|
91 | |
---|
92 | inline void setInvert(bool bInvert) |
---|
93 | { this->bInvertMode_ = bInvert; } |
---|
94 | inline bool getInvert() const |
---|
95 | { return this->bInvertMode_; } |
---|
96 | |
---|
97 | inline void setSwitch(bool bSwitch) |
---|
98 | { this->bSwitch_ = bSwitch; } |
---|
99 | inline bool getSwitch() const |
---|
100 | { return this->bSwitch_; } |
---|
101 | |
---|
102 | inline void setStayActive(bool bStayActive) |
---|
103 | { this->bStayActive_ = bStayActive; } |
---|
104 | inline bool getStayActive() const |
---|
105 | { return this->bStayActive_; } |
---|
106 | |
---|
107 | inline void setActivations(int activations) |
---|
108 | { this->remainingActivations_ = activations; } |
---|
109 | inline int getActivations() const |
---|
110 | { return this->remainingActivations_; } |
---|
111 | |
---|
112 | inline void setSimultaniousTriggerers(int triggerers) |
---|
113 | { this->maxNumSimultaniousTriggerers_ = triggerers; } |
---|
114 | inline int getSimultaniousTriggerers(void) |
---|
115 | { return this->maxNumSimultaniousTriggerers_; } |
---|
116 | |
---|
117 | inline void setDelay(float delay) |
---|
118 | { this->delay_= delay; } |
---|
119 | inline float getDelay() const |
---|
120 | { return this->delay_; } |
---|
121 | |
---|
122 | protected: |
---|
123 | void fire(bool status, BaseObject* originator = NULL); |
---|
124 | |
---|
125 | bool isModeTriggered(BaseObject* triggerer = NULL); |
---|
126 | bool isTriggered(BaseObject* triggerer = NULL); |
---|
127 | |
---|
128 | virtual std::queue<MultiTriggerState*>* letTrigger(void); |
---|
129 | |
---|
130 | inline ClassTreeMask& getTargetMask(void) |
---|
131 | { return this->targetMask_; } |
---|
132 | virtual void notifyMaskUpdate(void) {} |
---|
133 | |
---|
134 | private: |
---|
135 | static const int INF_s; |
---|
136 | static const std::string or_s; |
---|
137 | static const std::string and_s; |
---|
138 | static const std::string xor_s; |
---|
139 | |
---|
140 | bool addState(bool bTriggered, BaseObject* originator = NULL); |
---|
141 | |
---|
142 | bool checkAnd(BaseObject* triggerer); |
---|
143 | bool checkOr(BaseObject* triggerer); |
---|
144 | bool checkXor(BaseObject* triggerer); |
---|
145 | |
---|
146 | std::set<BaseObject*>& getActive(void) |
---|
147 | { return this->active_; } |
---|
148 | |
---|
149 | bool bFirstTick_; |
---|
150 | |
---|
151 | MultiTriggerMode::Value mode_; |
---|
152 | bool bInvertMode_; |
---|
153 | bool bSwitch_; |
---|
154 | bool bStayActive_; |
---|
155 | float delay_; |
---|
156 | int remainingActivations_; |
---|
157 | int maxNumSimultaniousTriggerers_; |
---|
158 | |
---|
159 | std::set<BaseObject*> active_; |
---|
160 | std::set<BaseObject*> triggered_; |
---|
161 | |
---|
162 | std::set<MultiTrigger*> children_; |
---|
163 | std::deque<std::pair<float, MultiTriggerState*> > stateQueue_; |
---|
164 | |
---|
165 | ClassTreeMask targetMask_; |
---|
166 | |
---|
167 | }; |
---|
168 | |
---|
169 | } |
---|
170 | |
---|
171 | #endif // _MultiTrigger_H__ |
---|