diff --git a/Core/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp b/Core/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp index c9c7cbb7602..fd9733f25ac 100644 --- a/Core/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp +++ b/Core/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp @@ -2383,18 +2383,16 @@ bool GameLogic::onLogicCrc(MAYBE_UNUSED GameMessage *msg) Player *msgPlayer = getMessagePlayer(msg); if (TheNetwork) { - Int slotIndex = -1; - for (Int i=0; igetPlayerType() != PLAYER_HUMAN) { - if (msgPlayer->getPlayerType() == PLAYER_HUMAN && TheNetwork->getPlayerName(i) == msgPlayer->getPlayerDisplayName()) - { - slotIndex = i; - break; - } + return false; } + const Int slotIndex = ThePlayerList->getSlotIndex(msgPlayer->getPlayerIndex()); if (slotIndex < 0 || !TheNetwork->isPlayerConnected(slotIndex)) + { return false; + } if (msgPlayer->isLocalPlayer()) { diff --git a/Generals/Code/GameEngine/Source/Common/Recorder.cpp b/Generals/Code/GameEngine/Source/Common/Recorder.cpp index a6f51ade405..7a955895827 100644 --- a/Generals/Code/GameEngine/Source/Common/Recorder.cpp +++ b/Generals/Code/GameEngine/Source/Common/Recorder.cpp @@ -989,13 +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; - if (samePlayer || (localPlayerIndex < 0)) + const Bool isLocalPlayer = !p || ThePlayerList->getSlotIndex(playerIndex) == localPlayerIndex; + if (isLocalPlayer) { UnsignedInt playbackCRC = m_crcInfo.readCRC(); //DEBUG_LOG(("RecorderClass::handleCRCMessage() - Comparing CRCs of InGame:%8.8X Replay:%8.8X Frame:%d from Player %d", diff --git a/Generals/Code/GameEngine/Source/GameLogic/ScriptEngine/VictoryConditions.cpp b/Generals/Code/GameEngine/Source/GameLogic/ScriptEngine/VictoryConditions.cpp index f101b226542..f27c9f93368 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/ScriptEngine/VictoryConditions.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/ScriptEngine/VictoryConditions.cpp @@ -211,18 +211,15 @@ void VictoryConditions::update() TheAudio->addAudioEvent(&leftGameSound); } - for (Int idx = 0; idx < MAX_SLOTS; ++idx) + if (TheGameInfo) { - AsciiString pName; - pName.format("player%d", idx); - if (p->getPlayerNameKey() == NAMEKEY(pName)) + const Int slotIndex = ThePlayerList->getSlotIndex(p->getPlayerIndex()); + const GameSlot* slot = slotIndex >= 0 ? TheGameInfo->getSlot(slotIndex) : nullptr; + + if (slot && slot->isAI()) { - 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()); } } diff --git a/GeneralsMD/Code/GameEngine/Source/Common/Recorder.cpp b/GeneralsMD/Code/GameEngine/Source/Common/Recorder.cpp index 2d9bfea3a16..9d71eb45b1b 100644 --- a/GeneralsMD/Code/GameEngine/Source/Common/Recorder.cpp +++ b/GeneralsMD/Code/GameEngine/Source/Common/Recorder.cpp @@ -991,13 +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; - if (samePlayer || (localPlayerIndex < 0)) + const Bool isLocalPlayer = !p || ThePlayerList->getSlotIndex(playerIndex) == localPlayerIndex; + if (isLocalPlayer) { UnsignedInt playbackCRC = m_crcInfo.readCRC(); //DEBUG_LOG(("RecorderClass::handleCRCMessage() - Comparing CRCs of InGame:%8.8X Replay:%8.8X Frame:%d from Player %d", diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/ScriptEngine/VictoryConditions.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/ScriptEngine/VictoryConditions.cpp index 76fc18d6e41..d8e217f6d35 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/ScriptEngine/VictoryConditions.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/ScriptEngine/VictoryConditions.cpp @@ -213,18 +213,15 @@ void VictoryConditions::update() TheAudio->addAudioEvent(&leftGameSound); } - for (Int idx = 0; idx < MAX_SLOTS; ++idx) + if (TheGameInfo) { - AsciiString pName; - pName.format("player%d", idx); - if (p->getPlayerNameKey() == NAMEKEY(pName)) + const Int slotIndex = ThePlayerList->getSlotIndex(p->getPlayerIndex()); + GameSlot *const slot = slotIndex >= 0 ? TheGameInfo->getSlot(slotIndex) : nullptr; + + if (slot && slot->isAI()) { - 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()); } }