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/GlobalQuest.cc

    r2105 r2146  
    2626 *
    2727 */
     28 
     29/**
     30    @file GlobalQuest.cc
     31    @brief
     32        Implementation of the GlobalQuest class.
     33*/
    2834
    2935#include "OrxonoxStableHeaders.h"
    3036#include "GlobalQuest.h"
    3137
     38#include "orxonox/objects/worldentities/ControllableEntity.h"
    3239#include "core/CoreIncludes.h"
    3340#include "util/Exception.h"
    3441
     42#include "QuestEffect.h"
     43
    3544namespace orxonox {
    3645
     
    3948    /**
    4049    @brief
    41         Constructor.
     50        Constructor. Initializes the object.
    4251    */
    4352    GlobalQuest::GlobalQuest(BaseObject* creator) : Quest(creator)
    4453    {
     54        this->initialize();
     55    }
     56   
     57    /**
     58    @brief
     59        Initializes the object.
     60    */
     61    void GlobalQuest::initialize(void)
     62    {
    4563        RegisterObject(GlobalQuest);
    46 
    47         this->initialize();
    4864    }
    4965
     
    5672
    5773    }
    58 
     74   
     75    /**
     76    @brief
     77        Method for creating a GlobalQuest object through XML.
     78    */
    5979    void GlobalQuest::XMLPort(Element& xmlelement, XMLPort::Mode mode)
    6080    {
    6181        SUPER(GlobalQuest, XMLPort, xmlelement, mode);
     82       
     83        XMLPortObject(GlobalQuest, QuestEffect, "reward-effects", addRewardEffect, getRewardEffects, xmlelement, mode);
    6284
    6385        COUT(3) << "New GlobalQuest {" << this->getId() << "} created." << std::endl;
    6486    }
    65 
    66     void GlobalQuest::initialize(void)
    67     {
    68         RegisterObject(GlobalQuest);
     87   
     88    /**
     89    @brief
     90        Fails the quest for all players.
     91        Invokes the failEffects on all the players possessing this quest.
     92    @param player
     93        The player failing it.
     94    @return
     95        Returns true if the quest could be failed, false if not.
     96    */
     97    bool GlobalQuest::fail(ControllableEntity* player)
     98    {
     99        if(this->isFailable(player)) //!< Check whether the quest can be failed.
     100        {
     101            this->setStatus(player, questStatus::failed);
     102           
     103            //! Iterate through all players possessing this quest.
     104            for(std::set<ControllableEntity*>::const_iterator it = players_.begin(); it != players_.end(); it++)
     105            {
     106                QuestEffect::invokeEffects(*it, this->failEffects_);
     107            }
     108
     109            return true;
     110        }
     111       
     112        COUT(2) << "A non-completable quest was trying to be failed." << std::endl;
     113        return false;
     114    }
     115
     116    /**
     117    @brief
     118        Completes the quest for all players.
     119        Invokes the completeEffects on all the players possessing this quest.
     120        Invokes the reward effects on the player completing the quest.
     121    @param player
     122        The player completing it.
     123    @return
     124        Returns true if the quest could be completed, false if not.
     125    */
     126    bool GlobalQuest::complete(ControllableEntity* player)
     127    {
     128        if(this->isCompletable(player)) //!< Check whether the quest can be completed.
     129        {
     130            this->setStatus(player, questStatus::completed);
     131           
     132            //! Iterate through all players possessing the quest.
     133            for(std::set<ControllableEntity*>::const_iterator it = players_.begin(); it != players_.end(); it++)
     134            {
     135                QuestEffect::invokeEffects(*it, this->completeEffects_);
     136            }
     137           
     138            QuestEffect::invokeEffects(player, this->rewards_); //!< Invoke reward effects on the player completing the quest.
     139            return true;
     140        }
     141       
     142        COUT(2) << "A non-completable quest was trying to be completed." << std::endl;
     143        return false;
    69144    }
    70145
     
    79154        Throws an exception if either isInactive() of isActive() throws one.
    80155    */
    81     bool GlobalQuest::isStartable(const Player* player) const
     156    bool GlobalQuest::isStartable(const ControllableEntity* player) const
    82157    {
    83158        return this->isInactive(player) ||  this->isActive(player);
     
    94169        Throws an Exception if isActive() throws one.
    95170    */
    96     bool GlobalQuest::isFailable(const Player* player) const
     171    bool GlobalQuest::isFailable(const ControllableEntity* player) const
    97172    {
    98173        return this->isActive(player);
     
    110185        Throws an Exception if isActive() throws one.
    111186    */
    112     bool GlobalQuest::isCompletable(const Player* player) const
     187    bool GlobalQuest::isCompletable(const ControllableEntity* player) const
    113188    {
    114189        return this->isActive(player);
     
    123198        Throws an Exception if player is NULL.
    124199    */
    125     questStatus::Enum GlobalQuest::getStatus(const Player* player) const
    126     {
    127         if(player == NULL)
    128         {
    129             ThrowException(Argument, "The input Player* is NULL.");
    130         }
    131 
    132         //TDO: Does this really work???
    133         std::set<Player*>::const_iterator it = this->players_.find((Player*)(void*)player);
    134         if (it != this->players_.end())
     200    questStatus::Enum GlobalQuest::getStatus(const ControllableEntity* player) const
     201    {
     202        if(player == NULL) //!< We don't want NULL-Pointers!
     203        {
     204            ThrowException(Argument, "The input ControllableEntity* is NULL.");
     205        }
     206
     207        //! Find the player.
     208        std::set<ControllableEntity*>::const_iterator it = this->players_.find((ControllableEntity*)(void*)player);
     209        if (it != this->players_.end()) //!< If the player was found.
    135210        {
    136211            return this->status_;
    137212        }
    138         else
    139         {
    140            return questStatus::inactive;
    141         }
    142 
     213
     214        return questStatus::inactive;
    143215    }
    144216
     
    154226        Returns false if player is NULL.
    155227    */
    156     bool GlobalQuest::setStatus(Player* player, const questStatus::Enum & status)
    157     {
    158         if(player == NULL)
     228    bool GlobalQuest::setStatus(ControllableEntity* player, const questStatus::Enum & status)
     229    {
     230        if(player == NULL) //!< We don't want NULL-Pointers!
    159231        {
    160232            return false;
    161233        }
    162234
    163         std::set<Player*>::const_iterator it = this->players_.find(player);
     235        //! Find the player.
     236        std::set<ControllableEntity*>::const_iterator it = this->players_.find(player);
    164237        if (it == this->players_.end()) //!< Player is not yet in the list.
    165238        {
    166             this->players_.insert(player);
    167         }
    168         this->status_ = status;
     239            this->players_.insert(player); //!< Add the player to the set.
     240        }
     241       
     242        this->status_ = status; //!< Set the status, which is global, remember...?
    169243        return true;
    170244    }
     245   
     246    /**
     247    @brief
     248        Adds a reward effect to the list of reward effects.
     249    @param effect
     250        The effect to be added.
     251    @return
     252        Returns true if successful.
     253    */
     254    bool GlobalQuest::addRewardEffect(QuestEffect* effect)
     255    {
     256        if(effect == NULL) //!< We don't want NULL-Pointers!
     257        {
     258            COUT(2) << "The reward effect to be added to quest {" << this->getId() << "} was NULL." << std::endl;
     259            return false;
     260        }
     261
     262        this->rewards_.push_back(effect); //!< Add the effect to the list.
     263
     264        COUT(3) << "Reward effect was added to Quest {" << this->getId() << "}." << std::endl;
     265        return true;
     266    }
     267   
     268    /**
     269    @brief
     270        Returns the reward effect at the given index.
     271    @param index
     272        The index.
     273    @return
     274        Returns the QuestEffect at the given index.
     275    */
     276    const QuestEffect* GlobalQuest::getRewardEffects(unsigned int index) const
     277    {
     278        int i = index;
     279        for (std::list<QuestEffect*>::const_iterator effect = this->rewards_.begin(); effect != this->rewards_.end(); ++effect)
     280        {
     281            if(i == 0)
     282            {
     283               return *effect;
     284            }
     285            i--;
     286        }
     287        return NULL;
     288    }
    171289
    172290
Note: See TracChangeset for help on using the changeset viewer.