Creating AI support (Co-op) For Your PR Map

Information and tutorials related to modding BF2.
Outlawz7
Retired PR Developer
Posts: 17261
Joined: 2007-02-17 14:59

Creating AI support (Co-op) For Your PR Map

Post by Outlawz7 »

In this tutorial you'll learn how to set up your PR map to support the Co-Operative gamemode with bots.
Before we continue, some info.

Required: Python 2.7


Navmesh - or navigation mesh; it's what you'll primarily be creating. Navmesh is used by the game to tell bots what areas they can move to. Navmesh will create holes where bots cannot move to, mainly objects but also slopes.

Navmesh comes in three different versions, which are found in AIPathFinding folder of a map:
  • Infantry - tells bots where they can move on foot.
  • Vehicle - tells bots where they can move in ground vehicles.
  • AerialHeighMap - tells bots in aircraft where they can fly.
Navmesh is generated by a program called navmesh.exe, which comes with your BFeditor install and can be found under C:\Program Files\EA GAMES\Battlefield 2\NavMesh\. Several other files involved in this process are also in that folder.

Nav statics - are clones of existing static objects in PR that feature a col3 - collision mesh used by navmesh.exe to generate the navmesh. If an object doesn't have a col3, the editor will use the object's bounding box as col3 instead when exporting the info for navmesh.exe. Original BF2 statics all come with this, but some PR statics do not. These clones are only temporarily used to export the necessary info for navmesh.exe. Simple objects do not require them.

IMPORTANT: Backup your entire map, as some files will get overwritten and some will be changed for the purposes of navmeshing.

It is advisable that you only do this when your map layout is final. Any major terrain or object placement change will mean the navmesh will be misaligned and will have to be redone. However, you can get away with small changes and also manually edit the navmesh to avoid this.

With that in mind, lets continue.
For this tutorial you'll need default editor install, the necessary files come with it as mentioned and the nav statics.

Nav Statics Download

Unzip this file to mods/pr_edit/objects. All of the _nav versions can then be found at mods/pr_edit/objects/staticobjects/_stuff. If your static doesn't have a _nav there then it's probably already got one as part of its original file.

You'll need to to copy two files - exportGTS.con and saveQuadNoP4.con from the Navmesh folder to the main Battlefield folder.

Image

AI folder

Before you load up your map in editor, copypaste the "AI" folder out of another PR map with coop support.
Inside it is another file called AI. Open it with Notepad.
rem ************** LEVEL SPECIFIC AI SETTINGS ***************************

rem aiSettings.setViewDistance 300

rem *** Init AI using current settings ****
ai.init 2

rem *** Set custom angle to avoid cracks in a road ***
aiPathfinding.setActiveMap Vehicle
aiPathfinding.map.maxSlope 35
aiPathfinding.map.addVehicleForClusterCost Tank
aiPathfinding.map.addVehicleForClusterCost ArmedCar

aiPathfinding.setActiveMap Infantry
aiPathfinding.map.maxSlope 45
aiPathfinding.map.addVehicleForClusterCost Infantery


rem ----------------------------------------------------------------------------
We're only interested in the maxSlope strings as those control the maximum angle the navmesh will reach (slopes above that angle do not get navmeshed).
You can keep the default values most of the time, however if your map is hilly/mountainous, you might want to slightly up the values. If your map is urban and mostly flat, but has enterable buildings with upper floors, the angle of staircases leading to those floors also counts in. It's preferable to keep the infantry angle high, so the said staircases do not cut off upper floors.

Setting up the navmesh area

As much as you'd like to see the entire map being used, unfortunately navmesh comes with some limitations in size. Do not expect much if your map is a.) 4km in size b.) overgrowth or static objects heavy.

For this tutorial I'll be using Silent Eagle as an example map.

To begin, make sure SinglePlayerEditor plugin is loaded into editor. Go under Tools>Add-in Manager.

Image

To pick the area that will be navmeshed, use the Combat area under Level editor and create a combat area as you normally would, but only around the area intended for navmeshing.
Make sure you place it counter-clockwise and check UsedByPathFinding in Tweakerbar.

Image

As I've said, navmesh is limited in size, so on 4km maps it is advisable to only do the 'bare bone' layout; several interest points and a route between them as seen here.

Image

Replacing your statics with nav statics

