Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/pch/src/orxonox/objects/quest/QuestHint.cc @ 3177

Last change on this file since 3177 was 3158, checked in by rgrieder, 16 years ago

Removed the filename part of all @file foo.cc because Doxygen chooses the (always correct) filename automatically.
Also removed a few <string> includes that are not necessary.

  • 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
38#include "orxonox/objects/infos/PlayerInfo.h"
39#include "QuestManager.h"
40#include "QuestDescription.h"
41#include "Quest.h"
42
43namespace orxonox
44{
45    CreateFactory(QuestHint);
46
47    /**
48    @brief
49        Constructor. Registers the object.
50    */
51    QuestHint::QuestHint(BaseObject* creator) : QuestItem(creator)
52    {
53        RegisterObject(QuestHint);
54    }
55
56    /**
57    @brief
58        Destructor.
59    */
60    QuestHint::~QuestHint()
61    {
62
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(3) << "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::Enum>::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(2) << "An already active questHint was trying to get activated." << std::endl;
129                return false;
130            }
131        }
132       
133        COUT(2) << "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.