Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

space_ship cleanup, ChangeLog update

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