Exemplo n.º 1
0
void C4GameSave::WriteDescPlayers(StdStrBuf &sBuf, bool fByTeam, int32_t idTeam)
{
	// write out all players; only if they match the given team if specified
	C4PlayerInfo *pPlr; bool fAnyPlrWritten = false;
	for (int i = 0; (pPlr = Game.PlayerInfos.GetPlayerInfoByIndex(i)); i++)
		if (pPlr->HasJoined() && !pPlr->IsRemoved() && !pPlr->IsInvisible())
		{
			if (fByTeam)
			{
				if (idTeam)
				{
					// match team
					if (pPlr->GetTeam() != idTeam) continue;
				}
				else
				{
					// must be in no known team
					if (Game.Teams.GetTeamByID(pPlr->GetTeam())) continue;
				}
			}
			if (fAnyPlrWritten)
				sBuf.Append(", ");
			else if (fByTeam && idTeam)
			{
				C4Team *pTeam = Game.Teams.GetTeamByID(idTeam);
				if (pTeam) sBuf.AppendFormat("%s: ", pTeam->GetName());
			}
			sBuf.Append(pPlr->GetName());
			fAnyPlrWritten = true;
		}
	if (fAnyPlrWritten) WriteDescLineFeed(sBuf);
}
void C4Network2Players::JoinUnjoinedPlayersInControlQueue(C4ClientPlayerInfos *pNewPacket)
{
	// only host may join any players to the queue
	assert(::Network.isHost());
	// check all players
	int i=0; C4PlayerInfo *pInfo;
	while ((pInfo = pNewPacket->GetPlayerInfo(i++)))
		// not yet joined and no savegame assignment?
		if (!pInfo->HasJoinIssued()) if (!pInfo->GetAssociatedSavegamePlayerID())
			{
				// join will be marked when queue is executed (C4Player::Join)
				// but better mark join now already to prevent permanent sending overkill
				pInfo->SetJoinIssued();
				// do so!
				C4Network2Res *pPlrRes = pInfo->GetRes();
				C4Network2Client *pClient = ::Network.Clients.GetClientByID(pNewPacket->GetClientID());
				if (!pPlrRes || (!pClient && pNewPacket->GetClientID() != ::Control.ClientID()))
					if (pInfo->GetType() != C4PT_Script)
					{
						// failure: Non-script players must have a res to join from!
						const char *szPlrName = pInfo->GetName(); if (!szPlrName) szPlrName="???";
						LogF("Network: C4Network2Players::JoinUnjoinedPlayersInControlQueue failed to join player %s!", szPlrName);
						continue;
					}
				if (pPlrRes)
				{
					// join with resource
					Game.Input.Add(CID_JoinPlr,
					               new C4ControlJoinPlayer(pPlrRes->getFile(), pNewPacket->GetClientID(), pInfo->GetID(), pPlrRes->getCore()));
				}
				else
				{
					// join without resource (script player)
					Game.Input.Add(CID_JoinPlr,
					               new C4ControlJoinPlayer(NULL, pNewPacket->GetClientID(), pInfo->GetID()));
				}
			}
}
Exemplo n.º 3
0
StdStrBuf C4Team::GetNameWithParticipants() const
{
	// compose team name like "Team 1 (boni, GhostBear, Clonko)"
	// or just "Team 1" for empty team
	StdStrBuf sTeamName;
	sTeamName.Copy(GetName());
	if (GetPlayerCount())
	{
		sTeamName.Append(" (");
		int32_t iTeamPlrCount=0;
		for (int32_t j=0; j<GetPlayerCount(); ++j)
		{
			int32_t iPlr = GetIndexedPlayer(j);
			C4PlayerInfo *pPlrInfo;
			if (iPlr) if  ((pPlrInfo = Game.PlayerInfos.GetPlayerInfoByID(iPlr)))
				{
					if (iTeamPlrCount++) sTeamName.Append(", ");
					sTeamName.Append(pPlrInfo->GetName());
				}
		}
		sTeamName.AppendChar(')');
	}
	return sTeamName;
}
Exemplo n.º 4
0
void C4PlayerInfoListAttributeConflictResolver::ResolveInInfo()
{
	// trial-loop for assignment of new player colors/names
	int32_t iTries = 0;
	// original/alternate conflict evaluated once only
	fOriginalConflict = false;
	fAlternateConflict = (eAttr == C4PlayerInfo::PLRATT_Name) || !pResolveInfo->GetAlternateColor(); // mark as conflict if there is no alternate color/name
	for (;;)
	{
		// check against all other player infos, and given info, too (may be redundant)
		fCurrentConflict = false;
		pLowPrioOriginalConflictPacket = pLowPrioAlternateConflictPacket = nullptr;
		MarkConflicts(rPriCheckList, !iTries);
		// check secondary list, too. But only for colors, not for names, because secondary list is Restore list
		// and colors are retained in restore while names are always taken from new joins
		if (eAttr != C4PlayerInfo::PLRATT_Name) MarkConflicts(rSecCheckList, !iTries);
		// and mark conflicts in additional packet that' sbeen passed
		if (pSecPacket) MarkConflicts(*pSecPacket, !iTries);
		// color conflict resolving
		if (eAttr == C4PlayerInfo::PLRATT_Color)
		{
			// original color free but not used?
			if (!iTries)
			{
				if (pResolveInfo->GetColor() != pResolveInfo->GetOriginalColor())
				{
					if (!fOriginalConflict)
					{
						// revert to original color!
						pResolveInfo->SetColor(pResolveInfo->GetOriginalColor());
						// in case a lower priority packet was blocking the attribute, re-check that packet
						// note that the may readd the current resolve packet, but the conflict will occur with the
						// lower priority packet in the next loop
						if (pLowPrioOriginalConflictPacket) ReaddInfoForCheck(pLowPrioOriginalConflictPacket);
						// done with this player (breaking the trial-loop)
						break;
					}
					// neither original nor alternate color used but alternate color free?
					else if (pResolveInfo->GetColor() != pResolveInfo->GetAlternateColor() && !fAlternateConflict)
					{
						// revert to alternate
						pResolveInfo->SetColor(pResolveInfo->GetAlternateColor());
						if (pLowPrioAlternateConflictPacket) ReaddInfoForCheck(pLowPrioAlternateConflictPacket);
						// done with this player (breaking the trial-loop)
						break;
					}
				}
			}
			// conflict found?
			if (!fCurrentConflict)
				// done with this player, then - break the trial-loop
				break;
			// try to get a new, unused player color
			uint32_t dwNewClr;
			if (++iTries > C4MaxPlayerColorChangeTries)
			{
				LogF(LoadResStr("IDS_PRC_NOREPLPLRCLR"), pResolveInfo->GetName() ? pResolveInfo->GetName() : "<NONAME>");
				// since there's a conflict anyway, change to original
				pResolveInfo->SetColor(pResolveInfo->GetOriginalColor());
				break;
			}
			else
				dwNewClr = GenerateRandomPlayerColor(iTries);
			pResolveInfo->SetColor(dwNewClr);
		}
		else // if (eAttr == PLRATT_Name)
		{
			// name conflict resolving
			// original name free but not used?
			if (!SEqualNoCase(pResolveInfo->GetName(), pResolveInfo->GetOriginalName()))
				if (!fOriginalConflict)
				{
					// revert to original name!
					pResolveInfo->SetForcedName(nullptr);
					if (pLowPrioOriginalConflictPacket) ReaddInfoForCheck(pLowPrioOriginalConflictPacket);
					// done with this player (breaking the trial-loop)
					break;
				}
			// conflict found?
			if (!fCurrentConflict)
				// done with this player, then - break the trial-loop
				break;
			// generate new name by appending an index
			if (++iTries > C4MaxPlayerNameChangeTries) break;
			pResolveInfo->SetForcedName(FormatString("%s (%d)", pResolveInfo->GetOriginalName(), iTries+1).getData());
		}
	}
}