Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/mac_osx2/src/modules/questsystem/QuestHint.cc @ 10415

Last change on this file since 10415 was 7552, checked in by dafrick, 14 years ago

Resolving some TODOs and doing some additional cleanup. Almost done now…

  • Property svn:eol-style set to native
File size: 4.0 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    @return
86        Returns true if the QuestHint is active for the specified player.
87    */
88    bool QuestHint::isActive(const PlayerInfo* player) const
89    {
90        if(player == NULL) // If the player is NULL, the Quest obviously can't be active.
91            return false;
92
93        // Find the player.
94        std::map<const PlayerInfo*, QuestHintStatus::Value>::const_iterator it = this->playerStatus_.find(player);
95        if (it != this->playerStatus_.end()) // If the player is in the map.
96            return it->second;
97
98        return QuestStatus::Inactive;
99    }
100
101    /**
102    @brief
103        Activates a QuestHint for a given player.
104    @param player
105        The player.
106    @return
107        Returns true if the activation was successful, false if there were problems.
108    */
109    bool QuestHint::setActive(PlayerInfo* player)
110    {
111        if(this->quest_->isActive(player)) // For a hint to get activated the quest must be active.
112        {
113            if(!(this->isActive(player)))  // If the hint is already active, activation is pointless.
114            {
115                this->playerStatus_[player] = QuestHintStatus::Active;
116
117                this->getDescription()->sendAddHintNotification(player);
118                return true;
119            }
120            else
121            {
122                COUT(4) << "An already active questHint was trying to get activated." << std::endl;
123                return false;
124            }
125        }
126
127        COUT(4) << "A hint of a non-active quest was trying to get activated." << std::endl;
128        return false;
129    }
130
131    /**
132    @brief
133        Sets the Quest the QuestHint belongs to.
134    @param quest
135        The Quest to be set as Quest the QuestHint is attached to.
136    @return
137        Returns true if successful.
138    */
139    bool QuestHint::setQuest(Quest* quest)
140    {
141        assert(quest);
142
143        this->quest_ = quest;
144        return true;
145    }
146
147}
Note: See TracBrowser for help on using the repository browser.