@@ -26,7 +26,7 @@ void APlayerSet::Reset()
2626{
2727 m_strUnk.SetPooledString ( TNULL );
2828
29- m_vecHumanSlots .Clear ();
29+ m_vecPlayerSlots .Clear ();
3030 m_aPlayerTeams[ 0 ] = 2 ;
3131 m_aPlayerTeams[ 1 ] = 2 ;
3232 m_aPlayerTeams[ 2 ] = 2 ;
@@ -45,7 +45,7 @@ TINT APlayerSet::AddAIPlayer()
4545}
4646
4747// $Barnyard: FUNCTION 006206d0
48- APlayerHumanSlot * APlayerSet::AddHumanPlayer ( Toshi::TInputDeviceController* a_pController )
48+ APlayerSlot * APlayerSet::AddHumanPlayer ( Toshi::TInputDeviceController* a_pController )
4949{
5050 // Adjust number of AI players
5151 if ( m_iNumHumanPlayers + m_iNumAIPlayers >= MAX_NUM_PLAYERS )
@@ -57,20 +57,20 @@ APlayerHumanSlot* APlayerSet::AddHumanPlayer( Toshi::TInputDeviceController* a_p
5757 }
5858
5959 // Find free slot
60- decltype ( m_vecHumanSlots )::Iterator itInsertBefore = m_vecHumanSlots .Begin ();
61- T2_FOREACH ( m_vecHumanSlots , it )
60+ auto itInsertBefore = m_vecPlayerSlots .Begin ();
61+ T2_FOREACH ( m_vecPlayerSlots , it )
6262 {
63- if ( ! it->m_bUsed )
63+ if ( it->m_uiFlags == 0 )
6464 {
6565 itInsertBefore = it;
6666 break ;
6767 }
6868 }
6969
70- APlayerHumanSlot oUsedSlot ( a_pController, TTRUE );
71- m_vecHumanSlots .InsertBefore ( itInsertBefore, oUsedSlot );
70+ APlayerSlot oUsedSlot ( a_pController, APlayerSlot::FLAGS_USED );
71+ m_vecPlayerSlots .InsertBefore ( itInsertBefore, oUsedSlot );
7272
73- return &m_vecHumanSlots [ itInsertBefore.Index () ];
73+ return &m_vecPlayerSlots [ itInsertBefore.Index () ];
7474}
7575
7676// $Barnyard: FUNCTION 006205f0
@@ -131,49 +131,68 @@ void APlayerSet::MakeTeamsFair()
131131 }
132132}
133133
134+ // $Barnyard: FUNCTION 00620820
135+ void APlayerSet::FinishUpAddingAIs ()
136+ {
137+ // Count all player slots without the AI flag
138+ TINT iCurrentNumAIPlayers = 0 ;
139+ for ( TINT i = 0 ; i < m_vecPlayerSlots.Size (); i++ )
140+ {
141+ if ( m_vecPlayerSlots[ i ].m_uiFlags & APlayerSlot::FLAGS_AI )
142+ iCurrentNumAIPlayers += 1 ;
143+ }
144+
145+ // Add missing AI players
146+ while ( iCurrentNumAIPlayers < m_iNumAIPlayers )
147+ {
148+ m_vecPlayerSlots.PushBack ( APlayerSlot ( TNULL, APlayerSlot::FLAGS_AI ) );
149+ iCurrentNumAIPlayers += 1 ;
150+ }
151+ }
152+
134153// $Barnyard: FUNCTION 00620400
135154TBOOL APlayerSet::IsPlayerSlotUsed ( TINT a_iSlot ) const
136155{
137- return m_vecHumanSlots [ a_iSlot ].m_bUsed & 1 ;
156+ return m_vecPlayerSlots [ a_iSlot ].m_uiFlags & 1 ;
138157}
139158
140159// $Barnyard: FUNCTION 006206d0
141- APlayerHumanSlot::APlayerHumanSlot ( Toshi::TInputDeviceController* a_pController, TBOOL a_bUsed )
160+ APlayerSlot::APlayerSlot ( Toshi::TInputDeviceController* a_pController, FLAGS a_uiFlags )
142161 : m_Unk1( 0 )
143162 , m_pController( a_pController )
144- , m_bUsed( a_bUsed )
163+ , m_uiFlags( a_uiFlags )
145164{
146165}
147166
148167// $Barnyard: FUNCTION 006206e0
149- APlayerHumanSlot::APlayerHumanSlot ( const APlayerHumanSlot & a_rcOther )
168+ APlayerSlot::APlayerSlot ( const APlayerSlot & a_rcOther )
150169{
151170 m_Unk1 = a_rcOther.m_Unk1 ;
152171 m_pController = a_rcOther.m_pController ;
153172 m_strUnk = a_rcOther.m_strUnk ;
154- m_bUsed = a_rcOther.m_bUsed ;
173+ m_uiFlags = a_rcOther.m_uiFlags ;
155174}
156175
157176// $Barnyard: FUNCTION 00620740
158- APlayerHumanSlot ::~APlayerHumanSlot ()
177+ APlayerSlot ::~APlayerSlot ()
159178{
160179 Reset ();
161180}
162181
163182// $Barnyard: FUNCTION 006207c0
164- APlayerHumanSlot& APlayerHumanSlot ::operator =( const APlayerHumanSlot & a_rcOther )
183+ APlayerSlot& APlayerSlot ::operator =( const APlayerSlot & a_rcOther )
165184{
166185 Reset ();
167186
168187 m_Unk1 = a_rcOther.m_Unk1 ;
169188 m_pController = a_rcOther.m_pController ;
170189 m_strUnk = a_rcOther.m_strUnk ;
171- m_bUsed = a_rcOther.m_bUsed ;
190+ m_uiFlags = a_rcOther.m_uiFlags ;
172191
173192 return *this ;
174193}
175194
176- void APlayerHumanSlot ::Reset ()
195+ void APlayerSlot ::Reset ()
177196{
178197 TASSERT ( TFALSE && " Destroy Unk1" );
179198 m_strUnk.SetPooledString ( TNULL );
0 commit comments