2013-12-02 19:31:46 -08:00
|
|
|
//========= Copyright Valve Corporation, All rights reserved. ============//
|
|
|
|
//
|
|
|
|
// Purpose: implementation of player info manager
|
|
|
|
//
|
|
|
|
//=============================================================================//
|
|
|
|
|
|
|
|
#include "cbase.h"
|
|
|
|
#include "player.h"
|
|
|
|
#include "playerinfomanager.h"
|
|
|
|
#include "edict.h"
|
|
|
|
|
2020-07-16 15:43:30 +00:00
|
|
|
#if defined( TF_DLL )
|
|
|
|
#include "tf_shareddefs.h"
|
|
|
|
#elif defined( CSTRIKE_DLL )
|
|
|
|
#include "weapon_csbase.h"
|
|
|
|
#elif defined( DOD_DLL )
|
|
|
|
#include "weapon_dodbase.h"
|
|
|
|
#elif defined( SDK_DLL )
|
|
|
|
#include "weapon_sdkbase.h"
|
|
|
|
#endif
|
|
|
|
|
2013-12-02 19:31:46 -08:00
|
|
|
extern CGlobalVars *gpGlobals;
|
|
|
|
static CPlayerInfoManager s_PlayerInfoManager;
|
|
|
|
static CPluginBotManager s_BotManager;
|
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
|
|
|
|
|
|
|
//
|
|
|
|
// Old version support
|
|
|
|
//
|
|
|
|
|
2020-07-16 15:43:30 +00:00
|
|
|
//Tony; pulled out version 1 and 2 support for orange box, we're starting fresh now with v3 player and v2 of the bot interface.
|
2013-12-02 19:31:46 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
IPlayerInfo *CPlayerInfoManager::GetPlayerInfo( edict_t *pEdict )
|
|
|
|
{
|
|
|
|
CBasePlayer *pPlayer = ( ( CBasePlayer * )CBaseEntity::Instance( pEdict ));
|
|
|
|
if ( pPlayer )
|
|
|
|
return pPlayer->GetPlayerInfo();
|
|
|
|
else
|
|
|
|
return NULL;
|
2020-07-16 15:43:30 +00:00
|
|
|
}
|
|
|
|
IPlayerInfo *CPlayerInfoManager::GetPlayerInfo( int index )
|
|
|
|
{
|
|
|
|
return GetPlayerInfo( engine->PEntityOfEntIndex( index ) );
|
2013-12-02 19:31:46 -08:00
|
|
|
}
|
|
|
|
|
2020-07-16 15:43:30 +00:00
|
|
|
// Games implementing advanced bot support should override this.
|
|
|
|
int CPlayerInfoManager::AliasToWeaponId(const char *weaponName)
|
|
|
|
{
|
|
|
|
//Tony; TF doesn't support this. Should it?
|
|
|
|
#if defined ( CSTRIKE_DLL ) || defined ( DOD_DLL ) || defined ( SDK_DLL )
|
|
|
|
return AliasToWeaponID(weaponName);
|
|
|
|
#endif
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Games implementing advanced bot support should override this.
|
|
|
|
const char *CPlayerInfoManager::WeaponIdToAlias(int weaponId)
|
|
|
|
{
|
|
|
|
#if defined( TF_DLL )
|
|
|
|
return WeaponIdToAlias(weaponId);
|
|
|
|
#elif defined ( CSTRIKE_DLL ) || defined ( DOD_DLL ) || defined ( SDK_DLL )
|
|
|
|
return WeaponIDToAlias(weaponId);
|
|
|
|
#endif
|
|
|
|
return "MOD_DIDNT_IMPLEMENT_ME";
|
|
|
|
}
|
2013-12-02 19:31:46 -08:00
|
|
|
CGlobalVars *CPlayerInfoManager::GetGlobalVars()
|
|
|
|
{
|
|
|
|
return gpGlobals;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
IBotController *CPluginBotManager::GetBotController( edict_t *pEdict )
|
|
|
|
{
|
|
|
|
CBasePlayer *pPlayer = ( ( CBasePlayer * )CBaseEntity::Instance( pEdict ));
|
|
|
|
if ( pPlayer && pPlayer->IsBot() )
|
|
|
|
{
|
|
|
|
return pPlayer->GetBotController();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
edict_t *CPluginBotManager::CreateBot( const char *botname )
|
|
|
|
{
|
|
|
|
edict_t *pEdict = engine->CreateFakeClient( botname );
|
|
|
|
if (!pEdict)
|
|
|
|
{
|
|
|
|
Msg( "Failed to create Bot.\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Allocate a player entity for the bot, and call spawn
|
|
|
|
CBasePlayer *pPlayer = ((CBasePlayer*)CBaseEntity::Instance( pEdict ));
|
|
|
|
|
|
|
|
pPlayer->ClearFlags();
|
|
|
|
pPlayer->AddFlag( FL_CLIENT | FL_FAKECLIENT );
|
|
|
|
pPlayer->ChangeTeam( TEAM_UNASSIGNED );
|
2020-07-16 15:43:30 +00:00
|
|
|
pPlayer->AddEFlags( EFL_PLUGIN_BASED_BOT ); // Mark it as a plugin based bot
|
2013-12-02 19:31:46 -08:00
|
|
|
pPlayer->RemoveAllItems( true );
|
|
|
|
pPlayer->Spawn();
|
|
|
|
|
|
|
|
return pEdict;
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPOSE_SINGLE_INTERFACE_GLOBALVAR(CPlayerInfoManager, IPlayerInfoManager, INTERFACEVERSION_PLAYERINFOMANAGER, s_PlayerInfoManager);
|
|
|
|
EXPOSE_SINGLE_INTERFACE_GLOBALVAR(CPluginBotManager, IBotManager, INTERFACEVERSION_PLAYERBOTMANAGER, s_BotManager);
|
|
|
|
|