Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/modules/questsystem/QuestHint.cc @ 7462

Last change on this file since 7462 was 7456, checked in by dafrick, 14 years ago

Reviewing documentation fo Questsystem, moving documentation fully into doxygen.
Added some files to modules they belong to.

  • Property svn:eol-style set to native
File size: 4.3 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 */
[6417]28
[2261]29/**
[7456]30    @file QuestHint.cc
[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"
[7456]38
39#include "Quest.h"
40#include "QuestDescription.h"
[2261]41#include "QuestManager.h"
[1992]42
[2662]43namespace orxonox
44{
[1992]45    CreateFactory(QuestHint);
46
[2068]47    /**
48    @brief
[2261]49        Constructor. Registers the object.
[2068]50    */
[2092]51    QuestHint::QuestHint(BaseObject* creator) : QuestItem(creator)
[2021]52    {
[2092]53        RegisterObject(QuestHint);
[2021]54    }
[2092]55
[1992]56    /**
57    @brief
58        Destructor.
59    */
60    QuestHint::~QuestHint()
61    {
[7163]62        if(this->isRegistered())
63            QuestManager::getInstance().unregisterHint(this);
[1992]64    }
[2092]65
[2261]66    /**
67    @brief
68        Method for creating a QuestHint object through XML.
69    */
[2068]70    void QuestHint::XMLPort(Element& xmlelement, XMLPort::Mode mode)
71    {
[2093]72        SUPER(QuestHint, XMLPort, xmlelement, mode);
[2092]73
[7456]74        QuestManager::getInstance().registerHint(this); // Registers the QuestHint with the QuestManager.
[6417]75
[7163]76        COUT(4) << "New QuestHint {" << this->getId() << "} created." << std::endl;
[2068]77    }
78
[2092]79
[1996]80    /**
81    @brief
[2261]82        Checks whether the QuestHint is active for a specific player.
[1996]83    @param player
84        The player.
[2068]85    @throws
86        Throws an Argument Exception if the input Player-pointer is NULL.
[1996]87    @return
[2261]88        Returns true if the QuestHint is active for the specified player.
[1996]89    */
[2261]90    bool QuestHint::isActive(const PlayerInfo* player) const
[1992]91    {
[7456]92        //TODO: Replace with asser.
93        if(player == NULL) // NULL-Pointers are ugly!
[2068]94        {
[2261]95            ThrowException(Argument, "The input PlayerInfo* is NULL.");
[2068]96            return false;
97        }
[2092]98
[7456]99        // Find the player.
[3280]100        std::map<const PlayerInfo*, QuestHintStatus::Value>::const_iterator it = this->playerStatus_.find(player);
[7456]101        if (it != this->playerStatus_.end()) // If the player is in the map.
[2093]102            return it->second;
[6417]103
[3280]104        return QuestStatus::Inactive;
[1992]105    }
[2092]106
[2021]107    /**
108    @brief
[2068]109        Activates a QuestHint for a given player.
[2021]110    @param player
[2068]111        The player.
[2021]112    @return
[2068]113        Returns true if the activation was successful, false if there were problems.
[2021]114    */
[2261]115    bool QuestHint::setActive(PlayerInfo* player)
[1992]116    {
[7456]117        if(this->quest_->isActive(player)) // For a hint to get activated the quest must be active.
[1992]118        {
[7456]119            if(!(this->isActive(player)))  // If the hint is already active, activation is pointless.
[2093]120            {
[3280]121                this->playerStatus_[player] = QuestHintStatus::Active;
[6417]122
[7403]123                this->getDescription()->sendAddHintNotification(player);
[2093]124                return true;
125            }
126            else
127            {
[7163]128                COUT(4) << "An already active questHint was trying to get activated." << std::endl;
[2068]129                return false;
[2093]130            }
[1992]131        }
[6417]132
[7163]133        COUT(4) << "A hint of a non-active quest was trying to get activated." << std::endl;
[2093]134        return false;
[1992]135    }
136
[2021]137    /**
138    @brief
[2261]139        Sets the Quest the QuestHint belongs to.
[2021]140    @param quest
[2261]141        The Quest to be set as Quest the QuestHint is attached to.
[2021]142    @return
[2261]143        Returns true if successful.
[2021]144    */
[2068]145    bool QuestHint::setQuest(Quest* quest)
[1992]146    {
[7456]147        //TODO: Replace with assert.
148        if(quest == NULL) // NULL-Pointer. Again..?
[2068]149        {
150            COUT(2) << "The input Quest* is NULL." << std::endl;
151            return false;
152        }
[2092]153
[1992]154        this->quest_ = quest;
[2068]155        return true;
[1992]156    }
157
158}
Note: See TracBrowser for help on using the repository browser.