Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 9965 was 9965, checked in by marcscha, 17 years ago

Modifications to ship, HUD,.. see changelog

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