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 | * Oliver Scheuss |
---|
24 | * Co-authors: |
---|
25 | * ... |
---|
26 | * |
---|
27 | */ |
---|
28 | |
---|
29 | #include "SimpleRocket.h" |
---|
30 | |
---|
31 | #include <BulletDynamics/Dynamics/btRigidBody.h> |
---|
32 | |
---|
33 | #include "core/CoreIncludes.h" |
---|
34 | #include "core/XMLPort.h" |
---|
35 | #include "worldentities/pawns/Pawn.h" |
---|
36 | #include "graphics/ParticleSpawner.h" |
---|
37 | #include "graphics/Model.h" |
---|
38 | #include "objects/collisionshapes/ConeCollisionShape.h" |
---|
39 | #include "infos/PlayerInfo.h" |
---|
40 | #include "controllers/Controller.h" |
---|
41 | #include "weapons/RocketController.h" |
---|
42 | #include "sound/WorldSound.h" |
---|
43 | #include "util/Debug.h" |
---|
44 | |
---|
45 | namespace orxonox |
---|
46 | { |
---|
47 | CreateFactory(SimpleRocket); |
---|
48 | // create the factory for the SimpleRocket |
---|
49 | |
---|
50 | /** |
---|
51 | @brief |
---|
52 | Constructor. Registers the object and initializes some default values. |
---|
53 | */ |
---|
54 | SimpleRocket::SimpleRocket(BaseObject* creator) : ControllableEntity(creator) |
---|
55 | { |
---|
56 | RegisterObject(SimpleRocket);// - register the SimpleRocket class to the core |
---|
57 | |
---|
58 | this->localAngularVelocity_ = 0; |
---|
59 | this->bDestroy_ = false; |
---|
60 | this->lifetime_ = 100; |
---|
61 | COUT(0)<< "simplerocket constructed\n"; |
---|
62 | |
---|
63 | |
---|
64 | if (GameMode::isMaster()) |
---|
65 | { |
---|
66 | this->setCollisionType(WorldEntity::Kinematic); |
---|
67 | this->setVelocity(0,0,100); |
---|
68 | |
---|
69 | Model* model = new Model(this); |
---|
70 | model->setMeshSource("rocket.mesh"); |
---|
71 | model->scale(0.7f); |
---|
72 | this->attach(model); |
---|
73 | |
---|
74 | ParticleEmitter* fire = new ParticleEmitter(this); |
---|
75 | this->attach(fire); |
---|
76 | fire->setOrientation(this->getOrientation()); |
---|
77 | fire->setSource("Orxonox/rocketfire2"); |
---|
78 | |
---|
79 | this->enableCollisionCallback(); |
---|
80 | this->setCollisionResponse(false); |
---|
81 | this->setCollisionType(Kinematic); |
---|
82 | |
---|
83 | // TODO: fix the orientation and size of this collision shape to match the rocket |
---|
84 | ConeCollisionShape* collisionShape = new ConeCollisionShape(this); |
---|
85 | collisionShape->setRadius(3); |
---|
86 | collisionShape->setHeight(5); |
---|
87 | this->attachCollisionShape(collisionShape); |
---|
88 | |
---|
89 | this->destroyTimer_.setTimer(this->lifetime_, false, createExecutor(createFunctor(&SimpleRocket::destroyObject, this))); |
---|
90 | } |
---|
91 | |
---|
92 | } |
---|
93 | void SimpleRocket::tick(float dt) |
---|
94 | { |
---|
95 | SUPER(SimpleRocket, tick, dt); |
---|
96 | |
---|
97 | this->setAngularVelocity(this->getOrientation() * this->localAngularVelocity_); |
---|
98 | this->setVelocity( this->getOrientation()*WorldEntity::FRONT*this->getVelocity().length() ); |
---|
99 | this->localAngularVelocity_ = 0; |
---|
100 | |
---|
101 | if( this->bDestroy_ ) |
---|
102 | this->destroy(); |
---|
103 | |
---|
104 | } |
---|
105 | |
---|
106 | /**s |
---|
107 | @brief |
---|
108 | Destructor. Destroys controller, if present and kills sounds, if playing. |
---|
109 | */ |
---|
110 | SimpleRocket::~SimpleRocket() |
---|
111 | { |
---|
112 | if (this->isInitialized()) { |
---|
113 | this->getController()->destroy(); |
---|
114 | COUT(0)<< "simplerocket destroyed\n"; |
---|
115 | } |
---|
116 | } |
---|
117 | |
---|
118 | /** |
---|
119 | @brief |
---|
120 | Method for creating a SimpleRocket through XML. |
---|
121 | */ |
---|
122 | void SimpleRocket::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
123 | { |
---|
124 | // this calls the XMLPort function of the parent class |
---|
125 | SUPER(SimpleRocket, XMLPort, xmlelement, mode); |
---|
126 | } |
---|
127 | |
---|
128 | void SimpleRocket::setOwner(Pawn* owner) |
---|
129 | { |
---|
130 | this->owner_ = owner; |
---|
131 | //this->originalControllableEntity_ = this->owner_->getPlayer()->getControllableEntity(); |
---|
132 | this->player_ = this->owner_->getPlayer(); |
---|
133 | } |
---|
134 | |
---|
135 | |
---|
136 | bool SimpleRocket::collidesAgainst(WorldEntity* otherObject, btManifoldPoint& contactPoint) |
---|
137 | { |
---|
138 | if (!this->bDestroy_ && GameMode::isMaster()) |
---|
139 | { |
---|
140 | if (otherObject == this->owner_) |
---|
141 | return false; |
---|
142 | |
---|
143 | this->bDestroy_ = true; |
---|
144 | |
---|
145 | if (this->owner_) |
---|
146 | { |
---|
147 | { |
---|
148 | ParticleSpawner* effect = new ParticleSpawner(this->owner_->getCreator()); |
---|
149 | effect->setPosition(this->getPosition()); |
---|
150 | effect->setOrientation(this->getOrientation()); |
---|
151 | effect->setDestroyAfterLife(true); |
---|
152 | effect->setSource("Orxonox/explosion4"); |
---|
153 | effect->setLifetime(2.0f); |
---|
154 | } |
---|
155 | |
---|
156 | { |
---|
157 | ParticleSpawner* effect = new ParticleSpawner(this->owner_->getCreator()); |
---|
158 | effect->setPosition(this->getPosition()); |
---|
159 | effect->setOrientation(this->getOrientation()); |
---|
160 | effect->setDestroyAfterLife(true); |
---|
161 | effect->setSource("Orxonox/smoke4"); |
---|
162 | effect->setLifetime(3.0f); |
---|
163 | } |
---|
164 | } |
---|
165 | |
---|
166 | float dmg = this->damage_; |
---|
167 | if (this->owner_) |
---|
168 | dmg = this->owner_->getPickups().processModifiers(ModifierType::Damage, dmg, false); |
---|
169 | |
---|
170 | Pawn* victim = orxonox_cast<Pawn*>(otherObject); |
---|
171 | if (victim) |
---|
172 | victim->hit(this->owner_, contactPoint, dmg); |
---|
173 | } |
---|
174 | return false; |
---|
175 | } |
---|
176 | |
---|
177 | void SimpleRocket::destroyObject() |
---|
178 | { |
---|
179 | if (GameMode::isMaster()) |
---|
180 | { |
---|
181 | this->destroy(); |
---|
182 | } |
---|
183 | } |
---|
184 | void SimpleRocket::setDestroy() { |
---|
185 | this->bDestroy_=true; |
---|
186 | COUT(0)<<"trying to destroy"; |
---|
187 | } |
---|
188 | |
---|
189 | void SimpleRocket::fired(unsigned int firemode) |
---|
190 | { |
---|
191 | if (this->owner_) |
---|
192 | { |
---|
193 | { |
---|
194 | ParticleSpawner* effect = new ParticleSpawner(this->owner_->getCreator()); |
---|
195 | effect->setPosition(this->getPosition()); |
---|
196 | effect->setOrientation(this->getOrientation()); |
---|
197 | effect->setDestroyAfterLife(true); |
---|
198 | effect->setSource("Orxonox/explosion4"); |
---|
199 | effect->setLifetime(2.0f); |
---|
200 | } |
---|
201 | |
---|
202 | { |
---|
203 | ParticleSpawner* effect = new ParticleSpawner(this->owner_->getCreator()); |
---|
204 | effect->setPosition(this->getPosition()); |
---|
205 | effect->setOrientation(this->getOrientation()); |
---|
206 | effect->setDestroyAfterLife(true); |
---|
207 | effect->setSource("Orxonox/smoke4"); |
---|
208 | effect->setLifetime(3.0f); |
---|
209 | } |
---|
210 | this->destroy(); |
---|
211 | } |
---|
212 | } |
---|
213 | |
---|
214 | /** |
---|
215 | @brief |
---|
216 | Rotates the SimpleRocket around the y-axis by the amount specified by the first component of the input 2-dim vector. |
---|
217 | @param value |
---|
218 | The vector determining the amount of the angular movement. |
---|
219 | */ |
---|
220 | void SimpleRocket::rotateYaw(const Vector2& value) |
---|
221 | { |
---|
222 | ControllableEntity::rotateYaw(value); |
---|
223 | |
---|
224 | if( !this->isInMouseLook() ) |
---|
225 | this->localAngularVelocity_.y += value.x; |
---|
226 | } |
---|
227 | |
---|
228 | /** |
---|
229 | @brief |
---|
230 | Rotates the SimpleRocket around the x-axis by the amount specified by the first component of the input 2-dim vector. |
---|
231 | @param value |
---|
232 | The vector determining the amount of the angular movement. |
---|
233 | */ |
---|
234 | void SimpleRocket::rotatePitch(const Vector2& value) |
---|
235 | { |
---|
236 | ControllableEntity::rotatePitch(value); |
---|
237 | |
---|
238 | if( !this->isInMouseLook() ) |
---|
239 | this->localAngularVelocity_.x += value.x; |
---|
240 | } |
---|
241 | |
---|
242 | /** |
---|
243 | @brief |
---|
244 | Rotates the SimpleRocket around the z-axis by the amount specified by the first component of the input 2-dim vector. |
---|
245 | @param value |
---|
246 | The vector determining the amount of the angular movement. |
---|
247 | */ |
---|
248 | void SimpleRocket::rotateRoll(const Vector2& value) |
---|
249 | { |
---|
250 | ControllableEntity::rotateRoll(value); |
---|
251 | |
---|
252 | if( !this->isInMouseLook() ) |
---|
253 | this->localAngularVelocity_.z += value.x; |
---|
254 | } |
---|
255 | |
---|
256 | } |
---|