Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 7085 was 7085, checked in by patrick, 18 years ago

trunk: entity is reset now after death

File size: 20.6 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
260void SpaceShip::reset()
261{
262  bUp = bDown = bLeft = bRight = bAscend = bDescend = bRollL = bRollR = false;
263
264  xMouse = yMouse = 0;
265
266  this->setHealth(80);
267  this->velocity = Vector(0.0, 0.0, 0.0);
268}
269
270
271void SpaceShip::enter()
272{
273  dynamic_cast<Element2D*>(this->getWeaponManager()->getFixedTarget())->setVisibility( true);
274  this->attachCamera();
275}
276
277void SpaceShip::leave()
278{
279  dynamic_cast<Element2D*>(this->getWeaponManager()->getFixedTarget())->setVisibility( false);
280  this->detachCamera();
281}
282
283
284/**
285 *  effect that occurs after the SpaceShip is spawned
286*/
287void SpaceShip::postSpawn ()
288{
289  //setCollision(new CollisionCluster(1.0, Vector(0,0,0)));
290}
291
292/**
293 *  the action occuring if the spaceship left the game
294*/
295void SpaceShip::leftWorld ()
296{}
297
298WorldEntity* ref = NULL;
299/**
300 *  this function is called, when two entities collide
301 * @param entity: the world entity with whom it collides
302 *
303 * Implement behaviour like damage application or other miscellaneous collision stuff in this function
304 */
305void SpaceShip::collidesWith(WorldEntity* entity, const Vector& location)
306{
307  Playable::collidesWith(entity, location);
308
309  if( entity->isA(CL_PROJECTILE) && entity != ref)
310  {
311    if ( isServer() )
312    {
313      networkCollisionList.push_back( entity->getHealth() );
314      doCollideNetwork( entity->getHealth() );
315    }
316  }
317//  PRINTF(3)("collision %s vs %s @ (%f,%f,%f)\n", this->getClassName(), entity->getClassName(), location.x, location.y, location.z);
318}
319
320/**
321 *  draws the spaceship after transforming it.
322*/
323void SpaceShip::draw () const
324{
325  WorldEntity::draw();
326  this->getWeaponManager()->draw();
327
328  //this->debug(0);
329}
330
331/**
332 *  the function called for each passing timeSnap
333 * @param time The timespan passed since last update
334*/
335void SpaceShip::tick (float time)
336{
337  Playable::tick(time);
338
339  if( ( xMouse != 0 || yMouse != 0 ) && this->getOwner() == this->getHostID() )
340   {
341    if (xMouse > controlVelocityX) xMouse = controlVelocityX;
342    else if (xMouse < -controlVelocityX) xMouse = -controlVelocityX;
343    if (yMouse > controlVelocityY) yMouse = controlVelocityY;
344    else if (yMouse < -controlVelocityY) yMouse = -controlVelocityY;
345
346    pitchDir = (Quaternion(xMouse*mouseSensitivity*0.5, Vector(1,0,0)));
347
348    mouseDir *= (Quaternion(-M_PI/4*xMouse*mouseSensitivity, Vector(0,1,0))*Quaternion(-M_PI/4*yMouse*mouseSensitivity*yInvert, Vector(0,0,1))*pitchDir);
349    xMouse = yMouse = 0;
350   }
351
352
353//   if( this != State::getPlayer()->getControllable())
354//     return;
355
356  // spaceship controlled movement
357  if (this->getOwner() == this->getHostID())
358    this->calculateVelocity(time);
359
360
361  Vector move = velocity*time;
362
363  //orient the velocity in the direction of the spaceship.
364  travelSpeed = velocity.len();
365  velocity += ((this->getAbsDirX())*travelSpeed-velocity)*airViscosity;
366  velocity = (velocity.getNormalized())*travelSpeed;
367  this->burstEmitter->setEmissionRate(travelSpeed);
368  this->burstEmitter->setEmissionVelocity(travelSpeed*.5, travelSpeed *.1);
369
370  //orient the spaceship in direction of the mouse
371   rotQuat = Quaternion::quatSlerp( this->getAbsDir(), mouseDir, 0.5);//fabsf(time)*shipInertia);
372   if (this->getAbsDir().distance(rotQuat) > 0.00000000000001)
373    this->setAbsDir( rotQuat);
374   //this->setAbsDirSoft(mouseDir,5);
375
376  // this is the air friction (necessary for a smooth control)
377  if(travelSpeed >= 120) velocity -= velocity.getNormalized()*travelSpeed*travelSpeed*0.0001;
378  else if (travelSpeed <= 80) velocity -= velocity.getNormalized()*travelSpeed*0.001;
379
380  //other physics (gravity)
381  //if(travelSpeed < 120)
382  //move += Vector(0,-1,0)*60*time + Vector(0,1,0)*travelSpeed/2*time;
383
384  //hoover effect
385  //cycle += time;
386  //this->shiftCoor(Vector(0,1,0)*cos(this->cycle*2.0)*0.02);
387
388  //readjust
389  //if (this->getAbsDirZ().y > 0.1) this->shiftDir(Quaternion(time*0.3, Vector(1,0,0)));
390  //else if (this->getAbsDirZ().y < -0.1) this->shiftDir(Quaternion(-time*0.3, Vector(1,0,0)));
391
392  //SDL_WarpMouse(GraphicsEngine::getInstance()->getResolutionX()/2, GraphicsEngine::getInstance()->getResolutionY()/2);
393
394  this->shiftCoor(move);
395
396
397}
398
399/**
400 *  calculate the velocity
401 * @param time the timeslice since the last frame
402*/
403void SpaceShip::calculateVelocity (float time)
404{
405  Vector accel(0.0, 0.0, 0.0);
406  /*
407  Vector rot(0.0, 0.0, 0.0); // wird benötigt für Helicopter
408  */
409  //float rotVal = 0.0;
410  /* FIXME: calculating the direction and orthDirection every timeSlice is redundant! save it somewhere */
411  /* calculate the direction in which the craft is heading  */
412
413  //Plane plane(Vector(0,1,0), Vector(0,0,0));
414
415  if( this->bUp )
416   {
417     //this->shiftCoor(this->getAbsDirX());
418      //accel += (this->getAbsDirX())*2;
419      accel += (this->getAbsDirX())*acceleration;
420
421   }
422
423  if( this->bDown )
424   {
425     //this->shiftCoor((this->getAbsDirX())*-1);
426     //accel -= (this->getAbsDirX())*2;
427    //if(velocity.len() > 50)
428     accel -= (this->getAbsDirX())*0.5*acceleration;
429
430
431
432   }
433
434  if( this->bLeft/* > -this->getRelCoor().z*2*/)
435  {
436    this->shiftDir(Quaternion(time, Vector(0,1,0)));
437//    accel -= rightDirection;
438    //velocityDir.normalize();
439    //rot +=Vector(1,0,0);
440    //rotVal -= .4;
441  }
442  if( this->bRight /* > this->getRelCoor().z*2*/)
443  {
444    this->shiftDir(Quaternion(-time, Vector(0,1,0)));
445
446    //    accel += rightDirection;
447    //velocityDir.normalize();
448    //rot += Vector(1,0,0);
449    //rotVal += .4;
450  }
451
452
453  if( this->bRollL /* > -this->getRelCoor().z*2*/)
454  {
455    mouseDir *= Quaternion(-time*2, Vector(1,0,0));
456//    accel -= rightDirection;
457    //velocityDir.normalize();
458    //rot +=Vector(1,0,0);
459    //rotVal -= .4;
460  }
461  if( this->bRollR /* > this->getRelCoor().z*2*/)
462  {
463    mouseDir *= Quaternion(time*2, Vector(1,0,0));
464
465    //    accel += rightDirection;
466    //velocityDir.normalize();
467    //rot += Vector(1,0,0);
468    //rotVal += .4;
469  }
470  if (this->bAscend )
471  {
472    this->shiftDir(Quaternion(time, Vector(0,0,1)));
473
474//    accel += upDirection;
475    //velocityDir.normalize();
476    //rot += Vector(0,0,1);
477    //rotVal += .4;
478  }
479  if (this->bDescend )
480  {
481    this->shiftDir(Quaternion(-time, Vector(0,0,1)));
482
483    //    accel -= upDirection;
484    //velocityDir.normalize();
485    //rot += Vector(0,0,1);
486    //rotVal -= .4;
487  }
488
489  velocity += accel*time*10;
490  //rot.normalize();
491  //this->setRelDirSoft(Quaternion(rotVal, rot), 5);
492}
493
494/**
495 * @todo switch statement ??
496 */
497void SpaceShip::process(const Event &event)
498{
499  Playable::process(event);
500
501  if( event.type == KeyMapper::PEV_LEFT)
502      this->bRollL = event.bPressed;
503  else if( event.type == KeyMapper::PEV_RIGHT)
504      this->bRollR = event.bPressed;
505  else if( event.type == KeyMapper::PEV_FORWARD)
506    this->bUp = event.bPressed; //this->shiftCoor(0,.1,0);
507  else if( event.type == KeyMapper::PEV_BACKWARD)
508    this->bDown = event.bPressed; //this->shiftCoor(0,-.1,0);
509  else if( event.type == EV_MOUSE_MOTION)
510  {
511    this->xMouse += event.xRel;
512    this->yMouse += event.yRel;
513  }
514}
515
516
517#define MASK_bUp         1
518#define MASK_bDown       2
519#define MASK_bLeft       4
520#define MASK_bRight      8
521#define MASK_bAscend    16
522#define MASK_bDescend   32
523#define MASK_bRollL     64
524#define MASK_bRollR    128
525
526#define DATA_state       1
527#define DATA_flags       2
528#define DATA_mouse       3
529#define DATA_sync        4
530#define DATA_velocity    5
531#define DATA_playables   6
532#define DATA_collision   7
533
534int SpaceShip::writeBytes( const byte * data, int length, int sender )
535{
536  SYNCHELP_READ_BEGIN();
537
538  byte b;
539
540  while ( SYNCHELP_READ_REMAINING()>0 )
541  {
542    SYNCHELP_READ_BYTE( b, NWT_SS_B );
543
544    if ( b == DATA_state )
545    {
546      setRequestedSync( false );
547      setIsOutOfSync( false );
548      SYNCHELP_READ_FKT( WorldEntity::writeState, NWT_SS_WE_STATE );
549
550      continue;
551    }
552
553    if ( b == DATA_flags )
554    {
555      if ( this->getOwner() != this->getHostID() )
556      {
557        byte flags = 0;
558        SYNCHELP_READ_BYTE( flags, NWT_SS_FLAGS );
559
560        bUp = (flags & MASK_bUp) != 0;
561        bDown = (flags & MASK_bDown) != 0;
562        bLeft = (flags & MASK_bLeft) != 0;
563        bRight = (flags & MASK_bRight) != 0;
564        bAscend = (flags & MASK_bAscend) != 0;
565        bDescend = (flags & MASK_bDescend) != 0;
566        bRollL = (flags & MASK_bRollL) != 0;
567        bRollR = (flags & MASK_bRollR) != 0;
568
569      }
570      else
571        assert(false);
572
573      continue;
574    }
575
576    if ( b == DATA_mouse )
577    {
578      if ( this->getOwner() != this->getHostID() )
579      {
580        SYNCHELP_READ_FLOAT( mouseDir.w, NWT_SS_MOUSEDIRW );
581        SYNCHELP_READ_FLOAT( mouseDir.v.x, NWT_SS_MOUSEDIRX );
582        SYNCHELP_READ_FLOAT( mouseDir.v.y, NWT_SS_MOUSEDIRY );
583        SYNCHELP_READ_FLOAT( mouseDir.v.z, NWT_SS_MOUSEDIRZ );
584      }
585      else
586        assert(false);
587
588      continue;
589    }
590
591    if ( b == DATA_sync )
592    {
593      if ( this->getOwner() != this->getHostID() )
594      {
595        SYNCHELP_READ_FKT( PNode::writeSync, NWT_SS_PN_SYNC );
596      }
597      else
598        assert(false);
599
600      continue;
601    }
602
603    if ( b == DATA_velocity )
604    {
605      if ( this->getOwner() != this->getHostID() )
606      {
607        SYNCHELP_READ_FLOAT( velocity.x, NWT_SS_VELX );
608        SYNCHELP_READ_FLOAT( velocity.y, NWT_SS_VELY );
609        SYNCHELP_READ_FLOAT( velocity.z, NWT_SS_VELZ );
610      }
611      else
612        assert(false);
613
614      continue;
615    }
616
617    if ( b == DATA_playables )
618    {
619      if ( this->getOwner() != this->getHostID() )
620      {
621        SYNCHELP_READ_FKT( Playable::writeSync, NWT_SS_PL_SYNC );
622      }
623      else
624        assert(false);
625    }
626
627    if ( b == DATA_collision )
628    {
629      int n;
630      float energy;
631      SYNCHELP_READ_INT( n, NWT_SS_CO_N );
632
633      for ( int i = 0; i<n; i++ )
634      {
635        SYNCHELP_READ_FLOAT( energy, NWT_SS_CO_CLID );
636        doCollideNetwork( energy );
637      }
638    }
639  }
640
641  return SYNCHELP_READ_N;
642}
643
644
645
646int SpaceShip::readBytes( byte * data, int maxLength, int * reciever )
647{
648  SYNCHELP_WRITE_BEGIN();
649
650  if ( isOutOfSync() && !requestedSync() /*&& this->getHostID()!=this->getOwner()*/ )
651  {
652    (NetworkGameManager::getInstance())->sync( this->getUniqueID(), this->getOwner() );
653    setRequestedSync( true );
654    PRINTF(0)("REQUESTED STATE %d\n", this->getUniqueID());
655  }
656
657  int rec = this->getRequestSync();
658  if ( rec > 0 )
659  {
660    *reciever = rec;
661
662    PRINTF(0)("SEND STATE %d %d\n", this->getUniqueID(), rec);
663
664    SYNCHELP_WRITE_BYTE( (byte)DATA_state, NWT_SS_B );
665
666    SYNCHELP_WRITE_FKT( WorldEntity::readState, NWT_SS_WE_STATE );
667
668    return SYNCHELP_WRITE_N;
669  }
670
671  *reciever = 0 - this->getOwner();
672  //TODO: implement with SYNCHELP_WRITE_SENT()
673  bool sentSomething = false;
674
675  if ( PNode::needsReadSync() && ( this->getHostID()==0 || this->getOwner() == this->getHostID() ) )
676  {
677    PRINTF(0)("sending PNode::readSync\n");
678    SYNCHELP_WRITE_BYTE( DATA_sync, NWT_SS_B );
679    SYNCHELP_WRITE_FKT( PNode::readSync, NWT_SS_PN_SYNC );
680    sentSomething = true;
681  }
682
683  if ( this->getHostID()==0 || this->getHostID()==this->getOwner() )
684  {
685    byte mask = 0;
686
687    if ( bUp )
688      mask |= MASK_bUp;
689    if ( bDown )
690      mask |= MASK_bDown;
691    if ( bLeft )
692      mask |= MASK_bLeft;
693    if ( bRight )
694      mask |= MASK_bRight;
695    if ( bAscend )
696      mask |= MASK_bAscend;
697    if ( bRollL )
698      mask |= MASK_bRollL;
699    if ( bRollR )
700      mask |= MASK_bRollR;
701
702
703    if ( mask != oldMask )
704    {
705      oldMask = mask;
706      PRINTF(0)("sending mask\n");
707      sentSomething = true;
708      SYNCHELP_WRITE_BYTE( DATA_flags, NWT_SS_B );
709      SYNCHELP_WRITE_BYTE( mask, NWT_SS_FLAGS );
710    }
711#define __OFFSET_MDIR_W 0.01
712#define __OFFSET_MDIR_V 0.01
713    if ( fabs( oldMouseDir.w - mouseDir.w ) > __OFFSET_MDIR_W ||
714         fabs( oldMouseDir.v.x - mouseDir.v.x ) > __OFFSET_MDIR_V ||
715         fabs( oldMouseDir.v.y - mouseDir.v.y ) > __OFFSET_MDIR_V ||
716         fabs( oldMouseDir.v.z - mouseDir.v.z ) > __OFFSET_MDIR_V )
717    {
718      oldMouseDir = mouseDir;
719
720      SYNCHELP_WRITE_BYTE( DATA_mouse, NWT_SS_B );
721      PRINTF(0)("SENDING mousedir\n");
722      sentSomething = true;
723      SYNCHELP_WRITE_FLOAT( mouseDir.w, NWT_SS_MOUSEDIRW );
724      SYNCHELP_WRITE_FLOAT( mouseDir.v.x, NWT_SS_MOUSEDIRX );
725      SYNCHELP_WRITE_FLOAT( mouseDir.v.y, NWT_SS_MOUSEDIRY );
726      SYNCHELP_WRITE_FLOAT( mouseDir.v.z, NWT_SS_MOUSEDIRZ );
727    }
728#define __OFFSET_VEL 0.05
729    if ( fabs( oldVelocity.x - velocity.x ) > __OFFSET_VEL*fabs(oldVelocity.x)+0.1 ||
730         fabs( oldVelocity.y - velocity.y ) > __OFFSET_VEL*fabs(oldVelocity.y)+0.1 ||
731         fabs( oldVelocity.z - velocity.z ) > __OFFSET_VEL*fabs(oldVelocity.z)+0.1 )
732    {
733      oldVelocity.x = velocity.x;
734      oldVelocity.y = velocity.y;
735      oldVelocity.z = velocity.z;
736      PRINTF(0)("SENDING velocity\n");
737      sentSomething = true;
738      SYNCHELP_WRITE_BYTE( DATA_velocity, NWT_SS_B );
739      SYNCHELP_WRITE_FLOAT( velocity.x, NWT_SS_VELX );
740      SYNCHELP_WRITE_FLOAT( velocity.y, NWT_SS_VELY );
741      SYNCHELP_WRITE_FLOAT( velocity.z, NWT_SS_VELZ );
742    }
743
744    while ( Playable::needsReadSync() )
745    {
746      sentSomething = true;
747      PRINTF(0)("SYNCHELP_WRITE_FKT( Playable::readSync, NWT_SS_PL_SYNC )\n");
748      SYNCHELP_WRITE_BYTE( DATA_playables, NWT_SS_B );
749      SYNCHELP_WRITE_FKT( Playable::readSync, NWT_SS_PL_SYNC );
750    }
751
752  }
753
754  if ( !sentSomething )
755  {
756    *reciever = 0;
757
758    if ( networkCollisionList.size()>0 )
759    {
760      SYNCHELP_WRITE_BYTE( DATA_collision, NWT_SS_B );
761
762      SYNCHELP_WRITE_INT( networkCollisionList.size(), NWT_SS_CO_N );
763
764      for ( std::list<float>::iterator it = networkCollisionList.begin(); it!=networkCollisionList.end(); it++ )
765      {
766        SYNCHELP_WRITE_FLOAT( *it, NWT_SS_CO_CLID );
767      }
768
769      networkCollisionList.clear();
770    }
771  }
772
773  return SYNCHELP_WRITE_N;
774}
775
776void SpaceShip::doCollideNetwork( float energy )
777{
778  this->decreaseHealth( energy );
779  if( this->getHealth() <= 0)
780  {
781    this->die();
782  }
783}
784
785
786
Note: See TracBrowser for help on using the repository browser.