BVB Source Codes

CRYENGINE Show VehicleSeatActionMovement.cpp Source code

Return Download CRYENGINE: download VehicleSeatActionMovement.cpp Source code - Download CRYENGINE Source code - Type:.cpp
  1. // Copyright 2001-2016 Crytek GmbH / Crytek Group. All rights reserved.
  2.  
  3. /*************************************************************************
  4.    -------------------------------------------------------------------------
  5.    $Id$
  6.    $DateTime$
  7.    Description: Implements a seat action which handle the vehicle movement
  8.  
  9.    -------------------------------------------------------------------------
  10.    History:
  11.    - 20:10:2006: Created by Mathieu Pinard
  12.  
  13. *************************************************************************/
  14. #include "StdAfx.h"
  15. #include "CryAction.h"
  16. #include "IVehicleSystem.h"
  17. #include "Vehicle.h"
  18. #include "VehicleSeat.h"
  19. #include "VehicleSeatActionMovement.h"
  20.  
  21. //------------------------------------------------------------------------
  22. CVehicleSeatActionMovement::CVehicleSeatActionMovement()
  23.         : m_delayedStop(0.0f),
  24.         m_actionForward(0.0f),
  25.         m_pVehicle(NULL),
  26.         m_pSeat(NULL)
  27. {
  28. }
  29.  
  30. //------------------------------------------------------------------------
  31. CVehicleSeatActionMovement::~CVehicleSeatActionMovement()
  32. {
  33. }
  34.  
  35. //------------------------------------------------------------------------
  36. bool CVehicleSeatActionMovement::Init(IVehicle* pVehicle, IVehicleSeat* pSeat, const CVehicleParams& table)
  37. {
  38.         return Init(pVehicle, pSeat);
  39. }
  40.  
  41. //------------------------------------------------------------------------
  42. bool CVehicleSeatActionMovement::Init(IVehicle* pVehicle, IVehicleSeat* pSeat)
  43. {
  44.         IVehicleMovement* pMovement = pVehicle->GetMovement();
  45.         if (!pMovement)
  46.                 return false;
  47.  
  48.         m_pVehicle = pVehicle;
  49.         m_pSeat = pSeat;
  50.  
  51.         return true;
  52. }
  53.  
  54. //------------------------------------------------------------------------
  55. void CVehicleSeatActionMovement::Reset()
  56. {
  57.         CRY_ASSERT(m_pVehicle);
  58.  
  59.         m_pVehicle->SetObjectUpdate(this, IVehicle::eVOU_NoUpdate);
  60.  
  61.         m_actionForward = 0.0f;
  62.         m_delayedStop = 0.0f;
  63.  
  64.         if (IVehicleMovement* pMovement = m_pVehicle->GetMovement())
  65.                 pMovement->Reset();
  66. }
  67.  
  68. //------------------------------------------------------------------------
  69. void CVehicleSeatActionMovement::StartUsing(EntityId passengerId)
  70. {
  71.         IActorSystem* pActorSystem = CCryAction::GetCryAction()->GetIActorSystem();
  72.         CRY_ASSERT(pActorSystem);
  73.  
  74.         IActor* pActor = pActorSystem->GetActor(passengerId);
  75.         CRY_ASSERT(pActor);
  76.  
  77.         IVehicleMovement* pMovement = m_pVehicle->GetMovement();
  78.         CRY_ASSERT(pMovement);
  79.  
  80.         if (!pMovement)
  81.                 return;
  82.  
  83.         if (m_delayedStop >= 0.0f)
  84.         {
  85.                 m_pVehicle->SetObjectUpdate(this, IVehicle::eVOU_NoUpdate);
  86.                 m_delayedStop = 0.0f;
  87.  
  88.                 pMovement->StopDriving();
  89.         }
  90.  
  91.         pMovement->StartDriving(passengerId);
  92. }
  93.  
  94. //------------------------------------------------------------------------
  95. void CVehicleSeatActionMovement::StopUsing()
  96. {
  97.         IActorSystem* pActorSystem = CCryAction::GetCryAction()->GetIActorSystem();
  98.         CRY_ASSERT(pActorSystem);
  99.  
  100.         IVehicleMovement* pMovement = m_pVehicle->GetMovement();
  101.         if (!pMovement)
  102.                 return;
  103.  
  104.         CRY_ASSERT(m_pSeat);
  105.  
  106.         // default to continuing for a bit
  107.         m_delayedStop = 0.8f;
  108.  
  109.         IActor* pActor = pActorSystem->GetActor(m_pSeat->GetPassenger());
  110.  
  111.         if (pActor && pActor->IsPlayer())
  112.         {
  113.                 // if stopped already don't go anywhere
  114.                 IPhysicalEntity* pPhys = m_pVehicle->GetEntity()->GetPhysics();
  115.                 pe_status_dynamics status;
  116.                 if (pPhys && pPhys->GetStatus(&status))
  117.                 {
  118.                         if (status.v.GetLengthSquared() < 25.0f)
  119.                                 m_delayedStop = 0.0f;
  120.                 }
  121.  
  122.                 if (m_actionForward > 0.0f)
  123.                         m_delayedStop = 1.5f;
  124.  
  125.                 if (pMovement->GetMovementType() == IVehicleMovement::eVMT_Air)
  126.                         m_delayedStop *= 2.0f;
  127.  
  128.                 m_pVehicle->SetObjectUpdate(this, IVehicle::eVOU_AlwaysUpdate);
  129.  
  130.                 // prevent full pedal being kept pressed, but give it a bit
  131.                 pMovement->OnAction(eVAI_MoveForward, eAAM_OnPress, 0.1f);
  132.         }
  133.         else
  134.         {
  135.                 if (pMovement->GetMovementType() == IVehicleMovement::eVMT_Air)
  136.                 {
  137.                         m_delayedStop = 0.0f;
  138.                         m_pVehicle->SetObjectUpdate(this, IVehicle::eVOU_AlwaysUpdate);
  139.                 }
  140.                 else
  141.                 {
  142.                         pMovement->StopDriving();
  143.                 }
  144.         }
  145. }
  146.  
  147. //------------------------------------------------------------------------
  148. void CVehicleSeatActionMovement::OnAction(const TVehicleActionId actionId, int activationMode, float value)
  149. {
  150.         if (actionId == eVAI_MoveForward)
  151.                 m_actionForward = value;
  152.         else if (actionId == eVAI_MoveBack)
  153.                 m_actionForward = -value;
  154.  
  155.         IVehicleMovement* pMovement = m_pVehicle->GetMovement();
  156.         CRY_ASSERT(pMovement);
  157.  
  158.         pMovement->OnAction(actionId, activationMode, value);
  159. }
  160.  
  161. //------------------------------------------------------------------------
  162. void CVehicleSeatActionMovement::Update(const float deltaTime)
  163. {
  164.         IVehicleMovement* pMovement = m_pVehicle->GetMovement();
  165.         CRY_ASSERT(pMovement);
  166.  
  167.         bool isReadyToStopEngine = true;
  168.  
  169.         if (isReadyToStopEngine)
  170.         {
  171.                 if (m_delayedStop > 0.0f)
  172.                         m_delayedStop -= deltaTime;
  173.  
  174.                 if (m_delayedStop <= 0.0f)
  175.                 {
  176.                         m_pVehicle->SetObjectUpdate(this, IVehicle::eVOU_NoUpdate);
  177.                         pMovement->StopDriving();
  178.                 }
  179.         }
  180. }
  181.  
  182. DEFINE_VEHICLEOBJECT(CVehicleSeatActionMovement);
  183.  
downloadVehicleSeatActionMovement.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