Пример #1
0
//------------------------------------------------------------------------
int CScriptBind_Weapon::SetAmmoCount(IFunctionHandler *pH)
{
	CWeapon *pWeapon = GetWeapon(pH);
	if (!pWeapon)
		return pH->EndFunction();

	IFireMode *pFireMode = pWeapon->GetFireMode(pWeapon->GetCurrentFireMode());

	if (pFireMode)
	{
		if (pH->GetParamType(2) != svtNumber)
			return pH->EndFunction();

		const char *ammoName = 0;
		if (pH->GetParamType(1) == svtString)
			pH->GetParam(1, ammoName);

		IEntityClass* pAmmoType = pFireMode->GetAmmoType();

		if (ammoName)
			pAmmoType = gEnv->pEntitySystem->GetClassRegistry()->FindClass(ammoName);

		int ammo = 0;
		pH->GetParam(2, ammo);

		pWeapon->SetAmmoCount(pAmmoType, ammo);
	}

	return pH->EndFunction();
}
	EStatus Update(float timePassed)
	{
		if (IsTransitioningOut())
		{
			const float ROTATION_LERP_SPEED = 10.0f;

			//--- Blend body rotation to match current view
			Ang3 targetViewDir = m_player.GetAngles();
			Quat targetRotation = Quat::CreateRotationZ(targetViewDir.z);
			Quat newRotation = Quat::CreateNlerp(m_player.GetEntity()->GetRotation(), targetRotation, timePassed*ROTATION_LERP_SPEED);
			m_player.GetEntity()->SetRotation(newRotation);
		}
		else
		{
			static uint32 leanParamCRC = gEnv->pSystem->GetCrc32Gen()->GetCRC32Lowercase("SlideFactor");

			const Matrix34 &worldTM = m_player.GetEntity()->GetWorldTM();
			const Vec3 baseRgt = worldTM.GetColumn0();
			const Vec3 baseFwd = worldTM.GetColumn1();
			const Vec3 lookFwd = m_player.GetViewQuatFinal().GetColumn1();
			const float leanAngle = cry_acosf(baseFwd.Dot(lookFwd));

			float targetLeanFactor = clamp(leanAngle / MAX_LEAN_ANGLE, 0.0f, 1.0f);
			if (baseRgt.Dot(lookFwd) < 0.0f)
			{
				targetLeanFactor *= -1.0f;
			}
			CWeapon *pWeapon = m_player.GetWeapon(m_player.GetCurrentItemId());
			if (pWeapon)
			{
				IFireMode *pFiremode = pWeapon->GetFireMode(pWeapon->GetCurrentFireMode());
				if (pFiremode && (pFiremode->GetNextShotTime() > 0.0f))
				{
					targetLeanFactor = 0.0f;
				}
			}
			const float delta					= targetLeanFactor - m_leanFactor;
			const float step					= LEAN_RATE * timePassed;
			const float newLeanFactor	= (float)__fsel(delta, min(m_leanFactor + step, targetLeanFactor), max(m_leanFactor - step, targetLeanFactor));
			SWeightData weightData;
			weightData.weights[0] = newLeanFactor;
			SetParam(leanParamCRC, weightData);
			m_leanFactor = newLeanFactor;

			if (GetRootScope().IsDifferent(m_fragmentID, m_fragTags))
			{
				SetFragment(m_fragmentID, m_fragTags);
			}
		}

		return TPlayerAction::Update(timePassed);
	}
