# Downed, morale and breakable cover Three things that make a fight last past the first shots: soldiers who go down and get dragged back up, soldiers who break and give up, and cover that does not last forever. ## Downed and revive Turn on **Can Be Downed** on the `USQHealthComponent`. When its health runs out, it goes down instead of dying: | Setting | Default | What it does | |---|---|---| | Can Be Downed | off | Down instead of dead when health runs out | | Bleed Out Seconds | 30 | Time on the ground before it dies. Damage taken while down eats into it: a hit worth the whole max health takes all of it | | Revive Health Share | 0.4 | Health after a revive, as a share of the max | | Max Downs | 2 | Times it can go down. The next time it dies. 0 for no limit | A downed body is alive but **out of the fight**: no AI shoots at it on purpose, its own AI stops thinking (the StateTree stops, abilities are cancelled, it lets go of its cover), its capsule stops blocking other pawns, and the tag `Squadcraft.State.Downed` goes on its ability system for your Anim Blueprint. `OnDowned` and `OnRevived` fire on the server and on every client. The default tree's **Revive** branch comes right after orders. A friend within 25 m who is not helping someone else (a squad mate, any AI of the same team, or the player it follows) runs to the body. If an enemy can see that spot, it drags the body to the nearest cover that hides it, walking backwards, at 1.6 m/s. Then it kneels for 4 s and the body gets up. One reviver per body: the squad subsystem keeps the claims (`ClaimRevive`, `GetReviver`). Under an order that keeps it somewhere (hold, follow, take cover...) it only goes for bodies within its Order Leash Radius of that spot. Turn off **Revive Friends** on a controller that should keep its post, a sniper say. The settings are on the **SQ Revive** task; the condition is **SQ Friend Downed**. Your own health system works too: - put the tag `Squadcraft.State.Downed` on the pawn's ability system while it is down, and take it off when it is up; - override **Revive Friend** on the controller (a hook): it gets the body at the end of a revive. The default revives its `USQHealthComponent`. Players count. In the demo the player can go down too, and the blue squad comes for them. ## Morale and surrender Every Squadcraft AI has a morale meter from 0 to 1, on the blue bar of the demo overlay. These take it down: | Loss | Default | |---|---| | A squad mate within 30 m dies | 0.30 | | A squad mate within 30 m goes down | 0.12 | | A hit, per whole max health | 0.30 | | Each second pinned down behind its cover | 0.02 | | The last one of its squad still fighting, once per fight | 0.30 | | A squad mate surrenders | 0.10 | The profile's **Morale Resistance** takes its share off every loss: 0 for the Recruit, 0.3 for the Soldier, 0.7 for the Veteran. It comes back at 0.02 a second while it is not suppressed, and 0.2 when it is revived. Under **Break Morale Below** (0.3) it breaks, unless it follows a commander: the player's squad keeps count but carries out its orders. The tag `Squadcraft.State.Broken` goes on, it calls out "falling back", and the tree's **Flee** branch takes it to cover 20 m or more from the enemy, where it keeps its head down and fires only blind. Over **Recover Morale Above** (0.6) it fights again. Broken, with an enemy it sees within **Surrender Distance** (12 m), it gives up when the profile's **Can Surrender** is on (Recruit and Soldier yes, Veteran no). It stops firing, leaves its squad and stops thinking for good, and plays the Surrender action of its animation set (the demo soldier hides its rifle and puts its hands up). The tag `Squadcraft.State.Surrendered` goes on, `OnSurrendered` fires, and no AI shoots it. What happens next is your game's call: arrest it, let it go, count it as a kill. | On the controller | What it does | |---|---| | Use Morale | Off, it fights to the end | | Get Morale, Change Morale | Read it, add to it (negative takes off, less the resistance) | | Is Morale Broken, Is Surrendered | The two states | | Surrender | Gives up now: a scripted moment, a negotiation | | Should Surrender (hook) | Asked before it gives up, with the nearest enemy and the profile's answer | | On Morale Broken, On Surrendered | Events | ## Breakable cover Put `USQBreakableCoverComponent` on a crate, a sandbag wall or a car. It takes engine damage: every Squadcraft shot and grenade deals it, and so do your weapons if they call Apply Damage. | Setting | Default | What it does | |---|---|---| | Max Hit Points | 400 | Damage before it breaks. An AI's rifle shot is 10 (times its profile's Damage Scale), a grenade up to 80, the demo player's shot 20 | | Broken Mesh | none | Swapped in on the owner's first static mesh, rubble say. Empty hides the owner and lets everything through | | Regenerate Delay Seconds | 0.6 | Time before the cover round it is found again, so the navmesh has rebuilt | When it breaks, the cover spots round it go at once, every AI that held one picks new cover and says "cover's gone", and a moment later the cover of that area is found again without it. `OnDamaged` fires on every hit, `OnBroken` on the server and every client. It needs a navmesh that rebuilds at runtime: **Project Settings > Navigation Mesh > Runtime Generation: Dynamic**. With a static navmesh the AIs would still try to walk through where the crate was. `USQCoverSubsystem::GetCoverInBounds` hands back every spot in a box, taken or not, for your own map or debug view. The demo's cover markers use it.