OpenXcom Forum

OpenXcom => Troubleshooting => Topic started by: Sander Bouwhuis on August 11, 2019, 10:16:07 am

Title: Go to predicted UFO location
Post by: Sander Bouwhuis on August 11, 2019, 10:16:07 am
When I turn on the 'Project predicted trajectory' setting, my interceptors go to the predicted UFO location, but then don't attack it. So, the UFO will just fly off and the interceptor just sits there idle.
Am I misunderstanding this feature? As it is now it is very annoying to constantly micromanage the interceptors (especially when you have 3 or so going to different UFOs at the same time).
Title: Re: Go to predicted UFO location
Post by: R1dO on August 11, 2019, 04:05:51 pm
You are not misunderstanding this feature. It is a bug that has been reported multiple times but turned out to be very hard to reproduce.

Most veteran players even advice against the feature (it has some other drawbacks as well according to them), even to the point that OXCE (a fork focused on more modding options and with Quality of life improvements) decided to remove that functionality.





Title: Re: Go to predicted UFO location
Post by: Sander Bouwhuis on August 12, 2019, 07:15:41 pm
Hard to reproduce?
Just send me a debug/logging build I can reproduce it 100% of the time. I have NEVER seen any time it actually worked.
Title: Re: Go to predicted UFO location
Post by: SupSuper on August 12, 2019, 10:06:44 pm
It's hard to reproduce and fix because the behavior changes very subtly between platforms, and even if we can reproduce it we can't exactly determine why it happens, nobody knows how to implement the feature 100% effectively. Perhaps I should add an (experimental) to the description.

Anyways let me know if the latest round of "fixes" helps. If not post your 100% reproducible save.
Title: Re: Go to predicted UFO location
Post by: kevL on August 12, 2019, 11:20:10 pm
Sup,

i'm not sure but ...

Code: [Select]
/**
 * Gets the radian-angle to another Target on the Globe.
 * @param target - pointer to other target
 * @return, distance in radians
 */
double Target::getDistance(const Target* const target) const
{
    const double lonTarget (target->getLongitude());
    const double latTarget (target->getLatitude());

    if (AreSameTwo(
                _lon, lonTarget,
                _lat, latTarget))
    {
        return 0.;
    }
    // else the formula below returns NaN <-----

    return std::acos(
                std::cos(_lat)
                * std::cos(latTarget)
                * std::cos(lonTarget - _lon)
            + std::sin(_lat)
                * std::sin(latTarget));
}

might be worth a shot,



EDIT: I ended up writing this and sprinkling it around in various places (not necessarily the predict-destination routines exclusively)

Code: [Select]
/**
 * Checks if val1 or val2 (lon,lat) is NaN or Inf.
 * @note Checks validity of Globe coordinates.
 * @param val1 - x-coordinate
 * @param val2 - y-coordinate
 * @return, true if either val1 or val2 is NaN or Inf
 */
template<class _Tx>
inline bool isNaNorInf(
        const _Tx& val1,
        const _Tx& val2)
{
    if (   std::isnan(val1) || std::isnan(val2)
        || std::isinf(val1) || std::isinf(val2))
    {
        return true;
    }
    return false;
}
Title: Re: Go to predicted UFO location
Post by: SupSuper on August 12, 2019, 11:44:48 pm
Sup,

i'm not sure but ...

might be worth a shot,
Nice catch. I'm pretty sure we always use reachDestination first but can't hurt to add an extra check. I don't wanna add too much though because this is code that has to run repeatedly each tick.

In most cases a NaN will just return false anyways so it's mostly harmless.
Title: Re: Go to predicted UFO location
Post by: kevL on August 12, 2019, 11:48:23 pm
ok, just something to keep a mind on i guess
Title: Re: Go to predicted UFO location
Post by: Sander Bouwhuis on August 13, 2019, 11:24:12 pm
Ok, I tested some versions (and attached a save game).

v2019-08-08 21:43
100% fails. The ufo coming from Antarctica overshoots the UFO and stays idling for a while until continuing pursuit.

v2019-08-12 03:30
Sort of works. I see the engagement window flashing but not actually opening. It then immediately pursues the UFO.

v2019-08-12 22:21
Sort of works. I see the engagement window flashing but not actually opening. It then immediately pursues the UFO.

v2019-08-13 12:58
Sort of works. I see the engagement window flashing but not actually opening. It then immediately pursues the UFO.


Is it because the UFOs are flying so fast that there will be a millisecond of engagement before the UFO outruns the Interceptor again?
Title: Re: Go to predicted UFO location
Post by: R1dO on August 13, 2019, 11:49:51 pm
You guessed correctly.

The crafts is able to intercept (because it is approaching from the front).
However the ufo speed is 2200, you interceptor can only do 2100, e.g. the ufo outruns your interceptor immediately.
Title: Re: Go to predicted UFO location
Post by: Meridian on August 13, 2019, 11:58:44 pm
But why does it happen only when Predict UFO Trajectory is turned on?
And not when it is turned off...
Title: Re: Go to predicted UFO location
Post by: R1dO on August 14, 2019, 01:11:30 am
Because the prediction is too good at it's job ;)

