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.

256 lines
8.2 KiB

  1. /***
  2. *
  3. //========= Copyright Valve Corporation, All rights reserved. ============//
  4. *
  5. * This product contains software technology licensed from Id
  6. * Software, Inc. ("Id Technology"). Id Technology (c) 1996 Id Software, Inc.
  7. * All Rights Reserved.
  8. *
  9. * Use, distribution, and modification of this source code and/or resulting
  10. * object code is restricted to non-commercial enhancements to products from
  11. * Valve LLC. All other use, distribution, or modification is prohibited
  12. * without written permission from Valve LLC.
  13. *
  14. ****/
  15. /*
  16. ===== tf_client.cpp ========================================================
  17. HL2 client/server game specific stuff
  18. */
  19. #include "cbase.h"
  20. #include "player.h"
  21. #include "gamerules.h"
  22. #include "entitylist.h"
  23. #include "physics.h"
  24. #include "game.h"
  25. #include "ai_network.h"
  26. #include "ai_node.h"
  27. #include "ai_hull.h"
  28. #include "shake.h"
  29. #include "player_resource.h"
  30. #include "engine/IEngineSound.h"
  31. #include "tf_player.h"
  32. #include "tf_gamerules.h"
  33. #include "tier0/vprof.h"
  34. #include "tf_bot_temp.h"
  35. #include "filesystem.h"
  36. // memdbgon must be the last include file in a .cpp file!!!
  37. #include "tier0/memdbgon.h"
  38. extern CBaseEntity *FindPickerEntity( CBasePlayer *pPlayer );
  39. extern bool g_fGameOver;
  40. void FinishClientPutInServer( CTFPlayer *pPlayer )
  41. {
  42. {
  43. bool save = engine->LockNetworkStringTables( false );
  44. pPlayer->InitialSpawn();
  45. pPlayer->Spawn();
  46. engine->LockNetworkStringTables( save );
  47. }
  48. char sName[128];
  49. Q_strncpy( sName, pPlayer->GetPlayerName(), sizeof( sName ) );
  50. // First parse the name and remove any %'s
  51. for ( char *pApersand = sName; pApersand != NULL && *pApersand != 0; pApersand++ )
  52. {
  53. // Replace it with a space
  54. if ( *pApersand == '%' )
  55. *pApersand = ' ';
  56. }
  57. // notify other clients of player joining the game
  58. if ( !pPlayer->IsFakeClient() )
  59. {
  60. UTIL_ClientPrintAll( HUD_PRINTNOTIFY, "#Game_connected", sName[0] != 0 ? sName : "<unconnected>" );
  61. }
  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. CTFPlayer *pPlayer = CTFPlayer::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. CTFPlayer *pPlayer = ToTFPlayer( 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 "Team Fortress";
  94. }
  95. //-----------------------------------------------------------------------------
  96. // Purpose: Precache game-specific models & sounds
  97. //-----------------------------------------------------------------------------
  98. void ClientGamePrecache( void )
  99. {
  100. const char *pFilename = "scripts/client_precache.txt";
  101. KeyValues *pValues = new KeyValues( "ClientPrecache" );
  102. if ( !pValues->LoadFromFile( filesystem, pFilename, "GAME" ) )
  103. {
  104. Error( "Can't open %s for client precache info.", pFilename );
  105. pValues->deleteThis();
  106. return;
  107. }
  108. for ( KeyValues *pData = pValues->GetFirstSubKey(); pData != NULL; pData = pData->GetNextKey() )
  109. {
  110. const char *pszType = pData->GetName();
  111. const char *pszFile = pData->GetString();
  112. if ( Q_strlen( pszType ) > 0 &&
  113. Q_strlen( pszFile ) > 0 )
  114. {
  115. if ( !Q_stricmp( pData->GetName(), "model" ) )
  116. {
  117. CBaseEntity::PrecacheModel( pszFile );
  118. }
  119. else if ( !Q_stricmp( pData->GetName(), "scriptsound" ) )
  120. {
  121. CBaseEntity::PrecacheScriptSound( pszFile );
  122. }
  123. }
  124. }
  125. pValues->deleteThis();
  126. // @FD This has been moved into pure_server_consistency.txt
  127. //
  128. // // particles
  129. //// engine->ForceExactFile( "particles/blood_impact.pcf" ); // Don't force consistency on this because of the LV version.
  130. //// engine->ForceExactFile( "particles/blood_impact_dx80.pcf" ); // Don't force consistency on this because of the LV version.
  131. //// engine->ForceExactFile( "particles/blood_trail.pcf" ); // Don't force consistency on this because of the LV version.
  132. //// engine->ForceExactFile( "particles/blood_trail_dx80.pcf" ); // Don't force consistency on this because of the LV version.
  133. //// engine->ForceExactFile( "particles/buildingdamage.pcf" );
  134. // engine->ForceExactFile( "particles/bullet_tracers.pcf" );
  135. // engine->ForceExactFile( "particles/burningplayer.pcf" );
  136. // engine->ForceExactFile( "particles/burningplayer_dx80.pcf" );
  137. // engine->ForceExactFile( "particles/cig_smoke.pcf" );
  138. // engine->ForceExactFile( "particles/cig_smoke_dx80.pcf" );
  139. //// engine->ForceExactFile( "particles/cinefx.pcf" );
  140. //// engine->ForceExactFile( "particles/crit.pcf" );
  141. //// engine->ForceExactFile( "particles/default.pcf" );
  142. // engine->ForceExactFile( "particles/disguise.pcf" );
  143. //// engine->ForceExactFile( "particles/explosion.pcf" );
  144. //// engine->ForceExactFile( "particles/explosion_dx80.pcf" );
  145. //// engine->ForceExactFile( "particles/explosion_dx90_slow.pcf" );
  146. //// engine->ForceExactFile( "particles/explosion_high.pcf" );
  147. // engine->ForceExactFile( "particles/flag_particles.pcf" );
  148. //// engine->ForceExactFile( "particles/flamethrower.pcf" );
  149. //// engine->ForceExactFile( "particles/flamethrowerTest.pcf" );
  150. //// engine->ForceExactFile( "particles/flamethrower_dx80.pcf" );
  151. //// engine->ForceExactFile( "particles/flamethrower_dx90_slow.pcf" );
  152. //// engine->ForceExactFile( "particles/flamethrower_high.pcf" );
  153. //// engine->ForceExactFile( "particles/impact_fx.pcf" );
  154. //// engine->ForceExactFile( "particles/item_fx.pcf" );
  155. //// engine->ForceExactFile( "particles/medicgun_attrib.pcf" );
  156. //// engine->ForceExactFile( "particles/medicgun_beam.pcf" );
  157. //// engine->ForceExactFile( "particles/medicgun_beam_dx80.pcf" );
  158. //// engine->ForceExactFile( "particles/muzzle_flash.pcf" );
  159. //// engine->ForceExactFile( "particles/muzzle_flash_dx80.pcf" );
  160. //// engine->ForceExactFile( "particles/nailtrails.pcf" );
  161. // engine->ForceExactFile( "particles/nemesis.pcf" );
  162. // engine->ForceExactFile( "particles/player_recent_teleport.pcf" );
  163. // engine->ForceExactFile( "particles/player_recent_teleport_dx80.pcf" );
  164. //// engine->ForceExactFile( "particles/rocketbackblast.pcf" );
  165. //// engine->ForceExactFile( "particles/rocketjumptrail.pcf" );
  166. //// engine->ForceExactFile( "particles/rockettrail.pcf" );
  167. //// engine->ForceExactFile( "particles/rockettrail_dx80.pcf" );
  168. //// engine->ForceExactFile( "particles/rockettrail_dx90_slow.pcf" );
  169. //// engine->ForceExactFile( "particles/shellejection.pcf" );
  170. //// engine->ForceExactFile( "particles/shellejection_dx80.pcf" );
  171. //// engine->ForceExactFile( "particles/shellejection_high.pcf" );
  172. //// engine->ForceExactFile( "particles/smoke_blackbillow.pcf" );
  173. //// engine->ForceExactFile( "particles/smoke_blackbillow_dx80.pcf" );
  174. //// engine->ForceExactFile( "particles/sparks.pcf" );
  175. // engine->ForceExactFile( "particles/speechbubbles.pcf" );
  176. //// engine->ForceExactFile( "particles/stickybomb.pcf" );
  177. //// engine->ForceExactFile( "particles/stickybomb_dx80.pcf" );
  178. // engine->ForceExactFile( "particles/teleported_fx.pcf" );
  179. // engine->ForceExactFile( "particles/teleport_status.pcf" );
  180. // engine->ForceExactFile( "particles/water.pcf" );
  181. // engine->ForceExactFile( "particles/water_dx80.pcf" );
  182. }
  183. // called by ClientKill and DeadThink
  184. void respawn( CBaseEntity *pEdict, bool fCopyCorpse )
  185. {
  186. if (gpGlobals->coop || gpGlobals->deathmatch)
  187. {
  188. if ( fCopyCorpse )
  189. {
  190. // make a copy of the dead body for appearances sake
  191. dynamic_cast< CBasePlayer* >( pEdict )->CreateCorpse();
  192. }
  193. // respawn player
  194. pEdict->Spawn();
  195. }
  196. else
  197. { // restart the entire server
  198. engine->ServerCommand("reload\n");
  199. }
  200. }
  201. void GameStartFrame( void )
  202. {
  203. VPROF( "GameStartFrame" );
  204. if ( g_pGameRules )
  205. g_pGameRules->Think();
  206. if ( g_fGameOver )
  207. return;
  208. gpGlobals->teamplay = teamplay.GetInt() ? true : false;
  209. Bot_RunAll();
  210. }
  211. //=========================================================
  212. // instantiate the proper game rules object
  213. //=========================================================
  214. void InstallGameRules()
  215. {
  216. CreateGameRulesObject( "CTFGameRules" );
  217. }