void CPlayerTeamMatchProxy::OnBind( void *pC_BaseEntity )
{
	if (!pC_BaseEntity)
		return;

	// Find the distance between the player and this entity....
	C_BaseEntity *pEntity = BindArgToEntity( pC_BaseEntity );
	C_BaseEntity* pPlayer = C_BasePlayer::GetLocalPlayer();
	if (!pPlayer)
		return;

	Assert( m_pResult );
	SetFloatResult( (pEntity->GetTeamNumber() == pPlayer->GetTeamNumber()) ? 1.0 : 0.0 );

	if ( ToolsEnabled() )
	{
		ToolFramework_RecordMaterialParams( GetMaterial() );
	}
}
//-----------------------------------------------------------------------------
// called when we're ticked...
//-----------------------------------------------------------------------------
void CEntityImageHealthPanel::OnTick()
{
	// tick the entity panel
	BaseClass::OnTick();

	C_BaseEntity* pBaseEntity = GetEntity();
	if (!pBaseEntity)
		return;
	// Don't draw if I'm not visible in the tactical map
	if ( MapData().IsEntityVisibleToTactical( pBaseEntity ) == false )
		return;

	if ( m_CommanderHealthBar )
		m_CommanderHealthBar->SetHealth( (float)pBaseEntity->GetHealth() / (float)pBaseEntity->GetMaxHealth() );
	if ( m_NormalHealthBar )
		m_NormalHealthBar->SetHealth( (float)pBaseEntity->GetHealth() / (float)pBaseEntity->GetMaxHealth() );

	// Hide the health bar we don't want to see
	C_BasePlayer *pPlayer = C_BasePlayer::GetLocalPlayer();

	if ( pPlayer && (pBaseEntity->GetTeamNumber() != pPlayer->GetTeamNumber()) )
	{
		if ( m_CommanderHealthBar )
			m_CommanderHealthBar->SetVisible( false );
		if ( m_NormalHealthBar ) 
			m_NormalHealthBar->SetVisible( false );
		if ( m_ResourceLevelBar )
			m_ResourceLevelBar->SetVisible( false );
		if ( m_pImagePanel )
			m_pImagePanel->SetVisible( false );
	}
	else if ( IsLocalPlayerInTactical() )
	{
		if ( m_CommanderHealthBar )
			m_CommanderHealthBar->SetVisible( true );
		if ( m_NormalHealthBar ) 
			m_NormalHealthBar->SetVisible( false );
		if ( m_ResourceLevelBar )
			m_ResourceLevelBar->SetVisible( true );
		if ( m_pImagePanel )
			m_pImagePanel->SetVisible( true );
	}
	else
	{
		if ( m_CommanderHealthBar )
			m_CommanderHealthBar->SetVisible( false );
		if ( m_NormalHealthBar ) 
			m_NormalHealthBar->SetVisible( true );
		if ( m_ResourceLevelBar )
			m_ResourceLevelBar->SetVisible( true );
		if ( m_pImagePanel )
			m_pImagePanel->SetVisible( false );
	}
}
Example #3
0
//-----------------------------------------------------------------------------
// Are we visible to someone on this team?
//-----------------------------------------------------------------------------
bool C_VGuiScreen::IsVisibleToTeam( int nTeam )
{
	// FIXME: Should this maybe go into a derived class of some sort?
	// Don't bother with screens on the wrong team
	if (IsVisibleOnlyToTeammates() && (nTeam > 0))
	{
		// Hmmm... sort of a hack...
		C_BaseEntity *pOwner = GetOwnerEntity();
		if ( pOwner && (nTeam != pOwner->GetTeamNumber()) )
			return false;
	}
	
	return true;
}
//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CTFHudFlagObjectives::UpdateStatus( void )
{
	C_TFPlayer *pLocalPlayer = ToTFPlayer( C_BasePlayer::GetLocalPlayer() );

	// are we carrying a flag?
	CCaptureFlag *pPlayerFlag = NULL;
	if ( pLocalPlayer && pLocalPlayer->HasItem() && ( pLocalPlayer->GetItem()->GetItemID() == TF_ITEM_CAPTURE_FLAG ) )
	{
		pPlayerFlag = dynamic_cast<CCaptureFlag*>( pLocalPlayer->GetItem() );
	}

	if ( pPlayerFlag )
	{
		m_bCarryingFlag = true;

		// make sure the panels are on, set the initial alpha values, 
		// set the color of the flag we're carrying, and start the animations
		if ( m_pCarriedImage && !m_bFlagAnimationPlayed )
		{
			m_bFlagAnimationPlayed = true;

			// Set the correct flag image depending on the flag we're holding
			switch (pPlayerFlag->GetTeamNumber())
			{
				case TF_TEAM_RED:
					m_pCarriedImage->SetImage("../hud/objectives_flagpanel_carried_red");
					break;	
				case TF_TEAM_BLUE:
					m_pCarriedImage->SetImage("../hud/objectives_flagpanel_carried_blue");
					break;
				case TF_TEAM_GREEN:
					m_pCarriedImage->SetImage("../hud/objectives_flagpanel_carried_green");
					break;
				case TF_TEAM_YELLOW:
					m_pCarriedImage->SetImage("../hud/objectives_flagpanel_carried_yellow");
					break;
			}

			if (m_pRedFlag && m_pRedFlag->IsVisible())
			{
				m_pRedFlag->SetVisible(false);
			}

			if ( m_pBlueFlag && m_pBlueFlag->IsVisible() )
			{
				m_pBlueFlag->SetVisible( false );
			}

			if (m_pGreenFlag && m_pGreenFlag->IsVisible())
			{
				m_pGreenFlag->SetVisible(false);
			}

			if (m_pYellowFlag && m_pYellowFlag->IsVisible())
			{
				m_pYellowFlag->SetVisible(false);
			}

			if ( !m_pCarriedImage->IsVisible() )
			{
				m_pCarriedImage->SetVisible( true );
			}

			g_pClientMode->GetViewportAnimationController()->StartAnimationSequence( "FlagOutline" );

			if ( m_pCapturePoint )
			{
				if ( !m_pCapturePoint->IsVisible() )
				{
					m_pCapturePoint->SetVisible( true );
				}

				if ( pLocalPlayer )
				{
					// go through all the capture zones and find ours
					for ( int i = 0; i < g_CaptureZones.Count(); i++ )
					{
						C_BaseEntity *pZone = ClientEntityList().GetEnt( g_CaptureZones[i] );

						if ( pZone )
						{
							if ( pZone->GetTeamNumber() == pLocalPlayer->GetTeamNumber() )
							{
								m_pCapturePoint->SetEntity( pZone );
							}
						}
					}
				}
			}
		}
	}
	else
	{
		// were we carrying the flag?
		if ( m_bCarryingFlag )
		{
			m_bCarryingFlag = false;
			g_pClientMode->GetViewportAnimationController()->StartAnimationSequence( "FlagOutline" );
		}

		m_bFlagAnimationPlayed = false;

		if ( m_pCarriedImage && m_pCarriedImage->IsVisible() )
		{
			m_pCarriedImage->SetVisible( false );
		}

		if ( m_pCapturePoint && m_pCapturePoint->IsVisible() )
		{
			m_pCapturePoint->SetVisible( false );
		}

		if ( m_pBlueFlag )
		{
			if ( !m_pBlueFlag->IsVisible() )
			{
				m_pBlueFlag->SetVisible( true );
			}
			
			m_pBlueFlag->UpdateStatus();
		}

		if ( m_pRedFlag )
		{
			if ( !m_pRedFlag->IsVisible() )
			{
				m_pRedFlag->SetVisible( true );
			}

			m_pRedFlag->UpdateStatus();
		}

		if (m_pGreenFlag)
		{
			if (!m_pGreenFlag->IsVisible())
			{
				m_pGreenFlag->SetVisible(true);
			}

			m_pGreenFlag->UpdateStatus();
		}

		if (m_pYellowFlag)
		{
			if (!m_pYellowFlag->IsVisible())
			{
				m_pYellowFlag->SetVisible(true);
			}

			m_pYellowFlag->UpdateStatus();
		}
	}
}
//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CTFArrowPanel::Paint()
{
	if ( !m_hEntity.Get() )
		return;

	C_BaseEntity *pEnt = m_hEntity.Get();
	IMaterial *pMaterial = m_NeutralMaterial;

	C_TFPlayer *pLocalPlayer = C_TFPlayer::GetLocalTFPlayer();

	// figure out what material we need to use
	if ( pEnt->GetTeamNumber() == TF_TEAM_RED )
	{
		pMaterial = m_RedMaterial;

		if ( pLocalPlayer && ( pLocalPlayer->GetObserverMode() == OBS_MODE_IN_EYE ) )
		{
			// is our target a player?
			C_BaseEntity *pTargetEnt = pLocalPlayer->GetObserverTarget();
			if ( pTargetEnt && pTargetEnt->IsPlayer() )
			{
				// does our target have the flag and are they carrying the flag we're currently drawing?
				C_TFPlayer *pTarget = static_cast< C_TFPlayer* >( pTargetEnt );
				if ( pTarget->HasTheFlag() && ( pTarget->GetItem() == pEnt ) )
				{
					pMaterial = m_RedMaterialNoArrow;
				}
			}
		}
	}
	else if ( pEnt->GetTeamNumber() == TF_TEAM_BLUE )
	{
		pMaterial = m_BlueMaterial;

		if ( pLocalPlayer && ( pLocalPlayer->GetObserverMode() == OBS_MODE_IN_EYE ) )
		{
			// is our target a player?
			C_BaseEntity *pTargetEnt = pLocalPlayer->GetObserverTarget();
			if ( pTargetEnt && pTargetEnt->IsPlayer() )
			{
				// does our target have the flag and are they carrying the flag we're currently drawing?
				C_TFPlayer *pTarget = static_cast< C_TFPlayer* >( pTargetEnt );
				if ( pTarget->HasTheFlag() && ( pTarget->GetItem() == pEnt ) )
				{
					pMaterial = m_BlueMaterialNoArrow;
				}
			}
		}
	}
	else if (pEnt->GetTeamNumber() == TF_TEAM_GREEN)
	{
		pMaterial = m_GreenMaterial;

		if (pLocalPlayer && (pLocalPlayer->GetObserverMode() == OBS_MODE_IN_EYE))
		{
			// is our target a player?
			C_BaseEntity *pTargetEnt = pLocalPlayer->GetObserverTarget();
			if (pTargetEnt && pTargetEnt->IsPlayer())
			{
				// does our target have the flag and are they carrying the flag we're currently drawing?
				C_TFPlayer *pTarget = static_cast< C_TFPlayer* >(pTargetEnt);
				if (pTarget->HasTheFlag() && (pTarget->GetItem() == pEnt))
				{
					pMaterial = m_GreenMaterialNoArrow;
				}
			}
		}
	}
	else if (pEnt->GetTeamNumber() == TF_TEAM_YELLOW)
	{
		pMaterial = m_YellowMaterial;

		if (pLocalPlayer && (pLocalPlayer->GetObserverMode() == OBS_MODE_IN_EYE))
		{
			// is our target a player?
			C_BaseEntity *pTargetEnt = pLocalPlayer->GetObserverTarget();
			if (pTargetEnt && pTargetEnt->IsPlayer())
			{
				// does our target have the flag and are they carrying the flag we're currently drawing?
				C_TFPlayer *pTarget = static_cast< C_TFPlayer* >(pTargetEnt);
				if (pTarget->HasTheFlag() && (pTarget->GetItem() == pEnt))
				{
					pMaterial = m_YellowMaterialNoArrow;
				}
			}
		}
	}

	int x = 0;
	int y = 0;
	ipanel()->GetAbsPos( GetVPanel(), x, y );
	int nWidth = GetWide();
	int nHeight = GetTall();

	CMatRenderContextPtr pRenderContext( materials );
	pRenderContext->MatrixMode( MATERIAL_MODEL );
	pRenderContext->PushMatrix(); 

	VMatrix panelRotation;
	panelRotation.Identity();
	MatrixBuildRotationAboutAxis( panelRotation, Vector( 0, 0, 1 ), GetAngleRotation() );
//	MatrixRotate( panelRotation, Vector( 1, 0, 0 ), 5 );
	panelRotation.SetTranslation( Vector( x + nWidth/2, y + nHeight/2, 0 ) );
	pRenderContext->LoadMatrix( panelRotation );

	IMesh *pMesh = pRenderContext->GetDynamicMesh( true, NULL, NULL, pMaterial );

	CMeshBuilder meshBuilder;
	meshBuilder.Begin( pMesh, MATERIAL_QUADS, 1 );

	meshBuilder.TexCoord2f( 0, 0, 0 );
	meshBuilder.Position3f( -nWidth/2, -nHeight/2, 0 );
	meshBuilder.Color4ub( 255, 255, 255, 255 );
	meshBuilder.AdvanceVertex();

	meshBuilder.TexCoord2f( 0, 1, 0 );
	meshBuilder.Position3f( nWidth/2, -nHeight/2, 0 );
	meshBuilder.Color4ub( 255, 255, 255, 255 );
	meshBuilder.AdvanceVertex();

	meshBuilder.TexCoord2f( 0, 1, 1 );
	meshBuilder.Position3f( nWidth/2, nHeight/2, 0 );
	meshBuilder.Color4ub( 255, 255, 255, 255 );
	meshBuilder.AdvanceVertex();

	meshBuilder.TexCoord2f( 0, 0, 1 );
	meshBuilder.Position3f( -nWidth/2, nHeight/2, 0 );
	meshBuilder.Color4ub( 255, 255, 255, 255 );
	meshBuilder.AdvanceVertex();

	meshBuilder.End();

	pMesh->Draw();
	pRenderContext->PopMatrix();
}