aboutsummaryrefslogtreecommitdiff
path: root/src/parsec_server/include/e_world.h
blob: d69fa697ba9433ff4ddd65400d3af9a47329126c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
/*
* PARSEC HEADER: E_WORLD.H
*/

#ifndef _E_WORLD_H_
#define _E_WORLD_H_
#include "parttype.h"

// flags ----------------------------------------------------------------------
//
//#define _SERVER_HAS_PARTICLE_CODE

// size of generic particle cluster
#define DEFAULT_CLUSTER_SIZE				256

// size of customdraw particle cluster
#define DEFAULT_CUSTOMDRAW_CLUSTER_SIZE		32

// size of genobject particle cluster
#define DEFAULT_GENOBJECT_CLUSTER_SIZE		128

// particle sphere rotation velocities
#define SPHERE_ROT_PITCH					0x0015  //0x01a0
#define SPHERE_ROT_YAW						-0x0022 //-0x02a0
#define SPHERE_ROT_ROLL						0x000d  //0x0100

// properties of pulsating sphere
#define SPHERE_PULSE_AMPLITUDE				FLOAT_TO_GEOMV( 12.0f )
#define SPHERE_PULSE_FREQUENCY				90

// properties of stochastic motion sphere
#define SPHERE_STOCHASTIC_MOTION_SPEED		100

// maximum number of registered particle definitions
#define MAX_PARTICLE_DEFS					256

#define PRTSB_ENERGYFIELD				PRT_NO_SIZEBOUND
// properties of energy field
#define ENERGY_FIELD_INITIAL_RADIUS 		FLOAT_TO_GEOMV( 0.0625f )
#define ENERGY_FIELD_LIFETIME				10000
#define SPHERE_PARTICLE_COLOR				255

// swarm behaviour constants --------------------------------------------------
//
#define NUM_PARTICLES		15						// number of particles in swarm
#define TIME_POSITIONS		3						// number of time positions recorded
#define PARTICLE_ACCEL		FLOAT_TO_GEOMV( 0.8f )	// acceleration of particles
#define PARTICLE_VELOCITY	FLOAT_TO_GEOMV( 2.0f )	// maximum particle velocity
#define PARTICLE_REFZ		300.0f					// particle refz
#define PARTICLE_LIFETIME	3000					// average lifetime of particles
#define LIFETIME_VARIANCE	400						// a small variance to avoid that all particles
// vanish at the same time
#define ANIM_TIMESLICE		6						// animate as if CurScreenRefFrames == 6
#define LIFETIME_AFTEREXPL	1200					// lifetime of particles after ship destruction


// swarm state structure ------------------------------------------------------
//
struct swarm_state_s {
    
	int						num;		// number of particles
	Point3h_f*				pos;		// current particle positions
    
	geomv_t*				x;			// particle position x[ time ][ partnum ]
	geomv_t*				y;			// particle position y[ time ][ partnum ]
	geomv_t*				z;			// particle position z[ time ][ partnum ]
    
	geomv_t*				xv;			// particle velocities xv[ partnum ]
	geomv_t*				yv;			// particle velocities xv[ partnum ]
	geomv_t*				zv;			// particle velocities xv[ partnum ]
    
	geomv_t					tx[ 3 ];	// target positions x
	geomv_t					ty[ 3 ];	// target positions y
	geomv_t					tz[ 3 ];	// target positions z
    
	ShipObject*				targetpo;	// the target object
	refframe_t				timerest;	// excess time from last animation frame
	GenObject				dummyobj; 	// just for sound position tracking
};

// photon properties
#define MIN_PHOTON_ENERGY                    10
#define PHOTON_ENERGY_CONSUMPTION           0x6000  // 0x10000 = 1.0

#define PHOTON_ROT_PITCH					0x0015  //0x01a0
#define PHOTON_ROT_YAW						-0x0022 //-0x02a0
#define PHOTON_ROT_ROLL						0x000d  //0x0100

#define PHOTON_SPHERE_PARTICLES				256
#define PHOTON_COLOR						123
#define PHOTON_REF_Z						75.0
#define PHOTON_CONTRACTION_TIME				50
#define PHOTON_CONTRACTION_SPEED			FIXED_TO_GEOMV( 0xA000 )
#define PHOTON_MAX_LOADING_TIME				1800
#define PHOTON_NUMLOADS						32

