Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 12103 was 11099, checked in by muemart, 9 years ago

Fix loads of doxygen warnings and other documentation issues

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