3
*************************************************************************
5
ArmageTron -- Just another Tron Lightcycle Game in 3D.
6
Copyright (C) 2000 Manuel Moos (manuel@moosnet.de)
8
**************************************************************************
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.
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.
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.
24
***************************************************************************
28
#ifndef ArmageTron_GAMEOBJECT_H
29
#define ArmageTron_GAMEOBJECT_H
46
// a generic object for the game (cycles,explosions, particles,
47
// maybe AI opponents..)
53
friend class ePlayerNetID;
55
// a list of all active gameobjects
57
#define GO ((eGameObject *)NULL)
58
#define GO_I ((int *)NULL)
60
// small wrapper of TimestepThis doing preparation and cleanup work
61
static void TimestepThisWrapper(eGrid * grid, REAL currentTime, eGameObject *t, REAL minTimestep);
64
// does a timestep and all interactions for this gameobject,
65
// divided in many small steps
66
static bool TimestepThis(REAL currentTime,eGameObject *t);
68
// tells game objects how far they are allowed to exeed the given simulation time
69
static REAL MaxSimulateAhead();
71
// a list of all eGameObjects that are interesting to watch
75
// shall s_Timestep delete a eGameObject requesting destruction
76
// completely (autodelete=1) or should it just be removed from the list
78
// (the latter may be useful if there exists other pointers to
83
REAL lastTime; // the time it was last updated
84
REAL deathTime; // the time the thing died
86
eCoord pos; // current position,
87
eCoord dir; // direction
88
REAL z; // and height (currently unused)
90
tJUST_CONTROLLED_PTR< eTeam > team; // the team we belong to
92
tJUST_CONTROLLED_PTR<eFace> currentFace; // the eFace pos it is currently
93
tCHECKED_PTR(eGrid) grid; // the game grid we are on
95
// entry and deletion in the list of all eGameObjects
97
//! tells game objects what the maximum lag caused by lazy simulation of timesteps is
98
static REAL GetMaxLazyLag();
99
//! sets the value reported by GetMaxLazyLag()
100
static void SetMaxLazyLag( REAL lag );
102
eTeam* Team() const { return team; }
104
static uActionPlayer se_turnLeft,se_turnRight;
106
eGrid* Grid() const { return grid; }
107
eFace* CurrentFace() const { return currentFace; }
109
virtual void AddRef() = 0; //!< adds a reference
110
virtual void Release() = 0; //!< removes a reference
113
void RemoveFromList();
114
void RemoveFromListsAll();
115
void RemoveFromGame(); //!< removes the object physically from the game
118
virtual void OnRemoveFromGame(); //!< called on RemoveFromGame(). Call base class implementation, too, in your implementation. Must keep the object alive.
120
virtual void DoRemoveFromGame(); //!< called on RemoveFromGame() after OnRemoveFromGame(). Do not call base class implementation of this function, don't expect to get called from subclasses.
123
int GOID() const {return id;}
124
REAL LastTime() const {return lastTime;}
125
virtual REAL NextInterestingTime() const {return lastTime;} //!< the next time something interesting is going to happen with this object
127
eGameObject(eGrid *grid, const eCoord &p,const eCoord &d, eFace *currentface, bool autodelete=1);
128
virtual ~eGameObject();
130
virtual eCoord Position()const{return pos;}
131
virtual eCoord Direction()const{return dir;}
132
virtual eCoord LastDirection()const{return dir;}
133
virtual REAL DeathTime()const{return deathTime;}
134
virtual REAL Speed()const{return 20;}
136
// position after FPS dependant extrapolation
137
virtual eCoord PredictPosition() const {return pos;}
139
// makes two gameObjects interact:
140
virtual void InteractWith( eGameObject *target,REAL time,int recursion=1 );
142
// what happens if we pass eWall w? (at position e->p[0]*a + e->p[1]*(1-a) )
143
virtual void PassEdge( const eWall *w,REAL time,REAL a,int recursion=1 );
145
// what length multiplicator does driving along the given wall get when it is the given distance away?
146
virtual REAL PathfindingModifier( const eWall *w ) const { return 1 ;}
148
// moves the object from pos to dest during the timeinterval
149
// [startTime,endTime] and issues all eWall-crossing tEvents
150
void Move( const eCoord &dest, REAL startTime, REAL endTime, bool useTempWalls = true );
152
// finds the eFace we are in
153
void FindCurrentFace();
155
// simulates behaviour up to currentTime:
156
virtual bool Timestep(REAL currentTime);
157
// return value: shall this object be destroyed?
159
virtual bool EdgeIsDangerous(const eWall *w, REAL time, REAL a) const{
163
//! called when the round begins, after all game objects have been created,
164
//! before the first network sync is sent out.
165
virtual void OnRoundBegin();
167
//! called when the round ends
168
virtual void OnRoundEnd();
170
//! destroys the gameobject (in the game)
173
//! tells whether the object is alive
174
virtual bool Alive() const {return false;}
176
//! draws object to the screen using OpenGL
177
virtual void Render(const eCamera *cam);
179
//! draws it in a svg file
180
virtual void DrawSvg(std::ofstream &f);
182
//! returns whether the rendering uses alpha blending (massively, so sorting errors would show)
183
virtual bool RendersAlpha() const;
185
// draws the cockpit or whatever is seen from the interior
186
// in fixed perspective, called before the main rendering
187
virtual bool RenderCockpitFixedBefore(bool primary=true);
188
// return value: draw everything else?
190
// the same purpose, but called after main rendering
191
virtual void RenderCockpitFixedAfter(bool primary=true);
193
// virtual perspective
194
virtual void RenderCockpitVirtual(bool primary=false);
197
virtual void SoundMix(unsigned char *dest,unsigned int len,
198
int viewer,REAL rvol,REAL lvol){};
201
virtual eCoord CamDir() const {return dir;}
202
virtual REAL CamRise() const {return 0;}
203
virtual eCoord CamPos() const {return pos;}
204
virtual REAL CamZ() const {return z;}
205
virtual eCoord CamTop() const {return eCoord(0,0);}
208
virtual REAL Lag() const{return 0;} //!< expected average network latency
209
virtual REAL LagThreshold() const{return 0;} //!< tolerated network latency variation
212
virtual void PPDisplay();
215
// Receives control from ePlayer
216
virtual bool Act(uActionPlayer *Act,REAL x);
218
// does a timestep and all interactions for every gameobject
219
static void s_Timestep(eGrid *grid, REAL currentTime, REAL minTimestep);
221
// displays everything:
222
static void RenderAll(eGrid *grid, const eCamera *cam);
223
static void PPDisplayAll();
226
static void DeleteAll(eGrid *grid);
229
// game object to be created on the heap
230
class eReferencableGameObject: public eGameObject, public tReferencable< eReferencableGameObject >
233
eReferencableGameObject(eGrid *grid, const eCoord &p,const eCoord &d, eFace *currentface, bool autodelete=1);
235
// real reference counting
236
virtual void AddRef(); //!< adds a reference
237
virtual void Release(); //!< removes a reference
240
virtual void DoRemoveFromGame(); //!< called when removed from the game
243
// game object of temporary lifetime on the stack. Don't dynamically allocate this.
244
class eStackGameObject: public eGameObject
247
eStackGameObject(eGrid *grid, const eCoord &p,const eCoord &d, eFace *currentface);
249
// dummy reference counting
250
virtual void AddRef(); //!< adds a reference
251
virtual void Release(); //!< removes a reference
254
virtual void DoRemoveFromGame(); //!< called when removed from the game
257
//! Exception to throw when a gameobject dies during movement
261
eDeath(){}; //!< constructor
262
~eDeath(){}; //!< destructor