Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/toonshader/src/orxonox/objects/quest/QuestManager.cc @ 8740

Last change on this file since 8740 was 2911, checked in by landauf, 16 years ago

Merged r1-2096 of questsystem5 back to trunk

I hope there weren't more "hidden merge changes" in r2909 than the one in OverlayGroup (removeElement) (and related to this the adjustments in NotificationQueue).

The corresponding media commit seems not yet to be done, but it doesn't break the build.

  • Property svn:eol-style set to native
  • Property svn:mergeinfo set to (toggle deleted branches)
    /code/branches/buildsystem2/src/orxonox/objects/quest/QuestManager.cc2506-2658
    /code/branches/buildsystem3/src/orxonox/objects/quest/QuestManager.cc2662-2708
    /code/branches/gui/src/orxonox/objects/quest/QuestManager.cc2795-2894
    /code/branches/lodfinal/src/orxonox/objects/quest/QuestManager.cc2372-2411
    /code/branches/miniprojects/src/orxonox/objects/quest/QuestManager.cc2754-2824
    /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/questsystem5/src/orxonox/objects/quest/QuestManager.cc2776-2905
    /code/branches/weapon2/src/orxonox/objects/quest/QuestManager.cc2107-2488
    /code/branches/weaponsystem/src/orxonox/objects/quest/QuestManager.cc2742-2890
    /code/trunk/src/orxonox/objects/quest/QuestManager.cc2-2089
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()
55    {
56        RegisterRootObject(QuestManager);
57
58        assert(singletonRef_s == 0);
59        singletonRef_s = this;
60    }
61
62    /**
63    @brief
64        Destructor.
65    */
66    QuestManager::~QuestManager()
67    {
68
69    }
70
71    /**
72    @brief
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
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.
87    @param quest
88        The Quest that is to be registered.
89    @return
90        Returns true if successful, false if not.
91    */
92    bool QuestManager::registerQuest(Quest* quest)
93    {
94        if(quest == NULL) //!< Doh! Just as if there were actual quests behind NULL-pointers.
95        {
96            COUT(2) << "Registration of Quest in QuestManager failed, because inserted Quest-pointer was NULL." << std::endl;
97            return false;
98        }
99
100        std::pair<std::map<std::string, Quest*>::iterator,bool> result;
101        result = this->questMap_.insert( std::pair<std::string,Quest*>(quest->getId(),quest) ); //!< Inserting the Quest.
102
103        if(result.second) //!< If inserting was a success.
104        {
105            COUT(3) << "Quest with questId {" << quest->getId() << "} successfully inserted." << std::endl;
106            return true;
107        }
108        else
109        {
110           COUT(2) << "Quest with the same id was already present." << std::endl;
111           return false;
112        }
113    }
114
115    /**
116    @brief
117        Registers a QuestHint with the QuestManager to make it globally accessable.
118        Uses it's id to make sure to be able to be identify and retrieve it later.
119    @param hint
120        The QuestHint to be registered.
121    @return
122        Returns true if successful, false if not.
123    */
124    bool QuestManager::registerHint(QuestHint* hint)
125    {
126        if(hint == NULL) //!< Still not liking NULL-pointers.
127        {
128            COUT(2) << "Registration of QuestHint in QuestManager failed, because inserted QuestHint-pointer was NULL." << std::endl;
129            return false;
130        }
131
132        std::pair<std::map<std::string, QuestHint*>::iterator,bool> result;
133        result = this->hintMap_.insert ( std::pair<std::string,QuestHint*>(hint->getId(),hint) ); //!< Inserting the QuestHSint.
134
135        if(result.second) //!< If inserting was a success.
136        {
137            COUT(3) << "QuestHint with hintId {" << hint->getId() << "} successfully inserted." << std::endl;
138            return true;
139        }
140        else
141        {
142           COUT(2) << "QuestHint with the same id was already present." << std::endl;
143           return false;
144        }
145    }
146
147    /**
148    @brief
149        Finds a Quest with the given id.
150    @param questId
151        The id of the Quest sought for.
152    @return
153        Returns a pointer to the Quest with the input id.
154        Returns NULL if there is no Quest with the given questId.
155    @throws
156        Throws an exception if the given questId is invalid.
157    */
158    Quest* QuestManager::findQuest(const std::string & questId)
159    {
160        if(!QuestItem::isId(questId)) //!< Check vor validity of the given id.
161        {
162            ThrowException(Argument, "Invalid questId.");
163        }
164
165        Quest* quest;
166        std::map<std::string, Quest*>::iterator it = this->questMap_.find(questId);
167        if (it != this->questMap_.end()) //!< If the Quest is registered.
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        }
176
177        return quest;
178
179    }
180
181    /**
182    @brief
183        Finds a QuestHint with the given id.
184    @param hintId
185        The id of the QuestHint sought for.
186    @return
187        Returns a pointer to the QuestHint with the input id.
188        Returns NULL if there is no QuestHint with the given hintId.
189    @throws
190        Throws an exception if the given hintId is invalid.
191    */
192    QuestHint* QuestManager::findHint(const std::string & hintId)
193    {
194        if(!QuestItem::isId(hintId)) //!< Check vor validity of the given id.
195        {
196            ThrowException(Argument, "Invalid hintId.");
197        }
198
199        QuestHint* hint;
200        std::map<std::string, QuestHint*>::iterator it = this->hintMap_.find(hintId);
201        if (it != this->hintMap_.end()) //!< If the QuestHint is registered.
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        }
210
211        return hint;
212
213    }
214
215
216}
Note: See TracBrowser for help on using the repository browser.