PDA

View Full Version : Mapping Creating AI support (Co-op) For Your PR Map


Outlawz7
2011-10-10, 17:03
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 (https://www.python.org/downloads/)


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 (https://www.dropbox.com/s/w86d8hdq3rou2vv/navstatics.rar?dl=0)

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.

http://i.imgur.com/ybc8t.jpg

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.

http://i.imgur.com/0tTLj.jpg

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.

http://i.imgur.com/NJgLC.jpg

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.

http://i.imgur.com/ZUBmw.jpg

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.

http://i.imgur.com/xxNBk.jpg

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)

http://i.imgur.com/xaf2L.jpg

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.

http://i.imgur.com/AfEZr.jpg

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:

http://i.imgur.com/2sADY.jpg

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.

http://i.imgur.com/k0Khg.jpg

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.

http://i.imgur.com/IlT6x.jpg

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.

http://i.imgur.com/dU1h1.jpg

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. (http://www.realitymod.com/forum/f189-modding-tutorials/80921-tutorial-navmesh-editing-3ds-max-9-a.html)

SavageCDN
2011-10-11, 19:33
Wow thanks for this Outlawz... we have a few =VG= guys who will be drooling over this post :-o

Veterans-Gaming
2011-10-11, 20:41
Fuckin A

SamBrev
2012-04-07, 14:25
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.

AFsoccer
2012-04-07, 20:42
Did you install BF2 Editor?

AFsoccer
2012-04-16, 22:10
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
2012-04-17, 00:43
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?

melonmuncher
2012-04-17, 01:20
You don't have python installed and it's opening generatenavmeshlocal.py with notepad or similiar instead.
install python it will then run.

AFsoccer
2012-04-17, 02:12
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
2012-04-17, 02:35
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
2012-04-17, 07:55
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/dnamro/tuts/Adding_AI_BF2_Kysterama.pdf

Fastjack
2012-08-23, 10:37
What version of python u using?

ChickenPie75
2012-10-17, 23:40
melonmuncher;1760719']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
2012-10-18, 00:20
Yeah create a work folder and the level folder.

ChickenPie75
2012-10-21, 20:21
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

http://s17.postimage.org/wljhz7a25/screencap_1.png

Compared to someone else's cmd

http://s17.postimage.org/gys8ltwa5/screencap_2.png

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
2012-10-21, 21:46
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
2018-10-02, 23:03
is there any update to this as have been trying this for hours without luck.

running creatnavmesh.bat just does nothing.

Python 27 installed

HeneraLuna
2018-10-03, 05:14
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


# Change the line below to the mod you are working on
mod = "pr_edit"

dunem666
2018-10-03, 20:08
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

Double_13
2018-10-04, 07:42
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/1dwaGqTJ9hy00BIyLti2cTD78PjhEUph6/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/showthread.php?t=103902

dunem666
2018-10-04, 22:16
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/1dwaGqTJ9hy00BIyLti2cTD78PjhEUph6/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/showthread.php?t=103902


Some great input. Thank you very much, I will give this a shot.

If I still struggle, would you be willing to give my new map a navmesh? I will order you pizza :D

Double_13
2018-10-05, 07:10
Some great input. Thank you very much, I will give this a shot.

If I still struggle, would you be willing to give my new map a navmesh? I will order you pizza :D

Sure just send me the map and I will mesh it.

I got for most staticobjects a _nav object thanks to outlawz so unless you use some new structures without a col3 mesh the navmesh process should not be an issue.

Keep me informed where if you managed to get your navmesher running.