Rampage/Giant/RampageGiant.cs

The giant form of the Rampage lizard. Scales the ReptileController sphere, speed, jump, turn rates and camera at each tier, springs the rig's Scale, and generates footfall and landing shockwaves, stomp damage, shin kicks and shoulder barges. Saves the controller, rig and camera values on engage and puts them back in Release, which also runs on disable, destroy and when the Rampage stops.

using System;
using System.Collections.Generic;

/// <summary>
/// In the Rampage the lizard is a GIANT: six to eight times its size when it comes up out of the
/// town square, and a step bigger with every tier. Houses come up to its knee and people to its
/// ankle. This component is the one place that says how big, and makes everything that depends on
/// size agree with it:
///
///  - the rigged model (<see cref="LizardRig.Scale"/>) and the controller's sphere, its stick and
///    reach distances;
///  - how it moves: long strides (speed grows with the root of the size, as it does for real big
///    animals), a slow start, a slow stop and wide turns; a heavy low jump;
///  - the camera, pulled far back and up so the giant and the street it is wrecking are both in
///    frame (the controller's own traces keep it out of walls);
///  - its feet: every footfall shakes the camera, sends out a little shockwave and flattens what
///    is under it, and its shins kick whatever small thing they walk into. Walking down a street
///    is an attack. People and props never block it; buildings do, until they are knocked down,
///    and leaning on one for a moment is a shoulder barge;
///  - every landing from a jump, which is a shockwave.
///
/// The weapon, the riders and the town's answers read the size from <see cref="ScaleNow"/>.
/// Everything changed on the controller and the rig is remembered first and put back by
/// <see cref="Release"/>: when the Rampage stops, the rig goes, or this is switched off or
/// destroyed (which a change of scene does).
/// </summary>
[Title( "Rampage Giant" ), Category( "Rampage" ), Icon( "accessibility_new" )]
public sealed class RampageGiant : Component
{
	public static RampageGiant Current { get; private set; }

	/// <summary>How many times its ordinary size the lizard is right now (1 outside the Rampage).</summary>
	public static float ScaleNow => Current.IsValid() && Current._engaged ? Current.GiantScale : 1f;

	// ---- Size ----

	/// <summary>Times its ordinary size at the start (the lizard is about 48 inches tall: 7 makes it 28 feet).</summary>
	[Property, Group( "Size" )] public float BaseScale { get; set; } = 7f;
	/// <summary>How much bigger again each tier makes it, as a share of the starting size, and for how many tiers.</summary>
	[Property, Group( "Size" )] public float GrowthPerTier { get; set; } = 0.1f;
	[Property, Group( "Size" )] public int GrowthTiers { get; set; } = 8;
	/// <summary>The model grows on a spring (it overshoots and wobbles into each new size). The controller's own size changes in one step.</summary>
	[Property, Group( "Size" )] public float GrowSpring { get; set; } = 26f;
	[Property, Group( "Size" )] public float GrowDamping { get; set; } = 5f;

	// ---- Movement ----

	/// <summary>Speed grows with the size to this power (0.5: a giant seven times the size strides about 2.6 times as fast).</summary>
	[Property, Group( "Movement" )] public float SpeedPower { get; set; } = 0.5f;
	/// <summary>How much of its ordinary quickness off the mark, in stopping and in turning the giant keeps. Low: enormous weight.</summary>
	[Property, Group( "Movement" ), Range( 0.05f, 1f )] public float StartFactor { get; set; } = 0.3f;
	[Property, Group( "Movement" ), Range( 0.05f, 1f )] public float StopFactor { get; set; } = 0.24f;
	[Property, Group( "Movement" ), Range( 0.05f, 1f )] public float TurnFactor { get; set; } = 0.34f;
	/// <summary>Jump speed and gravity against the ordinary lizard's: together a heavy, low jump (about half its own height) that takes over a second.</summary>
	[Property, Group( "Movement" )] public float JumpFactor { get; set; } = 1.5f;
	[Property, Group( "Movement" )] public float GravityFactor { get; set; } = 1.1f;

	// ---- Camera ----

