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.cpp
More file actions
1118 lines (907 loc) · 42.5 KB
/
Copy pathvscript_funcs_shared.cpp
File metadata and controls
1118 lines (907 loc) · 42.5 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
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//========= Mapbase - https://github.com/mapbase-source/source-sdk-2013 ============//
//
// Purpose: This file contains general shared VScript bindings which Mapbase adds onto
// what was ported from Alien Swarm instead of cluttering the existing files.
//
// This includes various functions, classes, etc. which were either created from
// scratch or were based on/inspired by things documented in APIs from L4D2 or even
// Source 2 games like Dota 2 or Half-Life: Alyx.
//
// Other VScript bindings can be found in files like vscript_singletons.cpp and
// things not exclusive to the game DLLs are embedded/recreated in the library itself
// via vscript_bindings_base.cpp.
//
// $NoKeywords: $
//=============================================================================//
#include "cbase.h"
#include "matchers.h"
#include "takedamageinfo.h"
#ifndef CLIENT_DLL
#include "globalstate.h"
#include "vscript_server.h"
#include "soundent.h"
#include "rope.h"
#include "ai_basenpc.h"
#else
#include "c_rope.h"
#endif // CLIENT_DLL
#include "con_nprint.h"
#include "particle_parse.h"
#include "npcevent.h"
#include "vscript_funcs_shared.h"
#include "vscript_singletons.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
extern IScriptManager *scriptmanager;
#ifndef CLIENT_DLL
void EmitSoundOn( const char *pszSound, HSCRIPT hEnt )
{
CBaseEntity *pEnt = ToEnt( hEnt );
if (!pEnt)
return;
pEnt->EmitSound( pszSound );
}
void EmitSoundOnClient( const char *pszSound, HSCRIPT hEnt, HSCRIPT hPlayer )
{
CBaseEntity *pEnt = ToEnt( hEnt );
CBasePlayer *pPlayer = ToBasePlayer( ToEnt( hPlayer ) );
if (!pEnt || !pPlayer)
return;
CSingleUserRecipientFilter filter( pPlayer );
EmitSound_t params;
params.m_pSoundName = pszSound;
params.m_flSoundTime = 0.0f;
params.m_pflSoundDuration = NULL;
params.m_bWarnOnDirectWaveReference = true;
pEnt->EmitSound( filter, pEnt->entindex(), params );
}
void AddThinkToEnt( HSCRIPT entity, const char *pszFuncName )
{
CBaseEntity *pEntity = ToEnt( entity );
if (!pEntity)
return;
pEntity->ScriptSetThinkFunction(pszFuncName, TICK_INTERVAL);
}
void ParseScriptTableKeyValues( CBaseEntity *pEntity, HSCRIPT hKV )
{
int nIterator = -1;
ScriptVariant_t varKey, varValue;
while ((nIterator = g_pScriptVM->GetKeyValue( hKV, nIterator, &varKey, &varValue )) != -1)
{
switch (varValue.m_type)
{
case FIELD_CSTRING: pEntity->KeyValue( varKey.m_pszString, varValue.m_pszString ); break;
case FIELD_INTEGER: pEntity->KeyValueFromInt( varKey.m_pszString, varValue.m_int ); break;
case FIELD_FLOAT: pEntity->KeyValue( varKey.m_pszString, varValue.m_float ); break;
case FIELD_VECTOR: pEntity->KeyValue( varKey.m_pszString, *varValue.m_pVector ); break;
case FIELD_HSCRIPT:
{
if ( varValue.m_hScript )
{
// Entity
if (ToEnt( varValue.m_hScript ))
{
pEntity->KeyValue( varKey.m_pszString, STRING( ToEnt( varValue.m_hScript )->GetEntityName() ) );
}
// Color
else if (Color *color = HScriptToClass<Color>( varValue.m_hScript ))
{
char szTemp[64];
Q_snprintf( szTemp, sizeof( szTemp ), "%i %i %i %i", color->r(), color->g(), color->b(), color->a() );
pEntity->KeyValue( varKey.m_pszString, szTemp );
}
}
break;
}
}
g_pScriptVM->ReleaseValue( varKey );
g_pScriptVM->ReleaseValue( varValue );
}
}
void PrecacheEntityFromTable( const char *pszClassname, HSCRIPT hKV )
{
if ( IsEntityCreationAllowedInScripts() == false )
{
CGWarning( 0, CON_GROUP_VSCRIPT, "VScript error: A script attempted to create an entity mid-game. Due to the server's settings, entity creation from scripts is only allowed during map init.\n" );
return;
}
// This is similar to UTIL_PrecacheOther(), but we can't check if we can only precache it once.
// Probably for the best anyway, as similar classes can still have different precachable properties.
CBaseEntity *pEntity = CreateEntityByName( pszClassname );
if (!pEntity)
{
Assert( !"PrecacheEntityFromTable: only works for CBaseEntities" );
return;
}
ParseScriptTableKeyValues( pEntity, hKV );
pEntity->Precache();
UTIL_RemoveImmediate( pEntity );
}
HSCRIPT SpawnEntityFromTable( const char *pszClassname, HSCRIPT hKV )
{
if ( IsEntityCreationAllowedInScripts() == false )
{
CGWarning( 0, CON_GROUP_VSCRIPT, "VScript error: A script attempted to create an entity mid-game. Due to the server's settings, entity creation from scripts is only allowed during map init.\n" );
return NULL;
}
CBaseEntity *pEntity = CreateEntityByName( pszClassname );
if ( !pEntity )
{
Assert( !"SpawnEntityFromTable: only works for CBaseEntities" );
return NULL;
}
gEntList.NotifyCreateEntity( pEntity );
ParseScriptTableKeyValues( pEntity, hKV );
DispatchSpawn( pEntity );
pEntity->Activate();
return ToHScript( pEntity );
}
#endif
HSCRIPT EntIndexToHScript( int index )
{
#ifdef GAME_DLL
edict_t *e = INDEXENT(index);
if ( e && !e->IsFree() )
{
return ToHScript( GetContainingEntity( e ) );
}
#else // CLIENT_DLL
if ( index < NUM_ENT_ENTRIES )
{
return ToHScript( CBaseEntity::Instance( index ) );
}
#endif
return NULL;
}
//-----------------------------------------------------------------------------
// Mapbase-specific functions start here
//-----------------------------------------------------------------------------
#ifndef CLIENT_DLL
void SaveEntityKVToTable( HSCRIPT hEnt, HSCRIPT hTable )
{
CBaseEntity *pEnt = ToEnt( hEnt );
if (pEnt == NULL)
return;
variant_t var; // For Set()
ScriptVariant_t varScript, varTable = hTable;
// loop through the data description list, reading each data desc block
for ( datamap_t *dmap = pEnt->GetDataDescMap(); dmap != NULL; dmap = dmap->baseMap )
{
// search through all the readable fields in the data description, looking for a match
for ( int i = 0; i < dmap->dataNumFields; i++ )
{
if ( dmap->dataDesc[i].flags & (FTYPEDESC_KEY) )
{
var.Set( dmap->dataDesc[i].fieldType, ((char*)pEnt) + dmap->dataDesc[i].fieldOffset[ TD_OFFSET_NORMAL ] );
var.SetScriptVariant( varScript );
g_pScriptVM->SetValue( varTable, dmap->dataDesc[i].externalName, varScript );
}
}
}
}
HSCRIPT SpawnEntityFromKeyValues( const char *pszClassname, HSCRIPT hKV )
{
if ( IsEntityCreationAllowedInScripts() == false )
{
Warning( "VScript error: A script attempted to create an entity mid-game. Due to the server's settings, entity creation from scripts is only allowed during map init.\n" );
return NULL;
}
CBaseEntity *pEntity = CreateEntityByName( pszClassname );
if ( !pEntity )
{
Assert( !"SpawnEntityFromKeyValues: only works for CBaseEntities" );
return NULL;
}
gEntList.NotifyCreateEntity( pEntity );
KeyValues *pKV = scriptmanager->GetKeyValuesFromScriptKV( g_pScriptVM, hKV );
for (pKV = pKV->GetFirstSubKey(); pKV != NULL; pKV = pKV->GetNextKey())
{
pEntity->KeyValue( pKV->GetName(), pKV->GetString() );
}
DispatchSpawn( pEntity );
pEntity->Activate();
return ToHScript( pEntity );
}
void ScriptDispatchSpawn( HSCRIPT hEntity )
{
CBaseEntity *pEntity = ToEnt( hEntity );
if (pEntity)
{
DispatchSpawn( pEntity );
}
}
#endif // !CLIENT_DLL
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
static HSCRIPT_RC CreateDamageInfo( HSCRIPT hInflictor, HSCRIPT hAttacker, const Vector &vecForce, const Vector &vecDamagePos, float flDamage, int iDamageType )
{
CTakeDamageInfo *damageInfo = new CTakeDamageInfo( ToEnt(hInflictor), ToEnt(hAttacker), flDamage, iDamageType );
HSCRIPT hScript = g_pScriptVM->RegisterInstance( damageInfo, true );
damageInfo->SetDamagePosition( vecDamagePos );
damageInfo->SetDamageForce( vecForce );
return hScript;
}
static void DestroyDamageInfo( HSCRIPT )
{
}
void ScriptCalculateExplosiveDamageForce( HSCRIPT info, const Vector &vecDir, const Vector &vecForceOrigin, float flScale )
{
CTakeDamageInfo *pInfo = HScriptToClass< CTakeDamageInfo >( info );
if ( pInfo )
{
CalculateExplosiveDamageForce( pInfo, vecDir, vecForceOrigin, flScale );
}
}
void ScriptCalculateBulletDamageForce( HSCRIPT info, int iBulletType, const Vector &vecBulletDir, const Vector &vecForceOrigin, float flScale )
{
CTakeDamageInfo *pInfo = HScriptToClass< CTakeDamageInfo >( info );
if ( pInfo )
{
CalculateBulletDamageForce( pInfo, iBulletType, vecBulletDir, vecForceOrigin, flScale );
}
}
void ScriptCalculateMeleeDamageForce( HSCRIPT info, const Vector &vecMeleeDir, const Vector &vecForceOrigin, float flScale )
{
CTakeDamageInfo *pInfo = HScriptToClass< CTakeDamageInfo >( info );
if ( pInfo )
{
CalculateMeleeDamageForce( pInfo, vecMeleeDir, vecForceOrigin, flScale );
}
}
void ScriptGuessDamageForce( HSCRIPT info, const Vector &vecForceDir, const Vector &vecForceOrigin, float flScale )
{
CTakeDamageInfo *pInfo = HScriptToClass< CTakeDamageInfo >( info );
if ( pInfo )
{
GuessDamageForce( pInfo, vecForceDir, vecForceOrigin, flScale );
}
}
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
BEGIN_SCRIPTDESC_ROOT_NAMED( CScriptGameTrace, "CGameTrace", "trace_t" )
DEFINE_SCRIPT_REFCOUNTED_INSTANCE()
DEFINE_SCRIPTFUNC( DidHitWorld, "Returns whether the trace hit the world entity or not." )
DEFINE_SCRIPTFUNC( DidHitNonWorldEntity, "Returns whether the trace hit something other than the world entity." )
DEFINE_SCRIPTFUNC( GetEntityIndex, "Returns the index of whatever entity this trace hit." )
DEFINE_SCRIPTFUNC( DidHit, "Returns whether the trace hit anything." )
DEFINE_SCRIPTFUNC( FractionLeftSolid, "If this trace started within a solid, this is the point in the trace's fraction at which it left that solid." )
DEFINE_SCRIPTFUNC( HitGroup, "Returns the specific hit group this trace hit if it hit an entity." )
DEFINE_SCRIPTFUNC( PhysicsBone, "Returns the physics bone this trace hit if it hit an entity." )
DEFINE_SCRIPTFUNC( Entity, "Returns the entity this trace has hit." )
DEFINE_SCRIPTFUNC( HitBox, "Returns the hitbox of the entity this trace has hit. If it hit the world entity, this returns the static prop index." )
DEFINE_SCRIPTFUNC( IsDispSurface, "Returns whether this trace hit a displacement." )
DEFINE_SCRIPTFUNC( IsDispSurfaceWalkable, "Returns whether DISPSURF_FLAG_WALKABLE is ticked on the displacement this trace hit." )
DEFINE_SCRIPTFUNC( IsDispSurfaceBuildable, "Returns whether DISPSURF_FLAG_BUILDABLE is ticked on the displacement this trace hit." )
DEFINE_SCRIPTFUNC( IsDispSurfaceProp1, "Returns whether DISPSURF_FLAG_SURFPROP1 is ticked on the displacement this trace hit." )
DEFINE_SCRIPTFUNC( IsDispSurfaceProp2, "Returns whether DISPSURF_FLAG_SURFPROP2 is ticked on the displacement this trace hit." )
DEFINE_SCRIPTFUNC( StartPos, "Gets the trace's start position." )
DEFINE_SCRIPTFUNC( EndPos, "Gets the trace's end position." )
DEFINE_SCRIPTFUNC( Fraction, "Gets the fraction of the trace completed. For example, if the trace stopped exactly halfway to the end position, this would be 0.5." )
DEFINE_SCRIPTFUNC( Contents, "Gets the contents of the surface the trace has hit." )
DEFINE_SCRIPTFUNC( DispFlags, "Gets the displacement flags of the surface the trace has hit." )
DEFINE_SCRIPTFUNC( AllSolid, "Returns whether the trace is completely within a solid." )
DEFINE_SCRIPTFUNC( StartSolid, "Returns whether the trace started within a solid." )
DEFINE_SCRIPTFUNC( Surface, "" )
DEFINE_SCRIPTFUNC( Plane, "" )
DEFINE_SCRIPTFUNC( Destroy, SCRIPT_HIDE )
END_SCRIPTDESC();
BEGIN_SCRIPTDESC_ROOT_NAMED( scriptsurfacedata_t, "surfacedata_t", "" )
DEFINE_SCRIPTFUNC( GetFriction, "" )
DEFINE_SCRIPTFUNC( GetThickness, "" )
DEFINE_SCRIPTFUNC( GetJumpFactor, "" )
DEFINE_SCRIPTFUNC( GetMaterialChar, "" )
DEFINE_SCRIPTFUNC( GetSoundStepLeft, "" )
DEFINE_SCRIPTFUNC( GetSoundStepRight, "" )
DEFINE_SCRIPTFUNC( GetSoundImpactSoft, "" )
DEFINE_SCRIPTFUNC( GetSoundImpactHard, "" )
DEFINE_SCRIPTFUNC( GetSoundScrapeSmooth, "" )
DEFINE_SCRIPTFUNC( GetSoundScrapeRough, "" )
DEFINE_SCRIPTFUNC( GetSoundBulletImpact, "" )
DEFINE_SCRIPTFUNC( GetSoundRolling, "" )
DEFINE_SCRIPTFUNC( GetSoundBreak, "" )
DEFINE_SCRIPTFUNC( GetSoundStrain, "" )
END_SCRIPTDESC();
BEGIN_SCRIPTDESC_ROOT_NAMED( CSurfaceScriptHelper, "csurface_t", "" )
DEFINE_SCRIPTFUNC( Name, "" )
DEFINE_SCRIPTFUNC( SurfaceProps, "The surface's properties." )
END_SCRIPTDESC();
CPlaneTInstanceHelper g_PlaneTInstanceHelper;
BEGIN_SCRIPTDESC_ROOT_WITH_HELPER( cplane_t, "", &g_PlaneTInstanceHelper )
END_SCRIPTDESC();
static HSCRIPT_RC ScriptTraceLineComplex( const Vector &vecStart, const Vector &vecEnd, HSCRIPT entIgnore, int iMask, int iCollisionGroup )
{
CScriptGameTrace *tr = new CScriptGameTrace();
CBaseEntity *pIgnore = ToEnt( entIgnore );
UTIL_TraceLine( vecStart, vecEnd, iMask, pIgnore, iCollisionGroup, tr );
return g_pScriptVM->RegisterInstance( tr, true );
}
static HSCRIPT_RC ScriptTraceHullComplex( const Vector &vecStart, const Vector &vecEnd, const Vector &hullMin, const Vector &hullMax,
HSCRIPT entIgnore, int iMask, int iCollisionGroup )
{
CScriptGameTrace *tr = new CScriptGameTrace();
CBaseEntity *pIgnore = ToEnt( entIgnore );
UTIL_TraceHull( vecStart, vecEnd, hullMin, hullMax, iMask, pIgnore, iCollisionGroup, tr );
return g_pScriptVM->RegisterInstance( tr, true );
}
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
BEGIN_SCRIPTDESC_ROOT( FireBulletsInfo_t, "" )
DEFINE_SCRIPT_CONSTRUCTOR()
DEFINE_SCRIPTFUNC( GetShots, "Gets the number of shots which should be fired." )
DEFINE_SCRIPTFUNC( SetShots, "Sets the number of shots which should be fired." )
DEFINE_SCRIPTFUNC( GetSource, "" )
DEFINE_SCRIPTFUNC( SetSource, "" )
DEFINE_SCRIPTFUNC( GetDirShooting, "" )
DEFINE_SCRIPTFUNC( SetDirShooting, "" )
DEFINE_SCRIPTFUNC( GetSpread, "" )
DEFINE_SCRIPTFUNC( SetSpread, "" )
DEFINE_SCRIPTFUNC( GetDistance, "Gets the distance the bullets should travel." )
DEFINE_SCRIPTFUNC( SetDistance, "Sets the distance the bullets should travel." )
DEFINE_SCRIPTFUNC( GetAmmoType, "" )
DEFINE_SCRIPTFUNC( SetAmmoType, "" )
DEFINE_SCRIPTFUNC( GetTracerFreq, "" )
DEFINE_SCRIPTFUNC( SetTracerFreq, "" )
DEFINE_SCRIPTFUNC( GetDamage, "Gets the damage the bullets should deal. 0 = use ammo type" )
DEFINE_SCRIPTFUNC( SetDamage, "Sets the damage the bullets should deal. 0 = use ammo type" )
DEFINE_SCRIPTFUNC( GetPlayerDamage, "Gets the damage the bullets should deal when hitting the player. 0 = use regular damage" )
DEFINE_SCRIPTFUNC( SetPlayerDamage, "Sets the damage the bullets should deal when hitting the player. 0 = use regular damage" )
DEFINE_SCRIPTFUNC( GetFlags, "Gets the flags the bullets should use." )
DEFINE_SCRIPTFUNC( SetFlags, "Sets the flags the bullets should use." )
DEFINE_SCRIPTFUNC( GetDamageForceScale, "" )
DEFINE_SCRIPTFUNC( SetDamageForceScale, "" )
DEFINE_SCRIPTFUNC_NAMED( ScriptGetAttacker, "GetAttacker", "" )
DEFINE_SCRIPTFUNC_NAMED( ScriptSetAttacker, "SetAttacker", "" )
DEFINE_SCRIPTFUNC_NAMED( ScriptGetAdditionalIgnoreEnt, "GetAdditionalIgnoreEnt", "" )
DEFINE_SCRIPTFUNC_NAMED( ScriptSetAdditionalIgnoreEnt, "SetAdditionalIgnoreEnt", "" )
DEFINE_SCRIPTFUNC( GetPrimaryAttack, "Gets whether the bullets came from a primary attack." )
DEFINE_SCRIPTFUNC( SetPrimaryAttack, "Sets whether the bullets came from a primary attack." )
END_SCRIPTDESC();
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
HSCRIPT FireBulletsInfo_t::ScriptGetAttacker()
{
return ToHScript( m_pAttacker );
}
void FireBulletsInfo_t::ScriptSetAttacker( HSCRIPT value )
{
m_pAttacker = ToEnt( value );
}
HSCRIPT FireBulletsInfo_t::ScriptGetAdditionalIgnoreEnt()
{
return ToHScript( m_pAdditionalIgnoreEnt );
}
void FireBulletsInfo_t::ScriptSetAdditionalIgnoreEnt( HSCRIPT value )
{
m_pAdditionalIgnoreEnt = ToEnt( value );
}
static HSCRIPT_RC CreateFireBulletsInfo( int cShots, const Vector &vecSrc, const Vector &vecDirShooting,
const Vector &vecSpread, float iDamage, HSCRIPT pAttacker )
{
FireBulletsInfo_t *info = new FireBulletsInfo_t();
HSCRIPT hScript = g_pScriptVM->RegisterInstance( info, true );
info->SetShots( cShots );
info->SetSource( vecSrc );
info->SetDirShooting( vecDirShooting );
info->SetSpread( vecSpread );
info->SetDamage( iDamage );
info->ScriptSetAttacker( pAttacker );
return hScript;
}
static void DestroyFireBulletsInfo( HSCRIPT )
{
}
//-----------------------------------------------------------------------------
// animevent_t
//-----------------------------------------------------------------------------
CAnimEventTInstanceHelper g_AnimEventTInstanceHelper;
BEGIN_SCRIPTDESC_ROOT_WITH_HELPER( scriptanimevent_t, "", &g_AnimEventTInstanceHelper )
DEFINE_SCRIPTFUNC( GetEvent, "" )
DEFINE_SCRIPTFUNC( SetEvent, "" )
DEFINE_SCRIPTFUNC( GetOptions, "" )
DEFINE_SCRIPTFUNC( SetOptions, "" )
DEFINE_SCRIPTFUNC( GetCycle, "" )
DEFINE_SCRIPTFUNC( SetCycle, "" )
DEFINE_SCRIPTFUNC( GetEventTime, "" )
DEFINE_SCRIPTFUNC( SetEventTime, "" )
DEFINE_SCRIPTFUNC( GetType, "Gets the event's type flags. See the 'AE_TYPE_' set of constants for valid flags." )
DEFINE_SCRIPTFUNC( SetType, "Sets the event's type flags. See the 'AE_TYPE_' set of constants for valid flags." )
DEFINE_SCRIPTFUNC( GetSource, "Gets the event's source entity." )
DEFINE_SCRIPTFUNC( SetSource, "Sets the event's source entity." )
END_SCRIPTDESC();
bool CAnimEventTInstanceHelper::Get( void *p, const char *pszKey, ScriptVariant_t &variant )
{
DevWarning( "VScript animevent_t.%s: animevent_t metamethod members are deprecated! Use 'script_help animevent_t' to see the correct functions.\n", pszKey );
animevent_t *ani = &((scriptanimevent_t *)p)->event;
if (FStrEq( pszKey, "event" ))
variant = ani->event;
else if (FStrEq( pszKey, "options" ))
variant = ani->options;
else if (FStrEq( pszKey, "cycle" ))
variant = ani->cycle;
else if (FStrEq( pszKey, "eventtime" ))
variant = ani->eventtime;
else if (FStrEq( pszKey, "type" ))
variant = ani->type;
else if (FStrEq( pszKey, "source" ))
variant = ToHScript(ani->pSource);
else
return false;
return true;
}
bool CAnimEventTInstanceHelper::Set( void *p, const char *pszKey, ScriptVariant_t &variant )
{
DevWarning( "VScript animevent_t.%s: animevent_t metamethod members are deprecated! Use 'script_help animevent_t' to see the correct functions.\n", pszKey );
scriptanimevent_t *script_ani = ((scriptanimevent_t *)p);
animevent_t *ani = &script_ani->event;
if (FStrEq( pszKey, "event" ))
{
return variant.AssignTo( &ani->event );
}
else if (FStrEq( pszKey, "options" ))
{
char *szOptions;
if (!variant.AssignTo( &szOptions ))
{
return false;
}
script_ani->SetOptions( szOptions );
}
else if (FStrEq( pszKey, "cycle" ))
return variant.AssignTo( &ani->cycle );
else if (FStrEq( pszKey, "eventtime" ))
return variant.AssignTo( &ani->eventtime );
else if (FStrEq( pszKey, "type" ))
return variant.AssignTo( &ani->type );
else if (FStrEq( pszKey, "source" ) && variant.m_type == FIELD_HSCRIPT)
{
CBaseEntity *pEnt = ToEnt( variant.m_hScript );
if (pEnt)
ani->pSource = pEnt->GetBaseAnimating();
}
else
return false;
return true;
}
//-----------------------------------------------------------------------------
// EmitSound_t
//-----------------------------------------------------------------------------
BEGIN_SCRIPTDESC_ROOT_NAMED( ScriptEmitSound_t, "EmitSound_t", "" )
DEFINE_SCRIPT_CONSTRUCTOR()
DEFINE_SCRIPTFUNC( GetChannel, "" )
DEFINE_SCRIPTFUNC( SetChannel, "" )
DEFINE_SCRIPTFUNC( GetSoundName, "Gets the sound's file path or soundscript name." )
DEFINE_SCRIPTFUNC( SetSoundName, "Sets the sound's file path or soundscript name." )
DEFINE_SCRIPTFUNC( GetVolume, "(Note that this may not apply to soundscripts)" )
DEFINE_SCRIPTFUNC( SetVolume, "(Note that this may not apply to soundscripts)" )
DEFINE_SCRIPTFUNC( GetSoundLevel, "Gets the sound's level in decibels. (Note that this may not apply to soundscripts)" )
DEFINE_SCRIPTFUNC( SetSoundLevel, "Sets the sound's level in decibels. (Note that this may not apply to soundscripts)" )
DEFINE_SCRIPTFUNC( GetFlags, "Gets the sound's flags. See the 'SND_' set of constants." )
DEFINE_SCRIPTFUNC( SetFlags, "Sets the sound's flags. See the 'SND_' set of constants." )
DEFINE_SCRIPTFUNC( GetPitch, "" )
DEFINE_SCRIPTFUNC( SetPitch, "Sets the sound's pitch in range [1, 255]" )
DEFINE_SCRIPTFUNC( GetSpecialDSP, "" )
DEFINE_SCRIPTFUNC( SetSpecialDSP, "" )
DEFINE_SCRIPTFUNC( HasOrigin, "Returns true if the sound has an origin override." )
DEFINE_SCRIPTFUNC( GetOrigin, "Gets the sound's origin override." )
DEFINE_SCRIPTFUNC( SetOrigin, "Sets the sound's origin override." )
DEFINE_SCRIPTFUNC( ClearOrigin, "Clears the sound's origin override if it has one." )
DEFINE_SCRIPTFUNC( GetSoundTime, "Gets the time the sound will begin, relative to Time()." )
DEFINE_SCRIPTFUNC( SetSoundTime, "Sets the time the sound will begin, relative to Time()." )
DEFINE_SCRIPTFUNC( GetEmitCloseCaption, "Gets whether or not the sound will emit closed captioning/subtitles." )
DEFINE_SCRIPTFUNC( SetEmitCloseCaption, "Sets whether or not the sound will emit closed captioning/subtitles." )
DEFINE_SCRIPTFUNC( GetWarnOnMissingCloseCaption, "Gets whether or not the sound will send a message to the console if there is no corresponding closed captioning token." )
DEFINE_SCRIPTFUNC( SetWarnOnMissingCloseCaption, "Sets whether or not the sound will send a message to the console if there is no corresponding closed captioning token." )
DEFINE_SCRIPTFUNC( GetWarnOnDirectWaveReference, "Gets whether or not the sound will send a message to the console if it references a direct sound file instead of a soundscript." )
DEFINE_SCRIPTFUNC( SetWarnOnDirectWaveReference, "Sets whether or not the sound will send a message to the console if it references a direct sound file instead of a soundscript." )
DEFINE_SCRIPTFUNC( GetSpeakerEntity, "Gets the sound's original source if it is being transmitted by a microphone." )
DEFINE_SCRIPTFUNC( SetSpeakerEntity, "Sets the sound's original source if it is being transmitted by a microphone." )
DEFINE_SCRIPTFUNC( GetSoundScriptHandle, "" )
DEFINE_SCRIPTFUNC( SetSoundScriptHandle, "" )
END_SCRIPTDESC();
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
BEGIN_SCRIPTDESC_ROOT_NAMED( CScriptUserCmd, "CUserCmd", "" )
DEFINE_SCRIPTFUNC( GetCommandNumber, "For matching server and client commands for debugging." )
DEFINE_SCRIPTFUNC_NAMED( ScriptGetTickCount, "GetTickCount", "The tick the client created this command." )
DEFINE_SCRIPTFUNC( GetViewAngles, "Player instantaneous view angles." )
DEFINE_SCRIPTFUNC( SetViewAngles, "Sets player instantaneous view angles." )
DEFINE_SCRIPTFUNC( GetForwardMove, "" )
DEFINE_SCRIPTFUNC( SetForwardMove, "" )
DEFINE_SCRIPTFUNC( GetSideMove, "" )
DEFINE_SCRIPTFUNC( SetSideMove, "" )
DEFINE_SCRIPTFUNC( GetUpMove, "" )
DEFINE_SCRIPTFUNC( SetUpMove, "" )
DEFINE_SCRIPTFUNC( GetButtons, "Input button state." )
DEFINE_SCRIPTFUNC( SetButtons, "Sets input button state." )
DEFINE_SCRIPTFUNC( GetImpulse, "Impulse command issued." )
DEFINE_SCRIPTFUNC( SetImpulse, "Sets impulse command issued." )
DEFINE_SCRIPTFUNC( GetWeaponSelect, "Current weapon id." )
DEFINE_SCRIPTFUNC( SetWeaponSelect, "Sets current weapon id." )
DEFINE_SCRIPTFUNC( GetWeaponSubtype, "Current weapon subtype id." )
DEFINE_SCRIPTFUNC( SetWeaponSubtype, "Sets current weapon subtype id." )
DEFINE_SCRIPTFUNC( GetRandomSeed, "For shared random functions." )
DEFINE_SCRIPTFUNC( GetMouseX, "Mouse accum in x from create move." )
DEFINE_SCRIPTFUNC( SetMouseX, "Sets mouse accum in x from create move." )
DEFINE_SCRIPTFUNC( GetMouseY, "Mouse accum in y from create move." )
DEFINE_SCRIPTFUNC( SetMouseY, "Sets mouse accum in y from create move." )
END_SCRIPTDESC();
#ifdef GAME_DLL
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
#define DEFINE_ENEMY_INFO_SCRIPTFUNCS(name, desc) \
DEFINE_SCRIPTFUNC_NAMED( Get##name, #name, "Get " desc ) \
DEFINE_SCRIPTFUNC( Set##name, "Set " desc )
BEGIN_SCRIPTDESC_ROOT_NAMED( Script_AI_EnemyInfo_t, "AI_EnemyInfo_t", "Accessor for information about an enemy." )
DEFINE_SCRIPTFUNC( Enemy, "" )
DEFINE_SCRIPTFUNC( SetEnemy, "" )
DEFINE_ENEMY_INFO_SCRIPTFUNCS( LastKnownLocation, "" )
DEFINE_ENEMY_INFO_SCRIPTFUNCS( LastSeenLocation, "" )
DEFINE_ENEMY_INFO_SCRIPTFUNCS( TimeLastSeen, "" )
DEFINE_ENEMY_INFO_SCRIPTFUNCS( TimeFirstSeen, "" )
DEFINE_ENEMY_INFO_SCRIPTFUNCS( TimeLastReacquired, "" )
DEFINE_ENEMY_INFO_SCRIPTFUNCS( TimeValidEnemy, "the time at which the enemy can be selected (reaction delay)." )
DEFINE_ENEMY_INFO_SCRIPTFUNCS( TimeLastReceivedDamageFrom, "the last time damage was received from this enemy." )
DEFINE_ENEMY_INFO_SCRIPTFUNCS( TimeAtFirstHand, "the time at which the enemy was seen firsthand." )
DEFINE_ENEMY_INFO_SCRIPTFUNCS( DangerMemory, "the memory of danger position w/o enemy pointer." )
DEFINE_ENEMY_INFO_SCRIPTFUNCS( EludedMe, "whether the enemy is not at the last known location." )
DEFINE_ENEMY_INFO_SCRIPTFUNCS( Unforgettable, "" )
DEFINE_ENEMY_INFO_SCRIPTFUNCS( MobbedMe, "whether the enemy was part of a mob at some point." )
END_SCRIPTDESC();
#endif
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
BEGIN_SCRIPTDESC_ROOT( IPhysicsObject, "VPhysics object class." )
DEFINE_SCRIPTFUNC( IsStatic, "" )
DEFINE_SCRIPTFUNC( IsAsleep, "" )
DEFINE_SCRIPTFUNC( IsTrigger, "" )
DEFINE_SCRIPTFUNC( IsFluid, "" )
DEFINE_SCRIPTFUNC( IsHinged, "" )
DEFINE_SCRIPTFUNC( IsCollisionEnabled, "" )
DEFINE_SCRIPTFUNC( IsGravityEnabled, "" )
DEFINE_SCRIPTFUNC( IsDragEnabled, "" )
DEFINE_SCRIPTFUNC( IsMotionEnabled, "" )
DEFINE_SCRIPTFUNC( IsMoveable, "" )
DEFINE_SCRIPTFUNC( IsAttachedToConstraint, "" )
DEFINE_SCRIPTFUNC( EnableCollisions, "" )
DEFINE_SCRIPTFUNC( EnableGravity, "" )
DEFINE_SCRIPTFUNC( EnableDrag, "" )
DEFINE_SCRIPTFUNC( EnableMotion, "" )
DEFINE_SCRIPTFUNC( Wake, "" )
DEFINE_SCRIPTFUNC( Sleep, "" )
DEFINE_SCRIPTFUNC( SetMass, "" )
DEFINE_SCRIPTFUNC( GetMass, "" )
DEFINE_SCRIPTFUNC( GetInvMass, "" )
DEFINE_SCRIPTFUNC( GetInertia, "" )
DEFINE_SCRIPTFUNC( GetInvInertia, "" )
DEFINE_SCRIPTFUNC( SetInertia, "" )
DEFINE_SCRIPTFUNC( ApplyForceCenter, "" )
DEFINE_SCRIPTFUNC( ApplyForceOffset, "" )
DEFINE_SCRIPTFUNC( ApplyTorqueCenter, "" )
DEFINE_SCRIPTFUNC( GetName, "" )
END_SCRIPTDESC();
static const Vector &GetPhysVelocity( HSCRIPT hPhys )
{
IPhysicsObject *pPhys = HScriptToClass<IPhysicsObject>( hPhys );
if (!pPhys)
return vec3_origin;
static Vector vecVelocity;
pPhys->GetVelocity( &vecVelocity, NULL );
return vecVelocity;
}
static const Vector &GetPhysAngVelocity( HSCRIPT hPhys )
{
IPhysicsObject *pPhys = HScriptToClass<IPhysicsObject>( hPhys );
if (!pPhys)
return vec3_origin;
static Vector vecAngVelocity;
pPhys->GetVelocity( NULL, &vecAngVelocity );
return vecAngVelocity;
}
static void SetPhysVelocity( HSCRIPT hPhys, const Vector& vecVelocity, const Vector& vecAngVelocity )
{
IPhysicsObject *pPhys = HScriptToClass<IPhysicsObject>( hPhys );
if (!pPhys)
return;
pPhys->SetVelocity( &vecVelocity, &vecAngVelocity );
}
static void AddPhysVelocity( HSCRIPT hPhys, const Vector& vecVelocity, const Vector& vecAngVelocity )
{
IPhysicsObject *pPhys = HScriptToClass<IPhysicsObject>( hPhys );
if (!pPhys)
return;
pPhys->AddVelocity( &vecVelocity, &vecAngVelocity );
}
static void ScriptPhysEnableEntityCollisions( HSCRIPT hPhys1, HSCRIPT hPhys2 )
{
IPhysicsObject *pPhys1 = HScriptToClass<IPhysicsObject>( hPhys1 );
IPhysicsObject *pPhys2 = HScriptToClass<IPhysicsObject>( hPhys2 );
if (!pPhys1 || !pPhys2)
return;
PhysEnableEntityCollisions( pPhys1, pPhys2 );
}
static void ScriptPhysDisableEntityCollisions( HSCRIPT hPhys1, HSCRIPT hPhys2 )
{
IPhysicsObject *pPhys1 = HScriptToClass<IPhysicsObject>( hPhys1 );
IPhysicsObject *pPhys2 = HScriptToClass<IPhysicsObject>( hPhys2 );
if (!pPhys1 || !pPhys2)
return;
PhysDisableEntityCollisions( pPhys1, pPhys2 );
}
//=============================================================================
//=============================================================================
#ifdef CLIENT_DLL
static int ScriptPrecacheModel( const char *modelname )
{
return CBaseEntity::PrecacheModel( modelname );
}
static void ScriptPrecacheOther( const char *classname )
{
UTIL_PrecacheOther( classname );
}
#else
static int ScriptPrecacheModel( const char *modelname, bool bPreload )
{
return CBaseEntity::PrecacheModel( modelname, bPreload );
}
static void ScriptPrecacheOther( const char *classname, const char *modelName )
{
UTIL_PrecacheOther( classname, modelName );
}
// TODO: Move this?
static void ScriptInsertSound( int iType, const Vector &vecOrigin, int iVolume, float flDuration, HSCRIPT hOwner, int soundChannelIndex, HSCRIPT hSoundTarget )
{
CSoundEnt::InsertSound( iType, vecOrigin, iVolume, flDuration, ToEnt(hOwner), soundChannelIndex, ToEnt(hSoundTarget) );
}
#endif
//=============================================================================
//=============================================================================
static void ScriptEntitiesInBox( HSCRIPT hTable, int listMax, const Vector &hullMin, const Vector &hullMax, int iMask )
{
CBaseEntity *list[1024];
int count = UTIL_EntitiesInBox( list, listMax, hullMin, hullMax, iMask );
for ( int i = 0; i < count; i++ )
{
g_pScriptVM->ArrayAppend( hTable, ToHScript(list[i]) );
}
}
static void ScriptEntitiesAtPoint( HSCRIPT hTable, int listMax, const Vector &point, int iMask )
{
CBaseEntity *list[1024];
int count = UTIL_EntitiesAtPoint( list, listMax, point, iMask );
for ( int i = 0; i < count; i++ )
{
g_pScriptVM->ArrayAppend( hTable, ToHScript(list[i]) );
}
}
static void ScriptEntitiesInSphere( HSCRIPT hTable, int listMax, const Vector ¢er, float radius, int iMask )
{
CBaseEntity *list[1024];
int count = UTIL_EntitiesInSphere( list, listMax, center, radius, iMask );
for ( int i = 0; i < count; i++ )
{
g_pScriptVM->ArrayAppend( hTable, ToHScript(list[i]) );
}
}
//-----------------------------------------------------------------------------
static void ScriptDecalTrace( HSCRIPT hTrace, const char *decalName )
{
CScriptGameTrace *tr = HScriptToClass< CScriptGameTrace >( hTrace );
if ( tr )
{
UTIL_DecalTrace( tr, decalName );
}
}
static HSCRIPT ScriptCreateRope( HSCRIPT hStart, HSCRIPT hEnd, int iStartAttachment, int iEndAttachment, float ropeWidth, const char *pMaterialName, int numSegments, int ropeFlags )
{
#ifdef CLIENT_DLL
C_RopeKeyframe *pRope = C_RopeKeyframe::Create( ToEnt( hStart ), ToEnt( hEnd ), iStartAttachment, iEndAttachment, ropeWidth, pMaterialName, numSegments, ropeFlags );
#else
CRopeKeyframe *pRope = CRopeKeyframe::Create( ToEnt( hStart ), ToEnt( hEnd ), iStartAttachment, iEndAttachment, ropeWidth, pMaterialName, numSegments );
if (pRope)
pRope->m_RopeFlags |= ropeFlags; // HACKHACK
#endif
return ToHScript( pRope );
}
#ifndef CLIENT_DLL
static HSCRIPT ScriptCreateRopeWithSecondPointDetached( HSCRIPT hStart, int iStartAttachment, int ropeLength, float ropeWidth, const char *pMaterialName, int numSegments, bool initialHang, int ropeFlags )
{
CRopeKeyframe *pRope = CRopeKeyframe::CreateWithSecondPointDetached( ToEnt( hStart ), iStartAttachment, ropeLength, ropeWidth, pMaterialName, numSegments, initialHang );
if (pRope)
pRope->m_RopeFlags |= ropeFlags; // HACKHACK
return ToHScript( pRope );
}
#endif
static void EmitSoundParamsOn( HSCRIPT hParams, HSCRIPT hEnt )
{
CBaseEntity *pEnt = ToEnt( hEnt );
if (!pEnt)
return;
ScriptEmitSound_t *pParams = (ScriptEmitSound_t*)g_pScriptVM->GetInstanceValue( hParams, GetScriptDescForClass( ScriptEmitSound_t ) );
if (!pParams)
return;
CPASAttenuationFilter filter( pEnt, pParams->m_pSoundName );
CBaseEntity::EmitSound( filter, pEnt->entindex(), *pParams );
}
//-----------------------------------------------------------------------------
// Simple particle effect dispatch
//-----------------------------------------------------------------------------
static void ScriptDispatchParticleEffect( const char *pszParticleName, const Vector &vecOrigin, const QAngle &vecAngles, HSCRIPT hEntity )
{
DispatchParticleEffect( pszParticleName, vecOrigin, vecAngles, ToEnt(hEntity) );
}
#ifndef CLIENT_DLL
const Vector& ScriptPredictedPosition( HSCRIPT hTarget, float flTimeDelta )
{
static Vector predicted;
UTIL_PredictedPosition( ToEnt(hTarget), flTimeDelta, &predicted );
return predicted;
}
#endif
//=============================================================================
//=============================================================================
bool ScriptMatcherMatch( const char *pszQuery, const char *szValue ) { return Matcher_Match( pszQuery, szValue ); }
//=============================================================================
//=============================================================================
#ifndef CLIENT_DLL
bool IsDedicatedServer()
{
return engine->IsDedicatedServer();
}
#endif
bool ScriptIsServer()
{
#ifdef GAME_DLL
return true;
#else
return false;
#endif
}
bool ScriptIsClient()
{
#ifdef CLIENT_DLL
return true;
#else
return false;
#endif
}
bool ScriptIsWindows()
{
return IsWindows();
}
bool ScriptIsLinux()
{
return IsLinux();
}
bool ScriptIsOSX()
{
return IsOSX();
}
bool ScriptIsPosix()
{
return IsPosix();
}
// Notification printing on the right edge of the screen
void NPrint( int pos, const char* fmt )
{
engine->Con_NPrintf( pos, "%s", fmt );
}
void NXPrint( int pos, int r, int g, int b, bool fixed, float ftime, const char* fmt )
{
con_nprint_t info;
info.index = pos;
info.time_to_live = ftime;
info.color[0] = r / 255.f;
info.color[1] = g / 255.f;
info.color[2] = b / 255.f;
info.fixed_width_font = fixed;
engine->Con_NXPrintf( &info, "%s", fmt );
}
static float IntervalPerTick()
{
return gpGlobals->interval_per_tick;
}
static int GetFrameCount()
{
return gpGlobals->framecount;
}