Inline Is(GameType) functions

They are used for two purposes, coloring gametypes in the serverbrowser
and enabling backward compatibility. These are independent, we shouldn't
add more stuff to the backward compatibility, hence I split them up and
inlined them.
This commit is contained in:
heinrich5991 2022-10-11 14:28:41 +02:00
parent 264987cfd6
commit a97a597592
5 changed files with 20 additions and 94 deletions

View file

@ -1578,7 +1578,7 @@ bool CClient::ShouldSendChatTimeoutCodeHeuristic()
{ {
return false; return false;
} }
return IsDDNet(&m_CurrentServerInfo); return str_find_nocase(m_CurrentServerInfo.m_aGameType, "ddracenet") || str_find_nocase(m_CurrentServerInfo.m_aGameType, "ddnet");
} }
static CServerCapabilities GetServerCapabilities(int Version, int Flags) static CServerCapabilities GetServerCapabilities(int Version, int Flags)

View file

@ -1564,70 +1564,7 @@ bool CServerInfo::ParseLocation(int *pResult, const char *pString)
return true; return true;
} }
bool IsVanilla(const CServerInfo *pInfo)
{
return !str_comp(pInfo->m_aGameType, "DM") || !str_comp(pInfo->m_aGameType, "TDM") || !str_comp(pInfo->m_aGameType, "CTF");
}
bool IsCatch(const CServerInfo *pInfo)
{
return str_find_nocase(pInfo->m_aGameType, "catch");
}
bool IsInsta(const CServerInfo *pInfo)
{
return str_find_nocase(pInfo->m_aGameType, "idm") || str_find_nocase(pInfo->m_aGameType, "itdm") || str_find_nocase(pInfo->m_aGameType, "ictf");
}
bool IsFNG(const CServerInfo *pInfo)
{
return str_find_nocase(pInfo->m_aGameType, "fng");
}
bool IsRace(const CServerInfo *pInfo)
{
return str_find_nocase(pInfo->m_aGameType, "race") || str_find_nocase(pInfo->m_aGameType, "fastcap");
}
bool IsFastCap(const CServerInfo *pInfo)
{
return str_find_nocase(pInfo->m_aGameType, "fastcap");
}
bool IsBlockInfectionZ(const CServerInfo *pInfo)
{
return str_find_nocase(pInfo->m_aGameType, "blockz") ||
str_find_nocase(pInfo->m_aGameType, "infectionz");
}
bool IsBlockWorlds(const CServerInfo *pInfo)
{
return (str_startswith(pInfo->m_aGameType, "bw ")) || (str_comp_nocase(pInfo->m_aGameType, "bw") == 0);
}
bool IsCity(const CServerInfo *pInfo)
{
return str_find_nocase(pInfo->m_aGameType, "city");
}
bool IsDDRace(const CServerInfo *pInfo)
{
return str_find_nocase(pInfo->m_aGameType, "ddrace") || str_find_nocase(pInfo->m_aGameType, "mkrace");
}
bool IsDDNet(const CServerInfo *pInfo)
{
return str_find_nocase(pInfo->m_aGameType, "ddracenet") || str_find_nocase(pInfo->m_aGameType, "ddnet");
}
// other
bool Is64Player(const CServerInfo *pInfo) bool Is64Player(const CServerInfo *pInfo)
{ {
return str_find(pInfo->m_aGameType, "64") || str_find(pInfo->m_aName, "64") || IsDDNet(pInfo); return str_find(pInfo->m_aGameType, "64") || str_find(pInfo->m_aName, "64") || str_find_nocase(pInfo->m_aGameType, "ddracenet") || str_find_nocase(pInfo->m_aGameType, "ddnet");
}
bool IsPlus(const CServerInfo *pInfo)
{
return str_find(pInfo->m_aGameType, "+");
} }

View file

