本文整理汇总了C++中IWeapon::AddEventListener方法的典型用法代码示例。如果您正苦于以下问题:C++ IWeapon::AddEventListener方法的具体用法?C++ IWeapon::AddEventListener怎么用?C++ IWeapon::AddEventListener使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IWeapon
的用法示例。
在下文中一共展示了IWeapon::AddEventListener方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Serialize
void Serialize(SActivationInfo* pActInfo, TSerialize ser)
{
ser.Value("active", m_active);
ser.Value("ammo", m_ammo);
ser.Value("weaponId", m_weapId);
if (ser.IsReading())
{
if (m_active && m_weapId != 0)
{
IItemSystem* pItemSys = CCryAction::GetCryAction()->GetIItemSystem();
IItem* pItem = pItemSys->GetItem(m_weapId);
if (!pItem || !pItem->GetIWeapon())
{
GameWarning("[flow] CFlowNode_WeaponListener: Serialize no item/weapon.");
return;
}
IWeapon* pWeapon = pItem->GetIWeapon();
// set weapon listener
pWeapon->AddEventListener(this, "CFlowNode_WeaponListener");
// CryLog("[flow] CFlowNode_WeaponListener::Serialize() successfully created on '%s'", pItem->GetEntity()->GetName());
}
else
{
Reset();
}
}
}
示例2: ProcessEvent
void ProcessEvent( EFlowEvent event, SActivationInfo *pActInfo )
{
IWeapon* pWeapon = GetWeapon(pActInfo);
if (!pWeapon)
return;
switch (event)
{
case eFE_Initialize:
{
m_isFiring = false;
m_numShots = GetPortInt( pActInfo, IN_NUMBEROFSHOTS );
m_actInfo = *pActInfo;
m_numShotsDone = 0;
pWeapon->StopFire();
if (pActInfo->pEntity->GetId() != m_weapId)
RemoveListener(m_weapId, this);
m_weapId = pActInfo->pEntity->GetId();
pWeapon->AddEventListener(this, __FUNCTION__);
#ifdef DEBUG_NODEFIREWEAPON
pActInfo->pGraph->SetRegularlyUpdated( pActInfo->myID, true );
#endif
break;
}
case eFE_Activate:
{
m_actInfo = *pActInfo;
if (IsPortActive(pActInfo, IN_NUMBEROFSHOTS))
m_numShots = GetPortBool( pActInfo, IN_NUMBEROFSHOTS );
if (IsPortActive(pActInfo, IN_STOPFIRE))
{
StopFiring( pActInfo, pWeapon );
}
if (IsPortActive(pActInfo, IN_STARTFIRE))
{
m_numShotsDone = 0;
ReplenishAmmo( pWeapon );
pWeapon->StopFire();
StartFiring( pActInfo, pWeapon );
}
break;
}
case eFE_Update:
{
// this fixes the problem when the entity is being externally moved/rotated, in the interval of time between when the weapon is aimed an the actual shot happens
if (m_isFiring && GetPortBool( pActInfo, IN_ALIGNTOTARGET ))
if (pActInfo->pEntity->GetWorldPos()!=m_lastPos || pActInfo->pEntity->GetWorldRotation()!=m_lastRotation)
CalcFiringPosition( pActInfo, pWeapon );
#ifdef DEBUG_NODEFIREWEAPON
ColorB colorRed( 255,0,0 );
ColorB colorGreen( 0,255,0 );
gEnv->pRenderer->GetIRenderAuxGeom()->DrawLine( posOrig, colorRed, posTarget, colorRed );
gEnv->pRenderer->GetIRenderAuxGeom()->DrawLine( posTarget, colorGreen, posShot, colorGreen );
#endif
break;
}
}
}