Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 23, 2008, 10:40:38 PM (16 years ago)
Author:
rgrieder
Message:

merged revisions 2260 - 2508 from trunk to buggy.
I'm sorry that I have to commit every merge. But otherwise I get tons of conflicts I have to solve ten times over.
Note: did not merge deletion of src/util/testing, tortoise wasn't very friendly with that.

Location:
code/branches/bugger
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/bugger

  • code/branches/bugger/src/orxonox/objects/quest/GlobalQuest.cc

    r2105 r2530  
    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/infos/PlayerInfo.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. Registers the object.
    4251    */
    4352    GlobalQuest::GlobalQuest(BaseObject* creator) : Quest(creator)
    4453    {
    4554        RegisterObject(GlobalQuest);
    46 
    47         this->initialize();
    4855    }
    4956
     
    5663
    5764    }
    58 
     65   
     66    /**
     67    @brief
     68        Method for creating a GlobalQuest object through XML.
     69    */
    5970    void GlobalQuest::XMLPort(Element& xmlelement, XMLPort::Mode mode)
    6071    {
    6172        SUPER(GlobalQuest, XMLPort, xmlelement, mode);
     73       
     74        XMLPortObject(GlobalQuest, QuestEffect, "reward-effects", addRewardEffect, getRewardEffects, xmlelement, mode);
    6275
    6376        COUT(3) << "New GlobalQuest {" << this->getId() << "} created." << std::endl;
    6477    }
    65 
    66     void GlobalQuest::initialize(void)
    67     {
    68         RegisterObject(GlobalQuest);
    69     }
    70 
    71     /**
    72     @brief
    73         Checks whether the quest can be started.
     78   
     79    /**
     80    @brief
     81        Fails the Quest for all players.
     82        Invokes the fail QuestEffects on all the players possessing this Quest.
     83    @param player
     84        The player failing it.
     85    @return
     86        Returns true if the Quest could be failed, false if not.
     87    */
     88    bool GlobalQuest::fail(PlayerInfo* player)
     89    {
     90        if(this->isFailable(player)) //!< Check whether the Quest can be failed.
     91        {
     92            this->setStatus(player, questStatus::failed);
     93           
     94            //! Iterate through all players possessing this Quest.
     95            for(std::set<PlayerInfo*>::const_iterator it = players_.begin(); it != players_.end(); it++)
     96            {
     97                QuestEffect::invokeEffects(*it, this->getFailEffectList());
     98            }
     99
     100            return true;
     101        }
     102       
     103        COUT(4) << "A non-completable quest was trying to be failed." << std::endl;
     104        return false;
     105    }
     106
     107    /**
     108    @brief
     109        Completes the Quest for all players.
     110        Invokes the complete QuestEffects on all the players possessing this Quest.
     111        Invokes the reward QuestEffects on the player completing the Quest.
     112    @param player
     113        The player completing it.
     114    @return
     115        Returns true if the Quest could be completed, false if not.
     116    */
     117    bool GlobalQuest::complete(PlayerInfo* player)
     118    {
     119        if(this->isCompletable(player)) //!< Check whether the Quest can be completed.
     120        {
     121            this->setStatus(player, questStatus::completed);
     122           
     123            //! Iterate through all players possessing the Quest.
     124            for(std::set<PlayerInfo*>::const_iterator it = players_.begin(); it != players_.end(); it++)
     125            {
     126                QuestEffect::invokeEffects(*it, this->getCompleteEffectList());
     127            }
     128           
     129            QuestEffect::invokeEffects(player, this->rewards_); //!< Invoke reward QuestEffects on the player completing the Quest.
     130            return true;
     131        }
     132       
     133        COUT(4) << "A non-completable quest was trying to be completed." << std::endl;
     134        return false;
     135    }
     136
     137    /**
     138    @brief
     139        Checks whether the Quest can be started.
    74140    @param player
    75141        The player for whom is to be checked.
     
    79145        Throws an exception if either isInactive() of isActive() throws one.
    80146    */
    81     bool GlobalQuest::isStartable(const Player* player) const
    82     {
    83         return this->isInactive(player) ||  this->isActive(player);
    84     }
    85 
    86     /**
    87     @brief
    88         Checks whether the quest can be failed.
     147    bool GlobalQuest::isStartable(const PlayerInfo* player) const
     148    {
     149        if(!(this->getParentQuest() == NULL || this->getParentQuest()->isActive(player)))
     150        {
     151            return false;
     152        }
     153        return (this->isInactive(player) && !(this->status_ == questStatus::completed || this->status_ == questStatus::failed));
     154    }
     155
     156    /**
     157    @brief
     158        Checks whether the Quest can be failed.
    89159    @param player
    90160        The player for whom is to be checked.
    91161    @return
    92         Returns true if the quest can be failed, false if not.
     162        Returns true if the Quest can be failed, false if not.
    93163    @throws
    94164        Throws an Exception if isActive() throws one.
    95165    */
    96     bool GlobalQuest::isFailable(const Player* player) const
     166    bool GlobalQuest::isFailable(const PlayerInfo* player) const
    97167    {
    98168        return this->isActive(player);
     
    102172    /**
    103173    @brief
    104         Checks whether the quest can be completed.
     174        Checks whether the Quest can be completed.
    105175    @param player
    106176        The player for whom is to be checked.
    107177    @return
    108         Returns true if the quest can be completed, false if not.
     178        Returns true if the Quest can be completed, false if not.
    109179    @throws
    110180        Throws an Exception if isActive() throws one.
    111181    */
    112     bool GlobalQuest::isCompletable(const Player* player) const
     182    bool GlobalQuest::isCompletable(const PlayerInfo* player) const
    113183    {
    114184        return this->isActive(player);
     
    117187    /**
    118188    @brief
    119         Returns the status of the quest for a specific player.
     189        Returns the status of the Quest for a specific player.
    120190    @param player
    121191        The player.
     
    123193        Throws an Exception if player is NULL.
    124194    */
    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())
     195    questStatus::Enum GlobalQuest::getStatus(const PlayerInfo* player) const
     196    {
     197        if(player == NULL) //!< We don't want NULL-Pointers!
     198        {
     199            ThrowException(Argument, "The input PlayerInfo* is NULL.");
     200        }
     201
     202        //! Find the player.
     203        std::set<PlayerInfo*>::const_iterator it = this->players_.find((PlayerInfo*)(void*)player);
     204        if (it != this->players_.end()) //!< If the player was found.
    135205        {
    136206            return this->status_;
    137207        }
    138         else
    139         {
    140            return questStatus::inactive;
    141         }
    142 
     208
     209    return questStatus::inactive;
    143210    }
    144211
     
    154221        Returns false if player is NULL.
    155222    */
    156     bool GlobalQuest::setStatus(Player* player, const questStatus::Enum & status)
    157     {
    158         if(player == NULL)
     223    bool GlobalQuest::setStatus(PlayerInfo* player, const questStatus::Enum & status)
     224    {
     225        if(player == NULL) //!< We don't want NULL-Pointers!
    159226        {
    160227            return false;
    161228        }
    162229
    163         std::set<Player*>::const_iterator it = this->players_.find(player);
     230        //! Find the player.
     231        std::set<PlayerInfo*>::const_iterator it = this->players_.find(player);
    164232        if (it == this->players_.end()) //!< Player is not yet in the list.
    165233        {
    166             this->players_.insert(player);
    167         }
    168         this->status_ = status;
     234            this->players_.insert(player); //!< Add the player to the set.
     235        }
     236       
     237        this->status_ = status; //!< Set the status, which is global, remember...?
    169238        return true;
    170239    }
     240   
     241    /**
     242    @brief
     243        Adds a reward QuestEffect to the list of reward QuestEffects.
     244    @param effect
     245        The QuestEffect to be added.
     246    @return
     247        Returns true if successful.
     248    */
     249    bool GlobalQuest::addRewardEffect(QuestEffect* effect)
     250    {
     251        if(effect == NULL) //!< We don't want NULL-Pointers!
     252        {
     253            COUT(2) << "The reward effect to be added to quest {" << this->getId() << "} was NULL." << std::endl;
     254            return false;
     255        }
     256
     257        this->rewards_.push_back(effect); //!< Add the QuestEffect to the list.
     258
     259        COUT(3) << "Reward effect was added to Quest {" << this->getId() << "}." << std::endl;
     260        return true;
     261    }
     262   
     263    /**
     264    @brief
     265        Returns the reward QuestEffect at the given index.
     266    @param index
     267        The index.
     268    @return
     269        Returns the QuestEffect at the given index.
     270    */
     271    const QuestEffect* GlobalQuest::getRewardEffects(unsigned int index) const
     272    {
     273        int i = index;
     274        for (std::list<QuestEffect*>::const_iterator effect = this->rewards_.begin(); effect != this->rewards_.end(); ++effect)
     275        {
     276            if(i == 0)
     277            {
     278               return *effect;
     279            }
     280            i--;
     281        }
     282        return NULL;
     283    }
    171284
    172285
Note: See TracChangeset for help on using the changeset viewer.