feat: Added threshold to unit movement

This commit is contained in:
Pax1601
2025-09-09 18:24:53 +02:00
parent 4e6701ff01
commit 73a7ea74f3
4 changed files with 11 additions and 3 deletions

View File

@@ -168,6 +168,12 @@ void Scheduler::handleRequest(string key, json::value value, string username, js
string WP = to_string(i);
double lat = path[i][L"lat"].as_double();
double lng = path[i][L"lng"].as_double();
if (path[i].has_number_field(L"threshold")) {
double threshold = path[i][L"threshold"].as_double();
Coords dest; dest.lat = lat; dest.lng = lng; dest.threshold = threshold;
newPath.push_back(dest);
continue;
}
Coords dest; dest.lat = lat; dest.lng = lng;
newPath.push_back(dest);
}

View File

@@ -765,6 +765,7 @@ void Unit::goToDestination(string enrouteTask)
}
}
// NOTE: if the current active path has a threshold set, that value will be used instead of the passed one
bool Unit::isDestinationReached(double threshold)
{
if (activeDestination != NULL)
@@ -774,7 +775,7 @@ bool Unit::isDestinationReached(double threshold)
{
double dist = 0;
Geodesic::WGS84().Inverse(p->getPosition().lat, p->getPosition().lng, activeDestination.lat, activeDestination.lng, dist);
if (dist < threshold)
if (dist < (activeDestination.threshold == 0? threshold: activeDestination.threshold))
{
log(unitName + " destination reached");
return true;