summaryrefslogtreecommitdiff
path: root/game/server/tf2/info_input_respawnplayers.cpp
diff options
context:
space:
mode:
authorFluorescentCIAAfricanAmerican <[email protected]>2020-04-22 12:56:21 -0400
committerFluorescentCIAAfricanAmerican <[email protected]>2020-04-22 12:56:21 -0400
commit3bf9df6b2785fa6d951086978a3e66f49427166a (patch)
tree2c0f1f0c63c4832882bc93814ebd2c2b1c6224e5 /game/server/tf2/info_input_respawnplayers.cpp
downloadarchived-source-engine-2018-hl2-src-master.tar.xz
archived-source-engine-2018-hl2-src-master.zip
Diffstat (limited to 'game/server/tf2/info_input_respawnplayers.cpp')
-rw-r--r--game/server/tf2/info_input_respawnplayers.cpp121
1 files changed, 121 insertions, 0 deletions
diff --git a/game/server/tf2/info_input_respawnplayers.cpp b/game/server/tf2/info_input_respawnplayers.cpp
new file mode 100644
index 0000000..4b9917f
--- /dev/null
+++ b/game/server/tf2/info_input_respawnplayers.cpp
@@ -0,0 +1,121 @@
+//========= Copyright Valve Corporation, All rights reserved. ============//
+//
+// Purpose:
+//
+// $NoKeywords: $
+//=============================================================================//
+#include "cbase.h"
+#include "EntityOutput.h"
+#include "EntityList.h"
+#include "tf_team.h"
+#include "baseentity.h"
+
+// Spawnflags
+const int SF_RESPAWNPLAYERS_RESETALL = 0x01; // Respawned players have their inventory completely reset
+const int SF_RESPAWNPLAYERS_RESETAMMO = 0x02; // Respawned players have their ammo counts reset
+
+//-----------------------------------------------------------------------------
+// Purpose: Map entity that respawns players
+//-----------------------------------------------------------------------------
+class CInfoInputRespawnPlayers : public CBaseEntity
+{
+ DECLARE_CLASS( CInfoInputRespawnPlayers, CBaseEntity );
+public:
+ DECLARE_DATADESC();
+
+ // Inputs
+ void InputRespawnAll( inputdata_t &inputdata );
+ void InputRespawnTeam1( inputdata_t &inputdata );
+ void InputRespawnTeam2( inputdata_t &inputdata );
+ void InputRespawnPlayer( inputdata_t &inputdata );
+
+ // Respawning
+ void RespawnPlayer( CBaseTFPlayer *pPlayer );
+ void RespawnTeam( CTFTeam *pTeam );
+};
+
+BEGIN_DATADESC( CInfoInputRespawnPlayers )
+
+ // inputs
+ DEFINE_INPUTFUNC( FIELD_VOID, "RespawnAll", InputRespawnAll ),
+ DEFINE_INPUTFUNC( FIELD_VOID, "RespawnTeam1", InputRespawnTeam1 ),
+ DEFINE_INPUTFUNC( FIELD_VOID, "RespawnTeam2", InputRespawnTeam2 ),
+ DEFINE_INPUTFUNC( FIELD_EHANDLE, "RespawnPlayer", InputRespawnPlayer ),
+
+END_DATADESC()
+
+LINK_ENTITY_TO_CLASS( info_input_respawnplayers, CInfoInputRespawnPlayers );
+
+//-----------------------------------------------------------------------------
+// Purpose: Respawn all the players
+//-----------------------------------------------------------------------------
+void CInfoInputRespawnPlayers::InputRespawnAll( inputdata_t &inputdata )
+{
+ for ( int i = 0; i < MAX_TF_TEAMS; i++ )
+ {
+ RespawnTeam( GetGlobalTFTeam(i+1) );
+ }
+}
+
+//-----------------------------------------------------------------------------
+// Purpose: Respawn all of team 1's players
+//-----------------------------------------------------------------------------
+void CInfoInputRespawnPlayers::InputRespawnTeam1( inputdata_t &inputdata )
+{
+ RespawnTeam( GetGlobalTFTeam(1) );
+}
+
+//-----------------------------------------------------------------------------
+// Purpose: Respawn all of team 2's players
+//-----------------------------------------------------------------------------
+void CInfoInputRespawnPlayers::InputRespawnTeam2( inputdata_t &inputdata )
+{
+ RespawnTeam( GetGlobalTFTeam(2) );
+}
+
+//-----------------------------------------------------------------------------
+// Purpose: Respawn a specific player
+//-----------------------------------------------------------------------------
+void CInfoInputRespawnPlayers::InputRespawnPlayer( inputdata_t &inputdata )
+{
+ CBaseEntity *pEntity = (inputdata.value.Entity()).Get();
+ if ( pEntity && pEntity->IsPlayer() )
+ {
+ CBaseTFPlayer *pPlayer = (CBaseTFPlayer *)pEntity;
+ RespawnPlayer( pPlayer );
+ }
+}
+
+//-----------------------------------------------------------------------------
+// Purpose: Respawn the team
+//-----------------------------------------------------------------------------
+void CInfoInputRespawnPlayers::RespawnTeam( CTFTeam *pTeam )
+{
+ Assert( pTeam );
+ if ( !pTeam )
+ return;
+
+ // Respawn all the players
+ for ( int i = 0; i < pTeam->GetNumPlayers(); i++ )
+ {
+ RespawnPlayer( (CBaseTFPlayer*)pTeam->GetPlayer(i) );
+ }
+}
+
+//-----------------------------------------------------------------------------
+// Purpose: Respawn the player
+//-----------------------------------------------------------------------------
+void CInfoInputRespawnPlayers::RespawnPlayer( CBaseTFPlayer *pPlayer )
+{
+ // Reset ammo if the spawnflag's set
+ if ( HasSpawnFlags( SF_RESPAWNPLAYERS_RESETALL ) )
+ {
+ pPlayer->ResupplyAmmo( 1.0, RESUPPLY_ALL_FROM_STATION );
+ }
+ else if ( HasSpawnFlags( SF_RESPAWNPLAYERS_RESETAMMO ) )
+ {
+ pPlayer->ResupplyAmmo( 1.0, RESUPPLY_RESPAWN );
+ }
+
+ pPlayer->ForceRespawn();
+} \ No newline at end of file