src/tron/gWall.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 #include <stdio>
00008 #include <stdlib.h>
00009 **************************************************************************
00010 
00011 This program is free software; you can redistribute it and/or
00012 modify it under the terms of the GNU General Public License
00013 as published by the Free Software Foundation; either version 2
00014 of the License, or (at your option) any later version.
00015 
00016 This program is distributed in the hope that it will be useful,
00017 but WITHOUT ANY WARRANTY; without even the implied warranty of
00018 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019 GNU General Public License for more details.
00020 
00021 You should have received a copy of the GNU General Public License
00022 along with this program; if not, write to the Free Software
00023 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00024 
00025 ***************************************************************************
00026 
00027 */
00028 
00029 #ifndef ArmageTron_gWALL_H
00030 #define ArmageTron_gWALL_H
00031 
00032 #define HUD_MAP
00033 
00034 #include "eAdvWall.h"
00035 #include "nNetObject.h"
00036 #include "gExplosion.h"
00037 #include "rDisplayList.h"
00038 //#include "nObserver.h"
00039 class gExplosion;
00040 class gCycle;
00041 class gCycleMovement;
00042 class gNetPlayerWall;
00043 class eTempEdge;
00044 
00045 class gWallRim:public eWallRim{
00046 public:
00047     gWallRim(eGrid *grid, REAL h=10000);
00048     gWallRim(eGrid *grid, REAL tBeg, REAL tEnd, REAL h=10000);
00049     virtual ~gWallRim();
00050 
00051     virtual bool Splittable() const;
00052 
00053     virtual void Split(eWall *& w1,eWall *& w2,REAL a);
00054     virtual bool RunsParallelPassive( eWall * newWall );
00055 
00056 #ifndef DEDICATED
00057     void RenderReal(const eCamera *cam);
00058 protected:
00059     virtual void OnBlocksCamera( eCamera * cam, REAL height ) const; 
00060 #endif
00061     virtual REAL Height();
00062     virtual REAL SeeHeight();
00063 
00064 private:
00065     mutable REAL renderHeight_; 
00066     mutable REAL lastUpdate_;   
00067 
00068     REAL tBeg_, tEnd_;          
00069 };
00070 
00073 class gPlayerWallCoord{
00074 public:
00075     REAL Pos;             
00076     REAL Time;            
00077     bool IsDangerous;     
00078     tJUST_CONTROLLED_PTR< gExplosion > holer; //< if it is a hole, store who made it here.
00079 };
00080 
00081 class gPlayerWall:public eWall{
00082 public:
00083     friend class gNetPlayerWall;
00084 
00085     gPlayerWall(gNetPlayerWall*w, gCycle *p);
00086     virtual ~gPlayerWall();
00087 
00088     //  virtual ArmageTron_eWalltype type();
00089 
00090     virtual void Flip();
00091     virtual void SplitByActive( eWall* oldWall );
00092     virtual bool RunsParallelActive( eWall* oldWall );
00093 
00094     virtual bool Splittable() const;
00095     virtual bool Deletable() const;
00096 
00097     virtual void Split(eWall *& w1,eWall *& w2,REAL a);
00098 
00099 #ifndef DEDICATED
00100     virtual void Render(const eCamera *cam);
00101     void RenderList(bool list);
00102 #endif
00103 
00104     virtual REAL BlockHeight() const;
00105     virtual REAL SeeHeight() const;
00106 
00107     int WindingNumber() const {return windingNumber_;}
00108 
00109     REAL LocalToGlobal( REAL a ) const; 
00110     REAL GlobalToLocal( REAL a ) const; 
00111 
00112     REAL Time(REAL a) const;
00113     REAL Pos(REAL a) const;
00114     REAL Alpha(REAL pos) const;
00115     bool IsDangerousAnywhere( REAL time ) const;
00116     bool IsDangerous( REAL a, REAL time ) const;
00117     gExplosion * Holer( REAL a, REAL time ) const; // returns the guy who holed here
00118 
00119     void BlowHole       ( REAL dbeg, REAL dend, gExplosion * holer ); // blow a hole into the wall form distance dbeg to dend, created by holer
00120 
00121     REAL BegPos() const;
00122     REAL EndPos() const;
00123     REAL BegTime() const;
00124     REAL EndTime() const;
00125 
00126     gCycle *Cycle() const;
00127     gCycleMovement *CycleMovement() const;
00128     gNetPlayerWall* NetWall() const;
00129 
00130     void Insert();
00131 
00132     //  void SetNetWall( const gNetPlayerWall* netWall );
00133     //  void SetCoords( const tArray< gPlayerWallCoord >& coords );
00134     //  const tArray< gPlayerWallCoord >&  GetCoords() const;
00135 private:
00136     void Check() const;
00137     tCONTROLLED_PTR(gCycle) cycle_;
00138     tCONTROLLED_PTR(gNetPlayerWall) netWall_;
00139 
00140     //  nObserverPtr< gNetPlayerWall > netWall_;
00141 
00142     int windingNumber_;
00143     // REAL begAlpha_, endAlpha_;       // relative position i gNetPlayerWall
00144     REAL begDist_, endDist_;    // cycle driving distance at beginning and end
00145 
00146     gPlayerWall();
00147 };
00148 
00149 
00150 // the sn_netObjects that represents eWalls across the network.
00151 class gNetPlayerWall: public tListItem< gNetPlayerWall >, public nNetObject{
00152     friend class gCycle;
00153     int id,griddedid;
00154 
00155     tCONTROLLED_PTR(gCycle) cycle_;       // our cycle
00156     tCONTROLLED_PTR(eTempEdge) edge_;       // the eEdge we are representing
00157     gPlayerWall * lastWall_;                
00158 
00159     eCoord dir;      // the direction from start to end
00160     REAL dbegin;    // the start position
00161     eCoord beg,end;  // start and end points
00162     REAL tBeg,tEnd; // start and end time
00163 
00164     unsigned short inGrid;   // are we planned to be insite the grid?
00165     REAL           gridding; // when are we going to enter the grid?
00166     bool           preliminary:1; // is it a eWall preliminary installed?
00167     REAL           obsoleted_;    // the game time this preliminary wall got obsoleted by a final wall (negative if it is not yet obsolete)
00168     // by the client while it is waiting for the real eWall from the server?
00169 
00170     void CreateEdge();
00171     void InitArray();
00172     void MyInitAfterCreation();
00173     void real_CopyIntoGrid(eGrid *grid);
00174     void PartialCopyIntoGrid(eGrid *grid);
00175     void real_Update(REAL tEnd,const eCoord &pend, bool force );
00176 public:
00177     virtual void InitAfterCreation();
00178     gNetPlayerWall(gCycle *c,
00179                    const eCoord &beg,const eCoord &dir,
00180                    REAL tBeg, REAL dbeg);
00181 
00182     //  void Update(REAL tEnd,REAL dend);
00183     void Update(REAL tEnd,const eCoord &pend);
00184     void CopyIntoGrid(eGrid *grid,bool force=false);
00185     static void s_CopyIntoGrid();
00186     void RealWallReceived( gNetPlayerWall* realwall );
00187     void Checkpoint(); 
00188 
00189     gNetPlayerWall(nMessage &m);
00190 
00191     //eCoord Vec(){return w->Vec();}
00192     eCoord Vec();  
00193 #ifdef HUD_MAP
00194     tArray<gPlayerWallCoord> &Coords() { return coords_; }
00195 #endif
00196 protected:
00197     virtual ~gNetPlayerWall();
00198     void ReleaseData(); // release all references
00199 public:
00200     void SetEndTime(REAL et);
00201     void SetEndPos(REAL ep);
00202 
00203     int  IndexAlpha(REAL a) const;
00204     int  IndexPos(REAL d) const;
00205     REAL Time(REAL a) const;
00206     REAL Pos(REAL a) const;
00207     REAL Alpha(REAL pos) const;
00208     bool IsDangerousAnywhere( REAL time ) const;
00209     bool IsDangerousApartFromHoles( REAL a, REAL time ) const; // checks all danger signs, except hooles
00210     bool IsDangerous( REAL a, REAL time ) const;               // checks all danger signs
00211     gExplosion * Holer( REAL a, REAL time ) const;                 // returns the cycle responsible for a hole
00212 
00213     void BlowHole       ( REAL dbeg, REAL dend, gExplosion * holer ); // blow a hole into the wall form distance dbeg to dend
00214 
00215     REAL BegPos() const;
00216     REAL EndPos() const;
00217     REAL BegTime() const;
00218     REAL EndTime() const;
00219 
00220     const eCoord& EndPoint(int i) const
00221     {
00222         switch ( i )
00223         {
00224         case 0:
00225             return beg;
00226         case 1:
00227         default:
00228             return end;
00229         }
00230     }
00231 
00232 
00233 #ifndef DEDICATED
00236     enum gWallRenderMode
00237     {
00238         gWallRenderMode_Lines = 1,
00239         gWallRenderMode_Quads = 2,
00240         gWallRenderMode_All =   3
00241     };
00242 
00243     virtual void Render(const eCamera *cam);
00244     void RenderList(bool list, gWallRenderMode mode = gWallRenderMode_All );
00245     virtual void RenderNormal(const eCoord &x1,const eCoord &x2,REAL ta,REAL te,REAL r,REAL g,REAL b,REAL a, gWallRenderMode mode );
00246     virtual void RenderBegin(const eCoord &x1,const eCoord &x2,REAL ta,REAL te,REAL ra,REAL rb,REAL r,REAL g,REAL b,REAL a);
00247 #endif
00248 
00249     virtual bool ActionOnQuit();
00250 
00251     virtual bool ClearToTransmit(int user) const;
00252 
00253     virtual void WriteSync(nMessage &m);
00254     virtual void ReadSync(nMessage &m);
00255 
00256     virtual void WriteCreate(nMessage &m);
00257     virtual nDescriptor &CreatorDescriptor() const;
00258     virtual void PrintName(tString &s) const;
00259 
00260     virtual bool SyncIsNew(nMessage &m);
00261 
00262 
00263     eTempEdge   *Edge(){return this->edge_;}
00264     gPlayerWall *Wall();
00265     gCycle *Cycle() const {return this->cycle_;}
00266     gCycleMovement *CycleMovement() const;
00267 
00268     bool Preliminary()const{return preliminary;}
00269     bool InGrid()const{return inGrid;}
00270 
00271     static void Clear(); // delete all sg_netPlayerWalls.
00272 
00273     void Check() const;
00274 
00275     bool HasDisplayList()
00276     {
00277         return displayList_.IsSet();
00278     }
00279 
00280     bool CanHaveDisplayList()
00281     {
00282         return !displayList_.IsInhibited();
00283     }
00284 
00286     void ClearDisplayList( int inhibitThis = 2, int inhibitCycle = 0 );
00287 private:
00288     tArray<gPlayerWallCoord> coords_;
00289 
00290     rDisplayList displayList_;
00291 };
00292 
00293 extern tList<gNetPlayerWall> sg_netPlayerWalls;
00294 extern tList<gNetPlayerWall> sg_netPlayerWallsGridded;
00295 
00296 #endif

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