1 | /* |
---|
2 | orxonox - the future of 3D-vertical-scrollers |
---|
3 | |
---|
4 | Copyright (C) 2004 orx |
---|
5 | |
---|
6 | This program is free software; you can redistribute it and/or modify |
---|
7 | it under the terms of the GNU General Public License as published by |
---|
8 | the Free Software Foundation; either version 2, or (at your option) |
---|
9 | any later version. |
---|
10 | |
---|
11 | ### File Specific: |
---|
12 | main-programmer: Benjamin Knecht |
---|
13 | co-programmer: Silvan Nellen |
---|
14 | |
---|
15 | */ |
---|
16 | |
---|
17 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD_ENTITY |
---|
18 | |
---|
19 | #include "executor/executor.h" |
---|
20 | #include "space_ship.h" |
---|
21 | |
---|
22 | #include "util/loading/resource_manager.h" |
---|
23 | |
---|
24 | #include "weapons/test_gun.h" |
---|
25 | #include "weapons/light_blaster.h" |
---|
26 | #include "weapons/medium_blaster.h" |
---|
27 | #include "weapons/heavy_blaster.h" |
---|
28 | #include "weapons/boomerang_gun.h" |
---|
29 | #include "weapons/turret.h" |
---|
30 | #include "weapons/cannon.h" |
---|
31 | |
---|
32 | #include "particles/dot_emitter.h" |
---|
33 | #include "particles/sprite_particles.h" |
---|
34 | |
---|
35 | #include "util/loading/factory.h" |
---|
36 | #include "key_mapper.h" |
---|
37 | |
---|
38 | #include "network_game_manager.h" |
---|
39 | #include "shared_network_data.h" |
---|
40 | |
---|
41 | #include "power_ups/weapon_power_up.h" |
---|
42 | #include "power_ups/param_power_up.h" |
---|
43 | |
---|
44 | #include "graphics_engine.h" |
---|
45 | |
---|
46 | #include "plane.h" |
---|
47 | |
---|
48 | #include "state.h" |
---|
49 | #include "player.h" |
---|
50 | |
---|
51 | #include "util/loading/load_param.h" |
---|
52 | |
---|
53 | |
---|
54 | // #include "lib/gui/gl_gui/glgui_bar.h" |
---|
55 | // #include "lib/gui/gl_gui/glgui_pushbutton.h" |
---|
56 | |
---|
57 | |
---|
58 | #include "class_id_DEPRECATED.h" |
---|
59 | ObjectListDefinitionID(SpaceShip, CL_SPACE_SHIP); |
---|
60 | CREATE_FACTORY(SpaceShip); |
---|
61 | |
---|
62 | #include "script_class.h" |
---|
63 | CREATE_SCRIPTABLE_CLASS(SpaceShip, |
---|
64 | addMethod("hasPlayer", Executor0ret<Playable, lua_State*,bool>(&Playable::hasPlayer)) |
---|
65 | ->addMethod("fire", Executor1<Playable, lua_State*, bool>(&Playable::fire)) |
---|
66 | ->addMethod("loadModel", Executor2<WorldEntity, lua_State*,const std::string& ,float>(&WorldEntity::loadModel2)) |
---|
67 | ->addMethod("setName", Executor1<BaseObject, lua_State*,const std::string&>(&BaseObject::setName)) |
---|
68 | ->addMethod("hide", Executor0<WorldEntity, lua_State*>(&WorldEntity::hide)) |
---|
69 | ->addMethod("unhide", Executor0<WorldEntity, lua_State*>(&WorldEntity::unhide)) |
---|
70 | //Coordinates |
---|
71 | ->addMethod("setAbsCoor", Executor3<PNode, lua_State*,float,float,float>(&PNode::setAbsCoor)) |
---|
72 | ->addMethod("getAbsCoorX", Executor0ret<PNode, lua_State*, float>(&PNode::getAbsCoorX)) |
---|
73 | ->addMethod("getAbsCoorY", Executor0ret<PNode, lua_State*, float>(&PNode::getAbsCoorY)) |
---|
74 | ->addMethod("getAbsCoorZ", Executor0ret<PNode, lua_State*, float>(&PNode::getAbsCoorZ)) |
---|
75 | ); |
---|
76 | |
---|
77 | /** |
---|
78 | * destructs the spaceship, deletes alocated memory |
---|
79 | */ |
---|
80 | SpaceShip::~SpaceShip () |
---|
81 | { |
---|
82 | this->setPlayer(NULL); |
---|
83 | } |
---|
84 | |
---|
85 | /** |
---|
86 | * loads a Spaceships information from a specified file. |
---|
87 | * @param fileName the name of the File to load the spaceship from (absolute path) |
---|
88 | */ |
---|
89 | SpaceShip::SpaceShip(const std::string& fileName) |
---|
90 | : secWeaponMan(this), |
---|
91 | supportedPlaymodes(Playable::Full3D || Playable::Horizontal || Playable::Vertical), |
---|
92 | playmode(Playable::Full3D) |
---|
93 | { |
---|
94 | this->init(); |
---|
95 | TiXmlDocument doc(fileName); |
---|
96 | |
---|
97 | if(!doc.LoadFile()) |
---|
98 | { |
---|
99 | PRINTF(2)("Loading file %s failed for spaceship.\n", fileName.c_str()); |
---|
100 | return; |
---|
101 | } |
---|
102 | |
---|
103 | this->loadParams(doc.RootElement()); |
---|
104 | } |
---|
105 | |
---|
106 | /** |
---|
107 | * creates a new Spaceship from Xml Data |
---|
108 | * @param root the xml element containing spaceship data |
---|
109 | |
---|
110 | @todo add more parameters to load |
---|
111 | */ |
---|
112 | SpaceShip::SpaceShip(const TiXmlElement* root) |
---|
113 | : secWeaponMan(this), |
---|
114 | supportedPlaymodes(Playable::Full3D || Playable::Horizontal || Playable::Vertical), |
---|
115 | playmode(Playable::Full3D) |
---|
116 | { |
---|
117 | this->init(); |
---|
118 | if (root != NULL) |
---|
119 | this->loadParams(root); |
---|
120 | |
---|
121 | } |
---|
122 | |
---|
123 | |
---|
124 | /** |
---|
125 | * initializes a Spaceship |
---|
126 | */ |
---|
127 | void SpaceShip::init() |
---|
128 | { |
---|
129 | |
---|
130 | // this->setRelDir(Quaternion(M_PI, Vector(1,0,0))); |
---|
131 | this->registerObject(this, SpaceShip::_objectList); |
---|
132 | |
---|
133 | PRINTF(4)("SPACESHIP INIT\n"); |
---|
134 | |
---|
135 | secWeaponMan.showCrosshair(); |
---|
136 | |
---|
137 | //weapons: |
---|
138 | |
---|
139 | Weapon* wpRight1 = new LightBlaster (); |
---|
140 | wpRight1->setName("Light Blaster Right"); |
---|
141 | Weapon* wpLeft1 = new LightBlaster (); |
---|
142 | wpLeft1->setName("Medium Blaster Left"); |
---|
143 | |
---|
144 | Weapon* wpRight2 = new MediumBlaster (); |
---|
145 | wpRight2->setName("Medium Blaster Right"); |
---|
146 | Weapon* wpLeft2 = new MediumBlaster (); |
---|
147 | wpLeft2->setName("Medium Blaster Left"); |
---|
148 | |
---|
149 | Weapon* wpRight3 = new HeavyBlaster (); |
---|
150 | wpRight3->setName("Heavy Blaster Right"); |
---|
151 | Weapon* wpLeft3 = new HeavyBlaster (); |
---|
152 | wpLeft3->setName("Heavy Blaster Left"); |
---|
153 | |
---|
154 | Weapon* cannon = new BoomerangGun();//Cannon(); |
---|
155 | cannon->setName("End of World"); |
---|
156 | |
---|
157 | |
---|
158 | this->weaponMan.addWeapon( wpLeft1, 1, 0); |
---|
159 | this->weaponMan.addWeapon( wpRight1, 1, 1); |
---|
160 | this->weaponMan.addWeapon( wpLeft2, 1, 2); |
---|
161 | this->weaponMan.addWeapon( wpRight2, 1, 3); |
---|
162 | this->weaponMan.addWeapon( wpLeft3, 0, 4); |
---|
163 | this->weaponMan.addWeapon( wpRight3, 0, 5); |
---|
164 | |
---|
165 | this->secWeaponMan.addWeapon( cannon, 0, 0); |
---|
166 | |
---|
167 | this->weaponMan.changeWeaponConfig(0); |
---|
168 | |
---|
169 | wpRight1->requestAction(WA_ACTIVATE); |
---|
170 | wpLeft1->requestAction(WA_ACTIVATE); |
---|
171 | wpRight2->requestAction(WA_ACTIVATE); |
---|
172 | wpLeft2->requestAction(WA_ACTIVATE); |
---|
173 | wpRight3->requestAction(WA_ACTIVATE); |
---|
174 | wpLeft3->requestAction(WA_ACTIVATE); |
---|
175 | |
---|
176 | cannon->requestAction(WA_ACTIVATE); |
---|
177 | |
---|
178 | curWeaponPrimary = 0; |
---|
179 | curWeaponSecondary = 0; |
---|
180 | |
---|
181 | Playable::weaponConfigChanged(); |
---|
182 | |
---|
183 | reactorOutput = 10; |
---|
184 | |
---|
185 | weaponEnergyRegen = 10; // 10 einheiten pro Sekunde |
---|
186 | engineSpeedBase = 5; |
---|
187 | shieldRegen = 2; |
---|
188 | |
---|
189 | shieldEnergyShare = 0.3; |
---|
190 | weaponEnergyShare = 0.3; |
---|
191 | engineEnergyShare = 0.4; |
---|
192 | |
---|
193 | shieldCur = 20; |
---|
194 | shieldMax = 100; |
---|
195 | |
---|
196 | /* |
---|
197 | this->addWeapon(wpLeft, 1, 0); |
---|
198 | this->addWeapon(wpRight,1 ,1); |
---|
199 | //this->addWeapon(cannon, 0, 6); |
---|
200 | |
---|
201 | this->getWeaponManager().changeWeaponConfig(1); |
---|
202 | */ |
---|
203 | |
---|
204 | this->loadModel("models/ships/mantawing.obj"); |
---|
205 | |
---|
206 | bUp = bDown = bLeft = bRight = bAscend = bDescend = bRollL = bRollR = bFire = bSecFire = false; |
---|
207 | |
---|
208 | xMouse = yMouse = 0; |
---|
209 | yInvert = 1; |
---|
210 | mouseSensitivity = 0.001; |
---|
211 | airViscosity = 0.9; |
---|
212 | controlVelocityX = 25; |
---|
213 | controlVelocityY = 150; |
---|
214 | shipInertia = 1.5; |
---|
215 | // cycle = 0.0; |
---|
216 | |
---|
217 | this->setHealthMax(shieldMax); |
---|
218 | this->setHealth(shieldCur); |
---|
219 | |
---|
220 | travelSpeed = 0.0; |
---|
221 | acceleration = 3; |
---|
222 | this->velocity = this->getAbsDirX()*travelSpeed; |
---|
223 | this->mouseDir = this->getAbsDir(); |
---|
224 | this->pitchDir = this->getAbsDir(); |
---|
225 | |
---|
226 | |
---|
227 | // GLGuiButton* button = new GLGuiPushButton(); |
---|
228 | // button->show(); |
---|
229 | // button->setLabel("orxonox"); |
---|
230 | // button->setBindNode(this); |
---|
231 | // GLGuiBar* bar = new GLGuiBar(); |
---|
232 | // bar->show(); |
---|
233 | // bar->setValue(7.0); |
---|
234 | // bar->setMaximum(10); |
---|
235 | // bar->setSize2D( 20, 100); |
---|
236 | // bar->setAbsCoor2D( 10, 200); |
---|
237 | |
---|
238 | //add events to the eventlist |
---|
239 | registerEvent(KeyMapper::PEV_FORWARD); |
---|
240 | registerEvent(KeyMapper::PEV_BACKWARD); |
---|
241 | registerEvent(KeyMapper::PEV_LEFT); |
---|
242 | registerEvent(KeyMapper::PEV_RIGHT); |
---|
243 | //registerEvent(SDLK_q); |
---|
244 | //registerEvent(SDLK_e); |
---|
245 | registerEvent(KeyMapper::PEV_FIRE1); |
---|
246 | registerEvent(KeyMapper::PEV_FIRE2); // Added for secondary weapon support |
---|
247 | registerEvent(KeyMapper::PEV_NEXT_WEAPON); |
---|
248 | registerEvent(KeyMapper::PEV_PREVIOUS_WEAPON); |
---|
249 | //registerEvent(SDLK_PAGEUP); |
---|
250 | //registerEvent(SDLK_PAGEDOWN); |
---|
251 | registerEvent(EV_MOUSE_MOTION); |
---|
252 | |
---|
253 | this->weaponMan.setSlotCount(6); |
---|
254 | |
---|
255 | this->weaponMan.setSlotPosition(0, Vector(-2.6, .1, -3.0)); |
---|
256 | this->weaponMan.setSlotCapability(0, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL); |
---|
257 | |
---|
258 | this->weaponMan.setSlotPosition(1, Vector(-2.6, .1, 3.0)); |
---|
259 | this->weaponMan.setSlotCapability(1, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL); |
---|
260 | |
---|
261 | this->weaponMan.setSlotPosition(2, Vector(-1.5, .5, -.5)); |
---|
262 | this->weaponMan.setSlotDirection(2, Quaternion(-M_PI_4*.5, Vector(1,0,0))); |
---|
263 | |
---|
264 | this->weaponMan.setSlotPosition(3, Vector(-1.5, .5, .5)); |
---|
265 | this->weaponMan.setSlotDirection(3, Quaternion(M_PI_4*.5, Vector(1,0,0))); |
---|
266 | |
---|
267 | this->weaponMan.setSlotPosition(4, Vector(-1.5, -.5, .5)); |
---|
268 | this->weaponMan.setSlotDirection(4, Quaternion(-M_PI_4*.5+M_PI, Vector(1,0,0))); |
---|
269 | |
---|
270 | this->weaponMan.setSlotPosition(5, Vector(-1.5, -.5, -.5)); |
---|
271 | this->weaponMan.setSlotDirection(5, Quaternion(+M_PI_4*.5-M_PI, Vector(1,0,0))); |
---|
272 | |
---|
273 | this->secWeaponMan.setSlotCount(6); |
---|
274 | |
---|
275 | this->secWeaponMan.setSlotPosition(0, Vector(2.6, -2.5, 0)); |
---|
276 | this->secWeaponMan.setSlotCapability(0, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL); |
---|
277 | |
---|
278 | this->secWeaponMan.setSlotPosition(1, Vector(2.6, .1, 3.0)); |
---|
279 | this->secWeaponMan.setSlotCapability(1, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL); |
---|
280 | |
---|
281 | this->secWeaponMan.setSlotPosition(2, Vector(1.5, .5, -.5)); |
---|
282 | this->secWeaponMan.setSlotDirection(2, Quaternion(-M_PI_4*.5, Vector(1,0,0))); |
---|
283 | |
---|
284 | this->secWeaponMan.setSlotPosition(3, Vector(1.5, .5, .5)); |
---|
285 | this->secWeaponMan.setSlotDirection(3, Quaternion(M_PI_4*.5, Vector(1,0,0))); |
---|
286 | |
---|
287 | this->secWeaponMan.setSlotPosition(4, Vector(1.5, -.5, .5)); |
---|
288 | this->secWeaponMan.setSlotDirection(4, Quaternion(-M_PI_4*.5+M_PI, Vector(1,0,0))); |
---|
289 | |
---|
290 | this->secWeaponMan.setSlotPosition(5, Vector(1.5, -.5, -.5)); |
---|
291 | this->secWeaponMan.setSlotDirection(5, Quaternion(+M_PI_4*.5-M_PI, Vector(1,0,0))); |
---|
292 | |
---|
293 | // |
---|
294 | // this->getWeaponManager().setSlotPosition(8, Vector(-2.5, -0.3, -2.0)); |
---|
295 | // this->getWeaponManager().setSlotDirection(8, Quaternion(-M_PI, Vector(1,0,0))); |
---|
296 | // |
---|
297 | // this->getWeaponManager().setSlotPosition(9, Vector(-2.5, -0.3, 2.0)); |
---|
298 | // this->getWeaponManager().setSlotDirection(9, Quaternion(+M_PI, Vector(1,0,0)));: |
---|
299 | |
---|
300 | this->weaponMan.getFixedTarget()->setParent(this); |
---|
301 | this->weaponMan.getFixedTarget()->setRelCoor(100000,0,0); |
---|
302 | |
---|
303 | this->secWeaponMan.getFixedTarget()->setParent(this); |
---|
304 | this->secWeaponMan.getFixedTarget()->setRelCoor(100000,0,0); |
---|
305 | |
---|
306 | dynamic_cast<Element2D*>(this->weaponMan.getFixedTarget())->setVisibility( false); |
---|
307 | |
---|
308 | this->burstEmitter = new DotEmitter(200, 0.0, .01); |
---|
309 | this->burstEmitter->setParent(this); |
---|
310 | this->burstEmitter->setRelCoor(-1, .5, 0); |
---|
311 | this->burstEmitter->setName("SpaceShip_Burst_emitter"); |
---|
312 | |
---|
313 | this->burstSystem = new SpriteParticles(1000); |
---|
314 | this->burstSystem->addEmitter(this->burstEmitter); |
---|
315 | this->burstSystem->setName("SpaceShip_Burst_System"); |
---|
316 | ((SpriteParticles*)this->burstSystem)->setMaterialTexture("maps/radial-trans-noise.png"); |
---|
317 | this->burstSystem->setLifeSpan(1.0, .3); |
---|
318 | this->burstSystem->setRadius(0.0, 1.0); |
---|
319 | this->burstSystem->setRadius(0.05, 1.0); |
---|
320 | this->burstSystem->setRadius(.5, .8); |
---|
321 | this->burstSystem->setRadius(1.0, 0); |
---|
322 | this->burstSystem->setColor(0.0, .7,.7,1,.7); |
---|
323 | this->burstSystem->setColor(0.2, 0,0,0.8,.5); |
---|
324 | this->burstSystem->setColor(0.5, .5,.5,.8,.8); |
---|
325 | this->burstSystem->setColor(1.0, .8,.8,.8,.0); |
---|
326 | |
---|
327 | registerVar( new SynchronizeableVector( &velocity, &velocity, "velocity", PERMISSION_MASTER_SERVER ) ); |
---|
328 | registerVar( new SynchronizeableQuaternion( &mouseDir, &mouseDir, "mousedir", PERMISSION_OWNER ) ); |
---|
329 | |
---|
330 | registerVar( new SynchronizeableBool( &bUp, &bUp, "bUp", PERMISSION_OWNER ) ); |
---|
331 | registerVar( new SynchronizeableBool( &bDown, &bDown, "bDown", PERMISSION_OWNER ) ); |
---|
332 | registerVar( new SynchronizeableBool( &bLeft, &bLeft, "bLeft", PERMISSION_OWNER ) ); |
---|
333 | registerVar( new SynchronizeableBool( &bRight, &bRight, "bRight", PERMISSION_OWNER ) ); |
---|
334 | registerVar( new SynchronizeableBool( &bAscend, &bAscend, "bAscend", PERMISSION_OWNER ) ); |
---|
335 | registerVar( new SynchronizeableBool( &bDescend, &bDescend, "bDescend", PERMISSION_OWNER ) ); |
---|
336 | registerVar( new SynchronizeableBool( &bRollL, &bRollL, "bRollL", PERMISSION_OWNER ) ); |
---|
337 | registerVar( new SynchronizeableBool( &bRollR, &bRollR, "bRollR", PERMISSION_OWNER ) ); |
---|
338 | } |
---|
339 | |
---|
340 | |
---|
341 | /** |
---|
342 | * loads the Settings of a SpaceShip from an XML-element. |
---|
343 | * @param root the XML-element to load the Spaceship's properties from |
---|
344 | */ |
---|
345 | void SpaceShip::loadParams(const TiXmlElement* root) |
---|
346 | { |
---|
347 | Playable::loadParams(root); |
---|
348 | } |
---|
349 | |
---|
350 | void SpaceShip::setPlayDirection(const Quaternion& quat, float speed) |
---|
351 | { |
---|
352 | this->mouseDir = quat; |
---|
353 | } |
---|
354 | |
---|
355 | |
---|
356 | void SpaceShip::reset() |
---|
357 | { |
---|
358 | bUp = bDown = bLeft = bRight = bAscend = bDescend = bRollL = bRollR = bFire = bSecFire = false; |
---|
359 | |
---|
360 | xMouse = yMouse = 0; |
---|
361 | |
---|
362 | this->setHealth(80); |
---|
363 | this->velocity = Vector(0.0, 0.0, 0.0); |
---|
364 | } |
---|
365 | |
---|
366 | |
---|
367 | void SpaceShip::enter() |
---|
368 | { |
---|
369 | dynamic_cast<Element2D*>(this->getWeaponManager().getFixedTarget())->setVisibility( true); |
---|
370 | this->attachCamera(); |
---|
371 | } |
---|
372 | |
---|
373 | void SpaceShip::leave() |
---|
374 | { |
---|
375 | dynamic_cast<Element2D*>(this->getWeaponManager().getFixedTarget())->setVisibility( false); |
---|
376 | this->detachCamera(); |
---|
377 | } |
---|
378 | |
---|
379 | |
---|
380 | /** |
---|
381 | * effect that occurs after the SpaceShip is spawned |
---|
382 | */ |
---|
383 | void SpaceShip::postSpawn () |
---|
384 | { |
---|
385 | //setCollision(new CollisionCluster(1.0, Vector(0,0,0))); |
---|
386 | } |
---|
387 | |
---|
388 | /** |
---|
389 | * the action occuring if the spaceship left the game |
---|
390 | */ |
---|
391 | void SpaceShip::leftWorld () |
---|
392 | {} |
---|
393 | |
---|
394 | WorldEntity* ref = NULL; |
---|
395 | /** |
---|
396 | * this function is called, when two entities collide |
---|
397 | * @param entity: the world entity with whom it collides |
---|
398 | * |
---|
399 | * Implement behaviour like damage application or other miscellaneous collision stuff in this function |
---|
400 | */ |
---|
401 | void SpaceShip::collidesWith(WorldEntity* entity, const Vector& location) |
---|
402 | { |
---|
403 | } |
---|
404 | |
---|
405 | /** |
---|
406 | * draws the spaceship after transforming it. |
---|
407 | */ |
---|
408 | void SpaceShip::draw () const |
---|
409 | { |
---|
410 | WorldEntity::draw(); |
---|
411 | |
---|
412 | //this->debug(0); |
---|
413 | } |
---|
414 | |
---|
415 | /** |
---|
416 | * the function called for each passing timeSnap |
---|
417 | * @param time The timespan passed since last update |
---|
418 | */ |
---|
419 | void SpaceShip::tick (float time) |
---|
420 | { |
---|
421 | // Playable::tick(time);$ |
---|
422 | |
---|
423 | // Own Tick Setup, as a different fire routine is used on the weapon manager |
---|
424 | this->weaponMan.tick(time); |
---|
425 | this->secWeaponMan.tick(time); |
---|
426 | |
---|
427 | if( this->bFire) |
---|
428 | { |
---|
429 | this->weaponMan.fire(); |
---|
430 | } |
---|
431 | if( this->bSecFire) |
---|
432 | { |
---|
433 | this->secWeaponMan.fire(); |
---|
434 | this->bSecFire = !this->bSecFire; // FIXME This currently is needed to prevent "echo fires" of a second rocket after its cooldown has passed |
---|
435 | } |
---|
436 | |
---|
437 | |
---|
438 | // Shield Regeneration and other regular calculations on the ship |
---|
439 | this->regen(time); |
---|
440 | |
---|
441 | // Weapon Regeneration and other regular calculations on the ship |
---|
442 | this->weaponRegen(time); |
---|
443 | |
---|
444 | // current engine speed output |
---|
445 | this->engineSpeedCur = this->engineSpeedBase + this->reactorOutput * this->engineEnergyShare; |
---|
446 | |
---|
447 | |
---|
448 | |
---|
449 | if( ( xMouse != 0 || yMouse != 0 ) && this->getOwner() == SharedNetworkData::getInstance()->getHostID() ) |
---|
450 | { |
---|
451 | if (xMouse > controlVelocityX) xMouse = controlVelocityX; |
---|
452 | else if (xMouse < -controlVelocityX) xMouse = -controlVelocityX; |
---|
453 | if (yMouse > controlVelocityY) yMouse = controlVelocityY; |
---|
454 | else if (yMouse < -controlVelocityY) yMouse = -controlVelocityY; |
---|
455 | |
---|
456 | pitchDir = (Quaternion(xMouse*mouseSensitivity*0.5, Vector(1,0,0))); |
---|
457 | |
---|
458 | mouseDir *= (Quaternion(-M_PI/4*xMouse*mouseSensitivity, Vector(0,1,0))*Quaternion(-M_PI/4*yMouse*mouseSensitivity*yInvert, Vector(0,0,1))*pitchDir); |
---|
459 | xMouse = yMouse = 0; |
---|
460 | } |
---|
461 | |
---|
462 | |
---|
463 | |
---|
464 | |
---|
465 | // if( this != State::getPlayer()->getControllable()) |
---|
466 | // return; |
---|
467 | |
---|
468 | // spaceship controlled movement fire(bool bF){ this->bFire = bF;} |
---|
469 | //if (this->getOwner() == this->getHostID()) |
---|
470 | this->calculateVelocity(time); |
---|
471 | |
---|
472 | |
---|
473 | Vector move = velocity*time; |
---|
474 | |
---|
475 | //orient the velocity in the direction of the spaceship. |
---|
476 | travelSpeed = velocity.len(); |
---|
477 | velocity += ((this->getAbsDirX())*travelSpeed-velocity)*airViscosity; |
---|
478 | velocity = (velocity.getNormalized())*travelSpeed; |
---|
479 | this->burstEmitter->setEmissionRate(travelSpeed); |
---|
480 | this->burstEmitter->setEmissionVelocity(travelSpeed*.5, travelSpeed *.1); |
---|
481 | |
---|
482 | //orient the spaceship in direction of the mouse |
---|
483 | rotQuat = Quaternion::quatSlerp( this->getAbsDir(), mouseDir, 0.5);//fabsf(time)*shipInertia); |
---|
484 | if (this->getAbsDir().distance(rotQuat) > 0.00000000000001) |
---|
485 | this->setAbsDir( rotQuat); |
---|
486 | //this->setAbsDirSoft(mouseDir,5); |
---|
487 | |
---|
488 | // this is the air friction (necessary for a smooth control) |
---|
489 | if(travelSpeed >= 120) velocity -= velocity.getNormalized()*travelSpeed*travelSpeed*0.0001; |
---|
490 | else if (travelSpeed <= 80) velocity -= velocity.getNormalized()*travelSpeed*0.001; |
---|
491 | |
---|
492 | //other physics (gravity) |
---|
493 | //if(travelSpeed < 120) |
---|
494 | //move += Vector(0,-1,0)*60*time + Vector(0,1,0)*travelSpeed/2*time; |
---|
495 | |
---|
496 | //hoover effect |
---|
497 | //cycle += time; |
---|
498 | //this->shiftCoor(Vector(0,1,0)*cos(this->cycle*2.0)*0.02); |
---|
499 | |
---|
500 | //readjust |
---|
501 | //if (this->getAbsDirZ().y > 0.1) this->shiftDir(Quaternion(time*0.3, Vector(1,0,0))); |
---|
502 | //else if (this->getAbsDirZ().y < -0.1) this->shiftDir(Quaternion(-time*0.3, Vector(1,0,0))); |
---|
503 | |
---|
504 | //SDL_WarpMouse(GraphicsEngine::getInstance()->getResolutionX()/2, GraphicsEngine::getInstance()->getResolutionY()/2); |
---|
505 | |
---|
506 | this->shiftCoor(move); |
---|
507 | |
---|
508 | // PRINTF(0)("id of %s is: %i\n", this->getName(), this->getOMListNumber()); |
---|
509 | |
---|
510 | } |
---|
511 | |
---|
512 | /** |
---|
513 | * calculate the velocity |
---|
514 | * @param time the timeslice since the last frame |
---|
515 | */ |
---|
516 | void SpaceShip::calculateVelocity (float time) |
---|
517 | { |
---|
518 | Vector accel(0.0, 0.0, 0.0); |
---|
519 | /* |
---|
520 | Vector rot(0.0, 0.0, 0.0); // wird ben�igt fr Helicopter |
---|
521 | */ |
---|
522 | //float rotVal = 0.0; |
---|
523 | /* FIXME: calculating the direction and orthDirection every timeSlice is redundant! save it somewhere */ |
---|
524 | /* calculate the direction in which the craft is heading */ |
---|
525 | |
---|
526 | //Plane plane(Vector(0,1,0), Vector(0,0,0)); |
---|
527 | |
---|
528 | if( this->bUp ) |
---|
529 | { |
---|
530 | //this->shiftCoor(this->getAbsDirX()); |
---|
531 | //accel += (this->getAbsDirX())*2; |
---|
532 | accel += (this->getAbsDirX())*acceleration; |
---|
533 | |
---|
534 | } |
---|
535 | |
---|
536 | if( this->bDown ) |
---|
537 | { |
---|
538 | //this->shiftCoor((this->getAbsDirX())*-1); |
---|
539 | //accel -= (this->getAbsDirX())*2; |
---|
540 | //if(velocity.len() > 50) |
---|
541 | accel -= (this->getAbsDirX())*0.5*acceleration; |
---|
542 | |
---|
543 | |
---|
544 | |
---|
545 | } |
---|
546 | |
---|
547 | if( this->bLeft/* > -this->getRelCoor().z*2*/) |
---|
548 | { |
---|
549 | this->shiftDir(Quaternion(time, Vector(0,1,0))); |
---|
550 | // accel -= rightDirection; |
---|
551 | //velocityDir.normalize(); |
---|
552 | //rot +=Vector(1,0,0); |
---|
553 | //rotVal -= .4; |
---|
554 | } |
---|
555 | if( this->bRight /* > this->getRelCoor().z*2*/) |
---|
556 | { |
---|
557 | this->shiftDir(Quaternion(-time, Vector(0,1,0))); |
---|
558 | |
---|
559 | // accel += rightDirection; |
---|
560 | //velocityDir.normalize(); |
---|
561 | //rot += Vector(1,0,0); |
---|
562 | //rotVal += .4; |
---|
563 | } |
---|
564 | |
---|
565 | |
---|
566 | if( this->bRollL /* > -this->getRelCoor().z*2*/) |
---|
567 | { |
---|
568 | mouseDir *= Quaternion(-time*2, Vector(1,0,0)); |
---|
569 | // accel -= rightDirection; |
---|
570 | //velocityDir.normalize(); |
---|
571 | //rot +=Vector(1,0,0); |
---|
572 | //rotVal -= .4; |
---|
573 | } |
---|
574 | if( this->bRollR /* > this->getRelCoor().z*2*/) |
---|
575 | { |
---|
576 | mouseDir *= Quaternion(time*2, Vector(1,0,0)); |
---|
577 | |
---|
578 | // accel += rightDirection; |
---|
579 | //velocityDir.normalize(); |
---|
580 | //rot += Vector(1,0,0); |
---|
581 | //rotVal += .4; |
---|
582 | } |
---|
583 | if (this->bAscend ) |
---|
584 | { |
---|
585 | this->shiftDir(Quaternion(time, Vector(0,0,1))); |
---|
586 | |
---|
587 | // accel += upDirection; |
---|
588 | //velocityDir.normalize(); |
---|
589 | //rot += Vector(0,0,1); |
---|
590 | //rotVal += .4; |
---|
591 | } |
---|
592 | if (this->bDescend ) |
---|
593 | { |
---|
594 | this->shiftDir(Quaternion(-time, Vector(0,0,1))); |
---|
595 | |
---|
596 | // accel -= upDirection; |
---|
597 | //velocityDir.normalize(); |
---|
598 | //rot += Vector(0,0,1); |
---|
599 | //rotVal -= .4; |
---|
600 | } |
---|
601 | |
---|
602 | velocity += accel*time*10; |
---|
603 | //rot.normalize(); |
---|
604 | //this->setRelDirSoft(Quaternion(rotVal, rot), 5); |
---|
605 | |
---|
606 | } |
---|
607 | |
---|
608 | /** |
---|
609 | * @todo switch statement ?? |
---|
610 | */ |
---|
611 | void SpaceShip::process(const Event &event) |
---|
612 | { |
---|
613 | //Playable::process(event); |
---|
614 | |
---|
615 | if( event.type == KeyMapper::PEV_LEFT) |
---|
616 | this->bRollL = event.bPressed; |
---|
617 | else if( event.type == KeyMapper::PEV_RIGHT) |
---|
618 | this->bRollR = event.bPressed; |
---|
619 | else if( event.type == KeyMapper::PEV_FORWARD) |
---|
620 | this->bUp = event.bPressed; //this->shiftCoor(0,.1,0); |
---|
621 | else if( event.type == KeyMapper::PEV_BACKWARD) |
---|
622 | this->bDown = event.bPressed; //this->shiftCoor(0,-.1,0); |
---|
623 | else if( event.type == KeyMapper::PEV_FIRE2) |
---|
624 | this->bSecFire = event.bPressed; |
---|
625 | else if( event.type == KeyMapper::PEV_FIRE1) |
---|
626 | this->bFire = event.bPressed; |
---|
627 | else if( event.type == EV_MOUSE_MOTION) |
---|
628 | { |
---|
629 | |
---|
630 | this->xMouse += event.xRel; |
---|
631 | this->yMouse += event.yRel; |
---|
632 | } |
---|
633 | } |
---|
634 | |
---|
635 | void SpaceShip::destroy( WorldEntity* killer ) |
---|
636 | { |
---|
637 | PRINTF(0)("spaceship destroy\n"); |
---|
638 | } |
---|
639 | |
---|
640 | void SpaceShip::respawn( ) |
---|
641 | { |
---|
642 | toList( OM_PLAYERS ); |
---|
643 | } |
---|
644 | |
---|
645 | |
---|
646 | void SpaceShip::damage(float pDamage, float eDamage){ |
---|
647 | if( this->shieldActive) { |
---|
648 | if( this->shieldCur > pDamage) { |
---|
649 | this->shieldCur = this->shieldCur - pDamage; |
---|
650 | } |
---|
651 | else { // shield <= pDamage |
---|
652 | this->shieldCur -=pDamage; |
---|
653 | this->shieldActive = false; //shield collapses |
---|
654 | pDamage = pDamage - this->shieldCur; |
---|
655 | if( !this->shieldActive) { |
---|
656 | this->armorCur -= pDamage / 2; // remaining damages hits armor at half rate |
---|
657 | this->electronicCur -= eDamage; |
---|
658 | } |
---|
659 | } |
---|
660 | } |
---|
661 | else { |
---|
662 | this->armorCur = this->armorCur - pDamage; |
---|
663 | this->electronicCur = this->electronicCur - eDamage; |
---|
664 | } |
---|
665 | if( this->armorCur <= 0) { /* FIXME implement shipcrash*/ } |
---|
666 | } |
---|
667 | |
---|
668 | |
---|
669 | void SpaceShip::regen(float time){ |
---|
670 | float tmp; |
---|
671 | if (this->armorCur != this->armorMax || this->armorRegen != 0){ |
---|
672 | tmp = this->armorCur + this->armorRegen * time; |
---|
673 | if ( tmp > electronicMax) |
---|
674 | this->armorCur = this->armorMax; |
---|
675 | else |
---|
676 | this->armorCur = tmp; |
---|
677 | } |
---|
678 | if (this->shieldCur != this->shieldMax || this->shieldRegen != 0){ |
---|
679 | tmp = this->shieldCur + (this->shieldRegen + this->reactorOutput * this->shieldEnergyShare) * time; |
---|
680 | if( tmp > shieldMax) |
---|
681 | this->shieldCur = this->shieldMax; |
---|
682 | else |
---|
683 | this->shieldCur = tmp; |
---|
684 | this->shieldActive = ( this->shieldActive || this->shieldCur > shieldTH); |
---|
685 | } |
---|
686 | |
---|
687 | this->setHealth( this->shieldCur); // FIXME currently just to test share system |
---|
688 | |
---|
689 | if (this->electronicCur != this->electronicMax || this->electronicRegen != 0){ |
---|
690 | tmp = this->electronicCur + this->electronicRegen * time; |
---|
691 | if ( tmp > electronicMax) |
---|
692 | this->electronicCur = this->electronicMax; |
---|
693 | else |
---|
694 | this->electronicCur = tmp; |
---|
695 | } |
---|
696 | } |
---|
697 | |
---|
698 | |
---|
699 | /** |
---|
700 | * Weapon regeneration |
---|
701 | * does not use any reactor capacity, as it wouldn't work in a consistent way. |
---|
702 | */ |
---|
703 | void SpaceShip::weaponRegen(float time) |
---|
704 | { |
---|
705 | float energy = ( this->reactorOutput * this->weaponEnergyShare + this->weaponEnergyRegen) * time; |
---|
706 | Weapon* weapon; |
---|
707 | for( unsigned int i=0; i < this->weaponMan.getSlotCount(); i++) |
---|
708 | { |
---|
709 | weapon = this->weaponMan.getWeapon(i); |
---|
710 | if( weapon != NULL && weapon->isActive()) |
---|
711 | { |
---|
712 | weapon->increaseEnergy( energy); |
---|
713 | } |
---|
714 | |
---|
715 | } |
---|
716 | // weaponMan.increaseAmmunition( weapon, energy); |
---|
717 | |
---|
718 | } |
---|
719 | |
---|
720 | |
---|
721 | void SpaceShip::enterPlaymode(Playable::Playmode playmode) |
---|
722 | { |
---|
723 | } |
---|
724 | |
---|
725 | |
---|
726 | void SpaceShip::movement (float dt) |
---|
727 | { |
---|
728 | } |
---|