BVB Source Codes

CRYENGINE Show ScriptBind_Inventory.cpp Source code

Return Download CRYENGINE: download ScriptBind_Inventory.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.  
  8.    -------------------------------------------------------------------------
  9.    History:
  10.    - 4:9:2005   15:32 : Created by M谩rcio Martins
  11.  
  12. *************************************************************************/
  13. #include "StdAfx.h"
  14. #include "ScriptBind_Inventory.h"
  15. #include "Inventory.h"
  16. #include "IGameObject.h"
  17.  
  18. //------------------------------------------------------------------------
  19. CScriptBind_Inventory::CScriptBind_Inventory(ISystem* pSystem, IGameFramework* pGameFramework)
  20.         : m_pSystem(pSystem),
  21.         m_pEntitySystem(gEnv->pEntitySystem),
  22.         m_pGameFramework(pGameFramework)
  23. {
  24.         Init(m_pSystem->GetIScriptSystem(), m_pSystem, 1);
  25.  
  26.         RegisterMethods();
  27.         RegisterGlobals();
  28. }
  29.  
  30. //------------------------------------------------------------------------
  31. CScriptBind_Inventory::~CScriptBind_Inventory()
  32. {
  33. }
  34.  
  35. //------------------------------------------------------------------------
  36. void CScriptBind_Inventory::AttachTo(CInventory* pInventory)
  37. {
  38.         IScriptTable* pScriptTable = pInventory->GetEntity()->GetScriptTable();
  39.  
  40.         if (pScriptTable)
  41.         {
  42.                 SmartScriptTable thisTable(m_pSS);
  43.  
  44.                 thisTable->SetValue("__this", ScriptHandle(pInventory));
  45.                 thisTable->Delegate(GetMethodsTable());
  46.  
  47.                 pScriptTable->SetValue("inventory", thisTable);
  48.         }
  49. }
  50.  
  51. //------------------------------------------------------------------------
  52. void CScriptBind_Inventory::DetachFrom(CInventory* pInventory)
  53. {
  54.         IScriptTable* pScriptTable = pInventory->GetEntity()->GetScriptTable();
  55.  
  56.         if (pScriptTable)
  57.                 pScriptTable->SetToNull("inventory");
  58. }
  59.  
  60. //------------------------------------------------------------------------
  61. void CScriptBind_Inventory::RegisterGlobals()
  62. {
  63. }
  64.  
  65. //------------------------------------------------------------------------
  66. void CScriptBind_Inventory::RegisterMethods()
  67. {
  68. #undef SCRIPT_REG_CLASSNAME
  69. #define SCRIPT_REG_CLASSNAME &CScriptBind_Inventory::
  70.  
  71.         SCRIPT_REG_TEMPLFUNC(Destroy, "");
  72.         SCRIPT_REG_TEMPLFUNC(Clear, "");
  73.  
  74.         SCRIPT_REG_TEMPLFUNC(Dump, "");
  75.  
  76.         SCRIPT_REG_TEMPLFUNC(GetItemByClass, "className");
  77.         SCRIPT_REG_TEMPLFUNC(GetGrenadeWeaponByClass, "className");
  78.         SCRIPT_REG_TEMPLFUNC(HasAccessory, "accessoryName");
  79.  
  80.         SCRIPT_REG_TEMPLFUNC(GetCurrentItemId, "");
  81.         SCRIPT_REG_TEMPLFUNC(GetCurrentItem, "");
  82.         SCRIPT_REG_TEMPLFUNC(GetAmmoCapacity, "ammoName");
  83.         SCRIPT_REG_TEMPLFUNC(GetAmmoCount, "ammoName");
  84.         SCRIPT_REG_TEMPLFUNC(SetAmmoCount, "ammoName, count");
  85. }
  86.  
  87. //------------------------------------------------------------------------
  88. CInventory* CScriptBind_Inventory::GetInventory(IFunctionHandler* pH)
  89. {
  90.         return (CInventory*)pH->GetThis();
  91. }
  92.  
  93. //------------------------------------------------------------------------
  94. int CScriptBind_Inventory::Destroy(IFunctionHandler* pH)
  95. {
  96.         CInventory* pInventory = GetInventory(pH);
  97.         CRY_ASSERT(pInventory);
  98.  
  99.         pInventory->Destroy();
  100.         return pH->EndFunction();
  101. }
  102.  
  103. //------------------------------------------------------------------------
  104. int CScriptBind_Inventory::Clear(IFunctionHandler* pH)
  105. {
  106.         CInventory* pInventory = GetInventory(pH);
  107.         CRY_ASSERT(pInventory);
  108.  
  109.         pInventory->Clear();
  110.         return pH->EndFunction();
  111. }
  112.  
  113. //------------------------------------------------------------------------
  114. int CScriptBind_Inventory::Dump(IFunctionHandler* pH)
  115. {
  116.  
  117. #if DEBUG_INVENTORY_ENABLED
  118.         CInventory* pInventory = GetInventory(pH);
  119.         CRY_ASSERT(pInventory);
  120.  
  121.         pInventory->Dump();
  122. #endif
  123.  
  124.         return pH->EndFunction();
  125. }
  126.  
  127. //------------------------------------------------------------------------
  128. int CScriptBind_Inventory::GetItemByClass(IFunctionHandler* pH, const char* className)
  129. {
  130.         CInventory* pInventory = GetInventory(pH);
  131.         CRY_ASSERT(pInventory);
  132.  
  133.         IEntityClass* pClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass(className);
  134.         EntityId itemId = pInventory->GetItemByClass(pClass);
  135.         if (itemId)
  136.                 return pH->EndFunction(ScriptHandle(itemId));
  137.  
  138.         return pH->EndFunction();
  139. }
  140.  
  141. //----------------------------------------------------------------------
  142. int CScriptBind_Inventory::GetGrenadeWeaponByClass(IFunctionHandler* pH, const char* className)
  143. {
  144.         CInventory* pInventory = GetInventory(pH);
  145.         CRY_ASSERT(pInventory);
  146.  
  147.         IEntityClass* pClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass(className);
  148.         EntityId itemId = pInventory->GetItemByClass(pClass, NULL);
  149.         if (itemId)
  150.                 return pH->EndFunction(ScriptHandle(itemId));
  151.  
  152.         return pH->EndFunction();
  153. }
  154.  
  155. //-------------------------------------------------------------------
  156. int CScriptBind_Inventory::HasAccessory(IFunctionHandler* pH, const char* accessoryName)
  157. {
  158.         CInventory* pInventory = GetInventory(pH);
  159.         CRY_ASSERT(pInventory);
  160.  
  161.         IEntityClass* pClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass(accessoryName);
  162.         if (pClass)
  163.                 return pH->EndFunction(pInventory->HasAccessory(pClass));
  164.  
  165.         return pH->EndFunction();
  166. }
  167.  
  168. //------------------------------------------------------------------------
  169. int CScriptBind_Inventory::GetCurrentItemId(IFunctionHandler* pH)
  170. {
  171.         CInventory* pInventory = GetInventory(pH);
  172.         CRY_ASSERT(pInventory);
  173.  
  174.         EntityId currentItemId = pInventory->GetCurrentItem();
  175.         if (currentItemId)
  176.                 return pH->EndFunction(ScriptHandle(currentItemId));
  177.         return pH->EndFunction();
  178. }
  179.  
  180. //------------------------------------------------------------------------
  181. int CScriptBind_Inventory::GetCurrentItem(IFunctionHandler* pH)
  182. {
  183.         CInventory* pInventory = GetInventory(pH);
  184.         CRY_ASSERT(pInventory);
  185.  
  186.         EntityId currentItemId = pInventory->GetCurrentItem();
  187.         if (currentItemId)
  188.         {
  189.                 IEntity* pEntity = m_pEntitySystem->GetEntity(currentItemId);
  190.                 if (pEntity)
  191.                         return pH->EndFunction(pEntity->GetScriptTable());
  192.         }
  193.         return pH->EndFunction();
  194. }
  195.  
  196. //------------------------------------------------------------------------
  197. int CScriptBind_Inventory::GetAmmoCapacity(IFunctionHandler* pH, const char* ammoName)
  198. {
  199.         CInventory* pInventory = GetInventory(pH);
  200.         CRY_ASSERT(pInventory);
  201.  
  202.         IEntityClass* pClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass(ammoName);
  203.         CRY_ASSERT(pClass);
  204.         return pH->EndFunction(pInventory->GetAmmoCapacity(pClass));
  205. }
  206.  
  207. //------------------------------------------------------------------------
  208. int CScriptBind_Inventory::GetAmmoCount(IFunctionHandler* pH, const char* ammoName)
  209. {
  210.         CInventory* pInventory = GetInventory(pH);
  211.         CRY_ASSERT(pInventory);
  212.  
  213.         IEntityClass* pClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass(ammoName);
  214.         CRY_ASSERT(pClass);
  215.         return pH->EndFunction(pInventory->GetAmmoCount(pClass));
  216. }
  217.  
  218. //------------------------------------------------------------------------
  219. int CScriptBind_Inventory::SetAmmoCount(IFunctionHandler* pH, const char* ammoName, int count)
  220. {
  221.         CInventory* pInventory = GetInventory(pH);
  222.         CRY_ASSERT(pInventory);
  223.  
  224.         IEntityClass* pClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass(ammoName);
  225.         CRY_ASSERT(pClass);
  226.         if (pClass)
  227.         {
  228.                 pInventory->SetAmmoCount(pClass, count);
  229.                 if (gEnv->bServer)
  230.                 {
  231.                         pInventory->GetActor()->GetGameObject()->InvokeRMI(CInventory::Cl_SetAmmoCount(),
  232.                                                                            TRMIInventory_Ammo(ammoName, count),
  233.                                                                            eRMI_ToRemoteClients);
  234.                 }
  235.         }
  236.         else
  237.         {
  238.                 CryWarning(VALIDATOR_MODULE_GAME, VALIDATOR_ERROR, "Ammo class %s not found!", ammoName);
  239.         }
  240.  
  241.         return pH->EndFunction();
  242. }
  243.  
downloadScriptBind_Inventory.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