Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/questsystem5/src/orxonox/objects/quest/QuestManager.cc @ 2785

Last change on this file since 2785 was 2785, checked in by dafrick, 15 years ago

Made QuestManager and NotificationManager to Singletons. Fixed/Changed som other stuff I don't remember…

  • Property svn:eol-style set to native
  • Property svn:mergeinfo set to (toggle deleted branches)
    /code/branches/lodfinal/src/orxonox/objects/quest/QuestManager.ccmergedeligible
    /code/trunk/src/orxonox/objects/quest/QuestManager.ccmergedeligible
    /code/branches/buildsystem2/src/orxonox/objects/quest/QuestManager.cc2506-2658
    /code/branches/buildsystem3/src/orxonox/objects/quest/QuestManager.cc2662-2708
    /code/branches/network/src/orxonox/objects/quest/QuestManager.cc2356
    /code/branches/network64/src/orxonox/objects/quest/QuestManager.cc2210-2355
    /code/branches/objecthierarchy2/src/orxonox/objects/quest/QuestManager.cc2171-2479
    /code/branches/overlay/src/orxonox/objects/quest/QuestManager.cc2117-2385
    /code/branches/physics/src/orxonox/objects/quest/QuestManager.cc2107-2439
    /code/branches/physics_merge/src/orxonox/objects/quest/QuestManager.cc2436-2457
    /code/branches/pickups2/src/orxonox/objects/quest/QuestManager.cc2107-2497
    /code/branches/presentation/src/orxonox/objects/quest/QuestManager.cc2369-2652,​2654-2660
    /code/branches/questsystem2/src/orxonox/objects/quest/QuestManager.cc2107-2259
    /code/branches/weapon2/src/orxonox/objects/quest/QuestManager.cc2107-2488
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/**
[2779]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{
[2785]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.
[2785]51    @todo
52        Is inheriting from BaseObject proper?
[2261]53    */
[2785]54    QuestManager::QuestManager() : BaseObject(this)
[1996]55    {
[2785]56        RegisterRootObject(QuestManager);
57
[1996]58    }
[2092]59
[2261]60    /**
61    @brief
62        Destructor.
63    */
[1996]64    QuestManager::~QuestManager()
65    {
[2092]66
[1996]67    }
68
69    /**
70    @brief
[2785]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;
82    }
83
84    /**
85    @brief
[2261]86        Registers a Quest with the QuestManager to make it globally accessable.
87        Uses it's id to make sure to be able to be identify and retrieve it later.
[1996]88    @param quest
[2261]89        The Quest that is to be registered.
[1996]90    @return
91        Returns true if successful, false if not.
92    */
[2785]93    bool QuestManager::registerQuest(Quest* quest)
[1996]94    {
[2261]95        if(quest == NULL) //!< Doh! Just as if there were actual quests behind NULL-pointers.
[2068]96        {
97            COUT(2) << "Registration of Quest in QuestManager failed, because inserted Quest-pointer was NULL." << std::endl;
98            return false;
[2093]99        }
[2092]100
[2261]101        std::pair<std::map<std::string, Quest*>::iterator,bool> result;
[2785]102        result = this->questMap_.insert( std::pair<std::string,Quest*>(quest->getId(),quest) ); //!< Inserting the Quest.
[2092]103
[2261]104        if(result.second) //!< If inserting was a success.
[2068]105        {
106            COUT(3) << "Quest with questId {" << quest->getId() << "} successfully inserted." << std::endl;
107            return true;
[2093]108        }
109        else
110        {
111           COUT(2) << "Quest with the same id was already present." << std::endl;
112           return false;
113        }
[1996]114    }
[2092]115
[1996]116    /**
117    @brief
118        Registers a QuestHint with the QuestManager to make it globally accessable.
[2261]119        Uses it's id to make sure to be able to be identify and retrieve it later.
[1996]120    @param hint
121        The QuestHint to be registered.
122    @return
123        Returns true if successful, false if not.
124    */
[2785]125    bool QuestManager::registerHint(QuestHint* hint)
[1996]126    {
[2261]127        if(hint == NULL) //!< Still not liking NULL-pointers.
[2068]128        {
129            COUT(2) << "Registration of QuestHint in QuestManager failed, because inserted QuestHint-pointer was NULL." << std::endl;
130            return false;
131        }
[2092]132
[2261]133        std::pair<std::map<std::string, QuestHint*>::iterator,bool> result;
[2785]134        result = this->hintMap_.insert ( std::pair<std::string,QuestHint*>(hint->getId(),hint) ); //!< Inserting the QuestHSint.
[2092]135
[2261]136        if(result.second) //!< If inserting was a success.
[2068]137        {
138            COUT(3) << "QuestHint with hintId {" << hint->getId() << "} successfully inserted." << std::endl;
139            return true;
[2093]140        }
141        else
142        {
143           COUT(2) << "QuestHint with the same id was already present." << std::endl;
144           return false;
145        }
[1996]146    }
[2092]147
[1996]148    /**
149    @brief
[2261]150        Finds a Quest with the given id.
[1996]151    @param questId
[2261]152        The id of the Quest sought for.
[1996]153    @return
[2261]154        Returns a pointer to the Quest with the input id.
155        Returns NULL if there is no Quest with the given questId.
[2068]156    @throws
157        Throws an exception if the given questId is invalid.
[1996]158    */
[2785]159    Quest* QuestManager::findQuest(const std::string & questId)
[1996]160    {
[2261]161        if(!QuestItem::isId(questId)) //!< Check vor validity of the given id.
[2093]162        {
[2068]163            ThrowException(Argument, "Invalid questId.");
[2093]164        }
[2092]165
[1996]166        Quest* quest;
[2785]167        std::map<std::string, Quest*>::iterator it = this->questMap_.find(questId);
168        if (it != this->questMap_.end()) //!< If the Quest is registered.
[2093]169        {
170            quest = it->second;
171        }
172        else
173        {
174           quest = NULL;
175           COUT(2) << "The quest with id {" << questId << "} is nowhere to be found." << std::endl;
176        }
[2092]177
[2093]178        return quest;
[1996]179
180    }
[2092]181
[1996]182    /**
183    @brief
[2261]184        Finds a QuestHint with the given id.
[1996]185    @param hintId
[2261]186        The id of the QuestHint sought for.
[1996]187    @return
[2261]188        Returns a pointer to the QuestHint with the input id.
189        Returns NULL if there is no QuestHint with the given hintId.
[2068]190    @throws
191        Throws an exception if the given hintId is invalid.
[1996]192    */
[2785]193    QuestHint* QuestManager::findHint(const std::string & hintId)
[1996]194    {
[2261]195        if(!QuestItem::isId(hintId)) //!< Check vor validity of the given id.
[2093]196        {
[2068]197            ThrowException(Argument, "Invalid hintId.");
[2093]198        }
[2092]199
[1996]200        QuestHint* hint;
[2785]201        std::map<std::string, QuestHint*>::iterator it = this->hintMap_.find(hintId);
202        if (it != this->hintMap_.end()) //!< If the QuestHint is registered.
[2093]203        {
204            hint = it->second;
205        }
206        else
207        {
208           hint = NULL;
209           COUT(2) << "The hint with id {" << hintId << "} is nowhere to be found." << std::endl;
210        }
[2092]211
[2093]212        return hint;
[1996]213
214    }
215
[2092]216
[1996]217}
Note: See TracBrowser for help on using the repository browser.