# Player squads, spawners and doors ## A squad that takes the player's orders The same AI fights on the player's side. Give it a commander and orders: These calls, like everything Squadcraft does, run on the server: from a client, send them through a Server RPC on your player controller. - **Set Commander** (on the SQ AI Controller) with the player's pawn. It starts following. Its commander is never an enemy to it, and neither are other players without a team while it has one. - **Give Order**, one of: | Order | What it does | |---|---| | Follow | stays with the commander, in formation | | Hold | stays at the location | | Move To | goes to the location, then holds there | | Attack | goes after the target as if it had seen it; once the target is dead, back to following | | Suppress | keeps the location under suppressing fire for 8 s, an enemy there or not, then holds where it is | | Grenade | throws a grenade at the location (waiting up to 6 s for one to be ready), then holds | | Take Cover | gets into the nearest free cover round the location, the wall between it and the enemy (or facing the way the commander looks), crouched behind low cover, and holds it | | Regroup | runs back to its place behind the commander, not stopping to fight, then follows | | Watch | holds where it stands, looking at the location | | Flank | **Give Flank Order** with a target and a side (left, right or either, seen from the squad): goes round it to cover on that side, then attacks | | Breach | the target is a door (Squadcraft door interface) and the location its doorway: the squad stacks beside it on its side, the first opens it once all are ready (8 s at most), then they go in one by one, each to its own corner of the room, firing on any enemy in sight on the way, and watch the room | | None | its own judgement | - **Fire Rule** on the controller: Fire At Will, Return Fire (only once its squad has been shot at or hurt in the last 15 s) or Hold Fire (never on its own, for stealth). Orders to attack, flank, suppress or throw a grenade are carried out whatever the rule. Under Follow, Hold, Move To, Suppress, Grenade, Take Cover and Watch it takes cover and fights within **Order Leash Radius** (8 m) of where the order keeps it, never flanks off on its own, and comes back when the commander walks away. The orders with an action of their own (suppress, grenade, take cover, regroup, flank) go first in the default tree, ahead of the fight: the SQ Carry Out Order task, also a Behavior Tree task. Put your companions in one squad (`Squad:Allies`) and on a team of their own, different from the enemies'. Every Squadcraft AI without a Team tag is on team 1, so give the companions `Team:2` (or give the enemies another number). Bind Give Order to your input in the player controller, through a Server RPC; nothing else is needed. It follows its commander across a respawn: Set Commander remembers the commander's controller, and takes whatever pawn it has next. ### The command menu Add **SQ Command** to the player controller and give it a command set: `/Squadcraft/Commands/DA_SQCommands_Companion` (5 commands, a numbered list), `_Military` (14, radial: orders, cover, flanks, formations, spacing) or `_Tactical` (16, radial: orders, cover, watch, flanks, breach, fire rules, team switch). That is all: the component binds its own keys on the local player. Hold **Menu Key** (Q) to open the menu, point with the mouse (the camera holds still meanwhile) and let go to issue; every command's hotkey issues it at once. It only listens: your own bindings of the same keys still get them. Untick **Hold Menu Key** to open with one press and issue with the next. To drive it your own way, untick **Bind Input** and: - call **Open Menu** and **Close Menu** (closing issues the command pointed at), and while the menu is open send the mouse movement to **Add Menu Pointer**; - pass key presses to **Issue Hotkey**; - or call **Issue Command** with an index from your own UI. "There" commands use where the player aims (the camera's line), "here" where the player stands. Breach Door needs a door in the crosshair. **Teams.** The AIs that take a commander are split red, blue, red... as they join (**Fire Team** on the controller, which you can set yourself). The **Switch Team** command (T in the Tactical set) sends the next commands to the red team, the blue team or everyone again: hold with one team while the other flanks, or breach with one and cover with the other. The command goes to the server through the component's Server RPC, so a client needs nothing else, and every AI whose commander is the player's pawn obeys. A grenade order goes to the AI nearest the spot only. To make your own set: duplicate a template, or create an **SQ Command Set**, pick a template and press **Reset To Template**, then add, remove and reorder commands, change labels, keys and icons, and choose Radial or List. The menu draws itself (no art needed); for your own look, subclass **SQ Command Menu Widget** and set it on the component. The demo plays the Tactical set on Q. ### Formations Under Follow the squad walks in **Formation** (on each AI's controller): Column, Staggered Column, Wedge (the default) or Line, **Formation Spacing** apart (2 m). Places are in the order the AIs joined the squad, worked out from the way the commander faces (or walks, when that is ahead: a commander backing off while firing keeps the squad behind it) and pulled in along the navmesh from the commander, so a place behind a wall ends at the wall, not on its far side. Where there is no place at all the AI just follows close. AIs that follow an AI leader along its patrol route use the leader's Formation. They run to catch up when they are more than two places behind. Squad mates step round each other on the way (Character Movement's RVO avoidance, which the controller turns on: **Avoid Others**), so a squad walking together doesn't block its own paths. The demo plays all of this: press Enter on L_SquadDemo and see `SQDemoPlayerController` for the calls. ## Cover for the player Add **SQ Player Cover** to the player's pawn to use the same cover spots as the AIs: - **Is In Cover** and **Get Current Cover** (low or high, which sides it can lean out of, the way the wall faces), checked every 0.15 s on the server and replicated, and **On Cover Changed** on every machine for your animation (crouch behind low cover, for one). - **Request Cover Toward** a direction (the camera's) within a radius, for a take cover button: the server finds the nearest free spot that way and **On Cover Found** brings it back to the machine that owns the pawn. On the server, **Find Cover Toward** answers at once. Moving there is yours: the demo uses Simple Move To Location. - **Is Covered From** a location: in cover, with the wall between. Cover spots exist on the server only, which is why the state comes from there. While the player stands at a spot, the spot is held, so allied AIs pick another one; a dead player holds nothing. ## Spawners and waves Place a **SQ Spawner** and fill **Waves**: each wave is a list of groups (pawn class, controller class, count, pawn tags such as `Profile:Recruit`) and a delay. The next wave comes once the one before is dead or gone, after its delay. Every pawn of a wave joins the spawner's squad and team (Team Number, 1 by default like every other Squadcraft AI), so a wave fights as one squad. Pawns appear around the spawner, or at the Spawn Points you list, on the navmesh. Events: On Wave Started, On Wave Cleared, On All Waves Cleared. Start Waves and Stop Waves are there when Start On Begin Play is off, and Loop Waves starts over after the last. ## Patrol routes Place a **SQ Patrol Route** and shape its spline: the AI walks its points in order, waiting Wait Seconds At Point at each, looping or back and forth. Give it to an enemy by listing the pawn in the route's **Assigned Pawns**, by a pawn tag `Patrol:<a tag on the route>`, or through the controller's Patrol Route. Squad mates without a route follow their leader along it. ## Doors Put the **SQ Door Interface** on your door (Is Door Open, Open Door) and Squadcraft AIs open it when they are about to walk into it (the controller's Door Look Ahead, 1.8 m). The navmesh has to run through the doorway, so turn off Can Ever Affect Navigation on the door's moving part. `SQDemoDoor` in the example module is a working one. ## Vaulting low cover Moving up on the enemy, an AI behind a low wall (up to 1.3 m high and 80 cm thick) jumps over it instead of walking round, when there is room to land. The vault ability takes an optional montage (the Game Animation Sample has vaults), and the tag `Squadcraft.State.Vaulting` is on while it is in the air. Turn it off with Can Vault on the controller. ## Grenades and other dangers A grenade on the ground is a **danger** for the rest of its fuse: every AI in its blast runs out of it, whichever side threw it (also one that walks in later, or that the grenade rolls up to), and no cover inside it is taken. Each squad throws one grenade every 6 s at most (Seconds Between Squad Grenades, Project Settings > Plugins > Squadcraft Squads), so four AIs with a grenade ready don't bury a hiding player. Your own grenades, fires and bombs can do the same with **Report Danger** (SQ Combat Library, on the server): a location, a radius, how long, and optionally an actor it moves with. Squadcraft's grenades follow the throwing ability's damage settings: engine radial damage unless Apply Engine Damage is off, and its Damage Effect Class on every victim with an ability system. ## Characters and Mover A Character works as it is. A pawn that moves some other way (Epic's **Mover**, a vehicle, your own movement) needs two things: - its movement has to take the AI's path following. On Mover, add a **Nav Mover Component** next to the Character Mover Component; - the **SQ Pawn Movement Interface** on the pawn or on one of its components, so Squadcraft can set its pace (Set Squadcraft Move Speed) and crouch it (Set Squadcraft Crouched). On Mover, set Max Speed on its Common Legacy Movement Settings and call Crouch and Un Crouch on the Character Mover Component. This has been checked with a Mover pawn on 5.8: it patrols, runs to cover, leans out and fires like a Character. Vaulting needs a Character. ## Performance On a dedicated server (the editor binary, so a packaged server does better) a Squadcraft AI costs about **0.1 ms of game thread** per frame, Character Movement included: 64 AIs fighting take 6.9 ms on average and 11.2 ms in the worst frame, against the 33 ms a 30 Hz server has. Measured with 0, 16, 32 and 64 AIs in two teams fighting across a field of cover, 12 s each. Next: [Behavior Trees and EQS](7-behavior-trees-and-eqs.html).