Skip to content

Commit 5ed741f

Browse files
committed
Fix for Predict Trajectory OpenXcom#42
1 parent 6b85ae9 commit 5ed741f

6 files changed

Lines changed: 14 additions & 6 deletions

File tree

‎src/Geoscape/GeoscapeState.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -879,7 +879,7 @@ void GeoscapeState::time5Seconds()
879879
continue;
880880
}
881881
// Can we actually fight it
882-
if (!(*j)->isInDogfight() && !(*j)->getDistance(u))
882+
if (!(*j)->isInDogfight())
883883
{
884884
_dogfightsToBeStarted.push_back(new DogfightState(this, (*j), u));
885885
if ((*j)->getRules()->isWaterOnly() && u->getAltitudeInt() > (*j)->getRules()->getMaxAltitude())

‎src/Savegame/Craft.cpp‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -685,6 +685,7 @@ void Craft::think()
685685
else
686686
{
687687
_takeoff--;
688+
resetMeetPoint();
688689
}
689690
if (reachedDestination() && _dest == (Target*)_base)
690691
{

‎src/Savegame/MovingTarget.cpp‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ void MovingTarget::move()
207207
calculateSpeed();
208208
if (_dest != 0)
209209
{
210-
if (getDistance(_dest) > _speedRadian)
210+
if (getDistance(_meetPointLon, _meetPointLat) > _speedRadian)
211211
{
212212
setLongitude(_lon + _speedLon);
213213
setLatitude(_lat + _speedLat);
@@ -216,6 +216,7 @@ void MovingTarget::move()
216216
{
217217
setLongitude(_dest->getLongitude());
218218
setLatitude(_dest->getLatitude());
219+
resetMeetPoint();
219220
}
220221
}
221222
}
@@ -240,7 +241,7 @@ void MovingTarget::calculateMeetPoint()
240241
_meetPointLon = _lon;
241242
}
242243

243-
if (!_dest || !Options::meetingPoint) return;
244+
if (!_dest || !Options::meetingPoint || reachedDestination()) return;
244245

245246
MovingTarget *t = dynamic_cast<MovingTarget*>(_dest);
246247
if (!t || !t->getDestination()) return;

‎src/Savegame/Target.cpp‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,12 @@ std::vector<Craft*> Target::getCraftFollowers() const
238238
*/
239239
double Target::getDistance(const Target *target) const
240240
{
241-
return acos(cos(_lat) * cos(target->getLatitude()) * cos(target->getLongitude() - _lon) + sin(_lat) * sin(target->getLatitude()));
241+
return getDistance(target->getLongitude(), target->getLatitude());
242+
}
243+
244+
double Target::getDistance(double lon, double lat) const
245+
{
246+
return acos(cos(_lat) * cos(lat) * cos(lon - _lon) + sin(_lat) * sin(lat));
242247
}
243248

244249
}

‎src/Savegame/Target.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ class Target
8080
std::vector<Craft*> getCraftFollowers() const;
8181
/// Gets the distance to another target.
8282
double getDistance(const Target *target) const;
83+
double getDistance(double lon, double lat) const;
8384
};
8485

8586
}

‎src/fmath.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@
3232

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

3838
inline bool AreSame(double l, double r)
3939
{
40-
return std::fabs(l-r) <= DBL_EPSILON;
40+
return std::fabs(l-r) <= DBL_EPSILON * std::max(1.0, std::max(std::fabs(l), std::fabs(r)));;
4141
}
4242

4343
inline float Round(float x)

0 commit comments

Comments
 (0)