Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/questsystem2/src/orxonox/objects/quest/LocalQuest.cc @ 2146

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

Started implementation of QuestEffectBeacon.
Done some documentation of QuestItem and subclasses.

File size: 6.3 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 LocalQuest.cc
31    @brief
32        Implementation of the LocalQuest class.
33*/
34
35#include "OrxonoxStableHeaders.h"
36#include "LocalQuest.h"
37
38#include "core/CoreIncludes.h"
39#include "util/Exception.h"
40
41#include "orxonox/objects/worldentities/ControllableEntity.h"
42#include "QuestEffect.h"
43
44namespace orxonox {
45
46    CreateFactory(LocalQuest);
47
48    /**
49    @brief
50        Constructor. Initializes the object.
51    */
52    LocalQuest::LocalQuest(BaseObject* creator) : Quest(creator)
53    {
54        this->initialize();
55    }
56   
57    /**
58    @brief
59        Initializes the object.
60    */
61    void LocalQuest::initialize(void)
62    {
63        RegisterObject(LocalQuest);
64    }
65
66    /**
67    @brief
68        Destructor.
69    */
70    LocalQuest::~LocalQuest()
71    {
72
73    }
74
75    /**
76    @brief
77        Method for creating a LocalQuest object through XML.
78    */
79    void LocalQuest::XMLPort(Element& xmlelement, XMLPort::Mode mode)
80    {
81        SUPER(LocalQuest, XMLPort, xmlelement, mode);
82
83        COUT(3) << "New LocalQuest {" << this->getId() << "} created." << std::endl;
84    }
85
86    /**
87    @brief
88        Fails the quest for a given player.
89        Invokes all the failEffects on the player.
90    @param player
91        The player.
92    @return
93        Returns true if the quest could be failed, false if not.
94    */
95    bool LocalQuest::fail(ControllableEntity* player)
96    {
97        if(this->isFailable(player)) //!< Checks whether the quest can be failed.
98        {
99            this->setStatus(player, questStatus::failed);
100            QuestEffect::invokeEffects(player, this->failEffects_); //!< Invoke the failEffects.
101            return true;
102        }
103       
104        COUT(2) << "A non-failable quest was trying to be failed." << std::endl;
105        return false;
106    }
107
108    /**
109    @brief
110        Completes the quest for a given player.
111        Invokes all the completeEffects on the player.
112    @param player
113        The player.
114    @return
115        Returns true if the quest could be completed, false if not.
116    */
117    bool LocalQuest::complete(ControllableEntity* player)
118    {
119        if(this->isCompletable(player)) //!< Checks whether the quest can be completed.
120        {
121            this->setStatus(player, questStatus::completed);
122            QuestEffect::invokeEffects(player, this->completeEffects_); //!< Invoke the completeEffects.
123            return true;
124        }
125       
126        COUT(2) << "A non-completable quest was trying to be completed." << std::endl;
127        return false;
128    }
129
130    /**
131    @brief
132        Checks whether the quest can be started.
133    @param player
134        The player for whom is to be checked.
135    @return
136        Returns true if the quest can be started, false if not.
137    @throws
138        Throws an exception if isInactive(ControllableEntity*) throws one.
139    */
140    bool LocalQuest::isStartable(const ControllableEntity* player) const
141    {
142        return this->isInactive(player);
143    }
144
145    /**
146    @brief
147        Checks whether the quest can be failed.
148    @param player
149        The player for whom is to be checked.
150    @return
151        Returns true if the quest can be failed, false if not.
152    @throws
153        Throws an exception if isActive(ControllableEntity*) throws one.
154    */
155    bool LocalQuest::isFailable(const ControllableEntity* player) const
156    {
157        return this->isActive(player);
158    }
159
160    /**
161    @brief
162        Checks whether the quest can be completed.
163    @param player
164        The player for whom is to be checked.
165    @return
166        Returns true if the quest can be completed, false if not.
167    @throws
168        Throws an exception if isInactive(ControllableEntity*) throws one.
169    */
170    bool LocalQuest::isCompletable(const ControllableEntity* player) const
171    {
172        return this->isActive(player);
173    }
174
175    /**
176    @brief
177        Returns the status of the quest for a specific player.
178    @param player
179        The player.
180    @return
181        Returns the status of the quest for the input player.
182    @throws
183        Throws an Exception if player is NULL.
184    */
185    questStatus::Enum LocalQuest::getStatus(const ControllableEntity* player) const
186    {
187        if(player == NULL) //!< No player has no defined status.
188        {
189            ThrowException(Argument, "The input ControllableEntity* is NULL.");
190        }
191
192        std::map<ControllableEntity*, questStatus::Enum>::const_iterator it = this->playerStatus_.find((ControllableEntity*)(void*)player); //Thx. to x3n for the (ControllableEntity*)(void*) 'hack'.
193        if (it != this->playerStatus_.end()) //!< If there is a player in the map.
194        {
195            return it->second;
196        }
197       
198        return questStatus::inactive; //!< If the player is not yet in the map, that means the status of the quest form him is 'inactive'.
199    }
200
201    /**
202    @brief
203        Sets the status for a specific player.
204        But be careful wit this one, the status will just be set without checking for its validity. You have to know what you're doing. Really!
205    @param player
206        The player the status should be set for.
207    @param status
208        The status to be set.
209    @return
210        Returns false if player is NULL.
211    */
212    bool LocalQuest::setStatus(ControllableEntity* player, const questStatus::Enum & status)
213    {
214        if(player == NULL) //!< We can't set a status for no player.
215        {
216            return false;
217        }
218       
219        this->playerStatus_[player] = status;
220        return true;
221    }
222
223}
Note: See TracBrowser for help on using the repository browser.