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 "GlobalQuest.h" |
---|
33 | |
---|
34 | namespace orxonox { |
---|
35 | |
---|
36 | CreateFactory(GlobalQuest); |
---|
37 | |
---|
38 | /** |
---|
39 | @brief |
---|
40 | Constructor. |
---|
41 | */ |
---|
42 | GlobalQuest::GlobalQuest() : Quest() |
---|
43 | { |
---|
44 | this->initialize(); |
---|
45 | } |
---|
46 | |
---|
47 | /** |
---|
48 | @brief |
---|
49 | Destructor. |
---|
50 | */ |
---|
51 | GlobalQuest::~GlobalQuest() |
---|
52 | { |
---|
53 | |
---|
54 | } |
---|
55 | |
---|
56 | void GlobalQuest::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
57 | { |
---|
58 | SUPER(GlobalQuest, XMLPort, xmlelement, mode); |
---|
59 | |
---|
60 | COUT(3) << "New GlobalQuest {" << this->getId() << "} created." << std::endl; |
---|
61 | } |
---|
62 | |
---|
63 | void GlobalQuest::initialize(void) |
---|
64 | { |
---|
65 | RegisterObject(GlobalQuest); |
---|
66 | } |
---|
67 | |
---|
68 | /** |
---|
69 | @brief |
---|
70 | Checks whether the quest can be started. |
---|
71 | @param player |
---|
72 | The player for whom is to be checked. |
---|
73 | @return |
---|
74 | Returns true if the quest can be started, false if not. |
---|
75 | @throws |
---|
76 | Throws an exception if either isInactive() of isActive() throws one. |
---|
77 | */ |
---|
78 | bool GlobalQuest::isStartable(const Player* player) const |
---|
79 | { |
---|
80 | return this->isInactive(player) || this->isActive(player); |
---|
81 | } |
---|
82 | |
---|
83 | /** |
---|
84 | @brief |
---|
85 | Checks whether the quest can be failed. |
---|
86 | @param player |
---|
87 | The player for whom is to be checked. |
---|
88 | @return |
---|
89 | Returns true if the quest can be failed, false if not. |
---|
90 | @throws |
---|
91 | Throws an Exception if isActive() throws one. |
---|
92 | */ |
---|
93 | bool GlobalQuest::isFailable(const Player* player) const |
---|
94 | { |
---|
95 | return this->isActive(player); |
---|
96 | |
---|
97 | } |
---|
98 | |
---|
99 | /** |
---|
100 | @brief |
---|
101 | Checks whether the quest can be completed. |
---|
102 | @param player |
---|
103 | The player for whom is to be checked. |
---|
104 | @return |
---|
105 | Returns true if the quest can be completed, false if not. |
---|
106 | @throws |
---|
107 | Throws an Exception if isActive() throws one. |
---|
108 | */ |
---|
109 | bool GlobalQuest::isCompletable(const Player* player) const |
---|
110 | { |
---|
111 | return this->isActive(player); |
---|
112 | } |
---|
113 | |
---|
114 | /** |
---|
115 | @brief |
---|
116 | Returns the status of the quest for a specific player. |
---|
117 | @param player |
---|
118 | The player. |
---|
119 | @throws |
---|
120 | Throws an Exception if player is NULL. |
---|
121 | */ |
---|
122 | questStatus::Enum GlobalQuest::getStatus(const Player* player) const |
---|
123 | { |
---|
124 | if(player == NULL) |
---|
125 | { |
---|
126 | ThrowException(Argument, "The input Player* is NULL."); |
---|
127 | } |
---|
128 | |
---|
129 | //TDO: Does this really work??? |
---|
130 | std::set<Player*>::const_iterator it = this->players_.find((Player*)(void*)player); |
---|
131 | if (it != this->players_.end()) |
---|
132 | { |
---|
133 | return this->status_; |
---|
134 | } |
---|
135 | else |
---|
136 | { |
---|
137 | return questStatus::inactive; |
---|
138 | } |
---|
139 | |
---|
140 | } |
---|
141 | |
---|
142 | /** |
---|
143 | @brief |
---|
144 | Sets the status for a specific player. |
---|
145 | 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. |
---|
146 | @param player |
---|
147 | The player. |
---|
148 | @param status |
---|
149 | The status to be set. |
---|
150 | @return |
---|
151 | Returns false if player is NULL. |
---|
152 | */ |
---|
153 | bool GlobalQuest::setStatus(Player* player, const questStatus::Enum & status) |
---|
154 | { |
---|
155 | if(player == NULL) |
---|
156 | { |
---|
157 | return false; |
---|
158 | } |
---|
159 | |
---|
160 | std::set<Player*>::const_iterator it = this->players_.find(player); |
---|
161 | if (it == this->players_.end()) //!< Player is not yet in the list. |
---|
162 | { |
---|
163 | this->players_.insert(player); |
---|
164 | } |
---|
165 | this->status_ = status; |
---|
166 | return true; |
---|
167 | } |
---|
168 | |
---|
169 | |
---|
170 | } |
---|