source:
code/branches/presentation/src/orxonox/objects/quest/QuestManager.cc
@
2677
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 | /** |
30 | @file |
31 | @brief Implementation of the QuestManager class. |
32 | */ |
33 | |
34 | #include "OrxonoxStableHeaders.h" |
35 | #include "QuestManager.h" |
36 | |
37 | #include "core/CoreIncludes.h" |
38 | |
39 | #include "util/Exception.h" |
40 | #include "Quest.h" |
41 | #include "QuestHint.h" |
42 | |
43 | namespace orxonox |
44 | { |
45 | //! All Quests registered by their id's. |
46 | std::map<std::string, Quest*> QuestManager::questMap_s; |
47 | //! All QuestHints registered by their id's. |
48 | std::map<std::string, QuestHint*> QuestManager::hintMap_s; |
49 | |
50 | /** |
51 | @brief |
52 | Constructor. Registers the object. |
53 | */ |
54 | QuestManager::QuestManager(BaseObject* creator) : BaseObject(creator) |
55 | { |
56 | RegisterObject(QuestManager); |
57 | } |
58 | |
59 | /** |
60 | @brief |
61 | Destructor. |
62 | */ |
63 | QuestManager::~QuestManager() |
64 | { |
65 | |
66 | } |
67 | |
68 | /** |
69 | @brief |
70 | Registers a Quest with the QuestManager to make it globally accessable. |
71 | Uses it's id to make sure to be able to be identify and retrieve it later. |
72 | @param quest |
73 | The Quest that is to be registered. |
74 | @return |
75 | Returns true if successful, false if not. |
76 | */ |
77 | /*static*/ bool QuestManager::registerQuest(Quest* quest) |
78 | { |
79 | if(quest == NULL) //!< Doh! Just as if there were actual quests behind NULL-pointers. |
80 | { |
81 | COUT(2) << "Registration of Quest in QuestManager failed, because inserted Quest-pointer was NULL." << std::endl; |
82 | return false; |
83 | } |
84 | |
85 | std::pair<std::map<std::string, Quest*>::iterator,bool> result; |
86 | result = questMap_s.insert( std::pair<std::string,Quest*>(quest->getId(),quest) ); //!< Inserting the Quest. |
87 | |
88 | if(result.second) //!< If inserting was a success. |
89 | { |
90 | COUT(3) << "Quest with questId {" << quest->getId() << "} successfully inserted." << std::endl; |
91 | return true; |
92 | } |
93 | else |
94 | { |
95 | COUT(2) << "Quest with the same id was already present." << std::endl; |
96 | return false; |
97 | } |
98 | } |
99 | |
100 | /** |
101 | @brief |
102 | Registers a QuestHint with the QuestManager to make it globally accessable. |
103 | Uses it's id to make sure to be able to be identify and retrieve it later. |
104 | @param hint |
105 | The QuestHint to be registered. |
106 | @return |
107 | Returns true if successful, false if not. |
108 | */ |
109 | /*static*/ bool QuestManager::registerHint(QuestHint* hint) |
110 | { |
111 | if(hint == NULL) //!< Still not liking NULL-pointers. |
112 | { |
113 | COUT(2) << "Registration of QuestHint in QuestManager failed, because inserted QuestHint-pointer was NULL." << std::endl; |
114 | return false; |
115 | } |
116 | |
117 | std::pair<std::map<std::string, QuestHint*>::iterator,bool> result; |
118 | result = hintMap_s.insert ( std::pair<std::string,QuestHint*>(hint->getId(),hint) ); //!< Inserting the QuestHSint. |
119 | |
120 | if(result.second) //!< If inserting was a success. |
121 | { |
122 | COUT(3) << "QuestHint with hintId {" << hint->getId() << "} successfully inserted." << std::endl; |
123 | return true; |
124 | } |
125 | else |
126 | { |
127 | COUT(2) << "QuestHint with the same id was already present." << std::endl; |
128 | return false; |
129 | } |
130 | } |
131 | |
132 | /** |
133 | @brief |
134 | Finds a Quest with the given id. |
135 | @param questId |
136 | The id of the Quest sought for. |
137 | @return |
138 | Returns a pointer to the Quest with the input id. |
139 | Returns NULL if there is no Quest with the given questId. |
140 | @throws |
141 | Throws an exception if the given questId is invalid. |
142 | */ |
143 | /*static*/ Quest* QuestManager::findQuest(const std::string & questId) |
144 | { |
145 | if(!QuestItem::isId(questId)) //!< Check vor validity of the given id. |
146 | { |
147 | ThrowException(Argument, "Invalid questId."); |
148 | } |
149 | |
150 | Quest* quest; |
151 | std::map<std::string, Quest*>::iterator it = questMap_s.find(questId); |
152 | if (it != questMap_s.end()) //!< If the Quest is registered. |
153 | { |
154 | quest = it->second; |
155 | } |
156 | else |
157 | { |
158 | quest = NULL; |
159 | COUT(2) << "The quest with id {" << questId << "} is nowhere to be found." << std::endl; |
160 | } |
161 | |
162 | return quest; |
163 | |
164 | } |
165 | |
166 | /** |
167 | @brief |
168 | Finds a QuestHint with the given id. |
169 | @param hintId |
170 | The id of the QuestHint sought for. |
171 | @return |
172 | Returns a pointer to the QuestHint with the input id. |
173 | Returns NULL if there is no QuestHint with the given hintId. |
174 | @throws |
175 | Throws an exception if the given hintId is invalid. |
176 | */ |
177 | /*static*/ QuestHint* QuestManager::findHint(const std::string & hintId) |
178 | { |
179 | if(!QuestItem::isId(hintId)) //!< Check vor validity of the given id. |
180 | { |
181 | ThrowException(Argument, "Invalid hintId."); |
182 | } |
183 | |
184 | QuestHint* hint; |
185 | std::map<std::string, QuestHint*>::iterator it = hintMap_s.find(hintId); |
186 | if (it != hintMap_s.end()) //!< If the QuestHint is registered. |
187 | { |
188 | hint = it->second; |
189 | } |
190 | else |
191 | { |
192 | hint = NULL; |
193 | COUT(2) << "The hint with id {" << hintId << "} is nowhere to be found." << std::endl; |
194 | } |
195 | |
196 | return hint; |
197 | |
198 | } |
199 | |
200 | |
201 | } |
Note: See TracBrowser
for help on using the repository browser.