Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 6, 2008, 12:02:05 AM (16 years ago)
Author:
dafrick
Message:

Started implementation of QuestEffectBeacon.
Done some documentation of QuestItem and subclasses.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/questsystem2/src/orxonox/objects/quest/LocalQuest.cc

    r2105 r2146  
    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/worldentities/ControllableEntity.h"
     42#include "QuestEffect.h"
     43
    3544namespace orxonox {
    3645
    3746    CreateFactory(LocalQuest);
    3847
     48    /**
     49    @brief
     50        Constructor. Initializes the object.
     51    */
    3952    LocalQuest::LocalQuest(BaseObject* creator) : Quest(creator)
    4053    {
     54        this->initialize();
     55    }
     56   
     57    /**
     58    @brief
     59        Initializes the object.
     60    */
     61    void LocalQuest::initialize(void)
     62    {
    4163        RegisterObject(LocalQuest);
    42 
    43         this->initialize();
    4464    }
    4565
     
    5373    }
    5474
     75    /**
     76    @brief
     77        Method for creating a LocalQuest object through XML.
     78    */
    5579    void LocalQuest::XMLPort(Element& xmlelement, XMLPort::Mode mode)
    5680    {
     
    6084    }
    6185
    62     void LocalQuest::initialize(void)
    63     {
    64         RegisterObject(LocalQuest);
     86    /**
     87    @brief
     88        Fails the quest for a given player.
     89        Invokes all the failEffects on the player.
     90    @param player
     91        The player.
     92    @return
     93        Returns true if the quest could be failed, false if not.
     94    */
     95    bool LocalQuest::fail(ControllableEntity* player)
     96    {
     97        if(this->isFailable(player)) //!< Checks whether the quest can be failed.
     98        {
     99            this->setStatus(player, questStatus::failed);
     100            QuestEffect::invokeEffects(player, this->failEffects_); //!< Invoke the failEffects.
     101            return true;
     102        }
     103       
     104        COUT(2) << "A non-failable quest was trying to be failed." << std::endl;
     105        return false;
     106    }
     107
     108    /**
     109    @brief
     110        Completes the quest for a given player.
     111        Invokes all the completeEffects on the player.
     112    @param player
     113        The player.
     114    @return
     115        Returns true if the quest could be completed, false if not.
     116    */
     117    bool LocalQuest::complete(ControllableEntity* player)
     118    {
     119        if(this->isCompletable(player)) //!< Checks whether the quest can be completed.
     120        {
     121            this->setStatus(player, questStatus::completed);
     122            QuestEffect::invokeEffects(player, this->completeEffects_); //!< Invoke the completeEffects.
     123            return true;
     124        }
     125       
     126        COUT(2) << "A non-completable quest was trying to be completed." << std::endl;
     127        return false;
    65128    }
    66129
     
    73136        Returns true if the quest can be started, false if not.
    74137    @throws
    75         Throws an exception if isInactive(Player*) throws one.
    76     */
    77     bool LocalQuest::isStartable(const Player* player) const
     138        Throws an exception if isInactive(ControllableEntity*) throws one.
     139    */
     140    bool LocalQuest::isStartable(const ControllableEntity* player) const
    78141    {
    79142        return this->isInactive(player);
     
    88151        Returns true if the quest can be failed, false if not.
    89152    @throws
    90         Throws an exception if isActive(Player*) throws one.
    91     */
    92     bool LocalQuest::isFailable(const Player* player) const
     153        Throws an exception if isActive(ControllableEntity*) throws one.
     154    */
     155    bool LocalQuest::isFailable(const ControllableEntity* player) const
    93156    {
    94157        return this->isActive(player);
     
    103166        Returns true if the quest can be completed, false if not.
    104167    @throws
    105         Throws an exception if isInactive(Player*) throws one.
    106     */
    107     bool LocalQuest::isCompletable(const Player* player) const
     168        Throws an exception if isInactive(ControllableEntity*) throws one.
     169    */
     170    bool LocalQuest::isCompletable(const ControllableEntity* player) const
    108171    {
    109172        return this->isActive(player);
     
    120183        Throws an Exception if player is NULL.
    121184    */
    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())
     185    questStatus::Enum LocalQuest::getStatus(const ControllableEntity* player) const
     186    {
     187        if(player == NULL) //!< No player has no defined status.
     188        {
     189            ThrowException(Argument, "The input ControllableEntity* is NULL.");
     190        }
     191
     192        std::map<ControllableEntity*, questStatus::Enum>::const_iterator it = this->playerStatus_.find((ControllableEntity*)(void*)player); //Thx. to x3n for the (ControllableEntity*)(void*) 'hack'.
     193        if (it != this->playerStatus_.end()) //!< If there is a player in the map.
    131194        {
    132195            return it->second;
    133196        }
    134         return questStatus::inactive;
     197       
     198        return questStatus::inactive; //!< If the player is not yet in the map, that means the status of the quest form him is 'inactive'.
    135199    }
    136200
     
    138202    @brief
    139203        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.
     204        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!
     205    @param player
     206        The player the status should be set for.
    143207    @param status
    144         The status.
     208        The status to be set.
    145209    @return
    146210        Returns false if player is NULL.
    147211    */
    148     bool LocalQuest::setStatus(Player* player, const questStatus::Enum & status)
    149     {
    150         if(player == NULL)
     212    bool LocalQuest::setStatus(ControllableEntity* player, const questStatus::Enum & status)
     213    {
     214        if(player == NULL) //!< We can't set a status for no player.
    151215        {
    152216            return false;
    153217        }
     218       
    154219        this->playerStatus_[player] = status;
    155220        return true;
Note: See TracChangeset for help on using the changeset viewer.