Author Topic: Progress with modding AI armour classes  (Read 1047 times)

Offline Drawde

  • Jr. Member
  • **
  • Posts: 160
    • View Profile
Progress with modding AI armour classes
« on: 11-04-2010, 18:04:22 »
This post has a lot of rather technical detail probably only of interest to other AI modders, so, to summarise: I've found a workaround for BF2's limited number of "armour class" settings used by the AI, which will allow bots to select weapons and shell types more intelligently, and also do things they couldn't effectively do before (like troops firing small arms at unarmoured trucks, or planes strafing lightly armoured tanks but ignoring heavier ones)

In more detail:
StrTypes are values indicating the "armour class" of a vehicle to the AI, so (a) bots know whether they can attack a target with a particular weapon, and (b) they know how to prioritise targets. They're specified in the "objects.ai" file for each object/vehicle (e.g "aiTemplatePlugIn.setStrType HeavyArmour") and referred to by the "weapons.ai" file for each weapon (e.g "weaponTemplate.setStrength HeavyArmour 5.0"

FH2 uses the following StrTypes: Infantry, Plane, LightArmour (unarmoured vehicles, guns, and halftracks/APCs) and HeavyArmour (all other armoured vehicles). Helicopter and NavalArmour are also in the BF2 engine but not used by FH2.
The problem with this setup is that a lot of quite different objects are grouped into the same class, often making it hard for the AI to know what weapon/shell type to use, and very hard for modders to fix - for example, HE shells are the best choice against AT guns and MG positions, but not much good against halftracks; but both use the LightArmour class. If you give both AP and HE shells similar priority against LightArmour, bots will more often than not pick the wrong shell type!
Similarly, all tanks (and other non-APC armoured vehicles), from Panzer IIs to King Tigers, use the HeavyArmour class, so there's no easy way to get bots to use special AP rounds on heavy tanks like Tigers and Matildas, or to fire AA guns and plane cannons at light armoured vehicles.

The ideal system would probably be to have seven different StrTypes: Infantry, Plane, Gun, Unarmoured, LightArmour, MediumArmour and HeavyArmour. Unfortunately, the existing StrTypes are hard-coded into the BF2 engine (I know, I tried adding new ones and it just CTDed when loading the map). However, I then had the idea of using the unused Helicopter and NavalArmour StrTypes as placeholders for Unarmoured and HeavyArmour respectively. I wasn't initially sure if this would work, but after a bit of testing it works fine.
Basically, the Infantry and Plane StrTypes are unchanged, "Helicopter" is used by unarmoured vehicles and guns, "LightArmour" by light armoured vehicles (including APCs, armoured cars, light tanks etc.), "HeavyArmour" by medium armoured vehicles (including most tanks) and "NavalArmour" by the heaviest tanks - the Matilda, Valentine, Churchill and German "big cats". I've modified all the weapons.ai files to make use of these changes.

Note that the StrType setting only affects bot weapon usage, it has nothing to do with the vehicle's behaviour or its actual armour thickness (bots won't attempt to fly trucks if you set their StrType to "Helicopter"!)

This makes a noticeable difference to the AI's use of weapon and shell types vs. different targets - for example, infantry will now fire small arms at trucks, jeeps and static gun positions, and tanks will almost always fire HE at AT guns. If I don't find any problems with it in future (none so far) this will be in the next version of my AI minimod.

Offline Dnarag1M

  • WoT Team
  • *
  • Posts: 1.068
  • Forgotten Hope Alliance
    • View Profile
    • mah website
Re: Progress with modding AI armour classes
« Reply #1 on: 11-04-2010, 19:04:50 »
I have no relation to or with singeplayer FH2...but I musta, good find ..this will solve some problems and make a lot of people happy :) Nice!

Offline RN_Max

  • FH-Betatester
  • ***
  • Posts: 190
    • View Profile