	/// <summary>Camera distance and height per unit of size, in inches (at 7: about 105 feet back and 26 up).</summary>
	[Property, Group( "Camera" )] public float CameraDistancePerScale { get; set; } = 180f;
	[Property, Group( "Camera" )] public float CameraHeightPerScale { get; set; } = 44f;
	[Property, Group( "Camera" )] public float CameraFollow { get; set; } = 3.5f;
	[Property, Group( "Camera" )] public float FarClip { get; set; } = 90000f;

	/// <summary>Extra camera distance and height asked for by the weapon this frame (it grows; a charge pulls back). Set every frame.</summary>
	public float CameraPull { get; set; }
	public float CameraLift { get; set; }

	// ---- Feet ----

	/// <summary>A footfall's shockwave: radius per unit of size, and its speed. Small: it cracks bins and bowls people, it does not take cars.</summary>
	[Property, Group( "Feet" )] public float StepShockPerScale { get; set; } = 34f;
	[Property, Group( "Feet" )] public float StepShockSpeed { get; set; } = 420f;
	/// <summary>What is right under the foot: radius per unit of size, damage (times <see cref="Rampage.Might"/>) and how hard it is thrown.</summary>
	[Property, Group( "Feet" )] public float StompRadiusPerScale { get; set; } = 17f;
	[Property, Group( "Feet" )] public float StompDamage { get; set; } = 60f;
	[Property, Group( "Feet" )] public float StompThrow { get; set; } = 900f;
	/// <summary>Camera jolt of one footfall, in inches.</summary>
	[Property, Group( "Feet" )] public float StepKick { get; set; } = 5f;
	/// <summary>Walking faster than this (inches a second), the shins kick small things out of the way.</summary>
	[Property, Group( "Feet" )] public float KickFromSpeed { get; set; } = 120f;
	[Property, Group( "Feet" )] public float KickDamage { get; set; } = 35f;
	/// <summary>Only things with a radius under this are kicked or stomped (and never a building or a tower).</summary>
	[Property, Group( "Feet" )] public float KickSmallerThan { get; set; } = 330f;
	/// <summary>Stride length per unit of size, used when the feet cannot be read from the rig.</summary>
	[Property, Group( "Feet" )] public float StridePerScale { get; set; } = 30f;

	// ---- Landing, barging ----

	/// <summary>Landing from a jump: shockwave radius per unit of size, speed, and the fall speed below which it is just a step.</summary>
	[Property, Group( "Landing" )] public float LandShockPerScale { get; set; } = 75f;
	[Property, Group( "Landing" )] public float LandShockSpeed { get; set; } = 1500f;
	[Property, Group( "Landing" )] public float LandFromFall { get; set; } = 420f;
	/// <summary>Pushing against a building for this long is a shoulder barge: damage (times might) every so often.</summary>
	[Property, Group( "Landing" )] public float BargeAfter { get; set; } = 0.3f;
	[Property, Group( "Landing" )] public float BargeDamage { get; set; } = 170f;
	[Property, Group( "Landing" )] public float BargeEvery { get; set; } = 0.55f;

	// ---- Coming up ----

	/// <summary>The eruption out of the square: shockwave radius and speed, and how high it throws the giant (times its jump).</summary>
	[Property, Group( "Eruption" )] public float EruptRadius { get; set; } = 1100f;
	[Property, Group( "Eruption" )] public float EruptSpeed { get; set; } = 1700f;
	[Property, Group( "Eruption" )] public float EruptLeap { get; set; } = 1.25f;

	/// <summary>The size it is being drawn at now (the spring), and the size its body really is (the step).</summary>
	public float GiantScale { get; private set; } = 1f;
	public float BodyScale { get; private set; } = 1f;
	/// <summary>A footfall: where, and which foot (0 left, 1 right). The riders bounce to it.</summary>
	public event Action<Vector3, int> Footfall;
	/// <summary>It has landed from a jump: where, and how hard (0.5 a hop to 2 a dive).</summary>
	public event Action<Vector3, float> Landed;

	ReptileController _controller;
	LizardRig _rig;
	bool _engaged, _erupted;
	float _scaleSpeed;

