Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 10335 was 10335, checked in by bknecht, 17 years ago

track now works pretty good. I'm really pleased. Check it out, it doesn't crash anymore

File size: 34.8 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"
[10023]28#include "weapons/swarm_launcher.h"
[10170]29#include "weapons/spike_launcher.h"
[10196]30#include "weapons/spike_thrower.h"
[10298]31#include "weapons/acid_launcher.h"
[9970]32#include "weapons/boomerang_gun.h"
[6868]33#include "weapons/turret.h"
34#include "weapons/cannon.h"
35
[10120]36#include "elements/glgui_energywidgetvertical.h"
[10230]37#include "glgui_bar.h"
[10120]38
[9869]39#include "particles/dot_emitter.h"
[10073]40#include "particles/emitter_node.h"
[9869]41#include "particles/sprite_particles.h"
[10081]42#include "effects/trail.h"
[6868]43
[10154]44#include "effects/wobblegrid.h"
45
[7193]46#include "util/loading/factory.h"
[6868]47#include "key_mapper.h"
48
49#include "network_game_manager.h"
[8708]50#include "shared_network_data.h"
[6868]51
52#include "power_ups/weapon_power_up.h"
53#include "power_ups/param_power_up.h"
54
55#include "graphics_engine.h"
56
57#include "plane.h"
58
59#include "state.h"
60#include "player.h"
[10237]61#include "camera.h"
[6868]62
[10113]63
[7193]64#include "util/loading/load_param.h"
[10020]65#include "time.h"
[6868]66
[10096]67#include "track/track.h"
[10291]68#include "math.h"
[7056]69
[10096]70
[6868]71// #include "lib/gui/gl_gui/glgui_bar.h"
72// #include "lib/gui/gl_gui/glgui_pushbutton.h"
73
74
[9869]75#include "class_id_DEPRECATED.h"
76ObjectListDefinitionID(SpaceShip, CL_SPACE_SHIP);
77CREATE_FACTORY(SpaceShip);
[9406]78
[9061]79#include "script_class.h"
[9869]80CREATE_SCRIPTABLE_CLASS(SpaceShip,
81                        addMethod("hasPlayer", Executor0ret<Playable, lua_State*,bool>(&Playable::hasPlayer))
82                        ->addMethod("fire", Executor1<Playable, lua_State*, bool>(&Playable::fire))
83                        ->addMethod("loadModel", Executor2<WorldEntity, lua_State*,const std::string& ,float>(&WorldEntity::loadModel2))
84                        ->addMethod("setName", Executor1<BaseObject, lua_State*,const std::string&>(&BaseObject::setName))
85                        ->addMethod("hide", Executor0<WorldEntity, lua_State*>(&WorldEntity::hide))
86                        ->addMethod("unhide", Executor0<WorldEntity, lua_State*>(&WorldEntity::unhide))
87                        //Coordinates
88                        ->addMethod("setAbsCoor", Executor3<PNode, lua_State*,float,float,float>(&PNode::setAbsCoor))
89                        ->addMethod("getAbsCoorX", Executor0ret<PNode, lua_State*, float>(&PNode::getAbsCoorX))
90                        ->addMethod("getAbsCoorY", Executor0ret<PNode, lua_State*, float>(&PNode::getAbsCoorY))
91                        ->addMethod("getAbsCoorZ", Executor0ret<PNode, lua_State*, float>(&PNode::getAbsCoorZ))
[10017]92                        //->addMethod("setCameraSpeed", Executor1<SpaceShip, lua_State*, float>(&SpaceShip::setCameraSpeed))
[9061]93                       );
[6868]94
95/**
96 *  destructs the spaceship, deletes alocated memory
97 */
98SpaceShip::~SpaceShip ()
99{
[6986]100  this->setPlayer(NULL);
[6868]101}
102
103/**
104 * loads a Spaceships information from a specified file.
105 * @param fileName the name of the File to load the spaceship from (absolute path)
106 */
[7221]107SpaceShip::SpaceShip(const std::string& fileName)
[10019]108    : secWeaponMan(this) //,
109    //supportedPlaymodes(Playable::Vertical) ,
110    //playmode(Playable::Vertical)
[6868]111{
112  this->init();
113  TiXmlDocument doc(fileName);
114
115  if(!doc.LoadFile())
116  {
[7221]117    PRINTF(2)("Loading file %s failed for spaceship.\n", fileName.c_str());
[6868]118    return;
119  }
120
121  this->loadParams(doc.RootElement());
122}
123
124/**
125 *  creates a new Spaceship from Xml Data
126 * @param root the xml element containing spaceship data
127
128   @todo add more parameters to load
129*/
130SpaceShip::SpaceShip(const TiXmlElement* root)
[10019]131    : secWeaponMan(this) //,
132    //supportedPlaymodes(Playable::Vertical) ,
133    //playmode(Playable::Vertical)
[6868]134{
135  this->init();
[10081]136  //this->setParentMode(PNODE_REPARENT_DELETE_CHILDREN);
[6868]137  if (root != NULL)
138    this->loadParams(root);
139
140}
141
142
143/**
144 * initializes a Spaceship
145 */
146void SpaceShip::init()
147{
[9998]148
[10022]149  srand(time(0));   //initialize Random Nomber Generator
150
[9869]151  //  this->setRelDir(Quaternion(M_PI, Vector(1,0,0)));
152  this->registerObject(this, SpaceShip::_objectList);
[6868]153  PRINTF(4)("SPACESHIP INIT\n");
[10121]154  this->weaponMan.setParentEntity( this);
[6868]155  //weapons:
[10098]156 
[9996]157  Weapon* wpRight1 = new LightBlaster ();
[10073]158  wpRight1->setName( "LightBlaster");
[9996]159  Weapon* wpLeft1 = new LightBlaster ();
[10073]160  wpLeft1->setName( "LightBlaster");
[6868]161
[9996]162  Weapon* wpRight2 = new MediumBlaster ();
[10073]163  wpRight2->setName( "MediumBlaster");
[9996]164  Weapon* wpLeft2 = new MediumBlaster ();
[10073]165  wpLeft2->setName( "MediumBlaster");
[10252]166
[10152]167  Weapon* wpRight3 = new HeavyBlaster (1);
[10073]168  wpRight3->setName( "HeavyBlaster");
[10152]169  Weapon* wpLeft3 = new HeavyBlaster (0);
[10073]170  wpLeft3->setName( "HeavyBlaster");
[9996]171
[10173]172  Weapon* cannon = new SwarmLauncher();
173  cannon->setName( "SwarmLauncher");
[6868]174
[10252]175  Weapon* spike = new SpikeThrower();
176  spike->setName( "SpikeThrower" );
[9961]177
[10196]178
[10298]179  Weapon* acid0 = new AcidLauncher();
180  acid0->setName( "AcidSplasher" );
181
182  Weapon* acid1 = new AcidLauncher();
183  acid1->setName( "AcidSplasher" );
184
[10333]185
[10098]186  this->weaponMan.addWeapon( wpLeft1, 0, 0);
187  this->weaponMan.addWeapon( wpRight1, 0, 1);
[9998]188
[10121]189  this->weaponMan.addWeapon( wpLeft2, 1, 2);
190  this->weaponMan.addWeapon( wpRight2, 1, 3);
[9961]191
[10121]192  this->weaponMan.addWeapon( wpLeft3, 2, 4);
193  this->weaponMan.addWeapon( wpRight3, 2, 5);
[10333]194/*
[10152]195  this->weaponMan.addWeapon( wpLeft1, 3, 0);
196  this->weaponMan.addWeapon( wpRight1, 3, 1);
197
198  this->weaponMan.addWeapon( wpLeft2, 3, 2);
199  this->weaponMan.addWeapon( wpRight2, 3, 3);
200
201  this->weaponMan.addWeapon( wpLeft3, 3, 4);
202  this->weaponMan.addWeapon( wpRight3, 3, 5);
[10333]203*/
[10152]204
[10333]205  this->weaponMan.addWeapon( acid0, 3, 0);
206  this->weaponMan.addWeapon( acid1, 3, 1);
[9998]207
[10333]208
[10298]209  this->secWeaponMan.addWeapon( cannon, 0, 2);
210  this->secWeaponMan.addWeapon( spike, 1, 3);
211//   this->secWeaponMan.addWeapon( acid0, 2, 2);
212//   this->secWeaponMan.addWeapon( acid1, 2, 3);
[10252]213
[10298]214
[10333]215  this->weaponMan.changeWeaponConfig(3);
[10271]216  this->secWeaponMan.changeWeaponConfig(1);
[10113]217
[10333]218  curWeaponPrimary    = 0;
219  curWeaponSecondary  = 1;
[9965]220
221  Playable::weaponConfigChanged();
222
[9970]223  reactorOutput     = 10;
[9965]224
[9970]225  weaponEnergyRegen = 10;       // 10 einheiten pro Sekunde
226  engineSpeedBase   = 5;
227  shieldRegen       = 2;
228
229  shieldEnergyShare = 0.3;
230  weaponEnergyShare = 0.3;
231  engineEnergyShare = 0.4;
232
233  shieldCur         = 20;
234  shieldMax         = 100;
[10252]235  shieldTH          = .2 * shieldMax;   // shield power must be 20% before shield kicks in again
[9970]236
[10119]237  this->setHealth( 20);
238  this->setHealthMax( 100);
239
[10024]240  electronicCur = 50;
[10022]241  electronicMax = 50;
[10020]242  electronicRegen   = 3;
243  electronicTH      = .7 * electronicMax; // 30% of eDamage can be handled by the ship
244
[6868]245
[9970]246  this->loadModel("models/ships/mantawing.obj");
[10017]247  //this->setVisibiliy(false);
[6868]248
[10017]249  bForward = bBackward = bLeft = bRight = bAscend = bDescend = bRollL = bRollR = bFire = bSecFire = false;
[6868]250
[9970]251  this->setHealthMax(shieldMax);
252  this->setHealth(shieldCur);
[6868]253
[10017]254  this->travelNode = new PNode();
255
256  // camera - issue
257  this->cameraNode.addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT);
258  this->cameraNode.addNodeFlags(PNODE_PROHIBIT_CHILD_DELETE);
259
[10120]260  // widget handling
[10139]261  /*
[10120]262  this->electronicWidget = new OrxGui::GLGuiEnergyWidgetVertical();
263  this->electronicWidget->setDisplayedName(std::string(this->getClassName()) + " Electronics:");
264  this->electronicWidget->setSize2D(30,400);
265  this->electronicWidget->setAbsCoor2D(150,200);
266  this->electronicWidget->shiftDir2D(270);
267  this->updateElectronicWidget();
268  this->shieldWidget = new OrxGui::GLGuiEnergyWidgetVertical();
269  this->shieldWidget->setDisplayedName(std::string(this->getClassName()) + " Shield:");
270  this->shieldWidget->setSize2D(30,400);
271  this->shieldWidget->setAbsCoor2D(200,200);
272  this->shieldWidget->shiftDir2D(270);
273  this->updateShieldWidget();
274  if (this->hasPlayer())
275  {
276    State::getPlayer()->hud().setShiledWidget(this->shieldWidget);
277    State::getPlayer()->hud().setEnergyWidget(this->electronicWidget);
278  }
[10139]279  */
280  this->electronicWidget = NULL;
281  this->shieldWidget = NULL;
[6868]282
283  //add events to the eventlist
[6997]284  registerEvent(KeyMapper::PEV_FORWARD);
285  registerEvent(KeyMapper::PEV_BACKWARD);
[6868]286  registerEvent(KeyMapper::PEV_LEFT);
287  registerEvent(KeyMapper::PEV_RIGHT);
288  //registerEvent(SDLK_q);
289  //registerEvent(SDLK_e);
290  registerEvent(KeyMapper::PEV_FIRE1);
[9958]291  registerEvent(KeyMapper::PEV_FIRE2);                  // Added for secondary weapon support
[6868]292  registerEvent(KeyMapper::PEV_NEXT_WEAPON);
293  registerEvent(KeyMapper::PEV_PREVIOUS_WEAPON);
294  //registerEvent(SDLK_PAGEUP);
295  //registerEvent(SDLK_PAGEDOWN);
296  registerEvent(EV_MOUSE_MOTION);
297
[10073]298  this->weaponMan.setParentEntity( this);
299  this->secWeaponMan.setParentEntity( this);
300
[10298]301  this->weaponMan.setSlotCount(8);
[6868]302
[10152]303  this->weaponMan.setSlotPosition(0, Vector(0.0, 0, -3.0));
[9965]304  this->weaponMan.setSlotCapability(0, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL);
[6868]305
[10152]306  this->weaponMan.setSlotPosition(1, Vector(0.0, 0, 3.0));
[9965]307  this->weaponMan.setSlotCapability(1, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL);
[6868]308
[10286]309  this->weaponMan.setSlotPosition(2, Vector(1.0, 0, -1.5));
[9965]310  this->weaponMan.setSlotDirection(2, Quaternion(-M_PI_4*.5, Vector(1,0,0)));
[6868]311
[10286]312  this->weaponMan.setSlotPosition(3, Vector(1.0, 0, 1.5));
[9965]313  this->weaponMan.setSlotDirection(3, Quaternion(M_PI_4*.5, Vector(1,0,0)));
[6868]314
[10133]315  this->weaponMan.setSlotPosition(4, Vector(1.5, 0, .5));
[9965]316  this->weaponMan.setSlotDirection(4, Quaternion(-M_PI_4*.5+M_PI, Vector(1,0,0)));
[6868]317
[10133]318  this->weaponMan.setSlotPosition(5, Vector(1.5, 0, -.5));
[9965]319  this->weaponMan.setSlotDirection(5, Quaternion(+M_PI_4*.5-M_PI, Vector(1,0,0)));
[9961]320
[10298]321  this->weaponMan.setSlotPosition(6, Vector(0.5, 0, 2.5));
322  this->weaponMan.setSlotDirection(6, Quaternion(-M_PI_4*.5+M_PI, Vector(1,0,0)));
323
324  this->weaponMan.setSlotPosition(7, Vector(0.5, 0, -2.5));
325  this->weaponMan.setSlotDirection(7, Quaternion(+M_PI_4*.5-M_PI, Vector(1,0,0)));
326
[9961]327  this->secWeaponMan.setSlotCount(6);
328
[10073]329  this->secWeaponMan.setSlotPosition(0, Vector(1.5, 0, 0));
[9961]330  this->secWeaponMan.setSlotCapability(0, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL);
331
[10073]332  this->secWeaponMan.setSlotPosition(1, Vector(2.6, 0, 3.0));
[9961]333  this->secWeaponMan.setSlotCapability(1, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL);
334
[10073]335  this->secWeaponMan.setSlotPosition(2, Vector(1.5, 0, -.5));
[9961]336  this->secWeaponMan.setSlotDirection(2, Quaternion(-M_PI_4*.5, Vector(1,0,0)));
337
[10073]338  this->secWeaponMan.setSlotPosition(3, Vector(1.5, 0, .5));
[9961]339  this->secWeaponMan.setSlotDirection(3, Quaternion(M_PI_4*.5, Vector(1,0,0)));
340
[10073]341  this->secWeaponMan.setSlotPosition(4, Vector(1.5, 0, .5));
[9961]342  this->secWeaponMan.setSlotDirection(4, Quaternion(-M_PI_4*.5+M_PI, Vector(1,0,0)));
343
[10073]344  this->secWeaponMan.setSlotPosition(5, Vector(1.5, 0, -.5));
[9961]345  this->secWeaponMan.setSlotDirection(5, Quaternion(+M_PI_4*.5-M_PI, Vector(1,0,0)));
[9965]346
[6868]347
[9965]348  this->weaponMan.getFixedTarget()->setParent(this);
349  this->weaponMan.getFixedTarget()->setRelCoor(100000,0,0);
[10004]350
[9998]351 
[9961]352  this->secWeaponMan.getFixedTarget()->setParent(this);
353  this->secWeaponMan.getFixedTarget()->setRelCoor(100000,0,0);
[10004]354  this->secWeaponMan.setRotationSpeed(0);
[6868]355
[9965]356  dynamic_cast<Element2D*>(this->weaponMan.getFixedTarget())->setVisibility( false);
[9961]357
[6868]358
[10017]359  registerVar( new SynchronizeableBool( &bForward, &bForward, "bForward", PERMISSION_OWNER ) );
360  registerVar( new SynchronizeableBool( &bBackward, &bBackward, "bBackward", PERMISSION_OWNER ) );
361  registerVar( new SynchronizeableBool( &bLeft, &bLeft, "bLeft", PERMISSION_OWNER ) );
362  registerVar( new SynchronizeableBool( &bRight, &bRight, "bRight", PERMISSION_OWNER ) );
363  registerVar( new SynchronizeableFloat( &cameraLook, &cameraLook, "cameraLook", PERMISSION_OWNER ) );
364  registerVar( new SynchronizeableFloat( &rotation, &rotation, "rotation", PERMISSION_OWNER ) );
[10023]365  registerVar( new SynchronizeableBool( &bFire, &bFire, "bSecFire", PERMISSION_OWNER));
[10017]366  registerVar( new SynchronizeableVector( &velocity, &velocity, "velocity", PERMISSION_MASTER_SERVER ) );
367
368  //this->airFriction = 0.5f;
[10291]369  //this->travelDistancePlus = Vector2D(38.0, 43.0);
370  //this->travelDistanceMinus = Vector2D(-38.0, -43.0);
[10332]371  this->travelDistancePlus = Vector2D(50,50);
372  this->travelDistanceMinus = Vector2D(-50,-50);
[10291]373  this->isTravelDistanceInit = false;
[10306]374  this->actionWidthPercentage = 1;
[10291]375
[10017]376  this->cameraSpeed = 40;
[10019]377  this->cameraLook = 0.0f;
378  //this->airFriction = 0.0f;
[10017]379
[10020]380  srand(time(0));  //initaialize RNG
381
[10017]382  this->travelNode->debugDraw();
[10032]383
384  this->setSupportedPlaymodes(Playable::Horizontal | Playable::Vertical);
[10081]385
[10261]386  /// FIXME
387  this->trail = new Trail( 5, 10, .2, this);
[10081]388  this->trail->setTexture( "maps/engine.png");
389
[10261]390  this->trailL = new Trail( 5, 10, .2, this);
[10081]391  this->trailL->setTexture( "maps/engine.png");
392
[10261]393  this->trailR = new Trail( 5, 10, .2, this);
[10081]394  this->trailR->setTexture( "maps/engine.png");
[10098]395
[10113]396
[10098]397  this->toList(OM_GROUP_00);
[10154]398
[10155]399  //FIXME Just testaddition to show the wobblegrid
[10261]400/*
[10156]401  this->test  = new Wobblegrid(5);
[10159]402  test->setTexture("maps/blub.png");
[10154]403 
404  test->setAbsCoor( this->getAbsCoor() + Vector(0, 2, 0));
405  test->setParent( this);
[10261]406*/
[10154]407 
[6868]408}
409
410
411/**
412 * loads the Settings of a SpaceShip from an XML-element.
413 * @param root the XML-element to load the Spaceship's properties from
414 */
415void SpaceShip::loadParams(const TiXmlElement* root)
416{
417  Playable::loadParams(root);
[10032]418
419  LoadParam(root, "playmode", this, SpaceShip, setPlaymodeXML);
[10270]420  LoadParam(root, "cameraDistance", this, SpaceShip, setCameraDistance);
421  LoadParam(root, "cameraFovy", this, SpaceShip, setCameraFovy);
[10332]422  //LoadParam(root, "actionWidthPercentage", this, SpaceShip, setActionWidthPercentage);
[10281]423
424  State::getCamera()->setViewMode(Camera::ViewTop);
[6868]425}
426
[10032]427
[10017]428void SpaceShip::setPlayDirection(const Quaternion& rot, float speed)
[7056]429{
[10032]430  //this->direction = Quaternion (rot.getHeading(), Vector(0,1,0));
[7056]431}
[6868]432
[7085]433void SpaceShip::reset()
434{
[10017]435  bForward = bBackward = bLeft = bRight = bAscend = bDescend = bRollL = bRollR = bFire = bSecFire = false;
[7056]436
[10017]437  //xMouse = yMouse = 0;
[7085]438
439  this->setHealth(80);
440  this->velocity = Vector(0.0, 0.0, 0.0);
441}
442
443
[6868]444void SpaceShip::enter()
445{
[10004]446  this->secWeaponMan.showCrosshair();
[10095]447  this->toList( OM_GROUP_01 );
[10270]448  State::getPlayer()->hud().setRadarCenterNode(this->travelNode);
[10233]449  State::getPlayer()->hud().setOverlayActive(true);
[10194]450  //dynamic_cast <OrxGui::GLGuiEnergyWidgetVertical*> (State::getPlayer()->hud().getArmorWidget())->setDisplayedName("Armor");
[10004]451  //dynamic_cast<Element2D*>(this->secWeaponMan.getFixedTarget())->setVisibility( true);
[10019]452  //this->attachCamera();
[10032]453 // this->setPlaymode(Playable::Horizontal);
[6868]454}
455
456void SpaceShip::leave()
457{
[10004]458  this->secWeaponMan.hideCrosshair();
[10095]459  this->toList( OM_GROUP_00);
[10233]460  State::getPlayer()->hud().setOverlayActive(false);
[10237]461  State::getCamera()->setEventHandling(true);
[10270]462  State::getPlayer()->hud().setRadarCenterNode(NULL);
[10004]463  //dynamic_cast<Element2D*>(this->secWeaponMan.getFixedTarget())->setVisibility( false);
[10019]464  //this->detachCamera();
[6868]465}
466
467
468/**
469 *  effect that occurs after the SpaceShip is spawned
470*/
471void SpaceShip::postSpawn ()
472{
[10261]473  if(this->hasPlayer())
474    Playable::postSpawn();
475
[6868]476  //setCollision(new CollisionCluster(1.0, Vector(0,0,0)));
477}
478
479/**
480 *  the action occuring if the spaceship left the game
481*/
482void SpaceShip::leftWorld ()
[10073]483{
484
[10064]485}
[6868]486
487WorldEntity* ref = NULL;
488
489/**
490 *  draws the spaceship after transforming it.
491*/
492void SpaceShip::draw () const
493{
494  WorldEntity::draw();
495
[10081]496  glMatrixMode(GL_MODELVIEW);
497  glPushMatrix();
498
499  float matrix[4][4];
500  glTranslatef (this->getAbsCoor ().x-1, this->getAbsCoor ().y-.2, this->getAbsCoor ().z);
501  this->getAbsDir().matrix (matrix);
502  glMultMatrixf((float*)matrix);
503  //glScalef(2.0, 2.0, 2.0);  // no double rescale
[10282]504        // FIXME
[10081]505  this->trail->draw();
506 
507  glTranslatef(0,0,-.5);
508  this->trailL->draw();
509
510  glTranslatef(0,0,1);
511  this->trailR->draw();
[10282]512
[10081]513  glPopMatrix();
[6868]514  //this->debug(0);
515}
516
517/**
518 *  the function called for each passing timeSnap
519 * @param time The timespan passed since last update
520*/
521void SpaceShip::tick (float time)
522{
[10261]523  // Playable::tick(time);
524
525 // this->test->tick(time);
526
[9961]527  // Own Tick Setup, as a different fire routine is used on the weapon manager
[9965]528  this->weaponMan.tick(time);
[9961]529  this->secWeaponMan.tick(time);
530
[10020]531  if( this->systemFailure() )
532    bFire = bSecFire = false;
533
[10037]534  // fire reqeust/release for primary weapons
[9965]535  if( this->bFire)
536    this->weaponMan.fire();
[10036]537  else
538    this->weaponMan.releaseFire();
539
[10037]540  // fire reqeust/release for secondary weapons
[9961]541  if( this->bSecFire)
542    this->secWeaponMan.fire();
[10036]543  else
544    this->secWeaponMan.releaseFire();
[10096]545   
546  // Tracktick
547  if(this->entityTrack)
548    this->entityTrack->tick(time);
[9961]549
[9970]550
551  // Shield Regeneration and other regular calculations on the ship
552  this->regen(time);
553
554  // Weapon Regeneration and other regular calculations on the ship
[9965]555  this->weaponRegen(time);
556
[9970]557  // current engine speed output
558  this->engineSpeedCur = this->engineSpeedBase + this->reactorOutput * this->engineEnergyShare;
559
[10043]560  // calculation of maxSpeed and acceleration:
561  this->travelSpeed = this->engineSpeedCur * 5;
562  this->acceleration = this->travelSpeed * 2;
[9970]563
[10017]564  this->movement(time);
565
566   // TRYING TO FIX PNode.
567  this->cameraNode.setAbsCoorSoft(this->getAbsCoor() + Vector(0.0f, 5.0f, 0.0f), 30.0f);
568  this->cameraNode.setRelDirSoft(this->getAbsDir(), 30.0f);
569
[10095]570 
571  this->velocity  = (this->getAbsCoor() - this->oldPos) / time;
572  this->oldPos    = this->getAbsCoor();
573
[10261]574//FIXME
[10081]575  this->trail->tick(time);
576  this->trailL->tick(time);
577  this->trailR->tick(time);
[10095]578
[10291]579  if (!this->isTravelDistanceInit)
580  {
581    this->updateTravelDistance();
[10306]582    //this->isTravelDistanceInit = true;
[10291]583  }
584
[6868]585  //orient the spaceship in direction of the mouse
[10017]586  /*
[9869]587  rotQuat = Quaternion::quatSlerp( this->getAbsDir(), mouseDir, 0.5);//fabsf(time)*shipInertia);
588  if (this->getAbsDir().distance(rotQuat) > 0.00000000000001)
[6868]589    this->setAbsDir( rotQuat);
[9869]590  //this->setAbsDirSoft(mouseDir,5);
[10017]591  */
592  /*
[6868]593  this->shiftCoor(move);
[10017]594  */
[6868]595
[9869]596  //   PRINTF(0)("id of %s is: %i\n", this->getName(), this->getOMListNumber());
[6868]597
598}
599
600/**
601 * @todo switch statement ??
602 */
603void SpaceShip::process(const Event &event)
604{
[9961]605  //Playable::process(event);
[10113]606 
[6868]607  if( event.type == KeyMapper::PEV_LEFT)
[10017]608    this->bLeft = event.bPressed;
[6868]609  else if( event.type == KeyMapper::PEV_RIGHT)
[10291]610  {
[10017]611    this->bRight = event.bPressed;
[10291]612    printf("ShipCoorX: %f \n", this->getRelCoor().x);
613  }
[6997]614  else if( event.type == KeyMapper::PEV_FORWARD)
[10291]615  {
[10017]616    this->bForward = event.bPressed; //this->shiftCoor(0,.1,0);
[10291]617   
618  }
[6997]619  else if( event.type == KeyMapper::PEV_BACKWARD)
[10017]620    this->bBackward = event.bPressed; //this->shiftCoor(0,-.1,0);
[9961]621  else if( event.type == KeyMapper::PEV_FIRE2)
622    this->bSecFire = event.bPressed;
[9958]623  else if( event.type == KeyMapper::PEV_FIRE1)
[9965]624    this->bFire = event.bPressed;
[10113]625  else if( event.type == KeyMapper::PEV_NEXT_WEAPON && event.bPressed)
626  {
627    this->nextWeaponConfig();
628  }
629  else if ( event.type == KeyMapper::PEV_PREVIOUS_WEAPON && event.bPressed)
630    this->previousWeaponConfig();
[10017]631
[10237]632  if (!(State::getCamera()->getEventHandling()))
633  {
634    if( event.type == KeyMapper::PEV_VIEW0)
635    {
636      State::getCamera()->setViewMode(Camera::ViewNormal);
637      State::getCameraTargetNode()->setParent(this);
638      State::getCamera()->setParent(this);
639    }
640    else if( event.type == KeyMapper::PEV_VIEW1)
641    {
642      State::getCamera()->setViewMode(Camera::ViewBehind);
643      State::getCameraTargetNode()->setParent(this);
644      State::getCamera()->setParent(this);
645    }
646    else if( event.type == KeyMapper::PEV_VIEW2)
647    {
648      State::getCamera()->setViewMode(Camera::ViewFront);
649      State::getCameraTargetNode()->setParent(this);
650      State::getCamera()->setParent(this);
651    }
652    else if( event.type == KeyMapper::PEV_VIEW3)
653    {
654      State::getCamera()->setViewMode(Camera::ViewLeft);
655      State::getCameraTargetNode()->setParent(this);
656      State::getCamera()->setParent(this);
657    }
658    else if( event.type == KeyMapper::PEV_VIEW4)
659    {
660      State::getCamera()->setViewMode(Camera::ViewRight);
661      State::getCameraTargetNode()->setParent(this);
662      State::getCamera()->setParent(this);
663    }
664    else if( event.type == KeyMapper::PEV_VIEW5)
665    {
666      State::getCamera()->setViewMode(Camera::ViewTop);
667      State::getCameraTargetNode()->setParent(this->travelNode);
668      State::getCamera()->setParent(this->travelNode);
669    }
670  }
[10017]671
[10237]672
[10017]673  /*
[6868]674  else if( event.type == EV_MOUSE_MOTION)
675  {
[9961]676
[6868]677    this->xMouse += event.xRel;
678    this->yMouse += event.yRel;
679  }
[10017]680  */
[6868]681}
682
[9235]683void SpaceShip::destroy( WorldEntity* killer )
[9008]684{
[10261]685  if(this->hasPlayer())
686    Playable::destroy( killer);
687
[10107]688  PRINTF(5)("spaceship destroy\n");
[10261]689
[10073]690  EmitterNode* node  = NULL;
691  DotEmitter* emitter = NULL;
692  SpriteParticles*  explosionParticles  = NULL;
[10064]693
[10107]694  explosionParticles = new SpriteParticles(200);
695  explosionParticles->setName("SpaceShipExplosionParticles");
696  explosionParticles->setLifeSpan(.2, .3);
[10073]697  explosionParticles->setRadius(0.0, 10.0);
698  explosionParticles->setRadius(.5, 6.0);
699  explosionParticles->setRadius(1.0, 3.0);
[10098]700  explosionParticles->setColor(0.0, 1,1,1,.9);
701  explosionParticles->setColor(0.1,  1,1,0,.9);
702  explosionParticles->setColor(0.5, .8,.4,0,.5);
[10107]703  explosionParticles->setColor(1.0, .2,.2,.2,.5);
[10064]704
[10073]705 
[10107]706  emitter = new DotEmitter( 2000, 70, 360);
707  //emitter->setSpread( 0, M_2_PI);
708  emitter->setEmissionRate( 200.0);
[10098]709  //emitter->setEmissionVelocity( 200.0);
[10107]710  //emitter->setSystem( explosionParticles);
711  //emitter->setAbsCoor( this->getAbsCoor());
[10064]712
[10107]713  node  = new EmitterNode( .1f);
[10073]714  node->setupParticle( emitter, explosionParticles);
[10107]715  node->setAbsDir( this->getAbsDir());
716  node->setVelocity( this->getVelocity() * .9f);
[10073]717  node->setAbsCoor( this->getAbsCoor());
[10107]718  if( !node->start())
719    PRINTF(0)("Explosion node not correctly started!");
[10095]720/*
[10081]721  PNode* node          = new PNode();
722  node->setAbsCoor(this->getAbsCoor());
723  Explosion* explosion = new Explosion();
724  explosion->explode( node, Vector(5,5,5));
[10095]725*/
[10261]726/*
[10107]727  if( this->hasPlayer())
728  {
729        this->setAbsCoor(Vector(-10000,10000,10000));
730        this->hide();
731  }
732  else
[10261]733  {*/
[10113]734    this->setAbsCoor( this->getAbsCoor() + Vector(100,0,0) + Vector(1,0,0) * VECTOR_RAND(150).dot(Vector(1,0,0)));
[10261]735  //}
[10107]736
[9008]737}
[6868]738
[9008]739void SpaceShip::respawn( )
740{
[10261]741  Playable::respawn();
[9008]742}
[6868]743
744
[9957]745void SpaceShip::damage(float pDamage, float eDamage){
[10117]746  PRINTF(5)("ship hit for (%f,%f) \n",pDamage,eDamage);
[10081]747
[10064]748  if( this->shieldActive) {
[9950]749    if( this->shieldCur > pDamage) {
750      this->shieldCur = this->shieldCur - pDamage;
751    }
752    else { // shield <= pDamage
[9987]753      this->shieldCur -=pDamage;
754      this->shieldActive = false; //shield collapses
[10081]755      pDamage += this->shieldCur;
[9950]756      if( !this->shieldActive) {
[9957]757        this->armorCur -= pDamage / 2; // remaining damages hits armor at half rate
[9953]758        this->electronicCur -= eDamage;
[9950]759      }
760    }
761  }
762  else {
763    this->armorCur = this->armorCur - pDamage;
764    this->electronicCur = this->electronicCur - eDamage;
765  }
766  if( this->armorCur <= 0) { /* FIXME implement shipcrash*/ }
[10064]767    this->destroy(this);
[10119]768
[10120]769  updateElectronicWidget();
770  updateShieldWidget();
771
[10119]772  this->setHealth( this->armorCur);
[9950]773}
774
[9987]775
[9957]776void SpaceShip::regen(float time){
777  float tmp;
[9963]778  if (this->armorCur != this->armorMax || this->armorRegen != 0){
779    tmp = this->armorCur + this->armorRegen * time;
780    if ( tmp > electronicMax)
781      this->armorCur = this->armorMax;
782    else
783      this->armorCur = tmp;
784  }
785  if (this->shieldCur != this->shieldMax || this->shieldRegen != 0){
[9970]786    tmp =  this->shieldCur + (this->shieldRegen + this->reactorOutput * this->shieldEnergyShare) * time;
[9957]787    if( tmp > shieldMax)
[9953]788      this->shieldCur = this->shieldMax;
789    else
[9957]790      this->shieldCur = tmp;
791    this->shieldActive = ( this->shieldActive || this->shieldCur > shieldTH);
[10120]792
793    updateShieldWidget();
[9953]794  }
[9970]795
796  this->setHealth( this->shieldCur);      // FIXME currently just to test share system
797
[9963]798  if (this->electronicCur != this->electronicMax || this->electronicRegen != 0){
[9957]799    tmp = this->electronicCur + this->electronicRegen * time;
800    if ( tmp > electronicMax)
[9953]801      this->electronicCur = this->electronicMax;
802    else
[9957]803      this->electronicCur = tmp;
[10120]804
805    updateElectronicWidget();
[9953]806  }
[10120]807
[9950]808}
[9965]809
[9987]810
[9965]811/**
812 * Weapon regeneration
813 * does not use any reactor capacity, as it wouldn't work in a consistent way.
814 */
815void SpaceShip::weaponRegen(float time)
816{
817  float energy  = ( this->reactorOutput * this->weaponEnergyShare + this->weaponEnergyRegen) * time;
818  Weapon* weapon;
[9987]819  for( unsigned int i=0; i < this->weaponMan.getSlotCount(); i++)
[9965]820  {
821    weapon = this->weaponMan.getWeapon(i);
822    if( weapon != NULL && weapon->isActive())
823    {
824      weapon->increaseEnergy( energy);
825    }
826
827  }
828  // weaponMan.increaseAmmunition( weapon, energy);
829}
[9975]830
[9987]831
[9975]832void SpaceShip::enterPlaymode(Playable::Playmode playmode)
833{
[10017]834  switch(playmode)
835  {
836    case Playable::Full3D:
837      /*
838      if (State::getCameraNode != NULL)
839      {
840        Vector absCoor = this->getAbsCoor();
841        this->setParent(PNode::getNullParent());
842        this->setAbsCoor(absCoor);
843        State::getCameraNode()->setParentSoft(&this->cameraNode);
844        State::getCameraNode()->setRelCoorSoft(-10, 0,0);
845        State::getCameraTargetNode()->setParentSoft(&this->cameraNode);
846        State::getCameraTargetNode()->setRelCoorSoft(100, 0,0);
847
848      }
849      */
850      //break;
851
[10032]852      break;
853    case Playable::Horizontal:
[10017]854      if (State::getCameraNode != NULL)
855      {
856        this->debugNode(1);
857        this->travelNode->debugNode(1);
858
859        this->travelNode->setAbsCoor(this->getAbsCoor());
860        this->travelNode->updateNode(0.01f);
[10332]861
862        if (this->hasPlayer())
863          this->isTravelDistanceInit = false;
864
[10297]865        if(this->entityTrack)
866           this->travelNode->setParent(this->entityTrack->getTrackNode());
[10289]867
[10098]868        this->setParent(this->travelNode);
[10017]869        this->setRelCoor(0,0,0);
870
[10098]871        State::getCameraNode()->setParentSoft(this->travelNode);
[10289]872        //State::getCameraNode()->setParentSoft(this);
[10237]873        //State::getCameraNode()->setRelCoorSoft(-0.01, 40, 0);
[10098]874        State::getCameraTargetNode()->setParentSoft(this->travelNode);
[10289]875        //State::getCameraTargetNode()->setParentSoft(this);
[10237]876        //State::getCameraTargetNode()->setRelCoorSoft(0,0,0);
877        this->setCameraMode(Camera::ViewTop);
878        State::getCamera()->setEventHandling(false);
879        registerEvent(KeyMapper::PEV_VIEW0);
880        registerEvent(KeyMapper::PEV_VIEW1);
881        registerEvent(KeyMapper::PEV_VIEW2);
882        registerEvent(KeyMapper::PEV_VIEW3);
883        registerEvent(KeyMapper::PEV_VIEW4);
884        registerEvent(KeyMapper::PEV_VIEW5);
[10017]885
[10335]886        State::getCamera()->setParentMode(PNODE_ALL);
[10237]887
[10291]888        //this->updateTravelDistance();
889
[10017]890        this->debugNode(1);
891        this->travelNode->debugNode(1);
892      }
893      break;
894
895    default:
896      PRINTF(2)("Playmode %s Not Implemented in %s\n", Playable::playmodeToString(this->getPlaymode()).c_str(), this->getClassCName());
897  }
[9975]898}
899
[10017]900/**
901 * @brief calculate the velocity
902 * @param time the timeslice since the last frame
903*/
[9987]904
[9975]905void SpaceShip::movement (float dt)
906{
[10019]907  //by releasing the buttons, the velocity decreases with airCoeff*Acceleration. Should be strong enough so
908  //the ship doesn't slide too much.
909  float airCoeff = 2.5;
910  float pi = 3.14;
[10017]911
[10032]912  switch(this->getPlaymode())
[10017]913  {
[10032]914    case Playable::Horizontal:
[10017]915    {
[10032]916      // these routines will change the travel movement into zero in a short amout of time, if the player
917      // doesn't press any buttons.
[10098]918      if (this->travelVelocity.x >= 0)
[10017]919      {
[10098]920        if (this->travelVelocity.x > airCoeff*this->acceleration * dt)
921          this->travelVelocity.x -= airCoeff* this->acceleration * dt;
[10032]922        else
[10098]923          this->travelVelocity.x = 0;
[10017]924      }
925      else
926      {
[10098]927        if (this->travelVelocity.x < -airCoeff*this->acceleration * dt)
928          this->travelVelocity.x += airCoeff* this->acceleration * dt;
[10032]929        else
[10098]930          this->travelVelocity.x = 0;
[10017]931      }
[10098]932      if (this->travelVelocity.z >= 0)
[10017]933      {
[10098]934        if (this->travelVelocity.z > airCoeff*this->acceleration * dt)
935          this->travelVelocity.z -= airCoeff* this->acceleration * dt;
[10032]936        else
[10098]937          this->travelVelocity.z = 0;
[10017]938      }
939      else
940      {
[10098]941        if (this->travelVelocity.z < -airCoeff*this->acceleration * dt)
942          this->travelVelocity.z += airCoeff* this->acceleration * dt;
[10032]943        else
[10098]944          this->travelVelocity.z = 0;
[10017]945      }
[10032]946   
947      // this will evite, that the ship moves outside the travelDistance- borders,when the player releases all buttons
948      // and its continuing to slide a bit.
949      Vector oldCoor = this->getRelCoor();
950      if (this->getRelCoor().x > this->travelDistancePlus.x) this->setRelCoor(this->travelDistancePlus.x, oldCoor.y, oldCoor.z);
951      if (this->getRelCoor().x < this->travelDistanceMinus.x) this->setRelCoor(this->travelDistanceMinus.x, oldCoor.y, oldCoor.z);
952      if (this->getRelCoor().z > this->travelDistancePlus.y) this->setRelCoor(oldCoor.x, oldCoor.y, this->travelDistancePlus.y);
953      if (this->getRelCoor().z < this->travelDistanceMinus.y) this->setRelCoor(oldCoor.x, oldCoor.y, this->travelDistanceMinus.y);
954   
955      if( this->systemFailure() )
956        bForward = bBackward = bLeft = bRight = false;
957   
958      if( this->bForward )
[10019]959      {
[10291]960        //printf("ShipCoorX: %f \n", this->getRelCoor().x);
[10032]961        if(this->getRelCoor().x < this->travelDistancePlus.x)
962        {
[10098]963          if (this->travelVelocity.x < this->travelSpeed)
[10032]964          {
[10098]965            this->travelVelocity.x += (airCoeff + 1.0)*this->acceleration*dt;
[10032]966          }
967          else
968          {
[10098]969            this->travelVelocity.x = this->travelSpeed;
[10032]970          }
971        }
972        else
973        {
[10098]974          this->travelVelocity.x = 0.0f;
[10032]975        }
[10019]976      }
[10032]977   
978      if( this->bBackward )
[10019]979      {
[10032]980        if(this->getRelCoor().x > this->travelDistanceMinus.x)
981        {
[10098]982          if (this->travelVelocity.x > -this->travelSpeed)
[10032]983          {
[10098]984            this->travelVelocity.x -= (airCoeff + 1.0)*this->acceleration*dt;
[10032]985          }
986          else
987          {
[10098]988            this->travelVelocity.x = -this->travelSpeed;
[10032]989          }
990        }
991        else
992        {
[10098]993          this->travelVelocity.x = 0.0f;
[10032]994        }
[10019]995      }
[10032]996   
997      if( this->bLeft)
[10019]998      {
[10032]999        if(this->getRelCoor().z > this->travelDistanceMinus.y)
1000        {
[10098]1001          if (this->travelVelocity.z > -this->travelSpeed)
[10032]1002          {
[10098]1003            this->travelVelocity.z -= (airCoeff + 1.0)*this->acceleration*dt;
[10032]1004          }
1005          else
1006          {
[10098]1007            this->travelVelocity.z = -this->travelSpeed;
[10032]1008          }
1009        }
1010        else
1011        {
[10098]1012          this->travelVelocity.z = 0.0f;
[10032]1013        }
[10043]1014        this->setRelDirSoft(Quaternion(-pi/6, Vector(1,0,0)), 6);
[10019]1015      }
[10032]1016   
1017      if( this->bRight)
[10019]1018      {
[10291]1019        //printf("ShipCoorZ: %f \n", this->getRelCoor().z);
[10032]1020        if(this->getRelCoor().z < this->travelDistancePlus.y)
1021        {
[10098]1022          if (this->travelVelocity.z < this->travelSpeed)
[10032]1023          {
[10098]1024            this->travelVelocity.z += (airCoeff + 1.0)*this->acceleration*dt;
[10032]1025          }
1026          else
1027          {
[10098]1028            this->travelVelocity.z = this->travelSpeed;
[10032]1029          }
1030        }
1031        else
1032        {
[10098]1033          this->travelVelocity.z = 0.0f;
[10032]1034        }
[10043]1035        this->setRelDirSoft(Quaternion(pi/6, Vector(1,0,0)), 6);
[10019]1036      }
[10032]1037      if (!this->bRight && !this->bLeft)
1038      {
[10043]1039        this->setRelDirSoft(Quaternion(0, Vector(1,0,0)), 6);
[10032]1040      }
1041
[10043]1042    //normalisation of the vectors (vector sum must be <= travelspeed)
[10098]1043    float xzNorm = sqrt(pow(this->travelVelocity.x, 2) + pow(this->travelVelocity.z, 2));
[10043]1044    if (xzNorm > this->travelSpeed)
1045    {
[10098]1046      this->travelVelocity.x = this->travelVelocity.x/xzNorm * this->travelSpeed;
1047      this->travelVelocity.z = this->travelVelocity.z/xzNorm * this->travelSpeed;
[10043]1048    }
[10032]1049
[10099]1050    //this moves camera and ship along the travel path.
[10297]1051    if(!this->entityTrack) 
1052       this->travelNode->shiftCoor(Vector(this->cameraSpeed * dt, 0, 0));
[10099]1053
[10043]1054    break;
[10019]1055    }
[10032]1056    case Playable::Vertical:
1057      break;
[10017]1058    default:
[10032]1059      PRINTF(4)("Playmode %s Not Implemented in %s\n", Playable::playmodeToString(this->getPlaymode()).c_str(), this->getClassCName());
[10017]1060  }
[10099]1061   //set new coordinates calculated through key- events.
[10098]1062  this->shiftCoor (this->travelVelocity * dt);
[9975]1063}
[10017]1064
[10032]1065void SpaceShip::setPlaymodeXML(const std::string& playmode)
1066{
1067  this->setPlaymode(Playable::stringToPlaymode(playmode));
1068}
1069
[10113]1070/**
1071 * @brief jumps to the next WeaponConfiguration
1072 */
1073void SpaceShip::nextWeaponConfig()
1074{
[10117]1075  PRINTF(0)("Requested next weapon config!\n");
1076  this->weaponMan.nextWeaponConfig();
[10113]1077  Playable::weaponConfigChanged();
1078}
1079
1080/**
1081 * @brief moves to the last WeaponConfiguration
1082 */
1083void SpaceShip::previousWeaponConfig()
1084{
[10117]1085  this->curWeaponPrimary    = (this->curWeaponPrimary + 1) % 3;
[10113]1086  this->weaponMan.changeWeaponConfig(this->curWeaponPrimary);
1087  Playable::weaponConfigChanged();
[10117]1088}
1089
[10274]1090void SpaceShip::hit( float damage, WorldEntity* killer)
[10117]1091{
1092  this->damage(killer->getDamage(),0);
1093}
[10120]1094
1095void SpaceShip::updateElectronicWidget()
1096{
[10139]1097  if (this->electronicWidget != NULL)
1098  { //if it exists already: update it
1099     this->electronicWidget->setMaximum(this->electronicMax);
1100     this->electronicWidget->setValue(this->electronicCur);
1101  }
1102  else
1103  { //create the widget
1104    this->electronicWidget = new OrxGui::GLGuiEnergyWidgetVertical();
[10230]1105    this->electronicWidget->getBarWidget()->setChangedValueColor(Color(1,0,0,1));
[10194]1106    //this->electronicWidget->setDisplayedName("Electronics:");
[10139]1107    //this->electronicWidget->setSize2D(100,20);
1108    //this->electronicWidget->setAbsCoor2D(150,200);
1109    this->updateElectronicWidget();
1110    if (this->hasPlayer())
1111      State::getPlayer()->hud().setEnergyWidget(this->electronicWidget);
1112  }
[10120]1113}
1114
1115void SpaceShip::updateShieldWidget()
1116{
[10139]1117  if (this->shieldWidget != NULL)
1118  { 
1119    this->shieldWidget->setMaximum(this->shieldMax);
1120    this->shieldWidget->setValue(this->shieldCur);;
1121  }
1122  else
1123  {
1124    this->shieldWidget = new OrxGui::GLGuiEnergyWidgetVertical();
[10230]1125    this->shieldWidget->getBarWidget()->setChangedValueColor(Color(1,0,0,1));
[10194]1126    //this->shieldWidget->setDisplayedName("Shield:");
[10139]1127    //his->shieldWidget->setSize2D(100,20);
1128    //this->shieldWidget->setAbsCoor2D(200,200);
1129    this->updateShieldWidget();
1130    if (this->hasPlayer())
1131      State::getPlayer()->hud().setShiledWidget(this->shieldWidget);
1132  }
[10120]1133}
[10270]1134
1135void SpaceShip::setCameraDistance(float dist)
1136{
1137  State::getCamera()->setViewTopDistance(dist);
1138}
1139
1140void SpaceShip::setCameraFovy(float fovy)
1141{
1142  State::getCamera()->setViewTopFovy(fovy);
1143}
[10291]1144
1145void SpaceShip::updateTravelDistance()
1146{
[10306]1147  float x = 1.25 * this->actionWidthPercentage * fabsf(State::getCamera()->getAbsCoor().y) * tan(State::getCamera()->getFovy()*M_PI /360.0);
1148  float y = x / State::getCamera()->getAspectRatio() / this->actionWidthPercentage;
[10291]1149  //State::getCamera()->setAbsCoor(-5, 1000, 0);
1150
1151
1152  //State::getCamera()->getAbsCoor().print();
[10306]1153  //printf("CameraRelCoorY: %f \n", State::getCamera()->getRelCoor().y);
[10291]1154
[10306]1155  //printf("x: %f, y: %f \n", x, y);
[10303]1156  this->travelDistancePlus = Vector2D(y, x);
1157  this->travelDistanceMinus = Vector2D(-y, -x);
[10291]1158
[10306]1159  State::getPlayer()->hud().setOverlayPercentage(100-int(100*this->actionWidthPercentage));
1160  PRINTF(0)("TravelDistance has been updated\n");
1161  this->isTravelDistanceInit = true;
[10297]1162}
[10306]1163
1164void SpaceShip::setActionWidthPercentage(int i) 
1165{
1166  if (i>100) i=100;
1167  if (i<0) i=0;
1168  this->actionWidthPercentage = i/100.0;
1169  //State::getPlayer()->hud().setOverlayPercentage(100-i);
1170  //updateTravelDistance();
[10332]1171  if (this->hasPlayer())
1172    this->isTravelDistanceInit = false;
[10306]1173};
Note: See TracBrowser for help on using the repository browser.