42 int R1 = 0xff & (dwClr1 >> 16);
43 int G1 = 0xff & (dwClr1 >> 8);
44 int B1 = 0xff & (dwClr1 );
45 int R2 = 0xff & (dwClr2 >> 16);
46 int G2 = 0xff & (dwClr2 >> 8);
47 int B2 = 0xff & (dwClr2 );
48 double r1=0,g1=0,b1=0,r2=0,g2=0,b2=0,x1=0,y1=0,Y1=0,x2=0,y2=0,Y2=0,u1=0,v1=0,u2=0,v2=0;
49 RGB2rgb(R1, G1, B1, &r1, &g1, &b1);
50 RGB2rgb(R2, G2, B2, &r2, &g2, &b2);
51 rgb2xyY(r1, g1, b1, &x1, &y1, &Y1);
52 rgb2xyY(r2, g2, b2, &x2, &y2, &Y2);
55 double Y = (Y1+Y2)/2.0;
56 double clrdiff = sqrt((u2-u1)*(u2-u1) + (v2-v1)*(v2-v1)) * Y*Y * 150;
57 double lumdiff = (Abs<double>(Y2-Y1) / std::max<double>(Y*Y*5, 0.5)) / 0.10;
58 return clrdiff + lumdiff < 1.0;
70 int32_t iCheckInfoCount;
85 bool fCurrentConflict, fOriginalConflict, fAlternateConflict;
99 void ResolveInPacket();
114 : ppCheckInfos(nullptr), iCheckInfoCount(0), rPriCheckList(rPriCheckList), rSecCheckList(rSecCheckList), pSecPacket(pSecPacket)
117 int32_t iMaxCheckCount = rPriCheckList.
GetInfoCount() + !!pSecPacket;
118 if (!iMaxCheckCount)
return;
124 if (pInfos != pSecPacket)
125 ppCheckInfos[iCheckInfoCount++] = pInfos;
129 this->pSecPacket =
nullptr;
133 if (pSecPacket) ppCheckInfos[iCheckInfoCount++] = pSecPacket;
138 delete [] ppCheckInfos;
141 void C4PlayerInfoListAttributeConflictResolver::ReaddInfoForCheck(
C4ClientPlayerInfos *pCheckAdd)
144 for (int32_t i=0; i<iCheckInfoCount; ++i)
if (ppCheckInfos[i] == pCheckAdd)
return;
147 ppCheckInfos[iCheckInfoCount++] = pCheckAdd;
159 int32_t iTypeDiff = int(pInfo2->
GetType()) - int(pInfo1->
GetType());
160 if (iTypeDiff)
return iTypeDiff;
163 if (iScoreDiff)
return iScoreDiff;
178 uint32_t dwClr1 = pInfo1->
GetColor(), dwClr2 = 0;
189 const char *szName1 = pInfo1->
GetName(), *szName2 =
"";
200 void C4PlayerInfoListAttributeConflictResolver::MarkConflicts(
C4ClientPlayerInfos &rCheckPacket,
bool fTestOriginal)
204 for (int32_t j=0; (pCheckAgainstInfo = rCheckPacket.
GetPlayerInfo(j)); ++j)
206 if (pCheckAgainstInfo->
IsUsingAttribute(eAttr))
if (!pResolveInfo->
GetID() || pResolveInfo->
GetID() != pCheckAgainstInfo->
GetID())
if (pResolveInfo != pCheckAgainstInfo)
210 bool fHasHigherPrio = (GetAttributePriorityDifference(pResolveInfo, pResolvePacket, pCheckAgainstInfo, &rCheckPacket) > 0);
213 fCurrentConflict =
true;
218 if (fHasHigherPrio && !fOriginalConflict && !pLowPrioOriginalConflictPacket)
222 pLowPrioOriginalConflictPacket = &rCheckPacket;
228 pLowPrioOriginalConflictPacket =
nullptr;
229 fOriginalConflict =
true;
234 if (fHasHigherPrio && !fAlternateConflict && !pLowPrioAlternateConflictPacket)
235 pLowPrioAlternateConflictPacket = &rCheckPacket;
237 fAlternateConflict =
true;
244 void C4PlayerInfoListAttributeConflictResolver::MarkConflicts(
const C4PlayerInfoList &rCheckList,
bool fTestOriginal)
251 void C4PlayerInfoListAttributeConflictResolver::ResolveInInfo()
256 fOriginalConflict =
false;
261 fCurrentConflict =
false;
262 pLowPrioOriginalConflictPacket = pLowPrioAlternateConflictPacket =
nullptr;
263 MarkConflicts(rPriCheckList, !iTries);
268 if (pSecPacket) MarkConflicts(*pSecPacket, !iTries);
277 if (!fOriginalConflict)
284 if (pLowPrioOriginalConflictPacket) ReaddInfoForCheck(pLowPrioOriginalConflictPacket);
293 if (pLowPrioAlternateConflictPacket) ReaddInfoForCheck(pLowPrioAlternateConflictPacket);
300 if (!fCurrentConflict)
321 if (!fOriginalConflict)
325 if (pLowPrioOriginalConflictPacket) ReaddInfoForCheck(pLowPrioOriginalConflictPacket);
330 if (!fCurrentConflict)
340 void C4PlayerInfoListAttributeConflictResolver::ResolveInPacket()
345 while ((pResolveInfo = pResolvePacket->
GetPlayerInfo(iCheck++)))
384 while (iCheckInfoCount)
386 pResolvePacket = ppCheckInfos[--iCheckInfoCount];
const char * LoadResStr(const char *id)
bool LogF(const char *strMessage,...)
const int32_t C4MaxPlayerNameChangeTries
bool IsColorConflict(DWORD dwClr1, DWORD dwClr2)
DWORD GenerateRandomPlayerColor(int32_t iTry)
const int32_t C4MaxPlayerColorChangeTries
uint32_t UnsyncedRandom()
bool SEqualNoCase(const char *szStr1, const char *szStr2, int iLen)
StdStrBuf FormatString(const char *szFmt,...)
bool rgb2xyY(double r, double g, double b, double *px, double *py, double *pY)
bool xy2upvp(double x, double y, double *pu, double *pv)
bool RGB2rgb(int R, int G, int B, double *pr, double *pg, double *pb, double gamma=2.2)
C4PlayerInfo * GetPlayerInfo(int32_t iIndex) const
bool IsDeveloperPacket() const
C4PlayerInfoList & RestorePlayerInfos
bool IsUsingAttribute(Attribute eAttr) const
uint32_t GetOriginalColor() const
uint32_t GetColor() const
bool IsAttributesFixed() const
const char * getLeagueAccount() const
int32_t GetAssociatedSavegamePlayerID() const
uint32_t GetAlternateColor() const
const char * GetOriginalName() const
int32_t getLeagueScore() const
void SetColor(DWORD dwUseClr)
const char * GetForcedName() const
void SetForcedName(const char *szNewName)
const char * GetName() const
C4PlayerType GetType() const
C4PlayerInfoListAttributeConflictResolver(C4PlayerInfoList &rPriCheckList, const C4PlayerInfoList &rSecCheckList, C4ClientPlayerInfos *pSecPacket)
~C4PlayerInfoListAttributeConflictResolver()
C4ClientPlayerInfos * GetIndexedInfo(int32_t iIndex) const
void ResolvePlayerAttributeConflicts(C4ClientPlayerInfos *pSecPacket)
int32_t GetInfoCount() const
C4Team * GetTeamByID(int32_t iID) const
bool IsTeamColors() const
const char * getData() const