Merge pull request #8252 from ChillerDragon/pr_num_skinparts

Use NUM_SKINPARTS instead of magic number
This commit is contained in:
Dennis Felsing 2024-04-23 08:32:22 +00:00 committed by GitHub
commit 1a397ad995
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 14 additions and 13 deletions

View file

@ -1584,7 +1584,7 @@ void CGameContext::OnClientEnter(int ClientId)
NewClientInfoMsg.m_Country = Server()->ClientCountry(ClientId);
NewClientInfoMsg.m_Silent = false;
for(int p = 0; p < 6; p++)
for(int p = 0; p < protocol7::NUM_SKINPARTS; p++)
{
NewClientInfoMsg.m_apSkinPartNames[p] = pNewPlayer->m_TeeInfos.m_apSkinPartNames[p];
NewClientInfoMsg.m_aUseCustomColors[p] = pNewPlayer->m_TeeInfos.m_aUseCustomColors[p];
@ -1614,7 +1614,7 @@ void CGameContext::OnClientEnter(int ClientId)
ClientInfoMsg.m_Country = Server()->ClientCountry(i);
ClientInfoMsg.m_Silent = 0;
for(int p = 0; p < 6; p++)
for(int p = 0; p < protocol7::NUM_SKINPARTS; p++)
{
ClientInfoMsg.m_apSkinPartNames[p] = pPlayer->m_TeeInfos.m_apSkinPartNames[p];
ClientInfoMsg.m_aUseCustomColors[p] = pPlayer->m_TeeInfos.m_aUseCustomColors[p];
@ -1882,7 +1882,7 @@ void *CGameContext::PreProcessMsg(int *pMsgId, CUnpacker *pUnpacker, int ClientI
protocol7::CNetMsg_Sv_SkinChange Msg;
Msg.m_ClientId = ClientId;
for(int p = 0; p < 6; p++)
for(int p = 0; p < protocol7::NUM_SKINPARTS; p++)
{
Msg.m_apSkinPartNames[p] = pMsg->m_apSkinPartNames[p];
Msg.m_aSkinPartColors[p] = pMsg->m_aSkinPartColors[p];
@ -2630,7 +2630,7 @@ void CGameContext::OnChangeInfoNetMessage(const CNetMsg_Cl_ChangeInfo *pMsg, int
Info.m_Silent = true;
Info.m_Team = pPlayer->GetTeam();
for(int p = 0; p < 6; p++)
for(int p = 0; p < protocol7::NUM_SKINPARTS; p++)
{
Info.m_apSkinPartNames[p] = pPlayer->m_TeeInfos.m_apSkinPartNames[p];
Info.m_aSkinPartColors[p] = pPlayer->m_TeeInfos.m_aSkinPartColors[p];
@ -2650,7 +2650,7 @@ void CGameContext::OnChangeInfoNetMessage(const CNetMsg_Cl_ChangeInfo *pMsg, int
{
protocol7::CNetMsg_Sv_SkinChange Msg;
Msg.m_ClientId = ClientId;
for(int p = 0; p < 6; p++)
for(int p = 0; p < protocol7::NUM_SKINPARTS; p++)
{
Msg.m_apSkinPartNames[p] = pPlayer->m_TeeInfos.m_apSkinPartNames[p];
Msg.m_aSkinPartColors[p] = pPlayer->m_TeeInfos.m_aSkinPartColors[p];

View file

@ -1,5 +1,6 @@
#include <base/color.h>
#include <base/system.h>
#include <game/generated/protocol7.h>
#include "teeinfo.h"
@ -7,9 +8,9 @@ struct StdSkin
{
char m_aSkinName[24];
// body, marking, decoration, hands, feet, eyes
char m_apSkinPartNames[6][24];
bool m_aUseCustomColors[6];
int m_aSkinPartColors[6];
char m_apSkinPartNames[protocol7::NUM_SKINPARTS][24];
bool m_aUseCustomColors[protocol7::NUM_SKINPARTS];
int m_aSkinPartColors[protocol7::NUM_SKINPARTS];
};
static StdSkin g_aStdSkins[] = {
@ -38,9 +39,9 @@ CTeeInfo::CTeeInfo(const char *pSkinName, int UseCustomColor, int ColorBody, int
m_ColorFeet = ColorFeet;
}
CTeeInfo::CTeeInfo(const char *apSkinPartNames[6], const int *pUseCustomColors, const int *pSkinPartColors)
CTeeInfo::CTeeInfo(const char *apSkinPartNames[protocol7::NUM_SKINPARTS], const int *pUseCustomColors, const int *pSkinPartColors)
{
for(int i = 0; i < 6; i++)
for(int i = 0; i < protocol7::NUM_SKINPARTS; i++)
{
str_copy(m_apSkinPartNames[i], apSkinPartNames[i], sizeof(m_apSkinPartNames[i]));
m_aUseCustomColors[i] = pUseCustomColors[i];
@ -51,7 +52,7 @@ CTeeInfo::CTeeInfo(const char *apSkinPartNames[6], const int *pUseCustomColors,
void CTeeInfo::ToSixup()
{
// reset to default skin
for(int p = 0; p < 6; p++)
for(int p = 0; p < protocol7::NUM_SKINPARTS; p++)
{
str_copy(m_apSkinPartNames[p], g_aStdSkins[0].m_apSkinPartNames[p], 24);
m_aUseCustomColors[p] = g_aStdSkins[0].m_aUseCustomColors[p];
@ -63,7 +64,7 @@ void CTeeInfo::ToSixup()
{
if(!str_comp(m_aSkinName, StdSkin.m_aSkinName))
{
for(int p = 0; p < 6; p++)
for(int p = 0; p < protocol7::NUM_SKINPARTS; p++)
{
str_copy(m_apSkinPartNames[p], StdSkin.m_apSkinPartNames[p], 24);
m_aUseCustomColors[p] = StdSkin.m_aUseCustomColors[p];
@ -102,7 +103,7 @@ void CTeeInfo::FromSixup()
for(auto &StdSkin : g_aStdSkins)
{
bool match = true;
for(int p = 0; p < 6; p++)
for(int p = 0; p < protocol7::NUM_SKINPARTS; p++)
{
if(str_comp(m_apSkinPartNames[p], StdSkin.m_apSkinPartNames[p]) || m_aUseCustomColors[p] != StdSkin.m_aUseCustomColors[p] || (m_aUseCustomColors[p] && m_aSkinPartColors[p] != StdSkin.m_aSkinPartColors[p]))
{