Assault: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
m (→‎Structure: Unicodifying, replaced: [[Image: → [[File:)
 
(41 intermediate revisions by 14 users not shown)
Line 1: Line 1:
An assault consists of four component types:
The purpose of an assault is to make one or more NPC(s) tactically advance along a predesigned route, securing tactical points along the way. It is much more flexible than a [[path_corner]] entity.


* ai_goal_assault
An assault consists of two or three component entities:
* assault_rallypoint
* assault_assaultpoint
* [[info_node|info_nodes]]  for pathfinding


Its purpose is to coordinate a group of NPCs to follow a designed route. In this regard it is quite similar to [[path_corner]]: the differences revolve around assaults being designed for combat situations.
* [[ai_goal_assault]] (1 per assault, optional)
* [[assault_rallypoint]] (1 per NPC)
* [[assault_assaultpoint]] (any number)


An assault is also far more flexible. An assault can have multiple paths that are chosen by the AI based on their surroundings and hints from the mapper. An assault can be suspended (e.g. to clear a room not directly on the chain) and resumed, again dynamically but with design-time influences. You can order an assault to pause until another event has occurred with far more precision than previous systems. This article will detail how to use them, but please be aware that AI was previously undocumented so mistakes are inevitable.
This article will show you the overall picture on how to set up an assault. (For entity specific information, see the related entity.)


==Structure==
{{tip|Use the console command <code>ai_debug_assault</code> for basic visual information about where NPCs are headed to.}}


<center>[[Image:Assault_diagram.png]]</center>
{{tip|Note that assaults don't seem to work with all NPCs, such as fast zombies. You may need to use the [[aiscripted_schedule]] or [[scripted_sequence]] entities instead.}}


NPCs follow the structure of rally and assault points they are attached to by an AI goal.
__TOC__


===ai_goal_assault===
==Structure==
 
This entity specifies what NPCs are to carry out the assault and triggers it when any conditions given are met.
 
* '''Actor(s) to affect:''' Enter the name of the actors that will perform the assault. This field supports wildcards, should they be needed.
* '''Rally Point Set:''' The name of the assault_rallypoint at which this assault will begin. This field can also support wildcards, which will be matched with the wildcards in '''Actor(s) to affect'''. This means that rebel_1 will go to rally_1, rebel_2 to rally_2, and so on.
* '''Search Type:''' It is also possible to specify classes. If your NPCs do not have names, or you want all NPCs of a certain type to join the assault, you can set this to 'Classname' and make the appropriate changes to '''Actor(s) to affect'''.
* '''Assault Cue: ''' The goal can be set immediately after being activated, after it has received an input through the I/O system, or when the entity 'hears' gunfire depending on the setting here.
 
===assault_rallypoint===
 
All assaults begin at a rallypoint. Specific differences are currently unknown.
 
* '''Assault Point:''' The first assault_assaultpoint in the chain.
* '''Assault Delay:''' The amount of time to wait here once the assault has begun before moving to the first assault_assaultpoint.
* '''Rally Sequence:''' Set a specific animation sequence for NPCs waiting to begin the assault.
* '''Priority:''' If an NPC is faced with multiple assault_rallypoints, it will choose the best from it’s knowledge or take the one with the highest priority.


===assault_assaultpoint===
An assault consists of an AI goal (the [[ai_goal_assault]] entity) gathering a set of one or more NPCs (called ''actor(s)'') to one or more "rally point" locations ([[assault_rallypoint]] entities) where they will normally await a cue to commence the assault. On this cue, they will proceed to the first "assault point" location ([[assault_assaultpoint]] entity) to secure, or 'clear' it, and then proceed on to the next assault point (if any), clear it, and then proceed to the next, and so on.
Clearing an assault point, by default, consists of standing on its location and ensuring that there are no hostiles in sight for the timeout period, but this is completely configurable.


The body of an assault chain. Specifies where the assault should go once it has begun. There can be any number of assault_assaultpoints in each chain and they do not need to be linked in a row. An assaultpoint can link to a rallypoint and move the assault on to a new chain.
<center>[[File:Assault_diagram.png]]</center>


'''It is important to remember that assaultpoints affect the journey ''to'' them, not ''from'' them.'''
Assaults can be triggered in one of two ways:


* '''Assault Hint Group:''' Constrain NPCs in the assault to this [[hint]] group.
# When activated, an '''ai_goal_assault''' entity can send its ''actor(s)'' to the associated ''assault_rallypoint(s)'', where they wait for the assault cue. This is the most common usage. The ''ai_goal_assault'' entity can either be activated by an ''Activate'' input, or set to start active through its ''Start Active'' keyvalue, which causes the assault to begin as soon as the map is loaded.
* '''Assault time out:''' How long to wait with no activity at this assaultpoint before moving on.
# [[npc_combine_s|Combine soldiers]] may be instantly associated with a rally point without the use of an ''ai_goal_assault'' entity. Using the entity [[Inputs and Outputs|I/O system]], you can fire the '''Assault''' input on the soldier, providing the name of the ''assault_rallypoint'' as an input parameter. When a Combine soldier receives this input, it will search for the specified [[assault_rallypoint]] entity, move to it, and then proceed immediately to the associated ''assault_assaultpoint''. Please note that although the ''Assault'' input can be sent to any NPC ''it is only ''supported'' for Combine soldiers''. You may use wildcards when specifying the rally point in the parameter. You may also use the ''priority'' keyvalue of an ''assault_rallypoint'' entity as a parameter to influence this decision, if providing a wildcard which specifies more than one ''assault_rallypoint'' entity.
* '''Clear on contact with enemies:''' If the assault meets enemies on it’s way to this point, it will consider it cleared and target the next point in the chain.
* '''Allow diversion:''' If the assault comes into contact with hostiles on the way to the point, divert to kill them and resume once the area appears clear.
**If it set to '''Yes''' NPCs will chase any hostiles until they are dead or out of sight for the period set in '''Assault time out'''.
**If this is set to '''No''' assaulting NPCs will run non-stop to the next point, attacking enemies they can see but not chasing them.  
* '''Never Timeout:''' Force NPCs to try and reach this point forever, with no timeouts.


==Advantages==
While an assault requires extra work to set up, and the end result is very similar to other ai entities, such as [[aiscripted_schedule]], assaults do allow for more flexibility than other scripting entities.
* You can select a group of NPCs
** Other scripting options can do this too, but this often results in the entire group heading toward a specific point, or only one member of the group moving. To create similar results, each individual npc would need to be scripted.
* More control
** With options such as "allow diversion" and "clear on contact", the mapper has more control of when an ai stops moving. Unlike an [[aiscripted_schedule]] set to interrupt on "general", which can be broken by gunfire or other sounds.
* An NPC will realistically stick to one place
** Without a combination of hintgrouping and moving to a [[path_corner]] there aren't any other options to have an ai stay at one point. Also, unlike the hintgroup set up, the ai will move to avoid grenades or reload.


* '''Flag: Clear this point on arrival, UNCONDITIONALLY:''' Move on to the next point once reaching this one regardless of any other influences.
==Major options==
The assault behaviour offers a flexible degree of customisation among the entities that make up an assault. This list's purpose is to provide an overview of the major options (beyond entity placement). Consult each entity's individual page for more detailed information.
* '''ai_goal_assault''':
:Keyvalue '''AssaultCue''': Determines what will cause the NPC to move off their rally point and begin the assault.
* '''assault_rallypoint''':
:Keyvalue '''priority''': Determines how appealing the rally point will be to an NPC when it has multiple rally points to choose between.
:Keyvalue '''assaultdelay''': Time to wait at rally point after assault cue, before beginning assault.
{{Note|If '''allowdiversion''' is set on the next [[assault_assaultpoint|assault point]], an NPC can divert from the [[assault_rallypoint|rally point]] as well.}}
* '''assault_assaultpoint''':
:Keyvalue '''assaultgroup''': Constrain an NPC's hint node use to this hint group.
:Keyvalue '''assaulttimeout''', '''nevertimeout''': How long to wait without seeing enemies before considering the point cleared.
:Keyvalue '''clearoncontact''': Whether to clear assault point if the NPC encounters enemies while moving to it.
:Keyvalue '''allowdiversion''': Whether the NPC should move to engage enemies it encounters or ignore them and follow the assault points.
:Spawnflag '''1''': Clear point upon arrival, unconditionally.


==Limitations and bugs==
==Examples==
 
===Example map===
* When moving to an assaultpoint, all assaulting NPCs will wait for any others before continuing. If there is only one NPC it will go to the standing posture for a moment before continuing, which looks unnatural.
[http://www.steamreview.org/external/vdc/assaults/assault_simple.zip This example map] contains a single NPC on a linear chain using all the major options available to designers when moving NPCs from assaultpoint to assaultpoint. There are four points, and each is configured differently:
 
* NPCs will always arrive at a rally or assault point and turn to face in the direction the entity is set to. This is again unnatural in most cases.
 
* NPCs must stand on or near an assaultpoint to clear it if '''Clear on contact with enemies''' is not set and triggered. This can result in illogical backtracking.
 
* If enemies are in view of an assaultpoint, they will be seen just before the point is reached and probably calculated using the wrong (previous) settings. To avoid this, try to ensure assaultpoints are always in 'safe' areas.
 
==Example==
 
This example map contains a single NPC on a linear chain using all the major options available to designers when moving NPCs from assaultpoint to assaultpoint. There are four points, and each is configured differently:


# '''Clear on contact with enemies''' is enabled. When the NPC sees the hostiles, it clears out the assaultpoint and continues to 2.
# '''Clear on contact with enemies''' is enabled. When the NPC sees the hostiles, it clears out the assaultpoint and continues to 2.
Line 70: Line 60:
# '''Allow diversion''' is set to '''Yes'''. The NPC will divert from moving to this point until there are no hostiles visible.
# '''Allow diversion''' is set to '''Yes'''. The NPC will divert from moving to this point until there are no hostiles visible.


Note that the Metropolice cannot harm the NPC and will not attack you in this example.
Note that the Metropolice cannot harm the NPC and will not attack the player in this example.
 
===Prefabs===
The [[npc_metrocop_assault]] and the [[npc_soldier_assault]] prefabs contains complete setups of a mass assault of metrocops and soldiers respectively.
 
==Notes==
* If "clear on contact" is set, a single enemy might clear not only the current assaultpoint but the next one(s). A consequence of this is that if an NPC encounters an enemy on the way to a "clear on contact" assaultpoint the assaulting NPC may never proceed to another rallypoint. This occurs regardless of the subsequent assaultpoints "Clear on contact" and "Allow diversion" settings.
* If "allow diversion" is set and the NPC encounters an enemy, the assaulting NPC will pause for a while after killing the enemy before proceeding. The article says that this pause is the length of the "timeout" setting, but in my tests it was several times as long.
* If an NPC encounters an enemy on the way to an assaultpoint marked "allow diversion" but not "clear on arrival" the assaulting NPC will be pausing twice. Mappers might need to consider this if timing is important.
* An assaultpoint with both "clear on contact" and "allow diversion" causes weirdness: if an enemy is encountered on the way to the assaultpoint the assaulting NPC will kill it, but then upon reaching the assaultpoint will not pursue or return fire from other enemies until the ''next'' assaultpoint is reached. In fact, the assaulting NPC doesn't even change direction to face the fire. This happens regardless of the "clear on arrival" or "never time out" settings.
* I didn't observe any effect of the "never time out" setting. However, all firefights were fairly brief, so it might not have had a chance to come into effect.
* All-settings-off is great for making the NPC dash to a point regardless of enemy fire and then attack everyone at the point.
* Having only "clear on arrival" on is great for making the NPC dash from point to point without pausing, regardless of enemy fire.
* The OnAssaultClear output is only fired for the ''last'' assaultpoint in a chain. All assaultpoints will fire their OnArrival output, however.
* The delay after a "Allow diversions" diversion is about 18 seconds for a 3-second "timeout" time.
* A diversion causes another such delay immediately upon reaching the assaultpoint, and then the assaultpoint OnArrive ''re''-fires. If the NPC is again diverted before the timeout, the OnArrive output will fire again, ''ad infinitum''. So don't spawn enemies during from the OnArrive output.
* If the first assaultpoint is set to "Clear on contact" and an enemy is sighted before reaching the assaultpoint, the assaulting NPC will never make it to the assaultpoint. If the subsequent assaultpoint has "Allow diversion" off, this will cause ''that'' (or perhaps the final) assaultpoint to fire the OnArrival output&mdash;despite the assaulting NPC being nowhere nearby and having not even gotten to the first assaultpoint, nor having yet finished dealing with the enemies. If, on the other hand, the second assaultpoint has "Allow diversion" on, no messages are sent whatsoever.
* In [[Half-Life 2: Episode One]] and [[Half-Life 2: Episode Two]] rally points behave differently than in [[Half-Life 2]]. If there is an assault point with "Never Time Out" in the assault chain connecting to a rally point, than that rally point will be "locked" and unusable until the NPC on the chain dies.


[http://www.btinternet.com/~varsity_uk/VDC/Assaults/assault_simple.zip Example (VMF)]
==See also==


==Conclusion==
* [[Dynamic assaults]] - A simpler system, for assaulting the player or other NPCs.


Assaults are extremely powerful, flexible tools which in conjunction with other AI controllers can create believable strategic behaviour of infinite complexity.


[[Category:AI]]
[[Category:AI]]

Latest revision as of 06:27, 8 January 2024

The purpose of an assault is to make one or more NPC(s) tactically advance along a predesigned route, securing tactical points along the way. It is much more flexible than a path_corner entity.

An assault consists of two or three component entities:

This article will show you the overall picture on how to set up an assault. (For entity specific information, see the related entity.)

Tip.pngTip:Use the console command ai_debug_assault for basic visual information about where NPCs are headed to.
Tip.pngTip:Note that assaults don't seem to work with all NPCs, such as fast zombies. You may need to use the aiscripted_schedule or scripted_sequence entities instead.

Structure

An assault consists of an AI goal (the ai_goal_assault entity) gathering a set of one or more NPCs (called actor(s)) to one or more "rally point" locations (assault_rallypoint entities) where they will normally await a cue to commence the assault. On this cue, they will proceed to the first "assault point" location (assault_assaultpoint entity) to secure, or 'clear' it, and then proceed on to the next assault point (if any), clear it, and then proceed to the next, and so on. Clearing an assault point, by default, consists of standing on its location and ensuring that there are no hostiles in sight for the timeout period, but this is completely configurable.

Assault diagram.png

Assaults can be triggered in one of two ways:

  1. When activated, an ai_goal_assault entity can send its actor(s) to the associated assault_rallypoint(s), where they wait for the assault cue. This is the most common usage. The ai_goal_assault entity can either be activated by an Activate input, or set to start active through its Start Active keyvalue, which causes the assault to begin as soon as the map is loaded.
  2. Combine soldiers may be instantly associated with a rally point without the use of an ai_goal_assault entity. Using the entity I/O system, you can fire the Assault input on the soldier, providing the name of the assault_rallypoint as an input parameter. When a Combine soldier receives this input, it will search for the specified assault_rallypoint entity, move to it, and then proceed immediately to the associated assault_assaultpoint. Please note that although the Assault input can be sent to any NPC it is only supported for Combine soldiers. You may use wildcards when specifying the rally point in the parameter. You may also use the priority keyvalue of an assault_rallypoint entity as a parameter to influence this decision, if providing a wildcard which specifies more than one assault_rallypoint entity.

Advantages

While an assault requires extra work to set up, and the end result is very similar to other ai entities, such as aiscripted_schedule, assaults do allow for more flexibility than other scripting entities.

  • You can select a group of NPCs
    • Other scripting options can do this too, but this often results in the entire group heading toward a specific point, or only one member of the group moving. To create similar results, each individual npc would need to be scripted.
  • More control
    • With options such as "allow diversion" and "clear on contact", the mapper has more control of when an ai stops moving. Unlike an aiscripted_schedule set to interrupt on "general", which can be broken by gunfire or other sounds.
  • An NPC will realistically stick to one place
    • Without a combination of hintgrouping and moving to a path_corner there aren't any other options to have an ai stay at one point. Also, unlike the hintgroup set up, the ai will move to avoid grenades or reload.

Major options

The assault behaviour offers a flexible degree of customisation among the entities that make up an assault. This list's purpose is to provide an overview of the major options (beyond entity placement). Consult each entity's individual page for more detailed information.

  • ai_goal_assault:
Keyvalue AssaultCue: Determines what will cause the NPC to move off their rally point and begin the assault.
  • assault_rallypoint:
Keyvalue priority: Determines how appealing the rally point will be to an NPC when it has multiple rally points to choose between.
Keyvalue assaultdelay: Time to wait at rally point after assault cue, before beginning assault.
Note.pngNote:If allowdiversion is set on the next assault point, an NPC can divert from the rally point as well.
  • assault_assaultpoint:
Keyvalue assaultgroup: Constrain an NPC's hint node use to this hint group.
Keyvalue assaulttimeout, nevertimeout: How long to wait without seeing enemies before considering the point cleared.
Keyvalue clearoncontact: Whether to clear assault point if the NPC encounters enemies while moving to it.
Keyvalue allowdiversion: Whether the NPC should move to engage enemies it encounters or ignore them and follow the assault points.
Spawnflag 1: Clear point upon arrival, unconditionally.

Examples

Example map

This example map contains a single NPC on a linear chain using all the major options available to designers when moving NPCs from assaultpoint to assaultpoint. There are four points, and each is configured differently:

  1. Clear on contact with enemies is enabled. When the NPC sees the hostiles, it clears out the assaultpoint and continues to 2.
  2. Clear this point on arrival, UNCONDITIONALLY is flagged. When the NPC reaches this point it clears it regardless of the fact that there are still hostiles in sight and begins to move towards 3.
  3. Allow diversion is set to No. The NPC will charge towards the assaultpoint without stopping or giving chase. It will however attack enemies in view.
  4. Allow diversion is set to Yes. The NPC will divert from moving to this point until there are no hostiles visible.

Note that the Metropolice cannot harm the NPC and will not attack the player in this example.

Prefabs

The npc_metrocop_assault and the npc_soldier_assault prefabs contains complete setups of a mass assault of metrocops and soldiers respectively.

Notes

  • If "clear on contact" is set, a single enemy might clear not only the current assaultpoint but the next one(s). A consequence of this is that if an NPC encounters an enemy on the way to a "clear on contact" assaultpoint the assaulting NPC may never proceed to another rallypoint. This occurs regardless of the subsequent assaultpoints "Clear on contact" and "Allow diversion" settings.
  • If "allow diversion" is set and the NPC encounters an enemy, the assaulting NPC will pause for a while after killing the enemy before proceeding. The article says that this pause is the length of the "timeout" setting, but in my tests it was several times as long.
  • If an NPC encounters an enemy on the way to an assaultpoint marked "allow diversion" but not "clear on arrival" the assaulting NPC will be pausing twice. Mappers might need to consider this if timing is important.
  • An assaultpoint with both "clear on contact" and "allow diversion" causes weirdness: if an enemy is encountered on the way to the assaultpoint the assaulting NPC will kill it, but then upon reaching the assaultpoint will not pursue or return fire from other enemies until the next assaultpoint is reached. In fact, the assaulting NPC doesn't even change direction to face the fire. This happens regardless of the "clear on arrival" or "never time out" settings.
  • I didn't observe any effect of the "never time out" setting. However, all firefights were fairly brief, so it might not have had a chance to come into effect.
  • All-settings-off is great for making the NPC dash to a point regardless of enemy fire and then attack everyone at the point.
  • Having only "clear on arrival" on is great for making the NPC dash from point to point without pausing, regardless of enemy fire.
  • The OnAssaultClear output is only fired for the last assaultpoint in a chain. All assaultpoints will fire their OnArrival output, however.
  • The delay after a "Allow diversions" diversion is about 18 seconds for a 3-second "timeout" time.
  • A diversion causes another such delay immediately upon reaching the assaultpoint, and then the assaultpoint OnArrive re-fires. If the NPC is again diverted before the timeout, the OnArrive output will fire again, ad infinitum. So don't spawn enemies during from the OnArrive output.
  • If the first assaultpoint is set to "Clear on contact" and an enemy is sighted before reaching the assaultpoint, the assaulting NPC will never make it to the assaultpoint. If the subsequent assaultpoint has "Allow diversion" off, this will cause that (or perhaps the final) assaultpoint to fire the OnArrival output—despite the assaulting NPC being nowhere nearby and having not even gotten to the first assaultpoint, nor having yet finished dealing with the enemies. If, on the other hand, the second assaultpoint has "Allow diversion" on, no messages are sent whatsoever.
  • In Half-Life 2: Episode One and Half-Life 2: Episode Two rally points behave differently than in Half-Life 2. If there is an assault point with "Never Time Out" in the assault chain connecting to a rally point, than that rally point will be "locked" and unusable until the NPC on the chain dies.

See also