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 | #include "OrxonoxStableHeaders.h" |
---|
30 | #include "QuestEffectBeacon.h" |
---|
31 | |
---|
32 | #include "core/CoreIncludes.h" |
---|
33 | #include "core/XMLPort.h" |
---|
34 | #include "core/Event.h" |
---|
35 | #include "core/EventIncludes.h" |
---|
36 | |
---|
37 | #include "orxonox/objects/worldentities/ControllableEntity.h" |
---|
38 | #include "orxonox/objects/worldentities/triggers/PlayerTrigger.h" |
---|
39 | #include "QuestEffect.h" |
---|
40 | |
---|
41 | namespace orxonox { |
---|
42 | |
---|
43 | CreateFactory(QuestEffectBeacon); |
---|
44 | |
---|
45 | QuestEffectBeacon::QuestEffectBeacon(BaseObject* creator) : PositionableEntity(creator) |
---|
46 | { |
---|
47 | RegisterObject(QuestEffectBeacon); |
---|
48 | |
---|
49 | this->status_ = QuestEffectBeaconStatus::active; |
---|
50 | this->times_ = -1; |
---|
51 | this->trigger_ = NULL; |
---|
52 | this->player_ = NULL; |
---|
53 | } |
---|
54 | |
---|
55 | QuestEffectBeacon::~QuestEffectBeacon() |
---|
56 | { |
---|
57 | } |
---|
58 | |
---|
59 | void QuestEffectBeacon::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
60 | { |
---|
61 | SUPER(QuestEffectBeacon, XMLPort, xmlelement, mode); |
---|
62 | |
---|
63 | XMLPortParam(QuestEffectBeacon, "times", setTimes, getTimes, xmlelement, mode); |
---|
64 | XMLPortObject(QuestEffectBeacon, QuestEffect, "", addEffect, getEffect, xmlelement, mode); |
---|
65 | XMLPortObject(QuestEffectBeacon, Trigger, "", addTrigger, getTrigger, xmlelement, mode); |
---|
66 | } |
---|
67 | |
---|
68 | void QuestEffectBeacon::processEvent(Event& event) |
---|
69 | { |
---|
70 | SetSubclassEvent(QuestEffectBeacon, "execute", execute, event, PlayerTrigger); |
---|
71 | |
---|
72 | this->player_ = dynamic_cast<ControllableEntity*>(event.originator_); |
---|
73 | } |
---|
74 | |
---|
75 | bool QuestEffectBeacon::execute(void) |
---|
76 | { |
---|
77 | |
---|
78 | if(!(this->isActive())) |
---|
79 | { |
---|
80 | return false; |
---|
81 | } |
---|
82 | if(this->player_ == NULL) |
---|
83 | { |
---|
84 | return false; |
---|
85 | } |
---|
86 | |
---|
87 | bool check = QuestEffect::invokeEffects(this->player_, this->effects_); |
---|
88 | if(check) |
---|
89 | { |
---|
90 | this->decrementTimes(); |
---|
91 | return true; |
---|
92 | } |
---|
93 | |
---|
94 | return false; |
---|
95 | } |
---|
96 | |
---|
97 | bool QuestEffectBeacon::isActive(void) |
---|
98 | { |
---|
99 | return this->status_ == QuestEffectBeaconStatus::active; |
---|
100 | } |
---|
101 | |
---|
102 | bool QuestEffectBeacon::decrementTimes(void) |
---|
103 | { |
---|
104 | if(!(this->isActive())) |
---|
105 | { |
---|
106 | return false; |
---|
107 | } |
---|
108 | if(this->getTimes() == -1) |
---|
109 | { |
---|
110 | return true; |
---|
111 | } |
---|
112 | |
---|
113 | this->times_ = this->times_ - 1; |
---|
114 | if(this->getTimes() == 0) |
---|
115 | { |
---|
116 | this->status_ = QuestEffectBeaconStatus::inactive; |
---|
117 | } |
---|
118 | |
---|
119 | return true; |
---|
120 | } |
---|
121 | |
---|
122 | |
---|
123 | bool QuestEffectBeacon::setTimes(const int & n) |
---|
124 | { |
---|
125 | if(n < -1) |
---|
126 | { |
---|
127 | return false; |
---|
128 | } |
---|
129 | |
---|
130 | this->times_ = n; |
---|
131 | return true; |
---|
132 | } |
---|
133 | |
---|
134 | |
---|
135 | /** |
---|
136 | @brief |
---|
137 | |
---|
138 | */ |
---|
139 | bool QuestEffectBeacon::addEffect(QuestEffect* effect) |
---|
140 | { |
---|
141 | if(effect == NULL) |
---|
142 | { |
---|
143 | COUT(2) << "A NULL-QuestEffect was trying to be added" << std::endl; |
---|
144 | return false; |
---|
145 | } |
---|
146 | |
---|
147 | this->effects_.push_back(effect); |
---|
148 | |
---|
149 | COUT(3) << "A QuestEffect was added to a QuestEffectBeacon." << std::endl; |
---|
150 | return true; |
---|
151 | } |
---|
152 | |
---|
153 | bool QuestEffectBeacon::addTrigger(PlayerTrigger* trigger) |
---|
154 | { |
---|
155 | if(this->trigger_ != NULL) |
---|
156 | { |
---|
157 | COUT(2) << "A Trigger was trying to be added, where one was already set." << std::endl; |
---|
158 | return false; |
---|
159 | } |
---|
160 | if(trigger == NULL) |
---|
161 | { |
---|
162 | COUT(2) << "A NULL-Trigger was trying to be added." << std::endl; |
---|
163 | return false; |
---|
164 | } |
---|
165 | |
---|
166 | COUT(3) << "A Trigger was added to a QuestEffectBeacon." << std::endl; |
---|
167 | this->trigger_ = trigger; |
---|
168 | return true; |
---|
169 | } |
---|
170 | |
---|
171 | /** |
---|
172 | @brief |
---|
173 | |
---|
174 | */ |
---|
175 | const QuestEffect* QuestEffectBeacon::getEffect(unsigned int index) const |
---|
176 | { |
---|
177 | int i = index; |
---|
178 | for (std::list<QuestEffect*>::const_iterator effect = this->effects_.begin(); effect != this->effects_.end(); ++effect) |
---|
179 | { |
---|
180 | if(i == 0) |
---|
181 | { |
---|
182 | return *effect; |
---|
183 | } |
---|
184 | i--; |
---|
185 | } |
---|
186 | return NULL; |
---|
187 | } |
---|
188 | |
---|
189 | const Trigger* QuestEffectBeacon::getTrigger(unsigned int index) const |
---|
190 | { |
---|
191 | if(index == 0) |
---|
192 | { |
---|
193 | return this->trigger_; |
---|
194 | } |
---|
195 | |
---|
196 | return NULL; |
---|
197 | } |
---|
198 | |
---|
199 | } |
---|