Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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