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.

176 lines
4.4 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //=============================================================================//
  8. /*
  9. ===== portal_client.cpp ========================================================
  10. Portal client/server game specific stuff
  11. */
  12. #include "cbase.h"
  13. #include "portal_player.h"
  14. #include "portal_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. CPortal_Player *pPlayer = CPortal_Player::CreatePlayer( "player", pEdict );
  38. pPlayer->PlayerData()->netname = AllocPooledString( playername );
  39. }
  40. void ClientActive( edict_t *pEdict, bool bLoadGame )
  41. {
  42. CPortal_Player *pPlayer = dynamic_cast< CPortal_Player* >( CBaseEntity::Instance( pEdict ) );
  43. Assert( pPlayer );
  44. pPlayer->InitialSpawn();
  45. if ( !bLoadGame )
  46. {
  47. pPlayer->Spawn();
  48. }
  49. }
  50. /*
  51. ===============
  52. const char *GetGameDescription()
  53. Returns the descriptive name of this .dll. E.g., Half-Life, or Team Fortress 2
  54. ===============
  55. */
  56. const char *GetGameDescription()
  57. {
  58. if ( g_pGameRules ) // this function may be called before the world has spawned, and the game rules initialized
  59. return g_pGameRules->GetGameDescription();
  60. else
  61. return "Half-Life 2";
  62. }
  63. //-----------------------------------------------------------------------------
  64. // Purpose: Given a player and optional name returns the entity of that
  65. // classname that the player is nearest facing
  66. //
  67. // Input :
  68. // Output :
  69. //-----------------------------------------------------------------------------
  70. CBaseEntity* FindEntity( edict_t *pEdict, char *classname)
  71. {
  72. // If no name was given set bits based on the picked
  73. if (FStrEq(classname,""))
  74. {
  75. return (FindPickerEntityClass( static_cast<CBasePlayer*>(GetContainingEntity(pEdict)), classname ));
  76. }
  77. return NULL;
  78. }
  79. //-----------------------------------------------------------------------------
  80. // Purpose: Precache game-specific models & sounds
  81. //-----------------------------------------------------------------------------
  82. void ClientGamePrecache( void )
  83. {
  84. CBaseEntity::PrecacheModel("models/player.mdl");
  85. CBaseEntity::PrecacheModel( "models/gibs/agibs.mdl" );
  86. CBaseEntity::PrecacheModel("models/weapons/v_hands.mdl");
  87. CBaseEntity::PrecacheScriptSound( "HUDQuickInfo.LowAmmo" );
  88. CBaseEntity::PrecacheScriptSound( "HUDQuickInfo.LowHealth" );
  89. CBaseEntity::PrecacheScriptSound( "Missile.ShotDown" );
  90. CBaseEntity::PrecacheScriptSound( "Bullets.DefaultNearmiss" );
  91. CBaseEntity::PrecacheScriptSound( "Bullets.GunshipNearmiss" );
  92. CBaseEntity::PrecacheScriptSound( "Bullets.StriderNearmiss" );
  93. CBaseEntity::PrecacheScriptSound( "Geiger.BeepHigh" );
  94. CBaseEntity::PrecacheScriptSound( "Geiger.BeepLow" );
  95. CBaseEntity::PrecacheModel( "models/portals/portal1.mdl" );
  96. CBaseEntity::PrecacheModel( "models/portals/portal2.mdl" );
  97. }
  98. // called by ClientKill and DeadThink
  99. void respawn( CBaseEntity *pEdict, bool fCopyCorpse )
  100. {
  101. if (gpGlobals->coop || gpGlobals->deathmatch)
  102. {
  103. if ( fCopyCorpse )
  104. {
  105. // make a copy of the dead body for appearances sake
  106. ((CPortal_Player *)pEdict)->CreateCorpse();
  107. }
  108. // respawn player
  109. pEdict->Spawn();
  110. }
  111. else
  112. { // restart the entire server
  113. engine->ServerCommand("reload\n");
  114. }
  115. }
  116. void GameStartFrame( void )
  117. {
  118. VPROF("GameStartFrame()");
  119. if ( g_fGameOver )
  120. return;
  121. gpGlobals->teamplay = (teamplay.GetInt() != 0);
  122. }
  123. //=========================================================
  124. // instantiate the proper game rules object
  125. //=========================================================
  126. void InstallGameRules()
  127. {
  128. if ( !gpGlobals->deathmatch )
  129. {
  130. CreateGameRulesObject( "CPortalGameRules" );
  131. return;
  132. }
  133. else
  134. {
  135. if ( teamplay.GetInt() > 0 )
  136. {
  137. // teamplay
  138. CreateGameRulesObject( "CTeamplayRules" );
  139. }
  140. else
  141. {
  142. // vanilla deathmatch
  143. CreateGameRulesObject( "CMultiplayRules" );
  144. }
  145. }
  146. }