Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/questsystem/src/orxonox/objects/GlobalQuest.cc @ 2068

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

Started with XMLPort…

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