-
-
Notifications
You must be signed in to change notification settings - Fork 25
/
c_tf_player.cpp
12179 lines (10351 loc) · 353 KB
/
c_tf_player.cpp
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
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
//=============================================================================
#include "cbase.h"
#include "c_tf_player.h"
#include "c_user_message_register.h"
#include "view.h"
#include "iclientvehicle.h"
#include "ivieweffects.h"
#include "input.h"
#include "IEffects.h"
#include "fx.h"
#include "c_basetempentity.h"
#include "hud_macros.h"
#include "engine/ivdebugoverlay.h"
#include "smoke_fog_overlay.h"
#include "playerandobjectenumerator.h"
#include "bone_setup.h"
#include "in_buttons.h"
#include "r_efx.h"
#include "dlight.h"
#include "shake.h"
#include "cl_animevent.h"
#include "animation.h"
#include "choreoscene.h"
#include "tf_weaponbase.h"
#include "c_tf_playerresource.h"
#include "toolframework/itoolframework.h"
#include "tier1/KeyValues.h"
#include "tier0/vprof.h"
#include "prediction.h"
#include "effect_dispatch_data.h"
#include "c_te_effect_dispatch.h"
#include "tf_fx_muzzleflash.h"
#include "tf_gamerules.h"
#include "view_scene.h"
#include "c_baseobject.h"
#include "toolframework_client.h"
#include "materialsystem/imaterialvar.h"
#include "soundenvelope.h"
#include "voice_status.h"
#include "clienteffectprecachesystem.h"
#include "functionproxy.h"
#include "toolframework_client.h"
#include "choreoevent.h"
#include "vguicenterprint.h"
#include "eventlist.h"
#include "input.h"
#include "tf_weapon_medigun.h"
#include "tf_weapon_pipebomblauncher.h"
#include "tf_weapon_shovel.h"
#include "tf_hud_mediccallers.h"
#include "in_main.h"
#include "c_team.h"
#include "collisionutils.h"
// for spy material proxy
#include "tf_proxyentity.h"
#include "materialsystem/imaterial.h"
#include "materialsystem/imaterialvar.h"
#include "materialsystem/itexturecompositor.h"
#include "c_tf_team.h"
#include "tf_item_inventory.h"
#include "model_types.h"
#include "dt_utlvector_recv.h"
#include "tf_item_wearable.h"
#include "cam_thirdperson.h"
#include "c_tf_projectile_arrow.h"
#include "econ_entity.h"
#include "ihasowner.h"
#include "tf_hud_itemeffectmeter.h"
#include "replay/vgui/replayinputpanel.h"
#include "tf_replay.h"
#include "netadr.h"
#include "input.h"
#include "gcsdk/gcclientsdk.h"
#include "econ_gcmessages.h"
#include "rtime.h"
#include "networkstringtable_clientdll.h"
#include "replay/ireplaymanager.h"
#include "gc_clientsystem.h"
#include "c_entitydissolve.h"
#include "tf_viewmodel.h"
#include "player_vs_environment/c_tf_upgrades.h"
#include "sourcevr/isourcevirtualreality.h"
#include "tempent.h"
#include "confirm_dialog.h"
#include "c_tf_weapon_builder.h"
#include "tf_shared_content_manager.h"
#include "baseanimatedtextureproxy.h"
#include "econ_entity.h"
#include "halloween/tf_weapon_spellbook.h"
#include "tf_weapon_grapplinghook.h"
#include "tf_logic_robot_destruction.h"
#include "econ_notifications.h"
#include "tf_weapon_buff_item.h"
#include "tf_dropped_weapon.h"
#include "tf_hud_notification_panel.h"
#include "tf_dropped_weapon.h"
#include "tf_hud_passtime_reticle.h"
#include "passtime_convars.h"
#include "c_tf_passtime_logic.h"
#include "tf_weapon_passtime_gun.h"
#include "eiface.h"
#include "filesystem.h"
#include "debugoverlay_shared.h"
#include "tf_hud_chat.h"
#include "tf_item_powerup_bottle.h"
#include <vgui_controls/AnimationController.h>
#ifdef STAGING_ONLY
#include "tf_matchmaking_shared.h"
#include "tier2/keyvaluesmacros.h"
#endif // STAGING_ONLY
#if defined( REPLAY_ENABLED )
#include "replay/ienginereplay.h"
#endif
#if defined( CTFPlayer )
#undef CTFPlayer
#endif
#include "materialsystem/imesh.h" //for materials->FindMaterial
#include "iviewrender.h" //for view->
// NVNT haptics system interface
#include "c_tf_haptics.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
using namespace GCSDK;
static_assert( TEAM_UNASSIGNED == 0, "If this assert fires, update the assert and the enum in ctexturecompositor.cpp which specifies team colors" );
static_assert( TF_TEAM_RED == 2, "If this assert fires, update the assert and the enum in ctexturecompositor.cpp which specifies team colors" );
static_assert( TF_TEAM_BLUE == 3, "If this assert fires, update the assert and the enum in ctexturecompositor.cpp which specifies team colors" );
// Forward decl
CEconItemView *GetEconItemViewFromProxyEntity( void *pEntity );
C_TFPlayer *GetOwnerFromProxyEntity( void *pEntity );
// --------------------------------------------------------------------------------
// Local Convar Helper Function
// --------------------------------------------------------------------------------
void VisionMode_ChangeCallback( IConVar *pConVar, char const *pOldString, float flOldValue )
{
C_BasePlayer *pLocalPlayer = C_BasePlayer::GetLocalPlayer();
if ( pLocalPlayer )
{
pLocalPlayer->CalculateVisionUsingCurrentFlags();
}
}
#ifdef _DEBUG
CON_COMMAND_F ( tf_test_bomb, "Test halloween bomb", 0 )
{
C_BasePlayer *pLocalPlayer = C_BasePlayer::GetLocalPlayer();
if ( !pLocalPlayer )
return;
C_TFPlayer *pPlayer = ToTFPlayer( pLocalPlayer );
if ( !pPlayer )
return;
pPlayer->CreateBombonomiconHint();
}
ConVar test_vision_off( "test_vision_off", "0", FCVAR_NONE, "Force vision modes off!", VisionMode_ChangeCallback );
ConVar test_pyrovision( "test_pyrovision", "0", FCVAR_NONE, "Force Pyrovision on!", VisionMode_ChangeCallback );
ConVar test_romevision( "test_romevision", "0", FCVAR_NONE, "Force Romevision on!", VisionMode_ChangeCallback );
ConVar test_halloweenvision( "test_halloweenvision", "0", FCVAR_NONE, "Force halloween vision on!", VisionMode_ChangeCallback );
#endif
// These are all permanently STAGING_ONLY
#ifdef STAGING_ONLY
ConVar tf_paint_kit_disable( "tf_paint_kit_disable", "0", FCVAR_NONE, "Set to disable using paintkits completely." );
ConVar tf_paint_kit_team_override( "tf_paint_kit_team_override", "-1", FCVAR_NONE, "Set to -1:disabled, 0:TF_TEAM_RED, 1:TF_TEAM_BLUE" );
ConVar tf_paint_kit_seed_override( "tf_paint_kit_seed_override", "0", FCVAR_NONE, "Set to none-0 will force composite weapon skin to use this as random seed number." );
ConVar tf_paint_kit_force_regen( "tf_paint_kit_force_regen", "0", FCVAR_NONE, "Set to 1 to force regen after every generation. (dev only)" );
ConVar tf_paint_kit_generating_icons( "tf_paint_kit_generating_icons", "0", FCVAR_NONE, "Only Set by the Icon Generating System." );
extern ConVar tf_paint_kit_force_wear;
KeyValues *s_kvOverridePaintkit = NULL;
bool s_bIsPaintkitOverrideSet = false;
void LoadPaintKit( const char* pszFile )
{
//scripts\items\unencrypted\paintkits
static char pszPaintkitFile[MAX_PATH] = { '\0' };
if ( pszFile )
{
V_sprintf_safe( pszPaintkitFile, "scripts/items/unencrypted/paintkits/%s.paintkit", pszFile );
}
if ( pszPaintkitFile[0] == '\0' )
return;
// Make sure we have a file system
if ( !g_pFullFileSystem || !g_pFullFileSystem->FileExists( pszPaintkitFile ) )
{
Msg( "Unable to load %s from File System \n", pszPaintkitFile );
return;
}
if ( s_kvOverridePaintkit )
{
s_kvOverridePaintkit->deleteThis();
s_kvOverridePaintkit = NULL;
}
// Parse the KeyValues
s_kvOverridePaintkit = new KeyValues( "paintkit" );
if ( !s_kvOverridePaintkit->LoadFromFile( g_pFullFileSystem, pszPaintkitFile ) )
{
Msg( "Unable to read KeyValues from %s \n", pszPaintkitFile );
return;
}
HandleKeyValuesMacros( s_kvOverridePaintkit );
Msg( "Setting %s as Paintkit override.\nCall with no args to disable\ntf_paint_kit_force_regen set to 1\n", pszPaintkitFile );
s_bIsPaintkitOverrideSet = true;
}
CON_COMMAND_F( tf_paint_kit_override_file, "Set a override paintkit file", FCVAR_NONE )
{
// Enable force regen
tf_paint_kit_force_regen.SetValue( 1 );
s_bIsPaintkitOverrideSet = false;
// Take the con var
if ( args.ArgC() <= 1 )
{
Msg( "No paintkit file specified, turning override off.\nYou may want to set tf_paint_kit_force_regen to 0\n" );
return;
}
const char *pszFile = args.Arg( 1 );
LoadPaintKit( pszFile );
}
CON_COMMAND( tf_paint_kit_override_refresh, "Refresh the current override paint kit file" )
{
if ( !s_bIsPaintkitOverrideSet )
return;
LoadPaintKit( NULL );
}
#endif
ConVar tf_playergib_forceup( "tf_playersgib_forceup", "1.0", FCVAR_CHEAT | FCVAR_DEVELOPMENTONLY, "Upward added velocity for gibs." );
ConVar tf_playergib_force( "tf_playersgib_force", "500.0", FCVAR_CHEAT | FCVAR_DEVELOPMENTONLY, "Gibs force." );
ConVar tf_playergib_maxspeed( "tf_playergib_maxspeed", "400", FCVAR_CHEAT | FCVAR_DEVELOPMENTONLY, "Max gib speed." );
ConVar tf_always_deathanim( "tf_always_deathanim", "0", FCVAR_CHEAT, "Force death anims to always play." );
ConVar tf_clientsideeye_lookats( "tf_clientsideeye_lookats", "1", FCVAR_NONE, "When on, players will turn their pupils to look at nearby players." );
extern ConVar tf_halloween_kart_boost_recharge;
extern ConVar tf_halloween_kart_boost_duration;
extern ConVar cl_thirdperson;
#ifdef STAGING_ONLY
ConVar test_local_player_skin_override( "test_local_player_skin_override", "-1", FCVAR_CHEAT, "If >= 0, force this skin index to be used by the local player model." );
ConVar tf_test_setkillcount( "tf_test_setkillcount", "0", FCVAR_NONE, "Force a kill streak count for eye glow testing" );
extern ConVar tf_random_item_min;
extern ConVar tf_random_item_max;
extern ConVar tf_killstreak_eyeglow;
extern ConVar tf_killstreak_color;
extern ConVar tf_eyeglow_wip;
ConVar tf_sheen_all( "tf_sheen_all", "0", FCVAR_NONE, "When on, enables sheens on all weapons" );
ConVar tf_sheen_fast( "tf_sheen_fast", "0", FCVAR_NONE, "When on, no delay's between sheens" );
ConVar tf_sheen_shader_override( "tf_sheen_shader_override", "0", FCVAR_NONE, "Set for shader effect override" );
ConVar tf_sheen_color_override_r( "tf_sheen_color_override_r", "0", FCVAR_HIDDEN, "Set by ConCommand tf_sheen_color_override" );
ConVar tf_sheen_color_override_g( "tf_sheen_color_override_g", "0", FCVAR_HIDDEN, "Set by ConCommand tf_sheen_color_override" );
ConVar tf_sheen_color_override_b( "tf_sheen_color_override_b", "0", FCVAR_HIDDEN, "Set by ConCommand tf_sheen_color_override" );
ConVar tf_sheen_color_override_a( "tf_sheen_color_override_a", "0", FCVAR_HIDDEN, "Set by ConCommand tf_sheen_color_override" );
CON_COMMAND_F ( tf_sheen_color_override, "Sheen Color Override RGBA 0-255", 0 )
{
if ( args.ArgC() < 5 )
{
Msg( "requires 4 inputs, r g b a (in 0 - 255 range) \n" );
return;
}
float r = atof( args.Arg(1) ) / 255.0f;
float g = atof( args.Arg(2) ) / 255.0f;
float b = atof( args.Arg(3) ) / 255.0f;
float a = atof( args.Arg(4) ) / 255.0f;
tf_sheen_color_override_r.SetValue( r );
tf_sheen_color_override_g.SetValue( g );
tf_sheen_color_override_b.SetValue( b );
tf_sheen_color_override_a.SetValue( a );
}
ConVar cl_taunt_max_turn_speed( "cl_taunt_max_turn_speed", "0", FCVAR_HIDDEN | FCVAR_CHEAT );
ConVar cl_halloween_kart_turn_speed( "cl_halloween_kart_turn_speed", "100" );
#endif // Staging only
ConVar tf_sheen_framerate( "tf_sheen_framerate", "25", FCVAR_NONE | FCVAR_HIDDEN, "Set Sheen Frame Rate" );
extern ConVar tf_killstreak_alwayson;
ConVar tf_sheen_alpha_firstperson( "tf_sheen_alpha_firstperson", "0.1", FCVAR_NONE, "Set the Alpha Value for first person sheens" );
ConVar tf_killstreakeyes_minkills( "tf_killstreakeyes_minkills", "5", FCVAR_DEVELOPMENTONLY, "min kills to get base eyeglow" );
ConVar tf_killstreakeyes_maxkills( "tf_killstreakeyes_maxkills", "10", FCVAR_DEVELOPMENTONLY, "kills to get the max eye glow effect" );
//ConVar spectate_random_server_basetime( "spectate_random_server_basetime", "240", FCVAR_DEVELOPMENTONLY );
ConVar cl_autorezoom( "cl_autorezoom", "1", FCVAR_USERINFO | FCVAR_ARCHIVE, "When set to 1, sniper rifle will re-zoom after firing a zoomed shot." );
ConVar tf_remember_activeweapon( "tf_remember_activeweapon", "0", FCVAR_CLIENTDLL | FCVAR_ARCHIVE | FCVAR_USERINFO, "Setting this to 1 will make the active weapon persist between lives." );
ConVar tf_remember_lastswitched( "tf_remember_lastswitched", "0", FCVAR_CLIENTDLL | FCVAR_ARCHIVE | FCVAR_USERINFO, "Setting this to 1 will make the 'last weapon' persist between lives." );
ConVar cl_autoreload( "cl_autoreload", "1", FCVAR_USERINFO | FCVAR_ARCHIVE, "When set to 1, clip-using weapons will automatically be reloaded whenever they're not being fired." );
ConVar tf_respawn_on_loadoutchanges( "tf_respawn_on_loadoutchanges", "1", FCVAR_ARCHIVE, "When set to 1, you will automatically respawn whenever you change loadouts inside a respawn zone." );
ConVar sb_dontshow_maxplayer_warning( "sb_dontshow_maxplayer_warning", "0", FCVAR_ARCHIVE );
ConVar sb_close_browser_on_connect( "sb_close_browser_on_connect", "1", FCVAR_ARCHIVE );
ConVar tf_spectate_pyrovision( "tf_spectate_pyrovision", "0", FCVAR_ARCHIVE, "When on, spectator will see the world with Pyrovision active", VisionMode_ChangeCallback );
ConVar tf_replay_pyrovision( "tf_replay_pyrovision", "0", FCVAR_ARCHIVE, "When on, replays will be seen with Pyrovision active", VisionMode_ChangeCallback );
ConVar tf_taunt_first_person( "tf_taunt_first_person", "0", FCVAR_NONE, "1 = taunts remain first-person" );
ConVar tf_romevision_opt_in( "tf_romevision_opt_in", "0", FCVAR_ARCHIVE, "Enable Romevision in Mann vs. Machine mode when available." );
ConVar tf_romevision_skip_prompt( "tf_romevision_skip_prompt", "0", FCVAR_ARCHIVE, "If nonzero, skip the prompt about sharing Romevision." );
#ifdef STAGING_ONLY
extern ConVar tf_bountymode_showhealth;
#endif // STAGING_ONLY
#define BDAY_HAT_MODEL "models/effects/bday_hat.mdl"
#define BOMB_HAT_MODEL "models/props_lakeside_event/bomb_temp_hat.mdl"
#define BOMBONOMICON_MODEL "models/props_halloween/bombonomicon.mdl"
IMaterial *g_pHeadLabelMaterial[2] = { NULL, NULL };
void SetupHeadLabelMaterials( void );
extern CBaseEntity *BreakModelCreateSingle( CBaseEntity *pOwner, breakmodel_t *pModel, const Vector &position,
const QAngle &angles, const Vector &velocity, const AngularImpulse &angVelocity, int nSkin, const breakablepropparams_t ¶ms );
extern int EconWear_ToIntCategory( float flWear );
const char *g_pszHeadGibs[] =
{
"",
"models/player\\gibs\\scoutgib007.mdl",
"models/player\\gibs\\snipergib005.mdl",
"models/player\\gibs\\soldiergib007.mdl",
"models/player\\gibs\\demogib006.mdl",
"models/player\\gibs\\medicgib007.mdl",
"models/player\\gibs\\heavygib007.mdl",
"models/player\\gibs\\pyrogib008.mdl",
"models/player\\gibs\\spygib007.mdl",
"models/player\\gibs\\engineergib006.mdl",
};
const char *g_pszBotHeadGibs[] =
{
"",
"models/bots\\gibs\\scoutbot_gib_head.mdl",
"models/bots\\gibs\\sniperbot_gib_head.mdl",
"models/bots\\gibs\\soldierbot_gib_head.mdl",
"models/bots\\gibs\\demobot_gib_head.mdl",
"models/bots\\gibs\\medicbot_gib_head.mdl",
"models/bots\\gibs\\heavybot_gib_head.mdl",
"models/bots\\gibs\\pyrobot_gib_head.mdl",
"models/bots\\gibs\\spybot_gib_head.mdl",
"models/bots\\gibs\\engineerbot_gib_head.mdl",
};
const char *pszHeadLabelNames[] =
{
"effects/speech_voice_red",
"effects/speech_voice_blue"
};
extern SkyBoxMaterials_t s_PyroSkyboxMaterials;
#define TF_PLAYER_HEAD_LABEL_RED 0
#define TF_PLAYER_HEAD_LABEL_BLUE 1
CLIENTEFFECT_REGISTER_BEGIN( PrecacheInvuln )
CLIENTEFFECT_MATERIAL( "models/effects/invulnfx_blue.vmt" )
CLIENTEFFECT_MATERIAL( "models/effects/invulnfx_red.vmt" )
CLIENTEFFECT_REGISTER_END()
// *********************************************************************************************************
// KillStreak Effect Data
// *********************************************************************************************************
struct killstreak_params_t
{
killstreak_params_t ( int iShaderIndex, const char *pTexture, bool bHasTeamColor,
int sheen_r, int sheen_g, int sheen_b, int sheen_a,
int color1_r, int color1_g, int color1_b, int color1_a,
int color2_r, int color2_g, int color2_b, int color2_a
) {
m_iShaderIndex = iShaderIndex;
m_pTexture = pTexture;
m_bHasTeamColor = bHasTeamColor;
m_sheen_r = (float)sheen_r / 255.0f;
m_sheen_g = (float)sheen_g / 255.0f;
m_sheen_b = (float)sheen_b / 255.0f;
m_sheen_a = (float)sheen_a / 255.0f;
m_color1_r = (float)color1_r / 255.0f;
m_color1_g = (float)color1_g / 255.0f;
m_color1_b = (float)color1_b / 255.0f;
m_color1_a = (float)color1_a / 255.0f;
m_color2_r = (float)color2_r / 255.0f;
m_color2_g = (float)color2_g / 255.0f;
m_color2_b = (float)color2_b / 255.0f;
m_color2_a = (float)color2_a / 255.0f;
}
int m_iShaderIndex;
bool m_bHasTeamColor;
const char *m_pTexture;
float m_sheen_r, m_sheen_g, m_sheen_b, m_sheen_a;
float m_color1_r, m_color1_g, m_color1_b, m_color1_a;
float m_color2_r, m_color2_g, m_color2_b, m_color2_a;
};
// *********************************************************************************************************
// Base Sheen Colors (Team Red)
static const killstreak_params_t g_KillStreakEffectsBase[] =
{
killstreak_params_t( 0, NULL, false, 0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0 ), // Empty (Index 0)
killstreak_params_t( 0, "Effects/AnimatedSheen/animatedsheen0", true, 200, 20, 15, 255, 255, 118, 118, 255, 255, 35, 28, 255 ),
killstreak_params_t( 0, "Effects/AnimatedSheen/animatedsheen0", false, 242, 172, 10, 255, 255, 237, 138, 255, 255, 213, 65, 255 ),
killstreak_params_t( 0, "Effects/AnimatedSheen/animatedsheen0", false, 255, 75, 5, 255, 255, 111, 5, 255, 255, 137, 31, 255 ),
killstreak_params_t( 0, "Effects/AnimatedSheen/animatedsheen0", false, 100, 255, 10, 255, 230, 255, 60, 255, 193, 255, 61, 255 ),
killstreak_params_t( 0, "Effects/AnimatedSheen/animatedsheen0", false, 40, 255, 70, 255, 103, 255, 121, 255, 165, 255, 193, 255 ),
killstreak_params_t( 0, "Effects/AnimatedSheen/animatedsheen0", false, 105, 20, 255, 255, 105, 20, 255, 255, 185, 145, 255, 255 ),
killstreak_params_t( 0, "Effects/AnimatedSheen/animatedsheen0", false, 255, 30, 255, 255, 255, 120, 255, 255, 255, 176, 217, 255 ),
};
// *********************************************************************************************************
// Optional Team Color
static const killstreak_params_t g_KillStreakEffectsBlue[] =
{
killstreak_params_t( 0, NULL, false, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ), // Empty (Index 0)
killstreak_params_t( 0, "Effects/AnimatedSheen/animatedsheen0", true, 40, 98, 200, 255, 0, 92, 255, 255, 134, 203, 243, 255 ),
};
// thirdperson medieval
static ConVar tf_medieval_thirdperson( "tf_medieval_thirdperson", "0", FCVAR_CLIENTDLL | FCVAR_ARCHIVE , "Turns on third-person camera in medieval mode." );
static ConVar tf_medieval_cam_idealdist( "tf_medieval_cam_idealdist", "125", FCVAR_CLIENTDLL | FCVAR_CHEAT ); // thirdperson distance
static ConVar tf_medieval_cam_idealdistright( "tf_medieval_cam_idealdistright", "25", FCVAR_CLIENTDLL | FCVAR_CHEAT ); // thirdperson distance
static ConVar tf_medieval_cam_idealdistup( "tf_medieval_cam_idealdistup", "-10", FCVAR_CLIENTDLL | FCVAR_CHEAT ); // thirdperson distance
static ConVar tf_medieval_cam_idealpitch( "tf_medieval_cam_idealpitch", "0", FCVAR_CLIENTDLL | FCVAR_CHEAT ); // thirdperson pitch
extern ConVar cam_idealpitch;
extern ConVar tf_allow_taunt_switch;
static void PromptAcceptReviveCallback( bool bCancel, void *pContext )
{
if ( bCancel )
{
KeyValues *kv = new KeyValues( "MVM_Revive_Response" );
kv->SetBool( "accepted", false );
engine->ServerCmdKeyValues( kv );
}
}
C_TFPlayerPreviewEffect g_PlayerPreviewEffect;
C_TFPlayerPreviewEffect::C_TFPlayerPreviewEffect() :
m_nPreviewEffect(PREVIEW_EFFECT_NONE)
, m_nTeam(-1)
{
}
void C_TFPlayerPreviewEffect::SetTeam(int nTeam)
{
if ( nTeam == m_nTeam )
return;
m_nTeam = nTeam;
const char *pszMaterial = NULL;
switch ( m_nTeam )
{
case TF_TEAM_BLUE:
pszMaterial = "models/effects/invulnfx_blue.vmt";
break;
case TF_TEAM_RED:
pszMaterial = "models/effects/invulnfx_red.vmt";
break;
default:
break;
}
if ( pszMaterial )
{
m_InvulnerableMaterial.Init( pszMaterial, TEXTURE_GROUP_CLIENT_EFFECTS );
}
else
{
m_InvulnerableMaterial.Shutdown();
}
}
void C_TFPlayerPreviewEffect::Reset()
{
SetEffect(PREVIEW_EFFECT_NONE);
SetTeam(-1);
}
C_EntityDissolve *DissolveEffect( C_BaseEntity *pTarget, float flTime );
void SetAppropriateCamera( C_TFPlayer *pPlayer )
{
if ( pPlayer->IsLocalPlayer() == false )
return;
if ( TFGameRules() &&
( ( TFGameRules()->IsInMedievalMode() && tf_medieval_thirdperson.GetBool() )
|| pPlayer->m_Shared.InCond( TF_COND_HALLOWEEN_GHOST_MODE ) ) )
{
g_ThirdPersonManager.SetForcedThirdPerson( true );
Vector offset( tf_medieval_cam_idealdist.GetFloat(), tf_medieval_cam_idealdistright.GetFloat(), tf_medieval_cam_idealdistup.GetFloat() );
g_ThirdPersonManager.SetDesiredCameraOffset( offset );
cam_idealpitch.SetValue( tf_medieval_cam_idealpitch.GetFloat() );
::input->CAM_ToThirdPerson();
pPlayer->ThirdPersonSwitch( true );
}
else
{
g_ThirdPersonManager.SetForcedThirdPerson( false );
}
}
// -------------------------------------------------------------------------------- //
// Player animation event. Sent to the client when a player fires, jumps, reloads, etc..
// -------------------------------------------------------------------------------- //
class C_TEPlayerAnimEvent : public C_BaseTempEntity
{
public:
DECLARE_CLASS( C_TEPlayerAnimEvent, C_BaseTempEntity );
DECLARE_CLIENTCLASS();
virtual void PostDataUpdate( DataUpdateType_t updateType )
{
VPROF( "C_TEPlayerAnimEvent::PostDataUpdate" );
// Create the effect.
if ( m_iPlayerIndex == TF_PLAYER_INDEX_NONE )
return;
EHANDLE hPlayer = cl_entitylist->GetNetworkableHandle( m_iPlayerIndex );
if ( !hPlayer )
return;
C_TFPlayer *pPlayer = dynamic_cast< C_TFPlayer* >( hPlayer.Get() );
if ( pPlayer && !pPlayer->IsDormant() )
{
// Ignore anim events that are also played on the client.
PlayerAnimEvent_t animEvent = (PlayerAnimEvent_t) m_iEvent.Get();
switch ( animEvent )
{
case PLAYERANIMEVENT_STUN_BEGIN:
case PLAYERANIMEVENT_STUN_MIDDLE:
case PLAYERANIMEVENT_STUN_END:
case PLAYERANIMEVENT_PASSTIME_THROW_BEGIN:
case PLAYERANIMEVENT_PASSTIME_THROW_MIDDLE:
case PLAYERANIMEVENT_PASSTIME_THROW_END:
case PLAYERANIMEVENT_PASSTIME_THROW_CANCEL:
break; // ignore these
default:
pPlayer->DoAnimationEvent( animEvent, m_nData );
break;
};
}
}
public:
CNetworkVar( int, m_iPlayerIndex );
CNetworkVar( int, m_iEvent );
CNetworkVar( int, m_nData );
};
IMPLEMENT_CLIENTCLASS_EVENT( C_TEPlayerAnimEvent, DT_TEPlayerAnimEvent, CTEPlayerAnimEvent );
//-----------------------------------------------------------------------------
// Data tables and prediction tables.
//-----------------------------------------------------------------------------
BEGIN_RECV_TABLE_NOBASE( C_TEPlayerAnimEvent, DT_TEPlayerAnimEvent )
RecvPropInt( RECVINFO( m_iPlayerIndex ) ),
RecvPropInt( RECVINFO( m_iEvent ) ),
RecvPropInt( RECVINFO( m_nData ) )
END_RECV_TABLE()
//=============================================================================
//
// Ragdoll
//
// ----------------------------------------------------------------------------- //
// Client ragdoll entity.
// ----------------------------------------------------------------------------- //
ConVar cl_ragdoll_physics_enable( "cl_ragdoll_physics_enable", "1", 0, "Enable/disable ragdoll physics." );
ConVar cl_ragdoll_fade_time( "cl_ragdoll_fade_time", "15", FCVAR_CLIENTDLL );
ConVar cl_ragdoll_forcefade( "cl_ragdoll_forcefade", "0", FCVAR_CLIENTDLL );
ConVar cl_ragdoll_pronecheck_distance( "cl_ragdoll_pronecheck_distance", "64", FCVAR_GAMEDLL );
class C_TFRagdoll : public C_BaseFlex
{
public:
DECLARE_CLASS( C_TFRagdoll, C_BaseFlex );
DECLARE_CLIENTCLASS();
C_TFRagdoll();
~C_TFRagdoll();
virtual void OnDataChanged( DataUpdateType_t type );
IRagdoll* GetIRagdoll() const;
void ImpactTrace( trace_t *pTrace, int iDamageType, const char *pCustomImpactName );
void ClientThink( void );
// Deal with recording
virtual void GetToolRecordingState( KeyValues *msg );
void StartFadeOut( float fDelay );
void EndFadeOut();
void DissolveEntity( CBaseEntity* pEnt );
EHANDLE GetPlayerHandle( void )
{
if ( m_iPlayerIndex == TF_PLAYER_INDEX_NONE )
return NULL;
return cl_entitylist->GetNetworkableHandle( m_iPlayerIndex );
}
bool IsRagdollVisible();
float GetBurnStartTime() { return m_flBurnEffectStartTime; }
virtual void BuildTransformations( CStudioHdr *hdr, Vector *pos, Quaternion q[], const matrix3x4_t& cameraTransform, int boneMask, CBoneBitList &boneComputed );
virtual void SetupWeights( const matrix3x4_t *pBoneToWorld, int nFlexWeightCount, float *pFlexWeights, float *pFlexDelayedWeights );
bool IsDeathAnim() { return m_bDeathAnim; }
int GetDamageCustom() { return m_iDamageCustom; }
virtual bool GetAttachment( int iAttachment, matrix3x4_t &attachmentToWorld );
virtual bool GetAttachmentDeferred( int iAttachment, matrix3x4_t &attachmentToWorld );
int GetClass() { return m_iClass; }
float GetPercentInvisible( void ) { return m_flPercentInvisible; }
bool IsCloaked( void ) { return m_bCloaked; }
int GetRagdollTeam( void ){ return m_iTeam; }
float GetHeadScale() const { return m_flHeadScale; }
float GetTorsoScale() const { return m_flTorsoScale; }
float GetHandScale() const { return m_flHandScale; }
private:
C_TFRagdoll( const C_TFRagdoll & ) {}
void Interp_Copy( C_BaseAnimatingOverlay *pSourceEntity );
void CreateTFRagdoll();
void CreateTFGibs( bool bDestroyRagdoll = true, bool bCurrentPosition = false );
void CreateWearableGibs( bool bDisguiseWearables );
void CreateTFHeadGib();
virtual float FrameAdvance( float flInterval );
bool IsDecapitation();
bool IsHeadSmash();
virtual int InternalDrawModel( int flags );
private:
CNetworkVector( m_vecRagdollVelocity );
CNetworkVector( m_vecRagdollOrigin );
int m_iPlayerIndex;
float m_fDeathTime;
bool m_bFadingOut;
bool m_bGib;
bool m_bBurning;
bool m_bElectrocuted;
bool m_bBatted;
bool m_bDissolving;
bool m_bFeignDeath;
bool m_bWasDisguised;
bool m_bCloaked;
bool m_bBecomeAsh;
int m_iDamageCustom;
bool m_bGoldRagdoll;
bool m_bIceRagdoll;
CountdownTimer m_freezeTimer;
CountdownTimer m_frozenTimer;
int m_iTeam;
int m_iClass;
float m_flBurnEffectStartTime; // start time of burning, or 0 if not burning
bool m_bRagdollOn;
bool m_bDeathAnim;
bool m_bOnGround;
bool m_bFixedConstraints;
matrix3x4_t m_mHeadAttachment;
bool m_bBaseTransform;
float m_flPercentInvisible;
float m_flTimeToDissolve;
bool m_bCritOnHardHit; // plays the red mist particle effect
float m_flHeadScale;
float m_flTorsoScale;
float m_flHandScale;
CMaterialReference m_MaterialOverride;
CUtlVector<CHandle<CEconWearable > > m_hRagWearables; // These look like they are no longer used?
CUtlVector< CHandle< CEconWearable > > m_hClientWearables; // wearables on the ragdoll that are "following" it
bool m_bCreatedWhilePlaybackSkipping;
};
IMPLEMENT_CLIENTCLASS_DT_NOBASE( C_TFRagdoll, DT_TFRagdoll, CTFRagdoll )
RecvPropVector( RECVINFO(m_vecRagdollOrigin) ),
RecvPropInt( RECVINFO( m_iPlayerIndex ) ),
RecvPropVector( RECVINFO(m_vecForce) ),
RecvPropVector( RECVINFO(m_vecRagdollVelocity) ),
RecvPropInt( RECVINFO( m_nForceBone ) ),
RecvPropBool( RECVINFO( m_bGib ) ),
RecvPropBool( RECVINFO( m_bBurning ) ),
RecvPropBool( RECVINFO( m_bElectrocuted ) ),
RecvPropBool( RECVINFO( m_bFeignDeath ) ),
RecvPropBool( RECVINFO( m_bWasDisguised ) ),
RecvPropBool( RECVINFO( m_bOnGround ) ),
RecvPropBool( RECVINFO( m_bCloaked ) ),
RecvPropBool( RECVINFO( m_bBecomeAsh ) ),
RecvPropInt( RECVINFO( m_iDamageCustom ) ),
RecvPropInt( RECVINFO( m_iTeam ) ),
RecvPropInt( RECVINFO( m_iClass ) ),
RecvPropUtlVector( RECVINFO_UTLVECTOR( m_hRagWearables ), 8, RecvPropEHandle(NULL, 0, 0) ),
RecvPropBool( RECVINFO( m_bGoldRagdoll ) ),
RecvPropBool( RECVINFO( m_bIceRagdoll ) ),
RecvPropBool( RECVINFO( m_bCritOnHardHit ) ),
RecvPropFloat( RECVINFO( m_flHeadScale ) ),
RecvPropFloat( RECVINFO( m_flTorsoScale ) ),
RecvPropFloat( RECVINFO( m_flHandScale ) ),
END_RECV_TABLE()
//-----------------------------------------------------------------------------
// Purpose:
// Input : -
//-----------------------------------------------------------------------------
C_TFRagdoll::C_TFRagdoll()
{
m_iPlayerIndex = TF_PLAYER_INDEX_NONE;
m_fDeathTime = -1;
m_bFadingOut = false;
m_bGib = false;
m_bBurning = false;
m_bElectrocuted = false;
m_bBatted = false;
m_bDissolving = false;
m_bFeignDeath = false;
m_bWasDisguised = false;
m_bCloaked = false;
m_bBecomeAsh = false;
m_flBurnEffectStartTime = 0.0f;
m_iDamageCustom = 0;
m_bGoldRagdoll = false;
m_bIceRagdoll = false;
m_freezeTimer.Invalidate();
m_frozenTimer.Invalidate();
m_iTeam = -1;
m_iClass = -1;
m_nForceBone = -1;
m_bRagdollOn = false;
m_bDeathAnim = false;
m_bOnGround = false;
m_bBaseTransform = false;
m_bFixedConstraints = false;
m_flTimeToDissolve = 0.3f;
m_bCritOnHardHit = false;
m_flHeadScale = 1.f;
m_flTorsoScale = 1.f;
m_flHandScale = 1.f;
UseClientSideAnimation();
m_bCreatedWhilePlaybackSkipping = engine->IsSkippingPlayback();
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : -
//-----------------------------------------------------------------------------
C_TFRagdoll::~C_TFRagdoll()
{
PhysCleanupFrictionSounds( this );
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : *pSourceEntity -
//-----------------------------------------------------------------------------
void C_TFRagdoll::Interp_Copy( C_BaseAnimatingOverlay *pSourceEntity )
{
if ( !pSourceEntity )
return;
VarMapping_t *pSrc = pSourceEntity->GetVarMapping();
VarMapping_t *pDest = GetVarMapping();
// Find all the VarMapEntry_t's that represent the same variable.
for ( int i = 0; i < pDest->m_Entries.Count(); i++ )
{
VarMapEntry_t *pDestEntry = &pDest->m_Entries[i];
for ( int j=0; j < pSrc->m_Entries.Count(); j++ )
{
VarMapEntry_t *pSrcEntry = &pSrc->m_Entries[j];
if ( !Q_strcmp( pSrcEntry->watcher->GetDebugName(), pDestEntry->watcher->GetDebugName() ) )
{
pDestEntry->watcher->Copy( pSrcEntry->watcher );
break;
}
}
}
}
//-----------------------------------------------------------------------------
// Purpose: Setup vertex weights for drawing
//-----------------------------------------------------------------------------
void C_TFRagdoll::SetupWeights( const matrix3x4_t *pBoneToWorld, int nFlexWeightCount, float *pFlexWeights, float *pFlexDelayedWeights )
{
// While we're dying, we want to mimic the facial animation of the player. Once they're dead, we just stay as we are.
EHANDLE hPlayer = GetPlayerHandle();
if ( ( hPlayer && hPlayer->IsAlive()) || !hPlayer )
{
BaseClass::SetupWeights( pBoneToWorld, nFlexWeightCount, pFlexWeights, pFlexDelayedWeights );
}
else if ( hPlayer )
{
hPlayer->SetupWeights( pBoneToWorld, nFlexWeightCount, pFlexWeights, pFlexDelayedWeights );
}
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : *pTrace -
// iDamageType -
// *pCustomImpactName -
//-----------------------------------------------------------------------------
void C_TFRagdoll::ImpactTrace( trace_t *pTrace, int iDamageType, const char *pCustomImpactName )
{
VPROF( "C_TFRagdoll::ImpactTrace" );
IPhysicsObject *pPhysicsObject = VPhysicsGetObject();
if( !pPhysicsObject )
return;
Vector vecDir;
VectorSubtract( pTrace->endpos, pTrace->startpos, vecDir );
if ( iDamageType == DMG_BLAST )
{
// Adjust the impact strength and apply the force at the center of mass.
vecDir *= 4000;
pPhysicsObject->ApplyForceCenter( vecDir );
}
else
{
// Find the apporx. impact point.
Vector vecHitPos;
VectorMA( pTrace->startpos, pTrace->fraction, vecDir, vecHitPos );
VectorNormalize( vecDir );
// Adjust the impact strength and apply the force at the impact point..
vecDir *= 4000;
pPhysicsObject->ApplyForceOffset( vecDir, vecHitPos );
}
m_pRagdoll->ResetRagdollSleepAfterTime();
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : -
//-----------------------------------------------------------------------------
void C_TFRagdoll::CreateTFRagdoll()
{
// Get the player.
C_TFPlayer *pPlayer = NULL;
EHANDLE hPlayer = GetPlayerHandle();
if ( hPlayer )
{
pPlayer = dynamic_cast<C_TFPlayer*>( hPlayer.Get() );
}
int nModelIndex = -1;
if ( pPlayer && pPlayer->GetPlayerClass() && !pPlayer->ShouldDrawSpyAsDisguised() )
{
nModelIndex = modelinfo->GetModelIndex( pPlayer->GetPlayerClass()->GetModelName() );
}
else
{
TFPlayerClassData_t *pData = GetPlayerClassData( m_iClass );
if ( pData )
{
nModelIndex = modelinfo->GetModelIndex( pData->GetModelName() );
}
}
if ( pPlayer )
{
m_flHeadScale = pPlayer->GetHeadScale();
m_flTorsoScale = pPlayer->GetTorsoScale();
m_flHandScale = pPlayer->GetHandScale();
}
if ( nModelIndex != -1 )
{
SetModelIndex( nModelIndex );
if ( m_iTeam == TF_TEAM_RED )
{
m_nSkin = 0;
}
else
{
m_nSkin = 1;
}
}
// Check for any special player skin override behaviour.
if ( pPlayer && pPlayer->BRenderAsZombie() )
{
C_TFPlayer::AdjustSkinIndexForZombie( m_iClass, m_nSkin );
}
// We check against new-style (special flag to indicate goldification) and old style (custom damage type)
// to maintain old demos involving the golden wrench.
if ( m_bGoldRagdoll || m_iDamageCustom == TF_DMG_CUSTOM_GOLD_WRENCH )
{
EmitSound( "Saxxy.TurnGold" );
m_bFixedConstraints = true;
}
if ( m_bIceRagdoll )
{
EmitSound( "Icicle.TurnToIce" );
ParticleProp()->Create( "xms_icicle_impact_dryice", PATTACH_ABSORIGIN_FOLLOW );
m_freezeTimer.Start( RandomFloat( 0.1f, 0.75f ) );
m_frozenTimer.Start( RandomFloat( 9.0f, 11.0f ) );
}
#ifdef _DEBUG
DevMsg( 2, "CreateTFRagdoll %d %d\n", gpGlobals->framecount, pPlayer ? pPlayer->entindex() : 0 );
#endif
if ( pPlayer && !pPlayer->IsDormant() )
{
// Move my current model instance to the ragdoll's so decals are preserved.
pPlayer->SnatchModelInstance( this );
VarMapping_t *varMap = GetVarMapping();
// Copy all the interpolated vars from the player entity.
// The entity uses the interpolated history to get bone velocity.
if ( !pPlayer->IsLocalPlayer() && pPlayer->IsInterpolationEnabled() )
{
Interp_Copy( pPlayer );
SetAbsAngles( pPlayer->GetRenderAngles() );
GetRotationInterpolator().Reset();
m_flAnimTime = pPlayer->m_flAnimTime;
SetSequence( pPlayer->GetSequence() );