	// What it was like before.
	float _oRadius, _oSpeed, _oSprint, _oJump, _oGravity, _oAccel, _oNewAccel, _oBraking, _oNewBraking, _oTurn, _oNewTurn;
	float _oCamDistance, _oCamHeight, _oStick, _oReach, _oRigScale = 1.15f, _oRunAbove = 380f, _oFar, _oJumpShove;
	bool _oCling, _oPass, _rigKnown, _farKnown;
	string _oStepSound;
	Func<Vector3, float> _oFloor, _floor;

	// Feet.
	readonly float[] _footBase = { float.MaxValue, float.MaxValue };
	readonly bool[] _footUp = new bool[2];
	float _sinceStep, _strideLeft;
	int _nextFoot;
	readonly Dictionary<IRampageTarget, float> _kicked = new();

	// Air and barging.
	float _airTime, _fall, _blocked, _nextBarge;
	bool _gripsTuned;

	protected override void OnUpdate()
	{
		if ( !Ready() ) { Release(); return; }
		if ( !_engaged ) Engage();

		float dt = MathF.Min( Time.Delta, 0.05f );
		if ( dt <= 0f ) return;

		if ( _rig.IsValid() && !_rigKnown ) AdoptRig();
		Grow( dt );
		Camera( dt );
		Feet( dt );
		if ( !_erupted && Rampage.Started ) Erupt();
		if ( !_gripsTuned ) TuneGrips();
	}

	protected override void OnFixedUpdate()
	{
		if ( !_engaged || !_controller.IsValid() ) return;
		float dt = Time.Delta;
		Shins();
		Air( dt );
		Barge( dt );
	}

	protected override void OnDisabled() => Release();
	protected override void OnDestroy() => Release();

	bool Ready()
	{
		if ( !Rampage.Running ) return false;
		if ( !_controller.IsValid() ) _controller = Components.Get<ReptileController>() ?? Rampage.Player;
		if ( !_controller.IsValid() ) return false;
		var rig = _controller.Rig;
		if ( rig != _rig )
		{
			// A new rig (or none yet): whatever was changed on the old one stays with it; this one is read afresh.
			_rig = rig;
			_rigKnown = false;
		}
		return true;
	}

	float WantedScale => MathF.Max( BaseScale, 1f ) * (1f + GrowthPerTier * Math.Min( Rampage.Tier, Math.Max( GrowthTiers, 0 ) ));

	// ---- Becoming a giant, and stopping -------------------------------------------------------------

	void Engage()
	{
		_engaged = true;
		Current = this;
		var c = _controller;

		_oRadius = c.Radius; _oSpeed = c.Speed; _oSprint = c.SprintSpeed; _oJump = c.JumpSpeed; _oGravity = c.Gravity;
		_oAccel = c.Acceleration; _oNewAccel = c.NewAcceleration; _oBraking = c.Braking; _oNewBraking = c.NewBraking;
		_oTurn = c.TurnSpeed; _oNewTurn = c.NewTurnSpeed;
		_oCamDistance = c.CameraDistance; _oCamHeight = c.CameraHeight; _oStick = c.StickDistance; _oReach = c.ReachDistance;
		_oCling = c.ClingEnabled; _oPass = c.PassCrowd; _oStepSound = c.StepSound; _oFloor = c.FloorHeight; _oJumpShove = c.JumpShoveMass;

		// A giant does not climb walls, wade through people as if they were not there, and never sinks into the road.
		c.ClingEnabled = false;
		c.PassCrowd = true;
		c.StepSound = "";               // its own footfalls are made here, from the rig's feet
		c.FloorHeight = _floor ??= FloorAt;

		if ( Scene.Camera.IsValid() )
		{
			_oFar = Scene.Camera.ZFar;
			_farKnown = true;
			Scene.Camera.ZFar = MathF.Max( _oFar, FarClip );
		}

		GiantScale = 1f;                // it comes up out of the square lizard-sized and swells (see Erupt)
		_scaleSpeed = 0f;
		_erupted = false;
		_airTime = 0f; _fall = 0f; _blocked = 0f;
		_footBase[0] = _footBase[1] = float.MaxValue;
		ApplyBody( WantedScale );
	}

	static float FloorAt( Vector3 point ) => RampageWorld.GroundHeightAt( point );

