Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 2092 was 2092, checked in by landauf, 16 years ago
  • adopted quest classes to the new hierarchy (with a creator pointer)
  • added "RegisterObject(…)" in all constructors and "virtual" to all destructors
  • Property svn:eol-style set to native
File size: 4.7 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
29#include "core/CoreIncludes.h"
[2068]30#include "util/Exception.h"
[2021]31
[1996]32#include "QuestManager.h"
33
34namespace orxonox {
35
[2021]36    std::map<std::string, Quest*> QuestManager::questMap_;
37    std::map<std::string, QuestHint*> QuestManager::hintMap_;
[1996]38
[2092]39    QuestManager::QuestManager(BaseObject* creator) : BaseObject(creator)
[1996]40    {
41        RegisterObject(QuestManager);
42    }
[2092]43
44
[1996]45    QuestManager::~QuestManager()
46    {
[2092]47
[1996]48    }
49
50    /**
51    @brief
52        Registers a quest with the QuestManager to make it globally accessable.
53    @param quest
54        The quest that is to be registered.
55    @return
56        Returns true if successful, false if not.
57    */
[2021]58    bool QuestManager::registerQuest(Quest* quest)
[1996]59    {
[2068]60        if(quest == NULL)
61        {
62            COUT(2) << "Registration of Quest in QuestManager failed, because inserted Quest-pointer was NULL." << std::endl;
63            return false;
64        }
[2092]65
[2068]66        std::pair<std::map<std::string, Quest*>::iterator,bool> ret;
67        ret = questMap_.insert( std::pair<std::string,Quest*>(quest->getId(),quest) );
[2092]68
[2068]69        if(ret.second)
70        {
71            COUT(3) << "Quest with questId {" << quest->getId() << "} successfully inserted." << std::endl;
72            return true;
73        }
74        else
75        {
76           COUT(2) << "Quest with the same id was already present." << std::endl;
77           return false;
78        }
[1996]79    }
[2092]80
[1996]81    /**
82    @brief
83        Registers a QuestHint with the QuestManager to make it globally accessable.
84    @param hint
85        The QuestHint to be registered.
86    @return
87        Returns true if successful, false if not.
88    */
[2021]89    bool QuestManager::registerHint(QuestHint* hint)
[1996]90    {
[2068]91        if(hint == NULL)
92        {
93            COUT(2) << "Registration of QuestHint in QuestManager failed, because inserted QuestHint-pointer was NULL." << std::endl;
94            return false;
95        }
[2092]96
[2068]97        std::pair<std::map<std::string, QuestHint*>::iterator,bool> ret;
98        ret = hintMap_.insert ( std::pair<std::string,QuestHint*>(hint->getId(),hint) );
[2092]99
[2068]100        if(ret.second)
101        {
102            COUT(3) << "QuestHint with hintId {" << hint->getId() << "} successfully inserted." << std::endl;
103            return true;
104        }
105        else
106        {
107           COUT(2) << "QuestHint with the same id was already present." << std::endl;
108           return false;
109        }
[1996]110    }
[2092]111
[1996]112    /**
113    @brief
114        Finds a quest with the given id.
115    @param questId
116        The id of the quest sought for.
117    @return
118        Returns a reference to the quest with the input id.
[2068]119        Returns NULL if there is no quest with the given questId.
120    @throws
121        Throws an exception if the given questId is invalid.
[1996]122    */
[2021]123    Quest* QuestManager::findQuest(const std::string & questId)
[1996]124    {
[2068]125        if(!QuestItem::isId(questId))
126        {
127            ThrowException(Argument, "Invalid questId.");
128        }
[2092]129
[1996]130        Quest* quest;
[2022]131        std::map<std::string, Quest*>::iterator it = questMap_.find(questId);
132        if (it != questMap_.end())
[1996]133        {
[2022]134            quest = it->second;
[1996]135        }
136        else
137        {
138           quest = NULL;
139           COUT(2) << "The quest with id {" << questId << "} is nowhere to be found." << std::endl;
140        }
[2092]141
[2021]142        return quest;
[1996]143
144    }
[2092]145
[1996]146    /**
147    @brief
148        Finds a hint with the given id.
149    @param hintId
150        The id of the hint sought for.
151    @return
152        Returns a reference to the hint with the input id.
[2068]153        Returns NULL if there is no hint with the given hintId.
154    @throws
155        Throws an exception if the given hintId is invalid.
[1996]156    */
[2022]157    QuestHint* QuestManager::findHint(const std::string & hintId)
[1996]158    {
[2068]159        if(!QuestItem::isId(hintId))
160        {
161            ThrowException(Argument, "Invalid hintId.");
162        }
[2092]163
[1996]164        QuestHint* hint;
[2022]165        std::map<std::string, QuestHint*>::iterator it = hintMap_.find(hintId);
166        if (it != hintMap_.end())
[1996]167        {
[2022]168            hint = it->second;
[1996]169        }
170        else
171        {
172           hint = NULL;
173           COUT(2) << "The hint with id {" << hintId << "} is nowhere to be found." << std::endl;
174        }
[2092]175
[1996]176        return hint;
177
178    }
179
[2092]180
[1996]181}
Note: See TracBrowser for help on using the repository browser.