Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/ggz2/src/modules/questsystem/AddQuestHint.cc @ 6554

Last change on this file since 6554 was 5738, checked in by landauf, 15 years ago

merged libraries2 back to trunk

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