	void AdoptRig()
	{
		_rigKnown = true;
		_oRigScale = _rig.Scale;
		_oRunAbove = _rig.RunAbove;
		ApplyRig();
	}

	/// <summary>
	/// The body's real size: the controller's sphere and everything measured against it. Done in one
	/// step (at the start and at each tier), because the sphere has to be stood back on the ground
	/// when it changes; the speed it had is given straight back.
	/// </summary>
	void ApplyBody( float scale )
	{
		var c = _controller;
		BodyScale = scale;
		float pace = MathF.Pow( scale, Math.Clamp( SpeedPower, 0f, 1f ) );

		var feet = c.WorldPosition;
		var velocity = c.Velocity;
		bool grounded = c.Attached;

		c.Radius = _oRadius * scale;
		c.StickDistance = _oStick * scale;
		c.ReachDistance = _oReach * scale;
		c.Speed = _oSpeed * pace;
		c.SprintSpeed = _oSprint * pace;
		c.JumpSpeed = _oJump * JumpFactor * MathF.Sqrt( scale / MathF.Max( BaseScale, 1f ) );
		c.Gravity = _oGravity * GravityFactor;
		c.Acceleration = _oAccel * StartFactor;
		c.NewAcceleration = _oNewAccel * StartFactor;
		c.Braking = _oBraking * StopFactor;
		c.NewBraking = _oNewBraking * StopFactor;
		c.TurnSpeed = _oTurn * TurnFactor;
		c.NewTurnSpeed = _oNewTurn * TurnFactor;
		c.JumpShoveMass = _oJumpShove * scale * scale;

		// Stood back on its feet at the new size, and on its way again.
		c.Teleport( feet.WithZ( MathF.Max( feet.z, FloorAt( feet ) ) + (grounded ? 0.5f : 0f) ) );
		if ( velocity.Length > 1f ) c.Lunge( velocity.Normal, velocity.Length );

		ApplyRig();
	}

	void ApplyRig()
	{
		if ( !_rig.IsValid() || !_rigKnown ) return;
		// It breaks into a run later than a lizard does: halfway between its walk and its sprint.
		_rig.RunAbove = (_controller.Speed + _controller.SprintSpeed) * 0.5f;
	}

	/// <summary>Everything back as it was.</summary>
	public void Release()
	{
		if ( !_engaged ) return;
		_engaged = false;
		if ( Current == this ) Current = null;

		if ( _rig.IsValid() && _rigKnown )
		{
			_rig.Scale = _oRigScale;
			_rig.RunAbove = _oRunAbove;
		}
		_rigKnown = false;

		var c = _controller;
		if ( c.IsValid() )
		{
			var feet = c.WorldPosition;
			c.Radius = _oRadius; c.StickDistance = _oStick; c.ReachDistance = _oReach;
			c.Speed = _oSpeed; c.SprintSpeed = _oSprint; c.JumpSpeed = _oJump; c.Gravity = _oGravity;
			c.Acceleration = _oAccel; c.NewAcceleration = _oNewAccel; c.Braking = _oBraking; c.NewBraking = _oNewBraking;
			c.TurnSpeed = _oTurn; c.NewTurnSpeed = _oNewTurn;
			c.CameraDistance = _oCamDistance; c.CameraHeight = _oCamHeight;
			c.ClingEnabled = _oCling; c.PassCrowd = _oPass; c.StepSound = _oStepSound; c.JumpShoveMass = _oJumpShove;
			if ( ReferenceEquals( c.FloorHeight, _floor ) ) c.FloorHeight = _oFloor;
			c.SetSpeedFactor( "giant", 1f );
			c.Teleport( feet );
		}
		if ( _farKnown && Scene is not null && Scene.Camera.IsValid() ) Scene.Camera.ZFar = _oFar;
		_farKnown = false;

		GiantScale = 1f;
		BodyScale = 1f;
		CameraPull = CameraLift = 0f;
		_kicked.Clear();
		Footfall = null;
		Landed = null;
	}

	// ---- Size ------------------------------------------------------------------------------------------

