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.

205 lines
5.4 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 "cs_player.h"
  25. #include "cs_gamerules.h"
  26. #include "cs_bot.h"
  27. #include "tier0/vprof.h"
  28. #include "teamplayroundbased_gamerules.h"
  29. // memdbgon must be the last include file in a .cpp file!!!
  30. #include "tier0/memdbgon.h"
  31. extern CBaseEntity *FindPickerEntity( CBasePlayer *pPlayer );
  32. extern bool g_fGameOver;
  33. void FinishClientPutInServer( CCSPlayer *pPlayer )
  34. {
  35. pPlayer->InitialSpawn();
  36. pPlayer->Spawn();
  37. if (!pPlayer->IsBot())
  38. {
  39. // When the player first joins the server, they
  40. pPlayer->m_iNumSpawns = 0;
  41. pPlayer->m_takedamage = DAMAGE_NO;
  42. pPlayer->pl.deadflag = true;
  43. pPlayer->m_lifeState = LIFE_DEAD;
  44. pPlayer->AddEffects( EF_NODRAW );
  45. pPlayer->ChangeTeam( TEAM_UNASSIGNED );
  46. pPlayer->SetThink( NULL );
  47. pPlayer->AddAccount( CSGameRules()->GetStartMoney() );
  48. // Move them to the first intro camera.
  49. pPlayer->MoveToNextIntroCamera();
  50. pPlayer->SetMoveType( MOVETYPE_NONE );
  51. }
  52. char sName[128];
  53. Q_strncpy( sName, pPlayer->GetPlayerName(), sizeof( sName ) );
  54. // First parse the name and remove any %'s
  55. for ( char *pApersand = sName; pApersand != NULL && *pApersand != 0; pApersand++ )
  56. {
  57. // Replace it with a space
  58. if ( *pApersand == '%' )
  59. *pApersand = ' ';
  60. }
  61. // notify other clients of player joining the game
  62. UTIL_ClientPrintAll( HUD_PRINTNOTIFY, "#Game_connected", sName[0] != 0 ? sName : "<unconnected>" );
  63. }
  64. /*
  65. ===========
  66. ClientPutInServer
  67. called each time a player is spawned into the game
  68. ============
  69. */
  70. void ClientPutInServer( edict_t *pEdict, const char *playername )
  71. {
  72. // Allocate a CBaseTFPlayer for pev, and call spawn
  73. CCSPlayer *pPlayer = CCSPlayer::CreatePlayer( "player", pEdict );
  74. pPlayer->SetPlayerName( playername );
  75. }
  76. void ClientActive( edict_t *pEdict, bool bLoadGame )
  77. {
  78. // Can't load games in CS!
  79. Assert( !bLoadGame );
  80. CCSPlayer *pPlayer = ToCSPlayer( CBaseEntity::Instance( pEdict ) );
  81. FinishClientPutInServer( pPlayer );
  82. CSingleUserRecipientFilter user( pPlayer );
  83. user.MakeReliable();
  84. // send the 4 end of match conditions. long frag limit, long max rounds, long rounds needed won, and long time
  85. UserMessageBegin( user, "MatchEndConditions" );
  86. WRITE_LONG( fraglimit.GetInt() );
  87. WRITE_LONG( mp_maxrounds.GetInt() );
  88. WRITE_LONG( mp_winlimit.GetInt() );
  89. WRITE_LONG( mp_timelimit.GetInt() );
  90. MessageEnd();
  91. }
  92. /*
  93. ===============
  94. const char *GetGameDescription()
  95. Returns the descriptive name of this .dll. E.g., Half-Life, or Team Fortress 2
  96. ===============
  97. */
  98. const char *GetGameDescription()
  99. {
  100. if ( g_pGameRules ) // this function may be called before the world has spawned, and the game rules initialized
  101. return g_pGameRules->GetGameDescription();
  102. else
  103. return "Counter-Strike: Source";
  104. }
  105. //-----------------------------------------------------------------------------
  106. // Purpose: Precache game-specific models & sounds
  107. //-----------------------------------------------------------------------------
  108. void ClientGamePrecache( void )
  109. {
  110. // Materials used by the client effects
  111. CBaseEntity::PrecacheModel( "sprites/white.vmt" );
  112. CBaseEntity::PrecacheModel( "sprites/physbeam.vmt" );
  113. // Legacy temp ents sounds
  114. CBaseEntity::PrecacheScriptSound( "Bounce.PistolShell" );
  115. CBaseEntity::PrecacheScriptSound( "Bounce.RifleShell" );
  116. CBaseEntity::PrecacheScriptSound( "Bounce.ShotgunShell" );
  117. // Moved to pure_server_minimal.txt
  118. // // Flashbang-related files
  119. // engine->ForceExactFile( "sprites/white.vmt" );
  120. // engine->ForceExactFile( "sprites/white.vtf" );
  121. // engine->ForceExactFile( "vgui/white.vmt" );
  122. // engine->ForceExactFile( "vgui/white.vtf" );
  123. // engine->ForceExactFile( "effects/flashbang.vmt" );
  124. // engine->ForceExactFile( "effects/flashbang_white.vmt" );
  125. //
  126. // // Smoke grenade-related files
  127. // engine->ForceExactFile( "particle/particle_smokegrenade1.vmt" );
  128. // engine->ForceExactFile( "particle/particle_smokegrenade.vtf" );
  129. //
  130. // // Sniper scope
  131. // engine->ForceExactFile( "sprites/scope_arc.vmt" );
  132. // engine->ForceExactFile( "sprites/scope_arc.vtf" );
  133. //
  134. // // DSP presets - don't want people avoiding the deafening + ear ring
  135. // engine->ForceExactFile( "scripts/dsp_presets.txt" );
  136. }
  137. // called by ClientKill and DeadThink
  138. void respawn( CBaseEntity *pEdict, bool fCopyCorpse )
  139. {
  140. if (gpGlobals->coop || gpGlobals->deathmatch)
  141. {
  142. if ( fCopyCorpse )
  143. {
  144. // make a copy of the dead body for appearances sake
  145. dynamic_cast< CBasePlayer* >( pEdict )->CreateCorpse();
  146. }
  147. // respawn player
  148. pEdict->Spawn();
  149. }
  150. else
  151. { // restart the entire server
  152. engine->ServerCommand("reload\n");
  153. }
  154. }
  155. void GameStartFrame( void )
  156. {
  157. VPROF( "GameStartFrame" );
  158. if ( g_fGameOver )
  159. return;
  160. gpGlobals->teamplay = teamplay.GetInt() ? true : false;
  161. }
  162. //=========================================================
  163. // instantiate the proper game rules object
  164. //=========================================================
  165. void InstallGameRules()
  166. {
  167. CreateGameRulesObject( "CCSGameRules" );
  168. }