Strange AI pathfinding

Moderators: rbodleyscott, Slitherine Core, Gothic Labs

Post Reply
StuccoFresco
2nd Lieutenant - Panzer IVF/2
2nd Lieutenant - Panzer IVF/2
Posts: 669
Joined: Sun Feb 10, 2019 11:10 am

Strange AI pathfinding

Post by StuccoFresco »

I've created another custom scenario where the AI army starts a bit far from mine. I assigned AI groups to try to "shepherd" the army toward mine in an orderly fashion, but as soon as the scenario starts all hell breaks loose, with most of the enemy infantry and archers going into the woods on the right and the elephants moving south staying next to the hills on the left. Why is that?

I assigned all enemy army (in the "north" of the screenshot) except for the cavalry to an AI group, given it code 18 (2 to "move close togather" and 16 for "search and destroy") and assigned an AI target in the middle of my army, where there is the small pike square. What am I doing wrong?

Image
rbodleyscott
Field of Glory 2
Field of Glory 2
Posts: 28330
Joined: Sun Dec 04, 2005 6:25 pm

Re: Strange AI pathfinding

Post by rbodleyscott »

Using "search and destroy" from the start is a sure way to have the army scoot all over the place.

With regard to the archers etc heading for the woods, the AI will try to route bowmen and medium foot through rough/difficult terrain if possible for protection against heavy foot and cavalry.

To be honest, the in built Editor AI commands simply aren't enough to make good AI on their own.

We didn't use them ourselves. All of the Historical Battles scenarios have scripted AI, and so do skirmishes.

There is a template scenario script called SCENARIOTEMPLATE.BSF in the main directory of the game. If you copy it into your user "campaign" folder, in the /SCENARIOS subdirectory (i.e. the place where your scenario .BAM file is), you can then rename it to match your scenario .BAM file.