	/// <summary>
	/// The drawn size follows the wanted size on a spring; the body's real size steps up when a
	/// tier has moved the wanted size on by a few percent.
	/// </summary>
	void Grow( float dt )
	{
		float want = _erupted ? WantedScale : 1f;
		if ( _erupted && MathF.Abs( want - BodyScale ) > BodyScale * 0.03f )
		{
			ApplyBody( want );
			_scaleSpeed += want * 1.5f;
			Rampage.Shake( 0.5f );
			Rampage.PlaySound( "giant_grow", _controller.WorldPosition );
		}

		_scaleSpeed += ((want - GiantScale) * GrowSpring - _scaleSpeed * GrowDamping) * dt;
		GiantScale = Math.Clamp( GiantScale + _scaleSpeed * dt, 0.5f, want * 1.35f + 1f );
		if ( _rig.IsValid() && _rigKnown ) _rig.Scale = _oRigScale * GiantScale;
	}

	/// <summary>The camera backs off and climbs with the size, plus whatever the weapon asks for.</summary>
	void Camera( float dt )
	{
		var c = _controller;
		float size = MathF.Max( GiantScale, 1f );
		float distance = MathF.Max( _oCamDistance, size * CameraDistancePerScale ) + MathF.Max( CameraPull, 0f );
		float height = MathF.Max( _oCamHeight, size * CameraHeightPerScale ) + CameraLift;
		float t = MathF.Min( dt * CameraFollow, 1f );
		c.CameraDistance += (distance - c.CameraDistance) * t;
		c.CameraHeight += (height - c.CameraHeight) * t;
	}

	// ---- Coming up out of the square ---------------------------------------------------------------

	/// <summary>
	/// The intro is over. The square heaves, cracks and throws the giant out of the ground, swelling
	/// as it comes; it lands with its first shockwave.
	/// </summary>
	void Erupt()
	{
		_erupted = true;
		var at = _controller.WorldPosition;
		_scaleSpeed += WantedScale * 2.2f;
		Rampage.SendShockwave( at, EruptRadius, EruptSpeed );
		Rampage.Shake( 1f );
		_controller.Kick( Vector3.Up * 30f );
		_controller.Lunge( Vector3.Up, _controller.JumpSpeed * EruptLeap );
		Rampage.PlaySound( "giant_erupt", at );

		// The square, cracked: slabs of road thrown up and a great deal of dust.
		var world = RampageWorld.Current;
		if ( world.IsValid() )
		{
			var fx = world.Fx;
			fx?.Dust( at, new Vector3( 420f, 420f, 60f ), 14 );
			fx?.Rubble( at + Vector3.Up * 20f, new Vector3( 260f, 260f, 10f ), Vector3.Up * 900f, 10, 60f, Tone.Asphalt, Tone.Pavement, Tone.Dirt );
		}
	}

	// ---- Feet ------------------------------------------------------------------------------------------

	/// <summary>
	/// Watches the rig's two feet. A foot that has been up and comes down is a footfall. If the feet
	/// cannot be read (no rig, or bones by another name) a footfall is made every stride instead.
	/// </summary>
	void Feet( float dt )
	{
		var c = _controller;
		_sinceStep += dt;
		float speed = c.Velocity.WithZ( 0f ).Length;
		if ( !c.Attached || !_erupted ) { _footUp[0] = _footUp[1] = false; return; }

		float size = MathF.Max( BodyScale, 1f );
		bool read = false;
		if ( _rig.IsValid() )
		{
			for ( int side = 0; side < 2; side++ )
			{
				if ( !_rig.TryBonePosition( side == 0 ? "foot_l" : "foot_r", out var foot ) ) continue;
				read = true;
				float height = foot.z - c.WorldPosition.z;
				// The lowest it has been is the ground, as far as this foot is concerned (it drifts up slowly, so a new pose is learned).
				_footBase[side] = MathF.Min( _footBase[side] + size * 0.4f * dt, height );
				float lifted = height - _footBase[side];

				if ( !_footUp[side] ) { if ( lifted > size * 1.6f ) _footUp[side] = true; continue; }
				if ( lifted > size * 0.6f ) continue;
				_footUp[side] = false;
				if ( speed > 30f && _sinceStep > 0.12f ) StepDown( foot.WithZ( c.WorldPosition.z ), side, speed );
			}
		}

		// The fallback, and a net under the rig's reading: never further than two strides without a footfall.
		_strideLeft -= speed * dt;
		if ( speed > 30f && _strideLeft <= 0f && (!read || _sinceStep > 1.2f) )
		{
			var side = c.WorldRotation.Left * (_nextFoot == 0 ? 1f : -1f) * (c.Radius * 0.8f);
			StepDown( c.WorldPosition + side, _nextFoot, speed );
		}
	}

