AI Relations (Editing): Difference between revisions
Line 3: | Line 3: | ||
==AI Types (Teams)== | ==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 values for the '''''team''''' property and their team type: | 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 | * 0 = player |
Revision as of 15:07, 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
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. By default, all teams are friendly to itself (team 2 is friendly to 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.