Special Aircraft Service

Battlefield - Airborne - Tactical (BAT) => BAT Missions and Campaigns => Topic started by: Wing Walker on April 22, 2023, 12:18:55 PM

Title: Limit the "vision" of AI?
Post by: Wing Walker on April 22, 2023, 12:18:55 PM
Is there a way to limit the "vision" of enemy AI aircraft to a shorter range?

I like big dogfights.

But the challenge is you have no idea who is who until you make a pass at them, or see them shoot.

Meanwhile the enemy A/C know you are enemy so far out you only see a little speck.

Would be nice to be able to change their reaction to something more real.

Title: Re: Limit the "vision" of AI?
Post by: FL2070 on April 22, 2023, 12:24:47 PM
Ah, if only... the AI has been chasing the player across the map, tens of kilometers out of sight, for the past twenty years... if a mod could be made that fixes that, I would declare its creator the greatest IL-2 modder of all time.
Title: Re: Limit the "vision" of AI?
Post by: Mick on April 22, 2023, 03:09:44 PM
... and not only that, but smart AI can also see through clouds and at night ...  :-[ :-X
Title: Re: Limit the "vision" of AI?
Post by: WxTech on April 23, 2023, 04:53:04 PM
In VisCheck.class we have the following, which is a basic first check on detectability at a distance. It's further modified by other factors.

Code: [Select]
    private static boolean commonCheck(Aircraft aircraft, Aircraft aircraft1, float f, float f1, float f2, float f3, float f4)
    {
        dist = (float)aircraft.pos.getAbsPoint().distance(aircraft1.pos.getAbsPoint());
        float f5 = aircraft1.FM.Wingspan / 2.0F;
        float f6 = (float)Math.atan2(f5, dist) / f5;
        if(f6 < 0.00015F)
            return false;

Assuming the threshold of 0.00015 is radians, that's 0.5 arcminute, or 1 arcminute (1/60 degree). It's a reasonable value for detecting a dark object against a light background when the contrast is sufficiently high.

If we wanted to apply a tighter constraint on detection distance across the board, we might start here by increasing the threshold value. For instance, doubling to 0.0003 would halve the basic detection distance. Of course, this should be carefully considered in conjunction with other visibility factors.

But what we really want to examine is the distance at which the AI can distinguish foe from friend. I'll see what I can find...
Title: Re: Limit the "vision" of AI?
Post by: WxTech on April 23, 2023, 05:21:39 PM
In the same class, for the following method variable "f" is the AI skill. Note how it's used to increment variable envLighting by 150 for each step in AI skill, on this line:

        envLighting += f * 150F;

I interpret envLighting as a measure of how well a plane can be seen, sort of a surrogate for contrast.

Note also how Main.cur().dotRangeFoe.dot() is used separately for calculating envLighting under the conditions of Sun and Moon lighting. This suggests a role is played by the dot range parameter?

Code: [Select]
    private static boolean checkAmbientPos(Point3d point3d, Point3d point3d1, Aircraft aircraft, Actor actor, float f, boolean flag)
    {
        envLighting = com.maddox.il2.ai.World.Sun().lightAtAlt((float)point3d1.z);
        float f1 = (float)(point3d.z * -1.2960000276507344E-005D);
        tmpVGr2.set(tmpVGr1);
        tmpVGr2.normalize();
        if(tmpVGr2.z >= (double)f1)
            envLighting += 0.05F;
        if(com.maddox.il2.ai.World.Sun().ToSun.z > 0.0F)
        {
            envLighting *= 0.7F * (float)Main.cur().dotRangeFoe.dot();
            return (double)envLighting > tmpVGr1.length();
        }
        boolean flag1 = false;
        Aircraft aircraft1 = null;
        if(actor instanceof Aircraft)
            aircraft1 = (Aircraft)actor;
        if(aircraft1 != null && (aircraft1.FM.CT.bAntiColLights || aircraft1.FM.AS.bLandingLightOn || aircraft1.FM.AS.bNavLightsOn || aircraft1.FM.AS.astateTankStates[0] > 4 || aircraft1.FM.AS.astateTankStates[1] > 4 || aircraft1.FM.AS.astateTankStates[2] > 4 || aircraft1.FM.AS.astateTankStates[3] > 4 || isShooting(aircraft1) || aircraft1.FM.AS.astateEngineStates[0] > 3 || aircraft1.FM.AS.astateEngineStates[1] > 3 || aircraft1.FM.AS.astateEngineStates[2] > 3 || aircraft1.FM.AS.astateEngineStates[3] > 3 || aircraft1.tmSearchlighted != 0L && Time.current() - aircraft1.tmSearchlighted < 1000L))
        {
            envLighting = 6000F;
            flag1 = true;
        }
        if(!flag1)
        {
            Vmoon.set(com.maddox.il2.ai.World.Sun().ToMoon);
            Vlight.set(com.maddox.il2.ai.World.Sun().ToLight);
            double d = v_1.dot(Vmoon);
            double d1 = v_1.dot(Vlight);
            d = Math.abs(d);
            d1 = Math.abs(d1);
            envLighting *= 2500F;
            if(d > 0.96599999999999997D || d1 > 0.96599999999999997D)
                envLighting = 0.5F * (float)Main.cur().dotRangeFoe.dot();
        }
        envLighting += f * 150F;
        if(flag)
        {
            if(Mission.isSingle() && aircraft != null && aircraft1 != null && (aircraft1.FM instanceof Maneuver) && (aircraft.FM instanceof Maneuver))
            {
                AirGroup airgroup = ((Maneuver)aircraft1.FM).Group;
                AirGroup airgroup1 = ((Maneuver)aircraft.FM).Group;
                if(airgroup1 != null && airgroup != null && !AirGroupList.groupInList(airgroup1.enemies[0], airgroup))
                    envLighting *= 0.5F;
            }
            return (double)World.Rnd().nextFloat(0.0F, envLighting) > tmpVGr1.length();
        } else
        {
            return (double)envLighting > tmpVGr1.length();
        }
    }


This portion below is interesting, as it suggests to this Java monkey that if both aircraft are maneuvering, the envLighting value is halved, which impacts the visibility distance threshold.

Code: [Select]
        if(flag)
        {
            if(Mission.isSingle() && aircraft != null && aircraft1 != null && (aircraft1.FM instanceof Maneuver) && (aircraft.FM instanceof Maneuver))
            {
                AirGroup airgroup = ((Maneuver)aircraft1.FM).Group;
                AirGroup airgroup1 = ((Maneuver)aircraft.FM).Group;
                if(airgroup1 != null && airgroup != null && !AirGroupList.groupInList(airgroup1.enemies[0], airgroup))
                    envLighting *= 0.5F;
            }
            return (double)World.Rnd().nextFloat(0.0F, envLighting) > tmpVGr1.length();
        } else
        {
            return (double)envLighting > tmpVGr1.length();
        }
Title: Re: Limit the "vision" of AI?
Post by: WxTech on April 23, 2023, 08:36:55 PM
In my first post I was too quick in determining the visibility threshold. For the algorithm as it is, for a plane having a 10m wingspan, the threshold result of 0.00015 corresponds to a distance of about 6.7km. This seems to accord with the point at which one's flight members call out bandits under good conditions in daytime.

It seems to me that this might prove to be a fruitful place to bring down the distance, by increasing the threshold condition. If I can successfully compile an altered class and try it out, I'll be back with a result...
Title: Re: Limit the "vision" of AI?
Post by: WxTech on April 23, 2023, 09:01:24 PM
Well, I increased the threshold value by a factor of 2 (from 0.00015 to 0.0003), and indeed, the distance at which my flight called out the bogies was reduced to the expected nearer distance of about 3-1/3km.

Is this the kind of reduction we would want across the board, as a new baseline? I would expect it to have an impact on the rate of engagements, and would likely have a bad, or at least unintended, impact on existing missions.

In any event, this seems to be an area for exploration for those who would find such changes useful.
Title: Re: Limit the "vision" of AI?
Post by: Mick on April 24, 2023, 03:59:10 AM
... I certainly am one of those who would find such changes useful ...  ;)

You currently hardly can't compete against AI, simply because they can see at night like in plain day time, can spot you through clouds, never overheat their engine, are impossible to catch up if you are taking off after one of them (unless you engage the "Auto" switch ...) etc ...  :-X
Title: Re: Limit the "vision" of AI?
Post by: WxTech on April 24, 2023, 04:47:34 AM
In that same VisCheck.class there is a very specific invocation of a method for each of clouds and darkness. I've not examined them in depth, but it seems that there is a check done for the imposition of a cloud. As for nighttime, it takes the Sun's elevation into account, and my own impression during play is that indeed as twilight deepens the AI ability to see does deteriorate.
Title: Re: Limit the "vision" of AI?
Post by: Frankiek on April 24, 2023, 05:22:02 AM
In the old days of 409 and 410 we had AI tweaking that reduced AI capacity to see through clouds and at night, no sniper gunners,  engines suffered from overheating and other things it seems to me that this work came to a stop when the new AI from TD 4.12 was introduced and all these mods become incompatible. We could maybe revisit these codes and verify if there is something that could be  used/adapted 
Title: Re: Limit the "vision" of AI?
Post by: Mick on April 24, 2023, 07:33:30 AM
... you're right, I forgot the AI sniper gunners, and AI pilots are aces in the art of deflection shooting too...  :-X

Well, if the situation could be reverted somewhat back, what an improvement this would be ...!  8)
Title: Re: Limit the "vision" of AI?
Post by: SAS~Storebror on April 24, 2023, 08:17:43 AM
Sniper gunners are a 4.10 (and earlier) thing (and have been eliminated in Ultrapack).
"See through clouds" and "see at night" are a 4.11 (and earlier) thing (and have been eliminated in Ultrapack).

