BVB Source Codes

CRYENGINE Show VehicleUsableActionEnter.cpp Source code

Return Download CRYENGINE: download VehicleUsableActionEnter.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 usable action to enter a vehicle seat
  8.  
  9.    -------------------------------------------------------------------------
  10.    History:
  11.    - 19:01:2006: Created by Mathieu Pinard
  12.  
  13. *************************************************************************/
  14. #include "StdAfx.h"
  15. #include "CryAction.h"
  16. #include "GameObjects/GameObject.h"
  17. #include "IActorSystem.h"
  18. #include "IGameObject.h"
  19. #include "IItem.h"
  20. #include "IItemSystem.h"
  21. #include "IVehicleSystem.h"
  22. #include "Vehicle.h"
  23. #include "VehicleSeat.h"
  24. #include "VehicleSeatGroup.h"
  25. #include "VehicleUsableActionEnter.h"
  26.  
  27. //------------------------------------------------------------------------
  28. bool CVehicleUsableActionEnter::Init(IVehicle* pVehicle, const CVehicleParams& table)
  29. {
  30.         CVehicleParams enterTable = table.findChild("Enter");
  31.         if (!enterTable)
  32.                 return false;
  33.  
  34.         m_pVehicle = static_cast<CVehicle*>(pVehicle);
  35.  
  36.         if (CVehicleParams seatsTables = enterTable.findChild("Seats"))
  37.         {
  38.                 int c = seatsTables.getChildCount();
  39.                 int i = 0;
  40.                 m_seatIds.reserve(c);
  41.  
  42.                 for (; i < c; i++)
  43.                 {
  44.                         CVehicleParams seatRef = seatsTables.getChild(i);
  45.  
  46.                         if (const char* pSeatName = seatRef.getAttr("value"))
  47.                         {
  48.                                 if (TVehicleSeatId seatId = m_pVehicle->GetSeatId(pSeatName))
  49.                                         m_seatIds.push_back(seatId);
  50.                         }
  51.                 }
  52.         }
  53.  
  54.         return !m_seatIds.empty();
  55. }
  56.  
  57. //------------------------------------------------------------------------
  58. int CVehicleUsableActionEnter::OnEvent(int eventType, SVehicleEventParams& eventParams)
  59. {
  60.         if (eventType == eVAE_IsUsable)
  61.         {
  62.                 EntityId& userId = eventParams.entityId;
  63.  
  64.                 for (TVehicleSeatIdVector::iterator ite = m_seatIds.begin(), end = m_seatIds.end(); ite != end; ++ite)
  65.                 {
  66.                         TVehicleSeatId seatId = *ite;
  67.                         IVehicleSeat* pSeat = m_pVehicle->GetSeatById(seatId);
  68.                         if (IsSeatAvailable(pSeat, userId))
  69.                         {
  70.                                 eventParams.iParam = seatId;
  71.                                 return 1;
  72.                         }
  73.                 }
  74.  
  75.                 return 0;
  76.         }
  77.         else if (eventType == eVAE_OnUsed)
  78.         {
  79.                 EntityId& userId = eventParams.entityId;
  80.  
  81.                 IVehicleSeat* pSeat = m_pVehicle->GetSeatById(eventParams.iParam);
  82.  
  83.                 if (IsSeatAvailable(pSeat, userId))
  84.                         return pSeat->Enter(userId);
  85.  
  86.                 return -1;
  87.         }
  88.  
  89.         return 0;
  90. }
  91.  
  92. //------------------------------------------------------------------------
  93. bool CVehicleUsableActionEnter::IsSeatAvailable(IVehicleSeat* pSeat, EntityId userId)
  94. {
  95.         if (!pSeat)
  96.                 return false;
  97.  
  98.         IActor* pActor = CCryAction::GetCryAction()->GetIActorSystem()->GetActor(userId);
  99.         if (!static_cast<CVehicleSeat*>(pSeat)->IsFree(pActor))
  100.                 return false;
  101.  
  102.         return true;
  103. }
  104.  
  105. void CVehicleUsableActionEnter::GetMemoryStatistics(ICrySizer* s)
  106. {
  107.         s->Add(*this);
  108.         s->AddContainer(m_seatIds);
  109. }
  110.  
  111. DEFINE_VEHICLEOBJECT(CVehicleUsableActionEnter);
  112.  
downloadVehicleUsableActionEnter.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