00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef ARMAGETRONAD_SRC_TRON_GCYCLEMOVEMENT_H_INCLUDED
00029 #define ARMAGETRONAD_SRC_TRON_GCYCLEMOVEMENT_H_INCLUDED
00030
00031 #include "eNetGameObject.h"
00032 #include <deque>
00033
00034 class gCycle;
00035 class gDestination;
00036 class gPlayerWall;
00037 class gCycleMovement;
00038 class gSensor;
00039 struct gMaxSpaceAheadHitInfo;
00040
00042 class gMaxSpaceAheadHitInfoClearer
00043 {
00044 public:
00045 gMaxSpaceAheadHitInfoClearer( gMaxSpaceAheadHitInfo * & info );
00046 ~gMaxSpaceAheadHitInfoClearer();
00047 private:
00048 gMaxSpaceAheadHitInfo * & info_;
00049 };
00050
00051 REAL GetTurnSpeedFactor(void);
00052
00053 class gEnemyInfluence{
00054 private:
00055 nObserverPtr< ePlayerNetID > lastEnemyInfluence;
00056 REAL lastTime;
00057
00058 public:
00059 gEnemyInfluence();
00060
00061 ePlayerNetID const * GetEnemy() const;
00062 REAL GetTime() const;
00063 void AddSensor( const gSensor& sensor, REAL timePenalty, gCycleMovement * thisCycle );
00064 void AddWall( const eWall * wall, eCoord const & point, REAL timePenalty, gCycleMovement * thisCycle );
00065 void AddWall( const gPlayerWall * wall, REAL timeBuilt, gCycleMovement * thisCycle );
00066 };
00067
00068 struct gRealColor {
00069 REAL r,g,b;
00070
00071 gRealColor():r(1), g(1), b(1){}
00072
00073 };
00074
00076 class gCycleMovement : public eNetGameObject
00077 {
00078 public:
00079
00080 static float RubberSpeed () ;
00081 static float SpeedMultiplier () ;
00082 static void SetSpeedMultiplier ( REAL mult ) ;
00083 static float MaximalSpeed () ;
00084
00085
00086 int WindingNumber () const ;
00087 void SetWindingNumberWrapped ( int newWindingNumberWrapped ) ;
00088
00089
00090 virtual eCoord Direction () const ;
00091 virtual eCoord LastDirection () const ;
00092 virtual REAL Speed () const ;
00093 virtual bool Alive () const ;
00094 virtual bool Vulnerable () const ;
00095 virtual eCoord SpawnDirection () const ;
00096
00097 bool CanMakeTurn (int direction ) const ;
00098 bool CanMakeTurn ( REAL time, int direction ) const ;
00099 inline REAL GetDistanceSinceLastTurn( ) const ;
00100 REAL GetTurnDelay ( ) const ;
00101 REAL GetTurnDelayDb ( ) const ;
00102 REAL GetNextTurn (int direction ) const ;
00103
00104
00105 void AddDestination () ;
00106 void AdvanceDestination () ;
00107 void AddDestination ( gDestination * dest ) ;
00108 gDestination* GetCurrentDestination () const ;
00109 void NotifyNewDestination ( gDestination * dest ) ;
00110 bool IsDestinationUsed ( const gDestination * dest ) const ;
00111
00112 inline void DropTempWall ( gPlayerWall * wall
00113 , eCoord const & pos
00114 , eCoord const & dir ) ;
00115
00116 virtual bool EdgeIsDangerous ( const eWall * wall
00117 , REAL time
00118 , REAL alpha ) const ;
00119
00120
00121 bool Turn ( REAL dir ) ;
00122 bool Turn ( int dir ) ;
00123
00124 void MoveSafely (const eCoord & dest
00125 , REAL startTime
00126 , REAL endTime ) ;
00127
00128 virtual bool Timestep ( REAL currentTime ) ;
00129
00130 virtual REAL NextInterestingTime () const ;
00131
00132
00133 virtual void AddRef () ;
00134
00135 gCycleMovement ( eGrid * grid
00136 , const eCoord & pos
00137 , const eCoord & dir
00138 , ePlayerNetID * p=NULL
00139 , bool autodelete=1 ) ;
00140 gCycleMovement ( nMessage & message ) ;
00141 virtual ~gCycleMovement () ;
00142 virtual void OnRemoveFromGame();
00143
00144 void RequestSync(bool ack=true);
00145 void RequestSync(int user,bool ack);
00146 protected:
00148 struct SyncData
00149 {
00150 eCoord pos, dir, lastTurn;
00151 REAL distance, speed, time, rubber, rubberMalus, brakingReservoir;
00152 unsigned short turns,braking,messageID;
00153
00154 SyncData()
00155 :distance(0), speed(0), time(-10000), rubber(0), rubberMalus(0), brakingReservoir(0)
00156 ,turns(0),braking(0),messageID(0)
00157 {}
00158 };
00159
00160 void CopyFrom ( const gCycleMovement & other ) ;
00161
00162 void CopyFrom ( const SyncData & sync
00163 , const gCycleMovement & other ) ;
00164
00165 virtual void InitAfterCreation () ;
00166
00167
00168 virtual void AccelerationDiscontinuity () ;
00169 virtual void CalculateAcceleration ( ) ;
00170 virtual void ApplyAcceleration ( REAL dt ) ;
00171
00172
00173 REAL DistanceToDestination ( gDestination & dest ) const ;
00174 virtual void OnNotifyNewDestination ( gDestination * dest ) ;
00175 virtual void OnDropTempWall ( gPlayerWall * wall
00176 , eCoord const & pos
00177 , eCoord const & dir ) ;
00178 virtual bool DoIsDestinationUsed ( const gDestination * dest ) const ;
00179 static gDestination* GetDestinationBefore ( const SyncData & sync
00180 , gDestination* first ) ;
00181
00182 virtual bool DoTurn ( int dir ) ;
00183 virtual REAL DoGetDistanceSinceLastTurn ( ) const ;
00184
00185 virtual void RightBeforeDeath ( int numTries ) ;
00186 virtual void Die ( REAL time ) ;
00187
00188 virtual bool TimestepCore ( REAL currentTime
00189 , bool calculateAcceleration = true ) ;
00190 private:
00191 void MyInitAfterCreation () ;
00192
00193
00194
00195
00196 gCycleMovement () ;
00197 gCycleMovement ( gCycleMovement const & other ) ;
00198 gCycleMovement& operator = ( gCycleMovement const & other ) ;
00199
00200 private:
00201 short alive_;
00202
00203 protected:
00204 gEnemyInfluence enemyInfluence;
00205
00206 gDestination* destinationList;
00207 gDestination* currentDestination;
00208 gDestination* lastDestination;
00209
00210 eCoord dirDrive;
00211 eCoord dirSpawn;
00212 eCoord lastDirDrive;
00213 REAL acceleration;
00214 REAL totalZoneAcceleration;
00215
00216 REAL lastTimestep_;
00217 REAL verletSpeed_;
00218
00219 REAL distance;
00220
00221
00222 mutable bool refreshSpaceAhead_;
00223 REAL maxSpaceMaxCast_;
00224 mutable gMaxSpaceAheadHitInfo * maxSpaceHit_;
00225
00226 unsigned short turns;
00227 unsigned short braking;
00228
00229 int windingNumber_;
00230 int windingNumberWrapped_;
00231
00232 mutable REAL gap_[2];
00233 mutable bool keepLookingForGap_[2];
00234
00235 eCoord lastTurnPos_;
00236 REAL lastTurnTimeRight_;
00237 REAL lastTurnTimeLeft_;
00238 REAL lastTimeAlive_;
00239 std::deque<int> pendingTurns;
00240
00241 REAL brakingReservoir;
00242 REAL rubber;
00243 REAL rubberMalus;
00244 REAL rubberSpeedFactor;
00245
00246 REAL brakeUsage;
00247 REAL rubberUsage;
00248
00249
00250 public:
00251 REAL GetMaxSpaceAhead( REAL maxReport ) const;
00252
00253 inline REAL GetDistance( void ) const;
00254 inline gCycleMovement const & GetDistance( REAL & distance ) const;
00255 inline REAL GetRubber( void ) const;
00256 inline gCycleMovement const & GetRubber( REAL & rubber ) const;
00257 inline unsigned short GetTurns( void ) const;
00258 inline gCycleMovement const & GetTurns( unsigned short & turns ) const;
00259 inline unsigned short GetBraking( void ) const;
00260 inline gCycleMovement const & GetBraking( unsigned short & braking ) const;
00261 inline REAL GetBrakingReservoir( void ) const;
00262 inline gCycleMovement const & GetBrakingReservoir( REAL & brakingReservoir ) const;
00263 inline REAL GetRubberMalus( void ) const;
00264 inline gCycleMovement const & GetRubberMalus( REAL & rubberMalus ) const;
00265 static bool RubberMalusActive( void ) ;
00266 inline eCoord const & GetLastTurnPos( void ) const;
00267 inline gCycleMovement const & GetLastTurnPos( eCoord & lastTurnPos ) const;
00268 inline REAL const & GetLastTurnTime( void ) const;
00269 inline gCycleMovement const & GetLastTurnTime( REAL & lastTurnTime ) const;
00270 REAL GetAcceleration(void) const { return acceleration; };
00271 virtual void AddZoneAcceleration ( REAL zoneAcceleration ) ;
00272
00273 protected:
00274 inline gCycleMovement & SetLastTurnPos( eCoord const & lastTurnPos );
00275 inline gCycleMovement & SetLastTurnTime( REAL const & lastTurnTime );
00276 private:
00277 inline gCycleMovement & SetDistance( REAL distance );
00278 public:
00279
00280 inline gCycleMovement & SetRubber( REAL rubber );
00281 private:
00282 inline gCycleMovement & SetTurns( unsigned short turns );
00283 inline gCycleMovement & SetBraking( unsigned short braking );
00284 public:
00285
00286 inline gCycleMovement & SetBrakingReservoir( REAL brakingReservoir );
00287 private:
00288 inline gCycleMovement & SetRubberMalus( REAL rubberMalus );
00289 };
00290
00292
00293
00295 class gCycleDeath: public eDeath
00296 {
00297 public:
00298 gCycleDeath( eCoord const & pos )
00299 : pos_(pos)
00300 {}
00301
00302 eCoord pos_;
00303 };
00304
00306 class gCycleStop: public eDeath
00307 {
00308 };
00309
00310
00311
00312
00313
00314 class gDestination{
00315 friend class gCycleMovement;
00316 friend class gCycle;
00317 friend class gCycleExtrapolator;
00318
00319 eCoord position;
00320 eCoord direction;
00321 REAL gameTime;
00322 REAL distance;
00323 REAL speed;
00324 bool braking;
00325 bool chatting;
00326
00327 unsigned short turns;
00328 bool hasBeenUsed;
00329 unsigned short messageID;
00330 bool missable;
00331
00332 gDestination *next;
00333 gDestination **list;
00334 public:
00335
00336 explicit gDestination(const gCycleMovement &takeitfrom);
00337 explicit gDestination(const gCycle &takeitfrom);
00338
00339
00340 explicit gDestination( nMessage &m, unsigned short & cycle_id );
00341
00342
00343 void CopyFrom(const gCycleMovement &other);
00344 void CopyFrom(const gCycle &other);
00345
00347 int CompareWith( const gDestination& other ) const;
00348
00349
00350 void WriteCreate( nMessage &m, unsigned short cycle_id );
00351
00352
00353 void InsertIntoList(gDestination **list);
00354
00355
00356 static gDestination *RightBefore(gDestination *list, REAL dist);
00357
00358
00359 static gDestination *RightAfter(gDestination *list, REAL dist);
00360
00361
00362 void RemoveFromList();
00363
00364 bool Chatting(){ return chatting; }
00365
00366 ~gDestination(){RemoveFromList();}
00367
00368 gDestination & SetGameTime( REAL gameTime );
00369 REAL GetGameTime( void ) const;
00370 gDestination const & GetGameTime( REAL & gameTime ) const;
00371 };
00372
00373
00374
00375
00376
00377
00382
00383
00384 inline bool gCycleMovement::IsDestinationUsed( const gDestination * dest ) const
00385 {
00386
00387 return DoIsDestinationUsed( dest );
00388 }
00389
00390
00391
00392
00393
00394
00400
00401
00402 inline void gCycleMovement::DropTempWall( gPlayerWall * wall, eCoord const & pos, eCoord const & dir )
00403 {
00404 this->OnDropTempWall( wall, pos, dir );
00405 }
00406
00407
00408
00409
00410
00411
00415
00416
00417 inline REAL gCycleMovement::GetDistance( void ) const
00418 {
00419 return this->distance;
00420 }
00421
00422
00423
00424
00425
00426
00431
00432
00433 inline gCycleMovement const & gCycleMovement::GetDistance( REAL & distance ) const
00434 {
00435 distance = this->distance;
00436 return *this;
00437 }
00438
00439
00440
00441
00442
00443
00448
00449
00450 inline gCycleMovement & gCycleMovement::SetDistance( REAL distance )
00451 {
00452 this->distance = distance;
00453 return *this;
00454 }
00455
00456
00457
00458
00459
00460
00464
00465
00466 inline REAL gCycleMovement::GetRubber( void ) const
00467 {
00468 return this->rubber;
00469 }
00470
00471
00472
00473
00474
00475
00480
00481
00482 inline gCycleMovement const & gCycleMovement::GetRubber( REAL & rubber ) const
00483 {
00484 rubber = this->rubber;
00485 return *this;
00486 }
00487
00488
00489
00490
00491
00492
00497
00498
00499 inline gCycleMovement & gCycleMovement::SetRubber( REAL rubber )
00500 {
00501 this->rubber = rubber;
00502 return *this;
00503 }
00504
00505
00506
00507
00508
00509
00513
00514
00515 inline unsigned short gCycleMovement::GetTurns( void ) const
00516 {
00517 return this->turns;
00518 }
00519
00520
00521
00522
00523
00524
00529
00530
00531 inline gCycleMovement const & gCycleMovement::GetTurns( unsigned short & turns ) const
00532 {
00533 turns = this->turns;
00534 return *this;
00535 }
00536
00537
00538
00539
00540
00541
00546
00547
00548 inline gCycleMovement & gCycleMovement::SetTurns( unsigned short turns )
00549 {
00550 this->turns = turns;
00551 return *this;
00552 }
00553
00554
00555
00556
00557
00558
00562
00563
00564 inline unsigned short gCycleMovement::GetBraking( void ) const
00565 {
00566 return this->braking;
00567 }
00568
00569
00570
00571
00572
00573
00578
00579
00580 inline gCycleMovement const & gCycleMovement::GetBraking( unsigned short & braking ) const
00581 {
00582 braking = this->braking;
00583 return *this;
00584 }
00585
00586
00587
00588
00589
00590
00595
00596
00597 inline gCycleMovement & gCycleMovement::SetBraking( unsigned short braking )
00598 {
00599 this->braking = braking;
00600 return *this;
00601 }
00602
00603
00604
00605
00606
00607
00611
00612
00613 inline REAL gCycleMovement::GetBrakingReservoir( void ) const
00614 {
00615 return this->brakingReservoir;
00616 }
00617
00618
00619
00620
00621
00622
00627
00628
00629 inline gCycleMovement const & gCycleMovement::GetBrakingReservoir( REAL & brakingReservoir ) const
00630 {
00631 brakingReservoir = this->brakingReservoir;
00632 return *this;
00633 }
00634
00635
00636
00637
00638
00639
00644
00645
00646 inline gCycleMovement & gCycleMovement::SetBrakingReservoir( REAL brakingReservoir )
00647 {
00648 this->brakingReservoir = brakingReservoir;
00649 return *this;
00650 }
00651
00652
00653
00654
00655
00656
00660
00661
00662 inline REAL gCycleMovement::GetDistanceSinceLastTurn( void ) const
00663 {
00664 return this->DoGetDistanceSinceLastTurn();
00665 }
00666
00667
00668
00669
00670
00671
00675
00676
00677 inline REAL gCycleMovement::GetRubberMalus( void ) const
00678 {
00679 return this->rubberMalus;
00680 }
00681
00682
00683
00684
00685
00686
00691
00692
00693 inline gCycleMovement const & gCycleMovement::GetRubberMalus( REAL & rubberMalus ) const
00694 {
00695 rubberMalus = this->rubberMalus;
00696 return *this;
00697 }
00698
00699
00700
00701
00702
00703
00708
00709
00710 inline gCycleMovement & gCycleMovement::SetRubberMalus( REAL rubberMalus )
00711 {
00712 this->rubberMalus = rubberMalus;
00713 return *this;
00714 }
00715
00716
00717
00718
00719
00720
00724
00725
00726 eCoord const & gCycleMovement::GetLastTurnPos( void ) const
00727 {
00728 return this->lastTurnPos_;
00729 }
00730
00731
00732
00733
00734
00735
00740
00741
00742 gCycleMovement const & gCycleMovement::GetLastTurnPos( eCoord & lastTurnPos ) const
00743 {
00744 lastTurnPos = this->lastTurnPos_;
00745 return *this;
00746 }
00747
00748
00749
00750
00751
00752
00757
00758
00759 gCycleMovement & gCycleMovement::SetLastTurnPos( eCoord const & lastTurnPos )
00760 {
00761 this->lastTurnPos_ = lastTurnPos;
00762 return *this;
00763 }
00764
00765
00766
00767
00768
00769
00773
00774
00775 REAL const & gCycleMovement::GetLastTurnTime( void ) const
00776 {
00777 return lastTurnTimeRight_ > lastTurnTimeLeft_ ? lastTurnTimeRight_ : lastTurnTimeLeft_;
00778 }
00779
00780
00781
00782
00783
00784
00789
00790
00791 gCycleMovement const & gCycleMovement::GetLastTurnTime( REAL & lastTurnTime ) const
00792 {
00793 lastTurnTime = GetLastTurnTime();
00794 return *this;
00795 }
00796
00797
00798
00799
00800
00801
00806
00807
00808 gCycleMovement & gCycleMovement::SetLastTurnTime( REAL const & lastTurnTime )
00809 {
00810 lastTurnTimeRight_ = lastTurnTimeLeft_ = lastTurnTime;
00811 return *this;
00812 }
00813
00814 #endif // ARMAGETRONAD_SRC_TRON_GCYCLEMOVEMENT_H_INCLUDED