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