mirror of
https://github.com/Pax1601/DCSOlympus.git
synced 2025-10-29 16:56:34 +00:00
feat: New predicting algorithm
This commit is contained in:
@@ -242,7 +242,12 @@ void GroundUnit::AIloop()
|
||||
if (!getHasTask()) {
|
||||
std::ostringstream taskSS;
|
||||
taskSS.precision(10);
|
||||
taskSS << "{id = 'FireAtPoint', lat = " << targetPosition.lat << ", lng = " << targetPosition.lng << ", radius = 100}";
|
||||
if (targetPosition.alt == NULL) {
|
||||
taskSS << "{id = 'FireAtPoint', lat = " << targetPosition.lat << ", lng = " << targetPosition.lng << ", radius = 100}";
|
||||
}
|
||||
else {
|
||||
taskSS << "{id = 'FireAtPoint', lat = " << targetPosition.lat << ", lng = " << targetPosition.lng << ", alt = " << targetPosition.alt << ", radius = 100}";
|
||||
}
|
||||
Command* command = dynamic_cast<Command*>(new SetTask(groupName, taskSS.str(), [this]() { this->setHasTaskAssigned(true); }));
|
||||
scheduler->appendCommand(command);
|
||||
setHasTask(true);
|
||||
@@ -429,9 +434,22 @@ void GroundUnit::AIloop()
|
||||
taskString += "Missing on purpose. Valid target at range: " + to_string((int) round(distance)) + "m";
|
||||
|
||||
double correctedAimTime = aimTime;
|
||||
double dstep = 0;
|
||||
double vstep = muzzleVelocity;
|
||||
double dt = 0.1;
|
||||
double k = 0.0086;
|
||||
double gdelta = 9.81;
|
||||
|
||||
/* Approximate the flight time */
|
||||
if (muzzleVelocity != 0)
|
||||
correctedAimTime += distance / muzzleVelocity;
|
||||
unsigned int stepCount = 0;
|
||||
if (muzzleVelocity != 0) {
|
||||
while (dstep < distance && stepCount < 1000) {
|
||||
dstep += vstep * dt;
|
||||
vstep -= (k * vstep + gdelta) * dt;
|
||||
stepCount++;
|
||||
}
|
||||
correctedAimTime += stepCount * dt;
|
||||
}
|
||||
|
||||
/* If the target is in targeting range and we are in highest precision mode, target it */
|
||||
if (distance < targetingRange && shotsScatter == ShotsScatter::LOW) {
|
||||
|
||||
@@ -619,6 +619,11 @@ void Scheduler::handleRequest(string key, json::value value, string username, js
|
||||
double lat = value[L"location"][L"lat"].as_double();
|
||||
double lng = value[L"location"][L"lng"].as_double();
|
||||
Coords loc; loc.lat = lat; loc.lng = lng;
|
||||
|
||||
if (value[L"location"].has_number_field(L"alt")) {
|
||||
loc.alt = value[L"location"][L"alt"].as_double();
|
||||
}
|
||||
|
||||
Unit* unit = unitsManager->getGroupLeader(ID);
|
||||
if (unit != nullptr) {
|
||||
unit->setTargetPosition(loc);
|
||||
|
||||
Reference in New Issue
Block a user