bool C4PlayerInfoListAttributeConflictResolver::IsAttributeConflict(const C4PlayerInfo *pInfo1, const C4PlayerInfo *pInfo2, C4PlayerInfo::AttributeLevel eLevel)
{
	// check for conflict of colors and names
	if (eAttr == C4PlayerInfo::PLRATT_Color)
	{
		uint32_t dwClr1 = pInfo1->GetColor(), dwClr2 = 0;
		switch (eLevel)
		{
		case C4PlayerInfo::PLRAL_Current: dwClr2 = pInfo2->GetColor(); break;
		case C4PlayerInfo::PLRAL_Original: dwClr2 = pInfo2->GetOriginalColor(); break;
		case C4PlayerInfo::PLRAL_Alternate: dwClr2 = pInfo2->GetAlternateColor(); break;
		}
		return IsColorConflict(dwClr1, dwClr2);
	}
	else if (eAttr == C4PlayerInfo::PLRATT_Name)
	{
		const char *szName1 = pInfo1->GetName(), *szName2 = "";
		switch (eLevel)
		{
		case C4PlayerInfo::PLRAL_Current: szName2 = pInfo2->GetName(); break;
		case C4PlayerInfo::PLRAL_Original: szName2 = pInfo2->GetOriginalName(); break;
		default: return SEqualNoCase(szName1, szName2);
		}
	}
	return false;
}
Beispiel #2
0
void C4Team::RecheckColor(C4TeamList &rForList)
{
	// number of times trying new player colors
	const int32_t C4MaxTeamColorChangeTries = 100;
	if (!dwClr)
	{
		const int defTeamColorCount = 10;
		DWORD defTeamColorRGB[defTeamColorCount] = { 0xF40000, 0x00C800, 0xFCF41C, 0x2020FF, // red, green, yellow, blue,
		    0xC48444, 0xFFFFFF, 0x848484, 0xFF00EF, // brown, white, grey, pink,
		    0x00FFFF, 0x784830
		                                           }; // cyan, dk brown
		// no color assigned yet: Generate by team ID
		if (iID >=1 && iID <=defTeamColorCount)
		{
			// default colors
			dwClr = defTeamColorRGB[iID-1] | 0xff000000;
		}
		else
		{
			// find a new, unused color
			for (int32_t iTry=1; iTry<C4MaxTeamColorChangeTries; ++iTry)
			{
				dwClr = GenerateRandomPlayerColor(iTry);
				int32_t iIdx=0; C4Team *pTeam; bool fOK=true;
				while ((pTeam = rForList.GetTeamByIndex(iIdx++)))
					if (pTeam != this)
						if (IsColorConflict(pTeam->GetColor(), dwClr))
						{
							fOK=false;
							break;
						}
				// color is fine?
				if (fOK) return;
				// it's not; try next color
			}
			// Giving up: Use last generated color
		}
	}
}