
FOLLOW THE BLACK BRICK ROAD ... ?
sample files
--------------------------------------------------------------------------------
Welcome to Part One of the Ai Pathmapping Tutorial
In this Part of the Tutorial I will introduce you to Pathfinding Maps, what they are, how they work and how to work with these files that are necessary for Bot support.
We will be using the original Battlefield 1942 level Kursk in this tutorial as an example of existing pathmaps.
There are many things that will not be covered in this Tutorial.
Firstly, this tutorial will only cover Land based maps that only use Cars, Infantry, Tanks & Aircraft.
LANDING CRAFT and BOATS (ships) will NOT be covered.
Also, on occasions you may be required to do tasks that requires other software, such as RFA Tools, Image Editors and Map Editors. If you are doing this tutorial, you should already know how to do these tasks. It is not within the scope of this tutorial to teach you other software unless it is a tool or technique specific to Pathmapping.
--------------------------------------------------------------------------------
What are Pathmaps ?
Pathmaps are images that are used to describe to the Bots the location of objects, steep slopes and anything in a level that could get the Bots in trouble or “stuck.” This is done by literally drawing the Bots a diagram of the map, using an image that is marked to show “Pathed Areas,” that are open areas where the Bots may travel, and “Non-Pathed Areas” the Bots Should avoid such as Walls or Cliffs. A simple two colour system is used, with Black (Index#0) used for “Pathed Areas” and White (Index#255) for “Non-pathed Area”
Without Pathmapping Bots would continually; try to walk/drive through walls, try to walk/drive up slopes they cannot get up, walk/drive into holes/off cliffs, get stuck on buildings & other Static Objects, drown/blow up when they try to walk/drive across rivers, lakes or oceans ... phew.
In this case the picture speaks a million words, so we should have a look at an Existing Pathmap. We will also need access to the files within the level Kursk we will be working with. Open your favorite RFA tool and Extract Kursk.rfa to the Folder that you use for Editor42 map editing.
To save confusion later, its not a bad idea to rename the Folder of the extracted level from Kursk to Kursk_Pathmap.

--------------------------------------------------------------------------------
Importing Pathmaps
Pathmaps are packed in Dice's own format that we are not able to view with our normal software. If you have software installed that has the RAW file type already associated, such as Photoshop™, the program will attempt to open the .RAW file when you double-click it, but as you may have already discovered, the program will not display or open the file properly.
Luckily the format is similar to the .RAW Image format, and Rexman was able to write an “Importer” that will unpack & convert Dice's .RAW Pathmaps to 8-bit Greyscale .RAW images, that we can view and edit.
Browse to the Folder you extracted Kursk to, and look in the Pathfinding folder.

15 files in all, and you should notice that there are three groups of 5 files for each unit type. Each of these file contains information that is based on the Level0Map Pathmapping files, and these are the files we will be having a closer look at.
Browse to the Folder where you have unzipped Rexman's Ai Tools.

Import_Pathfind.exe is the first Ai Tool we will be using. It is a Command Line Application that needs to be run from a Command Prompt (MS-Dos Window in Win9x/Me) or from a .BAT (batch) File.
Included with this tutorial is Import_Level0Maps.bat, make a Copy of this .BAT file in the same Folder as Import_Pathfind.exe. This batch file is setup to Import most level0 Pathmaps that are in this Folder when run. If you are curious which Pathmaps are setup for importing, or want to check that i haven't slipped Format C: /Q into the file just right-click on the .bat and select Edit.

Go back to where Kursk's Pathmaps were extracted and grab a Copy of the Car4Level0Map.raw and browse back into your Ai_Bots folder and Paste the Car4Level0Map.raw here.

Double-click Import_Level0Maps.bat to run the conversion process, and a new file will be created, Car4Level0Map8bit.raw. Notice the same standard of file naming is used, with the extra 8bit added to remind us the file is 8bit greyscale .RAW

If you are using Photoshop™ or other software that can open 8-bit Greyscale .RAWs, double-click on the new file, and if requested, make sure your settings are the same as this.

IF YOU ARE NOT USING PHOTOSHOP
Don't Panic! If you don't have Photoshop or you prefer to use another Image Editor that cannot open .RAW files, don't fret, there is a great utility called FlyRawGui that will convert a 8-bit Greyscale .RAW image to a 8-bit Greyscale .BMP (Windows Bitmap) images.

Use Convert RAW to BMP and browse to locate our Car4Level0Map8bit.raw

Open the file and it will be converted by the Program.

This File format is much friendlier, and can be edited in most Image editing software ... except MS-Paint
--------------------------------------------------------------------------------
Viewing Pathmaps
Now that we have the Pathmap in a format we can use and view, Open it in your favorite Image Editor and you should see something similar to this
(note: the following image is 50% of its original size)

O dear, does this look anything like Kursk ? For starters, like many other things in Battlefield 1942 this is upside down Miss Jane, once we turn it up the right way it might make more sense.
Photoshop

–=#=–
Similar in Corel Paint and other software

–=#=–
Once up the right way, look for features you may recognize. Near the bottom is the Axis base, you can see the fence that goes around the House, and the Barn off to the right.

The best way to see how a Pathmap interacts with the Terrain and Static Objects, is to preview it, textured onto the map.
Rexman has another tool for us, exactly for this purpose. Ai_GenerateForLevel will convert a level0 Pathmap to TX*.dds terrain tiles that we can then use to view in a Map Editor or even In Game.
Go back to Kursk's extracted Pathmaps and grab another Copy of Car4Level0Map.raw. Browse to the folder for Ai_GenerateForLevel and Paste the Pathmap there.

The _convertTolevelTexture.bat runs the several steps that are required, and controls how our pathmap is converted. There are two settings in the .bat file we may need to adjust from time to time depending on which Pathmap we want to preview (car/infantry/tank) and the size of the map. Right-Click on the .bat file, and select Edit, this will open the file in notepad for our convenience.
The first setting relates to the Unit type of the Pathmap that we want to preview.
@echo off
rem --- Do NOT put a .raw at the end of the filename here! ---
set tmpFileAI=Infantry1Level0Map
The tmpFileAI setting is a setting that allows to specify a variable that will be used a few times within the batch file, so thankfully this allows us to make one change instead of several. You need to change this to correspond with the Pathmap that you are going to preview, in this case we want to preview the Car Pathmap so we shall change the line to read.
set tmpFileAI=Car4Level0Map
And of course you need to change this line again to match your Pathmap if you wish to view others such as the Tank0 or Infantry1 pathmap.
The next setting to look at is further down. This command runs a program that will split our pathmap into tiles, you can see the tmpFileAI reference that calls the setting we changed above. The setting we need to change here is the value at the end. This refers to the number of Texture Segments & needs to be set for the appropriate value for the of size of a map.
tgaSplit.exe %tmpFileAI%.tga 4
How do you know what setting you should use ? Well, in most cases there is a very straight-forward answer, the following Table covers the Standard Size maps.
Height Map Size
|
Std Worldsize
|
Std Texture Size (pixels)
|
Texture Tiles
|
Texture Segments
|
256
|
1024
|
4096
|
16 (4x4) (tx00x00 - tx03x03)
|
4
|
512
|
2048
|
8192
|
64 (8x8) (tx00x00 - tx07x07)
|
8
|
1024
|
4096
|
16384
|
256 (16x16) (tx00x00 - tx15x15)
|
16
|
Of course there are a few things that can throw a spanner in the works.
The most common being “missing” tiles – in some maps that only use a portion of the terrain, the texture tile where no play occurs can be removed to reduce the .RFA size – so this will stuff up counting them. If the last tile in the series is “missing” (eg: tx15x15) that will stuff up matching that to the table.
Something else you may have to work around is Texture offsets. This command is used in Init/Terrain.con to “move” the textures, and you may want to check this file to ensure that GeometryTemplate.texOffsetX and GeometryTemplate.texOffsetY are BOTH set to 0.
Next is a not so common occurrence ... non-standard maps where the Worldsize is not 4 times Heightmap Size as is the standard. Custom map makers may use something like a 512/4096 Level (Heightmap/Worldsize) to increase the playing area without increasing CPU requirements, or go the other way with a 256/512 level for greater detail in the terrain. Your best guide in these cases is the Worldsize which you can check in Init/Terrain.con the setting to look for is GeometryTemplate.worldSize.
Since there are only a few choices, if you don't get it right first go, at least you will know which one it isn't. ; )
In this case we look at Kursk's Textures folder, and we note there is 16 Texture tiles, and also that the highest numbered Tile is tx03x03.dds
This matches with a Standard 1024 Worldsize level and the value we need is 4. Lucky for us the setting in the .bat file is already the right value, but remember when doing other maps you may need to change this.
Save the changes to the .bat file, and then double-click it, to run the process. It doesn't take long for the magic to manifest