Re: Progress with modding AI armour classes
« Reply #2 on: 12-04-2010, 08:04:05 »
Nice work, that could make bot weapon selection far more effective.

As for NavalArmour, if ships appear later on, it will probably make sense in most cases to hit them with the same munitions as heavy tanks ... except for potential problems with torpedoes of course ... though I remember trying to drop them on tanks in FH1 :D

Smaller and unarmoured craft could be put into an appropriate existing weapon category.


Offline cannonfodder

  • Full Member
  • ***
  • Posts: 1.228
    • View Profile
Re: Progress with modding AI armour classes
« Reply #3 on: 12-04-2010, 10:04:18 »
Glad to see it works... :)

Offline Raziel

  • Jr. Member
  • **
  • Posts: 859
  • Bullet Magnet
    • View Profile
Re: Progress with modding AI armour classes
« Reply #4 on: 12-04-2010, 13:04:50 »
 :D Hooray for Drawde

Offline Drawde

  • Jr. Member
  • **
  • Posts: 160
    • View Profile
Re: Progress with modding AI armour classes
« Reply #5 on: 13-04-2010, 16:04:56 »
After some more testing, these changes definitely affect AI weapon use significantly (for the better). Tanks almost invariably use HE against AT guns (if they have any) and exposed gunners are also a lot more vulnerable to MG and rifle fire. Haven't confirmed whether the bots will use special AP vs. heavy tanks yet, but they certainly should do.

As for NavalArmour, if ships appear later on, it will probably make sense in most cases to hit them with the same munitions as heavy tanks ... except for potential problems with torpedoes of course ... though I remember trying to drop them on tanks in FH1 :D

Smaller and unarmoured craft could be put into an appropriate existing weapon category.

FH2 actually already has a U-boat and a Flower-class corvette in the data files (as well as a Swordfish) - but even when/if these are actually used in a future FH2 map, I suspect they won't be AI-supported  :(. I'm not sure BF2 has any AI code for large ships (unless the old BF1 code is still in there), and sea maps appear to be the hardest to code for AI (I don't think any of the FH1 naval maps had AI support).

The LCA landing craft (the only sea craft actually used in FH2 so far) uses the LightArmour class IIRC.

Offline djinn

  • Masterspammer
  • ****
  • Posts: 5.723
    • View Profile
Re: Progress with modding AI armour classes
« Reply #6 on: 15-04-2010, 21:04:48 »
I'm sure we will cross that bridge when we get there - Hopefully the devs will have taken some renewed interest in AI and got some coder spurning new code to make subs functional *fingers crossed*

Great job Drawde... Nice too see tanks might just get to use their full armament after all :-D

Offline Excavus

  • Jr. Member
  • **
  • Posts: 391
  • Member of the FH2 Cynic Club
    • View Profile
Re: Progress with modding AI armour classes
« Reply #7 on: 16-04-2010, 02:04:37 »
What about the commander giving bogus orders like on Siege of Tobruk, the AI commander gives the order to defend the main base when it isn't cappable. Also sometimes on El Alamein, some tanks just stay in place in one part of the desert and don't move, sometimes not even shooting at the enemy. This happens for both the British and Germans.

Offline djinn

  • Masterspammer
  • ****
  • Posts: 5.723
    • View Profile
Re: Progress with modding AI armour classes
« Reply #8 on: 16-04-2010, 09:04:42 »
For the former, check out this thread
http://fhpubforum.warumdarum.de/index.php?topic=5305.0

For the latter, I believe its an error introduced by accident when, possibly Legion or Winterhilf tried to grant us our wish of making tanks fire and move as opposed to always firing on the move. After a long drawn out battle, some tanks 'forget themselves' and just remain there, long after the front has moved so they become casualties. Try to displace the tankers and they kill themselves

Another issue that may well be solved by somehow restoring AI tank logic to that of 2.2... But the stop and go had its advantages, just not sure its worth the price payed for in gameplay... especially, in North Africa