Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/orxonox/objects/quest/LocalQuest.cc @ 3110

Last change on this file since 3110 was 3110, checked in by rgrieder, 15 years ago

Removed old msvc specific support for precompiled header files.

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