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