mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 10:08:18 +00:00
Merge #4779
4779: Add enum for ShowOthers value r=def- a=C0D3D3V This just improves the readability of the code. Also like my last enum I don't know if `src/game/gamecore.h` is the best place for the enum, but I think it fits in well. A question about this, maybe one can answer me without much research. It is about the technical part. Why does `/showothers` only affect dummy or player but `cl_show_others` affects both. ## Checklist - [x] Tested the change ingame - [ ] Provided screenshots if it is a visual change - [ ] Tested in combination with possibly related configuration options - [ ] Written a unit test if it works standalone, system.c especially - [x] Considered possible null pointers and out of bounds array indexing - [x] Changed no physics that affect existing maps - [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional) Co-authored-by: c0d3d3v <c0d3d3v@mag-keinen-spam.de>
This commit is contained in:
commit
7de0651da6
|
@ -2495,18 +2495,17 @@ void CMenus::RenderSettingsDDNet(CUIRect MainView)
|
|||
UI()->DoLabelScaled(&Label, Localize("Alpha"), 14.0f, TEXTALIGN_LEFT);
|
||||
g_Config.m_ClShowOthersAlpha = (int)(UIEx()->DoScrollbarH(&g_Config.m_ClShowOthersAlpha, &Button, g_Config.m_ClShowOthersAlpha / 100.0f) * 100.0f);
|
||||
|
||||
if(DoButton_CheckBox(&g_Config.m_ClShowOthers, Localize("Show others"), g_Config.m_ClShowOthers == 1, &LeftLeft))
|
||||
if(DoButton_CheckBox(&g_Config.m_ClShowOthers, Localize("Show others"), g_Config.m_ClShowOthers == SHOW_OTHERS_ON, &LeftLeft))
|
||||
{
|
||||
g_Config.m_ClShowOthers = g_Config.m_ClShowOthers != 1 ? 1 : 0;
|
||||
g_Config.m_ClShowOthers = g_Config.m_ClShowOthers != SHOW_OTHERS_ON ? SHOW_OTHERS_ON : SHOW_OTHERS_OFF;
|
||||
}
|
||||
}
|
||||
|
||||
Left.HSplitTop(20.0f, &Button, &Left);
|
||||
bool ShowOwnTeam = g_Config.m_ClShowOthers == 2;
|
||||
static int s_ShowOwnTeamID = 0;
|
||||
if(DoButton_CheckBox(&s_ShowOwnTeamID, Localize("Show others (own team only)"), ShowOwnTeam, &Button))
|
||||
if(DoButton_CheckBox(&s_ShowOwnTeamID, Localize("Show others (own team only)"), g_Config.m_ClShowOthers == SHOW_OTHERS_ONLY_TEAM, &Button))
|
||||
{
|
||||
g_Config.m_ClShowOthers = g_Config.m_ClShowOthers != 2 ? 2 : 0;
|
||||
g_Config.m_ClShowOthers = g_Config.m_ClShowOthers != SHOW_OTHERS_ONLY_TEAM ? SHOW_OTHERS_ONLY_TEAM : SHOW_OTHERS_OFF;
|
||||
}
|
||||
|
||||
Left.HSplitTop(20.0f, &Button, &Left);
|
||||
|
|
|
@ -276,8 +276,8 @@ void CGameClient::OnInit()
|
|||
|
||||
m_DDRaceMsgSent[0] = false;
|
||||
m_DDRaceMsgSent[1] = false;
|
||||
m_ShowOthers[0] = -1;
|
||||
m_ShowOthers[1] = -1;
|
||||
m_ShowOthers[0] = SHOW_OTHERS_NOT_SET;
|
||||
m_ShowOthers[1] = SHOW_OTHERS_NOT_SET;
|
||||
m_SwitchStateTeam[0] = -1;
|
||||
m_SwitchStateTeam[1] = -1;
|
||||
|
||||
|
@ -511,8 +511,8 @@ void CGameClient::OnReset()
|
|||
m_Teams.Reset();
|
||||
m_DDRaceMsgSent[0] = false;
|
||||
m_DDRaceMsgSent[1] = false;
|
||||
m_ShowOthers[0] = -1;
|
||||
m_ShowOthers[1] = -1;
|
||||
m_ShowOthers[0] = SHOW_OTHERS_NOT_SET;
|
||||
m_ShowOthers[1] = SHOW_OTHERS_NOT_SET;
|
||||
|
||||
m_LastZoom = .0;
|
||||
m_LastScreenAspect = .0;
|
||||
|
@ -654,7 +654,7 @@ void CGameClient::OnRender()
|
|||
void CGameClient::OnDummyDisconnect()
|
||||
{
|
||||
m_DDRaceMsgSent[1] = false;
|
||||
m_ShowOthers[1] = -1;
|
||||
m_ShowOthers[1] = SHOW_OTHERS_NOT_SET;
|
||||
m_LastNewPredictedTick[1] = -1;
|
||||
m_PredictedDummyID = -1;
|
||||
}
|
||||
|
@ -1605,7 +1605,7 @@ void CGameClient::OnNewSnapshot()
|
|||
m_DDRaceMsgSent[i] = true;
|
||||
}
|
||||
|
||||
if(m_ShowOthers[g_Config.m_ClDummy] == -1 || (m_ShowOthers[g_Config.m_ClDummy] != -1 && m_ShowOthers[g_Config.m_ClDummy] != g_Config.m_ClShowOthers))
|
||||
if(m_ShowOthers[g_Config.m_ClDummy] == SHOW_OTHERS_NOT_SET || (m_ShowOthers[g_Config.m_ClDummy] != SHOW_OTHERS_NOT_SET && m_ShowOthers[g_Config.m_ClDummy] != g_Config.m_ClShowOthers))
|
||||
{
|
||||
{
|
||||
CNetMsg_Cl_ShowOthers Msg;
|
||||
|
|
|
@ -167,6 +167,15 @@ enum
|
|||
//COREEVENT_HOOK_TELE=0x80,
|
||||
};
|
||||
|
||||
// show others values - do not change them
|
||||
enum
|
||||
{
|
||||
SHOW_OTHERS_NOT_SET = -1, // show others value before it is set
|
||||
SHOW_OTHERS_OFF = 0, // show no other players in solo or other teams
|
||||
SHOW_OTHERS_ON = 1, // show all other players in solo and other teams
|
||||
SHOW_OTHERS_ONLY_TEAM = 2 // show players that are in solo and are in the same team
|
||||
};
|
||||
|
||||
class CWorldCore
|
||||
{
|
||||
public:
|
||||
|
|
|
@ -1161,12 +1161,12 @@ bool CCharacter::CanSnapCharacter(int SnappingClient)
|
|||
|
||||
if(pSnapPlayer->GetTeam() == TEAM_SPECTATORS || pSnapPlayer->IsPaused())
|
||||
{
|
||||
if(pSnapPlayer->m_SpectatorID != -1 && !CanCollide(pSnapPlayer->m_SpectatorID) && (pSnapPlayer->m_ShowOthers == 0 || (pSnapPlayer->m_ShowOthers == 2 && !SameTeam(pSnapPlayer->m_SpectatorID))))
|
||||
if(pSnapPlayer->m_SpectatorID != -1 && !CanCollide(pSnapPlayer->m_SpectatorID) && (pSnapPlayer->m_ShowOthers == SHOW_OTHERS_OFF || (pSnapPlayer->m_ShowOthers == SHOW_OTHERS_ONLY_TEAM && !SameTeam(pSnapPlayer->m_SpectatorID))))
|
||||
return false;
|
||||
else if(pSnapPlayer->m_SpectatorID == -1 && !CanCollide(SnappingClient) && pSnapPlayer->m_SpecTeam && !SameTeam(SnappingClient))
|
||||
return false;
|
||||
}
|
||||
else if(pSnapChar && !pSnapChar->m_Super && !CanCollide(SnappingClient) && (pSnapPlayer->m_ShowOthers == 0 || (pSnapPlayer->m_ShowOthers == 2 && !SameTeam(SnappingClient))))
|
||||
else if(pSnapChar && !pSnapChar->m_Super && !CanCollide(SnappingClient) && (pSnapPlayer->m_ShowOthers == SHOW_OTHERS_OFF || (pSnapPlayer->m_ShowOthers == SHOW_OTHERS_ONLY_TEAM && !SameTeam(SnappingClient))))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
|
|
|
@ -243,7 +243,7 @@ void CDragger::Snap(int SnappingClient)
|
|||
if(!pChar && !pTarget && m_CaughtTeam != 0)
|
||||
continue;
|
||||
|
||||
if(pChar && pTarget && pTarget->GetPlayer()->GetCID() != pChar->GetPlayer()->GetCID() && ((pChar->GetPlayer()->m_ShowOthers == 0 && (pChar->Teams()->m_Core.GetSolo(SnappingClient) || pChar->Teams()->m_Core.GetSolo(pTarget->GetPlayer()->GetCID()))) || (pChar->GetPlayer()->m_ShowOthers == 2 && !pTarget->SameTeam(SnappingClient))))
|
||||
if(pChar && pTarget && pTarget->GetPlayer()->GetCID() != pChar->GetPlayer()->GetCID() && ((pChar->GetPlayer()->m_ShowOthers == SHOW_OTHERS_OFF && (pChar->Teams()->m_Core.GetSolo(SnappingClient) || pChar->Teams()->m_Core.GetSolo(pTarget->GetPlayer()->GetCID()))) || (pChar->GetPlayer()->m_ShowOthers == SHOW_OTHERS_ONLY_TEAM && !pTarget->SameTeam(SnappingClient))))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -94,10 +94,10 @@ void CPlasma::Snap(int SnappingClient)
|
|||
if(SnapChar && SnapChar->IsAlive() && (m_Layer == LAYER_SWITCH && m_Number > 0 && !GameServer()->Collision()->m_pSwitchers[m_Number].m_Status[SnapChar->Team()]) && (!Tick))
|
||||
return;
|
||||
|
||||
if(SnapPlayer && (SnapPlayer->GetTeam() == TEAM_SPECTATORS || SnapPlayer->IsPaused()) && SnapPlayer->m_SpectatorID != -1 && GameServer()->GetPlayerChar(SnapPlayer->m_SpectatorID) && GameServer()->GetPlayerChar(SnapPlayer->m_SpectatorID)->Team() != m_ResponsibleTeam && SnapPlayer->m_ShowOthers != 1)
|
||||
if(SnapPlayer && (SnapPlayer->GetTeam() == TEAM_SPECTATORS || SnapPlayer->IsPaused()) && SnapPlayer->m_SpectatorID != -1 && GameServer()->GetPlayerChar(SnapPlayer->m_SpectatorID) && GameServer()->GetPlayerChar(SnapPlayer->m_SpectatorID)->Team() != m_ResponsibleTeam && SnapPlayer->m_ShowOthers != SHOW_OTHERS_ON)
|
||||
return;
|
||||
|
||||
if(SnapPlayer && SnapPlayer->GetTeam() != TEAM_SPECTATORS && !SnapPlayer->IsPaused() && SnapChar && SnapChar->Team() != m_ResponsibleTeam && SnapPlayer->m_ShowOthers != 1)
|
||||
if(SnapPlayer && SnapPlayer->GetTeam() != TEAM_SPECTATORS && !SnapPlayer->IsPaused() && SnapChar && SnapChar->Team() != m_ResponsibleTeam && SnapPlayer->m_ShowOthers != SHOW_OTHERS_ON)
|
||||
return;
|
||||
|
||||
if(SnapPlayer && (SnapPlayer->GetTeam() == TEAM_SPECTATORS || SnapPlayer->IsPaused()) && SnapPlayer->m_SpectatorID == -1 && SnapChar && SnapChar->Team() != m_ResponsibleTeam && SnapPlayer->m_SpecTeam)
|
||||
|
|
|
@ -1302,7 +1302,7 @@ void CGameContext::OnClientEnter(int ClientID)
|
|||
if(g_Config.m_SvWelcome[0] != 0)
|
||||
SendChatTarget(ClientID, g_Config.m_SvWelcome);
|
||||
|
||||
if(g_Config.m_SvShowOthersDefault > 0)
|
||||
if(g_Config.m_SvShowOthersDefault > SHOW_OTHERS_OFF)
|
||||
{
|
||||
if(g_Config.m_SvShowOthers)
|
||||
SendChatTarget(ClientID, "You can see other players. To disable this use DDNet client and type /showothers .");
|
||||
|
@ -3194,7 +3194,7 @@ void CGameContext::OnInit(/*class IKernel *pKernel*/)
|
|||
g_Config.m_SvOldTeleportWeapons = 0;
|
||||
g_Config.m_SvTeleportHoldHook = 0;
|
||||
g_Config.m_SvTeam = SV_TEAM_ALLOWED;
|
||||
g_Config.m_SvShowOthersDefault = 0;
|
||||
g_Config.m_SvShowOthersDefault = SHOW_OTHERS_OFF;
|
||||
|
||||
if(Collision()->m_NumSwitchers > 0)
|
||||
for(int i = 0; i < Collision()->m_NumSwitchers + 1; ++i)
|
||||
|
@ -3210,7 +3210,7 @@ void CGameContext::OnInit(/*class IKernel *pKernel*/)
|
|||
if(g_Config.m_SvSoloServer)
|
||||
{
|
||||
g_Config.m_SvTeam = SV_TEAM_FORCED_SOLO;
|
||||
g_Config.m_SvShowOthersDefault = 1;
|
||||
g_Config.m_SvShowOthersDefault = SHOW_OTHERS_ON;
|
||||
|
||||
Tuning()->Set("player_collision", 0);
|
||||
Tuning()->Set("player_hooking", 0);
|
||||
|
|
|
@ -201,8 +201,8 @@ void CGameWorld::UpdatePlayerMaps()
|
|||
(!GameServer()->m_apPlayers[i] ||
|
||||
GameServer()->m_apPlayers[i]->GetClientVersion() == VERSION_VANILLA ||
|
||||
(GameServer()->m_apPlayers[i]->GetClientVersion() >= VERSION_DDRACE &&
|
||||
(GameServer()->m_apPlayers[i]->m_ShowOthers == 0 ||
|
||||
(GameServer()->m_apPlayers[i]->m_ShowOthers == 2 && !GameServer()->m_apPlayers[i]->GetCharacter()->SameTeam(j))))))
|
||||
(GameServer()->m_apPlayers[i]->m_ShowOthers == SHOW_OTHERS_OFF ||
|
||||
(GameServer()->m_apPlayers[i]->m_ShowOthers == SHOW_OTHERS_ONLY_TEAM && !GameServer()->m_apPlayers[i]->GetCharacter()->SameTeam(j))))))
|
||||
Dist[j].first = 1e8;
|
||||
else
|
||||
Dist[j].first = 0;
|
||||
|
|
|
@ -433,7 +433,7 @@ void CPlayer::Snap(int SnappingClient)
|
|||
if(SnappingClient >= 0)
|
||||
{
|
||||
CPlayer *pSnapPlayer = GameServer()->m_apPlayers[SnappingClient];
|
||||
ShowSpec = ShowSpec && (GameServer()->GetDDRaceTeam(m_ClientID) == GameServer()->GetDDRaceTeam(SnappingClient) || pSnapPlayer->m_ShowOthers == 1 || (pSnapPlayer->GetTeam() == TEAM_SPECTATORS || pSnapPlayer->IsPaused()));
|
||||
ShowSpec = ShowSpec && (GameServer()->GetDDRaceTeam(m_ClientID) == GameServer()->GetDDRaceTeam(SnappingClient) || pSnapPlayer->m_ShowOthers == SHOW_OTHERS_ON || (pSnapPlayer->GetTeam() == TEAM_SPECTATORS || pSnapPlayer->IsPaused()));
|
||||
}
|
||||
|
||||
if(ShowSpec)
|
||||
|
|
|
@ -499,12 +499,12 @@ int64_t CGameTeams::TeamMask(int Team, int ExceptID, int Asker)
|
|||
{ // Actions of other players
|
||||
if(!Character(i))
|
||||
continue; // Player is currently dead
|
||||
if(GetPlayer(i)->m_ShowOthers == 2)
|
||||
if(GetPlayer(i)->m_ShowOthers == SHOW_OTHERS_ONLY_TEAM)
|
||||
{
|
||||
if(m_Core.Team(i) != Team && m_Core.Team(i) != TEAM_SUPER)
|
||||
continue; // In different teams
|
||||
}
|
||||
else if(GetPlayer(i)->m_ShowOthers == 0)
|
||||
else if(GetPlayer(i)->m_ShowOthers == SHOW_OTHERS_OFF)
|
||||
{
|
||||
if(m_Core.GetSolo(Asker))
|
||||
continue; // When in solo part don't show others
|
||||
|
@ -521,12 +521,12 @@ int64_t CGameTeams::TeamMask(int Team, int ExceptID, int Asker)
|
|||
{ // Actions of other players
|
||||
if(!Character(GetPlayer(i)->m_SpectatorID))
|
||||
continue; // Player is currently dead
|
||||
if(GetPlayer(i)->m_ShowOthers == 2)
|
||||
if(GetPlayer(i)->m_ShowOthers == SHOW_OTHERS_ONLY_TEAM)
|
||||
{
|
||||
if(m_Core.Team(GetPlayer(i)->m_SpectatorID) != Team && m_Core.Team(GetPlayer(i)->m_SpectatorID) != TEAM_SUPER)
|
||||
continue; // In different teams
|
||||
}
|
||||
else if(GetPlayer(i)->m_ShowOthers == 0)
|
||||
else if(GetPlayer(i)->m_ShowOthers == SHOW_OTHERS_OFF)
|
||||
{
|
||||
if(m_Core.GetSolo(Asker))
|
||||
continue; // When in solo part don't show others
|
||||
|
|
Loading…
Reference in a new issue