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