	void StepDown( Vector3 at, int foot, float speed )
	{
		var c = _controller;
		float size = MathF.Max( BodyScale, 1f );
		_sinceStep = 0f;
		_strideLeft = StridePerScale * size;
		_nextFoot = 1 - foot;

		float pace = Math.Clamp( speed / MathF.Max( c.SprintSpeed, 1f ), 0.25f, 1f );
		float bonus = GiantRiders.ShockBonus;

		// What is under the foot is flattened; what is near it is bowled over.
		Stomp( at, StompRadiusPerScale * size, StompDamage * Rampage.Might, StompThrow );
		Rampage.SendShockwave( at, StepShockPerScale * size * (0.6f + 0.4f * pace) * bonus, StepShockSpeed * (0.6f + 0.4f * pace) );
		c.Kick( Vector3.Down * (StepKick * pace) );

		var sound = Rampage.PlaySound( "giant_step", at );
		if ( sound is not null )
		{
			sound.Volume = 0.45f + 0.55f * pace;
			sound.Pitch = Math.Clamp( 1.2f - size * 0.04f, 0.6f, 1.1f ) * (foot == 0 ? 1f : 0.94f);
		}
		RampageWorld.Current?.Fx?.Dust( at, new Vector3( size * 9f, size * 9f, 8f ), 2 );
		Footfall?.Invoke( at, foot );
	}

	/// <summary>Everything small within a radius of a point on the ground is hit: thrown up and outward.</summary>
	void Stomp( Vector3 at, float radius, float damage, float throwSpeed )
	{
		var near = Rampage.Borrow();
		Rampage.TargetsNear( at, radius, near );
		for ( int i = 0; i < near.Count; i++ )
		{
			var target = near[i];
			if ( !Small( target ) || MathF.Abs( target.Centre.z - at.z ) > radius + 120f ) continue;
			var away = (target.Centre - at).WithZ( 0f );
			var direction = away.Length > 1f ? away.Normal : Vector3.Zero;
			Touch( target, direction * (throwSpeed * 0.5f) + Vector3.Up * throwSpeed, damage, at );
		}
		Rampage.Return( near );
	}

	/// <summary>Small enough for a foot or a shin to deal with: never a building, a tower or a sleeping crowd.</summary>
	bool Small( IRampageTarget target ) =>
		target is not null && target.Alive && target is not Building && target is not Toppler && target.Radius < KickSmallerThan;

	void Touch( IRampageTarget target, Vector3 velocity, float damage, Vector3 at )
	{
		if ( _kicked.Count > 300 ) _kicked.Clear();
		_kicked[target] = Time.Now + 0.45f;
		target.Hit( velocity, damage, at );
	}

	/// <summary>
	/// Each physics step: whatever small thing the moving legs have walked into is kicked on ahead,
	/// with the giant's own speed and a bit of lift. People are ankle-high: they go a long way.
	/// </summary>
	void Shins()
	{
		var c = _controller;
		if ( !_erupted || !Rampage.Started ) return;
		var velocity = c.Velocity;
		float speed = velocity.WithZ( 0f ).Length;
		if ( speed < KickFromSpeed ) return;

		float radius = c.Radius;
		var at = c.WorldPosition + Vector3.Up * radius + velocity.WithZ( 0f ).Normal * (radius * 0.4f);
		float now = Time.Now;
		float damage = KickDamage * Rampage.Might * Math.Clamp( speed / MathF.Max( c.Speed, 1f ), 0.5f, 2f );

		var near = Rampage.Borrow();
		Rampage.TargetsNear( at, radius * 1.25f, near );
		for ( int i = 0; i < near.Count; i++ )
		{
			var target = near[i];
			if ( !Small( target ) ) continue;
			if ( _kicked.TryGetValue( target, out float until ) && now < until ) continue;
			Touch( target, velocity * 1.15f + Vector3.Up * (260f + speed * 0.35f), damage, target.Centre );
		}
		Rampage.Return( near );
	}

