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