Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/modules/pickup/Pickup.cc @ 8352

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

Documenting and cleanup.

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