Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/pickup3/src/modules/pickup/items/TestPickup.cc @ 6517

Last change on this file since 6517 was 6517, checked in by dafrick, 15 years ago

TestPickup now more universal, as it accepts all PickupCarriers as its target.

File size: 4.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#include "core/CoreIncludes.h"
30#include "core/XMLPort.h"
31#include "interfaces/PickupCarrier.h"
32#include "pickup/PickupIdentifier.h"
33
34#include "TestPickup.h"
35
36namespace orxonox {
37 
38    CreateFactory(TestPickup);
39   
40    /*static*/ const std::string TestPickup::testTypeNone_s = "none";
41    /*static*/ const std::string TestPickup::testTypeUse_s = "use";
42    /*static*/ const std::string TestPickup::testTypeDrop_s = "drop";
43   
44    TestPickup::TestPickup(BaseObject* creator) : Pickup(creator)
45    {
46        RegisterObject(TestPickup);
47       
48        this->addTarget(ClassIdentifier<PickupCarrier>::getIdentifier());
49        this->setActivationTypeDirect(pickupActivationType::immediate);
50        this->setDurationTypeDirect(pickupDurationType::once);
51        this->testType_ = pickupTestType::none;
52    }
53   
54    TestPickup::~TestPickup()
55    {
56       
57    }
58   
59    void TestPickup::initializeIdentifier(void)
60    {
61        std::string val = this->getTestType();
62        std::string type = "testType";
63        this->pickupIdentifier_->addParameter(type, val);
64    }
65   
66    void TestPickup::XMLPort(Element& xmlelement, orxonox::XMLPort::Mode mode)
67    {
68        SUPER(TestPickup, XMLPort, xmlelement, mode);
69       
70        XMLPortParam(TestPickup, "testType", setTestType, getTestType, xmlelement, mode);
71       
72        this->initializeIdentifier();
73    }
74   
75    void TestPickup::changedUsed(void)
76    {
77        SUPER(TestPickup, changedUsed);
78       
79        if(this->isUsed())
80        {
81            PickupCarrier* carrier = this->getCarrier();
82            if(this->getTestTypeDirect() != pickupTestType::none && carrier != NULL)
83            {
84                std::set<Pickupable*> pickups = carrier->getPickups();
85                for(std::set<Pickupable*>::iterator it = pickups.begin(); it != pickups.end(); it++)
86                {
87                    Pickup* pickup = dynamic_cast<Pickup*>(*it);
88                    if(this->getTestTypeDirect() == pickupTestType::use)
89                    {
90                        if(pickup != NULL && pickup != this && pickup->isOnUse() && !pickup->isUsed())
91                        {
92                            pickup->setUsed(true);
93                        }
94                    }
95                    if(this->getTestTypeDirect() == pickupTestType::drop)
96                    {
97                        if(pickup != NULL && pickup != this)
98                        {
99                            carrier->drop(pickup);
100                        }
101                    }
102                }
103            }
104            this->destroy();
105        }
106    }
107   
108    const std::string& TestPickup::getTestType(void)
109    {
110        switch(this->getTestTypeDirect())
111        {
112            case pickupTestType::none:
113                return TestPickup::testTypeNone_s;
114            case pickupTestType::use:
115                return TestPickup::testTypeUse_s;
116            case pickupTestType::drop:
117                return TestPickup::testTypeDrop_s;
118            default:
119                return BLANKSTRING;
120        }
121    }
122   
123    void TestPickup::setTestType(const std::string& type)
124    {
125        if(type == TestPickup::testTypeNone_s)
126        {
127            this->setTestTypeDirect(pickupTestType::none);
128        }
129        else if(type == TestPickup::testTypeUse_s)
130        {
131            this->setTestTypeDirect(pickupTestType::use);
132        }
133        else if(type == TestPickup::testTypeDrop_s)
134        {
135            this->setTestTypeDirect(pickupTestType::drop);
136        }
137    }
138   
139    void TestPickup::clone(OrxonoxClass*& item)
140    {
141        if(item == NULL)
142            item = new TestPickup(this);
143       
144        SUPER(TestPickup, clone, item);
145       
146        TestPickup* pickup = dynamic_cast<TestPickup*>(item);
147        pickup->setTestTypeDirect(this->getTestTypeDirect());
148       
149        pickup->initializeIdentifier();
150    }
151   
152}
Note: See TracBrowser for help on using the repository browser.