Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 6, 2008, 12:02:05 AM (16 years ago)
Author:
dafrick
Message:

Started implementation of QuestEffectBeacon.
Done some documentation of QuestItem and subclasses.

Location:
code/branches/questsystem2/src/orxonox
Files:
2 added
26 edited

Legend:

Unmodified
Added
Removed
  • code/branches/questsystem2/src/orxonox/CMakeLists.txt

    r2106 r2146  
    8080  objects/quest/QuestDescription.cc
    8181  objects/quest/QuestEffect.cc
     82  objects/quest/QuestEffectBeacon.cc
    8283  objects/quest/QuestHint.cc
    8384  objects/quest/QuestItem.cc
  • code/branches/questsystem2/src/orxonox/OrxonoxPrereqs.h

    r2096 r2146  
    9797    class QuestDescription;
    9898    class QuestEffect;
     99    class QuestEffectBeacon;
    99100    class QuestHint;
    100101    class QuestItem;
  • code/branches/questsystem2/src/orxonox/objects/quest/AddQuest.cc

    r2105 r2146  
    3131
    3232#include <string>
     33
    3334#include "core/CoreIncludes.h"
    3435#include "util/Exception.h"
    3536
     37#include "orxonox/objects/worldentities/ControllableEntity.h"
    3638#include "QuestManager.h"
    3739#include "Quest.h"
     
    6971        Returns true if the effect was successfully invoked.
    7072    */
    71     bool AddQuest::invoke(Player* player)
     73    bool AddQuest::invoke(ControllableEntity* player)
    7274    {
    7375        if(player == NULL)
  • code/branches/questsystem2/src/orxonox/objects/quest/AddQuest.h

    r2096 r2146  
    3939namespace orxonox {
    4040
    41     class Player; //Forward declaration, remove when fully integrated into the objecthirarchy.
    42 
    4341    /**
    4442    @brief
     
    5553            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    5654
    57             virtual bool invoke(Player* player); //!< Invokes the effect.
     55            virtual bool invoke(ControllableEntity* player); //!< Invokes the effect.
    5856
    5957    };
  • code/branches/questsystem2/src/orxonox/objects/quest/AddQuestHint.cc

    r2105 r2146  
    3333#include "util/Exception.h"
    3434
     35#include "orxonox/objects/worldentities/ControllableEntity.h"
    3536#include "QuestManager.h"
    3637#include "QuestItem.h"
     
    8081        Returns true if the effect was successfully invoked.
    8182    */
    82     bool AddQuestHint::invoke(Player* player)
     83    bool AddQuestHint::invoke(ControllableEntity* player)
    8384    {
    8485        if(player == NULL)
     
    9192        {
    9293            QuestHint* hint = QuestManager::findHint(this->hintId_);
    93             if(!hint->activate(player))
     94            if(!hint->setActive(player))
    9495            {
    9596                return false;
  • code/branches/questsystem2/src/orxonox/objects/quest/AddQuestHint.h

    r2096 r2146  
    3838namespace orxonox {
    3939
    40     class Player; //Forward declaration, remove when fully integrated into the objecthirarchy.
    41 
    4240    /**
    4341    @brief
     
    5452            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    5553
    56             virtual bool invoke(Player* player); //!< Invokes the effect.
     54            virtual bool invoke(ControllableEntity* player); //!< Invokes the effect.
    5755
    5856        private:
  • code/branches/questsystem2/src/orxonox/objects/quest/AddReward.cc

    r2105 r2146  
    3232#include "core/CoreIncludes.h"
    3333
     34#include "orxonox/objects/worldentities/ControllableEntity.h"
    3435#include "Rewardable.h"
    3536
     
    9293        Returns true if the effect was invoked successfully.
    9394    */
    94     bool AddReward::invoke(Player* player)
     95    bool AddReward::invoke(ControllableEntity* player)
    9596    {
    9697        bool check = true;
  • code/branches/questsystem2/src/orxonox/objects/quest/AddReward.h

    r2096 r2146  
    3939namespace orxonox {
    4040
    41     class Player; //Forward declaration, remove when fully integrated into the objecthirarchy.
    42 
    4341    /**
    4442    @brief
     
    5553            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    5654
    57             virtual bool invoke(Player* player); //!< Invokes the effect.
     55            virtual bool invoke(ControllableEntity* player); //!< Invokes the effect.
    5856
    5957        private:
  • code/branches/questsystem2/src/orxonox/objects/quest/ChangeQuestStatus.h

    r2096 r2146  
    3939namespace orxonox {
    4040
    41     class Player; //Forward declaration, remove when fully integrated into the objecthirarchy.
    42 
    4341    /**
    4442    @brief
     
    5553            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    5654
    57             virtual bool invoke(Player* player) = 0; //!< Invokes the effect.
     55            virtual bool invoke(ControllableEntity* player) = 0; //!< Invokes the effect.
    5856
    5957        protected:
  • code/branches/questsystem2/src/orxonox/objects/quest/CompleteQuest.cc

    r2105 r2146  
    3333#include "util/Exception.h"
    3434
     35#include "orxonox/objects/worldentities/ControllableEntity.h"
    3536#include "QuestManager.h"
    3637#include "Quest.h"
     
    6667        Returns true if the effect was invoked successfully.
    6768    */
    68     bool CompleteQuest::invoke(Player* player)
     69    bool CompleteQuest::invoke(ControllableEntity* player)
    6970    {
    7071        if(player == NULL)
  • code/branches/questsystem2/src/orxonox/objects/quest/CompleteQuest.h

    r2096 r2146  
    3939namespace orxonox {
    4040
    41     class Player; //Forward declaration, remove when fully integrated into the objecthirarchy.
    42 
    4341    /**
    4442    @brief
     
    5553            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    5654
    57             virtual bool invoke(Player* player); //!< Invokes the effect.
     55            virtual bool invoke(ControllableEntity* player); //!< Invokes the effect.
    5856
    5957    };
  • code/branches/questsystem2/src/orxonox/objects/quest/FailQuest.cc

    r2105 r2146  
    3333#include "util/Exception.h"
    3434
     35#include "orxonox/objects/worldentities/ControllableEntity.h"
    3536#include "QuestManager.h"
    3637#include "Quest.h"
     
    6667        Returns true if the effect was invoked successfully.
    6768    */
    68     bool FailQuest::invoke(Player* player)
     69    bool FailQuest::invoke(ControllableEntity* player)
    6970    {
    7071        if(player == NULL)
  • code/branches/questsystem2/src/orxonox/objects/quest/FailQuest.h

    r2096 r2146  
    3939namespace orxonox {
    4040
    41     class Player; //Forward declaration, remove when fully integrated into the objecthirarchy.
    42 
    4341    /**
    4442    @brief
     
    5553            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    5654
    57             virtual bool invoke(Player* player); //!< Invokes the effect.
     55            virtual bool invoke(ControllableEntity* player); //!< Invokes the effect.
    5856
    5957    };
  • code/branches/questsystem2/src/orxonox/objects/quest/GlobalQuest.cc

    r2105 r2146  
    2626 *
    2727 */
     28 
     29/**
     30    @file GlobalQuest.cc
     31    @brief
     32        Implementation of the GlobalQuest class.
     33*/
    2834
    2935#include "OrxonoxStableHeaders.h"
    3036#include "GlobalQuest.h"
    3137
     38#include "orxonox/objects/worldentities/ControllableEntity.h"
    3239#include "core/CoreIncludes.h"
    3340#include "util/Exception.h"
    3441
     42#include "QuestEffect.h"
     43
    3544namespace orxonox {
    3645
     
    3948    /**
    4049    @brief
    41         Constructor.
     50        Constructor. Initializes the object.
    4251    */
    4352    GlobalQuest::GlobalQuest(BaseObject* creator) : Quest(creator)
    4453    {
     54        this->initialize();
     55    }
     56   
     57    /**
     58    @brief
     59        Initializes the object.
     60    */
     61    void GlobalQuest::initialize(void)
     62    {
    4563        RegisterObject(GlobalQuest);
    46 
    47         this->initialize();
    4864    }
    4965
     
    5672
    5773    }
    58 
     74   
     75    /**
     76    @brief
     77        Method for creating a GlobalQuest object through XML.
     78    */
    5979    void GlobalQuest::XMLPort(Element& xmlelement, XMLPort::Mode mode)
    6080    {
    6181        SUPER(GlobalQuest, XMLPort, xmlelement, mode);
     82       
     83        XMLPortObject(GlobalQuest, QuestEffect, "reward-effects", addRewardEffect, getRewardEffects, xmlelement, mode);
    6284
    6385        COUT(3) << "New GlobalQuest {" << this->getId() << "} created." << std::endl;
    6486    }
    65 
    66     void GlobalQuest::initialize(void)
    67     {
    68         RegisterObject(GlobalQuest);
     87   
     88    /**
     89    @brief
     90        Fails the quest for all players.
     91        Invokes the failEffects on all the players possessing this quest.
     92    @param player
     93        The player failing it.
     94    @return
     95        Returns true if the quest could be failed, false if not.
     96    */
     97    bool GlobalQuest::fail(ControllableEntity* player)
     98    {
     99        if(this->isFailable(player)) //!< Check whether the quest can be failed.
     100        {
     101            this->setStatus(player, questStatus::failed);
     102           
     103            //! Iterate through all players possessing this quest.
     104            for(std::set<ControllableEntity*>::const_iterator it = players_.begin(); it != players_.end(); it++)
     105            {
     106                QuestEffect::invokeEffects(*it, this->failEffects_);
     107            }
     108
     109            return true;
     110        }
     111       
     112        COUT(2) << "A non-completable quest was trying to be failed." << std::endl;
     113        return false;
     114    }
     115
     116    /**
     117    @brief
     118        Completes the quest for all players.
     119        Invokes the completeEffects on all the players possessing this quest.
     120        Invokes the reward effects on the player completing the quest.
     121    @param player
     122        The player completing it.
     123    @return
     124        Returns true if the quest could be completed, false if not.
     125    */
     126    bool GlobalQuest::complete(ControllableEntity* player)
     127    {
     128        if(this->isCompletable(player)) //!< Check whether the quest can be completed.
     129        {
     130            this->setStatus(player, questStatus::completed);
     131           
     132            //! Iterate through all players possessing the quest.
     133            for(std::set<ControllableEntity*>::const_iterator it = players_.begin(); it != players_.end(); it++)
     134            {
     135                QuestEffect::invokeEffects(*it, this->completeEffects_);
     136            }
     137           
     138            QuestEffect::invokeEffects(player, this->rewards_); //!< Invoke reward effects on the player completing the quest.
     139            return true;
     140        }
     141       
     142        COUT(2) << "A non-completable quest was trying to be completed." << std::endl;
     143        return false;
    69144    }
    70145
     
    79154        Throws an exception if either isInactive() of isActive() throws one.
    80155    */
    81     bool GlobalQuest::isStartable(const Player* player) const
     156    bool GlobalQuest::isStartable(const ControllableEntity* player) const
    82157    {
    83158        return this->isInactive(player) ||  this->isActive(player);
     
    94169        Throws an Exception if isActive() throws one.
    95170    */
    96     bool GlobalQuest::isFailable(const Player* player) const
     171    bool GlobalQuest::isFailable(const ControllableEntity* player) const
    97172    {
    98173        return this->isActive(player);
     
    110185        Throws an Exception if isActive() throws one.
    111186    */
    112     bool GlobalQuest::isCompletable(const Player* player) const
     187    bool GlobalQuest::isCompletable(const ControllableEntity* player) const
    113188    {
    114189        return this->isActive(player);
     
    123198        Throws an Exception if player is NULL.
    124199    */
    125     questStatus::Enum GlobalQuest::getStatus(const Player* player) const
    126     {
    127         if(player == NULL)
    128         {
    129             ThrowException(Argument, "The input Player* is NULL.");
    130         }
    131 
    132         //TDO: Does this really work???
    133         std::set<Player*>::const_iterator it = this->players_.find((Player*)(void*)player);
    134         if (it != this->players_.end())
     200    questStatus::Enum GlobalQuest::getStatus(const ControllableEntity* player) const
     201    {
     202        if(player == NULL) //!< We don't want NULL-Pointers!
     203        {
     204            ThrowException(Argument, "The input ControllableEntity* is NULL.");
     205        }
     206
     207        //! Find the player.
     208        std::set<ControllableEntity*>::const_iterator it = this->players_.find((ControllableEntity*)(void*)player);
     209        if (it != this->players_.end()) //!< If the player was found.
    135210        {
    136211            return this->status_;
    137212        }
    138         else
    139         {
    140            return questStatus::inactive;
    141         }
    142 
     213
     214        return questStatus::inactive;
    143215    }
    144216
     
    154226        Returns false if player is NULL.
    155227    */
    156     bool GlobalQuest::setStatus(Player* player, const questStatus::Enum & status)
    157     {
    158         if(player == NULL)
     228    bool GlobalQuest::setStatus(ControllableEntity* player, const questStatus::Enum & status)
     229    {
     230        if(player == NULL) //!< We don't want NULL-Pointers!
    159231        {
    160232            return false;
    161233        }
    162234
    163         std::set<Player*>::const_iterator it = this->players_.find(player);
     235        //! Find the player.
     236        std::set<ControllableEntity*>::const_iterator it = this->players_.find(player);
    164237        if (it == this->players_.end()) //!< Player is not yet in the list.
    165238        {
    166             this->players_.insert(player);
    167         }
    168         this->status_ = status;
     239            this->players_.insert(player); //!< Add the player to the set.
     240        }
     241       
     242        this->status_ = status; //!< Set the status, which is global, remember...?
    169243        return true;
    170244    }
     245   
     246    /**
     247    @brief
     248        Adds a reward effect to the list of reward effects.
     249    @param effect
     250        The effect to be added.
     251    @return
     252        Returns true if successful.
     253    */
     254    bool GlobalQuest::addRewardEffect(QuestEffect* effect)
     255    {
     256        if(effect == NULL) //!< We don't want NULL-Pointers!
     257        {
     258            COUT(2) << "The reward effect to be added to quest {" << this->getId() << "} was NULL." << std::endl;
     259            return false;
     260        }
     261
     262        this->rewards_.push_back(effect); //!< Add the effect to the list.
     263
     264        COUT(3) << "Reward effect was added to Quest {" << this->getId() << "}." << std::endl;
     265        return true;
     266    }
     267   
     268    /**
     269    @brief
     270        Returns the reward effect at the given index.
     271    @param index
     272        The index.
     273    @return
     274        Returns the QuestEffect at the given index.
     275    */
     276    const QuestEffect* GlobalQuest::getRewardEffects(unsigned int index) const
     277    {
     278        int i = index;
     279        for (std::list<QuestEffect*>::const_iterator effect = this->rewards_.begin(); effect != this->rewards_.end(); ++effect)
     280        {
     281            if(i == 0)
     282            {
     283               return *effect;
     284            }
     285            i--;
     286        }
     287        return NULL;
     288    }
    171289
    172290
  • code/branches/questsystem2/src/orxonox/objects/quest/GlobalQuest.h

    r2096 r2146  
    2626 *
    2727 */
     28 
     29/**
     30    @file GlobalQuest.h
     31    @brief
     32        Definition of the GlobalQuest class.
     33*/
    2834
    2935#ifndef _GlobalQuest_H__
     
    3339
    3440#include <set>
     41#include <list>
    3542
    3643#include "core/XMLPort.h"
     
    3946namespace orxonox {
    4047
    41     class Player; //Forward declaration, remove when fully integrated into the objecthirarchy.
    42 
    4348    /**
    4449    @brief
    4550        Global quests are quests, that have the same status for all players.
    46         This means, that when a player successfully completes this quest, it is completed for all players that have it.
     51        This means, that when a player successfully completes a GlobalQuest, it is completed for all players that have it.
     52       
     53        Creating a GlobalQuest through XML goes as follows:
     54       
     55        <GlobalQuest id="questId"> //Where questId is a GUID, see http://en.wikipedia.org/wiki/Globally_Unique_Identifier#Basic_structure for more information
     56            <QuestDescription title="Title" description="Description." /> //The description of the quest.
     57            <subquests>
     58                <Quest id ="questId1" /> //A list of n subquest, be aware, each of the <Quest /> tags must have a description and so on and so forth as well.
     59                ...
     60                <Quest id="questIdn" />
     61            </subquests>
     62            <hints>
     63                <QuestHint id="hintId1" /> //A list of n QuestHints, see QuestHint for the full XML representation of those.
     64                ...
     65                <QuestHint id="hintIdn" />
     66            </hints>
     67            <fail-effects>
     68                <QuestEffect /> //A list of QuestEffects, invoked on all players possessing this quest, when the Quest is failed, see QuestEffect for the full XML representation.
     69                ...
     70                <QuestEffect />
     71            </fail-effects>
     72            <complete-effects>
     73                <QuestEffect /> //A list of QuestEffects, invoked on all players possessing this quest, when the Quest is completed, see QuestEffect for the full XML representation.
     74                ...
     75                <QuestEffect />
     76            </complete-effects>
     77            <reward-effects>
     78                <QuestEffect /> //A list of QuestEffects, invoked on the player completing this quest. See QuestEffect for the full XML representation.
     79                ...
     80                <QuestEffect />
     81            </reward-effects>
     82        </GlobalQuest>
    4783    @author
    4884        Damian 'Mozork' Frick
     
    5490            virtual ~GlobalQuest();
    5591
    56             virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
     92            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); //!< Method for creating a GlobalQuest object through XML.
     93           
     94            virtual bool fail(ControllableEntity* player); //!< Fails the quest.
     95            virtual bool complete(ControllableEntity* player); //!< Completes the quest.
    5796
    5897        protected:
    59             virtual bool isStartable(const Player* player) const; //!< Checks whether the quest can be started.
    60             virtual bool isFailable(const Player* player) const; //!< Checks whether the quest can be failed.
    61             virtual bool isCompletable(const Player* player) const; //!< Checks whether the quest can be completed.
     98            virtual bool isStartable(const ControllableEntity* player) const; //!< Checks whether the quest can be started.
     99            virtual bool isFailable(const ControllableEntity* player) const; //!< Checks whether the quest can be failed.
     100            virtual bool isCompletable(const ControllableEntity* player) const; //!< Checks whether the quest can be completed.
    62101
    63             virtual questStatus::Enum getStatus(const Player* player) const; //!< Returns the status of the quest for a specific player.
    64             virtual bool setStatus(Player* player, const questStatus::Enum & status); //!< Sets the status for a specific player.
     102            virtual questStatus::Enum getStatus(const ControllableEntity* player) const; //!< Returns the status of the quest for a specific player.
     103            virtual bool setStatus(ControllableEntity* player, const questStatus::Enum & status); //!< Sets the status for a specific player.
    65104
    66105        private:
    67             std::set<Player*> players_; //!< The set of players which possess this quest.
     106            std::set<ControllableEntity*> players_; //!< The set of players which possess this quest.
    68107            questStatus::Enum status_; //!< The status of this quest.
     108            std::list<QuestEffect*> rewards_; //!< Reward effects only invoked on the player completing the quest.
     109           
     110            bool addRewardEffect(QuestEffect* effect); //!< Adds a reward effect to the list of reward effects.
     111            const QuestEffect* getRewardEffects(unsigned int index) const; //!< Returns the reward effect at the given index.
    69112
    70             void initialize(void);
     113            void initialize(void); //!< Initializes the object.
    71114
    72115    };
  • code/branches/questsystem2/src/orxonox/objects/quest/LocalQuest.cc

    r2105 r2146  
    2727 */
    2828
     29/**
     30    @file LocalQuest.cc
     31    @brief
     32        Implementation of the LocalQuest class.
     33*/
     34
    2935#include "OrxonoxStableHeaders.h"
    3036#include "LocalQuest.h"
     
    3339#include "util/Exception.h"
    3440
     41#include "orxonox/objects/worldentities/ControllableEntity.h"
     42#include "QuestEffect.h"
     43
    3544namespace orxonox {
    3645
    3746    CreateFactory(LocalQuest);
    3847
     48    /**
     49    @brief
     50        Constructor. Initializes the object.
     51    */
    3952    LocalQuest::LocalQuest(BaseObject* creator) : Quest(creator)
    4053    {
     54        this->initialize();
     55    }
     56   
     57    /**
     58    @brief
     59        Initializes the object.
     60    */
     61    void LocalQuest::initialize(void)
     62    {
    4163        RegisterObject(LocalQuest);
    42 
    43         this->initialize();
    4464    }
    4565
     
    5373    }
    5474
     75    /**
     76    @brief
     77        Method for creating a LocalQuest object through XML.
     78    */
    5579    void LocalQuest::XMLPort(Element& xmlelement, XMLPort::Mode mode)
    5680    {
     
    6084    }
    6185
    62     void LocalQuest::initialize(void)
    63     {
    64         RegisterObject(LocalQuest);
     86    /**
     87    @brief
     88        Fails the quest for a given player.
     89        Invokes all the failEffects on the player.
     90    @param player
     91        The player.
     92    @return
     93        Returns true if the quest could be failed, false if not.
     94    */
     95    bool LocalQuest::fail(ControllableEntity* player)
     96    {
     97        if(this->isFailable(player)) //!< Checks whether the quest can be failed.
     98        {
     99            this->setStatus(player, questStatus::failed);
     100            QuestEffect::invokeEffects(player, this->failEffects_); //!< Invoke the failEffects.
     101            return true;
     102        }
     103       
     104        COUT(2) << "A non-failable quest was trying to be failed." << std::endl;
     105        return false;
     106    }
     107
     108    /**
     109    @brief
     110        Completes the quest for a given player.
     111        Invokes all the completeEffects on the player.
     112    @param player
     113        The player.
     114    @return
     115        Returns true if the quest could be completed, false if not.
     116    */
     117    bool LocalQuest::complete(ControllableEntity* player)
     118    {
     119        if(this->isCompletable(player)) //!< Checks whether the quest can be completed.
     120        {
     121            this->setStatus(player, questStatus::completed);
     122            QuestEffect::invokeEffects(player, this->completeEffects_); //!< Invoke the completeEffects.
     123            return true;
     124        }
     125       
     126        COUT(2) << "A non-completable quest was trying to be completed." << std::endl;
     127        return false;
    65128    }
    66129
     
    73136        Returns true if the quest can be started, false if not.
    74137    @throws
    75         Throws an exception if isInactive(Player*) throws one.
    76     */
    77     bool LocalQuest::isStartable(const Player* player) const
     138        Throws an exception if isInactive(ControllableEntity*) throws one.
     139    */
     140    bool LocalQuest::isStartable(const ControllableEntity* player) const
    78141    {
    79142        return this->isInactive(player);
     
    88151        Returns true if the quest can be failed, false if not.
    89152    @throws
    90         Throws an exception if isActive(Player*) throws one.
    91     */
    92     bool LocalQuest::isFailable(const Player* player) const
     153        Throws an exception if isActive(ControllableEntity*) throws one.
     154    */
     155    bool LocalQuest::isFailable(const ControllableEntity* player) const
    93156    {
    94157        return this->isActive(player);
     
    103166        Returns true if the quest can be completed, false if not.
    104167    @throws
    105         Throws an exception if isInactive(Player*) throws one.
    106     */
    107     bool LocalQuest::isCompletable(const Player* player) const
     168        Throws an exception if isInactive(ControllableEntity*) throws one.
     169    */
     170    bool LocalQuest::isCompletable(const ControllableEntity* player) const
    108171    {
    109172        return this->isActive(player);
     
    120183        Throws an Exception if player is NULL.
    121184    */
    122     questStatus::Enum LocalQuest::getStatus(const Player* player) const
    123     {
    124         if(player == NULL)
    125         {
    126             ThrowException(Argument, "The input Player* is NULL.");
    127         }
    128 
    129         std::map<Player*, questStatus::Enum>::const_iterator it = this->playerStatus_.find((Player*)(void*)player); //Thx. to x3n for the (Player*)(void*) 'hack'.
    130         if (it != this->playerStatus_.end())
     185    questStatus::Enum LocalQuest::getStatus(const ControllableEntity* player) const
     186    {
     187        if(player == NULL) //!< No player has no defined status.
     188        {
     189            ThrowException(Argument, "The input ControllableEntity* is NULL.");
     190        }
     191
     192        std::map<ControllableEntity*, questStatus::Enum>::const_iterator it = this->playerStatus_.find((ControllableEntity*)(void*)player); //Thx. to x3n for the (ControllableEntity*)(void*) 'hack'.
     193        if (it != this->playerStatus_.end()) //!< If there is a player in the map.
    131194        {
    132195            return it->second;
    133196        }
    134         return questStatus::inactive;
     197       
     198        return questStatus::inactive; //!< If the player is not yet in the map, that means the status of the quest form him is 'inactive'.
    135199    }
    136200
     
    138202    @brief
    139203        Sets the status for a specific player.
    140         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.
    141     @param player
    142         The player.
     204        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. Really!
     205    @param player
     206        The player the status should be set for.
    143207    @param status
    144         The status.
     208        The status to be set.
    145209    @return
    146210        Returns false if player is NULL.
    147211    */
    148     bool LocalQuest::setStatus(Player* player, const questStatus::Enum & status)
    149     {
    150         if(player == NULL)
     212    bool LocalQuest::setStatus(ControllableEntity* player, const questStatus::Enum & status)
     213    {
     214        if(player == NULL) //!< We can't set a status for no player.
    151215        {
    152216            return false;
    153217        }
     218       
    154219        this->playerStatus_[player] = status;
    155220        return true;
  • code/branches/questsystem2/src/orxonox/objects/quest/LocalQuest.h

    r2096 r2146  
    2626 *
    2727 */
     28 
     29/**
     30    @file LocalQuest.h
     31    @brief
     32        Definition of the LocalQuest class.
     33*/
    2834
    2935#ifndef _LocalQuest_H__
     
    4046namespace orxonox {
    4147
    42     class Player; //Forward declaration, remove when fully integrated into the objecthirarchy.
    43 
    4448    /**
    4549    @brief
    4650        Handles quests which have different states for different players.
     51        LocalQuests have (as opposed to GlobalQuests) a different state for each player, that means if for one player the status of the Quest changes it does not for all the other players which also possess this quest.
     52       
     53        Creating a LocalQuest through XML goes as follows:
     54       
     55        <LocalQuest id="questId"> //Where questId is a GUID, see http://en.wikipedia.org/wiki/Globally_Unique_Identifier#Basic_structure for more information
     56            <QuestDescription title="Title" description="Description." /> //The description of the quest.
     57            <subquests>
     58                <Quest id ="questId1" /> //A list of n subquest, be aware, each of the <Quest /> tags must have a description and so on and so forth as well.
     59                ...
     60                <Quest id="questIdn" />
     61            </subquests>
     62            <hints>
     63                <QuestHint id="hintId1" /> //A list of n QuestHints, see QuestHint for the full XML representation of those.
     64                ...
     65                <QuestHint id="hintIdn" />
     66            </hints>
     67            <fail-effects>
     68                <QuestEffect /> //A list of QuestEffects, invoked when the Quest is failed, see QuestEffect for the full XML representation.
     69                ...
     70                <QuestEffect />
     71            </fail-effects>
     72            <complete-effects>
     73                <QuestEffect /> //A list of QuestEffects, invoked when the Quest is completed, see QuestEffect for the full XML representation.
     74                ...
     75                <QuestEffect />
     76            </complete-effects>
     77        </LocalQuest>
    4778    @author
    4879        Damian 'Mozork' Frick
     
    5485            virtual ~LocalQuest();
    5586
    56             virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
     87            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); //!< Method for creating a LocalQuest object through XML.
     88           
     89            virtual bool fail(ControllableEntity* player); //!< Fails the quest.
     90            virtual bool complete(ControllableEntity* player); //!< Completes the quest.
    5791
    5892        protected:
    59             virtual bool isStartable(const Player* player) const; //!< Checks whether the quest can be started.
    60             virtual bool isFailable(const Player* player) const; //!< Checks whether the quest can be failed.
    61             virtual bool isCompletable(const Player* player) const; //!< Checks whether the quest can be completed.
     93            virtual bool isStartable(const ControllableEntity* player) const; //!< Checks whether the quest can be started.
     94            virtual bool isFailable(const ControllableEntity* player) const; //!< Checks whether the quest can be failed.
     95            virtual bool isCompletable(const ControllableEntity* player) const; //!< Checks whether the quest can be completed.
    6296
    63             virtual questStatus::Enum getStatus(const Player* player) const; //!< Returns the status of the quest for a specific player.
    64             virtual bool setStatus(Player* player, const questStatus::Enum & status); //!< Sets the status for a specific player.
     97            virtual questStatus::Enum getStatus(const ControllableEntity* player) const; //!< Returns the status of the quest for a specific player.
     98            virtual bool setStatus(ControllableEntity* player, const questStatus::Enum & status); //!< Sets the status for a specific player.
    6599
    66100        private:
    67             std::map<Player*, questStatus::Enum> playerStatus_; //!< List of the status for each player, with the Player-pointer as key.
     101            std::map<ControllableEntity*, questStatus::Enum> playerStatus_; //!< List of the status for each player, with the Player-pointer as key.
    68102
    69             void initialize(void);
     103            void initialize(void); //!< Initializes the object.
    70104
    71105    };
    72 
    73106
    74107}
  • code/branches/questsystem2/src/orxonox/objects/quest/Quest.cc

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

    r2096 r2146  
    2626 *
    2727 */
    28 
     28 
     29/**
     30    @file Quest.h
     31    @brief
     32        Definition of the Quest class.
     33       
     34        The Quest is the parent class of LocalQuest and GlobalQuest.
     35*/
     36 
    2937#ifndef _Quest_H__
    3038#define _Quest_H__
     
    3846#include "QuestItem.h"
    3947
     48
    4049namespace questStatus
    4150{
    4251
     52    //!Different states of a quest.
    4353    enum Enum
    4454    {
     
    5363namespace orxonox {
    5464
    55     class Player; //Forward declaration, remove when fully integrated into the objecthirarchy.
    56 
    5765    /**
    5866    @brief
     
    6068        A quest has a list of subquests and a parentquest (if it is not a rootquest).
    6169        Each quest exists only once but it has a different status (inactive, active, failed or completed) for each player.
     70        A quest has several hints (QuestHint) that can be unlocked through QuestEffects and then display aid in solving the quest.
     71        A quest has a list of QuestEffects that are invoked when the quest is failed and also a list of effects that are invoked, when the quest is completed.
     72       
     73        Quest itself should not be instantiated, if you want to create a quest either go for LocalQuest or GlobalQuest, whichever suits you needs better.
    6274    @author
    6375        Damian 'Mozork' Frick
     
    6981            virtual ~Quest();
    7082
    71             virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
     83            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); //!< Method for creating a Quest object through XML.
    7284
    7385            inline Quest* getParentQuest(void) const //!< Returns the parent quest of the quest.
     
    7688                { return this->subQuests_; }
    7789
    78             bool isInactive(const Player* player) const; //!< Returns true if the quest status for the specific player is 'inactive'.
    79             bool isActive(const Player* player) const; //!< Returns true if the quest status for the specific player is 'active'.
    80             bool isFailed(const Player* player) const; //!< Returns true if the quest status for the specific player is 'failed'.
    81             bool isCompleted(const Player* player) const; //!< Returns true if the quest status for the specific player is 'completed'.
     90            bool isInactive(const ControllableEntity* player) const; //!< Returns true if the quest status for the specific player is 'inactive'.
     91            bool isActive(const ControllableEntity* player) const; //!< Returns true if the quest status for the specific player is 'active'.
     92            bool isFailed(const ControllableEntity* player) const; //!< Returns true if the quest status for the specific player is 'failed'.
     93            bool isCompleted(const ControllableEntity* player) const; //!< Returns true if the quest status for the specific player is 'completed'.
    8294
    83             bool start(Player* player); //!< Sets a quest to active.
    84             bool fail(Player* player); //!< Fails the quest.
    85             bool complete(Player* player); //!< Completes the quest.
     95            bool start(ControllableEntity* player); //!< Sets a quest to active.
     96            virtual bool fail(ControllableEntity* player) = 0; //!< Fails the quest.
     97            virtual bool complete(ControllableEntity* player) = 0; //!< Completes the quest.
    8698
    8799        protected:
    88             void initialize(void); //!< Initialized the object.
     100            void initialize(void); //!< Initializes the object.
    89101
    90             virtual bool isStartable(const Player* player) const = 0; //!< Checks whether the quest can be started.
    91             virtual bool isFailable(const Player* player) const = 0; //!< Checks whether the quest can be failed.
    92             virtual bool isCompletable(const Player* player) const = 0; //!< Checks whether the quest can be completed.
     102            virtual bool isStartable(const ControllableEntity* player) const = 0; //!< Checks whether the quest can be started.
     103            virtual bool isFailable(const ControllableEntity* player) const = 0; //!< Checks whether the quest can be failed.
     104            virtual bool isCompletable(const ControllableEntity* player) const = 0; //!< Checks whether the quest can be completed.
    93105
    94106            bool setParentQuest(Quest* quest); //!< Sets the parent quest of the quest.
    95107            bool addSubQuest(Quest* quest); //!< Adds a sub quest to the quest.
    96108            bool addHint(QuestHint* hint); //!< Add a hint to the list of hints.
    97             bool addFailEffect(QuestEffect* effect);
    98             bool addCompleteEffect(QuestEffect* effect);
     109            bool addFailEffect(QuestEffect* effect); //!< Adds an effect to the list of failEffects.
     110            bool addCompleteEffect(QuestEffect* effect); //!< Adds an effect to the list of completeEffects.
    99111
    100             const Quest* getParentQuest(void);
    101             const Quest* getSubQuests(unsigned int index) const;
    102             const QuestHint* getHints(unsigned int index) const;
    103             const QuestEffect* getFailEffects(unsigned int index) const;
    104             const QuestEffect* getCompleteEffects(unsigned int index) const;
     112            const Quest* getParentQuest(void); //!< Returns the parent quest of the quest.
     113            const Quest* getSubQuests(unsigned int index) const; //!<Returns the sub quest of the given index.
     114            const QuestHint* getHints(unsigned int index) const; //!< Returns the hint of the given index.
     115            const QuestEffect* getFailEffects(unsigned int index) const; //!< Returns the failEffect of the given index.
     116            const QuestEffect* getCompleteEffects(unsigned int index) const; //!Returns the completeEffect of the given index.
    105117
    106             virtual questStatus::Enum getStatus(const Player* player) const = 0; //!< Returns the status of the quest for a specific player.
    107             virtual bool setStatus(Player* player, const questStatus::Enum & status) = 0; //!< Changes the status for a specific player.
     118            virtual questStatus::Enum getStatus(const ControllableEntity* player) const = 0; //!< Returns the status of the quest for a specific player.
     119            virtual bool setStatus(ControllableEntity* player, const questStatus::Enum & status) = 0; //!< Changes the status for a specific player.
    108120
    109121            Quest* parentQuest_; //!< Pointer to the parent quest.
  • code/branches/questsystem2/src/orxonox/objects/quest/QuestEffect.cc

    r2105 r2146  
    3232#include "core/CoreIncludes.h"
    3333
     34#include "orxonox/objects/worldentities/ControllableEntity.h"
     35
    3436namespace orxonox {
    3537
     
    6365        Returns false if there was an error, view console of log for further detail.
    6466    */
    65     bool QuestEffect::invokeEffects(Player* player, std::list<QuestEffect*> & effects)
     67    bool QuestEffect::invokeEffects(ControllableEntity* player, std::list<QuestEffect*> & effects)
    6668    {
    6769        bool check = true;
  • code/branches/questsystem2/src/orxonox/objects/quest/QuestEffect.h

    r2096 r2146  
    3838namespace orxonox {
    3939
    40     class Player; //Forward declaration, remove when fully integrated into the objecthirarchy.
    41 
    4240    /**
    4341    @brief
     
    5250            virtual ~QuestEffect();
    5351
    54             virtual bool invoke(Player* player) = 0; //!< Invokes the effect.
    55             static bool invokeEffects(Player* player, std::list<QuestEffect*> & effects); //!< Invokes all effects in the list.
     52            virtual bool invoke(ControllableEntity* player) = 0; //!< Invokes the effect.
     53            static bool invokeEffects(ControllableEntity* player, std::list<QuestEffect*> & effects); //!< Invokes all effects in the list.
    5654
    5755
  • code/branches/questsystem2/src/orxonox/objects/quest/QuestHint.cc

    r2105 r2146  
    2626 *
    2727 */
     28 
     29/**
     30    @file QuestHint.cc
     31    @brief
     32        Implementation of the QuestHint class.
     33*/
    2834
    2935#include "OrxonoxStableHeaders.h"
     
    3339#include "util/Exception.h"
    3440
     41#include "orxonox/objects/worldentities/ControllableEntity.h"
    3542#include "Quest.h"
    3643
     
    4148    /**
    4249    @brief
    43         Constructor.
     50        Constructor. Initializes the object.
    4451    */
    4552    QuestHint::QuestHint(BaseObject* creator) : QuestItem(creator)
    4653    {
     54        this->initialize();
     55    }
     56   
     57    /**
     58    @brief
     59        Initialize the object.
     60    */
     61    void QuestHint::initialize(void)
     62    {
    4763        RegisterObject(QuestHint);
    48 
    49         this->initialize();
    5064    }
    5165
     
    5973    }
    6074
    61     void QuestHint::initialize(void)
    62     {
    63         RegisterObject(QuestHint);
    64     }
    65 
     75    /**
     76    @brief
     77        Method for creating a QuestHint object through XML.
     78    */
    6679    void QuestHint::XMLPort(Element& xmlelement, XMLPort::Mode mode)
    6780    {
     
    8295        Returns true if the hint is active for the specified player.
    8396    */
    84     bool QuestHint::isActive(Player* player)
     97    bool QuestHint::isActive(ControllableEntity* player)
    8598    {
    86         if(player == NULL)
     99        if(player == NULL) //!< NULL-Pointers are ugly!
    87100        {
    88             ThrowException(Argument, "The input Player* is NULL.");
     101            ThrowException(Argument, "The input ControllableEntity* is NULL.");
    89102            return false;
    90103        }
    91104
    92         std::map<Player*, questHintStatus::Enum>::iterator it = this->playerStatus_.find(player);
    93         if (it != this->playerStatus_.end())
     105        //! Find the player.
     106        std::map<ControllableEntity*, questHintStatus::Enum>::iterator it = this->playerStatus_.find(player);
     107        if (it != this->playerStatus_.end()) //!< If the player is in the map.
    94108        {
    95109            return it->second;
    96110        }
     111       
    97112        return questStatus::inactive;
    98113    }
     
    106121        Returns true if the activation was successful, false if there were problems.
    107122    */
    108     bool QuestHint::activate(Player* player)
     123    bool QuestHint::setActive(ControllableEntity* player)
    109124    {
    110         if(this->quest_->isActive(player))
     125        if(this->quest_->isActive(player)) //!< For a hint to get activated the quest must be active.
    111126        {
    112             if(!(this->isActive(player)))
     127            if(!(this->isActive(player)))  //!< If the hint is already active, activation is pointless.
    113128            {
    114129                this->playerStatus_[player] = questHintStatus::active;
     
    121136            }
    122137        }
     138       
    123139        COUT(2) << "A hint of a non-active quest was trying to get activated." << std::endl;
    124140        return false;
     
    129145        Sets the quest the QuestHitn belongs to.
    130146    @param quest
     147        The quest to be set as quest the hint is attached to.
    131148    @return
     149        Returns true if successful.
    132150    */
    133151    bool QuestHint::setQuest(Quest* quest)
    134152    {
    135         if(quest == NULL)
     153        if(quest == NULL) //!< NULL-Pointer. Again..?
    136154        {
    137155            COUT(2) << "The input Quest* is NULL." << std::endl;
  • code/branches/questsystem2/src/orxonox/objects/quest/QuestHint.h

    r2096 r2146  
    2626 *
    2727 */
     28 
     29/**
     30    @file QuestHint.h
     31    @brief
     32        Definition of the QuestHint class.
     33*/
    2834
    2935#ifndef _QuestHint_H__
     
    4147{
    4248
     49    //! The status of the hint.
    4350    enum Enum
    4451    {
     
    5259{
    5360
    54     class Player; //Forward declaration, remove when fully integrated into the objecthirarchy.
    55 
    5661    /**
    5762    @brief
    5863        Represents a hint in the game towards completing a Quest.
    5964        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.
     65        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 states for each of them.
     66       
     67        Creating a QuestHint through XML goes as follows:
     68       
     69        <QuestHint id="hintId">  //Where hintId is a GUID, see http://en.wikipedia.org/wiki/Globally_Unique_Identifier#Basic_structure for more information
     70            <QuestDesctription title="" description="" />
     71        </QuestHint>
    6172    @author
    6273        Damian 'Mozork' Frick
     
    6980            virtual ~QuestHint();
    7081
    71             virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
     82            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); //!< Method for creating a QuestHint object through XML.
    7283
    73             bool isActive(Player* player); //!< Returns true if the hint is active for the input player.
     84            bool isActive(ControllableEntity* player); //!< Returns true if the hint is active for the input player.
    7485
    75             bool activate(Player* player); //!< Activates the hint for the input player.
    76 
     86            bool setActive(ControllableEntity* player); //!< Activates the hint for the input player.
    7787            bool setQuest(Quest* quest); //!< Sets the quest the hint belongs to.
    7888
    79             inline Quest* getQuest(void)
     89            inline Quest* getQuest(void) //!< Returns the quest the hint is attached to.
    8090               { return this->quest_; }
    8191
    8292        private:
     93            Quest* quest_; //!< The quest the hint belongs to.
     94            std::map<ControllableEntity*, questHintStatus::Enum> playerStatus_; //!< List of the status for each player, with the Player-pointer as key.
    8395
    84             void initialize(void);
    85 
    86             Quest* quest_; //!< The quest the hint belongs to.
    87             std::map<Player*, questHintStatus::Enum> playerStatus_; //!< List of the status for each player, with the Player-pointer as key.
     96            void initialize(void); //!< Initializes the object.
    8897
    8998    };
  • code/branches/questsystem2/src/orxonox/objects/quest/QuestItem.cc

    r2105 r2146  
    2626 *
    2727 */
     28 
     29/**
     30    @file QuestItem.cc
     31    @brief
     32        Implementation of the QuestItem class.
     33*/
    2834
    2935#include "OrxonoxStableHeaders.h"
     
    3642namespace orxonox {
    3743
     44    /**
     45    @brief
     46        Constructor. Registers and initializes the object.
     47    */
    3848    QuestItem::QuestItem(BaseObject* creator) : BaseObject(creator)
    3949    {
     
    4252        this->initialize();
    4353    }
    44 
    45     /**
    46     @brief
    47         Destructor.
    48     */
    49     QuestItem::~QuestItem()
    50     {
    51 
    52     }
    53 
    54     void QuestItem::XMLPort(Element& xmlelement, XMLPort::Mode mode)
    55     {
    56         SUPER(QuestItem, XMLPort, xmlelement, mode);
    57 
    58         XMLPortParam(QuestItem, "id", setId, getId, xmlelement, mode);
    59         //Doesn't getDescription have to be of type getDescription(unsigned int) ?
    60         //XMLPortObjectTemplate(QuestItem, QuestDescription, "", setDescription, getDescription, xmlelement, mode, unsigned int);
    61         XMLPortObject(QuestItem, QuestDescription, "", setDescription, getDescription, xmlelement, mode);
    62 
    63     }
    64 
    65 
     54   
    6655    /**
    6756    @brief
     
    7665    }
    7766
     67    /**
     68    @brief
     69        Destructor.
     70    */
     71    QuestItem::~QuestItem()
     72    {
     73
     74    }
     75
     76    /**
     77    @brief
     78        Method for creating a QuestItem object through XML.
     79    */
     80    void QuestItem::XMLPort(Element& xmlelement, XMLPort::Mode mode)
     81    {
     82        SUPER(QuestItem, XMLPort, xmlelement, mode);
     83
     84        XMLPortParam(QuestItem, "id", setId, getId, xmlelement, mode);
     85        XMLPortObject(QuestItem, QuestDescription, "", setDescription, getDescription, xmlelement, mode);
     86    }
     87
     88    /**
     89    @brief
     90        Sets the id of the QuestItem.
     91        The id must be of GUID form. See 'http://en.wikipedia.org/wiki/Globally_Unique_Identifier#Basic_structure' for more information.
     92    @param id
     93        The id to be set.
     94    */
    7895    void QuestItem::setId(const std::string & id)
    7996    {
    80         if(!isId(id))
     97        if(!isId(id)) //!< Checks whether the id is a valid id.
    8198        {
    8299            COUT(2) << "Invalid id. QuestItem id {" << id << "} could not be set." << std::endl;
    83100            return;
    84101        }
     102       
    85103        this->id_ = id;
    86104    }
    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     //}
    94105
    95106    /**
  • code/branches/questsystem2/src/orxonox/objects/quest/QuestItem.h

    r2096 r2146  
    2626 *
    2727 */
     28 
     29/**
     30    @file QuestItem.h
     31    @brief
     32        Definition of the QuestItem class.
     33       
     34        The QuestItem is the parent class of Quest and QuestHint.
     35*/
     36
    2837
    2938#ifndef _QuestItem_H__
     
    5463            virtual ~QuestItem();
    5564
    56             virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
     65            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); //!< Method for creating a QuestItem object through XML.
    5766
    5867            inline const std::string & getId(void) const //!< Returns the id of this quest.
     
    6069            inline const QuestDescription* getDescription(void) const //!< Returns the description of the QuestItem.
    6170                { return this->description_; }
    62             //const QuestDescription* getDescription(unsigned int index) const; //!< Returns the description of the QuestItem.
    6371
    6472            static bool isId(const std::string & id); //!< Checks whether a given id is valid.
    6573
    6674        protected:
    67             void setId(const std::string & id);
    68             inline void setDescription(QuestDescription* description)
     75            void setId(const std::string & id); //!< Sets the id of the QuestItem.
     76            inline void setDescription(QuestDescription* description) //!< Sets the description of the QuestItem.
    6977                { this->description_ = description; }
    7078
  • code/branches/questsystem2/src/orxonox/objects/quest/Rewardable.h

    r2096 r2146  
    3636namespace orxonox {
    3737
    38     class Player; //Forward declaration, remove when fully integrated in objecthirarchy.
    39 
    4038    /**
    4139    @brief
     
    5149            virtual ~Rewardable();
    5250
    53             virtual bool reward(Player* player) = 0; //!<Method to transcribe a rewardable object to the player.
     51            virtual bool reward(ControllableEntity* player) = 0; //!<Method to transcribe a rewardable object to the player.
    5452
    5553    };
Note: See TracChangeset for help on using the changeset viewer.