Counter Strike : Global Offensive Source Code
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.

250 lines
8.0 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef VEHICLES_H
  8. #define VEHICLES_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include "datamap.h"
  13. #define VEHICLE_TYPE_CAR_WHEELS (1<<0)
  14. #define VEHICLE_TYPE_CAR_RAYCAST (1<<1)
  15. #define VEHICLE_TYPE_JETSKI_RAYCAST (1<<2)
  16. #define VEHICLE_TYPE_AIRBOAT_RAYCAST (1<<3)
  17. #define VEHICLE_MAX_AXLE_COUNT 4
  18. #define VEHICLE_MAX_GEAR_COUNT 6
  19. #define VEHICLE_MAX_WHEEL_COUNT (2*VEHICLE_MAX_AXLE_COUNT)
  20. #define VEHICLE_TIRE_NORMAL 0
  21. #define VEHICLE_TIRE_BRAKING 1
  22. #define VEHICLE_TIRE_POWERSLIDE 2
  23. struct vehicle_controlparams_t
  24. {
  25. float throttle;
  26. float steering;
  27. float brake;
  28. float boost;
  29. bool handbrake;
  30. bool handbrakeLeft;
  31. bool handbrakeRight;
  32. bool brakepedal;
  33. bool bHasBrakePedal;
  34. bool bAnalogSteering;
  35. };
  36. struct vehicle_operatingparams_t
  37. {
  38. DECLARE_SIMPLE_DATADESC();
  39. float speed;
  40. float engineRPM;
  41. int gear;
  42. float boostDelay;
  43. int boostTimeLeft;
  44. float skidSpeed;
  45. int skidMaterial;
  46. float steeringAngle;
  47. int wheelsNotInContact;
  48. int wheelsInContact;
  49. bool isTorqueBoosting;
  50. };
  51. // Debug!
  52. #define VEHICLE_DEBUGRENDERDATA_MAX_WHEELS 10
  53. #define VEHICLE_DEBUGRENDERDATA_MAX_AXLES 3
  54. struct vehicle_debugcarsystem_t
  55. {
  56. Vector vecAxlePos[VEHICLE_DEBUGRENDERDATA_MAX_AXLES];
  57. Vector vecWheelPos[VEHICLE_DEBUGRENDERDATA_MAX_WHEELS];
  58. Vector vecWheelRaycasts[VEHICLE_DEBUGRENDERDATA_MAX_WHEELS][2];
  59. Vector vecWheelRaycastImpacts[VEHICLE_DEBUGRENDERDATA_MAX_WHEELS];
  60. };
  61. struct vehicleparams_t;
  62. class IPhysicsVehicleController
  63. {
  64. public:
  65. virtual ~IPhysicsVehicleController() {}
  66. // call this from the game code with the control parameters
  67. virtual void Update( float dt, vehicle_controlparams_t &controls ) = 0;
  68. virtual const vehicle_operatingparams_t &GetOperatingParams() = 0;
  69. virtual const vehicleparams_t &GetVehicleParams() = 0;
  70. virtual vehicleparams_t &GetVehicleParamsForChange() = 0;
  71. virtual float UpdateBooster(float dt) = 0;
  72. virtual int GetWheelCount(void) = 0;
  73. virtual IPhysicsObject *GetWheel(int index) = 0;
  74. virtual bool GetWheelContactPoint( int index, Vector *pContactPoint, int *pSurfaceProps ) = 0;
  75. virtual void SetSpringLength(int wheelIndex, float length) = 0;
  76. virtual void SetWheelFriction(int wheelIndex, float friction) = 0;
  77. virtual void OnVehicleEnter( void ) = 0;
  78. virtual void OnVehicleExit( void ) = 0;
  79. virtual void SetEngineDisabled( bool bDisable ) = 0;
  80. virtual bool IsEngineDisabled( void ) = 0;
  81. // Debug
  82. virtual void GetCarSystemDebugData( vehicle_debugcarsystem_t &debugCarSystem ) = 0;
  83. virtual void VehicleDataReload() = 0;
  84. };
  85. // parameters for the body object control of the vehicle
  86. struct vehicle_bodyparams_t
  87. {
  88. DECLARE_SIMPLE_DATADESC();
  89. Vector massCenterOverride; // leave at vec3_origin for no override
  90. float massOverride; // leave at 0 for no override
  91. float addGravity; // keeps car down
  92. float tiltForce; // keeps car down when not on flat ground
  93. float tiltForceHeight; // where the tilt force pulls relative to center of mass
  94. float counterTorqueFactor;
  95. float keepUprightTorque;
  96. float maxAngularVelocity; // clamp the car angular velocity separately from other objects to keep stable
  97. };
  98. // wheel objects are created by vphysics, these are the parameters for those objects
  99. // NOTE: They are paired, so only one set of parameters is necessary per axle
  100. struct vehicle_wheelparams_t
  101. {
  102. DECLARE_SIMPLE_DATADESC();
  103. float radius;
  104. float mass;
  105. float inertia;
  106. float damping; // usually 0
  107. float rotdamping; // usually 0
  108. float frictionScale; // 1.5 front, 1.8 rear
  109. int materialIndex;
  110. int brakeMaterialIndex;
  111. int skidMaterialIndex;
  112. float springAdditionalLength; // 0 means the spring is at it's rest length
  113. };
  114. struct vehicle_suspensionparams_t
  115. {
  116. DECLARE_SIMPLE_DATADESC();
  117. float springConstant;
  118. float springDamping;
  119. float stabilizerConstant;
  120. float springDampingCompression;
  121. float maxBodyForce;
  122. };
  123. // NOTE: both raytrace and wheel data here because jetski uses both.
  124. struct vehicle_axleparams_t
  125. {
  126. DECLARE_SIMPLE_DATADESC();
  127. Vector offset; // center of this axle in vehicle object space
  128. Vector wheelOffset; // offset to wheel (assume other wheel is symmetric at -wheelOffset) from axle center
  129. Vector raytraceCenterOffset; // offset to center of axle for the raytrace data.
  130. Vector raytraceOffset; // offset to raytrace for non-wheel (some wheeled) vehicles
  131. vehicle_wheelparams_t wheels;
  132. vehicle_suspensionparams_t suspension;
  133. float torqueFactor; // normalized to 1 across all axles
  134. // e.g. 0,1 for rear wheel drive - 0.5,0.5 for 4 wheel drive
  135. float brakeFactor; // normalized to 1 across all axles
  136. };
  137. struct vehicle_steeringparams_t
  138. {
  139. DECLARE_SIMPLE_DATADESC();
  140. float degreesSlow; // angle in degrees of steering at slow speed
  141. float degreesFast; // angle in degrees of steering at fast speed
  142. float degreesBoost; // angle in degrees of steering at fast speed
  143. float steeringRateSlow; // this is the speed the wheels are steered when the vehicle is slow
  144. float steeringRateFast; // this is the speed the wheels are steered when the vehicle is "fast"
  145. float steeringRestRateSlow; // this is the speed at which the wheels move toward their resting state (straight ahead) at slow speed
  146. float steeringRestRateFast; // this is the speed at which the wheels move toward their resting state (straight ahead) at fast speed
  147. float speedSlow; // this is the max speed of "slow"
  148. float speedFast; // this is the min speed of "fast"
  149. float turnThrottleReduceSlow; // this is the amount of throttle reduction to apply at the maximum steering angle
  150. float turnThrottleReduceFast; // this is the amount of throttle reduction to apply at the maximum steering angle
  151. float brakeSteeringRateFactor; // this scales the steering rate when the brake/handbrake is down
  152. float throttleSteeringRestRateFactor; // this scales the steering rest rate when the throttle is down
  153. float powerSlideAccel; // scale of speed to acceleration
  154. float boostSteeringRestRateFactor; // this scales the steering rest rate when boosting
  155. float boostSteeringRateFactor; // this scales the steering rest rate when boosting
  156. float steeringExponent; // this makes the steering response non-linear. The steering function is linear, then raised to this power
  157. bool isSkidAllowed; // true/false skid flag
  158. bool dustCloud; // flag for creating a dustcloud behind vehicle
  159. };
  160. struct vehicle_engineparams_t
  161. {
  162. DECLARE_SIMPLE_DATADESC();
  163. float horsepower;
  164. float maxSpeed;
  165. float maxRevSpeed;
  166. float maxRPM; // redline RPM limit
  167. float axleRatio; // ratio of engine rev to axle rev
  168. float throttleTime; // time to reach full throttle in seconds
  169. // transmission
  170. int gearCount; // gear count - max 10
  171. float gearRatio[VEHICLE_MAX_GEAR_COUNT]; // ratio for each gear
  172. // automatic transmission (simple auto-shifter - switches at fixed RPM limits)
  173. float shiftUpRPM; // max RPMs to switch to a higher gear
  174. float shiftDownRPM; // min RPMs to switch to a lower gear
  175. float boostForce;
  176. float boostDuration;
  177. float boostDelay;
  178. float boostMaxSpeed;
  179. float autobrakeSpeedGain;
  180. float autobrakeSpeedFactor;
  181. bool torqueBoost;
  182. bool isAutoTransmission; // true for auto, false for manual
  183. };
  184. struct vehicleparams_t
  185. {
  186. DECLARE_SIMPLE_DATADESC();
  187. int axleCount;
  188. int wheelsPerAxle;
  189. vehicle_bodyparams_t body;
  190. vehicle_axleparams_t axles[VEHICLE_MAX_AXLE_COUNT];
  191. vehicle_engineparams_t engine;
  192. vehicle_steeringparams_t steering;
  193. };
  194. // Iterator for queries
  195. class CPassengerSeatTransition;
  196. typedef CUtlVector< CPassengerSeatTransition> PassengerSeatAnims_t;
  197. // Seat query types
  198. enum VehicleSeatQuery_e
  199. {
  200. VEHICLE_SEAT_ANY, // Any available seat for our role
  201. VEHICLE_SEAT_NEAREST, // Seat closest to our starting point
  202. };
  203. // Seat anim types for return
  204. enum PassengerSeatAnimType_t
  205. {
  206. PASSENGER_SEAT_ENTRY,
  207. PASSENGER_SEAT_EXIT
  208. };
  209. #define VEHICLE_SEAT_INVALID -1 // An invalid seat
  210. #endif // VEHICLES_H