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.

236 lines
7.2 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 "dod_player.h"
  25. #include "dod_gamerules.h"
  26. #include "tier0/vprof.h"
  27. // memdbgon must be the last include file in a .cpp file!!!
  28. #include "tier0/memdbgon.h"
  29. extern CBaseEntity *FindPickerEntity( CBasePlayer *pPlayer );
  30. extern bool g_fGameOver;
  31. void FinishClientPutInServer( CDODPlayer *pPlayer )
  32. {
  33. pPlayer->InitialSpawn();
  34. pPlayer->Spawn();
  35. if (!pPlayer->IsBot())
  36. {
  37. // When the player first joins the server, they
  38. pPlayer->m_takedamage = DAMAGE_NO;
  39. pPlayer->pl.deadflag = true;
  40. pPlayer->m_lifeState = LIFE_DEAD;
  41. pPlayer->AddEffects( EF_NODRAW );
  42. pPlayer->SetThink( NULL );
  43. if ( 1 )
  44. {
  45. pPlayer->ChangeTeam( TEAM_UNASSIGNED );
  46. // Move them to the first intro camera.
  47. pPlayer->MoveToNextIntroCamera();
  48. pPlayer->SetMoveType( MOVETYPE_NONE );
  49. }
  50. }
  51. char sName[128];
  52. Q_strncpy( sName, pPlayer->GetPlayerName(), sizeof( sName ) );
  53. // First parse the name and remove any %'s
  54. for ( char *pApersand = sName; pApersand != NULL && *pApersand != 0; pApersand++ )
  55. {
  56. // Replace it with a space
  57. if ( *pApersand == '%' )
  58. *pApersand = ' ';
  59. }
  60. // notify other clients of player joining the game
  61. UTIL_ClientPrintAll( HUD_PRINTNOTIFY, "#Game_connected", sName[0] != 0 ? sName : "<unconnected>" );
  62. }
  63. /*
  64. ===========
  65. ClientPutInServer
  66. called each time a player is spawned into the game
  67. ============
  68. */
  69. void ClientPutInServer( edict_t *pEdict, const char *playername )
  70. {
  71. // Allocate a CBaseTFPlayer for pev, and call spawn
  72. CDODPlayer *pPlayer = CDODPlayer::CreatePlayer( "player", pEdict );
  73. pPlayer->SetPlayerName( playername );
  74. }
  75. void ClientActive( edict_t *pEdict, bool bLoadGame )
  76. {
  77. // Can't load games in CS!
  78. Assert( !bLoadGame );
  79. CDODPlayer *pPlayer = ToDODPlayer( CBaseEntity::Instance( pEdict ) );
  80. FinishClientPutInServer( pPlayer );
  81. }
  82. /*
  83. ===============
  84. const char *GetGameDescription()
  85. Returns the descriptive name of this .dll. E.g., Half-Life, or Team Fortress 2
  86. ===============
  87. */
  88. const char *GetGameDescription()
  89. {
  90. if ( g_pGameRules ) // this function may be called before the world has spawned, and the game rules initialized
  91. return g_pGameRules->GetGameDescription();
  92. else
  93. return "Day of Defeat";
  94. }
  95. int g_iHelmetModels[NUM_HELMETS];
  96. //-----------------------------------------------------------------------------
  97. // Purpose: Precache game-specific models & sounds
  98. //-----------------------------------------------------------------------------
  99. void ClientGamePrecache( void )
  100. {
  101. // Materials used by the client effects
  102. CBaseEntity::PrecacheModel( "sprites/white.vmt" );
  103. CBaseEntity::PrecacheModel( "sprites/physbeam.vmt" );
  104. for( int i=0;i<NUM_HELMETS;i++ )
  105. {
  106. g_iHelmetModels[i] = CBaseEntity::PrecacheModel( m_pszHelmetModels[i] );
  107. }
  108. // Moved to pure_server_minimal.txt
  109. // // Sniper scope
  110. // engine->ForceExactFile( "sprites/scopes/scope_spring_ul.vmt" );
  111. // engine->ForceExactFile( "sprites/scopes/scope_spring_ul.vtf" );
  112. // engine->ForceExactFile( "sprites/scopes/scope_spring_ur.vmt" );
  113. // engine->ForceExactFile( "sprites/scopes/scope_spring_ur.vtf" );
  114. // engine->ForceExactFile( "sprites/scopes/scope_spring_ll.vmt" );
  115. // engine->ForceExactFile( "sprites/scopes/scope_spring_ll.vtf" );
  116. // engine->ForceExactFile( "sprites/scopes/scope_spring_lr.vmt" );
  117. // engine->ForceExactFile( "sprites/scopes/scope_spring_lr.vtf" );
  118. //
  119. // engine->ForceExactFile( "sprites/scopes/scope_k43_ul.vmt" );
  120. // engine->ForceExactFile( "sprites/scopes/scope_k43_ul.vtf" );
  121. // engine->ForceExactFile( "sprites/scopes/scope_k43_ur.vmt" );
  122. // engine->ForceExactFile( "sprites/scopes/scope_k43_ur.vtf" );
  123. // engine->ForceExactFile( "sprites/scopes/scope_k43_ll.vmt" );
  124. // engine->ForceExactFile( "sprites/scopes/scope_k43_ll.vtf" );
  125. // engine->ForceExactFile( "sprites/scopes/scope_k43_lr.vmt" );
  126. // engine->ForceExactFile( "sprites/scopes/scope_k43_lr.vtf" );
  127. //
  128. // // Smoke grenade-related files
  129. // engine->ForceExactFile( "particle/particle_smokegrenade1.vmt" );
  130. // engine->ForceExactFile( "particle/particle_smokegrenade.vtf" );
  131. // engine->ForceExactFile( "effects/stun.vmt" );
  132. //
  133. // // DSP presets - don't want people avoiding the deafening + ear ring
  134. // engine->ForceExactFile( "scripts/dsp_presets.txt" );
  135. //
  136. // // force weapon scripts because people are dirty cheaters
  137. // engine->ForceExactFile( "scripts/weapon_30cal.ctx");
  138. // engine->ForceExactFile( "scripts/weapon_amerknife.ctx");
  139. // engine->ForceExactFile( "scripts/weapon_bar.ctx");
  140. // engine->ForceExactFile( "scripts/weapon_bazooka.ctx");
  141. // engine->ForceExactFile( "scripts/weapon_c96.ctx");
  142. // engine->ForceExactFile( "scripts/weapon_colt.ctx");
  143. // engine->ForceExactFile( "scripts/weapon_frag_ger.ctx");
  144. // engine->ForceExactFile( "scripts/weapon_frag_ger_live.ctx");
  145. // engine->ForceExactFile( "scripts/weapon_frag_us.ctx");
  146. // engine->ForceExactFile( "scripts/weapon_frag_us_live.ctx");
  147. // engine->ForceExactFile( "scripts/weapon_garand.ctx");
  148. // engine->ForceExactFile( "scripts/weapon_k98.ctx");
  149. // engine->ForceExactFile( "scripts/weapon_k98_scoped.ctx");
  150. // engine->ForceExactFile( "scripts/weapon_m1carbine.ctx");
  151. // engine->ForceExactFile( "scripts/weapon_mg42.ctx");
  152. // engine->ForceExactFile( "scripts/weapon_mp40.ctx");
  153. // engine->ForceExactFile( "scripts/weapon_mp44.ctx");
  154. // engine->ForceExactFile( "scripts/weapon_p38.ctx");
  155. // engine->ForceExactFile( "scripts/weapon_pschreck.ctx");
  156. // engine->ForceExactFile( "scripts/weapon_riflegren_ger.ctx");
  157. // engine->ForceExactFile( "scripts/weapon_riflegren_ger_live.ctx");
  158. // engine->ForceExactFile( "scripts/weapon_riflegren_us.ctx");
  159. // engine->ForceExactFile( "scripts/weapon_riflegren_us_live.ctx");
  160. // engine->ForceExactFile( "scripts/weapon_smoke_ger.ctx");
  161. // engine->ForceExactFile( "scripts/weapon_smoke_us.ctx");
  162. // engine->ForceExactFile( "scripts/weapon_spade.ctx");
  163. // engine->ForceExactFile( "scripts/weapon_spring.ctx");
  164. // engine->ForceExactFile( "scripts/weapon_thompson.ctx");
  165. }
  166. // called by ClientKill and DeadThink
  167. void respawn( CBaseEntity *pEdict, bool fCopyCorpse )
  168. {
  169. if (gpGlobals->coop || gpGlobals->deathmatch)
  170. {
  171. if ( fCopyCorpse )
  172. {
  173. // make a copy of the dead body for appearances sake
  174. dynamic_cast< CBasePlayer* >( pEdict )->CreateCorpse();
  175. }
  176. // respawn player
  177. pEdict->Spawn();
  178. }
  179. else
  180. { // restart the entire server
  181. engine->ServerCommand("reload\n");
  182. }
  183. }
  184. void GameStartFrame( void )
  185. {
  186. VPROF( "GameStartFrame" );
  187. if ( g_fGameOver )
  188. return;
  189. gpGlobals->teamplay = teamplay.GetInt() ? true : false;
  190. extern void Bot_RunAll();
  191. Bot_RunAll();
  192. }
  193. //=========================================================
  194. // instantiate the proper game rules object
  195. //=========================================================
  196. void InstallGameRules()
  197. {
  198. CreateGameRulesObject( "CDODGameRules" );
  199. }