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 Quest.cc |
---|
31 | @brief |
---|
32 | Implementation of the Quest class. |
---|
33 | */ |
---|
34 | |
---|
35 | #include "OrxonoxStableHeaders.h" |
---|
36 | #include "Quest.h" |
---|
37 | |
---|
38 | #include "core/CoreIncludes.h" |
---|
39 | |
---|
40 | #include "orxonox/objects/infos/PlayerInfo.h" |
---|
41 | #include "QuestManager.h" |
---|
42 | #include "QuestDescription.h" |
---|
43 | #include "QuestHint.h" |
---|
44 | #include "QuestEffect.h" |
---|
45 | |
---|
46 | namespace orxonox { |
---|
47 | |
---|
48 | /** |
---|
49 | @brief |
---|
50 | Constructor. Registers and initializes object. |
---|
51 | */ |
---|
52 | Quest::Quest(BaseObject* creator) : QuestItem(creator) |
---|
53 | { |
---|
54 | RegisterObject(Quest); |
---|
55 | |
---|
56 | this->parentQuest_ = NULL; |
---|
57 | } |
---|
58 | |
---|
59 | /** |
---|
60 | @brief |
---|
61 | Destructor. |
---|
62 | */ |
---|
63 | Quest::~Quest() |
---|
64 | { |
---|
65 | |
---|
66 | } |
---|
67 | |
---|
68 | /** |
---|
69 | @brief |
---|
70 | Method for creating a Quest object through XML. |
---|
71 | */ |
---|
72 | void Quest::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
73 | { |
---|
74 | SUPER(Quest, XMLPort, xmlelement, mode); |
---|
75 | |
---|
76 | XMLPortObject(Quest, Quest, "subquests", addSubQuest, getSubQuest, xmlelement, mode); |
---|
77 | XMLPortObject(Quest, QuestHint, "hints", addHint, getHint, xmlelement, mode); |
---|
78 | XMLPortObject(Quest, QuestEffect, "fail-effects", addFailEffect, getFailEffect, xmlelement, mode); |
---|
79 | XMLPortObject(Quest, QuestEffect, "complete-effects", addCompleteEffect, getCompleteEffect, xmlelement, mode); |
---|
80 | |
---|
81 | QuestManager::registerQuest(this); //!<Registers the Quest with the QuestManager. |
---|
82 | } |
---|
83 | |
---|
84 | /** |
---|
85 | @brief |
---|
86 | Sets the parentquest of the Quest. |
---|
87 | @param quest |
---|
88 | A pointer to the Quest to be set as parentquest. |
---|
89 | @return |
---|
90 | Returns true if the parentquest could be set. |
---|
91 | */ |
---|
92 | bool Quest::setParentQuest(Quest* quest) |
---|
93 | { |
---|
94 | if(quest == NULL) //!< We don't want to set NULL-Pointers. |
---|
95 | { |
---|
96 | COUT(2) << "The parentquest to be added to quest {" << this->getId() << "} was NULL." << std::endl; |
---|
97 | return false; |
---|
98 | } |
---|
99 | |
---|
100 | this->parentQuest_ = quest; |
---|
101 | |
---|
102 | COUT(3) << "Parent Quest {" << quest->getId() << "} was added to Quest {" << this->getId() << "}." << std::endl; |
---|
103 | return true; |
---|
104 | } |
---|
105 | |
---|
106 | /** |
---|
107 | @brief |
---|
108 | Adds a subquest to the Quest. |
---|
109 | @param quest |
---|
110 | A pointer to the Quest to be set as subquest. |
---|
111 | @return |
---|
112 | Returns true if the subquest could be set. |
---|
113 | */ |
---|
114 | bool Quest::addSubQuest(Quest* quest) |
---|
115 | { |
---|
116 | if(quest == NULL) //!< We don't want to set NULL-Pointers. |
---|
117 | { |
---|
118 | COUT(2) << "The subquest to be added to quest {" << this->getId() << "} was NULL." << std::endl; |
---|
119 | return false; |
---|
120 | } |
---|
121 | |
---|
122 | quest->setParentQuest(this); //!< Sets the currentQuest (this) as parentquest for the added subquest. |
---|
123 | this->subQuests_.push_back(quest); //!< Adds the Quest to the end of the list of subquests. |
---|
124 | |
---|
125 | COUT(3) << "Sub Quest {" << quest->getId() << "} was added to Quest {" << this->getId() << "}." << std::endl; |
---|
126 | return true; |
---|
127 | } |
---|
128 | |
---|
129 | |
---|
130 | /** |
---|
131 | @brief |
---|
132 | Adds a QuestHint to the list of QuestHints |
---|
133 | @param hint |
---|
134 | The QuestHint that should be added to the list of QuestHints. |
---|
135 | @return |
---|
136 | Returns true if the hint was successfully added. |
---|
137 | */ |
---|
138 | bool Quest::addHint(QuestHint* hint) |
---|
139 | { |
---|
140 | if(hint == NULL) //!< We don't want to set NULL-Pointers. Seriously! |
---|
141 | { |
---|
142 | COUT(2) << "A NULL-QuestHint was trying to be added." << std::endl; |
---|
143 | return false; |
---|
144 | } |
---|
145 | |
---|
146 | hint->setQuest(this); //!< Sets the current Quest (this) as Quest for the added QuestHint. |
---|
147 | this->hints_.push_back(hint); //!< Adds the QuestHint to the end of the list of QuestHints. |
---|
148 | |
---|
149 | COUT(3) << "QuestHint {" << hint->getId() << "} was added to Quest {" << this->getId() << "}." << std::endl; |
---|
150 | return true; |
---|
151 | } |
---|
152 | |
---|
153 | /** |
---|
154 | @brief |
---|
155 | Adds an QuestEffect to the list of fail QuestEffects. |
---|
156 | @param effect |
---|
157 | The QuestEffect to be added. |
---|
158 | @return |
---|
159 | Returns true if successful. |
---|
160 | */ |
---|
161 | bool Quest::addFailEffect(QuestEffect* effect) |
---|
162 | { |
---|
163 | if(effect == NULL) //!< We don't want to set NULL-Pointers. |
---|
164 | { |
---|
165 | COUT(2) << "A NULL-QuestEffect was trying to be added" << std::endl; |
---|
166 | return false; |
---|
167 | } |
---|
168 | |
---|
169 | this->failEffects_.push_back(effect); //!< Adds the QuestEffect to the end of the list of fail QuestEffects. |
---|
170 | |
---|
171 | COUT(3) << "A FailEffect was added to Quest {" << this->getId() << "}." << std::endl; |
---|
172 | return true; |
---|
173 | } |
---|
174 | |
---|
175 | /** |
---|
176 | @brief |
---|
177 | Adds an QuestEffect to the list of complete QuestEffects. |
---|
178 | @param effect |
---|
179 | The QuestEffect to be added. |
---|
180 | @return |
---|
181 | Returns true if successful. |
---|
182 | */ |
---|
183 | bool Quest::addCompleteEffect(QuestEffect* effect) |
---|
184 | { |
---|
185 | if(effect == NULL) //!< We don't want to set NULL-Pointers. |
---|
186 | { |
---|
187 | COUT(2) << "A NULL-QuestEffect was trying to be added" << std::endl; |
---|
188 | return false; |
---|
189 | } |
---|
190 | |
---|
191 | this->completeEffects_.push_back(effect); //!< Adds the QuestEffect to the end of the list of complete QuestEffects. |
---|
192 | |
---|
193 | COUT(3) << "A CompleteEffect was added to Quest {" << this->getId() << "}." << std::endl; |
---|
194 | return true; |
---|
195 | } |
---|
196 | |
---|
197 | /** |
---|
198 | @brief |
---|
199 | Returns the parentquest of the Quest. |
---|
200 | @return |
---|
201 | Returns a pointer to the parentquest of the Quest. |
---|
202 | */ |
---|
203 | const Quest* Quest::getParentQuest(void) |
---|
204 | { |
---|
205 | return this->parentQuest_; |
---|
206 | } |
---|
207 | |
---|
208 | /** |
---|
209 | @brief |
---|
210 | Returns the subquest at the given index. |
---|
211 | @param |
---|
212 | The index. |
---|
213 | @return |
---|
214 | Returns a pointer to the subquest at the given index. NULL if there is no element at the given index. |
---|
215 | */ |
---|
216 | const Quest* Quest::getSubQuest(unsigned int index) const |
---|
217 | { |
---|
218 | int i = index; |
---|
219 | |
---|
220 | //! Iterate through all subquests. |
---|
221 | for (std::list<Quest*>::const_iterator subQuest = this->subQuests_.begin(); subQuest != this->subQuests_.end(); ++subQuest) |
---|
222 | { |
---|
223 | if(i == 0) //!< We're counting down... |
---|
224 | { |
---|
225 | return *subQuest; |
---|
226 | } |
---|
227 | i--; |
---|
228 | } |
---|
229 | |
---|
230 | return NULL; //!< If the index is greater than the number of elements in the list. |
---|
231 | } |
---|
232 | |
---|
233 | /** |
---|
234 | @brief |
---|
235 | Returns the QuestHint at the given index. |
---|
236 | @param |
---|
237 | The index. |
---|
238 | @return |
---|
239 | Returns a pointer to the QuestHint at the given index. NULL if there is no element at the given index. |
---|
240 | */ |
---|
241 | const QuestHint* Quest::getHint(unsigned int index) const |
---|
242 | { |
---|
243 | int i = index; |
---|
244 | |
---|
245 | //! Iterate through all QuestHints. |
---|
246 | for (std::list<QuestHint*>::const_iterator hint = this->hints_.begin(); hint != this->hints_.end(); ++hint) |
---|
247 | { |
---|
248 | if(i == 0) //!< We're counting down... |
---|
249 | { |
---|
250 | return *hint; |
---|
251 | } |
---|
252 | i--; |
---|
253 | } |
---|
254 | return NULL; //!< If the index is greater than the number of elements in the list. |
---|
255 | } |
---|
256 | |
---|
257 | /** |
---|
258 | @brief |
---|
259 | Returns the fail QuestEffect at the given index. |
---|
260 | @param |
---|
261 | The index. |
---|
262 | @return |
---|
263 | Returns a pointer to the fail QuestEffect at the given index. NULL if there is no element at the given index. |
---|
264 | */ |
---|
265 | const QuestEffect* Quest::getFailEffect(unsigned int index) const |
---|
266 | { |
---|
267 | int i = index; |
---|
268 | |
---|
269 | //! Iterate through all fail QuestEffects. |
---|
270 | for (std::list<QuestEffect*>::const_iterator effect = this->failEffects_.begin(); effect != this->failEffects_.end(); ++effect) |
---|
271 | { |
---|
272 | if(i == 0) //!< We're counting down... |
---|
273 | { |
---|
274 | return *effect; |
---|
275 | } |
---|
276 | i--; |
---|
277 | } |
---|
278 | return NULL; //!< If the index is greater than the number of elements in the list. |
---|
279 | } |
---|
280 | |
---|
281 | /** |
---|
282 | @brief |
---|
283 | Returns the complete QuestEffect at the given index. |
---|
284 | @param |
---|
285 | The index. |
---|
286 | @return |
---|
287 | Returns a pointer to the complete QuestEffect at the given index. NULL if there is no element at the given index. |
---|
288 | */ |
---|
289 | const QuestEffect* Quest::getCompleteEffect(unsigned int index) const |
---|
290 | { |
---|
291 | int i = index; |
---|
292 | |
---|
293 | //! Iterate through all complete QuestEffects. |
---|
294 | for (std::list<QuestEffect*>::const_iterator effect = this->completeEffects_.begin(); effect != this->completeEffects_.end(); ++effect) |
---|
295 | { |
---|
296 | if(i == 0) //!< We're counting down... |
---|
297 | { |
---|
298 | return *effect; |
---|
299 | } |
---|
300 | i--; |
---|
301 | } |
---|
302 | return NULL; //!< If the index is greater than the number of elements in the list. |
---|
303 | } |
---|
304 | |
---|
305 | /** |
---|
306 | @brief |
---|
307 | Returns true if the quest status for the specific player is 'inactive'. |
---|
308 | @param player |
---|
309 | The player. |
---|
310 | @return |
---|
311 | Returns true if the quest status for the specific player is 'inactive'. |
---|
312 | @throws |
---|
313 | Throws an exception if getStatus throws one. |
---|
314 | */ |
---|
315 | bool Quest::isInactive(const PlayerInfo* player) const |
---|
316 | { |
---|
317 | return this->getStatus(player) == questStatus::inactive; |
---|
318 | } |
---|
319 | |
---|
320 | /** |
---|
321 | @brief |
---|
322 | Returns true if the quest status for the specific player is 'active'. |
---|
323 | @param player |
---|
324 | The player. |
---|
325 | @return |
---|
326 | Returns true if the quest status for the specific player is 'active'. |
---|
327 | @throws |
---|
328 | Throws an exception if getStatus throws one. |
---|
329 | */ |
---|
330 | bool Quest::isActive(const PlayerInfo* player) const |
---|
331 | { |
---|
332 | |
---|
333 | return this->getStatus(player) == questStatus::active; |
---|
334 | } |
---|
335 | |
---|
336 | /** |
---|
337 | @brief |
---|
338 | Returns true if the quest status for the specific player is 'failed'. |
---|
339 | @param player |
---|
340 | The player. |
---|
341 | @return |
---|
342 | Returns true if the quest status for the specific player is 'failed'. |
---|
343 | @throws |
---|
344 | Throws an exception if getStatus throws one. |
---|
345 | */ |
---|
346 | bool Quest::isFailed(const PlayerInfo* player) const |
---|
347 | { |
---|
348 | return this->getStatus(player) == questStatus::failed; |
---|
349 | } |
---|
350 | |
---|
351 | /** |
---|
352 | @brief |
---|
353 | Returns true if the quest status for the specific player is 'completed'. |
---|
354 | @param player |
---|
355 | The player. |
---|
356 | @return |
---|
357 | Returns true if the quest status for the specific player is 'completed'. |
---|
358 | @throws |
---|
359 | Throws an exception if getStatus throws one. |
---|
360 | */ |
---|
361 | bool Quest::isCompleted(const PlayerInfo* player) const |
---|
362 | { |
---|
363 | return this->getStatus(player) == questStatus::completed; |
---|
364 | } |
---|
365 | |
---|
366 | /** |
---|
367 | @brief |
---|
368 | Starts the Quest for an input player. |
---|
369 | @param player |
---|
370 | The player. |
---|
371 | @return |
---|
372 | Returns true if the Quest could be started, false if not. |
---|
373 | */ |
---|
374 | bool Quest::start(PlayerInfo* player) |
---|
375 | { |
---|
376 | if(this->isStartable(player)) //!< Checks whether the quest can be started. |
---|
377 | { |
---|
378 | this->setStatus(player, questStatus::active); |
---|
379 | return true; |
---|
380 | } |
---|
381 | |
---|
382 | COUT(2) << "A non-startable quest was trying to be started." << std::endl; |
---|
383 | return false; |
---|
384 | } |
---|
385 | |
---|
386 | } |
---|