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 | * Benjamin Knecht |
---|
24 | * Co-authors: |
---|
25 | * ... |
---|
26 | * |
---|
27 | */ |
---|
28 | |
---|
29 | #ifndef _Trigger_H__ |
---|
30 | #define _Trigger_H__ |
---|
31 | |
---|
32 | #include <set> |
---|
33 | #include <queue> |
---|
34 | |
---|
35 | #include "OrxonoxPrereqs.h" |
---|
36 | |
---|
37 | #include "objects/worldentities/PositionableEntity.h" |
---|
38 | #include "tools/BillboardSet.h" |
---|
39 | |
---|
40 | namespace orxonox |
---|
41 | { |
---|
42 | enum TriggerMode |
---|
43 | { |
---|
44 | TM_EventTriggerAND, |
---|
45 | TM_EventTriggerOR, |
---|
46 | TM_EventTriggerXOR, |
---|
47 | }; |
---|
48 | |
---|
49 | class _OrxonoxExport Trigger : public PositionableEntity |
---|
50 | { |
---|
51 | public: |
---|
52 | Trigger(BaseObject* creator); |
---|
53 | ~Trigger(); |
---|
54 | |
---|
55 | virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); |
---|
56 | virtual void tick(float dt); |
---|
57 | |
---|
58 | inline bool isActive() const |
---|
59 | { return bActive_; } |
---|
60 | |
---|
61 | void addTrigger(Trigger* trigger); |
---|
62 | const Trigger* getTrigger(unsigned int index) const; |
---|
63 | |
---|
64 | void setMode(const std::string& modeName); |
---|
65 | inline void setMode(TriggerMode mode) |
---|
66 | { this->mode_ = mode; } |
---|
67 | inline TriggerMode getMode() const |
---|
68 | { return mode_; } |
---|
69 | |
---|
70 | inline void setInvert(bool bInvert) |
---|
71 | { this->bInvertMode_ = bInvert; } |
---|
72 | inline bool getInvert() const |
---|
73 | { return this->bInvertMode_; } |
---|
74 | |
---|
75 | inline void setSwitch(bool bSwitch) |
---|
76 | { this->bSwitch_ = bSwitch; } |
---|
77 | inline bool getSwitch() const |
---|
78 | { return this->bSwitch_; } |
---|
79 | |
---|
80 | inline void setStayActive(bool bStayActive) |
---|
81 | { this->bStayActive_ = bStayActive; } |
---|
82 | inline bool getStayActive() const |
---|
83 | { return this->bStayActive_; } |
---|
84 | |
---|
85 | inline void setActivations(int activations) |
---|
86 | { this->remainingActivations_ = activations; } |
---|
87 | inline int getActivations() const |
---|
88 | { return this->remainingActivations_; } |
---|
89 | |
---|
90 | void setDelay(float delay); |
---|
91 | inline float getDelay() const |
---|
92 | { return this->delay_; } |
---|
93 | |
---|
94 | bool switchState(); |
---|
95 | |
---|
96 | static void debugFlares(bool bVisible); |
---|
97 | virtual void changedVisibility(); |
---|
98 | |
---|
99 | protected: |
---|
100 | inline bool isTriggered() { return this->isTriggered(this->mode_); } |
---|
101 | virtual bool isTriggered(TriggerMode mode); |
---|
102 | |
---|
103 | private: |
---|
104 | bool checkAnd(); |
---|
105 | bool checkOr(); |
---|
106 | bool checkXor(); |
---|
107 | void setBillboardColour(const ColourValue& colour); |
---|
108 | void storeState(); |
---|
109 | std::string getModeString() const; |
---|
110 | |
---|
111 | bool bActive_; |
---|
112 | bool bTriggered_; |
---|
113 | |
---|
114 | TriggerMode mode_; |
---|
115 | bool bInvertMode_; |
---|
116 | bool bSwitch_; |
---|
117 | bool bStayActive_; |
---|
118 | float delay_; |
---|
119 | int remainingActivations_; |
---|
120 | |
---|
121 | char latestState_; |
---|
122 | float remainingTime_; |
---|
123 | float timeSinceLastEvent_; |
---|
124 | |
---|
125 | // bool bUpdating_; |
---|
126 | BillboardSet debugBillboard_; |
---|
127 | |
---|
128 | std::set<Trigger*> children_; |
---|
129 | std::queue<std::pair<float, char> > stateChanges_; |
---|
130 | }; |
---|
131 | |
---|
132 | } |
---|
133 | |
---|
134 | #endif /* _Trigger_H__ */ |
---|