void CHudBuildingStatusContainer::RecalculateAlertState( void ) { BuildingHudAlert_t maxAlertLevel = BUILDING_HUD_ALERT_NONE; // find our highest warning level for ( int i = 0; i < m_BuildingPanels.Count(); i++ ) { CBuildingStatusItem *pItem = m_BuildingPanels.Element(i); C_BaseObject * pObj = pItem->GetRepresentativeObject(); if ( pObj ) { BuildingHudAlert_t alertLevel = pObj->GetBuildingAlertLevel(); if ( alertLevel > maxAlertLevel ) { maxAlertLevel = alertLevel; } } } if ( maxAlertLevel != m_AlertLevel ) { if ( maxAlertLevel >= BUILDING_HUD_ALERT_VERY_LOW_AMMO ) { m_flNextBeep = gpGlobals->curtime; // beep asap m_iNumBeepsToBeep = tf_hud_num_building_alert_beeps.GetInt(); } m_AlertLevel = maxAlertLevel; } }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CBuildingStatusItem::OnTick() { // We only tick while active and with a valid built object C_BaseObject *pObj = GetRepresentativeObject(); if ( !pObj ) // implies not active { if ( m_bActive ) { // we lost our object. force relayout to inactive mode InvalidateLayout(); // tell our parent that we're gone IGameEvent *event = gameeventmanager->CreateEvent( "building_info_changed" ); if ( event ) { event->SetInt( "building_type", GetRepresentativeObjectType() ); gameeventmanager->FireEventClientSide( event ); } } // We don't want to tick while inactive regardless return; } float flHealth = (float)pObj->GetHealth() / (float)pObj->GetMaxHealth(); m_pHealthBar->SetProgress( flHealth ); if ( pObj->IsBuilding() ) { m_pBuildingPanel->SetVisible( true ); m_pRunningPanel->SetVisible( false ); m_pBuildingProgress->SetProgress( pObj->GetPercentageConstructed() ); } else { m_pBuildingPanel->SetVisible( false ); m_pRunningPanel->SetVisible( true ); } // what is our current alert state? BuildingHudAlert_t alertLevel = pObj->GetBuildingAlertLevel(); if ( alertLevel <= BUILDING_HUD_ALERT_NONE ) { // if the tray is out, hide it if ( m_pAlertTray->IsTrayOut() ) { m_pAlertTray->HideTray(); m_pWrenchIcon->SetVisible( false ); m_pSapperIcon->SetVisible( false ); } } else { if ( !m_pAlertTray->IsTrayOut() ) { m_pAlertTray->ShowTray(); } m_pAlertTray->SetAlertType( alertLevel ); m_pWrenchIcon->SetVisible( false ); m_pSapperIcon->SetVisible( false ); if ( m_pAlertTray->GetAlertType() != BUILDING_HUD_ALERT_NONE && m_pAlertTray->GetPercentDeployed() >= 1.0f ) { switch( m_pAlertTray->GetAlertType() ) { case BUILDING_HUD_ALERT_LOW_AMMO: case BUILDING_HUD_ALERT_LOW_HEALTH: case BUILDING_HUD_ALERT_VERY_LOW_AMMO: case BUILDING_HUD_ALERT_VERY_LOW_HEALTH: m_pWrenchIcon->SetVisible( true ); break; case BUILDING_HUD_ALERT_SAPPER: m_pSapperIcon->SetVisible( true ); break; case BUILDING_HUD_ALERT_NONE: default: break; } } } }