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

    r2105 r2261  
    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/infos/PlayerInfo.h"
    3441#include "QuestManager.h"
    3542#include "QuestDescription.h"
     
    3946namespace orxonox {
    4047
     48    /**
     49    @brief
     50        Constructor. Registers and initializes object.
     51    */
    4152    Quest::Quest(BaseObject* creator) : QuestItem(creator)
    4253    {
    4354        RegisterObject(Quest);
    4455
    45         this->initialize();
     56        this->parentQuest_ = NULL;
    4657    }
    4758
     
    5566    }
    5667
     68    /**
     69    @brief
     70        Method for creating a Quest object through XML.
     71    */
    5772    void Quest::XMLPort(Element& xmlelement, XMLPort::Mode mode)
    5873    {
    5974        SUPER(Quest, XMLPort, xmlelement, mode);
    6075
    61         XMLPortObject(Quest, Quest, "", addSubQuest, getSubQuests, xmlelement, mode);
    62         XMLPortObject(Quest, QuestHint, "", addHint, getHints, xmlelement, mode);
    63         XMLPortObject(Quest, QuestEffect, "fail-effects", addFailEffect, getFailEffects, xmlelement, mode);
    64         XMLPortObject(Quest, QuestEffect, "complete-effects", addCompleteEffect, getCompleteEffects, xmlelement, mode);
    65 
    66         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;
    78     }
    79 
    80     /**
    81     @brief
    82         Sets the parent quest of the quest.
     76        XMLPortObject(Quest, Quest, "subquests", addSubQuest, getSubQuest, xmlelement, mode);
     77        XMLPortObject(Quest, QuestHint, "hints", addHint, getHint, xmlelement, mode);
     78        XMLPortObject(Quest, QuestEffect, "fail-effects", addFailEffect, getFailEffect, xmlelement, mode);
     79        XMLPortObject(Quest, QuestEffect, "complete-effects", addCompleteEffect, getCompleteEffect, xmlelement, mode);
     80
     81        QuestManager::registerQuest(this); //!<Registers the Quest with the QuestManager.
     82    }
     83
     84    /**
     85    @brief
     86        Sets the parentquest of the Quest.
    8387    @param quest
    84         A pointer to the quest to be set as parent quest.
    85     @return
    86         Returns true if the parentQuest could be set.
     88        A pointer to the Quest to be set as parentquest.
     89    @return
     90        Returns true if the parentquest could be set.
    8791    */
    8892    bool Quest::setParentQuest(Quest* quest)
    8993    {
    90         if(quest == NULL)
     94        if(quest == NULL) //!< We don't want to set NULL-Pointers.
    9195        {
    9296            COUT(2) << "The parentquest to be added to quest {" << this->getId() << "} was NULL." << std::endl;
     
    102106    /**
    103107    @brief
    104         Adds a sub quest to the quest.
     108        Adds a subquest to the Quest.
    105109    @param quest
    106         A pointer to the quest to be set as sub quest.
    107     @return
    108         Returns true if the subQuest vould be set.
     110        A pointer to the Quest to be set as subquest.
     111    @return
     112        Returns true if the subquest could be set.
    109113    */
    110114    bool Quest::addSubQuest(Quest* quest)
    111115    {
    112         if(quest == NULL)
     116        if(quest == NULL) //!< We don't want to set NULL-Pointers.
    113117        {
    114118            COUT(2) << "The subquest to be added to quest {" << this->getId() << "} was NULL." << std::endl;
     
    116120        }
    117121
    118         quest->setParentQuest(this);
    119         this->subQuests_.push_back(quest);
     122        quest->setParentQuest(this); //!< Sets the currentQuest (this) as parentquest for the added subquest.
     123        this->subQuests_.push_back(quest); //!< Adds the Quest to the end of the list of subquests.
    120124
    121125        COUT(3) << "Sub Quest {" << quest->getId() << "} was added to Quest {" << this->getId() << "}." << std::endl;
     
    126130    /**
    127131    @brief
    128         Adds a Hint to the list of hints
     132        Adds a QuestHint to the list of QuestHints
    129133    @param hint
    130         The hint that should be added to the list of hints.
     134        The QuestHint that should be added to the list of QuestHints.
    131135    @return
    132136        Returns true if the hint was successfully added.
     
    134138    bool Quest::addHint(QuestHint* hint)
    135139    {
    136         if(hint == NULL)
     140        if(hint == NULL) //!< We don't want to set NULL-Pointers. Seriously!
    137141        {
    138142            COUT(2) << "A NULL-QuestHint was trying to be added." << std::endl;
     
    140144        }
    141145
    142         this->hints_.push_back(hint);
    143         hint->setQuest(this);
     146        hint->setQuest(this); //!< Sets the current Quest (this) as Quest for the added QuestHint.
     147        this->hints_.push_back(hint); //!< Adds the QuestHint to the end of the list of QuestHints.
    144148
    145149        COUT(3) << "QuestHint {" << hint->getId() << "} was added to Quest {" << this->getId() << "}." << std::endl;
     
    149153    /**
    150154    @brief
    151 
     155        Adds an QuestEffect to the list of fail QuestEffects.
     156    @param effect
     157        The QuestEffect to be added.
     158    @return
     159        Returns true if successful.
    152160    */
    153161    bool Quest::addFailEffect(QuestEffect* effect)
    154162    {
    155         if(effect == NULL)
     163        if(effect == NULL) //!< We don't want to set NULL-Pointers.
    156164        {
    157165            COUT(2) << "A NULL-QuestEffect was trying to be added" << std::endl;
     
    159167        }
    160168
    161         this->failEffects_.push_back(effect);
     169        this->failEffects_.push_back(effect); //!< Adds the QuestEffect to the end of the list of fail QuestEffects.
    162170
    163171        COUT(3) << "A FailEffect was added to Quest {" << this->getId() << "}." << std::endl;
     
    167175    /**
    168176    @brief
    169 
     177        Adds an QuestEffect to the list of complete QuestEffects.
     178    @param effect
     179        The QuestEffect to be added.
     180    @return
     181        Returns true if successful.
    170182    */
    171183    bool Quest::addCompleteEffect(QuestEffect* effect)
    172184    {
    173         if(effect == NULL)
     185        if(effect == NULL) //!< We don't want to set NULL-Pointers.
    174186        {
    175187            COUT(2) << "A NULL-QuestEffect was trying to be added" << std::endl;
     
    177189        }
    178190
    179         this->completeEffects_.push_back(effect);
     191        this->completeEffects_.push_back(effect); //!< Adds the QuestEffect to the end of the list of complete QuestEffects.
    180192
    181193        COUT(3) << "A CompleteEffect was added to Quest {" << this->getId() << "}." << std::endl;
     
    185197    /**
    186198    @brief
    187 
     199        Returns the parentquest of the Quest.
     200    @return
     201        Returns a pointer to the parentquest of the Quest.
    188202    */
    189203    const Quest* Quest::getParentQuest(void)
     
    194208    /**
    195209    @brief
    196 
    197     */
    198     const Quest* Quest::getSubQuests(unsigned int index) const
     210        Returns the subquest at the given index.
     211    @param
     212        The index.
     213    @return
     214        Returns a pointer to the subquest at the given index. NULL if there is no element at the given index.
     215    */
     216    const Quest* Quest::getSubQuest(unsigned int index) const
    199217    {
    200218        int i = index;
     219       
     220        //! Iterate through all subquests.
    201221        for (std::list<Quest*>::const_iterator subQuest = this->subQuests_.begin(); subQuest != this->subQuests_.end(); ++subQuest)
    202222        {
    203             if(i == 0)
     223            if(i == 0) //!< We're counting down...
    204224            {
    205225               return *subQuest;
     
    207227            i--;
    208228        }
    209         return NULL;
    210     }
    211 
    212     /**
    213     @brief
    214 
    215     */
    216     const QuestHint* Quest::getHints(unsigned int index) const
     229       
     230        return NULL; //!< If the index is greater than the number of elements in the list.
     231    }
     232
     233    /**
     234    @brief
     235        Returns the QuestHint at the given index.
     236    @param
     237        The index.
     238    @return
     239        Returns a pointer to the QuestHint at the given index. NULL if there is no element at the given index.
     240    */
     241    const QuestHint* Quest::getHint(unsigned int index) const
    217242    {
    218243        int i = index;
     244       
     245        //! Iterate through all QuestHints.
    219246        for (std::list<QuestHint*>::const_iterator hint = this->hints_.begin(); hint != this->hints_.end(); ++hint)
    220247        {
    221             if(i == 0)
     248            if(i == 0) //!< We're counting down...
    222249            {
    223250               return *hint;
     
    225252            i--;
    226253        }
    227         return NULL;
    228     }
    229 
    230     /**
    231     @brief
    232 
    233     */
    234     const QuestEffect* Quest::getFailEffects(unsigned int index) const
     254        return NULL; //!< If the index is greater than the number of elements in the list.
     255    }
     256
     257    /**
     258    @brief
     259        Returns the fail QuestEffect at the given index.
     260    @param
     261        The index.
     262    @return
     263        Returns a pointer to the fail QuestEffect at the given index. NULL if there is no element at the given index.
     264    */
     265    const QuestEffect* Quest::getFailEffect(unsigned int index) const
    235266    {
    236267        int i = index;
     268       
     269        //! Iterate through all fail QuestEffects.
    237270        for (std::list<QuestEffect*>::const_iterator effect = this->failEffects_.begin(); effect != this->failEffects_.end(); ++effect)
    238271        {
    239             if(i == 0)
     272            if(i == 0) //!< We're counting down...
    240273            {
    241274               return *effect;
     
    243276            i--;
    244277        }
    245         return NULL;
    246     }
    247 
    248     /**
    249     @brief
    250 
    251     */
    252     const QuestEffect* Quest::getCompleteEffects(unsigned int index) const
     278        return NULL; //!< If the index is greater than the number of elements in the list.
     279    }
     280
     281    /**
     282    @brief
     283        Returns the complete QuestEffect at the given index.
     284    @param
     285        The index.
     286    @return
     287        Returns a pointer to the complete QuestEffect at the given index. NULL if there is no element at the given index.
     288    */
     289    const QuestEffect* Quest::getCompleteEffect(unsigned int index) const
    253290    {
    254291        int i = index;
     292       
     293        //! Iterate through all complete QuestEffects.
    255294        for (std::list<QuestEffect*>::const_iterator effect = this->completeEffects_.begin(); effect != this->completeEffects_.end(); ++effect)
    256295        {
    257             if(i == 0)
     296            if(i == 0) //!< We're counting down...
    258297            {
    259298               return *effect;
     
    261300            i--;
    262301        }
    263         return NULL;
     302        return NULL; //!< If the index is greater than the number of elements in the list.
    264303    }
    265304
     
    274313        Throws an exception if getStatus throws one.
    275314    */
    276     bool Quest::isInactive(const Player* player) const
     315    bool Quest::isInactive(const PlayerInfo* player) const
    277316    {
    278317        return this->getStatus(player) == questStatus::inactive;
     
    289328        Throws an exception if getStatus throws one.
    290329    */
    291     bool Quest::isActive(const Player* player) const
     330    bool Quest::isActive(const PlayerInfo* player) const
    292331    {
    293332
     
    305344        Throws an exception if getStatus throws one.
    306345    */
    307     bool Quest::isFailed(const Player* player) const
     346    bool Quest::isFailed(const PlayerInfo* player) const
    308347    {
    309348        return this->getStatus(player) == questStatus::failed;
     
    320359        Throws an exception if getStatus throws one.
    321360    */
    322     bool Quest::isCompleted(const Player* player) const
     361    bool Quest::isCompleted(const PlayerInfo* player) const
    323362    {
    324363        return this->getStatus(player) == questStatus::completed;
     
    327366    /**
    328367    @brief
    329         Starts the quest.
    330     @param player
    331         The player.
    332     @return
    333         Returns true if the quest could be started, false if not.
    334     */
    335     bool Quest::start(Player* player)
    336     {
    337         if(this->isStartable(player))
     368        Starts the Quest for an input player.
     369    @param player
     370        The player.
     371    @return
     372        Returns true if the Quest could be started, false if not.
     373    */
     374    bool Quest::start(PlayerInfo* player)
     375    {
     376        if(this->isStartable(player)) //!< Checks whether the quest can be started.
    338377        {
    339378            this->setStatus(player, questStatus::active);
    340379            return true;
    341380        }
    342         COUT(2) << "A non-startable quest was trying to be started." << std::endl;
     381       
     382        COUT(4) << "A non-startable quest was trying to be started." << std::endl;
    343383        return false;
    344384    }
    345385
    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 
    386386}
Note: See TracChangeset for help on using the changeset viewer.