Changeset 2068 for code/branches/questsystem
- Timestamp:
- Oct 30, 2008, 9:52:12 AM (16 years ago)
- Location:
- code/branches/questsystem/src/orxonox/objects
- Files:
-
- 28 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/questsystem/src/orxonox/objects/AddQuest.cc
r2021 r2068 30 30 31 31 #include "core/CoreIncludes.h" 32 #include "util/Exception.h" 32 33 33 34 #include "QuestManager.h" … … 69 70 @param player 70 71 The player the effect is invoked on. 72 @return 73 Returns true if the effect was successfully invoked. 71 74 */ 72 voidAddQuest::invoke(Player* player)75 bool AddQuest::invoke(Player* player) 73 76 { 74 Quest* quest = QuestManager::findQuest(this->getQuestId()); 75 quest->start(player); 77 if(player == NULL) 78 { 79 COUT(2) << "Input player is NULL." << std::endl; 80 return false; 81 } 82 83 try 84 { 85 Quest* quest = QuestManager::findQuest(this->getQuestId()); 86 if(!quest->start(player)) 87 { 88 return false; 89 } 90 } 91 catch(const orxonox::Exception& ex) 92 { 93 COUT(2) << ex.getFullDescription() << std::endl; 94 return false; 95 } 96 97 return true; 76 98 } 77 99 -
code/branches/questsystem/src/orxonox/objects/AddQuest.h
r2021 r2068 51 51 ~AddQuest(); 52 52 53 virtual voidinvoke(Player* player); //!< Invokes the effect.53 virtual bool invoke(Player* player); //!< Invokes the effect. 54 54 55 55 }; -
code/branches/questsystem/src/orxonox/objects/AddQuestHint.cc
r2021 r2068 28 28 29 29 #include "core/CoreIncludes.h" 30 #include "util/Exception.h" 30 31 31 32 #include "QuestManager.h" … … 66 67 @param player 67 68 The player. 69 @return 70 Returns true if the effect was successfully invoked. 68 71 */ 69 voidAddQuestHint::invoke(Player* player)72 bool AddQuestHint::invoke(Player* player) 70 73 { 71 QuestHint* hint = QuestManager::findHint(this->hintId_); 72 hint->activate(player); 74 if(player == NULL) 75 { 76 COUT(2) << "The input player is NULL." << std::endl; 77 return false; 78 } 79 80 try 81 { 82 QuestHint* hint = QuestManager::findHint(this->hintId_); 83 if(!hint->activate(player)) 84 { 85 return false; 86 } 87 } 88 catch(const Exception& e) 89 { 90 COUT(2) << e.getFullDescription() << std::endl; 91 return false; 92 } 93 94 return true; 95 73 96 } 74 97 } -
code/branches/questsystem/src/orxonox/objects/AddQuestHint.h
r2021 r2068 51 51 ~AddQuestHint(); 52 52 53 virtual voidinvoke(Player* player); //!< Invokes the effect.53 virtual bool invoke(Player* player); //!< Invokes the effect. 54 54 55 55 private: -
code/branches/questsystem/src/orxonox/objects/AddReward.cc
r2021 r2068 86 86 @param player 87 87 The player. 88 @return 89 Returns true if the effect was invoked successfully. 88 90 */ 89 voidAddReward::invoke(Player* player)91 bool AddReward::invoke(Player* player) 90 92 { 91 93 if ( this->rewards_ == NULL ) 92 94 { 93 95 COUT(2) << "NULL-Rewards list encountered." << std::endl; 94 return ;96 return false; 95 97 } 98 99 bool check = true; 96 100 for ( std::list<Rewardable*>::iterator reward = this->rewards_->begin(); reward != this->rewards_->end(); ++reward ) 97 101 { 98 (*reward)->reward(player);102 check = check && (*reward)->reward(player); 99 103 } 104 105 return check; 100 106 } 101 107 -
code/branches/questsystem/src/orxonox/objects/AddReward.h
r2021 r2068 53 53 ~AddReward(); 54 54 55 virtual voidinvoke(Player* player); //!< Invokes the effect.55 virtual bool invoke(Player* player); //!< Invokes the effect. 56 56 57 57 private: -
code/branches/questsystem/src/orxonox/objects/ChangeQuestStatus.h
r2021 r2068 51 51 virtual ~ChangeQuestStatus(); 52 52 53 virtual voidinvoke(Player* player) = 0; //!< Invokes the effect.53 virtual bool invoke(Player* player) = 0; //!< Invokes the effect. 54 54 55 55 protected: -
code/branches/questsystem/src/orxonox/objects/CompleteQuest.cc
r2021 r2068 28 28 29 29 #include "core/CoreIncludes.h" 30 #include "util/Exception.h" 30 31 31 32 #include "QuestManager.h" … … 66 67 @param player 67 68 The player the effect is invoked on. 69 @return 70 Returns true if the effect was invoked successfully. 68 71 */ 69 voidCompleteQuest::invoke(Player* player)72 bool CompleteQuest::invoke(Player* player) 70 73 { 71 Quest* quest = QuestManager::findQuest(this->getQuestId()); 72 quest->complete(player); 74 if(player == NULL) 75 { 76 COUT(2) << "Input player is NULL." << std::endl; 77 return false; 78 } 79 80 try 81 { 82 Quest* quest = QuestManager::findQuest(this->getQuestId()); 83 if(!quest->complete(player)) 84 { 85 return false; 86 } 87 } 88 catch(const Exception& e) 89 { 90 COUT(2) << e.getFullDescription() << std::endl; 91 return false; 92 } 93 94 return true; 73 95 } 74 96 -
code/branches/questsystem/src/orxonox/objects/CompleteQuest.h
r2021 r2068 51 51 ~CompleteQuest(); 52 52 53 virtual voidinvoke(Player* player); //!< Invokes the effect.53 virtual bool invoke(Player* player); //!< Invokes the effect. 54 54 55 55 }; -
code/branches/questsystem/src/orxonox/objects/FailQuest.cc
r2021 r2068 28 28 29 29 #include "core/CoreIncludes.h" 30 #include "util/Exception.h" 30 31 31 32 #include "QuestManager.h" … … 66 67 @param player 67 68 The player the effect is invoked on. 69 @return 70 Returns true if the effect was invoked successfully. 68 71 */ 69 voidFailQuest::invoke(Player* player)72 bool FailQuest::invoke(Player* player) 70 73 { 71 Quest* quest = QuestManager::findQuest(this->getQuestId()); 72 quest->fail(player); 74 if(player == NULL) 75 { 76 COUT(2) << "Input player is NULL." << std::endl; 77 return false; 78 } 79 80 try 81 { 82 Quest* quest = QuestManager::findQuest(this->getQuestId()); 83 if(!quest->fail(player)) 84 { 85 return false; 86 } 87 } 88 catch(const Exception& e) 89 { 90 COUT(2) << e.getFullDescription() << std::endl; 91 return false; 92 } 93 94 return true; 73 95 } 74 96 -
code/branches/questsystem/src/orxonox/objects/FailQuest.h
r2021 r2068 51 51 ~FailQuest(); 52 52 53 virtual voidinvoke(Player* player); //!< Invokes the effect.53 virtual bool invoke(Player* player); //!< Invokes the effect. 54 54 55 55 }; -
code/branches/questsystem/src/orxonox/objects/GlobalQuest.cc
r2043 r2068 28 28 29 29 #include "core/CoreIncludes.h" 30 #include "util/Exception.h" 30 31 31 32 #include "GlobalQuest.h" … … 35 36 CreateFactory(GlobalQuest); 36 37 38 /** 39 @brief 40 Constructor. 41 */ 37 42 GlobalQuest::GlobalQuest() : Quest() 38 43 { 39 44 this->initialize(); 40 45 } 41 46 … … 50 55 The description of the quest. 51 56 */ 52 GlobalQuest::GlobalQuest(std::string id , std::string title, std::string description) : Quest(id, title, description)57 GlobalQuest::GlobalQuest(std::string id) : Quest(id) 53 58 { 54 RegisterObject(GlobalQuest);59 this->initialize(); 55 60 } 56 61 … … 64 69 } 65 70 71 void GlobalQuest::initialize(void) 72 { 73 RegisterObject(GlobalQuest); 74 } 75 66 76 /** 67 77 @brief … … 71 81 @return 72 82 Returns true if the quest can be started, false if not. 83 @throws 84 Throws an exception if either isInactive() of isActive() throws one. 73 85 */ 74 86 bool GlobalQuest::isStartable(const Player* player) const 75 87 { 76 return this->isInactive(player) || this->isActive(player);88 return this->isInactive(player) || this->isActive(player); 77 89 } 78 90 … … 84 96 @return 85 97 Returns true if the quest can be failed, false if not. 98 @throws 99 Throws an Exception if isActive() throws one. 86 100 */ 87 101 bool GlobalQuest::isFailable(const Player* player) const 88 102 { 89 103 return this->isActive(player); 104 90 105 } 91 106 … … 97 112 @return 98 113 Returns true if the quest can be completed, false if not. 114 @throws 115 Throws an Exception if isActive() throws one. 99 116 */ 100 117 bool GlobalQuest::isCompletable(const Player* player) const … … 108 125 @param player 109 126 The player. 127 @throws 128 Throws an Exception if player is NULL. 110 129 */ 111 130 questStatus::Enum GlobalQuest::getStatus(const Player* player) const 112 131 { 132 if(player == NULL) 133 { 134 ThrowException(Argument, "The input Player* is NULL."); 135 } 136 113 137 //TDO: Does this really work??? 114 138 std::set<Player*>::const_iterator it = this->players_.find((Player*)(void*)player); … … 127 151 @brief 128 152 Sets the status for a specific player. 153 But be careful wit this one, the status will just be set without checking for its validity. You have to know what you're doing. 129 154 @param player 130 155 The player. 131 156 @param status 132 157 The status to be set. 158 @return 159 Returns false if player is NULL. 133 160 */ 134 161 bool GlobalQuest::setStatus(Player* player, const questStatus::Enum & status) 135 162 { 163 if(player == NULL) 164 { 165 return false; 166 } 167 136 168 std::set<Player*>::const_iterator it = this->players_.find(player); 137 169 if (it == this->players_.end()) //!< Player is not yet in the list. -
code/branches/questsystem/src/orxonox/objects/GlobalQuest.h
r2043 r2068 49 49 public: 50 50 GlobalQuest(); 51 GlobalQuest(std::string id , std::string title = "", std::string description = "");51 GlobalQuest(std::string id); 52 52 ~GlobalQuest(); 53 53 … … 63 63 std::set<Player*> players_; //!< The set of players which possess this quest. 64 64 questStatus::Enum status_; //!< The status of this quest. 65 66 void initialize(void); 65 67 66 68 }; -
code/branches/questsystem/src/orxonox/objects/LocalQuest.cc
r2043 r2068 28 28 29 29 #include "core/CoreIncludes.h" 30 #include "util/Exception.h" 30 31 31 32 #include "LocalQuest.h" … … 37 38 LocalQuest::LocalQuest() : Quest() 38 39 { 39 40 this->initialize(); 40 41 } 41 42 … … 45 46 @param id 46 47 The unique identifier. 47 @param title48 The title of the quest.49 @param description50 The description of the quest.51 48 */ 52 LocalQuest::LocalQuest(std::string id , std::string title, std::string description) : Quest(id, title, description)49 LocalQuest::LocalQuest(std::string id) : Quest(id) 53 50 { 54 RegisterObject(LocalQuest);51 this->initialize(); 55 52 } 56 53 … … 64 61 } 65 62 63 void LocalQuest::initialize(void) 64 { 65 RegisterObject(LocalQuest); 66 } 67 66 68 /** 67 69 @brief … … 71 73 @return 72 74 Returns true if the quest can be started, false if not. 75 @throws 76 Throws an exception if isInactive(Player*) throws one. 73 77 */ 74 78 bool LocalQuest::isStartable(const Player* player) const … … 84 88 @return 85 89 Returns true if the quest can be failed, false if not. 90 @throws 91 Throws an exception if isActive(Player*) throws one. 86 92 */ 87 93 bool LocalQuest::isFailable(const Player* player) const … … 97 103 @return 98 104 Returns true if the quest can be completed, false if not. 105 @throws 106 Throws an exception if isInactive(Player*) throws one. 99 107 */ 100 108 bool LocalQuest::isCompletable(const Player* player) const … … 110 118 @return 111 119 Returns the status of the quest for the input player. 120 @throws 121 Throws an Exception if player is NULL. 112 122 */ 113 123 questStatus::Enum LocalQuest::getStatus(const Player* player) const 114 124 { 125 if(player == NULL) 126 { 127 ThrowException(Argument, "The input Player* is NULL."); 128 } 129 115 130 std::map<Player*, questStatus::Enum>::const_iterator it = this->playerStatus_.find((Player*)(void*)player); //Thx. to x3n for the (Player*)(void*) 'hack'. 116 131 if (it != this->playerStatus_.end()) … … 124 139 @brief 125 140 Sets the status for a specific player. 141 But be careful wit this one, the status will just be set without checking for its validity. You have to know what you're doing. 126 142 @param player 127 143 The player. 128 144 @param status 129 145 The status. 146 @return 147 Returns false if player is NULL. 130 148 */ 131 149 bool LocalQuest::setStatus(Player* player, const questStatus::Enum & status) 132 150 { 151 if(player == NULL) 152 { 153 return false; 154 } 133 155 this->playerStatus_[player] = status; 134 156 return true; -
code/branches/questsystem/src/orxonox/objects/LocalQuest.h
r2043 r2068 49 49 public: 50 50 LocalQuest(); 51 LocalQuest(std::string id , std::string title = "", std::string description = "");51 LocalQuest(std::string id); 52 52 ~LocalQuest(); 53 53 … … 61 61 62 62 private: 63 std::map<Player*, questStatus::Enum> playerStatus_; 63 std::map<Player*, questStatus::Enum> playerStatus_; //!< List of the status for each player, with the Player-pointer as key. 64 65 void initialize(void); 64 66 65 67 }; -
code/branches/questsystem/src/orxonox/objects/Quest.cc
r2021 r2068 30 30 31 31 #include "Quest.h" 32 #include "QuestManager.h" 32 33 33 34 namespace orxonox { … … 35 36 Quest::Quest() : QuestItem() 36 37 { 37 38 this->initialize(); 38 39 } 39 40 … … 48 49 The description of the quest. 49 50 */ 50 Quest::Quest(std::string id , std::string title, std::string description) : QuestItem(id, title, description)51 { 52 initialize();51 Quest::Quest(std::string id) : QuestItem(id) 52 { 53 this->initialize(); 53 54 } 54 55 … … 59 60 Quest::~Quest() 60 61 { 61 //TDO: Unload lists...62 62 63 } 63 64 … … 70 71 RegisterObject(Quest); 71 72 72 this->parentQuest_ = 0; 73 this->parentQuest_ = NULL; 74 QuestManager::registerQuest(this); //Registers the quest with the QuestManager. 73 75 } 74 76 … … 78 80 @param quest 79 81 A pointer to the quest to be set as parent quest. 82 @return 83 Returns true if the parentQuest could be set. 80 84 */ 81 85 bool Quest::setParentQuest(Quest* quest) 82 86 { 87 if(quest == NULL) 88 { 89 COUT(2) << "The parentquest to be added to quest {" << this->getId() << "} was NULL." << std::endl; 90 return false; 91 } 92 83 93 this->parentQuest_ = quest; 84 94 return true; … … 90 100 @param quest 91 101 A pointer to the quest to be set as sub quest. 102 @return 103 Returns true if the subQuest vould be set. 92 104 */ 93 105 bool Quest::addSubQuest(Quest* quest) 94 106 { 107 if(quest == NULL) 108 { 109 COUT(2) << "The subquest to be added to quest {" << this->getId() << "} was NULL." << std::endl; 110 return false; 111 } 112 95 113 this->subQuests_.push_back(quest); 96 114 return true; 115 } 116 117 /** 118 @brief 119 Returns true if the quest status for the specific player is 'inactive'. 120 @param player 121 The player. 122 @return 123 Returns true if the quest status for the specific player is 'inactive'. 124 @throws 125 Throws an exception if getStatus throws one. 126 */ 127 bool Quest::isInactive(const Player* player) const 128 { 129 return this->getStatus(player) == questStatus::inactive; 130 } 131 132 /** 133 @brief 134 Returns true if the quest status for the specific player is 'active'. 135 @param player 136 The player. 137 @return 138 Returns true if the quest status for the specific player is 'active'. 139 @throws 140 Throws an exception if getStatus throws one. 141 */ 142 bool Quest::isActive(const Player* player) const 143 { 144 145 return this->getStatus(player) == questStatus::active; 146 } 147 148 /** 149 @brief 150 Returns true if the quest status for the specific player is 'failed'. 151 @param player 152 The player. 153 @return 154 Returns true if the quest status for the specific player is 'failed'. 155 @throws 156 Throws an exception if getStatus throws one. 157 */ 158 bool Quest::isFailed(const Player* player) const 159 { 160 return this->getStatus(player) == questStatus::failed; 161 } 162 163 /** 164 @brief 165 Returns true if the quest status for the specific player is 'completed'. 166 @param player 167 The player. 168 @return 169 Returns true if the quest status for the specific player is 'completed'. 170 @throws 171 Throws an exception if getStatus throws one. 172 */ 173 bool Quest::isCompleted(const Player* player) const 174 { 175 return this->getStatus(player) == questStatus::completed; 97 176 } 98 177 … … 102 181 @param hint 103 182 The hint that should be added to the list of hints. 104 */ 105 void Quest::addHint(QuestHint* hint) 106 { 107 if ( hint != NULL ) 108 { 109 this->hints_.push_back(hint); 110 hint->setQuest(this); 111 } 112 else 183 @return 184 Returns true if the hint was successfully added. 185 */ 186 bool Quest::addHint(QuestHint* hint) 187 { 188 if(hint == NULL) 113 189 { 114 190 COUT(2) << "A NULL-QuestHint was trying to be added." << std::endl; 115 } 191 return false; 192 } 193 194 this->hints_.push_back(hint); 195 hint->setQuest(this); 196 return true; 116 197 } 117 198 -
code/branches/questsystem/src/orxonox/objects/Quest.h
r2043 r2068 58 58 @brief 59 59 Represents a quest in the game. 60 A quest has a sub61 60 A quest has a list of subquests and a parentquest (if it is not a rootquest). 61 Each quest exists only once but it has a different status (inactive, active, failed or completed) for each player. 62 62 @author 63 63 Damian 'Mozork' Frick … … 67 67 public: 68 68 Quest(); 69 Quest(std::string id , std::string title = "", std::string description = "");69 Quest(std::string id); 70 70 virtual ~Quest(); 71 71 … … 75 75 { return this->subQuests_; } 76 76 77 //TDO: Necessary? Shouldn't this be decided whilest creating the object? 78 // Yes it absolutely should and will. Add these methods to protected then? 79 bool setParentQuest(Quest* quest); //!< Sets the parent quest of the quest. 80 bool addSubQuest(Quest* quest); //!< Adds a sub quest to the quest. 81 82 inline bool isInactive(const Player* player) const //!< Returns true if the quest status for the specific player is 'inactive'. 83 { return this->getStatus(player) == questStatus::inactive; } 84 inline bool isActive(const Player* player) const //!< Returns true if the quest status for the specific player is 'active'. 85 { return this->getStatus(player) == questStatus::active; } 86 inline bool isFailed(const Player* player) const //!< Returns true if the quest status for the specific player is 'failed'. 87 { return this->getStatus(player) == questStatus::failed; } 88 inline bool isCompleted(const Player* player) const //!< Returns true if the quest status for the specific player is 'completed'. 89 { return this->getStatus(player) == questStatus::completed; } 77 bool isInactive(const Player* player) const; //!< Returns true if the quest status for the specific player is 'inactive'. 78 bool isActive(const Player* player) const; //!< Returns true if the quest status for the specific player is 'active'. 79 bool isFailed(const Player* player) const; //!< Returns true if the quest status for the specific player is 'failed'. 80 bool isCompleted(const Player* player) const; //!< Returns true if the quest status for the specific player is 'completed'. 90 81 91 82 bool start(Player* player); //!< Sets a quest to active. … … 93 84 bool complete(Player* player); //!< Completes the quest. 94 85 95 voidaddHint(QuestHint* hint); //!< Add a hint to the list of hints.86 bool addHint(QuestHint* hint); //!< Add a hint to the list of hints. 96 87 97 88 protected: … … 102 93 virtual bool isCompletable(const Player* player) const = 0; //!< Checks whether the quest can be completed. 103 94 104 //TDO: Get the parameter const... 95 bool setParentQuest(Quest* quest); //!< Sets the parent quest of the quest. 96 bool addSubQuest(Quest* quest); //!< Adds a sub quest to the quest. 97 105 98 virtual questStatus::Enum getStatus(const Player* player) const = 0; //!< Returns the status of the quest for a specific player. 106 99 virtual bool setStatus(Player* player, const questStatus::Enum & status) = 0; //!< Changes the status for a specific player. -
code/branches/questsystem/src/orxonox/objects/QuestDescription.cc
r2021 r2068 37 37 QuestDescription::QuestDescription() : BaseObject() 38 38 { 39 39 this->initialize(); 40 40 } 41 41 42 /** 43 @brief 44 Constructor. Creates a new QuestDescription object and adds a title and description. 45 @param title 46 @param description 47 */ 42 48 QuestDescription::QuestDescription(std::string title, std::string description) : BaseObject() 43 49 { 44 initialize();50 this->initialize(); 45 51 this->title_ = title; 46 52 this->description_ = description; … … 50 56 { 51 57 58 } 59 60 void QuestDescription::XMLPort(Element& xmlelement, XMLPort::Mode mode) 61 { 62 SUPER(QuestDescription, XMLPort, xmlelement, mode); 63 64 XMLPortParam(QuestDescription, "title", setTitle, getTitle, xmlelement, mode); 65 XMLPortParam(QuestDescription, "description", setDescription, getDescription, xmlelement, mode); 66 67 COUT(1) << "QuestDescription created!" << std::endl; 52 68 } 53 69 -
code/branches/questsystem/src/orxonox/objects/QuestDescription.h
r2021 r2068 33 33 34 34 #include "core/BaseObject.h" 35 #include "core/XMLPort.h" 35 36 36 37 namespace orxonox { … … 50 51 ~QuestDescription(); 51 52 53 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 54 52 55 inline const std::string & getTitle(void) const //!< Returns the title. 53 56 { return this->title_; } … … 57 60 private: 58 61 void initialize(void); 62 63 inline void setTitle(const std::string & title) //!< Sets the title. 64 { this->title_ = title; } 65 inline void setDescription(const std::string & description) //!< Sets the description text. 66 { this->description_ = description; } 59 67 60 std::string title_; 61 std::string description_; 68 std::string title_; //!< The title. 69 std::string description_; //!< The description. 62 70 63 71 }; -
code/branches/questsystem/src/orxonox/objects/QuestEffect.cc
r2021 r2068 59 59 @param effects 60 60 A list of all the effects to be invoked. 61 @return 62 Returns false if there was an error, view console of log for further detail. 61 63 */ 62 voidQuestEffect::invokeEffects(Player* player, std::list<QuestEffect*> & effects)64 bool QuestEffect::invokeEffects(Player* player, std::list<QuestEffect*> & effects) 63 65 { 66 bool check = true; 67 64 68 for (std::list<QuestEffect*>::iterator effect = effects.begin(); effect != effects.end(); effect++) 65 69 { 66 (*effect)->invoke(player);70 check = check && (*effect)->invoke(player); 67 71 } 72 return check; 68 73 } 69 74 -
code/branches/questsystem/src/orxonox/objects/QuestEffect.h
r2021 r2068 50 50 virtual ~QuestEffect(); 51 51 52 virtual voidinvoke(Player* player) = 0; //!< Invokes the effect.53 static voidinvokeEffects(Player* player, std::list<QuestEffect*> & effects); //!< Invokes all effects in the list.52 virtual bool invoke(Player* player) = 0; //!< Invokes the effect. 53 static bool invokeEffects(Player* player, std::list<QuestEffect*> & effects); //!< Invokes all effects in the list. 54 54 55 55 -
code/branches/questsystem/src/orxonox/objects/QuestHint.cc
r2021 r2068 28 28 29 29 #include "core/CoreIncludes.h" 30 #include "util/Exception.h" 30 31 31 32 #include "Quest.h" … … 36 37 CreateFactory(QuestHint); 37 38 39 /** 40 @brief 41 Constructor. 42 */ 38 43 QuestHint::QuestHint() : QuestItem() 39 44 { 40 45 this->initialize(); 41 46 } 42 47 … … 51 56 The description of the hint, resp. the hint itself. 52 57 */ 53 QuestHint::QuestHint(std::string id , std::string title, std::string description) : QuestItem(id, title, description)58 QuestHint::QuestHint(std::string id) : QuestItem(id) 54 59 { 55 RegisterObject(QuestHint);60 this->initialize(); 56 61 } 57 62 … … 65 70 } 66 71 72 void QuestHint::initialize(void) 73 { 74 RegisterObject(QuestHint); 75 } 76 77 void QuestHint::XMLPort(Element& xmlelement, XMLPort::Mode mode) 78 { 79 SUPER(QuestHint, XMLPort, xmlelement, mode); 80 } 81 82 67 83 /** 68 84 @brief … … 70 86 @param player 71 87 The player. 88 @throws 89 Throws an Argument Exception if the input Player-pointer is NULL. 72 90 @return 73 Returns 91 Returns true if the hint is active for the specified player. 74 92 */ 75 93 bool QuestHint::isActive(Player* player) 76 94 { 95 if(player == NULL) 96 { 97 ThrowException(Argument, "The input Player* is NULL."); 98 return false; 99 } 100 77 101 std::map<Player*, questHintStatus::Enum>::iterator it = this->playerStatus_.find(player); 78 102 if (it != this->playerStatus_.end()) … … 85 109 /** 86 110 @brief 111 Activates a QuestHint for a given player. 87 112 @param player 113 The player. 88 114 @return 115 Returns true if the activation was successful, false if there were problems. 89 116 */ 90 117 bool QuestHint::activate(Player* player) 91 118 { 92 if(this->quest_->isActive(player) && !(this->isActive(player)))119 if(this->quest_->isActive(player)) 93 120 { 94 this->playerStatus_[player] = questHintStatus::active; 95 return true; 121 if(!(this->isActive(player))) 122 { 123 this->playerStatus_[player] = questHintStatus::active; 124 return true; 125 } 126 else 127 { 128 COUT(2) << "An already active questHint was trying to get activated." << std::endl; 129 return false; 130 } 96 131 } 97 132 COUT(2) << "A hint of a non-active quest was trying to get activated." << std::endl; … … 101 136 /** 102 137 @brief 138 Sets the quest the QuestHitn belongs to. 103 139 @param quest 104 140 @return 105 141 */ 106 voidQuestHint::setQuest(Quest* quest)142 bool QuestHint::setQuest(Quest* quest) 107 143 { 144 if(quest == NULL) 145 { 146 COUT(2) << "The input Quest* is NULL." << std::endl; 147 return false; 148 } 149 108 150 this->quest_ = quest; 151 return true; 109 152 } 110 153 -
code/branches/questsystem/src/orxonox/objects/QuestHint.h
r2021 r2068 33 33 #include <string> 34 34 35 #include "core/XMLPort.h" 35 36 #include "QuestDescription.h" 36 37 #include "QuestItem.h" … … 56 57 @brief 57 58 Represents a hint in the game towards completing a Quest. 58 Consists of title and description in textual form. 59 Consists of title and description in textual form and must belong to a quest. 60 A QuestHit has a defined status (inactive or active, where inactive is default) for each player, which means each QuestHint exists only once for all players, it doesn't belong to a player, it just has different stati for each of them. 59 61 @author 60 62 Damian 'Mozork' Frick … … 65 67 public: 66 68 QuestHint(); 67 QuestHint(std::string id , std::string title = "", std::string description = "");69 QuestHint(std::string id); 68 70 ~QuestHint(); 71 72 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 69 73 70 74 bool isActive(Player* player); //!< Returns true if the hint is active for the input player. … … 72 76 bool activate(Player* player); //!< Activates the hint for the input player. 73 77 74 void setQuest(Quest* quest); //!< Sets the quest the hint belongs to. 78 bool setQuest(Quest* quest); //!< Sets the quest the hint belongs to. 79 80 inline Quest* getQuest(void) 81 { return this->quest_; } 75 82 76 83 private: 77 84 78 Quest* quest_; 79 std::map<Player*, questHintStatus::Enum> playerStatus_; 85 void initialize(void); 86 87 Quest* quest_; //!< The quest the hint belongs to. 88 std::map<Player*, questHintStatus::Enum> playerStatus_; //!< List of the status for each player, with the Player-pointer as key. 80 89 81 90 }; -
code/branches/questsystem/src/orxonox/objects/QuestItem.cc
r2021 r2068 37 37 QuestItem::QuestItem() : BaseObject() 38 38 { 39 39 this->initialize(); 40 40 } 41 41 … … 45 45 @param id 46 46 The unique identifier. Should be of GUID form: http://en.wikipedia.org/wiki/Globally_Unique_Identifier#Basic_structure 47 @param title48 The title of this QuestItem. Has an empty string as default.49 @param description50 The description of this QuestItem. Has an empty string as default.51 47 */ 52 QuestItem::QuestItem(std::string id , std::string title, std::string description) : BaseObject()48 QuestItem::QuestItem(std::string id) : BaseObject() 53 49 { 54 50 this->initialize(); 55 51 56 52 this->id_ = id; 57 this->description_ = QuestDescription(title, description);58 53 } 59 54 … … 66 61 67 62 } 63 64 void QuestItem::XMLPort(Element& xmlelement, XMLPort::Mode mode) 65 { 66 SUPER(QuestItem, XMLPort, xmlelement, mode); 67 68 XMLPortParam(QuestItem, "id", setId, getId, xmlelement, mode); 69 //Doesn't getDescription have to be of type getDescription(unsigned int) ? 70 //XMLPortObjectTemplate(QuestItem, QuestDescription, "", setDescription, getDescription, xmlelement, mode, unsigned int); 71 XMLPortObject(QuestItem, QuestDescription, "", setDescription, getDescription, xmlelement, mode); 72 73 } 74 68 75 69 76 /** … … 78 85 this->id_ = ""; 79 86 } 87 88 //const QuestDescription* QuestItem::getDescription(unsigned int index) const //!< Returns the description of the QuestItem. 89 //{ 90 // if(index != 0) 91 // return NULL; 92 // return this->description_; 93 //} 94 95 /** 96 @brief 97 Checks whether an input id is of the required form. 98 @param id 99 The id to be checked. 100 @return 101 Returns true if the string is likely to be of the required form. 102 @todo 103 Clarify form, more vigorous checks. 104 */ 105 bool QuestItem::isId(const std::string & id) 106 { 107 return id.size() >= 32; 108 } 80 109 81 110 } -
code/branches/questsystem/src/orxonox/objects/QuestItem.h
r2021 r2068 32 32 #include <string> 33 33 34 #include "core/BaseObject.h" 35 #include "core/XMLPort.h" 34 36 #include "QuestDescription.h" 35 #include "core/BaseObject.h"36 37 37 38 namespace orxonox { … … 50 51 public: 51 52 QuestItem(); 52 QuestItem(std::string id , std::string title = "", std::string description = "");53 QuestItem(std::string id); 53 54 virtual ~QuestItem(); 54 55 55 inline std::string getId(void) const //!< Returns the id of this quest. 56 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 57 58 inline const std::string & getId(void) const //!< Returns the id of this quest. 56 59 { return this->id_; } 57 inline const QuestDescription &getDescription(void) const //!< Returns the description of the QuestItem.60 inline const QuestDescription* getDescription(void) const //!< Returns the description of the QuestItem. 58 61 { return this->description_; } 62 //const QuestDescription* getDescription(unsigned int index) const; //!< Returns the description of the QuestItem. 63 64 static bool isId(const std::string & id); //!< Checks whether a given id is valid. 65 66 protected: 67 inline void setId(const std::string & id) 68 { id_ = id; } 69 inline void setDescription(QuestDescription* description) 70 { this->description_ = description; } 59 71 60 72 private: 61 73 std::string id_; //!< Identifier. Should be of GUID form: http://en.wikipedia.org/wiki/Globally_Unique_Identifier#Basic_structure 62 QuestDescription description_; //!< The description of the QuestItem.74 QuestDescription* description_; //!< The description of the QuestItem. 63 75 64 76 void initialize(void); //!< Initializes the object. -
code/branches/questsystem/src/orxonox/objects/QuestManager.cc
r2022 r2068 28 28 29 29 #include "core/CoreIncludes.h" 30 #include "util/Exception.h" 30 31 31 32 #include "QuestManager.h" … … 57 58 bool QuestManager::registerQuest(Quest* quest) 58 59 { 59 questMap_.insert( std::pair<std::string,Quest*>(quest->getId(),quest) ); 60 return true; 60 if(quest == NULL) 61 { 62 COUT(2) << "Registration of Quest in QuestManager failed, because inserted Quest-pointer was NULL." << std::endl; 63 return false; 64 } 65 66 std::pair<std::map<std::string, Quest*>::iterator,bool> ret; 67 ret = questMap_.insert( std::pair<std::string,Quest*>(quest->getId(),quest) ); 68 69 if(ret.second) 70 { 71 COUT(3) << "Quest with questId {" << quest->getId() << "} successfully inserted." << std::endl; 72 return true; 73 } 74 else 75 { 76 COUT(2) << "Quest with the same id was already present." << std::endl; 77 return false; 78 } 61 79 } 62 80 … … 71 89 bool QuestManager::registerHint(QuestHint* hint) 72 90 { 73 hintMap_.insert ( std::pair<std::string,QuestHint*>(hint->getId(),hint) ); 74 return true; 91 if(hint == NULL) 92 { 93 COUT(2) << "Registration of QuestHint in QuestManager failed, because inserted QuestHint-pointer was NULL." << std::endl; 94 return false; 95 } 96 97 std::pair<std::map<std::string, QuestHint*>::iterator,bool> ret; 98 ret = hintMap_.insert ( std::pair<std::string,QuestHint*>(hint->getId(),hint) ); 99 100 if(ret.second) 101 { 102 COUT(3) << "QuestHint with hintId {" << hint->getId() << "} successfully inserted." << std::endl; 103 return true; 104 } 105 else 106 { 107 COUT(2) << "QuestHint with the same id was already present." << std::endl; 108 return false; 109 } 75 110 } 76 111 … … 82 117 @return 83 118 Returns a reference to the quest with the input id. 84 @todo 85 Throw exceptions in case of errors. 119 Returns NULL if there is no quest with the given questId. 120 @throws 121 Throws an exception if the given questId is invalid. 86 122 */ 87 123 Quest* QuestManager::findQuest(const std::string & questId) 88 124 { 125 if(!QuestItem::isId(questId)) 126 { 127 ThrowException(Argument, "Invalid questId."); 128 } 129 89 130 Quest* quest; 90 131 std::map<std::string, Quest*>::iterator it = questMap_.find(questId); … … 110 151 @return 111 152 Returns a reference to the hint with the input id. 112 @todo 113 Throw exceptopns in case of errors. 153 Returns NULL if there is no hint with the given hintId. 154 @throws 155 Throws an exception if the given hintId is invalid. 114 156 */ 115 157 QuestHint* QuestManager::findHint(const std::string & hintId) 116 158 { 159 if(!QuestItem::isId(hintId)) 160 { 161 ThrowException(Argument, "Invalid hintId."); 162 } 163 117 164 QuestHint* hint; 118 165 std::map<std::string, QuestHint*>::iterator it = hintMap_.find(hintId); -
code/branches/questsystem/src/orxonox/objects/QuestManager.h
r2021 r2068 42 42 @brief 43 43 Manages quests, by making them globally accessable. 44 Quests (and Hints) are registered in the QuestManager trough their id, and can be accessed in the same way. 44 45 @author 45 46 Damian 'Mozork' Frick … … 59 60 60 61 private: 61 static std::map<std::string, Quest*> questMap_; 62 static std::map<std::string, QuestHint*> hintMap_; 62 static std::map<std::string, Quest*> questMap_; //!< All quests registered by their id's. 63 static std::map<std::string, QuestHint*> hintMap_; //!< All hints registered by their id's. 63 64 64 65 }; -
code/branches/questsystem/src/orxonox/objects/Rewardable.cc
r2043 r2068 33 33 namespace orxonox { 34 34 35 35 36 Rewardable::Rewardable() : BaseObject() 36 37 {
Note: See TracChangeset
for help on using the changeset viewer.