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 | |
---|
29 | /** |
---|
30 | @file EventMultiTrigger.cc |
---|
31 | @brief Implementation of the EventMultiTrigger class. |
---|
32 | */ |
---|
33 | |
---|
34 | #include "EventMultiTrigger.h" |
---|
35 | |
---|
36 | #include "core/CoreIncludes.h" |
---|
37 | #include "core/EventIncludes.h" |
---|
38 | #include "core/XMLPort.h" |
---|
39 | #include "MultiTriggerContainer.h" |
---|
40 | |
---|
41 | namespace orxonox |
---|
42 | { |
---|
43 | |
---|
44 | CreateFactory(EventMultiTrigger); |
---|
45 | |
---|
46 | /** |
---|
47 | @brief |
---|
48 | Constructor. Registers the object. |
---|
49 | */ |
---|
50 | EventMultiTrigger::EventMultiTrigger(BaseObject* creator) : MultiTrigger(creator) |
---|
51 | { |
---|
52 | RegisterObject(EventMultiTrigger); |
---|
53 | } |
---|
54 | |
---|
55 | /** |
---|
56 | @brief |
---|
57 | Destructor. |
---|
58 | */ |
---|
59 | EventMultiTrigger::~EventMultiTrigger() |
---|
60 | { |
---|
61 | |
---|
62 | } |
---|
63 | |
---|
64 | /** |
---|
65 | @brief |
---|
66 | Method for creating an EventMultiTrigger object through XML. |
---|
67 | */ |
---|
68 | void EventMultiTrigger::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
69 | { |
---|
70 | SUPER(EventMultiTrigger, XMLPort, xmlelement, mode); |
---|
71 | |
---|
72 | this->setBroadcast(true); |
---|
73 | } |
---|
74 | |
---|
75 | /** |
---|
76 | @brief |
---|
77 | Creates an event port. |
---|
78 | */ |
---|
79 | void EventMultiTrigger::XMLEventPort(Element& xmlelement, XMLPort::Mode mode) |
---|
80 | { |
---|
81 | SUPER(EventMultiTrigger, XMLEventPort, xmlelement, mode); |
---|
82 | |
---|
83 | XMLPortEventState(EventMultiTrigger, BaseObject, "trigger", trigger, xmlelement, mode); |
---|
84 | } |
---|
85 | |
---|
86 | /** |
---|
87 | @brief |
---|
88 | Method that causes the EventMultiTrigger to trigger upon receiving an event. |
---|
89 | @param bTriggered |
---|
90 | Whether the event is a triggering or an un-triggering event. |
---|
91 | @param originator |
---|
92 | A pointer to the entity the event originates from. |
---|
93 | */ |
---|
94 | void EventMultiTrigger::trigger(bool bTriggered, BaseObject* originator) |
---|
95 | { |
---|
96 | // If the originator is a MultiTriggerContainer, the event originates from a MultiTrigger and thus the event only triggers the EventMultiTrigger for the originator that caused the MultiTrigger to trigger. |
---|
97 | if(originator != NULL && originator->isA(ClassIdentifier<MultiTriggerContainer>::getIdentifier())) |
---|
98 | { |
---|
99 | MultiTriggerContainer* container = static_cast<MultiTriggerContainer*>(originator); |
---|
100 | // If the entity that triggered the MultiTrigger is no target of this EventMultiTrigger we process it as it weren't an event caused by a MultiTrigger. |
---|
101 | // But if it is the EventMultiTrigger only triggers for the entity tha caused the MultiTrigger to trigger. |
---|
102 | if(this->isTarget(container->getData())) |
---|
103 | { |
---|
104 | if(this->isTriggered(container->getData()) ^ bTriggered) |
---|
105 | this->changeTriggered(container->getData()); |
---|
106 | |
---|
107 | return; |
---|
108 | } |
---|
109 | } |
---|
110 | |
---|
111 | // If we don't know who exactly caused the event we just send a broadcast. |
---|
112 | if(this->isTriggered() ^ bTriggered) |
---|
113 | this->changeTriggered(); |
---|
114 | } |
---|
115 | |
---|
116 | } |
---|
117 | |
---|