Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/chat2/src/modules/objects/triggers/MultiTrigger.h @ 6835

Last change on this file since 6835 was 6800, checked in by dafrick, 14 years ago

Created a new class of triggers called Multitriggers.
MultiTriggers are triggers which (as opposed to normal triggers) have a state for each object triggering the MultiTrigger, that means, that a MultiTrigger can be triggered for two different Players, while not being triggered for a third.
To go with this MultiTrigger I created a data structure (MultitriggerContainer), which helps relaying important information to the objects, that receive the Events of the trigger.
Also there is a MultiDistanceTrigger, which is just the DistanceTrigger as a MultiTrigger.

To make this work I had to make some adjustements to the eventsystem, namely an EventState can now be either an EventState (as it was before) or an EventSink, which means that every efent arriving at the EventState is processed as opposed to just the ones which change the state.
There is a new makro (XMLPortEventSink) to create an EventState with sink behaviour. It can be used exacly as the XMLPortEventState makro.

File size: 5.3 KB
Line 
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
43namespace 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    class _ObjectsExport MultiTrigger : public StaticEntity, public Tickable
64    {
65        public:
66            MultiTrigger(BaseObject* creator);
67            ~MultiTrigger();
68           
69            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
70            virtual void tick(float dt);
71           
72            bool isActive(BaseObject* triggerer = NULL);
73            void addTrigger(MultiTrigger* trigger);
74            const MultiTrigger* getTrigger(unsigned int index) const;
75           
76            void addTargets(const std::string& targets);
77            void removeTargets(const std::string& targets);
78            inline bool isTarget(BaseObject* target)
79                { return targetMask_.isIncluded(target->getIdentifier()); }
80           
81            void setMode(const std::string& modeName);
82            const std::string& getModeString(void) const;
83            inline void setMode(MultiTriggerMode::Value mode)
84                { this->mode_ = mode; }
85            inline MultiTriggerMode::Value getMode() const
86                { return mode_; }
87
88            inline void setInvert(bool bInvert)
89                { this->bInvertMode_ = bInvert; }
90            inline bool getInvert() const
91                { return this->bInvertMode_; }
92
93            inline void setSwitch(bool bSwitch)
94                { this->bSwitch_ = bSwitch; }
95            inline bool getSwitch() const
96                { return this->bSwitch_; }
97
98            inline void setStayActive(bool bStayActive)
99                { this->bStayActive_ = bStayActive; }
100            inline bool getStayActive() const
101                { return this->bStayActive_; }
102
103            inline void setActivations(int activations)
104                { this->remainingActivations_ = activations; }
105            inline int getActivations() const
106                { return this->remainingActivations_; }
107               
108            inline void setSimultaniousTriggerers(int triggerers)
109                { this->maxNumSimultaniousTriggerers_ = triggerers; }
110            inline int getSimultaniousTriggerers(void)
111                { return this->maxNumSimultaniousTriggerers_; }
112
113            inline void setDelay(float delay)
114                { this->delay_= delay; }
115            inline float getDelay() const
116                { return this->delay_; }
117           
118        protected:
119            void fire(bool status, BaseObject* originator = NULL);
120           
121            bool isModeTriggered(BaseObject* triggerer = NULL);
122            bool isTriggered(BaseObject* triggerer = NULL);
123           
124            virtual std::queue<MultiTriggerState*>* letTrigger(void);
125           
126            inline ClassTreeMask& getTargetMask(void)
127                { return this->targetMask_; }
128            virtual void notifyMaskUpdate(void) {}
129           
130        private:
131            static const int INF_s;
132            static const std::string or_s;
133            static const std::string and_s;
134            static const std::string xor_s;
135           
136            bool addState(bool bTriggered, BaseObject* originator = NULL);
137           
138            bool checkAnd(BaseObject* triggerer);
139            bool checkOr(BaseObject* triggerer);
140            bool checkXor(BaseObject* triggerer);
141
142            bool bFirstTick_;
143
144            MultiTriggerMode::Value mode_;
145            bool bInvertMode_;
146            bool bSwitch_;
147            bool bStayActive_;
148            float delay_;
149            int remainingActivations_;
150            int maxNumSimultaniousTriggerers_;
151           
152            std::set<BaseObject*> active_;
153            std::set<BaseObject*> triggered_;
154
155            std::set<MultiTrigger*> children_;
156            std::deque<std::pair<float, MultiTriggerState*> > stateQueue_;
157           
158            ClassTreeMask targetMask_;
159           
160    };
161
162}
163
164#endif // _MultiTrigger_H__
Note: See TracBrowser for help on using the repository browser.