// helper macros --------------------------------------------------------------
//
#define X( t, b )			( swarm->x[ ( t ) * swarm->num + ( b ) ] )
#define Y( t, b )			( swarm->y[ ( t ) * swarm->num + ( b ) ] )
#define Z( t, b )			( swarm->z[ ( t ) * swarm->num + ( b ) ] )
#define balance_rand( v )	( ( SWARM_rand() % v ) - ( ( v ) / 2 ) )

#define LIGHTNING_SIZZLE_SPEED		10

static unsigned long int nextrand = 1;

int SWARM_rand();
void SWARM_srand( unsigned int seed );
void SWARM_TimedAnimate( callback_pcluster_s* cluster );

// class representing the PARSEC game world -----------------------------------
//
class E_World
{
public:

	// singly-linked lists for specific kinds of geometric objects ------------
	//
	ShipObject*		m_PShipObjects; // list of existing spacecraft objects
	LaserObject*	m_LaserObjects; // list of existing laser objects
	MissileObject*	m_MisslObjects; // list of existing missile objects
	ExtraObject*	m_ExtraObjects; // list of existing extras (power-ups)
	CustomObject*	m_CustmObjects; // list of existing custom objects
       
	int				m_last_summoned_objectid;		// object id of last object summoned

	// client -> e_global.h
	// current and maximum number of extras 
	int				m_nCurrentNumExtras;
	int				m_nCurrentNumPrtExtras;

	// next object number available 
	dword			NextObjNumber; // 0 is free for special purposes

	// table of object classes (from which objects can be instantiated) -----------
	//
	GenObject*		ObjClasses[ MAX_DISTINCT_OBJCLASSES ];

    // counters for concurrently displayed laser objects ---------------------
	int 			MaxNumShots;
	int 			NumShots;

protected:
	int _CountGenObjects( GenObject* walklist );

	// free memory occupied by an object
	void _FreeObjectMem( GenObject* objectpo );

	// invoke constructor of custom object
	void _InvokeCustomConstructor( GenObject* objectpo );

	// invoke destructor of custom object
	void _InvokeCustomDestructor( GenObject* objectpo );

	// kill all instances of passed in object class (search only one list)
	//
	int _KillClassInstancesFromList( int objclass, GenObject *listpo );

	// init object maintenance structures
	void _InitObjCtrl();
    
    //Cluster behaviour 
    void AnimateClusterBehavior( pcluster_s *cluster );
    void CalcConstantVelocityAnimation( linear_pcluster_s *cluster );
    void CalcSphereParticlePosition( Vertex3& position, geomv_t radius, int spheretype );
    void CalcSphereParticleExplosion( Vertex3& position, geomv_t speed );
    void CalcSpherePulse( Vertex3& position, Vertex3& pulsebase, geomv_t pulseval );
    int CalcSphereContraction( Vertex3& position, geomv_t speed );
    void CalcSphereParticleRotation( Vertex3& position, bams_t pitch, bams_t yaw, bams_t roll );
    void CalcSphereObjectAnimation( sphereobj_pcluster_s *cluster );
    void CalcCallbackTrajectoryAnimation( callback_pcluster_s *cluster );
    void CalcLightningAnimation( lightning_pcluster_s *cluster );
    void SetLightningParticlePosition( lightning_pcluster_s *cluster, particle_s particles[], Vertex3& current, Xmatrx tmatrx );
    //Particle disable/delete
    void DisableParticle( pcluster_s *cluster, int pid );
    void PRT_DeleteCluster (pcluster_s* cluster);
    void PRT_RemoveClusterFromAttachedList (objectbase_pcluster_s* cluster);
    
    
	// standard ctor
	E_World();

public:

	// SINGLETON access
	static E_World* GetWorld()
	{
		static E_World _TheWorld;
		return &_TheWorld;
	}

	// correct pointers that have moved after object was instantiated
	void OBJ_CorrectObjectInstance( GenObject *dstobj, GenObject *srcobj );

	CustomObject *CreateVirtualObject( dword objtypeid, dword dwOwner );

	// create object of class at position with orientation
	GenObject* CreateObject( int objclass, const Xmatrx startmatrx, dword dwOwner );

	// kill object contained in specific object list (search only one list)
	int KillSpecificObject( dword objno, GenObject *listpo );

	// kill a specific ship object from a list
	int	KillSpecificShipObject( dword objno );

