Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 3, 2008, 4:40:00 PM (16 years ago)
Author:
dafrick
Message:
  • Created QuestListeners, they can be used to affect Objects due to status changes of quests.
Location:
code/branches/questsystem3/src/orxonox/objects/quest
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • code/branches/questsystem3/src/orxonox/objects/quest/AddQuest.cc

    r2261 r2328  
    4242
    4343#include "orxonox/objects/infos/PlayerInfo.h"
     44#include "orxonox/overlays/notifications/Notification.h"
    4445#include "QuestManager.h"
    4546#include "Quest.h"
     
    110111
    111112        COUT(3) << "Quest {" << this->getQuestId() << "} successfully added to player." << std::endl;
     113        Notification* notification = new Notification("Crazy Message...", "Title", 30);
     114        notification->send();
    112115        return true;
    113116    }
  • code/branches/questsystem3/src/orxonox/objects/quest/CMakeLists.txt

    r2261 r2328  
    1414  QuestHint.cc
    1515  QuestItem.cc
     16  QuestListener.cc
    1617  QuestManager.cc
    1718  Rewardable.cc
  • code/branches/questsystem3/src/orxonox/objects/quest/FailQuest.cc

    r2261 r2328  
    4040
    4141#include "orxonox/objects/infos/PlayerInfo.h"
     42#include "orxonox/overlays/notifications/Notification.h"
    4243#include "QuestManager.h"
    4344#include "Quest.h"
  • code/branches/questsystem3/src/orxonox/objects/quest/GlobalQuest.cc

    r2261 r2328  
    3838#include "orxonox/objects/infos/PlayerInfo.h"
    3939#include "core/CoreIncludes.h"
     40#include "core/Super.h"
    4041#include "util/Exception.h"
    4142
     
    8889    bool GlobalQuest::fail(PlayerInfo* player)
    8990    {
    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;
     91        if(!this->isFailable(player)) //!< Check whether the Quest can be failed.
     92        {
     93            COUT(4) << "A non-completable quest was trying to be failed." << std::endl;
     94            return false;
     95        }
     96       
     97        Quest::fail(player);
     98       
     99        //! Iterate through all players possessing this Quest.
     100        for(std::set<PlayerInfo*>::const_iterator it = players_.begin(); it != players_.end(); it++)
     101        {
     102            QuestEffect::invokeEffects(*it, this->getFailEffectList());
     103        }
     104
     105        return true;
    105106    }
    106107
     
    117118    bool GlobalQuest::complete(PlayerInfo* player)
    118119    {
    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;
     120        if(!this->isCompletable(player)) //!< Check whether the Quest can be completed.
     121        {
     122            COUT(4) << "A non-completable quest was trying to be completed." << std::endl;
     123            return false;
     124        }
     125       
     126        //! Iterate through all players possessing the Quest.
     127        for(std::set<PlayerInfo*>::const_iterator it = players_.begin(); it != players_.end(); it++)
     128        {
     129            QuestEffect::invokeEffects(*it, this->getCompleteEffectList());
     130        }
     131       
     132        Quest::complete(player);
     133       
     134        QuestEffect::invokeEffects(player, this->rewards_); //!< Invoke reward QuestEffects on the player completing the Quest.
     135        return true;
    135136    }
    136137
  • code/branches/questsystem3/src/orxonox/objects/quest/LocalQuest.cc

    r2261 r2328  
    3737
    3838#include "core/CoreIncludes.h"
     39#include "core/Super.h"
    3940#include "util/Exception.h"
    4041
     
    8687    bool LocalQuest::fail(PlayerInfo* player)
    8788    {
    88         if(this->isFailable(player)) //!< Checks whether the quest can be failed.
    89         {
    90             this->setStatus(player, questStatus::failed);
    91             QuestEffect::invokeEffects(player, this->getFailEffectList()); //!< Invoke the failEffects.
    92             return true;
    93         }
    94        
    95         COUT(4) << "A non-failable quest was trying to be failed." << std::endl;
    96         return false;
     89        if(!this->isFailable(player)) //!< Checks whether the quest can be failed.
     90        {
     91            COUT(4) << "A non-failable quest was trying to be failed." << std::endl;
     92            return false;
     93        }
     94       
     95        Quest::fail(player);
     96       
     97        QuestEffect::invokeEffects(player, this->getFailEffectList()); //!< Invoke the failEffects.
     98        return true;
    9799    }
    98100
     
    108110    bool LocalQuest::complete(PlayerInfo* player)
    109111    {
    110         if(this->isCompletable(player)) //!< Checks whether the Quest can be completed.
    111         {
    112             this->setStatus(player, questStatus::completed);
    113             QuestEffect::invokeEffects(player, this->getCompleteEffectList()); //!< Invoke the complete QuestEffects.
    114             return true;
    115         }
    116        
    117         COUT(4) << "A non-completable quest was trying to be completed." << std::endl;
    118         return false;
     112        if(!this->isCompletable(player)) //!< Checks whether the Quest can be completed.
     113        {
     114            COUT(4) << "A non-completable quest was trying to be completed." << std::endl;
     115            return false;
     116        }
     117       
     118        Quest::complete(player);
     119       
     120        QuestEffect::invokeEffects(player, this->getCompleteEffectList()); //!< Invoke the complete QuestEffects.
     121        return true;
    119122    }
    120123
  • code/branches/questsystem3/src/orxonox/objects/quest/Quest.cc

    r2261 r2328  
    4343#include "QuestHint.h"
    4444#include "QuestEffect.h"
     45#include "QuestListener.h"
    4546
    4647namespace orxonox {
     
    363364        return this->getStatus(player) == questStatus::completed;
    364365    }
     366   
     367    /**
     368    @brief
     369        Fails the Quest for an input player.
     370    @param player
     371        The player.
     372    @return
     373        Returns true if the Quest could be failed, false if not.
     374    */
     375    bool Quest::fail(PlayerInfo* player)
     376    {
     377        QuestListener::advertiseStatusChange(this->listeners_, "fail"); //!< Tells the QuestListeners, that the status has changed to failed.
     378        this->setStatus(player, questStatus::failed);
     379        return true;
     380    }
     381   
     382    /**
     383    @brief
     384        Completes the Quest for an input player.
     385    @param player
     386        The player.
     387    @return
     388        Returns true if the Quest could be completed, false if not.
     389    */
     390    bool Quest::complete(PlayerInfo* player)
     391    {
     392        QuestListener::advertiseStatusChange(this->listeners_, "complete"); //!< Tells the QuestListeners, that the status has changed to completed.
     393        this->setStatus(player, questStatus::completed);
     394        return true;
     395    }
    365396
    366397    /**
     
    374405    bool Quest::start(PlayerInfo* player)
    375406    {
    376         if(this->isStartable(player)) //!< Checks whether the quest can be started.
    377         {
    378             this->setStatus(player, questStatus::active);
    379             return true;
    380         }
    381        
    382         COUT(4) << "A non-startable quest was trying to be started." << std::endl;
    383         return false;
     407        if(!this->isStartable(player)) //!< Checks whether the quest can be started.
     408        {
     409            COUT(4) << "A non-startable quest was trying to be started." << std::endl;
     410            return false;
     411        }
     412       
     413        QuestListener::advertiseStatusChange(this->listeners_, "start"); //!< Tells the QuestListeners, that the status has changed to active.
     414       
     415        this->setStatus(player, questStatus::active);
     416        return true;
     417    }
     418   
     419    /**
     420    @brief
     421        Adds a QuestListener to the list of QuestListeners listening to this Quest.
     422    @param listener
     423        The QuestListener to be added.
     424    @return
     425        Returns true if successful, false if not.
     426    */
     427    bool Quest::addListener(QuestListener* listener)
     428    {
     429        if(listener == NULL)
     430        {
     431            COUT(2) << "A NULL-QuestListener was trying to be added to a Quests listeners." << std::endl;
     432            return false;
     433        }
     434       
     435        this->listeners_.push_back(listener);
     436        return true;
    384437    }
    385438
  • code/branches/questsystem3/src/orxonox/objects/quest/Quest.h

    r2261 r2328  
    110110           
    111111            bool start(PlayerInfo* player); //!< Sets a Quest to active.
    112             virtual bool fail(PlayerInfo* player) = 0; //!< Fails the Quest.
    113             virtual bool complete(PlayerInfo* player) = 0; //!< Completes the Quest.
     112            virtual bool fail(PlayerInfo* player); //!< Fails the Quest.
     113            virtual bool complete(PlayerInfo* player); //!< Completes the Quest.
     114           
     115            bool addListener(QuestListener* listener); //!< Adds a QuestListener to the list of QuestListeners listening to this Quest.
    114116
    115117        protected:
     
    150152            std::list<QuestEffect*> completeEffects_; //!< A list of QuestEffects to be invoked, when the Quest has been completed.
    151153           
     154            std::list<QuestListener*> listeners_; //!< A list of QuestListeners, that listen to what exactly happens with this Quest.
     155           
    152156            bool setParentQuest(Quest* quest); //!< Sets the parentquest of the Quest.
    153157            bool addSubQuest(Quest* quest); //!< Adds a subquest to the Quest.
  • code/branches/questsystem3/src/orxonox/objects/quest/QuestDescription.cc

    r2261 r2328  
    7474        XMLPortParam(QuestDescription, "title", setTitle, getTitle, xmlelement, mode);
    7575        XMLPortParam(QuestDescription, "description", setDescription, getDescription, xmlelement, mode);
     76        XMLPortParam(QuestDescription, "failMessage", setFailMessage, getFailMessage, xmlelement, mode);
     77        XMLPortParam(QuestDescription, "failMessage", setCompleteMessage, getCompleteMessage, xmlelement, mode);
    7678
    7779        COUT(3) << "New QuestDescription with title '" << this->getTitle() << "' created." << std::endl;
  • code/branches/questsystem3/src/orxonox/objects/quest/QuestDescription.h

    r2261 r2328  
    5252        Creating a QuestDescription through XML goes as follows:
    5353       
    54         <QuestDescription title="Title" description="Description Text" />
     54        <QuestDescription title="Title" description="Description Text" failMessage="You fail." completeMessage="You win!" />
    5555    @author
    5656        Damian 'Mozork' Frick
     
    6464            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); //!< Method for creating a QuestDescription object through XML.
    6565
    66         /**
    67         @brief Returns the title.
    68         @return Returns a string containing the title of the QuestDescription.
    69         */
    70             inline const std::string & getTitle(void) const
    71                 { return this->title_; }
    72        
    73         /**
    74         @brief Returns the description text.
    75         @return Returns a string containing the description text of the QuestDescription.
    76         */
    77             inline const std::string & getDescription(void) const
    78                 { return this->description_; }
     66            /**
     67            @brief Returns the title.
     68            @return Returns a string containing the title of the QuestDescription.
     69            */
     70            inline const std::string & getTitle(void) const
     71                { return this->title_; }
     72           
     73            /**
     74            @brief Returns the description text.
     75            @return Returns a string containing the description text of the QuestDescription.
     76            */
     77            inline const std::string & getDescription(void) const
     78                { return this->description_; }
     79               
     80            /**
     81            @brief Returns the fail message.
     82            @return Returns a string containing the fail message of the QuestDescription.
     83            */
     84            inline const std::string & getFailMessage(void) const
     85                { return this->failMessage_; }
     86               
     87            /**
     88            @brief Returns the complete message.
     89            @return Returns a string containing the complete message of the QuestDescription.
     90            */
     91            inline const std::string & getCompleteMessage(void) const
     92                { return this->completeMessage_; }
    7993
    8094        private:
    8195            std::string title_; //!< The title.
    8296            std::string description_; //!< The description.
     97            std::string failMessage_; //!< The message displayed when the Quest is failed.
     98            std::string completeMessage_; //!< The message displayed when the Quest is completed.
    8399
    84100            /**
     
    89105                { this->title_ = title; }
    90106               
    91         /**
     107            /**
    92108            @brief Sets the description text.
    93109            @param description The description text to be set.
     
    96112                { this->description_ = description; }
    97113
     114            /**
     115            @brief Sets the fail message.
     116            @param message The fail message to be set.
     117            */
     118            inline void setFailMessage(const std::string & message)
     119                { this->failMessage_ = message; }
     120               
     121            /**
     122            @brief Sets the complete message.
     123            @param message The complete message to be set.
     124            */
     125            inline void setCompleteMessage(const std::string & message)
     126                { this->completeMessage_ = message; }
     127
    98128    };
    99129
Note: See TracChangeset for help on using the changeset viewer.