Browse into the dds_terrain folder, and there you have your Pathmap on a Map.

Cut all the .dds files, Browse to the Folder where Kursk is extracted, and Paste the new .dds files into the Textures folder and Overwrite all the old files.

You could repack the Kursk.rfa with these new textures, or even just make a _00x.rfa style update, but for now, viewing the map in an Editor will do fine. Coin Coin's Editor42 is used heavily in Pathmapping and its now time to fire this editor up and open the level.

And first up you will see this, and remember Black is Pathed Area, and white is Non-Pathed Area.

Now this explains thing much more clearly, note that around the Trees & Rocks and up the sides of Hills the Areas are white. These are the Non-pathed Areas that are used to keep the Bots from running into objects or going up slopes that are too steep, and the flat area that is directly ahead is mostly black, allowing Bots to roam free in this area.
Lets have a look at some other parts of the map.

Here we are at the Axis base we we're trying to look at earlier on the Pathmap, again seeing the Pathmap around objects gives you a clearer indication of how the pathmapping works.

Here we are looking straight down on the Sawmill Control Point. From here you can clearly see the Pathmap image, how blocky it is in relation to the buildings.
Note that there is a fair amount of area that is non-pathed or “Pathed Out.” around Objects. Cars are the fastest moving ground vehicles in Battlefield and this liberal non-pathed coverage around objects is to ensure the Bots have plenty of space between themselves and Objects while on the move. Tanks are slower and do not require as much space. Infantry is the slowest ground unit, and they also have the ability to follow the pathmaps with the highest accuracy of all the units and require no extra space to keep them away from objects.
As always, its always best to see this difference firsthand. We will Repeat the process with Kursk's Infantry1Level0Map.raw.
First, Import the Infantry1Level0Map.raw and then open the 8bit .raw in your Image Editor/Viewer.
(note: the following image is 50% of its original size)

