diff --git a/Core/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp b/Core/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp index c9c7cbb7602..32d6665719e 100644 --- a/Core/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp +++ b/Core/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp @@ -2383,15 +2383,9 @@ bool GameLogic::onLogicCrc(MAYBE_UNUSED GameMessage *msg) Player *msgPlayer = getMessagePlayer(msg); if (TheNetwork) { - Int slotIndex = -1; - for (Int i=0; igetPlayerType() == PLAYER_HUMAN && TheNetwork->getPlayerName(i) == msgPlayer->getPlayerDisplayName()) - { - slotIndex = i; - break; - } - } + const Int slotIndex = msgPlayer->getPlayerType() == PLAYER_HUMAN + ? ThePlayerList->getSlotIndex(msgPlayer->getPlayerIndex()) + : -1; if (slotIndex < 0 || !TheNetwork->isPlayerConnected(slotIndex)) return false; diff --git a/Generals/Code/GameEngine/Source/Common/Recorder.cpp b/Generals/Code/GameEngine/Source/Common/Recorder.cpp index a6f51ade405..256b75a6639 100644 --- a/Generals/Code/GameEngine/Source/Common/Recorder.cpp +++ b/Generals/Code/GameEngine/Source/Common/Recorder.cpp @@ -989,12 +989,9 @@ void RecorderClass::handleCRCMessage(UnsignedInt newCRC, Int playerIndex, Bool f } Int localPlayerIndex = m_crcInfo.getLocalPlayer(); - Bool samePlayer = FALSE; - AsciiString playerName; - playerName.format("player%d", localPlayerIndex); const Player *p = ThePlayerList->getNthPlayer(playerIndex); - if (!p || (p->getPlayerNameKey() == NAMEKEY(playerName))) - samePlayer = TRUE; + const Int slotIndex = ThePlayerList->getSlotIndex(playerIndex); + const Bool samePlayer = !p || slotIndex == localPlayerIndex; if (samePlayer || (localPlayerIndex < 0)) { UnsignedInt playbackCRC = m_crcInfo.readCRC(); diff --git a/Generals/Code/GameEngine/Source/GameLogic/ScriptEngine/VictoryConditions.cpp b/Generals/Code/GameEngine/Source/GameLogic/ScriptEngine/VictoryConditions.cpp index f101b226542..8e1b358ab6f 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/ScriptEngine/VictoryConditions.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/ScriptEngine/VictoryConditions.cpp @@ -211,19 +211,12 @@ void VictoryConditions::update() TheAudio->addAudioEvent(&leftGameSound); } - for (Int idx = 0; idx < MAX_SLOTS; ++idx) + const Int slotIndex = ThePlayerList->getSlotIndex(p->getPlayerIndex()); + GameSlot *slot = TheGameInfo && slotIndex >= 0 ? TheGameInfo->getSlot(slotIndex) : nullptr; + if (slot && slot->isAI()) { - AsciiString pName; - pName.format("player%d", idx); - if (p->getPlayerNameKey() == NAMEKEY(pName)) - { - GameSlot *slot = (TheGameInfo)?TheGameInfo->getSlot(idx):nullptr; - if (slot && slot->isAI()) - { - DEBUG_LOG(("Marking AI player %s as defeated", pName.str())); - slot->setLastFrameInGame(TheGameLogic->getFrame()); - } - } + DEBUG_LOG(("Marking AI player %s as defeated", TheNameKeyGenerator->keyToName(p->getPlayerNameKey()).str())); + slot->setLastFrameInGame(TheGameLogic->getFrame()); } // destroy any remaining units (infantry if its a short game, for example) diff --git a/GeneralsMD/Code/GameEngine/Source/Common/Recorder.cpp b/GeneralsMD/Code/GameEngine/Source/Common/Recorder.cpp index 2d9bfea3a16..eedce53950a 100644 --- a/GeneralsMD/Code/GameEngine/Source/Common/Recorder.cpp +++ b/GeneralsMD/Code/GameEngine/Source/Common/Recorder.cpp @@ -991,12 +991,9 @@ void RecorderClass::handleCRCMessage(UnsignedInt newCRC, Int playerIndex, Bool f } Int localPlayerIndex = m_crcInfo.getLocalPlayer(); - Bool samePlayer = FALSE; - AsciiString playerName; - playerName.format("player%d", localPlayerIndex); const Player *p = ThePlayerList->getNthPlayer(playerIndex); - if (!p || (p->getPlayerNameKey() == NAMEKEY(playerName))) - samePlayer = TRUE; + const Int slotIndex = ThePlayerList->getSlotIndex(playerIndex); + const Bool samePlayer = !p || slotIndex == localPlayerIndex; if (samePlayer || (localPlayerIndex < 0)) { UnsignedInt playbackCRC = m_crcInfo.readCRC(); diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/ScriptEngine/VictoryConditions.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/ScriptEngine/VictoryConditions.cpp index 76fc18d6e41..5717943cc20 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/ScriptEngine/VictoryConditions.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/ScriptEngine/VictoryConditions.cpp @@ -213,19 +213,12 @@ void VictoryConditions::update() TheAudio->addAudioEvent(&leftGameSound); } - for (Int idx = 0; idx < MAX_SLOTS; ++idx) + const Int slotIndex = ThePlayerList->getSlotIndex(p->getPlayerIndex()); + GameSlot *slot = TheGameInfo && slotIndex >= 0 ? TheGameInfo->getSlot(slotIndex) : nullptr; + if (slot && slot->isAI()) { - AsciiString pName; - pName.format("player%d", idx); - if (p->getPlayerNameKey() == NAMEKEY(pName)) - { - GameSlot *slot = (TheGameInfo)?TheGameInfo->getSlot(idx):nullptr; - if (slot && slot->isAI()) - { - DEBUG_LOG(("Marking AI player %s as defeated", pName.str())); - slot->setLastFrameInGame(TheGameLogic->getFrame()); - } - } + DEBUG_LOG(("Marking AI player %s as defeated", TheNameKeyGenerator->keyToName(p->getPlayerNameKey()).str())); + slot->setLastFrameInGame(TheGameLogic->getFrame()); } // destroy any remaining units (infantry if its a short game, for example)