Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 9223 was 8864, checked in by dafrick, 13 years ago

Improving output.

  • 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    {
[8864]161        if(type == Pickup::activationTypeImmediate_s)
[6474]162            this->activationType_ = pickupActivationType::immediate;
[8864]163        else if(type == Pickup::activationTypeOnUse_s)
[6474]164            this->activationType_ = pickupActivationType::onUse;
165        else
[8864]166            orxout(internal_error, context::pickups) << "Invalid activationType '" << type << "' in " << this->getIdentifier()->getName() << "." << endl;
[6474]167    }
[6709]168
[6474]169    /**
170    @brief
171        Set the duration type of the Pickup.
172    @param type
173        The duration type of the Pickup as a string.
174    */
175    void Pickup::setDurationType(const std::string& type)
176    {
[8864]177        if(type == Pickup::durationTypeOnce_s)
[6474]178            this->durationType_ = pickupDurationType::once;
[8864]179        else if(type == Pickup::durationTypeContinuous_s)
[6474]180            this->durationType_ = pickupDurationType::continuous;
181        else
[8864]182            orxout(internal_error, context::pickups) << "Invalid durationType '" << type << "' in " << this->getIdentifier()->getName() << "." << endl;
[6474]183    }
[6709]184
[6474]185    /**
186    @brief
[6475]187        Should be called when the pickup has transited from picked up to dropped or the other way around.
[6521]188        Any Class overwriting this method must call its SUPER function by adding SUPER(Classname, changedPickedUp); to their changedPickedUp method.
[6475]189    */
[6521]190    void Pickup::changedPickedUp(void)
[6475]191    {
[6521]192        SUPER(Pickup, changedPickedUp);
[6709]193
[7494]194        // Sets the Pickup to used if the Pickup has activation type 'immediate' and gets picked up.
[7163]195        if(this->isPickedUp() && this->isImmediate())
[6475]196            this->setUsed(true);
197    }
[6709]198
[6475]199    /**
200    @brief
[7494]201        Creates a duplicate of the OrxonoxClass.
202    @param item
203        A reference to the pointer of the item that we're duplicating.
[6474]204    */
[6497]205    void Pickup::clone(OrxonoxClass*& item)
[6474]206    {
207        if(item == NULL)
208            item = new Pickup(this);
[6709]209
[6474]210        SUPER(Pickup, clone, item);
[6709]211
[6474]212        Pickup* pickup = dynamic_cast<Pickup*>(item);
213        pickup->setActivationTypeDirect(this->getActivationTypeDirect());
214        pickup->setDurationTypeDirect(this->getDurationTypeDirect());
[6709]215
[6474]216        pickup->initializeIdentifier();
217    }
[6709]218
[6475]219    /**
220    @brief
221        Facilitates the creation of a PickupSpawner upon dropping of the Pickupable.
222        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.:
223        DroppedPickup(BaseObject* creator, Pickupable* pickup, const Vector3& position);
224    @return
225        Returns true if a spawner was created, false if not.
226    */
[6540]227    bool Pickup::createSpawner(void)
[6474]228    {
[6540]229        new DroppedPickup(this, this, this->getCarrier());
[6475]230        return true;
[6474]231    }
[6709]232
[6474]233}
Note: See TracBrowser for help on using the repository browser.