Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 2101 was 2096, checked in by landauf, 16 years ago

merged weapon branch back to trunk
changed eol-style of all new files to native

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