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