void C_ASW_Snow_Volume::UpdateSnow(C_ASW_Player *pPlayer)
{
	if (!pPlayer)
		return;

	if (g_hSnowEmitter.IsValid())
	{
		C_ASW_Marine *pMarine = pPlayer->GetViewMarine();

		Vector vecSnowPos;
		if (pMarine)
			vecSnowPos = pMarine->GetAbsOrigin();
		else
			vecSnowPos = pPlayer->m_vecLastMarineOrigin;

		vecSnowPos += Vector(0,0,52);

		if (g_hSnowEmitter->m_hLastMarine.Get() != pMarine)
		{
			g_hSnowEmitter->SetSortOrigin(vecSnowPos);
			g_hSnowEmitter->GetBinding().DetectChanges();
			//g_hSnowEmitter->DoPresimulate(vecSnowPos, QAngle(0,0,0));
			//if (g_hSnowCloudEmitter.IsValid())
				//g_hSnowCloudEmitter->DoPresimulate(vecSnowPos, QAngle(0,0,0));
		}
		g_hSnowEmitter->m_hLastMarine = pMarine;
		g_hSnowEmitter->Think(gpGlobals->frametime, vecSnowPos, QAngle(0,0,0));
		//if (g_hSnowCloudEmitter.IsValid())
			//g_hSnowCloudEmitter->Think(gpGlobals->frametime, vecSnowPos, QAngle(0,0,0));
	}
}
void asw_mesh_emitter_test_f()
{
	C_ASW_Player *pPlayer = C_ASW_Player::GetLocalASWPlayer();
	if (pPlayer && pPlayer->GetMarine())
	{
		C_ASW_Marine *pMarine = pPlayer->GetMarine();
		C_ASW_Mesh_Emitter *pEmitter = new C_ASW_Mesh_Emitter;
		if (pEmitter)
		{
			if (pEmitter->InitializeAsClientEntity( "models/swarm/DroneGibs/dronepart01.mdl", false ))
			{
				Vector vecForward;
				AngleVectors(pMarine->GetAbsAngles(), &vecForward);
				Vector vecEmitterPos = pMarine->GetAbsOrigin() + vecForward * 200.0f;
				Q_snprintf(pEmitter->m_szTemplateName, sizeof(pEmitter->m_szTemplateName), "dronegiblots");
				pEmitter->m_fScale = 1.0f;
				pEmitter->m_bEmit = true;
				pEmitter->SetAbsOrigin(vecEmitterPos);
				pEmitter->CreateEmitter(vec3_origin);
				pEmitter->SetAbsOrigin(vecEmitterPos);
				pEmitter->SetDieTime(gpGlobals->curtime + 15.0f);
			}
			else
			{
				pEmitter->Release();
			}
		}
	}
}
// Actual work code
IterationRetval_t CASW_MarineAndObjectEnumerator::EnumElement( IHandleEntity *pHandleEntity )
{
	if ( !m_pLocal )
		return ITERATION_STOP;

	C_BaseEntity *pEnt = ClientEntityList().GetBaseEntityFromHandle( pHandleEntity->GetRefEHandle() );
	if ( pEnt == NULL )
		return ITERATION_CONTINUE;

	if ( pEnt == m_pLocal )
		return ITERATION_CONTINUE;

	if ( !pEnt->IsPlayer() &&
		 !pEnt->IsNPC() )
	{
		return ITERATION_CONTINUE;
	}

	if ( pEnt->IsNPC() )
	{
		C_AI_BaseNPC *pNPC = (C_AI_BaseNPC *)pEnt;

		if ( !pNPC->ShouldAvoidObstacle() )
			 return ITERATION_CONTINUE;
	}

	// Ignore vehicles, since they have vcollide collisions that's push me away
	if ( pEnt->GetCollisionGroup() == COLLISION_GROUP_VEHICLE )
		return ITERATION_CONTINUE;

#ifdef TF2_CLIENT_DLL
	// If it's solid to player movement, don't steer around it since we'll just bump into it
	if ( pEnt->GetCollisionGroup() == TFCOLLISION_GROUP_OBJECT_SOLIDTOPLAYERMOVEMENT )
		return ITERATION_CONTINUE;
#endif

	C_ASW_Marine *pMarine = m_pLocal->GetMarine();
	if (!pMarine)
		return ITERATION_CONTINUE;

	Vector	deltaPos = pEnt->GetAbsOrigin() - pMarine->GetAbsOrigin();
	//if ( deltaPos.LengthSqr() > m_flRadiusSquared )
		//return ITERATION_CONTINUE;

	CHandle< C_BaseEntity > h;
	h = pEnt;
	m_Objects.AddToTail( h );

	return ITERATION_CONTINUE;
}
	// if the player has his mouse over another marine, highlight it, cos he's the one we can give health to
	void CASW_Weapon_Medical_Satchel::MouseOverEntity(C_BaseEntity *pEnt, Vector vecWorldCursor)
	{
		C_ASW_Marine* pOtherMarine = C_ASW_Marine::AsMarine( pEnt );
		CASW_Player *pOwner = GetCommander();
		CASW_Marine *pMarine = GetMarine();
		if (!pOwner || !pMarine)
			return;

		float fOtherHealth = 1.0f;
		if (pOtherMarine && pOtherMarine->GetMarineResource())
			fOtherHealth = pOtherMarine->GetMarineResource()->GetHealthPercent();
		if (!pOtherMarine)
		{
			C_ASW_Game_Resource *pGameResource = ASWGameResource();
			if (pGameResource)
			{
				// find marine closest to world cursor
				const float fMustBeThisClose = 70;
				const C_ASW_Game_Resource::CMarineToCrosshairInfo::tuple_t &info = pGameResource->GetMarineCrosshairCache()->GetClosestMarine();
				if ( info.m_fDistToCursor <= fMustBeThisClose )
				{
					pOtherMarine = info.m_hMarine.Get();
				}
			}
		}

		// if the marine our cursor is over is near enough, highlight him
		if (pOtherMarine)
		{
			float dist = (pMarine->GetAbsOrigin() - pOtherMarine->GetAbsOrigin()).Length2D();
			if (dist < MAX_HEAL_DISTANCE)
			{
				bool bCanGiveHealth = ( fOtherHealth < 1.0f && m_iClip1 > 0 );
				ASWInput()->SetHighlightEntity( pOtherMarine, bCanGiveHealth );
				if ( bCanGiveHealth )		// if he needs healing, show the give health cursor
				{
					CASWHudCrosshair *pCrosshair = GET_HUDELEMENT( CASWHudCrosshair );
					if ( pCrosshair )
					{
						pCrosshair->SetShowGiveHealth(true);
					}
				}
			}
		}		
	}
