bool CLaser::GetFiringDir(EntityId weaponId, const IFireMode* pFireMode, Vec3& dir, const Vec3& probableHit, const Vec3& firingPos)
{
	CWeapon* pParentWeapon = GetWeapon();

	if (!m_laserBeam.IsLaserActivated())
		return false;

	if(gEnv->bMultiplayer && pParentWeapon && pParentWeapon->IsZoomed())
	{
		return false;
	}

	if(!probableHit.IsZero() && !firingPos.IsZero())
	{
		dir = (probableHit - firingPos).GetNormalized();

		return true;
	}


	if (pParentWeapon)
	{
		int slot = pParentWeapon->IsOwnerFP() ? eIGS_FirstPerson : eIGS_ThirdPerson;

		Matrix33 rotation = pParentWeapon->GetSlotHelperRotation(slot, "weapon_term", true);

		dir = rotation.GetColumn1();
		return true;
	}

	return false;
}
bool CLaser::GetProbableHit(EntityId weaponId, const IFireMode* pFireMode, Vec3& hit)
{
	if (!m_laserBeam.IsLaserActivated())
		return false;

	if(gEnv->bMultiplayer)
	{
		CWeapon* pParentWeapon = GetWeapon();
		if (pParentWeapon && pParentWeapon->IsZoomed())
		{
			return false;
		}
	}

	CWeapon* pWeapon = GetWeapon();
	int slot = pWeapon->IsOwnerFP() ? eIGS_FirstPerson : eIGS_ThirdPerson;

	Vec3 lastBeamHit = m_laserBeam.GetLastHit();
	Vec3 currentBeamPosition = pWeapon->GetSlotHelperPos(slot, "weapon_term", true);
	Matrix33 rotation = pWeapon->GetSlotHelperRotation(slot, "weapon_term", true);
	Vec3 currentBeamDirection = rotation.GetColumn1();

	const CFireMode* pCFireMode = static_cast<const CFireMode*>(pFireMode);
	const CSingle* pSingle = crygti_cast<const CSingle*>(pCFireMode);
	if (pSingle && pSingle->GetShared()->fireparams.laser_beam_uses_spread)
	{
		currentBeamDirection = pSingle->ApplySpread(currentBeamDirection, pSingle->GetSpread());
	}

	float distanceToLastHit = lastBeamHit.GetDistance(currentBeamPosition);
	hit = currentBeamPosition + currentBeamDirection * distanceToLastHit;

	return true;
}
//--------------------------------------------
void CLaser::TurnOnLaser(bool manual /*= false*/)
{
	CWeapon* pParentWeapon = GetWeapon();
	if(pParentWeapon == NULL)
		return;

	m_laserHelperFP.clear();
	const SAccessoryParams *params = GetWeapon()->GetAccessoryParams(GetEntity()->GetClass());
	if (params)
		m_laserHelperFP = params->attach_helper;

	int slot = pParentWeapon->IsOwnerFP() ? eIGS_FirstPerson: eIGS_ThirdPerson;

	CActor* pOwner = pParentWeapon->GetOwnerActor();
	GetGameObject()->EnableUpdateSlot(this, eIUS_General);
	if (pOwner && pOwner->IsPlayer())
		pParentWeapon->SetFiringLocator(this);
	m_laserBeam.TurnOnLaser();

	//Turn off crosshair
	if (pParentWeapon->IsOwnerClient())
	{
		pParentWeapon->SetCrosshairMode(CWeapon::eWeaponCrossHair_ForceOff);
		pParentWeapon->FadeCrosshair(0.0f, g_pGame->GetUI()->GetCVars()->hud_Crosshair_laser_fadeOutTime);
	}
}
bool CLaser::GetFiringPos(EntityId weaponId, const IFireMode* pFireMode, Vec3& pos)
{
	CWeapon* pParentWeapon = GetWeapon();

	if (!m_laserBeam.IsLaserActivated())
		return false;
	
	if (pParentWeapon && (!gEnv->bMultiplayer ||!pParentWeapon->IsZoomed()))
	{
		int slot = pParentWeapon->IsOwnerFP() ? eIGS_FirstPerson : eIGS_ThirdPerson;

		pos = pParentWeapon->GetSlotHelperPos(slot, "weapon_term", true);
		return true;
	}

	return false;
}
//--------------------------------------------
void CLaser::TurnOffLaser(bool manual /*= false*/)
{
	if(!m_laserBeam.IsLaserActivated())
		return;

	GetGameObject()->DisableUpdateSlot(this, eIUS_General);

	CWeapon* pParentWeapon = GetWeapon();
	if(pParentWeapon == NULL)
		return;
	bool ownerIsFP = pParentWeapon? pParentWeapon->IsOwnerFP(): false;

	m_laserBeam.TurnOffLaser();

	//Turn on crosshair
	if (pParentWeapon->IsOwnerClient())
	{
		pParentWeapon->SetCrosshairMode(CWeapon::eWeaponCrossHair_Default);
		pParentWeapon->FadeCrosshair(1.0f, g_pGame->GetUI()->GetCVars()->hud_Crosshair_laser_fadeInTime);
	}

	pParentWeapon->SetFiringLocator(0);
}
Beispiel #6
0
void CFlashLight::EnableLight(bool enable)
{
	CWeapon* pWeapon = GetWeapon();

	if (!pWeapon || !m_sharedparams->pFlashLightParams || (m_lightEnabled && enable) || (!m_lightEnabled && !enable))
	{
		return;
	}

	CActor* pOwner = pWeapon->GetOwnerActor();
	bool ownerIsFP = pWeapon->IsOwnerFP();
	int slot = ownerIsFP ? eIGS_FirstPerson : eIGS_ThirdPerson;

	if (enable)
	{
		const char* attachHelper = "light_term";
		const Vec3 direction = Vec3(-1.0f, 0.0f, 0.0f);

		IRenderNode* pCasterException = NULL;

		if (pOwner)
		{
			IComponentRender* pRenderProxy = static_cast<IComponentRender*>(pOwner->GetEntity()->GetComponent<IComponentRender>().get());

			if (pRenderProxy)
			{
				pCasterException = pRenderProxy->GetRenderNode();
			}
		}

		EntityEffects::SLightAttachParams lightParams;

		lightParams.pCasterException = pCasterException;
		lightParams.color = m_sharedparams->pFlashLightParams->color * m_sharedparams->pFlashLightParams->diffuseMult;
		lightParams.direction = direction;
		lightParams.radius = m_sharedparams->pFlashLightParams->distance;
		lightParams.specularMultiplier = m_sharedparams->pFlashLightParams->specularMult;
		lightParams.projectFov = m_sharedparams->pFlashLightParams->fov;
		lightParams.hdrDynamic = m_sharedparams->pFlashLightParams->HDRDynamic;
		lightParams.projectTexture = m_sharedparams->pFlashLightParams->lightCookie.c_str();
		lightParams.style = m_sharedparams->pFlashLightParams->style;
		lightParams.animSpeed = m_sharedparams->pFlashLightParams->animSpeed;
		lightParams.castShadows = g_pGameCVars->i_flashlight_has_shadows != 0;
		lightParams.firstSafeSlot = eIGS_Last;

		m_lightId = pWeapon->AttachLight(slot, attachHelper, lightParams);

		EnableFogVolume(pWeapon, slot, true);
	}
	else
	{
		if (m_lightId)
		{
			pWeapon->DetachEffect(m_lightId);
		}

		m_lightId = 0;
		EnableFogVolume(pWeapon, slot, false);
	}

	m_lightEnabled = enable;
}