Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

137 lines
3.3 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. // tf_bot_locomotion.cpp
  3. // Team Fortress NextBot locomotion interface
  4. // Michael Booth, May 2010
  5. #include "cbase.h"
  6. #include "tf_bot.h"
  7. #include "tf_bot_locomotion.h"
  8. #include "particle_parse.h"
  9. //-----------------------------------------------------------------------------------------
  10. void CTFBotLocomotion::Update( void )
  11. {
  12. BaseClass::Update();
  13. CTFBot *me = ToTFBot( GetBot()->GetEntity() );
  14. if ( !me )
  15. {
  16. return;
  17. }
  18. // always 'crouch jump'
  19. if ( IsOnGround() )
  20. {
  21. if ( !me->IsPlayerClass( TF_CLASS_ENGINEER ) )
  22. {
  23. // engineers need to crouch behind their guns
  24. me->ReleaseCrouchButton();
  25. }
  26. }
  27. else
  28. {
  29. me->PressCrouchButton( 0.3f );
  30. }
  31. }
  32. //-----------------------------------------------------------------------------------------
  33. // Move directly towards the given position
  34. void CTFBotLocomotion::Approach( const Vector &pos, float goalWeight )
  35. {
  36. if ( TFGameRules()->IsMannVsMachineMode() )
  37. {
  38. if ( !IsOnGround() && !IsClimbingOrJumping() )
  39. {
  40. // no air control
  41. return;
  42. }
  43. }
  44. BaseClass::Approach( pos, goalWeight );
  45. }
  46. //-----------------------------------------------------------------------------------------
  47. // Distance at which we will die if we fall
  48. float CTFBotLocomotion::GetDeathDropHeight( void ) const
  49. {
  50. return 1000.0f;
  51. }
  52. //-----------------------------------------------------------------------------------------
  53. // Get maximum running speed
  54. float CTFBotLocomotion::GetRunSpeed( void ) const
  55. {
  56. CTFBot *me = (CTFBot *)GetBot()->GetEntity();
  57. return me->GetPlayerClass()->GetMaxSpeed();
  58. }
  59. //-----------------------------------------------------------------------------------------
  60. // Return true if given area can be used for navigation
  61. bool CTFBotLocomotion::IsAreaTraversable( const CNavArea *baseArea ) const
  62. {
  63. CTFBot *me = (CTFBot *)GetBot()->GetEntity();
  64. CTFNavArea *area = (CTFNavArea *)baseArea;
  65. if ( area->IsBlocked( me->GetTeamNumber() ) )
  66. {
  67. return false;
  68. }
  69. if ( !TFGameRules()->RoundHasBeenWon() || TFGameRules()->GetWinningTeam() != me->GetTeamNumber() )
  70. {
  71. if ( area->HasAttributeTF( TF_NAV_SPAWN_ROOM_RED ) && me->GetTeamNumber() == TF_TEAM_BLUE )
  72. {
  73. return false;
  74. }
  75. if ( area->HasAttributeTF( TF_NAV_SPAWN_ROOM_BLUE ) && me->GetTeamNumber() == TF_TEAM_RED )
  76. {
  77. return false;
  78. }
  79. }
  80. return true;
  81. }
  82. //-----------------------------------------------------------------------------------------
  83. bool CTFBotLocomotion::IsEntityTraversable( CBaseEntity *obstacle, TraverseWhenType when ) const
  84. {
  85. // assume all players are "traversable" in that they will move or can be killed
  86. if ( obstacle && obstacle->IsPlayer() )
  87. {
  88. return true;
  89. }
  90. return PlayerLocomotion::IsEntityTraversable( obstacle, when );
  91. }
  92. void CTFBotLocomotion::Jump( void )
  93. {
  94. BaseClass::Jump();
  95. CTFBot *me = ToTFBot( GetBot()->GetEntity() );
  96. if ( !me )
  97. {
  98. return;
  99. }
  100. if ( TFGameRules() && TFGameRules()->IsMannVsMachineMode() )
  101. {
  102. int iCustomJumpParticle = 0;
  103. CALL_ATTRIB_HOOK_INT_ON_OTHER( me, iCustomJumpParticle, bot_custom_jump_particle );
  104. if ( iCustomJumpParticle )
  105. {
  106. const char *pEffectName = "rocketjump_smoke";
  107. DispatchParticleEffect( pEffectName, PATTACH_POINT_FOLLOW, me, "foot_L" );
  108. DispatchParticleEffect( pEffectName, PATTACH_POINT_FOLLOW, me, "foot_R" );
  109. }
  110. }
  111. }