Skip to content

Commit

Permalink
Merge pull request #99 from fortressforever/features/tfc-hh-grens
Browse files Browse the repository at this point in the history
Make handheld frag jumps more TFC-like™
  • Loading branch information
squeek502 committed Mar 7, 2015
2 parents 2ea366a + 00ce38c commit 1a56507
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 89 deletions.
183 changes: 95 additions & 88 deletions game_shared/ff/ff_gamerules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1425,22 +1425,14 @@ ConVar mp_prematch( "mp_prematch",
if (flAdjustedDamage <= 0)
continue;

// In TFC players only do 2/3 damage to themselves
// This also affects forces by the same amount
// Added: Make sure the source isn't a buildable though
// as that should do full damage!
if (pEntity == info.GetAttacker() && !pBuildable)
flAdjustedDamage *= 0.66666f;

// if inflictor is a buildable (e.g. SG or dispenser exploding), engineers take half damage
if ((pBuildable) && (pEntity->IsPlayer()))
{
CFFPlayer *pPlayer = ToFFPlayer(pEntity);
if ((pPlayer) &&( pPlayer->GetClassSlot() == CLASS_ENGINEER ))
{
flAdjustedDamage *= FFDEV_ENGI_BUILD_EXPL_REDUCE;
}
}
flAdjustedDamage = GetAdjustedDamage(flAdjustedDamage, pEntity, info);

// Create a new TakeDamageInfo for this player
CTakeDamageInfo adjustedInfo = info;

// Set the new adjusted damage
adjustedInfo.SetDamage(flAdjustedDamage);

// If we're stuck inside them, fixup the position and distance
// I'm assuming this is done in TFC too
if (tr.startsolid)
Expand All @@ -1449,85 +1441,14 @@ ConVar mp_prematch( "mp_prematch",
tr.fraction = 0.0;
}

// Create a new TakeDamageInfo for this player
CTakeDamageInfo adjustedInfo = info;

// Set the new adjusted damage
adjustedInfo.SetDamage(flAdjustedDamage);

// Don't calculate the forces if we already have them
if (adjustedInfo.GetDamagePosition() == vec3_origin || adjustedInfo.GetDamageForce() == vec3_origin)
{
// Multiply the damage by 8.0f (ala tfc) to get the force
// 0000936 - use convar; ensure a lower "bounds"
float flCalculatedForce = flAdjustedDamage * PUSH_MULTIPLIER;

CBaseEntity *pInflictor = info.GetInflictor();
// If this is an IC projectile, set to a lower clamp (350)
float flPushClamp = PUSH_CLAMP;

if ( pInflictor )
{
switch ( pInflictor->Classify() )
{
case CLASS_IC_ROCKET:
flPushClamp = 350.0f;
// lower the push because of the increased damage needed
flCalculatedForce /= 3;
if (pEntity == info.GetAttacker() && !pBuildable)
{
flAdjustedDamage *= IC_SELFDAMAGEMULTIPLIER;
adjustedInfo.SetDamage(flAdjustedDamage);
}
break;

case CLASS_RAIL_PROJECTILE:
flPushClamp = 300.0f;
// Don't want people jumpin' real high with the Rail Gun :)
flCalculatedForce /= 3;
break;

case CLASS_GREN_EMP:
if (flCalculatedForce > 700.0f )
flCalculatedForce = 700.0f;
break;
}
}

if (flCalculatedForce < flPushClamp)
flCalculatedForce = flPushClamp;

CFFPlayer *pPlayer = NULL;

if( pEntity->IsPlayer() )
pPlayer = ToFFPlayer(pEntity);

// We have to reduce the force further if they're fat
// 0000936 - use convar
if (pPlayer && pPlayer->GetClassSlot() == CLASS_HWGUY)
flCalculatedForce *= FATTYPUSH_MULTIPLIER;

//CFFPlayer *pAttacker = NULL;
CBaseEntity *pAttacker = info.GetAttacker();

/*
// If it's a building then take it's owner
if( ( info.GetAttacker()->Classify() == CLASS_DISPENSER ) ||
( info.GetAttacker()->Classify() == CLASS_SENTRYGUN ) ||
( info.GetAttacker()->Classify() == CLASS_DISPENSER ) )
{
pAttacker = ToFFPlayer( ( ( CFFBuildableObject * )info.GetAttacker() )->m_hOwner.Get() );
}
else
pAttacker = ToFFPlayer( info.GetAttacker() );
*/

// And also reduce if we couldn't hurt them
// TODO: Get exact figure for this
// 0000936 - use convar
if (pPlayer && pAttacker && !g_pGameRules->FCanTakeDamage(pPlayer, pAttacker))
flCalculatedForce *= NODAMAGEPUSH_MULTIPLIER;
flCalculatedForce = GetAdjustedPushForce(flCalculatedForce, pEntity, adjustedInfo);

// Don't use the damage source direction, use the reported position
// if it exists
Expand Down Expand Up @@ -1580,6 +1501,92 @@ ConVar mp_prematch( "mp_prematch",
}
}

float CFFGameRules::GetAdjustedPushForce(float flPushForce, CBaseEntity *pVictim, const CTakeDamageInfo &info)
{
float flAdjustedPushForce = flPushForce;

CBaseEntity *pInflictor = info.GetInflictor();
float flPushClamp = PUSH_CLAMP;

if ( pInflictor )
{
switch ( pInflictor->Classify() )
{
case CLASS_IC_ROCKET:
flPushClamp = 350.0f;
// lower the push because of the increased damage needed
flAdjustedPushForce /= 3;
break;

case CLASS_RAIL_PROJECTILE:
flPushClamp = 300.0f;
// Don't want people jumpin' real high with the Rail Gun :)
flAdjustedPushForce /= 3;
break;

case CLASS_GREN_EMP:
if (flAdjustedPushForce > 700.0f )
flAdjustedPushForce = 700.0f;
break;
}
}

if (flAdjustedPushForce < flPushClamp)
flAdjustedPushForce = flPushClamp;

CFFPlayer *pPlayer = NULL;

if( pVictim->IsPlayer() )
pPlayer = ToFFPlayer(pVictim);

// We have to reduce the force further if they're fat
// 0000936 - use convar
if (pPlayer && pPlayer->GetClassSlot() == CLASS_HWGUY)
flAdjustedPushForce *= FATTYPUSH_MULTIPLIER;

CBaseEntity *pAttacker = info.GetAttacker();

// And also reduce if we couldn't hurt them
// TODO: Get exact figure for this
// 0000936 - use convar
if (pPlayer && pAttacker && !g_pGameRules->FCanTakeDamage(pPlayer, pAttacker))
flAdjustedPushForce *= NODAMAGEPUSH_MULTIPLIER;

return flAdjustedPushForce;
}

float CFFGameRules::GetAdjustedDamage(float flDamage, CBaseEntity *pVictim, const CTakeDamageInfo &info)
{
float flAdjustedDamage = flDamage;

CBaseEntity *pInflictor = info.GetInflictor();
bool bIsInflictorABuildable = dynamic_cast <CFFBuildableObject *> (pInflictor) != NULL;

if (pInflictor && pInflictor->Classify() == CLASS_IC_ROCKET && pVictim == info.GetAttacker())
{
flAdjustedDamage *= IC_SELFDAMAGEMULTIPLIER;
}

// In TFC players only do 2/3 damage to themselves
// This also affects forces by the same amount
// Added: Make sure the source isn't a buildable though
// as that should do full damage!
if (pVictim == info.GetAttacker() && !bIsInflictorABuildable)
flAdjustedDamage *= 0.66666f;

// if inflictor is a buildable (e.g. SG or dispenser exploding), engineers take half damage
if (bIsInflictorABuildable && pVictim->IsPlayer())
{
CFFPlayer *pPlayer = ToFFPlayer(pVictim);
if (pPlayer && pPlayer->GetClassSlot() == CLASS_ENGINEER)
{
flAdjustedDamage *= FFDEV_ENGI_BUILD_EXPL_REDUCE;
}
}

return flAdjustedDamage;
}

// --> Mirv: Hodgepodge of different checks (from the base functions) inc. prematch
void CFFGameRules::Think()
{
Expand Down
2 changes: 2 additions & 0 deletions game_shared/ff/ff_gamerules.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ class CFFGameRules : public CTeamplayRules
virtual ~CFFGameRules();

virtual void RadiusDamage(const CTakeDamageInfo &info, const Vector &vecSrc, float flRadius, int iClassIgnore, CBaseEntity *pEntityIgnore);
virtual float GetAdjustedPushForce(float flPushForce, CBaseEntity *pVictim, const CTakeDamageInfo &info);
virtual float GetAdjustedDamage(float flDamage, CBaseEntity *pVictim, const CTakeDamageInfo &info);

virtual float FlPlayerFallDamage(CBasePlayer *pPlayer);
virtual bool FlPlayerFallDeathDoesScreenFade( CBasePlayer *pPlayer );
Expand Down
29 changes: 28 additions & 1 deletion game_shared/ff/ff_grenade_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "ff_player.h"
#include "ff_utils.h"
#include "ff_entity_system.h"
#include "ff_gamerules.h"
#else
#include "c_te_effect_dispatch.h"
#include "c_ff_player.h"
Expand Down Expand Up @@ -84,6 +85,8 @@ LINK_ENTITY_TO_CLASS(grenade_ff_base, CFFGrenadeBase);
#define GREN_WATER_VEL_DEC 0.5f
//ConVar gren_water_reduce_think("ffdev_gren_water_reduce_think", "0.2", FCVAR_FF_FFDEV_REPLICATED);
#define GREN_WATER_REDUCE_THINK 0.2f

#define GREN_HH_PUSHFORCE 1000.0f

//=============================================================================
// CFFGrenadeBase implementation
Expand Down Expand Up @@ -525,7 +528,31 @@ LINK_ENTITY_TO_CLASS(grenade_ff_base, CFFGrenadeBase);
// Use the grenade's position as the reported position
Vector vecReported = pTrace->endpos;
CTakeDamageInfo info( this, pThrower, GetBlastForce(), GetAbsOrigin(), m_flDamage, bitsDamageType, m_iKillType, &vecReported );
RadiusDamage( info, GetAbsOrigin(), m_DmgRadius, CLASS_NONE, NULL );

RadiusDamage( info, GetAbsOrigin(), m_DmgRadius, CLASS_NONE, m_fIsHandheld ? pThrower : NULL );

if (m_fIsHandheld)
{
CTakeDamageInfo infoSelfDamage = info;
Vector vecPushDir = pThrower->GetAbsVelocity();
float flPushForce = GREN_HH_PUSHFORCE;

if (vecPushDir.LengthSqr() > 0.0f)
{
vecPushDir.NormalizeInPlace();
}
else
{
vecPushDir = Vector(0.0f, 0.0f, 0.95f);
}

flPushForce = FFGameRules()->GetAdjustedPushForce(flPushForce, pThrower, infoSelfDamage);
float flAdjustedDamage = FFGameRules()->GetAdjustedDamage(infoSelfDamage.GetDamage(), pThrower, infoSelfDamage);

infoSelfDamage.SetDamageForce(vecPushDir * flPushForce);
infoSelfDamage.SetDamage(flAdjustedDamage);
pThrower->TakeDamage(infoSelfDamage);
}

EmitSound( "BaseGrenade.Explode" );
}
Expand Down

0 comments on commit 1a56507

Please sign in to comment.