void C_Prop_ASW_Fade::ClientThink()
{
	BaseClass::ClientThink();

	C_ASW_Player *pPlayer = C_ASW_Player::GetLocalASWPlayer();
	if (!pPlayer)
	{
		return;
	}

	C_ASW_Marine *pMarine = pPlayer->GetViewMarine();

	bool bFade = pPlayer->GetASWControls() == 1 && pMarine && pMarine->GetAbsOrigin().z <= m_vecFadeOrigin.z;
	byte target = bFade ? m_nFadeOpacity : m_nNormalOpacity;
	byte prev = bFade ? m_nNormalOpacity : m_nFadeOpacity;
	if (bFade != m_bFaded)
	{
		m_bFaded = bFade;
		m_flInterpStart = gpGlobals->curtime - fabs((m_nFadeOpacity != m_nNormalOpacity) ? asw_fade_duration.GetFloat() * (GetRenderAlpha() - prev) / (m_nFadeOpacity - m_nNormalOpacity) : asw_fade_duration.GetFloat());
		m_flInterpStart = MAX(0, m_flInterpStart);
	}

	if ( pPlayer->GetASWControls() != m_iLastControls || pMarine != m_hLastMarine.Get() )
	{
		m_iLastControls = pPlayer->GetASWControls();
		m_hLastMarine = pMarine;
		m_flInterpStart = 0;
		SetRenderAlpha(target);
		return;
	}

	if (m_flInterpStart + asw_fade_duration.GetFloat() <= gpGlobals->curtime)
	{
		SetRenderAlpha(target);
	}
	else if (m_flInterpStart > 0)
	{
		SetRenderAlpha(Lerp((gpGlobals->curtime - m_flInterpStart) / asw_fade_duration.GetFloat(), prev, target));
	}
}
Esempio n. 6
0
static void GetPos( const CCommand &args, Vector &vecOrigin, QAngle &angles )
{
	int nSlot = GET_ACTIVE_SPLITSCREEN_SLOT();
	vecOrigin = MainViewOrigin(nSlot);
	angles = MainViewAngles(nSlot);

#ifdef INFESTED_DLL
	C_ASW_Marine *pMarine = C_ASW_Marine::GetLocalMarine();
	if ( pMarine )
	{
		vecOrigin = pMarine->GetAbsOrigin();
		angles = pMarine->GetAbsAngles();
	}
#endif
	if ( ( args.ArgC() == 2 && atoi( args[1] ) == 2 ) || FStrEq( args[0], "getpos_exact" ) )
	{
		C_BasePlayer *pPlayer = C_BasePlayer::GetLocalPlayer();
		if ( pPlayer )
		{
			vecOrigin = pPlayer->GetAbsOrigin();
			angles = pPlayer->GetAbsAngles();
		}
	}
}
void C_SunlightShadowControl::ClientThink()
{
	VPROF("C_SunlightShadowControl::ClientThink");
	if ( m_bEnabled )
	{
		Vector vLinearFloatLightColor( m_LightColor.r, m_LightColor.g, m_LightColor.b );
		float flLinearFloatLightAlpha = m_LightColor.a;

		if ( m_CurrentLinearFloatLightColor != vLinearFloatLightColor || m_flCurrentLinearFloatLightAlpha != flLinearFloatLightAlpha )
		{
			float flColorTransitionSpeed = gpGlobals->frametime * m_flColorTransitionTime * 255.0f;

			m_CurrentLinearFloatLightColor.x = Approach( vLinearFloatLightColor.x, m_CurrentLinearFloatLightColor.x, flColorTransitionSpeed );
			m_CurrentLinearFloatLightColor.y = Approach( vLinearFloatLightColor.y, m_CurrentLinearFloatLightColor.y, flColorTransitionSpeed );
			m_CurrentLinearFloatLightColor.z = Approach( vLinearFloatLightColor.z, m_CurrentLinearFloatLightColor.z, flColorTransitionSpeed );
			m_flCurrentLinearFloatLightAlpha = Approach( flLinearFloatLightAlpha, m_flCurrentLinearFloatLightAlpha, flColorTransitionSpeed );
		}

		FlashlightState_t state;

		Vector vDirection = m_shadowDirection;
		VectorNormalize( vDirection );

		QAngle angView;
		engine->GetViewAngles( angView );

		//Vector vViewUp = Vector( 0.0f, 1.0f, 0.0f );
		Vector vSunDirection2D = vDirection;
		vSunDirection2D.z = 0.0f;

		HACK_GETLOCALPLAYER_GUARD( "C_SunlightShadowControl::ClientThink" );

#ifdef INFESTED_DLL		// shine sun on your current marine, rather than the player entity
		C_ASW_Marine *pMarine = C_ASW_Marine::GetLocalMarine();
		if ( !pMarine )
			return;

		Vector vPos = ( pMarine->GetAbsOrigin() + vSunDirection2D * m_flNorthOffset ) - vDirection * m_flSunDistance;
#else
		if ( !C_BasePlayer::GetLocalPlayer() )
			return;

		Vector vPos = ( C_BasePlayer::GetLocalPlayer()->GetAbsOrigin() + vSunDirection2D * m_flNorthOffset ) - vDirection * m_flSunDistance;
#endif

		QAngle angAngles;
		VectorAngles( vDirection, angAngles );

		Vector vForward, vRight, vUp;
		AngleVectors( angAngles, &vForward, &vRight, &vUp );

		state.m_fHorizontalFOVDegrees = m_flFOV;
		state.m_fVerticalFOVDegrees = m_flFOV;

		state.m_vecLightOrigin = vPos;
		BasisToQuaternion( vForward, vRight, vUp, state.m_quatOrientation );

		state.m_fQuadraticAtten = 0.0f;
		state.m_fLinearAtten = m_flSunDistance / 2.0f;
		state.m_fConstantAtten = 0.0f;
		state.m_FarZAtten = m_flSunDistance + 300.0f;
		state.m_Color[0] = m_CurrentLinearFloatLightColor.x * ( 1.0f / 255.0f ) * m_flCurrentLinearFloatLightAlpha;
		state.m_Color[1] = m_CurrentLinearFloatLightColor.y * ( 1.0f / 255.0f ) * m_flCurrentLinearFloatLightAlpha;
		state.m_Color[2] = m_CurrentLinearFloatLightColor.z * ( 1.0f / 255.0f ) * m_flCurrentLinearFloatLightAlpha;
		state.m_Color[3] = 0.0f; // fixme: need to make ambient work m_flAmbient;
		state.m_NearZ = fpmax( 4.0f, m_flSunDistance - m_flNearZ );
		state.m_FarZ = m_flSunDistance + 300.0f;

		float flOrthoSize = cl_sunlight_ortho_size.GetFloat();

		if ( flOrthoSize > 0 )
		{
			state.m_bOrtho = true;
			state.m_fOrthoLeft = -flOrthoSize;
			state.m_fOrthoTop = -flOrthoSize;
			state.m_fOrthoRight = flOrthoSize;
			state.m_fOrthoBottom = flOrthoSize;
		}
		else
		{
			state.m_bOrtho = false;
		}

		state.m_flShadowSlopeScaleDepthBias = 2;
		state.m_flShadowDepthBias = cl_sunlight_depthbias.GetFloat();
		state.m_bEnableShadows = m_bEnableShadows;
		state.m_pSpotlightTexture = m_SpotlightTexture;
		state.m_pProjectedMaterial = NULL;
		state.m_nSpotlightTextureFrame = 0;

		state.m_nShadowQuality = 1; // Allow entity to affect shadow quality
		state.m_bShadowHighRes = true;

		if ( m_bOldEnableShadows != m_bEnableShadows )
		{
			// If they change the shadow enable/disable, we need to make a new handle
			if ( m_LocalFlashlightHandle != CLIENTSHADOW_INVALID_HANDLE )
			{
				g_pClientShadowMgr->DestroyFlashlight( m_LocalFlashlightHandle );
				m_LocalFlashlightHandle = CLIENTSHADOW_INVALID_HANDLE;
			}

			m_bOldEnableShadows = m_bEnableShadows;
		}

		if( m_LocalFlashlightHandle == CLIENTSHADOW_INVALID_HANDLE )
		{
			m_LocalFlashlightHandle = g_pClientShadowMgr->CreateFlashlight( state );
		}
		else
		{
			g_pClientShadowMgr->UpdateFlashlightState( m_LocalFlashlightHandle, state );
#ifndef INFESTED_DLL
#pragma message("TODO: rebuild sunlight projected texture after sunlight control changes.")
			g_pClientShadowMgr->UpdateProjectedTexture( m_LocalFlashlightHandle, true );
#endif
		}
	}
	else if ( m_LocalFlashlightHandle != CLIENTSHADOW_INVALID_HANDLE )
	{
		g_pClientShadowMgr->DestroyFlashlight( m_LocalFlashlightHandle );
		m_LocalFlashlightHandle = CLIENTSHADOW_INVALID_HANDLE;
	}

	BaseClass::ClientThink();
}