AI Relations (Editing): Difference between revisions
Line 25: | Line 25: | ||
== Default Relationships == | == Default Relationships == | ||
Even if you're starting your map from scratch, the game will always load a set of default relationships from the entityDef '''atdm:team_relations_default'''. | Even if you're starting your map from scratch, at map start the game will always load a set of default relationships from the entityDef '''atdm:team_relations_default'''. Any relationships not defined in there are automatically made enemies ''between'' teams and friends ''within'' teams (members of Team 2 are friendly to other members of Team 2). | ||
You can view this set by opening the <tt>tdm_team_relations.def</tt> file, but '''do not alter''' these values. See the next section about how to specify custom team relations. | You can view this set by opening the <tt>tdm_team_relations.def</tt> file, but '''do not alter''' these values. See the next section about how to specify custom team relations. |
Revision as of 15:18, 13 March 2009
Originally written by Ishtvan on http://forums.thedarkmod.com/topic/1636, additions by greebo 2009-03-13
AI Types (Teams)
Different AI types are defined by their team property. Put simply, AI on one team will generally be friendly to each other and antagonistic to AI on some other teams and tolerate yet others. Some AI teams are passive and will flee; others will attack. These are the default values for the team property and their team type:
- 0 = player
- 1 = builders
- 2 = city watch, houseguards
- 3 = nobility, commoners
- 4 = inventors/engineers
- 5 = street people, beggars
- 6 = criminals
- 7 = pagans
- 8 = mages
- 9 = revenants, zombies, skeletons
- 10 = ghosts
- 11 = werebeasts
- 12 = spiders & spider queen
- 13 = belchers
- 14 = rats & other passive animals
- 15 = elementals
Mappers can change the team of individual AI entities by setting the team property to a new value but this is generally for special situations where for example, an individual(s) from one team is meant to have 'joined' another group. But to change the relationship between teams, eg, two normally friendly teams become enemies or vice versa, see the following sections.
Default Relationships
Even if you're starting your map from scratch, at map start the game will always load a set of default relationships from the entityDef atdm:team_relations_default. Any relationships not defined in there are automatically made enemies between teams and friends within teams (members of Team 2 are friendly to other members of Team 2).
You can view this set by opening the tdm_team_relations.def file, but do not alter these values. See the next section about how to specify custom team relations.
Inputting Team Relationship Info in the Editor
To specify relationships for your own map, create an entity atdm:team_relations in your map. (A small rectangular entity will show up.) Override certain relationships by adding spawnargs to this entity in the following way:
"rel 0,2" "1"
The left-hand key holds a pair of numbers defining the team numbers the relationship refers to, the right-hand value holds the type of relationship. Read this spawnarg like this:
Team 0 considers Team 2 as friendly.
As you might suspect, the right-hand value has the following convention:
- Negative (value < 0): hostile
- 0 is neutral
- Positive (value > 0): values
Important
The above spawnarg does not imply that team 2 regards team 0 as friendly too. This has to be specified explicitly, defining the asymmetric matrix element.To define the relationship for the reverse (team 2 => team 0), add a spawnarg like this:
"rel 2,0" "1"
Note that it is indeed possible to define a different relationship for 0 => 2 than for 2 => 0. Also, it's possible to define the relationship for the team itself, like
"rel 2,2" "-1"
This lets members of team 2 consider all members of the same team as hostile.
One small note about the atdm:team_relations entity: this entity will pass its spawnargs to the relationship manager at spawn time and remove itself immediately afterwards, so that you don't have an unnecessary entity floating around your map.
Why set the diagonals?
It might seem weird to define a team's relationship with itself by setting "rel 1,1" to something, but later on we might want to have a "rogue team," like beasts that attack everyone, even other members of the "beast" team (eg, a cannibalistic predator or something). Also, the team's relationship with itself can be thought of as "morale," and we can maybe check this number to see how likely they are to come to each other's aid in combat and stuff like that.
Just to emphasize, you don't HAVE to set the diagonals, they will be set to some default value (5) if a new team is added to the relationship matrix. If you want team X "every man for himself" and attack its own members, set "rel X,X" explicitly to a negative value.
Changing Relationships during the Game
To let relationships change during runtime, you can use triggers or scripts. There is a trigger entity called target_tdm_setrelations which can hold the same type of relationship spawnargs as described above. To activate these settings, just trigger this entity. Note that you can even trigger this entity multiple times, so you can re-use it, if you ever wanted to.
If you're switching teams to friendly, remember to define both directions of the relationship on these types of entities ("0,2" as well as "2,0").
What happens if a Team is not mentioned at all?
If an AI is present in the map (or maybe is spawned by script later during the game), whose team is not mentioned in the matrix (like, say, team 60), the relationship code will handle this gracefully and consider this team as hostile to all the other teams. Still, members of team 60 are friendly to all other members of team 60 by default.
Debugging Relatinships
Use the following console command to dump the current values of the relationship matrix to the console:
tdm_ai_rel_print
This will produce a rather long list, so you might want to use the condump command to write the console output to a file for later studying.
Also, watch out for console warnings during map start, which might indicate syntax errors of your spawnargs. Finally, it's also possible to use the log file. Activate the AI log class to see any messages coming from the relationship code.