Changeset 2785 for code/branches/questsystem5/src/orxonox/objects
- Timestamp:
- Mar 15, 2009, 11:41:25 AM (16 years ago)
- Location:
- code/branches/questsystem5/src/orxonox/objects/quest
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/questsystem5/src/orxonox/objects/quest/AddQuest.cc
r2779 r2785 97 97 try 98 98 { 99 Quest* quest = QuestManager:: findQuest(this->getQuestId());99 Quest* quest = QuestManager::getInstance().findQuest(this->getQuestId()); 100 100 if(quest == NULL || !quest->start(player)) 101 101 { -
code/branches/questsystem5/src/orxonox/objects/quest/AddQuestHint.cc
r2779 r2785 117 117 try 118 118 { 119 QuestHint* hint = QuestManager:: findHint(this->hintId_);119 QuestHint* hint = QuestManager::getInstance().findHint(this->hintId_); 120 120 if(hint == NULL || !hint->setActive(player)) 121 121 { -
code/branches/questsystem5/src/orxonox/objects/quest/CompleteQuest.cc
r2779 r2785 96 96 try 97 97 { 98 quest = QuestManager:: findQuest(this->getQuestId());98 quest = QuestManager::getInstance().findQuest(this->getQuestId()); 99 99 if(quest == NULL || !quest->complete(player)) 100 100 { -
code/branches/questsystem5/src/orxonox/objects/quest/FailQuest.cc
r2779 r2785 95 95 try 96 96 { 97 quest = QuestManager:: findQuest(this->getQuestId());97 quest = QuestManager::getInstance().findQuest(this->getQuestId()); 98 98 if(quest == NULL || !quest->fail(player)) 99 99 { -
code/branches/questsystem5/src/orxonox/objects/quest/Quest.cc
r2779 r2785 79 79 XMLPortObject(Quest, QuestEffect, "complete-effects", addCompleteEffect, getCompleteEffect, xmlelement, mode); 80 80 81 QuestManager:: registerQuest(this); //!<Registers the Quest with the QuestManager.81 QuestManager::getInstance().registerQuest(this); //!<Registers the Quest with the QuestManager. 82 82 } 83 83 -
code/branches/questsystem5/src/orxonox/objects/quest/QuestHint.cc
r2779 r2785 73 73 SUPER(QuestHint, XMLPort, xmlelement, mode); 74 74 75 QuestManager:: registerHint(this); //!< Registers the QuestHint with the QuestManager.75 QuestManager::getInstance().registerHint(this); //!< Registers the QuestHint with the QuestManager. 76 76 77 77 COUT(3) << "New QuestHint {" << this->getId() << "} created." << std::endl; -
code/branches/questsystem5/src/orxonox/objects/quest/QuestListener.cc
r2779 r2785 112 112 bool QuestListener::setQuestId(const std::string & id) 113 113 { 114 this->quest_ = QuestManager:: findQuest(id); //!< Find the Quest corresponding to the given questId.114 this->quest_ = QuestManager::getInstance().findQuest(id); //!< Find the Quest corresponding to the given questId. 115 115 116 116 if(this->quest_ == NULL) //!< If there is no such Quest. -
code/branches/questsystem5/src/orxonox/objects/quest/QuestManager.cc
r2779 r2785 43 43 namespace orxonox 44 44 { 45 //! All Quests registered by their id's. 46 std::map<std::string, Quest*> QuestManager::questMap_s; 47 //! All QuestHints registered by their id's. 48 std::map<std::string, QuestHint*> QuestManager::hintMap_s; 45 //! Pointer to the current (and single) instance of this class. 46 QuestManager* QuestManager::singletonRef_s = NULL; 49 47 50 48 /** 51 49 @brief 52 50 Constructor. Registers the object. 53 */ 54 QuestManager::QuestManager(BaseObject* creator) : BaseObject(creator) 55 { 56 RegisterObject(QuestManager); 51 @todo 52 Is inheriting from BaseObject proper? 53 */ 54 QuestManager::QuestManager() : BaseObject(this) 55 { 56 RegisterRootObject(QuestManager); 57 57 58 } 58 59 … … 64 65 { 65 66 67 } 68 69 /** 70 @brief 71 Returns a reference to the current (and single) instance of the QuestManager, and creates one if there isn't one to begin with. 72 @return 73 Returns a reference to the single instance of the Quest Manager. 74 */ 75 /*static*/ QuestManager & QuestManager::getInstance() 76 { 77 if(singletonRef_s == NULL) 78 { 79 singletonRef_s = new QuestManager(); 80 } 81 return *singletonRef_s; 66 82 } 67 83 … … 75 91 Returns true if successful, false if not. 76 92 */ 77 /*static*/bool QuestManager::registerQuest(Quest* quest)93 bool QuestManager::registerQuest(Quest* quest) 78 94 { 79 95 if(quest == NULL) //!< Doh! Just as if there were actual quests behind NULL-pointers. … … 84 100 85 101 std::pair<std::map<std::string, Quest*>::iterator,bool> result; 86 result = questMap_s.insert( std::pair<std::string,Quest*>(quest->getId(),quest) ); //!< Inserting the Quest.102 result = this->questMap_.insert( std::pair<std::string,Quest*>(quest->getId(),quest) ); //!< Inserting the Quest. 87 103 88 104 if(result.second) //!< If inserting was a success. … … 107 123 Returns true if successful, false if not. 108 124 */ 109 /*static*/bool QuestManager::registerHint(QuestHint* hint)125 bool QuestManager::registerHint(QuestHint* hint) 110 126 { 111 127 if(hint == NULL) //!< Still not liking NULL-pointers. … … 116 132 117 133 std::pair<std::map<std::string, QuestHint*>::iterator,bool> result; 118 result = hintMap_s.insert ( std::pair<std::string,QuestHint*>(hint->getId(),hint) ); //!< Inserting the QuestHSint.134 result = this->hintMap_.insert ( std::pair<std::string,QuestHint*>(hint->getId(),hint) ); //!< Inserting the QuestHSint. 119 135 120 136 if(result.second) //!< If inserting was a success. … … 141 157 Throws an exception if the given questId is invalid. 142 158 */ 143 /*static*/Quest* QuestManager::findQuest(const std::string & questId)159 Quest* QuestManager::findQuest(const std::string & questId) 144 160 { 145 161 if(!QuestItem::isId(questId)) //!< Check vor validity of the given id. … … 149 165 150 166 Quest* quest; 151 std::map<std::string, Quest*>::iterator it = questMap_s.find(questId);152 if (it != questMap_s.end()) //!< If the Quest is registered.167 std::map<std::string, Quest*>::iterator it = this->questMap_.find(questId); 168 if (it != this->questMap_.end()) //!< If the Quest is registered. 153 169 { 154 170 quest = it->second; … … 175 191 Throws an exception if the given hintId is invalid. 176 192 */ 177 /*static*/QuestHint* QuestManager::findHint(const std::string & hintId)193 QuestHint* QuestManager::findHint(const std::string & hintId) 178 194 { 179 195 if(!QuestItem::isId(hintId)) //!< Check vor validity of the given id. … … 183 199 184 200 QuestHint* hint; 185 std::map<std::string, QuestHint*>::iterator it = hintMap_s.find(hintId);186 if (it != hintMap_s.end()) //!< If the QuestHint is registered.201 std::map<std::string, QuestHint*>::iterator it = this->hintMap_.find(hintId); 202 if (it != this->hintMap_.end()) //!< If the QuestHint is registered. 187 203 { 188 204 hint = it->second; -
code/branches/questsystem5/src/orxonox/objects/quest/QuestManager.h
r2779 r2785 46 46 /** 47 47 @brief 48 Is a static classand manages Quests, by registering every Quest/QuestHint (through registerX()) and making them globally accessable (through findX()).48 Is a Singleton and manages Quests, by registering every Quest/QuestHint (through registerX()) and making them globally accessable (through findX()). 49 49 Quests (and QuestHints) are registered in the QuestManager with their id, and can be accessed in the same way. 50 50 @author … … 54 54 { 55 55 56 protected: 57 QuestManager(); 58 56 59 public: 57 QuestManager(BaseObject* creator);58 60 virtual ~QuestManager(); 59 61 60 static bool registerQuest(Quest* quest); //!< Registers a Quest in the QuestManager. 61 static bool registerHint(QuestHint* quest); //!< Registers a QuestHint in the QuestManager. 62 static QuestManager& getInstance(); //!< Returns a reference to the single instance of the Quest Manager. 62 63 63 static Quest* findQuest(const std::string & questId); //!< Returns the Quest with the input id. 64 static QuestHint* findHint(const std::string & hintId); //!< Returns the QuestHint with the input id. 64 bool registerQuest(Quest* quest); //!< Registers a Quest in the QuestManager. 65 bool registerHint(QuestHint* quest); //!< Registers a QuestHint in the QuestManager. 66 67 Quest* findQuest(const std::string & questId); //!< Returns the Quest with the input id. 68 QuestHint* findHint(const std::string & hintId); //!< Returns the QuestHint with the input id. 65 69 66 70 private: 67 static std::map<std::string, Quest*> questMap_s; //!< All Quests registered by their id's. 68 static std::map<std::string, QuestHint*> hintMap_s; //!< All QuestHints registered by their id's. 71 static QuestManager* singletonRef_s; 72 73 std::map<std::string, Quest*> questMap_; //!< All Quests registered by their id's. 74 std::map<std::string, QuestHint*> hintMap_; //!< All QuestHints registered by their id's. 69 75 70 76 };
Note: See TracChangeset
for help on using the changeset viewer.