forked from ValveSoftware/source-sdk-2013
-
Notifications
You must be signed in to change notification settings - Fork 169
Expand file tree
/
Copy pathvscript_funcs_shared.h
More file actions
338 lines (272 loc) · 11.4 KB
/
Copy pathvscript_funcs_shared.h
File metadata and controls
338 lines (272 loc) · 11.4 KB
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
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
//========= Mapbase - https://github.com/mapbase-source/source-sdk-2013 =================
//
// Purpose: See vscript_funcs_shared.cpp
//
// $NoKeywords: $
//=============================================================================
#ifndef VSCRIPT_FUNCS_SHARED
#define VSCRIPT_FUNCS_SHARED
#ifdef _WIN32
#pragma once
#endif
#include "npcevent.h"
#ifdef GAME_DLL
#include "ai_memory.h"
#endif
//-----------------------------------------------------------------------------
// Exposes surfacedata_t to VScript
//-----------------------------------------------------------------------------
struct scriptsurfacedata_t : public surfacedata_t
{
public:
float GetFriction() const { return physics.friction; }
float GetThickness() const { return physics.thickness; }
float GetJumpFactor() const { return game.jumpFactor; }
char GetMaterialChar() const { return game.material; }
const char* GetSoundStepLeft() const { return physprops->GetString( sounds.stepleft ); }
const char* GetSoundStepRight() const { return physprops->GetString( sounds.stepright ); }
const char* GetSoundImpactSoft() const { return physprops->GetString( sounds.impactSoft ); }
const char* GetSoundImpactHard() const { return physprops->GetString( sounds.impactHard ); }
const char* GetSoundScrapeSmooth() const { return physprops->GetString( sounds.scrapeSmooth ); }
const char* GetSoundScrapeRough() const { return physprops->GetString( sounds.scrapeRough ); }
const char* GetSoundBulletImpact() const { return physprops->GetString( sounds.bulletImpact ); }
const char* GetSoundRolling() const { return physprops->GetString( sounds.rolling ); }
const char* GetSoundBreak() const { return physprops->GetString( sounds.breakSound ); }
const char* GetSoundStrain() const { return physprops->GetString( sounds.strainSound ); }
};
//-----------------------------------------------------------------------------
// Exposes csurface_t to VScript
//-----------------------------------------------------------------------------
class CSurfaceScriptHelper
{
public:
CSurfaceScriptHelper() : m_pSurface(NULL), m_hSurfaceData(NULL) {}
~CSurfaceScriptHelper()
{
if ( m_hSurfaceData )
{
g_pScriptVM->RemoveInstance( m_hSurfaceData );
}
}
void Init( csurface_t *surf )
{
m_pSurface = surf;
m_hSurfaceData = g_pScriptVM->RegisterInstance(
reinterpret_cast< scriptsurfacedata_t* >( physprops->GetSurfaceData( m_pSurface->surfaceProps ) ) );
}
const char* Name() const { return m_pSurface->name; }
HSCRIPT SurfaceProps() const { return m_hSurfaceData; }
private:
csurface_t *m_pSurface;
HSCRIPT m_hSurfaceData;
};
//-----------------------------------------------------------------------------
// Exposes cplane_t to VScript
//-----------------------------------------------------------------------------
class CPlaneTInstanceHelper : public IScriptInstanceHelper
{
bool Get( void *p, const char *pszKey, ScriptVariant_t &variant )
{
cplane_t *pi = ((cplane_t *)p);
if (FStrEq(pszKey, "normal"))
variant = pi->normal;
else if (FStrEq(pszKey, "dist"))
variant = pi->dist;
else
return false;
return true;
}
//bool Set( void *p, const char *pszKey, ScriptVariant_t &variant );
};
//-----------------------------------------------------------------------------
// Exposes trace_t to VScript
//-----------------------------------------------------------------------------
class CScriptGameTrace : public CGameTrace
{
public:
CScriptGameTrace() : m_surfaceAccessor(NULL), m_planeAccessor(NULL)
{
}
~CScriptGameTrace()
{
if ( m_surfaceAccessor )
{
g_pScriptVM->RemoveInstance( m_surfaceAccessor );
}
if ( m_planeAccessor )
{
g_pScriptVM->RemoveInstance( m_planeAccessor );
}
}
public:
float FractionLeftSolid() const { return fractionleftsolid; }
int HitGroup() const { return hitgroup; }
int PhysicsBone() const { return physicsbone; }
HSCRIPT Entity() const { return ToHScript( m_pEnt ); }
int HitBox() const { return hitbox; }
const Vector& StartPos() const { return startpos; }
const Vector& EndPos() const { return endpos; }
float Fraction() const { return fraction; }
int Contents() const { return contents; }
int DispFlags() const { return dispFlags; }
bool AllSolid() const { return allsolid; }
bool StartSolid() const { return startsolid; }
HSCRIPT Surface()
{
if ( !m_surfaceAccessor )
{
m_surfaceHelper.Init( &surface );
m_surfaceAccessor = g_pScriptVM->RegisterInstance( &m_surfaceHelper );
}
return m_surfaceAccessor;
}
HSCRIPT Plane()
{
if ( !m_planeAccessor )
m_planeAccessor = g_pScriptVM->RegisterInstance( &plane );
return m_planeAccessor;
}
void Destroy() {}
private:
HSCRIPT m_surfaceAccessor;
HSCRIPT m_planeAccessor;
CSurfaceScriptHelper m_surfaceHelper;
CScriptGameTrace( const CScriptGameTrace& v );
};
//-----------------------------------------------------------------------------
// Exposes animevent_t to VScript
//-----------------------------------------------------------------------------
struct scriptanimevent_t
{
friend class CAnimEventTInstanceHelper;
public:
scriptanimevent_t( animevent_t &event ) : event( event ), options( NULL ) { }
~scriptanimevent_t( ) { delete[] options; }
int GetEvent() { return event.event; }
void SetEvent( int nEvent ) { event.event = nEvent; }
const char *GetOptions() { return event.options; }
void SetOptions( const char *pOptions )
{
size_t len = strlen( pOptions );
delete[] options;
event.options = options = new char[len + 1];
memcpy( options, pOptions, len + 1 );
}
float GetCycle() { return event.cycle; }
void SetCycle( float flCycle ) { event.cycle = flCycle; }
float GetEventTime() { return event.eventtime; }
void SetEventTime( float flEventTime ) { event.eventtime = flEventTime; }
int GetType() { return event.type; }
void SetType( int nType ) { event.type = nType; }
HSCRIPT GetSource() { return ToHScript( event.pSource ); }
void SetSource( HSCRIPT hSource )
{
CBaseEntity *pEnt = ToEnt( hSource );
if (pEnt)
event.pSource = pEnt->GetBaseAnimating();
}
private:
animevent_t &event;
// storage for ScriptVariant_t string, which may be temporary
char *options;
};
class CAnimEventTInstanceHelper : public IScriptInstanceHelper
{
bool Get( void *p, const char *pszKey, ScriptVariant_t &variant );
bool Set( void *p, const char *pszKey, ScriptVariant_t &variant );
};
//-----------------------------------------------------------------------------
// Exposes EmitSound_t to VScript
//-----------------------------------------------------------------------------
struct ScriptEmitSound_t : public EmitSound_t
{
int GetChannel() { return m_nChannel; }
void SetChannel( int nChannel ) { m_nChannel = nChannel; }
const char *GetSoundName() { return m_pSoundName; }
void SetSoundName( const char *pSoundName ) { m_pSoundName = pSoundName; }
float GetVolume() { return m_flVolume; }
void SetVolume( float flVolume ) { m_flVolume = flVolume; }
int GetSoundLevel() { return m_SoundLevel; }
void SetSoundLevel( int iSoundLevel ) { m_SoundLevel = (soundlevel_t)iSoundLevel; }
int GetFlags() { return m_nFlags; }
void SetFlags( int nFlags ) { m_nFlags = nFlags; }
int GetPitch() { return m_nPitch; }
void SetPitch( int nPitch ) { m_nPitch = nPitch; }
int GetSpecialDSP() { return m_nSpecialDSP; }
void SetSpecialDSP( int nSpecialDSP ) { m_nSpecialDSP = nSpecialDSP; }
bool HasOrigin() { return m_pOrigin ? true : false; }
const Vector &GetOrigin() { return m_pOrigin ? *m_pOrigin : vec3_origin; }
void SetOrigin( const Vector &origin ) { static Vector tempOrigin; tempOrigin = origin; m_pOrigin = &tempOrigin; }
void ClearOrigin() { m_pOrigin = NULL; }
float GetSoundTime() { return m_flSoundTime; }
void SetSoundTime( float flSoundTime ) { m_flSoundTime = flSoundTime; }
// NOTE: Incorrectly returns float for boolean type.
// Fixing this would break scripts explicitly comparing against 0 or 1
// Keeping this would prevent implicit falseness check in a language such as Lua where 0.0 is truthy
float GetEmitCloseCaption() { return m_bEmitCloseCaption; }
void SetEmitCloseCaption( bool bEmitCloseCaption ) { m_bEmitCloseCaption = bEmitCloseCaption; }
float GetWarnOnMissingCloseCaption() { return m_bWarnOnMissingCloseCaption; }
void SetWarnOnMissingCloseCaption( bool bWarnOnMissingCloseCaption ) { m_bWarnOnMissingCloseCaption = bWarnOnMissingCloseCaption; }
float GetWarnOnDirectWaveReference() { return m_bWarnOnDirectWaveReference; }
void SetWarnOnDirectWaveReference( bool bWarnOnDirectWaveReference ) { m_bWarnOnDirectWaveReference = bWarnOnDirectWaveReference; }
int GetSpeakerEntity() { return m_nSpeakerEntity; }
void SetSpeakerEntity( int nSpeakerEntity ) { m_nSpeakerEntity = nSpeakerEntity; }
int GetSoundScriptHandle() { return m_hSoundScriptHandle; }
void SetSoundScriptHandle( int hSoundScriptHandle ) { m_hSoundScriptHandle = hSoundScriptHandle; }
};
//-----------------------------------------------------------------------------
// Exposes CUserCmd to VScript
//-----------------------------------------------------------------------------
class CScriptUserCmd : public CUserCmd
{
public:
int GetCommandNumber() { return command_number; }
int ScriptGetTickCount() { return tick_count; }
const QAngle& GetViewAngles() { return viewangles; }
void SetViewAngles( const QAngle& val ) { viewangles = val; }
float GetForwardMove() { return forwardmove; }
void SetForwardMove( float val ) { forwardmove = val; }
float GetSideMove() { return sidemove; }
void SetSideMove( float val ) { sidemove = val; }
float GetUpMove() { return upmove; }
void SetUpMove( float val ) { upmove = val; }
int GetButtons() { return buttons; }
void SetButtons( int val ) { buttons = val; }
int GetImpulse() { return impulse; }
void SetImpulse( int val ) { impulse = val; }
int GetWeaponSelect() { return weaponselect; }
void SetWeaponSelect( int val ) { weaponselect = val; }
int GetWeaponSubtype() { return weaponsubtype; }
void SetWeaponSubtype( int val ) { weaponsubtype = val; }
int GetRandomSeed() { return random_seed; }
int GetMouseX() { return mousedx; }
void SetMouseX( int val ) { mousedx = val; }
int GetMouseY() { return mousedy; }
void SetMouseY( int val ) { mousedy = val; }
};
#ifdef GAME_DLL
//-----------------------------------------------------------------------------
// Exposes AI_EnemyInfo_t to VScript
//-----------------------------------------------------------------------------
struct Script_AI_EnemyInfo_t : public AI_EnemyInfo_t
{
#define ENEMY_INFO_SCRIPT_FUNCS(type, name, var) \
type Get##name() { return var; } \
void Set##name( type v ) { var = v; }
HSCRIPT Enemy() { return ToHScript(hEnemy); }
void SetEnemy( HSCRIPT ent ) { hEnemy = ToEnt(ent); }
ENEMY_INFO_SCRIPT_FUNCS( Vector, LastKnownLocation, vLastKnownLocation );
ENEMY_INFO_SCRIPT_FUNCS( Vector, LastSeenLocation, vLastSeenLocation );
ENEMY_INFO_SCRIPT_FUNCS( float, TimeLastSeen, timeLastSeen );
ENEMY_INFO_SCRIPT_FUNCS( float, TimeFirstSeen, timeFirstSeen );
ENEMY_INFO_SCRIPT_FUNCS( float, TimeLastReacquired, timeLastReacquired );
ENEMY_INFO_SCRIPT_FUNCS( float, TimeValidEnemy, timeValidEnemy );
ENEMY_INFO_SCRIPT_FUNCS( float, TimeLastReceivedDamageFrom, timeLastReceivedDamageFrom );
ENEMY_INFO_SCRIPT_FUNCS( float, TimeAtFirstHand, timeAtFirstHand );
ENEMY_INFO_SCRIPT_FUNCS( bool, DangerMemory, bDangerMemory );
ENEMY_INFO_SCRIPT_FUNCS( bool, EludedMe, bEludedMe );
ENEMY_INFO_SCRIPT_FUNCS( bool, Unforgettable, bUnforgettable );
ENEMY_INFO_SCRIPT_FUNCS( bool, MobbedMe, bMobbedMe );
};
#endif
#endif