Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions src/game/client/clientmode_shared.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,10 @@ void ClientModeShared::Init()
ListenForGameEvent( "game_newmap" );
#endif

#ifdef MAPBASE_MP
ListenForGameEvent( "player_afk" );
#endif

#ifndef _XBOX
HLTVCamera()->Init();
#if defined( REPLAY_ENABLED )
Expand Down Expand Up @@ -1632,6 +1636,36 @@ void ClientModeShared::FireGameEvent( IGameEvent *event )
CReplayMessagePanel::RemoveAll();
}
#endif
#ifdef MAPBASE_MP
else if ( V_strcmp( "player_afk", eventname ) == 0 )
{
if ( !hudChat )
return;

int iPlayerIndex = engine->GetPlayerForUserID( event->GetInt( "userid" ) );
C_BasePlayer *pPlayer = UTIL_PlayerByIndex( iPlayerIndex );
if ( pPlayer )
{
const char *pszPlayerName = pPlayer->GetPlayerName();
if (PlayerNameNotSetYet( pszPlayerName ))
return;

CSteamID steamID;
pPlayer->GetSteamID( &steamID );

wchar_t wszPlayerName[MAX_PLAYER_NAME_LENGTH];
UTIL_GetFilteredPlayerNameAsWChar( steamID, pszPlayerName, wszPlayerName );

wchar_t wszLocalized[100];
g_pVGuiLocalize->ConstructString_safe( wszLocalized, g_pVGuiLocalize->Find( "#game_idle_spectator" ), 1, wszPlayerName );

char szLocalized[100];
g_pVGuiLocalize->ConvertUnicodeToANSI( wszLocalized, szLocalized, sizeof( szLocalized ) );

hudChat->Printf( CHAT_FILTER_TEAMCHANGE, "%s", szLocalized );
}
}
#endif

else
{
Expand Down
56 changes: 56 additions & 0 deletions src/game/client/hl2mp/clientmode_hl2mpnormal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
#include "hl2mpclientscoreboard.h"
#include "hl2mptextwindow.h"
#include "ienginevgui.h"
#ifdef MAPBASE
#include "hl2mp_gamerules.h"
#include "usermessages.h"
#endif

// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
Expand Down Expand Up @@ -109,6 +113,18 @@ ClientModeHL2MPNormal::~ClientModeHL2MPNormal()
}


#ifdef MAPBASE
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
int g_nNumHideBots = 0;
static void __MsgFunc_HideBotsJoin( bf_read &msg )
{
g_nNumHideBots = msg.ReadChar();
}
#endif


//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
Expand All @@ -122,6 +138,46 @@ void ClientModeHL2MPNormal::Init()
{
Warning( "Couldn't load combine panel scheme!\n" );
}

#ifdef MAPBASE
usermessages->HookMessage( "HideBotsJoin", __MsgFunc_HideBotsJoin );
#endif
}


//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void ClientModeHL2MPNormal::FireGameEvent( IGameEvent *event )
{
const char *eventname = event->GetName();

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

#ifdef MAPBASE
if ( FStrEq( "player_connect_client", eventname ) || FStrEq( "player_disconnect", eventname ) )
{
if ( event->GetInt( "bot" ) != 0 )
{
if (g_nNumHideBots > 0)
{
g_nNumHideBots--;
return;
}
}
}
else if ( FStrEq( "player_team", eventname ) )
{
// Don't show player team messages during this
if (g_nNumHideBots > 0)
{
return;
}
}
#endif

BaseClass::FireGameEvent( event );
}


Expand Down
2 changes: 2 additions & 0 deletions src/game/client/hl2mp/clientmode_hl2mpnormal.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ class ClientModeHL2MPNormal : public ClientModeShared

virtual void Init();
virtual int GetDeathMessageStartHeight( void );

virtual void FireGameEvent( IGameEvent *event );
};

extern IClientMode *GetClientModeNormal();
Expand Down
43 changes: 43 additions & 0 deletions src/game/server/hl2mp/bot/hl2mp_bot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,10 @@ void CHL2MPBot::Spawn()
SetBrokenFormation( false );

GetVisionInterface()->ForgetAllKnownEntities();

#ifdef MAPBASE
SetUse( &CHL2MPBot::BotUse );
#endif
}


Expand Down Expand Up @@ -847,6 +851,45 @@ void CHL2MPBot::Event_Killed( const CTakeDamageInfo &info )
}


#ifdef MAPBASE
//-----------------------------------------------------------------------------------------------------
int CHL2MPBot::ObjectCaps( void )
{
int nCaps = BaseClass::ObjectCaps();

if ( ( HasAttribute( CHL2MPBot::CAN_POSSESS ) || HasAttribute( CHL2MPBot::IS_NPC ) ) && IsAlive() )
Comment thread
arbabf marked this conversation as resolved.
nCaps |= FCAP_IMPULSE_USE;

return nCaps;
}

//-----------------------------------------------------------------------------------------------------
void CHL2MPBot::BotUse( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value )
{
if ( HasAttribute( CHL2MPBot::CAN_POSSESS ) )
{
CHL2MP_Player *pPlayer = ToHL2MPPlayer( pActivator );
if ( pPlayer )
{
CRecipientFilter user;
user.AddAllPlayers();
user.MakeReliable();

// Make sure these bots come and go seamlessly
UserMessageBegin( user, "HideBotsJoin" );
WRITE_CHAR( 2 );
MessageEnd();

if (TheHL2MPBots().BotTakeOverPlayer( pPlayer, false ))
{
TheHL2MPBots().PlayerTakeOverBot( pPlayer, this );
}
}
}
}
#endif


//---------------------------------------------------------------------------------------------
class CCollectReachableObjects : public ISearchSurroundingAreasFunctor
{
Expand Down
8 changes: 8 additions & 0 deletions src/game/server/hl2mp/bot/hl2mp_bot.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ class CHL2MPBot: public NextBotPlayer< CHL2MP_Player >, public CGameEventListene

virtual CNavArea *GetLastKnownArea( void ) const { return static_cast< CNavArea * >( BaseClass::GetLastKnownArea() ); } // return the last nav area the player occupied - NULL if unknown

#ifdef MAPBASE
virtual int ObjectCaps( void );
virtual void BotUse( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value );
#endif

// NextBotPlayer
static CBasePlayer *AllocatePlayerEntity( edict_t *pEdict, const char *playerName );

Expand Down Expand Up @@ -192,6 +197,9 @@ class CHL2MPBot: public NextBotPlayer< CHL2MP_Player >, public CGameEventListene
ALWAYS_FIRE_WEAPON = 1<<13, // constantly fire our weapon
TELEPORT_TO_HINT = 1<<14, // bot will teleport to hint target instead of walking out from the spawn point
AUTO_JUMP = 1<<18, // auto jump
#ifdef MAPBASE
CAN_POSSESS = 1<<19, // player can switch to this bot
#endif
};
void SetAttribute( int attributeFlag );
void ClearAttribute( int attributeFlag );
Expand Down
Loading
Loading