This portion below is interesting, as it suggests to this Java monkey that if both aircraft are maneuvering

"aircraft.FM instanceof Maneuver" just tells whether an aircraft is AI (or player on autopilot to the same effect).

]cheers[
Mike
Title: Re: Limit the "vision" of AI?
Post by: Epervier on April 24, 2023, 08:52:42 AM
In the old days of 409 and 410 we had AI tweaking that reduced AI capacity to see through clouds and at night, no sniper gunners,  engines suffered from overheating and other things it seems to me that this work came to a stop when the new AI from TD 4.12 was introduced and all these mods become incompatible. We could maybe revisit these codes and verify if there is something that could be  used/adapted
In my 409/UP2.01 I use old Mods that improve all this:
- AAA do not shoot through clouds,
- AAA cannot see at night without a searchlight,
- AAA shoot at a much shorter distance without a searchlight,
- AAA do not fire in bad weather, if friendly aircraft are close,
- AI overheating.

And more...

Title: Re: Limit the "vision" of AI?
Post by: Frankiek on April 24, 2023, 09:06:25 AM
Me too... but one thing would be nice is to take the AI by surprise they are always aware of you and as soon as you reach 300-350 meters  they start evading no matter if you are coming from the sun or clouds (rookies are the exception).

On the other hand this is also the fun part and I can compensate by flying in wonder woman view :)
Title: Re: Limit the "vision" of AI?
Post by: WxTech on April 24, 2023, 12:49:25 PM
I'd like to examine those old modded classes...
Title: Re: Limit the "vision" of AI?
Post by: Epervier on April 24, 2023, 12:59:11 PM
I'd like to examine those old modded classes...
Check your PM !  ;)
Title: Re: Limit the "vision" of AI?
Post by: wern moldy on April 24, 2023, 01:46:24 PM
All I can say is........it's about f*ckin' time this conversation took place. For my money, you can throw all the candy floss you like at this sim, but if the game play sucks then what's the point?! It's the worst fault of the game; and never receives attention. To add candy alone is akin to putting a new paint job on a car with a faulty gear box. In any other field, an activity like this would be regarded as complete stupidity.
Anyone to achieve this with some measure of success would certainly receive my gratitude, which would be to regularly contribute $$ to this forum once again.
It doesn't have to be perfect; hell, nothing else about the game is, but it becomes painfully obvious to anyone who's played it long enough to notice, that the better you get at it, the better the AI gets! A decade ago when I was a poor flyer and a lousy shot, the AI didn't need to cheat!
I suggest that anyone making the attempt.... try and stop the bastards ganging up on you as well; I really hate fighting the war alone........
Title: Re: Limit the "vision" of AI?
Post by: WxTech on April 24, 2023, 08:38:24 PM
Gabriel sent me a number of 4.09 mods. I just adapted the code for the AI engine overheat mod to work in B.A.T. using my v1.6 Effects mod. That is, you must be using my Effects pack due to the new effects.

I'll look at a cooking up a version that doesn't require to use my effects mod...

After a test flight I get the distinct impression of it working. The mod can be got in this thread:

https://www.sas1946.com/main/index.php/topic,70706.0.html
Title: Re: Limit the "vision" of AI?
Post by: WxTech on April 24, 2023, 10:03:29 PM
Well, with the reduced threshold distance set in VisCheck.class, and playing a mission having AAA, the game crashes due to a null pointer error in ai\ground\NearestEnemies.class, method getAFoundEnemy. Clearly, a more wide-ranging approach is necessary! Sigh...   :-|