//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void C_BaseObject::GetTargetIDDataString( wchar_t *sDataString, int iMaxLenInBytes )
{
	sDataString[0] = '\0';

	// Don't show anything if the building cannot be upgraded at all.
	if ( m_iHighestUpgradeLevel <= 1 )
		return;

	C_TFPlayer *pLocalPlayer = C_TFPlayer::GetLocalTFPlayer();
	if ( !pLocalPlayer )
		return;

	wchar_t wszBuilderName[ MAX_PLAYER_NAME_LENGTH ];
	wchar_t wszObjectName[ 32 ];
	wchar_t wszUpgradeProgress[ 32 ];
	wchar_t wszLevel[ 5 ];

	_snwprintf(wszLevel, ARRAYSIZE(wszLevel) - 1, L"%d", m_iUpgradeLevel);

	g_pVGuiLocalize->ConvertANSIToUnicode( GetStatusName(), wszObjectName, sizeof(wszObjectName) );

	C_BasePlayer *pBuilder = GetOwner();

	if ( pBuilder )
	{
		g_pVGuiLocalize->ConvertANSIToUnicode( pBuilder->GetPlayerName(), wszBuilderName, sizeof(wszBuilderName) );
	}
	else
	{
		wszBuilderName[0] = '\0';
	}

	if (m_iUpgradeLevel >= m_iHighestUpgradeLevel)
	{
		const char *printFormatString = "#TF_playerid_object_level";

		g_pVGuiLocalize->ConstructString(sDataString, iMaxLenInBytes, g_pVGuiLocalize->Find(printFormatString),
			1,
			wszLevel);
	}
	else
	{
		// level 1 and 2 show upgrade progress
		_snwprintf(wszUpgradeProgress, ARRAYSIZE(wszUpgradeProgress) - 1, L"%d / %d", m_iUpgradeMetal, m_iUpgradeMetalRequired);
		wszUpgradeProgress[ARRAYSIZE(wszUpgradeProgress) - 1] = '\0';

		const char *printFormatString = "#TF_playerid_object_upgrading_level";		

		g_pVGuiLocalize->ConstructString(sDataString, iMaxLenInBytes, g_pVGuiLocalize->Find(printFormatString),
			2,
			wszLevel,
			wszUpgradeProgress);
	}



}
void CC_FreezeStatus( const CCommand& args )
{
	C_BaseEntity *pEntity = ProcessTarget();

	// Did we find a target?
	if ( pEntity )
	{
		// Is it a block?
		if ( pEntity->IsBlock() && pEntity->GetHealth() > 0 )
		{
			C_BlockBase *pBlock = static_cast< C_BlockBase * > ( pEntity );

			if ( ClassicGameRules() )
			{
				int frozenplayerindex = engine->GetPlayerForUserID( pBlock->GetLastFrozenByUserID()  );
				C_BasePlayer *pPlayer = UTIL_PlayerByIndex( frozenplayerindex );
				if ( pPlayer )
				{
					Msg( "\tFrozen by %s\n", pPlayer->GetPlayerName() );
				}
				else
				{
					Msg( "\tFrozen by WORLD\n" );
				}
				
				int unfrozenplayerindex = engine->GetPlayerForUserID( pBlock->GetLastUnFrozenByUserID()  );
				pPlayer = UTIL_PlayerByIndex( unfrozenplayerindex );
				if ( pPlayer )
				{
					Msg( "\tUnFrozen by %s\n", pPlayer->GetPlayerName() );
				}
				else
				{
					Msg( "\tUnFrozen by WORLD\n" );
				}
			}
		}
	}
}
Exemple #3
0
void C_HLTVCamera::SpecNamedPlayer( const char *szPlayerName )
{
	for ( int index = 1; index <= gpGlobals->maxClients; ++index )
	{
		C_BasePlayer *pPlayer =	UTIL_PlayerByIndex( index );

		if ( !pPlayer )
			continue;

		if ( !FStrEq( szPlayerName, pPlayer->GetPlayerName() ) )
			continue;

		// only follow living players or dedicated spectators
		if ( pPlayer->IsObserver() && pPlayer->GetTeamNumber() != TEAM_SPECTATOR )
			continue;

		SetPrimaryTarget( index );
		return;
	}
}
Exemple #4
0
void CHudDHLRoundTime::MsgFunc_RoundEnd( bf_read &msg )
{
	bool bSuccess = false;
	byte val = msg.ReadByte();
	if ( val == 255 ) //Arbitrary "round draw" value
	{
		wcsncpy( wszHudText, g_pVGuiLocalize->Find( "#DHL_ROUND_DRAW" ), 50 );
		bSuccess = true;
	}
	else
	{
		if ( DHLRules()->IsTeamplay() )
		{
			//Val indicates winning team #
			C_Team* pTeam = GetGlobalTeam( val );
			if ( pTeam )
			{
				wchar_t wszTeamName[32];
				g_pVGuiLocalize->ConvertANSIToUnicode( pTeam->Get_Name(), wszTeamName, sizeof(wszTeamName) );
				g_pVGuiLocalize->ConstructString( wszHudText, sizeof( wszHudText ), g_pVGuiLocalize->Find( "#DHL_ROUNDPLAY_WINNER" ), 1, wszTeamName );
				bSuccess = true;
			}
		}
		else
		{
			//Val indicates winning player's index
			C_BasePlayer *pPlayer = UTIL_PlayerByIndex( val );
			if ( pPlayer )
			{
				wchar_t wszPlayerName[MAX_PLAYER_NAME_LENGTH];
				g_pVGuiLocalize->ConvertANSIToUnicode( pPlayer->GetPlayerName(), wszPlayerName, sizeof(wszPlayerName) );
				g_pVGuiLocalize->ConstructString( wszHudText, sizeof( wszHudText ), g_pVGuiLocalize->Find( "#DHL_LMS_WINNER" ), 1, wszPlayerName );
				bSuccess = true;
			}
		}
	}

	static ConVarRef restartDelay( "dhl_roundrestartdelay" );
	if ( bSuccess )
		flHudTextTime = gpGlobals->curtime + restartDelay.GetFloat();
}
Exemple #5
0
void C_Camera::SpecTargetByName(const char *name)
{
	if (!Q_stricmp(name, "ball"))
	{
		if (GetMatchBall())
		{
			SetTarget(GetMatchBall()->entindex());
		}
	}
	else
	{
		for (int i = 1; i <= gpGlobals->maxClients; i++)
		{
			C_BasePlayer *pPlayer =	UTIL_PlayerByIndex(i);

			if (!pPlayer || Q_strcmp(name, pPlayer->GetPlayerName()))
				continue;

			SetTarget(i);
			break;
		}
	}
}
void ClientModeDODNormal::FireGameEvent( IGameEvent * event)
{
	const char *eventname = event->GetName();

	if ( !eventname || !eventname[0] )
		return;

	if ( Q_strcmp( "dod_round_start", eventname ) == 0 )
	{
		// Just tell engine to clear decals
		engine->ClientCmd( "r_cleardecals\n" );

		// recreate all client side physics props
		// check for physenv, because we sometimes crash on changelevel
		// if we get this message before fully connecting
		if ( physenv )
		{
            C_PhysPropClientside::RecreateAll();
		}
	}
	else if( Q_strcmp( "dod_broadcast_audio", eventname ) == 0 )
	{
		CLocalPlayerFilter filter;
		const char *pszSoundName = event->GetString("sound");
		C_BaseEntity::EmitSound( filter, SOUND_FROM_LOCAL_PLAYER, pszSoundName );
	}
	else if ( Q_strcmp( "dod_bomb_planted", eventname ) == 0 )
	{
		int defendingTeam = event->GetInt( "team" );

		C_DODPlayer *pLocalPlayer = C_DODPlayer::GetLocalDODPlayer();

		if ( !pLocalPlayer )
			return;

		const char *pszSound = "";
		const char *pszMessage = "";

		int localTeam = pLocalPlayer->GetTeamNumber();

		const char *pPlanterName = NULL;

		int iPlanterIndex = 0;

		if ( defendingTeam == localTeam )
		{
			// play defend sound
			switch( localTeam )
			{
			case TEAM_ALLIES:
				{
					pszSound = "Voice.US_C4EnemyPlanted";
					pszMessage = "#dod_bomb_us_enemy_planted";
				}
				break;
			case TEAM_AXIS:
				{
					pszSound = "Voice.German_C4EnemyPlanted";
					pszMessage = "#dod_bomb_ger_enemy_planted";
				}
				break;
			default:
				break;
			}
		}
		else
		{
			// play planting sound
			switch( localTeam )
			{
			case TEAM_ALLIES:
				{
					pszSound = "Voice.US_C4TeamPlanted";
					pszMessage = "#dod_bomb_us_team_planted";
				}
				break;
			case TEAM_AXIS:
				{
					pszSound = "Voice.German_C4TeamPlanted";
					pszMessage = "#dod_bomb_ger_team_planted";
				}
				break;
			default:
				break;
			}

			// Only show the planter name if its a team plant, not enemy plant
			iPlanterIndex = engine->GetPlayerForUserID( event->GetInt("userid") );
			pPlanterName = g_PR->GetPlayerName( iPlanterIndex );
		}		

		RadioMessage( pszSound, pszMessage, pPlanterName, iPlanterIndex );
	}
	else if ( Q_strcmp( "dod_bomb_defused", eventname ) == 0 )
	{
		int defusingTeam = event->GetInt( "team" );

		C_DODPlayer *pLocalPlayer = C_DODPlayer::GetLocalDODPlayer();

		if ( !pLocalPlayer )
			return;

		const char *pszSound = "";
		const char *pszMessage = "";

		int localTeam = pLocalPlayer->GetTeamNumber();

		if ( defusingTeam == localTeam )
		{
			// play defused sound
			switch( localTeam )
			{
			case TEAM_ALLIES:
				{
					pszSound = "Voice.US_C4Defused";
					pszMessage = "#dod_bomb_us_defused";
				}
				break;
			case TEAM_AXIS:
				{
					pszSound = "Voice.German_C4Defused";
					pszMessage = "#dod_bomb_ger_defused";
				}
				break;
			default:
				break;
			}

			int iDefuser = engine->GetPlayerForUserID( event->GetInt("userid") );
			const char *pDefuserName = g_PR->GetPlayerName( iDefuser );

			RadioMessage( pszSound, pszMessage, pDefuserName, iDefuser );
		}
	}
	else if ( Q_strcmp( "player_team", eventname ) == 0 )
	{
		C_BasePlayer *pPlayer = USERID2PLAYER( event->GetInt("userid") );

		if ( !pPlayer )
			return;

		bool bDisconnected = event->GetBool("disconnect");

		if ( bDisconnected )
			return;

		int team = event->GetInt( "team" );

		if ( pPlayer->IsLocalPlayer() )
		{
			// that's me
			pPlayer->TeamChange( team );
		}

		CBaseHudChat *hudChat = (CBaseHudChat *)GET_HUDELEMENT( CHudChat );

		if ( !hudChat )
			return;

		char *pTemplate = NULL;

		if ( team == TEAM_ALLIES )
		{
			pTemplate = "#game_joined_allies";
		}
		else if ( team == TEAM_AXIS )
		{
			pTemplate = "#game_joined_axis";
		}
		else
		{
			pTemplate = "#game_joined_spectators";
		} 

		wchar_t szPlayerName[MAX_PLAYER_NAME_LENGTH];
		g_pVGuiLocalize->ConvertANSIToUnicode( pPlayer->GetPlayerName(), szPlayerName, sizeof(szPlayerName) );

		wchar_t wszPrint[128];
		char szPrint[128];

		g_pVGuiLocalize->ConstructString( wszPrint, sizeof(wszPrint), g_pVGuiLocalize->Find(pTemplate), 1, szPlayerName );
		g_pVGuiLocalize->ConvertUnicodeToANSI( wszPrint, szPrint, sizeof(szPrint) );

		hudChat->Printf( CHAT_FILTER_TEAMCHANGE, "%s",szPrint );
	}
	else if ( Q_strcmp( "dod_timer_flash", eventname ) == 0 )
	{
		C_DODPlayer *pLocalPlayer = C_DODPlayer::GetLocalDODPlayer();

		if ( !pLocalPlayer )
			return;

		const char *pszSound = "";
		const char *pszMessage = "";

		int localTeam = pLocalPlayer->GetTeamNumber();

		int iTimeRemaining = event->GetInt( "time_remaining", 0 );

		switch( iTimeRemaining )
		{
		case 60:
			switch( localTeam )
			{
			case TEAM_ALLIES:
				{
					pszSound = "Voice.US_OneMinute";
					pszMessage = "#dod_time_remaining_us_1_min";
				}
				break;
			case TEAM_AXIS:
				{
					pszSound = "Voice.German_OneMinute";
					pszMessage = "#dod_time_remaining_ger_1_min";
				}
				break;
			default:
				break;
			}
			break;
		case 120:
			switch( localTeam )
			{
			case TEAM_ALLIES:
				{
					pszSound = "Voice.US_TwoMinute";
					pszMessage = "#dod_time_remaining_us_2_min";
				}
				break;
			case TEAM_AXIS:
				{
					pszSound = "Voice.German_TwoMinute";
					pszMessage = "#dod_time_remaining_ger_2_min";
				}
				break;
			default:
				break;
			}
			break;
		default:
			break;
		}

		RadioMessage( pszSound, pszMessage );
	}
	else
		BaseClass::FireGameEvent( event );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void C_BaseObject::GetTargetIDString( wchar_t *sIDString, int iMaxLenInBytes )
{
	sIDString[0] = '\0';

	C_TFPlayer *pLocalPlayer = C_TFPlayer::GetLocalTFPlayer();

	if ( !pLocalPlayer )
		return;

	if ( InSameTeam( pLocalPlayer ) || pLocalPlayer->IsPlayerClass( TF_CLASS_SPY ) || pLocalPlayer->GetTeamNumber() == TEAM_SPECTATOR )
	{
		wchar_t wszBuilderName[ MAX_PLAYER_NAME_LENGTH ];

		const char *pszStatusName = GetStatusName();
		wchar_t *wszObjectName = g_pVGuiLocalize->Find( pszStatusName );

		if ( !wszObjectName )
		{
			wszObjectName = L"";
		}

		C_BasePlayer *pBuilder = GetOwner();

		if ( pBuilder )
		{
			g_pVGuiLocalize->ConvertANSIToUnicode( pBuilder->GetPlayerName(), wszBuilderName, sizeof(wszBuilderName) );
		}
		else
		{
			wszBuilderName[0] = '\0';
		}

		// building or live, show health
		const char *printFormatString;
		
		if ( GetObjectInfo(GetType())->m_AltModes.Count() > 0 )
		{
			printFormatString = "#TF_playerid_object_mode";

			pszStatusName = GetObjectInfo( GetType() )->m_AltModes.Element( m_iObjectMode * 3 + 1 );
			wchar_t *wszObjectModeName = g_pVGuiLocalize->Find( pszStatusName );

			if ( !wszObjectModeName )
			{
				wszObjectModeName = L"";
			}

			g_pVGuiLocalize->ConstructString( sIDString, iMaxLenInBytes, g_pVGuiLocalize->Find(printFormatString),
				4,
				wszObjectName,
				wszBuilderName,
				wszObjectModeName);
		}
		else
		{
			if ( m_bMiniBuilding )
				printFormatString = "#TF_playerid_object_mini";
			else
				printFormatString = "#TF_playerid_object";

			g_pVGuiLocalize->ConstructString( sIDString, iMaxLenInBytes, g_pVGuiLocalize->Find( printFormatString ),
				3,
				wszObjectName,
				wszBuilderName );
		}
	}
}
//-----------------------------------------------------------------------------
// Purpose: Draw function for the element
//-----------------------------------------------------------------------------
void CTargetID::Paint()
{
	C_BasePlayer *pPlayer = C_BasePlayer::GetLocalPlayer();
	if ( !pPlayer )
		return;

	// No id if still choosing class
	if ( C_BaseTFPlayer::GetLocalPlayer()->GetClass() == TFCLASS_UNDECIDED )
		return;

	// Get our target's ent index
	int iEntIndex = C_BaseTFPlayer::GetLocalPlayer()->GetIDTarget();
	// Didn't find one?
	if ( !iEntIndex )
	{
		// Check to see if we should clear our ID
		if ( m_flLastChangeTime && (gpGlobals->curtime > (m_flLastChangeTime + 0.5)) )
		{
			m_flLastChangeTime = 0;
			m_sIDString[0] = 0;
			m_iLastEntIndex = 0;
		}
		else
		{
			// Keep re-using the old one
			iEntIndex = m_iLastEntIndex;
		}
	}
	else
	{
		m_flLastChangeTime = gpGlobals->curtime;
	}

	// Is this an entindex sent by the server?
	if ( iEntIndex )
	{
		C_BaseTFPlayer *pPlayer = static_cast<C_BaseTFPlayer*>(cl_entitylist->GetEnt( iEntIndex ));
		C_BaseTFPlayer *pLocalPlayer = C_BaseTFPlayer::GetLocalPlayer();

		// Some entities we always want to check, cause the text may change
		// even while we're looking at it
		// Is it a player?
		if ( IsPlayerIndex( iEntIndex ) )
		{
			if ( pPlayer->InSameTeam(pLocalPlayer) )
			{
				// Check distance to other player, and if the player is on the same team
				float flDistSq = pPlayer->GetRenderOrigin().DistToSqr( pLocalPlayer->GetRenderOrigin() );
				if ( flDistSq < PLAYER_HINT_DISTANCE_SQ )
				{
					Q_snprintf( m_sIDString, sizeof(m_sIDString), "%s\nHealth: %.0f percent\nUse to donate resources",
						pPlayer->GetPlayerName(), ((float)pPlayer->GetHealth() / (float)pPlayer->GetMaxHealth() ) * 100 );
				}
				else
				{
					Q_snprintf( m_sIDString, sizeof(m_sIDString), "%s\nHealth: %.0f percent",
						pPlayer->GetPlayerName(), ((float)pPlayer->GetHealth() / (float)pPlayer->GetMaxHealth() ) * 100 );
				}
			}
			else if (( pPlayer->GetHealth() == 0) && (pLocalPlayer->GetClass() == TFCLASS_INFILTRATOR) )
			{
				Q_snprintf( m_sIDString, sizeof(m_sIDString), "%s\nUse to disguise as this player", pPlayer->GetPlayerName() );
			}
			else
			{
				m_sIDString[0] = 0;
				m_iLastEntIndex = 0;
			}
		}
		else
		{
			// Objects
			C_BaseEntity *pEnt = cl_entitylist->GetEnt( iEntIndex );
			if ( !pEnt || !pEnt->InSameTeam(pLocalPlayer) )
			{
				// This can happen because the object was destroyed
				m_sIDString[0] = 0;
				m_iLastEntIndex = 0;
			}
			else
			{
				// Don't check validity if it's sent by the server
				Q_strncpy( m_sIDString, pEnt->GetIDString(), sizeof(m_sIDString) );
				m_iLastEntIndex = iEntIndex;
			}
		}
	}

	// Draw our ID string
	if ( m_sIDString[0] )
	{
		int width, height;
		int ypos = YRES(300);

		// Messagechars can't handle multiple line strings, so parse out the \n's and give it one line at a time
		char *ch = m_sIDString;
		while ( *ch )
		{
			// Find the next newline
			char *next_line;
			for ( next_line = ch; *next_line != '\n' && *next_line != 0; next_line++ )
			{
			}

			// Stomp the newline
			char *top = next_line;
			if ( *top == '\n' )
			{
				*top = 0;
			}
			else
			{
				top = NULL;
			}

			// Draw the line
			messagechars->GetStringLength( m_hFont, &width, &height, ch );
			messagechars->DrawString( m_hFont, (ScreenWidth() - width) / 2, ypos, 255, 255, 245, 255, ch, IMessageChars::MESSAGESTRINGID_NONE );

			ypos += height;

			// Restore the newline
			if ( top ) 
			{
				*top = '\n';
			}

			// Move to the next line
			ch = next_line;
			if ( *ch == '\n' )
			{
				ch++;
			}
		}
	}
}