Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/ipv6/src/modules/questsystem/QuestHint.cc @ 7300

Last change on this file since 7300 was 7163, checked in by dafrick, 14 years ago

Merged presentation3 branch into trunk.

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