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 LocalQuest.cc |
---|
31 | @brief |
---|
32 | Implementation of the LocalQuest class. |
---|
33 | */ |
---|
34 | |
---|
35 | #include "OrxonoxStableHeaders.h" |
---|
36 | #include "LocalQuest.h" |
---|
37 | |
---|
38 | #include "core/CoreIncludes.h" |
---|
39 | #include "core/Super.h" |
---|
40 | #include "util/Exception.h" |
---|
41 | |
---|
42 | #include "orxonox/objects/infos/PlayerInfo.h" |
---|
43 | #include "QuestEffect.h" |
---|
44 | |
---|
45 | namespace orxonox { |
---|
46 | |
---|
47 | CreateFactory(LocalQuest); |
---|
48 | |
---|
49 | /** |
---|
50 | @brief |
---|
51 | Constructor. Registers and initializes the object. |
---|
52 | */ |
---|
53 | LocalQuest::LocalQuest(BaseObject* creator) : Quest(creator) |
---|
54 | { |
---|
55 | RegisterObject(LocalQuest); |
---|
56 | } |
---|
57 | |
---|
58 | /** |
---|
59 | @brief |
---|
60 | Destructor. |
---|
61 | */ |
---|
62 | LocalQuest::~LocalQuest() |
---|
63 | { |
---|
64 | |
---|
65 | } |
---|
66 | |
---|
67 | /** |
---|
68 | @brief |
---|
69 | Method for creating a LocalQuest object through XML. |
---|
70 | */ |
---|
71 | void LocalQuest::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
72 | { |
---|
73 | SUPER(LocalQuest, XMLPort, xmlelement, mode); |
---|
74 | |
---|
75 | COUT(3) << "New LocalQuest {" << this->getId() << "} created." << std::endl; |
---|
76 | } |
---|
77 | |
---|
78 | /** |
---|
79 | @brief |
---|
80 | Fails the Quest for a given player. |
---|
81 | Invokes all the failEffects on the player. |
---|
82 | @param player |
---|
83 | The player. |
---|
84 | @return |
---|
85 | Returns true if the Quest could be failed, false if not. |
---|
86 | */ |
---|
87 | bool LocalQuest::fail(PlayerInfo* player) |
---|
88 | { |
---|
89 | if(!this->isFailable(player)) //!< Checks whether the quest can be failed. |
---|
90 | { |
---|
91 | COUT(4) << "A non-failable quest was trying to be failed." << std::endl; |
---|
92 | return false; |
---|
93 | } |
---|
94 | |
---|
95 | Quest::fail(player); |
---|
96 | |
---|
97 | QuestEffect::invokeEffects(player, this->getFailEffectList()); //!< Invoke the failEffects. |
---|
98 | return true; |
---|
99 | } |
---|
100 | |
---|
101 | /** |
---|
102 | @brief |
---|
103 | Completes the Quest for a given player. |
---|
104 | Invokes all the complete QuestEffects on the player. |
---|
105 | @param player |
---|
106 | The player. |
---|
107 | @return |
---|
108 | Returns true if the Quest could be completed, false if not. |
---|
109 | */ |
---|
110 | bool LocalQuest::complete(PlayerInfo* player) |
---|
111 | { |
---|
112 | if(!this->isCompletable(player)) //!< Checks whether the Quest can be completed. |
---|
113 | { |
---|
114 | COUT(4) << "A non-completable quest was trying to be completed." << std::endl; |
---|
115 | return false; |
---|
116 | } |
---|
117 | |
---|
118 | Quest::complete(player); |
---|
119 | |
---|
120 | QuestEffect::invokeEffects(player, this->getCompleteEffectList()); //!< Invoke the complete QuestEffects. |
---|
121 | return true; |
---|
122 | } |
---|
123 | |
---|
124 | /** |
---|
125 | @brief |
---|
126 | Checks whether the Quest can be started. |
---|
127 | @param player |
---|
128 | The player for whom is to be checked. |
---|
129 | @return |
---|
130 | Returns true if the Quest can be started, false if not. |
---|
131 | @throws |
---|
132 | Throws an exception if isInactive(PlayerInfo*) throws one. |
---|
133 | */ |
---|
134 | bool LocalQuest::isStartable(const PlayerInfo* player) const |
---|
135 | { |
---|
136 | if(!(this->getParentQuest() == NULL || this->getParentQuest()->isActive(player))) |
---|
137 | { |
---|
138 | return false; |
---|
139 | } |
---|
140 | return this->isInactive(player); |
---|
141 | } |
---|
142 | |
---|
143 | /** |
---|
144 | @brief |
---|
145 | Checks whether the Quest can be failed. |
---|
146 | @param player |
---|
147 | The player for whom is to be checked. |
---|
148 | @return |
---|
149 | Returns true if the Quest can be failed, false if not. |
---|
150 | @throws |
---|
151 | Throws an exception if isActive(PlayerInfo*) throws one. |
---|
152 | */ |
---|
153 | bool LocalQuest::isFailable(const PlayerInfo* player) const |
---|
154 | { |
---|
155 | return this->isActive(player); |
---|
156 | } |
---|
157 | |
---|
158 | /** |
---|
159 | @brief |
---|
160 | Checks whether the Quest can be completed. |
---|
161 | @param player |
---|
162 | The player for whom is to be checked. |
---|
163 | @return |
---|
164 | Returns true if the Quest can be completed, false if not. |
---|
165 | @throws |
---|
166 | Throws an exception if isInactive(PlayerInfo*) throws one. |
---|
167 | */ |
---|
168 | bool LocalQuest::isCompletable(const PlayerInfo* player) const |
---|
169 | { |
---|
170 | return this->isActive(player); |
---|
171 | } |
---|
172 | |
---|
173 | /** |
---|
174 | @brief |
---|
175 | Returns the status of the Quest for a specific player. |
---|
176 | @param player |
---|
177 | The player. |
---|
178 | @return |
---|
179 | Returns the status of the Quest for the input player. |
---|
180 | @throws |
---|
181 | Throws an Exception if player is NULL. |
---|
182 | */ |
---|
183 | questStatus::Enum LocalQuest::getStatus(const PlayerInfo* player) const |
---|
184 | { |
---|
185 | if(player == NULL) //!< No player has no defined status. |
---|
186 | { |
---|
187 | ThrowException(Argument, "The input PlayerInfo* is NULL."); |
---|
188 | } |
---|
189 | |
---|
190 | std::map<const PlayerInfo*, questStatus::Enum>::const_iterator it = this->playerStatus_.find(player); |
---|
191 | if (it != this->playerStatus_.end()) //!< If there is a player in the map. |
---|
192 | { |
---|
193 | return it->second; |
---|
194 | } |
---|
195 | |
---|
196 | return questStatus::inactive; //!< If the player is not yet in the map, that means the status of the quest form him is 'inactive'. |
---|
197 | } |
---|
198 | |
---|
199 | /** |
---|
200 | @brief |
---|
201 | Sets the status for a specific player. |
---|
202 | But be careful wit this one, the status will just be set without checking for its validity. You have to know what you're doing. Really! |
---|
203 | @param player |
---|
204 | The player the status should be set for. |
---|
205 | @param status |
---|
206 | The status to be set. |
---|
207 | @return |
---|
208 | Returns false if player is NULL. |
---|
209 | */ |
---|
210 | bool LocalQuest::setStatus(PlayerInfo* player, const questStatus::Enum & status) |
---|
211 | { |
---|
212 | if(player == NULL) //!< We can't set a status for no player. |
---|
213 | { |
---|
214 | return false; |
---|
215 | } |
---|
216 | |
---|
217 | this->playerStatus_[player] = status; |
---|
218 | return true; |
---|
219 | } |
---|
220 | |
---|
221 | } |
---|