Skip to content
Permalink
Browse files

Fix for Predict Trajectory #796

  • Loading branch information...
SupSuper committed Aug 13, 2019
1 parent 0a0e09e commit 4fc8c8b3395f4a75f938f5e2d80e37ce9cea80ff
@@ -748,7 +748,7 @@ void DogfightState::update()
_ufo->setInterceptionProcessed(true);
int escapeCounter = _ufo->getEscapeCountdown();

if (escapeCounter > 0 )
if (escapeCounter > 0)
{
escapeCounter--;
_ufo->setEscapeCountdown(escapeCounter);
@@ -879,20 +879,21 @@ void GeoscapeState::time5Seconds()
continue;
}
// Can we actually fight it
if (!(*j)->isInDogfight())
if (!(*j)->isInDogfight() && u->getSpeed() <= (*j)->getRules()->getMaxSpeed())
{
_dogfightsToBeStarted.push_back(new DogfightState(this, (*j), u));
DogfightState *dogfight = new DogfightState(this, (*j), u);
_dogfightsToBeStarted.push_back(dogfight);
if ((*j)->getRules()->isWaterOnly() && u->getAltitudeInt() > (*j)->getRules()->getMaxAltitude())
{
popup(new DogfightErrorState((*j), tr("STR_UNABLE_TO_ENGAGE_DEPTH")));
_dogfightsToBeStarted.back()->setMinimized(true);
_dogfightsToBeStarted.back()->setWaitForAltitude(true);
dogfight->setMinimized(true);
dogfight->setWaitForAltitude(true);
}
else if ((*j)->getRules()->isWaterOnly() && !_globe->insideLand((*j)->getLongitude(), (*j)->getLatitude()))
{
popup(new DogfightErrorState((*j), tr("STR_UNABLE_TO_ENGAGE_AIRBORNE")));
_dogfightsToBeStarted.back()->setMinimized(true);
_dogfightsToBeStarted.back()->setWaitForPoly(true);
dogfight->setMinimized(true);
dogfight->setWaitForPoly(true);
}
if (!_dogfightStartTimer->isRunning())
{
@@ -219,8 +219,16 @@ void MovingTarget::move()
}
else
{
setLongitude(_dest->getLongitude());
setLatitude(_dest->getLatitude());
if (getDistance(_dest) > _speedRadian)
{
setLongitude(_meetPointLon);
setLatitude(_meetPointLat);
}
else
{
setLongitude(_dest->getLongitude());
setLatitude(_dest->getLatitude());
}
resetMeetPoint();
}
}
@@ -233,16 +233,14 @@ std::vector<Craft*> Target::getCraftFollowers() const
/**
* Returns the great circle distance to another
* target on the globe.
* @param target Pointer to other target.
* @param lon Longitude.
* @param lat Latitude.
* @returns Distance in radian.
*/
double Target::getDistance(const Target *target) const
{
return getDistance(target->getLongitude(), target->getLatitude());
}

double Target::getDistance(double lon, double lat) const
{
if (AreSame(lon, _lon) && AreSame(lat, _lat))
return 0.0;
return acos(cos(_lat) * cos(lat) * cos(lon - _lon) + sin(_lat) * sin(lat));
}

@@ -79,7 +79,8 @@ class Target
/// Gets the target's craft followers.
std::vector<Craft*> getCraftFollowers() const;
/// Gets the distance to another target.
double getDistance(const Target *target) const;
double getDistance(const Target *target) const { return getDistance(target->getLongitude(), target->getLatitude()); }
/// Gets the distance to another position.
double getDistance(double lon, double lat) const;
};

@@ -37,7 +37,7 @@ inline bool AreSame(float l, float r)

inline bool AreSame(double l, double r)
{
return std::fabs(l-r) <= DBL_EPSILON * std::max(1.0, std::max(std::fabs(l), std::fabs(r)));;
return std::fabs(l-r) <= DBL_EPSILON * std::max(1.0, std::max(std::fabs(l), std::fabs(r)));
}

inline float Round(float x)

0 comments on commit 4fc8c8b

Please sign in to comment.
You can’t perform that action at this time.