Esempio n. 1
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 CASWHudCrosshair::GetCurrentPos( int &x, int &y )
{
	C_ASW_Player* pPlayer = C_ASW_Player::GetLocalASWPlayer();
	if ( !pPlayer )
		return;

	C_ASW_Marine *pMarine = pPlayer->GetViewMarine();
	bool bControllingTurret = (pMarine && pMarine->IsControllingTurret());

	m_pTurretTextTopLeft->SetVisible( bControllingTurret );
	m_pTurretTextTopRight->SetVisible( bControllingTurret );
	m_pTurretTextTopLeftGlow->SetVisible( bControllingTurret );
	m_pTurretTextTopRightGlow->SetVisible( bControllingTurret );

	if ( !bControllingTurret )
	{
		ASWInput()->GetSimulatedFullscreenMousePos( &x, &y );
	}
	else
	{
		x = ScreenWidth() / 2;
		y = ScreenHeight() / 2;
	}
}
void C_ASW_AOEGrenade_Projectile::UpdateTargetAOEEffects( void )
{
	// Find all the targets we've stopped giving a buff to
	AOEGrenTargetFXList_t::IndexLocalType_t i = m_hAOETargetEffects.Head();
	while ( m_hAOETargetEffects.IsValidIndex(i) )
	{
		AOETargetEffects_t &aoeTargetEffect = m_hAOETargetEffects[i];
		Assert( m_hAOETargetEffects[i].me == &m_hAOETargetEffects[i] );
		bool bStillAOEGren = false;

		// Are we still buffing this target?
		for ( int target = 0; target < m_hAOETargets.Count(); target++ )
		{
			if ( m_hAOETargets[target] && m_hAOETargets[target] == aoeTargetEffect.hTarget.Get() )
			{
				bStillAOEGren = true;
				break;
			}
		}

		// advance before deleting the pointer out from under us
		const AOEGrenTargetFXList_t::IndexLocalType_t oldi = i;
		i = m_hAOETargetEffects.Next( i );

		if ( !bStillAOEGren )
		{
			ParticleProp()->StopEmission( aoeTargetEffect.pEffect );

			// stop the sound on this marine
			C_ASW_Marine *pMarine = dynamic_cast<C_ASW_Marine*>( m_hAOETargetEffects[oldi].hTarget.Get() );
			if ( pMarine && pMarine->GetCommander() )
			{
				C_ASW_Player *pLocalPlayer = C_ASW_Player::GetLocalASWPlayer();
				if ( pMarine->GetCommander() == pLocalPlayer && pMarine->IsInhabited() && m_hAOETargetEffects[oldi].pBuffLoopSound )
				{
					CSoundEnvelopeController::GetController().SoundDestroy( m_hAOETargetEffects[oldi].pBuffLoopSound );
					m_hAOETargetEffects[oldi].pBuffLoopSound = NULL;
				}
			}

			m_hAOETargetEffects.Remove(oldi);
		}
	}

	// Now add any new targets
	for ( int i = 0; i < m_hAOETargets.Count(); i++ )
	{
		C_BaseEntity *pTarget = m_hAOETargets[i].Get();

		// Loops through the aoe targets, and make sure we have an effect for each of them
		if ( pTarget )
		{
			bool bHaveEffect = false;

			for ( AOEGrenTargetFXList_t::IndexLocalType_t i = m_hAOETargetEffects.Head() ;
				  m_hAOETargetEffects.IsValidIndex(i) ;
				  i = m_hAOETargetEffects.Next(i) )
			{
				if ( m_hAOETargetEffects[i].hTarget.Get() == pTarget )
				{
					bHaveEffect = true;
					break;
				}
			}

			if ( !bHaveEffect )
			{
				CNewParticleEffect *pEffect = ParticleProp()->Create( GetArcEffectName(), PATTACH_ABSORIGIN_FOLLOW );

				AOEGrenTargetFXList_t::IndexLocalType_t iIndex = m_hAOETargetEffects.AddToTail();
				m_hAOETargetEffects[iIndex].hTarget = pTarget;
				m_hAOETargetEffects[iIndex].pEffect = pEffect;
				Assert( m_hAOETargetEffects[iIndex].me == &m_hAOETargetEffects[iIndex] );

				UpdateParticleAttachments( m_hAOETargetEffects[iIndex].pEffect, pTarget );

				// Start the sound over again every time we start a new beam
				//StopSound( GetLoopSoundName() );

				C_ASW_Marine *pMarine = C_ASW_Marine::AsMarine( pTarget );
				if ( pMarine && pMarine->GetCommander() )
				{
					C_ASW_Player *pLocalPlayer = C_ASW_Player::GetLocalASWPlayer();
					if ( pMarine->GetCommander() == pLocalPlayer && pMarine->IsInhabited() )
					{
						if ( m_hAOETargetEffects[iIndex].pBuffLoopSound )
						{
							CSoundEnvelopeController::GetController().SoundDestroy( m_hAOETargetEffects[iIndex].pBuffLoopSound );
							m_hAOETargetEffects[iIndex].pBuffLoopSound = NULL;
						}

						CSingleUserRecipientFilter filter( pLocalPlayer );
						EmitSound( filter, pMarine->entindex(), GetStartSoundName() );
						m_hAOETargetEffects[iIndex].pBuffLoopSound = CSoundEnvelopeController::GetController().SoundCreate( filter, pMarine->entindex(), GetLoopSoundName() );
						CSoundEnvelopeController::GetController().Play( m_hAOETargetEffects[iIndex].pBuffLoopSound, 1.0, 100 );
					}
				}
			}
		}
	}
}
Esempio n. 4
0
void CASWHudWeapons::Paint()
{
	VPROF_BUDGET( "CASWHudWeapons::Paint", VPROF_BUDGETGROUP_ASW_CLIENT );
	GetSize(m_iFrameWidth,m_iFrameHeight);
	BaseClass::Paint();

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

	C_ASW_Marine *pMarine = pPlayer->GetMarine();
	if (!pMarine)
		return;		
	char cbuffer[64];

	if ( !m_hUseArea.Get() )
	{
		m_hUseArea = ( CASWHudUseArea * )GET_HUDELEMENT( CASWHudUseArea );
	}

	ASWUseAction* pUseAction = NULL;
	if ( m_hUseArea.Get() && m_hUseArea->m_pUseIcon )
	{
		pUseAction = m_hUseArea->m_pUseIcon->GetCurrentUseAction();
	}
	
	int r, g, b;
	
	int tall = m_iFrameHeight * 0.25f * asw_hud_scale.GetFloat();	// how tall to draw the weapon icons
	int spacing_y = tall * 0.7f;
	int nWeaponsToShow = asw_hotbar_self.GetBool() ? ASW_NUM_INVENTORY_SLOTS - 1 : ASW_NUM_INVENTORY_SLOTS;
	bool bPowOnWeapon = false;
	for ( int k = 0; k < nWeaponsToShow; k++ )
	{
		C_ASW_Weapon* pWeapon = pMarine->GetASWWeapon(k);
		// set draw color
		bool bActiveWeapon = (pWeapon && pWeapon == pMarine->GetActiveWeapon());
		if ( bActiveWeapon )
		{
			r = 255;
			g = 255;
			b = 255;
		}
		else
		{
			r = 66;	// light blue
			g = 142;
			b = 192;
		}
		
		if (asw_debug_hud.GetInt()!=0)
		{
			if (pWeapon)
			{
				Q_snprintf(cbuffer, sizeof(cbuffer), "%d:%s %d(%d)", k, pWeapon->GetClassname(),
					pWeapon->GetEffects(), pWeapon->IsEffectActive(EF_NODRAW));
			}
			else
			{
				b = 255;
				Q_snprintf(cbuffer, sizeof(cbuffer), "%d:Empty", k);
			}		
			g_pMatSystemSurface->DrawColoredText(m_hWeaponHUDFont, 0, k*tall, r, g, 
				b, 200, &cbuffer[0]);
		}

		// draw icon
		if (pWeapon && ASWEquipmentList())
		{
			int list_index = pWeapon->GetEquipmentListIndex();
			int iTexture = ASWEquipmentList()->GetEquipIconTexture(!pWeapon->GetWeaponInfo()->m_bExtra, list_index);
			if (iTexture != -1)
			{				
				surface()->DrawSetColor(Color(r,g,b,255));
				surface()->DrawSetTexture(iTexture);

				int icon_x_offset = pWeapon->GetWeaponInfo()->m_iHUDIconOffsetX * (m_iFrameWidth / 160.0f) * asw_hud_scale.GetFloat();
				int icon_y_offset = pWeapon->GetWeaponInfo()->m_iHUDIconOffsetY * (m_iFrameHeight / 160.0f) * asw_hud_scale.GetFloat();
				int text_x_offset = pWeapon->GetWeaponInfo()->m_iHUDNumberOffsetX * (m_iFrameWidth / 160.0f) * asw_hud_scale.GetFloat();
				int text_y_offset = pWeapon->GetWeaponInfo()->m_iHUDNumberOffsetY * (m_iFrameHeight / 160.0f) * asw_hud_scale.GetFloat();

				// drop shadow
				/*
				surface()->DrawSetColor(Color(0,0,0,255));
				if (pWeapon->GetWeaponInfo()->m_bExtra)
					surface()->DrawTexturedRect(icon_x_offset + 1, k*spacing_y + 1 + icon_y_offset,
												icon_x_offset + 1 + tall, k*spacing_y + tall + 1 + icon_y_offset);
				else
					surface()->DrawTexturedRect(icon_x_offset + 1, k*spacing_y + 1 + icon_y_offset,
												icon_x_offset + 1 + tall * 2, k*spacing_y + tall + 1 + icon_y_offset);
				*/

				//todo: set glow vars to make the weapon glow when it's currently selected
				/*
				bool foundVar;
				MaterialVar* pTextureVar = pMaterial->FindVar( "$basetexture", &foundVar, false );
				if (foundVar)
				{
					if ( bActiveWeapon )
					{

					}
					else
					{

					}
				}
				*/

				surface()->DrawSetColor(Color(r,g,b,255));
				if ( pWeapon->GetWeaponInfo()->m_bExtra )
				{
					surface()->DrawTexturedRect(icon_x_offset, k*spacing_y + icon_y_offset,
												icon_x_offset + tall, k*spacing_y + tall + icon_y_offset);
				}
				else
				{
					surface()->DrawTexturedRect(icon_x_offset, k*spacing_y + icon_y_offset,
												icon_x_offset + tall * 2, k*spacing_y + tall + icon_y_offset);
				}

				pWeaponPos[ k ]->SetBounds( icon_x_offset, k * spacing_y + icon_y_offset, tall * 2, tall );

				if ( pWeapon->m_bPoweredUp )
				{
					int iPowBuffer = m_iFrameHeight/20;
					m_pPowerups->SetBounds(icon_x_offset + (tall*2) + iPowBuffer, (k * spacing_y + icon_y_offset) + iPowBuffer, (tall*2), tall - (iPowBuffer*2));
					bPowOnWeapon = true;
				}

				// show charges?
				if (pWeapon->GetWeaponInfo()->m_bShowCharges)
				{
					Q_snprintf(cbuffer, sizeof(cbuffer), "%d", pWeapon->GetChargesForHUD() );
					g_pMatSystemSurface->DrawColoredText(m_hWeaponHUDFont, text_x_offset, 
						k*spacing_y + text_y_offset, r, g, 	b, 200, &cbuffer[0]); 
				}
				// show weapon swaps
				if ( asw_hud_swaps.GetBool() && pUseAction && pUseAction->iInventorySlot == k )
				{
					const CASW_WeaponInfo* pWeaponData = NULL;
					const char *szWeaponClass = NULL;
					C_ASW_Pickup_Weapon *pPickup = dynamic_cast<C_ASW_Pickup_Weapon*>( pUseAction->UseTarget.Get());
					if ( pPickup )
					{
						pWeaponData = ASWEquipmentList()->GetWeaponDataFor( pPickup->GetWeaponClass() );
						szWeaponClass = pPickup->GetWeaponClass();
					}
					else
					{
						C_ASW_Weapon *pWeapon = dynamic_cast<C_ASW_Weapon*>( pUseAction->UseTarget.Get() );
						if ( pWeapon )
						{
							pWeaponData = pWeapon->GetWeaponInfo();
							szWeaponClass = pWeapon->GetClassname();
						}
					}
					if ( pWeaponData )
					{
						int iEquipListIndex = pWeaponData->m_bExtra ? ASWEquipmentList()->GetExtraIndex( szWeaponClass )
							: ASWEquipmentList()->GetRegularIndex( szWeaponClass );
						int iSwapWeaponTexture = ASWEquipmentList()->GetEquipIconTexture( !pWeaponData->m_bExtra, iEquipListIndex );
						if ( m_nSwapArrowTexture != -1 && iSwapWeaponTexture != -1 )
						{
							surface()->DrawSetColor( Color( r,g,b,m_hUseArea->m_pUseIcon->m_pUseText->GetAlpha() ) );	// fade in along with the use icon
							icon_x_offset = tall * 2.0f;
							icon_y_offset = 0;
							surface()->DrawSetTexture( m_nSwapArrowTexture );
							surface()->DrawTexturedRect( icon_x_offset, k*spacing_y + icon_y_offset,
								icon_x_offset + tall, k*spacing_y + tall + icon_y_offset );

							icon_x_offset = tall * 3.0f + pWeaponData->m_iHUDIconOffsetX;
							icon_y_offset = pWeaponData->m_iHUDIconOffsetY;
							surface()->DrawSetTexture( iSwapWeaponTexture );
							surface()->DrawTexturedRect( icon_x_offset, k*spacing_y + icon_y_offset,
								icon_x_offset + ( pWeaponData->m_bExtra ? tall : tall * 2.0f ) , k*spacing_y + tall + icon_y_offset );
						}
					}
				}
			}
		}		
	}

	if ( !bPowOnWeapon )
	{
		//int iPowBuffer = m_iFrameHeight/20;
		int xpos = 12 * (m_iFrameWidth / 160.0f) * asw_hud_scale.GetFloat();
		//int ypos = 2 * (m_iFrameWidth / 160.0f) * asw_hud_scale.GetFloat();
		m_pPowerups->SetBounds(xpos, (spacing_y*nWeaponsToShow) + (spacing_y/3), tall, tall*0.75f );
	}
}
//-----------------------------------------------------------------------------
// Purpose: Message handler for ASWOrderUseItemFX message
//-----------------------------------------------------------------------------
void CASW_Hud_Squad_Hotbar::MsgFunc_ASWOrderUseItemFX( bf_read &msg )
{
	int iMarine = msg.ReadShort();	
	C_ASW_Marine *pMarine = dynamic_cast<C_ASW_Marine*>(ClientEntityList().GetEnt(iMarine));		// turn iMarine ent index into the marine
	if ( !pMarine )
		return;

	int iOrderType = msg.ReadShort();
	int iInventorySlot = msg.ReadShort();

	Vector vecPosition;
	vecPosition.x = msg.ReadFloat();
	vecPosition.y = msg.ReadFloat();
	vecPosition.z = msg.ReadFloat();

	// loops through to see if we already have an order effect for this marine
	StopItemFX( pMarine );

	const char *pszClassName = NULL;

	switch( iOrderType )
	{
	case ASW_USE_ORDER_WITH_ITEM:
		{
			// check we have an item in that slot
			CASW_Weapon* pWeapon = pMarine->GetASWWeapon( iInventorySlot );
			if ( !pWeapon || !pWeapon->GetWeaponInfo() || !pWeapon->GetWeaponInfo()->m_bOffhandActivate )
				return;

			pszClassName = pWeapon->GetClassname();
		}
		break;

	case ASW_USE_ORDER_HACK:
		{
			pszClassName = "asw_weapon_t75";	// for now, we're using the t75 icon for hacking
		}
		break;

	default:
		{
			Assert( false ); // unspecified order type
			return;
		}
		break;
	}

	//CNewParticleEffect *pEffect = pMarine->ParticleProp()->Create( "order_use_item", PATTACH_CUSTOMORIGIN, -1, vecPosition - pMarine->GetAbsOrigin() );
	CNewParticleEffect *pEffect = pMarine->ParticleProp()->Create( "order_use_item", PATTACH_ABSORIGIN );
	if ( pEffect )
	{
		pMarine->ParticleProp()->AddControlPoint( pEffect, 1, pMarine, PATTACH_CUSTOMORIGIN );
		pEffect->SetControlPoint( 1, vecPosition );//vecPosition - pMarine->GetAbsOrigin()
		for ( int i = 0; i < NUM_USE_ITEM_ORDER_CLASSES; i++ )
		{
			if ( pszUseItemOrderClasses[i] && !Q_strcmp (  pszUseItemOrderClasses[i]  ,  pszClassName )  )
			{
				pEffect->SetControlPoint( 2, Vector( i, 0, 0 ) );
				break;
			}
		}

		HotbarOrderEffectsList_t::IndexLocalType_t iIndex = m_hHotbarOrderEffects.AddToTail();
		m_hHotbarOrderEffects[iIndex].iEffectID = iMarine;
		m_hHotbarOrderEffects[iIndex].pEffect = pEffect;
	}
}
void CASW_Hud_Squad_Hotbar::UpdateList()
{
	if ( !ASWGameResource() )
		return;

	C_ASW_Player *pPlayer = C_ASW_Player::GetLocalASWPlayer();

	int iEntry = 0;
	bool bHasItem = false;
	if ( asw_hotbar_self.GetBool() )
	{
		if ( iEntry >= m_pEntries.Count() )
		{
			CASW_Hotbar_Entry *pPanel = new CASW_Hotbar_Entry( this, "SquadInventoryPanelEntry" );
			m_pEntries.AddToTail( pPanel );
			InvalidateLayout();
		}

		// add your offhand item to the hotbar first
		CASW_Marine *pPlayerMarine = pPlayer->GetMarine();
		if ( pPlayerMarine )
		{
			C_ASW_Weapon *pWeapon = pPlayerMarine->GetASWWeapon( ASW_INVENTORY_SLOT_EXTRA );
			if ( pWeapon )
			{
				m_pEntries[ iEntry ]->m_iHotKeyIndex = -1;
				m_pEntries[ iEntry ]->SetVisible( true );
				m_pEntries[ iEntry ]->SetDetails( pPlayerMarine, ASW_INVENTORY_SLOT_EXTRA );
				bHasItem = true;
			}
		}

		if ( !bHasItem )	// blank it out if there's no item in that slot
		{
			m_pEntries[ iEntry ]->m_iHotKeyIndex = iEntry;
			m_pEntries[ iEntry ]->SetDetails( NULL, -1 );
			m_pEntries[ iEntry ]->SetVisible( false );
		}

		iEntry++;
	}

	for ( int i = 0; i < ASWGameResource()->GetMaxMarineResources(); i++ )
	{
		C_ASW_Marine_Resource* pMR = ASWGameResource()->GetMarineResource( i );
		if ( !pMR )
			continue;

		if ( pMR->GetCommander() != pPlayer )
			continue;

		C_ASW_Marine *pMarine = pMR->GetMarineEntity();
		if ( !pMarine )
			continue;

		if ( pMarine->IsInhabited() )
			continue;

		if ( iEntry >= m_pEntries.Count() )
		{
			CASW_Hotbar_Entry *pPanel = new CASW_Hotbar_Entry( this, "SquadInventoryPanelEntry" );
			m_pEntries.AddToTail( pPanel );
			InvalidateLayout();
		}

		bHasItem = false;
		for ( int k = 0; k < ASW_NUM_INVENTORY_SLOTS; k++ )
		{
			C_ASW_Weapon *pWeapon = pMarine->GetASWWeapon( k );
			if ( !pWeapon )
				continue;

			const CASW_WeaponInfo* pInfo = pWeapon->GetWeaponInfo();
			if ( !pInfo || !pInfo->m_bOffhandActivate )		// TODO: Fix for sentry guns
				continue;

			m_pEntries[ iEntry ]->m_iHotKeyIndex = iEntry;
			m_pEntries[ iEntry ]->SetVisible( true );
			m_pEntries[ iEntry ]->SetDetails( pMarine, k );
			bHasItem = true;

			if ( asw_hotbar_simple.GetBool() )		// only 1 item per marine
				break;
		}

		if ( !bHasItem )	// blank it out if there's no item in that slot
		{
			m_pEntries[ iEntry ]->m_iHotKeyIndex = iEntry;
			m_pEntries[ iEntry ]->SetDetails( NULL, -1 );
			m_pEntries[ iEntry ]->SetVisible( false );
		}

		iEntry++;
	}

	for ( int i = iEntry; i < m_pEntries.Count(); i++ )
	{
		m_pEntries[ i ]->SetVisible( false );
	}
}
void CASWViewRender::PerformNightVisionEffect( const CViewSetup &view )
{
	C_ASW_Player *pPlayer = C_ASW_Player::GetLocalASWPlayer();
	if ( !pPlayer )
		return;

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

	float flVisionAlpha = 0.0f;
	float flFlashAlpha = 0.0f;
	C_BaseCombatWeapon*	pExtraItem = pMarine->GetWeapon( 2 );
	if ( pExtraItem && pExtraItem->Classify() == CLASS_ASW_NIGHT_VISION )
	{
		C_ASW_Weapon_Night_Vision *pVision = assert_cast<CASW_Weapon_Night_Vision*>( pExtraItem );
		flVisionAlpha = pVision->UpdateVisionAlpha();
		flFlashAlpha = pVision->UpdateFlashAlpha();
	}

	if ( flVisionAlpha > 0 )
	{
		IMaterial *pMaterial = materials->FindMaterial( "effects/nightvision", TEXTURE_GROUP_CLIENT_EFFECTS, true );

		if ( pMaterial )
		{
			byte overlaycolor[4] = { 0, 255, 0, 255 };

			UpdateScreenEffectTexture( 0, view.x, view.y, view.width, view.height );

			overlaycolor[3] = flVisionAlpha;

			render->ViewDrawFade( overlaycolor, pMaterial );

			CMatRenderContextPtr pRenderContext( materials );
			pRenderContext->DrawScreenSpaceQuad( pMaterial );
			render->ViewDrawFade( overlaycolor, pMaterial );
			pRenderContext->DrawScreenSpaceQuad( pMaterial );
		}
		IMaterial *pNoiseMaterial = materials->FindMaterial( "effects/nightvision_noise", TEXTURE_GROUP_CLIENT_EFFECTS, true );

		if ( pNoiseMaterial )
		{
			byte overlaycolor[4] = { 255, 255, 255, 255 };
			overlaycolor[3] = MAX( flFlashAlpha, 16.0f );
			CMatRenderContextPtr pRenderContext( materials );
			render->ViewDrawFade( overlaycolor, pNoiseMaterial );
		}
	}
	if ( flFlashAlpha > 0 )
	{
		IMaterial *pMaterial = materials->FindMaterial( "effects/nightvision_flash", TEXTURE_GROUP_CLIENT_EFFECTS, true );

		if ( pMaterial )
		{
			byte overlaycolor[4] = { 255, 255, 255, 255 };
			overlaycolor[3] = flFlashAlpha;
			CMatRenderContextPtr pRenderContext( materials );
			render->ViewDrawFade( overlaycolor, pMaterial );
		}		
	}
}
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();
}
Esempio n. 9
0
bool CScriptedIconLesson::Mod_ProcessElementAction( int iAction, bool bNot, const char *pchVarName, EHANDLE &hVar, const CGameInstructorSymbol *pchParamName, float fParam, C_BaseEntity *pParam, const char *pchParam, bool &bModHandled )
{
	// Assume we're going to handle the action
	bModHandled = true;

	C_BaseEntity *pVar = hVar.Get();

	switch ( iAction )
	{
		case LESSON_ACTION_IS_ALLOWED_ITEM:
		{
			C_ASW_Marine *pMarine = NULL;

			C_ASW_Player *pPlayer = dynamic_cast< C_ASW_Player* >( pVar );
			if ( pPlayer )
			{
				pMarine = dynamic_cast< C_ASW_Marine* >( pPlayer->GetMarine() );
			}

			if ( !pMarine )
			{
				if ( gameinstructor_verbose.GetInt() > 0 && ShouldShowSpew() )
				{
					ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, "\t[%s]->AllowedToPickup( [%s] )", pchParamName->String(), pchVarName );
					ConColorMsg( CBaseLesson::m_rgbaVerboseName, "... " );
					ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, ( bNot ) ? ( "== false\n" ) : ( "== true\n" ) );
					ConColorMsg( CBaseLesson::m_rgbaVerboseClose, "\tVar handle as ASW_Marine returned NULL!\n" );
				}

				return false;
			}

			bool bIsAllowed = false;

			C_ASW_Pickup *pPickup = dynamic_cast< C_ASW_Pickup * >( pParam );
			if ( !pPickup )
			{
				C_ASW_Weapon *pWeapon = dynamic_cast< C_ASW_Weapon * >( pParam );

				if ( !pWeapon )
				{
					if ( gameinstructor_verbose.GetInt() > 0 && ShouldShowSpew() )
					{
						ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, "\t[%s]->AllowedToPickup( [%s] )", pchParamName->String(), pchVarName );
						ConColorMsg( CBaseLesson::m_rgbaVerboseName, "... " );
						ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, ( bNot ) ? ( "== false\n" ) : ( "== true\n" ) );
						ConColorMsg( CBaseLesson::m_rgbaVerboseClose, "\tParam handle as ASW_Weapon and ASW_Pickup returned NULL!\n" );
					}

					return false;
				}
				else
				{
					bIsAllowed = pWeapon->AllowedToPickup( pMarine );
				}
			}
			else
			{
				bIsAllowed = pPickup->AllowedToPickup( pMarine );
			}

			if ( gameinstructor_verbose.GetInt() > 0 && ShouldShowSpew() )
			{
				ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, "\t[%s]->AllowedToPickup( [%s] )", pchParamName->String(), pchVarName );
				ConColorMsg( CBaseLesson::m_rgbaVerboseName, "%s ", ( bIsAllowed ? "true" : "false" ) );
				ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, ( bNot ) ? ( "== false\n" ) : ( "== true\n" ) );
			}

			return ( bNot ) ? ( !bIsAllowed ) : ( bIsAllowed );
		}

		case LESSON_ACTION_ITEM_WILL_SWAP:
		{
			C_ASW_Marine *pMarine = NULL;

			C_ASW_Player *pPlayer = dynamic_cast< C_ASW_Player* >( pVar );
			if ( pPlayer )
			{
				pMarine = dynamic_cast< C_ASW_Marine* >( pPlayer->GetMarine() );
			}

			if ( !pMarine )
			{
				if ( gameinstructor_verbose.GetInt() > 0 && ShouldShowSpew() )
				{
					ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, "\t[%s]->WillSwap( [%s] )", pchParamName->String(), pchVarName );
					ConColorMsg( CBaseLesson::m_rgbaVerboseName, "... " );
					ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, ( bNot ) ? ( "== false\n" ) : ( "== true\n" ) );
					ConColorMsg( CBaseLesson::m_rgbaVerboseClose, "\tVar handle as ASW_Marine returned NULL!\n" );
				}

				return false;
			}

			bool bWillSwap = false;

			C_ASW_Pickup_Weapon *pPickup = dynamic_cast< C_ASW_Pickup_Weapon * >( pParam );
			if ( !pPickup )
			{
				C_ASW_Weapon *pWeapon = dynamic_cast< C_ASW_Weapon * >( pParam );

				if ( !pWeapon )
				{
					if ( gameinstructor_verbose.GetInt() > 0 && ShouldShowSpew() )
					{
						ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, "\t[%s]->WillSwap( [%s] )", pchParamName->String(), pchVarName );
						ConColorMsg( CBaseLesson::m_rgbaVerboseName, "... " );
						ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, ( bNot ) ? ( "== false\n" ) : ( "== true\n" ) );
						ConColorMsg( CBaseLesson::m_rgbaVerboseClose, "\tParam handle as ASW_Weapon and ASW_Pickup returned NULL!\n" );
					}

					return false;
				}
				else
				{
					int nSlot = pMarine->GetWeaponPositionForPickup( pWeapon->GetClassname() );
					bWillSwap = ( pMarine->GetASWWeapon( nSlot ) != NULL );
				}
			}
			else
			{
				int nSlot = pMarine->GetWeaponPositionForPickup( pPickup->GetWeaponClass() );
				bWillSwap = ( pMarine->GetASWWeapon( nSlot ) != NULL );
			}

			if ( gameinstructor_verbose.GetInt() > 0 && ShouldShowSpew() )
			{
				ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, "\t[%s]->WillSwap( [%s] )", pchParamName->String(), pchVarName );
				ConColorMsg( CBaseLesson::m_rgbaVerboseName, "%s ", ( bWillSwap ? "true" : "false" ) );
				ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, ( bNot ) ? ( "== false\n" ) : ( "== true\n" ) );
			}

			return ( bNot ) ? ( !bWillSwap ) : ( bWillSwap );
		}

		case LESSON_ACTION_CAN_HACK:
		{
			C_ASW_Marine *pMarine = NULL;

			C_ASW_Player *pPlayer = dynamic_cast< C_ASW_Player* >( pVar );
			if ( pPlayer )
			{
				pMarine = dynamic_cast< C_ASW_Marine* >( pPlayer->GetMarine() );
			}

			if ( !pMarine )
			{
				if ( gameinstructor_verbose.GetInt() > 0 && ShouldShowSpew() )
				{
					ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, "\t[%s]->CanHack()", pchVarName );
					ConColorMsg( CBaseLesson::m_rgbaVerboseName, "... " );
					ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, ( bNot ) ? ( "== false\n" ) : ( "== true\n" ) );
					ConColorMsg( CBaseLesson::m_rgbaVerboseClose, "\tVar handle as ASW_Marine returned NULL!\n" );
				}

				return false;
			}

			bool bCanHack = pMarine->GetMarineProfile()->CanHack();

			if ( gameinstructor_verbose.GetInt() > 0 && ShouldShowSpew() )
			{
				ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, "\t[%s]->AllowedToPickup()", pchVarName );
				ConColorMsg( CBaseLesson::m_rgbaVerboseName, "%s ", ( bCanHack ? "true" : "false" ) );
				ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, ( bNot ) ? ( "== false\n" ) : ( "== true\n" ) );
			}

			return ( bNot ) ? ( !bCanHack ) : ( bCanHack );
		}

		case LESSON_ACTION_CAN_OFFHAND:
		{
			C_ASW_Weapon *pWeapon = dynamic_cast< C_ASW_Weapon* >( pVar );
			if ( !pWeapon )
			{
				if ( gameinstructor_verbose.GetInt() > 0 && ShouldShowSpew() )
				{
					ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, "\t[%s]->CanOffhand()", pchVarName );
					ConColorMsg( CBaseLesson::m_rgbaVerboseName, "... " );
					ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, ( bNot ) ? ( "== false\n" ) : ( "== true\n" ) );
					ConColorMsg( CBaseLesson::m_rgbaVerboseClose, "\tVar handle as ASW_Weapon returned NULL!\n" );
				}

				return false;
			}

			bool bCanOffhand = pWeapon->GetWeaponInfo()->m_bOffhandActivate;

			if ( gameinstructor_verbose.GetInt() > 0 && ShouldShowSpew() )
			{
				ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, "\t[%s]->CanOffhand()", pchVarName );
				ConColorMsg( CBaseLesson::m_rgbaVerboseName, "%s ", ( bCanOffhand ? "true" : "false" ) );
				ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, ( bNot ) ? ( "== false\n" ) : ( "== true\n" ) );
			}

			return ( bNot ) ? ( !bCanOffhand ) : ( bCanOffhand );
		}

		case LESSON_ACTION_HAS_SECONDARY:
		{
			C_ASW_Weapon *pWeapon = dynamic_cast< C_ASW_Weapon* >( pVar );
			if ( !pWeapon )
			{
				if ( gameinstructor_verbose.GetInt() > 0 && ShouldShowSpew() )
				{
					ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, "\t[%s]->HasSecondary()", pchVarName );
					ConColorMsg( CBaseLesson::m_rgbaVerboseName, "... " );
					ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, ( bNot ) ? ( "== false\n" ) : ( "== true\n" ) );
					ConColorMsg( CBaseLesson::m_rgbaVerboseClose, "\tVar handle as ASW_Weapon returned NULL!\n" );
				}

				return false;
			}

			bool bHasSecondary = pWeapon->UsesSecondaryAmmo();

			if ( bHasSecondary )
			{
				bHasSecondary = !( ( pWeapon->UsesClipsForAmmo2() && pWeapon->m_iClip2 <= 0 ) ||
								   ( !pWeapon->UsesClipsForAmmo2() && pWeapon->GetOwner() && pWeapon->GetOwner()->GetAmmoCount( pWeapon->m_iSecondaryAmmoType ) <= 0 ) );
			}

			if ( gameinstructor_verbose.GetInt() > 0 && ShouldShowSpew() )
			{
				ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, "\t[%s]->HasSecondary()", pchVarName );
				ConColorMsg( CBaseLesson::m_rgbaVerboseName, "%s ", ( bHasSecondary ? "true" : "false" ) );
				ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, ( bNot ) ? ( "== false\n" ) : ( "== true\n" ) );
			}

			return ( bNot ) ? ( !bHasSecondary ) : ( bHasSecondary );
		}

		case LESSON_ACTION_HAS_SECONDARY_EXPLOSIVES:
		{
			C_ASW_Marine *pMarine = NULL;

			C_ASW_Player *pPlayer = dynamic_cast< C_ASW_Player* >( pVar );
			if ( pPlayer )
			{
				pMarine = dynamic_cast< C_ASW_Marine* >( pPlayer->GetMarine() );
			}

			if ( !pMarine )
			{
				if ( gameinstructor_verbose.GetInt() > 0 && ShouldShowSpew() )
				{
					ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, "\t[%s]->HasAnySecondary()", pchVarName );
					ConColorMsg( CBaseLesson::m_rgbaVerboseName, "... " );
					ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, ( bNot ) ? ( "== false\n" ) : ( "== true\n" ) );
					ConColorMsg( CBaseLesson::m_rgbaVerboseClose, "\tVar handle as ASW_Marine returned NULL!\n" );
				}

				return false;
			}

			bool bHasAnySecondary = false;

			for ( int i = 0; i < ASW_MAX_EQUIP_SLOTS; ++i )
			{
				C_ASW_Weapon *pWeapon = static_cast< C_ASW_Weapon* >( pMarine->GetWeapon( i ) );
				if ( pWeapon && pWeapon->HasSecondaryExplosive() )
				{
					if ( !( ( pWeapon->UsesClipsForAmmo2() && pWeapon->m_iClip2 <= 0 ) || 
							( !pWeapon->UsesClipsForAmmo2() && pWeapon->GetOwner() && pWeapon->GetOwner()->GetAmmoCount( pWeapon->m_iSecondaryAmmoType ) <= 0 ) ) )
					{
						bHasAnySecondary = true;
						break;
					}
				}
			}

			if ( gameinstructor_verbose.GetInt() > 0 && ShouldShowSpew() )
			{
				ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, "\t[%s]->HasAnySecondary()", pchVarName );
				ConColorMsg( CBaseLesson::m_rgbaVerboseName, "%s ", ( bHasAnySecondary ? "true" : "false" ) );
				ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, ( bNot ) ? ( "== false\n" ) : ( "== true\n" ) );
			}

			return ( bNot ) ? ( !bHasAnySecondary ) : ( bHasAnySecondary );
		}

		case LESSON_ACTION_GET_MARINE:
		{
			int iTemp = static_cast<int>( fParam );

			if ( iTemp <= 0 || iTemp > 2 )
			{
				if ( gameinstructor_verbose.GetInt() > 0 && ShouldShowSpew() )
				{
					ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, "\t[entityINVALID] = [%s]->GetMarine()\n", pchVarName );
					ConColorMsg( CBaseLesson::m_rgbaVerboseClose, "\tParam selecting string is out of range!\n" );
				}

				return false;
			}

			CHandle<C_BaseEntity> *pHandle;

			char const *pchParamNameTemp = NULL;

			if ( iTemp == 2 )
			{
				pHandle = &m_hEntity2;
				pchParamNameTemp = "entity2";
			}
			else
			{
				pHandle = &m_hEntity1;
				pchParamNameTemp = "entity1";
			}

			C_ASW_Player *pPlayer = dynamic_cast< C_ASW_Player* >( pVar );
			if ( !pPlayer )
			{
				if ( gameinstructor_verbose.GetInt() > 0 && ShouldShowSpew() )
				{
					ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, "\t[%s] = [%s]->GetMarine()", pchParamNameTemp, pchVarName );
					ConColorMsg( CBaseLesson::m_rgbaVerboseName, "...\n" );
					ConColorMsg( CBaseLesson::m_rgbaVerboseClose, "\tVar handle as ASW_Player returned NULL!\n" );
				}

				return false;
			}

			C_ASW_Marine *pMarine = dynamic_cast< C_ASW_Marine* >( pPlayer->GetMarine() );

			pHandle->Set( pMarine );

			if ( gameinstructor_verbose.GetInt() > 0 && ShouldShowSpew() )
			{
				ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, "\t[%s] = [%s]->GetMarine()\n", pchParamNameTemp, pchVarName );
			}

			return true;
		}

		case LESSON_ACTION_IS_BOT:
		{
			C_ASW_Marine *pMarine = dynamic_cast< C_ASW_Marine* >( pVar );

			if ( !pMarine )
			{
				if ( gameinstructor_verbose.GetInt() > 0 && ShouldShowSpew() )
				{
					ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, "\t![%s]->IsInhabited()", pchVarName );
					ConColorMsg( CBaseLesson::m_rgbaVerboseName, "... " );
					ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, ( bNot ) ? ( "== false\n" ) : ( "== true\n" ) );
					ConColorMsg( CBaseLesson::m_rgbaVerboseClose, "\tVar handle as ASW_Marine returned NULL!\n" );
				}

				return false;
			}

			bool bIsBot = !pMarine->IsInhabited();

			if ( gameinstructor_verbose.GetInt() > 0 && ShouldShowSpew() )
			{
				ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, "\t![%s]->IsInhabited()", pchVarName );
				ConColorMsg( CBaseLesson::m_rgbaVerboseName, "%s ", ( bIsBot ? "true" : "false" ) );
				ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, ( bNot ) ? ( "== false\n" ) : ( "== true\n" ) );
			}

			return ( bNot ) ? ( !bIsBot ) : ( bIsBot );
		}

		case LESSON_ACTION_WEAPON_HAS_SPARE:
		{
			C_ASW_Marine *pMarine = NULL;

			C_ASW_Player *pPlayer = dynamic_cast< C_ASW_Player* >( pVar );
			if ( pPlayer )
			{
				pMarine = dynamic_cast< C_ASW_Marine* >( pPlayer->GetMarine() );
			}

			if ( !pMarine )
			{
				if ( gameinstructor_verbose.GetInt() > 0 && ShouldShowSpew() )
				{
					ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, "\t[%s]->HasSpareWeapon()", pchVarName );
					ConColorMsg( CBaseLesson::m_rgbaVerboseName, "... " );
					ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, ( bNot ) ? ( "== false\n" ) : ( "== true\n" ) );
					ConColorMsg( CBaseLesson::m_rgbaVerboseClose, "\tVar handle as ASW_Marine returned NULL!\n" );
				}

				return false;
			}

			int nOffensiveWeaponCount = 0;

			for ( int i = 0; i < ASW_MAX_EQUIP_SLOTS; ++i )
			{
				C_ASW_Weapon *pWeapon = static_cast< C_ASW_Weapon* >( pMarine->GetWeapon( i ) );
				if ( pWeapon && pWeapon->IsOffensiveWeapon() )
				{
					if ( !( ( pWeapon->UsesClipsForAmmo1() && pWeapon->m_iClip1 <= 0 ) || 
						 ( !pWeapon->UsesClipsForAmmo1() && pWeapon->GetOwner() && pWeapon->GetOwner()->GetAmmoCount( pWeapon->m_iPrimaryAmmoType ) <= 0 ) ) )
					{
						nOffensiveWeaponCount++;
					}
				}
			}

			bool bHasSpare = ( nOffensiveWeaponCount > 1 );

			if ( gameinstructor_verbose.GetInt() > 0 && ShouldShowSpew() )
			{
				ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, "\t[%s]->HasSpareWeapon()", pchVarName );
				ConColorMsg( CBaseLesson::m_rgbaVerboseName, "%s ", ( bHasSpare ? "true" : "false" ) );
				ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, ( bNot ) ? ( "== false\n" ) : ( "== true\n" ) );
			}

			return ( bNot ) ? ( !bHasSpare ) : ( bHasSpare );
		}

		case LESSON_ACTION_WEAPON_IS_OFFENSIVE:
		{
			C_ASW_Marine *pMarine = NULL;

			C_ASW_Player *pPlayer = dynamic_cast< C_ASW_Player* >( pVar );
			if ( pPlayer )
			{
				pMarine = dynamic_cast< C_ASW_Marine* >( pPlayer->GetMarine() );
			}

			if ( !pMarine )
			{
				if ( gameinstructor_verbose.GetInt() > 0 && ShouldShowSpew() )
				{
					ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, "\t[%s]->WeaponIsOffensive()", pchVarName );
					ConColorMsg( CBaseLesson::m_rgbaVerboseName, "... " );
					ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, ( bNot ) ? ( "== false\n" ) : ( "== true\n" ) );
					ConColorMsg( CBaseLesson::m_rgbaVerboseClose, "\tVar handle as ASW_Marine returned NULL!\n" );
				}

				return false;
			}

			bool bIsOffensive = false;

			C_ASW_Weapon *pWeapon = pMarine->GetActiveASWWeapon();
			if ( pWeapon && pWeapon->IsOffensiveWeapon() )
			{
				if ( !( ( pWeapon->UsesClipsForAmmo1() && pWeapon->m_iClip1 <= 0 ) || 
					( !pWeapon->UsesClipsForAmmo1() && pWeapon->GetOwner() && pWeapon->GetOwner()->GetAmmoCount( pWeapon->m_iPrimaryAmmoType ) <= 0 ) ) )
				{
					bIsOffensive = true;
				}
			}

			if ( gameinstructor_verbose.GetInt() > 0 && ShouldShowSpew() )
			{
				ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, "\t[%s]->WeaponIsOffensive()", pchVarName );
				ConColorMsg( CBaseLesson::m_rgbaVerboseName, "%s ", ( bIsOffensive ? "true" : "false" ) );
				ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, ( bNot ) ? ( "== false\n" ) : ( "== true\n" ) );
			}

			return ( bNot ) ? ( !bIsOffensive ) : ( bIsOffensive );
		}

		case LESSON_ACTION_WEAPON_LOCAL_HOTBAR_SLOT:
		{
			CASW_Hud_Master *pHUDMaster = GET_HUDELEMENT( CASW_Hud_Master );
			if ( pHUDMaster )
			{
				m_fOutput = pHUDMaster->GetHotBarSlot( pchParam );

				if ( gameinstructor_verbose.GetInt() > 0 && ShouldShowSpew() )
				{
					ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, "\tm_fOutput = GET_HUDELEMENT( CASW_Hud_Squad_Hotbar )->GetHotBarSlot( [%s] ", pchParamName->String() );
					ConColorMsg( CBaseLesson::m_rgbaVerboseName, "\"%s\"", pchParam );
					ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, ")\n" );
				}
			}

			return true;
		}

		case LESSON_ACTION_OWNS_HOTBAR_SLOT:
		{
			int iTemp = static_cast<int>( fParam );

			C_ASW_Player *pPlayer = dynamic_cast< C_ASW_Player* >( pVar );
			if ( !pPlayer )
			{
				if ( gameinstructor_verbose.GetInt() > 0 && ShouldShowSpew() )
				{
					ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, "\tGET_HUDELEMENT( CASW_Hud_Squad_Hotbar )->OwnsHotBarSlot( [%s] ", pchVarName );
					ConColorMsg( CBaseLesson::m_rgbaVerboseName, "..." );
					ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, ", [%s] ", pchParamName->String() );
					ConColorMsg( CBaseLesson::m_rgbaVerboseName, "\"%i\" ", iTemp );
					ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, ") " );
					ConColorMsg( CBaseLesson::m_rgbaVerboseName, "... " );
					ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, ( bNot ) ? ( "== false\n" ) : ( "== true\n" ) );
					ConColorMsg( CBaseLesson::m_rgbaVerboseClose, "\tVar handle as ASW_Player returned NULL!\n" );
				}

				return false;
			}

			bool bOwnsHotBarSlot = false;

			CASW_Hud_Master *pHUDMaster = GET_HUDELEMENT( CASW_Hud_Master );
			if ( pHUDMaster )
			{
				bOwnsHotBarSlot = pHUDMaster->OwnsHotBarSlot( pPlayer, iTemp );

				if ( gameinstructor_verbose.GetInt() > 0 && ShouldShowSpew() )
				{
					ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, "\tGET_HUDELEMENT( CASW_Hud_Squad_Hotbar )->OwnsHotBarSlot( [%s], [%s] ", pchVarName, pchParamName->String() );
					ConColorMsg( CBaseLesson::m_rgbaVerboseName, "\"%i\" ", iTemp );
					ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, ") " );
					ConColorMsg( CBaseLesson::m_rgbaVerboseName, "%s ", ( bOwnsHotBarSlot ? "true" : "false" ) );
					ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, ( bNot ) ? ( "== false\n" ) : ( "== true\n" ) );
				}
			}

			return ( bNot ) ? ( !bOwnsHotBarSlot ) : ( bOwnsHotBarSlot );
		}

		case LESSON_ACTION_SENTRY_WANTS_DISMANTLE:
		{
			C_ASW_Sentry_Base *pSentry = dynamic_cast< C_ASW_Sentry_Base* >( pVar );
			if ( !pSentry )
			{
				if ( gameinstructor_verbose.GetInt() > 0 && ShouldShowSpew() )
				{
					ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, "\t[%s]->WantsDismantle()", pchVarName );
					ConColorMsg( CBaseLesson::m_rgbaVerboseName, "... " );
					ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, ( bNot ) ? ( "== false\n" ) : ( "== true\n" ) );
					ConColorMsg( CBaseLesson::m_rgbaVerboseClose, "\tVar handle as ASW_Sentry_Base returned NULL!\n" );
				}

				return false;
			}

			bool bWantsDismantle = pSentry->WantsDismantle();

			if ( gameinstructor_verbose.GetInt() > 0 && ShouldShowSpew() )
			{
				ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, "\t[%s]->WantsDismantle()", pchVarName );
				ConColorMsg( CBaseLesson::m_rgbaVerboseName, "%s ", ( bWantsDismantle ? "true" : "false" ) );
				ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, ( bNot ) ? ( "== false\n" ) : ( "== true\n" ) );
			}

			return ( bNot ) ? ( !bWantsDismantle ) : ( bWantsDismantle );
		}

		case LESSON_ACTION_IS_TUTORIAL:
		{
			bool bIsTutorial = ASWGameRules()->IsTutorialMap();

			if ( gameinstructor_verbose.GetInt() > 0 && ShouldShowSpew() )
			{
				ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, "\tASWGameRules()->IsTutorialMap()" );
				ConColorMsg( CBaseLesson::m_rgbaVerboseName, "%s ", ( bIsTutorial ? "true" : "false" ) );
				ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, ( bNot ) ? ( "== false\n" ) : ( "== true\n" ) );
			}

			return ( bNot ) ? ( !bIsTutorial ) : ( bIsTutorial );
		}

		case LESSON_ACTION_IS_SINGLEPLAYER:
		{
			bool bIsSingleplayer = ASWGameRules()->IsOfflineGame();

			if ( gameinstructor_verbose.GetInt() > 0 && ShouldShowSpew() )
			{
				ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, "\tASWGameRules()->IsOfflineGame()" );
				ConColorMsg( CBaseLesson::m_rgbaVerboseName, "%s ", ( bIsSingleplayer ? "true" : "false" ) );
				ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, ( bNot ) ? ( "== false\n" ) : ( "== true\n" ) );
			}

			return ( bNot ) ? ( !bIsSingleplayer ) : ( bIsSingleplayer );
		}

		default:
			// Didn't handle this action
			bModHandled = false;
			break;
	}

	return false;
}
void CASWHudCrosshair::DrawDirectionalCrosshair( int x, int y, int iSize )
{
	C_ASW_Player *local = C_ASW_Player::GetLocalASWPlayer();
	if (!local)
		return;	
	
	C_ASW_Marine *pMarine = local->GetMarine();
	if (!pMarine)
		return;

	Vector MarinePos = pMarine->GetRenderOrigin();
	Vector screenPos;
	debugoverlay->ScreenPosition( MarinePos + Vector( 0, 0, 45 ), screenPos );

	int cx, cy, dx, dy;
	ASWInput()->ASW_GetWindowCenter(cx, cy);
	dx = x - cx;
	dy = y - cy;
	float flDistance = FastSqrt( dx * dx + dy * dy );

	//CASWScriptCreatedItem *pItem = static_cast<CASWScriptCreatedItem*>( pMarine->GetActiveASWWeapon()->GetAttributeContainer()->GetItem() );
	//if ( !m_bIsCastingSuitAbility )//pItem && pItem->IsMeleeWeapon() &&
	//{
		// here is where we do the crosshair scaling
		int iMax = YRES(54);
		int iMin = YRES(16);
		// clamp the min and max distance the cursor is from the marine on screen
		float flSizeDist = clamp( flDistance, iMin, iMax );

		// this is the full percentage to scale by
		float flTemp = (flSizeDist - iMin) / ( iMax - iMin );
		
		float flMinTexScale = 0.8;
		float flMaxTexScale = 1.0;
		// this is the final percentage to scale by based on the clamping we want for the min and max texture scaling
		float flAdjust = flTemp * (flMaxTexScale - flMinTexScale) + flMinTexScale;

		iSize *= flAdjust;
		m_pAmmoProgress->SetScale( flAdjust );
	//}

	iSize *= 2;
	int iXHairHalfSize = iSize / 2;
	// draw a red pointing, potentially blinking, arrow
	//Vector vecFacing(screenPos.x - (ScreenWidth() * 0.5f), screenPos.y - (ScreenHeight() * 0.5f), 0);
	//float fFacingYaw = -UTIL_VecToYaw(vecFacing);

	Vector2D vXHairCenter( x , y );

	Vector vecCornerTL(-iXHairHalfSize, -iXHairHalfSize, 0);
	Vector vecCornerTR(iXHairHalfSize, -iXHairHalfSize, 0);
	Vector vecCornerBR(iXHairHalfSize, iXHairHalfSize, 0);
	Vector vecCornerBL(-iXHairHalfSize, iXHairHalfSize, 0);
	Vector vecCornerTL_rotated, vecCornerTR_rotated, vecCornerBL_rotated, vecCornerBR_rotated;	

	int current_posx = 0;
	int current_posy = 0;
	ASWInput()->GetSimulatedFullscreenMousePos( &current_posx, &current_posy );
	Vector vecFacing( 0, 0, 0 );
	vecFacing.x = screenPos.x - current_posx;
	vecFacing.y = screenPos.y - current_posy;
	float fFacingYaw = -UTIL_VecToYaw( vecFacing );

	/*
	if ( ASWInput()->ControllerModeActive() )
	{
		int current_posx = 0;
		int current_posy = 0;
		ASWInput()->GetSimulatedFullscreenMousePos( &current_posx, &current_posy );
		vecFacing.x = screenPos.x - current_posx;
		vecFacing.y = screenPos.y - current_posy;
		fFacingYaw = -UTIL_VecToYaw( vecFacing );
	}
	*/

	// rotate it by our facing yaw
	QAngle angFacing(0, -fFacingYaw + 90.0, 0);
	VectorRotate(vecCornerTL, angFacing, vecCornerTL_rotated);
	VectorRotate(vecCornerTR, angFacing, vecCornerTR_rotated);
	VectorRotate(vecCornerBR, angFacing, vecCornerBR_rotated);
	VectorRotate(vecCornerBL, angFacing, vecCornerBL_rotated);
	//


	float flAlpha = 245;

	// fade the crosshair out when it is very close to the marine
	float flAdjust2 = flDistance / YRES(28);
	flAdjust2 = clamp( flAdjust2, 0.1f, 1.0f );

	bool bShotWarn = false;
	Color colorCross = Color(255,255,255,flAlpha*flAdjust2);
	C_ASW_Weapon* pWeapon = pMarine->GetActiveASWWeapon();
	if ( pWeapon && pWeapon->IsOffensiveWeapon() )
	{
		C_BaseEntity *pEnt = pWeapon->GetLaserTargetEntity();
		if ( pEnt && pEnt->Classify() == CLASS_ASW_MARINE )
		{
			bShotWarn = true;
			colorCross = Color(255,0,0,flAlpha*flAdjust2);
		}
	}
	
	surface()->DrawSetColor( colorCross );
	
	if ( !asw_crosshair_use_perspective.GetBool() )
	{
		surface()->DrawSetTexture( m_nDirectCrosshairTexture2 );
	}
	else
	{
		if ( bShotWarn )
			surface()->DrawSetTexture( m_nDirectCrosshairTextureX );
		else
			surface()->DrawSetTexture( m_nDirectCrosshairTexture );
	}
	

	Vertex_t points[4] = 
	{ 
		Vertex_t( Vector2D(vXHairCenter.x + vecCornerTL_rotated.x, vXHairCenter.y + vecCornerTL_rotated.y), 
		Vector2D(0,0) ), 
		Vertex_t( Vector2D(vXHairCenter.x + vecCornerTR_rotated.x, vXHairCenter.y + vecCornerTR_rotated.y), 
		Vector2D(1,0) ), 
		Vertex_t( Vector2D(vXHairCenter.x + vecCornerBR_rotated.x, vXHairCenter.y + vecCornerBR_rotated.y), 
		Vector2D(1,1) ), 
		Vertex_t( Vector2D(vXHairCenter.x + vecCornerBL_rotated.x, vXHairCenter.y + vecCornerBL_rotated.y), 
		Vector2D(0,1) ) 
	}; 
	surface()->DrawTexturedPolygon( 4, points );

	// draw the center
	if ( !asw_crosshair_use_perspective.GetBool() )
	{
		surface()->DrawSetColor( colorCross );
		surface()->DrawSetTexture( m_nCrosshairTexture );
		surface()->DrawTexturedRect(vXHairCenter.x - iXHairHalfSize, vXHairCenter.y - iXHairHalfSize, vXHairCenter.x + iXHairHalfSize, vXHairCenter.y + iXHairHalfSize);
	}
}
void CASWHudCrosshair::OnThink()
{
	C_ASW_Player* pPlayer = C_ASW_Player::GetLocalASWPlayer();
	if ( !pPlayer )
		return;

	PaintReloadProgressBar();

	C_ASW_Marine *pMarine = pPlayer->GetViewMarine();
	bool bControllingTurret = (pMarine && pMarine->IsControllingTurret());
	if (!bControllingTurret)
		return;

	C_ASW_Remote_Turret *pTurret = pMarine->GetRemoteTurret();
	if (!pTurret)
		return;

	Vector vecWeaponPos = pTurret->GetAbsOrigin();
	QAngle angWeapon = pTurret->EyeAngles();
	Vector vecWeaponDir;
	AngleVectors(angWeapon, &vecWeaponDir);

	// increase lock time of all targets and discard out of range/facing ones
	for (int k=0;k<ASW_MAX_TURRET_TARGETS;k++)
	{
		C_BaseEntity *pEnt = m_TurretTarget[k].Get();
		if (pEnt)
		{
			// validate the target
			bool bValid = true;
			Vector diff = pEnt->GetAbsOrigin() - vecWeaponPos;
			if (diff.Length() > ASW_TURRET_TARGET_RANGE || !pEnt->ShouldDraw())				
			{
				bValid = false;
			}
			else
			{
				diff.NormalizeInPlace();
				float flDot = diff.Dot(vecWeaponDir);
				if (flDot < asw_turret_dot.GetFloat())
					bValid = false;
					
			}
			// fade it in or out appropriately
			if (bValid)
			{
				if (m_fTurretTargetLock[k] < 1.0f)
				{
					m_fTurretTargetLock[k] += gpGlobals->frametime * 2;
					if (m_fTurretTargetLock[k] > 1.0f)
						m_fTurretTargetLock[k] = 1.0f;
				}
			}
			else
			{
				if (m_fTurretTargetLock[k] <= 0)
				{
					m_TurretTarget[k] = NULL;
				}
				else
				{
					m_fTurretTargetLock[k] -= gpGlobals->frametime * 2;
					if (m_fTurretTargetLock[k] < 0.0f)
						m_fTurretTargetLock[k] = 0.0f;
				}
			}
		}
	}

	// check for adding new targets to the array
	for ( int i = 0; i < IASW_Client_Aim_Target::AutoList().Count(); i++ )
	{
		IASW_Client_Aim_Target *pAimTarget = static_cast< IASW_Client_Aim_Target* >( IASW_Client_Aim_Target::AutoList()[ i ] );
		C_BaseEntity *pEnt = pAimTarget->GetEntity();
		if (!pEnt || !pAimTarget->IsAimTarget() || !pEnt->ShouldDraw())
			continue;
		
		// check he's in range
		Vector vecAlienPos = pEnt->WorldSpaceCenter();
		float flAlienDist = vecAlienPos.DistTo(vecWeaponPos);		
		if (flAlienDist > ASW_TURRET_TARGET_RANGE)
			continue;

		// check it's in front of us
		Vector dir = vecAlienPos - vecWeaponPos;
		dir.NormalizeInPlace();
		if (dir.Dot(vecWeaponDir) <= asw_turret_dot.GetFloat())
			continue;

		// we've got a possible target, add him to the list if he's not in there already
		bool bAlreadyInArray = false;
		int iSpace = -1;
		for (int k=0;k<ASW_MAX_TURRET_TARGETS;k++)
		{
			if (m_TurretTarget[k].Get() == pEnt)
			{
				bAlreadyInArray = true;
				break;
			}
			if (iSpace == -1 && m_TurretTarget[k].Get() == NULL)
				iSpace = k;
		}

		if (bAlreadyInArray)
			continue;

		if (iSpace != -1)
		{
			m_TurretTarget[iSpace] = pEnt;
			m_fTurretTargetLock[iSpace] = 0;
		}
	}
}
void CASWHudCrosshair::PaintReloadProgressBar( void )
{
	if ( !engine->IsActiveApp() )
	{
		m_pAmmoProgress->SetVisible( false );
		m_pFastReloadBar->SetVisible( false );
		return;
	}

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

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

	C_ASW_Weapon* pWeapon = pMarine->GetActiveASWWeapon();
	if ( !pWeapon || !asw_crosshair_use_perspective.GetBool() )
	{
		m_pAmmoProgress->SetVisible( false );
		m_pFastReloadBar->SetVisible( false );
		return;
	}

	int x, y;
	GetCurrentPos( x, y );
	int nCrosshair = GetCurrentCrosshair( x, y );

	if ( pWeapon && pWeapon->IsReloading() )
	{	
		m_bIsReloading = true;

		float flProgress = 0.0;

		float fStart = pWeapon->m_fReloadStart;
		float fNext = pWeapon->m_flNextPrimaryAttack;
		float fTotalTime = fNext - fStart;
		if (fTotalTime <= 0)
			fTotalTime = 0.1f;

		// if we're in single player, the progress code in the weapon doesn't run on the client because we aren't predicting
		if ( !cl_predict->GetInt() )
			flProgress = RescaleProgessForArt( (gpGlobals->curtime - fStart) / fTotalTime );
		else
			flProgress = RescaleProgessForArt( pWeapon->m_fReloadProgress );

		if ((int(gpGlobals->curtime*10) % 2) == 0)
			m_pAmmoProgress->SetFgColor( Color( 215, 205, 80, 255) );
		else
			m_pAmmoProgress->SetFgColor( Color( 175, 80, 80, 255) );

		if ( asw_fast_reload_enabled.GetBool() )
		{
			m_pFastReloadBar->SetFgColor( Color( 235, 235, 235, 100) );
			m_pFastReloadBar->SetBgColor( Color( 0, 0, 0, 0 ) );
			// fractions of ammo wide for fast reload start/end
			float fFastStart = RescaleProgessForArt( (pWeapon->m_fFastReloadStart - fStart) / fTotalTime );
			float fFastEnd = RescaleProgessForArt( (pWeapon->m_fFastReloadEnd - fStart) / fTotalTime );
			m_pFastReloadBar->SetStartProgress( fFastStart );
			m_pFastReloadBar->SetProgress( fFastEnd );
			m_pFastReloadBar->SetVisible( true );
		}

		m_pAmmoProgress->SetProgress( flProgress );
		m_pAmmoProgress->SetAlpha( 255 );
		m_pAmmoProgress->SetBgColor( Color( 100, 100, 100, 160*m_pAmmoProgress->GetScale() ) );
		m_pAmmoProgress->SetVisible( true );
	}
	/*else if ( m_bIsReloading )
	{
		m_bIsReloading = false;
		m_pAmmoProgress->SetFgColor( Color( 200, 200, 200, 255 ) );
		m_pAmmoProgress->SetProgress( 1.0 );
		vgui::GetAnimationController()->RunAnimationCommand( m_pAmmoProgress, "alpha",	0,		0, 0.5f, vgui::AnimationController::INTERPOLATOR_ACCEL );
	}
	*/
	else
	{
		float flScale = m_pAmmoProgress->GetScale();
		m_bIsReloading = false;
		m_pAmmoProgress->SetFgColor( Color( 220, 220, 220, 140*flScale ) );
		m_pFastReloadBar->SetVisible( false );

		int	nClip1 = pWeapon->Clip1();
		if ( nClip1 < 0 )
		{
			m_pAmmoProgress->SetVisible( false );
			return;
		}

		float flProgress = RescaleProgessForArt( float(nClip1) / float(pWeapon->GetMaxClip1()) ); 

		m_pAmmoProgress->SetProgress( flProgress );
		if ( flProgress < 0.25 && (int(gpGlobals->curtime*10) % 2) == 0 )
		{
			m_pAmmoProgress->SetBgColor( Color( 130, 90, 50, 160*flScale ) );
		}
		else
		{
			m_pAmmoProgress->SetBgColor( Color( 80, 80, 80, 130*flScale ) );
		}

		m_pAmmoProgress->SetVisible( !pPlayer->IsSniperScopeActive() && nCrosshair == m_nCrosshairTexture );
	}
};
void CASWHudCrosshair::PaintTurretTextures()
{
	// draw border in centre of screen
	//int h = ScreenHeight();
	//int w = h * 1.333333f;
	//int x = (ScreenWidth() * 0.5f) - (w * 0.5f);
	//int y = 0;

	surface()->DrawSetColor(Color(255,255,255,255));

	/*
	int tx = YRES( 5 );
	int ty = YRES( 5 );
	vgui::surface()->DrawSetTextFont( m_hTurretFont );
	vgui::surface()->DrawSetTextColor( 255, 255, 255, 200 );
	vgui::surface()->DrawSetTextPos( tx, ty );

	int nFontTall = vgui::surface()->GetFontTall( m_hTurretFont );

	wchar_t szconverted[ 1024 ];
	g_pVGuiLocalize->ConvertANSIToUnicode( "#asw_turret_text_top_left", szconverted, sizeof( szconverted )  );
	vgui::surface()->DrawPrintText( szconverted, wcslen( szconverted ) );

	ty = ScreenHeight() - nFontTall * 8 - YRES( 100 );
	vgui::surface()->DrawSetTextPos( tx, ty );
	g_pVGuiLocalize->ConvertANSIToUnicode( "#asw_turret_text_lower_left", szconverted, sizeof( szconverted )  );
	vgui::surface()->DrawPrintText( szconverted, wcslen( szconverted ) );
	*/

	// draw black boxes either side
	//if (m_nBlackBarTexture != -1)
	//{
		//surface()->DrawSetTexture(m_nBlackBarTexture);
		//surface()->DrawTexturedRect(0, y, x, y + h);
		//surface()->DrawTexturedRect(x + w, y, x, y + h);
	//}

	// draw fancy brackets over all turret targets
	float fScale = (ScreenHeight() / 768.0f);
	int iBSize = fScale * 32.0f;
	for (int i=0;i<ASW_MAX_TURRET_TARGETS;i++)
	{
		C_BaseEntity *pEnt = m_TurretTarget[i];
		if (!pEnt)
			continue;

		// distance of each bracket part from the ent
		float fDist = fScale * 200.0f * (1.0f - m_fTurretTargetLock[i]);
		
		Vector pos = (pEnt->WorldSpaceCenter() - pEnt->GetAbsOrigin()) + pEnt->GetRenderOrigin();
		Vector screenPos;
		debugoverlay->ScreenPosition( pos, screenPos );
		surface()->DrawSetColor(Color(255,255,255,255.0f * m_fTurretTargetLock[i] ));

		surface()->DrawSetTexture(m_nLeftBracketTexture);
		int bx = screenPos[0] - fDist;
		int by = screenPos[1] - fDist;
		surface()->DrawTexturedRect(bx - iBSize, by - iBSize, bx + iBSize, by + iBSize);

		surface()->DrawSetTexture(m_nRightBracketTexture);
		bx = screenPos[0] + fDist;
		by = screenPos[1] - fDist;
		surface()->DrawTexturedRect(bx - iBSize, by - iBSize, bx + iBSize, by + iBSize);

		surface()->DrawSetTexture(m_nLowerBracketTexture);
		bx = screenPos[0];
		by = screenPos[1] + fDist;
		surface()->DrawTexturedRect(bx - iBSize, by - iBSize, bx + iBSize, by + iBSize);
	}

	// draw crosshair
	C_ASW_Player* pPlayer = C_ASW_Player::GetLocalASWPlayer();
	if ( pPlayer )
	{
		C_ASW_Marine *pMarine = pPlayer->GetViewMarine();
		bool bControllingTurret = (pMarine && pMarine->IsControllingTurret());
		if (bControllingTurret)
		{
			C_ASW_Remote_Turret *pTurret = pMarine->GetRemoteTurret();
			if (pTurret)
			{
				Vector vecWeaponSrc = pTurret->GetTurretMuzzlePosition();
				QAngle angFacing = pTurret->EyeAngles();
				Vector vecWeaponDir;
				AngleVectors(angFacing, &vecWeaponDir);

				// trace along until we hit something
				trace_t tr;
				UTIL_TraceLine(vecWeaponSrc, vecWeaponSrc + vecWeaponDir * 1200,	// fog range of the turret
					MASK_SHOT, pTurret, COLLISION_GROUP_NONE, &tr);
				//Msg("Tracing from %s ", VecToString(vecWeaponSrc));
				//Msg("at angle %s\n", VecToString(angFacing));
				
				Vector pos = tr.DidHit() ? tr.endpos : vecWeaponSrc + vecWeaponDir * 1200;
				Vector screenPos;
				debugoverlay->ScreenPosition( pos, screenPos );

				// paint a crosshair at that spot
				surface()->DrawSetColor(Color(255,255,255,255));
				surface()->DrawSetTexture(m_nTurretCrosshair);
				surface()->DrawTexturedRect(screenPos[0] - iBSize, screenPos[1] - iBSize,	// shift it up a bit to match where the gun actually fires (not sure why it's not matched already!)
											screenPos[0] + iBSize, screenPos[1] + iBSize);
			}
		}
	}

	// draw interlace/noise overlay
	if (m_nTurretTexture!=-1)
	{
		surface()->DrawSetColor(Color(255,255,255,255));
		surface()->DrawSetTexture(m_nTurretTexture);
		surface()->DrawTexturedRect(0, 0, ScreenWidth(), ScreenHeight());
	}
}
void CASWHudCrosshair::Paint( void )
{
	VPROF_BUDGET( "CASWHudCrosshair::Paint", VPROF_BUDGETGROUP_ASW_CLIENT );
	if ( !crosshair.GetBool() )
		return;

	if ( engine->IsDrawingLoadingImage() || engine->IsPaused() || !engine->IsActiveApp() )
		return;
	
	C_ASW_Player* pPlayer = C_ASW_Player::GetLocalASWPlayer();
	if ( !pPlayer )
		return;

	if ( pPlayer->GetFlags() & FL_FROZEN )
		return;

	if ( pPlayer->entindex() != render->GetViewEntity() )
		return;

	m_curViewAngles = CurrentViewAngles();
	m_curViewOrigin = CurrentViewOrigin();

	C_ASW_Marine *pMarine = pPlayer->GetViewMarine();
	bool bControllingTurret = (pMarine && pMarine->IsControllingTurret());
	if ( bControllingTurret )
	{
		PaintTurretTextures();
		return;	// don't draw the normal cross hair in addition
	}

	int x, y;
	GetCurrentPos( x, y );

	int nCrosshair = GetCurrentCrosshair( x, y );

	if ( nCrosshair == m_nCrosshairTexture )
	{
		if ( pPlayer->IsSniperScopeActive() )
		{
			DrawSniperScope( x, y );
		}
		else
		{
			if ( pPlayer->GetASWControls() != 1 )
				return;
			DrawDirectionalCrosshair( x, y, YRES( asw_crosshair_progress_size.GetInt() ) );
		}
	}
	else if ( nCrosshair != -1 )
	{
		const float fCrosshairScale = 1.0f;
		int w = YRES( 20 ) * fCrosshairScale;
		int h = YRES( 20 ) * fCrosshairScale;
		surface()->DrawSetColor( m_clrCrosshair );
		surface()->DrawSetTexture( nCrosshair );
		surface()->DrawTexturedRect( x - w, y - h, x + w, y + h );
	}

	// icons attached to the cursor
	x += 32; y += 16;	// move them down and to the right a bit
	if ( m_bShowGiveAmmo )
	{
		// todo: this text should in the ammo report tooltip?
		const wchar_t *ammoName = g_pVGuiLocalize->Find(GetAmmoName(m_iShowGiveAmmoType));
		DrawAttachedIcon(m_nGiveAmmoTexture, x, y, ammoName);
	}
	else if (m_bShowGiveHealth)
	{
		DrawAttachedIcon(m_nGiveHealthTexture, x, y);
	}
}
Esempio n. 15
0
void CASW_Prediction::CheckMarineError( int nSlot, int commands_acknowledged )
{
	C_ASW_Player	*player;
	Vector		origin;
	Vector		delta;
	float		len;
	static int	pos = 0;

	// Not in the game yet
	if ( !engine->IsInGame() )
		return;

	// Not running prediction
	if ( !cl_predict->GetInt() )
		return;

	player = C_ASW_Player::GetLocalASWPlayer( nSlot );
	if ( !player )
		return;

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

	// Not predictable yet (flush entity packet?)
	if ( !pMarine->IsIntermediateDataAllocated() )
		return;

	origin = pMarine->GetNetworkOrigin();

	const void *slot = pMarine->GetPredictedFrame( commands_acknowledged - 1 );
	if ( !slot )
		return;

	if ( !m_bMarineOriginTypedescriptionSearched )
	{
		m_bMarineOriginTypedescriptionSearched = true;
		const typedescription_t *td = CPredictionCopy::FindFlatFieldByName( "m_vecNetworkOrigin", pMarine->GetPredDescMap() );
		if ( td ) 
		{
			m_MarineOriginTypeDescription.AddToTail( td );
		}
	}

	if ( !m_MarineOriginTypeDescription.Count() )
		return;

	Vector predicted_origin;

	memcpy( (Vector *)&predicted_origin, (Vector *)( (byte *)slot + m_MarineOriginTypeDescription[ 0 ]->flatOffset[ TD_OFFSET_PACKED ] ), sizeof( Vector ) );

	// Compare what the server returned with what we had predicted it to be
	VectorSubtract ( predicted_origin, origin, delta );

	len = VectorLength( delta );
	if (len > MAX_PREDICTION_ERROR )
	{	
		// A teleport or something, clear out error
		len = 0;
	}
	else
	{
		if ( len > MIN_PREDICTION_EPSILON )
		{
			pMarine->NotePredictionError( delta );

			if ( cl_showerror.GetInt() >= 1 )
			{
				con_nprint_t np;
				np.fixed_width_font = true;
				np.color[0] = 1.0f;
				np.color[1] = 0.95f;
				np.color[2] = 0.7f;
				np.index = 20 + ( ++pos % 20 );
				np.time_to_live = 2.0f;

				engine->Con_NXPrintf( &np, "marine pred error %6.3f units (%6.3f %6.3f %6.3f)", len, delta.x, delta.y, delta.z );
			}
		}
	}
}