Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/questsystem/src/orxonox/objects/Quest.cc @ 1996

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

Some cleaning, reorganization and implementation of some small methods.

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#include "core/CoreIncludes.h"
30#include "Quest.h"
31
32namespace orxonox {
33
34    CreateFactory(Quest);
35
36    /**
37    @brief
38        Constructor. Creates a quest with a given id, title and description.
39    @param id
40        The unique identifier of the quest.
41    @param title
42        The title of the quest.
43    @param description
44        The description of the quest.
45    */
46    Quest::Quest(std::string id, std::string title = "", std::string description = "") : QuestItem(id, title, description)
47    {
48        initialize();
49    }
50   
51    /**
52    @brief
53        Destructor.
54    */
55    Quest::~Quest()
56    {
57        //TDO: Unload lists...
58    }
59   
60    /**
61    @brief
62        Initializes the object. Needs to be called first in every constructor of this class.
63    */
64    void Quest::initialize(void)
65    {
66        RegisterObject(Quest);
67       
68        this->parentQuest_ = 0;
69    }
70
71    /**
72    @brief
73        Sets the parent quest of the quest.
74    @param quest
75        A pointer to the quest to be set as parent quest.
76    */
77    bool setParentQuest(Quest* quest)
78    {
79        this->parentQuest_ = quest;
80        return true;
81    }
82   
83    /**
84    @brief
85        Adds a sub quest to the quest.
86    @param quest
87        A pointer to the quest to be set as sub quest.
88    */
89    bool addSubQuest(Quest & quest)
90    {
91        this->subQuests_.push_back = quest;
92        return true;
93    }
94
95    /**
96    @brief
97        Adds a Hint to the list of hints
98    @param hint
99        The hint that should be added to the list of hints.
100    */
101    void Quest::addHint(QuestHint & hint)
102    {
103        if ( hint != NULL )
104        {
105            this->hints_.push_back(hint);
106            hint.setQuest(this);
107        }
108        else
109        {
110            COUT(2) << "A NULL-QuestHint was trying to be added." << std::endl;
111        }
112    }
113   
114    /**
115    @brief
116        Starts the quest.
117    @param player
118        The player.
119    @return
120        Returns true if the quest could be started, false if not.
121    */
122    bool Quest::start(const Player & player)
123    {
124        if(this->isStartable(player))
125        {
126            this->setStatus(player, questStatus::active);
127            return true;
128        }
129        COUT(2) << "A non-startable quest was trying to be started." << std::endl;
130        return false;
131    }
132   
133    /**
134    @brief
135        Fails the quest.
136    @param player
137        The player.
138    @return
139        Returns true if the quest could be failed, false if not.
140    */
141    void Quest::fail(Player & player)
142    {
143        if(this->isFailable(player))
144        {
145            this->setStatus(player, questStatus::failed);
146            QuestEffect::invokeEffects(player, this->failEffects_);
147            return true;
148        }
149        COUT(2) << "A non-failable quest was trying to be failed." << std::endl;
150        return false;
151    }
152   
153    /**
154    @brief
155        Completes the quest.
156    @param player
157        The player.
158    @return
159        Returns true if the quest could be completed, false if not.
160    */
161    void Quest::complete(Player & player)
162    {
163        if(this->isCompletable(player))
164        {
165            this->setStatus(player, questStatus::completed);
166            QuestEffect::invokeEffects(player, this->completeEffects_);
167            return true;
168        }
169        COUT(2) << "A non-completable quest was trying to be completed." << std::endl;
170        return false;
171    }
172
173}
Note: See TracBrowser for help on using the repository browser.