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