Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/mac_osx/src/modules/questsystem/QuestHint.cc @ 8748

Last change on this file since 8748 was 7456, checked in by dafrick, 14 years ago

Reviewing documentation fo Questsystem, moving documentation fully into doxygen.
Added some files to modules they belong to.

  • 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 "core/XMLPort.h"
38
39#include "Quest.h"
40#include "QuestDescription.h"
41#include "QuestManager.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        if(this->isRegistered())
63            QuestManager::getInstance().unregisterHint(this);
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(4) << "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        //TODO: Replace with asser.
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::Value>::const_iterator it = this->playerStatus_.find(player);
101        if (it != this->playerStatus_.end()) // If the player is in the map.
102            return it->second;
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(player);
124                return true;
125            }
126            else
127            {
128                COUT(4) << "An already active questHint was trying to get activated." << std::endl;
129                return false;
130            }
131        }
132
133        COUT(4) << "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        //TODO: Replace with assert.
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.