project reality header
Go Back   Project Reality Forums > PR:BF2 Mod Forums > PR:BF2 Community Modding > Modding Tutorials
24 Apr 2018, 00:00:00 (PRT)
Register Forum RulesDeveloper Blogs Project Reality Members List Search Today's Posts Mark Forums Read
Modding Tutorials Information and tutorials related to modding BF2.

Reply
 
Thread Tools Display Modes
Old 10-10-2011, 12:03 PM   #1
[R-DEV]Outlawz7
PR:BF2 Developer

[R-DEV]Outlawz7's Avatar
Default Creating AI support (Co-op) For Your PR Map

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.



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.

Quote:
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.



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.



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.



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.



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)



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.



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:



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.



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.



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.



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)

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

THIS IS OPTIONAL - Open navmeshControl and search for this.
Quote:
# 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.
Quote:
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.

[R-DEV]Outlawz7 is offline
Last edited by [R-DEV]Outlawz7; 12-03-2016 at 11:27 AM.. Reason: fixed nav statics download
Reply With Quote
Old 10-11-2011, 02:33 PM   #2
SavageCDN
PR Server License Moderator
Default re: [Tutorial]Creating AI support (co-op) for your Project Reality map

Wow thanks for this Outlawz... we have a few =VG= guys who will be drooling over this post
SavageCDN is offline Reply With Quote
Old 10-11-2011, 03:41 PM   #3
Veterans-Gaming
Supporting Member
PR Server License Administrator

Veterans-Gaming's Avatar
Send a message via MSN to Veterans-Gaming Send a message via Skype™ to Veterans-Gaming
Default re: [Tutorial]Creating AI support (co-op) for your Project Reality map

Fuckin A

Veterans-Gaming is offline Reply With Quote
Old 04-07-2012, 09:25 AM   #4
SamBrev

SamBrev's Avatar
Default Re: [Tutorial]Creating AI support (co-op) for your Project Reality map

Quote:
Originally Posted by [R-DEV]Outlawz7 View Post
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.
SamBrev is offline Reply With Quote
Old 04-07-2012, 03:42 PM   #5
AFsoccer
Retired PR Developer
Supporting Member

AFsoccer's Avatar
Default Re: [Tutorial]Creating AI support (co-op) for your Project Reality map

Did you install BF2 Editor?

AFsoccer is offline Reply With Quote
Old 04-16-2012, 05:10 PM   #6
AFsoccer
Retired PR Developer
Supporting Member

AFsoccer's Avatar
Default Re: [Tutorial]Creating AI support (co-op) for your Project Reality map

Quote:
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

AFsoccer is offline Reply With Quote
Old 04-16-2012, 07:43 PM   #7
ballard_44
Retired PR Developer
Default Re: [Tutorial]Creating AI support (co-op) for your Project Reality map

You did edit the GenerateNavmeshLocal.py and GenerateNavmesh_mod.py files so they reference pr_edit?

Quote:
# Change the line below to the mod you are working on
#mod = "pr_edit"
Make sure they aren't 'read only' perhaps?

ballard_44 is offline Reply With Quote
Old 04-16-2012, 08:20 PM   #8
[R-DEV] melonmuncher
PR:BF2 Developer
Default Re: [Tutorial]Creating AI support (co-op) for your Project Reality map

You don't have python installed and it's opening generatenavmeshlocal.py with notepad or similiar instead.
install python it will then run.
[R-DEV] melonmuncher is offline Reply With Quote
Old 04-16-2012, 09:12 PM   #9
AFsoccer
Retired PR Developer
Supporting Member

AFsoccer's Avatar
Default Re: [Tutorial]Creating AI support (co-op) for your Project Reality map

Quote:
Originally Posted by melonmuncher View Post
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.

AFsoccer is offline Reply With Quote
Old 04-16-2012, 09:35 PM   #10
[R-DEV] melonmuncher
PR:BF2 Developer
Default Re: [Tutorial]Creating AI support (co-op) for your Project Reality map

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.
[R-DEV] melonmuncher is offline Reply With Quote
Reply


Tags
coop, creating, map, project, reality, support, tutorialcreating
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



All times are GMT -4. The time now is 06:32 PM.


Powered by: vBulletin. ©vBulletin Solutions, Inc.
All Content Copyright ©2004 - 2018, Project Reality