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(4) << "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 | |
---|
94 | void SimpleRocket::tick(float dt) |
---|
95 | { |
---|
96 | SUPER(SimpleRocket, tick, dt); |
---|
97 | |
---|
98 | this->setAngularVelocity(this->getOrientation() * this->localAngularVelocity_); |
---|
99 | this->setVelocity( this->getOrientation()*WorldEntity::FRONT*this->getVelocity().length() ); |
---|
100 | this->localAngularVelocity_ = 0; |
---|
101 | |
---|
102 | if( this->bDestroy_ ) |
---|
103 | this->destroy(); |
---|
104 | |
---|
105 | } |
---|
106 | |
---|
107 | /**s |
---|
108 | @brief |
---|
109 | Destructor. Destroys controller, if present and kills sounds, if playing. |
---|
110 | */ |
---|
111 | SimpleRocket::~SimpleRocket() |
---|
112 | { |
---|
113 | if (this->isInitialized()) |
---|
114 | { |
---|
115 | this->getController()->destroy(); |
---|
116 | COUT(4)<< "simplerocket destroyed\n"; |
---|
117 | } |
---|
118 | } |
---|
119 | |
---|
120 | /** |
---|
121 | @brief |
---|
122 | Method for creating a SimpleRocket through XML. |
---|
123 | */ |
---|
124 | void SimpleRocket::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
125 | { |
---|
126 | // this calls the XMLPort function of the parent class |
---|
127 | SUPER(SimpleRocket, XMLPort, xmlelement, mode); |
---|
128 | } |
---|
129 | |
---|
130 | void SimpleRocket::setOwner(Pawn* owner) |
---|
131 | { |
---|
132 | this->owner_ = owner; |
---|
133 | //this->originalControllableEntity_ = this->owner_->getPlayer()->getControllableEntity(); |
---|
134 | this->player_ = this->owner_->getPlayer(); |
---|
135 | } |
---|
136 | |
---|
137 | |
---|
138 | bool SimpleRocket::collidesAgainst(WorldEntity* otherObject, btManifoldPoint& contactPoint) |
---|
139 | { |
---|
140 | if (!this->bDestroy_ && GameMode::isMaster()) |
---|
141 | { |
---|
142 | if (otherObject == this->owner_) |
---|
143 | return false; |
---|
144 | |
---|
145 | this->bDestroy_ = true; |
---|
146 | |
---|
147 | if (this->owner_) |
---|
148 | { |
---|
149 | { |
---|
150 | ParticleSpawner* effect = new ParticleSpawner(this->owner_->getCreator()); |
---|
151 | effect->setPosition(this->getPosition()); |
---|
152 | effect->setOrientation(this->getOrientation()); |
---|
153 | effect->setDestroyAfterLife(true); |
---|
154 | effect->setSource("Orxonox/explosion4"); |
---|
155 | effect->setLifetime(2.0f); |
---|
156 | } |
---|
157 | |
---|
158 | { |
---|
159 | ParticleSpawner* effect = new ParticleSpawner(this->owner_->getCreator()); |
---|
160 | effect->setPosition(this->getPosition()); |
---|
161 | effect->setOrientation(this->getOrientation()); |
---|
162 | effect->setDestroyAfterLife(true); |
---|
163 | effect->setSource("Orxonox/smoke4"); |
---|
164 | effect->setLifetime(3.0f); |
---|
165 | } |
---|
166 | } |
---|
167 | |
---|
168 | float dmg = this->damage_; |
---|
169 | // if (this->owner_) |
---|
170 | // dmg = this->owner_->getPickups().processModifiers(ModifierType::Damage, dmg, false); |
---|
171 | |
---|
172 | Pawn* victim = orxonox_cast<Pawn*>(otherObject); |
---|
173 | if (victim) |
---|
174 | victim->hit(this->owner_, contactPoint, dmg); |
---|
175 | } |
---|
176 | return false; |
---|
177 | } |
---|
178 | |
---|
179 | void SimpleRocket::destroyObject() |
---|
180 | { |
---|
181 | if (GameMode::isMaster()) |
---|
182 | { |
---|
183 | this->destroy(); |
---|
184 | } |
---|
185 | } |
---|
186 | |
---|
187 | void SimpleRocket::setDestroy() |
---|
188 | { |
---|
189 | this->bDestroy_=true; |
---|
190 | CCOUT(4)<<"trying to destroy"; |
---|
191 | } |
---|
192 | |
---|
193 | void SimpleRocket::fired(unsigned int firemode) |
---|
194 | { |
---|
195 | if (this->owner_) |
---|
196 | { |
---|
197 | { |
---|
198 | ParticleSpawner* effect = new ParticleSpawner(this->owner_->getCreator()); |
---|
199 | effect->setPosition(this->getPosition()); |
---|
200 | effect->setOrientation(this->getOrientation()); |
---|
201 | effect->setDestroyAfterLife(true); |
---|
202 | effect->setSource("Orxonox/explosion4"); |
---|
203 | effect->setLifetime(2.0f); |
---|
204 | } |
---|
205 | |
---|
206 | { |
---|
207 | ParticleSpawner* effect = new ParticleSpawner(this->owner_->getCreator()); |
---|
208 | effect->setPosition(this->getPosition()); |
---|
209 | effect->setOrientation(this->getOrientation()); |
---|
210 | effect->setDestroyAfterLife(true); |
---|
211 | effect->setSource("Orxonox/smoke4"); |
---|
212 | effect->setLifetime(3.0f); |
---|
213 | } |
---|
214 | this->destroy(); |
---|
215 | } |
---|
216 | } |
---|
217 | |
---|
218 | /** |
---|
219 | @brief |
---|
220 | Rotates the SimpleRocket around the y-axis by the amount specified by the first component of the input 2-dim vector. |
---|
221 | @param value |
---|
222 | The vector determining the amount of the angular movement. |
---|
223 | */ |
---|
224 | void SimpleRocket::rotateYaw(const Vector2& value) |
---|
225 | { |
---|
226 | ControllableEntity::rotateYaw(value); |
---|
227 | |
---|
228 | if( !this->isInMouseLook() ) |
---|
229 | this->localAngularVelocity_.y += value.x; |
---|
230 | } |
---|
231 | |
---|
232 | /** |
---|
233 | @brief |
---|
234 | Rotates the SimpleRocket around the x-axis by the amount specified by the first component of the input 2-dim vector. |
---|
235 | @param value |
---|
236 | The vector determining the amount of the angular movement. |
---|
237 | */ |
---|
238 | void SimpleRocket::rotatePitch(const Vector2& value) |
---|
239 | { |
---|
240 | ControllableEntity::rotatePitch(value); |
---|
241 | |
---|
242 | if( !this->isInMouseLook() ) |
---|
243 | this->localAngularVelocity_.x += value.x; |
---|
244 | } |
---|
245 | |
---|
246 | /** |
---|
247 | @brief |
---|
248 | Rotates the SimpleRocket around the z-axis by the amount specified by the first component of the input 2-dim vector. |
---|
249 | @param value |
---|
250 | The vector determining the amount of the angular movement. |
---|
251 | */ |
---|
252 | void SimpleRocket::rotateRoll(const Vector2& value) |
---|
253 | { |
---|
254 | ControllableEntity::rotateRoll(value); |
---|
255 | |
---|
256 | if( !this->isInMouseLook() ) |
---|
257 | this->localAngularVelocity_.z += value.x; |
---|
258 | } |
---|
259 | |
---|
260 | } |
---|