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