Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/pch/src/orxonox/objects/quest/LocalQuest.cc @ 3177

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

Removed the filename part of all @file foo.cc because Doxygen chooses the (always correct) filename automatically.
Also removed a few <string> includes that are not necessary.

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