Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/vs-enhencements/src/world_entities/space_ships/space_ship.cc @ 10660

Last change on this file since 10660 was 10660, checked in by nicolasc, 17 years ago

night bunp

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