Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/network/src/orxonox/objects/quest/GlobalQuest.cc @ 2371

Last change on this file since 2371 was 2105, checked in by rgrieder, 16 years ago

updated msvc files and precompiled headers.

File size: 4.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#include "OrxonoxStableHeaders.h"
30#include "GlobalQuest.h"
31
32#include "core/CoreIncludes.h"
33#include "util/Exception.h"
34
35namespace orxonox {
36
37    CreateFactory(GlobalQuest);
38
39    /**
40    @brief
41        Constructor.
42    */
43    GlobalQuest::GlobalQuest(BaseObject* creator) : Quest(creator)
44    {
45        RegisterObject(GlobalQuest);
46
47        this->initialize();
48    }
49
50    /**
51    @brief
52        Destructor.
53    */
54    GlobalQuest::~GlobalQuest()
55    {
56
57    }
58
59    void GlobalQuest::XMLPort(Element& xmlelement, XMLPort::Mode mode)
60    {
61        SUPER(GlobalQuest, XMLPort, xmlelement, mode);
62
63        COUT(3) << "New GlobalQuest {" << this->getId() << "} created." << std::endl;
64    }
65
66    void GlobalQuest::initialize(void)
67    {
68        RegisterObject(GlobalQuest);
69    }
70
71    /**
72    @brief
73        Checks whether the quest can be started.
74    @param player
75        The player for whom is to be checked.
76    @return
77        Returns true if the quest can be started, false if not.
78    @throws
79        Throws an exception if either isInactive() of isActive() throws one.
80    */
81    bool GlobalQuest::isStartable(const Player* player) const
82    {
83        return this->isInactive(player) ||  this->isActive(player);
84    }
85
86    /**
87    @brief
88        Checks whether the quest can be failed.
89    @param player
90        The player for whom is to be checked.
91    @return
92        Returns true if the quest can be failed, false if not.
93    @throws
94        Throws an Exception if isActive() throws one.
95    */
96    bool GlobalQuest::isFailable(const Player* player) const
97    {
98        return this->isActive(player);
99
100    }
101
102    /**
103    @brief
104        Checks whether the quest can be completed.
105    @param player
106        The player for whom is to be checked.
107    @return
108        Returns true if the quest can be completed, false if not.
109    @throws
110        Throws an Exception if isActive() throws one.
111    */
112    bool GlobalQuest::isCompletable(const Player* player) const
113    {
114        return this->isActive(player);
115    }
116
117    /**
118    @brief
119        Returns the status of the quest for a specific player.
120    @param player
121        The player.
122    @throws
123        Throws an Exception if player is NULL.
124    */
125    questStatus::Enum GlobalQuest::getStatus(const Player* player) const
126    {
127        if(player == NULL)
128        {
129            ThrowException(Argument, "The input Player* is NULL.");
130        }
131
132        //TDO: Does this really work???
133        std::set<Player*>::const_iterator it = this->players_.find((Player*)(void*)player);
134        if (it != this->players_.end())
135        {
136            return this->status_;
137        }
138        else
139        {
140           return questStatus::inactive;
141        }
142
143    }
144
145    /**
146    @brief
147        Sets the status for a specific player.
148        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.
149    @param player
150        The player.
151    @param status
152        The status to be set.
153    @return
154        Returns false if player is NULL.
155    */
156    bool GlobalQuest::setStatus(Player* player, const questStatus::Enum & status)
157    {
158        if(player == NULL)
159        {
160            return false;
161        }
162
163        std::set<Player*>::const_iterator it = this->players_.find(player);
164        if (it == this->players_.end()) //!< Player is not yet in the list.
165        {
166            this->players_.insert(player);
167        }
168        this->status_ = status;
169        return true;
170    }
171
172
173}
Note: See TracBrowser for help on using the repository browser.