BVB Source Codes

CRYENGINE Show FlowVehiclePassenger.cpp Source code

Return Download CRYENGINE: download FlowVehiclePassenger.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 flow node to handle vehicle passengers
  8.  
  9.    -------------------------------------------------------------------------
  10.    History:
  11.    - 09:12:2005: Created by Mathieu Pinard
  12.  
  13. *************************************************************************/
  14. #include "StdAfx.h"
  15. #include "CryAction.h"
  16. #include "IVehicleSystem.h"
  17. #include "VehicleSystem/Vehicle.h"
  18. #include "VehicleSystem/VehicleSeat.h"
  19. #include "FlowVehiclePassenger.h"
  20.  
  21. #include <CryFlowGraph/IFlowBaseNode.h>
  22.  
  23. //------------------------------------------------------------------------
  24. CFlowVehiclePassenger::CFlowVehiclePassenger(SActivationInfo* pActivationInfo)
  25.         : m_passengerCount(0)
  26. {
  27.         CFlowVehicleBase::Init(pActivationInfo);
  28. }
  29.  
  30. //------------------------------------------------------------------------
  31. IFlowNodePtr CFlowVehiclePassenger::Clone(SActivationInfo* pActivationInfo)
  32. {
  33.         IFlowNode* pNode = new CFlowVehiclePassenger(pActivationInfo);
  34.         return pNode;
  35. }
  36.  
  37. //------------------------------------------------------------------------
  38. void CFlowVehiclePassenger::GetConfiguration(SFlowNodeConfig& nodeConfig)
  39. {
  40.         CFlowVehicleBase::GetConfiguration(nodeConfig);
  41.  
  42.         static const SInputPortConfig pInConfig[] =
  43.         {
  44.                 InputPortConfig_Void("ActorInTrigger",  _HELP("Forces actor [ActorId] to get inside a vehicle, if a seat is available")),
  45.                 InputPortConfig_Void("ActorOutTrigger", _HELP("Forces passenger [ActorId] to get out of a vehicle")),
  46.                 InputPortConfig<EntityId>("ActorId",    _HELP("Entity ID of the actor which is used")),
  47.                 InputPortConfig<int>("SeatId",          _HELP("Seat ID of the preferred seat where place the new passenger")),
  48.                 { 0 }
  49.         };
  50.  
  51.         static const SOutputPortConfig pOutConfig[] =
  52.         {
  53.                 OutputPortConfig<EntityId>("ActorIn",  _HELP("Triggered when ANY Actor got in. Outputs its EntityId.")),
  54.                 OutputPortConfig<EntityId>("ActorOut", _HELP("Triggered when ANY Actor got out. Outputs its EntityId.")),
  55.                 { 0 }
  56.         };
  57.  
  58.         nodeConfig.sDescription = _HELP("Handle vehicle passengers");
  59.         nodeConfig.nFlags |= EFLN_TARGET_ENTITY;
  60.         nodeConfig.pInputPorts = pInConfig;
  61.         nodeConfig.pOutputPorts = pOutConfig;
  62.         nodeConfig.SetCategory(EFLN_APPROVED);
  63. }
  64.  
  65. //------------------------------------------------------------------------
  66. void CFlowVehiclePassenger::ProcessEvent(EFlowEvent flowEvent, SActivationInfo* pActivationInfo)
  67. {
  68.         CFlowVehicleBase::ProcessEvent(flowEvent, pActivationInfo);
  69.  
  70.         if (flowEvent == eFE_Activate)
  71.         {
  72.                 m_actorId = GetPortEntityId(pActivationInfo, IN_ACTORID);
  73.                 m_seatId = GetPortInt(pActivationInfo, IN_SEATID);
  74.  
  75.                 if (IVehicle* pVehicle = GetVehicle())
  76.                 {
  77.                         if (IsPortActive(pActivationInfo, IN_TRIGGERPASSENGERIN))
  78.                         {
  79.                                 if (m_actorId && m_seatId > 0)
  80.                                 {
  81.                                         IActor* pActor = gEnv->pGameFramework->GetIActorSystem()->GetActor(m_actorId);
  82.  
  83.                                         if (pActor)
  84.                                         {
  85.                                                 IVehicle* pCurrent = pActor->GetLinkedVehicle();
  86.  
  87.                                                 if (pCurrent && pCurrent != pVehicle)
  88.                                                 {
  89.                                                         if (IVehicleSeat* pSeat = pCurrent->GetSeatForPassenger(m_actorId))
  90.                                                                 pSeat->Exit(false, true);
  91.                                                 }
  92.  
  93.                                                 if (pCurrent == pVehicle && pCurrent->GetSeatForPassenger(m_actorId))
  94.                                                 {
  95.                                                         ((CVehicle*)pVehicle)->ChangeSeat(m_actorId, 0, m_seatId);
  96.                                                 }
  97.                                                 else
  98.                                                 {
  99.                                                         if (IVehicleSeat* pSeat = pVehicle->GetSeatById(m_seatId))
  100.                                                                 pSeat->Enter(m_actorId);
  101.                                                 }
  102.                                         }
  103.                                 }
  104.                         }
  105.  
  106.                         if (IsPortActive(pActivationInfo, IN_TRIGGERPASSENGEROUT))
  107.                         {
  108.                                 if (m_actorId)
  109.                                 {
  110.                                         if (IVehicleSeat* pSeat = pVehicle->GetSeatForPassenger(m_actorId))
  111.                                                 pSeat->Exit(true);
  112.                                 }
  113.                         }
  114.                 }
  115.         }
  116. }
  117.  
  118. //------------------------------------------------------------------------
  119. void CFlowVehiclePassenger::OnVehicleEvent(EVehicleEvent event, const SVehicleEventParams& params)
  120. {
  121.         CFlowVehicleBase::OnVehicleEvent(event, params);
  122.  
  123.         if (event == eVE_PassengerEnter)
  124.         {
  125.                 SFlowAddress addr(m_nodeID, OUT_ACTORIN, true);
  126.                 m_pGraph->ActivatePort(addr, params.entityId);
  127.         }
  128.         else if (event == eVE_PassengerExit)
  129.         {
  130.                 SFlowAddress addr(m_nodeID, OUT_ACTOROUT, true);
  131.                 m_pGraph->ActivatePort(addr, params.entityId);
  132.         }
  133. }
  134.  
  135. REGISTER_FLOW_NODE("Vehicle:Passenger", CFlowVehiclePassenger);
  136.  
downloadFlowVehiclePassenger.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