Changeset 2530 for code/branches/bugger/src/orxonox/objects/quest/Quest.cc
- Timestamp:
- Dec 23, 2008, 10:40:38 PM (16 years ago)
- Location:
- code/branches/bugger
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/bugger
- Property svn:mergeinfo changed
/code/branches/questsystem2 (added) merged: 2109,2146,2159,2191,2193-2196,2205-2206,2208-2209,2221,2226,2228,2251,2258
- Property svn:mergeinfo changed
-
code/branches/bugger/src/orxonox/objects/quest/Quest.cc
- Property svn:mergeinfo changed
/code/branches/questsystem2/src/orxonox/objects/quest/Quest.cc (added) merged: 2146,2159,2191,2205,2226,2251 /code/trunk/src/orxonox/objects/quest/Quest.cc merged: 1925-2089
r2105 r2530 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/infos/PlayerInfo.h" 34 41 #include "QuestManager.h" 35 42 #include "QuestDescription.h" … … 39 46 namespace orxonox { 40 47 48 /** 49 @brief 50 Constructor. Registers and initializes object. 51 */ 41 52 Quest::Quest(BaseObject* creator) : QuestItem(creator) 42 53 { 43 54 RegisterObject(Quest); 44 55 45 this-> initialize();56 this->parentQuest_ = NULL; 46 57 } 47 58 … … 55 66 } 56 67 68 /** 69 @brief 70 Method for creating a Quest object through XML. 71 */ 57 72 void Quest::XMLPort(Element& xmlelement, XMLPort::Mode mode) 58 73 { 59 74 SUPER(Quest, XMLPort, xmlelement, mode); 60 75 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); 65 66 QuestManager::registerQuest(this); //Registers the quest with the QuestManager. 67 } 68 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); 76 77 this->parentQuest_ = NULL; 78 } 79 80 /** 81 @brief 82 Sets the parent quest of the quest. 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); 80 81 QuestManager::registerQuest(this); //!<Registers the Quest with the QuestManager. 82 } 83 84 /** 85 @brief 86 Sets the parentquest of the Quest. 83 87 @param quest 84 A pointer to the quest to be set as parentquest.85 @return 86 Returns true if the parent Quest could be set.88 A pointer to the Quest to be set as parentquest. 89 @return 90 Returns true if the parentquest could be set. 87 91 */ 88 92 bool Quest::setParentQuest(Quest* quest) 89 93 { 90 if(quest == NULL) 94 if(quest == NULL) //!< We don't want to set NULL-Pointers. 91 95 { 92 96 COUT(2) << "The parentquest to be added to quest {" << this->getId() << "} was NULL." << std::endl; … … 102 106 /** 103 107 @brief 104 Adds a sub quest to the quest.108 Adds a subquest to the Quest. 105 109 @param quest 106 A pointer to the quest to be set as subquest.107 @return 108 Returns true if the sub Quest vould be set.110 A pointer to the Quest to be set as subquest. 111 @return 112 Returns true if the subquest could be set. 109 113 */ 110 114 bool Quest::addSubQuest(Quest* quest) 111 115 { 112 if(quest == NULL) 116 if(quest == NULL) //!< We don't want to set NULL-Pointers. 113 117 { 114 118 COUT(2) << "The subquest to be added to quest {" << this->getId() << "} was NULL." << std::endl; … … 116 120 } 117 121 118 quest->setParentQuest(this); 119 this->subQuests_.push_back(quest); 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. 120 124 121 125 COUT(3) << "Sub Quest {" << quest->getId() << "} was added to Quest {" << this->getId() << "}." << std::endl; … … 126 130 /** 127 131 @brief 128 Adds a Hint to the list of hints132 Adds a QuestHint to the list of QuestHints 129 133 @param hint 130 The hint that should be added to the list of hints.134 The QuestHint that should be added to the list of QuestHints. 131 135 @return 132 136 Returns true if the hint was successfully added. … … 134 138 bool Quest::addHint(QuestHint* hint) 135 139 { 136 if(hint == NULL) 140 if(hint == NULL) //!< We don't want to set NULL-Pointers. Seriously! 137 141 { 138 142 COUT(2) << "A NULL-QuestHint was trying to be added." << std::endl; … … 140 144 } 141 145 142 this->hints_.push_back(hint);143 hint->setQuest(this);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. 144 148 145 149 COUT(3) << "QuestHint {" << hint->getId() << "} was added to Quest {" << this->getId() << "}." << std::endl; … … 149 153 /** 150 154 @brief 151 155 Adds an QuestEffect to the list of fail QuestEffects. 156 @param effect 157 The QuestEffect to be added. 158 @return 159 Returns true if successful. 152 160 */ 153 161 bool Quest::addFailEffect(QuestEffect* effect) 154 162 { 155 if(effect == NULL) 163 if(effect == NULL) //!< We don't want to set NULL-Pointers. 156 164 { 157 165 COUT(2) << "A NULL-QuestEffect was trying to be added" << std::endl; … … 159 167 } 160 168 161 this->failEffects_.push_back(effect); 169 this->failEffects_.push_back(effect); //!< Adds the QuestEffect to the end of the list of fail QuestEffects. 162 170 163 171 COUT(3) << "A FailEffect was added to Quest {" << this->getId() << "}." << std::endl; … … 167 175 /** 168 176 @brief 169 177 Adds an QuestEffect to the list of complete QuestEffects. 178 @param effect 179 The QuestEffect to be added. 180 @return 181 Returns true if successful. 170 182 */ 171 183 bool Quest::addCompleteEffect(QuestEffect* effect) 172 184 { 173 if(effect == NULL) 185 if(effect == NULL) //!< We don't want to set NULL-Pointers. 174 186 { 175 187 COUT(2) << "A NULL-QuestEffect was trying to be added" << std::endl; … … 177 189 } 178 190 179 this->completeEffects_.push_back(effect); 191 this->completeEffects_.push_back(effect); //!< Adds the QuestEffect to the end of the list of complete QuestEffects. 180 192 181 193 COUT(3) << "A CompleteEffect was added to Quest {" << this->getId() << "}." << std::endl; … … 185 197 /** 186 198 @brief 187 199 Returns the parentquest of the Quest. 200 @return 201 Returns a pointer to the parentquest of the Quest. 188 202 */ 189 203 const Quest* Quest::getParentQuest(void) … … 194 208 /** 195 209 @brief 196 197 */ 198 const Quest* Quest::getSubQuests(unsigned int index) const 210 Returns the subquest at the given index. 211 @param 212 The index. 213 @return 214 Returns a pointer to the subquest at the given index. NULL if there is no element at the given index. 215 */ 216 const Quest* Quest::getSubQuest(unsigned int index) const 199 217 { 200 218 int i = index; 219 220 //! Iterate through all subquests. 201 221 for (std::list<Quest*>::const_iterator subQuest = this->subQuests_.begin(); subQuest != this->subQuests_.end(); ++subQuest) 202 222 { 203 if(i == 0) 223 if(i == 0) //!< We're counting down... 204 224 { 205 225 return *subQuest; … … 207 227 i--; 208 228 } 209 return NULL; 210 } 211 212 /** 213 @brief 214 215 */ 216 const QuestHint* Quest::getHints(unsigned int index) const 229 230 return NULL; //!< If the index is greater than the number of elements in the list. 231 } 232 233 /** 234 @brief 235 Returns the QuestHint at the given index. 236 @param 237 The index. 238 @return 239 Returns a pointer to the QuestHint at the given index. NULL if there is no element at the given index. 240 */ 241 const QuestHint* Quest::getHint(unsigned int index) const 217 242 { 218 243 int i = index; 244 245 //! Iterate through all QuestHints. 219 246 for (std::list<QuestHint*>::const_iterator hint = this->hints_.begin(); hint != this->hints_.end(); ++hint) 220 247 { 221 if(i == 0) 248 if(i == 0) //!< We're counting down... 222 249 { 223 250 return *hint; … … 225 252 i--; 226 253 } 227 return NULL; 228 } 229 230 /** 231 @brief 232 233 */ 234 const QuestEffect* Quest::getFailEffects(unsigned int index) const 254 return NULL; //!< If the index is greater than the number of elements in the list. 255 } 256 257 /** 258 @brief 259 Returns the fail QuestEffect at the given index. 260 @param 261 The index. 262 @return 263 Returns a pointer to the fail QuestEffect at the given index. NULL if there is no element at the given index. 264 */ 265 const QuestEffect* Quest::getFailEffect(unsigned int index) const 235 266 { 236 267 int i = index; 268 269 //! Iterate through all fail QuestEffects. 237 270 for (std::list<QuestEffect*>::const_iterator effect = this->failEffects_.begin(); effect != this->failEffects_.end(); ++effect) 238 271 { 239 if(i == 0) 272 if(i == 0) //!< We're counting down... 240 273 { 241 274 return *effect; … … 243 276 i--; 244 277 } 245 return NULL; 246 } 247 248 /** 249 @brief 250 251 */ 252 const QuestEffect* Quest::getCompleteEffects(unsigned int index) const 278 return NULL; //!< If the index is greater than the number of elements in the list. 279 } 280 281 /** 282 @brief 283 Returns the complete QuestEffect at the given index. 284 @param 285 The index. 286 @return 287 Returns a pointer to the complete QuestEffect at the given index. NULL if there is no element at the given index. 288 */ 289 const QuestEffect* Quest::getCompleteEffect(unsigned int index) const 253 290 { 254 291 int i = index; 292 293 //! Iterate through all complete QuestEffects. 255 294 for (std::list<QuestEffect*>::const_iterator effect = this->completeEffects_.begin(); effect != this->completeEffects_.end(); ++effect) 256 295 { 257 if(i == 0) 296 if(i == 0) //!< We're counting down... 258 297 { 259 298 return *effect; … … 261 300 i--; 262 301 } 263 return NULL; 302 return NULL; //!< If the index is greater than the number of elements in the list. 264 303 } 265 304 … … 274 313 Throws an exception if getStatus throws one. 275 314 */ 276 bool Quest::isInactive(const Player * player) const315 bool Quest::isInactive(const PlayerInfo* player) const 277 316 { 278 317 return this->getStatus(player) == questStatus::inactive; … … 289 328 Throws an exception if getStatus throws one. 290 329 */ 291 bool Quest::isActive(const Player * player) const330 bool Quest::isActive(const PlayerInfo* player) const 292 331 { 293 332 … … 305 344 Throws an exception if getStatus throws one. 306 345 */ 307 bool Quest::isFailed(const Player * player) const346 bool Quest::isFailed(const PlayerInfo* player) const 308 347 { 309 348 return this->getStatus(player) == questStatus::failed; … … 320 359 Throws an exception if getStatus throws one. 321 360 */ 322 bool Quest::isCompleted(const Player * player) const361 bool Quest::isCompleted(const PlayerInfo* player) const 323 362 { 324 363 return this->getStatus(player) == questStatus::completed; … … 327 366 /** 328 367 @brief 329 Starts the quest.330 @param player 331 The player. 332 @return 333 Returns true if the quest could be started, false if not.334 */ 335 bool Quest::start(Player * player)336 { 337 if(this->isStartable(player)) 368 Starts the Quest for an input player. 369 @param player 370 The player. 371 @return 372 Returns true if the Quest could be started, false if not. 373 */ 374 bool Quest::start(PlayerInfo* player) 375 { 376 if(this->isStartable(player)) //!< Checks whether the quest can be started. 338 377 { 339 378 this->setStatus(player, questStatus::active); 340 379 return true; 341 380 } 342 COUT(2) << "A non-startable quest was trying to be started." << std::endl; 381 382 COUT(4) << "A non-startable quest was trying to be started." << std::endl; 343 383 return false; 344 384 } 345 385 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 386 } - Property svn:mergeinfo changed
Note: See TracChangeset
for help on using the changeset viewer.