Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/questsystem3/src/orxonox/objects/quest/QuestHint.cc @ 2349

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