Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 9696 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
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    @param creator
56        The objects creator.
57    */
58    Pickup::Pickup(Context* context) : BaseObject(context)
59    {
60        RegisterObject(Pickup);
61
62        this->initialize();
63    }
64
65    /**
66    @brief
67        Destructor.
68    */
69    Pickup::~Pickup()
70    {
71
72    }
73
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    }
83
84    /**
85    @brief
86        Method for creating a Pickup object through XML.
87    */
88    void Pickup::XMLPort(Element& xmlelement, XMLPort::Mode mode)
89    {
90        SUPER(Pickup, XMLPort, xmlelement, mode);
91
92        XMLPortParam(Pickup, "representation", setRepresentationName, getRepresentationName, xmlelement, mode);
93        XMLPortParam(Pickup, "activationType", setActivationTypeAsString, getActivationTypeAsString, xmlelement, mode);
94        XMLPortParam(Pickup, "durationType", setDurationTypeAsString, getDurationTypeAsString, xmlelement, mode);
95    }
96
97    /**
98    @brief
99        Get the activation type of the pickup.
100    @return
101        Returns a string containing the activation type.
102    */
103    const std::string& Pickup::getActivationTypeAsString(void) const
104    {
105        switch(this->getActivationType())
106        {
107            case pickupActivationType::immediate:
108                return activationTypeImmediate_s;
109            case pickupActivationType::onUse:
110                return activationTypeOnUse_s;
111            default:
112                return BLANKSTRING;
113        }
114    }
115
116    /**
117    @brief
118        Get the duration type of the pickup.
119    @return
120        Returns a string containing the duration type.
121    */
122    const std::string& Pickup::getDurationTypeAsString(void) const
123    {
124        switch(this->getDurationType())
125        {
126            case pickupDurationType::once:
127                return durationTypeOnce_s;
128            case pickupDurationType::continuous:
129                return durationTypeContinuous_s;
130            default:
131                return BLANKSTRING;
132        }
133    }
134
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    */
141    void Pickup::setActivationTypeAsString(const std::string& type)
142    {
143        if(type == Pickup::activationTypeImmediate_s)
144            this->setActivationType(pickupActivationType::immediate);
145        else if(type == Pickup::activationTypeOnUse_s)
146            this->setActivationType(pickupActivationType::onUse);
147        else
148            orxout(internal_error, context::pickups) << "Invalid activationType '" << type << "' in " << this->getIdentifier()->getName() << "." << endl;
149    }
150
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    */
157    void Pickup::setDurationTypeAsString(const std::string& type)
158    {
159        if(type == Pickup::durationTypeOnce_s)
160            this->setDurationType(pickupDurationType::once);
161        else if(type == Pickup::durationTypeContinuous_s)
162            this->setDurationType(pickupDurationType::continuous);
163        else
164            orxout(internal_error, context::pickups) << "Invalid durationType '" << type << "' in " << this->getIdentifier()->getName() << "." << endl;
165    }
166
167    /**
168    @brief
169        Should be called when the pickup has transited from picked up to dropped or the other way around.
170        Any Class overwriting this method must call its SUPER function by adding SUPER(Classname, changedPickedUp); to their changedPickedUp method.
171    */
172    void Pickup::changedPickedUp(void)
173    {
174        SUPER(Pickup, changedPickedUp);
175
176        // Sets the Pickup to used if the Pickup has activation type 'immediate' and gets picked up.
177        if(this->isPickedUp() && this->isImmediate())
178            this->setUsed(true);
179    }
180
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    */
187    bool Pickup::createSpawner(void)
188    {
189        PickupSpawner::createDroppedPickup(this->getContext(), this, this->getCarrier());
190        return true;
191    }
192
193}
Note: See TracBrowser for help on using the repository browser.