Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 2208 was 2105, checked in by rgrieder, 16 years ago

updated msvc files and precompiled headers.

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