perf(autohunt): avoid discarded A-star searches for attack sight lines

This commit is contained in:
shen
2026-10-16 23:14:48 -07:00
parent b9f5d737cb
commit ae0fc25a81
4 changed files with 25 additions and 8 deletions
+4 -1
View File
@@ -35,12 +35,15 @@ inline Point Toward(Point p, Point goal, float body) {
}
// Empty means unreachable within the loaded data/search budget, never permission to walk straight.
inline std::vector<Point> FindPath(Point start, Point goal, float arrival, const Walkable& walkable,
int budget=3500, float body=0.f) {
int budget=3500, float body=0.f, bool directOnly=false) {
if (!std::isfinite(start.x) || !std::isfinite(start.y) || !std::isfinite(goal.x) ||
!std::isfinite(goal.y) || arrival < 0 || body < 0 || budget <= 0 || Distance(start,goal)>40000.f) return {};
auto reaches=[&](Point p) { return Segment(p,Toward(p,goal,body),walkable); };
if (Distance(start,goal) <= arrival && reaches(start)) return {start};
if (reaches(start)) return {Toward(start,goal,body)};
// Attack/skill line checks reject a detour anyway. Do not run a 3500-node
// A* search for each monster in a crowded room just to discard that route.
if (directOnly) return {};
constexpr float cell=100.f;
// Grid is relative to the exact starting position, so the first step cannot cross an unchecked edge.
const int extent = int(std::ceil(Distance(start,goal)/cell))+25;
+1 -1
View File
@@ -757,7 +757,7 @@ class CPythonPlayer : public CSingleton<CPythonPlayer>, public IAbstractPlayer
bool __AutoHunt_CastSkill(DWORD slot, float now);
bool __AutoHunt_UpdateMount(CInstanceBase& main, float now);
bool __AutoHunt_UpdateRecovery(CInstanceBase& main, float now);
bool __AutoHunt_BuildPath(const TPixelPosition& goal, float arrival, std::vector<TPixelPosition>& path, float body = 0.f);
bool __AutoHunt_BuildPath(const TPixelPosition& goal, float arrival, std::vector<TPixelPosition>& path, float body = 0.f, bool directOnly = false);
bool __AutoHunt_MoveTo(const TPixelPosition& goal, float arrival, float now, float body = 0.f);
void __AutoHunt_ResetMovement();
void __AutoHunt_WalkAt(CInstanceBase& main, const TPixelPosition& goal, float now);
@@ -389,7 +389,7 @@ bool CPythonPlayer::__AutoHunt_CanAttackHere(CInstanceBase& main, CInstanceBase&
// the player cannot enter (a hydra beside the deck), so there is no line to test.
if (body > 0.f) return true;
std::vector<TPixelPosition> line;
return __AutoHunt_BuildPath(goal, 0.f, line, body) && line.size() == 1 && PixelDistance(line.back(), goal) <= body + 1.f;
return __AutoHunt_BuildPath(goal, 0.f, line, body, true) && line.size() == 1 && PixelDistance(line.back(), goal) <= body + 1.f;
}
DWORD CPythonPlayer::__AutoHunt_FindCloseTarget(CInstanceBase& main, int* count)
@@ -419,11 +419,12 @@ DWORD CPythonPlayer::__AutoHunt_FindCloseTarget(CInstanceBase& main, int* count)
bool CPythonPlayer::__AutoHunt_RequestPull(CInstanceBase& main, float now)
{
const int maxHP = GetStatus(POINT_MAX_HP);
int nearby = 0; __AutoHunt_FindCloseTarget(main, &nearby);
if (nearby >= 2 || now < m_fAutoHuntCrowdUntil ||
if (now < m_fAutoHuntCrowdUntil ||
m_kAutoHuntConfig.iGatherCount <= 0 || m_isAutoHuntGathering || now < m_fAutoHuntNextPullTime ||
main.IsInSafe() || maxHP <= 0 || GetStatus(POINT_HP) * 100 < maxHP * c_iAutoHuntGatherHPPercent)
return false;
int nearby = 0; __AutoHunt_FindCloseTarget(main, &nearby);
if (nearby >= 2) return false;
if (m_kAutoHuntConfig.bAttackStone) {
auto* target = NEW_FindActorPtr(__AutoHunt_FindTarget(main, now));
if (target && target->IsStone()) return false;
@@ -1153,7 +1154,7 @@ void CPythonPlayer::__AutoHunt_ResetMovement()
m_fAutoHuntTargetScanTime=0;
}
bool CPythonPlayer::__AutoHunt_BuildPath(const TPixelPosition& goal, float arrival, std::vector<TPixelPosition>& path, float body)
bool CPythonPlayer::__AutoHunt_BuildPath(const TPixelPosition& goal, float arrival, std::vector<TPixelPosition>& path, float body, bool directOnly)
{
auto* main=NEW_GetMainActorPtr();
auto& background=CPythonBackground::Instance();
@@ -1195,7 +1196,7 @@ bool CPythonPlayer::__AutoHunt_BuildPath(const TPixelPosition& goal, float arriv
probeAt(p.x,p.y,probe);
return !probe.blocked;
};
const auto points=AutoHuntNavigation::FindPath({start.x,start.y},{goal.x,goal.y},arrival,walkable,3500,body);
const auto points=AutoHuntNavigation::FindPath({start.x,start.y},{goal.x,goal.y},arrival,walkable,3500,body,directOnly);
path.clear();
for (const auto& point:points) {
TPixelPosition position=goal; position.x=point.x; position.y=point.y;
@@ -1290,7 +1291,7 @@ bool CPythonPlayer::__AutoHunt_CastSkill(DWORD slot, float now)
if (!target || !__AutoHunt_IsTargetAllowed(*main,*target)) return false;
TPixelPosition goal; target->NEW_GetPixelPosition(&goal);
std::vector<TPixelPosition> line;
if (!__AutoHunt_BuildPath(goal,0.f,line) || line.size()!=1 || PixelDistance(line.back(),goal)>1.f) return false;
if (!__AutoHunt_BuildPath(goal,0.f,line,0.f,true) || line.size()!=1 || PixelDistance(line.back(),goal)>1.f) return false;
}
if (main->IsMountingHorse() && !data->IsHorseSkill()) {
if (m_iAutoHuntMountState || !m_kAutoHuntConfig.bDismountSkill || now<m_fAutoHuntMountNextTime) return false;