예제 #1
0
void CASW_Campaign_Save::UpdateLastCommanders()
{
	// save which marines the players have selected
	// add which marines he has selected
	CASW_Game_Resource *pGameResource = ASWGameResource();
	if ( !pGameResource )
		return;

	// first check there were some marines selected (i.e. we're not in the campaign lobby map)
	int iNumMarineResources = 0;
	for (int i=0;i<pGameResource->GetMaxMarineResources();i++)
	{
		if (pGameResource->GetMarineResource(i))
			iNumMarineResources++;
	}
	if ( iNumMarineResources <= 0 )
		return;
	
	char buffer[256];
	for (int i=0;i<ASW_NUM_MARINE_PROFILES;i++)
	{
		// look for a marine info for this marine
		bool bFound = false;
		for (int k=0;k<pGameResource->GetMaxMarineResources();k++)
		{
			CASW_Marine_Resource *pMR = pGameResource->GetMarineResource(k);
			if (pMR && pMR->GetProfileIndex() == i && pMR->GetCommander())
			{
				CASW_Player *pPlayer = pMR->GetCommander();
				if (pPlayer)
				{
					// store the commander who has this marine
					Q_snprintf(buffer, sizeof(buffer), "%s%s",pPlayer->GetPlayerName(), pPlayer->GetASWNetworkID());
					m_LastCommanders[i] = AllocPooledString(buffer);
					m_LastMarineResourceSlot[i] = k;
					m_LastPrimaryMarines[i] = pPlayer->IsPrimaryMarine(i);
					bFound = true;
					break;
				}
			}
		}
		if (!bFound)
		{
			m_LastCommanders[i] = AllocPooledString("");
			m_LastMarineResourceSlot[i] = 0;
		}
	}
}
예제 #2
0
bool CASW_Game_Resource::AddMarineResource( CASW_Marine_Resource *m, int nPreferredSlot )
{
	if ( nPreferredSlot != -1 )
	{
		CASW_Marine_Resource *pExisting = static_cast<CASW_Marine_Resource*>( m_MarineResources[ nPreferredSlot ].Get() );
		if ( pExisting != NULL )
		{
			// if the existing is owned by someone else, then we abort
			if ( pExisting->GetCommander() != m->GetCommander() )
				return false;

			SetRosterSelected( pExisting->GetProfileIndex(), 0 );
			UTIL_Remove( pExisting );
		}

		m_MarineResources.Set( nPreferredSlot, m );

		// the above causes strange cases where the client copy of this networked array is incorrect
		// so we flag each element dirty to cause a complete update, which seems to fix the problem
		for (int k=0;k<ASW_MAX_MARINE_RESOURCES;k++)
		{
			m_MarineResources.GetForModify(k);
		}
		return true;
	}

	for (int i=0;i<ASW_MAX_MARINE_RESOURCES;i++)
	{
		if (m_MarineResources[i] == NULL)	// found a free slot
		{
			m_MarineResources.Set(i, m);

			// the above causes strange cases where the client copy of this networked array is incorrect
			// so we flag each element dirty to cause a complete update, which seems to fix the problem
			for (int k=0;k<ASW_MAX_MARINE_RESOURCES;k++)
			{
				m_MarineResources.GetForModify(k);
			}
			return true;
		}
	}
	Msg("Couldn't add new marine resource to list as no free slots\n");
	return false;
}