Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 2092 was 2092, checked in by landauf, 16 years ago
  • adopted quest classes to the new hierarchy (with a creator pointer)
  • added "RegisterObject(…)" in all constructors and "virtual" to all destructors
  • Property svn:eol-style set to native
File size: 4.2 KB
RevLine 
[1992]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"
[2068]30#include "util/Exception.h"
[1992]31
32#include "GlobalQuest.h"
33
34namespace orxonox {
35
36    CreateFactory(GlobalQuest);
37
[2068]38    /**
39    @brief
40        Constructor.
41    */
[2092]42    GlobalQuest::GlobalQuest(BaseObject* creator) : Quest(creator)
[2021]43    {
[2092]44        RegisterObject(GlobalQuest);
45
[2068]46        this->initialize();
[2021]47    }
[2092]48
[1992]49    /**
50    @brief
51        Destructor.
52    */
53    GlobalQuest::~GlobalQuest()
54    {
[2092]55
[1992]56    }
[2092]57
[2076]58    void GlobalQuest::XMLPort(Element& xmlelement, XMLPort::Mode mode)
59    {
60        SUPER(GlobalQuest, XMLPort, xmlelement, mode);
61
[2081]62        COUT(3) << "New GlobalQuest {" << this->getId() << "} created." << std::endl;
[2076]63    }
[2092]64
[2068]65    void GlobalQuest::initialize(void)
66    {
67        RegisterObject(GlobalQuest);
68    }
[2092]69
[1996]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.
[2068]77    @throws
78        Throws an exception if either isInactive() of isActive() throws one.
[1996]79    */
[2043]80    bool GlobalQuest::isStartable(const Player* player) const
[1996]81    {
[2068]82        return this->isInactive(player) ||  this->isActive(player);
[1996]83    }
[2092]84
[1996]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.
[2068]92    @throws
93        Throws an Exception if isActive() throws one.
[1996]94    */
[2043]95    bool GlobalQuest::isFailable(const Player* player) const
[1996]96    {
97        return this->isActive(player);
[2068]98
[1996]99    }
[2092]100
[1996]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.
[2068]108    @throws
109        Throws an Exception if isActive() throws one.
[1996]110    */
[2043]111    bool GlobalQuest::isCompletable(const Player* player) const
[1996]112    {
113        return this->isActive(player);
114    }
[1992]115
116    /**
117    @brief
118        Returns the status of the quest for a specific player.
119    @param player
120        The player.
[2068]121    @throws
122        Throws an Exception if player is NULL.
[1992]123    */
[2043]124    questStatus::Enum GlobalQuest::getStatus(const Player* player) const
[1992]125    {
[2068]126        if(player == NULL)
127        {
128            ThrowException(Argument, "The input Player* is NULL.");
129        }
[2092]130
[1992]131        //TDO: Does this really work???
[2021]132        std::set<Player*>::const_iterator it = this->players_.find((Player*)(void*)player);
133        if (it != this->players_.end())
[1992]134        {
135            return this->status_;
136        }
137        else
138        {
139           return questStatus::inactive;
140        }
141
142    }
[2092]143
[1992]144    /**
145    @brief
146        Sets the status for a specific player.
[2068]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.
[1992]148    @param player
149        The player.
150    @param status
151        The status to be set.
[2068]152    @return
153        Returns false if player is NULL.
[1992]154    */
[2021]155    bool GlobalQuest::setStatus(Player* player, const questStatus::Enum & status)
[1992]156    {
[2068]157        if(player == NULL)
158        {
159            return false;
160        }
[2092]161
[2021]162        std::set<Player*>::const_iterator it = this->players_.find(player);
163        if (it == this->players_.end()) //!< Player is not yet in the list.
[1996]164        {
[2021]165            this->players_.insert(player);
[1996]166        }
167        this->status_ = status;
[2021]168        return true;
[1992]169    }
170
[1996]171
[1992]172}
Note: See TracBrowser for help on using the repository browser.