Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Oct 22, 2008, 4:03:10 PM (16 years ago)
Author:
dafrick
Message:

Some cleaning, reorganization and implementation of some small methods.

Location:
code/branches/questsystem/src/orxonox
Files:
6 added
1 deleted
17 edited

Legend:

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

    r1992 r1996  
    5959        The player the effect is invoked on.
    6060    */
    61     virtual void AddQuest::invoke(Player & player)
     61    void AddQuest::invoke(Player & player)
    6262    {
    6363        Quest quest = QuestManager::findQuest(this->getQuestId());
  • code/branches/questsystem/src/orxonox/objects/AddQuestHint.cc

    r1992 r1996  
    6060        The player.
    6161    */
    62     virtual void invoke(Player & player)
     62    void invoke(Player & player)
    6363    {
    6464        QuestHint hint = QuestManager::findHint(this->hintId_);
  • code/branches/questsystem/src/orxonox/objects/AddReward.cc

    r1992 r1996  
    8181        The player.
    8282    */
    83     virtual void AddReward::invoke(Player & player)
     83    void AddReward::invoke(Player & player)
    8484    {
    8585        if ( this->rewards_ == NULL )
  • code/branches/questsystem/src/orxonox/objects/ChangeQuestStatus.h

    r1992 r1996  
    4646        public:
    4747            ChangeQuestStatus(std::string questId);
    48             ~ChangeQuestStatus();
     48            virtual ~ChangeQuestStatus();
    4949           
    5050            virtual void invoke(Player & player) = 0; //!< Invokes the effect.
  • code/branches/questsystem/src/orxonox/objects/CompleteQuest.cc

    r1992 r1996  
    5959        The player the effect is invoked on.
    6060    */
    61     virtual void CompleteQuest::invoke(Player & player)
     61    void CompleteQuest::invoke(Player & player)
    6262    {
    6363        Quest quest = QuestManager::findQuest(this->getQuestId());
  • code/branches/questsystem/src/orxonox/objects/FailQuest.cc

    r1992 r1996  
    5959        The player the effect is invoked on.
    6060    */
    61     virtual void FailQuest::invoke(Player & player)
     61    void FailQuest::invoke(Player & player)
    6262    {
    6363        Quest quest = QuestManager::findQuest(this->getQuestId());
  • code/branches/questsystem/src/orxonox/objects/GlobalQuest.cc

    r1992 r1996  
    5858       
    5959    }
     60   
     61    /**
     62    @brief
     63        Checks whether the quest can be started.
     64    @param player
     65        The player for whom is to be checked.
     66    @return
     67        Returns true if the quest can be started, false if not.
     68    */
     69    bool GlobalQuest::isStartable(const Player & player) const
     70    {
     71        return this->isInactive(player) || this->isActive(player);
     72    }
     73   
     74    /**
     75    @brief
     76        Checks whether the quest can be failed.
     77    @param player
     78        The player for whom is to be checked.
     79    @return
     80        Returns true if the quest can be failed, false if not.
     81    */
     82    bool GlobalQuest::isFailable(const Player & player) const
     83    {
     84        return this->isActive(player);
     85    }
     86   
     87    /**
     88    @brief
     89        Checks whether the quest can be completed.
     90    @param player
     91        The player for whom is to be checked.
     92    @return
     93        Returns true if the quest can be completed, false if not.
     94    */
     95    bool GlobalQuest::isCompletable(const Player & player) const
     96    {
     97        return this->isActive(player);
     98    }
    6099
    61100    /**
     
    65104        The player.
    66105    */
    67     virtual questStatus::Enum getStatus(const Player & player) const
     106    questStatus::Enum getStatus(const Player & player) const
    68107    {
    69108        //TDO: Does this really work???
     
    87126        The status to be set.
    88127    */
    89     virtual void setStatus(const Player & player, const questStatus::Enum & status)
     128    void setStatus(const Player & player, const questStatus::Enum & status)
    90129    {
    91         //TDO: Implement.
     130        if (this->players_.find(&player) == this->players_.end()) //!< Player is not yet in the list.
     131        {
     132            this->players_.insert(&player);
     133        }
     134        this->status_ = status;
    92135    }
    93136
     137
    94138}
  • code/branches/questsystem/src/orxonox/objects/GlobalQuest.h

    r1992 r1996  
    4747        public:
    4848            GlobalQuest(std::string id, std::string title = "", std::string description = "");
    49             ~GlobalQuest();
     49            virtual ~GlobalQuest();
    5050           
    5151        protected:
     52            virtual bool isStartable(const Player & player) const; //!< Checks whether the quest can be started.
     53            virtual bool isFailable(const Player & player) const; //!< Checks whether the quest can be failed.
     54            virtual bool isCompletable(const Player & player) const; //!< Checks whether the quest can be completed.
     55       
    5256            virtual questStatus::Enum getStatus(const Player & player) const; //!< Returns the status of the quest for a specific player.
    53             virtual void setStatus(const Player & player, const questStatus::Enum & status); //!< Sets the status for a specific player.
     57            virtual bool setStatus(const Player & player, const questStatus::Enum & status); //!< Sets the status for a specific player.
    5458           
    5559        private:
  • code/branches/questsystem/src/orxonox/objects/LocalQuest.cc

    r1992 r1996  
    6161    /**
    6262    @brief
     63        Checks whether the quest can be started.
     64    @param player
     65        The player for whom is to be checked.
     66    @return
     67        Returns true if the quest can be started, false if not.
     68    */
     69    bool LocalQuest::isStartable(const Player & player) const
     70    {
     71        return this->isInactive(player);
     72    }
     73   
     74    /**
     75    @brief
     76        Checks whether the quest can be failed.
     77    @param player
     78        The player for whom is to be checked.
     79    @return
     80        Returns true if the quest can be failed, false if not.
     81    */
     82    bool LocalQuest::isFailable(const Player & player) const
     83    {
     84        return this->isActive(player);
     85    }
     86   
     87    /**
     88    @brief
     89        Checks whether the quest can be completed.
     90    @param player
     91        The player for whom is to be checked.
     92    @return
     93        Returns true if the quest can be completed, false if not.
     94    */
     95    bool LocalQuest::isCompletable(const Player & player) const
     96    {
     97        return this->isActive(player);
     98    }
     99   
     100    /**
     101    @brief
    63102        Returns the status of the quest for a specific player.
    64103    @param player
    65         The player
     104        The player.
     105    @return
     106        Returns the status of the quest for the input player.
    66107    */
    67     virtual int LocalQuest::getStatus(const Player & player) const
     108    virtual questStatus::Enum LocalQuest::getStatus(const Player & player) const
    68109    {
    69         //TDO: Implenet.
     110        std::map<Player*, questStatus::Enum>::iterator it = this->playerStatus_.find(&player);
     111        if (it != this->playerStatus_.end())
     112        {
     113            return it->second;
     114        }
     115        return questStatus::inactive;
    70116    }
    71117   
     
    80126    virtual void LocalQuest::setStatus(const Player & player, const questStatus::Enum & status)
    81127    {
    82         //TDO: Implement.
     128        this->playerStatus[&player] = status;
    83129    }
    84130
  • code/branches/questsystem/src/orxonox/objects/LocalQuest.h

    r1992 r1996  
    3030#define _LocalQuest_H__
    3131
     32#include <map>
    3233#include <string>
    3334
     
    4647        public:
    4748            LocalQuest(std::string id, std::string title = "", std::string description = "");
    48             ~LocalQuest();
     49            virtual ~LocalQuest();
    4950           
    5051        protected:
     52            virtual bool isStartable(const Player & player) const; //!< Checks whether the quest can be started.
     53            virtual bool isFailable(const Player & player) const; //!< Checks whether the quest can be failed.
     54            virtual bool isCompletable(const Player & player) const; //!< Checks whether the quest can be completed.
     55       
    5156            virtual questStatus::Enum getStatus(const Player & player) const; //!< Returns the status of the quest for a specific player.
    5257            virtual void setStatus(const Player & player, const questStatus::Enum & status); //!< Sets the status for a specific player.
    5358               
    5459        private:
    55             //TDO: List of Players and the status of the quest fo them.
    56             questStatus::Enum status_; //!< The status of the quest.
     60            std::map<Player*, questStatus::Enum> playerStatus_;
    5761   
    5862    };
     63   
    5964
    6065}
  • code/branches/questsystem/src/orxonox/objects/Quest.cc

    r1992 r1996  
    7171    /**
    7272    @brief
     73        Sets the parent quest of the quest.
     74    @param quest
     75        A pointer to the quest to be set as parent quest.
     76    */
     77    bool setParentQuest(Quest* quest)
     78    {
     79        this->parentQuest_ = quest;
     80        return true;
     81    }
     82   
     83    /**
     84    @brief
     85        Adds a sub quest to the quest.
     86    @param quest
     87        A pointer to the quest to be set as sub quest.
     88    */
     89    bool addSubQuest(Quest & quest)
     90    {
     91        this->subQuests_.push_back = quest;
     92        return true;
     93    }
     94
     95    /**
     96    @brief
    7397        Adds a Hint to the list of hints
    7498    @param hint
     
    93117    @param player
    94118        The player.
     119    @return
     120        Returns true if the quest could be started, false if not.
    95121    */
    96     void Quest::start(const Player & player)
     122    bool Quest::start(const Player & player)
    97123    {
    98         if(this->isInactive(player))
     124        if(this->isStartable(player))
    99125        {
    100126            this->setStatus(player, questStatus::active);
     127            return true;
    101128        }
    102         else
    103         {
    104             COUT(2) << "A non-inactive quest was trying to be started." << std::endl;
    105         }
     129        COUT(2) << "A non-startable quest was trying to be started." << std::endl;
     130        return false;
    106131    }
    107132   
     
    111136    @param player
    112137        The player.
     138    @return
     139        Returns true if the quest could be failed, false if not.
    113140    */
    114141    void Quest::fail(Player & player)
    115142    {
    116         if(this->isActive(player))
     143        if(this->isFailable(player))
    117144        {
    118145            this->setStatus(player, questStatus::failed);
    119146            QuestEffect::invokeEffects(player, this->failEffects_);
     147            return true;
    120148        }
    121         else
    122         {
    123             COUT(2) << "A non-pending quest was trying to be failed." << std::endl;
    124         }
     149        COUT(2) << "A non-failable quest was trying to be failed." << std::endl;
     150        return false;
    125151    }
    126152   
     
    130156    @param player
    131157        The player.
     158    @return
     159        Returns true if the quest could be completed, false if not.
    132160    */
    133161    void Quest::complete(Player & player)
    134162    {
    135         if(this->isActive(player))
     163        if(this->isCompletable(player))
    136164        {
    137165            this->setStatus(player, questStatus::completed);
    138166            QuestEffect::invokeEffects(player, this->completeEffects_);
     167            return true;
    139168        }
    140         else
    141         {
    142             COUT(2) << "A non-pending quest was trying to be completed." << std::endl;
    143         }
     169        COUT(2) << "A non-completable quest was trying to be completed." << std::endl;
     170        return false;
    144171    }
    145172
  • code/branches/questsystem/src/orxonox/objects/Quest.h

    r1992 r1996  
    3333#include <string>
    3434
    35 #include "orxonox/quests/QuestDescription.h"
     35#include "QuestDescription.h"
    3636#include "QuestItem.h"
    3737#include "QuestHint.h"
     
    5252        public:
    5353            Quest(std::string id, std::string title = "", std::string description = "");
    54             ~Quest();
     54            virtual ~Quest();
    5555   
    5656            inline Quest* getParentQuest(void) const //!< Returns the parent quest of the quest.
     
    6060           
    6161            //TDO: Necessary? Shouldn't this be decided whilest creating the object?
    62             inline void setParentQuest(Quest* quest) //!< Sets the parent quest of the quest.
    63                 { this->parentQuest_ = quest; }
    64             inline void addSubQuest(Quest & quest) //!< Adds a sub quest to the quest.
    65                 { this->subQuests_.push_back = quest; }
     62            bool setParentQuest(Quest* quest); //!< Sets the parent quest of the quest.
     63            bool addSubQuest(Quest & quest); //!< Adds a sub quest to the quest.
    6664           
    6765            inline bool isInactive(const Player & player) const //!< Returns true if the quest status for the specific player is 'inactive'.
    68                { return this->getStatus(player) != questStatus::inactive; }
     66               { return this->getStatus(player) == questStatus::inactive; }
    6967            inline bool isActive(const Player & player) const //!< Returns true if the quest status for the specific player is 'active'.
    7068               { return this->getStatus(player) == questStatus::active; }
     
    7472               { return this->getStatus(player) == questStatus::completed; }
    7573               
    76             void start(const Player & player); //!< Sets a quest to pending.
    77             void fail(Player & player); //!< Fails the quest.
    78             void complete(Player & player); //!< Completes the quest.
     74            bool start(const Player & player); //!< Sets a quest to active.
     75            bool fail(Player & player); //!< Fails the quest.
     76            bool complete(Player & player); //!< Completes the quest.
    7977               
    8078            void addHint(QuestHint & hint); //!< Add a hint to the list of hints.
     
    8280        protected:
    8381            void initialize(void); //!< Initialized the object.
     82           
     83            virtual bool isStartable(const Player & player) const = 0; //!< Checks whether the quest can be started.
     84            virtual bool isFailable(const Player & player) const = 0; //!< Checks whether the quest can be failed.
     85            virtual bool isCompletable(const Player & player) const = 0; //!< Checks whether the quest can be completed.
    8486           
    8587            virtual questStatus::Enum getStatus(const Player & player) const = 0; //!< Returns the status of the quest for a specific player.
  • code/branches/questsystem/src/orxonox/objects/QuestEffect.cc

    r1992 r1996  
    6161        A list of all the effects to be invoked.
    6262    */
    63     static void QuestEffect::invokeEffects(Player & player, std::list<QuestEffect> & effects)
     63    void QuestEffect::invokeEffects(Player & player, std::list<QuestEffect> & effects)
    6464    {
    6565        if ( effects == NULL )
  • code/branches/questsystem/src/orxonox/objects/QuestEffect.h

    r1992 r1996  
    4646        public:
    4747            QuestEffect();
    48             ~QuestEffect();
     48            virtual ~QuestEffect();
    4949           
    5050            virtual void invoke(Player & player) = 0; //!< Invokes the effect.
  • code/branches/questsystem/src/orxonox/objects/QuestHint.cc

    r1992 r1996  
    5858    }
    5959   
     60    /**
     61    @brief
     62        Checks whether the hint is active for a specific player.
     63    @param player
     64        The player.
     65    @return
     66        Returns
     67    */
    6068    bool QuestHint::isActive(const Player & player) const
    6169    {
    62         //TDO: Implement.
     70        std::map<Player*, questHintStatus::Enum>::iterator it = this->playerStatus_.find(&player);
     71        if (it != this->playerStatus_.end())
     72        {
     73            return it->second;
     74        }
     75        return questStatus::inactive;
    6376    }
    6477   
    65     void QuestHint::activate(const Player & player)
     78    bool QuestHint::activate(const Player & player)
    6679    {
    67         if(this->quest_->isActive(player))
     80        if(this->quest_->isActive(player) && !this->isActive())
    6881        {
    69             //TDO: Implement.
     82            this->playerStatus_[&player] = questHintStatus::active;
     83            return true;
    7084        }
    71         else
    72         {
    73             COUT(2) << "A hint of a non-active quest was trying to get activated." << std::endl;
    74         }
     85        COUT(2) << "A hint of a non-active quest was trying to get activated." << std::endl;
     86        return false;
    7587    }
    7688
  • code/branches/questsystem/src/orxonox/objects/QuestHint.h

    r1992 r1996  
    3030#define _QuestHint_H__
    3131
     32#include <map>
    3233#include <string>
    3334
    34 #include "orxonox/quests/QuestDescription.h"
     35#include "QuestDescription.h"
    3536#include "Quest.h"
    3637#include "QuestItem.h"
     
    5556            bool isActive(const Player & player) const; //!< Returns true if the hint is active for the input player.
    5657           
    57             void activate(const Player & player); //!< Activates the hint for the input player.
     58            bool activate(const Player & player); //!< Activates the hint for the input player.
    5859           
    5960            void setQuest(Quest* quest); //!< Sets the quest the hint belongs to.
     
    6263           
    6364            Quest* quest_;
    64             //TDO: questHint statuslist.
     65            std::map<Player*, questHintStatus::Enum> playerStatus_;
    6566   
    6667    };
  • code/branches/questsystem/src/orxonox/objects/QuestItem.h

    r1992 r1996  
    5050        public:
    5151            QuestItem(std::string id, std::string title = "", std::string description = "");
    52             ~QuestItem();
     52            virtual ~QuestItem();
    5353           
    5454            inline std::string getId(void) const //!< Returns the id of this quest.
Note: See TracChangeset for help on using the changeset viewer.