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 "Rocket.h" |
---|
30 | |
---|
31 | #include "core/XMLPort.h" |
---|
32 | #include "BulletDynamics/Dynamics/btRigidBody.h" |
---|
33 | #include "worldentities/pawns/Pawn.h" |
---|
34 | #include "graphics/ParticleSpawner.h" |
---|
35 | #include "graphics/Model.h" |
---|
36 | #include "objects/collisionshapes/ConeCollisionShape.h" |
---|
37 | #include "infos/PlayerInfo.h" |
---|
38 | #include "controllers/Controller.h" |
---|
39 | #include "worldentities/CameraPosition.h" |
---|
40 | |
---|
41 | namespace orxonox |
---|
42 | { |
---|
43 | CreateFactory(Rocket); |
---|
44 | // create the factory for the Rocket |
---|
45 | |
---|
46 | /** |
---|
47 | @brief |
---|
48 | Constructor. Registers the object and initializes some default values. |
---|
49 | */ |
---|
50 | Rocket::Rocket(BaseObject* creator) : ControllableEntity(creator) |
---|
51 | { |
---|
52 | RegisterObject(Rocket);// - register the Rocket class to the core |
---|
53 | |
---|
54 | this->localAngularVelocity_ = 0; |
---|
55 | |
---|
56 | if (GameMode::isMaster()) |
---|
57 | { |
---|
58 | this->setCollisionType(WorldEntity::Kinematic); |
---|
59 | this->setVelocity(0,0,-100); |
---|
60 | this->lifetime_ = 100; |
---|
61 | this->bDestroy_ = false; |
---|
62 | |
---|
63 | Model* model = new Model(this); |
---|
64 | model->setMeshSource("rocket.mesh"); |
---|
65 | this->attach(model); |
---|
66 | ParticleEmitter* fire = new ParticleEmitter(this); |
---|
67 | this->attach(fire); |
---|
68 | fire->setOrientation(this->getOrientation()); |
---|
69 | fire->setSource("Orxonox/rocketfire"); |
---|
70 | |
---|
71 | this->enableCollisionCallback(); |
---|
72 | this->setCollisionResponse(false); |
---|
73 | this->setCollisionType(Kinematic); |
---|
74 | |
---|
75 | ConeCollisionShape* collisionShape = new ConeCollisionShape(this); |
---|
76 | collisionShape->setRadius(3); |
---|
77 | collisionShape->setHeight(500); |
---|
78 | this->attachCollisionShape(collisionShape); |
---|
79 | |
---|
80 | this->destroyTimer_.setTimer(this->lifetime_, false, createExecutor(createFunctor(&Rocket::destroyObject, this))); |
---|
81 | } |
---|
82 | |
---|
83 | CameraPosition* camPosition = new CameraPosition(this); |
---|
84 | camPosition->setPosition(0,10,40); |
---|
85 | camPosition->setAllowMouseLook(true); |
---|
86 | this->addCameraPosition(camPosition); |
---|
87 | } |
---|
88 | |
---|
89 | /** |
---|
90 | @brief |
---|
91 | Destructor. Destroys controller, if present. |
---|
92 | */ |
---|
93 | Rocket::~Rocket() |
---|
94 | { |
---|
95 | if(this->isInitialized()) |
---|
96 | { |
---|
97 | if (GameMode::isMaster() && this->player_) |
---|
98 | this->player_->stopTemporaryControl(); |
---|
99 | } |
---|
100 | } |
---|
101 | |
---|
102 | /** |
---|
103 | @brief |
---|
104 | Method for creating a Rocket through XML. |
---|
105 | */ |
---|
106 | void Rocket::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
107 | { |
---|
108 | // this calls the XMLPort function of the parent class |
---|
109 | SUPER(Rocket, XMLPort, xmlelement, mode); |
---|
110 | } |
---|
111 | |
---|
112 | void Rocket::setOwner(Pawn* owner) |
---|
113 | { |
---|
114 | this->owner_ = owner; |
---|
115 | this->originalControllableEntity_ = this->owner_->getPlayer()->getControllableEntity(); |
---|
116 | this->player_ = this->owner_->getPlayer(); |
---|
117 | this->owner_->getPlayer()->startTemporaryControl(this); |
---|
118 | } |
---|
119 | |
---|
120 | /** |
---|
121 | @brief |
---|
122 | Defines which actions the Rocket has to take in each tick. |
---|
123 | @param dt |
---|
124 | The length of the tick. |
---|
125 | */ |
---|
126 | void Rocket::tick(float dt) |
---|
127 | { |
---|
128 | SUPER(Rocket, tick, dt); |
---|
129 | |
---|
130 | if( this->hasLocalController() ) |
---|
131 | { |
---|
132 | this->setAngularVelocity(this->getOrientation() * this->localAngularVelocity_); |
---|
133 | this->setVelocity( this->getOrientation()*WorldEntity::FRONT*this->getVelocity().length() ); |
---|
134 | this->localAngularVelocity_ = 0; |
---|
135 | |
---|
136 | if( this->bDestroy_ ) |
---|
137 | this->destroy(); |
---|
138 | } |
---|
139 | } |
---|
140 | |
---|
141 | bool Rocket::collidesAgainst(WorldEntity* otherObject, btManifoldPoint& contactPoint) |
---|
142 | { |
---|
143 | if (!this->bDestroy_ && GameMode::isMaster()) |
---|
144 | { |
---|
145 | if (otherObject == this->owner_) |
---|
146 | return false; |
---|
147 | |
---|
148 | this->bDestroy_ = true; |
---|
149 | |
---|
150 | if (this->owner_) |
---|
151 | { |
---|
152 | { |
---|
153 | ParticleSpawner* effect = new ParticleSpawner(this->owner_->getCreator()); |
---|
154 | effect->setPosition(this->getPosition()); |
---|
155 | effect->setOrientation(this->getOrientation()); |
---|
156 | effect->setDestroyAfterLife(true); |
---|
157 | effect->setSource("Orxonox/explosion4"); |
---|
158 | effect->setLifetime(2.0f); |
---|
159 | } |
---|
160 | |
---|
161 | { |
---|
162 | ParticleSpawner* effect = new ParticleSpawner(this->owner_->getCreator()); |
---|
163 | effect->setPosition(this->getPosition()); |
---|
164 | effect->setOrientation(this->getOrientation()); |
---|
165 | effect->setDestroyAfterLife(true); |
---|
166 | effect->setSource("Orxonox/smoke4"); |
---|
167 | effect->setLifetime(3.0f); |
---|
168 | } |
---|
169 | } |
---|
170 | |
---|
171 | float dmg = this->damage_; |
---|
172 | if (this->owner_) |
---|
173 | dmg = this->owner_->getPickups().processModifiers(ModifierType::Damage, dmg, false); |
---|
174 | |
---|
175 | Pawn* victim = orxonox_cast<Pawn*>(otherObject); |
---|
176 | if (victim) |
---|
177 | victim->damage(dmg, this->owner_); |
---|
178 | // this->destroy(); |
---|
179 | } |
---|
180 | return false; |
---|
181 | } |
---|
182 | |
---|
183 | void Rocket::destroyObject() |
---|
184 | { |
---|
185 | if (GameMode::isMaster()) |
---|
186 | this->destroy(); |
---|
187 | } |
---|
188 | |
---|
189 | void Rocket::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 Rocket 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 Rocket::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 Rocket 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 Rocket::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 Rocket 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 Rocket::rotateRoll(const Vector2& value) |
---|
249 | { |
---|
250 | ControllableEntity::rotateRoll(value); |
---|
251 | |
---|
252 | if( !this->isInMouseLook() ) |
---|
253 | this->localAngularVelocity_.z += value.x; |
---|
254 | } |
---|
255 | |
---|
256 | } |
---|