Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/pickup3/src/modules/pickup/PickupCollection.cc @ 6466

Last change on this file since 6466 was 6466, checked in by dafrick, 14 years ago

Lots of things done in pickups module. Compiles, but it seems, that I've also introduced an error preventing steering of the spaceship.

  • Property svn:eol-style set to native
File size: 4.7 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 PickupCollection.
32*/
33
34#include "PickupCollection.h"
35
36#include "core/CoreIncludes.h"
37#include "core/Template.h"
38#include "core/XMLPort.h"
39#include "interfaces/PickupCarrier.h"
40
41namespace orxonox
42{
43 
44    /**
45    @brief
46        Default Constructor.
47    */
48    PickupCollection::PickupCollection(BaseObject* creator) : BaseObject(creator)
49    {
50        RegisterObject(PickupCollection);
51    }
52   
53    /**
54    @brief
55        Destructor.
56    */
57    PickupCollection::~PickupCollection()
58    {
59        //! Destroy all Pickupables constructing this PickupCollection.
60        for(std::vector<Pickupable*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
61        {
62            delete *it;
63        }
64    }
65   
66    /**
67    @brief
68        Creates an instance of this Class through XML.
69    */
70    void PickupCollection::XMLPort(Element& xmlelement, XMLPort::Mode mode)
71    {
72        SUPER(PickupCollection, XMLPort, xmlelement, mode);
73       
74        //TODO: Does this work? Problem could be, that Pickupable itself cannot be instantiated through XML, doubt that, though.
75        XMLPortObject(PickupCollection, PickupCollection, "pickupables", addPickupable, getPickupable, xmlelement, mode);
76       
77        this->initializeIdentifier();
78    }
79   
80    void PickupCollection::initializeIdentifier(void)
81    {
82        this->pickupCollectionIdentifier_.addClass(this->getIdentifier());
83       
84        for(std::vector<Pickupable*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
85        {
86            this->pickupCollectionIdentifier_.addPickup((*it)->getPickupIdentifier());
87        }
88    }
89   
90    /**
91    @brief
92        Add the input Pickupable to list of Pickupables combined by this PickupCollection.
93    @param pickup
94        The Pickupable to be added.
95    @return
96        Returns true if successful,
97    */
98    bool PickupCollection::addPickupable(Pickupable* pickup)
99    {
100        if(pickup == NULL)
101            return false;
102       
103        this->pickups_.push_back(pickup);
104        return true;
105    }
106   
107    /**
108    @brief
109        Get the Pickupable at the given index.
110    @param index
111        The index the Pickupable is fetched from.
112    @return
113        Returns a pointer to the Pickupable at the index given by index.
114    */
115    const Pickupable* PickupCollection::getPickupable(unsigned int index)
116    {
117        return this->pickups_[index]; //TODO. Does this work?
118    }
119   
120    //TODO: Steal description from Pickupable.
121    void PickupCollection::changedUsed(void)
122    {
123        SUPER(PickupCollection, changedUsed);
124       
125        //! Change used for all Pickupables this PickupCollection consists of.
126        for(std::vector<Pickupable*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
127        {
128            (*it)->setUsed(this->isUsed());
129        }
130    }
131   
132    void PickupCollection::changedCarrier()
133    {
134        SUPER(PickupCollection, changedCarrier);
135       
136        //! Change the carrier for all Pickupables this PickupCollection consists of.
137        for(std::vector<Pickupable*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
138        {
139            (*it)->setCarrier(this->getCarrier());
140        }
141    }
142   
143    //TODO: Steal description from Pickupable.
144    void PickupCollection::clone(OrxonoxClass* item)
145    {
146        if(item == NULL)
147            item = new PickupCollection(this);
148       
149        SUPER(PickupCollection, clone, item);
150       
151        PickupCollection* pickup = dynamic_cast<PickupCollection*>(item);
152        for(std::vector<Pickupable*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
153        {
154            Pickupable* newPickup = (*it)->clone();
155            pickup->addPickupable(newPickup);
156        }
157
158        pickup->initializeIdentifier();
159    }
160   
161}
Note: See TracBrowser for help on using the repository browser.