BVB Source Codes

CRYENGINE Show VehicleDamageBehaviorMovementNotification.cpp Source code

Return Download CRYENGINE: download VehicleDamageBehaviorMovementNotification.cpp Source code - Download CRYENGINE Source code - Type:.cpp
  1. // Copyright 2001-2016 Crytek GmbH / Crytek Group. All rights reserved.
  2.  
  3. #include "StdAfx.h"
  4. #include "VehicleDamageBehaviorMovementNotification.h"
  5.  
  6. #include "IVehicleSystem.h"
  7. #include "Vehicle.h"
  8.  
  9. //------------------------------------------------------------------------
  10. CVehicleDamageBehaviorMovementNotification::CVehicleDamageBehaviorMovementNotification()
  11.         : m_pVehicle(nullptr)
  12.         , m_isSteeringInvolved(false)
  13.         , m_isFatal(true)
  14.         , m_isDamageAlwaysFull(false)
  15.         , m_param(0)
  16. {}
  17.  
  18. //------------------------------------------------------------------------
  19. bool CVehicleDamageBehaviorMovementNotification::Init(IVehicle* pVehicle, const CVehicleParams& table)
  20. {
  21.         CRY_ASSERT(pVehicle);
  22.         m_pVehicle = pVehicle;
  23.  
  24.         m_param = 0;
  25.  
  26.         if (CVehicleParams notificationParams = table.findChild("MovementNotification"))
  27.         {
  28.                 notificationParams.getAttr("isSteering", m_isSteeringInvolved);
  29.                 notificationParams.getAttr("isFatal", m_isFatal);
  30.                 notificationParams.getAttr("param", m_param);
  31.                 notificationParams.getAttr("isDamageAlwaysFull", m_isDamageAlwaysFull);
  32.         }
  33.  
  34.         return true;
  35. }
  36.  
  37. //------------------------------------------------------------------------
  38. void CVehicleDamageBehaviorMovementNotification::Reset()
  39. {
  40. }
  41.  
  42. //------------------------------------------------------------------------
  43. void CVehicleDamageBehaviorMovementNotification::OnDamageEvent(EVehicleDamageBehaviorEvent event, const SVehicleDamageBehaviorEventParams& behaviorParams)
  44. {
  45.         if (event == eVDBE_Hit || event == eVDBE_VehicleDestroyed || event == eVDBE_Repair)
  46.         {
  47.                 IVehicleMovement::EVehicleMovementEvent eventType;
  48.  
  49.                 if (event == eVDBE_Repair)
  50.                         eventType = IVehicleMovement::eVME_Repair;
  51.                 else if (m_isSteeringInvolved)
  52.                         eventType = IVehicleMovement::eVME_DamageSteering;
  53.                 else
  54.                         eventType = IVehicleMovement::eVME_Damage;
  55.  
  56.                 SVehicleMovementEventParams params;
  57.                 if (m_isDamageAlwaysFull)
  58.                 {
  59.                         if (event != eVDBE_Repair)
  60.                                 params.fValue = 1.0f;
  61.                         else
  62.                                 params.fValue = 0.0f;
  63.                 }
  64.                 else
  65.                 {
  66.                         if (event != eVDBE_Repair)
  67.                                 params.fValue = min(1.0f, behaviorParams.componentDamageRatio);
  68.                         else
  69.                         {
  70.                                 // round down to nearest 0.25 (ensures movement object is sent zero damage on fully repairing vehicle).
  71.                                 params.fValue = ((int)(behaviorParams.componentDamageRatio * 4)) / 4.0f;
  72.                         }
  73.                 }
  74.  
  75.                 params.vParam = behaviorParams.localPos;
  76.                 params.bValue = m_isFatal;
  77.                 params.iValue = m_param;
  78.                 params.pComponent = behaviorParams.pVehicleComponent;
  79.  
  80.                 m_pVehicle->GetMovement()->OnEvent(eventType, params);
  81.         }
  82. }
  83.  
  84. DEFINE_VEHICLEOBJECT(CVehicleDamageBehaviorMovementNotification);
  85.  
downloadVehicleDamageBehaviorMovementNotification.cpp 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