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.

201 lines
5.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 "hl2mp_player.h"
  14. #include "hl2mp_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 "team.h"
  23. #include "viewport_panel_names.h"
  24. #include "tier0/vprof.h"
  25. // memdbgon must be the last include file in a .cpp file!!!
  26. #include "tier0/memdbgon.h"
  27. void Host_Say( edict_t *pEdict, bool teamonly );
  28. ConVar sv_motd_unload_on_dismissal( "sv_motd_unload_on_dismissal", "0", 0, "If enabled, the MOTD contents will be unloaded when the player closes the MOTD." );
  29. extern CBaseEntity* FindPickerEntityClass( CBasePlayer *pPlayer, char *classname );
  30. extern bool g_fGameOver;
  31. void FinishClientPutInServer( CHL2MP_Player *pPlayer )
  32. {
  33. pPlayer->InitialSpawn();
  34. pPlayer->Spawn();
  35. char sName[128];
  36. Q_strncpy( sName, pPlayer->GetPlayerName(), sizeof( sName ) );
  37. // First parse the name and remove any %'s
  38. for ( char *pApersand = sName; pApersand != NULL && *pApersand != 0; pApersand++ )
  39. {
  40. // Replace it with a space
  41. if ( *pApersand == '%' )
  42. *pApersand = ' ';
  43. }
  44. // notify other clients of player joining the game
  45. UTIL_ClientPrintAll( HUD_PRINTNOTIFY, "#Game_connected", sName[0] != 0 ? sName : "<unconnected>" );
  46. if ( HL2MPRules()->IsTeamplay() == true )
  47. {
  48. ClientPrint( pPlayer, HUD_PRINTTALK, "You are on team %s1\n", pPlayer->GetTeam()->GetName() );
  49. }
  50. const ConVar *hostname = cvar->FindVar( "hostname" );
  51. const char *title = (hostname) ? hostname->GetString() : "MESSAGE OF THE DAY";
  52. KeyValues *data = new KeyValues("data");
  53. data->SetString( "title", title ); // info panel title
  54. data->SetString( "type", "1" ); // show userdata from stringtable entry
  55. data->SetString( "msg", "motd" ); // use this stringtable entry
  56. data->SetBool( "unload", sv_motd_unload_on_dismissal.GetBool() );
  57. pPlayer->ShowViewPortPanel( PANEL_INFO, true, data );
  58. data->deleteThis();
  59. }
  60. /*
  61. ===========
  62. ClientPutInServer
  63. called each time a player is spawned into the game
  64. ============
  65. */
  66. void ClientPutInServer( edict_t *pEdict, const char *playername )
  67. {
  68. // Allocate a CBaseTFPlayer for pev, and call spawn
  69. CHL2MP_Player *pPlayer = CHL2MP_Player::CreatePlayer( "player", pEdict );
  70. pPlayer->SetPlayerName( playername );
  71. }
  72. void ClientActive( edict_t *pEdict, bool bLoadGame )
  73. {
  74. // Can't load games in CS!
  75. Assert( !bLoadGame );
  76. CHL2MP_Player *pPlayer = ToHL2MPPlayer( CBaseEntity::Instance( pEdict ) );
  77. FinishClientPutInServer( pPlayer );
  78. }
  79. /*
  80. ===============
  81. const char *GetGameDescription()
  82. Returns the descriptive name of this .dll. E.g., Half-Life, or Team Fortress 2
  83. ===============
  84. */
  85. const char *GetGameDescription()
  86. {
  87. if ( g_pGameRules ) // this function may be called before the world has spawned, and the game rules initialized
  88. return g_pGameRules->GetGameDescription();
  89. else
  90. return "Half-Life 2 Deathmatch";
  91. }
  92. //-----------------------------------------------------------------------------
  93. // Purpose: Given a player and optional name returns the entity of that
  94. // classname that the player is nearest facing
  95. //
  96. // Input :
  97. // Output :
  98. //-----------------------------------------------------------------------------
  99. CBaseEntity* FindEntity( edict_t *pEdict, char *classname)
  100. {
  101. // If no name was given set bits based on the picked
  102. if (FStrEq(classname,""))
  103. {
  104. return (FindPickerEntityClass( static_cast<CBasePlayer*>(GetContainingEntity(pEdict)), classname ));
  105. }
  106. return NULL;
  107. }
  108. //-----------------------------------------------------------------------------
  109. // Purpose: Precache game-specific models & sounds
  110. //-----------------------------------------------------------------------------
  111. void ClientGamePrecache( void )
  112. {
  113. CBaseEntity::PrecacheModel("models/player.mdl");
  114. CBaseEntity::PrecacheModel( "models/gibs/agibs.mdl" );
  115. CBaseEntity::PrecacheModel ("models/weapons/v_hands.mdl");
  116. CBaseEntity::PrecacheScriptSound( "HUDQuickInfo.LowAmmo" );
  117. CBaseEntity::PrecacheScriptSound( "HUDQuickInfo.LowHealth" );
  118. CBaseEntity::PrecacheScriptSound( "FX_AntlionImpact.ShellImpact" );
  119. CBaseEntity::PrecacheScriptSound( "Missile.ShotDown" );
  120. CBaseEntity::PrecacheScriptSound( "Bullets.DefaultNearmiss" );
  121. CBaseEntity::PrecacheScriptSound( "Bullets.GunshipNearmiss" );
  122. CBaseEntity::PrecacheScriptSound( "Bullets.StriderNearmiss" );
  123. CBaseEntity::PrecacheScriptSound( "Geiger.BeepHigh" );
  124. CBaseEntity::PrecacheScriptSound( "Geiger.BeepLow" );
  125. }
  126. // called by ClientKill and DeadThink
  127. void respawn( CBaseEntity *pEdict, bool fCopyCorpse )
  128. {
  129. CHL2MP_Player *pPlayer = ToHL2MPPlayer( pEdict );
  130. if ( pPlayer )
  131. {
  132. if ( gpGlobals->curtime > pPlayer->GetDeathTime() + DEATH_ANIMATION_TIME )
  133. {
  134. // respawn player
  135. pPlayer->Spawn();
  136. }
  137. else
  138. {
  139. pPlayer->SetNextThink( gpGlobals->curtime + 0.1f );
  140. }
  141. }
  142. }
  143. void GameStartFrame( void )
  144. {
  145. VPROF("GameStartFrame()");
  146. if ( g_fGameOver )
  147. return;
  148. gpGlobals->teamplay = (teamplay.GetInt() != 0);
  149. #ifdef DEBUG
  150. extern void Bot_RunAll();
  151. Bot_RunAll();
  152. #endif
  153. }
  154. //=========================================================
  155. // instantiate the proper game rules object
  156. //=========================================================
  157. void InstallGameRules()
  158. {
  159. // vanilla deathmatch
  160. CreateGameRulesObject( "CHL2MPRules" );
  161. }