Changeset 5745 for code/trunk/src/modules
- Timestamp:
- Sep 13, 2009, 3:04:02 PM (15 years ago)
- Location:
- code/trunk/src/modules/questsystem
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/modules/questsystem/CMakeLists.txt
r5738 r5745 12 12 QuestEffect.cc 13 13 QuestEffectBeacon.cc 14 QuestGUINode.cc 15 QuestGUI.cc 14 16 QuestHint.cc 15 17 QuestItem.cc -
code/trunk/src/modules/questsystem/QuestManager.cc
r5738 r5745 37 37 #include "core/CoreIncludes.h" 38 38 #include "core/GUIManager.h" 39 #include "core/ConsoleCommand.h" 40 #include "core/input/InputManager.h" //TDO: Necessary? 41 #include <CEGUIWindow.h> 42 #include "overlays/GUIOverlay.h" 39 43 40 44 #include "infos/PlayerInfo.h" 41 45 #include "Quest.h" 42 46 #include "QuestHint.h" 43 #include "QuestItem.h" 47 #include "QuestItem.h" //TDO: Necessary? 44 48 45 49 namespace orxonox … … 65 69 QuestManager::~QuestManager() 66 70 { 71 for(std::map<PlayerInfo*, QuestGUI*>::iterator it = this->questGUIs_.begin(); it != this->questGUIs_.end(); it++) 72 { 73 delete (*it).second; 74 } 75 this->questGUIs_.clear(); 76 } 77 78 /** 79 @brief 80 Retreive all Quests. 81 @return 82 Returns a map with all Quests indexed by their id's. 83 */ 84 std::map<std::string, Quest*> & QuestManager::getQuests(void) 85 { 86 return this->questMap_; 67 87 } 68 88 … … 201 221 /** 202 222 @brief 203 204 @param name 205 @return 206 */ 207 QuestContainer* QuestManager::getQuestTree(std::string & name) 208 { 209 PlayerInfo* player = GUIManager::getInstance().getPlayer(name); 223 Retreive the main window for the GUI. 224 This is for the use in the lua script tu start the QuestGUI. 225 @param guiName 226 The name of the GUI. 227 @return 228 Returns a CEGUI Window. 229 */ 230 CEGUI::Window* QuestManager::getQuestGUI(const std::string & guiName) 231 { 232 PlayerInfo* player = this->retreivePlayer(guiName); 233 234 if(this->questGUIs_.find(player) == this->questGUIs_.end()) //!< Create a new GUI, if there is none, yet. 235 this->questGUIs_[player] = new QuestGUI(player); 236 237 return this->questGUIs_[player]->getGUI(); 238 } 239 240 /** 241 @brief 242 Retrieve the player for a certain GUI. 243 @param guiName 244 The name of the GUI the player is retrieved for. 245 @return 246 Returns the player. 247 @todo 248 This very well might be outdated. So: Check if still needed, and update if necessary. 249 */ 250 PlayerInfo* QuestManager::retreivePlayer(const std::string & guiName) 251 { 252 PlayerInfo* player = GUIManager::getInstance().getPlayer(guiName); 210 253 if(player == NULL) 211 254 { 212 COUT(1) << "Error: GUIOverlay with name '" << name << "' has no player." << std::endl;255 COUT(1) << "Error: GUIOverlay with name '" << guiName << "' has no player." << std::endl; 213 256 return NULL; 214 257 } 215 258 216 QuestContainer* root = NULL; 217 QuestContainer* current = NULL; 218 219 std::list<Quest*>* rootQuests = new std::list<Quest*>(); 220 getRootQuests(player, *rootQuests); 221 222 for(std::list<Quest*>::iterator it = rootQuests->begin(); it != rootQuests->end(); it++) 223 { 224 QuestContainer* container = addSubQuest(*it, player); 225 226 if(root == NULL) 227 { 228 root = container; 229 } 230 else 231 { 232 current->next = container; 233 } 234 235 current = container; 236 237 } 238 if(current != NULL) 239 current->next = NULL; 240 241 delete rootQuests; 242 243 return root; 244 } 245 246 /** 247 @brief 248 249 @param player 250 @param list 251 @return 252 */ 253 void QuestManager::getRootQuests(const PlayerInfo* player, std::list<Quest*> & list) 254 { 255 for(std::map<std::string, Quest*>::iterator it=this->questMap_.begin(); it!=this->questMap_.end(); it++) 256 { 257 Quest* quest = (*it).second; 258 if(quest->getParentQuest() == NULL && !quest->isInactive(player)) 259 { 260 list.push_back(quest); 261 } 262 } 263 } 264 265 /** 266 @brief 267 268 @param quest 269 @param player 270 @return 271 */ 272 QuestContainer* QuestManager::addSubQuest(Quest* quest, const PlayerInfo* player) 273 { 274 if(quest == NULL) 275 return NULL; 276 277 QuestContainer* container = new QuestContainer; 278 container->description = quest->getDescription(); 279 container->hint = addHints(quest, player); 280 281 if(quest->isActive(player)) 282 { 283 container->status = "active"; 284 } 285 else if(quest->isCompleted(player)) 286 { 287 container->status = "completed"; 288 } 289 else if(quest->isFailed(player)) 290 { 291 container->status = "failed"; 292 } 293 else 294 { 295 container->status = ""; 296 COUT(1) << "An error occurred. A Quest of un-specified status wanted to be displayed." << std::endl; 297 } 298 299 std::list<Quest*> quests = quest->getSubQuestList(); 300 QuestContainer* current = NULL; 301 QuestContainer* first = NULL; 302 for(std::list<Quest*>::iterator it = quests.begin(); it != quests.end(); it++) 303 { 304 Quest* subQuest = *it; 305 if(!subQuest->isInactive(player)) 306 { 307 QuestContainer* subContainer = addSubQuest(subQuest, player); 308 309 if(first == NULL) 310 { 311 first = subContainer; 312 } 313 else 314 { 315 current->next = subContainer; 316 } 317 318 current = subContainer; 319 } 320 } 321 if(current != NULL) 322 current->next = NULL; 323 container->subQuests = first; 324 325 return container; 326 } 327 328 /** 329 @brief 330 331 @param quest 332 @param player 333 @return 334 */ 335 HintContainer* QuestManager::addHints(Quest* quest, const PlayerInfo* player) 336 { 337 HintContainer* current = NULL; 338 HintContainer* first = NULL; 339 340 std::list<QuestHint*> hints = quest->getHintsList(); 341 for(std::list<QuestHint*>::iterator it = hints.begin(); it != hints.end(); it++) 342 { 343 if((*it)->isActive(player)) 344 { 345 HintContainer* hint = new HintContainer; 346 hint->description = (*it)->getDescription(); 347 348 if(first == NULL) 349 { 350 first = hint; 351 } 352 else 353 { 354 current->next = hint; 355 } 356 357 current = hint; 358 } 359 } 360 361 if(current != NULL) 362 current->next = NULL; 363 return first; 364 } 365 259 return player; 260 } 366 261 367 262 } -
code/trunk/src/modules/questsystem/QuestManager.h
r5738 r5745 36 36 37 37 #include "questsystem/QuestsystemPrereqs.h" 38 #include <CEGUIForwardRefs.h> 38 39 39 40 #include <list> … … 44 45 #include "core/OrxonoxClass.h" 45 46 47 #include "QuestGUI.h" 48 46 49 // tolua_begin 47 50 namespace orxonox 48 51 { 49 50 struct QuestContainer;51 struct HintContainer;52 53 struct QuestContainer54 {55 const QuestDescription* description;56 std::string status;57 HintContainer* hint;58 QuestContainer* subQuests;59 QuestContainer* next;60 };61 62 struct HintContainer63 {64 const QuestDescription* description;65 HintContainer* next;66 };67 52 68 53 typedef ScopedSingleton<QuestManager, ScopeID::GSLevel> ScopedSingletonQuestManagerGSLevel; // workaround for tolua … … 78 63 { 79 64 // tolua_end 65 80 66 friend class ScopedSingleton<QuestManager, ScopeID::GSLevel>; 67 friend class QuestGUI; //TDO: better solution. 68 //friend std::map<std::string, Quest*> & QuestGUI::getQuests(void); 69 81 70 public: 82 71 QuestManager(); … … 86 75 static QuestManager& getInstance() { return ScopedSingleton<QuestManager, ScopeID::GSLevel>::getInstance(); } // tolua_export 87 76 77 //! Retreive the main window for the GUI. 78 CEGUI::Window* getQuestGUI(const std::string & guiName); // tolua_export 79 88 80 bool registerQuest(Quest* quest); //!< Registers a Quest in the QuestManager. 89 81 bool registerHint(QuestHint* quest); //!< Registers a QuestHint in the QuestManager. … … 92 84 QuestHint* findHint(const std::string & hintId); //!< Returns the QuestHint with the input id. 93 85 94 QuestContainer* getQuestTree(std::string & name); // tolua_export 86 protected: 87 std::map<std::string, Quest*> & getQuests(void); //!< Retreive all Quests. 95 88 96 89 private: 97 90 static QuestManager* singletonPtr_s; 91 PlayerInfo* retreivePlayer(const std::string & guiName); //!< Retrieve the player for a certain GUI. 98 92 99 93 std::map<std::string, Quest*> questMap_; //!< All Quests registered by their id's. 100 94 std::map<std::string, QuestHint*> hintMap_; //!< All QuestHints registered by their id's. 101 95 102 void getRootQuests(const PlayerInfo* player, std::list<Quest*> & list); 103 HintContainer* addHints(Quest* quest, const PlayerInfo* player); 104 QuestContainer* addSubQuest(Quest* quest, const PlayerInfo* player); 96 //TDO: Call destructor of QuestGUI's on destruction of QuestManager? 97 std::map<PlayerInfo*, QuestGUI*> questGUIs_; //!< All GUI's registered by the players. 105 98 106 99 }; // tolua_export -
code/trunk/src/modules/questsystem/QuestsystemPrereqs.h
r5738 r5745 76 76 class QuestEffect; 77 77 class QuestEffectBeacon; 78 class QuestGUINode; 79 class QuestGUI; 78 80 class QuestHint; 79 81 class QuestItem;
Note: See TracChangeset
for help on using the changeset viewer.