Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/lod/src/modules/pickup/Pickup.cc @ 6608

Last change on this file since 6608 was 6540, checked in by dafrick, 15 years ago

Removed some TODO's. Finished up documenting pickup module.

File size: 6.8 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 Pickup.cc
31    @brief Implementation of the Pickup class.
32*/
33
34#include "Pickup.h"
35
36#include "core/CoreIncludes.h"
37#include "util/StringUtils.h"
38#include "pickup/PickupIdentifier.h"
39#include "DroppedPickup.h"
40
41namespace orxonox
42{
43   
44    /*static*/ const std::string Pickup::activationTypeImmediate_s = "immediate";
45    /*static*/ const std::string Pickup::activationTypeOnUse_s = "onUse";
46    /*static*/ const std::string Pickup::durationTypeOnce_s = "once";
47    /*static*/ const std::string Pickup::durationTypeContinuous_s = "continuous";
48   
49    Pickup::Pickup(BaseObject* creator) : BaseObject(creator)
50    {
51        RegisterObject(Pickup);
52       
53        this->initialize();
54    }
55   
56    Pickup::~Pickup()
57    {
58       
59    }
60   
61    /**
62    @brief
63        Initializes the member variables.
64    */
65    void Pickup::initialize(void)
66    {
67        this->activationType_ = pickupActivationType::immediate;
68        this->durationType_ = pickupDurationType::once;
69    }
70   
71    /**
72    @brief
73        Initializes the PickupIdentififer of this Pickup.
74    */
75    void Pickup::initializeIdentifier(void)
76    {       
77        std::string val1 = this->getActivationType();
78        std::string type1 = "activationType";
79        this->pickupIdentifier_->addParameter(type1, val1);
80       
81        std::string val2 = this->getDurationType();
82        std::string type2 = "durationType";
83        this->pickupIdentifier_->addParameter(type2, val2);
84    }
85   
86    /**
87    @brief
88        Method for creating a Pickup object through XML.
89    */
90    void Pickup::XMLPort(Element& xmlelement, XMLPort::Mode mode)
91    {
92        SUPER(Pickup, XMLPort, xmlelement, mode);
93
94        XMLPortParam(Pickup, "activationType", setActivationType, getActivationType, xmlelement, mode);
95        XMLPortParam(Pickup, "durationType", setDurationType, getDurationType, xmlelement, mode);
96       
97        this->initializeIdentifier();
98    }
99   
100    /**
101    @brief
102        Get the activation type of the pickup.
103    @return
104        Returns a string containing the activation type.
105    */
106    const std::string& Pickup::getActivationType(void)
107    {
108        switch(this->activationType_)
109        {
110            case pickupActivationType::immediate:
111                return activationTypeImmediate_s;
112            case pickupActivationType::onUse:
113                return activationTypeOnUse_s;
114            default:
115                return BLANKSTRING;
116        }
117    }
118       
119    /**
120    @brief
121        Get the duration type of the pickup.
122    @return
123        Returns a string containing the duration type.
124    */
125    const std::string& Pickup::getDurationType(void)
126    {
127        switch(this->durationType_)
128        {
129            case pickupDurationType::once:
130                return durationTypeOnce_s;
131            case pickupDurationType::continuous:
132                return durationTypeContinuous_s;
133            default:
134                return BLANKSTRING;
135        }
136    }
137   
138    /**
139    @brief
140        Set the activation type of the Pickup.
141    @param type
142        The activation type of the Pickup as a string.
143    */
144    void Pickup::setActivationType(const std::string& type)
145    {
146        if(type == activationTypeImmediate_s)
147        {
148            this->activationType_ = pickupActivationType::immediate;
149        }
150        else if(type == activationTypeOnUse_s)
151        {
152            this->activationType_ = pickupActivationType::onUse;
153        }
154        else
155        {
156            COUT(1) << "Invalid activationType in pickup." << std::endl;
157        }
158    }
159       
160    /**
161    @brief
162        Set the duration type of the Pickup.
163    @param type
164        The duration type of the Pickup as a string.
165    */
166    void Pickup::setDurationType(const std::string& type)
167    {
168        if(type == durationTypeOnce_s)
169        {
170            this->durationType_ = pickupDurationType::once;
171        }
172        else if(type == durationTypeContinuous_s)
173        {
174            this->durationType_ = pickupDurationType::continuous;
175        }
176        else
177        {
178            COUT(1) << "Invalid durationType in pickup." << std::endl;
179        }
180    }
181   
182    /**
183    @brief
184        Should be called when the pickup has transited from picked up to dropped or the other way around.
185        Any Class overwriting this method must call its SUPER function by adding SUPER(Classname, changedPickedUp); to their changedPickedUp method.
186    */
187    void Pickup::changedPickedUp(void)
188    {
189        SUPER(Pickup, changedPickedUp);
190       
191        //! Sets the Pickup to used if the Pickup has activation type 'immediate' and gets picked up.
192        if(this->getCarrier() != NULL && this->isPickedUp() && this->isImmediate())
193        {
194            this->setUsed(true);
195        }
196    }
197   
198    /**
199    @brief
200        Creates a duplicate of the Pickup.
201    @return
202        Returns the clone of this pickup as a pointer to a Pickupable.
203    */
204    void Pickup::clone(OrxonoxClass*& item)
205    {
206        if(item == NULL)
207            item = new Pickup(this);
208       
209        SUPER(Pickup, clone, item);
210       
211        Pickup* pickup = dynamic_cast<Pickup*>(item);
212        pickup->setActivationTypeDirect(this->getActivationTypeDirect());
213        pickup->setDurationTypeDirect(this->getDurationTypeDirect());
214       
215        pickup->initializeIdentifier();
216    }
217       
218    /**
219    @brief
220        Facilitates the creation of a PickupSpawner upon dropping of the Pickupable.
221        This method must be implemented by any class directly inheriting from Pickupable. It is most easily done by just creating a new DroppedPickup, e.g.:
222        DroppedPickup(BaseObject* creator, Pickupable* pickup, const Vector3& position);
223    @param position
224        The position at which the PickupSpawner should be placed.
225    @return
226        Returns true if a spawner was created, false if not.
227    */
228    bool Pickup::createSpawner(void)
229    {
230        new DroppedPickup(this, this, this->getCarrier());
231        return true;
232    }
233   
234}
Note: See TracBrowser for help on using the repository browser.