- 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/GlobalQuest.cc
r2105 r2146 26 26 * 27 27 */ 28 29 /** 30 @file GlobalQuest.cc 31 @brief 32 Implementation of the GlobalQuest class. 33 */ 28 34 29 35 #include "OrxonoxStableHeaders.h" 30 36 #include "GlobalQuest.h" 31 37 38 #include "orxonox/objects/worldentities/ControllableEntity.h" 32 39 #include "core/CoreIncludes.h" 33 40 #include "util/Exception.h" 34 41 42 #include "QuestEffect.h" 43 35 44 namespace orxonox { 36 45 … … 39 48 /** 40 49 @brief 41 Constructor. 50 Constructor. Initializes the object. 42 51 */ 43 52 GlobalQuest::GlobalQuest(BaseObject* creator) : Quest(creator) 44 53 { 54 this->initialize(); 55 } 56 57 /** 58 @brief 59 Initializes the object. 60 */ 61 void GlobalQuest::initialize(void) 62 { 45 63 RegisterObject(GlobalQuest); 46 47 this->initialize();48 64 } 49 65 … … 56 72 57 73 } 58 74 75 /** 76 @brief 77 Method for creating a GlobalQuest object through XML. 78 */ 59 79 void GlobalQuest::XMLPort(Element& xmlelement, XMLPort::Mode mode) 60 80 { 61 81 SUPER(GlobalQuest, XMLPort, xmlelement, mode); 82 83 XMLPortObject(GlobalQuest, QuestEffect, "reward-effects", addRewardEffect, getRewardEffects, xmlelement, mode); 62 84 63 85 COUT(3) << "New GlobalQuest {" << this->getId() << "} created." << std::endl; 64 86 } 65 66 void GlobalQuest::initialize(void) 67 { 68 RegisterObject(GlobalQuest); 87 88 /** 89 @brief 90 Fails the quest for all players. 91 Invokes the failEffects on all the players possessing this quest. 92 @param player 93 The player failing it. 94 @return 95 Returns true if the quest could be failed, false if not. 96 */ 97 bool GlobalQuest::fail(ControllableEntity* player) 98 { 99 if(this->isFailable(player)) //!< Check whether the quest can be failed. 100 { 101 this->setStatus(player, questStatus::failed); 102 103 //! Iterate through all players possessing this quest. 104 for(std::set<ControllableEntity*>::const_iterator it = players_.begin(); it != players_.end(); it++) 105 { 106 QuestEffect::invokeEffects(*it, this->failEffects_); 107 } 108 109 return true; 110 } 111 112 COUT(2) << "A non-completable quest was trying to be failed." << std::endl; 113 return false; 114 } 115 116 /** 117 @brief 118 Completes the quest for all players. 119 Invokes the completeEffects on all the players possessing this quest. 120 Invokes the reward effects on the player completing the quest. 121 @param player 122 The player completing it. 123 @return 124 Returns true if the quest could be completed, false if not. 125 */ 126 bool GlobalQuest::complete(ControllableEntity* player) 127 { 128 if(this->isCompletable(player)) //!< Check whether the quest can be completed. 129 { 130 this->setStatus(player, questStatus::completed); 131 132 //! Iterate through all players possessing the quest. 133 for(std::set<ControllableEntity*>::const_iterator it = players_.begin(); it != players_.end(); it++) 134 { 135 QuestEffect::invokeEffects(*it, this->completeEffects_); 136 } 137 138 QuestEffect::invokeEffects(player, this->rewards_); //!< Invoke reward effects on the player completing the quest. 139 return true; 140 } 141 142 COUT(2) << "A non-completable quest was trying to be completed." << std::endl; 143 return false; 69 144 } 70 145 … … 79 154 Throws an exception if either isInactive() of isActive() throws one. 80 155 */ 81 bool GlobalQuest::isStartable(const Player* player) const156 bool GlobalQuest::isStartable(const ControllableEntity* player) const 82 157 { 83 158 return this->isInactive(player) || this->isActive(player); … … 94 169 Throws an Exception if isActive() throws one. 95 170 */ 96 bool GlobalQuest::isFailable(const Player* player) const171 bool GlobalQuest::isFailable(const ControllableEntity* player) const 97 172 { 98 173 return this->isActive(player); … … 110 185 Throws an Exception if isActive() throws one. 111 186 */ 112 bool GlobalQuest::isCompletable(const Player* player) const187 bool GlobalQuest::isCompletable(const ControllableEntity* player) const 113 188 { 114 189 return this->isActive(player); … … 123 198 Throws an Exception if player is NULL. 124 199 */ 125 questStatus::Enum GlobalQuest::getStatus(const Player* player) const126 { 127 if(player == NULL) 128 { 129 ThrowException(Argument, "The input Player* is NULL.");130 } 131 132 // TDO: Does this really work???133 std::set< Player*>::const_iterator it = this->players_.find((Player*)(void*)player);134 if (it != this->players_.end()) 200 questStatus::Enum GlobalQuest::getStatus(const ControllableEntity* player) const 201 { 202 if(player == NULL) //!< We don't want NULL-Pointers! 203 { 204 ThrowException(Argument, "The input ControllableEntity* is NULL."); 205 } 206 207 //! Find the player. 208 std::set<ControllableEntity*>::const_iterator it = this->players_.find((ControllableEntity*)(void*)player); 209 if (it != this->players_.end()) //!< If the player was found. 135 210 { 136 211 return this->status_; 137 212 } 138 else 139 { 140 return questStatus::inactive; 141 } 142 213 214 return questStatus::inactive; 143 215 } 144 216 … … 154 226 Returns false if player is NULL. 155 227 */ 156 bool GlobalQuest::setStatus( Player* player, const questStatus::Enum & status)157 { 158 if(player == NULL) 228 bool GlobalQuest::setStatus(ControllableEntity* player, const questStatus::Enum & status) 229 { 230 if(player == NULL) //!< We don't want NULL-Pointers! 159 231 { 160 232 return false; 161 233 } 162 234 163 std::set<Player*>::const_iterator it = this->players_.find(player); 235 //! Find the player. 236 std::set<ControllableEntity*>::const_iterator it = this->players_.find(player); 164 237 if (it == this->players_.end()) //!< Player is not yet in the list. 165 238 { 166 this->players_.insert(player); 167 } 168 this->status_ = status; 239 this->players_.insert(player); //!< Add the player to the set. 240 } 241 242 this->status_ = status; //!< Set the status, which is global, remember...? 169 243 return true; 170 244 } 245 246 /** 247 @brief 248 Adds a reward effect to the list of reward effects. 249 @param effect 250 The effect to be added. 251 @return 252 Returns true if successful. 253 */ 254 bool GlobalQuest::addRewardEffect(QuestEffect* effect) 255 { 256 if(effect == NULL) //!< We don't want NULL-Pointers! 257 { 258 COUT(2) << "The reward effect to be added to quest {" << this->getId() << "} was NULL." << std::endl; 259 return false; 260 } 261 262 this->rewards_.push_back(effect); //!< Add the effect to the list. 263 264 COUT(3) << "Reward effect was added to Quest {" << this->getId() << "}." << std::endl; 265 return true; 266 } 267 268 /** 269 @brief 270 Returns the reward effect at the given index. 271 @param index 272 The index. 273 @return 274 Returns the QuestEffect at the given index. 275 */ 276 const QuestEffect* GlobalQuest::getRewardEffects(unsigned int index) const 277 { 278 int i = index; 279 for (std::list<QuestEffect*>::const_iterator effect = this->rewards_.begin(); effect != this->rewards_.end(); ++effect) 280 { 281 if(i == 0) 282 { 283 return *effect; 284 } 285 i--; 286 } 287 return NULL; 288 } 171 289 172 290
Note: See TracChangeset
for help on using the changeset viewer.