Changeset 2093 for code/trunk/src/orxonox
- Timestamp:
- Nov 1, 2008, 9:03:51 PM (16 years ago)
- Location:
- code/trunk/src/orxonox/objects/quest
- Files:
-
- 27 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/orxonox/objects/quest/AddQuest.cc
r2092 r2093 78 78 try 79 79 { 80 81 82 83 84 85 86 87 80 Quest* quest = QuestManager::findQuest(this->getQuestId()); 81 if(!quest->start(player)) 82 { 83 return false; 84 } 85 } 86 catch(const orxonox::Exception& ex) 87 { 88 88 COUT(2) << ex.getFullDescription() << std::endl; 89 89 return false; 90 90 } 91 91 92 92 return true; 93 93 } 94 94 -
code/trunk/src/orxonox/objects/quest/AddQuest.h
r2092 r2093 47 47 class AddQuest : public ChangeQuestStatus 48 48 { 49 49 public: 50 50 AddQuest(BaseObject* creator); 51 51 virtual ~AddQuest(); 52 52 53 53 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 54 54 55 55 virtual bool invoke(Player* player); //!< Invokes the effect. 56 56 57 57 }; -
code/trunk/src/orxonox/objects/quest/AddQuestHint.cc
r2092 r2093 88 88 { 89 89 QuestHint* hint = QuestManager::findHint(this->hintId_); 90 91 92 93 94 95 96 97 98 99 90 if(!hint->activate(player)) 91 { 92 return false; 93 } 94 } 95 catch(const Exception& e) 96 { 97 COUT(2) << e.getFullDescription() << std::endl; 98 return false; 99 } 100 100 101 101 return true; 102 102 103 103 } -
code/trunk/src/orxonox/objects/quest/AddQuestHint.h
r2092 r2093 40 40 /** 41 41 @brief 42 42 Adds a QuestHint, resp. Activates the QuestHint. 43 43 @author 44 44 Damian 'Mozork' Frick 45 45 */ 46 46 class AddQuestHint : public QuestEffect 47 47 { 48 48 public: 49 49 AddQuestHint(BaseObject* creator); 50 50 virtual ~AddQuestHint(); 51 51 52 52 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 53 53 54 54 virtual bool invoke(Player* player); //!< Invokes the effect. 55 55 56 56 private: 57 57 std::string hintId_; 58 58 59 59 inline const std::string & getHintId(void) const 60 60 { return this->hintId_; } 61 61 void setHintId(const std::string & id); 62 62 63 63 }; -
code/trunk/src/orxonox/objects/quest/AddReward.cc
r2092 r2093 71 71 int i = index; 72 72 for (std::list<Rewardable*>::const_iterator reward = this->rewards_.begin(); reward != this->rewards_.end(); ++reward) 73 74 75 76 77 78 79 73 { 74 if(i == 0) 75 { 76 return *reward; 77 } 78 i--; 79 } 80 80 return NULL; 81 81 } … … 91 91 bool AddReward::invoke(Player* player) 92 92 { 93 93 bool check = true; 94 94 for ( std::list<Rewardable*>::iterator reward = this->rewards_.begin(); reward != this->rewards_.end(); ++reward ) 95 96 97 95 { 96 check = check && (*reward)->reward(player); 97 } 98 98 99 99 return check; 100 100 } 101 101 -
code/trunk/src/orxonox/objects/quest/AddReward.h
r2092 r2093 42 42 /** 43 43 @brief 44 44 Adds a list of rewards to a player. 45 45 @author 46 46 Damian 'Mozork' Frick 47 47 */ 48 48 class AddReward : public QuestEffect 49 49 { 50 50 public: 51 51 AddReward(BaseObject* creator); 52 52 virtual ~AddReward(); 53 53 54 54 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 55 55 56 56 virtual bool invoke(Player* player); //!< Invokes the effect. 57 57 58 58 private: 59 59 std::list<Rewardable*> rewards_; 60 60 … … 63 63 inline void addRewardable(Rewardable* reward) 64 64 { this->rewards_.push_back(reward); } 65 65 const Rewardable* getRewardables(unsigned int index) const; 66 66 67 67 }; -
code/trunk/src/orxonox/objects/quest/ChangeQuestStatus.h
r2092 r2093 43 43 An effect which changes a quests status. 44 44 @author 45 45 Damian 'Mozork' Frick 46 46 */ 47 47 class ChangeQuestStatus : public QuestEffect 48 48 { 49 49 public: 50 50 ChangeQuestStatus(BaseObject* creator); 51 51 virtual ~ChangeQuestStatus(); 52 52 53 53 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 54 54 55 55 virtual bool invoke(Player* player) = 0; //!< Invokes the effect. 56 56 57 57 protected: 58 58 inline const std::string & getQuestId(void) const //!< Returns the quest id. 59 59 { return this->questId_; } … … 61 61 std::string questId_; //!< The id of the quest the status should be changed of. 62 62 63 64 63 private: 64 void setQuestId(const std::string & id); 65 65 66 66 }; -
code/trunk/src/orxonox/objects/quest/CompleteQuest.cc
r2092 r2093 74 74 try 75 75 { 76 77 78 79 80 81 82 83 76 Quest* quest = QuestManager::findQuest(this->getQuestId()); 77 if(!quest->complete(player)) 78 { 79 return false; 80 } 81 } 82 catch(const Exception& e) 83 { 84 84 COUT(2) << e.getFullDescription() << std::endl; 85 85 return false; 86 86 } 87 87 88 88 return true; 89 89 } 90 90 -
code/trunk/src/orxonox/objects/quest/CompleteQuest.h
r2092 r2093 47 47 class CompleteQuest : public ChangeQuestStatus 48 48 { 49 49 public: 50 50 CompleteQuest(BaseObject* creator); 51 51 virtual ~CompleteQuest(); 52 52 53 53 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 54 54 55 55 virtual bool invoke(Player* player); //!< Invokes the effect. 56 56 57 57 }; -
code/trunk/src/orxonox/objects/quest/FailQuest.cc
r2092 r2093 74 74 try 75 75 { 76 77 78 79 80 81 82 83 76 Quest* quest = QuestManager::findQuest(this->getQuestId()); 77 if(!quest->fail(player)) 78 { 79 return false; 80 } 81 } 82 catch(const Exception& e) 83 { 84 84 COUT(2) << e.getFullDescription() << std::endl; 85 85 return false; 86 86 } 87 87 88 88 return true; 89 89 } 90 90 -
code/trunk/src/orxonox/objects/quest/FailQuest.h
r2092 r2093 43 43 Fails a quest. 44 44 @author 45 45 Damian 'Mozork' Frick 46 46 */ 47 47 class FailQuest : public ChangeQuestStatus 48 48 { 49 49 public: 50 50 FailQuest(BaseObject* creator); 51 51 virtual ~FailQuest(); 52 52 53 53 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 54 54 55 55 virtual bool invoke(Player* player); //!< Invokes the effect. 56 56 57 57 }; -
code/trunk/src/orxonox/objects/quest/GlobalQuest.cc
r2092 r2093 132 132 std::set<Player*>::const_iterator it = this->players_.find((Player*)(void*)player); 133 133 if (it != this->players_.end()) 134 135 136 137 138 139 140 134 { 135 return this->status_; 136 } 137 else 138 { 139 return questStatus::inactive; 140 } 141 141 142 142 } … … 145 145 @brief 146 146 Sets the status for a specific player. 147 147 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. 148 148 @param player 149 149 The player. … … 158 158 { 159 159 return false; 160 160 } 161 161 162 162 std::set<Player*>::const_iterator it = this->players_.find(player); 163 163 if (it == this->players_.end()) //!< Player is not yet in the list. 164 165 166 167 168 164 { 165 this->players_.insert(player); 166 } 167 this->status_ = status; 168 return true; 169 169 } 170 170 -
code/trunk/src/orxonox/objects/quest/GlobalQuest.h
r2092 r2093 48 48 class GlobalQuest : public Quest 49 49 { 50 50 public: 51 51 GlobalQuest(BaseObject* creator); 52 52 virtual ~GlobalQuest(); 53 53 54 54 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 55 55 56 56 protected: 57 57 virtual bool isStartable(const Player* player) const; //!< Checks whether the quest can be started. 58 58 virtual bool isFailable(const Player* player) const; //!< Checks whether the quest can be failed. 59 59 virtual bool isCompletable(const Player* player) const; //!< Checks whether the quest can be completed. 60 60 61 62 61 virtual questStatus::Enum getStatus(const Player* player) const; //!< Returns the status of the quest for a specific player. 62 virtual bool setStatus(Player* player, const questStatus::Enum & status); //!< Sets the status for a specific player. 63 63 64 64 private: 65 65 std::set<Player*> players_; //!< The set of players which possess this quest. 66 66 questStatus::Enum status_; //!< The status of this quest. -
code/trunk/src/orxonox/objects/quest/LocalQuest.cc
r2092 r2093 127 127 128 128 std::map<Player*, questStatus::Enum>::const_iterator it = this->playerStatus_.find((Player*)(void*)player); //Thx. to x3n for the (Player*)(void*) 'hack'. 129 130 131 132 133 129 if (it != this->playerStatus_.end()) 130 { 131 return it->second; 132 } 133 return questStatus::inactive; 134 134 } 135 135 … … 150 150 { 151 151 return false; 152 152 } 153 153 this->playerStatus_[player] = status; 154 154 return true; -
code/trunk/src/orxonox/objects/quest/LocalQuest.h
r2092 r2093 48 48 class LocalQuest : public Quest 49 49 { 50 50 public: 51 51 LocalQuest(BaseObject* creator); 52 52 virtual ~LocalQuest(); 53 53 54 54 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 55 55 56 56 protected: 57 57 virtual bool isStartable(const Player* player) const; //!< Checks whether the quest can be started. 58 58 virtual bool isFailable(const Player* player) const; //!< Checks whether the quest can be failed. … … 62 62 virtual bool setStatus(Player* player, const questStatus::Enum & status); //!< Sets the status for a specific player. 63 63 64 64 private: 65 65 std::map<Player*, questStatus::Enum> playerStatus_; //!< List of the status for each player, with the Player-pointer as key. 66 66 -
code/trunk/src/orxonox/objects/quest/Quest.cc
r2092 r2093 135 135 } 136 136 137 138 139 140 141 137 this->hints_.push_back(hint); 138 hint->setQuest(this); 139 140 COUT(3) << "QuestHint {" << hint->getId() << "} was added to Quest {" << this->getId() << "}." << std::endl; 141 return true; 142 142 } 143 143 … … 195 195 int i = index; 196 196 for (std::list<Quest*>::const_iterator subQuest = this->subQuests_.begin(); subQuest != this->subQuests_.end(); ++subQuest) 197 198 199 200 201 202 203 197 { 198 if(i == 0) 199 { 200 return *subQuest; 201 } 202 i--; 203 } 204 204 return NULL; 205 205 } … … 213 213 int i = index; 214 214 for (std::list<QuestHint*>::const_iterator hint = this->hints_.begin(); hint != this->hints_.end(); ++hint) 215 216 217 218 219 220 221 215 { 216 if(i == 0) 217 { 218 return *hint; 219 } 220 i--; 221 } 222 222 return NULL; 223 223 } … … 231 231 int i = index; 232 232 for (std::list<QuestEffect*>::const_iterator effect = this->failEffects_.begin(); effect != this->failEffects_.end(); ++effect) 233 234 235 236 237 238 239 233 { 234 if(i == 0) 235 { 236 return *effect; 237 } 238 i--; 239 } 240 240 return NULL; 241 241 } … … 249 249 int i = index; 250 250 for (std::list<QuestEffect*>::const_iterator effect = this->completeEffects_.begin(); effect != this->completeEffects_.end(); ++effect) 251 252 253 254 255 256 257 251 { 252 if(i == 0) 253 { 254 return *effect; 255 } 256 i--; 257 } 258 258 return NULL; 259 259 } -
code/trunk/src/orxonox/objects/quest/Quest.h
r2092 r2093 66 66 class Quest : public QuestItem 67 67 { 68 68 public: 69 69 Quest(BaseObject* creator); 70 70 virtual ~Quest(); 71 71 72 72 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 73 73 74 74 inline Quest* getParentQuest(void) const //!< Returns the parent quest of the quest. 75 75 { return this->parentQuest_; } 76 76 inline const std::list<Quest*> & getSubQuestList(void) const //!< Returns the list of sub quests. 77 77 { return this->subQuests_; } 78 78 79 80 81 82 79 bool isInactive(const Player* player) const; //!< Returns true if the quest status for the specific player is 'inactive'. 80 bool isActive(const Player* player) const; //!< Returns true if the quest status for the specific player is 'active'. 81 bool isFailed(const Player* player) const; //!< Returns true if the quest status for the specific player is 'failed'. 82 bool isCompleted(const Player* player) const; //!< Returns true if the quest status for the specific player is 'completed'. 83 83 84 85 86 84 bool start(Player* player); //!< Sets a quest to active. 85 bool fail(Player* player); //!< Fails the quest. 86 bool complete(Player* player); //!< Completes the quest. 87 87 88 88 protected: … … 94 94 95 95 bool setParentQuest(Quest* quest); //!< Sets the parent quest of the quest. 96 97 98 99 96 bool addSubQuest(Quest* quest); //!< Adds a sub quest to the quest. 97 bool addHint(QuestHint* hint); //!< Add a hint to the list of hints. 98 bool addFailEffect(QuestEffect* effect); 99 bool addCompleteEffect(QuestEffect* effect); 100 100 101 102 103 104 105 101 const Quest* getParentQuest(void); 102 const Quest* getSubQuests(unsigned int index) const; 103 const QuestHint* getHints(unsigned int index) const; 104 const QuestEffect* getFailEffects(unsigned int index) const; 105 const QuestEffect* getCompleteEffects(unsigned int index) const; 106 106 107 107 virtual questStatus::Enum getStatus(const Player* player) const = 0; //!< Returns the status of the quest for a specific player. -
code/trunk/src/orxonox/objects/quest/QuestDescription.h
r2092 r2093 46 46 class QuestDescription : public BaseObject { 47 47 48 48 public: 49 49 QuestDescription(BaseObject* creator); 50 50 virtual ~QuestDescription(); 51 51 52 52 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 53 53 54 54 inline const std::string & getTitle(void) const //!< Returns the title. 55 55 { return this->title_; } 56 56 inline const std::string & getDescription(void) const //!< Returns the description text. 57 57 { return this->description_; } 58 58 59 59 private: 60 60 void initialize(void); 61 61 62 62 inline void setTitle(const std::string & title) //!< Sets the title. 63 63 { this->title_ = title; } 64 64 inline void setDescription(const std::string & description) //!< Sets the description text. 65 65 { this->description_ = description; } 66 66 -
code/trunk/src/orxonox/objects/quest/QuestEffect.cc
r2092 r2093 67 67 68 68 for (std::list<QuestEffect*>::iterator effect = effects.begin(); effect != effects.end(); effect++) 69 70 71 72 69 { 70 check = check && (*effect)->invoke(player); 71 } 72 return check; 73 73 } 74 74 -
code/trunk/src/orxonox/objects/quest/QuestEffect.h
r2092 r2093 46 46 class QuestEffect : public BaseObject 47 47 { 48 48 public: 49 49 QuestEffect(BaseObject* creator); 50 50 virtual ~QuestEffect(); 51 51 52 53 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/trunk/src/orxonox/objects/quest/QuestHint.cc
r2092 r2093 64 64 void QuestHint::XMLPort(Element& xmlelement, XMLPort::Mode mode) 65 65 { 66 66 SUPER(QuestHint, XMLPort, xmlelement, mode); 67 67 68 68 COUT(3) << "New QuestHint {" << this->getId() << "} created." << std::endl; 69 69 } 70 70 … … 89 89 90 90 std::map<Player*, questHintStatus::Enum>::iterator it = this->playerStatus_.find(player); 91 92 93 94 95 91 if (it != this->playerStatus_.end()) 92 { 93 return it->second; 94 } 95 return questStatus::inactive; 96 96 } 97 97 … … 108 108 if(this->quest_->isActive(player)) 109 109 { 110 111 112 113 114 115 116 110 if(!(this->isActive(player))) 111 { 112 this->playerStatus_[player] = questHintStatus::active; 113 return true; 114 } 115 else 116 { 117 117 COUT(2) << "An already active questHint was trying to get activated." << std::endl; 118 118 return false; 119 119 } 120 120 } 121 122 121 COUT(2) << "A hint of a non-active quest was trying to get activated." << std::endl; 122 return false; 123 123 } 124 124 -
code/trunk/src/orxonox/objects/quest/QuestHint.h
r2092 r2093 65 65 { 66 66 67 67 public: 68 68 QuestHint(BaseObject* creator); 69 69 virtual ~QuestHint(); 70 70 71 71 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 72 72 73 73 bool isActive(Player* player); //!< Returns true if the hint is active for the input player. 74 74 75 75 bool activate(Player* player); //!< Activates the hint for the input player. 76 76 77 77 bool setQuest(Quest* quest); //!< Sets the quest the hint belongs to. 78 78 79 80 79 inline Quest* getQuest(void) 80 { return this->quest_; } 81 81 82 82 private: -
code/trunk/src/orxonox/objects/quest/QuestItem.cc
r2092 r2093 94 94 Checks whether an input id is of the required form. 95 95 @param id 96 96 The id to be checked. 97 97 @return 98 98 Returns true if the string is likely to be of the required form. -
code/trunk/src/orxonox/objects/quest/QuestItem.h
r2092 r2093 41 41 /** 42 42 @brief 43 44 43 Functions as a base class for Quest classes such as Quest or QuestHint. 44 Has a unique identifier and a description. 45 45 @author 46 46 Damian 'Mozork' Frick 47 47 */ 48 48 class QuestItem : public BaseObject 49 49 { 50 50 51 51 public: 52 52 QuestItem(BaseObject* creator); 53 53 virtual ~QuestItem(); 54 54 55 55 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 56 56 57 57 inline const std::string & getId(void) const //!< Returns the id of this quest. 58 58 { return this->id_; } 59 59 inline const QuestDescription* getDescription(void) const //!< Returns the description of the QuestItem. 60 60 { return this->description_; } 61 61 //const QuestDescription* getDescription(unsigned int index) const; //!< Returns the description of the QuestItem. 62 62 63 63 static bool isId(const std::string & id); //!< Checks whether a given id is valid. 64 64 65 66 67 65 protected: 66 void setId(const std::string & id); 67 inline void setDescription(QuestDescription* description) 68 68 { this->description_ = description; } 69 69 70 71 72 70 private: 71 std::string id_; //!< Identifier. Should be of GUID form: http://en.wikipedia.org/wiki/Globally_Unique_Identifier#Basic_structure 72 QuestDescription* description_; //!< The description of the QuestItem. 73 73 74 74 void initialize(void); //!< Initializes the object. 75 75 76 76 }; -
code/trunk/src/orxonox/objects/quest/QuestManager.cc
r2092 r2093 62 62 COUT(2) << "Registration of Quest in QuestManager failed, because inserted Quest-pointer was NULL." << std::endl; 63 63 return false; 64 64 } 65 65 66 66 std::pair<std::map<std::string, Quest*>::iterator,bool> ret; … … 71 71 COUT(3) << "Quest with questId {" << quest->getId() << "} successfully inserted." << std::endl; 72 72 return true; 73 74 75 76 77 78 73 } 74 else 75 { 76 COUT(2) << "Quest with the same id was already present." << std::endl; 77 return false; 78 } 79 79 } 80 80 … … 102 102 COUT(3) << "QuestHint with hintId {" << hint->getId() << "} successfully inserted." << std::endl; 103 103 return true; 104 105 106 107 108 109 104 } 105 else 106 { 107 COUT(2) << "QuestHint with the same id was already present." << std::endl; 108 return false; 109 } 110 110 } 111 111 … … 124 124 { 125 125 if(!QuestItem::isId(questId)) 126 126 { 127 127 ThrowException(Argument, "Invalid questId."); 128 128 } 129 129 130 130 Quest* quest; 131 131 std::map<std::string, Quest*>::iterator it = questMap_.find(questId); 132 133 134 135 136 137 138 139 140 132 if (it != questMap_.end()) 133 { 134 quest = it->second; 135 } 136 else 137 { 138 quest = NULL; 139 COUT(2) << "The quest with id {" << questId << "} is nowhere to be found." << std::endl; 140 } 141 141 142 142 return quest; 143 143 144 144 } … … 158 158 { 159 159 if(!QuestItem::isId(hintId)) 160 160 { 161 161 ThrowException(Argument, "Invalid hintId."); 162 162 } 163 163 164 164 QuestHint* hint; 165 165 std::map<std::string, QuestHint*>::iterator it = hintMap_.find(hintId); 166 167 168 169 170 171 172 173 174 166 if (it != hintMap_.end()) 167 { 168 hint = it->second; 169 } 170 else 171 { 172 hint = NULL; 173 COUT(2) << "The hint with id {" << hintId << "} is nowhere to be found." << std::endl; 174 } 175 175 176 176 return hint; 177 177 178 178 } -
code/trunk/src/orxonox/objects/quest/QuestManager.h
r2092 r2093 49 49 { 50 50 51 52 53 51 public: 52 QuestManager(BaseObject* creator); 53 virtual ~QuestManager(); 54 54 55 56 55 static bool registerQuest(Quest* quest); //!< Registers a quest in the QuestManager. 56 static bool registerHint(QuestHint* quest); //!< Registers a QuestHint in the QuestManager. 57 57 58 59 58 static Quest* findQuest(const std::string & questId); //!< Returns the quest with the input id. 59 static QuestHint* findHint(const std::string & hintId); //!< Returns the QuestHint with the input id. 60 60 61 62 63 61 private: 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. 64 64 65 65 }; -
code/trunk/src/orxonox/objects/quest/Rewardable.h
r2092 r2093 45 45 { 46 46 47 48 49 47 public: 48 Rewardable(BaseObject* creator); 49 virtual ~Rewardable(); 50 50 51 51 virtual bool reward(Player* player) = 0; //!<Method to transcribe a rewardable object to the player. 52 52 53 53 };
Note: See TracChangeset
for help on using the changeset viewer.