Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/pch/src/orxonox/objects/quest/AddReward.cc @ 3180

Last change on this file since 3180 was 3180, checked in by rgrieder, 15 years ago

Cleanup in pickup and quest (almost only cleaned the header file sections).

  • Property svn:eol-style set to native
File size: 3.1 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/**
30    @file
31    @brief Implementation of the AddReward class.
32*/
33
34#include "AddReward.h"
35
36#include "util/Debug.h"
37#include "core/CoreIncludes.h"
38#include "core/XMLPort.h"
39#include "Rewardable.h"
40
41namespace orxonox
42{
43    CreateFactory(AddReward);
44
45    /**
46    @brief
47        Constructor. Registers the object.
48    */
49    AddReward::AddReward(BaseObject* creator) : QuestEffect(creator)
50    {
51        RegisterObject(AddReward);
52    }
53
54    /**
55    @brief
56        Destructor.
57    */
58    AddReward::~AddReward()
59    {
60    }
61
62    /**
63        Method for creating a AddReward object through XML.
64    */
65    void AddReward::XMLPort(Element& xmlelement, XMLPort::Mode mode)
66    {
67        SUPER(AddReward, XMLPort, xmlelement, mode);
68
69        XMLPortObject(AddReward, Rewardable, "", addRewardable, getRewardables, xmlelement, mode);
70       
71        COUT(3) << "New AddReward, with " << this->rewards_.size() << " Rewardables created." << std::endl;
72    }
73
74    /**
75    @brief
76        Returns the Rewardable object at the given index.
77    @param index
78        The index.
79    @return
80        Returns a pointer to the Rewardable object at the given index.
81    */
82    const Rewardable* AddReward::getRewardables(unsigned int index) const
83    {
84        int i = index;
85        for (std::list<Rewardable*>::const_iterator reward = this->rewards_.begin(); reward != this->rewards_.end(); ++reward)
86        {
87            if(i == 0)
88            {
89               return *reward;
90            }
91            i--;
92        }
93        return NULL;
94    }
95
96    /**
97    @brief
98        Invokes the QuestEffect.
99    @param player
100        The player.
101    @return
102        Returns true if the QuestEffect was invoked successfully.
103    */
104    bool AddReward::invoke(PlayerInfo* player)
105    {
106        COUT(3) << "AddReward on player: " << player << " ." << std::endl;
107       
108        bool check = true;
109        for ( std::list<Rewardable*>::iterator reward = this->rewards_.begin(); reward != this->rewards_.end(); ++reward )
110        {
111            check = check && (*reward)->reward(player);
112        }
113       
114        COUT(3) << "Rewardable successfully added to player." << player << " ." << std::endl;
115
116        return check;
117    }
118
119}
Note: See TracBrowser for help on using the repository browser.