Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 2092 was 2092, checked in by landauf, 16 years ago
  • adopted quest classes to the new hierarchy (with a creator pointer)
  • added "RegisterObject(…)" in all constructors and "virtual" to all destructors
  • Property svn:eol-style set to native
File size: 3.4 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#include "core/CoreIncludes.h"
30#include "util/Exception.h"
31
32#include "Quest.h"
33#include "QuestHint.h"
34
35namespace orxonox {
36
37    CreateFactory(QuestHint);
38
39    /**
40    @brief
41        Constructor.
42    */
43    QuestHint::QuestHint(BaseObject* creator) : QuestItem(creator)
44    {
45        RegisterObject(QuestHint);
46
47        this->initialize();
48    }
49
50    /**
51    @brief
52        Destructor.
53    */
54    QuestHint::~QuestHint()
55    {
56
57    }
58
59    void QuestHint::initialize(void)
60    {
61        RegisterObject(QuestHint);
62    }
63
64    void QuestHint::XMLPort(Element& xmlelement, XMLPort::Mode mode)
65    {
66        SUPER(QuestHint, XMLPort, xmlelement, mode);
67
68        COUT(3) << "New QuestHint {" << this->getId() << "} created." << std::endl;
69    }
70
71
72    /**
73    @brief
74        Checks whether the hint is active for a specific player.
75    @param player
76        The player.
77    @throws
78        Throws an Argument Exception if the input Player-pointer is NULL.
79    @return
80        Returns true if the hint is active for the specified player.
81    */
82    bool QuestHint::isActive(Player* player)
83    {
84        if(player == NULL)
85        {
86            ThrowException(Argument, "The input Player* is NULL.");
87            return false;
88        }
89
90        std::map<Player*, questHintStatus::Enum>::iterator it = this->playerStatus_.find(player);
91        if (it != this->playerStatus_.end())
92        {
93            return it->second;
94        }
95        return questStatus::inactive;
96    }
97
98    /**
99    @brief
100        Activates a QuestHint for a given player.
101    @param player
102        The player.
103    @return
104        Returns true if the activation was successful, false if there were problems.
105    */
106    bool QuestHint::activate(Player* player)
107    {
108        if(this->quest_->isActive(player))
109        {
110            if(!(this->isActive(player)))
111            {
112                this->playerStatus_[player] = questHintStatus::active;
113                return true;
114            }
115            else
116            {
117                COUT(2) << "An already active questHint was trying to get activated." << std::endl;
118                return false;
119            }
120        }
121        COUT(2) << "A hint of a non-active quest was trying to get activated." << std::endl;
122        return false;
123    }
124
125    /**
126    @brief
127        Sets the quest the QuestHitn belongs to.
128    @param quest
129    @return
130    */
131    bool QuestHint::setQuest(Quest* quest)
132    {
133        if(quest == NULL)
134        {
135            COUT(2) << "The input Quest* is NULL." << std::endl;
136            return false;
137        }
138
139        this->quest_ = quest;
140        return true;
141    }
142
143}
Note: See TracBrowser for help on using the repository browser.