So if your scenario is MYSCENARIO.BAM, rename SCENARIOTEMPLATE.BSF to MYSCENARIO.BSF. (Don't type in the .BSF, that will happen automatically)

You will find your user "campaign" folder in /Documents/My Games/PSCAMP/CAMPAIGNS.

Then you need to change line 36 from

Code: Select all

//      AI_Masterplan(15);
to

Code: Select all

      AI_Masterplan(15);
and line 71 from

Code: Select all

//  AI_ReassignTeams(1);
to

Code: Select all

  AI_ReassignTeams(1);
That will activate the Skirmish AI. See how the AI behaves then.

I suspect the archers etc. may still try to route through the woods though.
Richard Bodley Scott

Image
StuccoFresco
2nd Lieutenant - Panzer IVF/2
2nd Lieutenant - Panzer IVF/2
Posts: 669
Joined: Sun Feb 10, 2019 11:10 am

Re: Strange AI pathfinding

Post by StuccoFresco »

Thank you' I'll try. I tried to not use "search and destroy" command and to place the AI Target further on the left, but the infantry still took the forest route, indeed.

Do I have to manually cancel the editor AI commands?
rbodleyscott
Field of Glory 2
Field of Glory 2
Posts: 28330
Joined: Sun Dec 04, 2005 6:25 pm

Re: Strange AI pathfinding

Post by rbodleyscott »

StuccoFresco wrote: Tue Mar 31, 2020 2:10 pm Thank you' I'll try. I tried to not use "search and destroy" command and to place the AI Target further on the left, but the infantry still took the forest route, indeed.

Do I have to manually cancel the editor AI commands?
No, AI_Masterplan() will over-ride them.
Richard Bodley Scott

Image
StuccoFresco
2nd Lieutenant - Panzer IVF/2
2nd Lieutenant - Panzer IVF/2
Posts: 669
Joined: Sun Feb 10, 2019 11:10 am

Re: Strange AI pathfinding

Post by StuccoFresco »

Looks marginally better, but still 5 of 7 infantry blocks just run for the woods.
rbodleyscott
Field of Glory 2
Field of Glory 2
Posts: 28330
Joined: Sun Dec 04, 2005 6:25 pm

Re: Strange AI pathfinding

Post by rbodleyscott »

StuccoFresco wrote: Tue Mar 31, 2020 3:32 pm Looks marginally better, but still 5 of 7 infantry blocks just run for the woods.
What is the classification of the infantry?

It seems likely that you might need a small mod to make this work as you intend, to stop warriors, medium foot and bowmen from pathing through the woods by preference.

If you put a copy of AITools.BSF (from /DATA/Scripts in the main build) in your user "campaign" folder in /DATA/BATTLE/SCRIPTS.

Then comment out lines 4659-4671

Code: Select all

					if (LikesTerrain(me) == 1)
						{
							if (terrain == 1) // Enclosed or high vegetation
								{
									modifier = 2;
								}
							else // Rough or Difficult
								{
									modifier = 4; // effect of disorder on Medium Foot etc. already taken into account
								}

						ret /= modifier;
						}
it should probably fix this behaviour. This is the piece of code that makes them try to route through woods etc.

If it makes no difference, the game may not be reading the modded AITools.BSF file, in which case you should also add a copy of $DEFAULT.BSF to your /DATA/Battle/Scripts folder, which should force it to do so.
Richard Bodley Scott

Image
StuccoFresco
2nd Lieutenant - Panzer IVF/2
2nd Lieutenant - Panzer IVF/2
Posts: 669
Joined: Sun Feb 10, 2019 11:10 am

Re: Strange AI pathfinding

Post by StuccoFresco »

Cool, I'll try this out!
StuccoFresco
2nd Lieutenant - Panzer IVF/2
2nd Lieutenant - Panzer IVF/2
Posts: 669
Joined: Sun Feb 10, 2019 11:10 am

Re: Strange AI pathfinding

Post by StuccoFresco »

If I want them to ignore ONLY woods, I shoudl only comment out this part, right?


if (terrain == 1) // Enclosed or high vegetation
{
modifier = 2;
}
StuccoFresco
2nd Lieutenant - Panzer IVF/2
2nd Lieutenant - Panzer IVF/2
Posts: 669
Joined: Sun Feb 10, 2019 11:10 am

Re: Strange AI pathfinding

Post by StuccoFresco »

Nope, got an error.
rbodleyscott
Field of Glory 2
Field of Glory 2
Posts: 28330
Joined: Sun Dec 04, 2005 6:25 pm

Re: Strange AI pathfinding

Post by rbodleyscott »

StuccoFresco wrote: Wed Apr 01, 2020 5:45 pm If I want them to ignore ONLY woods, I shoudl only comment out this part, right?


if (terrain == 1) // Enclosed or high vegetation
{
modifier = 2;
}
StuccoFresco wrote: Wed Apr 01, 2020 6:02 pm Nope, got an error.
If you want them to advance straight towards the enemy you should comment out the whole section.

You could make it only woods by changing the code as follows, but they would then deviate into rough going.

Code: Select all

					if (LikesTerrain(me) == 1)
						{
							if (terrain == 1) // Enclosed or high vegetation
								{
									modifier = 2;
								}
						        
						        if (terrain == 2) // Rough
								{
									modifier = 4; 
								}

						ret /= modifier;
						}
Richard Bodley Scott

Image
StuccoFresco
2nd Lieutenant - Panzer IVF/2
2nd Lieutenant - Panzer IVF/2
Posts: 669
Joined: Sun Feb 10, 2019 11:10 am

Re: Strange AI pathfinding

Post by StuccoFresco »

With the second code, medium foot and warriors will stay OUT of the woods and try to keep in rough terrain, right?
rbodleyscott
Field of Glory 2
Field of Glory 2
Posts: 28330
Joined: Sun Dec 04, 2005 6:25 pm

Re: Strange AI pathfinding

Post by rbodleyscott »

StuccoFresco wrote: Thu Apr 02, 2020 9:02 pm With the second code, medium foot and warriors will stay OUT of the woods and try to keep in rough terrain, right?
That should be so, yes.
Richard Bodley Scott

Image
Post Reply

Return to “Modders Corner”