Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/modules/pickup/items/MetaPickup.cc @ 12203

Last change on this file since 12203 was 11071, checked in by landauf, 9 years ago

merged branch cpp11_v3 back to trunk

  • Property svn:eol-style set to native
File size: 6.4 KB
RevLine 
[6512]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
[6519]29/**
[6538]30    @file MetaPickup.cc
[6519]31    @brief Implementation of the MetaPickup class.
32*/
33
[6512]34#include "core/CoreIncludes.h"
35#include "core/XMLPort.h"
[7547]36
[6512]37#include "interfaces/PickupCarrier.h"
[7547]38#include "worldentities/pawns/Pawn.h"
[6512]39
[6518]40#include "MetaPickup.h"
[6512]41
42namespace orxonox {
[7163]43
[9667]44    RegisterClass(MetaPickup);
[7163]45
[6538]46    //! Setting the static variables to their values.
[6518]47    /*static*/ const std::string MetaPickup::metaTypeNone_s = "none";
48    /*static*/ const std::string MetaPickup::metaTypeUse_s = "use";
49    /*static*/ const std::string MetaPickup::metaTypeDrop_s = "drop";
[7163]50    /*static*/ const std::string MetaPickup::metaTypeDestroy_s = "destroy";
51    /*static*/ const std::string MetaPickup::metaTypeDestroyCarrier_s = "destroyCarrier";
52
[6519]53    /**
54    @brief
[6538]55        Constructor. Registers and initializes the object.
[6519]56    */
[9667]57    MetaPickup::MetaPickup(Context* context) : Pickup(context)
[6512]58    {
[6518]59        RegisterObject(MetaPickup);
[7163]60
[6538]61        this->initialize();
[6512]62    }
[7163]63
[6538]64    /**
65    @brief
66        Destructor.
67    */
[6518]68    MetaPickup::~MetaPickup()
[6512]69    {
[7163]70
[6512]71    }
[7163]72
[6538]73    /**
74    @brief
75        Initializes the object.
76    */
77    void MetaPickup::initialize(void)
78    {
79        this->addTarget(ClassIdentifier<PickupCarrier>::getIdentifier());
[7163]80
[11071]81        this->setDurationType(PickupDurationType::once);
82        this->metaType_ = PickupMetaType::none;
[6538]83    }
[7163]84
[6538]85    /**
86    @brief
87        Method for creating a MetaPickup object through XML.
88    */
[6518]89    void MetaPickup::XMLPort(Element& xmlelement, orxonox::XMLPort::Mode mode)
[6512]90    {
[6518]91        SUPER(MetaPickup, XMLPort, xmlelement, mode);
[7163]92
[9348]93        XMLPortParam(MetaPickup, "metaType", setMetaTypeAsString, getMetaTypeAsString, xmlelement, mode);
[6512]94    }
[7163]95
[6538]96    /**
97    @brief
98        Is called when the pickup has transited from used to unused or the other way around.
99        Any Class overwriting this method must call its SUPER function by adding SUPER(Classname, changedUsed); to their changdeUsed method.
100    */
[6518]101    void MetaPickup::changedUsed(void)
[6512]102    {
[6518]103        SUPER(MetaPickup, changedUsed);
[7163]104
[7547]105        // If the MetaPickup transited to used, and the metaType is not none.
[11071]106        if(this->isUsed() && this->metaType_ != PickupMetaType::none)
[6512]107        {
108            PickupCarrier* carrier = this->getCarrier();
[11071]109            if(this->getMetaType() != PickupMetaType::none && carrier != nullptr)
[6512]110            {
[7547]111                // If the metaType is destroyCarrier, then the PickupCarrier is destroyed.
[11071]112                if(this->getMetaType() == PickupMetaType::destroyCarrier)
[7163]113                {
114                    Pawn* pawn = orxonox_cast<Pawn*>(carrier);
115                    pawn->kill();
116                    return;
117                }
[6512]118                std::set<Pickupable*> pickups = carrier->getPickups();
[7547]119                // Iterate over all Pickupables of the PickupCarrier.
[11071]120                for(Pickupable* pickup : pickups)
[6512]121                {
[11071]122                    if(pickup == nullptr || pickup == this)
[7547]123                        continue;
124
125                    // If the metaType is use, then the Pickupable is set to used.
[11071]126                    if(this->getMetaType() == PickupMetaType::use && !pickup->isUsed())
[6512]127                    {
[7547]128                        pickup->setUsed(true);
[6512]129                    }
[7547]130                    // If the metaType is drop, then the Pickupable is dropped.
[11071]131                    else if(this->getMetaType() == PickupMetaType::drop)
[6512]132                    {
[7547]133                        pickup->drop();
[6512]134                    }
[7547]135                    // If the metaType is destroy, then the Pickupable is destroyed.
[11071]136                    else if(this->getMetaType() == PickupMetaType::destroy)
[7163]137                    {
[7547]138                        pickup->Pickupable::destroy();
[7163]139                    }
[6512]140                }
141            }
[7163]142            this->Pickupable::destroy();
[6512]143        }
144    }
[7163]145
[6538]146    /**
147    @brief
148        Get the meta type of this MetaPickup.
149    @return
150        Returns a string with the meta type of the MetaPickup.
151    */
[9348]152    const std::string& MetaPickup::getMetaTypeAsString(void) const
[6512]153    {
[9348]154        switch(this->getMetaType())
[6512]155        {
[11071]156            case PickupMetaType::none:
[6518]157                return MetaPickup::metaTypeNone_s;
[11071]158            case PickupMetaType::use:
[6518]159                return MetaPickup::metaTypeUse_s;
[11071]160            case PickupMetaType::drop:
[6518]161                return MetaPickup::metaTypeDrop_s;
[11071]162            case PickupMetaType::destroy:
[7163]163                return MetaPickup::metaTypeDestroy_s;
[11071]164            case PickupMetaType::destroyCarrier:
[7163]165                return MetaPickup::metaTypeDestroyCarrier_s;
[6512]166            default:
167                return BLANKSTRING;
168        }
169    }
[7163]170
[6538]171    /**
172    @brief
173        Set the meta type of this MetaPickup.
174    @param type
175        A string with the type to be set.
176    */
[9348]177    void MetaPickup::setMetaTypeAsString(const std::string& type)
[6512]178    {
[6518]179        if(type == MetaPickup::metaTypeNone_s)
[6512]180        {
[11071]181            this->setMetaType(PickupMetaType::none);
[6512]182        }
[6518]183        else if(type == MetaPickup::metaTypeUse_s)
[6512]184        {
[11071]185            this->setMetaType(PickupMetaType::use);
[6512]186        }
[6518]187        else if(type == MetaPickup::metaTypeDrop_s)
[6512]188        {
[11071]189            this->setMetaType(PickupMetaType::drop);
[6512]190        }
[7163]191        else if(type == MetaPickup::metaTypeDestroy_s)
192        {
[11071]193            this->setMetaType(PickupMetaType::destroy);
[7163]194        }
195        else if(type == MetaPickup::metaTypeDestroyCarrier_s)
196        {
[11071]197            this->setMetaType(PickupMetaType::destroyCarrier);
[7163]198        }
199        else
[8858]200            orxout(internal_warning, context::pickups) << "Invalid metaType '" << type << "' in MetaPickup." << endl;
[6512]201    }
[7163]202
[6512]203}
Note: See TracBrowser for help on using the repository browser.