	// object counting
	int GetNumShipObjects()			{ return _CountGenObjects( m_PShipObjects ); }
	int GetNumLaserObjects()		{ return _CountGenObjects( m_LaserObjects ); }
	int GetNumMisslObjects()		{ return _CountGenObjects( m_MisslObjects ); }
	int GetNumExtraObjects()		{ return _CountGenObjects( m_ExtraObjects ); }
	int GetNumCustmObjects()		{ return _CountGenObjects( m_CustmObjects ); }

	// return the object id of the last object that was summoned
	int	GetLastSummonedObjectID()   { return m_last_summoned_objectid; }

	// return pointer to first "real" ship in ship-objects list
	ShipObject* FetchFirstShip();

	// return pointer to first laser in laser-objects list 
	LaserObject* FetchFirstLaser() { return (LaserObject*) m_LaserObjects->NextObj; }

	// return pointer to first missile in missile-objects list
	MissileObject* FetchFirstMissile() { return (MissileObject*) m_MisslObjects->NextObj; }

	// return pointer to first extra in extra-objects list
	ExtraObject* FetchFirstExtra()	{ return (ExtraObject *) m_ExtraObjects->NextObj; }

	// return pointer to first custom object in custom-objects list
	CustomObject* FetchFirstCustom() { return  (CustomObject *) m_CustmObjects->NextObj; }

	// fetch object contained in specific object list
	GenObject* FetchSpecificObject( dword objno, GenObject* listpo );

	// fetch object via object id (search in all object lists)
	GenObject* FetchObject( dword objno );
    GenObject* SWARM_Init( int owner, Vertex3 *origin, ShipObject *targetpo, int randseed );

	// free memory occupied by an object
	void FreeObjectMem( GenObject *objectpo );

	// free all object memory blocks contained in specific list
	int FreeObjList( GenObject* listpo );

	// free all object memory blocks
	int FreeObjects();

	// free all objects and particles
	void KillAllObjects();

	// kill all instances of passed in object class (search in all object lists)
	int KillClassInstances( int objclass );

	//FIXME: here ?
	void IncreaseShotCounter();

	//FIXME: here ?
	void DecreaseShotCounter();
    
    //Energy Field
    void SFX_CreateEnergyField( Vertex3& origin );
    
    //particle man
    void InitParticleSystem();
    void PRT_InitParticle (particle_s&	particle,int color,int sizebound,float refz,Vertex3* position,Vector3* velocity, int lifetime,int	owner,pextinfo_s* extinfo);
    void PRT_InitClusterParticle (pcluster_s*	cluster,int	pid,int	bitmap,int color, int sizebound,float refz,Vertex3* position,Vector3*	velocity,int lifetime,int owner,pextinfo_s*	extinfo);
    void PRT_AttachClusterToObject( GenObject* genobjpo, objectbase_pcluster_s* cluster );
    int  PRT_DeleteAttachedClustersOfType( const GenObject * genobjpo, int animtype );
    void PRT_DeleteCluster_NoListRemoval( pcluster_s* cluster );
    
    // allocate new particle cluster and insert into list -------------------------
    //
    pcluster_s* PRT_NewCluster (dword type, int numelements, size_t auxstorage);

    particle_s* PRT_CreateLinearParticle (particle_s&	particle);
    sphereobj_pcluster_s* PRT_CreateParticleSphereObject (Vertex3& origin,geomv_t radius,int animtype,int clustersiz,int lifetime,pdrwinfo_s* pdinfo,int owner);
    
    pdef_s* PRT_AcquireParticleDefinitionById(int pdefid );
    pdef_s* PRT_AcquireParticleDefinition(const char* pdefname,int* retpdefid);
    objectbase_pcluster_s* PRT_ObjectHasAttachedClustersOfType( GenObject* genobjpo, int animtype );
    
    //Particle Animation call
    void PAN_AnimateParticles();
    int SWARM_Animate( callback_pcluster_s* cluster );
    
    //Lightning particles
    lightning_pcluster_s* CreateLightningParticles( ShipObject *shippo, int owner );
    
    //Photon
    photon_sphere_pcluster_s* CreatePhotonSphere( ShipObject *shippo );
    void CalcPhotonSphereAnimation( photon_sphere_pcluster_s *cluster );
};

#endif // _E_WORLD_H_