Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

Started implementation of QuestEffectBeacon.
Done some documentation of QuestItem and subclasses.

File size: 4.2 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. Initializes the object.
51    */
52    QuestHint::QuestHint(BaseObject* creator) : QuestItem(creator)
53    {
54        this->initialize();
55    }
56   
57    /**
58    @brief
59        Initialize the object.
60    */
61    void QuestHint::initialize(void)
62    {
63        RegisterObject(QuestHint);
64    }
65
66    /**
67    @brief
68        Destructor.
69    */
70    QuestHint::~QuestHint()
71    {
72
73    }
74
75    /**
76    @brief
77        Method for creating a QuestHint object through XML.
78    */
79    void QuestHint::XMLPort(Element& xmlelement, XMLPort::Mode mode)
80    {
81        SUPER(QuestHint, XMLPort, xmlelement, mode);
82
83        COUT(3) << "New QuestHint {" << this->getId() << "} created." << std::endl;
84    }
85
86
87    /**
88    @brief
89        Checks whether the hint is active for a specific player.
90    @param player
91        The player.
92    @throws
93        Throws an Argument Exception if the input Player-pointer is NULL.
94    @return
95        Returns true if the hint is active for the specified player.
96    */
97    bool QuestHint::isActive(ControllableEntity* player)
98    {
99        if(player == NULL) //!< NULL-Pointers are ugly!
100        {
101            ThrowException(Argument, "The input ControllableEntity* is NULL.");
102            return false;
103        }
104
105        //! Find the player.
106        std::map<ControllableEntity*, questHintStatus::Enum>::iterator it = this->playerStatus_.find(player);
107        if (it != this->playerStatus_.end()) //!< If the player is in the map.
108        {
109            return it->second;
110        }
111       
112        return questStatus::inactive;
113    }
114
115    /**
116    @brief
117        Activates a QuestHint for a given player.
118    @param player
119        The player.
120    @return
121        Returns true if the activation was successful, false if there were problems.
122    */
123    bool QuestHint::setActive(ControllableEntity* player)
124    {
125        if(this->quest_->isActive(player)) //!< For a hint to get activated the quest must be active.
126        {
127            if(!(this->isActive(player)))  //!< If the hint is already active, activation is pointless.
128            {
129                this->playerStatus_[player] = questHintStatus::active;
130                return true;
131            }
132            else
133            {
134                COUT(2) << "An already active questHint was trying to get activated." << std::endl;
135                return false;
136            }
137        }
138       
139        COUT(2) << "A hint of a non-active quest was trying to get activated." << std::endl;
140        return false;
141    }
142
143    /**
144    @brief
145        Sets the quest the QuestHitn belongs to.
146    @param quest
147        The quest to be set as quest the hint is attached to.
148    @return
149        Returns true if successful.
150    */
151    bool QuestHint::setQuest(Quest* quest)
152    {
153        if(quest == NULL) //!< NULL-Pointer. Again..?
154        {
155            COUT(2) << "The input Quest* is NULL." << std::endl;
156            return false;
157        }
158
159        this->quest_ = quest;
160        return true;
161    }
162
163}
Note: See TracBrowser for help on using the repository browser.