Vehicle AI Tutorial - Explaining how it all relates. by Dnamro

I am going to try to explain vehicle AI step by step, because the Dice tutorials don't, and point out what is important for bots.

Object.rfa file

Each object’s parameters are in the object.rfa file.

In that file, vehicles are divided in Air, Land, Sea.

There is also the handweapons and the stationary weapons folder.

In the vehicles\Air\B17 folder, there is an object.con and a weapons.con file

The object.con file needs to have an ai Template line for bot support:

ObjectTemplate.aiTemplate B17

***If the new vehicle will behave similar to another vehicle, just use the same ai Template line. Vehicle templates must have unique names. Duplicate names will cause the map to crash while loading, but the error log will have a message stating that the AI template name was already defined. A bad Aitemplate will cause the map to crash as soon as the bot tries to use the vehicle, but will not generate a log error.

The other important section in the vehicle object file is:

ObjectTemplate.setVehicleCategory VCAir

Category is VCAir, VCLand or VCSea

ObjectTemplate.setVehicleType VTBomber

These lines are important to get right, because the AI will not use the vehicle correctly if its wrong. Also the each vehicle type has hardcoded expectations of weapons systems and specific behaviors. There are a set of predefined vehicle types which appear to be hardcoded by Dice with no means to add more or change the existing ones in the con files. Having the wrong vehicle type set could cause the bots to not use weapons, not move, or even worse crash the game. ***Setting a land vehicle to an Air vehicle type will cause a crash. Some other mismatches will also cause a crash.

Aircraft are VTBombers, VTFighters, or VTDivebombers. Bombers will fly level, without any tricks and just drop bombs. Fighters will fly around strafing targets and trying to fight other aircraft. Divebombers will fly up high and then dive, dropping bombs on a target.

The CH47 in Secret Weapons is a new type, VTLevelBomber which is hardcoded to make bots bail out when its over a landing zone as defined in the AI strategic areas file for the map. It also appears to be hard coded to fly at a set low level. I have tried spawning it in the air at a higher altitude, but the bot pilot will fly it back to the set low level.

Boats can be VTLcvp, VTDestroyer, VTCarrier, VTBattleship or VTSubmarine. None of the existing vehicle types will allow bot boat pilots to fire a weapon from the pilots position. So the Submarine and the new PT boats (Elco80/type38) can not fire torpedoes (at least not with existing vehicle types or Aibehavior types). This appears to be why submarines and the new PT boats are not bot supported. Carriers and Battleships don’t move much with bot pilots (this might be because of the pathmaps that they follow on Dice maps). Destroyers will move with bots, but wont drop depth charges.

Land vehicles can be VTScoutCar, VTLightTank, VTHeavyTank, VTTankHunter, VTAPC, or VTArtillery. VTScoutCar is an unarmed fast-moving land vehicle, most likely will not allow bots to fire a weapon from the drivers position, but should work with a gunner in a passenger postion. Bots using light and heavy tanks expect to have a turret weapon, and generally will move head-on towards a target and then veer off to move alongside the target. Artillery, can not fire from the drivers position, and will position the vehicle so the gunner can attack the target with artillery.

VTStationaryMG.

The only weapons in the stationary folder that are assigned a vehicle type are the stationary Browning and the stationary MG42, which are VTStationaryMG vehicle types.

The other Stationary Weapons in the vehicle\land folder are set as VTDefgun or VTAAgun (flak38).

The new custom weapon, Pak40 is a VTATgun. The AiTemplate included with it wont work right because its copied from the flak38 (obviously not tested by Dice).

Weapons.con file

Each weapon that the vehicle has needs to be described in this file.

To tell bots how to use the weapon, an AI template line is needed for each weapon:

ObjectTemplate.aiTemplate B17Bombs

So, if you had an aircraft that dropped bombs like a heavy bomber, you could use the line above.

AI templates

Now to create custom object AI templates, add an AI folder to the vehicle folder and then create the following files:

>>AI\object.con - tells the bot how to control the vehicle.
>>AI\Weapons.con - tells the bot how to use the weapons.

Lets look at the B17\AI\object file:

rem *** Plugins ***
aiTemplatePlugIn.create Unit B17Unit
aiTemplatePlugIn.equipmentType 1
(equipment type is linked to the vehicle behaviors, which are in the aibehaviors.con file in the game.rfa and can be edited)
aiTemplatePlugIn.setStrategicStrength 0 7
(When the bots are attacking [0 for offense] , it will have a weight of 7 to use this vehicle. Tanks & Mustang has a weight of 3. Stuka has a weight of 5. The higher the number - the higher the chance of using the vehicle over another)
aiTemplatePlugIn.setStrategicStrength 1 4
(when the bots are defending[1 for defense] it will have a weight of 4 to use this vehicle )

aiTemplatePlugIn.create Cover B17Cover
aiTemplatePlugIn.coverValue 2.0
(bots will use a weight of 2 to use this as cover when its on the ground. Tanks have a weight of 4, bunkers are 100, buildings range between 40 – 80.)

aiTemplatePlugIn.create Physical B17Physical
aiTemplatePlugIn.setStrType Air
(Options are Air, Infantry LightArmor, HeavyArmor, Naval, Submarine.
This is just a label that is used by the bot weapon AI to determine the chance of attacking a target catergory with a specific weapon. A Flak38 has a high priority against Air targets. Just because its an specific vehicle category does not mean that its setStrType has to be set to that same category. It should be set to the type that weapons will damage it.)

aiTemplatePlugIn.create ControlInfo3d B17Ctrl
aiTemplatePlugIn.driveTurnControl PIYaw
aiTemplatePlugIn.driveThrottleControl PIThrottle
aiTemplatePlugIn.aimHorizontalControl PIYaw
aiTemplatePlugIn.aimVerticalControl PIPitch
aiTemplatePlugIn.driveRollControl PIRoll
aiTemplatePlugIn.drivePitchControl PIPitch
aiTemplatePlugIn.aimRollControl PIRoll
aiTemplatePlugIn.aimThrottleControl PIThrottle
aiTemplatePlugIn.throttleSensitivity -3.0
rem aiTemplatePlugIn.pitchSensitivity -0.5
aiTemplatePlugIn.pitchSensitivity -1.0
aiTemplatePlugIn.rollSensitivity -1.3
aiTemplatePlugIn.yawSensitivity 0.3
aiTemplatePlugIn.throttleLookAhead 1.0
aiTemplatePlugIn.pitchLookAhead 1.2
aiTemplatePlugIn.rollLookAhead 1.5
aiTemplatePlugIn.yawLookAhead 0.3
aiTemplatePlugIn.throttleScale 1.0
rem *** Angle in radians ***
aiTemplatePlugIn.pitchScale 0.0110
aiTemplatePlugIn.rollScale 0.0220
aiTemplatePlugIn.yawScale 0.0175
aiTemplatePlugIn.maxRollAngle 0.5000
aiTemplatePlugIn.maxClimbAngle 0.1700
(Ctrl plugin tells the bot how to control the vehicle)

aiTemplatePlugIn.create Mobile B17Mobile
aiTemplatePlugIn.vehicleNumber –1
(This determines the pathmap type that the vehicle follows. Planes don’t follow pathmaps so should be set to -1. Cars & tanks are set by Dice to use 0, Battleships & Carriers are set to 2, and Destroyers and Launches are set to 3)
aiTemplatePlugIn.maxSpeed 50.0
(max speed that the bot can go)
aiTemplatePlugIn.turnRadius 25.0

aiTemplatePlugIn.create Armament B17Arms

rem *** AITemplate ***
aiTemplate.create B17
aiTemplate.addType ITUnit
aiTemplate.addType ITMobile
aiTemplate.addType ITAir
(There are many types that can be added. See the Dice AI tutorials for a complete list and detailed explanation)
rem aiTemplate.addType ITCover
aiTemplate.degeneration 7
(how many seconds once its out of view, does it take for a bot to forget about it)
aiTemplate.allowedTimeDiff 0.5
aiTemplate.basicTemp 35
(As I understand it, this is the value of how important this is to bots. The higher the number, the more likely they are to interact with it)
aiTemplate.commonKnowledge 0
aiTemplate.addPlugIn B17Unit
aiTemplate.addPlugIn B17Cover
aiTemplate.addPlugIn B17Physical
aiTemplate.addPlugIn B17Ctrl
aiTemplate.addPlugIn B17Mobile
aiTemplate.addPlugIn B17Arms

-----------------------------------------------------
Other related bot info;

Bots will not fire on an unmanned vehicle.
Bots do not run out of ammo.

Vehicle Weapon AI
The vehicle weapon.con file will need to have an Aitemplate line for each weapon.

So in the object file, the vehicle\air\B17\weapon.con file is this:

