Custom Maps - THF Map Editing - Bots' Routes
 

This section contains informations on making bots' routes


Bots's route Tutorial


Introduction:

THF integrates bots, or if you prefer, artificial intelligence computer-controlled players. Those bots were implemented in THF using the source code of Grinbot II, the first bot mod for Heretic II coded by Grin.

Starting from this, deathmatch bots, Gwynhala enhanced them and made them able to play something much more complex: a player classes, level-based, teamplay driven and mission oriented mod.

While they aren't perfect or as smart as real players, they can be really good if the map they are playing on is not too complex and if the routes they are using are well done. So lets now talk bots routes.


Bots' routes: (What follows was taken from Grin and adapted to THF)

The most important thing the bots need to know is where they are, and where they can go. They don't see the level as we do, but get this information from a series of waypoints, or nodes.Not exactly original or ground-breaking, but it works well.

The route files contain the location of these nodes and a table that describes wich nodes are linked, along with the length of the link. This information is then used to generate another table that tells them the shortest path from any node to any other node. There is also a table that holds information about the location of all the good stuff on a level, such as items, shrines and teleporters.

The placement of the nodes, and the creation of the links between them needs to be done carefully to get the best performance from the bots.

Getting started

1) Debug mode

To edit and tweak the bot routes, you need to start a listen server in bot debug mode. To do so, execute the "Server Listen Bot Debug.bat" located in your "THF_5" directory or start a server with the "botdebug 1" parameter. Note that in order for this to work, you will need to have the server files in the root of the "THF_5" directory. Also note that when "botdebug" mode is on, the nodes and routes arent loaded automatically This means you will have to load them manually each time.

2) Loading nodes

Type "loadnodes" at the console to load the node file. When this is done, you will notice a message that reads "Node:25 Type: spawn point", or something very similar. If you walk around, this message will change. These messages tell you wich node you are close to, and what type of node it is.



If you type "shownodes", you will be surrounded by eggs, which show the location of each node ("shownodes" again will turn off this display. Leave it on for now)

3) Building paths
Now, there are a couple of things we need to do before the bots can use the route. Type "buildpaths", wait for it to finish, then type "builditems". "Buildpaths" generates a list of the shortest route from any node on the map to any other node on the map.

"Builditems" creates a list of all the items on the level. When this is done, the bots now have a complete set of information describing the level and everything within it, which they can use for navigation and decision making.

4) Testing
Turn Botdebug off by typing "botdebug 0" and then reload map. Then type "sv bot spawn" to bring a bot into the game. This will spawn a random bot. It will start to run around and get stuff. Information about what the bot is thinking is displayed on the screen. You can spawn a few more, watch them, and get an idea of how they use the nodes. To stop the bots attacking you, go into god-mode using "playbetter".
This route took about 5 minutes to make, and about 15 minutes of tweaking. There's still room for improvement. You can type "sv bot kick" to remove all bots.
.

Building a route from scratch


1) Loading map
It would be wise to back up you routes and nodes files you have in THF/grinbotsII/routes and /nodes, if they are any, before continuing. When done, load a THF map and type "shownodes".

2) Building basic nodes
No nodes will be displayed, as there aren't any yet. The next thing to do is type "build" into the console. This creates nodes for every item, shrine, teleport, rope, platform, spawn-point and teleporter-destination on the map. It also links teleporters to their destinations, and a few other bits and pieces.

3) Placing other nodes
Now, the task at hand is to fill in the gaps. You need to place nodes each side of doorways, arches, at the entrance and corners of corridors. You need to make sure that the bots can get where you want them to go without banging into things too much. They do have some obstacle-avoidance code, but try and make the route so that they don't need to use it. You also need to place the nodes so that the route they take looks as 'natural' as possible. The only way to learn what works well and what doesn't is to try it.

To add a node at your current position, type "addnode" into the console. I recommend that you bind this to an easily accesible key, as it will be used often.
When you have finished, save what you've done by typing "savenodes". This will create a file called dmlight.grn in the nodes\ folder. Nodes can be moved, but at the moment they can't be deleted. To move a node, type "movenode <nodenumber>" (without the <>) and the node will be moved to your current position. You can save the route whenever you like.

Linking the nodes together:

1) Auto nodes linking
You now need to define which nodes are linked. These links can be one-way or two way. Type "autolink 256", and the mod will try to automatically link together nodes that have a clear line of sight between them, and are closer together than the value specified.256 is a good value to start with. Nodes that differ greatly in height, or are further apart than the value given will not be linked, but we can do this manually.

2) Manual nodes linking
Type "linkmap" into the console. This is a toggle command that turns linking on or off. Now walk around the map. If you walk between 2 nodes that have not been autolinked, you will see a message such as path update: "node 36 -> node 31" telling you that a new link has been created. This is a one way link, so if you want node 31 to be linked to node 36, you need to walk back to the previous node.

