Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
210 changes: 210 additions & 0 deletions sp/src/game/server/RagdollBoogie.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
#include "effect_dispatch_data.h"
#include "te_effect_dispatch.h"
#include "IEffects.h"
#ifdef MAPBASE
#include "saverestore_utlvector.h"
#include "interval.h"
#endif

// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
Expand All @@ -37,6 +41,10 @@ BEGIN_DATADESC( CRagdollBoogie )
// Think this should be handled by StartTouch/etc.
// DEFINE_FIELD( m_nSuppressionCount, FIELD_INTEGER ),

#ifdef MAPBASE
DEFINE_FIELD( m_vecColor, FIELD_VECTOR ),
#endif

DEFINE_FUNCTION( BoogieThink ),
DEFINE_FUNCTION( ZapThink ),

Expand All @@ -50,7 +58,11 @@ LINK_ENTITY_TO_CLASS( env_ragdoll_boogie, CRagdollBoogie );
// Input : pTarget -
//-----------------------------------------------------------------------------
CRagdollBoogie *CRagdollBoogie::Create( CBaseEntity *pTarget, float flMagnitude,
#ifdef MAPBASE
float flStartTime, float flLengthTime, int nSpawnFlags, const Vector *vecColor )
#else
float flStartTime, float flLengthTime, int nSpawnFlags )
#endif
{
CRagdollProp *pRagdoll = dynamic_cast< CRagdollProp* >( pTarget );
if ( !pRagdoll )
Expand All @@ -64,6 +76,10 @@ CRagdollBoogie *CRagdollBoogie::Create( CBaseEntity *pTarget, float flMagnitude,
pBoogie->AttachToEntity( pTarget );
pBoogie->SetBoogieTime( flStartTime, flLengthTime );
pBoogie->SetMagnitude( flMagnitude );
#ifdef MAPBASE
if (vecColor != NULL)
pBoogie->SetColor( *vecColor );
#endif
pBoogie->Spawn();
return pBoogie;
}
Expand Down Expand Up @@ -115,6 +131,13 @@ void CRagdollBoogie::ZapThink()
data.m_nEntIndex = GetMoveParent()->entindex();
data.m_flMagnitude = 4;
data.m_flScale = HasSpawnFlags(SF_RAGDOLL_BOOGIE_ELECTRICAL_NARROW_BEAM) ? 1.0f : 2.0f;
#ifdef MAPBASE
if (!m_vecColor.IsZero())
{
data.m_bCustomColors = true;
data.m_CustomColors.m_vecColor1 = m_vecColor;
}
#endif

DispatchEffect( "TeslaHitboxes", data );
}
Expand Down Expand Up @@ -266,3 +289,190 @@ void CRagdollBoogie::BoogieThink( void )

SetNextThink( gpGlobals->curtime + random->RandomFloat( 0.1, 0.2f ) );
}

#ifdef MAPBASE
//-----------------------------------------------------------------------------
// Allows mappers to control ragdoll dancing
//-----------------------------------------------------------------------------
class CPointRagdollBoogie : public CBaseEntity
{
DECLARE_DATADESC();
DECLARE_CLASS( CPointRagdollBoogie, CBaseEntity );

public:
bool ApplyBoogie(CBaseEntity *pTarget, CBaseEntity *pActivator);

void InputActivate( inputdata_t &inputdata );
void InputDeactivate( inputdata_t &inputdata );
void InputBoogieTarget( inputdata_t &inputdata );
void InputSetZapColor( inputdata_t &inputdata );

bool KeyValue( const char *szKeyName, const char *szValue );

private:
float m_flStartTime;
interval_t m_BoogieLength;
float m_flMagnitude;

Vector m_vecZapColor;

// This allows us to change or remove active boogies later.
CUtlVector<CHandle<CRagdollBoogie>> m_Boogies;
};

//-----------------------------------------------------------------------------
// Save/load
//-----------------------------------------------------------------------------
BEGIN_DATADESC( CPointRagdollBoogie )

DEFINE_KEYFIELD( m_flStartTime, FIELD_FLOAT, "StartTime" ),
DEFINE_KEYFIELD( m_BoogieLength, FIELD_INTERVAL, "BoogieLength" ),
DEFINE_KEYFIELD( m_flMagnitude, FIELD_FLOAT, "Magnitude" ),

DEFINE_KEYFIELD( m_vecZapColor, FIELD_VECTOR, "ZapColor" ),

// Think this should be handled by StartTouch/etc.
// DEFINE_FIELD( m_nSuppressionCount, FIELD_INTEGER ),

