Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/doc/src/modules/pickup/Pickup.cc @ 7374

Last change on this file since 7374 was 7297, checked in by landauf, 14 years ago

fixed lots of Doxygen warnings

Note: Doxygen prints a warning if only a part of the parameters of a function are documented.

Added documentation for missing parameters (as good as I could), removed documentation of obsolete parameters and fixed names of renamed parameters.
Some parameters are tagged with "FIXME", please replace this with an appropriate documentation if you know what it does.

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