The first difference you should notice with the Infantry Pathmap is how much more area is Black. Infantry units are able to get up much steeper slopes then Cars, they can also move through much tighter spaces and closer to objects then Cars. You will also notice that around Buildings and other objects the details are much finer, whereas the Car's Pathmap had objects pretty much blotted out.
Next, Use the Pathmap preview tool on the Infantry pathmap, and when you are done Open our hacked up level again in Ed42. Remember, you will need to change the tmpFileAI setting in the _convertTolevelTexture.bat file to match the Infantry pathmap.

We're back at the same place we started with the Car Pathmap, and again you will notice how much more area is Black.

Looking at the Axis Base again, the White pathing follows the objects very closely. I bet your wondering why there are so many gaps in the pathing of the fence, well ... nobody has ever said Dice's pathing was perfect ; )
Look closely at the Barn, you can just see a white edge on the left edge of the building. This is how the Pathmaps for infantry should be, just the right amount of Pathing. Too much Non-pathed area around the outside of an object is an opportunity for a Bot to get “stuck” and once a Bot is stuck in a non-pathed area, it will not be able to move until it dies and respawns elsewhere, or is pushed into a Pathed Area. This can happen when a Bot is thrown into a non-pathed area by an explosion or could be pushed in by a passing vehicle. On the other side of the coin, if an object is not completely pathed out, then it becomes an opportunity for the Bots to try and walk through walls and/or other objects.
What other possibilities or problems do buildings pose to Infantry ? Lets take a closer look at that Barn.

O dear ... a veritable minefield of obstacles. So how is it pathed ?
We can move the building in this copy of the map without doing any damage to the original level, so lets move the Barn to get a better view of the pathing. Use Ed42's object mode [Press F4] select the Barn, and use the mouse wheel [or Page Up/Down] to move the Barn down into the ground until the floor sinks below the terrain.

