Scripting assaults

Assaults give the AI a goal. In our last example, the soldiers in the map had one goal—to hunt the player. The nodes we placed in the level helped to guide the AI in both navigation and for seeking defense. We can use the same process to script AI versus AI battles. Load the ch10_example04 example map to see a house held by citizens and an outside area filled with combine soldiers. You can also create your own scenario if you wish.

Scripting assaults

The map is littered with info nodes and hint nodes. There are also hint_nodes in the windows. These are set to be visually interesting but only for NPCs outside of the house. The FOV is 180 degrees with the hint angle pointing outside the house. We want only the soldiers to focus on the windows so that they will be ready when the citizens appear in them. Run the map and see what happens.

Scripting assaults

Have a look at the preceding image. You'll notice that the soldiers aren't storming the house, and the citizens aren't going outdoors to meet them. The combine standing outside will move to the closest cover and try to survive while trying to defeat the citizens. The citizens are nice and protected inside the house, so they have no reason to go anywhere. The NPCs can see each other but they have no goals other than killing their visible enemies. The goal we want is for the combine to gain entry to the house. Let's set up what's known as an assault.

Setting up an assault

An assault needs at least four entities that are mentioned as follows:

  • NPC
  • ai_goal_assault
  • assault_rallypoint
  • assault_assaultpoint
Setting up an assault

The assault_assaultpoint entity is the end destination; it's the point where the assault NPCs will try to reach. The assault_rallypoint entity is the area where an NPC will gather before beginning the assault. Once a rally point and an assault point are defined, the rally point entity will draw a purple line towards the assault point it's attached to. The ai_goal_assault entity is the master controller; this entity starts and stops the assault. It also gives you control over how aggressive the NPCs are in pursuing their goals. Let's set up our assault so that the NPC soldiers storm the house.

Placing the assault point

The first thing you want to do is place your assault_assaultpoint entity. Since we want the soldiers to gain entry to the house, place the assault_assaultpoint entity on the floor in the middle of the house, as shown in the following image:

Placing the assault point

Give it a name such as assault_here and change the allow diversion property to yes. This setting will still have the soldiers storm the house, but they will do so in a safe manner. They will seek cover and advance only when they can't see an enemy. If the allow diversion property is set to no, all the 12 soldiers will storm into the house at once. It's funny to watch, and useful in certain scenarios, but it's not exactly what we want to do here.

Placing rally points

An assault can have any number of rally points because each NPC involved in the assault needs its own specific rally point. Place one rally point for each NPC you would like to have. In the ch10_example05 example map, there are 12 soldiers mounting an assault on the house, so place 12 assault_rally points down behind the cover. Name them Gather_here01 - Gather_here12.

Placing rally points

Like all other entities, there are certain properties associated with rally points, which can drastically change how they function. The most important ones are:

  • The name property
  • The assault point property
  • The assault delay property
  • The urgent property

The assault point specifies the assault point we want our NPC to eventually go to. The assault delay specifies a time, in seconds, to wait before assaulting. The urgent property will force the NPC to move to this point, ignoring his/her surroundings. Set the assault point property to assault_here, set the assault delay to 3, and set the urgent property to yes. Copy those properties to the other rally points.

Placing assault goals

The last entity we need to make this assault work is the ai_goal_assault entity. This entity will kick the whole assault into motion. By default, this entity is disabled. Once activated, each NPC involved in the assault will move to its rally point and wait for the signal to begin the assault. Once that signal is received, the NPC will wait the specified amount of time and then begin the assault.

Placing assault goals

Place an ai_goal_assault entity anywhere in your map. Name it assault and change the properties, detailed in the following sections:

Actors to affect

Set actors to affect to npc_combine_s. When used in conjunction with search type set to classname, this will involve all of the combine soldiers in the map in the assault. You can also search for a specific entity name as well. If you wanted a soldier named Richard to assault a different area, you would set search type to entity name and the actors to affect field to Richard.

Setting rally points

The rally point set property tells the NPCs where to position themselves before they get the assault command. Typing gather_here* will set all rally points that start with gather_here to be proper rally points.

Tip

You could also have each rally point have the same name, and only put one entity name in for the rally point set parameter.

Search type

Change search type to look for either entity names or entity class types. In our case, we want to search for a specific class. The class we're searching for is specified in the actors to affect property, which we have already set to npc_combine_s.

Start active

If start active is set to yes, the NPCs involved will move to their rally points as soon as the map is loaded. If this is set to no, we would have to fire an activate input to move the NPCs into position. In this case, set this to yes.

Rally Point Selection Method

Each rally point can have a priority with the lowest number being the most important. Since we have 12 rally points and 12 NPCs, it really doesn't matter which point has the highest priority because every rally point will be filled. Change this to random so that each NPC will pick whichever rally point they want. When everything is set up, place a button on the inside wall of the house that will begin the assault:

Rally Point Selection Method

You need to create the following output:

OnIn > assault > beginassault > 0.00s delay

Compile and play the map to see the results!

Rally Point Selection Method

During combat, the soldiers will assault the house, moving towards the assault point whenever they can, as shown in the following image:

Rally Point Selection Method
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.173.199