Skip to content

Commit

Permalink
Minor tweaks to multiplay/stat/int
Browse files Browse the repository at this point in the history
  • Loading branch information
past-due committed Jan 29, 2025
1 parent 11739f6 commit 7e107ee
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 25 deletions.
8 changes: 4 additions & 4 deletions src/multiint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3458,8 +3458,8 @@ static SwapPlayerIndexesResult recvSwapPlayerIndexes(NETQUEUE queue, const std::
if ((game.blindMode != BLIND_MODE::NONE) && (selectedPlayer < MAX_PLAYERS))
{
std::string blindLobbyMessage = _("BLIND LOBBY NOTICE:");
blindLobbyMessage += "\n";
blindLobbyMessage += astringf(_("- You have been assigned the codename: \"%s\""), getPlayerGenericName(selectedPlayer));
blindLobbyMessage += "\n- ";
blindLobbyMessage += astringf(_("You have been assigned the codename: \"%s\""), getPlayerGenericName(selectedPlayer));
displayRoomNotifyMessage(blindLobbyMessage.c_str());
}
}
Expand Down Expand Up @@ -4174,7 +4174,7 @@ void WzMultiplayerOptionsTitleUI::openPlayerSlotSwapChooser(uint32_t playerIndex
auto psParentPlayersForm = (W_FORM *)widgGetFromID(psWScreen, MULTIOP_PLAYERS);
ASSERT_OR_RETURN(, psParentPlayersForm != nullptr, "Could not find players form?");
chooserParent->setCutoutWidget(psParentPlayersForm->shared_from_this()); // should be cleared on close
auto titleUI = std::dynamic_pointer_cast<WzMultiplayerOptionsTitleUI>(shared_from_this());
auto titleUI = std::static_pointer_cast<WzMultiplayerOptionsTitleUI>(shared_from_this());

int textHeight = iV_GetTextLineSize(font_regular);
int swapContextFormMargin = 1;
Expand Down Expand Up @@ -4317,7 +4317,7 @@ void WzMultiplayerOptionsTitleUI::addPlayerBox(bool players)
return;
}

auto titleUI = std::dynamic_pointer_cast<WzMultiplayerOptionsTitleUI>(shared_from_this());
auto titleUI = std::static_pointer_cast<WzMultiplayerOptionsTitleUI>(shared_from_this());

if (isBlindSimpleLobby(game.blindMode) && !NetPlay.isHost)
{
Expand Down
37 changes: 17 additions & 20 deletions src/multiplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <string.h>
#include <algorithm>
#include <chrono>
#include <array>

#include "lib/framework/frame.h"
#include "lib/framework/input.h"
Expand Down Expand Up @@ -694,24 +695,20 @@ BASE_OBJECT *IdToPointer(UDWORD id, UDWORD player)

bool isBlindPlayerInfoState()
{
if (game.blindMode == BLIND_MODE::NONE)
switch (game.blindMode)
{
case BLIND_MODE::NONE:
return false;
case BLIND_MODE::BLIND_LOBBY:
case BLIND_MODE::BLIND_LOBBY_SIMPLE_LOBBY:
// blind when game hasn't fully started yet
return !ingame.TimeEveryoneIsInGame.has_value();
case BLIND_MODE::BLIND_GAME:
case BLIND_MODE::BLIND_GAME_SIMPLE_LOBBY:
// blind when game hasn't ended yet
return !ingame.endTime.has_value();
}

// If blind lobby (only) and game hasn't started yet
if (game.blindMode < BLIND_MODE::BLIND_GAME && !ingame.TimeEveryoneIsInGame.has_value())
{
return true;
}

// If blind game and game hasn't _ended_ yet
if (game.blindMode >= BLIND_MODE::BLIND_GAME && !ingame.endTime.has_value())
{
return true;
}

return false;
return false; // silence warning
}


Expand Down Expand Up @@ -757,7 +754,7 @@ const char *getPlayerName(uint32_t player, bool treatAsNonHost)
const char *getPlayerGenericName(int player)
{
// genericNames are *not* localized - we want the same display across all systems (just like player-set names)
static const char *genericNames[] =
static constexpr std::array<const char *, 16> genericNames =
{
"Alpha",
"Beta",
Expand All @@ -776,10 +773,10 @@ const char *getPlayerGenericName(int player)
"Sigma",
"Tau"
};
STATIC_ASSERT(MAX_PLAYERS <= ARRAY_SIZE(genericNames));
ASSERT(player < ARRAY_SIZE(genericNames), "player number (%d) exceeds maximum (%lu)", player, (unsigned long) ARRAY_SIZE(genericNames));
static_assert(MAX_PLAYERS <= genericNames.size(), "Insufficient genericNames");
ASSERT(player < genericNames.size(), "player number (%d) exceeds maximum (%zu)", player, genericNames.size());

if (player >= ARRAY_SIZE(genericNames))
if (player >= genericNames.size())
{
return (player < MAX_PLAYERS) ? "Player" : "Spectator";
}
Expand Down Expand Up @@ -1944,7 +1941,7 @@ void setPlayerMuted(uint32_t playerIdx, bool muted)
{
auto trueIdentity = getTruePlayerIdentity(playerIdx);
if (!trueIdentity.identity.empty()
&& (NetPlay.isHost || game.blindMode == BLIND_MODE::NONE || (game.blindMode < BLIND_MODE::BLIND_GAME && ingame.TimeEveryoneIsInGame.has_value())))
&& (NetPlay.isHost || !isBlindPlayerInfoState()))
{
storePlayerMuteOption(NetPlay.players[playerIdx].name, trueIdentity.identity, muted);
}
Expand Down
2 changes: 1 addition & 1 deletion src/multistat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ bool swapPlayerMultiStatsLocal(uint32_t playerIndexA, uint32_t playerIndexB)

static bool sendMultiStatsInternal(uint32_t playerIndex, optional<uint32_t> recipientPlayerIndex = nullopt, bool sendHostVerifiedJoinIdentity = false)
{
ASSERT(NetPlay.isHost || playerIndex == realSelectedPlayer, "Hah");
ASSERT(NetPlay.isHost || playerIndex == realSelectedPlayer, "Huh?");

NETQUEUE queue;
if (!recipientPlayerIndex.has_value())
Expand Down

0 comments on commit 7e107ee

Please sign in to comment.