Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/pickups2/src/orxonox/objects/quest/QuestManager.cc @ 2972

Last change on this file since 2972 was 2917, checked in by landauf, 16 years ago

merged pickup into pickup2

File size: 6.3 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/**
[2911]30    @file QuestManager.cc
[2662]31    @brief Implementation of the QuestManager class.
[2261]32*/
33
[2105]34#include "OrxonoxStableHeaders.h"
35#include "QuestManager.h"
36
[1996]37#include "core/CoreIncludes.h"
[2105]38
[2068]39#include "util/Exception.h"
[2095]40#include "Quest.h"
41#include "QuestHint.h"
[1996]42
[2662]43namespace orxonox
44{
[2911]45    //! Pointer to the current (and single) instance of this class.
46    QuestManager* QuestManager::singletonRef_s = NULL;
[1996]47
[2261]48    /**
49    @brief
50        Constructor. Registers the object.
[2911]51    @todo
52        Is inheriting from BaseObject proper?
[2261]53    */
[2911]54    QuestManager::QuestManager()
[1996]55    {
[2911]56        RegisterRootObject(QuestManager);
57
58        assert(singletonRef_s == 0);
59        singletonRef_s = this;
[1996]60    }
[2092]61
[2261]62    /**
63    @brief
64        Destructor.
65    */
[1996]66    QuestManager::~QuestManager()
67    {
[2092]68
[1996]69    }
70
71    /**
72    @brief
[2911]73        Returns a reference to the current (and single) instance of the QuestManager, and creates one if there isn't one to begin with.
74    @return
75        Returns a reference to the single instance of the Quest Manager.
76    */
77    /*static*/ QuestManager & QuestManager::getInstance()
78    {
79        assert(singletonRef_s);
80        return *singletonRef_s;
81    }
82
83    /**
84    @brief
[2261]85        Registers a Quest with the QuestManager to make it globally accessable.
86        Uses it's id to make sure to be able to be identify and retrieve it later.
[1996]87    @param quest
[2261]88        The Quest that is to be registered.
[1996]89    @return
90        Returns true if successful, false if not.
91    */
[2911]92    bool QuestManager::registerQuest(Quest* quest)
[1996]93    {
[2261]94        if(quest == NULL) //!< Doh! Just as if there were actual quests behind NULL-pointers.
[2068]95        {
96            COUT(2) << "Registration of Quest in QuestManager failed, because inserted Quest-pointer was NULL." << std::endl;
97            return false;
[2093]98        }
[2092]99
[2261]100        std::pair<std::map<std::string, Quest*>::iterator,bool> result;
[2911]101        result = this->questMap_.insert( std::pair<std::string,Quest*>(quest->getId(),quest) ); //!< Inserting the Quest.
[2092]102
[2261]103        if(result.second) //!< If inserting was a success.
[2068]104        {
105            COUT(3) << "Quest with questId {" << quest->getId() << "} successfully inserted." << std::endl;
106            return true;
[2093]107        }
108        else
109        {
110           COUT(2) << "Quest with the same id was already present." << std::endl;
111           return false;
112        }
[1996]113    }
[2092]114
[1996]115    /**
116    @brief
117        Registers a QuestHint with the QuestManager to make it globally accessable.
[2261]118        Uses it's id to make sure to be able to be identify and retrieve it later.
[1996]119    @param hint
120        The QuestHint to be registered.
121    @return
122        Returns true if successful, false if not.
123    */
[2911]124    bool QuestManager::registerHint(QuestHint* hint)
[1996]125    {
[2261]126        if(hint == NULL) //!< Still not liking NULL-pointers.
[2068]127        {
128            COUT(2) << "Registration of QuestHint in QuestManager failed, because inserted QuestHint-pointer was NULL." << std::endl;
129            return false;
130        }
[2092]131
[2261]132        std::pair<std::map<std::string, QuestHint*>::iterator,bool> result;
[2911]133        result = this->hintMap_.insert ( std::pair<std::string,QuestHint*>(hint->getId(),hint) ); //!< Inserting the QuestHSint.
[2092]134
[2261]135        if(result.second) //!< If inserting was a success.
[2068]136        {
137            COUT(3) << "QuestHint with hintId {" << hint->getId() << "} successfully inserted." << std::endl;
138            return true;
[2093]139        }
140        else
141        {
142           COUT(2) << "QuestHint with the same id was already present." << std::endl;
143           return false;
144        }
[1996]145    }
[2092]146
[1996]147    /**
148    @brief
[2261]149        Finds a Quest with the given id.
[1996]150    @param questId
[2261]151        The id of the Quest sought for.
[1996]152    @return
[2261]153        Returns a pointer to the Quest with the input id.
154        Returns NULL if there is no Quest with the given questId.
[2068]155    @throws
156        Throws an exception if the given questId is invalid.
[1996]157    */
[2911]158    Quest* QuestManager::findQuest(const std::string & questId)
[1996]159    {
[2261]160        if(!QuestItem::isId(questId)) //!< Check vor validity of the given id.
[2093]161        {
[2068]162            ThrowException(Argument, "Invalid questId.");
[2093]163        }
[2092]164
[1996]165        Quest* quest;
[2911]166        std::map<std::string, Quest*>::iterator it = this->questMap_.find(questId);
167        if (it != this->questMap_.end()) //!< If the Quest is registered.
[2093]168        {
169            quest = it->second;
170        }
171        else
172        {
173           quest = NULL;
174           COUT(2) << "The quest with id {" << questId << "} is nowhere to be found." << std::endl;
175        }
[2092]176
[2093]177        return quest;
[1996]178
179    }
[2092]180
[1996]181    /**
182    @brief
[2261]183        Finds a QuestHint with the given id.
[1996]184    @param hintId
[2261]185        The id of the QuestHint sought for.
[1996]186    @return
[2261]187        Returns a pointer to the QuestHint with the input id.
188        Returns NULL if there is no QuestHint with the given hintId.
[2068]189    @throws
190        Throws an exception if the given hintId is invalid.
[1996]191    */
[2911]192    QuestHint* QuestManager::findHint(const std::string & hintId)
[1996]193    {
[2261]194        if(!QuestItem::isId(hintId)) //!< Check vor validity of the given id.
[2093]195        {
[2068]196            ThrowException(Argument, "Invalid hintId.");
[2093]197        }
[2092]198
[1996]199        QuestHint* hint;
[2911]200        std::map<std::string, QuestHint*>::iterator it = this->hintMap_.find(hintId);
201        if (it != this->hintMap_.end()) //!< If the QuestHint is registered.
[2093]202        {
203            hint = it->second;
204        }
205        else
206        {
207           hint = NULL;
208           COUT(2) << "The hint with id {" << hintId << "} is nowhere to be found." << std::endl;
209        }
[2092]210
[2093]211        return hint;
[1996]212
213    }
214
[2092]215
[1996]216}
Note: See TracBrowser for help on using the repository browser.