Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 25, 2008, 11:56:40 PM (15 years ago)
Author:
landauf
Message:

merged questsystem2 back to trunk

Location:
code/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/orxonox/objects/quest/LocalQuest.cc

    r2105 r2261  
    2727 */
    2828
     29/**
     30    @file LocalQuest.cc
     31    @brief
     32    Implementation of the LocalQuest class.
     33*/
     34
    2935#include "OrxonoxStableHeaders.h"
    3036#include "LocalQuest.h"
     
    3339#include "util/Exception.h"
    3440
     41#include "orxonox/objects/infos/PlayerInfo.h"
     42#include "QuestEffect.h"
     43
    3544namespace orxonox {
    3645
    3746    CreateFactory(LocalQuest);
    3847
     48    /**
     49    @brief
     50        Constructor. Registers and initializes the object.
     51    */
    3952    LocalQuest::LocalQuest(BaseObject* creator) : Quest(creator)
    4053    {
    4154        RegisterObject(LocalQuest);
    42 
    43         this->initialize();
    4455    }
    4556
     
    5364    }
    5465
     66    /**
     67    @brief
     68        Method for creating a LocalQuest object through XML.
     69    */
    5570    void LocalQuest::XMLPort(Element& xmlelement, XMLPort::Mode mode)
    5671    {
     
    6075    }
    6176
    62     void LocalQuest::initialize(void)
    63     {
    64         RegisterObject(LocalQuest);
    65     }
    66 
    67     /**
    68     @brief
    69         Checks whether the quest can be started.
     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)
     87    {
     88        if(this->isFailable(player)) //!< Checks whether the quest can be failed.
     89        {
     90            this->setStatus(player, questStatus::failed);
     91            QuestEffect::invokeEffects(player, this->getFailEffectList()); //!< Invoke the failEffects.
     92            return true;
     93        }
     94       
     95        COUT(4) << "A non-failable quest was trying to be failed." << std::endl;
     96        return false;
     97    }
     98
     99    /**
     100    @brief
     101        Completes the Quest for a given player.
     102    Invokes all the complete QuestEffects on the player.
     103    @param player
     104        The player.
     105    @return
     106        Returns true if the Quest could be completed, false if not.
     107    */
     108    bool LocalQuest::complete(PlayerInfo* player)
     109    {
     110        if(this->isCompletable(player)) //!< Checks whether the Quest can be completed.
     111        {
     112            this->setStatus(player, questStatus::completed);
     113            QuestEffect::invokeEffects(player, this->getCompleteEffectList()); //!< Invoke the complete QuestEffects.
     114            return true;
     115        }
     116       
     117        COUT(4) << "A non-completable quest was trying to be completed." << std::endl;
     118        return false;
     119    }
     120
     121    /**
     122    @brief
     123        Checks whether the Quest can be started.
    70124    @param player
    71125        The player for whom is to be checked.
    72126    @return
    73         Returns true if the quest can be started, false if not.
    74     @throws
    75         Throws an exception if isInactive(Player*) throws one.
    76     */
    77     bool LocalQuest::isStartable(const Player* player) const
    78     {
     127        Returns true if the Quest can be started, false if not.
     128    @throws
     129        Throws an exception if isInactive(PlayerInfo*) throws one.
     130    */
     131    bool LocalQuest::isStartable(const PlayerInfo* player) const
     132    {
     133        if(!(this->getParentQuest() == NULL || this->getParentQuest()->isActive(player)))
     134        {
     135            return false;
     136        }
    79137        return this->isInactive(player);
    80138    }
     
    82140    /**
    83141    @brief
    84         Checks whether the quest can be failed.
     142        Checks whether the Quest can be failed.
    85143    @param player
    86144        The player for whom is to be checked.
    87145    @return
    88         Returns true if the quest can be failed, false if not.
    89     @throws
    90         Throws an exception if isActive(Player*) throws one.
    91     */
    92     bool LocalQuest::isFailable(const Player* player) const
     146        Returns true if the Quest can be failed, false if not.
     147    @throws
     148        Throws an exception if isActive(PlayerInfo*) throws one.
     149    */
     150    bool LocalQuest::isFailable(const PlayerInfo* player) const
    93151    {
    94152        return this->isActive(player);
     
    97155    /**
    98156    @brief
    99         Checks whether the quest can be completed.
     157        Checks whether the Quest can be completed.
    100158    @param player
    101159        The player for whom is to be checked.
    102160    @return
    103         Returns true if the quest can be completed, false if not.
    104     @throws
    105         Throws an exception if isInactive(Player*) throws one.
    106     */
    107     bool LocalQuest::isCompletable(const Player* player) const
     161        Returns true if the Quest can be completed, false if not.
     162    @throws
     163        Throws an exception if isInactive(PlayerInfo*) throws one.
     164    */
     165    bool LocalQuest::isCompletable(const PlayerInfo* player) const
    108166    {
    109167        return this->isActive(player);
     
    112170    /**
    113171    @brief
    114         Returns the status of the quest for a specific player.
     172        Returns the status of the Quest for a specific player.
    115173    @param player
    116174        The player.
    117175    @return
    118         Returns the status of the quest for the input player.
     176        Returns the status of the Quest for the input player.
    119177    @throws
    120178        Throws an Exception if player is NULL.
    121179    */
    122     questStatus::Enum LocalQuest::getStatus(const Player* player) const
    123     {
    124         if(player == NULL)
    125         {
    126             ThrowException(Argument, "The input Player* is NULL.");
    127         }
    128 
    129         std::map<Player*, questStatus::Enum>::const_iterator it = this->playerStatus_.find((Player*)(void*)player); //Thx. to x3n for the (Player*)(void*) 'hack'.
    130         if (it != this->playerStatus_.end())
     180    questStatus::Enum LocalQuest::getStatus(const PlayerInfo* player) const
     181    {
     182        if(player == NULL) //!< No player has no defined status.
     183        {
     184            ThrowException(Argument, "The input PlayerInfo* is NULL.");
     185        }
     186
     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.
    131189        {
    132190            return it->second;
    133191        }
    134         return questStatus::inactive;
     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'.
    135194    }
    136195
     
    138197    @brief
    139198        Sets the status for a specific player.
    140         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.
    141     @param player
    142         The player.
     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!
     200    @param player
     201        The player the status should be set for.
    143202    @param status
    144         The status.
     203        The status to be set.
    145204    @return
    146205        Returns false if player is NULL.
    147206    */
    148     bool LocalQuest::setStatus(Player* player, const questStatus::Enum & status)
    149     {
    150         if(player == NULL)
     207    bool LocalQuest::setStatus(PlayerInfo* player, const questStatus::Enum & status)
     208    {
     209        if(player == NULL) //!< We can't set a status for no player.
    151210        {
    152211            return false;
    153212        }
     213       
    154214        this->playerStatus_[player] = status;
    155215        return true;
Note: See TracChangeset for help on using the changeset viewer.