本文整理汇总了C++中C_BaseObject::GetHealth方法的典型用法代码示例。如果您正苦于以下问题:C++ C_BaseObject::GetHealth方法的具体用法?C++ C_BaseObject::GetHealth怎么用?C++ C_BaseObject::GetHealth使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类C_BaseObject
的用法示例。
在下文中一共展示了C_BaseObject::GetHealth方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: PerformLayout
void CBuildingStatusItem_Sapper::PerformLayout( void )
{
BaseClass::PerformLayout();
// We only tick while active and with a valid built object
C_ObjectSapper *pSapper = static_cast<C_ObjectSapper*>(GetRepresentativeObject());
// only visible
SetVisible( pSapper != NULL );
if ( !IsActive() || !pSapper )
{
return;
}
C_BaseObject *pTarget = pSapper->GetParentObject();
if ( pTarget )
{
float flHealth = (float)pTarget->GetHealth() / (float)pTarget->GetMaxHealth();
m_pTargetHealthBar->SetProgress( flHealth );
int iTargetType = pTarget->GetType();
if ( m_iTargetType != iTargetType )
{
m_pTargetIcon->SetIcon( pTarget->GetHudStatusIcon() );
m_iTargetType = iTargetType;
}
}
else
{
m_pTargetHealthBar->SetProgress( 0.0f );
}
}
示例2: GetStatusText
//-----------------------------------------------------------------------------
// Purpose: Status string for hud
//-----------------------------------------------------------------------------
void C_ObjectSapper::GetStatusText( wchar_t *pStatus, int iMaxStatusLen )
{
float flHealthPercent = (float)GetHealth() / (float)GetMaxHealth();
wchar_t wszHealthPercent[32];
_snwprintf(wszHealthPercent, sizeof(wszHealthPercent)/sizeof(wchar_t) - 1, L"%d%%", (int)( flHealthPercent * 100 ) );
wchar_t *pszTemplate;
if ( IsBuilding() )
{
pszTemplate = g_pVGuiLocalize->Find( "#TF_ObjStatus_Sapper_Building" );
}
else
{
pszTemplate = g_pVGuiLocalize->Find( "#TF_ObjStatus_Sapper" );
}
if ( pszTemplate )
{
wchar_t wszTargetHealthPercent[32];
wszTargetHealthPercent[0] = '\0';
C_BaseObject *pParent = GetParentObject();
Assert( pParent );
if ( pParent )
{
float flTargetHealthPercent = (float)pParent->GetHealth() / (float)pParent->GetMaxHealth();
_snwprintf(wszTargetHealthPercent, sizeof(wszTargetHealthPercent)/sizeof(wchar_t) - 1, L"%d%%", (int)( flTargetHealthPercent * 100 ) );
}
g_pVGuiLocalize->ConstructString( pStatus, iMaxStatusLen, pszTemplate,
2,
wszHealthPercent,
wszTargetHealthPercent);
}
}
示例3: UpdateID
//.........这里部分代码省略.........
wchar_t wszChargeLevel[ 10 ];
_snwprintf( wszChargeLevel, ARRAYSIZE(wszChargeLevel) - 1, L"%.0f", pPlayer->MedicGetChargeLevel() * 100 );
wszChargeLevel[ ARRAYSIZE(wszChargeLevel)-1 ] = '\0';
g_pVGuiLocalize->ConstructString( sDataString, sizeof(sDataString), g_pVGuiLocalize->Find( "#TF_playerid_mediccharge" ), 1, wszChargeLevel );
}
if (pLocalTFPlayer->GetTeamNumber() == TEAM_SPECTATOR || pPlayer->InSameTeam(pLocalTFPlayer) || (bDisguisedEnemy && pPlayer->m_Shared.GetDisguiseTeam() == pLocalTFPlayer->GetTeamNumber()))
{
printFormatString = "#TF_playerid_sameteam";
bShowHealth = true;
}
else if ( pLocalTFPlayer->IsPlayerClass( TF_CLASS_SPY ) && !pPlayer->m_Shared.InCond( TF_COND_STEALTHED ) )
{
// Spy can see enemy's health.
printFormatString = "#TF_playerid_diffteam";
bShowHealth = true;
}
if ( bShowHealth )
{
C_TF_PlayerResource *tf_PR = dynamic_cast<C_TF_PlayerResource *>(g_PR);
if ( tf_PR )
{
flMaxHealth = tf_PR->GetMaxHealth( m_iTargetEntIndex );
iMaxBuffedHealth = pPlayer->m_Shared.GetMaxBuffedHealth();
if ( bDisguisedEnemy )
{
flHealth = (float)pPlayer->m_Shared.GetDisguiseHealth();
}
else
{
flHealth = (float)pPlayer->GetHealth();
}
}
else
{
bShowHealth = false;
}
}
if ( printFormatString )
{
wchar_t *pszPrepend = GetPrepend();
if ( !pszPrepend || !pszPrepend[0] )
{
pszPrepend = L"";
}
g_pVGuiLocalize->ConstructString( sIDString, sizeof(sIDString), g_pVGuiLocalize->Find(printFormatString), 2, pszPrepend, wszPlayerName );
}
}
else
{
// see if it is an object
if ( pEnt->IsBaseObject() )
{
C_BaseObject *pObj = assert_cast<C_BaseObject *>( pEnt );
pObj->GetTargetIDString( sIDString, sizeof(sIDString) );
pObj->GetTargetIDDataString( sDataString, sizeof(sDataString) );
bShowHealth = true;
flHealth = pObj->GetHealth();
flMaxHealth = pObj->GetMaxHealth();
C_TFPlayer *pBuilder = pObj->GetBuilder();
iColorNum = pBuilder ? pBuilder->GetTeamNumber() : pObj->GetTeamNumber();
示例4: OnTick
//-----------------------------------------------------------------------------
// 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;
}
}
}
}