Skip to content

[TF2] MvM: make miniboss icons appear before normals #1306

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 25 additions & 48 deletions src/game/client/tf/tf_hud_mann_vs_machine_status.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -524,14 +524,14 @@ void CWaveStatusPanel::UpdateEnemyCounts( void )
int nMaxEnemyCountNoSupport = TFObjectiveResource()->GetMannVsMachineWaveEnemyCount();

// Loop through all the class types to find which enemy counts to display
CUtlVector< hud_enemy_data_t > miniboss;
CUtlVector< hud_enemy_data_t > normal;
CUtlVector< hud_enemy_data_t > support;
CUtlVector< hud_enemy_data_t > mission;
int nNumEnemyRemaining = 0;
int nNumEnemyTypes = 0;
int nNumNonVerboseTypes = 0;

// Add icons to vectors
for ( int i = 0; i < MVM_CLASS_TYPES_PER_WAVE_MAX_NEW; ++i )
{
int nClassCount = TFObjectiveResource()->GetMannVsMachineWaveClassCount( i );
Expand Down Expand Up @@ -568,20 +568,7 @@ void CWaveStatusPanel::UpdateEnemyCounts( void )
nNumNonVerboseTypes++;
}
}
else if ( iFlags & MVM_CLASS_FLAG_MINIBOSS )
{
if ( nClassCount > 0 )
{
int index = miniboss.AddToTail();
miniboss[index].nCount = nClassCount;
miniboss[index].pchClassIconName = pchClassIconName;
miniboss[index].iFlags = iFlags;
miniboss[index].bActive = TFObjectiveResource()->GetMannVsMachineWaveClassActive( i );
nNumEnemyTypes++;
nNumEnemyRemaining += nClassCount;
}
}
else if ( iFlags & MVM_CLASS_FLAG_NORMAL )
else if ( iFlags & ( MVM_CLASS_FLAG_NORMAL | MVM_CLASS_FLAG_MINIBOSS ) )
{
// only show classes with > 0 remaining
if ( nClassCount > 0 )
Expand All @@ -603,6 +590,11 @@ void CWaveStatusPanel::UpdateEnemyCounts( void )
}
}

// Then sort, minibosses first, ordering kept
normal.StableSort();
support.StableSort();
mission.StableSort();

// update the progress bar
if ( nMaxEnemyCountNoSupport > 0 )
{
Expand Down Expand Up @@ -689,37 +681,6 @@ void CWaveStatusPanel::UpdateEnemyCounts( void )

int iPanelIndex = 0;

if ( bVerbose )
{
// miniboss enemies
for ( int i = 0 ; i < miniboss.Count() && iPanelIndex < m_EnemyCountPanels.Count() ; i++, iPanelIndex++ )
{
CEnemyCountPanel *pPanel = m_EnemyCountPanels[ iPanelIndex ];

pPanel->SetVisible( true );
pPanel->SetDialogVariable( "enemy_count", miniboss[i].nCount );
pPanel->SetPos( nXPos, m_nWaveCountYPos + nMinModeReduction );
pPanel->SetFlashing( false );

if ( pPanel->m_pEnemyCountImage )
{
pPanel->m_pEnemyCountImage->SetImage( VarArgs( "../hud/leaderboard_class_%s", miniboss[i].pchClassIconName ) );
pPanel->m_pEnemyCountImage->SetVisible( true );
}

if ( pPanel->m_pEnemyCountImageBG )
{
pPanel->m_pEnemyCountImageBG->SetBgColor( m_clrMiniBoss );
}
if ( pPanel->m_pEnemyCountCritBG )
{
pPanel->m_pEnemyCountCritBG->SetVisible( miniboss[i].iFlags & MVM_CLASS_FLAG_ALWAYSCRIT );
}

nXPos += nEnemyCountWide + m_nWaveCountOffset;
}
}

// normal enemies
for ( int i = 0 ; i < normal.Count() && iPanelIndex < m_EnemyCountPanels.Count() ; i++ )
{
Expand Down Expand Up @@ -769,8 +730,16 @@ void CWaveStatusPanel::UpdateEnemyCounts( void )
{
if ( pPanel->m_pEnemyCountImageBG )
{
pPanel->m_pEnemyCountImageBG->SetBgColor( m_clrNormal );
if ( normal[i].iFlags & MVM_CLASS_FLAG_MINIBOSS )
{
pPanel->m_pEnemyCountImageBG->SetBgColor( m_clrMiniBoss );
}
else
{
pPanel->m_pEnemyCountImageBG->SetBgColor( m_clrNormal );
}
}

if ( pPanel->m_pEnemyCountCritBG )
{
pPanel->m_pEnemyCountCritBG->SetVisible( normal[i].iFlags & MVM_CLASS_FLAG_ALWAYSCRIT );
Expand Down Expand Up @@ -918,8 +887,16 @@ void CWaveStatusPanel::UpdateEnemyCounts( void )
{
if ( pPanel->m_pEnemyCountImageBG )
{
pPanel->m_pEnemyCountImageBG->SetBgColor( m_clrNormal );
if ( mission[i].iFlags & MVM_CLASS_FLAG_MINIBOSS )
{
pPanel->m_pEnemyCountImageBG->SetBgColor( m_clrMiniBoss );
}
else
{
pPanel->m_pEnemyCountImageBG->SetBgColor( m_clrNormal );
}
}

if ( pPanel->m_pEnemyCountCritBG )
{
pPanel->m_pEnemyCountCritBG->SetVisible( false );
Expand Down
16 changes: 14 additions & 2 deletions src/game/client/tf/tf_hud_mann_vs_machine_status.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,25 @@
#define MAX_TANK_PROGRESS_BARS 5

//=========================================================
typedef struct
struct hud_enemy_data_t
{
int nCount;
const char *pchClassIconName;
int iFlags;
bool bActive;
} hud_enemy_data_t;

friend bool operator<( const hud_enemy_data_t& lhs, const hud_enemy_data_t& rhs )
{
// True only if lhs miniboss and rhs non-miniboss
if ( ( lhs.iFlags & MVM_CLASS_FLAG_MINIBOSS ) &&
!( rhs.iFlags & MVM_CLASS_FLAG_MINIBOSS ) ) {
return true;
}
return false;
}
};

typedef struct hud_enemy_data_t hud_enemy_data_t;

class CEnemyCountPanel : public vgui::EditablePanel, public CGameEventListener
{
Expand Down
8 changes: 8 additions & 0 deletions src/public/tier1/utlvector.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ class CUtlVector : public base_vector_t

/// sort using std:: and expecting a "<" function to be defined for the type
void Sort( void );
void StableSort( void );

/// sort using std:: with a predicate. e.g. [] -> bool ( T &a, T &b ) { return a < b; }
template <class F> void SortPredicate( F &&predicate );
Expand Down Expand Up @@ -944,6 +945,13 @@ void CUtlVector<T, A>::Sort( void )
std::sort( Base(), Base() + Count() );
}

template< typename T, class A >
void CUtlVector<T, A>::StableSort( void )
{
//STACK STATS TODO: Do we care about allocation tracking precision enough to match element origins across a sort?
std::stable_sort( Base(), Base() + Count() );
}

template< typename T, class A >
template <class F>
void CUtlVector<T, A>::SortPredicate( F &&predicate )
Expand Down