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
RevLine 
[6868]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
[7193]22#include "util/loading/resource_manager.h"
[6868]23
24#include "weapons/test_gun.h"
[9970]25#include "weapons/light_blaster.h"
26#include "weapons/medium_blaster.h"
27#include "weapons/heavy_blaster.h"
28#include "weapons/boomerang_gun.h"
[6868]29#include "weapons/turret.h"
30#include "weapons/cannon.h"
31
[9869]32#include "particles/dot_emitter.h"
33#include "particles/sprite_particles.h"
[6868]34
[7193]35#include "util/loading/factory.h"
[6868]36#include "key_mapper.h"
37
38#include "network_game_manager.h"
[8708]39#include "shared_network_data.h"
[6868]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
[7193]51#include "util/loading/load_param.h"
[6868]52
[7056]53
[6868]54// #include "lib/gui/gl_gui/glgui_bar.h"
55// #include "lib/gui/gl_gui/glgui_pushbutton.h"
56
57
[9869]58#include "class_id_DEPRECATED.h"
59ObjectListDefinitionID(SpaceShip, CL_SPACE_SHIP);
60CREATE_FACTORY(SpaceShip);
[9406]61
[9061]62#include "script_class.h"
[9869]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))
[9061]75                       );
[6868]76
77/**
78 *  destructs the spaceship, deletes alocated memory
79 */
80SpaceShip::~SpaceShip ()
81{
[6986]82  this->setPlayer(NULL);
[6868]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 */
[7221]89SpaceShip::SpaceShip(const std::string& fileName)
[9965]90    : secWeaponMan(this),
[9961]91    supportedPlaymodes(Playable::Full3D || Playable::Horizontal || Playable::Vertical),
92    playmode(Playable::Full3D)
[6868]93{
94  this->init();
95  TiXmlDocument doc(fileName);
96
97  if(!doc.LoadFile())
98  {
[7221]99    PRINTF(2)("Loading file %s failed for spaceship.\n", fileName.c_str());
[6868]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)
[9965]113    : secWeaponMan(this),
[9961]114    supportedPlaymodes(Playable::Full3D || Playable::Horizontal || Playable::Vertical),
115    playmode(Playable::Full3D)
[6868]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{
[9869]129  //  this->setRelDir(Quaternion(M_PI, Vector(1,0,0)));
130  this->registerObject(this, SpaceShip::_objectList);
[6868]131
132  PRINTF(4)("SPACESHIP INIT\n");
133
134  //weapons:
[9996]135  Weapon* wpRight1 = new LightBlaster ();
136  wpRight1->setName("Light Blaster Right");
137  Weapon* wpLeft1 = new LightBlaster ();
138  wpLeft1->setName("Medium Blaster Left");
[6868]139
[9996]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
[9970]150  Weapon* cannon = new BoomerangGun();//Cannon();
151  cannon->setName("End of World");
[6868]152
[9961]153
[9996]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);
[9965]160  this->secWeaponMan.addWeapon( cannon, 0, 0);
[9961]161
[9965]162  this->weaponMan.changeWeaponConfig(0);
[9961]163
[9996]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);
[9961]170  cannon->requestAction(WA_ACTIVATE);
[9965]171
[9970]172  curWeaponPrimary    = 0;
173  curWeaponSecondary  = 0;
[9965]174
175  Playable::weaponConfigChanged();
176
[9970]177  reactorOutput     = 10;
[9965]178
[9970]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
[9961]190  /*
[6868]191  this->addWeapon(wpLeft, 1, 0);
192  this->addWeapon(wpRight,1 ,1);
[7087]193  //this->addWeapon(cannon, 0, 6);
[6868]194
[7337]195  this->getWeaponManager().changeWeaponConfig(1);
[9961]196  */
[6868]197
[9970]198  this->loadModel("models/ships/mantawing.obj");
[6868]199
[9965]200  bUp = bDown = bLeft = bRight = bAscend = bDescend = bRollL = bRollR = bFire = bSecFire = false;
[9961]201
[6868]202  xMouse = yMouse = 0;
203  yInvert = 1;
204  mouseSensitivity = 0.001;
[7122]205  airViscosity = 0.9;
[6868]206  controlVelocityX = 25;
207  controlVelocityY = 150;
208  shipInertia = 1.5;
[9869]209  //  cycle = 0.0;
[6868]210
[9970]211  this->setHealthMax(shieldMax);
212  this->setHealth(shieldCur);
[6868]213
[6947]214  travelSpeed = 0.0;
[6868]215  acceleration = 3;
216  this->velocity = this->getAbsDirX()*travelSpeed;
217  this->mouseDir = this->getAbsDir();
218  this->pitchDir = this->getAbsDir();
219
[9965]220
[9869]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);
[6868]231
232  //add events to the eventlist
[6997]233  registerEvent(KeyMapper::PEV_FORWARD);
234  registerEvent(KeyMapper::PEV_BACKWARD);
[6868]235  registerEvent(KeyMapper::PEV_LEFT);
236  registerEvent(KeyMapper::PEV_RIGHT);
237  //registerEvent(SDLK_q);
238  //registerEvent(SDLK_e);
239  registerEvent(KeyMapper::PEV_FIRE1);
[9958]240  registerEvent(KeyMapper::PEV_FIRE2);                  // Added for secondary weapon support
[6868]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
[9965]247  this->weaponMan.setSlotCount(6);
[6868]248
[9965]249  this->weaponMan.setSlotPosition(0, Vector(-2.6, .1, -3.0));
250  this->weaponMan.setSlotCapability(0, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL);
[6868]251
[9965]252  this->weaponMan.setSlotPosition(1, Vector(-2.6, .1, 3.0));
253  this->weaponMan.setSlotCapability(1, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL);
[6868]254
[9965]255  this->weaponMan.setSlotPosition(2, Vector(-1.5, .5, -.5));
256  this->weaponMan.setSlotDirection(2, Quaternion(-M_PI_4*.5, Vector(1,0,0)));
[6868]257
[9965]258  this->weaponMan.setSlotPosition(3, Vector(-1.5, .5, .5));
259  this->weaponMan.setSlotDirection(3, Quaternion(M_PI_4*.5, Vector(1,0,0)));
[6868]260
[9965]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)));
[6868]263
[9965]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)));
[9961]266
267  this->secWeaponMan.setSlotCount(6);
268
[9965]269  this->secWeaponMan.setSlotPosition(0, Vector(2.6, -2.5, 0));
[9961]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)));
[9965]286
[9869]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)));:
[6868]293
[9965]294  this->weaponMan.getFixedTarget()->setParent(this);
295  this->weaponMan.getFixedTarget()->setRelCoor(100000,0,0);
[6868]296
[9961]297  this->secWeaponMan.getFixedTarget()->setParent(this);
298  this->secWeaponMan.getFixedTarget()->setRelCoor(100000,0,0);
[6868]299
[9965]300  dynamic_cast<Element2D*>(this->weaponMan.getFixedTarget())->setVisibility( false);
[9961]301
[6868]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);
[9008]320
[9656]321  registerVar( new SynchronizeableVector( &velocity, &velocity, "velocity", PERMISSION_MASTER_SERVER ) );
[7954]322  registerVar( new SynchronizeableQuaternion( &mouseDir, &mouseDir, "mousedir", PERMISSION_OWNER ) );
[6868]323
[7954]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 ) );
[6868]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
[7346]344void SpaceShip::setPlayDirection(const Quaternion& quat, float speed)
[7056]345{
[7095]346  this->mouseDir = quat;
[7056]347}
[6868]348
[7056]349
[7085]350void SpaceShip::reset()
351{
[9965]352  bUp = bDown = bLeft = bRight = bAscend = bDescend = bRollL = bRollR = bFire = bSecFire = false;
[7056]353
[7085]354  xMouse = yMouse = 0;
355
356  this->setHealth(80);
357  this->velocity = Vector(0.0, 0.0, 0.0);
358}
359
360
[6868]361void SpaceShip::enter()
362{
[7337]363  dynamic_cast<Element2D*>(this->getWeaponManager().getFixedTarget())->setVisibility( true);
[6868]364  this->attachCamera();
365}
366
367void SpaceShip::leave()
368{
[7337]369  dynamic_cast<Element2D*>(this->getWeaponManager().getFixedTarget())->setVisibility( false);
[6868]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{
[9961]415  // Playable::tick(time);$
[6868]416
[9961]417  // Own Tick Setup, as a different fire routine is used on the weapon manager
[9965]418  this->weaponMan.tick(time);
[9961]419  this->secWeaponMan.tick(time);
420
[9965]421  if( this->bFire)
[9961]422  {
[9965]423    this->weaponMan.fire();
[9961]424  }
425  if( this->bSecFire)
426  {
427    this->secWeaponMan.fire();
[9965]428    this->bSecFire = !this->bSecFire;   // FIXME This currently is needed to prevent "echo fires" of a second rocket after its cooldown has passed
[9961]429  }
430
[9970]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
[9965]436  this->weaponRegen(time);
437
[9970]438  // current engine speed output
439  this->engineSpeedCur = this->engineSpeedBase + this->reactorOutput * this->engineEnergyShare;
440
441
442
[8708]443  if( ( xMouse != 0 || yMouse != 0 ) && this->getOwner() == SharedNetworkData::getInstance()->getHostID() )
[9869]444  {
[6868]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;
[9869]454  }
[6868]455
[9970]456 
[6868]457
[9958]458
[9869]459  //   if( this != State::getPlayer()->getControllable())
460  //     return;
[6868]461
[9235]462  // spaceship controlled movement fire(bool bF){ this->bFire = bF;}
[7954]463  //if (this->getOwner() == this->getHostID())
[9869]464  this->calculateVelocity(time);
[6868]465
[6959]466
[6868]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
[9869]477  rotQuat = Quaternion::quatSlerp( this->getAbsDir(), mouseDir, 0.5);//fabsf(time)*shipInertia);
478  if (this->getAbsDir().distance(rotQuat) > 0.00000000000001)
[6868]479    this->setAbsDir( rotQuat);
[9869]480  //this->setAbsDirSoft(mouseDir,5);
[6868]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
[9869]502  //   PRINTF(0)("id of %s is: %i\n", this->getName(), this->getOMListNumber());
[6868]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  /*
[9235]514  Vector rot(0.0, 0.0, 0.0); // wird ben�igt fr Helicopter
[6868]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 )
[9869]523  {
524    //this->shiftCoor(this->getAbsDirX());
525    //accel += (this->getAbsDirX())*2;
526    accel += (this->getAbsDirX())*acceleration;
[6868]527
[9869]528  }
[6868]529
530  if( this->bDown )
[9869]531  {
532    //this->shiftCoor((this->getAbsDirX())*-1);
533    //accel -= (this->getAbsDirX())*2;
[6868]534    //if(velocity.len() > 50)
[9869]535    accel -= (this->getAbsDirX())*0.5*acceleration;
[6868]536
537
538
[9869]539  }
[6868]540
541  if( this->bLeft/* > -this->getRelCoor().z*2*/)
542  {
543    this->shiftDir(Quaternion(time, Vector(0,1,0)));
[9869]544    //    accel -= rightDirection;
[6868]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));
[9869]563    //    accel -= rightDirection;
[6868]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
[9869]581    //    accel += upDirection;
[6868]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
[6959]596  velocity += accel*time*10;
[6868]597  //rot.normalize();
598  //this->setRelDirSoft(Quaternion(rotVal, rot), 5);
[9961]599
[6868]600}
601
602/**
603 * @todo switch statement ??
604 */
605void SpaceShip::process(const Event &event)
606{
[9961]607  //Playable::process(event);
[6868]608
609  if( event.type == KeyMapper::PEV_LEFT)
[9869]610    this->bRollL = event.bPressed;
[6868]611  else if( event.type == KeyMapper::PEV_RIGHT)
[9869]612    this->bRollR = event.bPressed;
[6997]613  else if( event.type == KeyMapper::PEV_FORWARD)
[6868]614    this->bUp = event.bPressed; //this->shiftCoor(0,.1,0);
[6997]615  else if( event.type == KeyMapper::PEV_BACKWARD)
[6868]616    this->bDown = event.bPressed; //this->shiftCoor(0,-.1,0);
[9961]617  else if( event.type == KeyMapper::PEV_FIRE2)
618    this->bSecFire = event.bPressed;
[9958]619  else if( event.type == KeyMapper::PEV_FIRE1)
[9965]620    this->bFire = event.bPressed;
[6868]621  else if( event.type == EV_MOUSE_MOTION)
622  {
[9961]623
[6868]624    this->xMouse += event.xRel;
625    this->yMouse += event.yRel;
626  }
627}
628
[9235]629void SpaceShip::destroy( WorldEntity* killer )
[9008]630{
631  PRINTF(0)("spaceship destroy\n");
632}
[6868]633
[9008]634void SpaceShip::respawn( )
635{
636  toList( OM_PLAYERS );
637}
[6868]638
639
[9957]640void SpaceShip::damage(float pDamage, float eDamage){
[9950]641if( this->shieldActive) {
642    if( this->shieldCur > pDamage) {
643      this->shieldCur = this->shieldCur - pDamage;
644    }
645    else { // shield <= pDamage
[9987]646      this->shieldCur -=pDamage;
647      this->shieldActive = false; //shield collapses
[9950]648      pDamage = pDamage - this->shieldCur;
649      if( !this->shieldActive) {
[9957]650        this->armorCur -= pDamage / 2; // remaining damages hits armor at half rate
[9953]651        this->electronicCur -= eDamage;
[9950]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
[9987]662
[9957]663void SpaceShip::regen(float time){
664  float tmp;
[9963]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){
[9970]673    tmp =  this->shieldCur + (this->shieldRegen + this->reactorOutput * this->shieldEnergyShare) * time;
[9957]674    if( tmp > shieldMax)
[9953]675      this->shieldCur = this->shieldMax;
676    else
[9957]677      this->shieldCur = tmp;
678    this->shieldActive = ( this->shieldActive || this->shieldCur > shieldTH);
[9953]679  }
[9970]680
681  this->setHealth( this->shieldCur);      // FIXME currently just to test share system
682
[9963]683  if (this->electronicCur != this->electronicMax || this->electronicRegen != 0){
[9957]684    tmp = this->electronicCur + this->electronicRegen * time;
685    if ( tmp > electronicMax)
[9953]686      this->electronicCur = this->electronicMax;
687    else
[9957]688      this->electronicCur = tmp;
[9953]689  }
[9950]690}
[9965]691
[9987]692
[9965]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;
[9987]701  for( unsigned int i=0; i < this->weaponMan.getSlotCount(); i++)
[9965]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}
[9975]713
[9987]714
[9975]715void SpaceShip::enterPlaymode(Playable::Playmode playmode)
716{
717}
718
[9987]719
[9975]720void SpaceShip::movement (float dt)
721{
722}
Note: See TracBrowser for help on using the repository browser.