Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/orxonox/objects/quest/QuestManager.cc @ 2488

Last change on this file since 2488 was 2261, checked in by landauf, 16 years ago

merged questsystem2 back to trunk

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