BVB Source Codes

CRYENGINE Show VehicleComponent.h Source code

Return Download CRYENGINE: download VehicleComponent.h Source code - Download CRYENGINE Source code - Type:.h
  1. // Copyright 2001-2016 Crytek GmbH / Crytek Group. All rights reserved.
  2.  
  3. /*************************************************************************
  4.    -------------------------------------------------------------------------
  5.    $Id$
  6.    $DateTime$
  7.    Description: Implements a standard class for a vehicle component
  8.  
  9.    -------------------------------------------------------------------------
  10.    History:
  11.    - 12:10:2005: Created by Mathieu Pinard
  12.  
  13. *************************************************************************/
  14. #ifndef __VEHICLECOMPONENT_H__
  15. #define __VEHICLECOMPONENT_H__
  16.  
  17. #include "Vehicle.h"
  18. #include "VehicleDamages.h"
  19. #include "ISharedParamsManager.h"
  20. #include "SharedParams/ISharedParams.h"
  21.  
  22. class CVehicleHUDElement;
  23. class CVehicle;
  24. struct IVehiclePart;
  25.  
  26. #define COMPONENT_DAMAGE_LEVEL_RATIO 0.25f
  27.  
  28. class CVehicleComponent
  29.         : public IVehicleComponent
  30. {
  31. public:
  32.  
  33.         CVehicleComponent();
  34.         ~CVehicleComponent();
  35.  
  36.         bool Init(IVehicle* pVehicle, const CVehicleParams& paramsTable);
  37.         void Reset();
  38.         void Release() { delete this; }
  39.  
  40.         void GetMemoryUsage(ICrySizer* s) const;
  41.  
  42.         // IVehicleComponent
  43.         virtual unsigned int  GetPartCount() const;
  44.         virtual IVehiclePart* GetPart(unsigned int index) const;
  45.         virtual const AABB& GetBounds(); // bounds are in vehicle space
  46.         virtual float       GetDamageRatio() const;
  47.         virtual void        SetDamageRatio(float ratio);
  48.         virtual float       GetMaxDamage() const;
  49.  
  50.         virtual const char* GetComponentName() const
  51.         {
  52.                 return m_pSharedParams ? m_pSharedParams->name.c_str() : NULL;
  53.         }
  54.         // ~IVehicleComponent
  55.  
  56.         const string GetName() const
  57.         {
  58.                 return m_pSharedParams ? m_pSharedParams->name : string();
  59.         }
  60.  
  61.         ILINE bool IsHull() const
  62.         {
  63.                 return m_pSharedParams ? m_pSharedParams->isHull : false;
  64.         }
  65.  
  66.         void OnHit(const HitInfo& hitType, const TVehicleComponentVector* pAffectedComponents = 0);
  67.         void OnVehicleDestroyed();
  68.         void Update(float deltaTime);
  69.         void BroadcastDamage(float damage, EntityId shooterId);
  70.  
  71.         void Serialize(TSerialize ser, EEntityAspects aspects);
  72.  
  73.         void AddPart(IVehiclePart* pPart);
  74.  
  75. #if ENABLE_VEHICLE_DEBUG
  76.         void DebugDraw();
  77. #endif
  78.  
  79.         bool IsMajorComponent() const
  80.         {
  81.                 CRY_ASSERT(m_pSharedParams != 0);
  82.  
  83.                 return m_pSharedParams->isMajorComponent;
  84.         }
  85.  
  86.         void  SetProportionOfVehicleHealth(float proportion);
  87.         float GetProportionOfVehicleHealth() const { return m_proportionOfVehicleHealth; }
  88.  
  89. protected:
  90.  
  91.         float ProcessDamage(const HitInfo& hitInfo, bool impact, const TVehicleComponentVector* pAffectedComponents);
  92.  
  93.         CVehicle* m_pVehicle;
  94.  
  95.         AABB      m_bounds;
  96.  
  97.         float     m_damage;
  98.  
  99.         struct SDamageBehaviorParams
  100.         {
  101.                 float damageRatioMin;
  102.                 float damageRatioMax;
  103.                 bool  ignoreOnVehicleDestroyed;
  104.  
  105.                 void  GetMemoryUsage(ICrySizer* pSizer) const
  106.                 {
  107.                 }
  108.         };
  109.  
  110.         typedef std::pair<SDamageBehaviorParams, IVehicleDamageBehavior*> TVehicleDamageBehaviorPair;
  111.         typedef std::vector<TVehicleDamageBehaviorPair>                   TVehicleDamageBehaviorVector;
  112.  
  113.         TVehicleDamageBehaviorVector m_damageBehaviors;
  114.  
  115.         typedef std::vector<IVehiclePart*> TVehiclePartVector;
  116.         TVehiclePartVector m_parts;
  117.  
  118.         float              m_proportionOfVehicleHealth;
  119.  
  120.         Vec3               m_lastHitLocalPos;
  121.         float              m_lastHitRadius;
  122.         int                m_lastHitType;
  123.  
  124.         BEGIN_SHARED_PARAMS(SSharedParams)
  125.  
  126.         inline SSharedParams() : damageMax(0.0f), hullAffection(1.0f), isHull(false), isMajorComponent(true), isOnlyDamageableByPlayer(false), useBoundsFromParts(false), useDamageLevels(true)
  127.         {
  128.                 bounds.Reset();
  129.         }
  130.  
  131.         string                              name;
  132.         AABB                                bounds;
  133.         float                               damageMax;
  134.         float                               hullAffection;
  135.         bool                                isHull;
  136.         bool                                isMajorComponent;
  137.         bool                                isOnlyDamageableByPlayer;
  138.         bool                                useBoundsFromParts;
  139.         bool                                useDamageLevels;
  140.         CVehicleDamages::TDamageMultipliers damageMultipliersByHitType;
  141.         CVehicleDamages::TDamageMultipliers damageMultipliersByProjectile;
  142.  
  143.         END_SHARED_PARAMS
  144.  
  145.         SSharedParamsConstPtr GetSharedParams(const string& vehicleComponentName, const CVehicleParams& paramsTable) const;
  146.  
  147.         SSharedParamsConstPtr m_pSharedParams;
  148. };
  149.  
  150. #endif
  151.  
downloadVehicleComponent.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