Пример #3
0
//------------------------------------------------------------------------
int CScriptBind_Weapon::GetCrosshair(IFunctionHandler *pH)
{
	CWeapon *pWeapon = GetWeapon(pH);
	if (!pWeapon)
		return pH->EndFunction();

	IFireMode *pFireMode = pWeapon->GetFireMode(pWeapon->GetCurrentFireMode());

	if (pFireMode)
		return pH->EndFunction(pFireMode->GetCrosshair());

	return pH->EndFunction();
}
Пример #4
0
//------------------------------------------------------------------------
int CScriptBind_Weapon::GetFireMode(IFunctionHandler *pH, int idx)
{
	CWeapon *pWeapon = GetWeapon(pH);
	if (!pWeapon)
		return pH->EndFunction();

	IFireMode* pFireMode = pWeapon->GetFireMode(idx);
	if (pFireMode)
	{
		return pH->EndFunction(pFireMode->GetName());
	}

	return pH->EndFunction();
}
Пример #5
0
//------------------------------------------------------------------------
int CScriptBind_Weapon::EnableFireMode(IFunctionHandler *pH, const char* name, bool enable)
{
		CWeapon *pWeapon = GetWeapon(pH);
		if (!pWeapon)
				return pH->EndFunction();

		IFireMode* pFireMode = pWeapon->GetFireMode(name);
		if (pFireMode)
		{
				pFireMode->Enable(enable);
		}

		return pH->EndFunction();
}
Пример #6
0
//------------------------------------------------------------------------
int CScriptBind_Weapon::GetAmmoType(IFunctionHandler *pH)
{
	CWeapon *pWeapon = GetWeapon(pH);
	if (!pWeapon)
		return pH->EndFunction();

	IFireMode *pFireMode = pWeapon->GetFireMode(pWeapon->GetCurrentFireMode());

	if (pFireMode)
		if (IEntityClass * pCls = pFireMode->GetAmmoType())
			return pH->EndFunction(pCls->GetName());

	return pH->EndFunction();
}
Пример #7
0
//------------------------------------------------------------------------
int CScriptBind_Weapon::IsFireModeEnabled(IFunctionHandler *pH, const char* name)
{
		CWeapon *pWeapon = GetWeapon(pH);
		if (!pWeapon)
				return pH->EndFunction();

		bool bIsEnabled = false;
		IFireMode* pFireMode = pWeapon->GetFireMode(name);
		if (pFireMode)
		{
				bIsEnabled = pFireMode->IsEnabled();
		}

		return pH->EndFunction(bIsEnabled);
}
Пример #8
0
int CScriptBind_Weapon::IsFiring(IFunctionHandler *pH)
{
	CWeapon *pWeapon = GetWeapon(pH);
	if (!pWeapon)
		return pH->EndFunction();

	int n=pWeapon->GetNumOfFireModes();
	for (int i=0;i<n;i++)
	{
		if (IFireMode *pFireMode=pWeapon->GetFireMode(i))
		{
			if (pFireMode->IsEnabled() && pFireMode->IsFiring())
				return pH->EndFunction(true);
		}
	}

	return pH->EndFunction();
}
Пример #9
0
void CHUDCrosshair::UpdateCrosshair()
{
  IActor *pClientActor = g_pGame->GetIGameFramework()->GetClientActor();
	if(!pClientActor)
		return;

  int iNewFriendly = 0;

  if(pClientActor->GetLinkedVehicle())
  { 
    // JanM/MichaelR: 
    // Get status from the VehicleWeapon, which raycasts considering the necessary SkipEntities (in contrast to WorldQuery)
    // Julien: this is now done in MP as well
    iNewFriendly = g_pHUD->GetVehicleInterface()->GetFriendlyFire();
  }
  else
  {
    if(!gEnv->bMultiplayer)
    {
			CWeapon *pWeapon = g_pHUD->GetCurrentWeapon();
			if(pWeapon)
			{
				iNewFriendly = pWeapon->IsWeaponLowered() && pWeapon->IsPendingFireRequest();
				if(iNewFriendly && pWeapon->GetEntity()->GetClass() == CItem::sTACGunFleetClass)
					iNewFriendly = 0;
			}
			else{
				//Two handed pickups need the red X as well
				CPlayer *pPlayer= static_cast<CPlayer*>(pClientActor);
				if(CWeapon *pOffHand = static_cast<CWeapon*>(pPlayer->GetItemByClass(CItem::sOffHandClass)))
					iNewFriendly = pOffHand->IsWeaponLowered();
			}
    }
    else
    {
	    EntityId uiCenterId = pClientActor->GetGameObject()->GetWorldQuery()->GetLookAtEntityId();
			if(uiCenterId)
			{
				iNewFriendly = IsFriendlyEntity(gEnv->pEntitySystem->GetEntity(uiCenterId));
			}
    }
  }	

	// SNH: if player is carrying a claymore or mine, ask the weapon whether it is possible to place it currently
	//	(takes into account player speed / stance / aim direction).
	// So 'friendly' is a bit of a misnomer here, but we want the "don't/can't fire" crosshair...
	if(iNewFriendly != 1 && g_pHUD)
	{
		CWeapon *pWeapon = g_pHUD->GetCurrentWeapon();
		if(pWeapon)
		{
			static IEntityClass* pClaymoreClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass("Claymore");
			static IEntityClass* pAVMineClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass("AVMine");
			IEntityClass* pClass = pWeapon->GetEntity()->GetClass();
			if(pClass == pClaymoreClass || pClass == pAVMineClass)
			{
				if(IFireMode* pfm = pWeapon->GetFireMode(pWeapon->GetCurrentFireMode()))
				{
					if(!pfm->IsFiring())
						iNewFriendly = pWeapon->CanFire() ? 0 : 1;
				}
			}
		}
	}

	if(iNewFriendly != m_iFriendlyTarget)
	{
		m_iFriendlyTarget = iNewFriendly;
		//m_animCrossHair.Invoke("setFriendly", m_iFriendlyTarget);
		if(iNewFriendly)
			m_animFriendCross.SetVisible(true);
		else
			m_animFriendCross.SetVisible(false);
	}

	if(m_animInterActiveIcons.GetVisible())
	{
		m_bHideUseIconTemp = false;
		CItem *pItem = static_cast<CItem*>(pClientActor->GetCurrentItem());
		if(pItem)
		{
			IWeapon *pWeapon = pItem->GetIWeapon();
			if(pWeapon)
			{
				CItem::SStats stats = pItem->GetStats();
				if(stats.mounted && stats.used)
					m_bHideUseIconTemp = true;
			}
		}
		if(!m_bHideUseIconTemp)
		{
			EntityId offHandId = pClientActor->GetInventory()->GetItemByClass(CItem::sOffHandClass);
			IItem *pOffHandItem = g_pGame->GetIGameFramework()->GetIItemSystem()->GetItem(offHandId);
			if(pOffHandItem)
			{
				COffHand *pOffHand = static_cast<COffHand*>(pOffHandItem);
				uint32 offHandState = pOffHand->GetOffHandState();
				if(offHandState == eOHS_HOLDING_OBJECT || offHandState == eOHS_THROWING_OBJECT ||
					offHandState == eOHS_HOLDING_NPC || offHandState == eOHS_THROWING_NPC)
					m_bHideUseIconTemp = true;
			}
		}
	}
}