rem *** B17BombHolder ***
ObjectTemplate.create FireArms B17BombRack
ObjectTemplate.setNetworkableInfo PlaneFireArmInfo
ObjectTemplate.aiTemplate B17Bombs
***(AI template for B17 bombs)
ObjectTemplate.projectileTemplate HeavyBomberBomb
ObjectTemplate.projectilePosition 0/0/0
ObjectTemplate.magSize 8
ObjectTemplate.numOfMag 10
ObjectTemplate.velocity 0
ObjectTemplate.autoReload 1
ObjectTemplate.reloadtime 15
ObjectTemplate.roundOfFire 4
ObjectTemplate.setAsynchronyFire 1
ObjectTemplate.setInputFire c_PIAltFire
ObjectTemplate.addFireArmsPosition -1/-0.1/0 0/0/0
ObjectTemplate.addFireArmsPosition 1/0.1/0 0/0/0
ObjectTemplate.AmmoType 9

rem *** B17_GunT_GunBarrel ***
ObjectTemplate.create FireArms B17_MG1_FB

ObjectTemplate.setNetworkableInfo PlaneFireArmInfo ObjectTemplate.loadSoundScript Sounds/B17GunTGunBarrel.ssc
ObjectTemplate.aiTemplate B17MachineGun
****(Aitemplate forB17 machine gun)
rem -------------------------------------
ObjectTemplate.visibleBarrelTemplate e_MuzzB17
rem -------------------------------------
ObjectTemplate.projectileTemplate B17_GunT_Projectile
ObjectTemplate.setTracerTemplate Tracer_Projectile CRD_NONE/2/0/0
ObjectTemplate.projectilePosition 0/0/0
ObjectTemplate.magSize 900
ObjectTemplate.numOfMag 1
ObjectTemplate.velocity 400
ObjectTemplate.roundOfFire 10
ObjectTemplate.addFireArmsPosition 0.2/0.02/0.75 0/0/0
ObjectTemplate.addFireArmsPosition -0.2/0.02/0.75 0/0/0
ObjectTemplate.AmmoType 10
ObjectTemplate.setFireCameraShakeAnimationState FireMachineGunShake

rem *** B17_GunT_Projectile ***
*** (no aitemplate needed for projectiles)
ObjectTemplate.create Projectile B17_GunT_Projectile
ObjectTemplate.createNotInGrid 1
ObjectTemplate.loadSoundScript ../../../Common/Sounds/Projectile.ssc
rem ObjectTemplate.geometry tracklight_m1
ObjectTemplate.hasMobilePhysics 1
ObjectTemplate.hasCollisionPhysics 1
ObjectTemplate.hasResponsePhysics 1
ObjectTemplate.timeToLive CRD_NONE/2/0/0
ObjectTemplate.gravityModifier 0
ObjectTemplate.material 224
ObjectTemplate.material2 -1
ObjectTemplate.stopAtEndEffect 1
ObjectTemplate.hasCollisionEffect 1

rem *** B17_GunB_GunBarrel ***
ObjectTemplate.create FireArms B17_MG2_FB
ObjectTemplate.setNetworkableInfo PlaneFireArmInfo
ObjectTemplate.loadSoundScript Sounds/B17GunTGunBarrel.ssc
ObjectTemplate.aiTemplate B17MachineGun
***(The B17 machine guns share an Aitemplate)
rem -------------------------------------
ObjectTemplate.visibleBarrelTemplate e_MuzzB17
rem -------------------------------------
ObjectTemplate.projectileTemplate B17_GunB_Projectile
ObjectTemplate.setTracerTemplate Tracer_Projectile CRD_NONE/2/0/0
ObjectTemplate.projectilePosition 0/0/0
ObjectTemplate.magSize 900
ObjectTemplate.numOfMag 1
ObjectTemplate.velocity 400
ObjectTemplate.roundOfFire 10
ObjectTemplate.addFireArmsPosition 0.3/0/0.95 0/0/0
ObjectTemplate.addFireArmsPosition -0.3/0/0.95 0/0/0
ObjectTemplate.AmmoType 10
ObjectTemplate.setFireCameraShakeAnimationState FireMachineGunShake

