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 | * simonmie |
---|
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/Output.h" |
---|
44 | |
---|
45 | namespace orxonox |
---|
46 | { |
---|
47 | |
---|
48 | CreateFactory(SimpleRocket); |
---|
49 | |
---|
50 | SimpleRocket::SimpleRocket(BaseObject* creator) |
---|
51 | : ControllableEntity(creator) |
---|
52 | , BasicProjectile() |
---|
53 | , RadarViewable(creator, static_cast<WorldEntity*>(this)) |
---|
54 | { |
---|
55 | RegisterObject(SimpleRocket);// - register the SimpleRocket class to the core |
---|
56 | |
---|
57 | this->localAngularVelocity_ = 0; |
---|
58 | this->lifetime_ = 10; |
---|
59 | |
---|
60 | this->setMass(15); |
---|
61 | // orxout() << "simplerocket constructed" << endl; |
---|
62 | |
---|
63 | if (GameMode::isMaster()) |
---|
64 | { |
---|
65 | this->setCollisionType(WorldEntity::Kinematic); |
---|
66 | this->fuel_=true; |
---|
67 | |
---|
68 | Model* model = new Model(this); |
---|
69 | model->setMeshSource("rocket.mesh"); |
---|
70 | model->scale(0.7f); |
---|
71 | this->attach(model); |
---|
72 | |
---|
73 | this->fire_ = new ParticleEmitter(this); |
---|
74 | this->attach(this->fire_); |
---|
75 | |
---|
76 | this->fire_->setOrientation(this->getOrientation()); |
---|
77 | this->fire_->setSource("Orxonox/simplerocketfire"); |
---|
78 | this->enableCollisionCallback(); |
---|
79 | this->setCollisionResponse(false); |
---|
80 | this->setCollisionType(Kinematic); |
---|
81 | |
---|
82 | // TODO: fix the orientation and size of this collision shape to match the rocket |
---|
83 | ConeCollisionShape* collisionShape = new ConeCollisionShape(this); |
---|
84 | collisionShape->setOrientation(this->getOrientation()); |
---|
85 | collisionShape->setRadius(1.5f); |
---|
86 | collisionShape->setHeight(5); |
---|
87 | this->attachCollisionShape(collisionShape); |
---|
88 | this->destroyTimer_.setTimer(this->lifetime_, false, createExecutor(createFunctor(&SimpleRocket::destroyObject, this))); |
---|
89 | } |
---|
90 | |
---|
91 | this->setRadarObjectColour(ColourValue(1.0, 1.0, 0.0)); // yellow |
---|
92 | this->setRadarObjectShape(RadarViewable::Triangle); |
---|
93 | this->setRadarObjectScale(0.5f); |
---|
94 | } |
---|
95 | |
---|
96 | |
---|
97 | |
---|
98 | /** |
---|
99 | * @brief updates state of rocket, disables fire if no fuel |
---|
100 | * @param dt tick-length |
---|
101 | */ |
---|
102 | void SimpleRocket::tick(float dt) |
---|
103 | { |
---|
104 | |
---|
105 | SUPER(SimpleRocket, tick, dt); |
---|
106 | if ( GameMode::isMaster() ) |
---|
107 | { |
---|
108 | |
---|
109 | |
---|
110 | this->setAngularVelocity(this->getOrientation() * this->localAngularVelocity_); |
---|
111 | this->setVelocity( this->getOrientation()*WorldEntity::FRONT*this->getVelocity().length() ); |
---|
112 | this->localAngularVelocity_ = 0; |
---|
113 | |
---|
114 | |
---|
115 | if (this->fuel_) |
---|
116 | { |
---|
117 | if (this->destroyTimer_.getRemainingTime()< (static_cast<float>(this->FUEL_PERCENTAGE)/100) *this->lifetime_ ) |
---|
118 | this->fuel_=false; |
---|
119 | } else |
---|
120 | this->disableFire(); |
---|
121 | |
---|
122 | if( this->getBDestroy() ) |
---|
123 | this->destroy(); |
---|
124 | } |
---|
125 | |
---|
126 | } |
---|
127 | |
---|
128 | /** |
---|
129 | * @brief Sets the Acceleration to 0 and detaches the fire |
---|
130 | * @return void |
---|
131 | */ |
---|
132 | void SimpleRocket::disableFire() |
---|
133 | { |
---|
134 | this->setAcceleration(0,0,0); |
---|
135 | this->fire_->detachFromParent(); |
---|
136 | } |
---|
137 | |
---|
138 | /**s |
---|
139 | @brief |
---|
140 | Destructor. Destroys controller, if present and kills sounds, if playing. |
---|
141 | */ |
---|
142 | SimpleRocket::~SimpleRocket() |
---|
143 | { |
---|
144 | if (this->isInitialized()) |
---|
145 | { |
---|
146 | if( GameMode::isMaster() ) |
---|
147 | { |
---|
148 | this->getController()->destroy(); |
---|
149 | } |
---|
150 | } |
---|
151 | } |
---|
152 | |
---|
153 | /** |
---|
154 | @brief |
---|
155 | Method for creating a SimpleRocket through XML. |
---|
156 | */ |
---|
157 | void SimpleRocket::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
158 | { |
---|
159 | // this calls the XMLPort function of the parent class |
---|
160 | SUPER(SimpleRocket, XMLPort, xmlelement, mode); |
---|
161 | } |
---|
162 | |
---|
163 | void SimpleRocket::setOwner(Pawn* owner) |
---|
164 | { |
---|
165 | this->owner_ = owner; |
---|
166 | this->player_ = this->getOwner()->getPlayer(); |
---|
167 | } |
---|
168 | |
---|
169 | |
---|
170 | /* Calls the collidesAgainst function of BasicProjectile |
---|
171 | */ |
---|
172 | bool SimpleRocket::collidesAgainst(WorldEntity* otherObject, btManifoldPoint& contactPoint) |
---|
173 | { |
---|
174 | return BasicProjectile::basicCollidesAgainst(otherObject,contactPoint,this->getOwner(),this); |
---|
175 | } |
---|
176 | |
---|
177 | void SimpleRocket::destroyObject() |
---|
178 | { |
---|
179 | if (GameMode::isMaster()) |
---|
180 | { |
---|
181 | this->destroy(); |
---|
182 | } |
---|
183 | } |
---|
184 | |
---|
185 | /** |
---|
186 | @brief |
---|
187 | Rotates the SimpleRocket around the y-axis by the amount specified by the first component of the input 2-dim vector. |
---|
188 | @param value |
---|
189 | The vector determining the amount of the angular movement. |
---|
190 | */ |
---|
191 | void SimpleRocket::rotateYaw(const Vector2& value) |
---|
192 | { |
---|
193 | ControllableEntity::rotateYaw(value); |
---|
194 | |
---|
195 | if( !this->isInMouseLook() ) |
---|
196 | this->localAngularVelocity_.y += value.x; |
---|
197 | } |
---|
198 | |
---|
199 | /** |
---|
200 | @brief |
---|
201 | Rotates the SimpleRocket around the x-axis by the amount specified by the first component of the input 2-dim vector. |
---|
202 | @param value |
---|
203 | The vector determining the amount of the angular movement. |
---|
204 | */ |
---|
205 | void SimpleRocket::rotatePitch(const Vector2& value) |
---|
206 | { |
---|
207 | ControllableEntity::rotatePitch(value); |
---|
208 | |
---|
209 | if( !this->isInMouseLook() ) |
---|
210 | this->localAngularVelocity_.x += value.x; |
---|
211 | } |
---|
212 | |
---|
213 | /** |
---|
214 | @brief |
---|
215 | Rotates the SimpleRocket around the z-axis by the amount specified by the first component of the input 2-dim vector. |
---|
216 | @param value |
---|
217 | The vector determining the amount of the angular movement. |
---|
218 | */ |
---|
219 | void SimpleRocket::rotateRoll(const Vector2& value) |
---|
220 | { |
---|
221 | ControllableEntity::rotateRoll(value); |
---|
222 | |
---|
223 | if( !this->isInMouseLook() ) |
---|
224 | this->localAngularVelocity_.z += value.x; |
---|
225 | } |
---|
226 | |
---|
227 | } |
---|