Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jan 25, 2007, 3:05:01 AM (17 years ago)
Author:
patrick
Message:

merged playability. but got strange bug

Location:
branches/playability.new
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/playability.new

    • Property svn:ignore
      •  

        old new  
        1010autom4te.cache
        1111aclocal.m4
         12tags
         13test.bmp
         14config.sub
         15config.guess
         16OrxonoxPlayability.kdevses
         17OrxonoxPlayability.kdevelop.pcs
  • branches/playability.new/src/world_entities/space_ships/space_ship.cc

    r10317 r10362  
    2323
    2424#include "weapons/test_gun.h"
     25#include "weapons/light_blaster.h"
     26#include "weapons/medium_blaster.h"
     27#include "weapons/heavy_blaster.h"
     28#include "weapons/swarm_launcher.h"
     29#include "weapons/spike_launcher.h"
     30#include "weapons/spike_thrower.h"
     31#include "weapons/acid_launcher.h"
     32#include "weapons/boomerang_gun.h"
    2533#include "weapons/turret.h"
    2634#include "weapons/cannon.h"
    2735
     36#include "elements/glgui_energywidgetvertical.h"
     37#include "glgui_bar.h"
     38
    2839#include "particles/dot_emitter.h"
     40#include "particles/emitter_node.h"
    2941#include "particles/sprite_particles.h"
     42#include "effects/trail.h"
     43
     44#include "effects/wobblegrid.h"
    3045
    3146#include "util/loading/factory.h"
     
    4459#include "state.h"
    4560#include "player.h"
     61#include "camera.h"
     62
    4663
    4764#include "util/loading/load_param.h"
     65#include "time.h"
     66
     67#include "track/track.h"
     68#include "math.h"
    4869
    4970
    5071// #include "lib/gui/gl_gui/glgui_bar.h"
    5172// #include "lib/gui/gl_gui/glgui_pushbutton.h"
    52 
    5373
    5474
     
    7090                        ->addMethod("getAbsCoorY", Executor0ret<PNode, lua_State*, float>(&PNode::getAbsCoorY))
    7191                        ->addMethod("getAbsCoorZ", Executor0ret<PNode, lua_State*, float>(&PNode::getAbsCoorZ))
     92                        //->addMethod("setCameraSpeed", Executor1<SpaceShip, lua_State*, float>(&SpaceShip::setCameraSpeed))
    7293                       );
    7394
     
    85106 */
    86107SpaceShip::SpaceShip(const std::string& fileName)
     108    : secWeaponMan(this) //,
     109    //supportedPlaymodes(Playable::Vertical) ,
     110    //playmode(Playable::Vertical)
    87111{
    88112  this->init();
     
    105129*/
    106130SpaceShip::SpaceShip(const TiXmlElement* root)
     131    : secWeaponMan(this) //,
     132    //supportedPlaymodes(Playable::Vertical) ,
     133    //playmode(Playable::Vertical)
    107134{
    108135  this->init();
     136  //this->setParentMode(PNODE_REPARENT_DELETE_CHILDREN);
    109137  if (root != NULL)
    110138    this->loadParams(root);
     
    118146void SpaceShip::init()
    119147{
     148
     149  srand(time(0));   //initialize Random Nomber Generator
     150
    120151  //  this->setRelDir(Quaternion(M_PI, Vector(1,0,0)));
    121152  this->registerObject(this, SpaceShip::_objectList);
    122 
    123153  PRINTF(4)("SPACESHIP INIT\n");
    124 
     154  this->weaponMan.setParentEntity( this);
    125155  //weapons:
    126   Weapon* wpRight = new TestGun(0);
    127   wpRight->setName("testGun Right");
    128   Weapon* wpLeft = new TestGun(1);
    129   wpLeft->setName("testGun Left");
    130   //Weapon* cannon = dynamic_cast<Weapon*>(Factory::fabricate(CL_CANNON));
    131 
    132   //cannon->setName("BFG");
    133 
    134   this->addWeapon(wpLeft, 1, 0);
    135   this->addWeapon(wpRight,1 ,1);
    136   //this->addWeapon(cannon, 0, 6);
    137 
    138   this->getWeaponManager().changeWeaponConfig(1);
    139 
    140   bUp = bDown = bLeft = bRight = bAscend = bDescend = bRollL = bRollR = false;
    141 
    142   xMouse = yMouse = 0;
    143   yInvert = 1;
    144   mouseSensitivity = 0.001;
    145   airViscosity = 0.9;
    146   controlVelocityX = 25;
    147   controlVelocityY = 150;
    148   shipInertia = 1.5;
    149   //  cycle = 0.0;
    150 
    151   this->setHealthMax(100);
    152   this->setHealth(80);
    153 
    154   travelSpeed = 0.0;
    155   acceleration = 3;
    156   this->velocity = this->getAbsDirX()*travelSpeed;
    157   this->mouseDir = this->getAbsDir();
    158   this->pitchDir = this->getAbsDir();
    159 
    160   //   GLGuiButton* button = new GLGuiPushButton();
    161   //    button->show();
    162   //    button->setLabel("orxonox");
    163   //    button->setBindNode(this);
    164   //     GLGuiBar* bar = new GLGuiBar();
    165   //     bar->show();
    166   //     bar->setValue(7.0);
    167   //     bar->setMaximum(10);
    168   //     bar->setSize2D( 20, 100);
    169   //     bar->setAbsCoor2D( 10, 200);
     156 
     157  Weapon* wpRight1 = new LightBlaster ();
     158  wpRight1->setName( "LightBlaster");
     159  Weapon* wpLeft1 = new LightBlaster ();
     160  wpLeft1->setName( "LightBlaster");
     161
     162  Weapon* wpRight2 = new MediumBlaster ();
     163  wpRight2->setName( "MediumBlaster");
     164  Weapon* wpLeft2 = new MediumBlaster ();
     165  wpLeft2->setName( "MediumBlaster");
     166
     167  Weapon* wpRight3 = new HeavyBlaster (1);
     168  wpRight3->setName( "HeavyBlaster");
     169  Weapon* wpLeft3 = new HeavyBlaster (0);
     170  wpLeft3->setName( "HeavyBlaster");
     171
     172  Weapon* cannon = new SwarmLauncher();
     173  cannon->setName( "SwarmLauncher");
     174
     175  Weapon* spike = new SpikeThrower();
     176  spike->setName( "SpikeThrower" );
     177
     178
     179  Weapon* acid0 = new AcidLauncher();
     180  acid0->setName( "AcidSplasher" );
     181
     182  Weapon* acid1 = new AcidLauncher();
     183  acid1->setName( "AcidSplasher" );
     184
     185
     186  this->weaponMan.addWeapon( wpLeft1, 0, 0);
     187  this->weaponMan.addWeapon( wpRight1, 0, 1);
     188
     189  this->weaponMan.addWeapon( wpLeft2, 1, 2);
     190  this->weaponMan.addWeapon( wpRight2, 1, 3);
     191
     192  this->weaponMan.addWeapon( wpLeft3, 2, 4);
     193  this->weaponMan.addWeapon( wpRight3, 2, 5);
     194/*
     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);
     203*/
     204
     205  this->weaponMan.addWeapon( acid0, 3, 0);
     206  this->weaponMan.addWeapon( acid1, 3, 1);
     207
     208
     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);
     213
     214
     215  this->weaponMan.changeWeaponConfig(3);
     216  this->secWeaponMan.changeWeaponConfig(1);
     217
     218  curWeaponPrimary    = 0;
     219  curWeaponSecondary  = 1;
     220
     221  Playable::weaponConfigChanged();
     222
     223  reactorOutput     = 10;
     224
     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;
     235  shieldTH          = .2 * shieldMax;   // shield power must be 20% before shield kicks in again
     236
     237  this->setHealth( 20);
     238  this->setHealthMax( 100);
     239
     240  electronicCur = 50;
     241  electronicMax = 50;
     242  electronicRegen   = 3;
     243  electronicTH      = .7 * electronicMax; // 30% of eDamage can be handled by the ship
     244
     245
     246  this->loadModel("models/ships/mantawing.obj");
     247  //this->setVisibiliy(false);
     248
     249  bForward = bBackward = bLeft = bRight = bAscend = bDescend = bRollL = bRollR = bFire = bSecFire = false;
     250
     251  this->setHealthMax(shieldMax);
     252  this->setHealth(shieldCur);
     253
     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
     260  // widget handling
     261  /*
     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  }
     279  */
     280  this->electronicWidget = NULL;
     281  this->shieldWidget = NULL;
    170282
    171283  //add events to the eventlist
     
    177289  //registerEvent(SDLK_e);
    178290  registerEvent(KeyMapper::PEV_FIRE1);
     291  registerEvent(KeyMapper::PEV_FIRE2);                  // Added for secondary weapon support
    179292  registerEvent(KeyMapper::PEV_NEXT_WEAPON);
    180293  registerEvent(KeyMapper::PEV_PREVIOUS_WEAPON);
     
    183296  registerEvent(EV_MOUSE_MOTION);
    184297
    185   this->getWeaponManager().setSlotCount(7);
    186 
    187   this->getWeaponManager().setSlotPosition(0, Vector(-2.6, .1, -3.0));
    188   this->getWeaponManager().setSlotCapability(0, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL);
    189 
    190   this->getWeaponManager().setSlotPosition(1, Vector(-2.6, .1, 3.0));
    191   this->getWeaponManager().setSlotCapability(1, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL);
    192 
    193   this->getWeaponManager().setSlotPosition(2, Vector(-1.5, .5, -.5));
    194   this->getWeaponManager().setSlotDirection(2, Quaternion(-M_PI_4*.5, Vector(1,0,0)));
    195 
    196   this->getWeaponManager().setSlotPosition(3, Vector(-1.5, .5, .5));
    197   this->getWeaponManager().setSlotDirection(3, Quaternion(M_PI_4*.5, Vector(1,0,0)));
    198 
    199   this->getWeaponManager().setSlotPosition(4, Vector(-1.5, -.5, .5));
    200   this->getWeaponManager().setSlotDirection(4, Quaternion(-M_PI_4*.5+M_PI, Vector(1,0,0)));
    201 
    202   this->getWeaponManager().setSlotPosition(5, Vector(-1.5, -.5, -.5));
    203   this->getWeaponManager().setSlotDirection(5, Quaternion(+M_PI_4*.5-M_PI, Vector(1,0,0)));
    204   //
    205   this->getWeaponManager().setSlotPosition(6, Vector(-1, 0.0, 0));
    206   this->getWeaponManager().setSlotCapability(6, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL);
    207   //
    208   //   this->getWeaponManager().setSlotPosition(8, Vector(-2.5, -0.3, -2.0));
    209   //   this->getWeaponManager().setSlotDirection(8, Quaternion(-M_PI, Vector(1,0,0)));
    210   //
    211   //   this->getWeaponManager().setSlotPosition(9, Vector(-2.5, -0.3, 2.0));
    212   //   this->getWeaponManager().setSlotDirection(9, Quaternion(+M_PI, Vector(1,0,0)));:
    213 
    214   this->getWeaponManager().getFixedTarget()->setParent(this);
    215   this->getWeaponManager().getFixedTarget()->setRelCoor(100000,0,0);
    216 
    217   dynamic_cast<Element2D*>(this->getWeaponManager().getFixedTarget())->setVisibility( false);
    218 
    219   this->burstEmitter = new DotEmitter(200, 0.0, .01);
    220   this->burstEmitter->setParent(this);
    221   this->burstEmitter->setRelCoor(-1, .5, 0);
    222   this->burstEmitter->setName("SpaceShip_Burst_emitter");
     298  this->weaponMan.setParentEntity( this);
     299  this->secWeaponMan.setParentEntity( this);
     300
     301  this->weaponMan.setSlotCount(8);
     302
     303  this->weaponMan.setSlotPosition(0, Vector(0.0, 0, -3.0));
     304  this->weaponMan.setSlotCapability(0, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL);
     305
     306  this->weaponMan.setSlotPosition(1, Vector(0.0, 0, 3.0));
     307  this->weaponMan.setSlotCapability(1, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL);
     308
     309  this->weaponMan.setSlotPosition(2, Vector(1.0, 0, -1.5));
     310  this->weaponMan.setSlotDirection(2, Quaternion(-M_PI_4*.5, Vector(1,0,0)));
     311
     312  this->weaponMan.setSlotPosition(3, Vector(1.0, 0, 1.5));
     313  this->weaponMan.setSlotDirection(3, Quaternion(M_PI_4*.5, Vector(1,0,0)));
     314
     315  this->weaponMan.setSlotPosition(4, Vector(1.5, 0, .5));
     316  this->weaponMan.setSlotDirection(4, Quaternion(-M_PI_4*.5+M_PI, Vector(1,0,0)));
     317
     318  this->weaponMan.setSlotPosition(5, Vector(1.5, 0, -.5));
     319  this->weaponMan.setSlotDirection(5, Quaternion(+M_PI_4*.5-M_PI, Vector(1,0,0)));
     320
     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)));
    223326
    224327  this->burstSystem = new SpriteParticles(1000);
     
    236339  this->burstSystem->setColor(1.0, .8,.8,.8,.0);
    237340
    238   registerVar( new SynchronizeableVector( &velocity, &velocity, "velocity", PERMISSION_MASTER_SERVER ) );
    239   registerVar( new SynchronizeableQuaternion( &mouseDir, &mouseDir, "mousedir", PERMISSION_OWNER ) );
    240 
    241   registerVar( new SynchronizeableBool( &bUp, &bUp, "bUp", PERMISSION_OWNER ) );
    242   registerVar( new SynchronizeableBool( &bDown, &bDown, "bDown", PERMISSION_OWNER ) );
     341  this->secWeaponMan.setSlotPosition(0, Vector(1.5, 0, 0));
     342  this->secWeaponMan.setSlotCapability(0, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL);
     343
     344  this->secWeaponMan.setSlotPosition(1, Vector(2.6, 0, 3.0));
     345  this->secWeaponMan.setSlotCapability(1, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL);
     346
     347  this->secWeaponMan.setSlotPosition(2, Vector(1.5, 0, -.5));
     348  this->secWeaponMan.setSlotDirection(2, Quaternion(-M_PI_4*.5, Vector(1,0,0)));
     349
     350  this->secWeaponMan.setSlotPosition(3, Vector(1.5, 0, .5));
     351  this->secWeaponMan.setSlotDirection(3, Quaternion(M_PI_4*.5, Vector(1,0,0)));
     352
     353  this->secWeaponMan.setSlotPosition(4, Vector(1.5, 0, .5));
     354  this->secWeaponMan.setSlotDirection(4, Quaternion(-M_PI_4*.5+M_PI, Vector(1,0,0)));
     355
     356  this->secWeaponMan.setSlotPosition(5, Vector(1.5, 0, -.5));
     357  this->secWeaponMan.setSlotDirection(5, Quaternion(+M_PI_4*.5-M_PI, Vector(1,0,0)));
     358
     359
     360  this->weaponMan.getFixedTarget()->setParent(this);
     361  this->weaponMan.getFixedTarget()->setRelCoor(100000,0,0);
     362
     363 
     364  this->secWeaponMan.getFixedTarget()->setParent(this);
     365  this->secWeaponMan.getFixedTarget()->setRelCoor(100000,0,0);
     366  this->secWeaponMan.setRotationSpeed(0);
     367
     368  dynamic_cast<Element2D*>(this->weaponMan.getFixedTarget())->setVisibility( false);
     369
     370
     371  registerVar( new SynchronizeableBool( &bForward, &bForward, "bForward", PERMISSION_OWNER ) );
     372  registerVar( new SynchronizeableBool( &bBackward, &bBackward, "bBackward", PERMISSION_OWNER ) );
    243373  registerVar( new SynchronizeableBool( &bLeft, &bLeft, "bLeft", PERMISSION_OWNER ) );
    244374  registerVar( new SynchronizeableBool( &bRight, &bRight, "bRight", PERMISSION_OWNER ) );
    245   registerVar( new SynchronizeableBool( &bAscend, &bAscend, "bAscend", PERMISSION_OWNER ) );
    246   registerVar( new SynchronizeableBool( &bDescend, &bDescend, "bDescend", PERMISSION_OWNER ) );
    247   registerVar( new SynchronizeableBool( &bRollL, &bRollL, "bRollL", PERMISSION_OWNER ) );
    248   registerVar( new SynchronizeableBool( &bRollR, &bRollR, "bRollR", PERMISSION_OWNER ) );
     375  registerVar( new SynchronizeableFloat( &cameraLook, &cameraLook, "cameraLook", PERMISSION_OWNER ) );
     376  registerVar( new SynchronizeableFloat( &rotation, &rotation, "rotation", PERMISSION_OWNER ) );
     377  registerVar( new SynchronizeableBool( &bFire, &bFire, "bSecFire", PERMISSION_OWNER));
     378  registerVar( new SynchronizeableVector( &velocity, &velocity, "velocity", PERMISSION_MASTER_SERVER ) );
     379
     380  //this->airFriction = 0.5f;
     381  //this->travelDistancePlus = Vector2D(38.0, 43.0);
     382  //this->travelDistanceMinus = Vector2D(-38.0, -43.0);
     383  this->travelDistancePlus = Vector2D(50,50);
     384  this->travelDistanceMinus = Vector2D(-50,-50);
     385  this->isTravelDistanceInit = true;
     386  this->actionWidthPercentage = 1;
     387
     388  this->cameraSpeed = 40;
     389  this->cameraLook = 0.0f;
     390  //this->airFriction = 0.0f;
     391
     392  srand(time(0));  //initaialize RNG
     393
     394  this->travelNode->debugDraw();
     395
     396  this->setSupportedPlaymodes(Playable::Horizontal | Playable::Vertical);
     397
     398  /// FIXME
     399  this->trail = new Trail( 5, 10, .2, this);
     400  this->trail->setTexture( "maps/engine.png");
     401
     402  this->trailL = new Trail( 5, 10, .2, this);
     403  this->trailL->setTexture( "maps/engine.png");
     404
     405  this->trailR = new Trail( 5, 10, .2, this);
     406  this->trailR->setTexture( "maps/engine.png");
     407
     408
     409  this->toList(OM_GROUP_00);
     410
     411  //FIXME Just testaddition to show the wobblegrid
     412/*
     413  this->test  = new Wobblegrid(5);
     414  test->setTexture("maps/blub.png");
     415 
     416  test->setAbsCoor( this->getAbsCoor() + Vector(0, 2, 0));
     417  test->setParent( this);
     418*/
     419 
    249420}
    250421
     
    257428{
    258429  Playable::loadParams(root);
    259 }
    260 
    261 void SpaceShip::setPlayDirection(const Quaternion& quat, float speed)
    262 {
    263   this->mouseDir = quat;
    264 }
    265 
     430
     431  LoadParam(root, "playmode", this, SpaceShip, setPlaymodeXML);
     432  LoadParam(root, "cameraDistance", this, SpaceShip, setCameraDistance);
     433  LoadParam(root, "cameraFovy", this, SpaceShip, setCameraFovy);
     434  LoadParam(root, "actionWidthPercentage", this, SpaceShip, setActionWidthPercentage);
     435
     436  State::getCamera()->setViewMode(Camera::ViewTop);
     437}
     438
     439
     440void SpaceShip::setPlayDirection(const Quaternion& rot, float speed)
     441{
     442  //this->direction = Quaternion (rot.getHeading(), Vector(0,1,0));
     443}
    266444
    267445void SpaceShip::reset()
    268446{
    269   bUp = bDown = bLeft = bRight = bAscend = bDescend = bRollL = bRollR = false;
    270 
    271   xMouse = yMouse = 0;
     447  bForward = bBackward = bLeft = bRight = bAscend = bDescend = bRollL = bRollR = bFire = bSecFire = false;
     448
     449  //xMouse = yMouse = 0;
    272450
    273451  this->setHealth(80);
     
    278456void SpaceShip::enter()
    279457{
    280   dynamic_cast<Element2D*>(this->getWeaponManager().getFixedTarget())->setVisibility( true);
    281   this->attachCamera();
     458  this->secWeaponMan.showCrosshair();
     459  this->toList( OM_GROUP_01 );
     460  State::getPlayer()->hud().setRadarCenterNode(this->travelNode);
     461  State::getPlayer()->hud().setOverlayActive(true);
     462  //dynamic_cast <OrxGui::GLGuiEnergyWidgetVertical*> (State::getPlayer()->hud().getArmorWidget())->setDisplayedName("Armor");
     463  //dynamic_cast<Element2D*>(this->secWeaponMan.getFixedTarget())->setVisibility( true);
     464  //this->attachCamera();
     465 // this->setPlaymode(Playable::Horizontal);
    282466}
    283467
    284468void SpaceShip::leave()
    285469{
    286   dynamic_cast<Element2D*>(this->getWeaponManager().getFixedTarget())->setVisibility( false);
    287   this->detachCamera();
     470  this->secWeaponMan.hideCrosshair();
     471  this->toList( OM_GROUP_00);
     472  State::getPlayer()->hud().setOverlayActive(false);
     473  State::getCamera()->setEventHandling(true);
     474  State::getPlayer()->hud().setRadarCenterNode(NULL);
     475  //dynamic_cast<Element2D*>(this->secWeaponMan.getFixedTarget())->setVisibility( false);
     476  //this->detachCamera();
    288477}
    289478
     
    294483void SpaceShip::postSpawn ()
    295484{
     485  if(this->hasPlayer())
     486    Playable::postSpawn();
     487
    296488  //setCollision(new CollisionCluster(1.0, Vector(0,0,0)));
    297489}
     
    301493*/
    302494void SpaceShip::leftWorld ()
    303 {}
     495{
     496
     497}
    304498
    305499WorldEntity* ref = NULL;
    306 /**
    307  *  this function is called, when two entities collide
    308  * @param entity: the world entity with whom it collides
    309  *
    310  * Implement behaviour like damage application or other miscellaneous collision stuff in this function
    311  */
    312 void SpaceShip::collidesWith(WorldEntity* entity, const Vector& location)
    313 {
    314 }
    315500
    316501/**
     
    321506  WorldEntity::draw();
    322507
     508  glMatrixMode(GL_MODELVIEW);
     509  glPushMatrix();
     510
     511  float matrix[4][4];
     512  glTranslatef (this->getAbsCoor ().x-1, this->getAbsCoor ().y-.2, this->getAbsCoor ().z);
     513  this->getAbsDir().matrix (matrix);
     514  glMultMatrixf((float*)matrix);
     515  //glScalef(2.0, 2.0, 2.0);  // no double rescale
     516        // FIXME
     517  this->trail->draw();
     518 
     519  glTranslatef(0,0,-.5);
     520  this->trailL->draw();
     521
     522  glTranslatef(0,0,1);
     523  this->trailR->draw();
     524
     525  glPopMatrix();
    323526  //this->debug(0);
    324527}
     
    330533void SpaceShip::tick (float time)
    331534{
    332   Playable::tick(time);
    333 
    334   if( ( xMouse != 0 || yMouse != 0 ) && this->getOwner() == SharedNetworkData::getInstance()->getHostID() )
    335   {
    336     if (xMouse > controlVelocityX) xMouse = controlVelocityX;
    337     else if (xMouse < -controlVelocityX) xMouse = -controlVelocityX;
    338     if (yMouse > controlVelocityY) yMouse = controlVelocityY;
    339     else if (yMouse < -controlVelocityY) yMouse = -controlVelocityY;
    340 
    341     pitchDir = (Quaternion(xMouse*mouseSensitivity*0.5, Vector(1,0,0)));
    342 
    343     mouseDir *= (Quaternion(-M_PI/4*xMouse*mouseSensitivity, Vector(0,1,0))*Quaternion(-M_PI/4*yMouse*mouseSensitivity*yInvert, Vector(0,0,1))*pitchDir);
    344     xMouse = yMouse = 0;
    345   }
    346 
    347 
    348   //   if( this != State::getPlayer()->getControllable())
    349   //     return;
    350 
    351   // spaceship controlled movement fire(bool bF){ this->bFire = bF;}
    352   //if (this->getOwner() == this->getHostID())
    353   this->calculateVelocity(time);
    354 
    355 
    356   Vector move = velocity*time;
    357 
    358   //orient the velocity in the direction of the spaceship.
    359   travelSpeed = velocity.len();
    360   velocity += ((this->getAbsDirX())*travelSpeed-velocity)*airViscosity;
    361   velocity = (velocity.getNormalized())*travelSpeed;
    362   this->burstEmitter->setEmissionRate(travelSpeed);
    363   this->burstEmitter->setEmissionVelocity(travelSpeed*.5, travelSpeed *.1);
     535  // Playable::tick(time);
     536
     537 // this->test->tick(time);
     538
     539  // Own Tick Setup, as a different fire routine is used on the weapon manager
     540  this->weaponMan.tick(time);
     541  this->secWeaponMan.tick(time);
     542
     543  if( this->systemFailure() )
     544    bFire = bSecFire = false;
     545
     546  // fire reqeust/release for primary weapons
     547  if( this->bFire)
     548    this->weaponMan.fire();
     549  else
     550    this->weaponMan.releaseFire();
     551
     552  // fire reqeust/release for secondary weapons
     553  if( this->bSecFire)
     554    this->secWeaponMan.fire();
     555  else
     556    this->secWeaponMan.releaseFire();
     557   
     558  // Tracktick
     559  if(this->entityTrack)
     560    this->entityTrack->tick(time);
     561
     562
     563  // Shield Regeneration and other regular calculations on the ship
     564  this->regen(time);
     565
     566  // Weapon Regeneration and other regular calculations on the ship
     567  this->weaponRegen(time);
     568
     569  // current engine speed output
     570  this->engineSpeedCur = this->engineSpeedBase + this->reactorOutput * this->engineEnergyShare;
     571
     572  // calculation of maxSpeed and acceleration:
     573  this->travelSpeed = this->engineSpeedCur * 5;
     574  this->acceleration = this->travelSpeed * 2;
     575
     576  this->movement(time);
     577
     578   // TRYING TO FIX PNode.
     579  this->cameraNode.setAbsCoorSoft(this->getAbsCoor() + Vector(0.0f, 5.0f, 0.0f), 30.0f);
     580  this->cameraNode.setRelDirSoft(this->getAbsDir(), 30.0f);
     581
     582 
     583  this->velocity  = (this->getAbsCoor() - this->oldPos) / time;
     584  this->oldPos    = this->getAbsCoor();
     585
     586//FIXME
     587  this->trail->tick(time);
     588  this->trailL->tick(time);
     589  this->trailR->tick(time);
     590
     591  if (!this->isTravelDistanceInit)
     592  {
     593    this->updateTravelDistance();
     594    //this->isTravelDistanceInit = true;
     595  }
    364596
    365597  //orient the spaceship in direction of the mouse
     598  /*
    366599  rotQuat = Quaternion::quatSlerp( this->getAbsDir(), mouseDir, 0.5);//fabsf(time)*shipInertia);
    367600  if (this->getAbsDir().distance(rotQuat) > 0.00000000000001)
    368601    this->setAbsDir( rotQuat);
    369602  //this->setAbsDirSoft(mouseDir,5);
    370 
    371   // this is the air friction (necessary for a smooth control)
    372   if(travelSpeed >= 120) velocity -= velocity.getNormalized()*travelSpeed*travelSpeed*0.0001;
    373   else if (travelSpeed <= 80) velocity -= velocity.getNormalized()*travelSpeed*0.001;
    374 
    375   //other physics (gravity)
    376   //if(travelSpeed < 120)
    377   //move += Vector(0,-1,0)*60*time + Vector(0,1,0)*travelSpeed/2*time;
    378 
    379   //hoover effect
    380   //cycle += time;
    381   //this->shiftCoor(Vector(0,1,0)*cos(this->cycle*2.0)*0.02);
    382 
    383   //readjust
    384   //if (this->getAbsDirZ().y > 0.1) this->shiftDir(Quaternion(time*0.3, Vector(1,0,0)));
    385   //else if (this->getAbsDirZ().y < -0.1) this->shiftDir(Quaternion(-time*0.3, Vector(1,0,0)));
    386 
    387   //SDL_WarpMouse(GraphicsEngine::getInstance()->getResolutionX()/2, GraphicsEngine::getInstance()->getResolutionY()/2);
    388 
     603  */
     604  /*
    389605  this->shiftCoor(move);
     606  */
    390607
    391608  //   PRINTF(0)("id of %s is: %i\n", this->getName(), this->getOMListNumber());
    392609
    393 }
    394 
    395 /**
    396  *  calculate the velocity
    397  * @param time the timeslice since the last frame
    398 */
    399 void SpaceShip::calculateVelocity (float time)
    400 {
    401   Vector accel(0.0, 0.0, 0.0);
    402   /*
    403   Vector rot(0.0, 0.0, 0.0); // wird ben�igt fr Helicopter
    404   */
    405   //float rotVal = 0.0;
    406   /* FIXME: calculating the direction and orthDirection every timeSlice is redundant! save it somewhere */
    407   /* calculate the direction in which the craft is heading  */
    408 
    409   //Plane plane(Vector(0,1,0), Vector(0,0,0));
    410 
    411   if( this->bUp )
    412   {
    413     //this->shiftCoor(this->getAbsDirX());
    414     //accel += (this->getAbsDirX())*2;
    415     accel += (this->getAbsDirX())*acceleration;
    416 
    417   }
    418 
    419   if( this->bDown )
    420   {
    421     //this->shiftCoor((this->getAbsDirX())*-1);
    422     //accel -= (this->getAbsDirX())*2;
    423     //if(velocity.len() > 50)
    424     accel -= (this->getAbsDirX())*0.5*acceleration;
    425 
    426 
    427 
    428   }
    429 
    430   if( this->bLeft/* > -this->getRelCoor().z*2*/)
    431   {
    432     this->shiftDir(Quaternion(time, Vector(0,1,0)));
    433     //    accel -= rightDirection;
    434     //velocityDir.normalize();
    435     //rot +=Vector(1,0,0);
    436     //rotVal -= .4;
    437   }
    438   if( this->bRight /* > this->getRelCoor().z*2*/)
    439   {
    440     this->shiftDir(Quaternion(-time, Vector(0,1,0)));
    441 
    442     //    accel += rightDirection;
    443     //velocityDir.normalize();
    444     //rot += Vector(1,0,0);
    445     //rotVal += .4;
    446   }
    447 
    448 
    449   if( this->bRollL /* > -this->getRelCoor().z*2*/)
    450   {
    451     mouseDir *= Quaternion(-time*2, Vector(1,0,0));
    452     //    accel -= rightDirection;
    453     //velocityDir.normalize();
    454     //rot +=Vector(1,0,0);
    455     //rotVal -= .4;
    456   }
    457   if( this->bRollR /* > this->getRelCoor().z*2*/)
    458   {
    459     mouseDir *= Quaternion(time*2, Vector(1,0,0));
    460 
    461     //    accel += rightDirection;
    462     //velocityDir.normalize();
    463     //rot += Vector(1,0,0);
    464     //rotVal += .4;
    465   }
    466   if (this->bAscend )
    467   {
    468     this->shiftDir(Quaternion(time, Vector(0,0,1)));
    469 
    470     //    accel += upDirection;
    471     //velocityDir.normalize();
    472     //rot += Vector(0,0,1);
    473     //rotVal += .4;
    474   }
    475   if (this->bDescend )
    476   {
    477     this->shiftDir(Quaternion(-time, Vector(0,0,1)));
    478 
    479     //    accel -= upDirection;
    480     //velocityDir.normalize();
    481     //rot += Vector(0,0,1);
    482     //rotVal -= .4;
    483   }
    484 
    485   velocity += accel*time*10;
    486   //rot.normalize();
    487   //this->setRelDirSoft(Quaternion(rotVal, rot), 5);
    488610}
    489611
     
    493615void SpaceShip::process(const Event &event)
    494616{
    495   Playable::process(event);
    496 
     617  //Playable::process(event);
     618 
    497619  if( event.type == KeyMapper::PEV_LEFT)
    498     this->bRollL = event.bPressed;
     620    this->bLeft = event.bPressed;
    499621  else if( event.type == KeyMapper::PEV_RIGHT)
    500     this->bRollR = event.bPressed;
     622  {
     623    this->bRight = event.bPressed;
     624    printf("ShipCoorX: %f \n", this->getRelCoor().x);
     625  }
    501626  else if( event.type == KeyMapper::PEV_FORWARD)
    502     this->bUp = event.bPressed; //this->shiftCoor(0,.1,0);
     627  {
     628    this->bForward = event.bPressed; //this->shiftCoor(0,.1,0);
     629   
     630  }
    503631  else if( event.type == KeyMapper::PEV_BACKWARD)
    504     this->bDown = event.bPressed; //this->shiftCoor(0,-.1,0);
     632    this->bBackward = event.bPressed; //this->shiftCoor(0,-.1,0);
     633  else if( event.type == KeyMapper::PEV_FIRE2)
     634    this->bSecFire = event.bPressed;
     635  else if( event.type == KeyMapper::PEV_FIRE1)
     636    this->bFire = event.bPressed;
     637  else if( event.type == KeyMapper::PEV_NEXT_WEAPON && event.bPressed)
     638  {
     639    this->nextWeaponConfig();
     640  }
     641  else if ( event.type == KeyMapper::PEV_PREVIOUS_WEAPON && event.bPressed)
     642    this->previousWeaponConfig();
     643
     644  if (!(State::getCamera()->getEventHandling()))
     645  {
     646    if( event.type == KeyMapper::PEV_VIEW0)
     647    {
     648      State::getCamera()->setViewMode(Camera::ViewNormal);
     649      State::getCameraTargetNode()->setParent(this);
     650      State::getCamera()->setParent(this);
     651    }
     652    else if( event.type == KeyMapper::PEV_VIEW1)
     653    {
     654      State::getCamera()->setViewMode(Camera::ViewBehind);
     655      State::getCameraTargetNode()->setParent(this);
     656      State::getCamera()->setParent(this);
     657    }
     658    else if( event.type == KeyMapper::PEV_VIEW2)
     659    {
     660      State::getCamera()->setViewMode(Camera::ViewFront);
     661      State::getCameraTargetNode()->setParent(this);
     662      State::getCamera()->setParent(this);
     663    }
     664    else if( event.type == KeyMapper::PEV_VIEW3)
     665    {
     666      State::getCamera()->setViewMode(Camera::ViewLeft);
     667      State::getCameraTargetNode()->setParent(this);
     668      State::getCamera()->setParent(this);
     669    }
     670    else if( event.type == KeyMapper::PEV_VIEW4)
     671    {
     672      State::getCamera()->setViewMode(Camera::ViewRight);
     673      State::getCameraTargetNode()->setParent(this);
     674      State::getCamera()->setParent(this);
     675    }
     676    else if( event.type == KeyMapper::PEV_VIEW5)
     677    {
     678      State::getCamera()->setViewMode(Camera::ViewTop);
     679      State::getCameraTargetNode()->setParent(this->travelNode);
     680      State::getCamera()->setParent(this->travelNode);
     681    }
     682  }
     683
     684
     685  /*
    505686  else if( event.type == EV_MOUSE_MOTION)
    506687  {
     688
    507689    this->xMouse += event.xRel;
    508690    this->yMouse += event.yRel;
    509691  }
     692  */
    510693}
    511694
    512695void SpaceShip::destroy( WorldEntity* killer )
    513696{
    514   PRINTF(0)("spaceship destroy\n");
     697  if(this->hasPlayer())
     698    Playable::destroy( killer);
     699
     700  PRINTF(5)("spaceship destroy\n");
     701
     702  EmitterNode* node  = NULL;
     703  DotEmitter* emitter = NULL;
     704  SpriteParticles*  explosionParticles  = NULL;
     705
     706  explosionParticles = new SpriteParticles(200);
     707  explosionParticles->setName("SpaceShipExplosionParticles");
     708  explosionParticles->setLifeSpan(.2, .3);
     709  explosionParticles->setRadius(0.0, 10.0);
     710  explosionParticles->setRadius(.5, 6.0);
     711  explosionParticles->setRadius(1.0, 3.0);
     712  explosionParticles->setColor(0.0, 1,1,1,.9);
     713  explosionParticles->setColor(0.1,  1,1,0,.9);
     714  explosionParticles->setColor(0.5, .8,.4,0,.5);
     715  explosionParticles->setColor(1.0, .2,.2,.2,.5);
     716
     717 
     718  emitter = new DotEmitter( 2000, 70, 360);
     719  //emitter->setSpread( 0, M_2_PI);
     720  emitter->setEmissionRate( 200.0);
     721  //emitter->setEmissionVelocity( 200.0);
     722  //emitter->setSystem( explosionParticles);
     723  //emitter->setAbsCoor( this->getAbsCoor());
     724
     725  node  = new EmitterNode( .1f);
     726  node->setupParticle( emitter, explosionParticles);
     727  node->setAbsDir( this->getAbsDir());
     728  node->setVelocity( this->getVelocity() * .9f);
     729  node->setAbsCoor( this->getAbsCoor());
     730  if( !node->start())
     731    PRINTF(0)("Explosion node not correctly started!");
     732/*
     733  PNode* node          = new PNode();
     734  node->setAbsCoor(this->getAbsCoor());
     735  Explosion* explosion = new Explosion();
     736  explosion->explode( node, Vector(5,5,5));
     737*/
     738/*
     739  if( this->hasPlayer())
     740  {
     741        this->setAbsCoor(Vector(-10000,10000,10000));
     742        this->hide();
     743  }
     744  else
     745  {*/
     746    this->setAbsCoor( this->getAbsCoor() + Vector(100,0,0) + Vector(1,0,0) * VECTOR_RAND(150).dot(Vector(1,0,0)));
     747  //}
     748
    515749}
    516750
    517751void SpaceShip::respawn( )
    518752{
    519   toList( OM_PLAYERS );
    520 }
    521 
    522 
    523 
    524 
     753  Playable::respawn();
     754}
     755
     756
     757void SpaceShip::damage(float pDamage, float eDamage){
     758  PRINTF(5)("ship hit for (%f,%f) \n",pDamage,eDamage);
     759
     760  if( this->shieldActive) {
     761    if( this->shieldCur > pDamage) {
     762      this->shieldCur = this->shieldCur - pDamage;
     763    }
     764    else { // shield <= pDamage
     765      this->shieldCur -=pDamage;
     766      this->shieldActive = false; //shield collapses
     767      pDamage += this->shieldCur;
     768      if( !this->shieldActive) {
     769        this->armorCur -= pDamage / 2; // remaining damages hits armor at half rate
     770        this->electronicCur -= eDamage;
     771      }
     772    }
     773  }
     774  else {
     775    this->armorCur = this->armorCur - pDamage;
     776    this->electronicCur = this->electronicCur - eDamage;
     777  }
     778  if( this->armorCur <= 0) { /* FIXME implement shipcrash*/ }
     779    this->destroy(this);
     780
     781  updateElectronicWidget();
     782  updateShieldWidget();
     783
     784  this->setHealth( this->armorCur);
     785}
     786
     787
     788void SpaceShip::regen(float time){
     789  float tmp;
     790  if (this->armorCur != this->armorMax || this->armorRegen != 0){
     791    tmp = this->armorCur + this->armorRegen * time;
     792    if ( tmp > electronicMax)
     793      this->armorCur = this->armorMax;
     794    else
     795      this->armorCur = tmp;
     796  }
     797  if (this->shieldCur != this->shieldMax || this->shieldRegen != 0){
     798    tmp =  this->shieldCur + (this->shieldRegen + this->reactorOutput * this->shieldEnergyShare) * time;
     799    if( tmp > shieldMax)
     800      this->shieldCur = this->shieldMax;
     801    else
     802      this->shieldCur = tmp;
     803    this->shieldActive = ( this->shieldActive || this->shieldCur > shieldTH);
     804
     805    updateShieldWidget();
     806  }
     807
     808  this->setHealth( this->shieldCur);      // FIXME currently just to test share system
     809
     810  if (this->electronicCur != this->electronicMax || this->electronicRegen != 0){
     811    tmp = this->electronicCur + this->electronicRegen * time;
     812    if ( tmp > electronicMax)
     813      this->electronicCur = this->electronicMax;
     814    else
     815      this->electronicCur = tmp;
     816
     817    updateElectronicWidget();
     818  }
     819
     820}
     821
     822
     823/**
     824 * Weapon regeneration
     825 * does not use any reactor capacity, as it wouldn't work in a consistent way.
     826 */
     827void SpaceShip::weaponRegen(float time)
     828{
     829  float energy  = ( this->reactorOutput * this->weaponEnergyShare + this->weaponEnergyRegen) * time;
     830  Weapon* weapon;
     831  for( unsigned int i=0; i < this->weaponMan.getSlotCount(); i++)
     832  {
     833    weapon = this->weaponMan.getWeapon(i);
     834    if( weapon != NULL && weapon->isActive())
     835    {
     836      weapon->increaseEnergy( energy);
     837    }
     838
     839  }
     840  // weaponMan.increaseAmmunition( weapon, energy);
     841}
     842
     843
     844void SpaceShip::enterPlaymode(Playable::Playmode playmode)
     845{
     846  switch(playmode)
     847  {
     848    case Playable::Full3D:
     849      /*
     850      if (State::getCameraNode != NULL)
     851      {
     852        Vector absCoor = this->getAbsCoor();
     853        this->setParent(PNode::getNullParent());
     854        this->setAbsCoor(absCoor);
     855        State::getCameraNode()->setParentSoft(&this->cameraNode);
     856        State::getCameraNode()->setRelCoorSoft(-10, 0,0);
     857        State::getCameraTargetNode()->setParentSoft(&this->cameraNode);
     858        State::getCameraTargetNode()->setRelCoorSoft(100, 0,0);
     859
     860      }
     861      */
     862      //break;
     863
     864      break;
     865    case Playable::Horizontal:
     866      if (State::getCameraNode != NULL)
     867      {
     868        this->debugNode(1);
     869        this->travelNode->debugNode(1);
     870
     871        this->travelNode->setAbsCoor(this->getAbsCoor());
     872        this->travelNode->updateNode(0.01f);
     873
     874        this->isTravelDistanceInit = false;
     875
     876        if(this->entityTrack)
     877           this->travelNode->setParent(this->entityTrack->getTrackNode());
     878
     879        this->setParent(this->travelNode);
     880        this->setRelCoor(0,0,0);
     881
     882        State::getCameraNode()->setParentSoft(this->travelNode);
     883        //State::getCameraNode()->setParentSoft(this);
     884        //State::getCameraNode()->setRelCoorSoft(-0.01, 40, 0);
     885        State::getCameraTargetNode()->setParentSoft(this->travelNode);
     886        //State::getCameraTargetNode()->setParentSoft(this);
     887        //State::getCameraTargetNode()->setRelCoorSoft(0,0,0);
     888        this->setCameraMode(Camera::ViewTop);
     889        State::getCamera()->setEventHandling(false);
     890        registerEvent(KeyMapper::PEV_VIEW0);
     891        registerEvent(KeyMapper::PEV_VIEW1);
     892        registerEvent(KeyMapper::PEV_VIEW2);
     893        registerEvent(KeyMapper::PEV_VIEW3);
     894        registerEvent(KeyMapper::PEV_VIEW4);
     895        registerEvent(KeyMapper::PEV_VIEW5);
     896
     897        State::getCamera()->setParentMode(PNODE_ALL);
     898
     899        //this->updateTravelDistance();
     900
     901        this->debugNode(1);
     902        this->travelNode->debugNode(1);
     903      }
     904      break;
     905
     906    default:
     907      PRINTF(2)("Playmode %s Not Implemented in %s\n", Playable::playmodeToString(this->getPlaymode()).c_str(), this->getClassCName());
     908  }
     909}
     910
     911/**
     912 * @brief calculate the velocity
     913 * @param time the timeslice since the last frame
     914*/
     915
     916void SpaceShip::movement (float dt)
     917{
     918  //by releasing the buttons, the velocity decreases with airCoeff*Acceleration. Should be strong enough so
     919  //the ship doesn't slide too much.
     920  float airCoeff = 2.5;
     921  float pi = 3.14;
     922
     923  switch(this->getPlaymode())
     924  {
     925    case Playable::Horizontal:
     926    {
     927      // these routines will change the travel movement into zero in a short amout of time, if the player
     928      // doesn't press any buttons.
     929      if (this->travelVelocity.x >= 0)
     930      {
     931        if (this->travelVelocity.x > airCoeff*this->acceleration * dt)
     932          this->travelVelocity.x -= airCoeff* this->acceleration * dt;
     933        else
     934          this->travelVelocity.x = 0;
     935      }
     936      else
     937      {
     938        if (this->travelVelocity.x < -airCoeff*this->acceleration * dt)
     939          this->travelVelocity.x += airCoeff* this->acceleration * dt;
     940        else
     941          this->travelVelocity.x = 0;
     942      }
     943      if (this->travelVelocity.z >= 0)
     944      {
     945        if (this->travelVelocity.z > airCoeff*this->acceleration * dt)
     946          this->travelVelocity.z -= airCoeff* this->acceleration * dt;
     947        else
     948          this->travelVelocity.z = 0;
     949      }
     950      else
     951      {
     952        if (this->travelVelocity.z < -airCoeff*this->acceleration * dt)
     953          this->travelVelocity.z += airCoeff* this->acceleration * dt;
     954        else
     955          this->travelVelocity.z = 0;
     956      }
     957   
     958      // this will evite, that the ship moves outside the travelDistance- borders,when the player releases all buttons
     959      // and its continuing to slide a bit.
     960      Vector oldCoor = this->getRelCoor();
     961      if (this->getRelCoor().x > this->travelDistancePlus.x) this->setRelCoor(this->travelDistancePlus.x, oldCoor.y, oldCoor.z);
     962      if (this->getRelCoor().x < this->travelDistanceMinus.x) this->setRelCoor(this->travelDistanceMinus.x, oldCoor.y, oldCoor.z);
     963      if (this->getRelCoor().z > this->travelDistancePlus.y) this->setRelCoor(oldCoor.x, oldCoor.y, this->travelDistancePlus.y);
     964      if (this->getRelCoor().z < this->travelDistanceMinus.y) this->setRelCoor(oldCoor.x, oldCoor.y, this->travelDistanceMinus.y);
     965   
     966      if( this->systemFailure() )
     967        bForward = bBackward = bLeft = bRight = false;
     968   
     969      if( this->bForward )
     970      {
     971        //printf("ShipCoorX: %f \n", this->getRelCoor().x);
     972        if(this->getRelCoor().x < this->travelDistancePlus.x)
     973        {
     974          if (this->travelVelocity.x < this->travelSpeed)
     975          {
     976            this->travelVelocity.x += (airCoeff + 1.0)*this->acceleration*dt;
     977          }
     978          else
     979          {
     980            this->travelVelocity.x = this->travelSpeed;
     981          }
     982        }
     983        else
     984        {
     985          this->travelVelocity.x = 0.0f;
     986        }
     987      }
     988   
     989      if( this->bBackward )
     990      {
     991        if(this->getRelCoor().x > this->travelDistanceMinus.x)
     992        {
     993          if (this->travelVelocity.x > -this->travelSpeed)
     994          {
     995            this->travelVelocity.x -= (airCoeff + 1.0)*this->acceleration*dt;
     996          }
     997          else
     998          {
     999            this->travelVelocity.x = -this->travelSpeed;
     1000          }
     1001        }
     1002        else
     1003        {
     1004          this->travelVelocity.x = 0.0f;
     1005        }
     1006      }
     1007   
     1008      if( this->bLeft)
     1009      {
     1010        if(this->getRelCoor().z > this->travelDistanceMinus.y)
     1011        {
     1012          if (this->travelVelocity.z > -this->travelSpeed)
     1013          {
     1014            this->travelVelocity.z -= (airCoeff + 1.0)*this->acceleration*dt;
     1015          }
     1016          else
     1017          {
     1018            this->travelVelocity.z = -this->travelSpeed;
     1019          }
     1020        }
     1021        else
     1022        {
     1023          this->travelVelocity.z = 0.0f;
     1024        }
     1025        this->setRelDirSoft(Quaternion(-pi/6, Vector(1,0,0)), 6);
     1026      }
     1027   
     1028      if( this->bRight)
     1029      {
     1030        //printf("ShipCoorZ: %f \n", this->getRelCoor().z);
     1031        if(this->getRelCoor().z < this->travelDistancePlus.y)
     1032        {
     1033          if (this->travelVelocity.z < this->travelSpeed)
     1034          {
     1035            this->travelVelocity.z += (airCoeff + 1.0)*this->acceleration*dt;
     1036          }
     1037          else
     1038          {
     1039            this->travelVelocity.z = this->travelSpeed;
     1040          }
     1041        }
     1042        else
     1043        {
     1044          this->travelVelocity.z = 0.0f;
     1045        }
     1046        this->setRelDirSoft(Quaternion(pi/6, Vector(1,0,0)), 6);
     1047      }
     1048      if (!this->bRight && !this->bLeft)
     1049      {
     1050        this->setRelDirSoft(Quaternion(0, Vector(1,0,0)), 6);
     1051      }
     1052
     1053    //normalisation of the vectors (vector sum must be <= travelspeed)
     1054    float xzNorm = sqrt(pow(this->travelVelocity.x, 2) + pow(this->travelVelocity.z, 2));
     1055    if (xzNorm > this->travelSpeed)
     1056    {
     1057      this->travelVelocity.x = this->travelVelocity.x/xzNorm * this->travelSpeed;
     1058      this->travelVelocity.z = this->travelVelocity.z/xzNorm * this->travelSpeed;
     1059    }
     1060
     1061    //this moves camera and ship along the travel path.
     1062    if(!this->entityTrack)
     1063       this->travelNode->shiftCoor(Vector(this->cameraSpeed * dt, 0, 0));
     1064
     1065    break;
     1066    }
     1067    case Playable::Vertical:
     1068      break;
     1069    default:
     1070      PRINTF(4)("Playmode %s Not Implemented in %s\n", Playable::playmodeToString(this->getPlaymode()).c_str(), this->getClassCName());
     1071  }
     1072   //set new coordinates calculated through key- events.
     1073  this->shiftCoor (this->travelVelocity * dt);
     1074}
     1075
     1076void SpaceShip::setPlaymodeXML(const std::string& playmode)
     1077{
     1078  this->setPlaymode(Playable::stringToPlaymode(playmode));
     1079}
     1080
     1081/**
     1082 * @brief jumps to the next WeaponConfiguration
     1083 */
     1084void SpaceShip::nextWeaponConfig()
     1085{
     1086  PRINTF(0)("Requested next weapon config!\n");
     1087  this->weaponMan.nextWeaponConfig();
     1088  Playable::weaponConfigChanged();
     1089}
     1090
     1091/**
     1092 * @brief moves to the last WeaponConfiguration
     1093 */
     1094void SpaceShip::previousWeaponConfig()
     1095{
     1096  this->curWeaponPrimary    = (this->curWeaponPrimary + 1) % 3;
     1097  this->weaponMan.changeWeaponConfig(this->curWeaponPrimary);
     1098  Playable::weaponConfigChanged();
     1099}
     1100
     1101void SpaceShip::hit( float damage, WorldEntity* killer)
     1102{
     1103  this->damage(killer->getDamage(),0);
     1104}
     1105
     1106void SpaceShip::updateElectronicWidget()
     1107{
     1108  if (this->electronicWidget != NULL)
     1109  { //if it exists already: update it
     1110     this->electronicWidget->setMaximum(this->electronicMax);
     1111     this->electronicWidget->setValue(this->electronicCur);
     1112  }
     1113  else
     1114  { //create the widget
     1115    this->electronicWidget = new OrxGui::GLGuiEnergyWidgetVertical();
     1116    this->electronicWidget->getBarWidget()->setChangedValueColor(Color(1,0,0,1));
     1117    //this->electronicWidget->setDisplayedName("Electronics:");
     1118    //this->electronicWidget->setSize2D(100,20);
     1119    //this->electronicWidget->setAbsCoor2D(150,200);
     1120    this->updateElectronicWidget();
     1121    if (this->hasPlayer())
     1122      State::getPlayer()->hud().setEnergyWidget(this->electronicWidget);
     1123  }
     1124}
     1125
     1126void SpaceShip::updateShieldWidget()
     1127{
     1128  if (this->shieldWidget != NULL)
     1129  {
     1130    this->shieldWidget->setMaximum(this->shieldMax);
     1131    this->shieldWidget->setValue(this->shieldCur);;
     1132  }
     1133  else
     1134  {
     1135    this->shieldWidget = new OrxGui::GLGuiEnergyWidgetVertical();
     1136    this->shieldWidget->getBarWidget()->setChangedValueColor(Color(1,0,0,1));
     1137    //this->shieldWidget->setDisplayedName("Shield:");
     1138    //his->shieldWidget->setSize2D(100,20);
     1139    //this->shieldWidget->setAbsCoor2D(200,200);
     1140    this->updateShieldWidget();
     1141    if (this->hasPlayer())
     1142      State::getPlayer()->hud().setShiledWidget(this->shieldWidget);
     1143  }
     1144}
     1145
     1146void SpaceShip::setCameraDistance(float dist)
     1147{
     1148  State::getCamera()->setViewTopDistance(dist);
     1149}
     1150
     1151void SpaceShip::setCameraFovy(float fovy)
     1152{
     1153  State::getCamera()->setViewTopFovy(fovy);
     1154}
     1155
     1156void SpaceShip::updateTravelDistance()
     1157{
     1158  float x = 1.25 * this->actionWidthPercentage * fabsf(State::getCamera()->getAbsCoor().y) * tan(State::getCamera()->getFovy()*M_PI /360.0);
     1159  float y = x / State::getCamera()->getAspectRatio() / this->actionWidthPercentage;
     1160  //State::getCamera()->setAbsCoor(-5, 1000, 0);
     1161
     1162
     1163  //State::getCamera()->getAbsCoor().print();
     1164  //printf("CameraRelCoorY: %f \n", State::getCamera()->getRelCoor().y);
     1165
     1166  //printf("x: %f, y: %f \n", x, y);
     1167  this->travelDistancePlus = Vector2D(y, x);
     1168  this->travelDistanceMinus = Vector2D(-y, -x);
     1169
     1170  State::getPlayer()->hud().setOverlayPercentage(100-int(100*this->actionWidthPercentage));
     1171  PRINTF(0)("TravelDistance has been updated\n");
     1172  this->isTravelDistanceInit = true;
     1173}
     1174
     1175void SpaceShip::setActionWidthPercentage(int i)
     1176{
     1177  if (i>100) i=100;
     1178  if (i<0) i=0;
     1179  this->actionWidthPercentage = i/100.0;
     1180
     1181  if (this->hasPlayer())
     1182    this->isTravelDistanceInit = false;
     1183};
Note: See TracChangeset for help on using the changeset viewer.