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 | * Eric Beier |
---|
24 | * Co-authors: |
---|
25 | * ... |
---|
26 | * |
---|
27 | */ |
---|
28 | |
---|
29 | /** |
---|
30 | @file ShieldPickup.cc |
---|
31 | @brief Implementation of the ShieldPickup class. |
---|
32 | */ |
---|
33 | |
---|
34 | #include "ShieldPickup.h" |
---|
35 | |
---|
36 | #include "core/CoreIncludes.h" |
---|
37 | #include "core/XMLPort.h" |
---|
38 | #include "util/StringUtils.h" |
---|
39 | |
---|
40 | #include "worldentities/pawns/SpaceShip.h" |
---|
41 | #include "items/Engine.h" |
---|
42 | #include "pickup/PickupIdentifier.h" |
---|
43 | |
---|
44 | #include <sstream> |
---|
45 | |
---|
46 | |
---|
47 | namespace orxonox |
---|
48 | { |
---|
49 | CreateFactory(ShieldPickup); |
---|
50 | |
---|
51 | /** |
---|
52 | @brief |
---|
53 | Constructor. Registers the object and initializes the member variables. |
---|
54 | */ |
---|
55 | ShieldPickup::ShieldPickup(BaseObject* creator) : Pickup(creator) |
---|
56 | { |
---|
57 | RegisterObject(ShieldPickup); |
---|
58 | |
---|
59 | this->initialize(); |
---|
60 | } |
---|
61 | |
---|
62 | /** |
---|
63 | @brief |
---|
64 | Destructor. |
---|
65 | */ |
---|
66 | ShieldPickup::~ShieldPickup() |
---|
67 | { |
---|
68 | |
---|
69 | } |
---|
70 | |
---|
71 | /** |
---|
72 | @brief |
---|
73 | Initializes the member variables. |
---|
74 | */ |
---|
75 | void ShieldPickup::initialize(void) |
---|
76 | { |
---|
77 | this->duration_ = 0.0f; |
---|
78 | |
---|
79 | this->addTarget(ClassIdentifier<Engine>::getIdentifier()); |
---|
80 | } |
---|
81 | |
---|
82 | /** |
---|
83 | @brief |
---|
84 | Initializes the PickupIdentifier of this pickup. |
---|
85 | */ |
---|
86 | void ShieldPickup::initializeIdentifier(void) |
---|
87 | { |
---|
88 | std::stringstream stream; |
---|
89 | stream << this->getDuration(); |
---|
90 | std::string type1 = "duration"; |
---|
91 | std::string val1 = stream.str(); |
---|
92 | this->pickupIdentifier_->addParameter(type1, val1); |
---|
93 | |
---|
94 | // stream.clear(); |
---|
95 | // stream << this->getShieldAdd(); |
---|
96 | // std::string type2 = "ShieldAdd"; |
---|
97 | // std::string val2 = stream.str(); |
---|
98 | // this->pickupIdentifier_->addParameter(type2, val2); |
---|
99 | |
---|
100 | } |
---|
101 | |
---|
102 | /** |
---|
103 | @brief |
---|
104 | Method for creating a ShieldPickup object through XML. |
---|
105 | */ |
---|
106 | void ShieldPickup::XMLPort(Element& xmlelement, orxonox::XMLPort::Mode mode) |
---|
107 | { |
---|
108 | SUPER(ShieldPickup, XMLPort, xmlelement, mode); |
---|
109 | |
---|
110 | XMLPortParam(ShieldPickup, "duration", setDuration, getDuration, xmlelement, mode); |
---|
111 | |
---|
112 | this->initializeIdentifier(); |
---|
113 | } |
---|
114 | |
---|
115 | /** |
---|
116 | @brief |
---|
117 | Is called when the pickup has transited from used to unused or the other way around. |
---|
118 | */ |
---|
119 | void ShieldPickup::changedUsed(void) |
---|
120 | { |
---|
121 | SUPER(ShieldPickup, changedUsed); |
---|
122 | |
---|
123 | //! If the pickup is not picked up nothing must be done. |
---|
124 | if(!this->isPickedUp()) |
---|
125 | return; |
---|
126 | } |
---|
127 | |
---|
128 | /** |
---|
129 | @brief |
---|
130 | Creates a duplicate of the input OrxonoxClass. |
---|
131 | @param item |
---|
132 | A pointer to the Orxonox class. |
---|
133 | */ |
---|
134 | void ShieldPickup::clone(OrxonoxClass*& item) |
---|
135 | { |
---|
136 | if(item == NULL) |
---|
137 | item = new ShieldPickup(this); |
---|
138 | |
---|
139 | SUPER(ShieldPickup, clone, item); |
---|
140 | |
---|
141 | ShieldPickup* pickup = dynamic_cast<ShieldPickup*>(item); |
---|
142 | pickup->setDuration(this->getDuration()); |
---|
143 | |
---|
144 | pickup->initializeIdentifier(); |
---|
145 | } |
---|
146 | |
---|
147 | /** |
---|
148 | @brief |
---|
149 | Sets the duration. |
---|
150 | @param duration |
---|
151 | The duration |
---|
152 | */ |
---|
153 | void ShieldPickup::setDuration(float duration) |
---|
154 | { |
---|
155 | if(duration >= 0.0f) |
---|
156 | { |
---|
157 | this->duration_ = duration; |
---|
158 | } |
---|
159 | else |
---|
160 | { |
---|
161 | COUT(1) << "Invalid duration in ShieldPickup." << std::endl; |
---|
162 | this->duration_ = 0.0f; |
---|
163 | } |
---|
164 | } |
---|
165 | |
---|
166 | void ShieldPickup::pickupTimerCallback(void) |
---|
167 | { |
---|
168 | this->setUsed(false); |
---|
169 | } |
---|
170 | } |
---|