Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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