rem *** B17_GunB_Projectile ***
***(no aitemplate needed for projectiles)
ObjectTemplate.create Projectile B17_GunB_Projectile
ObjectTemplate.createNotInGrid 1
ObjectTemplate.loadSoundScript ../../../Common/Sounds/Projectile.ssc
rem ObjectTemplate.geometry tracklight_m1
ObjectTemplate.hasMobilePhysics 1
ObjectTemplate.hasCollisionPhysics 1
ObjectTemplate.hasResponsePhysics 1
ObjectTemplate.timeToLive CRD_NONE/2/0/0
ObjectTemplate.gravityModifier 0
ObjectTemplate.material 224
ObjectTemplate.material2 -1
ObjectTemplate.stopAtEndEffect 1
ObjectTemplate.hasCollisionEffect 1

Now the object files vehicle\air\b17\AI\weapon folder looks like this:

rem * Machine gun *
weaponTemplate.create B17MachineGun
(AI weapon template name)
weaponTemplate.burst 1
(Burst 1 means its an automatic weapon and the bot will fire in short bursts
Burst 0 means non-auto weapon, and the bot will fire separate shots. Bots will fire more accurately and more often in this mode, even with an automatic weapon.)
weaponTemplate.indirect 0
( set to 1 for artillery. Allows the bot to fire a weapon out of its normal line of site using a weapon with indirect fire capability. But, it has to be in its AI weapon range.
Set to 0 for line of site weapons.)
weaponTemplate.minRange 5.0
(this is usually used to make sure the bots are not caught in the blast radius of its own area effect weapon, like a bazooka or a bomb. – Don’t know why the B17 machine gun is set to 5?)
weaponTemplate.maxRange 300.0
weaponTemplate.weaponActivate PINone
( I have not seen this set to anything else. I assume it could be used for a weapon that had to be activated before it could be used)
weaponTemplate.weaponFire PIFire
(PIFire is the primary fire button. PIAltFire is the Alternate fire button)

(Now these are the priorities against target categories)
weaponTemplate.setStrength Infantry 7.0
weaponTemplate.setStrength LightArmour 3.0
weaponTemplate.setStrength HeavyArmour 0.0
weaponTemplate.setStrength NavalArmour 0.0
weaponTemplate.setStrength Submarine 0.0
weaponTemplate.setStrength Air 7.0

rem * Bombs *
weaponTemplate.create B17Bombs
weaponTemplate.burst 1
weaponTemplate.indirect 1
weaponTemplate.minRange 20.0
(Now a value of 20 should keep the bot from dropping bombs if its too close to the target)
weaponTemplate.maxRange 200.0
weaponTemplate.weaponActivate PINone
weaponTemplate.weaponFire PIAltFire
(notice that the weapon bomb code has a setinputfire line to the same key)
weaponTemplate.setStrength Infantry 18.0
weaponTemplate.setStrength LightArmour 12.0
weaponTemplate.setStrength HeavyArmour 11.0
weaponTemplate.setStrength NavalArmour 8.0
weaponTemplate.setStrength Submarine 0.0
weaponTemplate.setStrength Air 1.0

*****************************************

Handweapon AI is very similar, just that there is only an AI\weapons.con file - no AI\objects.con.

*****************************************
Bot AI tips
- Bots will not fire on unmanned objects. This is why in Battle of Britain, the factory has a bot spawn point in it. This is also why you can save your tank from bot attack by getting out when its health gets low, before it gets critical.

- To get bots to attack a destructable object, add a bot spawn to it.

- You can get bots to spawn in vehicles by adding a spawnpoint next to the vehicle (within the entry radius) and then in the SoldierSpawnTemplates.con file add the ObjectTemplate.setAIEnterOnSpawn 1 as shown in the example from BOB:

ObjectTemplate.create SpawnPoint SpawnAI_Axis_Airfield_1
ObjectTemplate.setSpawnId 21
ObjectTemplate.setGroup 3
ObjectTemplate.setAIEnterOnSpawn 1

- To Create spawn point groups only for bots add the line: spawnPointManager.OnlyForAI 1 to the SpawnPointManagerSettings.con file as in the example from BOB:

spawnPointManager.group 3
spawnPointManager.groupTeam 1
spawnPointManager.groupEnableToChangeTeam 0
spawnPointManager.groupIcon test1.tga
spawnPointManager.OnlyForAI 1

To make spawn groups only for Humans add the line: spawnPointManager.OnlyForHuman 1 as in this example:

spawnPointManager.group 2
spawnPointManager.groupTeam 1
spawnPointManager.groupEnableToChangeTeam 0
spawnPointManager.groupIcon test1.tga
spawnPointManager.OnlyForHuman 1