Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 10591 was 9667, checked in by landauf, 11 years ago

merged core6 back to trunk

  • Property svn:eol-style set to native
File size: 5.8 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
[9348]39#include "PickupSpawner.h"
[7494]40
[6474]41namespace orxonox
42{
[6709]43
[7533]44    //! Initializing the static strings.
[6474]45    /*static*/ const std::string Pickup::activationTypeImmediate_s = "immediate";
46    /*static*/ const std::string Pickup::activationTypeOnUse_s = "onUse";
47    /*static*/ const std::string Pickup::durationTypeOnce_s = "once";
48    /*static*/ const std::string Pickup::durationTypeContinuous_s = "continuous";
[6709]49
[9667]50    RegisterUnloadableClass(Pickup);
[7163]51
[7494]52    /**
53    @brief
54        Constructor. Registers and initializes the object.
55    @param creator
56        The objects creator.
57    */
[9667]58    Pickup::Pickup(Context* context) : BaseObject(context)
[6474]59    {
60        RegisterObject(Pickup);
[6709]61
[6475]62        this->initialize();
[6474]63    }
[6709]64
[7494]65    /**
66    @brief
67        Destructor.
68    */
[6474]69    Pickup::~Pickup()
70    {
[6709]71
[6474]72    }
[6709]73
[6475]74    /**
75    @brief
76        Initializes the member variables.
77    */
78    void Pickup::initialize(void)
79    {
80        this->activationType_ = pickupActivationType::immediate;
81        this->durationType_ = pickupDurationType::once;
82    }
[6709]83
[6475]84    /**
85    @brief
86        Method for creating a Pickup object through XML.
87    */
[6474]88    void Pickup::XMLPort(Element& xmlelement, XMLPort::Mode mode)
89    {
90        SUPER(Pickup, XMLPort, xmlelement, mode);
91
[9348]92        XMLPortParam(Pickup, "representation", setRepresentationName, getRepresentationName, xmlelement, mode);
93        XMLPortParam(Pickup, "activationType", setActivationTypeAsString, getActivationTypeAsString, xmlelement, mode);
94        XMLPortParam(Pickup, "durationType", setDurationTypeAsString, getDurationTypeAsString, xmlelement, mode);
[6474]95    }
[6709]96
[6474]97    /**
98    @brief
99        Get the activation type of the pickup.
[6475]100    @return
101        Returns a string containing the activation type.
[6474]102    */
[9348]103    const std::string& Pickup::getActivationTypeAsString(void) const
[6474]104    {
[9348]105        switch(this->getActivationType())
[6474]106        {
107            case pickupActivationType::immediate:
108                return activationTypeImmediate_s;
109            case pickupActivationType::onUse:
110                return activationTypeOnUse_s;
111            default:
[6475]112                return BLANKSTRING;
[6474]113        }
114    }
[6709]115
[6474]116    /**
117    @brief
118        Get the duration type of the pickup.
[6475]119    @return
120        Returns a string containing the duration type.
[6474]121    */
[9348]122    const std::string& Pickup::getDurationTypeAsString(void) const
[6474]123    {
[9348]124        switch(this->getDurationType())
[6474]125        {
126            case pickupDurationType::once:
127                return durationTypeOnce_s;
128            case pickupDurationType::continuous:
129                return durationTypeContinuous_s;
130            default:
[6475]131                return BLANKSTRING;
[6474]132        }
133    }
[6709]134
[6474]135    /**
136    @brief
137        Set the activation type of the Pickup.
138    @param type
139        The activation type of the Pickup as a string.
140    */
[9348]141    void Pickup::setActivationTypeAsString(const std::string& type)
[6474]142    {
[8864]143        if(type == Pickup::activationTypeImmediate_s)
[9348]144            this->setActivationType(pickupActivationType::immediate);
[8864]145        else if(type == Pickup::activationTypeOnUse_s)
[9348]146            this->setActivationType(pickupActivationType::onUse);
[6474]147        else
[8864]148            orxout(internal_error, context::pickups) << "Invalid activationType '" << type << "' in " << this->getIdentifier()->getName() << "." << endl;
[6474]149    }
[6709]150
[6474]151    /**
152    @brief
153        Set the duration type of the Pickup.
154    @param type
155        The duration type of the Pickup as a string.
156    */
[9348]157    void Pickup::setDurationTypeAsString(const std::string& type)
[6474]158    {
[8864]159        if(type == Pickup::durationTypeOnce_s)
[9348]160            this->setDurationType(pickupDurationType::once);
[8864]161        else if(type == Pickup::durationTypeContinuous_s)
[9348]162            this->setDurationType(pickupDurationType::continuous);
[6474]163        else
[8864]164            orxout(internal_error, context::pickups) << "Invalid durationType '" << type << "' in " << this->getIdentifier()->getName() << "." << endl;
[6474]165    }
[6709]166
[6474]167    /**
168    @brief
[6475]169        Should be called when the pickup has transited from picked up to dropped or the other way around.
[6521]170        Any Class overwriting this method must call its SUPER function by adding SUPER(Classname, changedPickedUp); to their changedPickedUp method.
[6475]171    */
[6521]172    void Pickup::changedPickedUp(void)
[6475]173    {
[6521]174        SUPER(Pickup, changedPickedUp);
[6709]175
[7494]176        // Sets the Pickup to used if the Pickup has activation type 'immediate' and gets picked up.
[7163]177        if(this->isPickedUp() && this->isImmediate())
[6475]178            this->setUsed(true);
179    }
[6709]180
[6475]181    /**
182    @brief
183        Facilitates the creation of a PickupSpawner upon dropping of the Pickupable.
184    @return
185        Returns true if a spawner was created, false if not.
186    */
[6540]187    bool Pickup::createSpawner(void)
[6474]188    {
[9667]189        PickupSpawner::createDroppedPickup(this->getContext(), this, this->getCarrier());
[6475]190        return true;
[6474]191    }
[6709]192
[6474]193}
Note: See TracBrowser for help on using the repository browser.