Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

update regen(); add new model for hbolt

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