Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 3014 was 2911, checked in by landauf, 16 years ago

Merged r1-2096 of questsystem5 back to trunk

I hope there weren't more "hidden merge changes" in r2909 than the one in OverlayGroup (removeElement) (and related to this the adjustments in NotificationQueue).

The corresponding media commit seems not yet to be done, but it doesn't break the build.

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