Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/questsystem/src/orxonox/objects/QuestHint.cc @ 2076

Last change on this file since 2076 was 2076, checked in by dafrick, 16 years ago

Completed XMLPort for all objects.

File size: 3.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#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() : QuestItem()
44    {
45        this->initialize();
46    }
47   
48    /**
49    @brief
50        Destructor.
51    */
52    QuestHint::~QuestHint()
53    {
54       
55    }
56   
57    void QuestHint::initialize(void)
58    {
59        RegisterObject(QuestHint);
60    }
61   
62    void QuestHint::XMLPort(Element& xmlelement, XMLPort::Mode mode)
63    {
64        SUPER(QuestHint, XMLPort, xmlelement, mode);
65       
66        COUT(1) << "New QuestHint {" << this->getId() << "} created." << std::endl;
67    }
68
69   
70    /**
71    @brief
72        Checks whether the hint is active for a specific player.
73    @param player
74        The player.
75    @throws
76        Throws an Argument Exception if the input Player-pointer is NULL.
77    @return
78        Returns true if the hint is active for the specified player.
79    */
80    bool QuestHint::isActive(Player* player)
81    {
82        if(player == NULL)
83        {
84            ThrowException(Argument, "The input Player* is NULL.");
85            return false;
86        }
87       
88        std::map<Player*, questHintStatus::Enum>::iterator it = this->playerStatus_.find(player);
89        if (it != this->playerStatus_.end())
90        {
91            return it->second;
92        }
93        return questStatus::inactive;
94    }
95   
96    /**
97    @brief
98        Activates a QuestHint for a given player.
99    @param player
100        The player.
101    @return
102        Returns true if the activation was successful, false if there were problems.
103    */
104    bool QuestHint::activate(Player* player)
105    {
106        if(this->quest_->isActive(player))
107        {
108            if(!(this->isActive(player)))
109            {
110                this->playerStatus_[player] = questHintStatus::active;
111                return true;
112            }
113            else
114            {
115                COUT(2) << "An already active questHint was trying to get activated." << std::endl;
116                return false;
117            }
118        }
119        COUT(2) << "A hint of a non-active quest was trying to get activated." << std::endl;
120        return false;
121    }
122
123    /**
124    @brief
125        Sets the quest the QuestHitn belongs to.
126    @param quest
127    @return
128    */
129    bool QuestHint::setQuest(Quest* quest)
130    {
131        if(quest == NULL)
132        {
133            COUT(2) << "The input Quest* is NULL." << std::endl;
134            return false;
135        }
136       
137        this->quest_ = quest;
138        return true;
139    }
140
141}
Note: See TracBrowser for help on using the repository browser.