Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 2800 was 2710, checked in by rgrieder, 16 years ago

Merged buildsystem3 containing buildsystem2 containing Adi's buildsystem branch back to the trunk.
Please update the media directory if you were not using buildsystem3 before.

  • Property svn:eol-style set to native
  • Property svn:mergeinfo set to (toggle deleted branches)
    /code/branches/lodfinal/src/orxonox/objects/quest/GlobalQuest.ccmergedeligible
    /code/trunk/src/orxonox/objects/quest/GlobalQuest.ccmergedeligible
    /code/branches/buildsystem2/src/orxonox/objects/quest/GlobalQuest.cc2506-2658
    /code/branches/buildsystem3/src/orxonox/objects/quest/GlobalQuest.cc2662-2708
    /code/branches/network/src/orxonox/objects/quest/GlobalQuest.cc2356
    /code/branches/network64/src/orxonox/objects/quest/GlobalQuest.cc2210-2355
    /code/branches/objecthierarchy2/src/orxonox/objects/quest/GlobalQuest.cc2171-2479
    /code/branches/overlay/src/orxonox/objects/quest/GlobalQuest.cc2117-2385
    /code/branches/physics/src/orxonox/objects/quest/GlobalQuest.cc2107-2439
    /code/branches/physics_merge/src/orxonox/objects/quest/GlobalQuest.cc2436-2457
    /code/branches/pickups2/src/orxonox/objects/quest/GlobalQuest.cc2107-2497
    /code/branches/presentation/src/orxonox/objects/quest/GlobalQuest.cc2369-2652,​2654-2660
    /code/branches/questsystem2/src/orxonox/objects/quest/GlobalQuest.cc2107-2259
    /code/branches/weapon2/src/orxonox/objects/quest/GlobalQuest.cc2107-2488
