BVB Source Codes

CRYENGINE Show ScriptBind_VehicleSeat.cpp Source code

Return Download CRYENGINE: download ScriptBind_VehicleSeat.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: Script Binding for the Vehicle Seat
  8.  
  9.    -------------------------------------------------------------------------
  10.    History:
  11.    - 28:04:2004   17:02 : Created by Mathieu Pinard
  12.  
  13. *************************************************************************/
  14. #include "StdAfx.h"
  15. #include <CryString/CryString.h>
  16. #include <IActionMapManager.h>
  17. #include <CryAnimation/ICryAnimation.h>
  18. #include <CryGame/IGameFramework.h>
  19. #include "IActorSystem.h"
  20. #include <vector>
  21. #include <CryMath/Cry_Math.h>
  22. #include <CryRenderer/IShader.h>
  23. #include <CryRenderer/IRenderAuxGeom.h>
  24. #include <CryMath/Cry_GeoOverlap.h>
  25.  
  26. #include "VehicleSystem.h"
  27. #include "VehicleSeat.h"
  28. #include "ScriptBind_VehicleSeat.h"
  29. #include "Vehicle.h"
  30. #include "VehicleSeatActionWeapons.h"
  31.  
  32. //------------------------------------------------------------------------
  33. // macro for retrieving vehicle and entity
  34. #undef GET_ENTITY
  35. #define GET_ENTITY IVehicle * pVehicle = GetVehicle(pH); CRY_ASSERT(pVehicle); \
  36.   IEntity* pEntity = pVehicle->GetEntity();                                    \
  37.   if (!pEntity) return pH->EndFunction();
  38.  
  39. //------------------------------------------------------------------------
  40. CScriptBind_VehicleSeat::CScriptBind_VehicleSeat(ISystem* pSystem, IGameFramework* pGameFW)
  41. {
  42.         m_pVehicleSystem = pGameFW->GetIVehicleSystem();
  43.  
  44.         Init(gEnv->pScriptSystem, gEnv->pSystem, 1);
  45.  
  46.         RegisterMethods();
  47.         RegisterGlobals();
  48. }
  49.  
  50. //------------------------------------------------------------------------
  51. CScriptBind_VehicleSeat::~CScriptBind_VehicleSeat()
  52. {
  53. }
  54.  
  55. //------------------------------------------------------------------------
  56. void CScriptBind_VehicleSeat::RegisterGlobals()
  57. {
  58. }
  59.  
  60. //------------------------------------------------------------------------
  61. void CScriptBind_VehicleSeat::RegisterMethods()
  62. {
  63. #undef SCRIPT_REG_CLASSNAME
  64. #define SCRIPT_REG_CLASSNAME &CScriptBind_VehicleSeat::
  65.  
  66.         SCRIPT_REG_TEMPLFUNC(Reset, "");
  67.         SCRIPT_REG_TEMPLFUNC(IsFree, "actor");
  68.         SCRIPT_REG_TEMPLFUNC(IsDriver, "");
  69.         SCRIPT_REG_TEMPLFUNC(IsGunner, "");
  70.         SCRIPT_REG_TEMPLFUNC(GetWeaponCount, "");
  71.         SCRIPT_REG_TEMPLFUNC(GetWeaponId, "index");
  72.         SCRIPT_REG_TEMPLFUNC(SetAIWeapon, "weaponId");
  73.         SCRIPT_REG_TEMPLFUNC(GetPassengerId, "");
  74. }
  75.  
  76. //------------------------------------------------------------------------
  77. void CScriptBind_VehicleSeat::AttachTo(IVehicle* pVehicle, TVehicleSeatId seatId)
  78. {
  79.         IScriptTable* pScriptTable = pVehicle->GetEntity()->GetScriptTable();
  80.  
  81.         if (!pScriptTable || seatId == InvalidVehicleSeatId)
  82.                 return;
  83.  
  84.         SmartScriptTable seatsTable;
  85.         if (!pScriptTable->GetValue("Seats", seatsTable))
  86.         {
  87.                 CRY_ASSERT(!"cannot read the seats table");
  88.                 return;
  89.         }
  90.  
  91.         SmartScriptTable seatTable(gEnv->pScriptSystem);
  92.  
  93.         SmartScriptTable thisTable(gEnv->pScriptSystem);
  94.         thisTable->SetValue("vehicleId", ScriptHandle(pVehicle->GetEntityId()));
  95.         thisTable->SetValue("seatId", (int)seatId);
  96.  
  97.         thisTable->Delegate(GetMethodsTable());
  98.         seatTable->SetValue("seat", thisTable);
  99.  
  100.         if (IVehicleSeat* pSeat = pVehicle->GetSeatById(seatId))
  101.                 seatTable->SetValue("isDriver", pSeat->IsDriver());
  102.  
  103.         seatsTable->SetAt(seatId, seatTable);
  104. }
  105.  
  106. //------------------------------------------------------------------------
  107. CVehicleSeat* CScriptBind_VehicleSeat::GetVehicleSeat(IFunctionHandler* pH)
  108. {
  109.         ScriptHandle handle;
  110.         int seatId = 0;
  111.  
  112.         SmartScriptTable table;
  113.         if (pH->GetSelf(table))
  114.         {
  115.                 if (table->GetValue("vehicleId", handle) && table->GetValue("seatId", seatId))
  116.                 {
  117.                         CVehicle* pVehicle = (CVehicle*)m_pVehicleSystem->GetVehicle((EntityId)handle.n);
  118.  
  119.                         if (pVehicle)
  120.                         {
  121.                                 return (CVehicleSeat*)pVehicle->GetSeatById((TVehicleSeatId)seatId);
  122.                         }
  123.                 }
  124.         }
  125.  
  126.         return 0;
  127. }
  128.  
  129. //------------------------------------------------------------------------
  130. int CScriptBind_VehicleSeat::Reset(IFunctionHandler* pH)
  131. {
  132.         CVehicleSeat* pVehicleSeat = GetVehicleSeat(pH);
  133.  
  134.         if (pVehicleSeat)
  135.                 pVehicleSeat->Reset();
  136.  
  137.         return pH->EndFunction();
  138. }
  139.  
  140. //------------------------------------------------------------------------
  141. int CScriptBind_VehicleSeat::GetWeaponId(IFunctionHandler* pH, int weaponIndex)
  142. {
  143.         // returns Weapon Id 02/11/05 Tetsuji
  144.         const CVehicleSeat* pVehicleSeat = GetVehicleSeat(pH);
  145.  
  146.         int weaponCounter = 1;
  147.  
  148.         if (pVehicleSeat)
  149.         {
  150.                 const TVehicleSeatActionVector& seatActions = pVehicleSeat->GetSeatActions();
  151.  
  152.                 for (TVehicleSeatActionVector::const_iterator ite = seatActions.begin(), end = seatActions.end(); ite != end; ++ite)
  153.                 {
  154.                         IVehicleSeatAction* pSeatAction = ite->pSeatAction;
  155.                         if (CVehicleSeatActionWeapons* pSeatWeapons = CAST_VEHICLEOBJECT(CVehicleSeatActionWeapons, pSeatAction))
  156.                         {
  157.                                 if ((weaponCounter == weaponIndex) && (pSeatWeapons->GetWeaponCount() > 0))
  158.                                 {
  159.                                         ScriptHandle weaponHandle;
  160.                                         weaponHandle.n = pSeatWeapons->GetWeaponEntityId(0);
  161.                                         return pH->EndFunction(weaponHandle);
  162.                                 }
  163.  
  164.                                 weaponCounter++;
  165.                         }
  166.                 }
  167.         }
  168.  
  169.         return pH->EndFunction();
  170. }
  171.  
  172. //------------------------------------------------------------------------
  173. int CScriptBind_VehicleSeat::GetWeaponCount(IFunctionHandler* pH)
  174. {
  175.         const CVehicleSeat* pVehicleSeat = GetVehicleSeat(pH);
  176.         int weaponCount = 0;
  177.  
  178.         if (pVehicleSeat)
  179.         {
  180.                 const TVehicleSeatActionVector& seatActions = pVehicleSeat->GetSeatActions();
  181.  
  182.                 for (TVehicleSeatActionVector::const_iterator ite = seatActions.begin(), end = seatActions.end(); ite != end; ++ite)
  183.                 {
  184.                         IVehicleSeatAction* pSeatAction = ite->pSeatAction;
  185.                         if (CAST_VEHICLEOBJECT(CVehicleSeatActionWeapons, pSeatAction))
  186.                                 weaponCount++;
  187.                 }
  188.         }
  189.  
  190.         return pH->EndFunction(weaponCount);
  191. }
  192.  
  193. //------------------------------------------------------------------------
  194. int CScriptBind_VehicleSeat::SetAIWeapon(IFunctionHandler* pH, ScriptHandle weaponHandle)
  195. {
  196.         if (CVehicleSeat* pVehicleSeat = GetVehicleSeat(pH))
  197.         {
  198.                 pVehicleSeat->SetAIWeaponId((EntityId)weaponHandle.n);
  199.                 return pH->EndFunction(true);
  200.         }
  201.  
  202.         return pH->EndFunction(false);
  203. }
  204.  
  205. //------------------------------------------------------------------------
  206. int CScriptBind_VehicleSeat::IsFree(IFunctionHandler* pH, ScriptHandle actorHandle)
  207. {
  208.         if (CVehicleSeat* pVehicleSeat = GetVehicleSeat(pH))
  209.         {
  210.                 IActor* pActor = CCryAction::GetCryAction()->GetIActorSystem()->GetActor((EntityId)actorHandle.n);
  211.                 return pH->EndFunction(pVehicleSeat->IsFree(pActor));
  212.         }
  213.  
  214.         return pH->EndFunction(false);
  215. }
  216.  
  217. //------------------------------------------------------------------------
  218. int CScriptBind_VehicleSeat::IsDriver(IFunctionHandler* pH)
  219. {
  220.         if (CVehicleSeat* pVehicleSeat = GetVehicleSeat(pH))
  221.         {
  222.                 return pH->EndFunction(pVehicleSeat->IsDriver());
  223.         }
  224.  
  225.         return pH->EndFunction(false);
  226. }
  227.  
  228. //------------------------------------------------------------------------
  229. int CScriptBind_VehicleSeat::IsGunner(IFunctionHandler* pH)
  230. {
  231.         if (CVehicleSeat* pVehicleSeat = GetVehicleSeat(pH))
  232.         {
  233.                 return pH->EndFunction(pVehicleSeat->IsGunner());
  234.         }
  235.  
  236.         return pH->EndFunction(false);
  237. }
  238.  
  239. //------------------------------------------------------------------------
  240. int CScriptBind_VehicleSeat::GetPassengerId(IFunctionHandler* pH)
  241. {
  242.         if (CVehicleSeat* pVehicleSeat = GetVehicleSeat(pH))
  243.         {
  244.                 return pH->EndFunction(ScriptHandle(pVehicleSeat->GetPassenger()));
  245.         }
  246.  
  247.         return pH->EndFunction();
  248. }
  249.  
downloadScriptBind_VehicleSeat.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