本文整理汇总了C++中IWeapon::GetAmmoCount方法的典型用法代码示例。如果您正苦于以下问题:C++ IWeapon::GetAmmoCount方法的具体用法?C++ IWeapon::GetAmmoCount怎么用?C++ IWeapon::GetAmmoCount使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IWeapon
的用法示例。
在下文中一共展示了IWeapon::GetAmmoCount方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ProcessEvent
void ProcessEvent( EFlowEvent event, SActivationInfo *pActInfo )
{
switch (event)
{
case (eFE_Activate):
{
if (!IsPortActive(pActInfo, 0))
return;
IItemSystem* pItemSys = CCryAction::GetCryAction()->GetIItemSystem();
// get actor
IActor* pActor = CCryAction::GetCryAction()->GetClientActor();
if (!pActor)
return;
IInventory *pInventory = pActor->GetInventory();
if (!pInventory)
return;
IEntityClass* pClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass(GetPortString(pActInfo,1));
IItem* pItem = pItemSys->GetItem(pInventory->GetItemByClass(pClass));
if (!pItem || !pItem->GetIWeapon())
{
pItem = pActor->GetCurrentItem();
if (!pItem || pItem->GetEntity()->GetClass() != pClass || !pItem->GetIWeapon())
{
GameWarning("[flow] CFlowNode_WeaponAmmo: No item/weapon %s!", GetPortString(pActInfo,1).c_str());
return;
}
}
IWeapon *pWeapon = pItem->GetIWeapon();
const string& ammoType = GetPortString(pActInfo,2);
IEntityClass* pAmmoClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass(ammoType.c_str());
CRY_ASSERT(pAmmoClass);
IFireMode* pCurrentFireMode = pWeapon->GetFireMode(pWeapon->GetCurrentFireMode());
if (pCurrentFireMode)
{
int clipSize = pCurrentFireMode->GetClipSize();
int ammo = pWeapon->GetAmmoCount(pAmmoClass) + GetPortInt(pActInfo,3);
ammo = CLAMP(ammo, 0, clipSize);
pWeapon->SetAmmoCount(pAmmoClass, ammo);
}
ActivateOutput(pActInfo, 0, pWeapon->GetAmmoCount(pAmmoClass));
}
break;
}
}
示例2: ProcessEvent
void ProcessEvent(EFlowEvent event, SActivationInfo* pActInfo)
{
if (event == eFE_Activate && (IsPortActive(pActInfo, IN_GET) || IsPortActive(pActInfo, IN_SET)))
{
IActor* pActor = GetInputActor(pActInfo);
if (!pActor)
return;
IInventory *pInventory = pActor->GetInventory();
if (pInventory)
{
const string& ammoType = GetPortString(pActInfo, IN_AMMOTYPE);
IEntityClass* pAmmoClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass(ammoType.c_str());
if (pAmmoClass)
{
if (IsPortActive(pActInfo, IN_SET))
{
const bool bAdd = GetPortBool(pActInfo, IN_ADD);
const int ammoAmount = GetPortInt(pActInfo, IN_AMMOCOUNT);
pInventory->SetAmmoCount(pAmmoClass, bAdd ? (ammoAmount + pInventory->GetAmmoCount(pAmmoClass)) : (ammoAmount));
}
int magazineAmmo = 0;
int inventoryAmmo = pInventory->GetAmmoCount(pAmmoClass);
if (IItem* pItem = pActor->GetCurrentItem())
{
IWeapon* pCurrentWeapon = GetWeapon(pItem->GetEntityId());
if (pCurrentWeapon)
{
magazineAmmo = pCurrentWeapon->GetAmmoCount(pAmmoClass);
}
}
ActivateOutput(pActInfo, OUT_MAGAZINE, magazineAmmo);
ActivateOutput(pActInfo, OUT_INVENTORY, inventoryAmmo);
ActivateOutput(pActInfo, OUT_TOTAL, (magazineAmmo + inventoryAmmo));
}
}
}
}