Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 7621 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
Line 
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
29/**
30    @file Pickup.cc
31    @brief Implementation of the Pickup class.
32*/
33
34#include "Pickup.h"
35
36#include "core/CoreIncludes.h"
37#include "util/StringUtils.h"
38#include "pickup/PickupIdentifier.h"
39#include "DroppedPickup.h"
40
41#include "tools/Timer.h"
42
43namespace orxonox
44{
45
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";
50
51    CreateUnloadableFactory(Pickup);
52
53    Pickup::Pickup(BaseObject* creator) : BaseObject(creator)
54    {
55        RegisterObject(Pickup);
56
57        this->initialize();
58    }
59
60    Pickup::~Pickup()
61    {
62
63    }
64
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    }
74
75    /**
76    @brief
77        Initializes the PickupIdentififer of this Pickup.
78    */
79    void Pickup::initializeIdentifier(void)
80    {
81        std::string val1 = this->getActivationType();
82        std::string type1 = "activationType";
83        this->pickupIdentifier_->addParameter(type1, val1);
84
85        std::string val2 = this->getDurationType();
86        std::string type2 = "durationType";
87        this->pickupIdentifier_->addParameter(type2, val2);
88    }
89
90    /**
91    @brief
92        Method for creating a Pickup object through XML.
93    */
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);
100
101        this->initializeIdentifier();
102    }
103
104    /**
105    @brief
106        Get the activation type of the pickup.
107    @return
108        Returns a string containing the activation type.
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:
119                return BLANKSTRING;
120        }
121    }
122
123    /**
124    @brief
125        Get the duration type of the pickup.
126    @return
127        Returns a string containing the duration type.
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:
138                return BLANKSTRING;
139        }
140    }
141
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    {
150        if(Pickup::activationTypeImmediate_s.compare(type) == 0)
151        {
152            this->activationType_ = pickupActivationType::immediate;
153        }
154        else if(Pickup::activationTypeOnUse_s.compare(type) == 0)
155        {
156            this->activationType_ = pickupActivationType::onUse;
157        }
158        else
159        {
160            COUT(1) << "Invalid activationType in pickup." << std::endl;
161        }
162    }
163
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    {
172        if(Pickup::durationTypeOnce_s.compare(type) == 0)
173        {
174            this->durationType_ = pickupDurationType::once;
175        }
176        else if(Pickup::durationTypeContinuous_s.compare(type) == 0)
177        {
178            this->durationType_ = pickupDurationType::continuous;
179        }
180        else
181        {
182            COUT(1) << "Invalid durationType in pickup." << std::endl;
183        }
184    }
185
186    /**
187    @brief
188        Should be called when the pickup has transited from picked up to dropped or the other way around.
189        Any Class overwriting this method must call its SUPER function by adding SUPER(Classname, changedPickedUp); to their changedPickedUp method.
190    */
191    void Pickup::changedPickedUp(void)
192    {
193        SUPER(Pickup, changedPickedUp);
194
195        //! Sets the Pickup to used if the Pickup has activation type 'immediate' and gets picked up.
196        if(this->isPickedUp() && this->isImmediate())
197        {
198            this->setUsed(true);
199        }
200    }
201
202    /**
203    @brief
204        Creates a duplicate of the Pickup.
205    @return
206        Returns the clone of this pickup as a pointer to a Pickupable.
207    */
208    void Pickup::clone(OrxonoxClass*& item)
209    {
210        if(item == NULL)
211            item = new Pickup(this);
212
213        SUPER(Pickup, clone, item);
214
215        Pickup* pickup = dynamic_cast<Pickup*>(item);
216        pickup->setActivationTypeDirect(this->getActivationTypeDirect());
217        pickup->setDurationTypeDirect(this->getDurationTypeDirect());
218
219        pickup->initializeIdentifier();
220    }
221
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    */
230    bool Pickup::createSpawner(void)
231    {
232        new DroppedPickup(this, this, this->getCarrier());
233        return true;
234    }
235
236}
Note: See TracBrowser for help on using the repository browser.