Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/orxonox/objects/quest/LocalQuest.cc @ 2662

Last change on this file since 2662 was 2662, checked in by rgrieder, 16 years ago

Merged presentation branch back to trunk.

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