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