Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/modules/questsystem/QuestListener.h @ 11071

Last change on this file since 11071 was 11071, checked in by landauf, 8 years ago

merged branch cpp11_v3 back to trunk

  • Property svn:eol-style set to native
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 QuestListener.h
31    @brief Definition of the QuestListener class.
32    @ingroup Questsystem
33*/
34
35#ifndef _QuestListener_H__
36#define _QuestListener_H__
37
38#include "questsystem/QuestsystemPrereqs.h"
39
40#include <string>
41#include <list>
42#include "core/BaseObject.h"
43
44namespace orxonox
45{
46    /**
47    @brief
48        The mode of the @ref orxonox::QuestListener "QuestListener".
49
50    @ingroup Questsystem
51    */
52    enum class QuestListenerMode
53    {
54        All, //!< Listens to all events.
55        Start, //!< Only listens to events pertaining the starting of @ref orxonox::Quest "Quests".
56        Fail, //!< Only listens to events pertaining the failing of @ref orxonox::Quest "Quests".
57        Complete //!< Only listens to events pertaining the completing of @ref orxonox::Quest "Quests".
58    };
59
60    /**
61    @brief
62        Provides a way to react to the starting, completing and failing of @ref orxonox::Quest "Quests".
63
64        The XML representation goes as follows:
65        @code
66        <BaseObject> // The object that should react to the status change of a Quest.
67            <events>
68                <function> // Where function is the method of the object that should be executed. Normally this would be visibility or activity.
69                    <QuestListener questId="someQuestId" mode="someMode" /> // Where someQuestId is the identifier for the Quest the QuestListener is reacting to, and someMode is the kind of status change the QUestListener reacts to (all, start, complete or fail).
70                </function>
71            </events>
72        </BaseObject>
73        @endcode
74
75        You can use the QuestListener as if it were a @ref orxonox::Trigger "Trigger" or @ref orxonox::EventListener "EventListener", that fires an Event when the status (depending on the set mode) of the given @ref orxonox::Quest "Quest" changes.
76
77    @author
78        Damian 'Mozork' Frick
79
80    @ingroup Questsystem
81    */
82    class _QuestsystemExport QuestListener : public BaseObject
83    {
84
85        public:
86            QuestListener(Context* context);
87            virtual ~QuestListener();
88
89            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode) override; //!< Method for creating a QuestListener object through XML.
90
91            static void advertiseStatusChange(std::list<QuestListener*> & listeners, const std::string & status); //!< Makes all QuestListener in the list aware that a certain status change has occured.
92
93            bool setQuestId(const std::string & id); //!< Sets the questId of the Quest the QuestListener reacts to.
94            bool setMode(const std::string & mode); //!< Sets the mode of the QuestListener.
95
96            std::string getMode(void); //!< Get the mode of the QuestListener.
97
98            const std::string & getQuestId(void);
99            bool execute(void); //!< Executes the QuestListener, resp. fires an Event.
100
101        private:
102            QuestListenerMode mode_; //!< The mode of the QuestListener.
103            Quest* quest_; //!< A pointer to the Quest the QuestListener is reacting to.
104
105            //! Static variables for the modes as strings.
106            static const std::string ALL;
107            static const std::string START;
108            static const std::string FAIL;
109            static const std::string COMPLETE;
110
111    };
112
113}
114
115#endif /* _QuestListener_H__ */
Note: See TracBrowser for help on using the repository browser.