Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/orxonox/objects/quest/GlobalQuest.cc @ 2095

Last change on this file since 2095 was 2093, checked in by landauf, 16 years ago

converted tabs to spaces

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