AI for Mapping - Subject9x/battleMETAL GitHub Wiki
(this is up-to-date for current release, however I am taking a look at some medium sized tweaks to AI behavior which may not be shown in this article, but I will update asap. 10/21/2020)
This is not an article on all the intricacies of how the AI works, (article todo), instead this will be about how AI is placed onto a map to make sure they work and their placement jives with your map.
The first part is knowing where the AI Units are for mapping - they are all located under unit_*
in the point entity
context menu.
From here you can place copies of all enemy vehicles in the game.
they are filtered by the following tags
_type
_faction_
_style
There are 5 vehicles and 3 mechs in regular battleMETAL.
- Dunerunner - 'hover' tank.
- Foslager - regular tank.
- Onnek - turretless tank destroyer.
- Sorcerer - turretless missile carrier.
- Trowel - heavy battle tank.
- Balaket - light mech.
- Warden - light mech.
- Sapper - medium mech.
- Matok - medium mech.
- Monitor - heavy mech.
- PSC - default 'player' faction.
- Survest - aristocratic but low technology.
- Militar - high-tech corporate overlords and mercenaries.
Now type is a bit more flexible. In the grand tradition of mech games, units usually have a large amount of variants trying to fulfill a niche on the battlefield. I broke it down to 3-4 main types.
-
Brawler
- generally equipped with short-range weaponry, best fighting under < 600 game units. Usually not geared to breaking shields. -
Zapper
- designed to attack and destroy shields, but weak at full damage output. -
Lobber
- carries 'lobbed' weapons like missiles, artillery, plasma...terrible shield damage. -
Gunner
- mostly 'ballistc' / non-shield breaking items.
So the types give you a general idea of where these AI fit into combat scenarios.
release v1.0.4+ The biggest task for AI is setting up the nodegraph, without this however, your AI will just stand in place. The Nodegraph allows your AI to navigate the terrain semi-competently.
To make the nodegraph, it is recommended you create a new layer
in Trenchbroom just for these.
Next, you place ai_node_path
entities all over your map according to the following pattern:
- Each
ai_node_path
entity has a max of 6 connections or edges to other nodes.- 'edges' tell the AI which nodes are valid to try walking to when path-finding.
- max length of an edge is 512 game units.
- When the engine generates
edges
for each node, the following items block an edge-connection:-
Brush
- contents =MONSTER_CLIP
-
Brush
- contents -BOT_CLIP
-
Entity
-building_*
orscenery_*
entities. -
Entity
-map_terrain
-
- nothing else will block edge connections, so don't worry about AI placement too much, they won't block the nodegraph generation.
-
angles
- the engine will test to make sure 2 nodes don't have a pitch difference greater than 45, this is aslope-block
check because AI cannot move up hills > 45 degrees.
If the ai_node_path
placement satisfies the above conditions, the engine will link the 2 nodes together.
note botclip
brushes are a great way to enforce AI paths, an example is putting them as walls on stairs/ramp.
note the engine cannot calculate paths for elevators / trains at this time.
You must place valid ai_node_path
entities everywhere on your map you want AI to be able to go.
Now for the slightly less annoying work.
- Save a copy of your map, then build it the normal way, generating a
.bsp
. - load this map up in
battleMETAL.exe
and go to it via consolemap <your map
. - switch
developer
mode on by using console commanddeveloper 1
and thenrestart
the map. - you should see all your
ai_node_path
objects on the map as orbs. - in the console, type
cmd m nodexprt
then close the console
- you should then see the console print out, line-by-line, the nodes being exported.
- this may take a while depending on how many nodes you placed.
- when this is done, you should fine the
.nodes
file over at (windows)/user/<user>/Saved Games/battlemetal/metaldata/data/maps
- plug that file into
/metaldata/data/maps/<your map>
-
restart
your map.
- with
developer
you should see theNODE_COUNT
in the console, and it should be > 0, indicating the file loaded.
- your AI should now be able to move around the map.
note .nodes
files, once generated, are separate from the map:
- if you update the map, you might have to regenerate the nodes.
- it is also strongly advised to make a final map that has no
ai_node_path
entities because they take up space on the server.
AI can be setup to run on specified paths. This uses the ai_node
map entity.
- Place any number of these entities on the map just like you would
ai_node_path
. - make sure each
ai_node
is next to aai_node_path
- patrol nodes are 'meta data' that need a nodegraph to work. -
.targetname
- required used by AI to find nodes, and used by nodes to link to other nodes. -
.target
- optional can be otherai_node
entities, orempty
, when empty, the bot will reach this node and just hang out. - AI can mostly path to a node they can't reach, so AI don't exactly need to start right next to a node.
required make sure all unit_*
that are to use these patrol nodes have .target
match .targetname
of their starting node.
If you've done it correctly, when the bots spawn into your map, they will move towards their assigned nodes.