You need to be careful here to stay close to the nodes, or stray links may be created. You will need to make sure that you walk up and down stairs and slopes, and also jump to high spots/low spots that you want the bots to reach. There is no limit to the length of a link. When you have made sure that there are links to everywhere you want the bots to go, save the route.

3) Building paths
Before the bots can use this route, you will have to "buildpaths" and "builditems". Then you can spawn a bot, and see how well it does. If the bots are failing to get from one node to another, you can remove the link they are trying to follow using "deletelink" <node1> <node2>". If you remove a link or add a new one, you will need to buildpaths before you notice the effect.

Before entering a teleport, turn off linking, otherwise stray links will be created. Also, don't use the teleport spell when linking is turned on, as this will also create bad links.
Now that we have the bots performing well on the level, it is time to save the finished route. The "saveroute" command will create a file in the grinbots2\routes\ directory called dmlight.gr2. This file contains the complete navigation data, and this will be loaded by the game at the start of the level when it is run with botdebug off (botdebug 0).

You can delete a link between 2 nodes by using the "deletelink X Y" command where X is the number of the starting node and Y the number of the destination node. Note that the link will only be deleted one way, if you want to delete both directions you will need to use the "delete link command again with the starting and ending node numbers inverted.

After you have linked nodes together and used the "buildpaths" command while shownodes is on, you will notice that the "eggs" representing the nodes will sometime change to red. This shows you all the nodes that are currectly linked to the node you have touched last. Use this visual information to check the links between the nodes and correct them if necessary.

4) tweaking the routes for THF
Here are some commands THF-specific commands that will help the bots behave a bit better.

You can use the "addnode 16" command to make an alternate route nodes. Place one of these about half-way along each path from the light to the goal, and the bots will sometimes take different paths to the goal.

You can also use "addnode 18" command to make gate block nodes. Place one of these on each side of a door or gate that can be opened and closed using a switch.
Not needed for automatically opening doors.

Tips

1) Making decent bot routes is all about trials and errors. You have to try it and find out for yourself how is has to be done for each map. Make a quick route with a minimal number of nodes, save your work, load the map with "botdebug" turned off and summon a few bots. See how they play and try to make changes according to their behavior.

2) In my experience, the best route is not always the one with nodes everywhere on the map. Sometime you will obtain better results with a minimum number of nodes. Bots dont need to go everywhere but to the most important spots.

3) The more complex a map is, the harder it will be to make a decent route for bots. Things like elevators and rope make it harder for bots.

4) The "botfill #" command can be use to fill the server with bots until a certain number of player (#) is reached. Make sure the "#" for "botfill" is lower then "maxclients" by at least one.

5) THF bots will react to most of the THF voice commands like "followme", "powerme", "healme" and so one.

6) Bots' routes are only needed and used on the server machine, not the client

7) you can change the status of a node with the movenode command. Say you want to change a normal move node to alternate node, you would type movenode X 16. Here is a list of all the node type and their respective number value (note that some aren't doing anything yet). Note: to chnage a special node back to a normal move node you will have to use "-1" as the node type, example: "movenode 124 -1".

0= normal move node
1= water node
2= rope top node
3= platform top node
4= platform bottom node
5= platform bottom node
6= teleporter node
7= teleporter destination node
8= spawn point
9= jump node (usefull for air vent/tunnel)
10= unkown
11= male spawn node
12= male spawn node
13= female spawn node
14= walking move node
15= creepiong move node
16= alternate path node
17= hiding spot node
18= gate block node
19= switch node

8) It can be usefull sometime to have a one way path only between nodes. A good example of this is having nodes in water that will only go out of water but not in it. That way bots will be able to get out of water but wont try to jump in water on purpose.

9) It is also helpfull of have "botdebug" on and spawn bots. That way you can check the message in console and see what bots are doing and where they get stuck and try to fix it later.

Command list

The following is a list of commands that can be used in debug mode during route creation. Many of them were created to help me develop the AI, and aren't needed any more, but here they are anyway.

- commands - displays a list of commands
- build - creates a new node list
- addnode - add a new node at your current location
- addnode 16 - add a new alternate route node at your current location
- addnode 18 - add a new gate block node at your current location
- movenode <nodenum> - move node to your current position
- movenode <nodenum> <nodetypenum> move node to your current position and change its status to another
- deletelink <start> <end> - remove a link between 2 nodes
- shownodes - toggle the node display on or off
- loadnodes - load a node file for the current map
- savenodes - save the node file
- saveroute - save the finished route file
- loadroute - load a finished route file
- linkmap - toggle dynamic linking on or off
- autolink <threshold> - automatically link nodes
- relinktele - updates teleporter information for routes generated with v01.
- clearlinks - removes all links and re-sets the link table
- buildpaths - generate path table
- builditems - create item lookup table
- listnodes - write node list to a text file
- listlinks - write link table to a text file
- listpaths - write path table to a text file
- listcosts - write cost table to a text file