@ -85,19 +85,7 @@ public:
static bool ParseLocation(int *pResult, const char *pString); static bool ParseLocation(int *pResult, const char *pString);
}; };
bool IsVanilla(const CServerInfo *pInfo);
bool IsCatch(const CServerInfo *pInfo);
bool IsInsta(const CServerInfo *pInfo);
bool IsFNG(const CServerInfo *pInfo);
bool IsRace(const CServerInfo *pInfo);
bool IsFastCap(const CServerInfo *pInfo);
bool IsDDRace(const CServerInfo *pInfo);
bool IsDDNet(const CServerInfo *pInfo);
bool IsBlockWorlds(const CServerInfo *pInfo);
bool IsCity(const CServerInfo *pInfo);
bool Is64Player(const CServerInfo *pInfo); bool Is64Player(const CServerInfo *pInfo);
bool IsPlus(const CServerInfo *pInfo);
class IServerBrowser : public IInterface class IServerBrowser : public IInterface
{ {

View file

@ -464,19 +464,19 @@ void CMenus::RenderServerbrowserServerList(CUIRect View)
{ {
ColorHSLA hsl = ColorHSLA(1.0f, 1.0f, 1.0f); ColorHSLA hsl = ColorHSLA(1.0f, 1.0f, 1.0f);
if(IsVanilla(pItem)) if(str_comp(pItem->m_aGameType, "DM") == 0 || str_comp(pItem->m_aGameType, "TDM") == 0 || str_comp(pItem->m_aGameType, "CTF") == 0)
hsl = ColorHSLA(0.33f, 1.0f, 0.75f); hsl = ColorHSLA(0.33f, 1.0f, 0.75f);
else if(IsCatch(pItem)) else if(str_find_nocase(pItem->m_aGameType, "catch"))
hsl = ColorHSLA(0.17f, 1.0f, 0.75f); hsl = ColorHSLA(0.17f, 1.0f, 0.75f);
else if(IsInsta(pItem)) else if(str_find_nocase(pItem->m_aGameType, "idm") || str_find_nocase(pItem->m_aGameType, "itdm") || str_find_nocase(pItem->m_aGameType, "ictf"))
hsl = ColorHSLA(0.00f, 1.0f, 0.75f); hsl = ColorHSLA(0.00f, 1.0f, 0.75f);
else if(IsFNG(pItem)) else if(str_find_nocase(pItem->m_aGameType, "fng"))
hsl = ColorHSLA(0.83f, 1.0f, 0.75f); hsl = ColorHSLA(0.83f, 1.0f, 0.75f);
else if(IsDDNet(pItem)) else if(str_find_nocase(pItem->m_aGameType, "ddracenet") || str_find_nocase(pItem->m_aGameType, "ddnet"))
hsl = ColorHSLA(0.58f, 1.0f, 0.75f); hsl = ColorHSLA(0.58f, 1.0f, 0.75f);
else if(IsDDRace(pItem)) else if(str_find_nocase(pItem->m_aGameType, "ddrace") || str_find_nocase(pItem->m_aGameType, "mkrace"))
hsl = ColorHSLA(0.75f, 1.0f, 0.75f); hsl = ColorHSLA(0.75f, 1.0f, 0.75f);
else if(IsRace(pItem)) else if(str_find_nocase(pItem->m_aGameType, "race") || str_find_nocase(pItem->m_aGameType, "fastcap"))
hsl = ColorHSLA(0.46f, 1.0f, 0.75f); hsl = ColorHSLA(0.46f, 1.0f, 0.75f);
ColorRGBA rgb = color_cast<ColorRGBA>(hsl); ColorRGBA rgb = color_cast<ColorRGBA>(hsl);
@ -1167,7 +1167,7 @@ void CMenus::RenderServerbrowserServerDetail(CUIRect View)
if(!pSelectedServer->m_aClients[i].m_Player) if(!pSelectedServer->m_aClients[i].m_Player)
str_copy(aTemp, "SPEC"); str_copy(aTemp, "SPEC");
else if(IsRace(pSelectedServer) && g_Config.m_ClDDRaceScoreBoard) else if((str_find_nocase(pSelectedServer->m_aGameType, "race") || str_find_nocase(pSelectedServer->m_aGameType, "fastcap")) && g_Config.m_ClDDRaceScoreBoard)
{ {
if(pSelectedServer->m_aClients[i].m_Score == -9999 || pSelectedServer->m_aClients[i].m_Score == 0) if(pSelectedServer->m_aClients[i].m_Score == -9999 || pSelectedServer->m_aClients[i].m_Score == 0)
aTemp[0] = 0; aTemp[0] = 0;

View file

@ -1009,15 +1009,16 @@ static CGameInfo GetGameInfo(const CNetObj_GameInfoEx *pInfoEx, int InfoExSize,
bool FDDrace; bool FDDrace;
if(Version < 1) if(Version < 1)
{ {
Race = IsRace(pFallbackServerInfo); const char *pGameType = pFallbackServerInfo->m_aGameType;
FastCap = IsFastCap(pFallbackServerInfo); Race = str_find_nocase(pGameType, "race") || str_find_nocase(pGameType, "fastcap");
FNG = IsFNG(pFallbackServerInfo); FastCap = str_find_nocase(pGameType, "fastcap");
DDRace = IsDDRace(pFallbackServerInfo); FNG = str_find_nocase(pGameType, "fng");
DDNet = IsDDNet(pFallbackServerInfo); DDRace = str_find_nocase(pGameType, "ddrace") || str_find_nocase(pGameType, "mkrace");
BlockWorlds = IsBlockWorlds(pFallbackServerInfo); DDNet = str_find_nocase(pGameType, "ddracenet") || str_find_nocase(pGameType, "ddnet");
City = IsCity(pFallbackServerInfo); BlockWorlds = str_startswith(pGameType, "bw ") || str_comp_nocase(pGameType, "bw") == 0;
Vanilla = IsVanilla(pFallbackServerInfo); City = str_find_nocase(pGameType, "city");
Plus = IsPlus(pFallbackServerInfo); Vanilla = str_comp(pGameType, "DM") == 0 || str_comp(pGameType, "TDM") == 0 || str_comp(pGameType, "CTF") == 0;
Plus = str_find(pGameType, "+");
FDDrace = false; FDDrace = false;
} }
else else