Skip to content

Commit 424583a

Browse files
committed
Use nearest path before nodes when trying to get close to enemy. Make Gargantua affected by npc_get_to_enemy_nearest
1 parent 06b3acc commit 424583a

File tree

2 files changed

+58
-34
lines changed

2 files changed

+58
-34
lines changed

dlls/gargantua.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,9 @@ class CGargantua : public CFollowingMonster
423423
bool CheckMeleeAttack1( float flDot, float flDist ) override; // Swipe
424424
bool CheckMeleeAttack2( float flDot, float flDist ) override; // Flames
425425
bool CheckRangeAttack1( float flDot, float flDist ) override; // Stomp attack
426+
bool WantsToGetCloseToEnemy() override {
427+
return true;
428+
}
426429
void SetObjectCollisionBox( void )
427430
{
428431
SetMyObjectCollisionBox(Vector( -80, -80, 0 ), Vector( 80, 80, 214 ));

dlls/monsters.cpp

Lines changed: 55 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1791,53 +1791,74 @@ bool CBaseMonster::BuildRoute( const Vector &vecGoal, int iMoveFlag, CBaseEntity
17911791
}
17921792
}
17931793

1794-
// last ditch, try nodes
1795-
if( !FBitSet(buildRouteFlags, BUILDROUTE_NO_NODEROUTE) && FGetNodeRoute( vecGoal ) )
1794+
auto nearestBuildRoute = [&]()
17961795
{
1797-
//ALERT( at_console, "Can get there on nodes\n" );
1798-
m_vecMoveGoal = vecGoal;
1799-
RouteSimplify( pTarget );
1800-
return true;
1801-
}
1802-
1803-
if (nearest && !FBitSet(buildRouteFlags, BUILDROUTE_NODEROUTE_ONLY))
1804-
{
1805-
SetBits(iMoveFlag, bits_MF_NEAREST_PATH);
1796+
if (nearest && !FBitSet(buildRouteFlags, BUILDROUTE_NODEROUTE_ONLY))
1797+
{
1798+
SetBits(iMoveFlag, bits_MF_NEAREST_PATH);
18061799

1807-
const Vector localMoveNearest = pev->origin + (vecGoal - pev->origin).Normalize() * flDist;
1800+
const Vector localMoveNearest = pev->origin + (vecGoal - pev->origin).Normalize() * flDist;
18081801

1809-
m_Route[0].vecLocation = localMoveNearest;
1810-
m_Route[0].iType = iMoveFlag | bits_MF_IS_GOAL;
1802+
m_Route[0].vecLocation = localMoveNearest;
1803+
m_Route[0].iType = iMoveFlag | bits_MF_IS_GOAL;
18111804

1812-
m_vecMoveGoal = localMoveNearest;
1805+
m_vecMoveGoal = localMoveNearest;
18131806

1814-
// Prevent playing walk/run animation while standing in place
1815-
const float distToMoveStraight = (localMoveNearest - pev->origin).Length2D();
1807+
// Prevent playing walk/run animation while standing in place
1808+
const float distToMoveStraight = (localMoveNearest - pev->origin).Length2D();
18161809

1817-
Vector apex;
1818-
const Vector triangulatedNearest = FTriangulateToNearest(pev->origin, vecGoal, flDist, pTarget, apex);
1810+
Vector apex;
1811+
const Vector triangulatedNearest = FTriangulateToNearest(pev->origin, vecGoal, flDist, pTarget, apex);
18191812

1820-
if ((vecGoal - triangulatedNearest).Length2D() < (vecGoal - localMoveNearest).Length2D())
1821-
{
1822-
if ((apex - triangulatedNearest).Length2D() < 1)
1813+
if ((vecGoal - triangulatedNearest).Length2D() < (vecGoal - localMoveNearest).Length2D())
18231814
{
1824-
m_Route[0].vecLocation = triangulatedNearest;
1825-
m_Route[0].iType = iMoveFlag | bits_MF_IS_GOAL;
1826-
}
1827-
else
1828-
{
1829-
m_Route[0].vecLocation = apex;
1830-
m_Route[0].iType = (iMoveFlag | bits_MF_TO_DETOUR);
1815+
if ((apex - triangulatedNearest).Length2D() < 1)
1816+
{
1817+
m_Route[0].vecLocation = triangulatedNearest;
1818+
m_Route[0].iType = iMoveFlag | bits_MF_IS_GOAL;
1819+
}
1820+
else
1821+
{
1822+
m_Route[0].vecLocation = apex;
1823+
m_Route[0].iType = (iMoveFlag | bits_MF_TO_DETOUR);
18311824

1832-
m_Route[1].vecLocation = triangulatedNearest;
1833-
m_Route[1].iType = iMoveFlag | bits_MF_IS_GOAL;
1825+
m_Route[1].vecLocation = triangulatedNearest;
1826+
m_Route[1].iType = iMoveFlag | bits_MF_IS_GOAL;
18341827

1835-
RouteSimplify( pTarget );
1828+
RouteSimplify( pTarget );
1829+
}
1830+
m_vecMoveGoal = triangulatedNearest;
1831+
return true;
18361832
}
1837-
m_vecMoveGoal = triangulatedNearest;
1833+
return distToMoveStraight >= 1.0f;
1834+
}
1835+
return false;
1836+
};
1837+
1838+
// If monster want to nearest route to enemy, it means he wants to get closer, so do this check before nodes
1839+
if (FBitSet(iMoveFlag, bits_MF_TO_ENEMY))
1840+
{
1841+
if (nearestBuildRoute())
1842+
{
1843+
return true;
1844+
}
1845+
}
1846+
1847+
// last ditch, try nodes
1848+
if( !FBitSet(buildRouteFlags, BUILDROUTE_NO_NODEROUTE) && FGetNodeRoute( vecGoal ) )
1849+
{
1850+
//ALERT( at_console, "Can get there on nodes\n" );
1851+
m_vecMoveGoal = vecGoal;
1852+
RouteSimplify( pTarget );
1853+
return true;
1854+
}
1855+
1856+
if (!FBitSet(iMoveFlag, bits_MF_TO_ENEMY))
1857+
{
1858+
if (nearestBuildRoute())
1859+
{
18381860
return true;
18391861
}
1840-
return distToMoveStraight >= 1.0f;
18411862
}
18421863

18431864
// b0rk

0 commit comments

Comments
 (0)