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.

199 lines
4.9 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //=============================================================================//
  8. /*
  9. ===== tf_client.cpp ========================================================
  10. HL1 client/server game specific stuff
  11. */
  12. #include "cbase.h"
  13. #include "hl1_player.h"
  14. #include "hl1mp_player.h"
  15. #include "hl1_gamerules.h"
  16. #include "gamerules.h"
  17. #include "teamplay_gamerules.h"
  18. #include "entitylist.h"
  19. #include "physics.h"
  20. #include "game.h"
  21. #include "player_resource.h"
  22. #include "engine/IEngineSound.h"
  23. #include "tier0/vprof.h"
  24. void Host_Say( edict_t *pEdict, bool teamonly );
  25. extern CBaseEntity* FindPickerEntityClass( CBasePlayer *pPlayer, char *classname );
  26. extern bool g_fGameOver;
  27. /*
  28. ===========
  29. ClientPutInServer
  30. called each time a player is spawned into the game
  31. ============
  32. */
  33. void ClientPutInServer( edict_t *pEdict, const char *playername )
  34. {
  35. CHL1_Player *pPlayer = NULL;
  36. // Allocate a CBasePlayer for pev, and call spawn
  37. if ( g_pGameRules->IsMultiplayer() )
  38. pPlayer = CHL1_Player::CreatePlayer( "player_mp", pEdict );
  39. else
  40. pPlayer = CHL1_Player::CreatePlayer( "player", pEdict );
  41. pPlayer->SetPlayerName( playername );
  42. }
  43. void ClientActive( edict_t *pEdict, bool bLoadGame )
  44. {
  45. CHL1_Player *pPlayer = dynamic_cast< CHL1_Player* >( CBaseEntity::Instance( pEdict ) );
  46. pPlayer->InitialSpawn();
  47. if ( !bLoadGame )
  48. {
  49. pPlayer->Spawn();
  50. }
  51. }
  52. /*
  53. ===============
  54. const char *GetGameDescription()
  55. Returns the descriptive name of this .dll. E.g., Half-Life, or Team Fortress 2
  56. ===============
  57. */
  58. const char *GetGameDescription()
  59. {
  60. if ( g_pGameRules ) // this function may be called before the world has spawned, and the game rules initialized
  61. return g_pGameRules->GetGameDescription();
  62. else
  63. return "Half-Life 1";
  64. }
  65. //-----------------------------------------------------------------------------
  66. // Purpose: Given a player and optional name returns the entity of that
  67. // classname that the player is nearest facing
  68. //
  69. // Input :
  70. // Output :
  71. //-----------------------------------------------------------------------------
  72. CBaseEntity* FindEntity( edict_t *pEdict, char *classname)
  73. {
  74. // If no name was given set bits based on the picked
  75. if (FStrEq(classname,""))
  76. {
  77. return (FindPickerEntityClass( static_cast<CBasePlayer*>(GetContainingEntity(pEdict)), classname ));
  78. }
  79. return NULL;
  80. }
  81. //-----------------------------------------------------------------------------
  82. // Purpose: Precache game-specific models & sounds
  83. //-----------------------------------------------------------------------------
  84. void ClientGamePrecache( void )
  85. {
  86. // Multiplayer uses different models, and more of them.
  87. if ( g_pGameRules->IsMultiplayer() )
  88. {
  89. CBaseEntity::PrecacheModel("models/player/mp/barney/barney.mdl");
  90. CBaseEntity::PrecacheModel("models/player/mp/gina/gina.mdl");
  91. CBaseEntity::PrecacheModel("models/player/mp/gman/gman.mdl");
  92. CBaseEntity::PrecacheModel("models/player/mp/gordon/gordon.mdl");
  93. CBaseEntity::PrecacheModel("models/player/mp/helmet/helmet.mdl");
  94. CBaseEntity::PrecacheModel("models/player/mp/hgrunt/hgrunt.mdl");
  95. CBaseEntity::PrecacheModel("models/player/mp/robo/robo.mdl");
  96. CBaseEntity::PrecacheModel("models/player/mp/scientist/scientist.mdl");
  97. CBaseEntity::PrecacheModel("models/player/mp/zombie/zombie.mdl");
  98. CBaseEntity::PrecacheModel("models/player.mdl" );
  99. }
  100. else
  101. {
  102. CBaseEntity::PrecacheModel("models/player.mdl" );
  103. }
  104. CBaseEntity::PrecacheModel( "models/gibs/agibs.mdl" );
  105. CBaseEntity::PrecacheScriptSound( "Player.UseDeny" );
  106. }
  107. // called by ClientKill and DeadThink
  108. void respawn( CBaseEntity *pEdict, bool fCopyCorpse )
  109. {
  110. if (gpGlobals->coop || gpGlobals->deathmatch)
  111. {
  112. if ( fCopyCorpse )
  113. {
  114. // make a copy of the dead body for appearances sake
  115. ((CHL1MP_Player *)pEdict)->CreateCorpse();
  116. }
  117. // respawn player
  118. pEdict->Spawn();
  119. }
  120. else
  121. { // restart the entire server
  122. engine->ServerCommand("reload\n");
  123. }
  124. }
  125. void GameStartFrame( void )
  126. {
  127. VPROF("GameStartFrame()");
  128. if ( g_fGameOver )
  129. return;
  130. gpGlobals->teamplay = (teamplay.GetInt() != 0);
  131. #ifdef DEBUG
  132. extern void Bot_RunAll();
  133. Bot_RunAll();
  134. #endif
  135. }
  136. //=========================================================
  137. // instantiate the proper game rules object
  138. //=========================================================
  139. void InstallGameRules()
  140. {
  141. engine->ServerCommand( "exec game.cfg\n" );
  142. engine->ServerExecute( );
  143. if ( !gpGlobals->deathmatch )
  144. {
  145. // generic half-life
  146. CreateGameRulesObject( "CHalfLife1" );
  147. return;
  148. }
  149. else
  150. {
  151. CreateGameRulesObject( "CHL1MPRules" );
  152. return;
  153. if ( teamplay.GetInt() > 0 )
  154. {
  155. // teamplay
  156. CreateGameRulesObject( "CTeamplayRules" );
  157. return;
  158. }
  159. // vanilla deathmatch
  160. CreateGameRulesObject( "CMultiplayRules" );
  161. return;
  162. }
  163. CreateGameRulesObject( "CHalfLife1" );
  164. }