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