Hmmm ... its a bit rough in here, but you should get the idea. Notice that the ladder is Pathed Out. As pathmaps are only Two Dimensional, it is not possible to path the ground section AND the upper floor. To prevent the Bots from running into the ladder & accidentally climbing it, only to get lost on the upper floor, it is Pathed Out so the Bots avoid it entirely.
Ok, last stop in our rounds is the Sawmill again.

Just to hammer it in ... More Black, less White and the Pathing closely follows the objects. Again take note of how blocky the Pathmap is compared to the objects.
If you are making a Custom Level from scratch and you intend to add Bot support, you should pay careful attention to building placement, especially if you wish Bots to able to walk inside buildings. A well placed building is very easy to Path as the dimensions of Dice's Objects match the “blockyness” of the Pathmaps, whereas a poorly placed building could be very difficult to path, and maybe even impossible as the doorways may not be able to match up with the Pathmap's available pixels.
It is worth considering making a Pathmap or part of one, as a guide when placing Buildings & other static objects in the early stages of your level construction. This could form part of your planning, and would ensure accurate placement of objects to the Pathmap, which will be very important for buildings or tight locations that you expect the Bots to traverse.
Where you feel a building or is totally unimportant for Bot access, you can be less stringent, and even Path out the building completely to save time.
--------------------------------------------------------------------------------
Making Pathmaps
Ok, staring at these things all day will get us no where, its time we made our own Pathmap.
Open your favorite image editor and create a new image, your software should give you a window for you set the new image's properties. So far we know that we want an 8-bit Greyscale image, but what size should the Pathmap be ?
Pathmaps will always use the Worldsize as their resolution.
Kursk is a 1024 Worldsize level, and in case you didn't notice, the Pathmaps we looked at were 1024 x 1024 pixels
Even in non-standard sized maps the Pathmaps are based on the Worldsize. Eg: A 256 height map with a 512 Worldsize, instead of the “standard” 1024. The Pathmaps size will still be set by the Worldsize and should be 512 x 512 pixels
But we still don't know how big our Pathmaps should be ! Ok, ok .... we are making our Pathmaps for Aberdeen, so we will need to know the worldsize of this level. Browse to the folder where Aberdeen is extracted, and in the Init Folder you will find Terrain.con.

Open this file up and look for the line.
GeometryTemplate.worldSize 1024
Bingo, there is the Worldsize plain as day, and will set our new Pathmap image to 1024 x 1024 pixels. Change the appropriate settings for our new Pathmap, and if possible set the Background or Paper Colour to Pure Black (Index 0)
Photoshop

–=#=–
Corel Paint

–=#=–
Paint Shop Pro

–=#=–
If your new image is anything other Pure Black, use a Bucket fill or a BIG brush and ensure the whole image is totally and utterly Pure Black. So after all that, if you don't have an image like this, you have done something wrong.

Now we are going to start generating a few files, so in wherever you like to have your “working” files, make a new Folder (or tree) and we shall save the Pathmap in there, away from our Levels folders.
To start with if you are using Photoshop, it needs to be noted that Photoshop can be a pain at times, it has its little quirks and has a habit of asking questions about settings that we couldn't give a flying frell about. One quirk is easily worked around, whenever saving a 8bit .RAW from Photoshop choose from the File menu, Save As ...

We will start by saving the Pathmap for the Cars, ensure the filename is Car4Level0Map8bit.raw, and the Format is set to .RAW
Be aware of another Photoshop quirk that may add “copy” in the filename to Save. Keep your eyes on it just in case.
Photoshop will then bug you ... Header: 0 is fine

And again, Photoshop will bug you, Printer settings we could not care less about, just hit Ok.

Paint Shop Pro is also capable of saving directly to 8bit .RAW

Now use the Save As ... again, and save the same image as Infantry1Level0Map8bit.raw and another Saved As ... Tank0Level0Map8bit.raw

