BVB Source Codes

CRYENGINE Show IVehicleSystem.h Source code

Return Download CRYENGINE: download IVehicleSystem.h Source code - Download CRYENGINE Source code - Type:.h
  1. // Copyright 2001-2016 Crytek GmbH / Crytek Group. All rights reserved.
  2.  
  3. #pragma once
  4.  
  5. #include <CryEntitySystem/IEntity.h>
  6. #include <CryEntitySystem/IEntitySystem.h>
  7. #include <CryNetwork/ISerialize.h>
  8. #include <CryAudio/IAudioSystem.h>
  9. #include "IGameObjectSystem.h"
  10. #include "IGameObject.h"
  11. #include "IMovementController.h"
  12. #include "VehicleSystem/VehicleParams.h"
  13.  
  14. struct IGameFramework;
  15. struct SViewParams;
  16. struct SOBJECTSTATE;
  17. struct IVehiclePart;
  18. struct IVehicleWheel;
  19. struct IVehicleMovement;
  20. class CMovementRequest;
  21. struct SMovementState;
  22. struct IVehicleEventListener;
  23. struct SVehicleEventParams;
  24. struct IFireController;
  25. struct IVehicleSystem;
  26. struct IVehicleSeat;
  27. struct IVehicleAnimation;
  28. struct IVehicleHelper;
  29. struct IVehicleComponent;
  30. struct IVehicleAnimationComponent;
  31. struct IVehicleClient;
  32. struct HitInfo;
  33.  
  34. // compile out debug draw code in release builds
  35. #if defined(_RELEASE) || defined(DEDICATED_SERVER)
  36.         #define ENABLE_VEHICLE_DEBUG 0
  37. #else
  38.         #define ENABLE_VEHICLE_DEBUG 1
  39. #endif
  40.  
  41. // Summary
  42. //   Type used to hold vehicle's ActionIds
  43. // See Also
  44. //   EVehicleActionIds
  45. typedef int TVehicleActionId;
  46.  
  47. // Summary
  48. //   ActionId constants
  49. // Description
  50. //   ActionId constants which represent the multiple ways that an actor can
  51. //   interact while being on a vehicle seat.
  52. // See Also
  53. //   TVehicleActionId
  54. enum EVehicleActionIds
  55. {
  56.         eVAI_Exit = 1,
  57.         eVAI_ChangeSeat,
  58.         eVAI_ChangeSeat1,
  59.         eVAI_ChangeSeat2,
  60.         eVAI_ChangeSeat3,
  61.         eVAI_ChangeSeat4,
  62.         eVAI_ChangeSeat5,
  63.         eVAI_RotatePitch,
  64.         eVAI_RotateYaw,
  65.         eVAI_RotatePitchAimAssist,
  66.         eVAI_RotateYawAimAssist,
  67.         eVAI_RotateRoll,
  68.         eVAI_XIRotatePitch,
  69.         eVAI_XIRotateYaw,
  70.         eVAI_MoveForward,
  71.         eVAI_MoveBack,
  72.         eVAI_XIMoveY,
  73.         eVAI_TurnLeft,
  74.         eVAI_TurnRight,
  75.         eVAI_XIMoveX,
  76.         eVAI_StrafeLeft,
  77.         eVAI_StrafeRight,
  78.         eVAI_XIStrafe,
  79.         eVAI_RollLeft,
  80.         eVAI_RollRight,
  81.         eVAI_AfterBurner,
  82.         eVAI_Brake,
  83.         eVAI_MoveUp,
  84.         eVAI_MoveDown,
  85.         eVAI_XIMoveUpDown,
  86.         eVAI_ChangeView,
  87.         eVAI_ViewOption,
  88.         eVAI_FireMode,
  89.         eVAI_Attack1,
  90.         eVAI_Attack2,
  91.         eVAI_Attack3,
  92.         eVAI_ToggleLights,
  93.         eVAI_Horn,
  94.         eVAI_ZoomIn,
  95.         eVAI_ZoomOut,
  96.         eVAI_DesirePitch,
  97.         eVAI_Boost,
  98.         eVAI_PitchUp,
  99.         eVAI_PitchDown,
  100.         eVAI_Debug_1,
  101.         eVAI_Debug_2,
  102.         eVAI_PhysicsStep,
  103.         eVAI_XIAccelerate,
  104.         eVAI_XIDeccelerate,
  105.         eVAI_Others,
  106. };
  107.  
  108. // Summary
  109. //   Vehicle event types
  110. // See Also
  111. //   IVehicle::BroadcastVehicleEvent, IVehicle::RegisterVehicleEventListener, IVehicleEventListener
  112. enum EVehicleEvent
  113. {
  114.         eVE_Collision = 0,
  115.         eVE_Hit,
  116.         eVE_Damaged,
  117.         eVE_Destroyed,
  118.         eVE_Repair,
  119.         eVE_PassengerEnter,
  120.         eVE_PassengerExit,
  121.         eVE_PassengerChangeSeat,
  122.         eVE_SeatFreed,
  123.         eVE_PreVehicleDeletion,
  124.         eVE_VehicleDeleted,
  125.         eVE_ToggleDriverControlledGuns,
  126.         eVE_Brake,
  127.         eVE_Timer,
  128.         eVE_EngineStopped,
  129.         eVE_OpenDoors,
  130.         eVE_CloseDoors,
  131.         eVE_BlockDoors,
  132.         eVE_ExtractGears,
  133.         eVE_RetractGears,
  134.         eVE_Indestructible,
  135.         eVE_BeingFlipped,
  136.         eVE_Reversing,
  137.         eVE_WeaponRemoved,
  138.         eVE_TryDetachPartEntity,
  139.         eVE_OnDetachPartEntity,
  140.         eVE_TryAttachPartEntityNetID,
  141.         eVE_RequestDelayedDetachAllPartEntities,
  142.         eVE_StartParticleEffect,
  143.         eVE_StopParticleEffect,
  144.         eVE_LockBoneRotation,
  145.         eVE_VehicleMovementRotation,
  146.         eVE_Hide,
  147.         eVE_ViewChanged,
  148.         eVE_Awake,
  149.         eVE_Sleep,
  150.         eVE_Last,
  151. };
  152.  
  153. // Summary
  154. //   Value type used to define the seat id in the vehicle system
  155. // See Also
  156. //   IVehicleSeat
  157. typedef int TVehicleSeatId;
  158. const TVehicleSeatId InvalidVehicleSeatId = 0;
  159. const TVehicleSeatId FirstVehicleSeatId   = 1;
  160.  
  161. // Summary
  162. //   Value type used to define the view id in the vehicle system
  163. // See Also
  164. //   IVehicleView
  165. typedef int TVehicleViewId;
  166. const TVehicleSeatId InvalidVehicleViewId = 0;
  167. const TVehicleSeatId FirstVehicleViewId   = 1;
  168.  
  169. // Summary
  170. //   Value type used to define the state id of a vehicle animation
  171. // See Also
  172. //   IVehicleAnimation
  173. typedef int TVehicleAnimStateId;
  174. const TVehicleAnimStateId InvalidVehicleAnimStateId = -1;
  175.  
  176. struct SVehicleStatus
  177. {
  178.         SVehicleStatus()
  179.         {
  180.                 Reset();
  181.         }
  182.  
  183.         void Reset()
  184.         {
  185.                 vel.Set(0, 0, 0);
  186.                 speed = 0.f;
  187.                 health = 1.f;
  188.                 passengerCount = 0;
  189.                 altitude = 0.f;
  190.                 flipped = 0.f;
  191.                 contacts = 0;
  192.                 submergedRatio = 0.f;
  193.                 frameId = 0;
  194.                 beingFlipped = false;
  195.                 doingNetPrediction = false;
  196.         }
  197.  
  198.         void Serialize(TSerialize ser, EEntityAspects aspects)
  199.         {
  200.                 ser.Value("health", health);
  201.                 ser.Value("speed", speed);
  202.                 ser.Value("altitude", altitude);
  203.                 ser.Value("flipped", flipped);
  204.         }
  205.  
  206.         Vec3  vel;
  207.         float speed;
  208.         float health;
  209.         float altitude;
  210.         float flipped;
  211.         int   passengerCount;
  212.         int   contacts;
  213.         float submergedRatio;
  214.         bool  beingFlipped;
  215.         bool  doingNetPrediction;
  216.  
  217.         int   frameId;
  218. };
  219.  
  220. // Vehicle Movement Status Interface
  221. enum EVehicleMovementStatusType
  222. {
  223.         eVMS_invalid,
  224.         eVMS_general,
  225.         eVMS_wheeled,
  226. };
  227.  
  228. struct SVehicleMovementStatus
  229. {
  230.         int typeId;
  231.         SVehicleMovementStatus(int type = eVMS_invalid) : typeId(type) {}
  232. };
  233.  
  234. // Gather general status
  235. struct SVehicleMovementStatusGeneral : SVehicleMovementStatus
  236. {
  237.         SVehicleMovementStatusGeneral() : SVehicleMovementStatus(eVMS_general)
  238.         {
  239.                 pos.zero();
  240.                 q.SetIdentity();
  241.                 centerOfMass.zero();
  242.                 vel.zero();
  243.                 angVel.zero();
  244.                 localVel.zero();
  245.                 localAngVel.zero();
  246.                 localAccel.zero();
  247.                 speed = 0.f;
  248.                 topSpeed = 0.f;
  249.                 submergedRatio = 0.f;
  250.         }
  251.  
  252.         Vec3  pos;
  253.         Quat  q;
  254.         Vec3  centerOfMass;
  255.         Vec3  vel;
  256.         Vec3  angVel;
  257.         Vec3  localVel;
  258.         Vec3  localAngVel;
  259.         Vec3  localAccel;
  260.         float speed;
  261.         float topSpeed;
  262.         float submergedRatio;
  263. };
  264.  
  265. // Gather wheeled status
  266. struct SVehicleMovementStatusWheeled : SVehicleMovementStatus
  267. {
  268.         SVehicleMovementStatusWheeled() : SVehicleMovementStatus(eVMS_wheeled)
  269.         {
  270.                 numWheels = 0;
  271.                 suspensionCompressionRate = 0.f;
  272.         }
  273.  
  274.         int   numWheels;
  275.         float suspensionCompressionRate;
  276. };
  277.  
  278. struct SVehicleDamageParams
  279. {
  280.         float collisionDamageThreshold;
  281.  
  282.         float groundCollisionMinSpeed;
  283.         float groundCollisionMaxSpeed;
  284.         float groundCollisionMinMult;
  285.         float groundCollisionMaxMult;
  286.  
  287.         float vehicleCollisionDestructionSpeed;
  288.  
  289.         float submergedRatioMax;
  290.         float submergedDamageMult;
  291.  
  292.         float aiKillPlayerSpeed;
  293.         float playerKillAISpeed;
  294.         float aiKillAISpeed;  // only applies to AI of other faction
  295.  
  296.         SVehicleDamageParams()
  297.         {
  298.                 collisionDamageThreshold = 50.f;
  299.  
  300.                 groundCollisionMinMult = 1.f; // increases "falling" damage when > 1
  301.                 groundCollisionMaxMult = 1.f;
  302.                 groundCollisionMinSpeed = 15.f;
  303.                 groundCollisionMaxSpeed = 50.f;
  304.  
  305.                 vehicleCollisionDestructionSpeed = -1;  // eg disabled.
  306.  
  307.                 submergedRatioMax = 1.f;
  308.                 submergedDamageMult = 1.f;
  309.  
  310.                 aiKillPlayerSpeed = 0.0f;
  311.                 playerKillAISpeed = 0.0f;
  312.                 aiKillAISpeed = 0.0f;
  313.         }
  314. };
  315.  
  316. struct SVehicleImpls
  317. {
  318.         void   Add(const string& impl) { vImpls.push_back(impl); }
  319.  
  320.         int    Count() const           { return vImpls.size(); }
  321.  
  322.         string GetAt(int idx) const
  323.         {
  324.                 if (idx >= 0 && idx < (int)vImpls.size())
  325.                         return vImpls[idx];
  326.                 return "";
  327.         }
  328. private:
  329.         std::vector<string> vImpls;
  330. };
  331.  
  332. /** Exhaust particles parameter structure
  333.  * Movement classes can use this to control exhausts.
  334.  * Currently we support a start/stop effect and a running effect
  335.  * with various parameters. It's up to the movement if/how
  336.  * it makes use of it.
  337.  */
  338. struct SExhaustParams
  339. {
  340.         SExhaustParams()
  341.         {
  342.                 runBaseSizeScale = 1.0f;
  343.                 runMinSpeed = runMaxSpeed = 0.0f;
  344.                 runMinPower = runMaxPower = 0.0f;
  345.                 runMinSpeedSizeScale = runMaxSpeedSizeScale = 1.0f;
  346.                 runMinSpeedCountScale = runMaxSpeedCountScale = 1.0f;
  347.                 runMinSpeedSpeedScale = runMaxSpeedSpeedScale = 1.0f;
  348.                 runMinPowerSizeScale = runMaxPowerSizeScale = 1.0f;
  349.                 runMinPowerSpeedScale = runMaxPowerSpeedScale = 1.0f;
  350.                 runMinPowerCountScale = 1.0f;
  351.                 runMaxPowerCountScale = 1.0f;
  352.                 insideWater = false;
  353.                 outsideWater = true;
  354.                 disableWithNegativePower = false;
  355.  
  356.                 hasExhaust = false;
  357.         }
  358.         virtual ~SExhaustParams(){}
  359.         virtual size_t          GetExhaustCount() const = 0;
  360.         virtual IVehicleHelper* GetHelper(int idx) const = 0;
  361.  
  362.         virtual const char*     GetStartEffect() const = 0;
  363.         virtual const char*     GetStopEffect() const = 0;
  364.         virtual const char*     GetRunEffect() const = 0;
  365.         virtual const char*     GetBoostEffect() const = 0;
  366.  
  367.         float                   runBaseSizeScale;
  368.         float                   runMinSpeed;
  369.         float                   runMinSpeedSizeScale;
  370.         float                   runMinSpeedCountScale;
  371.         float                   runMinSpeedSpeedScale;
  372.         float                   runMaxSpeed;
  373.         float                   runMaxSpeedSizeScale;
  374.         float                   runMaxSpeedCountScale;
  375.         float                   runMaxSpeedSpeedScale;
  376.         float                   runMinPower;
  377.         float                   runMinPowerSizeScale;
  378.         float                   runMinPowerCountScale;
  379.         float                   runMinPowerSpeedScale;
  380.         float                   runMaxPower;
  381.         float                   runMaxPowerSizeScale;
  382.         float                   runMaxPowerCountScale;
  383.         float                   runMaxPowerSpeedScale;
  384.  
  385.         bool                    insideWater;
  386.         bool                    outsideWater;
  387.         bool                    disableWithNegativePower;
  388.  
  389.         bool                    hasExhaust;
  390. };
  391.  
  392. struct SDamageEffect
  393. {
  394.         string          effectName;
  395.         IVehicleHelper* pHelper;
  396.         bool            isGravityDirUsed;
  397.         Vec3            gravityDir;
  398.         float           pulsePeriod;
  399.  
  400.         void            GetMemoryUsage(ICrySizer* s) const
  401.         {
  402.                 s->AddObject(effectName);
  403.         }
  404.  
  405.         SDamageEffect()
  406.                 : pHelper(NULL),
  407.                 isGravityDirUsed(false),
  408.                 gravityDir(ZERO),
  409.                 pulsePeriod(0.f)
  410.         {
  411.         }
  412. };
  413.  
  414. /** SEnvironmentParticles
  415.  * Holds params for environment particles like dust, dirt..
  416.  * A vehicle can use several layers to control different effects
  417.  * with distinct parameters.
  418.  */
  419. struct SEnvironmentLayer
  420. {
  421.         SEnvironmentLayer()
  422.         {
  423.                 minSpeed = 0;
  424.                 maxSpeed = 10;
  425.                 minSpeedSizeScale = maxSpeedSizeScale = 1.f;
  426.                 minSpeedCountScale = maxSpeedCountScale = 1.f;
  427.                 minSpeedSpeedScale = maxSpeedSpeedScale = 1.f;
  428.                 minPowerSizeScale = maxPowerSizeScale = 1.f;
  429.                 minPowerCountScale = maxPowerCountScale = 1.f;
  430.                 minPowerSpeedScale = maxPowerSpeedScale = 1.f;
  431.                 maxHeightSizeScale = maxHeightCountScale = 1.f;
  432.                 alignGroundHeight = 0;
  433.                 alignToWater = false;
  434.                 active = true;
  435.         }
  436.         virtual ~SEnvironmentLayer(){}
  437.  
  438.         virtual const char*     GetName() const = 0;
  439.  
  440.         virtual size_t          GetHelperCount() const = 0;
  441.         virtual IVehicleHelper* GetHelper(int idx) const = 0;
  442.  
  443.         virtual size_t          GetGroupCount() const = 0;
  444.         virtual size_t          GetWheelCount(int group) const = 0;
  445.         virtual int             GetWheelAt(int group, int wheel) const = 0;
  446.  
  447.         virtual bool            IsGroupActive(int group) const = 0;
  448.         virtual void            SetGroupActive(int group, bool active) = 0;
  449.  
  450.         float                   minSpeed;
  451.         float                   minSpeedSizeScale;
  452.         float                   minSpeedCountScale;
  453.         float                   minSpeedSpeedScale;
  454.         float                   maxSpeed;
  455.         float                   maxSpeedSizeScale;
  456.         float                   maxSpeedCountScale;
  457.         float                   maxSpeedSpeedScale;
  458.         float                   minPowerSizeScale;
  459.         float                   minPowerCountScale;
  460.         float                   minPowerSpeedScale;
  461.         float                   maxPowerSizeScale;
  462.         float                   maxPowerCountScale;
  463.         float                   maxPowerSpeedScale;
  464.         float                   alignGroundHeight;
  465.         float                   maxHeightSizeScale;
  466.         float                   maxHeightCountScale;
  467.         bool                    alignToWater;
  468.         bool                    active;
  469. };
  470.  
  471. /** SEnvironmentParticles
  472.  * Holds EnvironmentLayers
  473.  */
  474. struct SEnvironmentParticles
  475. {
  476.         virtual ~SEnvironmentParticles(){}
  477.         virtual size_t                   GetLayerCount() const = 0;
  478.         virtual const SEnvironmentLayer& GetLayer(int idx) const = 0;
  479.         virtual const char*              GetMFXRowName() const = 0;
  480. };
  481.  
  482. typedef std::map<string, SDamageEffect> TDamageEffectMap;
  483.  
  484. /** SParticleParams is the container for all particle structures
  485.  */
  486. struct SParticleParams
  487. {
  488.         virtual ~SParticleParams(){}
  489.         virtual SExhaustParams*        GetExhaustParams() = 0;
  490.         virtual const SDamageEffect*   GetDamageEffect(const char* pName) const = 0;
  491.         virtual SEnvironmentParticles* GetEnvironmentParticles() = 0;
  492. };
  493.  
  494. struct SVehicleEventParams
  495. {
  496.         EntityId entityId;
  497.  
  498.         bool     bParam;
  499.         int      iParam;
  500.         float    fParam, fParam2;
  501.         Vec3     vParam;
  502.  
  503.         SVehicleEventParams()
  504.                 : entityId(0)
  505.                 , bParam(false)
  506.                 , iParam(0)
  507.                 , fParam(0.f)
  508.                 , fParam2(0.0f)
  509.         {
  510.                 vParam.zero();
  511.         }
  512. };
  513.  
  514. struct SVehicleMovementEventParams
  515. {
  516.         Vec3               vParam; // param for hit pos or others
  517.         float              fValue; // param for e.g. damage value
  518.         int                iValue;
  519.         bool               bValue;
  520.         const char*        sParam;
  521.         IVehicleComponent* pComponent; // optionally, vehicle component involved
  522.  
  523.         SVehicleMovementEventParams()
  524.                 : fValue(0.f)
  525.                 , iValue(0)
  526.                 , bValue(false)
  527.                 , pComponent(NULL)
  528.                 , sParam(NULL)
  529.         {
  530.                 vParam.zero();
  531.         }
  532. };
  533.  
  534. // Sound event info
  535. struct SVehicleSoundInfo
  536. {
  537.         string          name; // event name
  538.         IVehicleHelper* pHelper;
  539.         AudioControlId  soundId;
  540.         bool            isEngineSound;
  541.  
  542.         SVehicleSoundInfo() : isEngineSound(false), pHelper(NULL)
  543.         {
  544.                 soundId = INVALID_AUDIO_CONTROL_ID;
  545.         }
  546. };
  547. typedef int TVehicleSoundEventId;
  548. const TVehicleSoundEventId InvalidSoundEventId = -1;
  549.  
  550. // Vehicle weapon info
  551. struct SVehicleWeaponInfo
  552. {
  553.         EntityId entityId;
  554.         bool     bCanFire;
  555.  
  556.         SVehicleWeaponInfo() : entityId(0), bCanFire(false) {}
  557. };
  558.  
  559. struct IVehicleEventListener
  560. {
  561.         virtual ~IVehicleEventListener(){}
  562.         virtual void OnVehicleEvent(EVehicleEvent event, const SVehicleEventParams& params) = 0;
  563. };
  564.  
  565. struct IVehicleUsageEventListener
  566. {
  567.         virtual ~IVehicleUsageEventListener(){}
  568.         virtual void OnStartUse(const EntityId playerId, IVehicle* pVehicle) = 0;
  569.         virtual void OnEndUse(const EntityId playerId, IVehicle* pVehicle) = 0;
  570. };
  571.  
  572. // Summary
  573. //   Type for the id used to define the class of a vehicle object
  574. // See Also
  575. //   IVehicleObject
  576. typedef unsigned int TVehicleObjectId;
  577. const TVehicleObjectId InvalidVehicleObjectId = 0;
  578.  
  579. // Summary
  580. //   Base interface used by many vehicle objects
  581. struct IVehicleObject
  582.         : public IVehicleEventListener
  583. {
  584.         // Summary
  585.         //   Returns the id of the vehicle object
  586.         virtual TVehicleObjectId GetId() const = 0;
  587.  
  588.         // Summary
  589.         //   Serialize the vehicle object
  590.         virtual void Serialize(TSerialize ser, EEntityAspects aspects) = 0;
  591.  
  592.         // Summary
  593.         //   Update the vehicle object
  594.         // Description
  595.         //   Used to handle any time sensitive updates. In example, rotation for
  596.         //   turret parts is implemented in this function.
  597.         // Parameters
  598.         //   deltaTime - total time for the update, in seconds
  599.         virtual void Update(const float deltaTime) = 0;
  600.  
  601.         virtual void UpdateFromPassenger(const float deltaTime, EntityId playerId) {}
  602.  
  603.         // Summary
  604.         //  Handle vehicle events
  605.         // See Also
  606.         //   EVehicleEvent
  607.         virtual void OnVehicleEvent(EVehicleEvent event, const SVehicleEventParams& params) = 0;
  608. };
  609.  
  610. // Summary
  611. //   Enumeration of different event which can trigger a vehicle action to
  612. //   perform some tasks.
  613. // See Also
  614. //   IVehicleAction
  615. enum EVehicleActionEvent
  616. {
  617.         eVAE_IsUsable = 1,      // When the vehicle is being tested to be usuable by a player (by aiming the crossair).
  618.         eVAE_OnUsed,            // When the vehicle is being used by a player (with the USE key).
  619.         eVAE_OnGroundCollision, // When the vehicle collide with the ground.
  620.         eVAE_OnEntityCollision, // When the vehicle collide with another entity.
  621.         eVAE_Others,            // ot be used as starting index for game specific action events.
  622. };
  623.  
  624. // Summary
  625. //   Interface used to implement a special behavior that affect the vehicle
  626. // Description
  627. //   In example, landing gears on flying vehicles or the entering procedure
  628. //   for the player are implemented as vehicle action.
  629. struct IVehicleAction
  630.         : public IVehicleObject
  631. {
  632.         virtual bool Init(IVehicle* pVehicle, const CVehicleParams& table) = 0;
  633.         virtual void Reset() = 0;
  634.         virtual void Release() = 0;
  635.  
  636.         virtual int  OnEvent(int eventType, SVehicleEventParams& eventParams) = 0;
  637.  
  638.         // IVehicleObject
  639.         virtual TVehicleObjectId GetId() const override = 0;
  640.         virtual void             Serialize(TSerialize ser, EEntityAspects aspects) override = 0;
  641.         virtual void             Update(const float deltaTime) override = 0;
  642.         // ~IVehicleObject
  643. };
  644.  
  645. #define IMPLEMENT_VEHICLEOBJECT         \
  646.   public:                               \
  647.     static TVehicleObjectId m_objectId; \
  648.     friend struct IVehicleSystem;       \
  649.     virtual TVehicleObjectId GetId() const override { return m_objectId; }
  650.  
  651. #define DEFINE_VEHICLEOBJECT(obj) \
  652.   TVehicleObjectId obj::m_objectId = InvalidVehicleObjectId;
  653.  
  654. #define CAST_VEHICLEOBJECT(type, objptr) \
  655.   (objptr->GetId() == type::m_objectId) ? (type*)objptr : NULL
  656.  
  657. // Summary:
  658. //   Vehicle implementation interface
  659. // Description:
  660. //   Interface used to implement a vehicle.
  661. struct IVehicle : public IGameObjectExtension
  662. {
  663.         // Summary:
  664.         //   Reset vehicle
  665.         // Description:
  666.         //   Will reset properly all components of the vehicle including the seats,
  667.         //   components, parts and the movement.
  668.         virtual void Reset(bool enterGame) = 0;
  669.  
  670.         // Summary:
  671.         //   Gets the physics params
  672.         // Description:
  673.         //   It will return the physics params which have been sent to the entity
  674.         //   system when the vehicle entity was spawned
  675.         // Return value:
  676.         //   a SEntityPhysicalizeParams structure
  677.         virtual SEntityPhysicalizeParams& GetPhysicsParams() = 0;
  678.  
  679.         // Summary:
  680.         //   Gets the status
  681.         // Description:
  682.         //   Will return a structure which hold several status information on the vehicle, including destroyed state and passenger count.
  683.         // Return value:
  684.         //   a SVehicleStatus structure
  685.         virtual const SVehicleStatus& GetStatus() const = 0;
  686.  
  687.         // Summary:
  688.         //   Updates view of a passenger
  689.         // Description:
  690.         //   Will update the SViewParams structure will the correct camera info for a specified passenger of the vehicle.
  691.         // Parameters:
  692.         //   viewParams - structure which is used to return the camera info
  693.         //   playerId - entity id of the passenger
  694.         virtual void UpdateView(SViewParams& viewParams, EntityId playerId = 0) = 0;
  695.  
  696.         virtual void UpdatePassenger(float frameTime, EntityId playerId) = 0;
  697.  
  698.         //FIXME:move this to the gameside, its not really needed here, plus add callerId to the IActionListener interface
  699.         virtual void                        OnAction(const TVehicleActionId actionId, int activationMode, float value, EntityId callerId) = 0;
  700.         virtual void                        OnHit(const HitInfo& hitInfo, IVehicleComponent* pHitComponent = NULL) = 0;
  701.  
  702.         virtual void                        SetUnmannedFlippedThresholdAngle(float angle) = 0;
  703.  
  704.         virtual float                       GetDamageRatio(bool onlyMajorComponents = false) const = 0;
  705.  
  706.         virtual void                        SetAmmoCount(IEntityClass* pAmmoType, int amount) = 0;
  707.         virtual int                         GetAmmoCount(IEntityClass* pAmmoType) const = 0;
  708.  
  709.         virtual void                        SetOwnerId(EntityId ownerId) = 0;
  710.         virtual EntityId                    GetOwnerId() const = 0;
  711.  
  712.         virtual int                         IsUsable(EntityId userId) = 0;
  713.         virtual bool                        OnUsed(EntityId userId, int index) = 0;
  714.  
  715.         virtual bool                        AddSeat(const SmartScriptTable& seatParams) = 0;
  716.         virtual bool                        AddHelper(const char* name, Vec3 position, Vec3 direction, IVehiclePart* pPart) = 0;
  717.  
  718.         virtual int                         GetPartCount() = 0;
  719.         virtual IVehiclePart*               GetPart(unsigned int index) = 0;
  720.         virtual void                        GetParts(IVehiclePart** parts, int nMax) = 0;
  721.  
  722.         virtual int                         GetComponentCount() const = 0;
  723.         virtual IVehicleComponent*          GetComponent(int index) = 0;
  724.         virtual IVehicleComponent*          GetComponent(const char* name) = 0;
  725.  
  726.         virtual IVehicleAnimationComponent& GetAnimationComponent() = 0;
  727.  
  728.         virtual IVehicleAnimation*          GetAnimation(const char* name) = 0;
  729.  
  730.         virtual int                         GetActionCount() = 0;
  731.         virtual IVehicleAction*             GetAction(int index) = 0;
  732.  
  733.         // get the current movement controller
  734.         virtual IMovementController* GetMovementController() = 0;
  735.  
  736.         virtual IFireController*     GetFireController(uint32 controllerNum = 0) = 0;
  737.  
  738.         // Get TVehicleSeatId of last seat
  739.         virtual TVehicleSeatId GetLastSeatId() = 0;
  740.  
  741.         // Get Seat by SeatId, or NULL
  742.         virtual IVehicleSeat* GetSeatById(const TVehicleSeatId seatId) const = 0;
  743.  
  744.         // Get amount of Seats
  745.         virtual unsigned int GetSeatCount() = 0;
  746.  
  747.         // get seat interface for passengerId, or NULL
  748.         virtual IVehicleSeat* GetSeatForPassenger(EntityId passengerId) const = 0;
  749.  
  750.         // Get SeatId by name
  751.         virtual TVehicleSeatId GetSeatId(const char* pSeatName) = 0;
  752.  
  753.         // check if player/client is driving this vehicle
  754.         virtual bool IsPlayerDriving(bool clientOnly = true) = 0;
  755.  
  756.         // check if there is friendlyPassenger
  757.         virtual bool HasFriendlyPassenger(IEntity* pPlayer) = 0;
  758.  
  759.         // check if client is inside this vehicle
  760.         virtual bool IsPlayerPassenger() = 0;
  761.  
  762.         // get total number of weapon entities on vehicle
  763.         virtual int GetWeaponCount() const = 0;
  764.  
  765.         // Get EntityId by weapon index
  766.         virtual EntityId GetWeaponId(int index) const = 0;
  767.  
  768.         // get EntityId for currently used weapon for passengerId, or 0
  769.         virtual EntityId GetCurrentWeaponId(EntityId passengerId, bool secondary = false) const = 0;
  770.  
  771.         // get currently used weapon info for passengerId. Returns true if info was found.
  772.         virtual bool GetCurrentWeaponInfo(SVehicleWeaponInfo& outInfo, EntityId passengerId, bool secondary = false) const = 0;
  773.  
  774.         // Summary:
  775.         //   Indicates if an helper position is available
  776.         // Description:
  777.         //   Will find if a specified helper position exist on the vehicle.
  778.         // Parameters:
  779.         //   name - name of the helper position
  780.         virtual bool              HasHelper(const char* pName) = 0;
  781.  
  782.         virtual IVehiclePart*     GetPart(const char* name) = 0;
  783.         virtual IVehiclePart*     GetWeaponParentPart(EntityId weaponId) = 0;
  784.         virtual IVehicleSeat*     GetWeaponParentSeat(EntityId weaponId) = 0;
  785.  
  786.         virtual IVehicleMovement* GetMovement() const = 0;
  787.  
  788.         // Summary:
  789.         //   Returns the wheel count
  790.         // Description:
  791.         //   Will return the wheel count of the vehicle, if any are preset.
  792.         // Return value:
  793.         //   The wheel count, or 0 if none are available
  794.         virtual int           GetWheelCount() = 0;
  795.  
  796.         virtual IVehiclePart* GetWheelPart(int idx) = 0;
  797.  
  798.         // Summary:
  799.         //   Returns the mass
  800.         // Description:
  801.         //   Will return the mass of the vehicle.
  802.         // Return value:
  803.         //   The mass value, it should never be a negative value
  804.         virtual float GetMass() const = 0;
  805.  
  806.         // Summary:
  807.         //   Returns the altitude
  808.         // Description:
  809.         //   Will return the altitude of the vehicle.
  810.         // Return value:
  811.         //   The altitude value, it should be a positive value
  812.         virtual float                GetAltitude() = 0;
  813.  
  814.         virtual IMovementController* GetPassengerMovementController(EntityId passenger) = 0;
  815.  
  816.         // Summary
  817.         //   Sends a vehicle event to all the listeners
  818.         // Parameters
  819.         //   event - One of the event declared in EVehicleEvent
  820.         //   params - optional parameter, see EVehicleEvent to know which member of this structure needs to be filled for the specific event
  821.         // See Also
  822.         //   UnregisterVehicleEventListener
  823.         virtual void BroadcastVehicleEvent(EVehicleEvent event, const SVehicleEventParams& params) = 0;
  824.  
  825.         // Summary
  826.         //   Registers an event listener
  827.         // Parameters
  828.         //   pEvenListener - a pointer to class which implements the IVehicleEventListener interface
  829.         // See Also
  830.         //   UnregisterVehicleEventListener
  831.         virtual void RegisterVehicleEventListener(IVehicleEventListener* pEvenListener, const char* name) = 0;
  832.  
  833.         // Summary
  834.         //   Unregisters an event listener
  835.         // Parameters
  836.         //   pEvenListener - a pointer to class which implements the IVehicleEventListener interface
  837.         // See Also
  838.         //   RegisterVehicleEventListener
  839.         virtual void                        UnregisterVehicleEventListener(IVehicleEventListener* pEvenListener) = 0;
  840.  
  841.         virtual SParticleParams*            GetParticleParams() = 0;
  842.         virtual const SVehicleDamageParams& GetDamageParams() const = 0;
  843.  
  844.         uint16                              GetChannelId()
  845.         {
  846.                 return GetGameObject()->GetChannelId();
  847.         }
  848.         void SetChannelId(uint16 id)
  849.         {
  850.                 GetGameObject()->SetChannelId(id);
  851.         }
  852.  
  853.         enum EVehicleUpdateSlot
  854.         {
  855.                 eVUS_Always = 0,    // used for vehicle elements which always need to be updated
  856.                 eVUS_EnginePowered, // used for vehicle elements which should only be updated when the engine is powered
  857.                 eVUS_PassengerIn,   // used for vehicle elements which should only when a passenger has entered the vehicle
  858.                 eVUS_Visible,       // currently unused
  859.                 eVUS_AIControlled,  // used for vehicle using new flight nav
  860.  
  861.                 eVUS_Last = eVUS_AIControlled
  862.         };
  863.  
  864.         enum EVehicleObjectUpdate
  865.         {
  866.                 eVOU_NoUpdate = 0,
  867.                 eVOU_AlwaysUpdate,
  868.                 eVOU_PassengerUpdate,
  869.                 eVOU_Visible,
  870.         };
  871.  
  872.         virtual void            SetObjectUpdate(IVehicleObject* pObject, EVehicleObjectUpdate updatePolicy) = 0;
  873.  
  874.         virtual IVehicleHelper* GetHelper(const char* pName) = 0;
  875.         virtual void            Destroy() = 0;
  876.         virtual bool            IsDestroyed() const = 0;
  877.         virtual bool            IsFlipped(float maxSpeed = 0.f) = 0;
  878.         // Summary:
  879.         //   Enables/disables engine slot triggering by vehicle speed
  880.         virtual void TriggerEngineSlotBySpeed(bool trigger) = 0;
  881.  
  882.         enum EVehicleNeedsUpdateFlags
  883.         {
  884.                 eVUF_AwakePhysics = 1 << 0,
  885.         };
  886.  
  887.         // Summary:
  888.         //  Notify vehicle to that update is required
  889.         virtual void NeedsUpdate(int flags = 0, bool bThreadSafe = false) = 0;
  890.  
  891.         // Summary:
  892.         //  Register Entity Timer. If timerId == -1, timerId will be assigned
  893.         virtual int SetTimer(int timerId, int ms, IVehicleObject* pObject) = 0;
  894.  
  895.         // Summary:
  896.         //  Kill Entity Timer
  897.         virtual int KillTimer(int timerId) = 0;
  898.  
  899.         // Summary:
  900.         //  Get Actor on driver seat, or NULL
  901.         virtual IActor* GetDriver() const = 0;
  902.  
  903.         // Summary:
  904.         //      Finds a valid world position the actor could be placed at when they exit the vehicle.
  905.         //      Based on seat helpers, but does additional checks if these are all blocked.
  906.         //      NB: actor may not necessarily be a passenger (used for MP spawn trucks)
  907.         //      Returns true if a valid position was found, false otherwise.
  908.         //      extended==true -> allows two actors to exit from one seat (lining up away from the vehicle).
  909.         virtual bool GetExitPositionForActor(IActor* pActor, Vec3& pos, bool extended = false) = 0;
  910.  
  911.         // Summary:
  912.         //      Returns the physical entities attached to this vehicle, for use with physics RWI and PWI tests
  913.         virtual int GetSkipEntities(IPhysicalEntity** pSkipEnts, int nMaxSkip) = 0;
  914.  
  915.         // Summary:
  916.         //  Returns vehicle modifications as a comma separated list (with no spaces)
  917.         virtual const char* GetModification() const = 0;
  918.  
  919.         // Request a passenger to leave the vehicle and spawn at pos
  920.         virtual void ExitVehicleAtPosition(EntityId passengerId, const Vec3& pos) = 0;
  921.  
  922.         // Evacuate all passengers
  923.         virtual void EvictAllPassengers() = 0;
  924.  
  925.         // Evacuate all passengers immediately on a client without having to ask the server for permission
  926.         virtual void ClientEvictAllPassengers() = 0;
  927.  
  928.         // Evict specified passenger immediately on a client without having to ask the server for permission
  929.         virtual void ClientEvictPassenger(IActor* pActor) = 0;
  930.  
  931.         // Check that an enemy is not already using this vehicle, before entering
  932.         virtual bool IsCrewHostile(EntityId actorId) = 0;
  933.  
  934.         // Returns the name of the action map specified for this vehicle type in
  935.         //      the xml file
  936.         virtual const char* GetActionMap() const = 0;
  937.  
  938.         // Returns collision damage multiplayer
  939.         virtual float GetSelfCollisionMult(const Vec3& velocity, const Vec3& normal, int partId, EntityId colliderId) const = 0;
  940.  
  941.         // Is vehicle probably distant from the player?
  942.         virtual bool IsProbablyDistant() const = 0;
  943.  
  944.         virtual bool IsIndestructable() const = 0;
  945.         // Sound parameters structure.
  946.  
  947.         virtual void OffsetPosition(const Vec3& delta) = 0;
  948.  
  949.         // Summary:
  950.         //Used in MP for logically linking associated vehicles together when spawning
  951.         virtual EntityId GetParentEntityId() const = 0;
  952.         virtual void     SetParentEntityId(EntityId parentEntityId) = 0;
  953. };
  954.  
  955. struct SVehicleNetState
  956. {
  957.         uint data[16];
  958. };
  959.  
  960. struct SVehicleMovementAction
  961. {
  962.         SVehicleMovementAction()
  963.         {
  964.                 Clear();
  965.         };
  966.  
  967.         float power;
  968.         float rotateYaw;
  969.         float rotatePitch;
  970.         float rotateRoll;
  971.         bool  brake;
  972.         bool  isAI;
  973.  
  974.         void  Clear(bool keepPressHoldControlledVars = false)
  975.         {
  976.                 if (!keepPressHoldControlledVars)
  977.                 {
  978.                         power = 0.0f;
  979.                         brake = false;
  980.                         isAI = false;
  981.                         rotateYaw = 0.0f;
  982.                 }
  983.                 else
  984.                 {
  985.                         // only keep slight pedal (to allow rolling)
  986.                         power *= 0.1f;
  987.                 }
  988.  
  989.                 rotateRoll = 0.0f;
  990.                 rotatePitch = 0.0f;
  991.         }
  992. };
  993.  
  994. struct IVehicleMovementActionFilter
  995. {
  996.         virtual ~IVehicleMovementActionFilter(){}
  997.         virtual void OnProcessActions(SVehicleMovementAction& movementAction) = 0;
  998.         virtual void GetMemoryUsage(ICrySizer* pSizer) const = 0;
  999. };
  1000.  
  1001. // Summary:
  1002. //   Interface for vehicle movement class
  1003. // Description:
  1004. //   Interface used to implement a movement class for vehicles.
  1005. struct IVehicleMovement
  1006.         : public IMovementController
  1007. {
  1008.         enum EVehicleMovementType
  1009.         {
  1010.                 eVMT_Sea = 0,
  1011.                 eVMT_Air,
  1012.                 eVMT_Land,
  1013.                 eVMT_Amphibious,
  1014.                 eVMT_Walker,
  1015.                 eVMT_Dummy,
  1016.                 eVMT_Other
  1017.         };
  1018.  
  1019.         // Summary:
  1020.         //   Event values for the movement
  1021.         // Description:
  1022.         //   All event type possible to be sent to a movement.
  1023.         enum EVehicleMovementEvent
  1024.         {
  1025.                 // the vehicle got hit and the movement should be damaged according to the
  1026.                 // value which got passed
  1027.                 eVME_Damage = 0,
  1028.                 // the vehicle got hit and the movement steering should fail according to
  1029.                 // the value which got passed
  1030.                 eVME_DamageSteering,
  1031.                 eVME_VehicleDestroyed,
  1032.                 // Repair event. New damage ratio is passed.
  1033.                 eVME_Repair,
  1034.                 // tire destroyed
  1035.                 eVME_TireBlown,
  1036.                 // tires restored
  1037.                 eVME_TireRestored,
  1038.                 // sent when player enters/leaves seat
  1039.                 eVME_PlayerEnterLeaveSeat,
  1040.                 // sent when player enters/leaves the vehicle
  1041.                 eVME_PlayerEnterLeaveVehicle,
  1042.                 // sent when player switches view
  1043.                 eVME_PlayerSwitchView,
  1044.                 // sent on collision
  1045.                 eVME_Collision,
  1046.                 // sent on ground collision
  1047.                 eVME_GroundCollision,
  1048.                 // ?
  1049.                 eVME_WarmUpEngine,
  1050.                 // sent when vehicle toggles engine update slot
  1051.                 eVME_ToggleEngineUpdate,
  1052.                 // becoming visible
  1053.                 eVME_BecomeVisible,
  1054.                 eVME_SetMode,
  1055.                 eVME_Turbulence,
  1056.                 eVME_NW_Discharge,
  1057.                 eVME_EnableHandbrake,
  1058.                 eVME_PartDetached,
  1059.                 eVME_SetFactorMaxSpeed,
  1060.                 eVME_SetFactorAccel,
  1061.                 eVME_StoodOnChange,
  1062.                 eVME_Others,
  1063.         };
  1064.  
  1065.         // Summary:
  1066.         //   Initializes the movement
  1067.         // Description:
  1068.         //   Used to initialize a movement from a script table.
  1069.         // Parameters:
  1070.         //   pVehicle - pointer to the vehicle which will uses this movement instance
  1071.         //   table - table which hold all the movement parameters
  1072.         virtual bool Init(IVehicle* pVehicle, const CVehicleParams& table) = 0;
  1073.  
  1074.         // Summary:
  1075.         //   PostInit, e.g. for things that need full physicalization
  1076.         virtual void PostInit() = 0;
  1077.  
  1078.         // Summary:
  1079.         //       Change physicalization of the vehicle.
  1080.         virtual void Physicalize() = 0;
  1081.  
  1082.         // Summary:
  1083.         //       Post - physicalize.
  1084.         virtual void PostPhysicalize() = 0;
  1085.  
  1086.         // Summary:
  1087.         //   Resets the movement
  1088.         virtual void Reset() = 0;
  1089.  
  1090.         // Summary:
  1091.         //   Releases the movement
  1092.         virtual void Release() = 0;
  1093.  
  1094.         // Summary:
  1095.         //   Get movement type
  1096.         virtual EVehicleMovementType GetMovementType() = 0;
  1097.  
  1098.         // Summary:
  1099.         //      Resets any input previously active in the movement
  1100.         virtual void ResetInput() = 0;
  1101.  
  1102.         // Summary:
  1103.         //   Turn On the engine effects
  1104.         // Description:
  1105.         //   It will soon be replaced by an event passed with the OnEvent function.
  1106.         virtual bool StartEngine() = 0;
  1107.  
  1108.         // Summary:
  1109.         //   Turn Off the engine effects
  1110.         // Description:
  1111.         //   It will soon be replaced by an event passed with the OnEvent function.
  1112.         virtual void StopEngine() = 0;
  1113.  
  1114.         // Summary:
  1115.         //   The vehicle has started being driven.
  1116.         // Description:
  1117.         //   Called when the vehicle gets a new driver.
  1118.         virtual bool StartDriving(EntityId driverId) = 0;
  1119.  
  1120.         // Summary:
  1121.         //   The vehicle has stopped being driven.
  1122.         // Description:
  1123.         //   The vehicle is not being driven any more.
  1124.         virtual void  StopDriving() = 0;
  1125.  
  1126.         virtual bool  IsPowered() = 0;
  1127.  
  1128.         virtual float GetEnginePedal() = 0;
  1129.  
  1130.         // Summary
  1131.         //              Returns the damage ratio of the engine
  1132.         // Description
  1133.         //              Used to receive the damage ratio of the movement. The damage ratio of
  1134.         //              the movement may not reflect the damage ratio of the vehicle. The value
  1135.         //              is between 0 and 1.
  1136.         // Returns
  1137.         //              The damage ratio
  1138.         virtual float GetDamageRatio() = 0;
  1139.  
  1140.         // Summary
  1141.         //  Gets number of wheel contacts, 0 if n/a
  1142.         virtual int GetWheelContacts() const = 0;
  1143.  
  1144.         // Summary:
  1145.         //   Sends an event message to the vehicle movement
  1146.         // Description:
  1147.         //   Used by various code module of the vehicle system to notify the
  1148.         //   movement code of any appropriate change. A list of all the supported
  1149.         //   event can be found in the EVehicleMovementEvent enum.
  1150.         // Parameters:
  1151.         //   event  - event to be passed to the movement
  1152.         //   params - event parameters, e.g. damage value
  1153.         virtual void OnEvent(EVehicleMovementEvent event, const SVehicleMovementEventParams& params) = 0;
  1154.  
  1155.         virtual void OnAction(const TVehicleActionId actionId, int activationMode, float value) = 0;
  1156.  
  1157.         // Summary:
  1158.         //   Updates all physics related to the movement
  1159.         // Description:
  1160.         //   Will update the vehicle movement for a specified frame time. Unlike the
  1161.         //   Update function also present on the movement interface, this function is
  1162.         //   called from a callback function in CryPhysics rather than from
  1163.         //   IVehicle::Update. It's usually called at fixed interval and much more
  1164.         //   often than the Update function. This should only be used to update
  1165.         //   physics related attributes of the vehicle.
  1166.         // Parameters:
  1167.         //   deltaTime - time in seconds of the update
  1168.         virtual void ProcessMovement(const float deltaTime) = 0;
  1169.  
  1170.         // Summary:
  1171.         //   Enables/disables movement processing
  1172.         // Description:
  1173.         //   This allows disabling of the actual movement processing, while still
  1174.         //   have the engine running and process driver input, effects, etc.
  1175.         //   Useful for trackview sequences
  1176.         virtual void EnableMovementProcessing(bool enable) = 0;
  1177.         virtual bool IsMovementProcessingEnabled() = 0;
  1178.  
  1179.         // Summary:
  1180.         //   Enables/disables engine's ability to start
  1181.         virtual void DisableEngine(bool disable) = 0;
  1182.  
  1183.         // Summary:
  1184.         //   Updates the movement
  1185.         // Description:
  1186.         //   Will update the vehicle movement for a specified frame time. Unlike the
  1187.         //   ProcessMovement function, this function is called from the Update
  1188.         //   function of IVehicle.
  1189.         // Parameters:
  1190.         //   deltaTime - time in seconds of the update
  1191.         virtual void Update(const float deltaTime) = 0;
  1192.  
  1193.         // Summary:
  1194.         //   Allows updates by the movement system after the view has updated
  1195.         // Description:
  1196.         //   Optionally update the SViewParams structure will additional camera information
  1197.         // Parameters:
  1198.         //   viewParams - structure which is used to return the camera info
  1199.         //   playerId - entity id of the passenger
  1200.         virtual void PostUpdateView(SViewParams& viewParams, EntityId playerId) = 0;
  1201.  
  1202.         // Summary:
  1203.         //   Get a vehicle status,
  1204.         //   Can return 0 on failure as different vehicle movements will support different status information
  1205.         virtual int                    GetStatus(SVehicleMovementStatus* status) = 0;
  1206.  
  1207.         virtual void                   Serialize(TSerialize ser, EEntityAspects aspects) = 0;
  1208.         virtual void                   SetAuthority(bool auth) = 0;
  1209.         virtual void                   PostSerialize() = 0;
  1210.  
  1211.         virtual SVehicleMovementAction GetMovementActions() = 0;
  1212.         virtual void                   RequestActions(const SVehicleMovementAction& movementAction) = 0;
  1213.         virtual bool                   RequestMovement(CMovementRequest& movementRequest) = 0;
  1214.         virtual void                   GetMovementState(SMovementState& movementState) = 0;
  1215.         virtual SVehicleNetState       GetVehicleNetState() = 0;
  1216.         virtual void                   SetVehicleNetState(const SVehicleNetState& state) = 0;
  1217.  
  1218.         virtual pe_type                GetPhysicalizationType() const = 0;
  1219.         virtual bool                   UseDrivingProxy() const = 0;
  1220.  
  1221.         virtual void                   RegisterActionFilter(IVehicleMovementActionFilter* pActionFilter) = 0;
  1222.         virtual void                   UnregisterActionFilter(IVehicleMovementActionFilter* pActionFilter) = 0;
  1223.  
  1224.         virtual void                   ProcessEvent(SEntityEvent& event) = 0;
  1225.         virtual CryCriticalSection*    GetNetworkLock() = 0;
  1226.  
  1227.         virtual void                   GetMemoryUsage(ICrySizer* s) const = 0;
  1228.  
  1229.         virtual IEntityAudioComponent*     GetAudioProxy() const                      { return nullptr; }
  1230.         virtual AudioControlId         GetPrimaryWeaponAudioTrigger() const       { return INVALID_AUDIO_CONTROL_ID; }
  1231.         virtual AudioControlId         GetPrimaryWeaponAudioStopTrigger() const   { return INVALID_AUDIO_CONTROL_ID; }
  1232.         virtual AudioControlId         GetSecondaryWeaponAudioTrigger() const     { return INVALID_AUDIO_CONTROL_ID; }
  1233.         virtual AudioControlId         GetSecondaryWeaponAudioStopTrigger() const { return INVALID_AUDIO_CONTROL_ID; }
  1234. };
  1235.  
  1236. // Summary
  1237. //              Interface used to implement vehicle views
  1238. // Description
  1239. //              A vehicle view is a camera implementation. Default implementations of a
  1240. //              first person and third person camera are already available in the
  1241. //              CryAction Dll.
  1242. struct IVehicleView
  1243.         : public IVehicleObject
  1244. {
  1245.         virtual bool Init(IVehicleSeat* pSeat, const CVehicleParams& table) = 0;
  1246.         virtual void Reset() = 0;
  1247.         virtual void Release() = 0;
  1248.         virtual void ResetPosition() = 0;
  1249.  
  1250.         // Summary
  1251.         //              Returns the name of the camera view
  1252.         virtual const char* GetName() = 0;
  1253.  
  1254.         // Summary
  1255.         //              Indicates if the view implements a third person camera
  1256.         virtual bool IsThirdPerson() = 0;
  1257.  
  1258.         // Summary
  1259.         //              Indicates if the player body has been hidden
  1260.         virtual bool IsPassengerHidden() = 0;
  1261.  
  1262.         // Views defined via XML can be disabled in code, eg. per level
  1263.         virtual bool IsEnabled() const = 0;
  1264.         virtual void SetEnabled(bool enabled) = 0;
  1265.  
  1266.         // Summary
  1267.         //              Performs tasks needed when the client start using this view
  1268.         // Parameters
  1269.         //      playerId - EntityId of the player who will use the view
  1270.         virtual void OnStartUsing(EntityId playerId) = 0;
  1271.  
  1272.         // Summary
  1273.         //              Performs tasks needed when the client stop using this view
  1274.         virtual void             OnStopUsing() = 0;
  1275.  
  1276.         virtual void             OnAction(const TVehicleActionId actionId, int activationMode, float value) = 0;
  1277.         virtual void             UpdateView(SViewParams& viewParams, EntityId playerId = 0) = 0;
  1278.  
  1279.         virtual TVehicleObjectId GetId() const override = 0;
  1280.         virtual void             Serialize(TSerialize ser, EEntityAspects aspects) override = 0;
  1281.  
  1282.         // Summary
  1283.         //              Performs computation which depends of the frame rate
  1284.         virtual void Update(const float deltaTime) override = 0;
  1285.  
  1286.         virtual void SetDebugView(bool debug) = 0;
  1287.         virtual bool IsDebugView() = 0;
  1288.  
  1289.         virtual bool ShootToCrosshair() = 0;
  1290.  
  1291.         virtual bool IsAvailableRemotely() const = 0;
  1292.  
  1293.         virtual void GetMemoryUsage(ICrySizer* pSizer) const = 0;
  1294.  
  1295.         virtual void OffsetPosition(const Vec3& delta) = 0;
  1296. };
  1297.  
  1298. // Summary:
  1299. //   Seat-dependent sound parameters
  1300. struct SSeatSoundParams
  1301. {
  1302.         CCryName moodName; //name of the soundmood to apply
  1303.         float    inout;    // [0..1], 0 means fully inside
  1304.         float    mood;     // [0..1], 1 means fully active (inside!)
  1305.         float    moodCurr; // current value
  1306.  
  1307.         SSeatSoundParams()
  1308.                 : moodName("vehicle")
  1309.                 , inout(0.f)
  1310.                 , mood(0.f)
  1311.                 , moodCurr(0.f)
  1312.         {
  1313.         }
  1314.  
  1315. };
  1316.  
  1317. // Summary:
  1318. //      Seat locking
  1319. enum EVehicleSeatLockStatus
  1320. {
  1321.         eVSLS_Unlocked,
  1322.         eVSLS_LockedForPlayers,
  1323.         eVSLS_LockedForAI,
  1324.         eVSLS_Locked,
  1325. };
  1326.  
  1327. struct IVehicleSeatAction;
  1328.  
  1329. // Summary:
  1330. //   Vehicle Seat interface
  1331. struct IVehicleSeat
  1332. {
  1333.         enum EVehicleTransition
  1334.         {
  1335.                 eVT_None = 0,
  1336.                 eVT_Entering,
  1337.                 eVT_Exiting,
  1338.                 eVT_ExitingWarped,
  1339.                 eVT_Dying,
  1340.                 eVT_SeatIsBorrowed,
  1341.                 eVT_RemoteUsage,
  1342.         };
  1343.         virtual ~IVehicleSeat(){}
  1344.         virtual bool Init(IVehicle* pVehicle, TVehicleSeatId seatId, const CVehicleParams& paramsTable) = 0;
  1345.         virtual void PostInit(IVehicle* pVehicle) = 0;
  1346.         virtual void Reset() = 0;
  1347.         virtual void Release() = 0;
  1348.  
  1349.         // Summary
  1350.         //   Returns the seat name
  1351.         // Returns
  1352.         //   a string with the name
  1353.         virtual const char* GetSeatName() const = 0;
  1354.  
  1355.         // Summary
  1356.         //   Returns the id of the seat
  1357.         // Returns
  1358.         //   A seat id
  1359.         virtual TVehicleSeatId GetSeatId() const = 0;
  1360.         virtual EntityId       GetPassenger(bool remoteUser = false) const = 0;
  1361.         virtual int            GetCurrentTransition() const = 0;
  1362.  
  1363.         // Seat Views
  1364.         virtual IVehicleView*           GetView(TVehicleViewId viewId) const = 0;
  1365.         virtual bool                    SetView(TVehicleViewId viewId) = 0;
  1366.         virtual TVehicleViewId          GetCurrentViewId() const = 0;
  1367.         virtual IVehicleView*           GetCurrentView() const = 0;
  1368.         virtual TVehicleViewId          GetNextViewId(bool bExcludeDebug, bool bExcludeDisabled) const = 0;
  1369.         virtual TVehicleViewId          GetNextAvailableViewId() const = 0;
  1370.         virtual int                     GetViewCount() const = 0;
  1371.  
  1372.         virtual bool                    IsDriver() const = 0;
  1373.         virtual bool                    IsGunner() const = 0;
  1374.         virtual bool                    IsRemoteControlled() const = 0;
  1375.         virtual bool                    IsLocked(IActor* pActor) const = 0;
  1376.  
  1377.         virtual bool                    Enter(EntityId actorId, bool isTransitionEnabled = true) = 0;
  1378.         virtual bool                    Exit(bool isTransitionEnabled, bool force = false, Vec3 exitPos = ZERO) = 0;
  1379.         virtual void                    SetLocked(EVehicleSeatLockStatus status) = 0;
  1380.         virtual EVehicleSeatLockStatus  GetLockedStatus() const = 0;
  1381.  
  1382.         virtual void                    PrePhysUpdate(const float dt) = 0;
  1383.  
  1384.         virtual void                    OnPassengerDeath() = 0;
  1385.         virtual void                    UnlinkPassenger(bool ragdoll) = 0;
  1386.         virtual bool                    IsPassengerHidden() const = 0;
  1387.         virtual bool                    IsPassengerExposed() const = 0;
  1388.  
  1389.         virtual bool                    ProcessPassengerMovementRequest(const CMovementRequest& movementRequest) = 0;
  1390.  
  1391.         virtual IVehicle*               GetVehicle() const = 0;
  1392.         virtual IVehiclePart*           GetAimPart() const = 0;
  1393.         virtual IVehicleHelper*         GetSitHelper() const = 0;
  1394.         virtual IVehicleHelper*         GetAIVisionHelper() const = 0;
  1395.         virtual const SSeatSoundParams& GetSoundParams() const = 0;
  1396.  
  1397.         virtual void                    OnCameraShake(float& angleAmount, float& shiftAmount, const Vec3& pos, const char* source) const = 0;
  1398.  
  1399.         virtual void                    ForceFinishExiting() = 0;
  1400.  
  1401.         // Returns the name of the action map specified for this vehicle seat in
  1402.         //      the xml file (can be null if no specific seat actionmap)
  1403.         virtual const char*               GetActionMap() const = 0;
  1404.  
  1405.         virtual void                      ChangedNetworkState(NetworkAspectType aspects) {};
  1406.  
  1407.         virtual bool                      IsAutoAimEnabled()                             { return false; }
  1408.  
  1409.         virtual IVehicleSeatAction*       GetISeatActionWeapons() = 0;
  1410.         virtual const IVehicleSeatAction* GetISeatActionWeapons() const = 0;
  1411.  
  1412.         virtual void                      OffsetPosition(const Vec3& delta) = 0;
  1413. };
  1414.  
  1415. // Summary:
  1416. //   Vehicle Wheel interface
  1417. // Description:
  1418. //   Interface providing wheel-specific access
  1419. struct IVehicleWheel
  1420. {
  1421.         virtual ~IVehicleWheel(){}
  1422.         virtual int                     GetSlot() const = 0;
  1423.         virtual int                     GetWheelIndex() const = 0;
  1424.         virtual float                   GetTorqueScale() const = 0;
  1425.         virtual float                   GetSlipFrictionMod(float slip) const = 0;
  1426.         virtual const pe_cargeomparams* GetCarGeomParams() const = 0;
  1427. };
  1428.  
  1429. // Summary:
  1430. //   Vehicle Part interface
  1431. // Description:
  1432. //   Interface used to implement parts of a vehicle.
  1433. struct IVehiclePart
  1434.         : public IVehicleObject
  1435. {
  1436.         // Summary:
  1437.         //   Part event values
  1438.         // Description:
  1439.         //   Values used by the type variable in SVehiclePartEvent.
  1440.         enum EVehiclePartEvent
  1441.         {
  1442.                 // the part got damaged, fparam will hold the damage ratio
  1443.                 eVPE_Damaged = 0,
  1444.                 // part gets repaired, fparam also holds damage ratio
  1445.                 eVPE_Repair,
  1446.                 // currently unused
  1447.                 eVPE_Physicalize,
  1448.                 // currently unused
  1449.                 eVPE_PlayAnimation,
  1450.                 // used to notify that the part geometry got modified and would need to be
  1451.                 // reloaded next time the part is reset
  1452.                 eVPE_GotDirty,
  1453.                 // toggle hide the part, fparam specify the amount of time until the requested effect is fully completed
  1454.                 eVPE_Fade,
  1455.                 // toggle hide
  1456.                 eVPE_Hide,
  1457.                 // sent when driver entered the vehicle
  1458.                 eVPE_DriverEntered,
  1459.                 // sent when driver left
  1460.                 eVPE_DriverLeft,
  1461.                 // sent when part starts being used in turret (or similar) rotation
  1462.                 eVPE_StartUsing,
  1463.                 // sent when part starts being used in turret (or similar) rotation
  1464.                 eVPE_StopUsing,
  1465.                 // sent when rotations need to be blocked
  1466.                 eVPE_BlockRotation,
  1467.                 // sent when vehicle flips over. bParam is true when flipping, false when returning to normal orientation
  1468.                 eVPE_FlippedOver,
  1469.                 // used as a starting index for project specific part events
  1470.                 eVPE_OtherEvents,
  1471.         };
  1472.  
  1473.         enum EVehiclePartType
  1474.         {
  1475.                 eVPT_Base = 0,
  1476.                 eVPT_Animated,
  1477.                 eVPT_AnimatedJoint,
  1478.                 eVPT_Static,
  1479.                 eVPT_SubPart,
  1480.                 eVPT_Wheel,
  1481.                 eVPT_Tread,
  1482.                 eVPT_Massbox,
  1483.                 eVPT_Light,
  1484.                 eVPT_Attachment,
  1485.                 eVPT_Entity,
  1486.                 eVPT_Last,
  1487.         };
  1488.  
  1489.         enum EVehiclePartState
  1490.         {
  1491.                 eVGS_Default = 0,
  1492.                 eVGS_Damaged1,
  1493.                 eVGS_Destroyed,
  1494.                 eVGS_Last,
  1495.         };
  1496.  
  1497.         enum EVehiclePartStateFlags
  1498.         {
  1499.                 eVPSF_Physicalize = 1 << 0,
  1500.                 eVPSF_Force       = 1 << 1,
  1501.         };
  1502.  
  1503.         // Summary:
  1504.         //   Part event structure
  1505.         // Description:
  1506.         //   This structure is used by the OnEvent function to pass message to
  1507.         //   vehicle parts.
  1508.         struct SVehiclePartEvent
  1509.         {
  1510.                 // message type value, usually defined in EVehiclePartEvent
  1511.                 EVehiclePartEvent type;
  1512.                 // c string parameter (optional)
  1513.                 const char*       sparam;
  1514.                 // float parameter (optional)
  1515.                 float             fparam;
  1516.                 bool              bparam;
  1517.                 void*             pData;
  1518.  
  1519.                 SVehiclePartEvent()
  1520.                 {
  1521.                         sparam = 0;
  1522.                         fparam = 0.f;
  1523.                         bparam = false;
  1524.                         pData = NULL;
  1525.                         type = eVPE_Damaged;
  1526.                 }
  1527.         };
  1528.  
  1529.         // Summary:
  1530.         //   Initializes the vehicle part
  1531.         // Description:
  1532.         //   Will initialize a newly allocated instance of the vehicle part class
  1533.         //   according to the parameter table which is passed. This function should only be called once.
  1534.         // Parameters:
  1535.         //   pVehicle - pointer to the vehicle instance which will own this part
  1536.         //   table - script table which hold all the part parameters
  1537.         //   pParent - pointer to a parent part, or NULL if there isn't any parent
  1538.         //             part specified
  1539.         // Return value:
  1540.         //   A boolean which indicate if the function succeeded
  1541.         //virtual bool Init(IVehicle* pVehicle, const SmartScriptTable &table, IVehiclePart* pParent = NULL) = 0;
  1542.  
  1543.         virtual void PostInit() = 0;
  1544.  
  1545.         virtual void PostSerialize() = 0;
  1546.  
  1547.         // Summary:
  1548.         //   Resets the vehicle part
  1549.         // Description:
  1550.         //   Used to reset a vehicle part to its initial state. Is usually being
  1551.         //   called when the Editor enter and exit the game mode.
  1552.         virtual void Reset() = 0;
  1553.  
  1554.         // Summary:
  1555.         //   Releases the vehicle part
  1556.         // Description:
  1557.         //   Used to release a vehicle part. A vehicle part implementation should
  1558.         //   then deallocate any memory or object that it dynamically allocated.
  1559.         //   In addition, the part implementation or its base class should include
  1560.         //   "delete this;".
  1561.         virtual void Release() = 0;
  1562.  
  1563.         virtual void GetMemoryUsage(ICrySizer* pSizer) const = 0;
  1564.  
  1565.         // Summary
  1566.         //   Retrieves a pointer of the parent part
  1567.         // Return Value
  1568.         //   A pointer to the parent part, or NULL if there isn't any.
  1569.         virtual IVehiclePart* GetParent(bool root = false) = 0;
  1570.  
  1571.         // Summary
  1572.         //   Retrieves the name of the part
  1573.         virtual const char* GetName() = 0;
  1574.  
  1575.         // Summary
  1576.         //   Retrieves the entity which hold the vehicle part
  1577.         // Description
  1578.         //   In most of the cases, the entity holding the vehicle part will be the vehicle entity itself.
  1579.         virtual IEntity* GetEntity() = 0;
  1580.  
  1581.         // Summary:
  1582.         //   Sends an event message to the vehicle part
  1583.         // Description:
  1584.         //   Used to send different events to the vehicle part implementation. The
  1585.         //   EVehiclePartEvent enum lists several usual vehicle part events.
  1586.         // Parameters:
  1587.         //   event - event to be passed to the part
  1588.         virtual void OnEvent(const SVehiclePartEvent& event) = 0;
  1589.  
  1590.         // Summary:
  1591.         //   Loads the geometry/character needed by the vehicle part
  1592.         virtual bool ChangeState(EVehiclePartState state, int flags = 0) = 0;
  1593.  
  1594.         // Summary:
  1595.         //   Query the current state of the vehicle part
  1596.         virtual EVehiclePartState GetState() const = 0;
  1597.  
  1598.         // Summary:
  1599.         //   Sets material on the part
  1600.         virtual void SetMaterial(IMaterial* pMaterial) = 0;
  1601.  
  1602.         // Summary:
  1603.         //   Query the current state of the vehicle part
  1604.         // Description:
  1605.         //   Obsolete. Will be changed soon in favor of an event passed by OnEvent.
  1606.         virtual void Physicalize() = 0;
  1607.  
  1608.         // Summary:
  1609.         //   Gets final local transform matrix
  1610.         // Description:
  1611.         //   Will return the FINAL local transform matrix (with recoil etc) relative to parent part or vehicle space
  1612.         // Return value:
  1613.         //   a 3x4 matrix
  1614.         virtual const Matrix34& GetLocalTM(bool relativeToParentPart, bool forced = false) = 0;
  1615.  
  1616.         // Summary:
  1617.         //   Gets the local base transform matrix
  1618.         // Description:
  1619.         //   Will return the local BASE transform matrix (without recoil etc) relative to parent part
  1620.         virtual const Matrix34& GetLocalBaseTM() = 0;
  1621.  
  1622.         // Summary:
  1623.         //   Gets the initial base transform matrix
  1624.         // Description:
  1625.         //   Will return the local transform matrix from the initial state of the model as relative to parent part
  1626.         virtual const Matrix34& GetLocalInitialTM() = 0;
  1627.  
  1628.         // Summary:
  1629.         //   Gets a world transform matrix
  1630.         // Description:
  1631.         //   Will return a transform matrix world space.
  1632.         // Return value:
  1633.         //   a 3x4 matrix
  1634.         virtual const Matrix34& GetWorldTM() = 0;
  1635.  
  1636.         // Summary:
  1637.         //   Sets local transformation matrix relative to parent part
  1638.         // Description:
  1639.         //   This sets the FINAL local tm only. Usually you'll want to use SetLocalBaseTM
  1640.         virtual void SetLocalTM(const Matrix34& localTM) = 0;
  1641.  
  1642.         // Summary:
  1643.         //   Sets local base transformation matrix relative to parent part
  1644.         // Description:
  1645.         //   This sets the local base tm.
  1646.         virtual void SetLocalBaseTM(const Matrix34& localTM) = 0;
  1647.  
  1648.         // Summary:
  1649.         //   Gets a local bounding box
  1650.         // Description:
  1651.         //   Will return a local transform matrix relative to the vehicle space.
  1652.         // Return value:
  1653.         //   a 3x4 matrix
  1654.         virtual const AABB& GetLocalBounds() = 0;
  1655.  
  1656.         // Summary:
  1657.         //   Obsolete function
  1658.         // Description:
  1659.         //   Obsolete. Will be changed soon.
  1660.         virtual void RegisterSerializer(IGameObjectExtension* pGameObjectExt) = 0;
  1661.  
  1662.         // Summary:
  1663.         //   Retrieve type id
  1664.         virtual int GetType() = 0;
  1665.  
  1666.         // Summary:
  1667.         //   Retrieve IVehicleWheel interface, or NULL
  1668.         virtual IVehicleWheel* GetIWheel() = 0;
  1669.  
  1670.         // Summary:
  1671.         //   Add part to child list
  1672.         // Description:
  1673.         //   Used for part implementations that needs to keep track of their children
  1674.         virtual void AddChildPart(IVehiclePart* pPart) = 0;
  1675.  
  1676.         // Summary:
  1677.         //   Invalidate local transformation matrix
  1678.         virtual void InvalidateTM(bool invalidate) = 0;
  1679.  
  1680.         // Summary:
  1681.         //   Sets part as being moveable and/or rotateable
  1682.         virtual void             SetMoveable(bool allowTranslationMovement = false) = 0;
  1683.  
  1684.         virtual const Vec3&      GetDetachBaseForce() = 0;
  1685.         virtual float            GetMass() = 0;
  1686.         virtual int              GetPhysId() = 0;
  1687.         virtual int              GetSlot() = 0;
  1688.  
  1689.         virtual int              GetIndex() const = 0;
  1690.  
  1691.         virtual TVehicleObjectId GetId() const override = 0;
  1692.         virtual void             Update(const float deltaTime) override = 0;
  1693.         virtual void             Serialize(TSerialize ser, EEntityAspects aspects) override = 0;
  1694. };
  1695.  
  1696. // Summary:
  1697. //   Damage behavior events
  1698. // Description:
  1699. //   Values used by the OnDamageEvent function
  1700. enum EVehicleDamageBehaviorEvent
  1701. {
  1702.         // Used to transmit the hit values that the vehicle component took
  1703.         eVDBE_Hit = 0,
  1704.         // repair event
  1705.         eVDBE_Repair,
  1706.         // Sent once when max damage ratio is exceeded
  1707.         eVDBE_MaxRatioExceeded,
  1708.         // Obsolete, eVDBE_Hit should be used instead
  1709.         eVDBE_ComponentDestroyed,
  1710.         // Obsolete, eVDBE_Hit should be used instead
  1711.         eVDBE_VehicleDestroyed,
  1712. };
  1713.  
  1714. // Summary
  1715. //   Interface used to define different areas
  1716. // Description
  1717. //    The most important use for the vehicle components is to define different
  1718. //    region on the vehicle which have specific uses. A good example would be
  1719. //    to have components on the vehicles which react to hit damage in different
  1720. //    ways.
  1721. struct IVehicleComponent
  1722. {
  1723.         virtual ~IVehicleComponent(){}
  1724.         // Summary
  1725.         //   Gets the name of the component
  1726.         // Returns
  1727.         //   A c style string with the name of the component.
  1728.         virtual const char* GetComponentName() const = 0;
  1729.  
  1730.         // Summary
  1731.         //   Gets the number of vehicle parts which are linked to the vehicle
  1732.         // Returns
  1733.         //   The number of parts
  1734.         // See Also
  1735.         //   GetPart
  1736.         virtual unsigned int  GetPartCount() const = 0;
  1737.  
  1738.         virtual IVehiclePart* GetPart(unsigned int index) const = 0;
  1739.  
  1740.         // Summary:
  1741.         //    Get bounding box in vehicle space
  1742.         virtual const AABB& GetBounds() = 0;
  1743.  
  1744.         // Summary:
  1745.         //  Get current damage ratio
  1746.         virtual float GetDamageRatio() const = 0;
  1747.  
  1748.         // Summary:
  1749.         //      Set current damage ratio
  1750.         virtual void SetDamageRatio(float ratio) = 0;
  1751.  
  1752.         // Summary:
  1753.         //  Get max damage
  1754.         virtual float GetMaxDamage() const = 0;
  1755.  
  1756.         virtual void  GetMemoryUsage(ICrySizer* s) const = 0;
  1757. };
  1758.  
  1759. // Summary
  1760. //   Handles animations on the vehicle
  1761. struct IVehicleAnimationComponent
  1762. {
  1763.         enum EPriority
  1764.         {
  1765.                 ePriority_SeatDefault = 1,
  1766.                 ePriority_SeatTransition,
  1767.         };
  1768.  
  1769.         virtual ~IVehicleAnimationComponent(){}
  1770.  
  1771.         virtual IActionController* GetActionController() = 0;
  1772.         virtual CTagState*         GetTagState() = 0;
  1773.         virtual bool               IsEnabled() const = 0;
  1774. };
  1775.  
  1776. struct SVehicleDamageBehaviorEventParams
  1777. {
  1778.         EntityId           shooterId;
  1779.         Vec3               localPos;
  1780.         float              radius;
  1781.         float              hitValue;
  1782.         int                hitType;
  1783.         float              componentDamageRatio;
  1784.         float              randomness;
  1785.         IVehicleComponent* pVehicleComponent;
  1786.  
  1787.         SVehicleDamageBehaviorEventParams()
  1788.         {
  1789.                 shooterId = 0;
  1790.                 localPos.zero();
  1791.                 radius = 0.f;
  1792.                 hitValue = 0.f;
  1793.                 hitType = 0;
  1794.                 componentDamageRatio = 0.f;
  1795.                 randomness = 0.f;
  1796.                 pVehicleComponent = 0;
  1797.         }
  1798.  
  1799.         void Serialize(TSerialize ser, IVehicle* pVehicle)
  1800.         {
  1801.                 ser.Value("shooterId", shooterId);
  1802.                 ser.Value("localPos", localPos);
  1803.                 ser.Value("radius", radius);
  1804.                 ser.Value("hitValue", hitValue);
  1805.                 ser.Value("componentDamageRatio", componentDamageRatio);
  1806.                 ser.Value("randomness", randomness);
  1807.                 string name;
  1808.                 if (ser.IsWriting())
  1809.                         name = pVehicleComponent->GetComponentName();
  1810.                 ser.Value("componentName", name);
  1811.                 if (ser.IsReading())
  1812.                         pVehicleComponent = pVehicle->GetComponent(name.c_str());
  1813.         }
  1814. };
  1815.  
  1816. // Summary:
  1817. //   Vehicle Damage Behavior interface
  1818. // Description:
  1819. //   Interface used to implement a damage behavior for vehicles.
  1820. struct IVehicleDamageBehavior
  1821.         : public IVehicleObject
  1822. {
  1823.         // Summary:
  1824.         //   Initializes the damage behavior
  1825.         // Description:
  1826.         //   Will initialize a newly allocated instance of the damage behavior class
  1827.         //   according to the parameter table which is passed. This function should
  1828.         //   only be called once.
  1829.         // Parameters:
  1830.         //   pVehicle - pointer to the vehicle instance for which will own this
  1831.         //              damage behavior
  1832.         //   table - script table which hold all the parameters
  1833.         // Return value:
  1834.         //   A boolean which indicate if the function succeeded
  1835.         virtual bool Init(IVehicle* pVehicle, const CVehicleParams& table) = 0;
  1836.  
  1837.         // Summary:
  1838.         //   Resets the damage behavior
  1839.         // Description:
  1840.         //   Used to reset a damage behavior to its initial state. Is usually being
  1841.         //   called when the Editor enter and exit the game mode.
  1842.         virtual void Reset() = 0;
  1843.  
  1844.         // Summary:
  1845.         //   Releases the damage behavior
  1846.         // Description:
  1847.         //   Used to release a damage behavior, usually at the same time than the
  1848.         //   vehicle is being released. A damage behavior implementation should
  1849.         //   then deallocate any memory or object that it dynamically allocated.
  1850.         //   In addition, the part implementation or its base class should include
  1851.         //   "delete this;".
  1852.         virtual void             Release() = 0;
  1853.  
  1854.         virtual void             GetMemoryUsage(ICrySizer* pSizer) const = 0;
  1855.         virtual TVehicleObjectId GetId() const override = 0;
  1856.         virtual void             Serialize(TSerialize ser, EEntityAspects aspects) override = 0;
  1857.         virtual void             Update(const float deltaTime) override = 0;
  1858.  
  1859.         // Summary:
  1860.         //   Sends an event message to the damage behavior
  1861.         // Description:
  1862.         //   Used to send different events to the damage behavior implementation.
  1863.         //   The EVehicleDamageBehaviorEvent enum lists all the event which a damage
  1864.         //   behavior can receive.
  1865.         // Parameters:
  1866.         //   event - event type
  1867.         //   value - a float value used for the event
  1868.         virtual void OnDamageEvent(EVehicleDamageBehaviorEvent event, const SVehicleDamageBehaviorEventParams& params) = 0;
  1869. };
  1870.  
  1871. // Summary
  1872. //   Interface used to implement interactive elements for the player passenger
  1873. // Description
  1874. //   The tank turret, headlights, vehicle weapons and steering wheels are all
  1875. //   examples of vehicle seat actions.
  1876. struct IVehicleSeatAction
  1877.         : public IVehicleObject
  1878. {
  1879.         virtual bool             Init(IVehicle* pVehicle, IVehicleSeat* pSeat, const CVehicleParams& table) = 0;
  1880.         virtual void             OnSpawnComplete() {}
  1881.         virtual void             Reset() = 0;
  1882.         virtual void             Release() = 0;
  1883.  
  1884.         virtual void             StartUsing(EntityId passengerId) = 0;
  1885.         virtual void             ForceUsage() = 0;
  1886.         virtual void             StopUsing() = 0;
  1887.         virtual void             OnAction(const TVehicleActionId actionId, int activationMode, float value) = 0;
  1888.  
  1889.         virtual void             PrePhysUpdate(const float dt) {}
  1890.  
  1891.         virtual void             GetMemoryUsage(ICrySizer* pSizer) const = 0;
  1892.         // IVehicleObject
  1893.         virtual TVehicleObjectId GetId() const override = 0;
  1894.         virtual void             Serialize(TSerialize ser, EEntityAspects aspects) override = 0;
  1895.         virtual void             PostSerialize() = 0;
  1896.         virtual void             Update(const float deltaTime) override = 0;
  1897.         // ~IVehicleObject
  1898.  
  1899.         virtual const char* GetName() const { return m_name.c_str(); }
  1900.  
  1901.         string m_name;
  1902. };
  1903.  
  1904. // Summary
  1905. //   Handles animations on the vehicle model
  1906. struct IVehicleAnimation
  1907. {
  1908.         virtual ~IVehicleAnimation(){}
  1909.         virtual bool Init(IVehicle* pVehicle, const CVehicleParams& table) = 0;
  1910.         virtual void Reset() = 0;
  1911.         virtual void Release() = 0;
  1912.  
  1913.         // Summary
  1914.         //   Triggers the animation to start
  1915.         // Returns
  1916.         //   A bool which indicates the success
  1917.         virtual bool StartAnimation() = 0;
  1918.  
  1919.         // Summary
  1920.         //   Triggers the animation to stop
  1921.         virtual void StopAnimation() = 0;
  1922.  
  1923.         // Summary
  1924.         //   Performs a change of state
  1925.         // Parameters
  1926.         //   stateId - An id of the state
  1927.         // Remarks
  1928.         //   The function GetStateId can return an appropriate stateId which can be
  1929.         //   used as parameter for this function.
  1930.         // Returns
  1931.         //   A bool which indicates if the state could be used
  1932.         // See Also
  1933.         //   GetState
  1934.         virtual bool ChangeState(TVehicleAnimStateId stateId) = 0;
  1935.  
  1936.         // Summary
  1937.         //   Returns the current animation state
  1938.         // Returns
  1939.         //   A stateId of the current animation state in use
  1940.         // See Also
  1941.         //   ChangeState
  1942.         virtual TVehicleAnimStateId GetState() = 0;
  1943.  
  1944.         virtual string              GetStateName(TVehicleAnimStateId stateId) = 0;
  1945.         virtual TVehicleAnimStateId GetStateId(const string& name) = 0;
  1946.  
  1947.         // Summary
  1948.         //   Changes the speed of the animation
  1949.         // Parameters
  1950.         //   speed - a value between 0 to 1
  1951.         virtual void SetSpeed(float speed) = 0;
  1952.  
  1953.         // Summary
  1954.         //   Returns the current time in the animation
  1955.         // Returns
  1956.         //   a value usually between 0 to 1
  1957.         virtual float GetAnimTime(bool raw = false) = 0;
  1958.  
  1959.         virtual void  ToggleManualUpdate(bool isEnabled) = 0;
  1960.         virtual bool  IsUsingManualUpdates() = 0;
  1961.  
  1962.         virtual void  SetTime(float time, bool force = false) = 0;
  1963.  
  1964.         virtual void  GetMemoryUsage(ICrySizer* pSizer) const = 0;
  1965. };
  1966.  
  1967. struct IVehicleDamagesGroup
  1968. {
  1969.         virtual ~IVehicleDamagesGroup(){}
  1970.         virtual bool ParseDamagesGroup(const CVehicleParams& table) = 0;
  1971. };
  1972.  
  1973. struct IVehicleDamagesTemplateRegistry
  1974. {
  1975.         virtual ~IVehicleDamagesTemplateRegistry(){}
  1976.         virtual bool Init(const string& damagesTemplatesPath) = 0;
  1977.         virtual void Release() = 0;
  1978.  
  1979.         virtual bool RegisterTemplates(const string& filename) = 0;
  1980.         virtual bool UseTemplate(const string& templateName, IVehicleDamagesGroup* pDamagesGroup) = 0;
  1981. };
  1982.  
  1983. struct IVehicleIterator
  1984. {
  1985.         virtual ~IVehicleIterator(){}
  1986.         virtual size_t    Count() = 0;
  1987.         virtual IVehicle* Next() = 0;
  1988.         virtual void      AddRef() = 0;
  1989.         virtual void      Release() = 0;
  1990. };
  1991. typedef _smart_ptr<IVehicleIterator> IVehicleIteratorPtr;
  1992.  
  1993. // Summary:
  1994. //   Vehicle System interface
  1995. // Description:
  1996. //   Interface used to implement the vehicle system.
  1997. struct IVehicleSystem
  1998. {
  1999.         DECLARE_GAMEOBJECT_FACTORY(IVehicleMovement);
  2000.         DECLARE_GAMEOBJECT_FACTORY(IVehicleView);
  2001.         DECLARE_GAMEOBJECT_FACTORY(IVehiclePart);
  2002.         DECLARE_GAMEOBJECT_FACTORY(IVehicleDamageBehavior);
  2003.         DECLARE_GAMEOBJECT_FACTORY(IVehicleSeatAction);
  2004.         DECLARE_GAMEOBJECT_FACTORY(IVehicleAction);
  2005.  
  2006.         virtual ~IVehicleSystem(){}
  2007.         virtual bool Init() = 0;
  2008.         virtual void Release() = 0;
  2009.         virtual void Reset() = 0;
  2010.  
  2011.         // Summary
  2012.         //   Performs the registration of all the different vehicle classes
  2013.         // Description
  2014.         //   The vehicle system will read all the xml files which are inside the
  2015.         //   directory "Scripts/Entities/Vehicles/Implementations/Xml/". All the
  2016.         //   valid vehicle classes will be registered as game object extension with
  2017.         //   IGameObjectSystem.
  2018.         //
  2019.         //   Several default vehicle parts, views, actions and
  2020.         //   damage behaviors classes are registered in this function as well.
  2021.         // Parameters
  2022.         //   pGameFramework - A pointer to the game framework
  2023.         virtual void RegisterVehicles(IGameFramework* pGameFramework) = 0;
  2024.  
  2025.         // Summary:
  2026.         //   Spawns a new vehicle instance
  2027.         // Description:
  2028.         //   Will spawn an entity based on the vehicle class requested. Usually
  2029.         //   called by the entity system when a vehicle entity is spawned.
  2030.         // Arguments:
  2031.         //   channelId - Id of the intented channel
  2032.         //   name - Name of the new vehicle instance to be spawned
  2033.         //   vehicleClass - Name of the vehicle class requested
  2034.         //   pos - Position of the new vehicle instance
  2035.         //   rot - Rotation of the new vehicle instance
  2036.         //   scale - Scale factor of the new vehicle instance
  2037.         //   id - Unused
  2038.         // Returns:
  2039.         //   A pointer to the correct vehicle proxy. The value 0 is returned in case
  2040.         //   that the specified vehicle couldn't be created.
  2041.         virtual IVehicle* CreateVehicle(uint16 channelId, const char* name, const char* vehicleClass, const Vec3& pos, const Quat& rot, const Vec3& scale, EntityId id = 0) = 0;
  2042.  
  2043.         // Summary:
  2044.         //   Gets the Vehicle proxy of an entity
  2045.         // Description:
  2046.         //   Will return the correct vehicle proxy of a vehicle entity.
  2047.         // Returns:
  2048.         //   A pointer to the correct vehicle proxy. The value 0 is returned in case
  2049.         //   that the proxy wasn't found.
  2050.         virtual IVehicle*                        GetVehicle(EntityId entityId) = 0;
  2051.  
  2052.         virtual IVehicle*                        GetVehicleByChannelId(uint16 channelId) = 0;
  2053.  
  2054.         virtual bool                             IsVehicleClass(const char* name) const = 0;
  2055.  
  2056.         virtual IVehicleMovement*                CreateVehicleMovement(const string& name) = 0;
  2057.         virtual IVehicleView*                    CreateVehicleView(const string& name) = 0;
  2058.         virtual IVehiclePart*                    CreateVehiclePart(const string& name) = 0;
  2059.         virtual IVehicleDamageBehavior*          CreateVehicleDamageBehavior(const string& name) = 0;
  2060.         virtual IVehicleSeatAction*              CreateVehicleSeatAction(const string& name) = 0;
  2061.         virtual IVehicleAction*                  CreateVehicleAction(const string& name) = 0;
  2062.  
  2063.         virtual IVehicleDamagesTemplateRegistry* GetDamagesTemplateRegistry() = 0;
  2064.  
  2065.         virtual void                             GetVehicleImplementations(SVehicleImpls& impls) = 0;
  2066.         virtual bool                             GetOptionalScript(const char* vehicleName, char* buf, size_t len) = 0;
  2067.  
  2068.         // Summary
  2069.         //   Registers a newly spawned vehicle in the vehicle system
  2070.         virtual void AddVehicle(EntityId entityId, IVehicle* pProxy) = 0;
  2071.  
  2072.         // Summary
  2073.         //   Registers a newly removed vehicle in the vehicle system
  2074.         virtual void             RemoveVehicle(EntityId entityId) = 0;
  2075.  
  2076.         virtual TVehicleObjectId AssignVehicleObjectId() = 0;
  2077.         virtual TVehicleObjectId AssignVehicleObjectId(const string& className) = 0;
  2078.         virtual TVehicleObjectId GetVehicleObjectId(const string& className) const = 0;
  2079.  
  2080.         // Summary
  2081.         //   Used to get the count of all vehicle instance
  2082.         // Returns
  2083.         //   The count of all the vehicle instance created by the vehicle system
  2084.         virtual uint32              GetVehicleCount() = 0;
  2085.         virtual IVehicleIteratorPtr CreateVehicleIterator() = 0;
  2086.  
  2087.         // Summary
  2088.         //   Returns the vehicle client class implementation
  2089.         // Returns
  2090.         //   A pointer to the current vehicle client implementation, or null
  2091.         //   if none as been registrated
  2092.         // See Also
  2093.         //   RegisterVehicleClient
  2094.         virtual IVehicleClient* GetVehicleClient() = 0;
  2095.  
  2096.         // Summary
  2097.         //   Performs the registration of vehicle client implementation
  2098.         // Parameters
  2099.         //   pVehicleClient - a pointer to the vehicle client implementation
  2100.         // Notes
  2101.         //   Only one vehicle client implementation can be registrated
  2102.         // See Also
  2103.         //   GetVehicleClient
  2104.         virtual void RegisterVehicleClient(IVehicleClient* pVehicleClient) = 0;
  2105.  
  2106.         // Summary
  2107.         //   Performs the registration of a class which wants to know when a specific player starts to use a vehicle
  2108.         // Parameters
  2109.         //   playerId  - the entity id of the player to listen for.
  2110.         //   pListener - a pointer to a listener object.
  2111.         // See Also
  2112.         //   IVehicle::RegisterVehicleEventListener()
  2113.         virtual void RegisterVehicleUsageEventListener(const EntityId playerId, IVehicleUsageEventListener* pEventListener) = 0;
  2114.  
  2115.         // Summary
  2116.         //   Unregisters class listening to the current player's vehicle.
  2117.         // Parameters
  2118.         //   playerId  - the entity id of the player that the listener is registered for.
  2119.         //   pListener - the pointer to be removed from the list of callbacks.
  2120.         // See Also
  2121.         //   IVehicle::RegisterVehicleEventListener()
  2122.         virtual void UnregisterVehicleUsageEventListener(const EntityId playerId, IVehicleUsageEventListener* pEventListener) = 0;
  2123.  
  2124.         // Summary
  2125.         //   Announces OnUse events for vehicles.
  2126.         // Parameters
  2127.         //   eventID   - One of the events declared in EVehicleEvent, currently only eVE_PassengerEnter and eVE_PassengerExit
  2128.         //   playerId  - the entity id of the player that the listener is registered for.
  2129.         //   pVehicle  - the vehicle which the player is interacting.
  2130.         // See Also
  2131.         //   RegisterVehicleUsageEventListener
  2132.         //   UnregisterVehicleEventListener
  2133.         virtual void BroadcastVehicleUsageEvent(const EVehicleEvent eventId, const EntityId playerId, IVehicle* pVehicle) = 0;
  2134.  
  2135.         virtual void Update(float deltaTime) = 0;
  2136. };
  2137.  
  2138. enum EVehicleDebugDraw
  2139. {
  2140.         eVDB_General       = 1,
  2141.         eVDB_Particles     = 2,
  2142.         eVDB_Parts         = 3,
  2143.         eVDB_View          = 4,
  2144.         eVDB_Sounds        = 5,
  2145.         eVDB_PhysParts     = 6,
  2146.         eVDB_PhysPartsExt  = 7,
  2147.         eVDB_Damage        = 8,
  2148.         eVDB_ClientPredict = 9,
  2149.         eVDB_Veed          = 10,
  2150. };
  2151.  
  2152. // Summary
  2153. //   Defines a position on a vehicle
  2154. // Description
  2155. //   The vehicle helper object is used to define a position on a vehicle.
  2156. //   Several components of the vehicle system use this object type to define
  2157. //   position on the vehicle (ie: seat position, firing position on vehicle
  2158. //   weapons). The Matrices are updated to reflect any changes in the position
  2159. //   or orientation parent part.
  2160. struct IVehicleHelper
  2161. {
  2162.         virtual ~IVehicleHelper(){}
  2163.         // Summary
  2164.         //   Releases the VehicleHelper instance
  2165.         // Notes
  2166.         //   Should usually be only used by the implementation of IVehicle
  2167.         virtual void Release() = 0;
  2168.  
  2169.         // Summary
  2170.         //   Returns the helper matrix in local space
  2171.         // Returns
  2172.         //   The Matrix34 holding the local space matrix
  2173.         // Notes
  2174.         //   The matrix is relative to the parent part
  2175.         // See Also
  2176.         //   GetParentPart, GetVehicleTM, GetWorldTM
  2177.         virtual const Matrix34& GetLocalTM() const = 0;
  2178.  
  2179.         // Summary
  2180.         //   Returns the helper matrix in vehicle space
  2181.         // Returns
  2182.         //   The Matrix34 holding the vehicle space matrix
  2183.         // See Also
  2184.         //   GetLocalTM, GetWorldTM
  2185.         virtual void GetVehicleTM(Matrix34& vehicleTM, bool forced = false) const = 0;
  2186.  
  2187.         // Summary
  2188.         //   Returns the helper matrix in world space
  2189.         // Returns
  2190.         //   The Matrix34 holding the world space matrix
  2191.         // See Also
  2192.         //   GetLocalTM, GetVehicleTM, GetReflectedWorldTM
  2193.         virtual void GetWorldTM(Matrix34& worldTM) const = 0;
  2194.  
  2195.         // Summary
  2196.         //      Returns the helper matrix in world space after reflecting the
  2197.         //      local translation across the yz plane (for left/right side of vehicle)
  2198.         // Returns
  2199.         //      The Matrix34 holding the world space matrix
  2200.         // See Also
  2201.         //      GetLocalTM, GetVehicleTM, GetWorldTM
  2202.         virtual void GetReflectedWorldTM(Matrix34& reflectedWorldTM) const = 0;
  2203.  
  2204.         // Summary
  2205.         //      Returns the helper translation in local space
  2206.         // Notes
  2207.         //   The matrix is relative to the parent part
  2208.         virtual Vec3 GetLocalSpaceTranslation() const = 0;
  2209.  
  2210.         // Summary
  2211.         //      Returns the helper translation in vehicle space
  2212.         virtual Vec3 GetVehicleSpaceTranslation() const = 0;
  2213.  
  2214.         // Summary
  2215.         //      Returns the helper translation in world space
  2216.         virtual Vec3 GetWorldSpaceTranslation() const = 0;
  2217.  
  2218.         // Summary
  2219.         //   Returns the parent part of the helper
  2220.         // Returns
  2221.         //   A pointer to the parent part, which is never null
  2222.         virtual IVehiclePart* GetParentPart() const = 0;
  2223.  
  2224.         // tmp(will be pure virtual soon)
  2225.         virtual void GetMemoryUsage(ICrySizer* pSizer) const = 0;
  2226. };
  2227.  
  2228. // Summary
  2229. //   Handles game specific client/player tasks
  2230. // Description
  2231. //   The implementation of the vehicle client class is used to perform
  2232. //   game specific tasks related to the client player. For example,
  2233. //   it can be used to store the last view used by the player on specific
  2234. //   vehicle class or to filter game specific action types into vehicle
  2235. //   ActionIds.
  2236. // Remarks
  2237. //   Should be implemented inside the Game DLL. The game should call the
  2238. //   function IVehicleSystem::RegisterVehicleClient during intialization.
  2239. struct IVehicleClient
  2240. {
  2241.         virtual ~IVehicleClient(){}
  2242.         // Summary
  2243.         //   Initializes the vehicle client implementation
  2244.         // Returns
  2245.         //   A bool representing the success of the initialization
  2246.         virtual bool Init() = 0;
  2247.  
  2248.         virtual void Reset() = 0;
  2249.  
  2250.         // Summary
  2251.         //   Releases the vehicle client implementation
  2252.         // Note
  2253.         //   Should only be called when the game is shutdown
  2254.         virtual void Release() = 0;
  2255.  
  2256.         // Summary
  2257.         //   Filters client actions
  2258.         // Parameter
  2259.         //   pVehicle - vehicle instance used by the client
  2260.         //   actionId - ActionId sent
  2261.         //   activationMode - One of the different activation mode defined in EActionActivationMode
  2262.         //   value - value of the action
  2263.         virtual void OnAction(IVehicle* pVehicle, EntityId actorId, const ActionId& actionId, int activationMode, float value) = 0;
  2264.  
  2265.         // Summary
  2266.         //   Perform game specific tasks when the client enter a vehicle seat
  2267.         // Parameters
  2268.         //   pSeat - instance of the new vehicle seat assigned to the client
  2269.         // Note
  2270.         //   Is also called when the client switch to a different seats inside the
  2271.         //   same vehicle
  2272.         virtual void OnEnterVehicleSeat(IVehicleSeat* pSeat) = 0;
  2273.  
  2274.         // Summary
  2275.         //   Perform game specific tasks when the client exit a vehicle seat
  2276.         // Parameters
  2277.         //   pSeat - instance of the new vehicle seat exited by the client
  2278.         // Note
  2279.         //   Is also called when the client switch to a different seats inside the
  2280.         //   same vehicle
  2281.         virtual void OnExitVehicleSeat(IVehicleSeat* pSeat) = 0;
  2282. };
  2283.  
downloadIVehicleSystem.h Source code - Download CRYENGINE Source code
Related Source Codes/Software:
postal - 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top