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
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//=============================================================================//
#ifndef ENV_METEOR_SHARED_H
#define ENV_METEOR_SHARED_H
#pragma once
#include "vstdlib/random.h"
#include "mathlib/vector.h"
#include "utlvector.h"
//=============================================================================
//
// Shared Meteor Class
//
#define METEOR_INVALID_TIME -9999.9f
#define METEOR_PASSIVE_TIME 0.0f
#define METEOR_MAX_LIFETIME 60.0f
#define METEOR_MIN_SIZE Vector( -100, -100, -100 )
#define METEOR_MAX_SIZE Vector( 100, 100, 100 )
#define METEOR_LOCATION_INVALID -1
#define METEOR_LOCATION_WORLD 0
#define METEOR_LOCATION_SKYBOX 1
class CEnvMeteorShared
{
public:
//-------------------------------------------------------------------------
// Initialization.
//-------------------------------------------------------------------------
CEnvMeteorShared();
void Init( int nID, float flStartTime, float flPassiveTime,
const Vector &vecStartPosition,
const Vector &vecDirection, float flSpeed, float flDamageRadius,
const Vector &vecTriggerMins, const Vector &vecTriggerMaxs );
//-------------------------------------------------------------------------
// Returns the position of the object at a given time.
//-------------------------------------------------------------------------
void GetPositionAtTime( float flTime, Vector &vecPosition );
//-------------------------------------------------------------------------
// Changes an objects paramters from "skybox space" to "world space."
//-------------------------------------------------------------------------
void ConvertFromSkyboxToWorld( void );
//-------------------------------------------------------------------------
// Changes an objects paramters from "world space" to "skybox space."
//-------------------------------------------------------------------------
void ConvertFromWorldToSkybox( void );
//-------------------------------------------------------------------------
// Returns whether or not the object is the the skybox given the time.
//-------------------------------------------------------------------------
bool IsInSkybox( float flTime );
//-------------------------------------------------------------------------
// Returns whether or not the object is moving in the skybox (or passive).
//-------------------------------------------------------------------------
bool IsPassive( float flTime );
//-------------------------------------------------------------------------
// Returns whether or not the object will ever transition from skybox to world.
//-------------------------------------------------------------------------
bool WillTransition( void );
//-------------------------------------------------------------------------
// Returns the splash damage radius of the object.
//-------------------------------------------------------------------------
float GetDamageRadius( void );
public:
int m_nID; // unique identifier
// The objects initial parametric conditions.
Vector m_vecStartPosition;
Vector m_vecDirection;
float m_flSpeed; // (units/sec), unit = 1 inch
float m_flStartTime;
// NOTE: All times are absolute - ie m_flStartTime has been added in.
// The time after the starting time in which it object starts to "move."
float m_flPassiveTime;
// The enter and exit times define the times at which the object enters and
// exits the world. In other words, m_flEnterTime is the time at which the
// object leaves the skybox and enters the world. m_flExitTime is the opposite.
float m_flWorldEnterTime;
float m_flWorldExitTime;
float m_flPosTime; // Timer used to find the position of the meteor.
Vector m_vecPos;
//
int m_nLocation; // 0 = Skybox, 1 = World
float m_flDamageRadius; //
private:
// Calculate the enter/exit times. (called from Init)
void CalcEnterAndExitTimes( const Vector &vecTriggerMins, const Vector &vecTriggerMaxs );
};
//=============================================================================
//
// Meteor Factory Interface
//
abstract_class IMeteorFactory
{
public:
virtual void CreateMeteor( int nID, int iType,
const Vector &vecPosition, const Vector &vecDirection,
float flSpeed, float flStartTime, float flDamageRadius,
const Vector &vecTriggerMins, const Vector &vecTriggerMaxs ) = 0;
};
//=============================================================================
//
// Shared Meteor Spawner Class
//
class CEnvMeteorSpawnerShared
{
public:
DECLARE_CLASS_NOBASE( CEnvMeteorSpawnerShared );
DECLARE_EMBEDDED_NETWORKVAR();
//-------------------------------------------------------------------------
// Initialization.
//-------------------------------------------------------------------------
CEnvMeteorSpawnerShared();
void Init( IMeteorFactory *pFactory, int nRandomSeed, float flTime,
const Vector &vecMinBounds, const Vector &vecMaxBounds,
const Vector &vecTriggerMins, const Vector &vecTriggerMaxs );
//-------------------------------------------------------------------------
// Method to generate meteors.
// Time passed in here is global time, not delta time.
// The function returns the time at which it must be called again.
//-------------------------------------------------------------------------
float MeteorThink( float flTime );
//-------------------------------------------------------------------------
// Add meteor target data, used to determine meteor travel direction.
//-------------------------------------------------------------------------
void AddToTargetList( const Vector &vecPosition, float flRadius );
// Debugging!
int GetRandomInt( int nMin, int nMax );
float GetRandomFloat( float flMin, float flMax );
public:
// Factory.
IMeteorFactory *m_pFactory; // Meteor creation factory.
int m_nMeteorCount; // Number of meteors created - used as IDs
// Initial spawner data.
CNetworkVar( float, m_flStartTime ); // Start time.
CNetworkVar( int, m_nRandomSeed ); // The random number stream seed.
CNetworkVar( int, m_iMeteorType ); // Type of meteor.
float m_flMeteorDamageRadius; // Meteor damage radius.
CNetworkVar( bool, m_bSkybox ); // Is the spawner in the skybox?
CNetworkVar( float, m_flMinSpawnTime ); // Spawn time - Min
CNetworkVar( float, m_flMaxSpawnTime ); // Max
CNetworkVar( int, m_nMinSpawnCount ); // Number of meteors to spawn - Min
CNetworkVar( int, m_nMaxSpawnCount ); // Max
CNetworkVector( m_vecMinBounds ); // Spawner volume (space) - Min
CNetworkVector( m_vecMaxBounds ); // Max
CNetworkVar( float, m_flMinSpeed ); // Meteor speed - Min
CNetworkVar( float, m_flMaxSpeed ); // Max
CNetworkVector( m_vecTriggerMins ); // World Bounds (Trigger) in 3D Skybox - Min
CNetworkVector( m_vecTriggerMaxs ); // Max
Vector m_vecTriggerCenter;
// Generated data.
int m_nRandomCallCount; // Debug! Keep track of number steam calls.
float m_flNextSpawnTime; // Next meteor spawn time (random).
CUniformRandomStream m_NumberStream; // Used to generate random numbers.
// Use "Targets" to determine meteor direction(s).
struct meteortarget_t
{
Vector m_vecPosition;
float m_flRadius;
};
CUtlVector<meteortarget_t> m_aTargets;
};
#endif // ENV_METEOR_SHARED_H
|