src/tron/gCycle.h

Go to the documentation of this file.
00001 /*
00002 
00003 *************************************************************************
00004 
00005 ArmageTron -- Just another Tron Lightcycle Game in 3D.
00006 Copyright (C) 2000  Manuel Moos (manuel@moosnet.de)
00007 
00008 **************************************************************************
00009 
00010 This program is free software; you can redistribute it and/or
00011 modify it under the terms of the GNU General Public License
00012 as published by the Free Software Foundation; either version 2
00013 of the License, or (at your option) any later version.
00014 
00015 This program is distributed in the hope that it will be useful,
00016 but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 GNU General Public License for more details.
00019 
00020 You should have received a copy of the GNU General Public License
00021 along with this program; if not, write to the Free Software
00022 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00023   
00024 ***************************************************************************
00025 
00026 */
00027 
00028 #ifndef ArmageTron_CYCLE_H
00029 #define ArmageTron_CYCLE_H
00030 
00031 //#define USE_HEADLIGHT
00032 
00033 #include "gStuff.h"
00034 //#include "rTexture.h"
00035 //#include "rModel.h"
00036 #include "eNetGameObject.h"
00037 #include "tList.h"
00038 #include "nObserver.h"
00039 #include "rDisplayList.h"
00040 
00041 #include "gCycleMovement.h"
00042 
00043 class rModel;
00044 class gTextureCycle;
00045 class gSensor;
00046 class gNetPlayerWall;
00047 class gPlayerWall;
00048 class eTempEdge;
00049 class gJoystick;
00050 struct gPredictPositionData;
00051 
00052 // minimum time between two cycle turns
00053 extern REAL sg_delayCycle;
00054 
00055 // Render the headlight effect?
00056 extern bool headlights;
00057 
00058 // steering help
00059 extern REAL sg_rubberCycle;
00060 
00061 
00062 // this class set is responsible for remembering which walls are too
00063 // close together to pass through safely. The AI uses this information,
00064 // so the real declaration of gCylceMemoryEntry can be found in gAIBase.cpp.
00065 class gCycleMemoryEntry;
00066 
00067 class gCycleMemory{
00068     friend class gCycleMemoryEntry;
00069 
00070     tList<gCycleMemoryEntry>     memory;  // memory about other cylces
00071 
00072 public:
00073     // memory functions: access the memory for a cylce
00074     gCycleMemoryEntry* Remember(const gCycle *cycle);
00075     int Len() const {return memory.Len();}
00076     gCycleMemoryEntry* operator() (int i)  const;
00077     gCycleMemoryEntry* Latest   (int side)  const;
00078     gCycleMemoryEntry* Earliest (int side)  const;
00079 
00080     void Clear();
00081 
00082     gCycleMemory();
00083     ~gCycleMemory();
00084 };
00085 
00086 // class used to extrapolate the movement of a lightcycle
00087 class gCycleExtrapolator: public gCycleMovement
00088 {
00089 public:
00090     void CopyFrom( const gCycleMovement& other );                                                       // copies relevant info from other cylce
00091     void CopyFrom( const SyncData& sync, const gCycle& other );                 // copies relevant info from sync data and everything else from other cycle
00092 
00093     gCycleExtrapolator(eGrid *grid, const eCoord &pos,const eCoord &dir,ePlayerNetID *p=NULL,bool autodelete=1);
00094     // gCycleExtrapolator(nMessage &m);
00095     virtual ~gCycleExtrapolator();
00096 
00097     // virtual gDestination* GetCurrentDestination() const;                     // returns the current destination
00098 
00099     virtual bool EdgeIsDangerous(const eWall *w, REAL time, REAL a) const;
00100 
00101     virtual void PassEdge(const eWall *w,REAL time,REAL a,int recursion=1);
00102 
00103     virtual bool TimestepCore(REAL currentTime, bool calculateAcceleration = true );
00104 
00105     // virtual bool DoTurn(int dir);
00106 
00107     REAL                          trueDistance_;                                                                                // distance predicted as best as we can
00108 private:
00109     // virtual REAL            DoGetDistanceSinceLastTurn  (                               ) const     ;   //!< returns the distance since the last turn
00110 
00111     virtual nDescriptor& CreatorDescriptor() const;
00112 
00113     const gCycleMovement* parent_;                                                                                              // the cycle that is extrapolated
00114 };
00115 
00116 class gCycleChatBot;
00117 
00118 #ifndef DEDICATED
00119 class gCycleWallsDisplayListManager
00120 {
00121     friend class gNetPlayerWall;
00122 
00123 public:
00124     gCycleWallsDisplayListManager();
00125 
00127     static bool CannotHaveList( REAL distance, gCycle const * cycle );
00128 
00129     void RenderAll( eCamera const * camera, gCycle * cycle );
00130     bool Walls() const
00131     {
00132         return wallList_ || wallsWithDisplayList_;
00133     }
00134 
00135     void Clear( int inhibit = 0 )
00136     {
00137         displayList_.Clear( inhibit );
00138     }
00139 private:
00140     gNetPlayerWall *                wallList_;                      
00141     gNetPlayerWall *                wallsWithDisplayList_;          
00142     rDisplayList                    displayList_;                   
00143     REAL                            wallsWithDisplayListMinDistance_; 
00144     int                             wallsInDisplayList_;            
00145 };
00146 #endif
00147 
00148 // a complete lightcycle
00149 class gCycle: public gCycleMovement
00150 {
00151     friend class gPlayerWall;
00152     friend class gNetPlayerWall;
00153     friend class gDestination;
00154     friend class gCycleWallRenderer;
00155 
00156     REAL spawnTime_;    
00157     REAL lastTimeAnim;  
00158 
00159     REAL timeCameIntoView;
00160 
00161     friend class gCycleChatBot;
00162     std::auto_ptr< gCycleChatBot > chatBot_;
00163 
00164     bool dropWallRequested_; 
00165 public:
00166     eCoord            lastGoodPosition_;    // the location of the last known good position
00167 
00168     REAL skew,skewDot;                                          // leaning to the side
00169 
00170     bool                                mp;                             // use moviepack or not?
00171 
00172     rModel *body,*front,*rear,
00173     *customModel;
00174 
00175     gTextureCycle  *wheelTex,*bodyTex;
00176     gTextureCycle  *customTexture;
00177 
00178     eCoord rotationFrontWheel,rotationRearWheel;        // wheel position (rotation)
00179     REAL   heightFrontWheel,heightRearWheel;            // wheel (suspension)
00180 public:
00181     //REAL      brakingReservoir; // reservoir for braking. 1 means full, 0 is empty
00182 
00183     static uActionPlayer s_brake;
00184     gCycleMemory memory;
00185 
00186     gRealColor color_;
00187     gRealColor trailColor_;
00188 
00189     // smooth corrections
00190     // pos is always the correct simulated position; the displayed position is calculated as pos + correctPosSmooth
00191     // and correctPosSmooth decays with time.
00192     eCoord correctPosSmooth;
00193     eCoord predictPosition_; 
00194 
00195     // every frame, a bit of this variable is taken away and added to the step the cycle makes.
00196     REAL correctDistanceSmooth;
00197 
00198 private:
00199     void TransferPositionCorrectionToDistanceCorrection();
00200 
00201 #ifndef DEDICATED
00202     gCycleWallsDisplayListManager displayList_;                     
00203 #endif
00204 
00205     tCHECKED_PTR(gNetPlayerWall)        currentWall;                    
00206     tCHECKED_PTR(gNetPlayerWall)        lastWall;                       
00207     tCHECKED_PTR(gNetPlayerWall)        lastNetWall;                    
00208 
00209     // for network prediction
00210     SyncData                                                                    lastSyncMessage_;       // the last sync message the cycle received
00211     tJUST_CONTROLLED_PTR<gCycleExtrapolator>    extrapolator_;          // the cycle copy used for extrapolation
00212     bool                                                                                resimulate_;            // flag indicating that a new extrapolation should be started
00213 
00214     void        ResetExtrapolator();                                                    // resets the extrapolator to the last known state
00215     bool        Extrapolate( REAL dt );                                                 // simulate the extrapolator at higher speed
00216     void        SyncFromExtrapolator();                                                 // take over the extrapolator's data
00217 
00218     virtual void OnNotifyNewDestination(gDestination *dest);   
00219     virtual void OnDropTempWall        ( gPlayerWall * wall, eCoord const & position, eCoord const & direction );   
00220 
00221     //  unsigned short currentWallID;
00222 
00223     nTimeRolling nextSync, nextSyncOwner;
00224 
00225     void MyInitAfterCreation();
00226 
00227     void SetCurrentWall(gNetPlayerWall *w);
00228 
00229     void PreparePredictPosition( gPredictPositionData & data ); 
00230     REAL CalculatePredictPosition( gPredictPositionData & data ); 
00231 protected:
00232     virtual ~gCycle();
00233 
00234     virtual void OnRemoveFromGame(); // called when the cycle is physically removed from the game
00235 
00236     virtual void OnRoundEnd();    
00237 
00238     // virtual REAL            DoGetDistanceSinceLastTurn  (                               ) const     ;   //!< returns the distance since the last turn
00239 public:
00240     virtual void Die ( REAL time )  ;  
00241     void KillAt( const eCoord& pos );  
00242 
00243     int WindingNumber() const {return windingNumber_;}
00244 
00245     virtual bool            Vulnerable              ()                                    const     ;   
00246 
00247     // bool CanMakeTurn() const { return pendingTurns <= 0 && lastTime >= nextTurn; }
00248 
00249     virtual void InitAfterCreation();
00250     gCycle(eGrid *grid, const eCoord &pos,const eCoord &dir,ePlayerNetID *p=NULL);
00251 
00252     static      void    SetWallsStayUpDelay             ( REAL delay );                         
00253     static      void    SetWallsLength                  ( REAL length);                         
00254     static      void    SetExplosionRadius              ( REAL radius);                         
00255 
00256     static      REAL    WallsStayUpDelay()       { return wallsStayUpDelay;     }       
00257     static      REAL    WallsLength()            { return wallsLength;          }       
00258     REAL                MaxWallsLength() const;                             
00259     REAL                ThisWallsLength() const;                            
00260     REAL                WallEndSpeed() const;                               
00261     static      REAL    ExplosionRadius()        { return explosionRadius;      }       
00262 
00263     bool    IsMe( eGameObject const * other ) const;              
00264 
00265     // the network routines:
00266     gCycle(nMessage &m);
00267     virtual void WriteCreate(nMessage &m);
00268     virtual void WriteSync(nMessage &m);
00269     virtual void ReadSync(nMessage &m);
00270     virtual void RequestSyncOwner(); 
00271     virtual void RequestSyncAll(); 
00272 
00273     virtual void SyncEnemy ( const eCoord& begWall );    
00274     // virtual void SyncFriend( const eCoord& begWall );    //!< handle sync message for enemy cycles
00275 
00276     virtual void ReceiveControl(REAL time,uActionPlayer *Act,REAL x);
00277     virtual void PrintName(tString &s) const;
00278     virtual bool ActionOnQuit();
00279 
00280     virtual nDescriptor &CreatorDescriptor() const;
00281     virtual bool SyncIsNew(nMessage &m);
00282     //virtual bool ClearToTransmit(int user) const;
00283 
00284     virtual bool Timestep(REAL currentTime);
00285     virtual bool TimestepCore(REAL currentTime,bool calculateAcceleration = true);
00286 
00287     virtual void InteractWith(eGameObject *target,REAL time,int recursion=1);
00288 
00289     virtual bool EdgeIsDangerous(const eWall *w, REAL time, REAL a) const;
00290 
00291     virtual void PassEdge(const eWall *w,REAL time,REAL a,int recursion=1);
00292 
00293     virtual REAL PathfindingModifier( const eWall *w ) const;
00294 
00295     virtual bool Act(uActionPlayer *Act,REAL x);
00296 
00297     virtual bool DoTurn(int dir);
00298     void DropWall( bool buildNew=true );                                    
00299 
00300     // void Turbo(bool turbo);
00301 
00302     virtual void Kill();
00303 
00304     const eTempEdge* Edge();
00305     const gPlayerWall* CurrentWall();
00306     // const gPlayerWall* LastWall();
00307 
00308 #ifndef DEDICATED
00309     virtual void Render(const eCamera *cam);
00310     virtual void Render2D(tCoord scale) const;
00311 
00312     virtual void RenderName( const eCamera *cam );
00313 
00314     virtual bool RenderCockpitFixedBefore(bool primary=true);
00315 
00316     //virtual void SoundMix(unsigned char *dest,unsigned int len,
00317     //                      int viewer,REAL rvol,REAL lvol);
00318 #endif
00319 
00320     virtual eCoord CamPos() const;
00321     virtual eCoord PredictPosition() const;
00322     virtual eCoord  CamTop() const;
00323     virtual eCoord CamDir()  const;
00324     virtual eCoord Direction()  const;
00325 
00326     virtual void RightBeforeDeath( int numTries );
00327 
00328 #ifdef POWERPAK_DEB
00329     virtual void PPDisplay();
00330 #endif
00331 
00332     static      void    PrivateSettings();                                                                      // initiate private setting items
00333 
00334     //  virtual void AddRef();
00335     //  virtual void Release();
00336 
00337 private:
00338     static      REAL    wallsStayUpDelay;                       
00339     static      REAL    wallsLength;                            
00340     static      REAL    explosionRadius;                        
00341     gJoystick *     joystick_;                  
00342 protected:
00343     virtual     bool                    DoIsDestinationUsed             ( const gDestination *  dest            ) const         ;       
00344 };
00345 
00346 #endif
00347 

Generated on Sat Mar 15 22:56:07 2008 for Armagetron Advanced by  doxygen 1.5.4