1 /*
2 
3 *************************************************************************
4 
5 ArmageTron -- Just another Tron Lightcycle Game in 3D.
6 Copyright (C) 2000  Manuel Moos (manuel@moosnet.de)
7 
8 **************************************************************************
9 
10 This program is free software; you can redistribute it and/or
11 modify it under the terms of the GNU General Public License
12 as published by the Free Software Foundation; either version 2
13 of the License, or (at your option) any later version.
14 
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 GNU General Public License for more details.
19 
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
23 
24 ***************************************************************************
25 
26 */
27 
28 #ifndef ArmageTron_WALL_H
29 #define ArmageTron_WALL_H
30 
31 // #include "eGrid.h"
32 #include "tHeap.h"
33 #include "eCoord.h"
34 
35 class eHalfEdge;
36 
37 // ******************************************************************
38 
39 
40 // ******************************************************************
41 
42 // a class for the different types of eWalls or similar objects
43 // (enery barriers, fault lines...) that may appear in the game
44 
45 //#ifdef WIN32
46 // disable a hack that apparently only works with gcc 2.95.x
47 //#define CAUTION_WALL
48 //#endif
49 
50 // uncomment to disable evil hack for all architectures
51 //#define CAUTION_WALL
52 
53 
54 
55 class eWall;
56 class eWallHolder;
57 class eGameObject;
58 class eCamera;
59 class eGrid;
60 
61 class eWallView:public tHeapElement{
62     friend class eWall;
63 protected:
64     virtual tHeapBase *Heap() const;
65 
66 #ifdef CAUTION_WALL
67     eWall *wall;
68 #endif
69 
70     int  viewer;
71 public:
eWallView()72     eWallView(){}
73     ~eWallView();
74 
Set(int view,eWall * mw)75     void Set(int view,eWall *mw){
76         viewer=view;
77 #ifdef CAUTION_WALL
78         wall=mw;
79 #endif
80     }
81 
Value()82     REAL Value(){return tHeapElement::Val();}
83     void SetValue(REAL v);
84 
85     eWall *Belongs();  // to wich wall do we belong?
86 
87 };
88 
89 class eWall: public tReferencable< eWall >{
90     friend class tReferencable< eWall >;
91     //friend class eHalfEdge;
92     //friend class eTempEdge;
93     friend class eWallView;
94     friend class eWallHolder;
95 
96     eWallView view[MAX_VIEWERS];
97 protected:
98     tCHECKED_PTR(eWallHolder)   holder_;
99     tJUST_CONTROLLED_PTR<eGrid> grid;
100     REAL                        len;
101     int                         flipped;
102 public:
103     int id;
104 
105     eWall(eGrid *grid);
106 
107     /*
108     	virtual void AddRef();
109     	virtual void Release();
110     	int GetRefcount();
111     */
112 
113     eHalfEdge* Edge()const;
114 
Len()115     REAL Len() const {return len;}
116 
117     void CalcLen();
118 
119     const eCoord& EndPoint(int i) const; // returns the coordinates of the beginning (i=0) or end (i=1) of this wall
120 
121     eCoord Point( REAL a ) const; // returns the coordinates somewhere between beginning and end
122 
123     eCoord Vec() const; // returns the vector from the beginning to the end of the wall
124 
125     // flip the fall
Flip()126     virtual void Flip(){flipped = 1-flipped;}
127 
128     // may we split the eWall in two?
129     virtual bool Splittable() const;
130 
131     // can we delete the eWall now?
132     virtual bool Deletable() const;
133 
134     // split the eWall in two with ratio a : 1-a
135     virtual void Split(eWall *& w1,eWall *& w2,REAL a);
136 
137     // split the wall absolutely correctly; update the grid accordingly.
138     void SplitComplete(eWall *& w1,eWall *& w2,REAL a);
139 
140     // is it still massive? (i.e. is the player it belongs to alive?)
Massive()141     virtual bool Massive() const{return true;}
142 
143     // what happens to a gameobject that passes here?
144     virtual void PassingGameObject(eGameObject *pass,REAL time,REAL pos,int recursion=1);
145 
146     // what happens if this wall, when layed out, turns out to cross another wall that was already there?
147     virtual void SplitByActive( eWall * oldWall );
148 
149     // the same question for the old wall.
150     virtual void SplitByPassive( eWall * newWall );
151 
152     // what happens if this wall, when layed out, turns out to be exactly parallel to another wall? The return value indicates if this operation is allowed.
153     virtual bool RunsParallelActive( eWall * oldWall );
154 
155     // the same seen from the other wall
156     virtual bool RunsParallelPassive( eWall * newWall );
157 #ifndef DEDICATED
158     //  static void Render_helper(eWall *w,REAL tBeg,REAL tEnd,REAL h=4,REAL hfrac=1,REAL bot=0);
159 
160     // draws it to the screen using OpenGL
Render(const eCamera * cam)161     virtual void Render(const eCamera *cam){};
162 #endif
163 
164     // can you see through it?
Height()165     virtual REAL Height() const{return 1;}
BlockHeight()166     virtual REAL BlockHeight() const{return 1;}
SeeHeight()167     virtual REAL SeeHeight() const{return 1;}
168 
169     inline void BlocksCamera( eCamera * cam, REAL height ) const; //!< called by the camera code when this wall is between the cycle and the camera
170 
171     void Insert();
172     void Remove();
173 
174     void SetVisHeight(int v,REAL h);
175 
176 protected:
177 
178     virtual void OnBlocksCamera( eCamera * cam, REAL height ) const; //!< called by the camera code when this wall is between the cycle and the camera
179 
180     virtual ~eWall();
181 private:
182 };
183 
184 class eWallHolder
185 {
186     friend class eWall;
187 public:
188     void SetWall( eWall* wall );
189     eWall* GetWall( void ) const;
190 
191 protected:
192     eWallHolder();
193     ~eWallHolder();
194 
195 private:
196     tCONTROLLED_PTR( eWall ) wall_;
197 };
198 
199 // TODO: get rid of these
200 extern tHeap<eWallView>  se_wallsVisible[MAX_VIEWERS];
201 
202 // *******************************************************************************************
203 // *
204 // *	BlocksCamera
205 // *
206 // *******************************************************************************************
207 //!
208 //! @param cam the camera that is blocked
209 //! @param height the maximal height the wall would be allowed to have without blocking the view
210 //!
211 // *******************************************************************************************
212 
BlocksCamera(eCamera * cam,REAL height)213 void eWall::BlocksCamera( eCamera * cam, REAL height ) const
214 {
215     OnBlocksCamera( cam, height );
216 }
217 
218 #endif
219 
220