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 "Quest.h" |
---|
33 | #include "QuestHint.h" |
---|
34 | |
---|
35 | namespace orxonox { |
---|
36 | |
---|
37 | CreateFactory(QuestHint); |
---|
38 | |
---|
39 | /** |
---|
40 | @brief |
---|
41 | Constructor. |
---|
42 | */ |
---|
43 | QuestHint::QuestHint() : QuestItem() |
---|
44 | { |
---|
45 | this->initialize(); |
---|
46 | } |
---|
47 | |
---|
48 | /** |
---|
49 | @brief |
---|
50 | Constructor. Needs as input a unique identifier to be able to identify different instances of this class (and subclasses). |
---|
51 | @param id |
---|
52 | The unique identifier. |
---|
53 | @param title |
---|
54 | The title of the hint. |
---|
55 | @param description |
---|
56 | The description of the hint, resp. the hint itself. |
---|
57 | */ |
---|
58 | QuestHint::QuestHint(std::string id) : QuestItem(id) |
---|
59 | { |
---|
60 | this->initialize(); |
---|
61 | } |
---|
62 | |
---|
63 | /** |
---|
64 | @brief |
---|
65 | Destructor. |
---|
66 | */ |
---|
67 | QuestHint::~QuestHint() |
---|
68 | { |
---|
69 | |
---|
70 | } |
---|
71 | |
---|
72 | void QuestHint::initialize(void) |
---|
73 | { |
---|
74 | RegisterObject(QuestHint); |
---|
75 | } |
---|
76 | |
---|
77 | void QuestHint::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
78 | { |
---|
79 | SUPER(QuestHint, XMLPort, xmlelement, mode); |
---|
80 | } |
---|
81 | |
---|
82 | |
---|
83 | /** |
---|
84 | @brief |
---|
85 | Checks whether the hint is active for a specific player. |
---|
86 | @param player |
---|
87 | The player. |
---|
88 | @throws |
---|
89 | Throws an Argument Exception if the input Player-pointer is NULL. |
---|
90 | @return |
---|
91 | Returns true if the hint is active for the specified player. |
---|
92 | */ |
---|
93 | bool QuestHint::isActive(Player* player) |
---|
94 | { |
---|
95 | if(player == NULL) |
---|
96 | { |
---|
97 | ThrowException(Argument, "The input Player* is NULL."); |
---|
98 | return false; |
---|
99 | } |
---|
100 | |
---|
101 | std::map<Player*, questHintStatus::Enum>::iterator it = this->playerStatus_.find(player); |
---|
102 | if (it != this->playerStatus_.end()) |
---|
103 | { |
---|
104 | return it->second; |
---|
105 | } |
---|
106 | return questStatus::inactive; |
---|
107 | } |
---|
108 | |
---|
109 | /** |
---|
110 | @brief |
---|
111 | Activates a QuestHint for a given player. |
---|
112 | @param player |
---|
113 | The player. |
---|
114 | @return |
---|
115 | Returns true if the activation was successful, false if there were problems. |
---|
116 | */ |
---|
117 | bool QuestHint::activate(Player* player) |
---|
118 | { |
---|
119 | if(this->quest_->isActive(player)) |
---|
120 | { |
---|
121 | if(!(this->isActive(player))) |
---|
122 | { |
---|
123 | this->playerStatus_[player] = questHintStatus::active; |
---|
124 | return true; |
---|
125 | } |
---|
126 | else |
---|
127 | { |
---|
128 | COUT(2) << "An already active questHint was trying to get activated." << std::endl; |
---|
129 | return false; |
---|
130 | } |
---|
131 | } |
---|
132 | COUT(2) << "A hint of a non-active quest was trying to get activated." << std::endl; |
---|
133 | return false; |
---|
134 | } |
---|
135 | |
---|
136 | /** |
---|
137 | @brief |
---|
138 | Sets the quest the QuestHitn belongs to. |
---|
139 | @param quest |
---|
140 | @return |
---|
141 | */ |
---|
142 | bool QuestHint::setQuest(Quest* quest) |
---|
143 | { |
---|
144 | if(quest == NULL) |
---|
145 | { |
---|
146 | COUT(2) << "The input Quest* is NULL." << std::endl; |
---|
147 | return false; |
---|
148 | } |
---|
149 | |
---|
150 | this->quest_ = quest; |
---|
151 | return true; |
---|
152 | } |
---|
153 | |
---|
154 | } |
---|