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 | |
---|
31 | #include "Quest.h" |
---|
32 | #include "QuestManager.h" |
---|
33 | |
---|
34 | namespace orxonox { |
---|
35 | |
---|
36 | Quest::Quest() : QuestItem() |
---|
37 | { |
---|
38 | this->initialize(); |
---|
39 | } |
---|
40 | |
---|
41 | /** |
---|
42 | @brief |
---|
43 | Constructor. Creates a quest with a given id, title and description. |
---|
44 | @param id |
---|
45 | The unique identifier of the quest. |
---|
46 | @param title |
---|
47 | The title of the quest. |
---|
48 | @param description |
---|
49 | The description of the quest. |
---|
50 | */ |
---|
51 | Quest::Quest(std::string id) : QuestItem(id) |
---|
52 | { |
---|
53 | this->initialize(); |
---|
54 | } |
---|
55 | |
---|
56 | /** |
---|
57 | @brief |
---|
58 | Destructor. |
---|
59 | */ |
---|
60 | Quest::~Quest() |
---|
61 | { |
---|
62 | |
---|
63 | } |
---|
64 | |
---|
65 | /** |
---|
66 | @brief |
---|
67 | Initializes the object. Needs to be called first in every constructor of this class. |
---|
68 | */ |
---|
69 | void Quest::initialize(void) |
---|
70 | { |
---|
71 | RegisterObject(Quest); |
---|
72 | |
---|
73 | this->parentQuest_ = NULL; |
---|
74 | QuestManager::registerQuest(this); //Registers the quest with the QuestManager. |
---|
75 | } |
---|
76 | |
---|
77 | /** |
---|
78 | @brief |
---|
79 | Sets the parent quest of the quest. |
---|
80 | @param quest |
---|
81 | A pointer to the quest to be set as parent quest. |
---|
82 | @return |
---|
83 | Returns true if the parentQuest could be set. |
---|
84 | */ |
---|
85 | bool Quest::setParentQuest(Quest* quest) |
---|
86 | { |
---|
87 | if(quest == NULL) |
---|
88 | { |
---|
89 | COUT(2) << "The parentquest to be added to quest {" << this->getId() << "} was NULL." << std::endl; |
---|
90 | return false; |
---|
91 | } |
---|
92 | |
---|
93 | this->parentQuest_ = quest; |
---|
94 | return true; |
---|
95 | } |
---|
96 | |
---|
97 | /** |
---|
98 | @brief |
---|
99 | Adds a sub quest to the quest. |
---|
100 | @param quest |
---|
101 | A pointer to the quest to be set as sub quest. |
---|
102 | @return |
---|
103 | Returns true if the subQuest vould be set. |
---|
104 | */ |
---|
105 | bool Quest::addSubQuest(Quest* quest) |
---|
106 | { |
---|
107 | if(quest == NULL) |
---|
108 | { |
---|
109 | COUT(2) << "The subquest to be added to quest {" << this->getId() << "} was NULL." << std::endl; |
---|
110 | return false; |
---|
111 | } |
---|
112 | |
---|
113 | this->subQuests_.push_back(quest); |
---|
114 | return true; |
---|
115 | } |
---|
116 | |
---|
117 | /** |
---|
118 | @brief |
---|
119 | Returns true if the quest status for the specific player is 'inactive'. |
---|
120 | @param player |
---|
121 | The player. |
---|
122 | @return |
---|
123 | Returns true if the quest status for the specific player is 'inactive'. |
---|
124 | @throws |
---|
125 | Throws an exception if getStatus throws one. |
---|
126 | */ |
---|
127 | bool Quest::isInactive(const Player* player) const |
---|
128 | { |
---|
129 | return this->getStatus(player) == questStatus::inactive; |
---|
130 | } |
---|
131 | |
---|
132 | /** |
---|
133 | @brief |
---|
134 | Returns true if the quest status for the specific player is 'active'. |
---|
135 | @param player |
---|
136 | The player. |
---|
137 | @return |
---|
138 | Returns true if the quest status for the specific player is 'active'. |
---|
139 | @throws |
---|
140 | Throws an exception if getStatus throws one. |
---|
141 | */ |
---|
142 | bool Quest::isActive(const Player* player) const |
---|
143 | { |
---|
144 | |
---|
145 | return this->getStatus(player) == questStatus::active; |
---|
146 | } |
---|
147 | |
---|
148 | /** |
---|
149 | @brief |
---|
150 | Returns true if the quest status for the specific player is 'failed'. |
---|
151 | @param player |
---|
152 | The player. |
---|
153 | @return |
---|
154 | Returns true if the quest status for the specific player is 'failed'. |
---|
155 | @throws |
---|
156 | Throws an exception if getStatus throws one. |
---|
157 | */ |
---|
158 | bool Quest::isFailed(const Player* player) const |
---|
159 | { |
---|
160 | return this->getStatus(player) == questStatus::failed; |
---|
161 | } |
---|
162 | |
---|
163 | /** |
---|
164 | @brief |
---|
165 | Returns true if the quest status for the specific player is 'completed'. |
---|
166 | @param player |
---|
167 | The player. |
---|
168 | @return |
---|
169 | Returns true if the quest status for the specific player is 'completed'. |
---|
170 | @throws |
---|
171 | Throws an exception if getStatus throws one. |
---|
172 | */ |
---|
173 | bool Quest::isCompleted(const Player* player) const |
---|
174 | { |
---|
175 | return this->getStatus(player) == questStatus::completed; |
---|
176 | } |
---|
177 | |
---|
178 | /** |
---|
179 | @brief |
---|
180 | Adds a Hint to the list of hints |
---|
181 | @param hint |
---|
182 | The hint that should be added to the list of hints. |
---|
183 | @return |
---|
184 | Returns true if the hint was successfully added. |
---|
185 | */ |
---|
186 | bool Quest::addHint(QuestHint* hint) |
---|
187 | { |
---|
188 | if(hint == NULL) |
---|
189 | { |
---|
190 | COUT(2) << "A NULL-QuestHint was trying to be added." << std::endl; |
---|
191 | return false; |
---|
192 | } |
---|
193 | |
---|
194 | this->hints_.push_back(hint); |
---|
195 | hint->setQuest(this); |
---|
196 | return true; |
---|
197 | } |
---|
198 | |
---|
199 | /** |
---|
200 | @brief |
---|
201 | Starts the quest. |
---|
202 | @param player |
---|
203 | The player. |
---|
204 | @return |
---|
205 | Returns true if the quest could be started, false if not. |
---|
206 | */ |
---|
207 | bool Quest::start(Player* player) |
---|
208 | { |
---|
209 | if(this->isStartable(player)) |
---|
210 | { |
---|
211 | this->setStatus(player, questStatus::active); |
---|
212 | return true; |
---|
213 | } |
---|
214 | COUT(2) << "A non-startable quest was trying to be started." << std::endl; |
---|
215 | return false; |
---|
216 | } |
---|
217 | |
---|
218 | /** |
---|
219 | @brief |
---|
220 | Fails the quest. |
---|
221 | @param player |
---|
222 | The player. |
---|
223 | @return |
---|
224 | Returns true if the quest could be failed, false if not. |
---|
225 | */ |
---|
226 | bool Quest::fail(Player* player) |
---|
227 | { |
---|
228 | if(this->isFailable(player)) |
---|
229 | { |
---|
230 | this->setStatus(player, questStatus::failed); |
---|
231 | QuestEffect::invokeEffects(player, this->failEffects_); |
---|
232 | return true; |
---|
233 | } |
---|
234 | COUT(2) << "A non-failable quest was trying to be failed." << std::endl; |
---|
235 | return false; |
---|
236 | } |
---|
237 | |
---|
238 | /** |
---|
239 | @brief |
---|
240 | Completes the quest. |
---|
241 | @param player |
---|
242 | The player. |
---|
243 | @return |
---|
244 | Returns true if the quest could be completed, false if not. |
---|
245 | */ |
---|
246 | bool Quest::complete(Player* player) |
---|
247 | { |
---|
248 | if(this->isCompletable(player)) |
---|
249 | { |
---|
250 | this->setStatus(player, questStatus::completed); |
---|
251 | QuestEffect::invokeEffects(player, this->completeEffects_); |
---|
252 | return true; |
---|
253 | } |
---|
254 | COUT(2) << "A non-completable quest was trying to be completed." << std::endl; |
---|
255 | return false; |
---|
256 | } |
---|
257 | |
---|
258 | } |
---|