Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/questsystem2/src/orxonox/objects/quest/QuestHint.cc @ 2159

Last change on this file since 2159 was 2159, checked in by dafrick, 15 years ago

Completed documentation of finished classes.

File size: 4.1 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
32        Implementation of the QuestHint class.
33*/
34
35#include "OrxonoxStableHeaders.h"
36#include "QuestHint.h"
37
38#include "core/CoreIncludes.h"
39#include "util/Exception.h"
40
41#include "orxonox/objects/worldentities/ControllableEntity.h"
42#include "Quest.h"
43
44namespace orxonox {
45
46    CreateFactory(QuestHint);
47
48    /**
49    @brief
50        Constructor. Registers the object.
51    */
52    QuestHint::QuestHint(BaseObject* creator) : QuestItem(creator)
53    {
54        RegisterObject(QuestHint);
55    }
56
57    /**
58    @brief
59        Destructor.
60    */
61    QuestHint::~QuestHint()
62    {
63
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        COUT(3) << "New QuestHint {" << this->getId() << "} created." << std::endl;
75    }
76
77
78    /**
79    @brief
80        Checks whether the hint is active for a specific player.
81    @param player
82        The player.
83    @throws
84        Throws an Argument Exception if the input Player-pointer is NULL.
85    @return
86        Returns true if the hint is active for the specified player.
87    */
88    bool QuestHint::isActive(ControllableEntity* player)
89    {
90        if(player == NULL) //!< NULL-Pointers are ugly!
91        {
92            ThrowException(Argument, "The input ControllableEntity* is NULL.");
93            return false;
94        }
95
96        //! Find the player.
97        std::map<ControllableEntity*, questHintStatus::Enum>::iterator it = this->playerStatus_.find(player);
98        if (it != this->playerStatus_.end()) //!< If the player is in the map.
99        {
100            return it->second;
101        }
102       
103        return questStatus::inactive;
104    }
105
106    /**
107    @brief
108        Activates a QuestHint for a given player.
109    @param player
110        The player.
111    @return
112        Returns true if the activation was successful, false if there were problems.
113    */
114    bool QuestHint::setActive(ControllableEntity* player)
115    {
116        if(this->quest_->isActive(player)) //!< For a hint to get activated the quest must be active.
117        {
118            if(!(this->isActive(player)))  //!< If the hint is already active, activation is pointless.
119            {
120                this->playerStatus_[player] = questHintStatus::active;
121                return true;
122            }
123            else
124            {
125                COUT(2) << "An already active questHint was trying to get activated." << std::endl;
126                return false;
127            }
128        }
129       
130        COUT(2) << "A hint of a non-active quest was trying to get activated." << std::endl;
131        return false;
132    }
133
134    /**
135    @brief
136        Sets the quest the QuestHitn belongs to.
137    @param quest
138        The quest to be set as quest the hint is attached to.
139    @return
140        Returns true if successful.
141    */
142    bool QuestHint::setQuest(Quest* quest)
143    {
144        if(quest == NULL) //!< NULL-Pointer. Again..?
145        {
146            COUT(2) << "The input Quest* is NULL." << std::endl;
147            return false;
148        }
149
150        this->quest_ = quest;
151        return true;
152    }
153
154}
Note: See TracBrowser for help on using the repository browser.