Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/presentation3/src/modules/questsystem/QuestHint.cc @ 7110

Last change on this file since 7110 was 6945, checked in by dafrick, 15 years ago

A lot of cleanup, mostly increasing output levels, which means, that the console is no longer cluttered by lots and lots of Quest-stuff (the log file still is, but that should be ok…).
Also some possible bugs (or let's say pitfalls) removed, which have been around for a long time and didn't cause any problems so far. Now they never will.
Also, regarding my previous commit. Quests seem tu work just fine, even the second time the level is loaded, which is awesome.

Ergo: Questsystem/Notificationsystem segfault upon loading a level with Quests/Notifications in it twice is now officially resolved.

  • 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/**
[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    {
[6940]61        if(this->isRegistered())
62            QuestManager::getInstance().unregisterHint(this);
[1992]63    }
[2092]64
[2261]65    /**
66    @brief
67        Method for creating a QuestHint object through XML.
68    */
[2068]69    void QuestHint::XMLPort(Element& xmlelement, XMLPort::Mode mode)
70    {
[2093]71        SUPER(QuestHint, XMLPort, xmlelement, mode);
[2092]72
[2911]73        QuestManager::getInstance().registerHint(this); //!< Registers the QuestHint with the QuestManager.
[6417]74
[6945]75        COUT(4) << "New QuestHint {" << this->getId() << "} created." << std::endl;
[2068]76    }
77
[2092]78
[1996]79    /**
80    @brief
[2261]81        Checks whether the QuestHint is active for a specific player.
[1996]82    @param player
83        The player.
[2068]84    @throws
85        Throws an Argument Exception if the input Player-pointer is NULL.
[1996]86    @return
[2261]87        Returns true if the QuestHint is active for the specified player.
[1996]88    */
[2261]89    bool QuestHint::isActive(const PlayerInfo* player) const
[1992]90    {
[2261]91        if(player == NULL) //!< NULL-Pointers are ugly!
[2068]92        {
[2261]93            ThrowException(Argument, "The input PlayerInfo* is NULL.");
[2068]94            return false;
95        }
[2092]96
[2261]97        //! Find the player.
[3280]98        std::map<const PlayerInfo*, QuestHintStatus::Value>::const_iterator it = this->playerStatus_.find(player);
[2261]99        if (it != this->playerStatus_.end()) //!< If the player is in the map.
[2093]100        {
101            return it->second;
102        }
[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    {
[2261]117        if(this->quest_->isActive(player)) //!< For a hint to get activated the quest must be active.
[1992]118        {
[2261]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
[2662]123                this->getDescription()->sendAddHintNotification();
[2093]124                return true;
125            }
126            else
127            {
[6945]128                COUT(4) << "An already active questHint was trying to get activated." << std::endl;
[2068]129                return false;
[2093]130            }
[1992]131        }
[6417]132
[6945]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    {
[2261]147        if(quest == NULL) //!< NULL-Pointer. Again..?
[2068]148        {
149            COUT(2) << "The input Quest* is NULL." << std::endl;
150            return false;
151        }
[2092]152
[1992]153        this->quest_ = quest;
[2068]154        return true;
[1992]155    }
156
157}
Note: See TracBrowser for help on using the repository browser.