@@ -1791,53 +1791,74 @@ bool CBaseMonster::BuildRoute( const Vector &vecGoal, int iMoveFlag, CBaseEntity
1791
1791
}
1792
1792
}
1793
1793
1794
- // last ditch, try nodes
1795
- if ( !FBitSet (buildRouteFlags, BUILDROUTE_NO_NODEROUTE) && FGetNodeRoute ( vecGoal ) )
1794
+ auto nearestBuildRoute = [&]()
1796
1795
{
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);
1806
1799
1807
- const Vector localMoveNearest = pev->origin + (vecGoal - pev->origin ).Normalize () * flDist;
1800
+ const Vector localMoveNearest = pev->origin + (vecGoal - pev->origin ).Normalize () * flDist;
1808
1801
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;
1811
1804
1812
- m_vecMoveGoal = localMoveNearest;
1805
+ m_vecMoveGoal = localMoveNearest;
1813
1806
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 ();
1816
1809
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);
1819
1812
1820
- if ((vecGoal - triangulatedNearest).Length2D () < (vecGoal - localMoveNearest).Length2D ())
1821
- {
1822
- if ((apex - triangulatedNearest).Length2D () < 1 )
1813
+ if ((vecGoal - triangulatedNearest).Length2D () < (vecGoal - localMoveNearest).Length2D ())
1823
1814
{
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);
1831
1824
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;
1834
1827
1835
- RouteSimplify ( pTarget );
1828
+ RouteSimplify ( pTarget );
1829
+ }
1830
+ m_vecMoveGoal = triangulatedNearest;
1831
+ return true ;
1836
1832
}
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
+ {
1838
1860
return true ;
1839
1861
}
1840
- return distToMoveStraight >= 1 .0f ;
1841
1862
}
1842
1863
1843
1864
// b0rk
0 commit comments