File size: 8.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 */
[2261]28 
29/**
[2662]30    @file
31    @brief Implementation of the GlobalQuest class.
[2261]32*/
[1992]33
[2105]34#include "OrxonoxStableHeaders.h"
35#include "GlobalQuest.h"
36
[2261]37#include "orxonox/objects/infos/PlayerInfo.h"
[1992]38#include "core/CoreIncludes.h"
[2662]39#include "core/Super.h"
[2068]40#include "util/Exception.h"
[1992]41
[2261]42#include "QuestEffect.h"
43
[2662]44namespace orxonox
45{
[1992]46    CreateFactory(GlobalQuest);
47
[2068]48    /**
49    @brief
[2261]50        Constructor. Registers the object.
[2068]51    */
[2092]52    GlobalQuest::GlobalQuest(BaseObject* creator) : Quest(creator)
[2021]53    {
[2092]54        RegisterObject(GlobalQuest);
[2021]55    }
[2092]56
[1992]57    /**
58    @brief
59        Destructor.
60    */
61    GlobalQuest::~GlobalQuest()
62    {
[2092]63
[1992]64    }
[2261]65   
66    /**
67    @brief
68        Method for creating a GlobalQuest object through XML.
69    */
[2076]70    void GlobalQuest::XMLPort(Element& xmlelement, XMLPort::Mode mode)
71    {
72        SUPER(GlobalQuest, XMLPort, xmlelement, mode);
[2261]73       
74        XMLPortObject(GlobalQuest, QuestEffect, "reward-effects", addRewardEffect, getRewardEffects, xmlelement, mode);
[2076]75
[2081]76        COUT(3) << "New GlobalQuest {" << this->getId() << "} created." << std::endl;
[2076]77    }
[2261]78   
79    /**
80    @brief
81        Fails the Quest for all players.
82        Invokes the fail QuestEffects on all the players possessing this Quest.
83    @param player
84        The player failing it.
85    @return
86        Returns true if the Quest could be failed, false if not.
87    */
88    bool GlobalQuest::fail(PlayerInfo* player)
89    {
[2662]90        if(!this->isFailable(player)) //!< Check whether the Quest can be failed.
[2261]91        {
[2662]92            COUT(4) << "A non-completable quest was trying to be failed." << std::endl;
93            return false;
[2261]94        }
95       
[2662]96        Quest::fail(player);
97   
98    //! Iterate through all players possessing this Quest.
99    for(std::set<PlayerInfo*>::const_iterator it = players_.begin(); it != players_.end(); it++)
100    {
101        QuestEffect::invokeEffects(*it, this->getFailEffectList());
[2261]102    }
103
[2662]104    return true;
105    }
106
[2261]107    /**
108    @brief
109        Completes the Quest for all players.
110        Invokes the complete QuestEffects on all the players possessing this Quest.
111        Invokes the reward QuestEffects on the player completing the Quest.
112    @param player
113        The player completing it.
114    @return
115        Returns true if the Quest could be completed, false if not.
116    */
117    bool GlobalQuest::complete(PlayerInfo* player)
[2068]118    {
[2662]119        if(!this->isCompletable(player)) //!< Check whether the Quest can be completed.
[2261]120        {
[2662]121            COUT(4) << "A non-completable quest was trying to be completed." << std::endl;
122            return false;
[2261]123        }
124       
[2662]125        //! Iterate through all players possessing the Quest.
126        for(std::set<PlayerInfo*>::const_iterator it = players_.begin(); it != players_.end(); it++)
127        {
128            QuestEffect::invokeEffects(*it, this->getCompleteEffectList());
129        }
130   
131        Quest::complete(player);
132   
133        QuestEffect::invokeEffects(player, this->rewards_); //!< Invoke reward QuestEffects on the player completing the Quest.
134        return true;
[2068]135    }
[2092]136
[1996]137    /**
138    @brief
[2261]139        Checks whether the Quest can be started.
[1996]140    @param player
141        The player for whom is to be checked.
142    @return
143        Returns true if the quest can be started, false if not.
[2068]144    @throws
145        Throws an exception if either isInactive() of isActive() throws one.
[1996]146    */
[2261]147    bool GlobalQuest::isStartable(const PlayerInfo* player) const
[1996]148    {
[2261]149        if(!(this->getParentQuest() == NULL || this->getParentQuest()->isActive(player)))
150        {
151            return false;
152        }
153        return (this->isInactive(player) && !(this->status_ == questStatus::completed || this->status_ == questStatus::failed));
[1996]154    }
[2092]155
[1996]156    /**
157    @brief
[2261]158        Checks whether the Quest can be failed.
[1996]159    @param player
160        The player for whom is to be checked.
161    @return
[2261]162        Returns true if the Quest can be failed, false if not.
[2068]163    @throws
164        Throws an Exception if isActive() throws one.
[1996]165    */
[2261]166    bool GlobalQuest::isFailable(const PlayerInfo* player) const
[1996]167    {
168        return this->isActive(player);
[2068]169
[1996]170    }
[2092]171
[1996]172    /**
173    @brief
[2261]174        Checks whether the Quest can be completed.
[1996]175    @param player
176        The player for whom is to be checked.
177    @return
[2261]178        Returns true if the Quest can be completed, false if not.
[2068]179    @throws
180        Throws an Exception if isActive() throws one.
[1996]181    */
[2261]182    bool GlobalQuest::isCompletable(const PlayerInfo* player) const
[1996]183    {
184        return this->isActive(player);
185    }
[1992]186
187    /**
188    @brief
[2261]189        Returns the status of the Quest for a specific player.
[1992]190    @param player
191        The player.
[2068]192    @throws
193        Throws an Exception if player is NULL.
[1992]194    */
[2261]195    questStatus::Enum GlobalQuest::getStatus(const PlayerInfo* player) const
[1992]196    {
[2261]197        if(player == NULL) //!< We don't want NULL-Pointers!
[2068]198        {
[2261]199            ThrowException(Argument, "The input PlayerInfo* is NULL.");
[2068]200        }
[2092]201
[2261]202        //! Find the player.
203        std::set<PlayerInfo*>::const_iterator it = this->players_.find((PlayerInfo*)(void*)player);
204        if (it != this->players_.end()) //!< If the player was found.
[2093]205        {
206            return this->status_;
207        }
[1992]208
[2662]209        return questStatus::inactive;
[1992]210    }
[2092]211
[1992]212    /**
213    @brief
214        Sets the status for a specific player.
[2093]215        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]216    @param player
217        The player.
218    @param status
219        The status to be set.
[2068]220    @return
221        Returns false if player is NULL.
[1992]222    */
[2261]223    bool GlobalQuest::setStatus(PlayerInfo* player, const questStatus::Enum & status)
[1992]224    {
[2261]225        if(player == NULL) //!< We don't want NULL-Pointers!
[2068]226        {
227            return false;
[2093]228        }
[2092]229
[2261]230        //! Find the player.
231        std::set<PlayerInfo*>::const_iterator it = this->players_.find(player);
[2021]232        if (it == this->players_.end()) //!< Player is not yet in the list.
[2093]233        {
[2261]234            this->players_.insert(player); //!< Add the player to the set.
[2093]235        }
[2261]236       
237        this->status_ = status; //!< Set the status, which is global, remember...?
[2093]238        return true;
[1992]239    }
[2261]240   
241    /**
242    @brief
243        Adds a reward QuestEffect to the list of reward QuestEffects.
244    @param effect
245        The QuestEffect to be added.
246    @return
247        Returns true if successful.
248    */
249    bool GlobalQuest::addRewardEffect(QuestEffect* effect)
250    {
251        if(effect == NULL) //!< We don't want NULL-Pointers!
252        {
253            COUT(2) << "The reward effect to be added to quest {" << this->getId() << "} was NULL." << std::endl;
254            return false;
255        }
[1992]256
[2261]257        this->rewards_.push_back(effect); //!< Add the QuestEffect to the list.
[1996]258
[2261]259        COUT(3) << "Reward effect was added to Quest {" << this->getId() << "}." << std::endl;
260        return true;
261    }
262   
263    /**
264    @brief
265        Returns the reward QuestEffect at the given index.
266    @param index
267        The index.
268    @return
269        Returns the QuestEffect at the given index.
270    */
271    const QuestEffect* GlobalQuest::getRewardEffects(unsigned int index) const
272    {
273        int i = index;
274        for (std::list<QuestEffect*>::const_iterator effect = this->rewards_.begin(); effect != this->rewards_.end(); ++effect)
275        {
276            if(i == 0)
277            {
278               return *effect;
279            }
280            i--;
281        }
282        return NULL;
283    }
284
285
[1992]286}
Note: See TracBrowser for help on using the repository browser.