Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/questsystem2/src/orxonox/objects/quest/AddQuestHint.cc @ 2191

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

Just changed some small stuff…

File size: 3.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 AddQuestHint.cc
31    @brief
32        Implementation of the AddQuestHint class.
33*/
34
35#include "OrxonoxStableHeaders.h"
36#include "AddQuestHint.h"
37
38#include "core/CoreIncludes.h"
39#include "util/Exception.h"
40
41#include "orxonox/objects/worldentities/ControllableEntity.h"
42#include "QuestManager.h"
43#include "QuestItem.h"
44#include "QuestHint.h"
45
46namespace orxonox {
47
48    CreateFactory(AddQuestHint);
49
50    /**
51    @brief
52        Constructor. Registers the object.
53    */
54    AddQuestHint::AddQuestHint(BaseObject* creator) : QuestEffect(creator)
55    {
56        RegisterObject(AddQuestHint);
57    }
58
59    /**
60    @brief
61        Destructor.
62    */
63    AddQuestHint::~AddQuestHint()
64    {
65    }
66
67    /**
68    @brief
69        Method for creating a AddQuestHint object through XML.
70    */
71    void AddQuestHint::XMLPort(Element& xmlelement, XMLPort::Mode mode)
72    {
73        SUPER(AddQuestHint, XMLPort, xmlelement, mode);
74
75        XMLPortParam(AddQuestHint, "hintId", setHintId, getHintId, xmlelement, mode);
76
77    }
78
79    /**
80    @brief
81        Sets the id of the QuestHint to be added to the player the QuestEffect is invoked on.
82    @param id
83        The QuestHint id.
84    @param
85        Returns true if successful.
86    */
87    bool AddQuestHint::setHintId(const std::string & id)
88    {
89        if(!QuestItem::isId(id))
90        {
91            COUT(2) << "Invalid id. QuestItem id {" << id << "} could not be set." << std::endl;
92            return false;
93        }
94       
95        this->hintId_ = id;
96        return true;
97    }
98
99    /**
100    @brief
101        Invokes the QuestEffect.
102    @param player
103        The player.
104    @return
105        Returns true if the QuestEffect was successfully invoked.
106    */
107    bool AddQuestHint::invoke(ControllableEntity* player)
108    {
109        if(player == NULL) //!< NULL-pointers are evil!
110        {
111            COUT(2) << "The input player is NULL." << std::endl;
112            return false;
113        }
114
115        try
116        {
117            QuestHint* hint = QuestManager::findHint(this->hintId_);
118            if(!hint->setActive(player))
119            {
120                return false;
121            }
122        }
123        catch(const Exception& e)
124        {
125           COUT(2) << e.getFullDescription() << std::endl;
126           return false;
127        }
128
129        return true;
130
131    }
132}
Note: See TracBrowser for help on using the repository browser.