Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/archive/tutorialHS09/src/modules/questsystem/QuestHint.cc @ 10256

Last change on this file since 10256 was 5738, checked in by landauf, 15 years ago

merged libraries2 back to trunk

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