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