Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/modules/questsystem/QuestManager.cc @ 5748

Last change on this file since 5748 was 5748, checked in by rgrieder, 16 years ago

In quest system:

  • Build fix (non-void function must return a value)
  • Removed some header files to reduce compile time
  • svn:eol-style "native" for the added files
  • removed svn:executable property from QuestNotification.cc
  • Property svn:eol-style set to native
File size: 7.7 KB
RevLine 
[1996]1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
23 *      Damian 'Mozork' Frick
24 *   Co-authors:
25 *      ...
26 *
27 */
28
[2261]29/**
[3196]30    @file
[2662]31    @brief Implementation of the QuestManager class.
[2261]32*/
33
[2105]34#include "QuestManager.h"
35
[5748]36#include <CEGUIWindow.h>
37
[3196]38#include "util/Exception.h"
[1996]39#include "core/CoreIncludes.h"
[5693]40#include "core/GUIManager.h"
[5745]41#include "core/ConsoleCommand.h"
[5748]42#include "infos/PlayerInfo.h"
[5745]43#include "overlays/GUIOverlay.h"
[2105]44
[2095]45#include "Quest.h"
46#include "QuestHint.h"
[5748]47#include "QuestItem.h"
[1996]48
[2662]49namespace orxonox
50{
[2911]51    //! Pointer to the current (and single) instance of this class.
[3370]52    /*static*/ QuestManager* QuestManager::singletonPtr_s = NULL;
[1996]53
[2261]54    /**
55    @brief
56        Constructor. Registers the object.
[2911]57    @todo
58        Is inheriting from BaseObject proper?
[2261]59    */
[2911]60    QuestManager::QuestManager()
[1996]61    {
[2911]62        RegisterRootObject(QuestManager);
[1996]63    }
[2092]64
[2261]65    /**
66    @brief
67        Destructor.
68    */
[1996]69    QuestManager::~QuestManager()
70    {
[5745]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();
[1996]76    }
77
78    /**
79    @brief
[5745]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_;
87    }
88
89    /**
90    @brief
[2261]91        Registers a Quest with the QuestManager to make it globally accessable.
92        Uses it's id to make sure to be able to be identify and retrieve it later.
[1996]93    @param quest
[2261]94        The Quest that is to be registered.
[1996]95    @return
96        Returns true if successful, false if not.
97    */
[2911]98    bool QuestManager::registerQuest(Quest* quest)
[1996]99    {
[2261]100        if(quest == NULL) //!< Doh! Just as if there were actual quests behind NULL-pointers.
[2068]101        {
102            COUT(2) << "Registration of Quest in QuestManager failed, because inserted Quest-pointer was NULL." << std::endl;
103            return false;
[2093]104        }
[2092]105
[2261]106        std::pair<std::map<std::string, Quest*>::iterator,bool> result;
[2911]107        result = this->questMap_.insert( std::pair<std::string,Quest*>(quest->getId(),quest) ); //!< Inserting the Quest.
[2092]108
[2261]109        if(result.second) //!< If inserting was a success.
[2068]110        {
111            COUT(3) << "Quest with questId {" << quest->getId() << "} successfully inserted." << std::endl;
112            return true;
[2093]113        }
114        else
115        {
116           COUT(2) << "Quest with the same id was already present." << std::endl;
117           return false;
118        }
[1996]119    }
[2092]120
[1996]121    /**
122    @brief
123        Registers a QuestHint with the QuestManager to make it globally accessable.
[2261]124        Uses it's id to make sure to be able to be identify and retrieve it later.
[1996]125    @param hint
126        The QuestHint to be registered.
127    @return
128        Returns true if successful, false if not.
129    */
[2911]130    bool QuestManager::registerHint(QuestHint* hint)
[1996]131    {
[2261]132        if(hint == NULL) //!< Still not liking NULL-pointers.
[2068]133        {
134            COUT(2) << "Registration of QuestHint in QuestManager failed, because inserted QuestHint-pointer was NULL." << std::endl;
135            return false;
136        }
[2092]137
[2261]138        std::pair<std::map<std::string, QuestHint*>::iterator,bool> result;
[2911]139        result = this->hintMap_.insert ( std::pair<std::string,QuestHint*>(hint->getId(),hint) ); //!< Inserting the QuestHSint.
[2092]140
[2261]141        if(result.second) //!< If inserting was a success.
[2068]142        {
143            COUT(3) << "QuestHint with hintId {" << hint->getId() << "} successfully inserted." << std::endl;
144            return true;
[2093]145        }
146        else
147        {
148           COUT(2) << "QuestHint with the same id was already present." << std::endl;
149           return false;
150        }
[1996]151    }
[2092]152
[1996]153    /**
154    @brief
[2261]155        Finds a Quest with the given id.
[1996]156    @param questId
[2261]157        The id of the Quest sought for.
[1996]158    @return
[2261]159        Returns a pointer to the Quest with the input id.
160        Returns NULL if there is no Quest with the given questId.
[2068]161    @throws
162        Throws an exception if the given questId is invalid.
[1996]163    */
[2911]164    Quest* QuestManager::findQuest(const std::string & questId)
[1996]165    {
[2261]166        if(!QuestItem::isId(questId)) //!< Check vor validity of the given id.
[2093]167        {
[2068]168            ThrowException(Argument, "Invalid questId.");
[2093]169        }
[2092]170
[1996]171        Quest* quest;
[2911]172        std::map<std::string, Quest*>::iterator it = this->questMap_.find(questId);
173        if (it != this->questMap_.end()) //!< If the Quest is registered.
[2093]174        {
175            quest = it->second;
176        }
177        else
178        {
179           quest = NULL;
180           COUT(2) << "The quest with id {" << questId << "} is nowhere to be found." << std::endl;
181        }
[2092]182
[2093]183        return quest;
[1996]184
185    }
[2092]186
[1996]187    /**
188    @brief
[2261]189        Finds a QuestHint with the given id.
[1996]190    @param hintId
[2261]191        The id of the QuestHint sought for.
[1996]192    @return
[2261]193        Returns a pointer to the QuestHint with the input id.
194        Returns NULL if there is no QuestHint with the given hintId.
[2068]195    @throws
196        Throws an exception if the given hintId is invalid.
[1996]197    */
[2911]198    QuestHint* QuestManager::findHint(const std::string & hintId)
[1996]199    {
[2261]200        if(!QuestItem::isId(hintId)) //!< Check vor validity of the given id.
[2093]201        {
[2068]202            ThrowException(Argument, "Invalid hintId.");
[2093]203        }
[2092]204
[1996]205        QuestHint* hint;
[2911]206        std::map<std::string, QuestHint*>::iterator it = this->hintMap_.find(hintId);
207        if (it != this->hintMap_.end()) //!< If the QuestHint is registered.
[2093]208        {
209            hint = it->second;
210        }
211        else
212        {
213           hint = NULL;
214           COUT(2) << "The hint with id {" << hintId << "} is nowhere to be found." << std::endl;
215        }
[2092]216
[2093]217        return hint;
[1996]218
219    }
220
[2993]221    /**
222    @brief
[5745]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.
[2993]227    @return
[5745]228        Returns a CEGUI Window.
[2993]229    */
[5745]230    CEGUI::Window* QuestManager::getQuestGUI(const std::string & guiName)
[2963]231    {
[5745]232        PlayerInfo* player = this->retreivePlayer(guiName);
[5693]233
[5745]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);
[5693]236
[5745]237        return this->questGUIs_[player]->getGUI();
[2963]238    }
239
[2993]240    /**
241    @brief
[5745]242        Retrieve the player for a certain GUI.
243    @param guiName
244        The name of the GUI the player is retrieved for.
[2993]245    @return
[5745]246        Returns the player.
247    @todo
248        This very well might be outdated. So: Check if still needed, and update if necessary.
[2993]249    */
[5745]250    PlayerInfo* QuestManager::retreivePlayer(const std::string & guiName)
[2963]251    {
[5745]252        PlayerInfo* player = GUIManager::getInstance().getPlayer(guiName);
253        if(player == NULL)
[2963]254        {
[5745]255            COUT(1) << "Error: GUIOverlay with name '" << guiName << "' has no player." << std::endl;
[2993]256            return NULL;
257        }
[5693]258
[5745]259        return player;
[2963]260    }
261
[1996]262}
Note: See TracBrowser for help on using the repository browser.