Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

Double Weapon Manager implementation

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