Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,7 @@ void ControlBar::populateObserverList()

for (i = 0; i < MAX_SLOTS; ++i)
{
AsciiString name;
name.format("player%d", i);
Player *p = ThePlayerList->findPlayerWithNameKey(TheNameKeyGenerator->nameToKey(name));
Player *p = ThePlayerList->getPlayerFromSlotIndex(i);
if(p)
{
if(p->isPlayerObserver())
Expand Down
4 changes: 1 addition & 3 deletions Core/GameEngine/Source/GameNetwork/ConnectionManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -764,9 +764,7 @@ void ConnectionManager::processChat(NetChatCommandMsg *msg)
unitext.format(L"[%ls] %ls", name.str(), msg->getText().str());
// DEBUG_LOG(("ConnectionManager::processChat - got message from player %d (mask %8.8X), message is %ls", playerID, msg->getPlayerMask(), unitext.str()));

AsciiString playerName;
playerName.format("player%d", msg->getPlayerID());
const Player *player = ThePlayerList->findPlayerWithNameKey( TheNameKeyGenerator->nameToKey( playerName ) );
const Player *player = ThePlayerList->getPlayerFromSlotIndex(playerID);
if (!player)
{
TheInGameUI->message(L"%ls", unitext.str());
Expand Down
14 changes: 3 additions & 11 deletions Core/GameEngine/Source/GameNetwork/GameSpy/StagingRoomGameInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -600,9 +600,7 @@ AsciiString GameSpyStagingRoom::generateGameSpyGameResultsPacket()
Int lastTeamAtGameEnd = -1;
for (i=0; i<MAX_SLOTS; ++i)
{
AsciiString playerName;
playerName.format("player%d", i);
Player *p = ThePlayerList->findPlayerWithNameKey(NAMEKEY(playerName));
Player *p = ThePlayerList->getPlayerFromSlotIndex(i);
if (p)
{
++numHumans;
Expand Down Expand Up @@ -646,9 +644,7 @@ AsciiString GameSpyStagingRoom::generateGameSpyGameResultsPacket()
Int playerID = 0;
for (i=0; i<MAX_SLOTS; ++i)
{
AsciiString playerName;
playerName.format("player%d", i);
Player *p = ThePlayerList->findPlayerWithNameKey(NAMEKEY(playerName));
Player *p = ThePlayerList->getPlayerFromSlotIndex(i);
if (p)
{
GameSpyGameSlot *slot = &(m_GameSpySlot[i]);
Expand Down Expand Up @@ -694,9 +690,7 @@ AsciiString GameSpyStagingRoom::generateLadderGameResultsPacket()
Player* p[MAX_SLOTS];
for (i=0; i<MAX_SLOTS; ++i)
{
AsciiString playerName;
playerName.format("player%d", i);
p[i] = ThePlayerList->findPlayerWithNameKey(NAMEKEY(playerName));
p[i] = ThePlayerList->getPlayerFromSlotIndex(i);
if (p[i])
{
++numPlayers;
Expand Down Expand Up @@ -730,8 +724,6 @@ AsciiString GameSpyStagingRoom::generateLadderGameResultsPacket()
Int playerID = 0;
for (i=0; i<MAX_SLOTS; ++i)
{
AsciiString playerName;
playerName.format("player%d", i);
if (p[i])
{
GameSpyGameSlot *slot = &(m_GameSpySlot[i]);
Expand Down
4 changes: 1 addition & 3 deletions Core/GameEngine/Source/GameNetwork/NetCommandMsg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,7 @@ GameMessage *NetGameCommandMsg::constructGameMessage() const
{
GameMessage *retval = newInstance(GameMessage)(m_type);

AsciiString name;
name.format("player%d", getPlayerID());
retval->friend_setPlayerIndex( ThePlayerList->findPlayerWithNameKey(TheNameKeyGenerator->nameToKey(name))->getPlayerIndex());
retval->friend_setPlayerIndex(ThePlayerList->getPlayerFromSlotIndex(getPlayerID())->getPlayerIndex());

for (size_t i = 0; i < m_argList.size(); ++i) {
const GameMessageArgument* arg = m_argList[i];
Expand Down
10 changes: 4 additions & 6 deletions Core/GameEngine/Source/GameNetwork/Network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -657,14 +657,12 @@ void Network::processRunAheadCommand(NetRunAheadCommandMsg *msg) {

void Network::processDestroyPlayerCommand(NetDestroyPlayerCommandMsg *msg)
{
UnsignedInt playerIndex = msg->getPlayerIndex();
DEBUG_ASSERTCRASH(playerIndex < MAX_SLOTS, ("Bad player index"));
if (playerIndex >= MAX_SLOTS)
UnsignedInt slotIndex = msg->getPlayerIndex();
DEBUG_ASSERTCRASH(slotIndex < MAX_SLOTS, ("Bad slot index"));
if (slotIndex >= MAX_SLOTS)
return;

AsciiString playerName;
playerName.format("player%d", playerIndex);
Player *pPlayer = ThePlayerList->findPlayerWithNameKey(NAMEKEY(playerName));
Player *pPlayer = ThePlayerList->getPlayerFromSlotIndex(slotIndex);
if (pPlayer)
{
GameMessage *msg = newInstance(GameMessage)(GameMessage::MSG_SELF_DESTRUCT);
Expand Down
1 change: 1 addition & 0 deletions Generals/Code/GameEngine/Include/Common/PlayerList.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ class PlayerList : public SubsystemInterface,
PlayerMaskType getPlayersWithRelationship( Int srcPlayerIndex, UnsignedInt allowedRelationships );

Int getSlotIndex(Int playerIndex) const;
Player *getPlayerFromSlotIndex(Int slotIndex) const;

protected:

Expand Down
15 changes: 15 additions & 0 deletions Generals/Code/GameEngine/Source/Common/RTS/PlayerList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,21 @@ Int PlayerList::getSlotIndex(Int playerIndex) const
return -1;
}

//-----------------------------------------------------------------------------
Player *PlayerList::getPlayerFromSlotIndex(Int slotIndex) const
{
if (slotIndex >= 0 && slotIndex < MAX_SLOTS)
{
for (Int playerIndex = 0; playerIndex < m_playerCount; ++playerIndex)
{
if (getSlotIndex(playerIndex) == slotIndex)
return m_players[playerIndex];
}
}

return nullptr;
}

//-----------------------------------------------------------------------------
void PlayerList::assignSlotIndices(const GameInfo& gameInfo)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -475,9 +475,7 @@ void PopulateInGameDiplomacyPopup()
}
if (slot->isAI())
isInGame = true;
AsciiString playerName;
playerName.format("player%d", slotNum);
Player *player = ThePlayerList->findPlayerWithNameKey(NAMEKEY(playerName));
Player *player = ThePlayerList->getPlayerFromSlotIndex(slotNum);
Bool isAlive = !TheVictoryConditions->hasSinglePlayerBeenDefeated(player);
Bool isObserver = player->isPlayerObserver();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,13 +217,11 @@ void ToggleInGameChat( Bool immediate )
if (!msg.isEmpty() && !handleInGameSlashCommands(msg))
{
const Player *localPlayer = ThePlayerList->getLocalPlayer();
AsciiString playerName;
Int playerMask = 0;

for (Int i=0; i<MAX_SLOTS; ++i)
{
playerName.format("player%d", i);
const Player *player = ThePlayerList->findPlayerWithNameKey( TheNameKeyGenerator->nameToKey( playerName ) );
const Player *player = ThePlayerList->getPlayerFromSlotIndex(i);
if (player && localPlayer)
{
switch (inGameChatType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1771,15 +1771,13 @@ void grabMultiPlayerInfo()
typedef ScoreMap::reverse_iterator RevScoreMapIt;

Int playerCount = 0;
AsciiString playerName;
Player *player;
ScoreMap scores;
ScoreMapIt it;
scores.clear();
Int adder = 1; // Varible used to add on an offset to the score to make sure we don't add people to the same map

player = ThePlayerList->getLocalPlayer();
if (player)
Player *localPlayer = ThePlayerList->getLocalPlayer();
if (localPlayer)
{
const Image *image = TheMappedImageCollection->findImageByName("MutiPlayer_ScoreScreen");
if(image)
Expand All @@ -1792,8 +1790,7 @@ void grabMultiPlayerInfo()
// Add each player and score to the map. THis allows us to sort the players based on score.
for( Int i = 0; i < MAX_SLOTS; ++i)
{
playerName.format("player%d",i);
player = ThePlayerList->findPlayerWithNameKey(TheNameKeyGenerator->nameToKey(playerName));
Player *player = ThePlayerList->getPlayerFromSlotIndex(i);
if(player)
{
Int score = player->getScoreKeeper()->calculateScore();
Expand Down
5 changes: 1 addition & 4 deletions Generals/Code/GameEngine/Source/GameClient/InGameUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6165,7 +6165,6 @@ void InGameUI::drawPlayerInfoList()
const Int lineH = m_playerInfoList.labels[PlayerInfoList::LabelType_Team]->getFont()->height;
const Int columnGap = static_cast<Int>(lineH * (6.0f / 12.0f) + 0.5f);

AsciiString name;
UnicodeString playerInfoListValue;
Int rowCount = 0;
Int maxValueWidths[PlayerInfoList::LabelType_Count] = {0};
Expand All @@ -6176,9 +6175,7 @@ void InGameUI::drawPlayerInfoList()

for (Int slotIndex = 0; slotIndex < MAX_SLOTS && rowCount < MAX_PLAYER_COUNT; ++slotIndex)
{
name.format("player%d", slotIndex);
const NameKeyType key = TheNameKeyGenerator->nameToKey(name);
Player *player = ThePlayerList->findPlayerWithNameKey(key);
Player *player = ThePlayerList->getPlayerFromSlotIndex(slotIndex);
if (!player || player->isPlayerObserver())
continue;

Expand Down
10 changes: 3 additions & 7 deletions Generals/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1648,13 +1648,11 @@ void GameLogic::tryStartNewGame( Bool loadingSaveGame )
if (!slot || !slot->isOccupied())
continue;

AsciiString playerName;
playerName.format("player%d", i);
Player *player = ThePlayerList->findPlayerWithNameKey(TheNameKeyGenerator->nameToKey(playerName));
Player *player = ThePlayerList->getPlayerFromSlotIndex(i);

if (slot->getPlayerTemplate() == PLAYERTEMPLATE_OBSERVER)
{
DEBUG_LOG(("Clearing shroud for observer %s in playerList slot %d", playerName.str(), player->getPlayerIndex()));
DEBUG_LOG(("Clearing shroud for observer in slot %d with player index %d", i, player->getPlayerIndex()));
ThePartitionManager->revealMapForPlayerPermanently( player->getPlayerIndex() );
}
else
Expand Down Expand Up @@ -1785,9 +1783,7 @@ void GameLogic::tryStartNewGame( Bool loadingSaveGame )
if (!slot || !slot->isOccupied())
continue;

AsciiString playerName;
playerName.format("player%d", i);
Player *player = ThePlayerList->findPlayerWithNameKey(TheNameKeyGenerator->nameToKey(playerName));
Player *player = ThePlayerList->getPlayerFromSlotIndex(i);

if (slot->getPlayerTemplate() == PLAYERTEMPLATE_OBSERVER)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -669,9 +669,7 @@ AsciiString GameSpyGameInfo::generateGameResultsPacket()
Int lastTeamAtGameEnd = -1;
for (i=0; i<MAX_SLOTS; ++i)
{
AsciiString playerName;
playerName.format("player%d", i);
Player *p = ThePlayerList->findPlayerWithNameKey(NAMEKEY(playerName));
Player *p = ThePlayerList->getPlayerFromSlotIndex(i);
if (p)
{
++numPlayers;
Expand Down Expand Up @@ -701,9 +699,7 @@ AsciiString GameSpyGameInfo::generateGameResultsPacket()
Int playerID = 0;
for (i=0; i<MAX_SLOTS; ++i)
{
AsciiString playerName;
playerName.format("player%d", i);
Player *p = ThePlayerList->findPlayerWithNameKey(NAMEKEY(playerName));
Player *p = ThePlayerList->getPlayerFromSlotIndex(i);
if (p)
{
GameSpyGameSlot *slot = &(m_GameSpySlot[i]);
Expand Down
1 change: 1 addition & 0 deletions GeneralsMD/Code/GameEngine/Include/Common/PlayerList.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ class PlayerList : public SubsystemInterface,
PlayerMaskType getPlayersWithRelationship( Int srcPlayerIndex, UnsignedInt allowedRelationships );

Int getSlotIndex(Int playerIndex) const;
Player *getPlayerFromSlotIndex(Int slotIndex) const;

protected:

Expand Down
15 changes: 15 additions & 0 deletions GeneralsMD/Code/GameEngine/Source/Common/RTS/PlayerList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,21 @@ Int PlayerList::getSlotIndex(Int playerIndex) const
return -1;
}

//-----------------------------------------------------------------------------
Player *PlayerList::getPlayerFromSlotIndex(Int slotIndex) const
{
if (slotIndex >= 0 && slotIndex < MAX_SLOTS)
{
for (Int playerIndex = 0; playerIndex < m_playerCount; ++playerIndex)
{
if (getSlotIndex(playerIndex) == slotIndex)
return m_players[playerIndex];
}
}

return nullptr;
}

//-----------------------------------------------------------------------------
void PlayerList::assignSlotIndices(const GameInfo& gameInfo)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -475,9 +475,7 @@ void PopulateInGameDiplomacyPopup()
}
if (slot->isAI())
isInGame = true;
AsciiString playerName;
playerName.format("player%d", slotNum);
Player *player = ThePlayerList->findPlayerWithNameKey(NAMEKEY(playerName));
Player *player = ThePlayerList->getPlayerFromSlotIndex(slotNum);
Bool isAlive = !TheVictoryConditions->hasSinglePlayerBeenDefeated(player);
Bool isObserver = player->isPlayerObserver();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,13 +217,11 @@ void ToggleInGameChat( Bool immediate )
if (!msg.isEmpty() && !handleInGameSlashCommands(msg))
{
const Player *localPlayer = ThePlayerList->getLocalPlayer();
AsciiString playerName;
Int playerMask = 0;

for (Int i=0; i<MAX_SLOTS; ++i)
{
playerName.format("player%d", i);
const Player *player = ThePlayerList->findPlayerWithNameKey( TheNameKeyGenerator->nameToKey( playerName ) );
const Player *player = ThePlayerList->getPlayerFromSlotIndex(i);
if (player && localPlayer)
{
switch (inGameChatType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2041,15 +2041,13 @@ void grabMultiPlayerInfo()
typedef ScoreMap::reverse_iterator RevScoreMapIt;

Int playerCount = 0;
AsciiString playerName;
Player *player;
ScoreMap scores;
ScoreMapIt it;
scores.clear();
Int adder = 1; // Varible used to add on an offset to the score to make sure we don't add people to the same map

player = ThePlayerList->getLocalPlayer();
if (player)
Player *localPlayer = ThePlayerList->getLocalPlayer();
if (localPlayer)
{
const Image *image = TheMappedImageCollection->findImageByName("MutiPlayer_ScoreScreen");
if(image)
Expand All @@ -2062,8 +2060,7 @@ void grabMultiPlayerInfo()
// Add each player and score to the map. THis allows us to sort the players based on score.
for( Int i = 0; i < MAX_SLOTS; ++i)
{
playerName.format("player%d",i);
player = ThePlayerList->findPlayerWithNameKey(TheNameKeyGenerator->nameToKey(playerName));
Player *player = ThePlayerList->getPlayerFromSlotIndex(i);
if(player)
{
Int score = player->getScoreKeeper()->calculateScore();
Expand Down
5 changes: 1 addition & 4 deletions GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6298,7 +6298,6 @@ void InGameUI::drawPlayerInfoList()
const Int lineH = m_playerInfoList.labels[PlayerInfoList::LabelType_Team]->getFont()->height;
const Int columnGap = static_cast<Int>(lineH * (6.0f / 12.0f) + 0.5f);

AsciiString name;
UnicodeString playerInfoListValue;
Int rowCount = 0;
Int maxValueWidths[PlayerInfoList::LabelType_Count] = {0};
Expand All @@ -6309,9 +6308,7 @@ void InGameUI::drawPlayerInfoList()

for (Int slotIndex = 0; slotIndex < MAX_SLOTS && rowCount < MAX_PLAYER_COUNT; ++slotIndex)
{
name.format("player%d", slotIndex);
const NameKeyType key = TheNameKeyGenerator->nameToKey(name);
Player *player = ThePlayerList->findPlayerWithNameKey(key);
Player *player = ThePlayerList->getPlayerFromSlotIndex(slotIndex);
if (!player || player->isPlayerObserver())
continue;

Expand Down
10 changes: 3 additions & 7 deletions GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1809,13 +1809,11 @@ void GameLogic::tryStartNewGame( Bool loadingSaveGame )
if (!slot || !slot->isOccupied())
continue;

AsciiString playerName;
playerName.format("player%d", i);
Player *player = ThePlayerList->findPlayerWithNameKey(TheNameKeyGenerator->nameToKey(playerName));
Player *player = ThePlayerList->getPlayerFromSlotIndex(i);

if (slot->getPlayerTemplate() == PLAYERTEMPLATE_OBSERVER)
{
DEBUG_LOG(("Clearing shroud for observer %s in playerList slot %d", playerName.str(), player->getPlayerIndex()));
DEBUG_LOG(("Clearing shroud for observer in slot %d with player index %d", i, player->getPlayerIndex()));
ThePartitionManager->revealMapForPlayerPermanently( player->getPlayerIndex() );
}
else
Expand Down Expand Up @@ -1998,9 +1996,7 @@ void GameLogic::tryStartNewGame( Bool loadingSaveGame )
if (!slot || !slot->isOccupied())
continue;

AsciiString playerName;
playerName.format("player%d", i);
Player *player = ThePlayerList->findPlayerWithNameKey(TheNameKeyGenerator->nameToKey(playerName));
Player *player = ThePlayerList->getPlayerFromSlotIndex(i);

if (slot->getPlayerTemplate() == PLAYERTEMPLATE_OBSERVER)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -669,9 +669,7 @@ AsciiString GameSpyGameInfo::generateGameResultsPacket()
Int lastTeamAtGameEnd = -1;
for (i=0; i<MAX_SLOTS; ++i)
{
AsciiString playerName;
playerName.format("player%d", i);
Player *p = ThePlayerList->findPlayerWithNameKey(NAMEKEY(playerName));
Player *p = ThePlayerList->getPlayerFromSlotIndex(i);
if (p)
{
++numPlayers;
Expand Down Expand Up @@ -701,9 +699,7 @@ AsciiString GameSpyGameInfo::generateGameResultsPacket()
Int playerID = 0;
for (i=0; i<MAX_SLOTS; ++i)
{
AsciiString playerName;
playerName.format("player%d", i);
Player *p = ThePlayerList->findPlayerWithNameKey(NAMEKEY(playerName));
Player *p = ThePlayerList->getPlayerFromSlotIndex(i);
if (p)
{
GameSpyGameSlot *slot = &(m_GameSpySlot[i]);
Expand Down
Loading