Skip to content

Commit

Permalink
expose/update some methods
Browse files Browse the repository at this point in the history
  • Loading branch information
wootguy committed Jan 11, 2025
1 parent b8ee875 commit 37841e7
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 88 deletions.
10 changes: 6 additions & 4 deletions dlls/CBaseEntity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ void CBaseEntity::SUB_FadeOut(void)
// FVisible - returns true if a line can be traced from
// the caller's eyes to the target
//=========================================================
BOOL CBaseEntity::FVisible(CBaseEntity* pEntity)
BOOL CBaseEntity::FVisible(CBaseEntity* pEntity, bool fIgnoreGlass)
{
TraceResult tr;
Vector vecLookerOrigin;
Expand All @@ -495,7 +495,8 @@ BOOL CBaseEntity::FVisible(CBaseEntity* pEntity)
vecLookerOrigin = pev->origin + pev->view_ofs;//look through the caller's 'eyes'
vecTargetOrigin = pEntity->IsBSPModel() ? pEntity->Center() : pEntity->EyePosition();

UTIL_TraceLine(vecLookerOrigin, vecTargetOrigin, ignore_monsters, ignore_glass, ENT(pev)/*pentIgnore*/, &tr);
IGNORE_GLASS ignore = fIgnoreGlass ? ignore_glass : dont_ignore_glass;
UTIL_TraceLine(vecLookerOrigin, vecTargetOrigin, ignore_monsters, ignore, ENT(pev)/*pentIgnore*/, &tr);

if (tr.flFraction != 1.0 && tr.pHit != pEntity->edict())
{
Expand All @@ -511,14 +512,15 @@ BOOL CBaseEntity::FVisible(CBaseEntity* pEntity)
// FVisible - returns true if a line can be traced from
// the caller's eyes to the target vector
//=========================================================
BOOL CBaseEntity::FVisible(const Vector& vecOrigin)
BOOL CBaseEntity::FVisible(const Vector& vecOrigin, bool fIgnoreGlass)
{
TraceResult tr;
Vector vecLookerOrigin;

vecLookerOrigin = EyePosition();//look through the caller's 'eyes'

UTIL_TraceLine(vecLookerOrigin, vecOrigin, ignore_monsters, ignore_glass, ENT(pev)/*pentIgnore*/, &tr);
IGNORE_GLASS ignore = fIgnoreGlass ? ignore_glass : dont_ignore_glass;
UTIL_TraceLine(vecLookerOrigin, vecOrigin, ignore_monsters, ignore, ENT(pev)/*pentIgnore*/, &tr);

if (tr.flFraction != 1.0)
{
Expand Down
5 changes: 3 additions & 2 deletions dlls/CBaseEntity.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once
#include "EHandle.h"
#include "saverestore.h"
#include <stdint.h>

class CBaseEntity;
class CBaseMonster;
Expand Down Expand Up @@ -322,8 +323,8 @@ class EXPORT CBaseEntity

virtual int Illumination() { return GETENTITYILLUM(ENT(pev)); };

virtual BOOL FVisible(CBaseEntity* pEntity);
virtual BOOL FVisible(const Vector& vecOrigin);
virtual BOOL FVisible(CBaseEntity* pEntity, bool fIgnoreGlass=true);
virtual BOOL FVisible(const Vector& vecOrigin, bool fIgnoreGlass=true);

virtual void SetClassify(int iNewClassify);
virtual int IRelationship(CBaseEntity* pTarget);
Expand Down
2 changes: 1 addition & 1 deletion dlls/env/explode.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ EXPORT extern DLL_GLOBAL short g_sModelIndexFireball;
EXPORT extern DLL_GLOBAL short g_sModelIndexSmoke;


extern void ExplosionCreate( const Vector &center, const Vector &angles, edict_t *pOwner, int magnitude, BOOL doDamage );
EXPORT extern void ExplosionCreate( const Vector &center, const Vector &angles, edict_t *pOwner, int magnitude, BOOL doDamage );

#endif //EXPLODE_H
2 changes: 1 addition & 1 deletion dlls/game/skill.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ float GetDefaultHealth(const char* monstertype, bool mapSkills) {
return defaultHp->second;
}
else {
ALERT(at_console, "Monster type %s has no default health\n", monstertype);
ALERT(at_aiconsole, "Monster type %s has no default health\n", monstertype);
return 0;
}
}
Expand Down
89 changes: 89 additions & 0 deletions dlls/monster/CBaseMonster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3567,6 +3567,95 @@ BOOL CBaseMonster::FCheckAITrigger(void)
return FALSE;
}

//=========================================================
// NoFriendlyFire - checks for possibility of friendly fire
//
// Builds a large box in front of the grunt and checks to see
// if any squad members are in that box.
//=========================================================
BOOL CBaseMonster::NoFriendlyFire(void)
{
if (!m_hEnemy) {
// if there's no enemy, pretend there's a friendly in the way, so the grunt won't shoot.
return FALSE;
}

{
// this works better than the 2D plane checks (sc_tropical1_final snipers)
Vector gunPos = GetGunPosition();
Vector targetPos = m_hEnemy->Center();
TraceResult tr, tr2;
TRACE_HULL(gunPos, targetPos, dont_ignore_monsters, head_hull, edict(), &tr);

// do a line check too in case head hull hit a wall or something
TRACE_LINE(gunPos, targetPos, dont_ignore_monsters, edict(), &tr2);

CBaseEntity* phit = CBaseEntity::Instance(tr.pHit);
CBaseEntity* phit2 = CBaseEntity::Instance(tr2.pHit);

if (phit && IRelationship(phit) == R_AL) {
return FALSE;
}
if (phit2 && IRelationship(phit2) == R_AL) {
return FALSE;
}

return TRUE;
}

// legacy logic
/*
CPlane backPlane;
CPlane leftPlane;
CPlane rightPlane;
Vector vecLeftSide;
Vector vecRightSide;
Vector v_left;
//!!!BUGBUG - to fix this, the planes must be aligned to where the monster will be firing its gun, not the direction it is facing!!!
UTIL_MakeVectors(UTIL_VecToAngles(m_hEnemy->Center() - pev->origin));
//UTIL_MakeVectors ( pev->angles );
vecLeftSide = pev->origin - (gpGlobals->v_right * (pev->size.x * 1.5));
vecRightSide = pev->origin + (gpGlobals->v_right * (pev->size.x * 1.5));
v_left = gpGlobals->v_right * -1;
leftPlane.InitializePlane(gpGlobals->v_right, vecLeftSide);
rightPlane.InitializePlane(v_left, vecRightSide);
backPlane.InitializePlane(gpGlobals->v_forward, pev->origin);
*/

/*
ALERT ( at_console, "LeftPlane: %f %f %f : %f\n", leftPlane.m_vecNormal.x, leftPlane.m_vecNormal.y, leftPlane.m_vecNormal.z, leftPlane.m_flDist );
ALERT ( at_console, "RightPlane: %f %f %f : %f\n", rightPlane.m_vecNormal.x, rightPlane.m_vecNormal.y, rightPlane.m_vecNormal.z, rightPlane.m_flDist );
ALERT ( at_console, "BackPlane: %f %f %f : %f\n", backPlane.m_vecNormal.x, backPlane.m_vecNormal.y, backPlane.m_vecNormal.z, backPlane.m_flDist );
*/

/*
CTalkSquadMonster* pSquadLeader = MySquadLeader();
for (int i = 0; i < MAX_SQUAD_MEMBERS; i++)
{
CTalkSquadMonster* pMember = pSquadLeader->MySquadMember(i);
if (pMember && pMember != this)
{
if (backPlane.PointInFront(pMember->pev->origin) &&
leftPlane.PointInFront(pMember->pev->origin) &&
rightPlane.PointInFront(pMember->pev->origin))
{
// this guy is in the check volume! Don't shoot!
return FALSE;
}
}
}
return TRUE;
*/
}

//=========================================================
// CanPlaySequence - determines whether or not the monster
// can play the scripted sequence or AI sequence that is
Expand Down
2 changes: 1 addition & 1 deletion dlls/monster/CBaseMonster.h
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ class EXPORT CBaseMonster : public CBaseToggle
BOOL FacingIdeal( void );

BOOL FCheckAITrigger( void );// checks and, if necessary, fires the monster's trigger target.
BOOL NoFriendlyFire( void );
virtual BOOL NoFriendlyFire( void );

BOOL BBoxFlat( void );

Expand Down
80 changes: 1 addition & 79 deletions dlls/monster/CTalkSquadMonster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1685,85 +1685,7 @@ BOOL CTalkSquadMonster::NoFriendlyFire(void)
return TRUE;
}

if (!m_hEnemy) {
// if there's no enemy, pretend there's a friendly in the way, so the grunt won't shoot.
return FALSE;
}

{
// this works better than the 2D plane checks (sc_tropical1_final snipers)
Vector gunPos = GetGunPosition();
Vector targetPos = m_hEnemy->Center();
TraceResult tr, tr2;
TRACE_HULL(gunPos, targetPos, dont_ignore_monsters, head_hull, edict(), &tr);

// do a line check too in case head hull hit a wall or something
TRACE_LINE(gunPos, targetPos, dont_ignore_monsters, edict(), &tr2);

CBaseEntity* phit = CBaseEntity::Instance(tr.pHit);
CBaseEntity* phit2 = CBaseEntity::Instance(tr2.pHit);

if (phit && IRelationship(phit) == R_AL) {
return FALSE;
}
if (phit2 && IRelationship(phit2) == R_AL) {
return FALSE;
}

return TRUE;
}

// legacy logic
/*
CPlane backPlane;
CPlane leftPlane;
CPlane rightPlane;
Vector vecLeftSide;
Vector vecRightSide;
Vector v_left;
//!!!BUGBUG - to fix this, the planes must be aligned to where the monster will be firing its gun, not the direction it is facing!!!
UTIL_MakeVectors(UTIL_VecToAngles(m_hEnemy->Center() - pev->origin));
//UTIL_MakeVectors ( pev->angles );
vecLeftSide = pev->origin - (gpGlobals->v_right * (pev->size.x * 1.5));
vecRightSide = pev->origin + (gpGlobals->v_right * (pev->size.x * 1.5));
v_left = gpGlobals->v_right * -1;
leftPlane.InitializePlane(gpGlobals->v_right, vecLeftSide);
rightPlane.InitializePlane(v_left, vecRightSide);
backPlane.InitializePlane(gpGlobals->v_forward, pev->origin);
*/

/*
ALERT ( at_console, "LeftPlane: %f %f %f : %f\n", leftPlane.m_vecNormal.x, leftPlane.m_vecNormal.y, leftPlane.m_vecNormal.z, leftPlane.m_flDist );
ALERT ( at_console, "RightPlane: %f %f %f : %f\n", rightPlane.m_vecNormal.x, rightPlane.m_vecNormal.y, rightPlane.m_vecNormal.z, rightPlane.m_flDist );
ALERT ( at_console, "BackPlane: %f %f %f : %f\n", backPlane.m_vecNormal.x, backPlane.m_vecNormal.y, backPlane.m_vecNormal.z, backPlane.m_flDist );
*/

/*
CTalkSquadMonster* pSquadLeader = MySquadLeader();
for (int i = 0; i < MAX_SQUAD_MEMBERS; i++)
{
CTalkSquadMonster* pMember = pSquadLeader->MySquadMember(i);
if (pMember && pMember != this)
{
if (backPlane.PointInFront(pMember->pev->origin) &&
leftPlane.PointInFront(pMember->pev->origin) &&
rightPlane.PointInFront(pMember->pev->origin))
{
// this guy is in the check volume! Don't shoot!
return FALSE;
}
}
}
return TRUE;
*/
return CBaseMonster::NoFriendlyFire();
}

//=========================================================
Expand Down

0 comments on commit 37841e7

Please sign in to comment.