To replace a static, select the static.
In the right side menu at the very top click "Select all of the same type". This will select all of the objects identical to the one you've selected across the map. Then click "Replace object(s)" below the previous button. A list will pop up, navigate to the nav statics and find the one that corresponds with the original name, but with a _nav suffix.

Image

Note: not all objects have a _nav version and identical models use the same _nav (ie. blue_tarp and white_tarp objects use blue_tarp_nav)

Image

Continue replacing other objects the same way.

IMPORTANT: If your map uses _nl (no ladder) versions of BF2 statics (mostly MiddleEast urban maps), replace all those with the original ones, otherwise they will not navmesh. If your map uses _roofwalls statics which are placed on top of existing buildings, delete them as they will interfere and also cause the buildings not to navmesh.

"Snap" statics

An issue with open areas is that navmesh will get oversimplified there, causing it to float and miss terrain completely. To avoid this, use a simple object, like a lightpole and place it around to snap the navmesh to ground.
Best areas to place these are near or on roads or paths between areas. You can later weld together the holes created when editing the navmesh in 3ds Max.

Image

Making sure

Before we export, it is good to check if we missed any object or any area that might need a snap static. Do this by clicking on Render > Toggle Draw Collision Meshes > AI Mesh. Your statics should now have colored shapes around them, like this:

Image

Look for objects that don't. Again, simple objects like walls do not need a col3/_nav clone, however beware of wall sections that feature doors - the door won't be recognized when exporting the info and the object will be exported as a box.

Another issue can be corner wall objects like this, which will again be turned into a box and cut off the entire corner area with it unless replaced.

Image

Before you go to the next step, save your map.

Exporting files necceseary for navmesh.exe

Switch to SinglePlayerEditor from LevelEditor, then on the right-side menu, click "Generate PathFinding". Wait a few minutes for data to export.

Image

You can now close the editor, but DO NOT SAVE.

Much like lightmapping, exporting the files will turn overgrowth into static objects, however while saving after lightmapping rarely saves the overgrowth as static objects, saving after this will do so every time.


Creating the navmesh

The exported files can be found in your map's folder as GTSData folder. Copy it, then go to C:\Program Files\EA GAMES\Battlefield 2\NavMesh\.

There create a new folder called 'work' (if it doesn't exist already) and inside create a new folder with the map's exact name. Paste the GTSData into that folder.

Image

Now go to the main folder (\Battlefield 2\NavMesh\). Before you start, there's two Python files that can be tweaked.

Open GenerateNavmeshLocal with Notepad. Tweak this line (self-explanatory)
# Change the line below to the mod you are working on
mod = "pr_edit"

THIS IS OPTIONAL - Open navmeshControl and search for this.
# Perform opt-steps
modes = [ "Infantry", "Vehicle"];
This line controls what navmeshes will get generated (AerialHeighMap is generated by default). For example, if you want an infantry only coop and thus only the Inf mesh, then remove the Vehicle bracket.
modes = [ "Infantry"];

Now, run the CreateNavmesh.bat file. It will ask you for the mod and map name, type them in exactly. bfeditor will run, prompting you to select the mod you just typed in. Do so and that's it.

Depending on your CPU power, come back in a few days or two weeks. You can still play PR/run BFeditor in the mean time or run other stuff, but check the Task Manager for resource usage, navmesh.exe will probably hog 40-50% of your CPU.

Once the process is complete, navmesh.exe will run bfeditor by itself to export the navmesh to your map, so it's a good idea not to have it open already or run BF2/PR during that time.

Now you can move onto the next step - editing the navmesh.
Last edited by Outlawz7 on 2016-12-03 16:27, edited 7 times in total.
Reason: fixed nav statics download
Image
SavageCDN
Posts: 7
Joined: 2010-12-31 17:46

re: [Tutorial]Creating AI support (co-op) for your Project Reality map

Post by SavageCDN »

Wow thanks for this Outlawz... we have a few =VG= guys who will be drooling over this post :-o
SamBrev
Posts: 32
Joined: 2012-04-02 11:38

Re: [Tutorial]Creating AI support (co-op) for your Project Reality map

Post by SamBrev »

'[R-DEV wrote:Outlawz7;1679248']Navmesh is generated by a program called navmesh.exe, which comes with your BFeditor install and can be found under C:\Program Files\EA GAMES\Battlefield 2\NavMesh\. Several other files involved in this process are also in that folder.
I can't find that folder anywhere. Help me, because I need these maps and I don't have a very good internet connection.
Finally a game with GB in it. Last time we were in a war game we were OpFor.
AFsoccer
Retired PR Developer
Posts: 4289
Joined: 2007-09-04 07:32

