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

    r2105 r2146  
    2626 *
    2727 */
     28 
     29/**
     30    @file Quest.cc
     31    @brief
     32        Implementation of the Quest class.
     33*/
    2834
    2935#include "OrxonoxStableHeaders.h"
     
    3238#include "core/CoreIncludes.h"
    3339
     40#include "orxonox/objects/worldentities/ControllableEntity.h"
    3441#include "QuestManager.h"
    3542#include "QuestDescription.h"
     
    3946namespace orxonox {
    4047
     48    /**
     49    @brief
     50        Constructor. Initializes object.
     51    */
    4152    Quest::Quest(BaseObject* creator) : QuestItem(creator)
    4253    {
     54        this->initialize();
     55    }
     56   
     57    /**
     58    @brief
     59        Initializes the object. Needs to be called first in every constructor of this class.
     60        Sets defaults.
     61    */
     62    void Quest::initialize(void)
     63    {
    4364        RegisterObject(Quest);
    4465
    45         this->initialize();
     66        this->parentQuest_ = NULL;
    4667    }
    4768
     
    5576    }
    5677
     78    /**
     79    @brief
     80        Method for creating a Quest object through XML.
     81    */
    5782    void Quest::XMLPort(Element& xmlelement, XMLPort::Mode mode)
    5883    {
    5984        SUPER(Quest, XMLPort, xmlelement, mode);
    6085
    61         XMLPortObject(Quest, Quest, "", addSubQuest, getSubQuests, xmlelement, mode);
    62         XMLPortObject(Quest, QuestHint, "", addHint, getHints, xmlelement, mode);
     86        XMLPortObject(Quest, Quest, "subquests", addSubQuest, getSubQuests, xmlelement, mode);
     87        XMLPortObject(Quest, QuestHint, "hints", addHint, getHints, xmlelement, mode);
    6388        XMLPortObject(Quest, QuestEffect, "fail-effects", addFailEffect, getFailEffects, xmlelement, mode);
    6489        XMLPortObject(Quest, QuestEffect, "complete-effects", addCompleteEffect, getCompleteEffects, xmlelement, mode);
    6590
    6691        QuestManager::registerQuest(this); //Registers the quest with the QuestManager.
    67     }
    68 
    69     /**
    70     @brief
    71         Initializes the object. Needs to be called first in every constructor of this class.
    72     */
    73     void Quest::initialize(void)
    74     {
    75         RegisterObject(Quest);
    76 
    77         this->parentQuest_ = NULL;
    7892    }
    7993
     
    88102    bool Quest::setParentQuest(Quest* quest)
    89103    {
    90         if(quest == NULL)
     104        if(quest == NULL) //!< We don't want to set NULL-Pointers.
    91105        {
    92106            COUT(2) << "The parentquest to be added to quest {" << this->getId() << "} was NULL." << std::endl;
     
    110124    bool Quest::addSubQuest(Quest* quest)
    111125    {
    112         if(quest == NULL)
     126        if(quest == NULL) //!< We don't want to set NULL-Pointers.
    113127        {
    114128            COUT(2) << "The subquest to be added to quest {" << this->getId() << "} was NULL." << std::endl;
     
    116130        }
    117131
    118         quest->setParentQuest(this);
    119         this->subQuests_.push_back(quest);
     132        quest->setParentQuest(this); //!< Sets the current quest (this) as parent quest for the added subquest.
     133        this->subQuests_.push_back(quest); //!< Adds the quest to the end of the list of subquests.
    120134
    121135        COUT(3) << "Sub Quest {" << quest->getId() << "} was added to Quest {" << this->getId() << "}." << std::endl;
     
    134148    bool Quest::addHint(QuestHint* hint)
    135149    {
    136         if(hint == NULL)
     150        if(hint == NULL) //!< We don't want to set NULL-Pointers. Seriously!
    137151        {
    138152            COUT(2) << "A NULL-QuestHint was trying to be added." << std::endl;
     
    140154        }
    141155
    142         this->hints_.push_back(hint);
    143         hint->setQuest(this);
     156        hint->setQuest(this); //!< Sets the current quest (this) as quest for the added hint.
     157        this->hints_.push_back(hint); //!< Adds the hint to the end of the list of hints.
    144158
    145159        COUT(3) << "QuestHint {" << hint->getId() << "} was added to Quest {" << this->getId() << "}." << std::endl;
     
    149163    /**
    150164    @brief
    151 
     165        Adds an effect to the list of failEffects.
     166    @param effect
     167        The QuestEffect to be added.
     168    @return
     169        Returns true if successful.
    152170    */
    153171    bool Quest::addFailEffect(QuestEffect* effect)
    154172    {
    155         if(effect == NULL)
     173        if(effect == NULL) //!< We don't want to set NULL-Pointers.
    156174        {
    157175            COUT(2) << "A NULL-QuestEffect was trying to be added" << std::endl;
     
    159177        }
    160178
    161         this->failEffects_.push_back(effect);
     179        this->failEffects_.push_back(effect); //!< Adds the effect to the end of the list of failEffects.
    162180
    163181        COUT(3) << "A FailEffect was added to Quest {" << this->getId() << "}." << std::endl;
     
    167185    /**
    168186    @brief
    169 
     187        Adds an effect to the list of completeEffects.
     188    @param effect
     189        The QuestEffect to be added.
     190    @return
     191        Returns true if successful.
    170192    */
    171193    bool Quest::addCompleteEffect(QuestEffect* effect)
    172194    {
    173         if(effect == NULL)
     195        if(effect == NULL) //!< We don't want to set NULL-Pointers.
    174196        {
    175197            COUT(2) << "A NULL-QuestEffect was trying to be added" << std::endl;
     
    177199        }
    178200
    179         this->completeEffects_.push_back(effect);
     201        this->completeEffects_.push_back(effect); //!< Adds the effect to the end of the list of completeEffects.
    180202
    181203        COUT(3) << "A CompleteEffect was added to Quest {" << this->getId() << "}." << std::endl;
     
    185207    /**
    186208    @brief
    187 
     209        Returns the parent quest of the quest.
     210    @return
     211        Returns the parent quest of the quest.
    188212    */
    189213    const Quest* Quest::getParentQuest(void)
     
    194218    /**
    195219    @brief
    196 
     220        Returns the sub quest of the given index.
     221    @param
     222        The index.
     223    @return
     224        Returns the subquest of the given index. NULL if there is no element on the given index.
    197225    */
    198226    const Quest* Quest::getSubQuests(unsigned int index) const
    199227    {
    200228        int i = index;
     229       
     230        //! Iterate through all subquests.
    201231        for (std::list<Quest*>::const_iterator subQuest = this->subQuests_.begin(); subQuest != this->subQuests_.end(); ++subQuest)
    202232        {
    203             if(i == 0)
     233            if(i == 0) //!< We're counting down...
    204234            {
    205235               return *subQuest;
     
    207237            i--;
    208238        }
    209         return NULL;
    210     }
    211 
    212     /**
    213     @brief
    214 
     239       
     240        return NULL; //!< If the index is greater than the number of elements in the list.
     241    }
     242
     243    /**
     244    @brief
     245        Returns the hint of the given index.
     246    @param
     247        The index.
     248    @return
     249        Returns the hint of the given index. NULL if there is no element on the given index.
    215250    */
    216251    const QuestHint* Quest::getHints(unsigned int index) const
    217252    {
    218253        int i = index;
     254       
     255        //! Iterate through all hints.
    219256        for (std::list<QuestHint*>::const_iterator hint = this->hints_.begin(); hint != this->hints_.end(); ++hint)
    220257        {
    221             if(i == 0)
     258            if(i == 0) //!< We're counting down...
    222259            {
    223260               return *hint;
     
    225262            i--;
    226263        }
    227         return NULL;
    228     }
    229 
    230     /**
    231     @brief
    232 
     264        return NULL; //!< If the index is greater than the number of elements in the list.
     265    }
     266
     267    /**
     268    @brief
     269        Returns the failEffect of the given index.
     270    @param
     271        The index.
     272    @return
     273        Returns the failEffect of the given index. NULL if there is no element on the given index.
    233274    */
    234275    const QuestEffect* Quest::getFailEffects(unsigned int index) const
    235276    {
    236277        int i = index;
     278       
     279        //! Iterate through all failEffects.
    237280        for (std::list<QuestEffect*>::const_iterator effect = this->failEffects_.begin(); effect != this->failEffects_.end(); ++effect)
    238281        {
    239             if(i == 0)
     282            if(i == 0) //!< We're counting down...
    240283            {
    241284               return *effect;
     
    243286            i--;
    244287        }
    245         return NULL;
    246     }
    247 
    248     /**
    249     @brief
    250 
     288        return NULL; //!< If the index is greater than the number of elements in the list.
     289    }
     290
     291    /**
     292    @brief
     293        Returns the completeEffect of the given index.
     294    @param
     295        The index.
     296    @return
     297        Returns the completeEffect of the given index. NULL if there is no element on the given index.
    251298    */
    252299    const QuestEffect* Quest::getCompleteEffects(unsigned int index) const
    253300    {
    254301        int i = index;
     302       
     303        //! Iterate through all completeEffects.
    255304        for (std::list<QuestEffect*>::const_iterator effect = this->completeEffects_.begin(); effect != this->completeEffects_.end(); ++effect)
    256305        {
    257             if(i == 0)
     306            if(i == 0) //!< We're counting down...
    258307            {
    259308               return *effect;
     
    261310            i--;
    262311        }
    263         return NULL;
     312        return NULL; //!< If the index is greater than the number of elements in the list.
    264313    }
    265314
     
    274323        Throws an exception if getStatus throws one.
    275324    */
    276     bool Quest::isInactive(const Player* player) const
     325    bool Quest::isInactive(const ControllableEntity* player) const
    277326    {
    278327        return this->getStatus(player) == questStatus::inactive;
     
    289338        Throws an exception if getStatus throws one.
    290339    */
    291     bool Quest::isActive(const Player* player) const
     340    bool Quest::isActive(const ControllableEntity* player) const
    292341    {
    293342
     
    305354        Throws an exception if getStatus throws one.
    306355    */
    307     bool Quest::isFailed(const Player* player) const
     356    bool Quest::isFailed(const ControllableEntity* player) const
    308357    {
    309358        return this->getStatus(player) == questStatus::failed;
     
    320369        Throws an exception if getStatus throws one.
    321370    */
    322     bool Quest::isCompleted(const Player* player) const
     371    bool Quest::isCompleted(const ControllableEntity* player) const
    323372    {
    324373        return this->getStatus(player) == questStatus::completed;
     
    327376    /**
    328377    @brief
    329         Starts the quest.
     378        Starts the quest for an input player.
    330379    @param player
    331380        The player.
     
    333382        Returns true if the quest could be started, false if not.
    334383    */
    335     bool Quest::start(Player* player)
    336     {
    337         if(this->isStartable(player))
     384    bool Quest::start(ControllableEntity* player)
     385    {
     386        if(this->isStartable(player)) //!< Checks whether the quest can be started.
    338387        {
    339388            this->setStatus(player, questStatus::active);
    340389            return true;
    341390        }
     391       
    342392        COUT(2) << "A non-startable quest was trying to be started." << std::endl;
    343393        return false;
    344394    }
    345395
    346     /**
    347     @brief
    348         Fails the quest.
    349     @param player
    350         The player.
    351     @return
    352         Returns true if the quest could be failed, false if not.
    353     */
    354     bool Quest::fail(Player* player)
    355     {
    356         if(this->isFailable(player))
    357         {
    358             this->setStatus(player, questStatus::failed);
    359             QuestEffect::invokeEffects(player, this->failEffects_);
    360             return true;
    361         }
    362         COUT(2) << "A non-failable quest was trying to be failed." << std::endl;
    363         return false;
    364     }
    365 
    366     /**
    367     @brief
    368         Completes the quest.
    369     @param player
    370         The player.
    371     @return
    372         Returns true if the quest could be completed, false if not.
    373     */
    374     bool Quest::complete(Player* player)
    375     {
    376         if(this->isCompletable(player))
    377         {
    378             this->setStatus(player, questStatus::completed);
    379             QuestEffect::invokeEffects(player, this->completeEffects_);
    380             return true;
    381         }
    382         COUT(2) << "A non-completable quest was trying to be completed." << std::endl;
    383         return false;
    384     }
    385 
    386396}
Note: See TracChangeset for help on using the changeset viewer.