Skip to content
Permalink
Browse files

Fix for Predict Trajectory #42

  • Loading branch information...
SupSuper committed Aug 12, 2019
1 parent 6b85ae9 commit 5ed741f45a1b2695cebe8c283198f768b63815f3
Showing with 14 additions and 6 deletions.
  1. +1 −1 src/Geoscape/GeoscapeState.cpp
  2. +1 −0 src/Savegame/Craft.cpp
  3. +3 −2 src/Savegame/MovingTarget.cpp
  4. +6 −1 src/Savegame/Target.cpp
  5. +1 −0 src/Savegame/Target.h
  6. +2 −2 src/fmath.h
@@ -879,7 +879,7 @@ void GeoscapeState::time5Seconds()
continue;
}
// Can we actually fight it
if (!(*j)->isInDogfight() && !(*j)->getDistance(u))
if (!(*j)->isInDogfight())
{
_dogfightsToBeStarted.push_back(new DogfightState(this, (*j), u));
if ((*j)->getRules()->isWaterOnly() && u->getAltitudeInt() > (*j)->getRules()->getMaxAltitude())
@@ -685,6 +685,7 @@ void Craft::think()
else
{
_takeoff--;
resetMeetPoint();
}
if (reachedDestination() && _dest == (Target*)_base)
{
@@ -207,7 +207,7 @@ void MovingTarget::move()
calculateSpeed();
if (_dest != 0)
{
if (getDistance(_dest) > _speedRadian)
if (getDistance(_meetPointLon, _meetPointLat) > _speedRadian)
{
setLongitude(_lon + _speedLon);
setLatitude(_lat + _speedLat);
@@ -216,6 +216,7 @@ void MovingTarget::move()
{
setLongitude(_dest->getLongitude());
setLatitude(_dest->getLatitude());
resetMeetPoint();
}
}
}
@@ -240,7 +241,7 @@ void MovingTarget::calculateMeetPoint()
_meetPointLon = _lon;
}

if (!_dest || !Options::meetingPoint) return;
if (!_dest || !Options::meetingPoint || reachedDestination()) return;

MovingTarget *t = dynamic_cast<MovingTarget*>(_dest);
if (!t || !t->getDestination()) return;
@@ -238,7 +238,12 @@ std::vector<Craft*> Target::getCraftFollowers() const
*/
double Target::getDistance(const Target *target) const
{
return acos(cos(_lat) * cos(target->getLatitude()) * cos(target->getLongitude() - _lon) + sin(_lat) * sin(target->getLatitude()));
return getDistance(target->getLongitude(), target->getLatitude());
}

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

}
@@ -80,6 +80,7 @@ class Target
std::vector<Craft*> getCraftFollowers() const;
/// Gets the distance to another target.
double getDistance(const Target *target) const;
double getDistance(double lon, double lat) const;
};

}
@@ -32,12 +32,12 @@

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

inline bool AreSame(double l, double r)
{
return std::fabs(l-r) <= DBL_EPSILON;
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 5ed741f

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