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.

155 lines
3.5 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 "tfc_player.h"
  25. #include "tfc_gamerules.h"
  26. #include "tier0/vprof.h"
  27. #include "tfc_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( CTFCPlayer *pPlayer )
  33. {
  34. pPlayer->InitialSpawn();
  35. pPlayer->Spawn();
  36. char sName[128];
  37. Q_strncpy( sName, pPlayer->GetPlayerName(), sizeof( sName ) );
  38. // First parse the name and remove any %'s
  39. for ( char *pApersand = sName; pApersand != NULL && *pApersand != 0; pApersand++ )
  40. {
  41. // Replace it with a space
  42. if ( *pApersand == '%' )
  43. *pApersand = ' ';
  44. }
  45. // notify other clients of player joining the game
  46. UTIL_ClientPrintAll( HUD_PRINTNOTIFY, "#Game_connected", sName[0] != 0 ? sName : "<unconnected>" );
  47. }
  48. /*
  49. ===========
  50. ClientPutInServer
  51. called each time a player is spawned into the game
  52. ============
  53. */
  54. void ClientPutInServer( edict_t *pEdict, const char *playername )
  55. {
  56. // Allocate a CBaseTFPlayer for pev, and call spawn
  57. CTFCPlayer *pPlayer = CTFCPlayer::CreatePlayer( "player", pEdict );
  58. pPlayer->SetPlayerName( playername );
  59. }
  60. void ClientActive( edict_t *pEdict, bool bLoadGame )
  61. {
  62. // Can't load games in CS!
  63. Assert( !bLoadGame );
  64. CTFCPlayer *pPlayer = ToTFCPlayer( CBaseEntity::Instance( pEdict ) );
  65. FinishClientPutInServer( pPlayer );
  66. }
  67. /*
  68. ===============
  69. const char *GetGameDescription()
  70. Returns the descriptive name of this .dll. E.g., Half-Life, or Team Fortress 2
  71. ===============
  72. */
  73. const char *GetGameDescription()
  74. {
  75. if ( g_pGameRules ) // this function may be called before the world has spawned, and the game rules initialized
  76. return g_pGameRules->GetGameDescription();
  77. else
  78. return "CounterStrike";
  79. }
  80. //-----------------------------------------------------------------------------
  81. // Purpose: Precache game-specific models & sounds
  82. //-----------------------------------------------------------------------------
  83. void ClientGamePrecache( void )
  84. {
  85. // Materials used by the client effects
  86. CBaseEntity::PrecacheModel( "sprites/white.vmt" );
  87. CBaseEntity::PrecacheModel( "sprites/physbeam.vmt" );
  88. }
  89. // called by ClientKill and DeadThink
  90. void respawn( CBaseEntity *pEdict, bool fCopyCorpse )
  91. {
  92. if (gpGlobals->coop || gpGlobals->deathmatch)
  93. {
  94. if ( fCopyCorpse )
  95. {
  96. // make a copy of the dead body for appearances sake
  97. dynamic_cast< CBasePlayer* >( pEdict )->CreateCorpse();
  98. }
  99. // respawn player
  100. pEdict->Spawn();
  101. }
  102. else
  103. { // restart the entire server
  104. engine->ServerCommand("reload\n");
  105. }
  106. }
  107. void GameStartFrame( void )
  108. {
  109. VPROF( "GameStartFrame" );
  110. if ( g_pGameRules )
  111. g_pGameRules->Think();
  112. if ( g_fGameOver )
  113. return;
  114. gpGlobals->teamplay = teamplay.GetInt() ? true : false;
  115. Bot_RunAll();
  116. }
  117. //=========================================================
  118. // instantiate the proper game rules object
  119. //=========================================================
  120. void InstallGameRules()
  121. {
  122. CreateGameRulesObject( "CTFCGameRules" );
  123. }