Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10368 in orxonox.OLD for trunk/src/world_entities/space_ships


Ignore:
Timestamp:
Jan 25, 2007, 2:18:07 PM (18 years ago)
Author:
patrick
Message:

merged the branche playability into the trunk

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk

    • Property svn:ignore
      •  

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

    r10317 r10368  
    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");
    223 
    224   this->burstSystem = new SpriteParticles(1000);
    225   this->burstSystem->addEmitter(this->burstEmitter);
    226   this->burstSystem->setName("SpaceShip_Burst_System");
    227   ((SpriteParticles*)this->burstSystem)->setMaterialTexture("textures/radial-trans-noise.png");
    228   this->burstSystem->setLifeSpan(1.0, .3);
    229   this->burstSystem->setRadius(0.0, 1.0);
    230   this->burstSystem->setRadius(0.05, 1.0);
    231   this->burstSystem->setRadius(.5, .8);
    232   this->burstSystem->setRadius(1.0, 0);
    233   this->burstSystem->setColor(0.0, .7,.7,1,.7);
    234   this->burstSystem->setColor(0.2, 0,0,0.8,.5);
    235   this->burstSystem->setColor(0.5, .5,.5,.8,.8);
    236   this->burstSystem->setColor(1.0, .8,.8,.8,.0);
    237 
    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 ) );
     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)));
     326
     327  this->secWeaponMan.setSlotPosition(0, Vector(1.5, 0, 0));
     328  this->secWeaponMan.setSlotCapability(0, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL);
     329
     330  this->secWeaponMan.setSlotPosition(1, Vector(2.6, 0, 3.0));
     331  this->secWeaponMan.setSlotCapability(1, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL);
     332
     333  this->secWeaponMan.setSlotPosition(2, Vector(1.5, 0, -.5));
     334  this->secWeaponMan.setSlotDirection(2, Quaternion(-M_PI_4*.5, Vector(1,0,0)));
     335
     336  this->secWeaponMan.setSlotPosition(3, Vector(1.5, 0, .5));
     337  this->secWeaponMan.setSlotDirection(3, Quaternion(M_PI_4*.5, Vector(1,0,0)));
     338
     339  this->secWeaponMan.setSlotPosition(4, Vector(1.5, 0, .5));
     340  this->secWeaponMan.setSlotDirection(4, Quaternion(-M_PI_4*.5+M_PI, Vector(1,0,0)));
     341
     342  this->secWeaponMan.setSlotPosition(5, Vector(1.5, 0, -.5));
     343  this->secWeaponMan.setSlotDirection(5, Quaternion(+M_PI_4*.5-M_PI, Vector(1,0,0)));
     344
     345
     346  this->weaponMan.getFixedTarget()->setParent(this);
     347  this->weaponMan.getFixedTarget()->setRelCoor(100000,0,0);
     348
     349
     350  this->secWeaponMan.getFixedTarget()->setParent(this);
     351  this->secWeaponMan.getFixedTarget()->setRelCoor(100000,0,0);
     352  this->secWeaponMan.setRotationSpeed(0);
     353
     354  dynamic_cast<Element2D*>(this->weaponMan.getFixedTarget())->setVisibility( false);
     355
     356
     357  registerVar( new SynchronizeableBool( &bForward, &bForward, "bForward", PERMISSION_OWNER ) );
     358  registerVar( new SynchronizeableBool( &bBackward, &bBackward, "bBackward", PERMISSION_OWNER ) );
    243359  registerVar( new SynchronizeableBool( &bLeft, &bLeft, "bLeft", PERMISSION_OWNER ) );
    244360  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 ) );
     361  registerVar( new SynchronizeableFloat( &cameraLook, &cameraLook, "cameraLook", PERMISSION_OWNER ) );
     362  registerVar( new SynchronizeableFloat( &rotation, &rotation, "rotation", PERMISSION_OWNER ) );
     363  registerVar( new SynchronizeableBool( &bFire, &bFire, "bSecFire", PERMISSION_OWNER));
     364  registerVar( new SynchronizeableVector( &velocity, &velocity, "velocity", PERMISSION_MASTER_SERVER ) );
     365
     366  //this->airFriction = 0.5f;
     367  //this->travelDistancePlus = Vector2D(38.0, 43.0);
     368  //this->travelDistanceMinus = Vector2D(-38.0, -43.0);
     369  this->travelDistancePlus = Vector2D(50,50);
     370  this->travelDistanceMinus = Vector2D(-50,-50);
     371  this->isTravelDistanceInit = true;
     372  this->actionWidthPercentage = 1;
     373
     374  this->cameraSpeed = 40;
     375  this->cameraLook = 0.0f;
     376  //this->airFriction = 0.0f;
     377
     378  srand(time(0));  //initaialize RNG
     379
     380  this->travelNode->debugDraw();
     381
     382  this->setSupportedPlaymodes(Playable::Horizontal | Playable::Vertical);
     383
     384  /// FIXME
     385  this->trail = new Trail( 5, 10, .2, this);
     386  this->trail->setTexture( "maps/engine.png");
     387
     388  this->trailL = new Trail( 5, 10, .2, this);
     389  this->trailL->setTexture( "maps/engine.png");
     390
     391  this->trailR = new Trail( 5, 10, .2, this);
     392  this->trailR->setTexture( "maps/engine.png");
     393
     394
     395  this->toList(OM_GROUP_00);
     396
     397  //FIXME Just testaddition to show the wobblegrid
     398/*
     399  this->test  = new Wobblegrid(5);
     400  test->setTexture("maps/blub.png");
     401
     402  test->setAbsCoor( this->getAbsCoor() + Vector(0, 2, 0));
     403  test->setParent( this);
     404*/
     405
    249406}
    250407
     
    257414{
    258415  Playable::loadParams(root);
    259 }
    260 
    261 void SpaceShip::setPlayDirection(const Quaternion& quat, float speed)
    262 {
    263   this->mouseDir = quat;
    264 }
    265 
     416
     417  LoadParam(root, "playmode", this, SpaceShip, setPlaymodeXML);
     418  LoadParam(root, "cameraDistance", this, SpaceShip, setCameraDistance);
     419  LoadParam(root, "cameraFovy", this, SpaceShip, setCameraFovy);
     420  LoadParam(root, "actionWidthPercentage", this, SpaceShip, setActionWidthPercentage);
     421
     422  State::getCamera()->setViewMode(Camera::ViewTop);
     423}
     424
     425
     426void SpaceShip::setPlayDirection(const Quaternion& rot, float speed)
     427{
     428  //this->direction = Quaternion (rot.getHeading(), Vector(0,1,0));
     429}
    266430
    267431void SpaceShip::reset()
    268432{
    269   bUp = bDown = bLeft = bRight = bAscend = bDescend = bRollL = bRollR = false;
    270 
    271   xMouse = yMouse = 0;
     433  bForward = bBackward = bLeft = bRight = bAscend = bDescend = bRollL = bRollR = bFire = bSecFire = false;
     434
     435  //xMouse = yMouse = 0;
    272436
    273437  this->setHealth(80);
     
    278442void SpaceShip::enter()
    279443{
    280   dynamic_cast<Element2D*>(this->getWeaponManager().getFixedTarget())->setVisibility( true);
    281   this->attachCamera();
     444  this->secWeaponMan.showCrosshair();
     445  this->toList( OM_GROUP_01 );
     446  State::getPlayer()->hud().setRadarCenterNode(this->travelNode);
     447  State::getPlayer()->hud().setOverlayActive(true);
     448  //dynamic_cast <OrxGui::GLGuiEnergyWidgetVertical*> (State::getPlayer()->hud().getArmorWidget())->setDisplayedName("Armor");
     449  //dynamic_cast<Element2D*>(this->secWeaponMan.getFixedTarget())->setVisibility( true);
     450  //this->attachCamera();
     451 // this->setPlaymode(Playable::Horizontal);
    282452}
    283453
    284454void SpaceShip::leave()
    285455{
    286   dynamic_cast<Element2D*>(this->getWeaponManager().getFixedTarget())->setVisibility( false);
    287   this->detachCamera();
     456  this->secWeaponMan.hideCrosshair();
     457  this->toList( OM_GROUP_00);
     458  State::getPlayer()->hud().setOverlayActive(false);
     459  State::getCamera()->setEventHandling(true);
     460  State::getPlayer()->hud().setRadarCenterNode(NULL);
     461  //dynamic_cast<Element2D*>(this->secWeaponMan.getFixedTarget())->setVisibility( false);
     462  //this->detachCamera();
    288463}
    289464
     
    294469void SpaceShip::postSpawn ()
    295470{
     471  if(this->hasPlayer())
     472    Playable::postSpawn();
     473
    296474  //setCollision(new CollisionCluster(1.0, Vector(0,0,0)));
    297475}
     
    301479*/
    302480void SpaceShip::leftWorld ()
    303 {}
     481{
     482
     483}
    304484
    305485WorldEntity* 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 }
    315486
    316487/**
     
    321492  WorldEntity::draw();
    322493
     494  glMatrixMode(GL_MODELVIEW);
     495  glPushMatrix();
     496
     497  float matrix[4][4];
     498  glTranslatef (this->getAbsCoor ().x-1, this->getAbsCoor ().y-.2, this->getAbsCoor ().z);
     499  this->getAbsDir().matrix (matrix);
     500  glMultMatrixf((float*)matrix);
     501  //glScalef(2.0, 2.0, 2.0);  // no double rescale
     502        // FIXME
     503  this->trail->draw();
     504
     505  glTranslatef(0,0,-.5);
     506  this->trailL->draw();
     507
     508  glTranslatef(0,0,1);
     509  this->trailR->draw();
     510
     511  glPopMatrix();
    323512  //this->debug(0);
    324513}
     
    330519void SpaceShip::tick (float time)
    331520{
    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);
     521  // Playable::tick(time);
     522
     523 // this->test->tick(time);
     524
     525  // Own Tick Setup, as a different fire routine is used on the weapon manager
     526  this->weaponMan.tick(time);
     527  this->secWeaponMan.tick(time);
     528
     529  if( this->systemFailure() )
     530    bFire = bSecFire = false;
     531
     532  // fire reqeust/release for primary weapons
     533  if( this->bFire)
     534    this->weaponMan.fire();
     535  else
     536    this->weaponMan.releaseFire();
     537
     538  // fire reqeust/release for secondary weapons
     539  if( this->bSecFire)
     540    this->secWeaponMan.fire();
     541  else
     542    this->secWeaponMan.releaseFire();
     543
     544  // Tracktick
     545  if(this->entityTrack)
     546    this->entityTrack->tick(time);
     547
     548
     549  // Shield Regeneration and other regular calculations on the ship
     550  this->regen(time);
     551
     552  // Weapon Regeneration and other regular calculations on the ship
     553  this->weaponRegen(time);
     554
     555  // current engine speed output
     556  this->engineSpeedCur = this->engineSpeedBase + this->reactorOutput * this->engineEnergyShare;
     557
     558  // calculation of maxSpeed and acceleration:
     559  this->travelSpeed = this->engineSpeedCur * 5;
     560  this->acceleration = this->travelSpeed * 2;
     561
     562  this->movement(time);
     563
     564   // TRYING TO FIX PNode.
     565  this->cameraNode.setAbsCoorSoft(this->getAbsCoor() + Vector(0.0f, 5.0f, 0.0f), 30.0f);
     566  this->cameraNode.setRelDirSoft(this->getAbsDir(), 30.0f);
     567
     568
     569  this->velocity  = (this->getAbsCoor() - this->oldPos) / time;
     570  this->oldPos    = this->getAbsCoor();
     571
     572//FIXME
     573  this->trail->tick(time);
     574  this->trailL->tick(time);
     575  this->trailR->tick(time);
     576
     577  if (!this->isTravelDistanceInit)
     578  {
     579    this->updateTravelDistance();
     580    //this->isTravelDistanceInit = true;
     581  }
    364582
    365583  //orient the spaceship in direction of the mouse
     584  /*
    366585  rotQuat = Quaternion::quatSlerp( this->getAbsDir(), mouseDir, 0.5);//fabsf(time)*shipInertia);
    367586  if (this->getAbsDir().distance(rotQuat) > 0.00000000000001)
    368587    this->setAbsDir( rotQuat);
    369588  //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 
     589  */
     590  /*
    389591  this->shiftCoor(move);
     592  */
    390593
    391594  //   PRINTF(0)("id of %s is: %i\n", this->getName(), this->getOMListNumber());
    392595
    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);
    488596}
    489597
     
    493601void SpaceShip::process(const Event &event)
    494602{
    495   Playable::process(event);
     603  //Playable::process(event);
    496604
    497605  if( event.type == KeyMapper::PEV_LEFT)
    498     this->bRollL = event.bPressed;
     606    this->bLeft = event.bPressed;
    499607  else if( event.type == KeyMapper::PEV_RIGHT)
    500     this->bRollR = event.bPressed;
     608  {
     609    this->bRight = event.bPressed;
     610    printf("ShipCoorX: %f \n", this->getRelCoor().x);
     611  }
    501612  else if( event.type == KeyMapper::PEV_FORWARD)
    502     this->bUp = event.bPressed; //this->shiftCoor(0,.1,0);
     613  {
     614    this->bForward = event.bPressed; //this->shiftCoor(0,.1,0);
     615
     616  }
    503617  else if( event.type == KeyMapper::PEV_BACKWARD)
    504     this->bDown = event.bPressed; //this->shiftCoor(0,-.1,0);
     618    this->bBackward = event.bPressed; //this->shiftCoor(0,-.1,0);
     619  else if( event.type == KeyMapper::PEV_FIRE2)
     620    this->bSecFire = event.bPressed;
     621  else if( event.type == KeyMapper::PEV_FIRE1)
     622    this->bFire = event.bPressed;
     623  else if( event.type == KeyMapper::PEV_NEXT_WEAPON && event.bPressed)
     624  {
     625    this->nextWeaponConfig();
     626  }
     627  else if ( event.type == KeyMapper::PEV_PREVIOUS_WEAPON && event.bPressed)
     628    this->previousWeaponConfig();
     629
     630  if (!(State::getCamera()->getEventHandling()))
     631  {
     632    if( event.type == KeyMapper::PEV_VIEW0)
     633    {
     634      State::getCamera()->setViewMode(Camera::ViewNormal);
     635      State::getCameraTargetNode()->setParent(this);
     636      State::getCamera()->setParent(this);
     637    }
     638    else if( event.type == KeyMapper::PEV_VIEW1)
     639    {
     640      State::getCamera()->setViewMode(Camera::ViewBehind);
     641      State::getCameraTargetNode()->setParent(this);
     642      State::getCamera()->setParent(this);
     643    }
     644    else if( event.type == KeyMapper::PEV_VIEW2)
     645    {
     646      State::getCamera()->setViewMode(Camera::ViewFront);
     647      State::getCameraTargetNode()->setParent(this);
     648      State::getCamera()->setParent(this);
     649    }
     650    else if( event.type == KeyMapper::PEV_VIEW3)
     651    {
     652      State::getCamera()->setViewMode(Camera::ViewLeft);
     653      State::getCameraTargetNode()->setParent(this);
     654      State::getCamera()->setParent(this);
     655    }
     656    else if( event.type == KeyMapper::PEV_VIEW4)
     657    {
     658      State::getCamera()->setViewMode(Camera::ViewRight);
     659      State::getCameraTargetNode()->setParent(this);
     660      State::getCamera()->setParent(this);
     661    }
     662    else if( event.type == KeyMapper::PEV_VIEW5)
     663    {
     664      State::getCamera()->setViewMode(Camera::ViewTop);
     665      State::getCameraTargetNode()->setParent(this->travelNode);
     666      State::getCamera()->setParent(this->travelNode);
     667    }
     668  }
     669
     670
     671  /*
    505672  else if( event.type == EV_MOUSE_MOTION)
    506673  {
     674
    507675    this->xMouse += event.xRel;
    508676    this->yMouse += event.yRel;
    509677  }
     678  */
    510679}
    511680
    512681void SpaceShip::destroy( WorldEntity* killer )
    513682{
    514   PRINTF(0)("spaceship destroy\n");
     683  if(this->hasPlayer())
     684    Playable::destroy( killer);
     685
     686  PRINTF(5)("spaceship destroy\n");
     687
     688  EmitterNode* node  = NULL;
     689  DotEmitter* emitter = NULL;
     690  SpriteParticles*  explosionParticles  = NULL;
     691
     692  explosionParticles = new SpriteParticles(200);
     693  explosionParticles->setName("SpaceShipExplosionParticles");
     694  explosionParticles->setLifeSpan(.2, .3);
     695  explosionParticles->setRadius(0.0, 10.0);
     696  explosionParticles->setRadius(.5, 6.0);
     697  explosionParticles->setRadius(1.0, 3.0);
     698  explosionParticles->setColor(0.0, 1,1,1,.9);
     699  explosionParticles->setColor(0.1,  1,1,0,.9);
     700  explosionParticles->setColor(0.5, .8,.4,0,.5);
     701  explosionParticles->setColor(1.0, .2,.2,.2,.5);
     702
     703
     704  emitter = new DotEmitter( 2000, 70, 360);
     705  //emitter->setSpread( 0, M_2_PI);
     706  emitter->setEmissionRate( 200.0);
     707  //emitter->setEmissionVelocity( 200.0);
     708  //emitter->setSystem( explosionParticles);
     709  //emitter->setAbsCoor( this->getAbsCoor());
     710
     711  node  = new EmitterNode( .1f);
     712  node->setupParticle( emitter, explosionParticles);
     713  node->setAbsDir( this->getAbsDir());
     714  node->setVelocity( this->getVelocity() * .9f);
     715  node->setAbsCoor( this->getAbsCoor());
     716  if( !node->start())
     717    PRINTF(0)("Explosion node not correctly started!");
     718/*
     719  PNode* node          = new PNode();
     720  node->setAbsCoor(this->getAbsCoor());
     721  Explosion* explosion = new Explosion();
     722  explosion->explode( node, Vector(5,5,5));
     723*/
     724/*
     725  if( this->hasPlayer())
     726  {
     727        this->setAbsCoor(Vector(-10000,10000,10000));
     728        this->hide();
     729  }
     730  else
     731  {*/
     732    this->setAbsCoor( this->getAbsCoor() + Vector(100,0,0) + Vector(1,0,0) * VECTOR_RAND(150).dot(Vector(1,0,0)));
     733  //}
     734
    515735}
    516736
    517737void SpaceShip::respawn( )
    518738{
    519   toList( OM_PLAYERS );
    520 }
    521 
    522 
    523 
    524 
     739  Playable::respawn();
     740}
     741
     742
     743void SpaceShip::damage(float pDamage, float eDamage){
     744  PRINTF(5)("ship hit for (%f,%f) \n",pDamage,eDamage);
     745
     746  if( this->shieldActive) {
     747    if( this->shieldCur > pDamage) {
     748      this->shieldCur = this->shieldCur - pDamage;
     749    }
     750    else { // shield <= pDamage
     751      this->shieldCur -=pDamage;
     752      this->shieldActive = false; //shield collapses
     753      pDamage += this->shieldCur;
     754      if( !this->shieldActive) {
     755        this->armorCur -= pDamage / 2; // remaining damages hits armor at half rate
     756        this->electronicCur -= eDamage;
     757      }
     758    }
     759  }
     760  else {
     761    this->armorCur = this->armorCur - pDamage;
     762    this->electronicCur = this->electronicCur - eDamage;
     763  }
     764  if( this->armorCur <= 0) { /* FIXME implement shipcrash*/ }
     765    this->destroy(this);
     766
     767  updateElectronicWidget();
     768  updateShieldWidget();
     769
     770  this->setHealth( this->armorCur);
     771}
     772
     773
     774void SpaceShip::regen(float time){
     775  float tmp;
     776  if (this->armorCur != this->armorMax || this->armorRegen != 0){
     777    tmp = this->armorCur + this->armorRegen * time;
     778    if ( tmp > electronicMax)
     779      this->armorCur = this->armorMax;
     780    else
     781      this->armorCur = tmp;
     782  }
     783  if (this->shieldCur != this->shieldMax || this->shieldRegen != 0){
     784    tmp =  this->shieldCur + (this->shieldRegen + this->reactorOutput * this->shieldEnergyShare) * time;
     785    if( tmp > shieldMax)
     786      this->shieldCur = this->shieldMax;
     787    else
     788      this->shieldCur = tmp;
     789    this->shieldActive = ( this->shieldActive || this->shieldCur > shieldTH);
     790
     791    updateShieldWidget();
     792  }
     793
     794  this->setHealth( this->shieldCur);      // FIXME currently just to test share system
     795
     796  if (this->electronicCur != this->electronicMax || this->electronicRegen != 0){
     797    tmp = this->electronicCur + this->electronicRegen * time;
     798    if ( tmp > electronicMax)
     799      this->electronicCur = this->electronicMax;
     800    else
     801      this->electronicCur = tmp;
     802
     803    updateElectronicWidget();
     804  }
     805
     806}
     807
     808
     809/**
     810 * Weapon regeneration
     811 * does not use any reactor capacity, as it wouldn't work in a consistent way.
     812 */
     813void SpaceShip::weaponRegen(float time)
     814{
     815  float energy  = ( this->reactorOutput * this->weaponEnergyShare + this->weaponEnergyRegen) * time;
     816  Weapon* weapon;
     817  for( unsigned int i=0; i < this->weaponMan.getSlotCount(); i++)
     818  {
     819    weapon = this->weaponMan.getWeapon(i);
     820    if( weapon != NULL && weapon->isActive())
     821    {
     822      weapon->increaseEnergy( energy);
     823    }
     824
     825  }
     826  // weaponMan.increaseAmmunition( weapon, energy);
     827}
     828
     829
     830void SpaceShip::enterPlaymode(Playable::Playmode playmode)
     831{
     832  switch(playmode)
     833  {
     834    case Playable::Full3D:
     835      /*
     836      if (State::getCameraNode != NULL)
     837      {
     838        Vector absCoor = this->getAbsCoor();
     839        this->setParent(PNode::getNullParent());
     840        this->setAbsCoor(absCoor);
     841        State::getCameraNode()->setParentSoft(&this->cameraNode);
     842        State::getCameraNode()->setRelCoorSoft(-10, 0,0);
     843        State::getCameraTargetNode()->setParentSoft(&this->cameraNode);
     844        State::getCameraTargetNode()->setRelCoorSoft(100, 0,0);
     845
     846      }
     847      */
     848      //break;
     849
     850      break;
     851    case Playable::Horizontal:
     852      if (State::getCameraNode != NULL)
     853      {
     854        this->debugNode(1);
     855        this->travelNode->debugNode(1);
     856
     857        this->travelNode->setAbsCoor(this->getAbsCoor());
     858        this->travelNode->updateNode(0.01f);
     859
     860        this->isTravelDistanceInit = false;
     861
     862        if(this->entityTrack)
     863           this->travelNode->setParent(this->entityTrack->getTrackNode());
     864
     865        this->setParent(this->travelNode);
     866        this->setRelCoor(0,0,0);
     867
     868        State::getCameraNode()->setParentSoft(this->travelNode);
     869        //State::getCameraNode()->setParentSoft(this);
     870        //State::getCameraNode()->setRelCoorSoft(-0.01, 40, 0);
     871        State::getCameraTargetNode()->setParentSoft(this->travelNode);
     872        //State::getCameraTargetNode()->setParentSoft(this);
     873        //State::getCameraTargetNode()->setRelCoorSoft(0,0,0);
     874        this->setCameraMode(Camera::ViewTop);
     875        State::getCamera()->setEventHandling(false);
     876        registerEvent(KeyMapper::PEV_VIEW0);
     877        registerEvent(KeyMapper::PEV_VIEW1);
     878        registerEvent(KeyMapper::PEV_VIEW2);
     879        registerEvent(KeyMapper::PEV_VIEW3);
     880        registerEvent(KeyMapper::PEV_VIEW4);
     881        registerEvent(KeyMapper::PEV_VIEW5);
     882
     883        State::getCamera()->setParentMode(PNODE_ALL);
     884
     885        //this->updateTravelDistance();
     886
     887        this->debugNode(1);
     888        this->travelNode->debugNode(1);
     889      }
     890      break;
     891
     892    default:
     893      PRINTF(2)("Playmode %s Not Implemented in %s\n", Playable::playmodeToString(this->getPlaymode()).c_str(), this->getClassCName());
     894  }
     895}
     896
     897/**
     898 * @brief calculate the velocity
     899 * @param time the timeslice since the last frame
     900*/
     901
     902void SpaceShip::movement (float dt)
     903{
     904  //by releasing the buttons, the velocity decreases with airCoeff*Acceleration. Should be strong enough so
     905  //the ship doesn't slide too much.
     906  float airCoeff = 2.5;
     907  float pi = 3.14;
     908
     909  switch(this->getPlaymode())
     910  {
     911    case Playable::Horizontal:
     912    {
     913      // these routines will change the travel movement into zero in a short amout of time, if the player
     914      // doesn't press any buttons.
     915      if (this->travelVelocity.x >= 0)
     916      {
     917        if (this->travelVelocity.x > airCoeff*this->acceleration * dt)
     918          this->travelVelocity.x -= airCoeff* this->acceleration * dt;
     919        else
     920          this->travelVelocity.x = 0;
     921      }
     922      else
     923      {
     924        if (this->travelVelocity.x < -airCoeff*this->acceleration * dt)
     925          this->travelVelocity.x += airCoeff* this->acceleration * dt;
     926        else
     927          this->travelVelocity.x = 0;
     928      }
     929      if (this->travelVelocity.z >= 0)
     930      {
     931        if (this->travelVelocity.z > airCoeff*this->acceleration * dt)
     932          this->travelVelocity.z -= airCoeff* this->acceleration * dt;
     933        else
     934          this->travelVelocity.z = 0;
     935      }
     936      else
     937      {
     938        if (this->travelVelocity.z < -airCoeff*this->acceleration * dt)
     939          this->travelVelocity.z += airCoeff* this->acceleration * dt;
     940        else
     941          this->travelVelocity.z = 0;
     942      }
     943
     944      // this will evite, that the ship moves outside the travelDistance- borders,when the player releases all buttons
     945      // and its continuing to slide a bit.
     946      Vector oldCoor = this->getRelCoor();
     947      if (this->getRelCoor().x > this->travelDistancePlus.x) this->setRelCoor(this->travelDistancePlus.x, oldCoor.y, oldCoor.z);
     948      if (this->getRelCoor().x < this->travelDistanceMinus.x) this->setRelCoor(this->travelDistanceMinus.x, oldCoor.y, oldCoor.z);
     949      if (this->getRelCoor().z > this->travelDistancePlus.y) this->setRelCoor(oldCoor.x, oldCoor.y, this->travelDistancePlus.y);
     950      if (this->getRelCoor().z < this->travelDistanceMinus.y) this->setRelCoor(oldCoor.x, oldCoor.y, this->travelDistanceMinus.y);
     951
     952      if( this->systemFailure() )
     953        bForward = bBackward = bLeft = bRight = false;
     954
     955      if( this->bForward )
     956      {
     957        //printf("ShipCoorX: %f \n", this->getRelCoor().x);
     958        if(this->getRelCoor().x < this->travelDistancePlus.x)
     959        {
     960          if (this->travelVelocity.x < this->travelSpeed)
     961          {
     962            this->travelVelocity.x += (airCoeff + 1.0)*this->acceleration*dt;
     963          }
     964          else
     965          {
     966            this->travelVelocity.x = this->travelSpeed;
     967          }
     968        }
     969        else
     970        {
     971          this->travelVelocity.x = 0.0f;
     972        }
     973      }
     974
     975      if( this->bBackward )
     976      {
     977        if(this->getRelCoor().x > this->travelDistanceMinus.x)
     978        {
     979          if (this->travelVelocity.x > -this->travelSpeed)
     980          {
     981            this->travelVelocity.x -= (airCoeff + 1.0)*this->acceleration*dt;
     982          }
     983          else
     984          {
     985            this->travelVelocity.x = -this->travelSpeed;
     986          }
     987        }
     988        else
     989        {
     990          this->travelVelocity.x = 0.0f;
     991        }
     992      }
     993
     994      if( this->bLeft)
     995      {
     996        if(this->getRelCoor().z > this->travelDistanceMinus.y)
     997        {
     998          if (this->travelVelocity.z > -this->travelSpeed)
     999          {
     1000            this->travelVelocity.z -= (airCoeff + 1.0)*this->acceleration*dt;
     1001          }
     1002          else
     1003          {
     1004            this->travelVelocity.z = -this->travelSpeed;
     1005          }
     1006        }
     1007        else
     1008        {
     1009          this->travelVelocity.z = 0.0f;
     1010        }
     1011        this->setRelDirSoft(Quaternion(-pi/6, Vector(1,0,0)), 6);
     1012      }
     1013
     1014      if( this->bRight)
     1015      {
     1016        //printf("ShipCoorZ: %f \n", this->getRelCoor().z);
     1017        if(this->getRelCoor().z < this->travelDistancePlus.y)
     1018        {
     1019          if (this->travelVelocity.z < this->travelSpeed)
     1020          {
     1021            this->travelVelocity.z += (airCoeff + 1.0)*this->acceleration*dt;
     1022          }
     1023          else
     1024          {
     1025            this->travelVelocity.z = this->travelSpeed;
     1026          }
     1027        }
     1028        else
     1029        {
     1030          this->travelVelocity.z = 0.0f;
     1031        }
     1032        this->setRelDirSoft(Quaternion(pi/6, Vector(1,0,0)), 6);
     1033      }
     1034      if (!this->bRight && !this->bLeft)
     1035      {
     1036        this->setRelDirSoft(Quaternion(0, Vector(1,0,0)), 6);
     1037      }
     1038
     1039    //normalisation of the vectors (vector sum must be <= travelspeed)
     1040    float xzNorm = sqrt(pow(this->travelVelocity.x, 2) + pow(this->travelVelocity.z, 2));
     1041    if (xzNorm > this->travelSpeed)
     1042    {
     1043      this->travelVelocity.x = this->travelVelocity.x/xzNorm * this->travelSpeed;
     1044      this->travelVelocity.z = this->travelVelocity.z/xzNorm * this->travelSpeed;
     1045    }
     1046
     1047    //this moves camera and ship along the travel path.
     1048    if(!this->entityTrack)
     1049       this->travelNode->shiftCoor(Vector(this->cameraSpeed * dt, 0, 0));
     1050
     1051    break;
     1052    }
     1053    case Playable::Vertical:
     1054      break;
     1055    default:
     1056      PRINTF(4)("Playmode %s Not Implemented in %s\n", Playable::playmodeToString(this->getPlaymode()).c_str(), this->getClassCName());
     1057  }
     1058   //set new coordinates calculated through key- events.
     1059  this->shiftCoor (this->travelVelocity * dt);
     1060}
     1061
     1062void SpaceShip::setPlaymodeXML(const std::string& playmode)
     1063{
     1064  this->setPlaymode(Playable::stringToPlaymode(playmode));
     1065}
     1066
     1067/**
     1068 * @brief jumps to the next WeaponConfiguration
     1069 */
     1070void SpaceShip::nextWeaponConfig()
     1071{
     1072  PRINTF(0)("Requested next weapon config!\n");
     1073  this->weaponMan.nextWeaponConfig();
     1074  Playable::weaponConfigChanged();
     1075}
     1076
     1077/**
     1078 * @brief moves to the last WeaponConfiguration
     1079 */
     1080void SpaceShip::previousWeaponConfig()
     1081{
     1082  this->curWeaponPrimary    = (this->curWeaponPrimary + 1) % 3;
     1083  this->weaponMan.changeWeaponConfig(this->curWeaponPrimary);
     1084  Playable::weaponConfigChanged();
     1085}
     1086
     1087void SpaceShip::hit( float damage, WorldEntity* killer)
     1088{
     1089  this->damage(killer->getDamage(),0);
     1090}
     1091
     1092void SpaceShip::updateElectronicWidget()
     1093{
     1094  if (this->electronicWidget != NULL)
     1095  { //if it exists already: update it
     1096     this->electronicWidget->setMaximum(this->electronicMax);
     1097     this->electronicWidget->setValue(this->electronicCur);
     1098  }
     1099  else
     1100  { //create the widget
     1101    this->electronicWidget = new OrxGui::GLGuiEnergyWidgetVertical();
     1102    this->electronicWidget->getBarWidget()->setChangedValueColor(Color(1,0,0,1));
     1103    //this->electronicWidget->setDisplayedName("Electronics:");
     1104    //this->electronicWidget->setSize2D(100,20);
     1105    //this->electronicWidget->setAbsCoor2D(150,200);
     1106    this->updateElectronicWidget();
     1107    if (this->hasPlayer())
     1108      State::getPlayer()->hud().setEnergyWidget(this->electronicWidget);
     1109  }
     1110}
     1111
     1112void SpaceShip::updateShieldWidget()
     1113{
     1114  if (this->shieldWidget != NULL)
     1115  {
     1116    this->shieldWidget->setMaximum(this->shieldMax);
     1117    this->shieldWidget->setValue(this->shieldCur);;
     1118  }
     1119  else
     1120  {
     1121    this->shieldWidget = new OrxGui::GLGuiEnergyWidgetVertical();
     1122    this->shieldWidget->getBarWidget()->setChangedValueColor(Color(1,0,0,1));
     1123    //this->shieldWidget->setDisplayedName("Shield:");
     1124    //his->shieldWidget->setSize2D(100,20);
     1125    //this->shieldWidget->setAbsCoor2D(200,200);
     1126    this->updateShieldWidget();
     1127    if (this->hasPlayer())
     1128      State::getPlayer()->hud().setShiledWidget(this->shieldWidget);
     1129  }
     1130}
     1131
     1132void SpaceShip::setCameraDistance(float dist)
     1133{
     1134  State::getCamera()->setViewTopDistance(dist);
     1135}
     1136
     1137void SpaceShip::setCameraFovy(float fovy)
     1138{
     1139  State::getCamera()->setViewTopFovy(fovy);
     1140}
     1141
     1142void SpaceShip::updateTravelDistance()
     1143{
     1144  float x = 1.25 * this->actionWidthPercentage * fabsf(State::getCamera()->getAbsCoor().y) * tan(State::getCamera()->getFovy()*M_PI /360.0);
     1145  float y = x / State::getCamera()->getAspectRatio() / this->actionWidthPercentage;
     1146  //State::getCamera()->setAbsCoor(-5, 1000, 0);
     1147
     1148
     1149  //State::getCamera()->getAbsCoor().print();
     1150  //printf("CameraRelCoorY: %f \n", State::getCamera()->getRelCoor().y);
     1151
     1152  //printf("x: %f, y: %f \n", x, y);
     1153  this->travelDistancePlus = Vector2D(y, x);
     1154  this->travelDistanceMinus = Vector2D(-y, -x);
     1155
     1156  State::getPlayer()->hud().setOverlayPercentage(100-int(100*this->actionWidthPercentage));
     1157  PRINTF(0)("TravelDistance has been updated\n");
     1158  this->isTravelDistanceInit = true;
     1159}
     1160
     1161void SpaceShip::setActionWidthPercentage(int i)
     1162{
     1163  if (i>100) i=100;
     1164  if (i<0) i=0;
     1165  this->actionWidthPercentage = i/100.0;
     1166
     1167  if (this->hasPlayer())
     1168    this->isTravelDistanceInit = false;
     1169};
  • trunk/src/world_entities/space_ships/space_ship.h

    r9869 r10368  
    22 * @file space_ship.h
    33 * Implements the Control of a Spaceship
     4 * Space Ships are the core class for all types of ships in Orxonox
     5 * By default is on OM_GROUP_00
     6 * If player boards the ship, it is moved to OM_GROUP_01
    47 */
    58
     
    1619class ParticleEmitter;
    1720class ParticleSystem;
     21class Trail;
     22class Wobblegrid;
    1823
    1924class SpaceShip : public Playable
     
    2934
    3035    virtual void setPlayDirection(const Quaternion& rot, float speed = 0.0f);
     36    /*
     37    void setTravelHeight(float travelHeight);
     38    void setTravelDistance(const Vector2D& distance);
     39    void setTravelDistance(float x, float y);
     40    */
     41
     42    //void setAirFriction(float friction) { this->airFriction = friction; };
    3143
    3244    virtual void enter();
     
    4153    virtual void respawn();
    4254
    43     virtual void collidesWith(WorldEntity* entity, const Vector& location);
     55    inline Vector getVelocity() { return this->velocity; };
     56
    4457    virtual void tick(float time);
    4558    virtual void draw() const;
    4659
    4760    virtual void process(const Event &event);
     61//    virtual void hit (WorldEntity* entity, float damage);
     62
     63    inline WeaponManager& getWeaponManagerSecondary() { return this->secWeaponMan; };
     64
     65    //Functions for GUI
     66    inline float getShieldCur() { return this->shieldCur; };        //!< returns current shield value
     67    inline float getShieldMax() { return this->shieldMax; };        //!< returns maximum shield value
     68
     69    inline float getArmorCur() { return this->armorCur; };          //!< returns current armor value
     70    inline float getArmorMax() { return this->armorMax; };          //!< returns current armor value
     71
     72    inline float getElectronicCur() { return this->electronicCur; }; //!< returns current electronic value
     73    inline float getElectronicMax() { return this->electronicMax; }; //!< returns current electronic value
     74
     75    inline PNode* getTravelNode() { return this->travelNode; };
     76
     77    //damage handler
     78    virtual void damage(float pDamage, float eDamage);  //!< pDamage physical damage, eDamage electronic damage
     79
     80    //included by Michel:
     81    virtual void enterPlaymode(Playable::Playmode playmode);
     82    void setPlaymodeXML(const std::string& playmode); //recieves the playmode from a string (useful for script implementation)
     83    void setActionWidthPercentage(int i);
     84    void updateTravelDistance();
     85    virtual void movement (float dt);
     86
     87    //
     88
     89    void nextWeaponConfig();
     90    void previousWeaponConfig();
     91
     92    virtual void hit(float damage, WorldEntity* killer);
    4893
    4994  private:
    5095    void init();
    5196
    52     void calculateVelocity(float time);
    53 
    54     bool                  bUp;                //!< up button pressed.
    55     bool                  bDown;              //!< down button pressed.
     97    //void calculateVelocity(float time);
     98
     99    void regen(float time);  //!< handler for shield and electronic regeneration
     100
     101    void weaponRegen(float time);   //!< weapon energy regeneration
     102
     103    inline bool systemFailure() {  return (this->electronicCur < float(rand())/float(RAND_MAX) * this->electronicTH); };
     104
     105    void updateElectronicWidget();
     106    void updateShieldWidget();
     107
     108    //WeaponManager         weaponMan;      //!< the primary weapon manager: managing a list of energy weapons to wepaon-slot mapping
     109    WeaponManager         secWeaponMan;       //!< the secondary weapon manager: managing a list of special weapons to weapon-slot mapping
     110    short                 supportedPlaymodes; //!< What Playmodes are Supported in this Playable.
     111    Playable::Playmode    playmode;           //!< The current playmode.
     112
     113    //ship atributes
     114    float       shieldCur;          //!< current shield
     115    float       shieldMax;          //!< maximum shield
     116    float       shieldEnergyShare;  //!< percentage of reactor output
     117    float       shieldRegen;        //!< shield regeneration rate per second
     118    float       shieldTH;           //!< shield threshhold for reactivation
     119    bool        shieldActive;       //!< wheather the shield is working
     120    OrxGui::GLGuiEnergyWidgetVertical* shieldWidget; //!< holds the widget that shows the shield bar
     121
     122    float       armorCur;           //!< current armor
     123    float       armorMax;           //!< maximum armor
     124    float       armorRegen;         //!< armor regeneration per tick (usable on bioships?)
     125    //note that the armor widget is set on the health- widget in world- entity (see in player.cc)
     126
     127    float       electronicCur;      //!< current electronic
     128    float       electronicMax;      //!< maximum electronic
     129    float       electronicRegen;    //!< electronic regenration rate per tick
     130    float       electronicTH;       //!< Threshhold for electronic failure
     131    OrxGui::GLGuiEnergyWidgetVertical* electronicWidget; //!< holds the widget that shows the electronic bar
     132
     133    float       engineSpeedCur;     //!< speed output for movement = speed base + energy share part
     134    float       engineSpeedBase;    //!< speed base
     135    int         enginePowerConsume; //!< energy needed
     136    float       engineEnergyShare;  //!< percentage of reactor output
     137
     138    int         weaponEnergySlot;   //!< number of energy weapon slots
     139    int         weaponEnergyUsed;
     140    float       weaponEnergyShare;
     141    float       weaponEnergyRegen;
     142    int         weaponSpecialSlot;  //!< number of special weapon slots
     143    int         weaponSpecialUsed;
     144
     145    float       reactorOutput;      //!< reactor output
     146    float       reactorCapacity;    //!< reactor capacity
     147
     148    int         curWeaponPrimary;   //!< current primary weapon config
     149    int         curWeaponSecondary; //!< current secondary weapon config
     150
     151    bool                  bForward;                //!< up button pressed.
     152    bool                  bBackward;              //!< down button pressed.
    56153    bool                  bLeft;              //!< left button pressed.
    57154    bool                  bRight;             //!< right button pressed.
    58155    bool                  bAscend;            //!< ascend button pressed.
    59156    bool                  bDescend;           //!< descend button presses.
    60 //    bool                  bFire;              //!< fire button pressed.(moved to playable)
    61157    bool                  bRollL;             //!< rolling button pressed (left)
    62158    bool                  bRollR;             //!< rolling button pressed (right)
    63 
     159    bool                  bSecFire;           //!< second fire button pressed
     160
     161    /*
    64162    float                 xMouse;             //!< mouse moved in x-Direction
    65163    float                 yMouse;             //!< mouse moved in y-Direction
     
    68166    int                   controlVelocityX;
    69167    int                   controlVelocityY;
    70 //    float                 cycle;              //!< hovercycle
     168    */
    71169
    72170    Vector                velocity;           //!< the velocity of the player.
    73     Vector                oldVelocity;        //!< the velocity the player had last synced
     171    Vector                oldPos;
     172
     173// 2D-traveling
     174    PNode*                travelNode;
     175    float                 travelSpeed;        //!< the current speed of the Ship (to make soft movement)
     176    Vector                travelVelocity;     //!< object internal velocity vector for relative movement to the track node
     177    Vector2D              travelDistancePlus;     //!< Travel-Distance away from the TravelNode
     178    Vector2D              travelDistanceMinus;
     179    bool                  isTravelDistanceInit;
     180
     181    float                 actionWidthPercentage;
     182
     183// Camera
     184    PNode                 cameraNode;
     185    float                 cameraLook;
     186    float                 rotation;
     187    float                 cameraSpeed;
     188
     189    void                  setCameraDistance(float dist);
     190    void                  setCameraFovy(float fovy);
     191
     192    /*
    74193    Quaternion            mouseDir;           //!< the direction where the player wants to fly
    75194    Quaternion            oldMouseDir;        //!< the direction where the player wanted to fly
     
    77196    Quaternion            rotQuat;
    78197    Quaternion            pitchDir;
    79     float                 travelSpeed;        //!< the current speed of the player (to make soft movement)
    80     float                 acceleration;       //!< the acceleration of the player.
    81 
    82     float                 airViscosity;
     198    float                 dogdeSpeed;        //!< the dogde Speed of the ship.
     199    */
     200
     201    //Quaternion            direction;          //!< the direction of the ship.
     202    float                 acceleration;       //!< the acceleration of the ship.
     203    //float                 airFriction;        //!< AirFriction.
     204    //float                 airViscosity;
    83205
    84206    byte                  oldMask;            //!< used for synchronisation
    85207
    86     ParticleEmitter*      burstEmitter;
    87     ParticleSystem*       burstSystem;
     208    Trail*                trail;              //!< Burst trail
     209    Trail*                trailL;              //!< Burst trail
     210    Trail*                trailR;              //!< Burst trail
     211
     212
    88213};
    89214
  • trunk/src/world_entities/space_ships/spacecraft_2d.cc

    r10317 r10368  
    273273{
    274274  dynamic_cast<Element2D*>(this->getWeaponManager().getFixedTarget())->setVisibility( true);
    275   this->setPlaymode(this->getPlaymode());
     275//   this->setPlaymode(this->getPlaymode());
     276  this->setPlaymode(Playable::Horizontal);
     277  this->setTravelSpeed(10.0f);
    276278}
    277279
  • trunk/src/world_entities/space_ships/spacecraft_2d.h

    r9869 r10368  
    6666    float                 acceleration;       //!< the acceleration of the Spacecraft2D.
    6767    float                 airFriction;        //!< AirFriction.
    68 
    6968    float                 airViscosity;
    7069
Note: See TracChangeset for help on using the changeset viewer.