Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 10341 was 9667, checked in by landauf, 11 years ago

merged core6 back to trunk

  • Property svn:eol-style set to native
File size: 6.5 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
[9348]81        this->setDurationType(pickupDurationType::once);
[6538]82        this->metaType_ = pickupMetaType::none;
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.
106        if(this->isUsed() && this->metaType_ != pickupMetaType::none)
[6512]107        {
108            PickupCarrier* carrier = this->getCarrier();
[9348]109            if(this->getMetaType() != pickupMetaType::none && carrier != NULL)
[6512]110            {
[7547]111                // If the metaType is destroyCarrier, then the PickupCarrier is destroyed.
[9348]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.
[6512]120                for(std::set<Pickupable*>::iterator it = pickups.begin(); it != pickups.end(); it++)
121                {
[7547]122                    Pickupable* pickup = (*it);
123                    if(pickup == NULL || pickup == this)
124                        continue;
125
126                    // If the metaType is use, then the Pickupable is set to used.
[9348]127                    if(this->getMetaType() == pickupMetaType::use && !pickup->isUsed())
[6512]128                    {
[7547]129                        pickup->setUsed(true);
[6512]130                    }
[7547]131                    // If the metaType is drop, then the Pickupable is dropped.
[9348]132                    else if(this->getMetaType() == pickupMetaType::drop)
[6512]133                    {
[7547]134                        pickup->drop();
[6512]135                    }
[7547]136                    // If the metaType is destroy, then the Pickupable is destroyed.
[9348]137                    else if(this->getMetaType() == pickupMetaType::destroy)
[7163]138                    {
[7547]139                        pickup->Pickupable::destroy();
[7163]140                    }
[6512]141                }
142            }
[7163]143            this->Pickupable::destroy();
[6512]144        }
145    }
[7163]146
[6538]147    /**
148    @brief
149        Get the meta type of this MetaPickup.
150    @return
151        Returns a string with the meta type of the MetaPickup.
152    */
[9348]153    const std::string& MetaPickup::getMetaTypeAsString(void) const
[6512]154    {
[9348]155        switch(this->getMetaType())
[6512]156        {
[6518]157            case pickupMetaType::none:
158                return MetaPickup::metaTypeNone_s;
159            case pickupMetaType::use:
160                return MetaPickup::metaTypeUse_s;
161            case pickupMetaType::drop:
162                return MetaPickup::metaTypeDrop_s;
[7163]163            case pickupMetaType::destroy:
164                return MetaPickup::metaTypeDestroy_s;
165            case pickupMetaType::destroyCarrier:
166                return MetaPickup::metaTypeDestroyCarrier_s;
[6512]167            default:
168                return BLANKSTRING;
169        }
170    }
[7163]171
[6538]172    /**
173    @brief
174        Set the meta type of this MetaPickup.
175    @param type
176        A string with the type to be set.
177    */
[9348]178    void MetaPickup::setMetaTypeAsString(const std::string& type)
[6512]179    {
[6518]180        if(type == MetaPickup::metaTypeNone_s)
[6512]181        {
[9348]182            this->setMetaType(pickupMetaType::none);
[6512]183        }
[6518]184        else if(type == MetaPickup::metaTypeUse_s)
[6512]185        {
[9348]186            this->setMetaType(pickupMetaType::use);
[6512]187        }
[6518]188        else if(type == MetaPickup::metaTypeDrop_s)
[6512]189        {
[9348]190            this->setMetaType(pickupMetaType::drop);
[6512]191        }
[7163]192        else if(type == MetaPickup::metaTypeDestroy_s)
193        {
[9348]194            this->setMetaType(pickupMetaType::destroy);
[7163]195        }
196        else if(type == MetaPickup::metaTypeDestroyCarrier_s)
197        {
[9348]198            this->setMetaType(pickupMetaType::destroyCarrier);
[7163]199        }
200        else
[8858]201            orxout(internal_warning, context::pickups) << "Invalid metaType '" << type << "' in MetaPickup." << endl;
[6512]202    }
[7163]203
[6512]204}
Note: See TracBrowser for help on using the repository browser.