fix: let auto hunt recover from an occupied blocked terrain cell
This commit is contained in:
@@ -12,6 +12,19 @@ namespace AutoHuntNavigation {
|
||||
struct Point { float x, y; };
|
||||
inline float Distance(Point a, Point b) { return std::hypot(a.x-b.x, a.y-b.y); }
|
||||
using Walkable = std::function<bool(Point)>;
|
||||
// Terrain queries return -1 for unloaded data, 0 for clear, 1 for blocked.
|
||||
// Knockback can leave the actor inside a blocked cell. Permit leaving that
|
||||
// occupied cell, while keeping adjacent blocked cells and missing data closed.
|
||||
inline Walkable TerrainWalkable(Point start, const std::function<int(Point)>& attribute, float cell) {
|
||||
const bool startBlocked=attribute(start)>0;
|
||||
return [=](Point p) {
|
||||
const int value=attribute(p);
|
||||
if (value<0) return false;
|
||||
if (!value) return true;
|
||||
return startBlocked && std::floor(p.x/cell)==std::floor(start.x/cell) &&
|
||||
std::floor(p.y/cell)==std::floor(start.y/cell);
|
||||
};
|
||||
}
|
||||
inline bool Segment(Point a, Point b, const Walkable& walkable) {
|
||||
const int samples = std::max(1, int(std::ceil(Distance(a,b) / 40.f)));
|
||||
Point previous=a;
|
||||
|
||||
@@ -1182,6 +1182,12 @@ bool CPythonPlayer::__AutoHunt_BuildPath(const TPixelPosition& goal, float arriv
|
||||
// client's movement test only stops a sphere entering one.
|
||||
std::set<CGraphicObjectInstance*> around;
|
||||
{ CollisionProbe probe; probe.hits=&around; probeAt(start.x,start.y,probe); }
|
||||
const auto terrainWalkable=AutoHuntNavigation::TerrainWalkable({start.x,start.y},
|
||||
[&](AutoHuntNavigation::Point p) {
|
||||
BYTE attr=0;
|
||||
if (!background.GetAttr(p.x,p.y,&attr)) return -1;
|
||||
return (attr&CTerrainImpl::ATTRIBUTE_BLOCK) ? 1 : 0;
|
||||
},float(CTerrainImpl::HALF_CELLSCALE));
|
||||
auto walkable=[&](AutoHuntNavigation::Point p) {
|
||||
if (std::hypot(p.x-m_kPPosAutoHuntAnchor.x,p.y-m_kPPosAutoHuntAnchor.y)>bound) return false;
|
||||
// Where the player already stands is walkable whatever the attribute map says (a ship's deck
|
||||
@@ -1189,8 +1195,7 @@ bool CPythonPlayer::__AutoHunt_BuildPath(const TPixelPosition& goal, float arriv
|
||||
if (std::hypot(p.x-start.x,p.y-start.y)<1.f) return true;
|
||||
// Missing/unloaded terrain is not a traversable cell. A small footprint keeps turns off wall edges.
|
||||
for (const auto offset : {AutoHuntNavigation::Point{0,0}, {25,0}, {-25,0}, {0,25}, {0,-25}}) {
|
||||
BYTE attr=0;
|
||||
if (!background.GetAttr(p.x+offset.x,p.y+offset.y,&attr) || (attr&CTerrainImpl::ATTRIBUTE_BLOCK)) return false;
|
||||
if (!terrainWalkable({p.x+offset.x,p.y+offset.y})) return false;
|
||||
}
|
||||
CollisionProbe probe; probe.ignore=&around;
|
||||
probeAt(p.x,p.y,probe);
|
||||
|
||||
Reference in New Issue
Block a user