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