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