Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/world_entities/space_ships/space_ship.cc @ 6806

Last change on this file since 6806 was 6804, checked in by bensch, 18 years ago

trunk: remastered Playables a bit

File size: 18.5 KB
RevLine 
[5907]1/*
2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2004 orx
5
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 2, or (at your option)
9   any later version.
10
11### File Specific:
12   main-programmer: Benjamin Knecht
[6034]13   co-programmer: Silvan Nellen
[5907]14
15*/
16
17#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD_ENTITY
18
19#include "executor/executor.h"
20#include "space_ship.h"
21
[6034]22#include "objModel.h"
[5907]23#include "resource_manager.h"
24
25#include "weapons/weapon_manager.h"
26#include "weapons/test_gun.h"
27#include "weapons/turret.h"
28#include "weapons/cannon.h"
29
[6756]30#include "particle_emitter.h"
31#include "sprite_particles.h"
32
[5907]33#include "factory.h"
34#include "key_mapper.h"
[5978]35#include "event_handler.h"
[5907]36
[6424]37#include "network_game_manager.h"
38
[6243]39#include "power_ups/weapon_power_up.h"
40#include "power_ups/param_power_up.h"
41
[5978]42#include "graphics_engine.h"
43
[6617]44#include "plane.h"
[6287]45
[6634]46#include "state.h"
47#include "player.h"
[6287]48
[6634]49
[6306]50// #include "lib/gui/gl_gui/glgui_bar.h"
51// #include "lib/gui/gl_gui/glgui_pushbutton.h"
[6287]52
53
[5907]54using namespace std;
55
56CREATE_FACTORY(SpaceShip, CL_SPACE_SHIP);
57
58/**
59 *  creates the controlable Spaceship
60 */
61SpaceShip::SpaceShip()
62{
63  this->init();
64}
65
66/**
67 *  destructs the spaceship, deletes alocated memory
68 */
69SpaceShip::~SpaceShip ()
70{
71}
72
73/**
74 * loads a Spaceships information from a specified file.
75 * @param fileName the name of the File to load the spaceship from (absolute path)
76 */
77SpaceShip::SpaceShip(const char* fileName)
78{
79  this->init();
80  TiXmlDocument doc(fileName);
81
82  if(!doc.LoadFile())
83  {
84    PRINTF(2)("Loading file %s failed for spaceship.\n", fileName);
85    return;
86  }
87
88  this->loadParams(doc.RootElement());
89}
90
91/**
92 *  creates a new Spaceship from Xml Data
93 * @param root the xml element containing spaceship data
94
95   @todo add more parameters to load
96*/
97SpaceShip::SpaceShip(const TiXmlElement* root)
98{
99  this->init();
100  if (root != NULL)
101    this->loadParams(root);
[6695]102  else
103  {
104    this->loadModel("models/ships/reap_#.obj");
105  }
[5907]106
[6695]107}
108
109
110/**
111 * initializes a Spaceship
112 */
113void SpaceShip::init()
114{
115//  this->setRelDir(Quaternion(M_PI, Vector(1,0,0)));
116  this->setClassID(CL_SPACE_SHIP, "SpaceShip");
117
118  PRINTF(4)("SPACESHIP INIT\n");
119
[5907]120  //weapons:
121  Weapon* wpRight = new TestGun(0);
122  wpRight->setName("testGun Right");
123  Weapon* wpLeft = new TestGun(1);
124  wpLeft->setName("testGun Left");
[5982]125  Weapon* cannon = dynamic_cast<Weapon*>(Factory::fabricate(CL_CANNON));
[5907]126
127  cannon->setName("BFG");
128
[6443]129  this->addWeapon(wpLeft, 1, 0);
130  this->addWeapon(wpRight,1 ,1);
131  this->addWeapon(cannon, 0, 6);
[5907]132
133  this->getWeaponManager()->changeWeaponConfig(1);
134
[5978]135  bUp = bDown = bLeft = bRight = bAscend = bDescend = bRollL = bRollR = false;
[5907]136  bFire = false;
[5978]137  xMouse = yMouse = 0;
[6637]138  yInvert = 1;
[5978]139  mouseSensitivity = 0.001;
[6692]140  airViscosity = 0.05;
[6637]141  controlVelocityX = 25;
142  controlVelocityY = 150;
[6803]143  shipInertia = 1.5;
[6637]144//  cycle = 0.0;
[5907]145
[6700]146  this->setHealthMax(100);
147  this->setHealth(80);
[5982]148
[6637]149  travelSpeed = 40.0;
150  acceleration = 3;
151  this->velocity = this->getAbsDirX()*travelSpeed;
[6162]152  this->mouseDir = this->getAbsDir();
[6637]153  this->pitchDir = this->getAbsDir();
[5907]154
[6306]155//   GLGuiButton* button = new GLGuiPushButton();
156//    button->show();
157//    button->setLabel("orxonox");
158//    button->setBindNode(this);
159//     GLGuiBar* bar = new GLGuiBar();
160//     bar->show();
161//     bar->setValue(7.0);
162//     bar->setMaximum(10);
163//     bar->setSize2D( 20, 100);
164//     bar->setAbsCoor2D( 10, 200);
[6300]165
[5907]166  //add events to the eventlist
[6637]167  registerEvent(KeyMapper::PEV_UP);
168  registerEvent(KeyMapper::PEV_DOWN);
169  registerEvent(KeyMapper::PEV_LEFT);
170  registerEvent(KeyMapper::PEV_RIGHT);
171  //registerEvent(SDLK_q);
172  //registerEvent(SDLK_e);
[5907]173  registerEvent(KeyMapper::PEV_FIRE1);
174  registerEvent(KeyMapper::PEV_NEXT_WEAPON);
175  registerEvent(KeyMapper::PEV_PREVIOUS_WEAPON);
[6637]176  //registerEvent(SDLK_PAGEUP);
177  //registerEvent(SDLK_PAGEDOWN);
[5978]178  registerEvent(EV_MOUSE_MOTION);
[5907]179
180  this->getWeaponManager()->setSlotCount(7);
181
182  this->getWeaponManager()->setSlotPosition(0, Vector(-2.6, .1, -3.0));
183  this->getWeaponManager()->setSlotCapability(0, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL);
184
185  this->getWeaponManager()->setSlotPosition(1, Vector(-2.6, .1, 3.0));
186  this->getWeaponManager()->setSlotCapability(1, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL);
187
188  this->getWeaponManager()->setSlotPosition(2, Vector(-1.5, .5, -.5));
189  this->getWeaponManager()->setSlotDirection(2, Quaternion(-M_PI_4*.5, Vector(1,0,0)));
190
191  this->getWeaponManager()->setSlotPosition(3, Vector(-1.5, .5, .5));
192  this->getWeaponManager()->setSlotDirection(3, Quaternion(M_PI_4*.5, Vector(1,0,0)));
193
194  this->getWeaponManager()->setSlotPosition(4, Vector(-1.5, -.5, .5));
195  this->getWeaponManager()->setSlotDirection(4, Quaternion(-M_PI_4*.5+M_PI, Vector(1,0,0)));
196
197  this->getWeaponManager()->setSlotPosition(5, Vector(-1.5, -.5, -.5));
198  this->getWeaponManager()->setSlotDirection(5, Quaternion(+M_PI_4*.5-M_PI, Vector(1,0,0)));
199//
200   this->getWeaponManager()->setSlotPosition(6, Vector(-1, 0.0, 0));
201   this->getWeaponManager()->setSlotCapability(6, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL);
202   //
203//   this->getWeaponManager()->setSlotPosition(8, Vector(-2.5, -0.3, -2.0));
204//   this->getWeaponManager()->setSlotDirection(8, Quaternion(-M_PI, Vector(1,0,0)));
205//
206//   this->getWeaponManager()->setSlotPosition(9, Vector(-2.5, -0.3, 2.0));
207//   this->getWeaponManager()->setSlotDirection(9, Quaternion(+M_PI, Vector(1,0,0)));:
208
[6162]209  this->getWeaponManager()->getFixedTarget()->setParent(this);
210  this->getWeaponManager()->getFixedTarget()->setRelCoor(100000,0,0);
211
[6222]212  dynamic_cast<Element2D*>(this->getWeaponManager()->getFixedTarget())->setVisibility( false);
[6756]213
[6764]214  this->burstEmitter = new ParticleEmitter(Vector(1,0,0), .01, 200, 0.0);
[6756]215  this->burstEmitter->setParent(this);
[6764]216  this->burstEmitter->setRelCoor(-1, .5, 0);
[6756]217  this->burstEmitter->setName("SpaceShip_Burst_emitter");
218
219  this->burstSystem = new SpriteParticles(1000);
220  this->burstSystem->addEmitter(this->burstEmitter);
221  this->burstSystem->setName("SpaceShip_Burst_System");
222  ((SpriteParticles*)this->burstSystem)->setMaterialTexture("maps/radial-trans-noise.png");
223  this->burstSystem->setLifeSpan(1.0, .3);
[6757]224  this->burstSystem->setRadius(0.0, 1.0);
225  this->burstSystem->setRadius(0.05, 1.0);
[6756]226  this->burstSystem->setRadius(.5, .8);
[6757]227  this->burstSystem->setRadius(1.0, 0);
228  this->burstSystem->setColor(0.0, .7,.7,1,.7);
229  this->burstSystem->setColor(0.2, 0,0,0.8,.5);
230  this->burstSystem->setColor(0.5, .5,.5,.8,.8);
[6756]231  this->burstSystem->setColor(1.0, .8,.8,.8,.0);
232
[5907]233}
234
[6695]235
[5907]236/**
237 * loads the Settings of a SpaceShip from an XML-element.
238 * @param root the XML-element to load the Spaceship's properties from
239 */
240void SpaceShip::loadParams(const TiXmlElement* root)
241{
[6756]242  Playable::loadParams(root);
[5907]243}
244
245
[6222]246void SpaceShip::enter()
247{
248  dynamic_cast<Element2D*>(this->getWeaponManager()->getFixedTarget())->setVisibility( true);
[6241]249  this->attachCamera();
[6222]250}
251
252void SpaceShip::leave()
253{
254  dynamic_cast<Element2D*>(this->getWeaponManager()->getFixedTarget())->setVisibility( false);
[6241]255  this->detachCamera();
[6222]256}
257
[5907]258
259/**
260 *  effect that occurs after the SpaceShip is spawned
261*/
262void SpaceShip::postSpawn ()
263{
264  //setCollision(new CollisionCluster(1.0, Vector(0,0,0)));
265}
266
267/**
268 *  the action occuring if the spaceship left the game
269*/
270void SpaceShip::leftWorld ()
271{}
272
273WorldEntity* ref = NULL;
274/**
275 *  this function is called, when two entities collide
276 * @param entity: the world entity with whom it collides
277 *
278 * Implement behaviour like damage application or other miscellaneous collision stuff in this function
279 */
280void SpaceShip::collidesWith(WorldEntity* entity, const Vector& location)
281{
[6436]282  Playable::collidesWith(entity, location);
[5907]283  if (entity->isA(CL_TURRET_POWER_UP) && entity != ref)
284  {
285    this->ADDWEAPON();
286    ref = entity;
287    }
288//  PRINTF(3)("collision %s vs %s @ (%f,%f,%f)\n", this->getClassName(), entity->getClassName(), location.x, location.y, location.z);
289}
290
291/**
292 *  draws the spaceship after transforming it.
293*/
294void SpaceShip::draw () const
295{
[6281]296  WorldEntity::draw();
[5907]297  this->getWeaponManager()->draw();
298
299  //this->debug(0);
300}
301
302/**
303 *  the function called for each passing timeSnap
304 * @param time The timespan passed since last update
305*/
306void SpaceShip::tick (float time)
307{
[6804]308  Playable::tick(time);
[6679]309
[6753]310  if( ( xMouse != 0 || yMouse != 0 ) && this->getOwner() == this->getHostID() )
[6637]311   {
312    if (xMouse > controlVelocityX) xMouse = controlVelocityX;
313    else if (xMouse < -controlVelocityX) xMouse = -controlVelocityX;
314    if (yMouse > controlVelocityY) yMouse = controlVelocityY;
315    else if (yMouse < -controlVelocityY) yMouse = -controlVelocityY;
[6679]316
[6637]317    pitchDir = (Quaternion(xMouse*mouseSensitivity*0.5, Vector(1,0,0)));
[6679]318
[6637]319    mouseDir *= (Quaternion(-M_PI/4*xMouse*mouseSensitivity, Vector(0,1,0))*Quaternion(-M_PI/4*yMouse*mouseSensitivity*yInvert, Vector(0,0,1))*pitchDir);
320    xMouse = yMouse = 0;
321   }
[6034]322
[6679]323
[6634]324//   if( this != State::getPlayer()->getControllable())
325//     return;
326
[5907]327  // spaceship controlled movement
328  this->calculateVelocity(time);
329
[6637]330  Vector move = velocity*time;
[6679]331
[6034]332  //orient the velocity in the direction of the spaceship.
333  travelSpeed = velocity.len();
334  velocity += ((this->getAbsDirX())*travelSpeed-velocity)*airViscosity;
335  velocity = (velocity.getNormalized())*travelSpeed;
[6756]336  this->burstEmitter->setEmissionRate(travelSpeed);
[6764]337  this->burstEmitter->setEmissionVelocity(travelSpeed*.5, travelSpeed *.1);
[6222]338
[6162]339  //orient the spaceship in direction of the mouse
[6760]340   rotQuat = Quaternion::quatSlerp( this->getAbsDir(), mouseDir, 0.5);//fabsf(time)*shipInertia);
[6241]341   if (this->getAbsDir().distance(rotQuat) > 0.00000000000001)
[6162]342    this->setAbsDir( rotQuat);
343   //this->setAbsDirSoft(mouseDir,5);
[6222]344
[5978]345  // this is the air friction (necessary for a smooth control)
[6637]346  if(travelSpeed >= 120) velocity -= velocity.getNormalized()*travelSpeed*travelSpeed*0.0001;
347  else if (travelSpeed <= 80) velocity -= velocity.getNormalized()*travelSpeed*0.001;
[6679]348
[6637]349  //other physics (gravity)
[6692]350  //if(travelSpeed < 120)
351  //move += Vector(0,-1,0)*60*time + Vector(0,1,0)*travelSpeed/2*time;
[6679]352
[6034]353  //hoover effect
[6634]354  //cycle += time;
355  //this->shiftCoor(Vector(0,1,0)*cos(this->cycle*2.0)*0.02);
[5982]356
[6034]357  //readjust
[6426]358  //if (this->getAbsDirZ().y > 0.1) this->shiftDir(Quaternion(time*0.3, Vector(1,0,0)));
[6034]359  //else if (this->getAbsDirZ().y < -0.1) this->shiftDir(Quaternion(-time*0.3, Vector(1,0,0)));
360
[5978]361  //SDL_WarpMouse(GraphicsEngine::getInstance()->getResolutionX()/2, GraphicsEngine::getInstance()->getResolutionY()/2);
[5907]362
[6637]363  this->shiftCoor(move);
[5907]364
[6634]365
[5907]366}
367
368/**
369 *  calculate the velocity
370 * @param time the timeslice since the last frame
371*/
372void SpaceShip::calculateVelocity (float time)
373{
374  Vector accel(0.0, 0.0, 0.0);
[6162]375  /*
376  Vector rot(0.0, 0.0, 0.0); // wird benötigt für Helicopter
377  */
[5907]378  //float rotVal = 0.0;
[5912]379  /* FIXME: calculating the direction and orthDirection every timeSlice is redundant! save it somewhere */
[5907]380  /* calculate the direction in which the craft is heading  */
381
[6637]382  //Plane plane(Vector(0,1,0), Vector(0,0,0));
[6222]383
[5907]384  if( this->bUp )
385   {
[5978]386     //this->shiftCoor(this->getAbsDirX());
[6637]387      //accel += (this->getAbsDirX())*2;
388      accel += (this->getAbsDirX())*acceleration;
[6222]389
[5907]390   }
391
392  if( this->bDown )
[5908]393   {
[5978]394     //this->shiftCoor((this->getAbsDirX())*-1);
[6637]395     //accel -= (this->getAbsDirX())*2;
[6724]396    //if(velocity.len() > 50)
[6637]397     accel -= (this->getAbsDirX())*0.5*acceleration;
[6724]398
399
400
[5907]401   }
402
[6034]403  if( this->bLeft/* > -this->getRelCoor().z*2*/)
[5907]404  {
[5912]405    this->shiftDir(Quaternion(time, Vector(0,1,0)));
406//    accel -= rightDirection;
[5908]407    //velocityDir.normalize();
[5907]408    //rot +=Vector(1,0,0);
409    //rotVal -= .4;
410  }
411  if( this->bRight /* > this->getRelCoor().z*2*/)
412  {
[5912]413    this->shiftDir(Quaternion(-time, Vector(0,1,0)));
414
415    //    accel += rightDirection;
[5908]416    //velocityDir.normalize();
[5907]417    //rot += Vector(1,0,0);
418    //rotVal += .4;
419  }
[5982]420
[6034]421
[5978]422  if( this->bRollL /* > -this->getRelCoor().z*2*/)
423  {
[6637]424    mouseDir *= Quaternion(-time*2, Vector(1,0,0));
[5978]425//    accel -= rightDirection;
426    //velocityDir.normalize();
427    //rot +=Vector(1,0,0);
428    //rotVal -= .4;
429  }
430  if( this->bRollR /* > this->getRelCoor().z*2*/)
431  {
[6637]432    mouseDir *= Quaternion(time*2, Vector(1,0,0));
[5978]433
434    //    accel += rightDirection;
435    //velocityDir.normalize();
436    //rot += Vector(1,0,0);
437    //rotVal += .4;
438  }
[5907]439  if (this->bAscend )
440  {
[5912]441    this->shiftDir(Quaternion(time, Vector(0,0,1)));
442
443//    accel += upDirection;
[5908]444    //velocityDir.normalize();
[5907]445    //rot += Vector(0,0,1);
446    //rotVal += .4;
447  }
448  if (this->bDescend )
449  {
[5912]450    this->shiftDir(Quaternion(-time, Vector(0,0,1)));
451
452    //    accel -= upDirection;
[5908]453    //velocityDir.normalize();
[5907]454    //rot += Vector(0,0,1);
455    //rotVal -= .4;
456  }
457
[5978]458  velocity += accel;
[5907]459  //rot.normalize();
460  //this->setRelDirSoft(Quaternion(rotVal, rot), 5);
461}
462
463/**
464 * @todo switch statement ??
465 */
466void SpaceShip::process(const Event &event)
467{
[6804]468  Playable::process(event);
469
[6637]470  if( event.type == KeyMapper::PEV_LEFT)
[5978]471      this->bRollL = event.bPressed;
[6637]472  else if( event.type == KeyMapper::PEV_RIGHT)
[5978]473      this->bRollR = event.bPressed;
[6637]474  else if( event.type == KeyMapper::PEV_UP)
[5978]475    this->bUp = event.bPressed; //this->shiftCoor(0,.1,0);
[6637]476  else if( event.type == KeyMapper::PEV_DOWN)
[5978]477    this->bDown = event.bPressed; //this->shiftCoor(0,-.1,0);
478  else if( event.type == EV_MOUSE_MOTION)
479  {
[6637]480    this->xMouse += event.xRel;
481    this->yMouse += event.yRel;
[5978]482  }
[5907]483}
484
485#include "weapons/aiming_turret.h"
486// FIXME THIS MIGHT BE CONSIDERED EITHER A FEATURE, OR A BUG
487void SpaceShip::ADDWEAPON()
488{
489  Weapon* turret = NULL;
490
[6306]491  if ((float)rand()/RAND_MAX < .9)
[5907]492  {
493    //if (this->getWeaponManager()->hasFreeSlot(2, WTYPE_TURRET))
494    {
495      turret = new Turret();
[6443]496      this->addWeapon(turret, 2);
[5907]497      this->getWeaponManager()->changeWeaponConfig(2);
498    }
499  }
500  else
501  {
502    //if (this->getWeaponManager()->hasFreeSlot(3))
503    {
[6426]504      turret = dynamic_cast<Weapon*>(Factory::fabricate(CL_TARGETING_TURRET));
505      if (turret != NULL)
[6443]506      this->addWeapon(turret, 3);
[5907]507
508      this->getWeaponManager()->changeWeaponConfig(3);
509    }
510  }
511
512  if(turret != NULL)
513  {
514    turret->setName("Turret");
515    turret->setStateDuration(WS_SHOOTING, (float)rand()/RAND_MAX*.5+.1);
516  }
517}
[6424]518
[6498]519#define MASK_bUp         1
520#define MASK_bDown       2
521#define MASK_bLeft       4
522#define MASK_bRight      8
523#define MASK_bAscend    16
524#define MASK_bDescend   32
525#define MASK_bFire      64
526#define MASK_bRollL    128
527#define MASK_bRollR    256
[6424]528
[6498]529#define DATA_state       1
530#define DATA_flags       2
531#define DATA_mouse       3
532
[6424]533int SpaceShip::writeBytes( const byte * data, int length, int sender )
534{
535  SYNCHELP_READ_BEGIN();
536
[6498]537  byte b;
[6424]538
[6737]539  do
[6498]540  {
[6737]541    SYNCHELP_READ_BYTE( b );
[6634]542
[6737]543    if ( b == DATA_state /*&& (this->getHostID()!=this->getOwner() || sender==0)*/ )
544    {
545     PRINTF(0)("GOT STATE %d\n", this->getUniqueID());
546     setRequestedSync( false );
547     setIsOutOfSync( false );
548     SYNCHELP_READ_FKT( WorldEntity::writeState );
549     //SYNCHELP_READ_FLOAT( cycle );
[6498]550
[6737]551      return SYNCHELP_READ_N;
552    }
[6634]553
[6498]554
[6737]555    //TODO: do not recieve data if you are the owner
556    if ( b == DATA_flags /*&& this->getHostID()!=this->getOwner()*/ )
557    {
558      int flags = 0;
559      SYNCHELP_READ_INT( flags );
[6634]560
[6753]561      bUp = (flags & MASK_bUp) != 0;
562      bDown = (flags & MASK_bDown) != 0;
563      bLeft = (flags & MASK_bLeft) != 0;
564      bRight = (flags & MASK_bRight) != 0;
565      bAscend = (flags & MASK_bAscend) != 0;
566      bDescend = (flags & MASK_bDescend) != 0;
567      bFire = (flags & MASK_bFire) != 0;
568      bRollL = (flags & MASK_bRollL) != 0;
569      bRollR = (flags & MASK_bRollR) != 0;
[6498]570
[6737]571    }
572
573    //TODO: do not recieve data if you are the owner
574    if ( b == DATA_mouse /*&& this->getHostID()!=this->getOwner()*/ )
575    {
[6753]576      SYNCHELP_READ_FLOAT( mouseDir.w );
577      SYNCHELP_READ_FLOAT( mouseDir.v.x );
578      SYNCHELP_READ_FLOAT( mouseDir.v.y );
579      SYNCHELP_READ_FLOAT( mouseDir.v.z );
[6737]580    }
581  } while( b != 0 );
582
[6634]583  /*if ( b == DATA_mouse && this->getHostID()!=this->getOwner() )
[6498]584  {
585    SYNCHELP_READ_FLOAT( xMouse );
586    SYNCHELP_READ_FLOAT( yMouse );
587    SYNCHELP_READ_FLOAT( mouseSensitivity );
588    SYNCHELP_READ_FLOAT( cycle );
[6634]589}*/
[6498]590
[6634]591  if ( this->getOwner() != this->getHostID() )
592    SYNCHELP_READ_FKT( PNode::writeSync );
593
[6424]594  return SYNCHELP_READ_N;
595}
596
[6498]597
598
[6424]599int SpaceShip::readBytes( byte * data, int maxLength, int * reciever )
600{
[6498]601  SYNCHELP_WRITE_BEGIN();
602
[6634]603  if ( isOutOfSync() && !requestedSync() /*&& this->getHostID()!=this->getOwner()*/ )
[6424]604  {
605    (NetworkGameManager::getInstance())->sync( this->getUniqueID(), this->getOwner() );
606    setRequestedSync( true );
[6634]607    PRINTF(0)("REQUESTED STATE %d\n", this->getUniqueID());
[6424]608  }
609
610  int rec = this->getRequestSync();
611  if ( rec > 0 )
612  {
613    *reciever = rec;
614
[6634]615    PRINTF(0)("SEND STATE %d %d\n", this->getUniqueID(), rec);
616
[6498]617    SYNCHELP_WRITE_BYTE( (byte)DATA_state );
[6424]618
619    SYNCHELP_WRITE_FKT( WorldEntity::readState );
[6634]620    //SYNCHELP_WRITE_FLOAT( cycle );
[6424]621
622    return SYNCHELP_WRITE_N;
623  }
624
625  *reciever = 0;
[6498]626
627  if ( this->getHostID()==this->getOwner() )
628  {
629    int mask = 0;
630
631    if ( bUp )
632      mask |= MASK_bUp;
633    if ( bDown )
634      mask |= MASK_bDown;
635    if ( bLeft )
636      mask |= MASK_bLeft;
637    if ( bRight )
638      mask |= MASK_bRight;
639    if ( bAscend )
640      mask |= MASK_bAscend;
641    if ( bFire )
642      mask |= MASK_bFire;
643    if ( bRollL )
644      mask |= MASK_bRollL;
645    if ( bRollR )
646      mask |= MASK_bRollR;
647
648
[6634]649    //static float oldxMouse = xMouse + 1.0;
650    //static float oldyMouse = yMouse + 1.0;
651
[6498]652    if ( mask != oldMask )
653    {
654      oldMask = mask;
655      SYNCHELP_WRITE_BYTE( DATA_flags );
656      SYNCHELP_WRITE_INT( mask );
657    }
[6737]658#define __OFFSET_ROT 0.05
659    if ( fabs( oldMouseDir.w - mouseDir.w ) > __OFFSET_ROT ||
660         fabs( oldMouseDir.v.x - mouseDir.v.x ) > __OFFSET_ROT ||
661         fabs( oldMouseDir.v.y - mouseDir.v.y ) > __OFFSET_ROT ||
662         fabs( oldMouseDir.v.z - mouseDir.v.z ) > __OFFSET_ROT )
[6634]663    {
[6737]664      oldMouseDir = mouseDir;
665
666      SYNCHELP_WRITE_BYTE( DATA_mouse );
667      SYNCHELP_WRITE_FLOAT( mouseDir.w );
668      SYNCHELP_WRITE_FLOAT( mouseDir.v.x );
669      SYNCHELP_WRITE_FLOAT( mouseDir.v.y );
670      SYNCHELP_WRITE_FLOAT( mouseDir.v.z );
[6634]671    }
[6498]672
673  }
674
[6737]675  SYNCHELP_WRITE_BYTE( 0 );
676
677
[6634]678  if ( this->getOwner() == this->getHostID() )
679    SYNCHELP_WRITE_FKT( PNode::readSync );
680
[6498]681  return SYNCHELP_WRITE_N;
[6424]682}
Note: See TracBrowser for help on using the repository browser.