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 "OrxonoxStableHeaders.h" |
---|
30 | #include "QuestListener.h" |
---|
31 | |
---|
32 | #include "core/CoreIncludes.h" |
---|
33 | #include "core/XMLPort.h" |
---|
34 | |
---|
35 | #include "Quest.h" |
---|
36 | #include "QuestManager.h" |
---|
37 | |
---|
38 | namespace orxonox { |
---|
39 | |
---|
40 | CreateFactory(QuestListener); |
---|
41 | |
---|
42 | QuestListener::QuestListener(BaseObject* creator) : BaseObject(creator) |
---|
43 | { |
---|
44 | RegisterObject(QuestListener); |
---|
45 | } |
---|
46 | |
---|
47 | QuestListener::~QuestListener() |
---|
48 | { |
---|
49 | } |
---|
50 | |
---|
51 | /** |
---|
52 | @brief |
---|
53 | Method for creating a Quest object through XML. |
---|
54 | */ |
---|
55 | void QuestListener::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
56 | { |
---|
57 | SUPER(QuestListener, XMLPort, xmlelement, mode); |
---|
58 | |
---|
59 | XMLPortParam(QuestListener, "questId", setQuestId, getQuestId, xmlelement, mode); |
---|
60 | XMLPortParam(QuestListener, "questStatus", setQuestStatus, getQuestStatus, xmlelement, mode); |
---|
61 | |
---|
62 | this->quest_->addListener(this); |
---|
63 | |
---|
64 | COUT(3) << "QuestListener created for quest: {" << this->quest_->getId() << "} and status '" << this->status_ << "'." << std::endl; |
---|
65 | } |
---|
66 | |
---|
67 | void QuestListener::advertiseStatusChange(std::list<QuestListener*> & listeners, const std::string & status) |
---|
68 | { |
---|
69 | for (std::list<QuestListener*>::iterator it = listeners.begin(); it != listeners.end(); ++it) |
---|
70 | { |
---|
71 | QuestListener* listener = *it; |
---|
72 | if(listener->getQuestStatus() == status) |
---|
73 | { |
---|
74 | listener->execute(); |
---|
75 | } |
---|
76 | } |
---|
77 | } |
---|
78 | |
---|
79 | bool QuestListener::execute() |
---|
80 | { |
---|
81 | this->fireEvent(true); //TDO This' right? |
---|
82 | |
---|
83 | COUT(3) << "QuestListener fired Event, expect for somethign to happen." << std::endl; |
---|
84 | |
---|
85 | return true; |
---|
86 | } |
---|
87 | |
---|
88 | bool QuestListener::setQuestId(const std::string & id) |
---|
89 | { |
---|
90 | this->quest_ = QuestManager::findQuest(id); |
---|
91 | if(this->quest_ == NULL) |
---|
92 | { |
---|
93 | COUT(1) << "This is bad!" << std::endl; //TDO Find a better way. |
---|
94 | return false; |
---|
95 | } |
---|
96 | |
---|
97 | return true; |
---|
98 | } |
---|
99 | |
---|
100 | bool QuestListener::setQuestStatus(const std::string & status) |
---|
101 | { |
---|
102 | if(status == "start") |
---|
103 | { |
---|
104 | this->status_ = questListenerStatus::start; |
---|
105 | } |
---|
106 | else if(status == "fail") |
---|
107 | { |
---|
108 | this->status_ = questListenerStatus::fail; |
---|
109 | } |
---|
110 | else if(status == "complete") |
---|
111 | { |
---|
112 | this->status_ = questListenerStatus::complete; |
---|
113 | } |
---|
114 | else |
---|
115 | { |
---|
116 | COUT(2) << "QuestListener with invalid status '" << status << "' created. Status set to 'start'." << std::endl; |
---|
117 | this->status_ = questListenerStatus::start; |
---|
118 | return false; |
---|
119 | } |
---|
120 | |
---|
121 | return true; |
---|
122 | } |
---|
123 | |
---|
124 | const std::string QuestListener::getQuestStatus(void) |
---|
125 | { |
---|
126 | if(this->status_ == questListenerStatus::start) |
---|
127 | { |
---|
128 | return "start"; |
---|
129 | } |
---|
130 | else if(this->status_ == questListenerStatus::fail) |
---|
131 | { |
---|
132 | return "fail"; |
---|
133 | } |
---|
134 | else if(this->status_ == questListenerStatus::complete) |
---|
135 | { |
---|
136 | return "complete"; |
---|
137 | } |
---|
138 | else |
---|
139 | { |
---|
140 | COUT(1) << "An unforseen, never to happen, Error has occured. This is impossible!" << std::endl; |
---|
141 | return ""; |
---|
142 | } |
---|
143 | } |
---|
144 | |
---|
145 | |
---|
146 | } |
---|