Counter Strike : Global Offensive Source Code
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.

138 lines
3.4 KiB

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