-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathasw_input.cpp
More file actions
1941 lines (1684 loc) · 63.7 KB
/
asw_input.cpp
File metadata and controls
1941 lines (1684 loc) · 63.7 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
#include "cbase.h"
#include "asw_input.h"
#include "c_asw_player.h"
#include "c_asw_marine.h"
#include "c_asw_alien.h"
#include "c_asw_weapon.h"
#include "asw_util_shared.h"
#include "asw_vgui_info_message.h"
#include "fx.h"
#include "idebugoverlaypanel.h"
#include "engine/IVDebugOverlay.h"
#include "vguimatsurface/imatsystemsurface.h"
#include "iclientmode.h"
#include <vgui_controls/AnimationController.h>
#include "asw_shareddefs.h"
#include "tier0/vprof.h"
#include "controller_focus.h"
#include "input.h"
#include "inputsystem/iinputsystem.h"
#include "c_asw_computer_area.h"
#include "c_asw_button_area.h"
#include "in_buttons.h"
#include "asw_gamerules.h"
#include "asw_melee_system.h"
#include "asw_trace_filter.h"
#include "rd_steam_input.h"
#include "radialmenu.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
extern ConVar rd_ray_trace_distance;
ConVar asw_marine_linear_turn_rate("asw_marine_linear_turn_rate", "1000", FCVAR_CHEAT, "Linear turning rate of the marine (used as minimum when fractional turning is employed)");
ConVar asw_marine_fraction_turn_scale("asw_marine_fraction_turn_scale", "0", FCVAR_CHEAT, "Scale for the fractional marine turning (large turns)");
ConVar asw_marine_turn_firing_fraction("asw_marine_turn_firing_fraction", "0.6", FCVAR_CHEAT, "Fractional turning value while firing, if using asw_marine_fraction_turn_scale");
ConVar asw_marine_turn_normal_fraction("asw_marine_turn_normal_fraction", "0.9", FCVAR_CHEAT, "Fractional turning value if using asw_marine_fraction_turn_scale");
ConVar asw_marine_turn_y_pos("asw_marine_turn_y_pos", "0.55", FCVAR_NONE, "Normalized height position for where the cursor changes the player from looking north to south.");
ConVar joy_autoattack( "joy_autoattack", "0", FCVAR_ARCHIVE, "If enabled, marine will fire when you push the right analog stick" );
ConVar joy_lock_firing_angle( "joy_lock_firing_angle", "0", FCVAR_ARCHIVE, "If enabled, your facing direction will be locked while firing instead of aiming to movement" );
ConVar joy_autoattack_threshold( "joy_autoattack_threshold", "0.6", FCVAR_ARCHIVE, "Threshold for joy_autoattack" );
ConVar joy_autoattack_angle( "joy_autoattack_angle", "10", FCVAR_ARCHIVE, "Facing has to be within this many degrees of aim for the marine to auto fire" );
ConVar joy_cursor_speed( "joy_cursor_speed", "2.0f", FCVAR_ARCHIVE, "Cursor speed of joystick when used in targeting mode" );
ConVar joy_cursor_scale( "joy_cursor_scale", "1.3f", FCVAR_ARCHIVE, "Cursor extent scale of joystick when used in targeting mode" );
ConVar joy_radius_snap_factor( "joy_radius_snap_factor", "2.0f", FCVAR_ARCHIVE, "Rate at which joystick targeting radius tracks the current cursor radius" );
ConVar joy_autowalk( "joy_autowalk", "0", FCVAR_ARCHIVE, "If enabled, marine will walk when you push the right analog stick" );
ConVar joy_autowalk_threshold( "joy_autowalk_threshold", "0.3", FCVAR_ARCHIVE, "Threshold for joy_autowalk" );
ConVar joy_aim_to_movement( "joy_aim_to_movement", "1", FCVAR_ARCHIVE, "Aim in the direction of movement if the aiming stick is not in use" );
ConVar joy_aim_to_movement_time( "joy_aim_to_movement_time", "1.0f", FCVAR_ARCHIVE, "Time before the player automatically aims in the direction of movement." );
ConVar joy_tilted_view( "joy_tilted_view", "0", FCVAR_ARCHIVE, "Set to 1 when using maps with tilted view to rotate player movement." );
ConVar asw_horizontal_autoaim( "asw_horizontal_autoaim", "1", FCVAR_NONE, "Applies horizontal correction towards best aim ent." );
ConVar joy_disable_movement_in_ui( "joy_disable_movement_in_ui", "1", FCVAR_NONE, "Disables joystick character movement when UI is active." );
ConVar rd_input_controller_mode_mouse( "rd_input_controller_mode_mouse", "-1", FCVAR_NONE );
ConVar rd_input_controller_mode_keyboard( "rd_input_controller_mode_keyboard", "-1", FCVAR_NONE );
ConVar rd_aim_ignore_above_camera_z( "rd_aim_ignore_above_camera_z", "-60", FCVAR_NONE, "Targets above the camera by this Z distance are ignored in top-down mode" );
extern kbutton_t in_attack;
extern kbutton_t in_walk;
extern int g_asw_iPlayerListOpen;
extern int g_asw_iTabbedGridDetailsOpen;
extern ConVar asw_DebugAutoAim;
extern ConVar in_forceuser;
extern ConVar asw_item_hotbar_hud;
extern ConVar in_joystick;
extern ConVar rd_ground_shooting;
extern ConVar asw_marine_gun_offset_x;
extern ConVar asw_marine_gun_offset_y;
extern ConVar asw_marine_gun_offset_z;
//-----------------------------------------------------------------------------
// Purpose: ASW Input interface
//-----------------------------------------------------------------------------
static CASWInput g_Input;
// Expose this interface
IInput *input = ( IInput * )&g_Input;
CASWInput *ASWInput()
{
return &g_Input;
}
void GetVGUICursorPos( int& x, int& y );
static char const *s_HumanKeynames[][2] =
{
{ "MWHEELUP", "#asw_mouse_wheel_up" },
{ "MWHEELDOWN", "#asw_mouse_wheel_down" },
{ "MOUSE1", "#asw_mouse1" },
{ "MOUSE2", "#asw_mouse2" },
{ "MOUSE3", "#asw_mouse3" },
{ "JOY1", "#asw_360_a" },
{ "JOY2", "#asw_360_b" },
{ "JOY3", "#asw_360_x" },
{ "JOY4", "#asw_360_y" },
{ "AUX5", "#asw_360_left_bumper" },
{ "AUX6", "#asw_360_right_bumper" },
{ "AUX7", "#asw_360_back" },
{ "AUX8", "#asw_360_start" },
{ "AUX9", "#asw_360_left_stick_in" },
{ "AUX10", "#asw_360_right_stick_in" },
{ "AUX29", "#asw_360_dpad_up" },
{ "AUX30", "#asw_360_dpad_right" },
{ "AUX31", "#asw_360_dpad_down" },
{ "AUX32", "#asw_360_dpad_left" },
{ "Z AXIS NEG", "#asw_360_right_trigger" },
{ "Z AXIS POS", "#asw_360_left_trigger" },
{ "X AXIS POS", "#asw_360_left_stick_right" },
{ "X AXIS NEG", "#asw_360_left_stick_left" },
{ "Y AXIS POS", "#asw_360_left_stick_down" },
{ "Y AXIS NEG", "#asw_360_left_stick_up" },
{ "U AXIS POS", "#asw_360_right_stick_right" },
{ "U AXIS NEG", "#asw_360_right_stick_left" },
{ "R AXIS POS", "#asw_360_right_stick_down" },
{ "R AXIS NEG", "#asw_360_right_stick_up" },
{ "A_BUTTON", "#asw_360_a" },
{ "B_BUTTON", "#asw_360_b" },
{ "X_BUTTON", "#asw_360_x" },
{ "Y_BUTTON", "#asw_360_y" },
{ "L_SHOULDER", "#asw_360_left_bumper" },
{ "R_SHOULDER", "#asw_360_right_bumper" },
{ "BACK", "#asw_360_back" },
{ "START", "#asw_360_start" },
{ "STICK1", "#asw_360_left_stick_in" },
{ "STICK2", "#asw_360_right_stick_in" },
{ "UP", "#asw_360_dpad_up" },
{ "RIGHT", "#asw_360_dpad_right" },
{ "DOWN", "#asw_360_dpad_down" },
{ "LEFT", "#asw_360_dpad_left" },
{ "R_TRIGGER", "#asw_360_right_trigger" },
{ "L_TRIGGER", "#asw_360_left_trigger" },
{ "S1_RIGHT", "#asw_360_left_stick_right" },
{ "S1_LEFT", "#asw_360_left_stick_left" },
{ "S1_DOWN", "#asw_360_left_stick_down" },
{ "S1_UP", "#asw_360_left_stick_up" },
{ "S2_RIGHT", "#asw_360_right_stick_right" },
{ "S2_LEFT", "#asw_360_right_stick_left" },
{ "S2_DOWN", "#asw_360_right_stick_down" },
{ "S2_UP", "#asw_360_right_stick_up" },
};
#define ASW_NUM_STORES 25
static float StoreAlienPosX[ASW_NUM_STORES];
static float StoreAlienPosY[ASW_NUM_STORES];
static float StoreAlienRadius[ASW_NUM_STORES];
static float StoreMarinePosX[ASW_NUM_STORES];
static float StoreMarinePosY[ASW_NUM_STORES];
static Vector2D StoreLineDir[ASW_NUM_STORES];
static int StoreCol[ASW_NUM_STORES];
void ASW_StoreLineCircle(int index, float alien_x, float alien_y, float alien_radius, float marine_x, float marine_y, Vector2D LineDir, int iCol)
{
if (index >= ASW_NUM_STORES)
return;
StoreAlienPosX[index] = alien_x;
StoreAlienPosY[index] = alien_y;
StoreAlienRadius[index] = alien_radius;
StoreMarinePosX[index] = marine_x;
StoreMarinePosY[index] = marine_y;
StoreLineDir[index] = LineDir;
StoreCol[index] = iCol;
}
void ASW_GetLineCircle(int index, float &alien_x, float &alien_y, float &alien_radius, float &marine_x, float &marine_y, Vector2D &LineDir, int &iCol)
{
if (index >= ASW_NUM_STORES)
return;
alien_radius = StoreAlienRadius[index];
if ( alien_radius == 0 )
return;
alien_x = StoreAlienPosX[index];
alien_y = StoreAlienPosY[index];
marine_x = StoreMarinePosX[index];
marine_y = StoreMarinePosY[index];
LineDir = StoreLineDir[index];
iCol = StoreCol[index];
}
void ASW_StoreClearAll()
{
for (int index=0;index<ASW_NUM_STORES;index++)
{
StoreAlienPosX[index] = 0;
StoreAlienPosY[index] = 0;
StoreAlienRadius[index] = 0;
StoreMarinePosX[index] = 0;
StoreMarinePosY[index] = 0;
StoreLineDir[index] = Vector2D(0,0);
}
}
// asw
bool MarineControllingTurret()
{
C_ASW_Marine *pMarine = C_ASW_Marine::GetLocalMarine();
return pMarine && pMarine->IsControllingTurret();
}
#define ASW_MARINE_HULL_MINS Vector(-13, -13, 0)
#define ASW_MARINE_HULL_MAXS Vector(13, 13, 72)
bool ValidOrderingSurface(const trace_t &tr)
{
if (!Q_strcmp("TOOLS/TOOLSNOLIGHT", tr.surface.name))
return false;
// check marine hull can fit in this spot
Ray_t ray;
trace_t pm;
ray.Init( tr.endpos, tr.endpos, ASW_MARINE_HULL_MINS, ASW_MARINE_HULL_MAXS );
UTIL_TraceRay( ray, MASK_PLAYERSOLID, NULL, COLLISION_GROUP_PLAYER_MOVEMENT, &pm );
if ( (pm.contents & MASK_PLAYERSOLID) && pm.m_pEnt )
{
return false;
}
return true;
};
// trace used by marine ordering - skips over toolsnolight and clip brushes, etc
bool HUDTraceToWorld(float screenx, float screeny, Vector &HitLocation, bool bUseMarineHull)
{
// Verify that we have input.
Assert( ASWInput() != NULL );
Vector X, Y, Z, projected;
Vector traceEnd;
Vector vCameraLocation;
Vector CamResult, TraceDirection;
QAngle CameraAngle;
HitLocation.Init(0,0,0);
C_ASW_Player *pPlayer = C_ASW_Player::GetLocalASWPlayer();
if (!pPlayer)
return false;
int omx, omy;
ASWInput()->ASW_GetCameraLocation(pPlayer, vCameraLocation, CameraAngle, omx, omy, false);
float fRatio = float( ScreenHeight() ) / float( ScreenWidth() );
AngleVectors(CameraAngle, &X, &Y, &Z);
float FOVAngle = pPlayer->GetFOV();
projected = X
- tanf(FOVAngle*M_PI/180*0.5) * 2 * Y * (screenx) * ( 0.75f / fRatio )
+ tanf(FOVAngle*M_PI/180*0.5) * 2 * Z * (screeny) * 0.75f;
TraceDirection = projected;
TraceDirection.NormalizeInPlace();
Vector traceStart = vCameraLocation;
traceEnd = traceStart + TraceDirection * rd_ray_trace_distance.GetFloat();
if (bUseMarineHull)
{
// do a trace into the world to see what we've pointing directly at
Ray_t ray2;
trace_t tr;
ray2.Init( traceStart, traceEnd, ASW_MARINE_HULL_MINS, ASW_MARINE_HULL_MAXS );
// BenLubar(sd2-ceiling-ents): use CASW_Trace_Filter to handle *_asw_fade properly
CASW_Trace_Filter filter( pPlayer, COLLISION_GROUP_NONE );
// reactivedrop: changed MASK_SOLID_BRUSHONLY to MASK_VISIBLE | CONTENTS_GRATE
// this fixes flares/grenades to aim correctly on visible surfaces
UTIL_TraceRay( ray2, MASK_SOLID | CONTENTS_IGNORE_NODRAW_OPAQUE, &filter, &tr );
if ( tr.fraction >= 1.0f )
return false;
bool bValidSurface = ValidOrderingSurface(tr);
HitLocation = tr.endpos;
if (!bValidSurface)
{
// trace down from above the hitlocation with a marine hull
Ray_t ray;
trace_t pm;
ray.Init( HitLocation + Vector(0, 0, 40), HitLocation, ASW_MARINE_HULL_MINS, ASW_MARINE_HULL_MAXS );
UTIL_TraceRay( ray, MASK_PLAYERSOLID, NULL, COLLISION_GROUP_PLAYER_MOVEMENT, &pm );
if ( pm.startsolid || pm.fraction < 0.01f )
{
return false;
}
HitLocation = pm.endpos;
//Msg("Using raised pos\n");
}
else
{
// trace down in-case this spot is in the air
Ray_t ray;
trace_t pm;
ray.Init( HitLocation, HitLocation - Vector(0, 0, 2200), ASW_MARINE_HULL_MINS, ASW_MARINE_HULL_MAXS );
UTIL_TraceRay( ray, MASK_PLAYERSOLID, NULL, COLLISION_GROUP_PLAYER_MOVEMENT, &pm );
if (pm.startsolid)
{
return false;
}
else
{
HitLocation = pm.endpos;
}
}
}
else
{
// do a trace into the world to see what we've pointing directly at
trace_t tr;
// BenLubar(sd2-ceiling-ents): use CASW_Trace_Filter to handle *_asw_fade properly
CASW_Trace_Filter filter( pPlayer, COLLISION_GROUP_NONE );
// reactivedrop: changed MASK_SOLID_BRUSHONLY to MASK_VISIBLE
// this fixes flares/grenades to aim correctly on visible surfaces
UTIL_TraceLine( traceStart, traceEnd, MASK_SOLID | CONTENTS_IGNORE_NODRAW_OPAQUE, &filter, &tr );
if ( tr.fraction >= 1.0f )
return false;
// if we hit tools no light texture, retrace through it
bool bValidSurface = ValidOrderingSurface(tr);
//int iRetrace = 4;
HitLocation = vCameraLocation + tr.fraction * rd_ray_trace_distance.GetFloat() * TraceDirection;
return bValidSurface;
}
// Note: disabled this code that repeatedly retraces through bad surfaces
/*
while (!bValidSurface && iRetrace > 0)
{
traceStart = tr.endpos + TraceDirection * 2;
traceEnd = traceStart + TraceDirection * 3000;
UTIL_TraceLine(traceStart, traceEnd, MASK_SOLID_BRUSHONLY, pPlayer, COLLISION_GROUP_NONE, &tr);
if ( tr.fraction >= 1.0f )
return false;
HitLocation = traceStart + tr.fraction * 3000 * TraceDirection;
bValidSurface = ValidOrderingSurface(tr);
iRetrace--;
}*/
//Msg("trace hit %s flags %d surfaceprops %d\n", tr.surface.name, tr.surface.flags, tr.surface.surfaceProps);
//FX_MicroExplosion(HitLocation, Vector(0,0,1));
return true;
}
// Finds the world location we should be aiming at, given the XY coords of our mouse cursor
// bIgnoreCursorPosition - if true, don't perform a trace beneath the cursor; just use the facing direction
C_BaseEntity* HUDToWorld(float screenx, float screeny,
Vector &HitLocation, IASW_Client_Aim_Target* &pAutoAimEnt,
bool bPreferFlatAiming, bool bIgnoreCursorPosition, float flForwardMove, float flSideMove)
{
// Verify that we have input.
Assert( ASWInput() != NULL );
HitLocation.Init(0,0,0);
C_ASW_Player *pPlayer = C_ASW_Player::GetLocalASWPlayer();
if (!pPlayer)
return NULL;
ASWInput()->SetAutoaimEntity( NULL );
C_ASW_Inhabitable_NPC *pNPC = pPlayer->GetViewNPC();
C_ASW_Weapon *pWeapon = pNPC ? pNPC->GetActiveASWWeapon() : NULL;
float flWeaponRadiusScale = pWeapon ? pWeapon->GetAutoAimRadiusScale() : 1.0f;
bool bWeaponHasRadiusScale = ( flWeaponRadiusScale > 1.0f );
// our source firing point
Vector marineScreenPos, alienScreenPos, bestAlienScreenPos;
Vector vWorldSpaceCameraToCursor;
IASW_Client_Aim_Target* pBestAlien = NULL;
IASW_Client_Aim_Target* pHighlightAlien = NULL; // this the ent our cursor is over
float flBestAlienRadius = 0;
bool bBestAlienUsingFlareAutoaim = false;
int omx, omy;
Vector vCameraLocation;
QAngle cameraAngle;
Vector vTraceEnd;
int nTraceMask = (CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_WINDOW|CONTENTS_MONSTER|CONTENTS_GRATE|CONTENTS_HITBOX); // CONTENTS_PLAYERCLIP
trace_t tr;
int nDebugLine = 3;
ASWInput()->ASW_GetCameraLocation(pPlayer, vCameraLocation, cameraAngle, omx, omy, false);
Vector X, Y, Z;
Vector CamResult;
if ( pPlayer->GetASWControls() == ASWC_TOPDOWN )
{
float fRatio = float( ScreenHeight() ) / float( ScreenWidth() );
AngleVectors( cameraAngle, &X, &Y, &Z );
float FOVAngle = pPlayer->GetFOV();
vWorldSpaceCameraToCursor = X
- tanf( FOVAngle * M_PI / 180 * 0.5 ) * 2 * Y * ( screenx ) * ( 0.75f / fRatio )
+ tanf( FOVAngle * M_PI / 180 * 0.5 ) * 2 * Z * ( screeny ) * 0.75f;
vWorldSpaceCameraToCursor.NormalizeInPlace();
}
else
{
engine->GetViewAngles( cameraAngle );
AngleVectors( cameraAngle, &X, &Y, &Z );
vWorldSpaceCameraToCursor = X;
}
vTraceEnd = vCameraLocation + vWorldSpaceCameraToCursor * ASW_MAX_AIM_TRACE;
// BenLubar(sd2-ceiling-ents): use CASW_Trace_Filter to handle *_asw_fade properly
CASW_Trace_Filter filter( pPlayer, COLLISION_GROUP_NONE );
// do a trace into the world to see what we've pointing directly at
UTIL_TraceLine( vCameraLocation, vTraceEnd, nTraceMask, &filter, &tr );
if ( tr.fraction >= 1.0f )
{
if (!pNPC)
return NULL;
float flFloorZ = pNPC->GetRenderOrigin().z + asw_marine_gun_offset_z.GetFloat();
float trace_dist_to_ground = -(vCameraLocation.z - flFloorZ) / vWorldSpaceCameraToCursor.z;
HitLocation = vCameraLocation + vWorldSpaceCameraToCursor * trace_dist_to_ground;
}
else
{
HitLocation = vCameraLocation + tr.fraction * 3000 * vWorldSpaceCameraToCursor;
HitLocation.z = 0;
}
if (!pNPC)
{
// no marine, just use the trace spot
return NULL;
}
Vector vecWeaponPos = pNPC->GetRenderOrigin() + Vector( 0, 0, asw_marine_gun_offset_z.GetFloat() );
float fFloorZ = vecWeaponPos.z; // normally aim flat
if ( !bIgnoreCursorPosition )
{
// if we're clicking right on something
if (tr.m_pEnt && tr.m_pEnt!=pNPC)
{
// store if we're clicking right on an aim target
IASW_Client_Aim_Target* pPossibleAimEnt = dynamic_cast<IASW_Client_Aim_Target*>(tr.m_pEnt);
if (pPossibleAimEnt && pPossibleAimEnt->IsAimTarget())
{
pBestAlien = pPossibleAimEnt;
debugoverlay->ScreenPosition( pBestAlien->GetAimTargetPos(vecWeaponPos, bPreferFlatAiming), bestAlienScreenPos ); // tr.m_pEnt->WorldSpaceCenter()
if (asw_DebugAutoAim.GetBool())
debugoverlay->AddLineOverlay(pBestAlien->GetAimTargetPos(vecWeaponPos, bPreferFlatAiming), pBestAlien->GetAimTargetPos(vecWeaponPos) + Vector(0,0,10),
0, 255, 0, true, 0.01f);
}
}
}
// go through possible aim targets and see if we're pointing the cursor in the direction of any
float best_d = -1;
debugoverlay->ScreenPosition( vecWeaponPos, marineScreenPos ); // asw should be hacked gun pos?
Vector mins, maxs, corner;
if (asw_DebugAutoAim.GetBool())
ASW_StoreClearAll();
// Check bad aim angles
if ( pPlayer->GetASWControls() == ASWC_TOPDOWN &&
!ASWInput()->ControllerModeActiveMouse() && pBestAlien )
{
Vector vecAlienPos = pBestAlien->GetAimTargetRadiusPos( vecWeaponPos );
// Don't aim at stuff a bit below camera and higher
if ( vecAlienPos.z > vCameraLocation.z + rd_aim_ignore_above_camera_z.GetFloat() )
{
pBestAlien = NULL;
}
}
// if we have our cursor over a target (and not using the controller), make sure we have LOS to him before we continue
if ( !ASWInput()->ControllerModeActiveMouse() && pBestAlien )
{
// check we have LOS to the target
CTraceFilterLOS traceFilter( pNPC, COLLISION_GROUP_NONE );
trace_t tr2;
UTIL_TraceLine( vecWeaponPos, pBestAlien->GetAimTargetRadiusPos( vecWeaponPos ), MASK_OPAQUE, &traceFilter, &tr2 );
C_BaseEntity *pEnt = pBestAlien->GetEntity();
bool bHasLOS = (!tr2.startsolid && (tr2.fraction >= 1.0 || tr2.m_pEnt == pEnt));
// we can't shoot it, so skip autoaiming to it, but still return it as an entity that we want to highlight
if ( !bHasLOS )
{
pHighlightAlien = pBestAlien;
pBestAlien = NULL;
}
else
{
if ( !bWeaponHasRadiusScale )
{
if ( ASWGameRules()->CanFlareAutoaimAt( pNPC, pEnt ) )
{
bBestAlienUsingFlareAutoaim = true;
}
}
}
}
if ( !pBestAlien && !pHighlightAlien ) // if we don't already have an ideal aim target from above, do the loop
{
int iStoreNum = 0;
for ( int i = 0; i < IASW_Client_Aim_Target::AutoList().Count(); i++ )
{
IASW_Client_Aim_Target *pAimTarget = static_cast< IASW_Client_Aim_Target* >( IASW_Client_Aim_Target::AutoList()[ i ] );
C_BaseEntity *pEnt = pAimTarget->GetEntity();
if ( !pEnt || !pAimTarget->IsAimTarget() )
continue;
// check it isn't attached to our marine (infesting parasites)
if (pEnt->GetMoveParent() == pNPC)
continue;
// autoaiming: skip yourself
if (pEnt == pNPC)
continue;
// check he's in range
Vector vecAlienPos = pAimTarget->GetAimTargetRadiusPos(vecWeaponPos); //pEnt->WorldSpaceCenter();
if ( vecAlienPos.DistToSqr(vecWeaponPos) > ASW_MAX_AUTO_AIM_RANGE )
continue;
// Don't aim at stuff a bit below camera and higher
if ( pPlayer->GetASWControls() == ASWC_TOPDOWN &&
vecAlienPos.z > vCameraLocation.z + rd_aim_ignore_above_camera_z.GetFloat() )
continue;
Vector vDirection = vecAlienPos - vecWeaponPos;
float fZDist = vDirection.z;
if ( fZDist > 250.0f )
{
VectorNormalize( vDirection );
if ( vDirection.z > 0.85f )
{
// Don't aim at stuff that's high up and directly above us
continue;
}
}
debugoverlay->ScreenPosition( vecAlienPos, alienScreenPos );
Vector AlienEdgeScreenPos;
float flRadiusScale = ASWInput()->ControllerModeActiveMouse() ? 2.0f : 1.0f;
flRadiusScale *= flWeaponRadiusScale;
bool bFlareAutoaim = false;
if ( !bWeaponHasRadiusScale )
{
if ( ASWGameRules()->CanFlareAutoaimAt( pNPC, pEnt ) )
{
flRadiusScale *= 2.0f;
bFlareAutoaim = true;
}
}
debugoverlay->ScreenPosition( vecAlienPos + Vector( pAimTarget->GetRadius() * flRadiusScale, 0, 0 ), AlienEdgeScreenPos);
float alien_radius = (alienScreenPos - AlienEdgeScreenPos).Length2D();
if (alien_radius <= 0)
continue;
float intersect1, intersect2;
Vector2D LineDir(omx - marineScreenPos.x, omy - marineScreenPos.y);
LineDir.NormalizeInPlace();
if (asw_DebugAutoAim.GetBool())
{
char buffer[255];
sprintf(buffer, "r=%f aim=%d\n", alien_radius, pEnt->GetFlags() & FL_AIMTARGET);
debugoverlay->AddTextOverlay(vecAlienPos, 0, 0.01f, buffer);
}
if (ASW_LineCircleIntersection(Vector2D(alienScreenPos.x, alienScreenPos.y), // center
alien_radius, // radius
Vector2D(marineScreenPos.x, marineScreenPos.y), // line start
LineDir, // line direction
&intersect1, &intersect2))
{
if (asw_DebugAutoAim.GetBool())
ASW_StoreLineCircle(iStoreNum++, alienScreenPos.x, alienScreenPos.y, alien_radius, marineScreenPos.x, marineScreenPos.y, LineDir, 1);
// midpoint of intersection is closest to circle center
float midintersect = (intersect1 + intersect2) * 0.5f;
if (midintersect > 0)
{
//Vector2D Midpoint = Vector2D(marineScreenPos.x, marineScreenPos.y) + LineDir * midintersect;
//Midpoint -= Vector2D(alienScreenPos.x, alienScreenPos.y);
// use how near we are to the center to prioritise aim target
//float dist = Midpoint.LengthSqr();
// we are now prioritizing enemies which are closer to the player that intersect the trace
float dist = midintersect;
if (dist < best_d || best_d == -1)
{
// check we have LOS to the target
CTraceFilterLOS traceFilter( pNPC, COLLISION_GROUP_NONE );
trace_t tr2;
UTIL_TraceLine( vecWeaponPos, pAimTarget->GetAimTargetRadiusPos( vecWeaponPos ), MASK_OPAQUE, &traceFilter, &tr2 );
bool bHasLOS = (!tr2.startsolid && (tr2.fraction >= 1.0 || tr2.m_pEnt == pEnt));
if ( !bHasLOS )
{
// just skip aliens that we can't shoot to
continue;
//dist += 50.0f; // bias against aliens that we don't have LOS to - we'll only aim up/down at them if we have no other valid targets
}
if ( dist < best_d || best_d == -1 )
{
best_d = dist;
pBestAlien = pAimTarget;
bestAlienScreenPos = alienScreenPos;
bBestAlienUsingFlareAutoaim = bFlareAutoaim;
flBestAlienRadius = alien_radius;
}
}
}
}
else
{
if ( asw_DebugAutoAim.GetBool() )
ASW_StoreLineCircle( iStoreNum++, alienScreenPos.x, alienScreenPos.y, alien_radius, marineScreenPos.x, marineScreenPos.y, LineDir, 0 );
}
}
}
// we found something to aim at
if ( pBestAlien )
{
if ( asw_DebugAutoAim.GetBool() )
{
debugoverlay->AddLineOverlay( pBestAlien->GetAimTargetPos(vecWeaponPos, bPreferFlatAiming), pBestAlien->GetAimTargetPos(vecWeaponPos, bPreferFlatAiming) + Vector(10,10,1),
0, 0, 255, true, 0.01f );
}
fFloorZ = pBestAlien->GetAimTargetPos( vecWeaponPos, bPreferFlatAiming ).z;
pAutoAimEnt = pBestAlien;
}
// in controller mode, if we have an alien to autoaim at, then aim directly at it
if ( ASWInput()->ControllerModeActiveMouse() && pBestAlien )
{
HitLocation = pBestAlien->GetAimTargetPos( vecWeaponPos, bPreferFlatAiming );
if ( asw_DebugAutoAim.GetBool() )
{
C_BaseEntity *pEnt = pBestAlien ? pBestAlien->GetEntity() : NULL;
engine->Con_NPrintf( nDebugLine++, "BestAlien = %d (%s)", pEnt ? pEnt->entindex() : 0, pEnt ? pEnt->GetClassname() : "NULL" );
engine->Con_NPrintf( nDebugLine++, "CONTROLLER AA" );
}
if ( bWeaponHasRadiusScale || bBestAlienUsingFlareAutoaim )
{
ASWInput()->SetAutoaimEntity( pBestAlien->GetEntity() );
}
pAutoAimEnt = pBestAlien;
return pHighlightAlien ? pHighlightAlien->GetEntity() : NULL;
}
if ( asw_DebugAutoAim.GetBool() )
{
C_BaseEntity *pEnt = pBestAlien ? pBestAlien->GetEntity() : NULL;
engine->Con_NPrintf( nDebugLine++, "BestAlien = %d (%s)", pEnt ? pEnt->entindex() : 0, pEnt ? pEnt->GetClassname() : "NULL" );
engine->Con_NPrintf( nDebugLine++, "fFloorZ = %f", fFloorZ );
}
// calculate where our trace direction intersects with a simulated floor
Vector vecFlatAim;
float trace_dist_to_ground = 0;
if (vWorldSpaceCameraToCursor.z != 0)
{
pPlayer->SmoothAimingFloorZ(fFloorZ);
trace_dist_to_ground = -(vCameraLocation.z - fFloorZ) / vWorldSpaceCameraToCursor.z;
vecFlatAim = vCameraLocation + vWorldSpaceCameraToCursor * trace_dist_to_ground;
// just do a little bit of additional x/y auto aim
Vector vecHitLoc = vecFlatAim;
if ( pBestAlien && asw_horizontal_autoaim.GetBool() && pBestAlien->GetEntity() && pBestAlien->GetEntity()->IsNPC() )
{
if ( bWeaponHasRadiusScale || bBestAlienUsingFlareAutoaim )
{
Vector vecAimTargetPos = pBestAlien->GetAimTargetPos( vecWeaponPos, bPreferFlatAiming );
vecHitLoc.x = vecAimTargetPos.x;
vecHitLoc.y = vecAimTargetPos.y;
if ( asw_DebugAutoAim.GetBool() )
{
Vector vMarineForward, vMarineRight, vMarineUp;
QAngle ang = pPlayer->EyeAngles();
ang[PITCH] = 0;
ang[ROLL] = 0;
AngleVectors( ang, &vMarineForward, &vMarineRight, &vMarineUp );
Vector vecDebugStartPos = pNPC->GetRenderOrigin()
+ vMarineForward * asw_marine_gun_offset_x.GetFloat()
+ vMarineRight * asw_marine_gun_offset_y.GetFloat()
+ vMarineUp * asw_marine_gun_offset_z.GetFloat();
debugoverlay->AddLineOverlay( vecDebugStartPos, vecHitLoc,
12, 255, 255, true, 0.01f);
}
ASWInput()->SetAutoaimEntity( pBestAlien->GetEntity() );
}
}
HitLocation = vecHitLoc;
return pHighlightAlien ? pHighlightAlien->GetEntity() : NULL;
}
// fall back to a simple trace into the world, reporting the collision point
UTIL_TraceLine(vCameraLocation, vTraceEnd, nTraceMask, pPlayer, COLLISION_GROUP_NONE, &tr);
if ( tr.fraction >= 1.0f )
return pHighlightAlien ? pHighlightAlien->GetEntity() : NULL;
HitLocation = vCameraLocation + tr.fraction * 3000 * vWorldSpaceCameraToCursor;
HitLocation.z = 0;
return pHighlightAlien ? pHighlightAlien->GetEntity() : NULL;
}
// rounds world coordinate to a screen pixel
// works by tracing from the camera to the position as a screen coordinate
void RoundToPixel(Vector &vecPos)
{
Vector vecScreenPos;
debugoverlay->ScreenPosition(vecPos, vecScreenPos);
C_ASW_Player *pPlayer = C_ASW_Player::GetLocalASWPlayer();
if (!pPlayer)
return;
QAngle CameraAngle;
Vector CamResult;
::input->CAM_GetCameraOffset( CamResult );
CameraAngle[ PITCH ] = CamResult[ PITCH ];
CameraAngle[ YAW ] = CamResult[ YAW ];
CameraAngle[ ROLL ] = 0;
float fRatio = float( ScreenHeight() ) / float( ScreenWidth() );
Vector vCameraLocation = pPlayer->m_vecLastCameraPosition;
Vector X, Y, Z;
AngleVectors(CameraAngle, &X, &Y, &Z);
float FOVAngle = pPlayer->GetFOV();
Vector projected = X
- tanf(FOVAngle*M_PI/180*0.5) * 2 * Y * (vecScreenPos.x) * ( 0.75f / fRatio )
+ tanf(FOVAngle*M_PI/180*0.5) * 2 * Z * (vecScreenPos.y) * 0.75f;
projected.NormalizeInPlace();
float trace_dist_to_ground = 0;
if (projected.z != 0)
{
trace_dist_to_ground = -(vCameraLocation.z - vecPos.z) / projected.z;
vecPos = vCameraLocation + projected * trace_dist_to_ground;
}
}
static float s_flLastTurnTime = 0.0f;
// smoothly rotates the current marine's turning yaw to the desired
void SmoothTurningYaw( CASW_Player *pPlayer, float &yaw )
{
if ( !pPlayer || !pPlayer->GetNPC() )
return;
// no change if we have no marine or just starting out or just changed marine
if ( pPlayer->m_vecLastCameraPosition == vec3_origin )
{
pPlayer->GetNPC()->m_fLastTurningYaw = yaw;
pPlayer->m_hLastTurningNPC = pPlayer->GetNPC();
return;
}
float dt = clamp( gpGlobals->curtime - s_flLastTurnTime, 0.0f, 0.2f );
s_flLastTurnTime = gpGlobals->curtime;
// fraction turning method
C_ASW_Inhabitable_NPC *pNPC = pPlayer->GetNPC();
Assert( pNPC );
C_ASW_Weapon *pWeapon = pNPC->GetActiveASWWeapon();
float fLinearTurnRate = pNPC->GetBasePlayerYawRate();
if ( pNPC->GetActiveASWWeapon() )
{
fLinearTurnRate *= pNPC->GetActiveASWWeapon()->GetTurnRateModifier();
}
if ( asw_marine_fraction_turn_scale.GetFloat() == 0 )
{
yaw = ASW_ClampYaw( fLinearTurnRate, pNPC->m_fLastTurningYaw, yaw, dt ); // linear turning method
}
else
{
// fractional turning system (not currently used)
float fFraction = 0.9f;
if ( pWeapon )
{
if ( pWeapon->m_bIsFiring )
{
fFraction *= asw_marine_turn_firing_fraction.GetFloat(); //pWeapon->m_fFiringTurnRateModifier;
}
else
{
fFraction *= asw_marine_turn_normal_fraction.GetFloat(); //pWeapon->m_fTurnRateModifier;
}
}
float old_yaw = yaw;
yaw = ASW_ClampYaw_Fraction( 1.0f - fFraction, pNPC->m_fLastTurningYaw, yaw, dt * asw_marine_fraction_turn_scale.GetFloat() );
float min_move = fLinearTurnRate * dt;
// make sure we're moving at least the minimum yaw speed
if ( abs( AngleDiff( yaw, old_yaw ) ) < min_move )
{
yaw = ASW_ClampYaw( fLinearTurnRate, pNPC->m_fLastTurningYaw, old_yaw, dt ); // linear turning method
}
}
pNPC->m_fLastTurningYaw = yaw;
pPlayer->m_hLastTurningNPC = pNPC;
}
CASWInput::CASWInput() :
CInput(),
m_bCursorPlacement( false ),
m_nRelativeCursorX( 0 ),
m_nRelativeCursorY( 0 ),
m_flDesiredCursorRadius( 0.0f ),
m_flTimeSinceLastTurn( 0.0f ),
//m_MouseOverGlowObject( NULL, Vector( 1.0f, 0.5f, 0.0f ), 0.5f, true, true ),
m_HighLightGlowObject( NULL, Vector( 0.4f, 0.7f, 0.9f ), 0.8f, true, true ),
m_UseGlowObject( NULL, Vector( 0.4f, 0.7f, 0.9f ), 0.8f, true, true ),
m_fCamYawRotStartTime(0.0f)
{
m_fJoypadPitch = 0;
m_fJoypadYaw = 0;
m_fJoypadFacingYaw = 0;
m_LastMouseX = -1;
m_LastMouseY = -1;
m_bDontTurnNPC = true;
m_hLastNPC = NULL;
m_vecCrosshairAimingPos = vec3_origin;
m_vecCrosshairTracePos = vec3_origin;
m_bAutoAttacking = false;
m_bAutoWalking = false;
cl_entitylist->AddListenerEntity( this );
#ifdef _WIN32
// HWND mainWnd = (HWND)g_pEngineWindow->GetWindowHandle();
// RECT windowClip;
// GetWindowRect( mainWnd, &windowClip );
// ClipCursor( &windowClip );
#endif
}
void CASWInput::ComputeNewMarineFacing( C_ASW_Player *pPlayer, const Vector &HitLocation, C_BaseEntity *pHitEnt, IASW_Client_Aim_Target *pAutoAimEnt, bool bPreferFlatAiming, float *pPitch, Vector *pNewMarineFacing )
{
*pPitch = 0;
if ( pPlayer && pPlayer->GetNPC() )
{
C_ASW_Inhabitable_NPC *pNPC = pPlayer->GetNPC();
Vector vecMarinePos = ( pNPC->GetRenderOrigin() + Vector( 0, 0, asw_marine_gun_offset_z.GetFloat() ) );
m_vecCrosshairAimingPos = HitLocation;
if ( !pHitEnt && pAutoAimEnt )
SetMouseOverEntity( pAutoAimEnt->GetEntity() );
else
SetMouseOverEntity( pHitEnt );
Vector vMarineForward, vMarineRight, vMarineUp;
QAngle ang = pPlayer->EyeAngles();
ang[PITCH] = 0;
ang[ROLL] = 0;
AngleVectors( ang, &vMarineForward, &vMarineRight, &vMarineUp );
Vector vMuzzlePosition = pNPC->Weapon_ShootPosition();
Vector vWeaponOffset = vMuzzlePosition - vecMarinePos;
// Vector from the marine's rough center to the world space cursor
Vector vMarineToTarget = HitLocation - vecMarinePos;
Vector vUnitUp = vMarineUp.Normalized();
// How far to the marine's right is the gun?
float flMarineGunOffsetY = vWeaponOffset.Dot( vMarineRight );
// Ignore height differences when computing desired yaw; subtract out vertical component
Vector vMarineToTargetUp = vMarineToTarget.Dot( vUnitUp ) * vUnitUp;
Vector vMarineToTargetFlat = vMarineToTarget - vMarineToTargetUp;
// If target is closer than threshold, offset the target position by at least this much to avoid twitchy angle changes
const float flMinRadius = 300.0f;
float flGunToTargetDistance = vMarineToTargetFlat.LengthSqr() - flMarineGunOffsetY * flMarineGunOffsetY;
if ( flGunToTargetDistance < flMinRadius * flMinRadius )
{
float flLength = vMarineToTargetFlat.NormalizeInPlace();
if ( flLength < 1.0f )
{
vMarineToTargetFlat = vMarineForward;
}
vMarineToTargetFlat *= flMinRadius;
flGunToTargetDistance = vMarineToTargetFlat.LengthSqr() - flMarineGunOffsetY * flMarineGunOffsetY;
if ( flGunToTargetDistance < 0.0f )
{
flGunToTargetDistance = flMinRadius;
}
}
flGunToTargetDistance = sqrtf( flGunToTargetDistance );
// Compute (along x-y plane) the marine's new forward vector such that a gun, offset to his right and pointed in the same direction, will shoot at the crosshair.
// You can visualize this by constructing a right triangle: hypotenuse is the vector from marine's center to target, short leg is from marine's center to bullet start position, medium leg is from bullet start to target.
// Assuming the bullet is fired in the marine's "forward" direction, we can solve for that vector with this math
Assert( flMarineGunOffsetY != flGunToTargetDistance );
float flNewForwardX = ( flMarineGunOffsetY * vMarineToTargetFlat.y - flGunToTargetDistance * vMarineToTargetFlat.x ) / ( flMarineGunOffsetY * flMarineGunOffsetY - flGunToTargetDistance * flGunToTargetDistance );
float flNewForwardY = ( flMarineGunOffsetY * vMarineToTargetFlat.x + flGunToTargetDistance * vMarineToTargetFlat.y ) / ( flMarineGunOffsetY * flMarineGunOffsetY - flGunToTargetDistance * flGunToTargetDistance );
// New forward/right vectors in world-space along the XY-plane
Vector vNewForward( flNewForwardX, -flNewForwardY, 0 );
Vector vNewRight( -flNewForwardY, -flNewForwardX, 0 );
*pNewMarineFacing = vNewForward;
Vector vecHitPos = HitLocation;
if ( pAutoAimEnt )
{
//vecHitPos = pAutoAimEnt->GetAimTargetPos(vMuzzlePosition, bPreferFlatAiming);
}
// The yaw of this vector is not quite right (hence "approximate") but the pitch is correct
Vector vApproximateMarineFacingVector = vecHitPos - vMuzzlePosition;
C_ASW_Marine *pMarine = C_ASW_Marine::AsMarine( pNPC );
if ( pMarine )
{
// Approximate a better laser sight direction; this will be used so long as it does not deviate from the marine's forward direction by too much
Vector vecLaserDir = ( vecHitPos - vMuzzlePosition );
pMarine->m_flLaserSightLength = vecLaserDir.NormalizeInPlace();
//pMarine->m_vLaserSightCorrection = vecLaserDir - vNewForward;
pMarine->m_vLaserSightCorrection = vecLaserDir;
}
if ( fabsf( vApproximateMarineFacingVector.z ) > 1e-3f )
{
if ( asw_DebugAutoAim.GetInt() == 3 )
FX_MicroExplosion( vecHitPos, Vector( 0, 0, 1 ) );
*pPitch = UTIL_VecToPitch( vApproximateMarineFacingVector );
if ( !IsFinite( *pPitch ) )
*pPitch = 0;
if ( asw_DebugAutoAim.GetInt() == 2 )
{
Msg( "[%s]%f: Setting pitch to %f (marine z:%f hitlocZ:%f\n", pPlayer->IsClient() ? "c" : "s",
gpGlobals->curtime, *pPitch, vMuzzlePosition.z, vecHitPos.z );
}
if ( asw_DebugAutoAim.GetBool() )
{
debugoverlay->AddLineOverlay( vecHitPos, vMuzzlePosition,
255, 255, 0, true, NDEBUG_PERSIST_TILL_NEXT_SERVER );
}
}
}
}
// asw
void CASWInput::TurnTowardMouse(QAngle& viewangles, CUserCmd *cmd)
{
VPROF_BUDGET( "CASWInput::TurnTowardMouse", VPROF_BUDGETGROUP_ASW_CLIENT );
if ( !engine->IsActiveApp() )
{
return;
}
float mx, my;
C_ASW_Player *pPlayer = C_ASW_Player::GetLocalASWPlayer();
C_ASW_Inhabitable_NPC *pNPC = pPlayer ? pPlayer->GetNPC() : NULL;
bool bPreferFlatAiming = false;
int iScreenWidth, iScreenHeight;
engine->GetScreenSize( iScreenWidth, iScreenHeight );
if ( iScreenWidth <= 0 || iScreenHeight <= 0 )
{
return;
}
int x, y;
GetWindowCenter( x, y );
int current_posx, current_posy;
GetMousePos(current_posx, current_posy);
//current_posy -= ( 0.020833f * iScreenHeight ); // slight vertical correction to account for the gun being lower than the marine's eyes
// don't change the marine's yaw if the mouse cursor hasn't moved and marine is still
// (this allows the player to switch between his marines without messing up their facing)
if ( pNPC )