Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 3132 was 3110, checked in by rgrieder, 15 years ago

Removed old msvc specific support for precompiled header files.

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