-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathNextBotPlayerBody.cpp
More file actions
940 lines (770 loc) · 25 KB
/
NextBotPlayerBody.cpp
File metadata and controls
940 lines (770 loc) · 25 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
// NextBotPlayerBody.cpp
// Implementation of Body interface for CBasePlayer-derived classes
// Author: Michael Booth, October 2006
//========= Copyright Valve Corporation, All rights reserved. ============//
#include "cbase.h"
#include "NextBot.h"
#include "NextBotPlayerBody.h"
#include "NextBotPlayer.h"
// NEO NOTE (nullsystem): CNEOBotBody will overload the VEC_ usage functions instead
// and here will use the SDK_ prefix macros to not warn out about redefining VEC_... macros
// and making it clear it's using what was the base SDK's version not NT;RE's version here
#ifdef NEO
#define SDK_VEC_HULL_MIN_SCALED( player ) ( g_pGameRules->GetViewVectors()->m_vHullMin * player->GetModelScale() )
#define SDK_VEC_HULL_MAX_SCALED( player ) ( g_pGameRules->GetViewVectors()->m_vHullMax * player->GetModelScale() )
#define SDK_VEC_VIEW_SCALED( player ) ( g_pGameRules->GetViewVectors()->m_vView * player->GetModelScale() )
#define SDK_VEC_DUCK_HULL_MIN_SCALED( player ) ( g_pGameRules->GetViewVectors()->m_vDuckHullMin * player->GetModelScale() )
#define SDK_VEC_DUCK_HULL_MAX_SCALED( player ) ( g_pGameRules->GetViewVectors()->m_vDuckHullMax * player->GetModelScale() )
#define SDK_VEC_DUCK_VIEW_SCALED( player ) ( g_pGameRules->GetViewVectors()->m_vDuckView * player->GetModelScale() )
#endif
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
ConVar nb_saccade_time( "nb_saccade_time", "0.1", FCVAR_CHEAT );
ConVar nb_saccade_speed( "nb_saccade_speed", "1000", FCVAR_CHEAT );
ConVar nb_head_aim_steady_max_rate( "nb_head_aim_steady_max_rate", "100", FCVAR_CHEAT );
ConVar nb_head_aim_settle_duration( "nb_head_aim_settle_duration", "0.3", FCVAR_CHEAT );
ConVar nb_head_aim_resettle_angle( "nb_head_aim_resettle_angle", "100", FCVAR_CHEAT, "After rotating through this angle, the bot pauses to 'recenter' its virtual mouse on its virtual mousepad" );
ConVar nb_head_aim_resettle_time( "nb_head_aim_resettle_time", "0.3", FCVAR_CHEAT, "How long the bot pauses to 'recenter' its virtual mouse on its virtual mousepad" );
//-----------------------------------------------------------------------------------------------
/**
* A useful reply for IBody::AimHeadTowards. When the
* head is aiming on target, press the fire button.
*/
void PressFireButtonReply::OnSuccess( INextBot *bot )
{
INextBotPlayerInput *playerInput = dynamic_cast< INextBotPlayerInput * >( bot->GetEntity() );
if ( playerInput )
{
playerInput->PressFireButton();
}
}
//-----------------------------------------------------------------------------------------------
/**
* A useful reply for IBody::AimHeadTowards. When the
* head is aiming on target, press the alternate fire button.
*/
void PressAltFireButtonReply::OnSuccess( INextBot *bot )
{
INextBotPlayerInput *playerInput = dynamic_cast< INextBotPlayerInput * >( bot->GetEntity() );
if ( playerInput )
{
playerInput->PressMeleeButton();
}
}
//-----------------------------------------------------------------------------------------------
/**
* A useful reply for IBody::AimHeadTowards. When the
* head is aiming on target, press the jump button.
*/
void PressJumpButtonReply::OnSuccess( INextBot *bot )
{
INextBotPlayerInput *playerInput = dynamic_cast< INextBotPlayerInput * >( bot->GetEntity() );
if ( playerInput )
{
playerInput->PressJumpButton();
}
}
//-----------------------------------------------------------------------------------------------
//-----------------------------------------------------------------------------------------------
PlayerBody::PlayerBody( INextBot *bot ) : IBody( bot )
{
m_player = static_cast< CBasePlayer * >( bot->GetEntity() );
}
//-----------------------------------------------------------------------------------------------
PlayerBody::~PlayerBody()
{
}
//-----------------------------------------------------------------------------------------------
/**
* reset to initial state
*/
void PlayerBody::Reset( void )
{
m_posture = STAND;
m_lookAtPos = vec3_origin;
m_lookAtSubject = NULL;
m_lookAtReplyWhenAimed = NULL;
m_lookAtVelocity = vec3_origin;
m_lookAtExpireTimer.Invalidate();
m_lookAtPriority = BORING;
m_lookAtExpireTimer.Invalidate();
m_lookAtDurationTimer.Invalidate();
m_isSightedIn = false;
m_hasBeenSightedIn = false;
m_headSteadyTimer.Invalidate();
m_priorAngles = vec3_angle;
m_anchorRepositionTimer.Invalidate();
m_anchorForward = vec3_origin;
}
ConVar bot_mimic( "bot_mimic", "0", 0, "Bot uses usercmd of player by index." );
#ifdef NEO
ConVar bot_mimic_yaw_offset("bot_mimic_yaw_offset", "0", 0, "Offsets the bot yaw.");
ConVar bot_mimic_mirror("bot_mimic_mirror", "0", 0, "Mirrors the mimic axes.");
#endif // NEO
//-----------------------------------------------------------------------------------------------
/**
* Update internal state.
* Do this every tick to keep head aims smooth and accurate
*/
void PlayerBody::Upkeep( void )
{
// If mimicking the player, don't modify the view angles.
static ConVarRef bot_mimic( "bot_mimic" );
if ( bot_mimic.IsValid() && bot_mimic.GetBool() )
return;
const float deltaT = gpGlobals->frametime;
if ( deltaT < 0.00001f )
{
return;
}
CBasePlayer *player = ( CBasePlayer * )GetBot()->GetEntity();
// get current view angles
QAngle currentAngles = player->EyeAngles() + player->GetPunchAngle();
// track when our head is "steady"
bool isSteady = true;
float actualPitchRate = AngleDiff( currentAngles.x, m_priorAngles.x );
if ( abs( actualPitchRate ) > nb_head_aim_steady_max_rate.GetFloat() * deltaT )
{
isSteady = false;
}
else
{
float actualYawRate = AngleDiff( currentAngles.y, m_priorAngles.y );
if ( abs( actualYawRate ) > nb_head_aim_steady_max_rate.GetFloat() * deltaT )
{
isSteady = false;
}
}
if ( isSteady )
{
if ( !m_headSteadyTimer.HasStarted() )
{
m_headSteadyTimer.Start();
}
}
else
{
m_headSteadyTimer.Invalidate();
}
if ( GetBot()->IsDebugging( NEXTBOT_LOOK_AT ) )
{
if ( IsHeadSteady() )
{
const float maxTime = 3.0f;
float t = GetHeadSteadyDuration() / maxTime;
t = clamp( t, 0.f, 1.0f );
NDebugOverlay::Circle( player->EyePosition(), t * 10.0f, 0, 255, 0, 255, true, 2.0f * deltaT );
}
}
m_priorAngles = currentAngles;
// if our current look-at has expired, don't change our aim further
if ( m_hasBeenSightedIn && m_lookAtExpireTimer.IsElapsed() )
{
return;
}
// simulate limited range of mouse movements
// compute the angle change from "center"
const Vector &forward = GetViewVector();
float deltaAngle = RAD2DEG( acos( DotProduct( forward, m_anchorForward ) ) );
if ( deltaAngle > nb_head_aim_resettle_angle.GetFloat() )
{
// time to recenter our 'virtual mouse'
m_anchorRepositionTimer.Start( RandomFloat( 0.9f, 1.1f ) * nb_head_aim_resettle_time.GetFloat() );
m_anchorForward = forward;
return;
}
// if we're currently recentering our "virtual mouse", wait
if ( m_anchorRepositionTimer.HasStarted() && !m_anchorRepositionTimer.IsElapsed() )
{
return;
}
m_anchorRepositionTimer.Invalidate();
// if we have a subject, update lookat point
CBaseEntity *subject = m_lookAtSubject;
if ( subject )
{
if ( m_lookAtTrackingTimer.IsElapsed() )
{
// update subject tracking by periodically estimating linear aim velocity, allowing for "slop" between updates
Vector desiredLookAtPos;
if ( subject->MyCombatCharacterPointer() )
{
desiredLookAtPos = GetBot()->GetIntentionInterface()->SelectTargetPoint( GetBot(), subject->MyCombatCharacterPointer() );
}
else
{
desiredLookAtPos = subject->WorldSpaceCenter();
}
desiredLookAtPos += GetHeadAimSubjectLeadTime() * subject->GetAbsVelocity();
Vector errorVector = desiredLookAtPos - m_lookAtPos;
float error = errorVector.NormalizeInPlace();
float trackingInterval = GetHeadAimTrackingInterval();
if ( trackingInterval < deltaT )
{
trackingInterval = deltaT;
}
float errorVel = error / trackingInterval;
m_lookAtVelocity = ( errorVel * errorVector ) + subject->GetAbsVelocity();
m_lookAtTrackingTimer.Start( RandomFloat( 0.8f, 1.2f ) * trackingInterval );
}
m_lookAtPos += deltaT * m_lookAtVelocity;
}
// aim view towards last look at point
Vector to = m_lookAtPos - GetEyePosition();
to.NormalizeInPlace();
QAngle desiredAngles;
VectorAngles( to, desiredAngles );
QAngle angles;
if ( GetBot()->IsDebugging( NEXTBOT_LOOK_AT ) )
{
NDebugOverlay::Line( GetEyePosition(), GetEyePosition() + 100.0f * forward, 255, 255, 0, false, 2.0f * deltaT );
float thickness = isSteady ? 2.0f : 3.0f;
int r = m_isSightedIn ? 255 : 0;
int g = subject ? 255 : 0;
NDebugOverlay::HorzArrow( GetEyePosition(), m_lookAtPos, thickness, r, g, 255, 255, false, 2.0f * deltaT );
}
const float onTargetTolerance = 0.98f;
float dot = DotProduct( forward, to );
if ( dot > onTargetTolerance )
{
// on target
m_isSightedIn = true;
if ( !m_hasBeenSightedIn )
{
m_hasBeenSightedIn = true;
if ( GetBot()->IsDebugging( NEXTBOT_LOOK_AT ) )
{
ConColorMsg( Color( 255, 100, 0, 255 ), "%3.2f: %s Look At SIGHTED IN\n",
gpGlobals->curtime,
m_player->GetPlayerName() );
}
}
if ( m_lookAtReplyWhenAimed )
{
m_lookAtReplyWhenAimed->OnSuccess( GetBot() );
m_lookAtReplyWhenAimed = NULL;
}
}
else
{
// off target
m_isSightedIn = false;
}
// rotate view at a rate proportional to how far we have to turn
// max rate if we need to turn around
// want first derivative continuity of rate as our aim hits to avoid pop
float approachRate = GetMaxHeadAngularVelocity();
const float easeOut = 0.7f;
if ( dot > easeOut )
{
float t = RemapVal( dot, easeOut, 1.0f, 1.0f, 0.02f );
const float halfPI = 1.57f;
approachRate *= sin( halfPI * t );
}
const float easeInTime = 0.25f;
if ( m_lookAtDurationTimer.GetElapsedTime() < easeInTime )
{
approachRate *= m_lookAtDurationTimer.GetElapsedTime() / easeInTime;
}
angles.y = ApproachAngle( desiredAngles.y, currentAngles.y, approachRate * deltaT );
angles.x = ApproachAngle( desiredAngles.x, currentAngles.x, 0.5f * approachRate * deltaT );
angles.z = 0.0f;
// back out "punch angle"
angles -= player->GetPunchAngle();
angles.x = AngleNormalize( angles.x );
angles.y = AngleNormalize( angles.y );
player->SnapEyeAngles( angles );
}
//-----------------------------------------------------------------------------------------------
bool PlayerBody::SetPosition( const Vector &pos )
{
m_player->SetAbsOrigin( pos );
return true;
}
//-----------------------------------------------------------------------------------------------
/**
* Return the eye position of the bot in world coordinates
*/
const Vector &PlayerBody::GetEyePosition( void ) const
{
m_eyePos = m_player->EyePosition();
return m_eyePos;
}
CBaseEntity *PlayerBody::GetEntity( void )
{
return m_player;
}
//-----------------------------------------------------------------------------------------------
CBaseEntity *PlayerBody::GetLookAtSubject( void ) const
{
return m_lookAtSubject.Get();
}
//-----------------------------------------------------------------------------------------------
/**
* Return the view unit direction vector in world coordinates
*/
const Vector &PlayerBody::GetViewVector( void ) const
{
m_player->EyeVectors( &m_viewVector );
return m_viewVector;
}
//-----------------------------------------------------------------------------------------------
/**
* Aim the bot's head towards the given goal
*/
void PlayerBody::AimHeadTowards( const Vector &lookAtPos, LookAtPriorityType priority, float duration, INextBotReply *replyWhenAimed, const char *reason )
{
if ( duration <= 0.0f )
{
duration = 0.1f;
}
// don't spaz our aim around
if ( m_lookAtPriority == priority )
{
if ( !IsHeadSteady() || GetHeadSteadyDuration() < nb_head_aim_settle_duration.GetFloat() )
{
// we're still finishing a look-at at the same priority
if ( replyWhenAimed )
{
replyWhenAimed->OnFail( GetBot(), INextBotReply::DENIED );
}
if ( GetBot()->IsDebugging( NEXTBOT_LOOK_AT ) )
{
ConColorMsg( Color( 255, 0, 0, 255 ), "%3.2f: %s Look At '%s' rejected - previous aim not %s\n",
gpGlobals->curtime,
m_player->GetPlayerName(),
reason,
IsHeadSteady() ? "settled long enough" : "head-steady" );
}
return;
}
}
// don't short-circuit if "sighted in" to avoid rapid view jitter
if ( m_lookAtPriority > priority && !m_lookAtExpireTimer.IsElapsed() )
{
// higher priority lookat still ongoing
if ( replyWhenAimed )
{
replyWhenAimed->OnFail( GetBot(), INextBotReply::DENIED );
}
if ( GetBot()->IsDebugging( NEXTBOT_LOOK_AT ) )
{
ConColorMsg( Color( 255, 0, 0, 255 ), "%3.2f: %s Look At '%s' rejected - higher priority aim in progress\n",
gpGlobals->curtime,
m_player->GetPlayerName(),
reason );
}
return;
}
if ( m_lookAtReplyWhenAimed )
{
// in-process aim was interrupted
m_lookAtReplyWhenAimed->OnFail( GetBot(), INextBotReply::INTERRUPTED );
}
m_lookAtReplyWhenAimed = replyWhenAimed;
m_lookAtExpireTimer.Start( duration );
// if given the same point, just update priority
const float epsilon = 1.0f;
if ( ( m_lookAtPos - lookAtPos ).IsLengthLessThan( epsilon ) )
{
m_lookAtPriority = priority;
return;
}
// new look-at point
m_lookAtPos = lookAtPos;
m_lookAtSubject = NULL;
m_lookAtPriority = priority;
m_lookAtDurationTimer.Start();
// do NOT clear this here, or continuous calls to AimHeadTowards will keep IsHeadAimingOnTarget returning false all of the time
// m_isSightedIn = false;
m_hasBeenSightedIn = false;
if ( GetBot()->IsDebugging( NEXTBOT_LOOK_AT ) )
{
NDebugOverlay::Cross3D( lookAtPos, 2.0f, 255, 255, 100, true, 2.0f * duration );
const char *priName = "";
switch( priority )
{
case BORING: priName = "BORING"; break;
case INTERESTING: priName = "INTERESTING"; break;
case IMPORTANT: priName = "IMPORTANT"; break;
case CRITICAL: priName = "CRITICAL"; break;
}
ConColorMsg( Color( 255, 100, 0, 255 ), "%3.2f: %s Look At ( %g, %g, %g ) for %3.2f s, Pri = %s, Reason = %s\n",
gpGlobals->curtime,
m_player->GetPlayerName(),
lookAtPos.x, lookAtPos.y, lookAtPos.z,
duration,
priName,
( reason ) ? reason : "" );
}
}
//-----------------------------------------------------------------------------------------------
/**
* Aim the bot's head towards the given goal
*/
void PlayerBody::AimHeadTowards( CBaseEntity *subject, LookAtPriorityType priority, float duration, INextBotReply *replyWhenAimed, const char *reason )
{
if ( duration <= 0.0f )
{
duration = 0.1f;
}
if ( subject == NULL )
{
return;
}
// don't spaz our aim around
if ( m_lookAtPriority == priority )
{
if ( !IsHeadSteady() || GetHeadSteadyDuration() < nb_head_aim_settle_duration.GetFloat() )
{
// we're still finishing a look-at at the same priority
if ( replyWhenAimed )
{
replyWhenAimed->OnFail( GetBot(), INextBotReply::DENIED );
}
if ( GetBot()->IsDebugging( NEXTBOT_LOOK_AT ) )
{
ConColorMsg( Color( 255, 0, 0, 255 ), "%3.2f: %s Look At '%s' rejected - previous aim not %s\n",
gpGlobals->curtime,
m_player->GetPlayerName(),
reason,
IsHeadSteady() ? "head-steady" : "settled long enough" );
}
return;
}
}
// don't short-circuit if "sighted in" to avoid rapid view jitter
if ( m_lookAtPriority > priority && !m_lookAtExpireTimer.IsElapsed() )
{
// higher priority lookat still ongoing
if ( replyWhenAimed )
{
replyWhenAimed->OnFail( GetBot(), INextBotReply::DENIED );
}
if ( GetBot()->IsDebugging( NEXTBOT_LOOK_AT ) )
{
ConColorMsg( Color( 255, 0, 0, 255 ), "%3.2f: %s Look At '%s' rejected - higher priority aim in progress\n",
gpGlobals->curtime,
m_player->GetPlayerName(),
reason );
}
return;
}
if ( m_lookAtReplyWhenAimed )
{
// in-process aim was interrupted
m_lookAtReplyWhenAimed->OnFail( GetBot(), INextBotReply::INTERRUPTED );
}
m_lookAtReplyWhenAimed = replyWhenAimed;
m_lookAtExpireTimer.Start( duration );
// if given the same subject, just update priority
if ( subject == m_lookAtSubject )
{
m_lookAtPriority = priority;
return;
}
// new subject
m_lookAtSubject = subject;
#ifdef REFACTOR_FOR_CLIENT_SIDE_EYE_TRACKING
CBasePlayer *pMyPlayer = static_cast< CBasePlayer * >( GetEntity() );
if ( subject->IsPlayer() )
{
// looking at a player, look at their eye position
TerrorPlayer *pMyTarget = ToTerrorPlayer( subject );
m_lookAtPos = subject->EyePosition();
if(pMyPlayer)
{
pMyPlayer->SetLookatPlayer( pMyTarget );
}
}
else
{
// not looking at a player
m_lookAtPos = subject->WorldSpaceCenter();
if(pMyPlayer)
{
pMyPlayer->SetLookatPlayer( NULL );
}
}
#endif
m_lookAtPriority = priority;
m_lookAtDurationTimer.Start();
// do NOT clear this here, or continuous calls to AimHeadTowards will keep IsHeadAimingOnTarget returning false all of the time
// m_isSightedIn = false;
m_hasBeenSightedIn = false;
if ( GetBot()->IsDebugging( NEXTBOT_LOOK_AT ) )
{
NDebugOverlay::Cross3D( m_lookAtPos, 2.0f, 100, 100, 100, true, duration );
const char *priName = "";
switch( priority )
{
case BORING: priName = "BORING"; break;
case INTERESTING: priName = "INTERESTING"; break;
case IMPORTANT: priName = "IMPORTANT"; break;
case CRITICAL: priName = "CRITICAL"; break;
}
ConColorMsg( Color( 255, 100, 0, 255 ), "%3.2f: %s Look At subject %s for %3.2f s, Pri = %s, Reason = %s\n",
gpGlobals->curtime,
m_player->GetPlayerName(),
subject->GetClassname(),
duration,
priName,
( reason ) ? reason : "" );
}
}
//-----------------------------------------------------------------------------------------------
/**
* Return true if head is not rapidly turning to look somewhere else
*/
bool PlayerBody::IsHeadSteady( void ) const
{
return m_headSteadyTimer.HasStarted();
}
//-----------------------------------------------------------------------------------------------
/**
* Return the duration that the bot's head has been on-target
*/
float PlayerBody::GetHeadSteadyDuration( void ) const
{
// return ( IsHeadAimingOnTarget() ) ? m_headSteadyTimer.GetElapsedTime() : 0.0f;
return m_headSteadyTimer.HasStarted() ? m_headSteadyTimer.GetElapsedTime() : 0.0f;
}
//-----------------------------------------------------------------------------------------------
// Clear out currently pending replyWhenAimed callback
void PlayerBody::ClearPendingAimReply( void )
{
m_lookAtReplyWhenAimed = NULL;
}
//-----------------------------------------------------------------------------------------------
float PlayerBody::GetMaxHeadAngularVelocity( void ) const
{
return nb_saccade_speed.GetFloat();
}
//-----------------------------------------------------------------------------------------------
bool PlayerBody::StartActivity( Activity act, unsigned int flags )
{
// player animation state is controlled on the client
return false;
}
//-----------------------------------------------------------------------------------------------
/**
* Return currently animating activity
*/
Activity PlayerBody::GetActivity( void ) const
{
return ACT_INVALID;
}
//-----------------------------------------------------------------------------------------------
/**
* Return true if currently animating activity matches the given one
*/
bool PlayerBody::IsActivity( Activity act ) const
{
return false;
}
//-----------------------------------------------------------------------------------------------
/**
* Return true if currently animating activity has any of the given flags
*/
bool PlayerBody::HasActivityType( unsigned int flags ) const
{
return false;
}
//-----------------------------------------------------------------------------------------------
/**
* Request a posture change
*/
void PlayerBody::SetDesiredPosture( PostureType posture )
{
m_posture = posture;
}
//-----------------------------------------------------------------------------------------------
/**
* Get posture body is trying to assume
*/
IBody::PostureType PlayerBody::GetDesiredPosture( void ) const
{
return m_posture;
}
//-----------------------------------------------------------------------------------------------
/**
* Return true if body is trying to assume this posture
*/
bool PlayerBody::IsDesiredPosture( PostureType posture ) const
{
return ( posture == m_posture );
}
//-----------------------------------------------------------------------------------------------
/**
* Return true if body's actual posture matches its desired posture
*/
bool PlayerBody::IsInDesiredPosture( void ) const
{
return true;
}
//-----------------------------------------------------------------------------------------------
/**
* Return body's current actual posture
*/
IBody::PostureType PlayerBody::GetActualPosture( void ) const
{
return m_posture;
}
//-----------------------------------------------------------------------------------------------
/**
* Return true if body is actually in the given posture
*/
bool PlayerBody::IsActualPosture( PostureType posture ) const
{
return ( posture == m_posture );
}
//-----------------------------------------------------------------------------------------------
/**
* Return true if body's current posture allows it to move around the world
*/
bool PlayerBody::IsPostureMobile( void ) const
{
return true;
}
//-----------------------------------------------------------------------------------------------
/**
* Return true if body's posture is in the process of changing to new posture
*/
bool PlayerBody::IsPostureChanging( void ) const
{
return false;
}
//-----------------------------------------------------------------------------------------------
/**
* Arousal level change
*/
void PlayerBody::SetArousal( ArousalType arousal )
{
m_arousal = arousal;
}
//-----------------------------------------------------------------------------------------------
/**
* Get arousal level
*/
IBody::ArousalType PlayerBody::GetArousal( void ) const
{
return m_arousal;
}
//-----------------------------------------------------------------------------------------------
/**
* Return true if body is at this arousal level
*/
bool PlayerBody::IsArousal( ArousalType arousal ) const
{
return ( arousal == m_arousal );
}
//-----------------------------------------------------------------------------------------------
/**
* Width of bot's collision hull in XY plane
*/
float PlayerBody::GetHullWidth( void ) const
{
#ifdef NEO
return SDK_VEC_HULL_MAX_SCALED( m_player ).x - SDK_VEC_HULL_MIN_SCALED( m_player ).x;
#else
return VEC_HULL_MAX_SCALED( m_player ).x - VEC_HULL_MIN_SCALED( m_player ).x;
#endif
}
//-----------------------------------------------------------------------------------------------
/**
* Height of bot's current collision hull based on posture
*/
float PlayerBody::GetHullHeight( void ) const
{
if ( m_posture == CROUCH )
{
return GetCrouchHullHeight();
}
return GetStandHullHeight();
}
//-----------------------------------------------------------------------------------------------
/**
* Height of bot's collision hull when standing
*/
float PlayerBody::GetStandHullHeight( void ) const
{
#ifdef NEO
return SDK_VEC_HULL_MAX_SCALED( m_player ).z - SDK_VEC_HULL_MIN_SCALED( m_player ).z;
#else
return VEC_HULL_MAX_SCALED( m_player ).z - VEC_HULL_MIN_SCALED( m_player ).z;
#endif
}
//-----------------------------------------------------------------------------------------------
/**
* Height of bot's collision hull when crouched
*/
float PlayerBody::GetCrouchHullHeight( void ) const
{
#ifdef NEO
return SDK_VEC_DUCK_HULL_MAX_SCALED( m_player ).z - SDK_VEC_DUCK_HULL_MIN_SCALED( m_player ).z;
#else
return VEC_DUCK_HULL_MAX_SCALED( m_player ).z - VEC_DUCK_HULL_MIN_SCALED( m_player ).z;
#endif
}
//-----------------------------------------------------------------------------------------------
/**
* Return current collision hull minimums based on actual body posture
*/
const Vector &PlayerBody::GetHullMins( void ) const
{
#ifdef NEO
if ( m_posture == CROUCH )
{
m_hullMins = SDK_VEC_DUCK_HULL_MIN_SCALED( m_player );
}
else
{
m_hullMins = SDK_VEC_HULL_MIN_SCALED( m_player );
}
#else
if ( m_posture == CROUCH )
{
m_hullMins = VEC_DUCK_HULL_MIN_SCALED( m_player );
}
else
{
m_hullMins = VEC_HULL_MIN_SCALED( m_player );
}
#endif
return m_hullMins;
}
//-----------------------------------------------------------------------------------------------
/**
* Return current collision hull maximums based on actual body posture
*/
const Vector &PlayerBody::GetHullMaxs( void ) const
{
#ifdef NEO
if ( m_posture == CROUCH )
{
m_hullMaxs = SDK_VEC_DUCK_HULL_MAX_SCALED( m_player );
}
else
{
m_hullMaxs = SDK_VEC_HULL_MAX_SCALED( m_player );
}
#else
if ( m_posture == CROUCH )
{
m_hullMaxs = VEC_DUCK_HULL_MAX_SCALED( m_player );
}
else
{
m_hullMaxs = VEC_HULL_MAX_SCALED( m_player );
}
#endif
return m_hullMaxs;
}
//-----------------------------------------------------------------------------------------------
/**
* Return the bot's collision mask (hack until we get a general hull trace abstraction here or in the locomotion interface)
*/
unsigned int PlayerBody::GetSolidMask( void ) const
{
return ( m_player ) ? m_player->PlayerSolidMask() : MASK_PLAYERSOLID;
}