- Timestamp:
- Nov 6, 2008, 12:02:05 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/questsystem2/src/orxonox/objects/quest/Quest.cc
r2105 r2146 26 26 * 27 27 */ 28 29 /** 30 @file Quest.cc 31 @brief 32 Implementation of the Quest class. 33 */ 28 34 29 35 #include "OrxonoxStableHeaders.h" … … 32 38 #include "core/CoreIncludes.h" 33 39 40 #include "orxonox/objects/worldentities/ControllableEntity.h" 34 41 #include "QuestManager.h" 35 42 #include "QuestDescription.h" … … 39 46 namespace orxonox { 40 47 48 /** 49 @brief 50 Constructor. Initializes object. 51 */ 41 52 Quest::Quest(BaseObject* creator) : QuestItem(creator) 42 53 { 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 { 43 64 RegisterObject(Quest); 44 65 45 this-> initialize();66 this->parentQuest_ = NULL; 46 67 } 47 68 … … 55 76 } 56 77 78 /** 79 @brief 80 Method for creating a Quest object through XML. 81 */ 57 82 void Quest::XMLPort(Element& xmlelement, XMLPort::Mode mode) 58 83 { 59 84 SUPER(Quest, XMLPort, xmlelement, mode); 60 85 61 XMLPortObject(Quest, Quest, " ", addSubQuest, getSubQuests, xmlelement, mode);62 XMLPortObject(Quest, QuestHint, " ", addHint, getHints, xmlelement, mode);86 XMLPortObject(Quest, Quest, "subquests", addSubQuest, getSubQuests, xmlelement, mode); 87 XMLPortObject(Quest, QuestHint, "hints", addHint, getHints, xmlelement, mode); 63 88 XMLPortObject(Quest, QuestEffect, "fail-effects", addFailEffect, getFailEffects, xmlelement, mode); 64 89 XMLPortObject(Quest, QuestEffect, "complete-effects", addCompleteEffect, getCompleteEffects, xmlelement, mode); 65 90 66 91 QuestManager::registerQuest(this); //Registers the quest with the QuestManager. 67 }68 69 /**70 @brief71 Initializes the object. Needs to be called first in every constructor of this class.72 */73 void Quest::initialize(void)74 {75 RegisterObject(Quest);76 77 this->parentQuest_ = NULL;78 92 } 79 93 … … 88 102 bool Quest::setParentQuest(Quest* quest) 89 103 { 90 if(quest == NULL) 104 if(quest == NULL) //!< We don't want to set NULL-Pointers. 91 105 { 92 106 COUT(2) << "The parentquest to be added to quest {" << this->getId() << "} was NULL." << std::endl; … … 110 124 bool Quest::addSubQuest(Quest* quest) 111 125 { 112 if(quest == NULL) 126 if(quest == NULL) //!< We don't want to set NULL-Pointers. 113 127 { 114 128 COUT(2) << "The subquest to be added to quest {" << this->getId() << "} was NULL." << std::endl; … … 116 130 } 117 131 118 quest->setParentQuest(this); 119 this->subQuests_.push_back(quest); 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. 120 134 121 135 COUT(3) << "Sub Quest {" << quest->getId() << "} was added to Quest {" << this->getId() << "}." << std::endl; … … 134 148 bool Quest::addHint(QuestHint* hint) 135 149 { 136 if(hint == NULL) 150 if(hint == NULL) //!< We don't want to set NULL-Pointers. Seriously! 137 151 { 138 152 COUT(2) << "A NULL-QuestHint was trying to be added." << std::endl; … … 140 154 } 141 155 142 this->hints_.push_back(hint);143 hint->setQuest(this);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. 144 158 145 159 COUT(3) << "QuestHint {" << hint->getId() << "} was added to Quest {" << this->getId() << "}." << std::endl; … … 149 163 /** 150 164 @brief 151 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. 152 170 */ 153 171 bool Quest::addFailEffect(QuestEffect* effect) 154 172 { 155 if(effect == NULL) 173 if(effect == NULL) //!< We don't want to set NULL-Pointers. 156 174 { 157 175 COUT(2) << "A NULL-QuestEffect was trying to be added" << std::endl; … … 159 177 } 160 178 161 this->failEffects_.push_back(effect); 179 this->failEffects_.push_back(effect); //!< Adds the effect to the end of the list of failEffects. 162 180 163 181 COUT(3) << "A FailEffect was added to Quest {" << this->getId() << "}." << std::endl; … … 167 185 /** 168 186 @brief 169 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. 170 192 */ 171 193 bool Quest::addCompleteEffect(QuestEffect* effect) 172 194 { 173 if(effect == NULL) 195 if(effect == NULL) //!< We don't want to set NULL-Pointers. 174 196 { 175 197 COUT(2) << "A NULL-QuestEffect was trying to be added" << std::endl; … … 177 199 } 178 200 179 this->completeEffects_.push_back(effect); 201 this->completeEffects_.push_back(effect); //!< Adds the effect to the end of the list of completeEffects. 180 202 181 203 COUT(3) << "A CompleteEffect was added to Quest {" << this->getId() << "}." << std::endl; … … 185 207 /** 186 208 @brief 187 209 Returns the parent quest of the quest. 210 @return 211 Returns the parent quest of the quest. 188 212 */ 189 213 const Quest* Quest::getParentQuest(void) … … 194 218 /** 195 219 @brief 196 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. 197 225 */ 198 226 const Quest* Quest::getSubQuests(unsigned int index) const 199 227 { 200 228 int i = index; 229 230 //! Iterate through all subquests. 201 231 for (std::list<Quest*>::const_iterator subQuest = this->subQuests_.begin(); subQuest != this->subQuests_.end(); ++subQuest) 202 232 { 203 if(i == 0) 233 if(i == 0) //!< We're counting down... 204 234 { 205 235 return *subQuest; … … 207 237 i--; 208 238 } 209 return NULL; 210 } 211 212 /** 213 @brief 214 239 240 return NULL; //!< If the index is greater than the number of elements in the list. 241 } 242 243 /** 244 @brief 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. 215 250 */ 216 251 const QuestHint* Quest::getHints(unsigned int index) const 217 252 { 218 253 int i = index; 254 255 //! Iterate through all hints. 219 256 for (std::list<QuestHint*>::const_iterator hint = this->hints_.begin(); hint != this->hints_.end(); ++hint) 220 257 { 221 if(i == 0) 258 if(i == 0) //!< We're counting down... 222 259 { 223 260 return *hint; … … 225 262 i--; 226 263 } 227 return NULL; 228 } 229 230 /** 231 @brief 232 264 return NULL; //!< If the index is greater than the number of elements in the list. 265 } 266 267 /** 268 @brief 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. 233 274 */ 234 275 const QuestEffect* Quest::getFailEffects(unsigned int index) const 235 276 { 236 277 int i = index; 278 279 //! Iterate through all failEffects. 237 280 for (std::list<QuestEffect*>::const_iterator effect = this->failEffects_.begin(); effect != this->failEffects_.end(); ++effect) 238 281 { 239 if(i == 0) 282 if(i == 0) //!< We're counting down... 240 283 { 241 284 return *effect; … … 243 286 i--; 244 287 } 245 return NULL; 246 } 247 248 /** 249 @brief 250 288 return NULL; //!< If the index is greater than the number of elements in the list. 289 } 290 291 /** 292 @brief 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. 251 298 */ 252 299 const QuestEffect* Quest::getCompleteEffects(unsigned int index) const 253 300 { 254 301 int i = index; 302 303 //! Iterate through all completeEffects. 255 304 for (std::list<QuestEffect*>::const_iterator effect = this->completeEffects_.begin(); effect != this->completeEffects_.end(); ++effect) 256 305 { 257 if(i == 0) 306 if(i == 0) //!< We're counting down... 258 307 { 259 308 return *effect; … … 261 310 i--; 262 311 } 263 return NULL; 312 return NULL; //!< If the index is greater than the number of elements in the list. 264 313 } 265 314 … … 274 323 Throws an exception if getStatus throws one. 275 324 */ 276 bool Quest::isInactive(const Player* player) const325 bool Quest::isInactive(const ControllableEntity* player) const 277 326 { 278 327 return this->getStatus(player) == questStatus::inactive; … … 289 338 Throws an exception if getStatus throws one. 290 339 */ 291 bool Quest::isActive(const Player* player) const340 bool Quest::isActive(const ControllableEntity* player) const 292 341 { 293 342 … … 305 354 Throws an exception if getStatus throws one. 306 355 */ 307 bool Quest::isFailed(const Player* player) const356 bool Quest::isFailed(const ControllableEntity* player) const 308 357 { 309 358 return this->getStatus(player) == questStatus::failed; … … 320 369 Throws an exception if getStatus throws one. 321 370 */ 322 bool Quest::isCompleted(const Player* player) const371 bool Quest::isCompleted(const ControllableEntity* player) const 323 372 { 324 373 return this->getStatus(player) == questStatus::completed; … … 327 376 /** 328 377 @brief 329 Starts the quest .378 Starts the quest for an input player. 330 379 @param player 331 380 The player. … … 333 382 Returns true if the quest could be started, false if not. 334 383 */ 335 bool Quest::start( Player* player)336 { 337 if(this->isStartable(player)) 384 bool Quest::start(ControllableEntity* player) 385 { 386 if(this->isStartable(player)) //!< Checks whether the quest can be started. 338 387 { 339 388 this->setStatus(player, questStatus::active); 340 389 return true; 341 390 } 391 342 392 COUT(2) << "A non-startable quest was trying to be started." << std::endl; 343 393 return false; 344 394 } 345 395 346 /**347 @brief348 Fails the quest.349 @param player350 The player.351 @return352 Returns true if the quest could be failed, false if not.353 */354 bool Quest::fail(Player* player)355 {356 if(this->isFailable(player))357 {358 this->setStatus(player, questStatus::failed);359 QuestEffect::invokeEffects(player, this->failEffects_);360 return true;361 }362 COUT(2) << "A non-failable quest was trying to be failed." << std::endl;363 return false;364 }365 366 /**367 @brief368 Completes the quest.369 @param player370 The player.371 @return372 Returns true if the quest could be completed, false if not.373 */374 bool Quest::complete(Player* player)375 {376 if(this->isCompletable(player))377 {378 this->setStatus(player, questStatus::completed);379 QuestEffect::invokeEffects(player, this->completeEffects_);380 return true;381 }382 COUT(2) << "A non-completable quest was trying to be completed." << std::endl;383 return false;384 }385 386 396 }
Note: See TracChangeset
for help on using the changeset viewer.