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