Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/Waypoints_HS17/src/modules/questsystem/Quest.cc @ 11559

Last change on this file since 11559 was 11559, checked in by jostoffe, 7 years ago

Pfeil wird angezeigt und fliegt mit dem Raumschiff mit, aber er ist noch nicht an der richtigen Position. Dazu muss ich noch die richtige Formel finden anhand der momentanen Ausrichtung des Raumschiffes

  • Property svn:eol-style set to native
File size: 12.2 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 */
[6417]28
[2261]29/**
[7456]30    @file Quest.cc
[2662]31    @brief Implementation of the Quest class.
[2261]32*/
[1992]33
[2105]34#include "Quest.h"
35
[1992]36#include "core/CoreIncludes.h"
[3196]37#include "core/XMLPort.h"
[7456]38
[2095]39#include "QuestDescription.h"
[7456]40#include "QuestEffect.h"
[2095]41#include "QuestHint.h"
[2662]42#include "QuestListener.h"
[7456]43#include "QuestManager.h"
[1992]44
[2662]45namespace orxonox
46{
[10624]47    RegisterAbstractClass(Quest).inheritsFrom<QuestItem>();
[9667]48
[2261]49    /**
50    @brief
51        Constructor. Registers and initializes object.
52    */
[9667]53    Quest::Quest(Context* context) : QuestItem(context)
[2021]54    {
[2092]55        RegisterObject(Quest);
56
[11071]57        this->parentQuest_ = nullptr;
[2021]58    }
[2092]59
[1992]60    /**
61    @brief
62        Destructor.
63    */
64    Quest::~Quest()
65    {
[7163]66        if(this->isRegistered())
67            QuestManager::getInstance().unregisterQuest(this);
[1992]68    }
[2092]69
[2261]70    /**
71    @brief
72        Method for creating a Quest object through XML.
73    */
[2076]74    void Quest::XMLPort(Element& xmlelement, XMLPort::Mode mode)
75    {
76        SUPER(Quest, XMLPort, xmlelement, mode);
[2092]77
[2261]78        XMLPortObject(Quest, Quest, "subquests", addSubQuest, getSubQuest, xmlelement, mode);
79        XMLPortObject(Quest, QuestHint, "hints", addHint, getHint, xmlelement, mode);
80        XMLPortObject(Quest, QuestEffect, "fail-effects", addFailEffect, getFailEffect, xmlelement, mode);
81        XMLPortObject(Quest, QuestEffect, "complete-effects", addCompleteEffect, getCompleteEffect, xmlelement, mode);
[11559]82        //XMLPortObject(Quest, Worldentity, "arrowtarget", addArrowTarget, getArrowTarget, xmlelement, mode);
[2092]83
[7456]84        QuestManager::getInstance().registerQuest(this); // Registers the Quest with the QuestManager.
[2076]85    }
[2092]86
[11539]87
[11559]88    /*bool Quest::addArrowTarget(Quest* quest){
[11539]89
90        assert(quest);
91
92
[11559]93    }*/
[11539]94
95
96
[1992]97    /**
98    @brief
[7456]99        Sets the parent-quest of the Quest.
[1996]100    @param quest
[7456]101        A pointer to the Quest to be set as parent-quest.
[2068]102    @return
[7456]103        Returns true if the parent-quest could be set.
[1996]104    */
[2021]105    bool Quest::setParentQuest(Quest* quest)
[1996]106    {
[7552]107        assert(quest);
[2092]108
[1996]109        this->parentQuest_ = quest;
[2092]110
[8858]111        orxout(verbose, context::quests) << "Parent Quest {" << quest->getId() << "} was added to Quest {" << this->getId() << "}." << endl;
[1996]112        return true;
113    }
[2092]114
[1996]115    /**
116    @brief
[7456]117        Adds a sub-quest to the Quest.
[1996]118    @param quest
[7456]119        A pointer to the Quest to be set as sub-quest.
[2068]120    @return
[7456]121        Returns true if the sub-quest could be set.
[1996]122    */
[2021]123    bool Quest::addSubQuest(Quest* quest)
[1996]124    {
[7552]125        assert(quest);
[2092]126
[7456]127        quest->setParentQuest(this); // Sets the currentQuest (this) as parent-quest for the added sub-quest.
128        this->subQuests_.push_back(quest); // Adds the Quest to the end of the list of sub-quests.
[2092]129
[8858]130        orxout(verbose, context::quests) << "Sub Quest {" << quest->getId() << "} was added to Quest {" << this->getId() << "}." << endl;
[1996]131        return true;
132    }
[2092]133
134
[2068]135    /**
136    @brief
[2261]137        Adds a QuestHint to the list of QuestHints
[2076]138    @param hint
[2261]139        The QuestHint that should be added to the list of QuestHints.
[2076]140    @return
141        Returns true if the hint was successfully added.
142    */
143    bool Quest::addHint(QuestHint* hint)
144    {
[7552]145        assert(hint);
[2092]146
[7456]147        hint->setQuest(this); // Sets the current Quest (this) as Quest for the added QuestHint.
148        this->hints_.push_back(hint); // Adds the QuestHint to the end of the list of QuestHints.
[2092]149
[8858]150        orxout(verbose, context::quests) << "QuestHint {" << hint->getId() << "} was added to Quest {" << this->getId() << "}." << endl;
[2093]151        return true;
[2076]152    }
[2092]153
[2076]154    /**
155    @brief
[2261]156        Adds an QuestEffect to the list of fail QuestEffects.
157    @param effect
158        The QuestEffect to be added.
159    @return
160        Returns true if successful.
[2076]161    */
162    bool Quest::addFailEffect(QuestEffect* effect)
163    {
[7552]164        assert(effect);
[2092]165
[7456]166        this->failEffects_.push_back(effect); // Adds the QuestEffect to the end of the list of fail QuestEffects.
[2092]167
[8858]168        orxout(verbose, context::quests) << "A FailEffect was added to Quest {" << this->getId() << "}." << endl;
[2076]169        return true;
170    }
[2092]171
[2076]172    /**
173    @brief
[2261]174        Adds an QuestEffect to the list of complete QuestEffects.
175    @param effect
176        The QuestEffect to be added.
177    @return
178        Returns true if successful.
[2076]179    */
180    bool Quest::addCompleteEffect(QuestEffect* effect)
181    {
[7552]182        assert(effect);
[2092]183
[7456]184        this->completeEffects_.push_back(effect); // Adds the QuestEffect to the end of the list of complete QuestEffects.
[2092]185
[8858]186        orxout(verbose, context::quests) << "A CompleteEffect was added to Quest {" << this->getId() << "}." << endl;
[2076]187        return true;
188    }
[2092]189
[2076]190    /**
191    @brief
[7456]192        Returns the sub-quest at the given index.
[7401]193    @param index
[2261]194        The index.
195    @return
[11071]196        Returns a pointer to the sub-quest at the given index. nullptr if there is no element at the given index.
[2076]197    */
[2261]198    const Quest* Quest::getSubQuest(unsigned int index) const
[2076]199    {
200        int i = index;
[6417]201
[7456]202        // Iterate through all subquests.
[11071]203        for (Quest* quest : this->subQuests_)
[2093]204        {
[7456]205            if(i == 0) // We're counting down...
[11071]206               return quest;
[7456]207
[2093]208            i--;
209        }
[6417]210
[11071]211        return nullptr; // If the index is greater than the number of elements in the list.
[2076]212    }
[2092]213
[2076]214    /**
215    @brief
[2261]216        Returns the QuestHint at the given index.
[7401]217    @param index
[2261]218        The index.
219    @return
[11071]220        Returns a pointer to the QuestHint at the given index. nullptr if there is no element at the given index.
[2076]221    */
[2261]222    const QuestHint* Quest::getHint(unsigned int index) const
[2076]223    {
224        int i = index;
[6417]225
[7456]226        // Iterate through all QuestHints.
[11071]227        for (QuestHint* hint : this->hints_)
[2093]228        {
[7456]229            if(i == 0) // We're counting down...
[11071]230               return hint;
[7456]231
[2093]232            i--;
233        }
[11071]234        return nullptr; // If the index is greater than the number of elements in the list.
[2076]235    }
[2092]236
[2076]237    /**
238    @brief
[2261]239        Returns the fail QuestEffect at the given index.
[7401]240    @param index
[2261]241        The index.
242    @return
[11071]243        Returns a pointer to the fail QuestEffect at the given index. nullptr if there is no element at the given index.
[2076]244    */
[2261]245    const QuestEffect* Quest::getFailEffect(unsigned int index) const
[2076]246    {
247        int i = index;
[6417]248
[7456]249        // Iterate through all fail QuestEffects.
[11071]250        for (QuestEffect* effect : this->failEffects_)
[2093]251        {
[7456]252            if(i == 0) // We're counting down...
[11071]253               return effect;
[7456]254
[2093]255            i--;
256        }
[11071]257        return nullptr; // If the index is greater than the number of elements in the list.
[2076]258    }
[2092]259
[2076]260    /**
261    @brief
[2261]262        Returns the complete QuestEffect at the given index.
[7401]263    @param index
[2261]264        The index.
265    @return
[11071]266        Returns a pointer to the complete QuestEffect at the given index. nullptr if there is no element at the given index.
[2076]267    */
[2261]268    const QuestEffect* Quest::getCompleteEffect(unsigned int index) const
[2076]269    {
270        int i = index;
[6417]271
[7456]272        // Iterate through all complete QuestEffects.
[11071]273        for (QuestEffect* effect : this->completeEffects_)
[2093]274        {
[7456]275            if(i == 0) // We're counting down...
[11071]276               return effect;
[7456]277
[2093]278            i--;
279        }
[11071]280        return nullptr; // If the index is greater than the number of elements in the list.
[2076]281    }
[2092]282
[2076]283    /**
284    @brief
[2068]285        Returns true if the quest status for the specific player is 'inactive'.
286    @param player
287        The player.
288    @return
289        Returns true if the quest status for the specific player is 'inactive'.
290    */
[2261]291    bool Quest::isInactive(const PlayerInfo* player) const
[2068]292    {
[11071]293        if(player == nullptr)
[7552]294            return true;
[3280]295        return this->getStatus(player) == QuestStatus::Inactive;
[2068]296    }
[2092]297
[2068]298    /**
299    @brief
300        Returns true if the quest status for the specific player is 'active'.
301    @param player
302        The player.
303    @return
304        Returns true if the quest status for the specific player is 'active'.
305    */
[2261]306    bool Quest::isActive(const PlayerInfo* player) const
[2068]307    {
[11071]308        if(player == nullptr)
[7552]309            return false;
[3280]310        return this->getStatus(player) == QuestStatus::Active;
[2068]311    }
[2092]312
[1996]313    /**
314    @brief
[2068]315        Returns true if the quest status for the specific player is 'failed'.
316    @param player
317        The player.
318    @return
319        Returns true if the quest status for the specific player is 'failed'.
320    */
[2261]321    bool Quest::isFailed(const PlayerInfo* player) const
[2068]322    {
[11071]323        if(player == nullptr)
[7552]324            return false;
[3280]325        return this->getStatus(player) == QuestStatus::Failed;
[2068]326    }
[2092]327
[2068]328    /**
329    @brief
330        Returns true if the quest status for the specific player is 'completed'.
331    @param player
332        The player.
333    @return
334        Returns true if the quest status for the specific player is 'completed'.
335    */
[2261]336    bool Quest::isCompleted(const PlayerInfo* player) const
[2068]337    {
[11071]338        if(player == nullptr)
[7552]339            return false;
[3280]340        return this->getStatus(player) == QuestStatus::Completed;
[2068]341    }
[6417]342
[2662]343    /**
344    @brief
345        Fails the Quest for an input player.
346    @param player
347        The player.
348    @return
349        Returns true if the Quest could be failed, false if not.
350    */
351    bool Quest::fail(PlayerInfo* player)
352    {
[7456]353        QuestListener::advertiseStatusChange(this->listeners_, "fail"); // Tells the QuestListeners, that the status has changed to failed.
[3280]354        this->setStatus(player, QuestStatus::Failed);
[6417]355
[8858]356        orxout(verbose, context::quests) << "Quest {" << this->getId() << "} is failed for player: " << player << " ." << endl;
[6417]357
[7403]358        this->getDescription()->sendFailQuestNotification(player);
[2662]359        return true;
360    }
[6417]361
[2662]362    /**
363    @brief
364        Completes the Quest for an input player.
365    @param player
366        The player.
367    @return
368        Returns true if the Quest could be completed, false if not.
369    */
370    bool Quest::complete(PlayerInfo* player)
371    {
[7456]372        QuestListener::advertiseStatusChange(this->listeners_, "complete"); // Tells the QuestListeners, that the status has changed to completed.
[3280]373        this->setStatus(player, QuestStatus::Completed);
[6417]374
[8858]375        orxout(verbose, context::quests) << "Quest {" << this->getId() << "} is completed for player: " << player << " ." << endl;
[6417]376
[7403]377        this->getDescription()->sendCompleteQuestNotification(player);
[2662]378        return true;
379    }
[2092]380
[1992]381    /**
382    @brief
[2261]383        Starts the Quest for an input player.
[1992]384    @param player
385        The player.
[1996]386    @return
[2261]387        Returns true if the Quest could be started, false if not.
[1992]388    */
[2261]389    bool Quest::start(PlayerInfo* player)
[1992]390    {
[7456]391        if(!this->isStartable(player)) // Checks whether the quest can be started.
[1992]392        {
[8858]393            orxout(verbose, context::quests) << "A non-startable quest was trying to be started." << endl;
[2662]394            return false;
[1992]395        }
[6417]396
[8858]397        orxout(verbose, context::quests) << "Quest {" << this->getId() << "} is started for player: " << player << " ." << endl;
[6417]398
[7456]399        QuestListener::advertiseStatusChange(this->listeners_, "start"); // Tells the QuestListeners, that the status has changed to active.
[6417]400
[3280]401        this->setStatus(player, QuestStatus::Active);
[6417]402
[7403]403        this->getDescription()->sendAddQuestNotification(player);
[2662]404        return true;
[1992]405    }
[6417]406
[2662]407    /**
408    @brief
409        Adds a QuestListener to the list of QuestListeners listening to this Quest.
410    @param listener
411        The QuestListener to be added.
412    @return
413        Returns true if successful, false if not.
414    */
415    bool Quest::addListener(QuestListener* listener)
416    {
[7552]417        assert(listener);
[6417]418
[2662]419        this->listeners_.push_back(listener);
420        return true;
421    }
[2092]422
[1992]423}
Note: See TracBrowser for help on using the repository browser.