DEFINE_UTLVECTOR( m_Boogies, FIELD_EHANDLE ),

// Inputs
DEFINE_INPUTFUNC( FIELD_VOID, "Activate", InputActivate ),
DEFINE_INPUTFUNC( FIELD_VOID, "Deactivate", InputDeactivate ),
DEFINE_INPUTFUNC( FIELD_STRING, "BoogieTarget", InputBoogieTarget ),
DEFINE_INPUTFUNC( FIELD_VECTOR, "SetZapColor", InputSetZapColor ),

END_DATADESC()

LINK_ENTITY_TO_CLASS( point_ragdollboogie, CPointRagdollBoogie );

//-----------------------------------------------------------------------------
// Purpose:
// Input : &inputdata -
//-----------------------------------------------------------------------------
bool CPointRagdollBoogie::ApplyBoogie( CBaseEntity *pTarget, CBaseEntity *pActivator )
{
if (dynamic_cast<CRagdollProp*>(pTarget))
{
m_Boogies.AddToTail(CRagdollBoogie::Create(pTarget, m_flMagnitude, gpGlobals->curtime + m_flStartTime, RandomInterval(m_BoogieLength), GetSpawnFlags(), &m_vecZapColor));
}
else if (pTarget->MyCombatCharacterPointer())
{
// Basically CBaseCombatCharacter::BecomeRagdollBoogie(), but adjusted to our needs
CTakeDamageInfo info(this, pActivator, 1.0f, DMG_GENERIC);

CBaseEntity *pRagdoll = CreateServerRagdoll(pTarget->MyCombatCharacterPointer(), 0, info, COLLISION_GROUP_INTERACTIVE_DEBRIS, true);

pRagdoll->SetCollisionBounds(CollisionProp()->OBBMins(), CollisionProp()->OBBMaxs());

m_Boogies.AddToTail(CRagdollBoogie::Create(pRagdoll, m_flMagnitude, gpGlobals->curtime + m_flStartTime, RandomInterval(m_BoogieLength), GetSpawnFlags(), &m_vecZapColor));

CTakeDamageInfo ragdollInfo(this, pActivator, 10000.0, DMG_GENERIC | DMG_REMOVENORAGDOLL);
ragdollInfo.SetDamagePosition(WorldSpaceCenter());
ragdollInfo.SetDamageForce(Vector(0, 0, 1));
ragdollInfo.SetForceFriendlyFire(true);
pTarget->TakeDamage(ragdollInfo);
}
else
{
return false;
}

return true;
}

//-----------------------------------------------------------------------------
// Purpose:
// Input : &inputdata -
//-----------------------------------------------------------------------------
void CPointRagdollBoogie::InputActivate( inputdata_t &inputdata )
{
CBaseEntity *pEnt = gEntList.FindEntityByName(NULL, STRING(m_target), this, inputdata.pActivator, inputdata.pCaller);
while (pEnt)
{
ApplyBoogie(pEnt, inputdata.pActivator);

pEnt = gEntList.FindEntityByName(pEnt, STRING(m_target), this, inputdata.pActivator, inputdata.pCaller);
}
}

//-----------------------------------------------------------------------------
// Purpose:
// Input : &inputdata -
//-----------------------------------------------------------------------------
void CPointRagdollBoogie::InputDeactivate( inputdata_t &inputdata )
{
if (m_Boogies.Count() == 0)
return;

for (int i = 0; i < m_Boogies.Count(); i++)
{
UTIL_Remove(m_Boogies[i]);
}

m_Boogies.Purge();

//m_Boogies.RemoveAll();
}

//-----------------------------------------------------------------------------
// Purpose:
// Input : &inputdata -
//-----------------------------------------------------------------------------
void CPointRagdollBoogie::InputBoogieTarget( inputdata_t &inputdata )
{
CBaseEntity *pEnt = gEntList.FindEntityByName(NULL, inputdata.value.String(), this, inputdata.pActivator, inputdata.pCaller);
while (pEnt)
{
if (!ApplyBoogie(pEnt, inputdata.pActivator))
{
Warning("%s was unable to apply ragdoll boogie to %s, classname %s.\n", GetDebugName(), pEnt->GetDebugName(), pEnt->GetClassname());
}

pEnt = gEntList.FindEntityByName(pEnt, inputdata.value.String(), this, inputdata.pActivator, inputdata.pCaller);
}
}

