Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/presentation3/src/modules/questsystem/Quest.h @ 6943

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

Resolved issue with the Questsystem causing a segfault when a level with Quests was loaded twice. The issue still persists, but not with the Questsystem anymore and it will be addressed with my next commit.
Also removed restrictions to the number of characters a quest/hint identifier must have.

  • Property svn:eol-style set to native
File size: 7.0 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 Definition of the Quest class.
32        The Quest is the parent class of LocalQuest and GlobalQuest.
33*/
34
35#ifndef _Quest_H__
36#define _Quest_H__
37
38#include "questsystem/QuestsystemPrereqs.h"
39
40#include <list>
41#include "QuestItem.h"
42
43namespace orxonox
44{
45    namespace QuestStatus
46    {
47        //!Different states of a Quest.
48        enum Value
49        {
50            Inactive,
51            Active,
52            Failed,
53            Completed
54        };
55    }
56
57    /**
58    @brief
59        Represents a Quest in the game.
60        A Quest has a list of subquests and a parentquest (if it is not a rootquest).
61        Each Quest exists only once but it has a different status (inactive, active, failed or completed) for each player.
62        A Quest has several hints (QuestHint) that can be unlocked through QuestEffects and then display aid in solving the Quest.
63        A Quest has a list of QuestEffects that are invoked when the quest is failed and also a list of QuestEffects that are invoked, when the Quest is completed.
64
65        Quest itself should not be instantiated, if you want to create a quest either go for LocalQuest or GlobalQuest, whichever suits you needs better.
66    @author
67        Damian 'Mozork' Frick
68    */
69    class _QuestsystemExport Quest : public QuestItem
70    {
71        public:
72            Quest(BaseObject* creator);
73            virtual ~Quest();
74
75            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); //!< Method for creating a Quest object through XML.
76
77            /**
78            @brief Returns the parentquest of the Quest.
79            @return Returns a pointer to the parentquest of the Quest.
80            */
81            inline Quest* getParentQuest(void) const
82                { return this->parentQuest_; }
83
84            /**
85            @brief Returns the list of subquests.
86            @return Returns a reference to the list of subquests of the quest.
87            */
88            inline const std::list<Quest*> & getSubQuestList(void) const
89                { return this->subQuests_; }
90
91            /**
92            @brief Returns the list of all QuestHints of this Quest.
93            @return Returns a reference to the list of QuestHints of the Quest.
94            */
95            inline const std::list<QuestHint*> & getHintsList(void) const
96                { return this->hints_; }
97
98            bool isInactive(const PlayerInfo* player) const; //!< Returns true if the quest status for the specific player is 'inactive'.
99            bool isActive(const PlayerInfo* player) const; //!< Returns true if the quest status for the specific player is 'active'.
100            bool isFailed(const PlayerInfo* player) const; //!< Returns true if the quest status for the specific player is 'failed'.
101            bool isCompleted(const PlayerInfo* player) const; //!< Returns true if the quest status for the specific player is 'completed'.
102
103            bool start(PlayerInfo* player); //!< Sets a Quest to active.
104            virtual bool fail(PlayerInfo* player); //!< Fails the Quest.
105            virtual bool complete(PlayerInfo* player); //!< Completes the Quest.
106           
107            bool addListener(QuestListener* listener); //!< Adds a QuestListener to the list of QuestListeners listening to this Quest.
108
109        protected:
110            virtual bool isStartable(const PlayerInfo* player) const = 0; //!< Checks whether the Quest can be started.
111            virtual bool isFailable(const PlayerInfo* player) const = 0; //!< Checks whether the Quest can be failed.
112            virtual bool isCompletable(const PlayerInfo* player) const = 0; //!< Checks whether the Quest can be completed.
113
114            const Quest* getSubQuest(unsigned int index) const; //!<Returns the subquest at the given index.
115            const QuestHint* getHint(unsigned int index) const; //!< Returns the QuestHint at the given index.
116            const QuestEffect* getFailEffect(unsigned int index) const; //!< Returns the fail QuestEffect at the given index.
117            const QuestEffect* getCompleteEffect(unsigned int index) const; //!< Returns the complete QuestEffect at the given index.
118
119            /**
120            @brief Returns the list of fail QuestEffects.
121            @return Returns a reference to the list of fail QuestEffects.
122            */
123            inline std::list<QuestEffect*> & getFailEffectList(void)
124                { return this->failEffects_; }
125
126            /**
127            @brief Returns the list of complete QuestEffects.
128            @return Returns a reference to the list of complete QuestEffects.
129            */
130            inline std::list<QuestEffect*> & getCompleteEffectList(void)
131                { return this->completeEffects_; }
132
133            virtual QuestStatus::Value getStatus(const PlayerInfo* player) const = 0; //!< Returns the status of the Quest for a specific player.
134            virtual bool setStatus(PlayerInfo* player, const QuestStatus::Value & status) = 0; //!< Changes the status for a specific player.
135
136        private:
137            Quest* parentQuest_; //!< Pointer to the parentquest.
138            std::list<Quest*> subQuests_; //!< List of all the subquests.
139
140            std::list<QuestHint*> hints_; //!< A list of all the QuestHints tied to this Quest.
141
142            std::list<QuestEffect*> failEffects_; //!< A list of all QuestEffects to be invoked, when the Quest has been failed.
143            std::list<QuestEffect*> completeEffects_; //!< A list of QuestEffects to be invoked, when the Quest has been completed.
144
145            std::list<QuestListener*> listeners_; //!< A list of QuestListeners, that listen to what exactly happens with this Quest.
146
147            bool setParentQuest(Quest* quest); //!< Sets the parentquest of the Quest.
148            bool addSubQuest(Quest* quest); //!< Adds a subquest to the Quest.
149            bool addHint(QuestHint* hint); //!< Add a QuestHint to the list of QuestHints.
150            bool addFailEffect(QuestEffect* effect); //!< Adds an QuestEffect to the list of fail QuestEffects.
151            bool addCompleteEffect(QuestEffect* effect); //!< Adds an QuestEffect to the list of complete QuestEffects.
152
153    };
154
155}
156
157#endif /* _Quest_H__ */
Note: See TracBrowser for help on using the repository browser.