upload "kind" alien swarm

This commit is contained in:
nillerusr
2023-10-03 17:23:56 +03:00
parent b7bd94c52e
commit 7d3c0d8b5a
4229 changed files with 462900 additions and 495155 deletions
+72 -147
View File
@@ -1,11 +1,10 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//===== Copyright © 1996-2005, Valve Corporation, All rights reserved. ======//
//
// Purpose:
//
//===========================================================================//
#include "cbase.h"
#include "team_train_watcher.h"
#include "trigger_area_capture.h"
#include "player.h"
#include "teamplay_gamerules.h"
@@ -14,16 +13,18 @@
#include "team_control_point_master.h"
#include "teamplayroundbased_gamerules.h"
// NOTE: This has to be the last file included!
#include "tier0/memdbgon.h"
extern ConVar mp_capstyle;
extern ConVar mp_blockstyle;
extern ConVar mp_capdeteriorate_time;
IMPLEMENT_AUTO_LIST( ITriggerAreaCaptureAutoList );
BEGIN_DATADESC(CTriggerAreaCapture)
// Touch functions
DEFINE_FUNCTION( CTriggerAreaCaptureShim::Touch ),
DEFINE_FUNCTION( AreaTouch ),
// Think functions
DEFINE_THINKFUNC( CaptureThink ),
@@ -43,6 +44,7 @@ BEGIN_DATADESC(CTriggerAreaCapture)
// DEFINE_FIELD( m_TeamData, CUtlVector < perteamdata_t > ),
// DEFINE_FIELD( m_Blockers, CUtlVector < blockers_t > ),
// DEFINE_FIELD( m_bActive, FIELD_BOOLEAN ),
// DEFINE_FIELD( m_iAreaIndex, FIELD_INTEGER ),
// DEFINE_FIELD( m_hPoint, CHandle < CTeamControlPoint > ),
// DEFINE_FIELD( m_bRequiresObject, FIELD_BOOLEAN ),
// DEFINE_FIELD( m_iCapAttemptNumber, FIELD_INTEGER ),
@@ -66,7 +68,6 @@ BEGIN_DATADESC(CTriggerAreaCapture)
DEFINE_OUTPUT( m_CapOutput, "OnEndCap" ),
DEFINE_OUTPUT( m_OnNumCappersChanged, "OnNumCappersChanged" ),
DEFINE_OUTPUT( m_OnNumCappersChanged2, "OnNumCappersChanged2" ),
END_DATADESC();
@@ -78,8 +79,6 @@ LINK_ENTITY_TO_CLASS( trigger_capture_area, CTriggerAreaCapture );
CTriggerAreaCapture::CTriggerAreaCapture()
{
m_TeamData.SetSize( GetNumberOfTeams() );
m_bStartTouch = false;
m_hTrainWatcher = NULL;
}
//-----------------------------------------------------------------------------
@@ -95,7 +94,9 @@ void CTriggerAreaCapture::Spawn( void )
Precache();
SetTouch ( &CTriggerAreaCaptureShim::Touch );
m_iAreaIndex = -1;
SetTouch ( &CTriggerAreaCapture::AreaTouch );
SetThink( &CTriggerAreaCapture::CaptureThink );
SetNextThink( gpGlobals->curtime + AREA_THINK_TIME );
@@ -105,11 +106,6 @@ void CTriggerAreaCapture::Spawn( void )
{
m_TeamData[i].iNumRequiredToCap = 1;
}
if ( m_TeamData[i].iNumRequiredToStartCap < 1 )
{
m_TeamData[i].iNumRequiredToStartCap = 1;
}
}
}
@@ -139,13 +135,6 @@ bool CTriggerAreaCapture::KeyValue( const char *szKeyName, const char *szValue )
m_TeamData[iTeam].iSpawnAdjust = atoi(szValue);
}
else if ( !Q_strncmp( szKeyName, "team_startcap_", 14 ) )
{
int iTeam = atoi(szKeyName+14);
Assert( iTeam >= 0 && iTeam < m_TeamData.Count() );
m_TeamData[iTeam].iNumRequiredToStartCap = atoi(szValue);
}
else
{
return BaseClass::KeyValue( szKeyName, szValue );
@@ -161,6 +150,14 @@ void CTriggerAreaCapture::Precache( void )
{
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CTriggerAreaCapture::SetAreaIndex( int index )
{
m_iAreaIndex = index;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
@@ -178,8 +175,6 @@ void CTriggerAreaCapture::StartTouch(CBaseEntity *pOther)
if ( PassesTriggerFilters(pOther) && m_hPoint )
{
m_nOwningTeam = m_hPoint->GetOwner();
IGameEvent *event = gameeventmanager->CreateEvent( "controlpoint_starttouch" );
if ( event )
{
@@ -191,9 +186,7 @@ void CTriggerAreaCapture::StartTouch(CBaseEntity *pOther)
// Call capture think immediately to make it update our area's player counts.
// If we don't do this, the player can receive the above event telling him he's
// in a zone, but the objective resource still thinks he's not.
m_bStartTouch = true;
CaptureThink();
m_bStartTouch = false;
if ( m_bCapturing )
{
@@ -205,7 +198,7 @@ void CTriggerAreaCapture::StartTouch(CBaseEntity *pOther)
if ( flRate > 0.0f )
{
CBaseMultiplayerPlayer *pPlayer = ToBaseMultiplayerPlayer(pOther);
if ( pPlayer && pPlayer->GetTeamNumber() == m_nCapturingTeam )
if ( pPlayer )
{
pPlayer->StartScoringEscortPoints( flRate );
}
@@ -220,7 +213,7 @@ void CTriggerAreaCapture::StartTouch(CBaseEntity *pOther)
//-----------------------------------------------------------------------------
void CTriggerAreaCapture::EndTouch(CBaseEntity *pOther)
{
if ( IsTouching( pOther ) && m_hPoint )
if ( PassesTriggerFilters(pOther) && m_hPoint )
{
IGameEvent *event = gameeventmanager->CreateEvent( "controlpoint_endtouch" );
if ( event )
@@ -241,14 +234,6 @@ void CTriggerAreaCapture::EndTouch(CBaseEntity *pOther)
BaseClass::EndTouch( pOther );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
bool CTriggerAreaCapture::CaptureModeScalesWithPlayers() const
{
return mp_capstyle.GetBool();
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
@@ -263,6 +248,8 @@ void CTriggerAreaCapture::AreaTouch( CBaseEntity *pOther )
if ( !TeamplayGameRules()->PointsMayBeCaptured() )
return;
Assert( m_iAreaIndex != -1 );
// dont touch for non-alive or non-players
if( !pOther->IsPlayer() || !pOther->IsAlive() )
return;
@@ -271,7 +258,7 @@ void CTriggerAreaCapture::AreaTouch( CBaseEntity *pOther )
CTeamControlPointMaster *pMaster = g_hControlPointMasters.Count() ? g_hControlPointMasters[0] : NULL;
if ( pMaster && m_hPoint )
{
if ( !pMaster->IsInRound( m_hPoint ) )
if ( !pMaster->PointCanBeCapped( m_hPoint ) )
{
return;
}
@@ -309,7 +296,7 @@ void CTriggerAreaCapture::CaptureThink( void )
CTeamControlPointMaster *pMaster = g_hControlPointMasters.Count() ? g_hControlPointMasters[0] : NULL;
if ( pMaster && m_hPoint )
{
if ( !pMaster->IsInRound( m_hPoint ) )
if ( !pMaster->PointCanBeCapped( m_hPoint ) )
{
return;
}
@@ -339,46 +326,43 @@ void CTriggerAreaCapture::CaptureThink( void )
pFirstPlayerTouching[i] = NULL;
}
if ( m_hPoint )
// Loop through the entities we're touching, and find players
for ( int i = 0; i < m_hTouchingEntities.Count(); i++ )
{
// Loop through the entities we're touching, and find players
for ( int i = 0; i < m_hTouchingEntities.Count(); i++ )
CBaseEntity *ent = m_hTouchingEntities[i];
if ( ent && ent->IsPlayer() )
{
CBaseEntity *ent = m_hTouchingEntities[i];
if ( ent && ent->IsPlayer() )
{
CBaseMultiplayerPlayer *pPlayer = ToBaseMultiplayerPlayer(ent);
if ( pPlayer->IsAlive() )
{
int iTeam = pPlayer->GetTeamNumber();
CBaseMultiplayerPlayer *pPlayer = ToBaseMultiplayerPlayer(ent);
if ( pPlayer->IsAlive() )
{
int iTeam = pPlayer->GetTeamNumber();
// If a team's not allowed to cap a point, don't count players in it at all
if ( !TeamplayGameRules()->TeamMayCapturePoint( iTeam, m_hPoint->GetPointIndex() ) )
continue;
// If a team's not allowed to cap a point, don't count players in it at all
if ( !TeamplayGameRules()->TeamMayCapturePoint( iTeam, m_hPoint->GetPointIndex() ) )
continue;
if ( !TeamplayGameRules()->PlayerMayCapturePoint( pPlayer, m_hPoint->GetPointIndex() ) )
{
if ( TeamplayGameRules()->PlayerMayBlockPoint( pPlayer, m_hPoint->GetPointIndex() ) )
{
if ( iNumPlayers[iTeam] == 0 && iNumBlockablePlayers[iTeam] == 0 )
{
pFirstPlayerTouching[iTeam] = pPlayer;
}
iNumBlockablePlayers[iTeam] += TeamplayGameRules()->GetCaptureValueForPlayer( pPlayer );
}
continue;
}
if ( iTeam >= FIRST_GAME_TEAM )
if ( !TeamplayGameRules()->PlayerMayCapturePoint( pPlayer, m_hPoint->GetPointIndex() ) )
{
if ( TeamplayGameRules()->PlayerMayBlockPoint( pPlayer, m_hPoint->GetPointIndex() ) )
{
if ( iNumPlayers[iTeam] == 0 && iNumBlockablePlayers[iTeam] == 0 )
{
pFirstPlayerTouching[iTeam] = pPlayer;
}
iNumPlayers[iTeam] += TeamplayGameRules()->GetCaptureValueForPlayer( pPlayer );
iNumBlockablePlayers[iTeam] += TeamplayGameRules()->GetCaptureValueForPlayer( pPlayer );
}
continue;
}
if ( iTeam >= FIRST_GAME_TEAM )
{
if ( iNumPlayers[iTeam] == 0 && iNumBlockablePlayers[iTeam] == 0 )
{
pFirstPlayerTouching[iTeam] = pPlayer;
}
iNumPlayers[iTeam] += TeamplayGameRules()->GetCaptureValueForPlayer( pPlayer );
}
}
}
@@ -426,16 +410,12 @@ void CTriggerAreaCapture::CaptureThink( void )
UpdateTeamInZone();
bool bBlocked = false;
// If the cap is being blocked, reset the number of players so the client
// knows to stop the capture as well.
if ( mp_blockstyle.GetInt() == 1 )
{
if ( m_bCapturing && iTeamsInZone > 1 )
{
bBlocked = true;
for ( int i = FIRST_GAME_TEAM; i < GetNumberOfTeams(); i++ )
{
iNumPlayers[i] = 0;
@@ -450,7 +430,7 @@ void CTriggerAreaCapture::CaptureThink( void )
if ( bUpdatePlayers )
{
UpdateNumPlayers( bBlocked );
UpdateNumPlayers();
}
// When a player blocks, tell them the cap index and attempt number
@@ -464,9 +444,8 @@ void CTriggerAreaCapture::CaptureThink( void )
// Calculate the amount of modification to the cap time
float flTimeDelta = gpGlobals->curtime - m_flLastReductionTime;
float flReduction = flTimeDelta;
if ( CaptureModeScalesWithPlayers() )
if ( mp_capstyle.GetInt() == 1 )
{
// Diminishing returns for successive players.
for ( int i = 1; i < m_TeamData[m_nTeamInZone].iNumTouching; i++ )
@@ -487,12 +466,12 @@ void CTriggerAreaCapture::CaptureThink( void )
// See if anyone gets credit for the block
float flPercentToGo = m_fTimeRemaining / m_flCapTime;
if ( CaptureModeScalesWithPlayers() )
if ( mp_capstyle.GetInt() == 1 )
{
flPercentToGo = m_fTimeRemaining / ((m_flCapTime * 2) * m_TeamData[m_nCapturingTeam].iNumRequiredToCap);
}
if ( ( flPercentToGo <= 0.5 || TeamplayGameRules()->PointsMayAlwaysBeBlocked() ) && m_hPoint )
if ( flPercentToGo <= 0.5 && m_hPoint )
{
// find the first player that is not on the capturing team
// they have just broken a cap and should be rewarded
@@ -520,8 +499,7 @@ void CTriggerAreaCapture::CaptureThink( void )
continue;
// If this guy's was a blocker, but not valid now, remove him from the list
if ( m_Blockers[i].iCapAttemptNumber != m_iCapAttemptNumber || !IsTouching(m_Blockers[i].hPlayer) ||
( TeamplayGameRules()->PointsMayAlwaysBeBlocked() && m_Blockers[i].flNextBlockTime < gpGlobals->curtime && m_bStartTouch ) )
if ( m_Blockers[i].iCapAttemptNumber != m_iCapAttemptNumber || !IsTouching(m_Blockers[i].hPlayer) )
{
m_Blockers.Remove(i);
continue;
@@ -539,7 +517,6 @@ void CTriggerAreaCapture::CaptureThink( void )
int iNew = m_Blockers.AddToTail();
m_Blockers[iNew].hPlayer = pBlockingPlayer;
m_Blockers[iNew].iCapAttemptNumber = m_iCapAttemptNumber;
m_Blockers[iNew].flNextBlockTime = gpGlobals->curtime + 10.0f;
}
}
}
@@ -558,7 +535,7 @@ void CTriggerAreaCapture::CaptureThink( void )
}
float flTotalTimeToCap = m_flCapTime;
if ( CaptureModeScalesWithPlayers() )
if ( mp_capstyle.GetInt() == 1 )
{
flTotalTimeToCap = ((m_flCapTime * 2) * m_TeamData[m_nCapturingTeam].iNumRequiredToCap);
}
@@ -577,8 +554,7 @@ void CTriggerAreaCapture::CaptureThink( void )
// Caps deteriorate over time
if ( TeamplayRoundBasedRules() && m_hPoint && TeamplayRoundBasedRules()->TeamMayCapturePoint(m_nCapturingTeam,m_hPoint->GetPointIndex()) )
{
float flDecreaseScale = CaptureModeScalesWithPlayers() ? mp_capdeteriorate_time.GetFloat() : flTotalTimeToCap;
float flDecrease = (flTotalTimeToCap / flDecreaseScale) * flTimeDelta;
float flDecrease = (flTotalTimeToCap / mp_capdeteriorate_time.GetFloat()) * flTimeDelta;
if ( TeamplayRoundBasedRules() && TeamplayRoundBasedRules()->InOvertime() )
{
flDecrease *= 6;
@@ -616,18 +592,10 @@ void CTriggerAreaCapture::CaptureThink( void )
}
else
{
// We may get several simultaneous CaptureThink calls from StartTouch if there are several players on the trigger
// when it is enabled (like in Raid mode). We haven't started reducing m_fTimeRemaining yet but the second call to CaptureThink
// from StartTouch has m_bCapturing set to true and we hit this condition and call BreakCapture right away.
// We put this check here to prevent calling BreakCapture from the StartTouch call to CaptureThink. If the capture should
// really be broken it will happen the next time the trigger thinks on its own.
if ( !m_bStartTouch )
if ( m_fTimeRemaining >= flTotalTimeToCap )
{
if ( m_fTimeRemaining >= flTotalTimeToCap )
{
BreakCapture( false );
return;
}
BreakCapture( false );
return;
}
}
}
@@ -644,10 +612,7 @@ void CTriggerAreaCapture::CaptureThink( void )
if ( m_TeamData[i].iNumTouching == 0 )
continue;
if ( m_TeamData[i].iNumTouching < m_TeamData[i].iNumRequiredToStartCap )
continue;
if ( !CaptureModeScalesWithPlayers() && m_TeamData[i].iNumTouching < m_TeamData[i].iNumRequiredToCap )
if ( mp_capstyle.GetInt() == 0 && m_TeamData[i].iNumTouching < m_TeamData[i].iNumRequiredToCap )
continue;
StartCapture( i, CAPTURE_NORMAL );
@@ -668,7 +633,7 @@ void CTriggerAreaCapture::SetCapTimeRemaining( float flTime )
if ( m_nCapturingTeam )
{
flCapPercentage = m_fTimeRemaining / m_flCapTime;
if ( CaptureModeScalesWithPlayers() )
if ( mp_capstyle.GetInt() == 1 )
{
flCapPercentage = m_fTimeRemaining / ((m_flCapTime * 2) * m_TeamData[m_nCapturingTeam].iNumRequiredToCap);
}
@@ -758,11 +723,9 @@ void CTriggerAreaCapture::StartCapture( int team, int capmode )
m_nCapturingTeam = team;
OnStartCapture( m_nCapturingTeam );
UpdateNumPlayers();
if ( CaptureModeScalesWithPlayers() )
if ( mp_capstyle.GetInt() == 1 )
{
SetCapTimeRemaining( ((m_flCapTime * 2) * m_TeamData[team].iNumRequiredToCap) );
}
@@ -895,7 +858,7 @@ void CTriggerAreaCapture::EndCapture( int team )
m_hPoint->CaptureEnd();
}
SetNumCappers( 0 );
m_OnNumCappersChanged.Set( 0, this, this );
// tell all touching players to stop racking up capture points
CTeam *pTeam = GetGlobalTeam( m_nCapturingTeam );
@@ -905,17 +868,11 @@ void CTriggerAreaCapture::EndCapture( int team )
{
CBaseMultiplayerPlayer *pPlayer = ToBaseMultiplayerPlayer( pTeam->GetPlayer(i) );
if ( pPlayer && IsTouching( pPlayer ) )
{
{
pPlayer->StopScoringEscortPoints();
}
}
}
// play any special cap sounds
if ( TeamplayRoundBasedRules() )
{
TeamplayRoundBasedRules()->PlaySpecialCapSounds( m_nOwningTeam );
}
}
//-----------------------------------------------------------------------------
@@ -956,19 +913,9 @@ void CTriggerAreaCapture::BreakCapture( bool bNotEnoughPlayers )
if( m_hPoint )
{
m_hPoint->CaptureEnd();
// The point reverted to it's previous owner.
IGameEvent *event = gameeventmanager->CreateEvent( "teamplay_capture_broken" );
if ( event )
{
event->SetInt( "cp", m_hPoint->GetPointIndex() );
event->SetString( "cpname", m_hPoint->GetName() );
event->SetFloat( "time_remaining", m_fTimeRemaining );
gameeventmanager->FireEvent( event );
}
}
SetNumCappers( 0 );
m_OnNumCappersChanged.Set( 0, this, this );
// tell all touching players to stop racking up capture points
CTeam *pTeam = GetGlobalTeam( m_nCapturingTeam );
@@ -1017,7 +964,7 @@ void CTriggerAreaCapture::InputRoundSpawn( inputdata_t &inputdata )
ObjectiveResource()->SetCPRequiredCappers( m_hPoint->GetPointIndex(), i, m_TeamData[i].iNumRequiredToCap );
ObjectiveResource()->SetTeamCanCap( m_hPoint->GetPointIndex(), i, m_TeamData[i].bCanCap );
if ( CaptureModeScalesWithPlayers() )
if ( mp_capstyle.GetInt() == 1 )
{
ObjectiveResource()->SetCPCapTime( m_hPoint->GetPointIndex(), i, (m_flCapTime * 2) * m_TeamData[i].iNumRequiredToCap );
}
@@ -1025,8 +972,6 @@ void CTriggerAreaCapture::InputRoundSpawn( inputdata_t &inputdata )
{
ObjectiveResource()->SetCPCapTime( m_hPoint->GetPointIndex(), i, m_flCapTime );
}
ObjectiveResource()->SetCPCapTimeScalesWithPlayers( m_hPoint->GetPointIndex(), CaptureModeScalesWithPlayers() );
}
}
}
@@ -1127,9 +1072,9 @@ bool CTriggerAreaCapture::CheckIfDeathCausesBlock( CBaseMultiplayerPlayer *pVict
// break early incase we kill multiple people in the same frame
bool bBreakCap = false;
if ( CaptureModeScalesWithPlayers() )
if ( mp_capstyle.GetInt() == 1 )
{
bBreakCap = ( m_TeamData[m_nCapturingTeam].iBlockedTouching - 1 ) <= 0;
bBreakCap = (m_TeamData[m_nCapturingTeam].iBlockedTouching - 1) <= 0;
}
else
{
@@ -1145,10 +1090,11 @@ bool CTriggerAreaCapture::CheckIfDeathCausesBlock( CBaseMultiplayerPlayer *pVict
return true;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CTriggerAreaCapture::UpdateNumPlayers( bool bBlocked /*= false */ )
void CTriggerAreaCapture::UpdateNumPlayers( void )
{
if( !m_hPoint )
return;
@@ -1158,7 +1104,7 @@ void CTriggerAreaCapture::UpdateNumPlayers( bool bBlocked /*= false */ )
{
if ( i >= FIRST_GAME_TEAM && i == m_nCapturingTeam )
{
SetNumCappers( m_TeamData[i].iNumTouching, bBlocked );
m_OnNumCappersChanged.Set( m_TeamData[i].iNumTouching, this, this );
}
ObjectiveResource()->SetNumPlayers( index, i, m_TeamData[i].iNumTouching );
@@ -1209,24 +1155,3 @@ void CTriggerAreaCapture::UpdateBlocked( void )
m_hPoint->CaptureInterrupted( m_bBlocked );
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CTriggerAreaCapture::SetNumCappers( int nNumCappers, bool bBlocked /* = false */ )
{
m_OnNumCappersChanged.Set( nNumCappers, this, this );
// m_OnNumCappersChanged2 sets -1 for a blocked cart (for movement decisions on hills)
if ( bBlocked )
{
nNumCappers = -1;
}
m_OnNumCappersChanged2.Set( nNumCappers, this, this );
if ( m_hTrainWatcher.Get() )
{
m_hTrainWatcher->SetNumTrainCappers( nNumCappers, this );
}
}