//-----------------------------------------------------------------------------
// Purpose:
// Input : &inputdata -
//-----------------------------------------------------------------------------
void CPointRagdollBoogie::InputSetZapColor( inputdata_t &inputdata )
{
inputdata.value.Vector3D( m_vecZapColor );
if (!m_vecZapColor.IsZero())
{
// Turn into ratios of 255
m_vecZapColor /= 255.0f;
}

// Apply to existing boogies
for (int i = 0; i < m_Boogies.Count(); i++)
{
if (m_Boogies[i])
{
m_Boogies[i]->SetColor( m_vecZapColor );
}
}
}

//-----------------------------------------------------------------------------
// Purpose: Handles key values from the BSP before spawn is called.
//-----------------------------------------------------------------------------
bool CPointRagdollBoogie::KeyValue( const char *szKeyName, const char *szValue )
{
if ( FStrEq( szKeyName, "ZapColor" ) )
{
UTIL_StringToVector(m_vecZapColor.Base(), szValue);
if (!m_vecZapColor.IsZero())
{
// Turn into ratios of 255
m_vecZapColor /= 255.0f;
}
}
else
return BaseClass::KeyValue( szKeyName, szValue );

return true;
}
#endif
12 changes: 12 additions & 0 deletions sp/src/game/server/RagdollBoogie.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,18 @@ class CRagdollBoogie : public CBaseEntity
DECLARE_CLASS( CRagdollBoogie, CBaseEntity );

public:
#ifdef MAPBASE
static CRagdollBoogie *Create( CBaseEntity *pTarget, float flMagnitude, float flStartTime, float flLengthTime = 0.0f, int nSpawnFlags = 0, const Vector *vecColor = NULL );
#else
static CRagdollBoogie *Create( CBaseEntity *pTarget, float flMagnitude, float flStartTime, float flLengthTime = 0.0f, int nSpawnFlags = 0 );
#endif
static void IncrementSuppressionCount( CBaseEntity *pTarget );
static void DecrementSuppressionCount( CBaseEntity *pTarget );

#ifdef MAPBASE
void SetColor( const Vector &vecColor ) { m_vecColor = vecColor; }
#endif

void Spawn();

private:
Expand All @@ -45,6 +53,10 @@ class CRagdollBoogie : public CBaseEntity
float m_flBoogieLength;
float m_flMagnitude;
int m_nSuppressionCount;

#ifdef MAPBASE
Vector m_vecColor = Vector(1, 1, 1);
#endif
};

#endif // RAGDOLLBOOGIE_H
24 changes: 24 additions & 0 deletions sp/src/game/server/ai_behavior_standoff.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ enum AI_Posture_t
AIP_INDIFFERENT,
AIP_STANDING,
AIP_CROUCHING,
#if EXPANDED_HL2_COVER_ACTIVITIES
AIP_CROUCHING_MED, // See UpdateTranslateActivityMap() for more information on what this is for
#endif
AIP_PEEKING,
};

Expand Down Expand Up @@ -103,6 +106,9 @@ class CAI_StandoffBehavior : public CAI_MappedActivityBehavior_Temporary
bool IsActive( void ) { return m_fActive; }
void OnChangeTacticalConstraints();

#ifdef EZ2
virtual
#endif
bool CanSelectSchedule();
bool IsBehindBattleLines( const Vector &point );

Expand Down Expand Up @@ -149,6 +155,24 @@ class CAI_StandoffBehavior : public CAI_MappedActivityBehavior_Temporary

// Standoff overrides base AI crouch handling
bool IsCrouching( void ) { return false; }

#ifdef MAPBASE
// Standoff overrides base cover activity translation
bool CanTranslateCrouchActivity( void ) { return false; }

#ifdef EZ2
// Don't do death poses while crouching
bool ShouldPickADeathPose( void ) { return (GetPosture() != AIP_CROUCHING && GetPosture() != AIP_PEEKING) && BaseClass::ShouldPickADeathPose(); }
#else
// Don't do death poses while crouching
bool ShouldPickADeathPose(void) { return (GetPosture() != AIP_CROUCHING && GetPosture() != AIP_PEEKING); }
#endif

#endif

#ifdef EZ
const AI_StandoffParams_t &GetParams() { return m_params; }
#endif

private:

Expand Down
4 changes: 4 additions & 0 deletions sp/src/game/server/basecombatcharacter.h
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,10 @@ class CBaseCombatCharacter : public CBaseFlex

bool m_bForceServerRagdoll;

#ifdef EZ
EHANDLE m_hDeathRagdoll;
#endif

// Pickup prevention
bool IsAllowedToPickupWeapons( void ) { return !m_bPreventWeaponPickup; }
void SetPreventWeaponPickup( bool bPrevent ) { m_bPreventWeaponPickup = bPrevent; }
Expand Down
Loading