BVB Source Codes

CRYENGINE Show VehiclePartEntityDelayedDetach.cpp Source code

Return Download CRYENGINE: download VehiclePartEntityDelayedDetach.cpp Source code - Download CRYENGINE Source code - Type:.cpp
  1. // Copyright 2001-2016 Crytek GmbH / Crytek Group. All rights reserved.
  2.  
  3. /*************************************************************************
  4.    -------------------------------------------------------------------------
  5.  
  6.    Description: Subclass of VehiclePartEntity that can be asked to detach at a random point in the future
  7.  
  8.    -------------------------------------------------------------------------
  9.    History:
  10.    - 14:02:2012:        Created by Andrew Blackwell
  11.  
  12. *************************************************************************/
  13.  
  14. #include "StdAfx.h"
  15.  
  16. //This Include
  17. #include "VehiclePartEntityDelayedDetach.h"
  18.  
  19. //------------------------------------------------------------------------
  20. CVehiclePartEntityDelayedDetach::CVehiclePartEntityDelayedDetach()
  21.         : CVehiclePartEntity()
  22.         , m_detachTimer(-1.0f)
  23. {
  24. }
  25.  
  26. //------------------------------------------------------------------------
  27. CVehiclePartEntityDelayedDetach::~CVehiclePartEntityDelayedDetach()
  28. {
  29. }
  30.  
  31. //------------------------------------------------------------------------
  32. void CVehiclePartEntityDelayedDetach::Update(const float frameTime)
  33. {
  34.         CVehiclePartEntity::Update(frameTime);
  35.  
  36.         if (EntityAttached() && m_detachTimer >= 0.0f)
  37.         {
  38.                 m_detachTimer -= frameTime;
  39.  
  40.                 if (m_detachTimer <= 0.0f)
  41.                 {
  42.                         SVehicleEventParams vehicleEventParams;
  43.                         vehicleEventParams.entityId = GetPartEntityId();
  44.                         vehicleEventParams.iParam = m_pVehicle->GetEntityId();
  45.  
  46.                         m_pVehicle->BroadcastVehicleEvent(eVE_OnDetachPartEntity, vehicleEventParams);
  47.  
  48.                         m_detachTimer = -1.0f;
  49.                 }
  50.         }
  51. }
  52.  
  53. //------------------------------------------------------------------------
  54. void CVehiclePartEntityDelayedDetach::OnVehicleEvent(EVehicleEvent event, const SVehicleEventParams& params)
  55. {
  56.         CVehiclePartEntity::OnVehicleEvent(event, params);
  57.  
  58.         switch (event)
  59.         {
  60.         case eVE_RequestDelayedDetachAllPartEntities:
  61.                 {
  62.                         //we're a part entity, so want to detach.
  63.                         //don't reset timer if all ready set
  64.                         if (m_detachTimer < 0.0f && EntityAttached())
  65.                         {
  66.                                 //random time between min + max wait
  67.                                 m_detachTimer = cry_random(params.fParam, params.fParam2);
  68.                         }
  69.                         break;
  70.                 }
  71.  
  72.         case eVE_Sleep:
  73.                 {
  74.                         //if we were scheduled to delay detach, do so now as we won't receive further updates
  75.                         if (m_detachTimer >= 0.0f && EntityAttached())
  76.                         {
  77.                                 m_detachTimer = -1.0f;
  78.  
  79.                                 SVehicleEventParams vehicleEventParams;
  80.  
  81.                                 vehicleEventParams.entityId = GetPartEntityId();
  82.                                 vehicleEventParams.iParam = m_pVehicle->GetEntityId();
  83.  
  84.                                 m_pVehicle->BroadcastVehicleEvent(eVE_OnDetachPartEntity, vehicleEventParams);
  85.                         }
  86.                         break;
  87.                 }
  88.         }
  89. }
  90.  
  91. //------------------------------------------------------------------------
  92. DEFINE_VEHICLEOBJECT(CVehiclePartEntityDelayedDetach)
  93.  
downloadVehiclePartEntityDelayedDetach.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