IF YOU ARE NOT USING PHOTOSHOP
Flyrawgui comes to the rescue again! If you don't have Photoshop or you prefer to use another Image Editor that cannot save directly to .RAW, you can save your Pathmap as a 8bit .BMP (Windows Bitmap) and use FlyRawGui to convert the 8bit .BMPs to 8bit .RAWs.
First save your new Pathmap Image as Car4Level0Map.bmp. If your software has a Colour Depth setting in the Save dialog, make sure it is set to 8 Bit Greyscale. Also make sure the image is saved Uncompressed if the option is available.

Then use the Save As ... option, and save the same image as Infantry1Level0Map8bit.raw and another Saved As ... Tank0Level0Map8bit.raw

Now, start FlyRawGui and select Convert BMP to RAW.

Browse to the Folder you have save the .BMP files, and Open Car4Level0Map8bit.bmp to convert it to raw.

Repeat the conversion for Infantry1Level0Map8bit.bmp & Tank0Level0Map8bit.bmp

Don't worry about the .ACT files. You may recognise them as a Photoshop Colour Table file, but for our purposes it is just luggage we have to work around. You can keep deleting them if you like, but you may get sick of doing so.
From here onwards you may find it handy to sort the files in a Window by Type as i have above, this groups the files together according to Filetype and may make it easier to find the file you want when things start getting crowded.
--------------------------------------------------------------------------------
Packing Pathmaps
We now have three 8bit Pathmaps, one for each unit class, but before they are usable by Battlefield we need to pack them in the same format as Dice has used. Again, its Rexman's tools to the rescue. Browse to your Ai_Tools folder and open the 8bit folder.

This is where the Ai Pathmap Packer resides, and much like the Pathmap Previewer requires several steps to do its job. Thankfully it can all be done with just a double-click of _pack.bat
There is a two things we need to do, so the Pathmap packer is ready for use.
First, Edit _pack.bat and change the line,
set AIOUTDIR=..\
to
set AIOUTDIR=Pathfinding
Then save and close the file. You now need to make a new folder of the same name.

Now when you double-click _pack.bat, 8bit .RAW Pathmaps that are in the same folder, will be converted to Dice's RAW Format and all the files that are required will be created in the Pathfinding folder we just created. Try it now, there are some sample Pathmaps already here. Double-Click _pack.bat and a Command Prompt window will appear briefly, now browse into the Pathfinding folder.

Well this is good, we have 15 files again and seems our little test was successful. Delete these test files and lets repeat the process with the new Pathmaps we have created. Browse to your “working” folder, and Copy the three 8bit .RAW pathmaps your saved earlier.

Next, back to the Ai packer's Folder and Paste our Pathmaps here, and overwrite the existing files.

Double-Click _pack.bat again, and then browse into the Pathfinding folder.

If all has gone well, we have 15 files again. Notice the files are quite small, this is due to the Pathmaps being totally Black, and as your Pathmaps increase in detail and complexity the filesize will also increase.
Now that we have our new Pathmaps converted to the type of files required by Battlefield, we could quite happily use these in a level. They will not do their job properly, since they are all Black and do not actually “Path out” any objects at all, but they will allow the Coop mode to start. This can be useful in getting a basic Ai package up and running as quickly as possible, just ignore all the Bots headbutting walls.
Full Black pathmaps can also be useful in testing. If your Bots are not moving at all, you can check your Pathmaps by temporarily replacing them with Black Pathmaps, and if the Bots suddenly start moving, you now know that your Pathmaps are suspect. If the Bots still do not move, you can at least remove bad pathmaps from the list of possible problems.
- END OF PATH 1 -
--------------------------------------------------------------------------------

Credits:
Arc D'Wraith – Author
Coralon – Feedback & Additional Material
Muzzi – Additional Material
White Thunder – Title Banner
Special Thanks to the toolmakers, for without your work modding Battlefield would be a joke.
Resources:
Bf1942 Modder's Wiki
bf42.com Editing Forums
Original Battlefield Maps
Tools Used:
Battlefield 1942
Corel Photo-Paint 8
Ed42
FlyRawGui
Notepad
NVDXT
Rexman's Ai Tools
RFA Extractor
TGA Merge
TGA Splitter
Open Office
undxt
Please excuse my english, i'm Australian ; )
ps. yes i do hate photoshop
|