Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

fixed the direction loading of spaceship

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