Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 2068


Ignore:
Timestamp:
Oct 30, 2008, 9:52:12 AM (16 years ago)
Author:
dafrick
Message:

Started with XMLPort…

Location:
code/branches/questsystem/src/orxonox/objects
Files:
28 edited

Legend:

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

    r2021 r2068  
    3030
    3131#include "core/CoreIncludes.h"
     32#include "util/Exception.h"
    3233
    3334#include "QuestManager.h"
     
    6970    @param player
    7071        The player the effect is invoked on.
     72    @return
     73        Returns true if the effect was successfully invoked.
    7174    */
    72     void AddQuest::invoke(Player* player)
     75    bool AddQuest::invoke(Player* player)
    7376    {
    74         Quest* quest = QuestManager::findQuest(this->getQuestId());
    75         quest->start(player);
     77        if(player == NULL)
     78        {
     79            COUT(2) << "Input player is NULL." << std::endl;
     80            return false;
     81        }
     82   
     83        try
     84        {
     85            Quest* quest = QuestManager::findQuest(this->getQuestId());
     86            if(!quest->start(player))
     87            {
     88               return false;
     89            }
     90        }
     91        catch(const orxonox::Exception& ex)
     92        {
     93            COUT(2) << ex.getFullDescription() << std::endl;
     94            return false;
     95        }
     96       
     97        return true;
    7698    }
    7799
  • code/branches/questsystem/src/orxonox/objects/AddQuest.h

    r2021 r2068  
    5151            ~AddQuest();
    5252           
    53             virtual void invoke(Player* player); //!< Invokes the effect.
     53            virtual bool invoke(Player* player); //!< Invokes the effect.
    5454   
    5555    };
  • code/branches/questsystem/src/orxonox/objects/AddQuestHint.cc

    r2021 r2068  
    2828
    2929#include "core/CoreIncludes.h"
     30#include "util/Exception.h"
    3031
    3132#include "QuestManager.h"
     
    6667    @param player
    6768        The player.
     69    @return
     70        Returns true if the effect was successfully invoked.
    6871    */
    69     void AddQuestHint::invoke(Player* player)
     72    bool AddQuestHint::invoke(Player* player)
    7073    {
    71         QuestHint* hint = QuestManager::findHint(this->hintId_);
    72         hint->activate(player);
     74        if(player == NULL)
     75        {
     76            COUT(2) << "The input player is NULL." << std::endl;
     77            return false;
     78        }
     79
     80        try
     81        {
     82            QuestHint* hint = QuestManager::findHint(this->hintId_);
     83            if(!hint->activate(player))
     84            {
     85                return false;
     86            }
     87        }
     88        catch(const Exception& e)
     89        {
     90           COUT(2) << e.getFullDescription() << std::endl;
     91           return false;
     92        }
     93       
     94        return true;
     95       
    7396    }
    7497}
  • code/branches/questsystem/src/orxonox/objects/AddQuestHint.h

    r2021 r2068  
    5151            ~AddQuestHint();
    5252           
    53             virtual void invoke(Player* player); //!< Invokes the effect.
     53            virtual bool invoke(Player* player); //!< Invokes the effect.
    5454           
    5555        private:
  • code/branches/questsystem/src/orxonox/objects/AddReward.cc

    r2021 r2068  
    8686    @param player
    8787        The player.
     88    @return
     89        Returns true if the effect was invoked successfully.
    8890    */
    89     void AddReward::invoke(Player* player)
     91    bool AddReward::invoke(Player* player)
    9092    {
    9193        if ( this->rewards_ == NULL )
    9294        {
    9395            COUT(2) << "NULL-Rewards list encountered." << std::endl;
    94             return;
     96            return false;
    9597        }
     98       
     99        bool check = true;
    96100        for ( std::list<Rewardable*>::iterator reward = this->rewards_->begin(); reward != this->rewards_->end(); ++reward )
    97101        {
    98             (*reward)->reward(player);
     102            check = check && (*reward)->reward(player);
    99103        }
     104       
     105        return check;
    100106    }
    101107
  • code/branches/questsystem/src/orxonox/objects/AddReward.h

    r2021 r2068  
    5353            ~AddReward();
    5454           
    55             virtual void invoke(Player* player); //!< Invokes the effect.
     55            virtual bool invoke(Player* player); //!< Invokes the effect.
    5656           
    5757        private:
  • code/branches/questsystem/src/orxonox/objects/ChangeQuestStatus.h

    r2021 r2068  
    5151            virtual ~ChangeQuestStatus();
    5252           
    53             virtual void invoke(Player* player) = 0; //!< Invokes the effect.
     53            virtual bool invoke(Player* player) = 0; //!< Invokes the effect.
    5454           
    5555        protected:
  • code/branches/questsystem/src/orxonox/objects/CompleteQuest.cc

    r2021 r2068  
    2828
    2929#include "core/CoreIncludes.h"
     30#include "util/Exception.h"
    3031
    3132#include "QuestManager.h"
     
    6667    @param player
    6768        The player the effect is invoked on.
     69    @return
     70        Returns true if the effect was invoked successfully.
    6871    */
    69     void CompleteQuest::invoke(Player* player)
     72    bool CompleteQuest::invoke(Player* player)
    7073    {
    71         Quest* quest = QuestManager::findQuest(this->getQuestId());
    72         quest->complete(player);
     74        if(player == NULL)
     75        {
     76            COUT(2) << "Input player is NULL." << std::endl;
     77            return false;
     78        }
     79   
     80        try
     81        {
     82            Quest* quest = QuestManager::findQuest(this->getQuestId());
     83            if(!quest->complete(player))
     84            {
     85               return false;
     86            }
     87        }
     88        catch(const Exception& e)
     89        {
     90            COUT(2) << e.getFullDescription() << std::endl;
     91            return false;
     92        }
     93       
     94        return true;
    7395    }
    7496
  • code/branches/questsystem/src/orxonox/objects/CompleteQuest.h

    r2021 r2068  
    5151            ~CompleteQuest();
    5252           
    53             virtual void invoke(Player* player); //!< Invokes the effect.
     53            virtual bool invoke(Player* player); //!< Invokes the effect.
    5454   
    5555    };
  • code/branches/questsystem/src/orxonox/objects/FailQuest.cc

    r2021 r2068  
    2828
    2929#include "core/CoreIncludes.h"
     30#include "util/Exception.h"
    3031
    3132#include "QuestManager.h"
     
    6667    @param player
    6768        The player the effect is invoked on.
     69    @return
     70        Returns true if the effect was invoked successfully.
    6871    */
    69     void FailQuest::invoke(Player* player)
     72    bool FailQuest::invoke(Player* player)
    7073    {
    71         Quest* quest = QuestManager::findQuest(this->getQuestId());
    72         quest->fail(player);
     74        if(player == NULL)
     75        {
     76            COUT(2) << "Input player is NULL." << std::endl;
     77            return false;
     78        }
     79   
     80        try
     81        {
     82            Quest* quest = QuestManager::findQuest(this->getQuestId());
     83            if(!quest->fail(player))
     84            {
     85               return false;
     86            }
     87        }
     88        catch(const Exception& e)
     89        {
     90            COUT(2) << e.getFullDescription() << std::endl;
     91            return false;
     92        }
     93       
     94        return true;
    7395    }
    7496
  • code/branches/questsystem/src/orxonox/objects/FailQuest.h

    r2021 r2068  
    5151            ~FailQuest();
    5252           
    53             virtual void invoke(Player* player); //!< Invokes the effect.
     53            virtual bool invoke(Player* player); //!< Invokes the effect.
    5454   
    5555    };
  • code/branches/questsystem/src/orxonox/objects/GlobalQuest.cc

    r2043 r2068  
    2828
    2929#include "core/CoreIncludes.h"
     30#include "util/Exception.h"
    3031
    3132#include "GlobalQuest.h"
     
    3536    CreateFactory(GlobalQuest);
    3637
     38    /**
     39    @brief
     40        Constructor.
     41    */
    3742    GlobalQuest::GlobalQuest() : Quest()
    3843    {
    39        
     44        this->initialize();
    4045    }
    4146
     
    5055        The description of the quest.
    5156    */
    52     GlobalQuest::GlobalQuest(std::string id, std::string title, std::string description) : Quest(id, title, description)
     57    GlobalQuest::GlobalQuest(std::string id) : Quest(id)
    5358    {
    54         RegisterObject(GlobalQuest);
     59        this->initialize();
    5560    }
    5661   
     
    6469    }
    6570   
     71    void GlobalQuest::initialize(void)
     72    {
     73        RegisterObject(GlobalQuest);
     74    }
     75   
    6676    /**
    6777    @brief
     
    7181    @return
    7282        Returns true if the quest can be started, false if not.
     83    @throws
     84        Throws an exception if either isInactive() of isActive() throws one.
    7385    */
    7486    bool GlobalQuest::isStartable(const Player* player) const
    7587    {
    76         return this->isInactive(player) || this->isActive(player);
     88        return this->isInactive(player) ||  this->isActive(player);
    7789    }
    7890   
     
    8496    @return
    8597        Returns true if the quest can be failed, false if not.
     98    @throws
     99        Throws an Exception if isActive() throws one.
    86100    */
    87101    bool GlobalQuest::isFailable(const Player* player) const
    88102    {
    89103        return this->isActive(player);
     104
    90105    }
    91106   
     
    97112    @return
    98113        Returns true if the quest can be completed, false if not.
     114    @throws
     115        Throws an Exception if isActive() throws one.
    99116    */
    100117    bool GlobalQuest::isCompletable(const Player* player) const
     
    108125    @param player
    109126        The player.
     127    @throws
     128        Throws an Exception if player is NULL.
    110129    */
    111130    questStatus::Enum GlobalQuest::getStatus(const Player* player) const
    112131    {
     132        if(player == NULL)
     133        {
     134            ThrowException(Argument, "The input Player* is NULL.");
     135        }
     136       
    113137        //TDO: Does this really work???
    114138        std::set<Player*>::const_iterator it = this->players_.find((Player*)(void*)player);
     
    127151    @brief
    128152        Sets the status for a specific player.
     153        But be careful wit this one, the status will just be set without checking for its validity. You have to know what you're doing.
    129154    @param player
    130155        The player.
    131156    @param status
    132157        The status to be set.
     158    @return
     159        Returns false if player is NULL.
    133160    */
    134161    bool GlobalQuest::setStatus(Player* player, const questStatus::Enum & status)
    135162    {
     163        if(player == NULL)
     164        {
     165            return false;
     166        }
     167       
    136168        std::set<Player*>::const_iterator it = this->players_.find(player);
    137169        if (it == this->players_.end()) //!< Player is not yet in the list.
  • code/branches/questsystem/src/orxonox/objects/GlobalQuest.h

    r2043 r2068  
    4949        public:
    5050            GlobalQuest();
    51             GlobalQuest(std::string id, std::string title = "", std::string description = "");
     51            GlobalQuest(std::string id);
    5252            ~GlobalQuest();
    5353           
     
    6363            std::set<Player*> players_; //!< The set of players which possess this quest.
    6464            questStatus::Enum status_; //!< The status of this quest.
     65           
     66            void initialize(void);
    6567   
    6668    };
  • code/branches/questsystem/src/orxonox/objects/LocalQuest.cc

    r2043 r2068  
    2828
    2929#include "core/CoreIncludes.h"
     30#include "util/Exception.h"
    3031
    3132#include "LocalQuest.h"
     
    3738    LocalQuest::LocalQuest() : Quest()
    3839    {
    39        
     40        this->initialize();
    4041    }
    4142
     
    4546    @param id
    4647        The unique identifier.
    47     @param title
    48         The title of the quest.
    49     @param description
    50         The description of the quest.
    5148    */
    52     LocalQuest::LocalQuest(std::string id, std::string title, std::string description) : Quest(id, title, description)
     49    LocalQuest::LocalQuest(std::string id) : Quest(id)
    5350    {
    54         RegisterObject(LocalQuest);
     51        this->initialize();
    5552    }
    5653   
     
    6461    }
    6562   
     63    void LocalQuest::initialize(void)
     64    {
     65        RegisterObject(LocalQuest);
     66    }
     67   
    6668    /**
    6769    @brief
     
    7173    @return
    7274        Returns true if the quest can be started, false if not.
     75    @throws
     76        Throws an exception if isInactive(Player*) throws one.
    7377    */
    7478    bool LocalQuest::isStartable(const Player* player) const
     
    8488    @return
    8589        Returns true if the quest can be failed, false if not.
     90    @throws
     91        Throws an exception if isActive(Player*) throws one.
    8692    */
    8793    bool LocalQuest::isFailable(const Player* player) const
     
    97103    @return
    98104        Returns true if the quest can be completed, false if not.
     105    @throws
     106        Throws an exception if isInactive(Player*) throws one.
    99107    */
    100108    bool LocalQuest::isCompletable(const Player* player) const
     
    110118    @return
    111119        Returns the status of the quest for the input player.
     120    @throws
     121        Throws an Exception if player is NULL.
    112122    */
    113123    questStatus::Enum LocalQuest::getStatus(const Player* player) const
    114124    {
     125        if(player == NULL)
     126        {
     127            ThrowException(Argument, "The input Player* is NULL.");
     128        }
     129       
    115130        std::map<Player*, questStatus::Enum>::const_iterator it = this->playerStatus_.find((Player*)(void*)player); //Thx. to x3n for the (Player*)(void*) 'hack'.
    116131        if (it != this->playerStatus_.end())
     
    124139    @brief
    125140        Sets the status for a specific player.
     141        But be careful wit this one, the status will just be set without checking for its validity. You have to know what you're doing.
    126142    @param player
    127143        The player.
    128144    @param status
    129145        The status.
     146    @return
     147        Returns false if player is NULL.
    130148    */
    131149    bool LocalQuest::setStatus(Player* player, const questStatus::Enum & status)
    132150    {
     151        if(player == NULL)
     152        {
     153            return false;
     154        }
    133155        this->playerStatus_[player] = status;
    134156        return true;
  • code/branches/questsystem/src/orxonox/objects/LocalQuest.h

    r2043 r2068  
    4949        public:
    5050            LocalQuest();
    51             LocalQuest(std::string id, std::string title = "", std::string description = "");
     51            LocalQuest(std::string id);
    5252            ~LocalQuest();
    5353           
     
    6161               
    6262        private:
    63             std::map<Player*, questStatus::Enum> playerStatus_;
     63            std::map<Player*, questStatus::Enum> playerStatus_; //!< List of the status for each player, with the Player-pointer as key.
     64           
     65            void initialize(void);
    6466   
    6567    };
  • code/branches/questsystem/src/orxonox/objects/Quest.cc

    r2021 r2068  
    3030
    3131#include "Quest.h"
     32#include "QuestManager.h"
    3233
    3334namespace orxonox {
     
    3536    Quest::Quest() : QuestItem()
    3637    {
    37        
     38        this->initialize();
    3839    }
    3940
     
    4849        The description of the quest.
    4950    */
    50     Quest::Quest(std::string id, std::string title, std::string description) : QuestItem(id, title, description)
    51     {
    52         initialize();
     51    Quest::Quest(std::string id) : QuestItem(id)
     52    {
     53        this->initialize();
    5354    }
    5455   
     
    5960    Quest::~Quest()
    6061    {
    61         //TDO: Unload lists...
     62       
    6263    }
    6364   
     
    7071        RegisterObject(Quest);
    7172       
    72         this->parentQuest_ = 0;
     73        this->parentQuest_ = NULL;
     74        QuestManager::registerQuest(this); //Registers the quest with the QuestManager.
    7375    }
    7476
     
    7880    @param quest
    7981        A pointer to the quest to be set as parent quest.
     82    @return
     83        Returns true if the parentQuest could be set.
    8084    */
    8185    bool Quest::setParentQuest(Quest* quest)
    8286    {
     87        if(quest == NULL)
     88        {
     89            COUT(2) << "The parentquest to be added to quest {" << this->getId() << "} was NULL." << std::endl;
     90            return false;
     91        }
     92       
    8393        this->parentQuest_ = quest;
    8494        return true;
     
    90100    @param quest
    91101        A pointer to the quest to be set as sub quest.
     102    @return
     103        Returns true if the subQuest vould be set.
    92104    */
    93105    bool Quest::addSubQuest(Quest* quest)
    94106    {
     107        if(quest == NULL)
     108        {
     109            COUT(2) << "The subquest to be added to quest {" << this->getId() << "} was NULL." << std::endl;
     110            return false;
     111        }
     112       
    95113        this->subQuests_.push_back(quest);
    96114        return true;
     115    }
     116   
     117    /**
     118    @brief
     119        Returns true if the quest status for the specific player is 'inactive'.
     120    @param player
     121        The player.
     122    @return
     123        Returns true if the quest status for the specific player is 'inactive'.
     124    @throws
     125        Throws an exception if getStatus throws one.
     126    */
     127    bool Quest::isInactive(const Player* player) const
     128    {
     129        return this->getStatus(player) == questStatus::inactive;
     130    }
     131   
     132    /**
     133    @brief
     134        Returns true if the quest status for the specific player is 'active'.
     135    @param player
     136        The player.
     137    @return
     138        Returns true if the quest status for the specific player is 'active'.
     139    @throws
     140        Throws an exception if getStatus throws one.
     141    */
     142    bool Quest::isActive(const Player* player) const
     143    {
     144
     145        return this->getStatus(player) == questStatus::active;
     146    }
     147   
     148    /**
     149    @brief
     150        Returns true if the quest status for the specific player is 'failed'.
     151    @param player
     152        The player.
     153    @return
     154        Returns true if the quest status for the specific player is 'failed'.
     155    @throws
     156        Throws an exception if getStatus throws one.
     157    */
     158    bool Quest::isFailed(const Player* player) const
     159    {
     160        return this->getStatus(player) == questStatus::failed;
     161    }
     162   
     163    /**
     164    @brief
     165        Returns true if the quest status for the specific player is 'completed'.
     166    @param player
     167        The player.
     168    @return
     169        Returns true if the quest status for the specific player is 'completed'.
     170    @throws
     171        Throws an exception if getStatus throws one.
     172    */
     173    bool Quest::isCompleted(const Player* player) const
     174    {
     175        return this->getStatus(player) == questStatus::completed;
    97176    }
    98177
     
    102181    @param hint
    103182        The hint that should be added to the list of hints.
    104     */
    105     void Quest::addHint(QuestHint* hint)
    106     {
    107         if ( hint != NULL )
    108         {
    109             this->hints_.push_back(hint);
    110             hint->setQuest(this);
    111         }
    112         else
     183    @return
     184        Returns true if the hint was successfully added.
     185    */
     186    bool Quest::addHint(QuestHint* hint)
     187    {
     188        if(hint == NULL)
    113189        {
    114190            COUT(2) << "A NULL-QuestHint was trying to be added." << std::endl;
    115         }
     191            return false;
     192        }
     193       
     194        this->hints_.push_back(hint);
     195        hint->setQuest(this);
     196        return true;
    116197    }
    117198   
  • code/branches/questsystem/src/orxonox/objects/Quest.h

    r2043 r2068  
    5858    @brief
    5959        Represents a quest in the game.
    60         A quest has a sub
    61        
     60        A quest has a list of subquests and a parentquest (if it is not a rootquest).
     61        Each quest exists only once but it has a different status (inactive, active, failed or completed) for each player.
    6262    @author
    6363        Damian 'Mozork' Frick
     
    6767        public:
    6868            Quest();
    69             Quest(std::string id, std::string title = "", std::string description = "");
     69            Quest(std::string id);
    7070            virtual ~Quest();
    7171   
     
    7575                { return this->subQuests_; }
    7676           
    77             //TDO: Necessary? Shouldn't this be decided whilest creating the object?
    78             //     Yes it absolutely should and will. Add these methods to protected then?
    79             bool setParentQuest(Quest* quest); //!< Sets the parent quest of the quest.
    80             bool addSubQuest(Quest* quest); //!< Adds a sub quest to the quest.
    81            
    82             inline bool isInactive(const Player* player) const //!< Returns true if the quest status for the specific player is 'inactive'.
    83                { return this->getStatus(player) == questStatus::inactive; }
    84             inline bool isActive(const Player* player) const //!< Returns true if the quest status for the specific player is 'active'.
    85                { return this->getStatus(player) == questStatus::active; }
    86             inline bool isFailed(const Player* player) const //!< Returns true if the quest status for the specific player is 'failed'.
    87                { return this->getStatus(player) == questStatus::failed; }
    88             inline bool isCompleted(const Player* player) const //!< Returns true if the quest status for the specific player is 'completed'.
    89                { return this->getStatus(player) == questStatus::completed; }
     77            bool isInactive(const Player* player) const; //!< Returns true if the quest status for the specific player is 'inactive'.
     78            bool isActive(const Player* player) const; //!< Returns true if the quest status for the specific player is 'active'.
     79            bool isFailed(const Player* player) const; //!< Returns true if the quest status for the specific player is 'failed'.
     80            bool isCompleted(const Player* player) const; //!< Returns true if the quest status for the specific player is 'completed'.
    9081               
    9182            bool start(Player* player); //!< Sets a quest to active.
     
    9384            bool complete(Player* player); //!< Completes the quest.
    9485               
    95             void addHint(QuestHint* hint); //!< Add a hint to the list of hints.
     86            bool addHint(QuestHint* hint); //!< Add a hint to the list of hints.
    9687           
    9788        protected:
     
    10293            virtual bool isCompletable(const Player* player) const = 0; //!< Checks whether the quest can be completed.
    10394           
    104             //TDO: Get the parameter const...
     95            bool setParentQuest(Quest* quest); //!< Sets the parent quest of the quest.
     96            bool addSubQuest(Quest* quest); //!< Adds a sub quest to the quest.
     97           
    10598            virtual questStatus::Enum getStatus(const Player* player) const = 0; //!< Returns the status of the quest for a specific player.
    10699            virtual bool setStatus(Player* player, const questStatus::Enum & status) = 0; //!< Changes the status for a specific player.
  • code/branches/questsystem/src/orxonox/objects/QuestDescription.cc

    r2021 r2068  
    3737    QuestDescription::QuestDescription() : BaseObject()
    3838    {
    39        
     39        this->initialize();
    4040    }
    4141       
     42    /**
     43    @brief
     44        Constructor. Creates a new QuestDescription object and adds a title and description.
     45    @param title
     46    @param description
     47    */
    4248    QuestDescription::QuestDescription(std::string title, std::string description) : BaseObject()
    4349    {
    44         initialize();
     50        this->initialize();
    4551        this->title_ = title;
    4652        this->description_ = description;
     
    5056    {
    5157       
     58    }
     59   
     60    void QuestDescription::XMLPort(Element& xmlelement, XMLPort::Mode mode)
     61    {
     62        SUPER(QuestDescription, XMLPort, xmlelement, mode);
     63   
     64        XMLPortParam(QuestDescription, "title", setTitle, getTitle, xmlelement, mode);
     65        XMLPortParam(QuestDescription, "description", setDescription, getDescription, xmlelement, mode);
     66       
     67        COUT(1) << "QuestDescription created!" << std::endl;
    5268    }
    5369   
  • code/branches/questsystem/src/orxonox/objects/QuestDescription.h

    r2021 r2068  
    3333
    3434#include "core/BaseObject.h"
     35#include "core/XMLPort.h"
    3536
    3637namespace orxonox {
     
    5051            ~QuestDescription();
    5152           
     53            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
     54           
    5255            inline const std::string & getTitle(void) const //!< Returns the title.
    5356                { return this->title_; }
     
    5760        private:
    5861            void initialize(void);
     62           
     63            inline void setTitle(const std::string & title) //!< Sets the title.
     64                { this->title_ = title; }
     65            inline void setDescription(const std::string & description) //!< Sets the description text.
     66                { this->description_ = description; }
    5967               
    60             std::string title_;
    61             std::string description_;
     68            std::string title_; //!< The title.
     69            std::string description_; //!< The description.
    6270   
    6371    };
  • code/branches/questsystem/src/orxonox/objects/QuestEffect.cc

    r2021 r2068  
    5959    @param effects
    6060        A list of all the effects to be invoked.
     61    @return
     62        Returns false if there was an error, view console of log for further detail.
    6163    */
    62     void QuestEffect::invokeEffects(Player* player, std::list<QuestEffect*> & effects)
     64    bool QuestEffect::invokeEffects(Player* player, std::list<QuestEffect*> & effects)
    6365    {
     66        bool check = true;
     67       
    6468        for (std::list<QuestEffect*>::iterator effect = effects.begin(); effect != effects.end(); effect++)
    6569        {
    66             (*effect)->invoke(player);
     70            check = check && (*effect)->invoke(player);
    6771        }
     72        return check;
    6873    }
    6974
  • code/branches/questsystem/src/orxonox/objects/QuestEffect.h

    r2021 r2068  
    5050            virtual ~QuestEffect();
    5151           
    52             virtual void invoke(Player* player) = 0; //!< Invokes the effect.
    53             static void invokeEffects(Player* player, std::list<QuestEffect*> & effects); //!< Invokes all effects in the list.
     52            virtual bool invoke(Player* player) = 0; //!< Invokes the effect.
     53            static bool invokeEffects(Player* player, std::list<QuestEffect*> & effects); //!< Invokes all effects in the list.
    5454           
    5555       
  • code/branches/questsystem/src/orxonox/objects/QuestHint.cc

    r2021 r2068  
    2828
    2929#include "core/CoreIncludes.h"
     30#include "util/Exception.h"
    3031
    3132#include "Quest.h"
     
    3637    CreateFactory(QuestHint);
    3738
     39    /**
     40    @brief
     41        Constructor.
     42    */
    3843    QuestHint::QuestHint() : QuestItem()
    3944    {
    40        
     45        this->initialize();
    4146    }
    4247
     
    5156        The description of the hint, resp. the hint itself.
    5257    */
    53     QuestHint::QuestHint(std::string id, std::string title, std::string description) : QuestItem(id, title, description)
     58    QuestHint::QuestHint(std::string id) : QuestItem(id)
    5459    {
    55         RegisterObject(QuestHint);
     60        this->initialize();
    5661    }
    5762   
     
    6570    }
    6671   
     72    void QuestHint::initialize(void)
     73    {
     74        RegisterObject(QuestHint);
     75    }
     76   
     77    void QuestHint::XMLPort(Element& xmlelement, XMLPort::Mode mode)
     78    {
     79        SUPER(QuestHint, XMLPort, xmlelement, mode);
     80    }
     81
     82   
    6783    /**
    6884    @brief
     
    7086    @param player
    7187        The player.
     88    @throws
     89        Throws an Argument Exception if the input Player-pointer is NULL.
    7290    @return
    73         Returns
     91        Returns true if the hint is active for the specified player.
    7492    */
    7593    bool QuestHint::isActive(Player* player)
    7694    {
     95        if(player == NULL)
     96        {
     97            ThrowException(Argument, "The input Player* is NULL.");
     98            return false;
     99        }
     100       
    77101        std::map<Player*, questHintStatus::Enum>::iterator it = this->playerStatus_.find(player);
    78102        if (it != this->playerStatus_.end())
     
    85109    /**
    86110    @brief
     111        Activates a QuestHint for a given player.
    87112    @param player
     113        The player.
    88114    @return
     115        Returns true if the activation was successful, false if there were problems.
    89116    */
    90117    bool QuestHint::activate(Player* player)
    91118    {
    92         if(this->quest_->isActive(player) && !(this->isActive(player)))
     119        if(this->quest_->isActive(player))
    93120        {
    94             this->playerStatus_[player] = questHintStatus::active;
    95             return true;
     121            if(!(this->isActive(player)))
     122            {
     123                this->playerStatus_[player] = questHintStatus::active;
     124                return true;
     125            }
     126            else
     127            {
     128                COUT(2) << "An already active questHint was trying to get activated." << std::endl;
     129                return false;
     130            }
    96131        }
    97132        COUT(2) << "A hint of a non-active quest was trying to get activated." << std::endl;
     
    101136    /**
    102137    @brief
     138        Sets the quest the QuestHitn belongs to.
    103139    @param quest
    104140    @return
    105141    */
    106     void QuestHint::setQuest(Quest* quest)
     142    bool QuestHint::setQuest(Quest* quest)
    107143    {
     144        if(quest == NULL)
     145        {
     146            COUT(2) << "The input Quest* is NULL." << std::endl;
     147            return false;
     148        }
     149       
    108150        this->quest_ = quest;
     151        return true;
    109152    }
    110153
  • code/branches/questsystem/src/orxonox/objects/QuestHint.h

    r2021 r2068  
    3333#include <string>
    3434
     35#include "core/XMLPort.h"
    3536#include "QuestDescription.h"
    3637#include "QuestItem.h"
     
    5657    @brief
    5758        Represents a hint in the game towards completing a Quest.
    58         Consists of title and description in textual form.
     59        Consists of title and description in textual form and must belong to a quest.
     60        A QuestHit has a defined status (inactive or active, where inactive is default) for each player, which means each QuestHint exists only once for all players, it doesn't belong to a player, it just has different stati for each of them.
    5961    @author
    6062        Damian 'Mozork' Frick
     
    6567        public:
    6668            QuestHint();
    67             QuestHint(std::string id, std::string title = "", std::string description = "");
     69            QuestHint(std::string id);
    6870            ~QuestHint();
     71           
     72            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    6973           
    7074            bool isActive(Player* player); //!< Returns true if the hint is active for the input player.
     
    7276            bool activate(Player* player); //!< Activates the hint for the input player.
    7377           
    74             void setQuest(Quest* quest); //!< Sets the quest the hint belongs to.
     78            bool setQuest(Quest* quest); //!< Sets the quest the hint belongs to.
     79           
     80            inline Quest* getQuest(void)
     81               { return this->quest_; }
    7582           
    7683        private:
    7784           
    78             Quest* quest_;
    79             std::map<Player*, questHintStatus::Enum> playerStatus_;
     85            void initialize(void);
     86           
     87            Quest* quest_; //!< The quest the hint belongs to.
     88            std::map<Player*, questHintStatus::Enum> playerStatus_; //!< List of the status for each player, with the Player-pointer as key.
    8089   
    8190    };
  • code/branches/questsystem/src/orxonox/objects/QuestItem.cc

    r2021 r2068  
    3737    QuestItem::QuestItem() : BaseObject()
    3838    {
    39        
     39        this->initialize();
    4040    }
    4141   
     
    4545    @param id
    4646        The unique identifier. Should be of GUID form: http://en.wikipedia.org/wiki/Globally_Unique_Identifier#Basic_structure
    47     @param title
    48         The title of this QuestItem. Has an empty string as default.
    49     @param description
    50         The description of this QuestItem. Has an empty string as default.
    5147    */
    52     QuestItem::QuestItem(std::string id, std::string title, std::string description) : BaseObject()
     48    QuestItem::QuestItem(std::string id) : BaseObject()
    5349    {
    5450        this->initialize();
    5551       
    5652        this->id_ = id;
    57         this->description_ = QuestDescription(title, description);
    5853    }
    5954   
     
    6661       
    6762    }
     63   
     64    void QuestItem::XMLPort(Element& xmlelement, XMLPort::Mode mode)
     65    {
     66        SUPER(QuestItem, XMLPort, xmlelement, mode);
     67       
     68        XMLPortParam(QuestItem, "id", setId, getId, xmlelement, mode);
     69        //Doesn't getDescription have to be of type getDescription(unsigned int) ?
     70        //XMLPortObjectTemplate(QuestItem, QuestDescription, "", setDescription, getDescription, xmlelement, mode, unsigned int);
     71        XMLPortObject(QuestItem, QuestDescription, "", setDescription, getDescription, xmlelement, mode);
     72
     73    }
     74
    6875   
    6976    /**
     
    7885        this->id_ = "";
    7986    }
     87   
     88    //const QuestDescription* QuestItem::getDescription(unsigned int index) const //!< Returns the description of the QuestItem.
     89    //{
     90    //    if(index != 0)
     91    //        return NULL;
     92    //    return this->description_;
     93    //}
     94   
     95    /**
     96    @brief
     97        Checks whether an input id is of the required form.
     98    @param id
     99        The id to be checked.
     100    @return
     101        Returns true if the string is likely to be of the required form.
     102    @todo
     103        Clarify form, more vigorous checks.
     104    */
     105    bool QuestItem::isId(const std::string & id)
     106    {
     107        return id.size() >= 32;
     108    }
    80109
    81110}
  • code/branches/questsystem/src/orxonox/objects/QuestItem.h

    r2021 r2068  
    3232#include <string>
    3333
     34#include "core/BaseObject.h"
     35#include "core/XMLPort.h"
    3436#include "QuestDescription.h"
    35 #include "core/BaseObject.h"
    3637
    3738namespace orxonox {
     
    5051        public:
    5152            QuestItem();
    52             QuestItem(std::string id, std::string title = "", std::string description = "");
     53            QuestItem(std::string id);
    5354            virtual ~QuestItem();
    5455           
    55             inline std::string getId(void) const //!< Returns the id of this quest.
     56            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
     57           
     58            inline const std::string & getId(void) const //!< Returns the id of this quest.
    5659                { return this->id_; }
    57             inline const QuestDescription & getDescription(void) const //!< Returns the description of the QuestItem.
     60            inline const QuestDescription* getDescription(void) const //!< Returns the description of the QuestItem.
    5861                { return this->description_; }
     62            //const QuestDescription* getDescription(unsigned int index) const; //!< Returns the description of the QuestItem.
     63               
     64            static bool isId(const std::string & id); //!< Checks whether a given id is valid.
     65           
     66        protected:
     67            inline void setId(const std::string & id)
     68                { id_ = id; }
     69            inline void setDescription(QuestDescription* description)
     70                { this->description_ = description; }
    5971           
    6072        private:
    6173            std::string id_; //!< Identifier. Should be of GUID form: http://en.wikipedia.org/wiki/Globally_Unique_Identifier#Basic_structure
    62             QuestDescription description_; //!< The description of the QuestItem.
     74            QuestDescription* description_; //!< The description of the QuestItem.
    6375           
    6476            void initialize(void); //!< Initializes the object.
  • code/branches/questsystem/src/orxonox/objects/QuestManager.cc

    r2022 r2068  
    2828
    2929#include "core/CoreIncludes.h"
     30#include "util/Exception.h"
    3031
    3132#include "QuestManager.h"
     
    5758    bool QuestManager::registerQuest(Quest* quest)
    5859    {
    59         questMap_.insert( std::pair<std::string,Quest*>(quest->getId(),quest) );
    60         return true;
     60        if(quest == NULL)
     61        {
     62            COUT(2) << "Registration of Quest in QuestManager failed, because inserted Quest-pointer was NULL." << std::endl;
     63            return false;
     64        }
     65       
     66        std::pair<std::map<std::string, Quest*>::iterator,bool> ret;
     67        ret = questMap_.insert( std::pair<std::string,Quest*>(quest->getId(),quest) );
     68       
     69        if(ret.second)
     70        {
     71            COUT(3) << "Quest with questId {" << quest->getId() << "} successfully inserted." << std::endl;
     72            return true;
     73        }
     74        else
     75        {
     76           COUT(2) << "Quest with the same id was already present." << std::endl;
     77           return false;
     78        }
    6179    }
    6280   
     
    7189    bool QuestManager::registerHint(QuestHint* hint)
    7290    {
    73         hintMap_.insert ( std::pair<std::string,QuestHint*>(hint->getId(),hint) );
    74         return true;
     91        if(hint == NULL)
     92        {
     93            COUT(2) << "Registration of QuestHint in QuestManager failed, because inserted QuestHint-pointer was NULL." << std::endl;
     94            return false;
     95        }
     96       
     97        std::pair<std::map<std::string, QuestHint*>::iterator,bool> ret;
     98        ret = hintMap_.insert ( std::pair<std::string,QuestHint*>(hint->getId(),hint) );
     99       
     100        if(ret.second)
     101        {
     102            COUT(3) << "QuestHint with hintId {" << hint->getId() << "} successfully inserted." << std::endl;
     103            return true;
     104        }
     105        else
     106        {
     107           COUT(2) << "QuestHint with the same id was already present." << std::endl;
     108           return false;
     109        }
    75110    }
    76111   
     
    82117    @return
    83118        Returns a reference to the quest with the input id.
    84     @todo
    85         Throw exceptions in case of errors.
     119        Returns NULL if there is no quest with the given questId.
     120    @throws
     121        Throws an exception if the given questId is invalid.
    86122    */
    87123    Quest* QuestManager::findQuest(const std::string & questId)
    88124    {
     125        if(!QuestItem::isId(questId))
     126        {
     127            ThrowException(Argument, "Invalid questId.");
     128        }
     129       
    89130        Quest* quest;
    90131        std::map<std::string, Quest*>::iterator it = questMap_.find(questId);
     
    110151    @return
    111152        Returns a reference to the hint with the input id.
    112     @todo
    113         Throw exceptopns in case of errors.
     153        Returns NULL if there is no hint with the given hintId.
     154    @throws
     155        Throws an exception if the given hintId is invalid.
    114156    */
    115157    QuestHint* QuestManager::findHint(const std::string & hintId)
    116158    {
     159        if(!QuestItem::isId(hintId))
     160        {
     161            ThrowException(Argument, "Invalid hintId.");
     162        }
     163       
    117164        QuestHint* hint;
    118165        std::map<std::string, QuestHint*>::iterator it = hintMap_.find(hintId);
  • code/branches/questsystem/src/orxonox/objects/QuestManager.h

    r2021 r2068  
    4242    @brief
    4343        Manages quests, by making them globally accessable.
     44        Quests (and Hints) are registered in the QuestManager trough their id, and can be accessed in the same way.
    4445    @author
    4546        Damian 'Mozork' Frick
     
    5960                   
    6061        private:
    61             static std::map<std::string, Quest*> questMap_;
    62             static std::map<std::string, QuestHint*> hintMap_;
     62            static std::map<std::string, Quest*> questMap_; //!< All quests registered by their id's.
     63            static std::map<std::string, QuestHint*> hintMap_; //!< All hints registered by their id's.
    6364   
    6465    };
  • code/branches/questsystem/src/orxonox/objects/Rewardable.cc

    r2043 r2068  
    3333namespace orxonox {
    3434
     35   
    3536    Rewardable::Rewardable() : BaseObject()
    3637    {
Note: See TracChangeset for help on using the changeset viewer.