SUBSIM Radio Room Forums

SUBSIM Radio Room Forums (https://www.subsim.com/radioroom/index.php)
-   SH5 Mods Workshop (https://www.subsim.com/radioroom/forumdisplay.php?f=249)
-   -   [TEC] Some aircraft AI tests/questions (https://www.subsim.com/radioroom/showthread.php?t=248833)

kapuhy 08-08-22 03:59 PM

Happy to report some progress :)

I figured out the culprit behind constant crashing into water. Planes have the "Avoid Impact" strategy which should prevent them from crashing, but other strategies did not have a condition preventing them from being applied when plane is "avoiding impact", which caused planes to try to follow two different strategies at once.

Adding and !Plane:StrafingTooClose() to bombing/strafing strategy solves the crashing problem - I ran my 6-plane test mission 10 times and only had two instances of plane crashing into water, when before I had on average 2 crashes per single test:

 
strategy BombCourseStrafe(Plane)
{
precond
{
Plane:HasCannons() and Plane:CanFireCannons() and Plane:GetContactRelDistOnWater() <= 3500 and Ship:GetContactSpeed() > 5 and !Plane:StrafingTooClose()
}
action
{
Plane:Strafe(1.0);
Ship:SetThrottleRatio(1.0);
}
}

strategy BombCourseSlow(Plane)
{
precond
{
Plane:GetContactRelDistOnWater() <= 3500 and Ship:GetContactSpeed() <= 5 and !Plane:StrafingTooClose()
}
action
{
Plane:SetCourseBombs();
#Ship:SetThrottle(1.0);
}
}


Downside (there's always one) is that planes occasionally break off the attack without dropping bombs like in original IRAI script. This seems to be dependent on plane characteristics now, though: for example Swordfish never finishes the run, but Catalina almost always does drop bombs. So the next thing to do is figuring out how to tweak "reluctant" planes to be more agressive.

Overall, for 10 attacks:
- 2 out of 60 planes crashed
- 7 out of 10 Uboats destroyed (most effective planes: Catalina, Sunderland, Martlet. B17 mostly misses, Swordfish and Liberator break off the attack)
- 3 Uboats survived, 1 with heavy damage but able to limp back to base

Jeff-Groves 08-08-22 04:05 PM

Good job Mate!!
:yeah:

Just as I stated before? TDW didn't have everything right.

Now.
Catalina is a Type=304
SwordFish is a Type=303
Try changing that

gap 08-08-22 05:01 PM

Quote:

Originally Posted by Jeff-Groves (Post 2822107)
Good job Mate!!
:yeah:

I second that :up:

Quote:

Originally Posted by Jeff-Groves (Post 2822107)
Now.
Catalina is a Type=304
SwordFish is a Type=303
Try changing that

My bet: minimum height, engine HP, aircraft mass, maximum speed. If flight physics were more accurate I would have mentioned drag coefficients as well, but I think those have little effect on SH aircraft.

gap 08-09-22 04:50 AM

Quote:

Originally Posted by kapuhy (Post 2822104)
 
strategy BombCourseStrafe(Plane)
{
precond
{
Plane:HasCannons() and Plane:CanFireCannons() and Plane:GetContactRelDistOnWater() <= 3500 and Ship:GetContactSpeed() > 5 and !Plane:StrafingTooClose()
}
action
{
Plane:Strafe(1.0);
Ship:SetThrottleRatio(1.0);
}
}

strategy BombCourseSlow(Plane)
{
precond
{
Plane:GetContactRelDistOnWater() <= 3500 and Ship:GetContactSpeed() <= 5 and !Plane:StrafingTooClose()
}
action
{
Plane:SetCourseBombs();
#Ship:SetThrottle(1.0);
}
}

Probably I am going to ask some silly questions but...
  • Does the question mark before a precondition, work the same way as the logical operator 'not' in other programming languages?

  • Why 'Plane:HasCannons() and Plane:CanFireCannons()'? Wouldn't 'Plane:HasBombs() and Plane:CanFireBombs()' be more logical preconditions for the 'BombCourseStrafe(Plane)' and 'BombCourseSlow(Plane)' strategies?

  • Do the 'Ship:SetThrottleRatio(1.0)' commands apply to the attacking aircraft or to the attacked sea unit? In the latter case, shouldn't them be part of ship, rather than aircraft, AI strategies?

kapuhy 08-09-22 05:01 AM

1 Attachment(s)
Quote:

Originally Posted by gap (Post 2822175)
[*]Does the question mark before a precondition, work the same way as the logical operator 'not' in other programming languages?

Exclamation mark? Yes, that's exactly what it does.


Quote:

Originally Posted by gap (Post 2822175)
Why 'Plane:HasCannons() and Plane:CanFireCannons()'? Wouldn't 'Plane:HasBombs() and Plane:CanFireBombs()' be more logical preconditions for the 'BombCourseStrafe(Plane)' and 'BombCourseSlow(Plane)' strategies?

Jeff's wrote above that Strafe action might not work well without these conditions. I don't see difference in behaviour but added them just in case. As for Plane:HasBombs() and Plane:CanFireBombs(), they are already preconditions to this strategy's parent strategy.

Quote:

Originally Posted by gap (Post 2822175)
[*]Do the 'Ship:SetThrottleRatio(1.0)' commands apply to the attacking aircraft or to the attacked sea unit? In the latter case, shouldn't them be part of ship, rather than aircraft, AI strategies?[/LIST]

In this case they apply to the plane.

In SH5, command syntax is:

UnitType:Command(parameters) where unit type might be Plane, Sub or Ship (edit: and, possibly, CostalDefense - it's not used by any scripts but has its own AI commander so... possibly). Now, commands only work with certain types so if you try to write Plane:SetThrottleRatio, game will CTD or ignore command. But if you put Ship:SetThrottleRatio in a strategy used by the plane, game will happily accept it and apply to the plane. I don't know why it works like this, but it does. It was similar with submarine deck guns, which started working after putting "Ship" type condition in their script.

EDIT: by the way,I attach the airplane script as it is now if you or someone else would like to take a look.

gap 08-09-22 06:52 AM

Quote:

Originally Posted by kapuhy (Post 2822178)
Exclamation mark? Yes, that's exactly what it does.

Ops, sorry, exclamation mark is what I meant :doh:

Quote:

Originally Posted by kapuhy (Post 2822178)
Jeff's wrote above that Strafe action might not work well without these conditions. I don't see difference in behaviour but added them just in case. As for Plane:HasBombs() and Plane:CanFireBombs(), they are already preconditions to this strategy's parent strategy.

Well, in common language, 'strafing' is done by attack aircraft when they shoot their cannons while flying low in the sky toward their target. This strategy doesn't encompass the usage of bombs, but apparently this is not the case in SH5. The only shortcoming I see in keeping those preconditions is that, if an aircraft has finished its bullets, it won't attack even though it still has plenty of bombs. Stock aircraft have a nearly endless bullet storage, but we might face a similar problem if we give them a more realistic ammo outfit.
All in all, I think that using Plane:HasBombs() and Plane:CanFireBombs() OR Plane:HasCannons() and Plane:CanFireCannons() as precondition of the parent strategy, might be preferable :hmmm:

Quote:

Originally Posted by kapuhy (Post 2822178)
In this case they apply to the plane.

In SH5, command syntax is:

UnitType:Command(parameters) where unit type might be Plane, Sub or Ship (edit: and, possibly, CostalDefense - it's not used by any scripts but has its own AI commander so... possibly). Now, commands only work with certain types so if you try to write Plane:SetThrottleRatio, game will CTD or ignore command. But if you put Ship:SetThrottleRatio in a strategy used by the plane, game will happily accept it and apply to the plane. I don't know why it works like this, but it does. It was similar with submarine deck guns, which started working after putting "Ship" type condition in their script.

Maybe devs wanted to implement different throttle commands for different unit types, but at the end they only implemented one for all of them.

Quote:

Originally Posted by kapuhy (Post 2822178)
EDIT: by the way,I attach the airplane script as it is now if you or someone else would like to take a look.

I will :up:

kapuhy 08-09-22 07:08 AM

Quote:

Originally Posted by gap (Post 2822188)
Well, in common language, 'strafing' is done by attack aircraft when they shoot their cannons while flying low in the sky toward their target. This strategy doesn't encompass the usage of bombs, but apparently this is not the case in SH5.

Note on this one: regardless of real word meanings, in SH5 either Strafe or SetCourseBombs are part of Lead strategy telling plane how to fly, and neither causes or denies plane from using its weapons. There is completely separate strategy for this which basically boils down to "If you have weapon X and can fire it - fire it!". So no matter which maneuver the plane is doing at the moment, if it somehow finds itself seeing target in its crosshairs, it should fire.

The problem with SetCourseBombs is, as I see it, that despite its name it does not put the plane in position that is considers correct to drop bombs (unless target is motionless, which leads me to believe problem is connected to not leading the target). So the maneuver part of the script is executed over and over while shooting part waits for target to enter the crosshairs. Strafe behaviour works because it (by pure accident) repeatedly puts the plane in position where it thinks it has a chance to hit.

Jeff-Groves 08-09-22 07:32 AM

Quote:

Originally Posted by kapuhy (Post 2822178)
if you try to write Plane:SetThrottleRatio, game will CTD or ignore command. But if you put Ship:SetThrottleRatio in a strategy used by the plane, game will happily accept it and apply to the plane. I don't know why it works like this, but it does.


Maybe this?
https://www.subsim.com/radioroom/pic...ictureid=12670

gap 08-09-22 08:33 AM

Quote:

Originally Posted by kapuhy (Post 2822189)
Note on this one: regardless of real word meanings, in SH5 either Strafe or SetCourseBombs are part of Lead strategy telling plane how to fly, and neither causes or denies plane from using its weapons. There is completely separate strategy for this which basically boils down to "If you have weapon X and can fire it - fire it!". So no matter which maneuver the plane is doing at the moment, if it somehow finds itself seeing target in its crosshairs, it should fire.

The problem with SetCourseBombs is, as I see it, that despite its name it does not put the plane in position that is considers correct to drop bombs (unless target is motionless, which leads me to believe problem is connected to not leading the target). So the maneuver part of the script is executed over and over while shooting part waits for target to enter the crosshairs. Strafe behaviour works because it (by pure accident) repeatedly puts the plane in position where it thinks it has a chance to hit.

Okay, I see your point.

Plane:SetCourseBombs tells aircraft to follow a trajectory which in theory should be optimal either for level or dive bombing (depending on sim file setting), but apparently it is bugged and it won't work on moving targets.
Plane:Strafe, on turn, should be more appropriate for cannon strafe runs, but due to the above limitations it happens to increase bombing accuracy over the previous command.

My point is: seeing that Plane:Strafe is the most effective command against moving targets, no matter the weapon used, game AI should trigger the relative strategy if the attacking plane has either gun bullets OR bombs left. With your current script, aircraft won't strafe if they have no cannon / cannon bullets, no matter if they can still drop bombs. That would be correct if strafing was used in game as in real life, and it still is if you want to set up distinct gun strafing and bombing strategies against stationary targets, but it is not according to the new usage you are doing of the said command against fast-moving targets.

I hope I made myself clearer this time. :salute:

Quote:

Originally Posted by Jeff-Groves (Post 2822193)

:up:

Jeff-Groves 08-09-22 12:22 PM

I'd think the structure is like this.........

AirPlane.aix is used by the Airplanes.
So Plane:statement checks the Plane for bombs and such.
In there is Ship:command or whatever..... That seems to be jumping to what I pointed out in the Sim settings.
:hmmm:

kapuhy 08-09-22 01:24 PM

Quote:

Originally Posted by Jeff-Groves (Post 2822234)
I'd think the structure is like this.........

AirPlane.aix is used by the Airplanes.
So Plane:statement checks the Plane for bombs and such.
In there is Ship:command or whatever..... That seems to be jumping to what I pointed out in the Sim settings.
:hmmm:

Or, even:

https://i.imgur.com/or9Y2Cx.png

If AI is governed by AIcommander controllers (which would be logical, wouldn't it?) then Submarine or Plane AI contains ship AI but not vice versa. Kinda explains why I could get AI sub guns working but similar trick didn't work with torpedoes on surface ships...

Jeff-Groves 08-09-22 01:35 PM

Maybe the torpedos on suface Ships are looking for the
wpn_SubTorpedoSys Controller?
The AI Subs have that.

I also wonder if we couldn't use the DIVE on AirPlanes and set it to say +5 meters above the water?

gap 08-09-22 01:47 PM

Quote:

Originally Posted by kapuhy (Post 2822240)
Or, even:

https://i.imgur.com/or9Y2Cx.png

If AI is governed by AIcommander controllers (which would be logical, wouldn't it?) then Submarine or Plane AI contains ship AI but not vice versa. Kinda explains why I could get AI sub guns working but similar trick didn't work with torpedoes on surface ships...

It makes sense. Besides the ones that we already know, we might find more 'ship' commands which work on ships as well as on other unit types.

Changin of topic, while looking into Airplane.aix I have noticed that several commands accept numeric parameters. Some of them are pretty obvious, e.g. Ship:SetThrottle() where 1.0 means full throttle and 0.0 means engine off, or Ship:TurnToHeading() whose arguments are likely to be angles in degrees, but in most cases their meaning is not so clear. I am under the impression that the parameters accepted by some commands are chances that those commands will be run, but that should be tested. Any ideas? :hmm2:

Jeff-Groves 08-09-22 01:52 PM

You mean the Random?
I'm thinking the Random numbers are start and final
So if Random(15, 20)
The numbers are drawn from 15 to 20
:hmmm:

gap 08-09-22 02:17 PM

Quote:

Originally Posted by Jeff-Groves (Post 2822246)
You mean the Random?
I'm thinking the Random numbers are start and final
So if Random(15, 20)
The numbers are drawn from 15 to 20
:hmmm:

No, Ship:Random is one of those commands whose arguments are pretty obvious. I mean the parameter of commands like Ship:ShipWaitAction, or the second parameter of Ship:TurnToHeading. They seem to always be in the range 0-1 :hmmm:

Else, Plane:Strafe is another of those commands that accept a numeric parameter, but all the instances I found of it go from -20 to 100. Could that be an angle relative to current aircraft heading? :doh:


All times are GMT -5. The time now is 04:06 PM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright © 1995- 2025 Subsim®
"Subsim" is a registered trademark, all rights reserved.