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.

177 lines
4.3 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 "hl2_player.h"
  14. #include "hl2_gamerules.h"
  15. #include "gamerules.h"
  16. #include "teamplay_gamerules.h"
  17. #include "entitylist.h"
  18. #include "physics.h"
  19. #include "game.h"
  20. #include "player_resource.h"
  21. #include "engine/IEngineSound.h"
  22. #include "tier0/vprof.h"
  23. // memdbgon must be the last include file in a .cpp file!!!
  24. #include "tier0/memdbgon.h"
  25. void Host_Say( edict_t *pEdict, bool teamonly );
  26. extern CBaseEntity* FindPickerEntityClass( CBasePlayer *pPlayer, char *classname );
  27. extern bool g_fGameOver;
  28. /*
  29. ===========
  30. ClientPutInServer
  31. called each time a player is spawned into the game
  32. ============
  33. */
  34. void ClientPutInServer( edict_t *pEdict, const char *playername )
  35. {
  36. // Allocate a CBasePlayer for pev, and call spawn
  37. CHL2_Player *pPlayer = CHL2_Player::CreatePlayer( "player", pEdict );
  38. pPlayer->SetPlayerName( playername );
  39. }
  40. void ClientActive( edict_t *pEdict, bool bLoadGame )
  41. {
  42. CHL2_Player *pPlayer = dynamic_cast< CHL2_Player* >( CBaseEntity::Instance( pEdict ) );
  43. Assert( pPlayer );
  44. if ( !pPlayer )
  45. {
  46. return;
  47. }
  48. pPlayer->InitialSpawn();
  49. if ( !bLoadGame )
  50. {
  51. pPlayer->Spawn();
  52. }
  53. }
  54. /*
  55. ===============
  56. const char *GetGameDescription()
  57. Returns the descriptive name of this .dll. E.g., Half-Life, or Team Fortress 2
  58. ===============
  59. */
  60. const char *GetGameDescription()
  61. {
  62. if ( g_pGameRules ) // this function may be called before the world has spawned, and the game rules initialized
  63. return g_pGameRules->GetGameDescription();
  64. else
  65. return "Half-Life 2";
  66. }
  67. //-----------------------------------------------------------------------------
  68. // Purpose: Given a player and optional name returns the entity of that
  69. // classname that the player is nearest facing
  70. //
  71. // Input :
  72. // Output :
  73. //-----------------------------------------------------------------------------
  74. CBaseEntity* FindEntity( edict_t *pEdict, char *classname)
  75. {
  76. // If no name was given set bits based on the picked
  77. if (FStrEq(classname,""))
  78. {
  79. return (FindPickerEntityClass( static_cast<CBasePlayer*>(GetContainingEntity(pEdict)), classname ));
  80. }
  81. return NULL;
  82. }
  83. //-----------------------------------------------------------------------------
  84. // Purpose: Precache game-specific models & sounds
  85. //-----------------------------------------------------------------------------
  86. void ClientGamePrecache( void )
  87. {
  88. CBaseEntity::PrecacheModel("models/player.mdl");
  89. CBaseEntity::PrecacheModel( "models/gibs/agibs.mdl" );
  90. CBaseEntity::PrecacheModel ("models/weapons/v_hands.mdl");
  91. CBaseEntity::PrecacheScriptSound( "HUDQuickInfo.LowAmmo" );
  92. CBaseEntity::PrecacheScriptSound( "HUDQuickInfo.LowHealth" );
  93. CBaseEntity::PrecacheScriptSound( "FX_AntlionImpact.ShellImpact" );
  94. CBaseEntity::PrecacheScriptSound( "Missile.ShotDown" );
  95. CBaseEntity::PrecacheScriptSound( "Bullets.DefaultNearmiss" );
  96. CBaseEntity::PrecacheScriptSound( "Bullets.GunshipNearmiss" );
  97. CBaseEntity::PrecacheScriptSound( "Bullets.StriderNearmiss" );
  98. CBaseEntity::PrecacheScriptSound( "Geiger.BeepHigh" );
  99. CBaseEntity::PrecacheScriptSound( "Geiger.BeepLow" );
  100. }
  101. // called by ClientKill and DeadThink
  102. void respawn( CBaseEntity *pEdict, bool fCopyCorpse )
  103. {
  104. if (gpGlobals->coop || gpGlobals->deathmatch)
  105. {
  106. if ( fCopyCorpse )
  107. {
  108. // make a copy of the dead body for appearances sake
  109. ((CHL2_Player *)pEdict)->CreateCorpse();
  110. }
  111. // respawn player
  112. pEdict->Spawn();
  113. }
  114. else
  115. { // restart the entire server
  116. engine->ServerCommand("reload\n");
  117. }
  118. }
  119. void GameStartFrame( void )
  120. {
  121. VPROF("GameStartFrame()");
  122. if ( g_fGameOver )
  123. return;
  124. gpGlobals->teamplay = (teamplay.GetInt() != 0);
  125. }
  126. #ifdef HL2_EPISODIC
  127. extern ConVar gamerules_survival;
  128. #endif
  129. //=========================================================
  130. // instantiate the proper game rules object
  131. //=========================================================
  132. void InstallGameRules()
  133. {
  134. #ifdef HL2_EPISODIC
  135. if ( gamerules_survival.GetBool() )
  136. {
  137. // Survival mode
  138. CreateGameRulesObject( "CHalfLife2Survival" );
  139. }
  140. else
  141. #endif
  142. {
  143. // generic half-life
  144. CreateGameRulesObject( "CHalfLife2" );
  145. }
  146. }