Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/modules/questsystem/LocalQuest.cc @ 6430

Last change on this file since 6430 was 6417, checked in by rgrieder, 15 years ago

Merged presentation2 branch back to trunk.
Major new features:

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