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.

220 lines
5.8 KiB

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