Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/orxonox/objects/quest/QuestHint.cc @ 4036

Last change on this file since 4036 was 3280, checked in by rgrieder, 15 years ago

Merged most of the core4 revisions back to the trunk except for:

  • orxonox_cast
  • all the radical changes in the input library
  • Property svn:eol-style set to native
File size: 4.2 KB
RevLine 
[1992]1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
23 *      Damian 'Mozork' Frick
24 *   Co-authors:
25 *      ...
26 *
27 */
[2261]28 
29/**
[3196]30    @file
[2662]31    @brief Implementation of the QuestHint class.
[2261]32*/
[1992]33
[2105]34#include "QuestHint.h"
35
[1992]36#include "core/CoreIncludes.h"
[3196]37#include "core/XMLPort.h"
[2261]38#include "QuestManager.h"
[2662]39#include "QuestDescription.h"
[2021]40#include "Quest.h"
[1992]41
[2662]42namespace orxonox
43{
[1992]44    CreateFactory(QuestHint);
45
[2068]46    /**
47    @brief
[2261]48        Constructor. Registers the object.
[2068]49    */
[2092]50    QuestHint::QuestHint(BaseObject* creator) : QuestItem(creator)
[2021]51    {
[2092]52        RegisterObject(QuestHint);
[2021]53    }
[2092]54
[1992]55    /**
56    @brief
57        Destructor.
58    */
59    QuestHint::~QuestHint()
60    {
[2092]61
[1992]62    }
[2092]63
[2261]64    /**
65    @brief
66        Method for creating a QuestHint object through XML.
67    */
[2068]68    void QuestHint::XMLPort(Element& xmlelement, XMLPort::Mode mode)
69    {
[2093]70        SUPER(QuestHint, XMLPort, xmlelement, mode);
[2092]71
[2911]72        QuestManager::getInstance().registerHint(this); //!< Registers the QuestHint with the QuestManager.
[2261]73       
[2093]74        COUT(3) << "New QuestHint {" << this->getId() << "} created." << std::endl;
[2068]75    }
76
[2092]77
[1996]78    /**
79    @brief
[2261]80        Checks whether the QuestHint is active for a specific player.
[1996]81    @param player
82        The player.
[2068]83    @throws
84        Throws an Argument Exception if the input Player-pointer is NULL.
[1996]85    @return
[2261]86        Returns true if the QuestHint is active for the specified player.
[1996]87    */
[2261]88    bool QuestHint::isActive(const PlayerInfo* player) const
[1992]89    {
[2261]90        if(player == NULL) //!< NULL-Pointers are ugly!
[2068]91        {
[2261]92            ThrowException(Argument, "The input PlayerInfo* is NULL.");
[2068]93            return false;
94        }
[2092]95
[2261]96        //! Find the player.
[3280]97        std::map<const PlayerInfo*, QuestHintStatus::Value>::const_iterator it = this->playerStatus_.find(player);
[2261]98        if (it != this->playerStatus_.end()) //!< If the player is in the map.
[2093]99        {
100            return it->second;
101        }
[2261]102       
[3280]103        return QuestStatus::Inactive;
[1992]104    }
[2092]105
[2021]106    /**
107    @brief
[2068]108        Activates a QuestHint for a given player.
[2021]109    @param player
[2068]110        The player.
[2021]111    @return
[2068]112        Returns true if the activation was successful, false if there were problems.
[2021]113    */
[2261]114    bool QuestHint::setActive(PlayerInfo* player)
[1992]115    {
[2261]116        if(this->quest_->isActive(player)) //!< For a hint to get activated the quest must be active.
[1992]117        {
[2261]118            if(!(this->isActive(player)))  //!< If the hint is already active, activation is pointless.
[2093]119            {
[3280]120                this->playerStatus_[player] = QuestHintStatus::Active;
[2662]121               
122                this->getDescription()->sendAddHintNotification();
[2093]123                return true;
124            }
125            else
126            {
[2068]127                COUT(2) << "An already active questHint was trying to get activated." << std::endl;
128                return false;
[2093]129            }
[1992]130        }
[2261]131       
[2093]132        COUT(2) << "A hint of a non-active quest was trying to get activated." << std::endl;
133        return false;
[1992]134    }
135
[2021]136    /**
137    @brief
[2261]138        Sets the Quest the QuestHint belongs to.
[2021]139    @param quest
[2261]140        The Quest to be set as Quest the QuestHint is attached to.
[2021]141    @return
[2261]142        Returns true if successful.
[2021]143    */
[2068]144    bool QuestHint::setQuest(Quest* quest)
[1992]145    {
[2261]146        if(quest == NULL) //!< NULL-Pointer. Again..?
[2068]147        {
148            COUT(2) << "The input Quest* is NULL." << std::endl;
149            return false;
150        }
[2092]151
[1992]152        this->quest_ = quest;
[2068]153        return true;
[1992]154    }
155
156}
Note: See TracBrowser for help on using the repository browser.