5959#endif
6060#include " GameLogic/SidesList.h"
6161#include " GameNetwork/NetworkDefs.h"
62+ #include " GameNetwork/GameInfo.h"
63+ #include " GameNetwork/GameSlot.h"
6264
6365
6466// -----------------------------------------------------------------------------
@@ -69,9 +71,11 @@ PlayerList::PlayerList() :
6971 m_local(nullptr ),
7072 m_playerCount(0 )
7173{
72- // we only allocate a few of these, so don't bother pooling 'em
7374 for (Int i = 0 ; i < MAX_PLAYER_COUNT ; i++)
75+ {
7476 m_players[ i ] = NEW Player ( i );
77+ m_slotIndices[ i ] = -1 ;
78+ }
7579 init ();
7680}
7781
@@ -239,6 +243,8 @@ void PlayerList::newGame()
239243 p->setDefaultTeam ();
240244 }
241245
246+ // GeneralsX @bugfix felipebraz 05/07/2026 Pre-compute the network slot to player mapping
247+ resolveSlotIndices ();
242248}
243249
244250// -----------------------------------------------------------------------------
@@ -495,3 +501,41 @@ void PlayerList::loadPostProcess()
495501
496502}
497503
504+
505+ void PlayerList::setSlotIndex (Int playerIndex, Byte slotIndex)
506+ {
507+ if (playerIndex >= 0 && playerIndex < ARRAY_SIZE (m_slotIndices))
508+ {
509+ m_slotIndices[playerIndex] = slotIndex;
510+ }
511+ }
512+
513+ Byte PlayerList::getSlotIndex (Int playerIndex) const
514+ {
515+ if (playerIndex >= 0 && playerIndex < ARRAY_SIZE (m_slotIndices))
516+ {
517+ return m_slotIndices[playerIndex];
518+ }
519+
520+ return -1 ;
521+ }
522+
523+ void PlayerList::resolveSlotIndices ()
524+ {
525+ AsciiString playerName;
526+
527+ for (Int i = 0 ; i < MAX_SLOTS ; ++i)
528+ {
529+ const GameSlot* slot = TheGameInfo->getSlot (i);
530+ if (!slot || !slot->isOccupied ())
531+ continue ;
532+
533+ playerName.format (" player%d" , i);
534+
535+ Player* player = findPlayerWithNameKey (TheNameKeyGenerator->nameToKey (playerName));
536+ if (player)
537+ {
538+ setSlotIndex (player->getPlayerIndex (), i);
539+ }
540+ }
541+ }
0 commit comments