Joking aside, as far as i understand from the code (supsuper can probably explain it much better):

Predict Ufo Trajectory sets the destination of the craft to the exact point where they would meet, satisfying the condition for "interception" when both the craft and the ufo arrive there at the same moment.

Default behavior (option off) is for the craft to set it's destination to the last known position of the ufo.
For this collision course case it is highly likely for the craft destination to lie behind the actual meeting point. E.g. craft has to turn around and start chasing the ufo again. The condition for "interception" is not met, and since the ufo is faster we see the classic chase we all know too well.
Title: Re: Go to predicted UFO location
Post by: SupSuper on August 14, 2019, 03:08:40 am
New fix is up, let me know if it's more consistent between both modes. Mainly if there's still any cases where a craft gets "stuck" and stops chasing the UFO.
Title: Re: Go to predicted UFO location
Post by: kevL on August 14, 2019, 12:24:55 pm
anyone?
Title: Re: Go to predicted UFO location
Post by: Sander Bouwhuis on August 14, 2019, 10:15:27 pm
Ok, I tested it with the new 2019-08-14 02:02 version.
It seems to work significantly better now. For me, it seems like this is fixed.
Maybe there are some edge cases, but now I can turn this option on again. Thanks for the swift fixes!
Title: Re: Go to predicted UFO location
Post by: N7Kopper on September 28, 2019, 12:46:22 pm
You are not misunderstanding this feature. It is a bug that has been reported multiple times but turned out to be very hard to reproduce.

Most veteran players even advice against the feature (it has some other drawbacks as well according to them), even to the point that OXCE (a fork focused on more modding options and with Quality of life improvements) decided to remove that functionality.
I'm assuming the downsides aren't just "makes the game easier through use of Actually Sensible Interceptor Pilots" and has more to do with implementation (or the pilot AI needing to cheat by reading the UFO's planned moves). I mean, it feels good to tell your pilots "Don't go where the X-Ray is, follow the damn flight pattern!" but if it doesn't actually help, or it cheats for you...

(yes i prefer 1rn in fire emblem why'd you ask)
Title: Re: Go to predicted UFO location
Post by: Meridian on September 28, 2019, 12:51:56 pm
I'm assuming the downsides aren't just "makes the game easier through use of Actually Sensible Interceptor Pilots" and has more to do with implementation (or the pilot AI needing to cheat by reading the UFO's planned moves). I mean, it feels good to tell your pilots "Don't go where the X-Ray is, follow the damn flight pattern!" but if it doesn't actually help, or it cheats for you...

(yes i prefer 1rn in fire emblem why'd you ask)

It doesn't cheat.

But there's a multitude of subtle problems with it, making it basically unusable (without carefully checking what it is doing, which defies its purpose). In OXC.

In OXCE, it's even worse.
(or would be... I just removed it completely)
Title: Re: Go to predicted UFO location
Post by: N7Kopper on September 28, 2019, 01:20:42 pm
It doesn't cheat.

But there's a multitude of subtle problems with it, making it basically unusable (without carefully checking what it is doing, which defies its purpose). In OXC.

In OXCE, it's even worse.
(or would be... I just removed it completely)
So implementation then. Gotcha.
Title: Re: Go to predicted UFO location
Post by: SupSuper on October 04, 2019, 10:22:42 pm
The vanilla behavior goes to where the UFO is, the predicted behavior goes to where the UFO will be. The latter is more effective if the UFO keeps flying in a straight line.
But UFOs randomly change direction, which neither behavior can guess (that would be cheating), so you're always at the mercy of the RNG.
Title: Re: Go to predicted UFO location
Post by: Sander Bouwhuis on October 05, 2019, 10:57:20 pm
Maybe a stupid/obvious idea, but why don't the airplanes simply constantly adjust their heading so as to fly directly to the UFO's current position? That wouldn't be cheating, and the player wouldn't have to micromanage the multiple airborne vehicles to make sure they don't stand still without actually pursuing their targeted UFO.
Title: Re: Go to predicted UFO location
Post by: ohartenstein23 on October 05, 2019, 11:43:51 pm
Maybe a stupid/obvious idea, but why don't the airplanes simply constantly adjust their heading so as to fly directly to the UFO's current position? That wouldn't be cheating, and the player wouldn't have to micromanage the multiple airborne vehicles to make sure they don't stand still without actually pursuing their targeted UFO.

That's exactly what happens when you have the "predict UFO trajectory" turned off.

Perhaps the way to improve the prediction option would be to have it turn off automatically when the interceptor and the target are under a certain distance from each other. That distance could even me related to the relative speeds of the interceptor and the UFO to help prevent overshooting the target when the interceptor is much faster.