Exemplo n.º 1
0
void C4TeamList::ReassignAllTeams()
{
	assert(::Control.isCtrlHost());
	if (!::Control.isCtrlHost()) return;
	// go through all player infos; reset team in them
	int32_t idStart = -1; C4PlayerInfo *pNfo;
	while ((pNfo = Game.PlayerInfos.GetNextPlayerInfoByID(idStart)))
	{
		idStart = pNfo->GetID();
		if (pNfo->HasJoinIssued()) continue;
		pNfo->SetTeam(0);
		// mark changed info as updated
		C4ClientPlayerInfos *pCltInfo = Game.PlayerInfos.GetClientInfoByPlayerID(idStart);
		assert(pCltInfo);
		if (pCltInfo)
		{
			pCltInfo->SetUpdated();
		}
	}
	// clear players from team lists
	RecheckPlayers();
	EnsureTeamCount();
	// reassign them
	idStart = -1;
	while ((pNfo = Game.PlayerInfos.GetNextPlayerInfoByID(idStart)))
	{
		idStart = pNfo->GetID();
		if (pNfo->HasJoinIssued()) continue;
		assert(!pNfo->GetTeam());
		RecheckPlayerInfoTeams(*pNfo, true);
	}
}
Exemplo n.º 2
0
int32_t C4Team::GetFirstUnjoinedPlayerID() const
{
	// search for a player that does not have the join-flag set
	int32_t i=iPlayerCount, idPlr, *piPlr = piPlayers;
	C4PlayerInfo *pInfo;
	while (i--)
		if ((pInfo = Game.PlayerInfos.GetPlayerInfoByID(idPlr = *piPlr++)))
			if (!pInfo->HasJoinIssued())
				return idPlr;
	// none found
	return 0;
}
Exemplo n.º 3
0
void C4TeamList::ReassignAllTeams()
{
	assert(::Control.isCtrlHost());
	if (!::Control.isCtrlHost()) return;
	// go through all player infos; reset team in them
	int32_t idStart = -1; C4PlayerInfo *pNfo;
	while ((pNfo = Game.PlayerInfos.GetNextPlayerInfoByID(idStart)))
	{
		idStart = pNfo->GetID();
		if (pNfo->HasJoinIssued()) continue;
		pNfo->SetTeam(0);
		// mark changed info as updated
		C4ClientPlayerInfos *pCltInfo = Game.PlayerInfos.GetClientInfoByPlayerID(idStart);
		assert(pCltInfo);
		if (pCltInfo)
		{
			pCltInfo->SetUpdated();
		}
	}
	// clear players from team lists
	RecheckPlayers();
	// in random autogenerate mode, there must be exactly two teams
	if (IsRandomTeam())
		if (IsAutoGenerateTeams() && GetTeamCount() != 2)
			{
			ClearTeams();
			GenerateDefaultTeams(2);
			}
	// reassign them
	idStart = -1;
	while ((pNfo = Game.PlayerInfos.GetNextPlayerInfoByID(idStart)))
	{
		idStart = pNfo->GetID();
		if (pNfo->HasJoinIssued()) continue;
		assert(!pNfo->GetTeam());
		RecheckPlayerInfoTeams(*pNfo, true);
	}
}
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()));
				}
			}
}