Re: [Tutorial]Creating AI support (co-op) for your Project Reality map

Post by AFsoccer »

Did you install BF2 Editor?
AFsoccer
Retired PR Developer
Posts: 4289
Joined: 2007-09-04 07:32

Re: [Tutorial]Creating AI support (co-op) for your Project Reality map

Post by AFsoccer »

Now, run the CreateNavmesh.bat file. It will ask you for the mod and map name, type them in exactly and that's it.

Depending on your CPU power, come back in a few days or two weeks. You can still play PR/run BFeditor in the mean time or run other stuff, but check the Task Manager for resource usage, navmesh.exe will probably hog 40-50% of your CPU.
When I enter those values (i.e. pr_edit and tad_sae) and hit enter each time, my computer opens up "GenerateNavmeshLocal.py" but doesn't do anything else. Any ideas what I'm doing wrong? I've tried running the .bat as admin and in XP compatibility mode.

Thanks
ballard_44
Retired PR Developer
Posts: 1204
Joined: 2007-05-30 22:47

Re: [Tutorial]Creating AI support (co-op) for your Project Reality map

Post by ballard_44 »

You did edit the GenerateNavmeshLocal.py and GenerateNavmesh_mod.py files so they reference pr_edit?
# Change the line below to the mod you are working on
#mod = "pr_edit"
Make sure they aren't 'read only' perhaps?
Image
melonmuncher
PR:BF2 Developer
Posts: 266
Joined: 2012-01-13 05:14

Re: [Tutorial]Creating AI support (co-op) for your Project Reality map

Post by melonmuncher »

You don't have python installed and it's opening generatenavmeshlocal.py with notepad or similiar instead.
install python it will then run.
AFsoccer
Retired PR Developer
Posts: 4289
Joined: 2007-09-04 07:32

Re: [Tutorial]Creating AI support (co-op) for your Project Reality map

Post by AFsoccer »

melonmuncher wrote:You don't have python installed and it's opening generatenavmeshlocal.py with notepad or similiar instead.
install python it will then run.
Wow, that would have been nice to have in the tutorial. LOL

So now that python is installed, it's no longer opening up the .py in notepad (yay) but still nothing is happening. I enter the info and hit enter, then the .bat window closes very fast and that's it. Nothing happens.

I've modified the .py file to show pr_edit, so that's not the issue. There must be something else missing from the tutorial that would be obvious to regular python users.
melonmuncher
PR:BF2 Developer
Posts: 266
Joined: 2012-01-13 05:14

Re: [Tutorial]Creating AI support (co-op) for your Project Reality map

Post by melonmuncher »

If the map is not correctly named in the Navmesh/work folder it will not run and will close instantly.
So for tad sae it should be NavMesh/work/tad_sae/GTSData also make sure you have uppercase and lowercase as it is in the levels folder.
ballard_44
Retired PR Developer
Posts: 1204
Joined: 2007-05-30 22:47

Re: [Tutorial]Creating AI support (co-op) for your Project Reality map

Post by ballard_44 »

Plus, is there or did you create a valid StrategicAreas.ai file?

I don't believe Outlawz talks about that here.

Here a link to an old forum post that's now in a PDF file.
Anybody who wanted to learn read this at some point...try page 14 of 62

http://www.battlefieldsingleplayer.com/ ... terama.pdf
Image
Fastjack
PR:BF2 Contributor
Posts: 525
Joined: 2011-09-04 19:47

Re: [Tutorial]Creating AI support (co-op) for your Project Reality map

Post by Fastjack »

What version of python u using?
ChickenPie75
Posts: 8
Joined: 2012-07-05 13:54

Re: [Tutorial]Creating AI support (co-op) for your Project Reality map

Post by ChickenPie75 »

[R-DEV]melonmuncher wrote:If the map is not correctly named in the Navmesh/work folder it will not run and will close instantly.
So for tad sae it should be NavMesh/work/tad_sae/GTSData also make sure you have uppercase and lowercase as it is in the levels folder.

