Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/pickups2/src/orxonox/objects/quest/QuestManager.cc @ 2682

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

updated msvc files and precompiled headers.

File size: 5.1 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#include "OrxonoxStableHeaders.h"
30#include "QuestManager.h"
31
32#include "core/CoreIncludes.h"
33
34#include "util/Exception.h"
35#include "Quest.h"
36#include "QuestHint.h"
37
38namespace orxonox {
39
40    std::map<std::string, Quest*> QuestManager::questMap_;
41    std::map<std::string, QuestHint*> QuestManager::hintMap_;
42
43    QuestManager::QuestManager(BaseObject* creator) : BaseObject(creator)
44    {
45        RegisterObject(QuestManager);
46    }
47
48
49    QuestManager::~QuestManager()
50    {
51
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    */
62    bool QuestManager::registerQuest(Quest* quest)
63    {
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;
68        }
69
70        std::pair<std::map<std::string, Quest*>::iterator,bool> ret;
71        ret = questMap_.insert( std::pair<std::string,Quest*>(quest->getId(),quest) );
72
73        if(ret.second)
74        {
75            COUT(3) << "Quest with questId {" << quest->getId() << "} successfully inserted." << std::endl;
76            return true;
77        }
78        else
79        {
80           COUT(2) << "Quest with the same id was already present." << std::endl;
81           return false;
82        }
83    }
84
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    */
93    bool QuestManager::registerHint(QuestHint* hint)
94    {
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        }
100
101        std::pair<std::map<std::string, QuestHint*>::iterator,bool> ret;
102        ret = hintMap_.insert ( std::pair<std::string,QuestHint*>(hint->getId(),hint) );
103
104        if(ret.second)
105        {
106            COUT(3) << "QuestHint with hintId {" << hint->getId() << "} successfully inserted." << std::endl;
107            return true;
108        }
109        else
110        {
111           COUT(2) << "QuestHint with the same id was already present." << std::endl;
112           return false;
113        }
114    }
115
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.
123        Returns NULL if there is no quest with the given questId.
124    @throws
125        Throws an exception if the given questId is invalid.
126    */
127    Quest* QuestManager::findQuest(const std::string & questId)
128    {
129        if(!QuestItem::isId(questId))
130        {
131            ThrowException(Argument, "Invalid questId.");
132        }
133
134        Quest* quest;
135        std::map<std::string, Quest*>::iterator it = questMap_.find(questId);
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        }
145
146        return quest;
147
148    }
149
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.
157        Returns NULL if there is no hint with the given hintId.
158    @throws
159        Throws an exception if the given hintId is invalid.
160    */
161    QuestHint* QuestManager::findHint(const std::string & hintId)
162    {
163        if(!QuestItem::isId(hintId))
164        {
165            ThrowException(Argument, "Invalid hintId.");
166        }
167
168        QuestHint* hint;
169        std::map<std::string, QuestHint*>::iterator it = hintMap_.find(hintId);
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        }
179
180        return hint;
181
182    }
183
184
185}
Note: See TracBrowser for help on using the repository browser.