Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/playability/src/world_entities/space_ships/space_ship.cc @ 9996

Last change on this file since 9996 was 9996, checked in by nicolasc, 17 years ago

updated spaceship to use all 3 blasters, set timing in medium blaster

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