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.

245 lines
8.3 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #ifndef AI_BEHAVIOR_PASSENGER_H
  7. #define AI_BEHAVIOR_PASSENGER_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "ai_speech.h"
  12. #include "ai_behavior.h"
  13. #include "ai_utils.h"
  14. #include "vehicle_jeep_episodic.h"
  15. #define STOPPED_VELOCITY_THRESHOLD 32.0f
  16. #define STOPPED_VELOCITY_THRESHOLD_SQR (STOPPED_VELOCITY_THRESHOLD*STOPPED_VELOCITY_THRESHOLD)
  17. #define STARTED_VELOCITY_THRESHOLD 64.0f
  18. #define STARTED_VELOCITY_THRESHOLD_SQR (STARTED_VELOCITY_THRESHOLD*STARTED_VELOCITY_THRESHOLD)
  19. // Custom activities
  20. extern int ACT_PASSENGER_IDLE;
  21. extern int ACT_PASSENGER_RANGE_ATTACK1;
  22. // ---------------------------------------------
  23. // Vehicle state
  24. // ---------------------------------------------
  25. struct passengerVehicleState_t
  26. {
  27. Vector m_vecLastLocalVelocity;
  28. Vector m_vecDeltaVelocity;
  29. QAngle m_vecLastAngles;
  30. float m_flNextWarningTime;
  31. float m_flLastSpeedSqr;
  32. bool m_bPlayerInVehicle;
  33. bool m_bWasBoosting;
  34. bool m_bWasOverturned;
  35. DECLARE_SIMPLE_DATADESC();
  36. };
  37. // ---------------------------------------------
  38. // Passenger intent
  39. // ---------------------------------------------
  40. enum passesngerVehicleIntent_e
  41. {
  42. PASSENGER_INTENT_NONE,
  43. PASSENGER_INTENT_ENTER, // We want to be in the vehicle
  44. PASSENGER_INTENT_EXIT, // We want to be outside the vehicle
  45. };
  46. // ---------------------------------------------
  47. // Passenger state functions
  48. // ---------------------------------------------
  49. enum PassengerState_e
  50. {
  51. PASSENGER_STATE_OUTSIDE = 0, // Not in the vehicle
  52. PASSENGER_STATE_ENTERING,
  53. PASSENGER_STATE_INSIDE,
  54. PASSENGER_STATE_EXITING,
  55. };
  56. class CAI_PassengerBehavior : public CAI_SimpleBehavior
  57. {
  58. DECLARE_CLASS( CAI_PassengerBehavior, CAI_SimpleBehavior );
  59. DECLARE_DATADESC()
  60. public:
  61. CAI_PassengerBehavior( void );
  62. enum
  63. {
  64. // Schedules
  65. SCHED_PASSENGER_IDLE = BaseClass::NEXT_SCHEDULE,
  66. SCHED_PASSENGER_ENTER_VEHICLE,
  67. SCHED_PASSENGER_EXIT_VEHICLE,
  68. SCHED_PASSENGER_RUN_TO_ENTER_VEHICLE,
  69. SCHED_PASSENGER_ENTER_VEHICLE_PAUSE,
  70. SCHED_PASSENGER_RUN_TO_ENTER_VEHICLE_FAILED,
  71. SCHED_PASSENGER_PLAY_SCRIPTED_ANIM,
  72. NEXT_SCHEDULE,
  73. // Tasks
  74. TASK_PASSENGER_ENTER_VEHICLE = BaseClass::NEXT_TASK,
  75. TASK_PASSENGER_EXIT_VEHICLE,
  76. TASK_PASSENGER_ATTACH_TO_VEHICLE,
  77. TASK_PASSENGER_DETACH_FROM_VEHICLE,
  78. TASK_PASSENGER_SET_IDEAL_ENTRY_YAW,
  79. NEXT_TASK,
  80. // Conditions
  81. COND_PASSENGER_HARD_IMPACT = BaseClass::NEXT_CONDITION,
  82. COND_PASSENGER_ENTERING,
  83. COND_PASSENGER_EXITING,
  84. COND_PASSENGER_VEHICLE_STARTED,
  85. COND_PASSENGER_VEHICLE_STOPPED,
  86. COND_PASSENGER_OVERTURNED,
  87. COND_PASSENGER_CANCEL_ENTER,
  88. COND_PASSENGER_ERRATIC_DRIVING,
  89. COND_PASSENGER_PLAYER_ENTERED_VEHICLE,
  90. COND_PASSENGER_PLAYER_EXITED_VEHICLE,
  91. COND_PASSENGER_JOSTLE_SMALL,
  92. NEXT_CONDITION
  93. };
  94. bool ForceVehicleInteraction( const char *lpszInteractionName, CBaseCombatCharacter *pOther );
  95. virtual bool CanSelectSchedule( void );
  96. virtual int SelectSchedule( void );
  97. virtual int SelectFailSchedule( int failedSchedule, int failedTask, AI_TaskFailureCode_t taskFailCode );
  98. virtual void RunTask( const Task_t *pTask );
  99. virtual void StartTask( const Task_t *pTask );
  100. virtual void BuildScheduleTestBits( void );
  101. virtual int TranslateSchedule( int scheduleType );
  102. virtual void GetEntryTarget( Vector *vecOrigin, QAngle *vecAngles );
  103. virtual void GatherConditions( void );
  104. virtual void ModifyOrAppendCriteria( AI_CriteriaSet& criteriaSet );
  105. virtual void Teleport( const Vector *newPosition, const QAngle *newAngles, const Vector *newVelocity );
  106. virtual void ClearSchedule( const char *szReason );
  107. virtual bool IsInterruptable( void );
  108. virtual void PrescheduleThink( void );
  109. virtual void CancelEnterVehicle( void );
  110. virtual const char *GetName( void ) { return "Passenger"; }
  111. virtual string_t GetRoleName( void ) { return MAKE_STRING( "passenger" ); }
  112. // Enable/disable code
  113. void Enable( CPropJeepEpisodic *pVehicle, bool bImmediateEntrance = false );
  114. void Disable( void );
  115. bool IsEnabled( void ) const { return m_bEnabled; }
  116. virtual void EnterVehicle( void );
  117. virtual void ExitVehicle( void );
  118. void AddPhysicsPush( float force );
  119. CPropVehicleDriveable *GetTargetVehicle( void ) const { return m_hVehicle; }
  120. PassengerState_e GetPassengerState( void ) const { return m_PassengerState; }
  121. virtual void OnRestore();
  122. protected:
  123. virtual int SelectTransitionSchedule( void );
  124. bool SpeakIfAllowed( AIConcept_t concept, const char *modifiers = NULL, bool bRespondingToPlayer = false, char *pszOutResponseChosen = NULL, size_t bufsize = 0 );
  125. bool CanExitVehicle( void );
  126. void SetTransitionSequence( int nSequence );
  127. void AttachToVehicle( void );
  128. virtual void OnExitVehicleFailed( void ) { } // NPC attempted to leave vehicle, but was unable to
  129. virtual void GatherVehicleStateConditions( void );
  130. // ------------------------------------------
  131. // Entry/exit transition code
  132. // ------------------------------------------
  133. virtual void FinishEnterVehicle( void );
  134. virtual void FinishExitVehicle( void );
  135. void DetachFromVehicle( void );
  136. void DrawDebugTransitionInfo( const Vector &vecIdealPos, const QAngle &vecIdealAngles, const Vector &vecAnimPos, const QAngle &vecAnimAngles );
  137. bool GetEntryPoint( int nSequence, Vector *vecEntryPoint, QAngle *vecEntryAngles = NULL );
  138. bool GetExitPoint( int nSequence, Vector *vecExitPoint, QAngle *vecExitAngles = NULL );
  139. bool PointIsNavigable( const Vector &vecTargetPos );
  140. bool ReserveEntryPoint( VehicleSeatQuery_e eSeatSearchType );
  141. bool ReserveExitPoint( void );
  142. bool FindGroundAtPosition( const Vector &in, float flUpDelta, float flDownDelta, Vector *out );
  143. bool DoTransitionMovement( void );
  144. bool GetSequenceBlendAmount( float flCycle, float *posBlend, float *angBlend );
  145. bool LocalIntervalMovement( float flInterval, bool &bMoveSeqFinished, Vector &newPosition, QAngle &newAngles );
  146. void GetTransitionAnimationIdeal( float flCycle, const Vector &vecTargetPos, const QAngle &vecTargetAngles, Vector *idealOrigin, QAngle *idealAngles );
  147. float GetNextCycleForInterval( int nSequence, float flInterval );
  148. void GetLocalVehicleVelocity( Vector *pOut );
  149. void CacheBlendTargets( void );
  150. void InitVehicleState( void );
  151. int FindEntrySequence( bool bNearest = false );
  152. int FindExitSequence( void );
  153. bool IsValidTransitionPoint( const Vector &vecStartPos, const Vector &vecEndPos );
  154. void SetPassengerState( PassengerState_e state ) { m_PassengerState = state; }
  155. PassengerState_e m_PassengerState; // State we're in, for the vehicle
  156. // ---------------------------------------------
  157. bool IsPassengerHostile( void );
  158. passengerVehicleState_t m_vehicleState; // Internal vehicle state
  159. CHandle <CPropVehicleDriveable> m_hVehicle; // The vehicle we're bound to
  160. CHandle <CEntityBlocker> m_hBlocker; // Blocking entity for space reservation
  161. Vector m_vecTargetPosition; // Target destination for exiting the vehicle
  162. QAngle m_vecTargetAngles; // Target angles for exiting the vehicle
  163. bool m_bEnabled; // If the behavior is running
  164. passesngerVehicleIntent_e m_PassengerIntent; // Gives us information about whether we're meant to get in/out, etc.
  165. int m_nTransitionSequence; // Animation we're using to transition with
  166. float m_flOriginStartFrame;
  167. float m_flOriginEndFrame;
  168. float m_flAnglesStartFrame;
  169. float m_flAnglesEndFrame;
  170. protected:
  171. DEFINE_CUSTOM_SCHEDULE_PROVIDER;
  172. };
  173. class CTraceFilterVehicleTransition : public CTraceFilterSkipTwoEntities
  174. {
  175. public:
  176. DECLARE_CLASS( CTraceFilterVehicleTransition, CTraceFilterSkipTwoEntities );
  177. CTraceFilterVehicleTransition( const IHandleEntity *passentity, const IHandleEntity *passentity2, int collisionGroup ) :
  178. CTraceFilterSkipTwoEntities( passentity, passentity2, collisionGroup ) {}
  179. bool ShouldHitEntity( IHandleEntity *pServerEntity, int contentsMask )
  180. {
  181. bool bRet = BaseClass::ShouldHitEntity( pServerEntity, contentsMask );
  182. CBaseEntity *pEntity = EntityFromEntityHandle( pServerEntity );
  183. if ( pEntity )
  184. {
  185. IPhysicsObject *pPhys = pEntity->VPhysicsGetObject();
  186. if ( pPhys )
  187. {
  188. // Ignore physics objects
  189. // TODO: This will have to be fleshed out more as cases arise
  190. if ( pPhys->IsMoveable() && pPhys->GetMass() < 80.0f )
  191. return false;
  192. }
  193. }
  194. return bRet;
  195. }
  196. };
  197. #endif // AI_BEHAVIOR_PASSENGER_H