Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/questsystem3/src/orxonox/objects/quest/LocalQuest.cc @ 2349

Last change on this file since 2349 was 2328, checked in by dafrick, 16 years ago
  • Created QuestListeners, they can be used to affect Objects due to status changes of quests.
File size: 6.1 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
[2261]29/**
30    @file LocalQuest.cc
31    @brief
32    Implementation of the LocalQuest class.
33*/
34
[2105]35#include "OrxonoxStableHeaders.h"
36#include "LocalQuest.h"
37
[1992]38#include "core/CoreIncludes.h"
[2328]39#include "core/Super.h"
[2068]40#include "util/Exception.h"
[1992]41
[2261]42#include "orxonox/objects/infos/PlayerInfo.h"
43#include "QuestEffect.h"
44
[1992]45namespace orxonox {
46
47    CreateFactory(LocalQuest);
48
[2261]49    /**
50    @brief
51        Constructor. Registers and initializes the object.
52    */
[2092]53    LocalQuest::LocalQuest(BaseObject* creator) : Quest(creator)
[2021]54    {
[2092]55        RegisterObject(LocalQuest);
[2021]56    }
[2092]57
[1992]58    /**
59    @brief
60        Destructor.
61    */
62    LocalQuest::~LocalQuest()
63    {
[2092]64
[1992]65    }
[2092]66
[2261]67    /**
68    @brief
69        Method for creating a LocalQuest object through XML.
70    */
[2076]71    void LocalQuest::XMLPort(Element& xmlelement, XMLPort::Mode mode)
72    {
73        SUPER(LocalQuest, XMLPort, xmlelement, mode);
74
[2081]75        COUT(3) << "New LocalQuest {" << this->getId() << "} created." << std::endl;
[2076]76    }
[2092]77
[2261]78    /**
79    @brief
80        Fails the Quest for a given player.
81        Invokes all the failEffects on the player.
82    @param player
83        The player.
84    @return
85        Returns true if the Quest could be failed, false if not.
86    */
87    bool LocalQuest::fail(PlayerInfo* player)
[2068]88    {
[2328]89        if(!this->isFailable(player)) //!< Checks whether the quest can be failed.
[2261]90        {
[2328]91            COUT(4) << "A non-failable quest was trying to be failed." << std::endl;
92            return false;
[2261]93        }
94       
[2328]95        Quest::fail(player);
96       
97        QuestEffect::invokeEffects(player, this->getFailEffectList()); //!< Invoke the failEffects.
98        return true;
[2068]99    }
[2092]100
[1992]101    /**
102    @brief
[2261]103        Completes the Quest for a given player.
104    Invokes all the complete QuestEffects on the player.
[1996]105    @param player
[2261]106        The player.
107    @return
108        Returns true if the Quest could be completed, false if not.
109    */
110    bool LocalQuest::complete(PlayerInfo* player)
111    {
[2328]112        if(!this->isCompletable(player)) //!< Checks whether the Quest can be completed.
[2261]113        {
[2328]114            COUT(4) << "A non-completable quest was trying to be completed." << std::endl;
115            return false;
[2261]116        }
117       
[2328]118        Quest::complete(player);
119       
120        QuestEffect::invokeEffects(player, this->getCompleteEffectList()); //!< Invoke the complete QuestEffects.
121        return true;
[2261]122    }
123
124    /**
125    @brief
126        Checks whether the Quest can be started.
127    @param player
[1996]128        The player for whom is to be checked.
129    @return
[2261]130        Returns true if the Quest can be started, false if not.
[2068]131    @throws
[2261]132        Throws an exception if isInactive(PlayerInfo*) throws one.
[1996]133    */
[2261]134    bool LocalQuest::isStartable(const PlayerInfo* player) const
[1996]135    {
[2261]136        if(!(this->getParentQuest() == NULL || this->getParentQuest()->isActive(player)))
137        {
138            return false;
139        }
[1996]140        return this->isInactive(player);
141    }
[2092]142
[1996]143    /**
144    @brief
[2261]145        Checks whether the Quest can be failed.
[1996]146    @param player
147        The player for whom is to be checked.
148    @return
[2261]149        Returns true if the Quest can be failed, false if not.
[2068]150    @throws
[2261]151        Throws an exception if isActive(PlayerInfo*) throws one.
[1996]152    */
[2261]153    bool LocalQuest::isFailable(const PlayerInfo* player) const
[1996]154    {
155        return this->isActive(player);
156    }
[2092]157
[1996]158    /**
159    @brief
[2261]160        Checks whether the Quest can be completed.
[1996]161    @param player
162        The player for whom is to be checked.
163    @return
[2261]164        Returns true if the Quest can be completed, false if not.
[2068]165    @throws
[2261]166        Throws an exception if isInactive(PlayerInfo*) throws one.
[1996]167    */
[2261]168    bool LocalQuest::isCompletable(const PlayerInfo* player) const
[1996]169    {
170        return this->isActive(player);
171    }
[2092]172
[1996]173    /**
174    @brief
[2261]175        Returns the status of the Quest for a specific player.
[1992]176    @param player
[1996]177        The player.
178    @return
[2261]179        Returns the status of the Quest for the input player.
[2068]180    @throws
181        Throws an Exception if player is NULL.
[1992]182    */
[2261]183    questStatus::Enum LocalQuest::getStatus(const PlayerInfo* player) const
[1992]184    {
[2261]185        if(player == NULL) //!< No player has no defined status.
[2068]186        {
[2261]187            ThrowException(Argument, "The input PlayerInfo* is NULL.");
[2068]188        }
[2092]189
[2261]190        std::map<const PlayerInfo*, questStatus::Enum>::const_iterator it = this->playerStatus_.find(player);
191        if (it != this->playerStatus_.end()) //!< If there is a player in the map.
[2093]192        {
193            return it->second;
194        }
[2261]195       
196        return questStatus::inactive; //!< If the player is not yet in the map, that means the status of the quest form him is 'inactive'.
[1992]197    }
[2092]198
[1992]199    /**
200    @brief
201        Sets the status for a specific player.
[2261]202        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. Really!
[1992]203    @param player
[2261]204        The player the status should be set for.
[1992]205    @param status
[2261]206        The status to be set.
[2068]207    @return
208        Returns false if player is NULL.
[1992]209    */
[2261]210    bool LocalQuest::setStatus(PlayerInfo* player, const questStatus::Enum & status)
[1992]211    {
[2261]212        if(player == NULL) //!< We can't set a status for no player.
[2068]213        {
214            return false;
[2093]215        }
[2261]216       
[2021]217        this->playerStatus_[player] = status;
218        return true;
[1992]219    }
220
221}
Note: See TracBrowser for help on using the repository browser.