Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

134 lines
3.4 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: implementation of player info manager
  4. //
  5. //=============================================================================//
  6. #include "cbase.h"
  7. #include "player.h"
  8. #include "playerinfomanager.h"
  9. #include "edict.h"
  10. extern CGlobalVars *gpGlobals;
  11. static CPlayerInfoManager s_PlayerInfoManager;
  12. static CPluginBotManager s_BotManager;
  13. namespace
  14. {
  15. //
  16. // Old version support
  17. //
  18. abstract_class IPlayerInfo_V1
  19. {
  20. public:
  21. // returns the players name (UTF-8 encoded)
  22. virtual const char *GetName() = 0;
  23. // returns the userid (slot number)
  24. virtual int GetUserID() = 0;
  25. // returns the string of their network (i.e Steam) ID
  26. virtual const char *GetNetworkIDString() = 0;
  27. // returns the team the player is on
  28. virtual int GetTeamIndex() = 0;
  29. // changes the player to a new team (if the game dll logic allows it)
  30. virtual void ChangeTeam( int iTeamNum ) = 0;
  31. // returns the number of kills this player has (exact meaning is mod dependent)
  32. virtual int GetFragCount() = 0;
  33. // returns the number of deaths this player has (exact meaning is mod dependent)
  34. virtual int GetDeathCount() = 0;
  35. // returns if this player slot is actually valid
  36. virtual bool IsConnected() = 0;
  37. // returns the armor/health of the player (exact meaning is mod dependent)
  38. virtual int GetArmorValue() = 0;
  39. };
  40. abstract_class IPlayerInfoManager_V1
  41. {
  42. public:
  43. virtual IPlayerInfo_V1 *GetPlayerInfo( edict_t *pEdict ) = 0;
  44. };
  45. class CPlayerInfoManager_V1: public IPlayerInfoManager_V1
  46. {
  47. public:
  48. virtual IPlayerInfo_V1 *GetPlayerInfo( edict_t *pEdict );
  49. };
  50. static CPlayerInfoManager_V1 s_PlayerInfoManager_V1;
  51. IPlayerInfo_V1 *CPlayerInfoManager_V1::GetPlayerInfo( edict_t *pEdict )
  52. {
  53. CBasePlayer *pPlayer = ( ( CBasePlayer * )CBaseEntity::Instance( pEdict ));
  54. if ( pPlayer )
  55. {
  56. return (IPlayerInfo_V1 *)pPlayer->GetPlayerInfo();
  57. }
  58. else
  59. {
  60. return NULL;
  61. }
  62. }
  63. EXPOSE_SINGLE_INTERFACE_GLOBALVAR(CPlayerInfoManager_V1, IPlayerInfoManager_V1, "PlayerInfoManager001", s_PlayerInfoManager_V1);
  64. }
  65. IPlayerInfo *CPlayerInfoManager::GetPlayerInfo( edict_t *pEdict )
  66. {
  67. CBasePlayer *pPlayer = ( ( CBasePlayer * )CBaseEntity::Instance( pEdict ));
  68. if ( pPlayer )
  69. {
  70. return pPlayer->GetPlayerInfo();
  71. }
  72. else
  73. {
  74. return NULL;
  75. }
  76. }
  77. CGlobalVars *CPlayerInfoManager::GetGlobalVars()
  78. {
  79. return gpGlobals;
  80. }
  81. IBotController *CPluginBotManager::GetBotController( edict_t *pEdict )
  82. {
  83. CBasePlayer *pPlayer = ( ( CBasePlayer * )CBaseEntity::Instance( pEdict ));
  84. if ( pPlayer && pPlayer->IsBot() )
  85. {
  86. return pPlayer->GetBotController();
  87. }
  88. else
  89. {
  90. return NULL;
  91. }
  92. }
  93. edict_t *CPluginBotManager::CreateBot( const char *botname )
  94. {
  95. edict_t *pEdict = engine->CreateFakeClient( botname );
  96. if (!pEdict)
  97. {
  98. Msg( "Failed to create Bot.\n");
  99. return NULL;
  100. }
  101. // Allocate a player entity for the bot, and call spawn
  102. CBasePlayer *pPlayer = ((CBasePlayer*)CBaseEntity::Instance( pEdict ));
  103. pPlayer->ClearFlags();
  104. pPlayer->AddFlag( FL_CLIENT | FL_FAKECLIENT );
  105. pPlayer->ChangeTeam( TEAM_UNASSIGNED );
  106. pPlayer->RemoveAllItems( true );
  107. pPlayer->Spawn();
  108. return pEdict;
  109. }
  110. EXPOSE_SINGLE_INTERFACE_GLOBALVAR(CPlayerInfoManager, IPlayerInfoManager, INTERFACEVERSION_PLAYERINFOMANAGER, s_PlayerInfoManager);
  111. EXPOSE_SINGLE_INTERFACE_GLOBALVAR(CPluginBotManager, IBotManager, INTERFACEVERSION_PLAYERBOTMANAGER, s_BotManager);