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
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:
[9979]135  Weapon* wpRight = new HeavyBlaster ();
[9970]136  wpRight->setName("Blaster Right");
[9979]137  Weapon* wpLeft = new HeavyBlaster ();
[9970]138  wpLeft->setName("Blaster Left");
[6868]139
[9970]140  Weapon* cannon = new BoomerangGun();//Cannon();
141  cannon->setName("End of World");
[6868]142
[9961]143
[9965]144  this->weaponMan.addWeapon( wpLeft, 0, 0);
145  this->weaponMan.addWeapon( wpRight, 0, 1);
146  this->secWeaponMan.addWeapon( cannon, 0, 0);
[9961]147
[9965]148  this->weaponMan.changeWeaponConfig(0);
[9961]149
150  wpRight->requestAction(WA_ACTIVATE);
151  wpLeft->requestAction(WA_ACTIVATE);
152  cannon->requestAction(WA_ACTIVATE);
[9965]153
[9970]154  curWeaponPrimary    = 0;
155  curWeaponSecondary  = 0;
[9965]156
157  Playable::weaponConfigChanged();
158
[9970]159  reactorOutput     = 10;
[9965]160
[9970]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
[9961]172  /*
[6868]173  this->addWeapon(wpLeft, 1, 0);
174  this->addWeapon(wpRight,1 ,1);
[7087]175  //this->addWeapon(cannon, 0, 6);
[6868]176
[7337]177  this->getWeaponManager().changeWeaponConfig(1);
[9961]178  */
[6868]179
[9970]180  this->loadModel("models/ships/mantawing.obj");
[6868]181
[9965]182  bUp = bDown = bLeft = bRight = bAscend = bDescend = bRollL = bRollR = bFire = bSecFire = false;
[9961]183
[6868]184  xMouse = yMouse = 0;
185  yInvert = 1;
186  mouseSensitivity = 0.001;
[7122]187  airViscosity = 0.9;
[6868]188  controlVelocityX = 25;
189  controlVelocityY = 150;
190  shipInertia = 1.5;
[9869]191  //  cycle = 0.0;
[6868]192
[9970]193  this->setHealthMax(shieldMax);
194  this->setHealth(shieldCur);
[6868]195
[6947]196  travelSpeed = 0.0;
[6868]197  acceleration = 3;
198  this->velocity = this->getAbsDirX()*travelSpeed;
199  this->mouseDir = this->getAbsDir();
200  this->pitchDir = this->getAbsDir();
201
[9965]202
[9869]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);
[6868]213
214  //add events to the eventlist
[6997]215  registerEvent(KeyMapper::PEV_FORWARD);
216  registerEvent(KeyMapper::PEV_BACKWARD);
[6868]217  registerEvent(KeyMapper::PEV_LEFT);
218  registerEvent(KeyMapper::PEV_RIGHT);
219  //registerEvent(SDLK_q);
220  //registerEvent(SDLK_e);
221  registerEvent(KeyMapper::PEV_FIRE1);
[9958]222  registerEvent(KeyMapper::PEV_FIRE2);                  // Added for secondary weapon support
[6868]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
[9965]229  this->weaponMan.setSlotCount(6);
[6868]230
[9965]231  this->weaponMan.setSlotPosition(0, Vector(-2.6, .1, -3.0));
232  this->weaponMan.setSlotCapability(0, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL);
[6868]233
[9965]234  this->weaponMan.setSlotPosition(1, Vector(-2.6, .1, 3.0));
235  this->weaponMan.setSlotCapability(1, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL);
[6868]236
[9965]237  this->weaponMan.setSlotPosition(2, Vector(-1.5, .5, -.5));
238  this->weaponMan.setSlotDirection(2, Quaternion(-M_PI_4*.5, Vector(1,0,0)));
[6868]239
[9965]240  this->weaponMan.setSlotPosition(3, Vector(-1.5, .5, .5));
241  this->weaponMan.setSlotDirection(3, Quaternion(M_PI_4*.5, Vector(1,0,0)));
[6868]242
[9965]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)));
[6868]245
[9965]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)));
[9961]248
249  this->secWeaponMan.setSlotCount(6);
250
[9965]251  this->secWeaponMan.setSlotPosition(0, Vector(2.6, -2.5, 0));
[9961]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)));
[9965]268
[9869]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)));:
[6868]275
[9965]276  this->weaponMan.getFixedTarget()->setParent(this);
277  this->weaponMan.getFixedTarget()->setRelCoor(100000,0,0);
[6868]278
[9961]279  this->secWeaponMan.getFixedTarget()->setParent(this);
280  this->secWeaponMan.getFixedTarget()->setRelCoor(100000,0,0);
[6868]281
[9965]282  dynamic_cast<Element2D*>(this->weaponMan.getFixedTarget())->setVisibility( false);
[9961]283
[6868]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);
[9008]302
[9656]303  registerVar( new SynchronizeableVector( &velocity, &velocity, "velocity", PERMISSION_MASTER_SERVER ) );
[7954]304  registerVar( new SynchronizeableQuaternion( &mouseDir, &mouseDir, "mousedir", PERMISSION_OWNER ) );
[6868]305
[7954]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 ) );
[6868]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
[7346]326void SpaceShip::setPlayDirection(const Quaternion& quat, float speed)
[7056]327{
[7095]328  this->mouseDir = quat;
[7056]329}
[6868]330
[7056]331
[7085]332void SpaceShip::reset()
333{
[9965]334  bUp = bDown = bLeft = bRight = bAscend = bDescend = bRollL = bRollR = bFire = bSecFire = false;
[7056]335
[7085]336  xMouse = yMouse = 0;
337
338  this->setHealth(80);
339  this->velocity = Vector(0.0, 0.0, 0.0);
340}
341
342
[6868]343void SpaceShip::enter()
344{
[7337]345  dynamic_cast<Element2D*>(this->getWeaponManager().getFixedTarget())->setVisibility( true);
[6868]346  this->attachCamera();
347}
348
349void SpaceShip::leave()
350{
[7337]351  dynamic_cast<Element2D*>(this->getWeaponManager().getFixedTarget())->setVisibility( false);
[6868]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{
[9961]397  // Playable::tick(time);$
[6868]398
[9961]399  // Own Tick Setup, as a different fire routine is used on the weapon manager
[9965]400  this->weaponMan.tick(time);
[9961]401  this->secWeaponMan.tick(time);
402
[9965]403  if( this->bFire)
[9961]404  {
[9965]405    this->weaponMan.fire();
[9961]406  }
407  if( this->bSecFire)
408  {
409    this->secWeaponMan.fire();
[9965]410    this->bSecFire = !this->bSecFire;   // FIXME This currently is needed to prevent "echo fires" of a second rocket after its cooldown has passed
[9961]411  }
412
[9970]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
[9965]418  this->weaponRegen(time);
419
[9970]420  // current engine speed output
421  this->engineSpeedCur = this->engineSpeedBase + this->reactorOutput * this->engineEnergyShare;
422
423
424
[8708]425  if( ( xMouse != 0 || yMouse != 0 ) && this->getOwner() == SharedNetworkData::getInstance()->getHostID() )
[9869]426  {
[6868]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;
[9869]436  }
[6868]437
[9970]438 
[6868]439
[9958]440
[9869]441  //   if( this != State::getPlayer()->getControllable())
442  //     return;
[6868]443
[9235]444  // spaceship controlled movement fire(bool bF){ this->bFire = bF;}
[7954]445  //if (this->getOwner() == this->getHostID())
[9869]446  this->calculateVelocity(time);
[6868]447
[6959]448
[6868]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
[9869]459  rotQuat = Quaternion::quatSlerp( this->getAbsDir(), mouseDir, 0.5);//fabsf(time)*shipInertia);
460  if (this->getAbsDir().distance(rotQuat) > 0.00000000000001)
[6868]461    this->setAbsDir( rotQuat);
[9869]462  //this->setAbsDirSoft(mouseDir,5);
[6868]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
[9869]484  //   PRINTF(0)("id of %s is: %i\n", this->getName(), this->getOMListNumber());
[6868]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  /*
[9235]496  Vector rot(0.0, 0.0, 0.0); // wird ben�igt fr Helicopter
[6868]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 )
[9869]505  {
506    //this->shiftCoor(this->getAbsDirX());
507    //accel += (this->getAbsDirX())*2;
508    accel += (this->getAbsDirX())*acceleration;
[6868]509
[9869]510  }
[6868]511
512  if( this->bDown )
[9869]513  {
514    //this->shiftCoor((this->getAbsDirX())*-1);
515    //accel -= (this->getAbsDirX())*2;
[6868]516    //if(velocity.len() > 50)
[9869]517    accel -= (this->getAbsDirX())*0.5*acceleration;
[6868]518
519
520
[9869]521  }
[6868]522
523  if( this->bLeft/* > -this->getRelCoor().z*2*/)
524  {
525    this->shiftDir(Quaternion(time, Vector(0,1,0)));
[9869]526    //    accel -= rightDirection;
[6868]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));
[9869]545    //    accel -= rightDirection;
[6868]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
[9869]563    //    accel += upDirection;
[6868]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
[6959]578  velocity += accel*time*10;
[6868]579  //rot.normalize();
580  //this->setRelDirSoft(Quaternion(rotVal, rot), 5);
[9961]581
[6868]582}
583
584/**
585 * @todo switch statement ??
586 */
587void SpaceShip::process(const Event &event)
588{
[9961]589  //Playable::process(event);
[6868]590
591  if( event.type == KeyMapper::PEV_LEFT)
[9869]592    this->bRollL = event.bPressed;
[6868]593  else if( event.type == KeyMapper::PEV_RIGHT)
[9869]594    this->bRollR = event.bPressed;
[6997]595  else if( event.type == KeyMapper::PEV_FORWARD)
[6868]596    this->bUp = event.bPressed; //this->shiftCoor(0,.1,0);
[6997]597  else if( event.type == KeyMapper::PEV_BACKWARD)
[6868]598    this->bDown = event.bPressed; //this->shiftCoor(0,-.1,0);
[9961]599  else if( event.type == KeyMapper::PEV_FIRE2)
600    this->bSecFire = event.bPressed;
[9958]601  else if( event.type == KeyMapper::PEV_FIRE1)
[9965]602    this->bFire = event.bPressed;
[6868]603  else if( event.type == EV_MOUSE_MOTION)
604  {
[9961]605
[6868]606    this->xMouse += event.xRel;
607    this->yMouse += event.yRel;
608  }
609}
610
[9235]611void SpaceShip::destroy( WorldEntity* killer )
[9008]612{
613  PRINTF(0)("spaceship destroy\n");
614}
[6868]615
[9008]616void SpaceShip::respawn( )
617{
618  toList( OM_PLAYERS );
619}
[6868]620
621
[9957]622void SpaceShip::damage(float pDamage, float eDamage){
[9950]623if( this->shieldActive) {
624    if( this->shieldCur > pDamage) {
625      this->shieldCur = this->shieldCur - pDamage;
626    }
627    else { // shield <= pDamage
[9987]628      this->shieldCur -=pDamage;
629      this->shieldActive = false; //shield collapses
[9950]630      pDamage = pDamage - this->shieldCur;
631      if( !this->shieldActive) {
[9957]632        this->armorCur -= pDamage / 2; // remaining damages hits armor at half rate
[9953]633        this->electronicCur -= eDamage;
[9950]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
[9987]644
[9957]645void SpaceShip::regen(float time){
646  float tmp;
[9963]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){
[9970]655    tmp =  this->shieldCur + (this->shieldRegen + this->reactorOutput * this->shieldEnergyShare) * time;
[9957]656    if( tmp > shieldMax)
[9953]657      this->shieldCur = this->shieldMax;
658    else
[9957]659      this->shieldCur = tmp;
660    this->shieldActive = ( this->shieldActive || this->shieldCur > shieldTH);
[9953]661  }
[9970]662
663  this->setHealth( this->shieldCur);      // FIXME currently just to test share system
664
[9963]665  if (this->electronicCur != this->electronicMax || this->electronicRegen != 0){
[9957]666    tmp = this->electronicCur + this->electronicRegen * time;
667    if ( tmp > electronicMax)
[9953]668      this->electronicCur = this->electronicMax;
669    else
[9957]670      this->electronicCur = tmp;
[9953]671  }
[9950]672}
[9965]673
[9987]674
[9965]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;
[9987]683  for( unsigned int i=0; i < this->weaponMan.getSlotCount(); i++)
[9965]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}
[9975]695
[9987]696
[9975]697void SpaceShip::enterPlaymode(Playable::Playmode playmode)
698{
699}
700
[9987]701
[9975]702void SpaceShip::movement (float dt)
703{
704}
Note: See TracBrowser for help on using the repository browser.