Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/orxonox/objects/quest/Quest.cc @ 2103

Last change on this file since 2103 was 2096, checked in by landauf, 16 years ago

merged weapon branch back to trunk
changed eol-style of all new files to native

File size: 9.7 KB
RevLine 
[1992]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"
[2021]30
[1992]31#include "Quest.h"
[2068]32#include "QuestManager.h"
[2095]33#include "QuestDescription.h"
34#include "QuestHint.h"
35#include "QuestEffect.h"
[1992]36
37namespace orxonox {
38
[2092]39    Quest::Quest(BaseObject* creator) : QuestItem(creator)
[2021]40    {
[2092]41        RegisterObject(Quest);
42
[2068]43        this->initialize();
[2021]44    }
[2092]45
[1992]46    /**
47    @brief
48        Destructor.
49    */
50    Quest::~Quest()
51    {
[2092]52
[1992]53    }
[2092]54
[2076]55    void Quest::XMLPort(Element& xmlelement, XMLPort::Mode mode)
56    {
57        SUPER(Quest, XMLPort, xmlelement, mode);
[2092]58
[2076]59        XMLPortObject(Quest, Quest, "", addSubQuest, getSubQuests, xmlelement, mode);
60        XMLPortObject(Quest, QuestHint, "", addHint, getHints, xmlelement, mode);
61        XMLPortObject(Quest, QuestEffect, "fail-effects", addFailEffect, getFailEffects, xmlelement, mode);
62        XMLPortObject(Quest, QuestEffect, "complete-effects", addCompleteEffect, getCompleteEffects, xmlelement, mode);
[2092]63
[2076]64        QuestManager::registerQuest(this); //Registers the quest with the QuestManager.
65    }
[2092]66
[1992]67    /**
68    @brief
69        Initializes the object. Needs to be called first in every constructor of this class.
70    */
71    void Quest::initialize(void)
72    {
73        RegisterObject(Quest);
[2092]74
[2068]75        this->parentQuest_ = NULL;
[1992]76    }
77
78    /**
79    @brief
[1996]80        Sets the parent quest of the quest.
81    @param quest
82        A pointer to the quest to be set as parent quest.
[2068]83    @return
84        Returns true if the parentQuest could be set.
[1996]85    */
[2021]86    bool Quest::setParentQuest(Quest* quest)
[1996]87    {
[2068]88        if(quest == NULL)
89        {
90            COUT(2) << "The parentquest to be added to quest {" << this->getId() << "} was NULL." << std::endl;
91            return false;
92        }
[2092]93
[1996]94        this->parentQuest_ = quest;
[2092]95
[2081]96        COUT(3) << "Parent Quest {" << quest->getId() << "} was added to Quest {" << this->getId() << "}." << std::endl;
[1996]97        return true;
98    }
[2092]99
[1996]100    /**
101    @brief
102        Adds a sub quest to the quest.
103    @param quest
104        A pointer to the quest to be set as sub quest.
[2068]105    @return
106        Returns true if the subQuest vould be set.
[1996]107    */
[2021]108    bool Quest::addSubQuest(Quest* quest)
[1996]109    {
[2068]110        if(quest == NULL)
111        {
112            COUT(2) << "The subquest to be added to quest {" << this->getId() << "} was NULL." << std::endl;
113            return false;
114        }
[2092]115
[2076]116        quest->setParentQuest(this);
[2021]117        this->subQuests_.push_back(quest);
[2092]118
[2081]119        COUT(3) << "Sub Quest {" << quest->getId() << "} was added to Quest {" << this->getId() << "}." << std::endl;
[1996]120        return true;
121    }
[2092]122
123
[2068]124    /**
125    @brief
[2092]126        Adds a Hint to the list of hints
[2076]127    @param hint
128        The hint that should be added to the list of hints.
129    @return
130        Returns true if the hint was successfully added.
131    */
132    bool Quest::addHint(QuestHint* hint)
133    {
134        if(hint == NULL)
135        {
136            COUT(2) << "A NULL-QuestHint was trying to be added." << std::endl;
137            return false;
138        }
[2092]139
[2093]140        this->hints_.push_back(hint);
141        hint->setQuest(this);
[2092]142
[2093]143        COUT(3) << "QuestHint {" << hint->getId() << "} was added to Quest {" << this->getId() << "}." << std::endl;
144        return true;
[2076]145    }
[2092]146
[2076]147    /**
148    @brief
[2092]149
[2076]150    */
151    bool Quest::addFailEffect(QuestEffect* effect)
152    {
153        if(effect == NULL)
154        {
155            COUT(2) << "A NULL-QuestEffect was trying to be added" << std::endl;
156            return false;
157        }
[2092]158
[2076]159        this->failEffects_.push_back(effect);
[2092]160
[2081]161        COUT(3) << "A FailEffect was added to Quest {" << this->getId() << "}." << std::endl;
[2076]162        return true;
163    }
[2092]164
[2076]165    /**
166    @brief
[2092]167
[2076]168    */
169    bool Quest::addCompleteEffect(QuestEffect* effect)
170    {
171        if(effect == NULL)
172        {
173            COUT(2) << "A NULL-QuestEffect was trying to be added" << std::endl;
174            return false;
175        }
[2092]176
[2076]177        this->completeEffects_.push_back(effect);
[2092]178
[2081]179        COUT(3) << "A CompleteEffect was added to Quest {" << this->getId() << "}." << std::endl;
[2076]180        return true;
181    }
[2092]182
[2076]183    /**
184    @brief
[2092]185
[2076]186    */
187    const Quest* Quest::getParentQuest(void)
188    {
189        return this->parentQuest_;
190    }
[2092]191
[2076]192    /**
193    @brief
[2092]194
[2076]195    */
196    const Quest* Quest::getSubQuests(unsigned int index) const
197    {
198        int i = index;
199        for (std::list<Quest*>::const_iterator subQuest = this->subQuests_.begin(); subQuest != this->subQuests_.end(); ++subQuest)
[2093]200        {
201            if(i == 0)
202            {
203               return *subQuest;
204            }
205            i--;
206        }
[2076]207        return NULL;
208    }
[2092]209
[2076]210    /**
211    @brief
[2092]212
[2076]213    */
214    const QuestHint* Quest::getHints(unsigned int index) const
215    {
216        int i = index;
217        for (std::list<QuestHint*>::const_iterator hint = this->hints_.begin(); hint != this->hints_.end(); ++hint)
[2093]218        {
219            if(i == 0)
220            {
221               return *hint;
222            }
223            i--;
224        }
[2076]225        return NULL;
226    }
[2092]227
[2076]228    /**
229    @brief
[2092]230
[2076]231    */
232    const QuestEffect* Quest::getFailEffects(unsigned int index) const
233    {
234        int i = index;
235        for (std::list<QuestEffect*>::const_iterator effect = this->failEffects_.begin(); effect != this->failEffects_.end(); ++effect)
[2093]236        {
237            if(i == 0)
238            {
239               return *effect;
240            }
241            i--;
242        }
[2076]243        return NULL;
244    }
[2092]245
[2076]246    /**
247    @brief
[2092]248
[2076]249    */
250    const QuestEffect* Quest::getCompleteEffects(unsigned int index) const
251    {
252        int i = index;
253        for (std::list<QuestEffect*>::const_iterator effect = this->completeEffects_.begin(); effect != this->completeEffects_.end(); ++effect)
[2093]254        {
255            if(i == 0)
256            {
257               return *effect;
258            }
259            i--;
260        }
[2076]261        return NULL;
262    }
[2092]263
[2076]264    /**
265    @brief
[2068]266        Returns true if the quest status for the specific player is 'inactive'.
267    @param player
268        The player.
269    @return
270        Returns true if the quest status for the specific player is 'inactive'.
271    @throws
272        Throws an exception if getStatus throws one.
273    */
274    bool Quest::isInactive(const Player* player) const
275    {
276        return this->getStatus(player) == questStatus::inactive;
277    }
[2092]278
[2068]279    /**
280    @brief
281        Returns true if the quest status for the specific player is 'active'.
282    @param player
283        The player.
284    @return
285        Returns true if the quest status for the specific player is 'active'.
286    @throws
287        Throws an exception if getStatus throws one.
288    */
289    bool Quest::isActive(const Player* player) const
290    {
[1996]291
[2068]292        return this->getStatus(player) == questStatus::active;
293    }
[2092]294
[1996]295    /**
296    @brief
[2068]297        Returns true if the quest status for the specific player is 'failed'.
298    @param player
299        The player.
300    @return
301        Returns true if the quest status for the specific player is 'failed'.
302    @throws
303        Throws an exception if getStatus throws one.
304    */
305    bool Quest::isFailed(const Player* player) const
306    {
307        return this->getStatus(player) == questStatus::failed;
308    }
[2092]309
[2068]310    /**
311    @brief
312        Returns true if the quest status for the specific player is 'completed'.
313    @param player
314        The player.
315    @return
316        Returns true if the quest status for the specific player is 'completed'.
317    @throws
318        Throws an exception if getStatus throws one.
319    */
320    bool Quest::isCompleted(const Player* player) const
321    {
322        return this->getStatus(player) == questStatus::completed;
323    }
[2092]324
[1992]325    /**
326    @brief
327        Starts the quest.
328    @param player
329        The player.
[1996]330    @return
331        Returns true if the quest could be started, false if not.
[1992]332    */
[2021]333    bool Quest::start(Player* player)
[1992]334    {
[1996]335        if(this->isStartable(player))
[1992]336        {
337            this->setStatus(player, questStatus::active);
[1996]338            return true;
[1992]339        }
[1996]340        COUT(2) << "A non-startable quest was trying to be started." << std::endl;
341        return false;
[1992]342    }
[2092]343
[1992]344    /**
345    @brief
346        Fails the quest.
347    @param player
348        The player.
[1996]349    @return
350        Returns true if the quest could be failed, false if not.
[1992]351    */
[2021]352    bool Quest::fail(Player* player)
[1992]353    {
[1996]354        if(this->isFailable(player))
[1992]355        {
356            this->setStatus(player, questStatus::failed);
357            QuestEffect::invokeEffects(player, this->failEffects_);
[1996]358            return true;
[1992]359        }
[1996]360        COUT(2) << "A non-failable quest was trying to be failed." << std::endl;
361        return false;
[1992]362    }
[2092]363
[1992]364    /**
365    @brief
366        Completes the quest.
367    @param player
368        The player.
[1996]369    @return
370        Returns true if the quest could be completed, false if not.
[1992]371    */
[2021]372    bool Quest::complete(Player* player)
[1992]373    {
[1996]374        if(this->isCompletable(player))
[1992]375        {
376            this->setStatus(player, questStatus::completed);
377            QuestEffect::invokeEffects(player, this->completeEffects_);
[1996]378            return true;
[1992]379        }
[1996]380        COUT(2) << "A non-completable quest was trying to be completed." << std::endl;
381        return false;
[1992]382    }
383
384}
Note: See TracBrowser for help on using the repository browser.