>NavMesh/work/...


My NavMesh folder doesn't even have a subfolder named "work" to begin with, There is only
a folder named "NavMesh_SDK" and a bunch of stuff inside it.

Do I have to create a new "work" folder myself and then put the GTS data in it?
melonmuncher
PR:BF2 Developer
Posts: 266
Joined: 2012-01-13 05:14

Re: [Tutorial]Creating AI support (co-op) for your Project Reality map

Post by melonmuncher »

Yeah create a work folder and the level folder.
ChickenPie75
Posts: 8
Joined: 2012-07-05 13:54

Re: [Tutorial]Creating AI support (co-op) for your Project Reality map

Post by ChickenPie75 »

OK, I did exactly that. So now the directiory looks like "Battlefield 2\NavMesh\work\silent_eagle\GTSData

But still it's not working. I run the NavMesh.bat and type in the mod / map name but
nothing happens at all. And yes, I did edit the GenerateNavmeshLocal.py and GenerateNavmesh_mod.py files so
they reference pr_edit. So that cannot be the problem...

Also, when I run NavMesh.bat it's showing different command lines than compared to someone else's

for example:

Here is a screencap of my cmd when running NavMesh.bat

Image

Compared to someone else's cmd

Image

As you can see, it's missing the "Usage: generatenavmeshlocal.py" line in my cmd. Can you tell me what I'm doing wrong?


Plus, when I double click on the "generatenavmeshlocal.py" it opens up with a text document by default
(as someone else in this thread mentioned earlier), although I DID install python on my computer.
And when I right-click and select "open with python", a DOS window shows up for a millisecond and closes immediately.
Is this normal?
melonmuncher
PR:BF2 Developer
Posts: 266
Joined: 2012-01-13 05:14

Re: [Tutorial]Creating AI support (co-op) for your Project Reality map

Post by melonmuncher »

Your navmesh.bat is fine it will work.

I think you haven't set your computer to open .py files with python by default and thats the reason it is closing.
dunem666
Posts: 559
Joined: 2009-06-02 13:04

Re: Creating AI support (Co-op) For Your PR Map

Post by dunem666 »

is there any update to this as have been trying this for hours without luck.

running creatnavmesh.bat just does nothing.

Python 27 installed
dunem
ImageImage
ImageImage
User avatar
ALADE3N
PR:BF2 Developer
Posts: 574
Joined: 2016-02-13 17:34
Location: Philippines

Re: Creating AI support (Co-op) For Your PR Map

Post by ALADE3N »

dunem666 wrote:is there any update to this as have been trying this for hours without luck.

running creatnavmesh.bat just does nothing.

Python 27 installed
make sure you edit your GenerateNavmeshLocal.py and find this line at the very top

Code: Select all

# Change the line below to the mod you are working on
[b]mod = "pr_edit"[/b] 
Image
dunem666
Posts: 559
Joined: 2009-06-02 13:04

Re: Creating AI support (Co-op) For Your PR Map

Post by dunem666 »

Thanks yes I have done this but still to no avail can't get it to work.

BFEditor will not open automatically either so wondering if its because of locaction of where its installed
dunem
ImageImage
ImageImage
Double_13
Posts: 45
Joined: 2016-10-16 21:29

Re: Creating AI support (Co-op) For Your PR Map

Post by Double_13 »

Hi I guess ill shed some light on this topic as I mainly do navmeshing for coop now.

First off you have to make sure that the file extention .py is ran by python (2.7.14) and not by notepad++ or any other.

Time to get complicated. I do not use the vanilla Create Navmesh but I do use the vanilla Fix Navmesh.

The backing reason for this is that Dnamro's navmesh tool does not require the editor to launch to generate the navmesh. It also doesnt crash your regular PR game everytime it increases its cutsize while the Vanilla navmesher does. The fix navmesh from Dnamro does not work so i use the vanilla one and yet so far i have to see issues with using this combination.

You can find the tool mentioned above here
https://drive.google.com/file/d/1dwaGqT ... EUph6/view

But remember the .py files does need to be set to python or else this simply does not work.

look over this topic again and make sure you did not miss any step
https://www.realitymod.com/forum/showth ... p?t=103902
Post Reply

Return to “Modding Tutorials”