Skip to content

Commit

Permalink
Implement CCSEntity::FireBuckshots (#651)
Browse files Browse the repository at this point in the history
  • Loading branch information
FEDERICOMB96 authored and SergeyShorokhov committed Aug 31, 2021
1 parent d079f26 commit 983500c
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 82 deletions.
5 changes: 5 additions & 0 deletions regamedll/dlls/API/CSEntity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ void CCSEntity::FireBullets(int iShots, Vector &vecSrc, Vector &vecDirShooting,
m_pContainingEntity->FireBullets(iShots, vecSrc, vecDirShooting, vecSpread, flDistance, iBulletType, iTracerFreq, iDamage, pevAttacker);
}

void CCSEntity::FireBuckshots(ULONG cShots, Vector &vecSrc, Vector &vecDirShooting, Vector &vecSpread, float flDistance, int iTracerFreq, int iDamage, entvars_t *pevAttacker)
{
m_pContainingEntity->FireBuckshots(cShots, vecSrc, vecDirShooting, vecSpread, flDistance, iTracerFreq, iDamage, pevAttacker);
}

Vector CCSEntity::FireBullets3(Vector &vecSrc, Vector &vecDirShooting, float vecSpread, float flDistance, int iPenetration, int iBulletType, int iDamage, float flRangeModifier, entvars_t *pevAttacker, bool bPistol, int shared_rand)
{
return m_pContainingEntity->FireBullets3(vecSrc, vecDirShooting, vecSpread, flDistance, iPenetration, iBulletType, iDamage, flRangeModifier, pevAttacker, bPistol, shared_rand);
Expand Down
162 changes: 81 additions & 81 deletions regamedll/dlls/cbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1146,87 +1146,87 @@ LINK_HOOK_CLASS_VOID_CHAIN(CBaseEntity, FireBuckshots, (ULONG cShots, VectorRef

void CBaseEntity::__API_HOOK(FireBuckshots)(ULONG cShots, VectorRef vecSrc, VectorRef vecDirShooting, VectorRef vecSpread, float flDistance, int iTracerFreq, int iDamage, entvars_t *pevAttacker)
{
static int tracerCount;
int tracer;

TraceResult tr;
Vector vecRight, vecUp;

vecRight = gpGlobals->v_right;
vecUp = gpGlobals->v_up;

if (!pevAttacker)
{
// the default attacker is ourselves
pevAttacker = pev;
}

ClearMultiDamage();
gMultiDamage.type = (DMG_BULLET | DMG_NEVERGIB);

for (ULONG iShot = 1; iShot <= cShots; iShot++)
{
// get circular gaussian spread
float x, y, z;

do
{
x = RANDOM_FLOAT(-0.5, 0.5) + RANDOM_FLOAT(-0.5, 0.5);
y = RANDOM_FLOAT(-0.5, 0.5) + RANDOM_FLOAT(-0.5, 0.5);
z = x * x + y * y;
}
while (z > 1);

Vector vecDir, vecEnd;

vecDir = vecDirShooting + x * vecSpread.x * vecRight + y * vecSpread.y * vecUp;
vecEnd = vecSrc + vecDir * flDistance;

UTIL_TraceLine(vecSrc, vecEnd, dont_ignore_monsters, ENT(pev), &tr);
tracer = 0;

if (iTracerFreq != 0 && !(tracerCount++ % iTracerFreq))
{
Vector vecTracerSrc;

if (IsPlayer())
{
// adjust tracer position for player
vecTracerSrc = vecSrc + Vector(0, 0, -4) + gpGlobals->v_right * 2 + gpGlobals->v_forward * 16;
}
else
{
vecTracerSrc = vecSrc;
}

// guns that always trace also always decal
if (iTracerFreq != 1)
tracer = 1;

MESSAGE_BEGIN(MSG_PAS, SVC_TEMPENTITY, vecTracerSrc);
WRITE_BYTE(TE_TRACER);
WRITE_COORD(vecTracerSrc.x);
WRITE_COORD(vecTracerSrc.y);
WRITE_COORD(vecTracerSrc.z);
WRITE_COORD(tr.vecEndPos.x);
WRITE_COORD(tr.vecEndPos.y);
WRITE_COORD(tr.vecEndPos.z);
MESSAGE_END();
}

// do damage, paint decals
if (tr.flFraction != 1.0f)
{
CBaseEntity *pEntity = CBaseEntity::Instance(tr.pHit);
float flDamage = ((1 - tr.flFraction) * iDamage);
pEntity->TraceAttack(pevAttacker, int(flDamage), vecDir, &tr, DMG_BULLET);
}

// make bullet trails
UTIL_BubbleTrail(vecSrc, tr.vecEndPos, int((flDistance * tr.flFraction) / 64));
}

ApplyMultiDamage(pev, pevAttacker);
static int tracerCount;
int tracer;

TraceResult tr;
Vector vecRight, vecUp;

vecRight = gpGlobals->v_right;
vecUp = gpGlobals->v_up;

if (!pevAttacker)
{
// the default attacker is ourselves
pevAttacker = pev;
}

ClearMultiDamage();
gMultiDamage.type = (DMG_BULLET | DMG_NEVERGIB);

for (ULONG iShot = 1; iShot <= cShots; iShot++)
{
// get circular gaussian spread
float x, y, z;

do
{
x = RANDOM_FLOAT(-0.5, 0.5) + RANDOM_FLOAT(-0.5, 0.5);
y = RANDOM_FLOAT(-0.5, 0.5) + RANDOM_FLOAT(-0.5, 0.5);
z = x * x + y * y;
}
while (z > 1);

Vector vecDir, vecEnd;

vecDir = vecDirShooting + x * vecSpread.x * vecRight + y * vecSpread.y * vecUp;
vecEnd = vecSrc + vecDir * flDistance;

UTIL_TraceLine(vecSrc, vecEnd, dont_ignore_monsters, ENT(pev), &tr);
tracer = 0;

if (iTracerFreq != 0 && !(tracerCount++ % iTracerFreq))
{
Vector vecTracerSrc;

if (IsPlayer())
{
// adjust tracer position for player
vecTracerSrc = vecSrc + Vector(0, 0, -4) + gpGlobals->v_right * 2 + gpGlobals->v_forward * 16;
}
else
{
vecTracerSrc = vecSrc;
}

// guns that always trace also always decal
if (iTracerFreq != 1)
tracer = 1;

MESSAGE_BEGIN(MSG_PAS, SVC_TEMPENTITY, vecTracerSrc);
WRITE_BYTE(TE_TRACER);
WRITE_COORD(vecTracerSrc.x);
WRITE_COORD(vecTracerSrc.y);
WRITE_COORD(vecTracerSrc.z);
WRITE_COORD(tr.vecEndPos.x);
WRITE_COORD(tr.vecEndPos.y);
WRITE_COORD(tr.vecEndPos.z);
MESSAGE_END();
}

// do damage, paint decals
if (tr.flFraction != 1.0f)
{
CBaseEntity *pEntity = CBaseEntity::Instance(tr.pHit);
float flDamage = ((1 - tr.flFraction) * iDamage);
pEntity->TraceAttack(pevAttacker, int(flDamage), vecDir, &tr, DMG_BULLET);
}

// make bullet trails
UTIL_BubbleTrail(vecSrc, tr.vecEndPos, int((flDistance * tr.flFraction) / 64));
}

ApplyMultiDamage(pev, pevAttacker);
}

bool EXT_FUNC IsPenetrableEntity_default(Vector &vecSrc, Vector &vecEnd, entvars_t *pevAttacker, edict_t *pHit)
Expand Down
40 changes: 39 additions & 1 deletion regamedll/public/regamedll/API/CSEntity.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,46 @@ class CCSEntity

virtual ~CCSEntity() {}
virtual void FireBullets(int iShots, Vector &vecSrc, Vector &vecDirShooting, Vector &vecSpread, float flDistance, int iBulletType, int iTracerFreq, int iDamage, entvars_t *pevAttacker);
virtual void FireBuckshots(ULONG cShots, Vector &vecSrc, Vector &vecDirShooting, Vector &vecSpread, float flDistance, int iTracerFreq, int iDamage, entvars_t *pevAttacker);
virtual Vector FireBullets3(Vector &vecSrc, Vector &vecDirShooting, float vecSpread, float flDistance, int iPenetration, int iBulletType, int iDamage, float flRangeModifier, entvars_t *pevAttacker, bool bPistol, int shared_rand);

#if defined(_MSC_VER)
#pragma region reserve_vfuncs_Region
#endif
virtual void func_reserve1() {};
virtual void func_reserve2() {};
virtual void func_reserve3() {};
virtual void func_reserve4() {};
virtual void func_reserve5() {};
virtual void func_reserve6() {};
virtual void func_reserve7() {};
virtual void func_reserve8() {};
virtual void func_reserve9() {};
virtual void func_reserve10() {};
virtual void func_reserve11() {};
virtual void func_reserve12() {};
virtual void func_reserve13() {};
virtual void func_reserve14() {};
virtual void func_reserve15() {};
virtual void func_reserve16() {};
virtual void func_reserve17() {};
virtual void func_reserve18() {};
virtual void func_reserve19() {};
virtual void func_reserve20() {};
virtual void func_reserve21() {};
virtual void func_reserve22() {};
virtual void func_reserve23() {};
virtual void func_reserve24() {};
virtual void func_reserve25() {};
virtual void func_reserve26() {};
virtual void func_reserve27() {};
virtual void func_reserve28() {};
virtual void func_reserve29() {};
virtual void func_reserve30() {};
#if defined(_MSC_VER)
#pragma endregion
#endif

public:
CBaseEntity *m_pContainingEntity;
};
Expand Down Expand Up @@ -69,4 +107,4 @@ class CCSMonster: public CCSToggle

};

#define CSENTITY_API_INTERFACE_VERSION "CSENTITY_API_INTERFACE_VERSION001"
#define CSENTITY_API_INTERFACE_VERSION "CSENTITY_API_INTERFACE_VERSION002"

0 comments on commit 983500c

Please sign in to comment.