	// ---- Landing and barging -----------------------------------------------------------------------

	void Air( float dt )
	{
		var c = _controller;
		if ( !c.Attached )
		{
			_airTime += dt;
			_fall = MathF.Max( _fall, -c.Velocity.z );
			return;
		}
		if ( _airTime > 0.2f && _fall > LandFromFall && _erupted ) Land( _fall );
		_airTime = 0f;
		_fall = 0f;
	}

	/// <summary>The landing of a heavy jump: a shockwave, a crater's worth of dust and everything nearby thrown.</summary>
	void Land( float fall )
	{
		var c = _controller;
		float size = MathF.Max( BodyScale, 1f );
		float hard = Math.Clamp( fall / MathF.Max( c.JumpSpeed, 1f ), 0.5f, 2f );
		var at = c.WorldPosition;

		Stomp( at, StompRadiusPerScale * size * 2.2f, StompDamage * 2f * Rampage.Might * hard, StompThrow * 1.3f );
		Rampage.SendShockwave( at, LandShockPerScale * size * hard * GiantRiders.ShockBonus, LandShockSpeed * hard );
		Rampage.Shake( 0.35f + 0.3f * hard );
		c.Kick( Vector3.Down * (10f + 8f * hard) );
		Rampage.PlaySound( "giant_land", at );
		RampageWorld.Current?.Fx?.Dust( at, new Vector3( size * 22f, size * 22f, 12f ), 6 );
		Landed?.Invoke( at, hard );
	}

	/// <summary>
	/// Buildings stop the giant. Leaning on one (trying to walk and getting nowhere) for a moment
	/// puts a shoulder into it, again and again until it gives.
	/// </summary>
	void Barge( float dt )
	{
		var c = _controller;
		bool pushing = c.Attached && !c.InputLocked && !c.IsPinned && Rampage.Started && Input.AnalogMove.Length > 0.3f;
		bool stuck = pushing && c.Velocity.WithZ( 0f ).Length < c.Speed * 0.22f;
		_blocked = stuck ? _blocked + dt : 0f;
		if ( _blocked < BargeAfter || Time.Now < _nextBarge ) return;
		_nextBarge = Time.Now + BargeEvery;

		// The way it is trying to go: the keys, steered by the camera.
		var move = Input.AnalogMove;
		var forward = Rotation.FromYaw( c.Look.yaw ) * new Vector3( move.x, move.y, 0f ).Normal;
		float radius = c.Radius;
		var at = c.WorldPosition + Vector3.Up * (radius * 1.5f) + forward * (radius * 1.6f);

		bool hit = false;
		var near = Rampage.Borrow();
		Rampage.TargetsNear( at, radius * 1.4f, near );
		for ( int i = 0; i < near.Count; i++ )
		{
			var target = near[i];
			if ( target is not Building && target is not Toppler ) continue;
			target.Hit( forward * 800f + Vector3.Up * 200f, BargeDamage * Rampage.Might, at );
			hit = true;
		}
		Rampage.Return( near );
		if ( !hit ) return;

		Rampage.Shake( 0.35f );
		c.Kick( -forward * 8f );
		Rampage.PlaySound( "giant_barge", at );
	}

	// ---- The people who grab ---------------------------------------------------------------------------

	/// <summary>
	/// Nobody pins a giant. The brave ones who take hold of an ankle are climbers: they slow it a
	/// very little, and the riders flick them off (see <see cref="GiantRiders"/>).
	/// </summary>
	void TuneGrips()
	{
		var populace = RampagePopulace.Current;
		if ( !populace.IsValid() ) return;
		var grips = populace.Grips;
		if ( !grips.IsValid() ) return;
		_gripsTuned = true;
		grips.PinGrips = 1000;
		grips.SlowPerGrip = 0.03f;
		grips.GrabBeatSeconds = 0.5f;
		grips.GripReach = MathF.Max( grips.GripReach, _controller.Radius * 4f );
	}
}