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.

164 lines
3.8 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //=============================================================================//
  8. /*
  9. ===== tf_client.cpp ========================================================
  10. HL2 client/server game specific stuff
  11. */
  12. #include "cbase.h"
  13. #include "player.h"
  14. #include "gamerules.h"
  15. #include "entitylist.h"
  16. #include "physics.h"
  17. #include "game.h"
  18. #include "ai_network.h"
  19. #include "ai_node.h"
  20. #include "ai_hull.h"
  21. #include "shake.h"
  22. #include "player_resource.h"
  23. #include "engine/IEngineSound.h"
  24. #include "sdk_player.h"
  25. #include "sdk_gamerules.h"
  26. #include "tier0/vprof.h"
  27. #include "sdk_bot_temp.h"
  28. // memdbgon must be the last include file in a .cpp file!!!
  29. #include "tier0/memdbgon.h"
  30. extern CBaseEntity *FindPickerEntity( CBasePlayer *pPlayer );
  31. extern bool g_fGameOver;
  32. void FinishClientPutInServer( CSDKPlayer *pPlayer )
  33. {
  34. pPlayer->InitialSpawn();
  35. pPlayer->Spawn();
  36. if (!pPlayer->IsBot())
  37. {
  38. // When the player first joins the server, they
  39. pPlayer->m_takedamage = DAMAGE_YES;
  40. pPlayer->pl.deadflag = false;
  41. pPlayer->m_lifeState = LIFE_ALIVE;
  42. pPlayer->RemoveEffects( EF_NODRAW );
  43. pPlayer->ChangeTeam( TEAM_UNASSIGNED );
  44. pPlayer->SetThink( NULL );
  45. }
  46. char sName[128];
  47. Q_strncpy( sName, pPlayer->GetPlayerName(), sizeof( sName ) );
  48. // First parse the name and remove any %'s
  49. for ( char *pApersand = sName; pApersand != NULL && *pApersand != 0; pApersand++ )
  50. {
  51. // Replace it with a space
  52. if ( *pApersand == '%' )
  53. *pApersand = ' ';
  54. }
  55. // notify other clients of player joining the game
  56. UTIL_ClientPrintAll( HUD_PRINTNOTIFY, "#Game_connected", sName[0] != 0 ? sName : "<unconnected>" );
  57. }
  58. /*
  59. ===========
  60. ClientPutInServer
  61. called each time a player is spawned into the game
  62. ============
  63. */
  64. void ClientPutInServer( edict_t *pEdict, const char *playername )
  65. {
  66. // Allocate a CBaseTFPlayer for pev, and call spawn
  67. CSDKPlayer *pPlayer = CSDKPlayer::CreatePlayer( "player", pEdict );
  68. pPlayer->SetPlayerName( playername );
  69. }
  70. void ClientActive( edict_t *pEdict, bool bLoadGame )
  71. {
  72. // Can't load games in CS!
  73. Assert( !bLoadGame );
  74. CSDKPlayer *pPlayer = ToSDKPlayer( CBaseEntity::Instance( pEdict ) );
  75. FinishClientPutInServer( pPlayer );
  76. }
  77. /*
  78. ===============
  79. const char *GetGameDescription()
  80. Returns the descriptive name of this .dll. E.g., Half-Life, or Team Fortress 2
  81. ===============
  82. */
  83. const char *GetGameDescription()
  84. {
  85. if ( g_pGameRules ) // this function may be called before the world has spawned, and the game rules initialized
  86. return g_pGameRules->GetGameDescription();
  87. else
  88. return "CounterStrike";
  89. }
  90. //-----------------------------------------------------------------------------
  91. // Purpose: Precache game-specific models & sounds
  92. //-----------------------------------------------------------------------------
  93. void ClientGamePrecache( void )
  94. {
  95. // Materials used by the client effects
  96. CBaseEntity::PrecacheModel( "sprites/white.vmt" );
  97. CBaseEntity::PrecacheModel( "sprites/physbeam.vmt" );
  98. }
  99. // called by ClientKill and DeadThink
  100. void respawn( CBaseEntity *pEdict, bool fCopyCorpse )
  101. {
  102. if (gpGlobals->coop || gpGlobals->deathmatch)
  103. {
  104. if ( fCopyCorpse )
  105. {
  106. // make a copy of the dead body for appearances sake
  107. dynamic_cast< CBasePlayer* >( pEdict )->CreateCorpse();
  108. }
  109. // respawn player
  110. pEdict->Spawn();
  111. }
  112. else
  113. { // restart the entire server
  114. engine->ServerCommand("reload\n");
  115. }
  116. }
  117. void GameStartFrame( void )
  118. {
  119. VPROF( "GameStartFrame" );
  120. if ( g_pGameRules )
  121. g_pGameRules->Think();
  122. if ( g_fGameOver )
  123. return;
  124. gpGlobals->teamplay = teamplay.GetInt() ? true : false;
  125. }
  126. //=========================================================
  127. // instantiate the proper game rules object
  128. //=========================================================
  129. void InstallGameRules()
  130. {
  131. CreateGameRulesObject( "CSDKGameRules" );
  132. }