Part of the SumpHub partial class. Builds the hub's small life props: a noticeboard with MISSING posters for each unhealed misfit plus a jar shelf counter, and the crooked path lamps between the landing and each shrine, radio, market and the way down, scaling the trail with the healed count. Also handles reading the board through Sump.Say.
using System;
using System.Collections.Generic;
using System.Linq;
// Small life: the noticeboard of "missing" posters for everyone still hiding, the shelf of jars
// that counts who has been helped, and the crooked lamps along the paths between the things that
// exist. All of it grows with the healed count.
public sealed partial class SumpHub
{
/// <summary>How far from the landing the noticeboard stands.</summary>
[Property, Group( "Life" )] public float BoardDistance { get; set; } = 390f;
/// <summary>Gap between lamps on the trail to the way down, in inches.</summary>
[Property, Group( "Life" )] public float TrailLampSpacing { get; set; } = 420f;
/// <summary>Most lamps the trail to the way down ever has.</summary>
[Property, Group( "Life" ), Range( 2, 12 )] public int TrailLampsMax { get; set; } = 8;
GameObject _boardRoot;
int _boardReads;
readonly HashSet<string> _lampKeys = new();
int _pathLights;
void ForgetLife()
{
_boardRoot = null;
_lampKeys.Clear();
_pathLights = 0;
}
// ---- The noticeboard ----------------------------------------------------------------------------
/// <summary>
/// Puts the board up, or takes it down and puts it up again with the posters as they now stand.
/// It only assembles itself the first time; after that a poster just changes.
/// </summary>
void RebuildBoard( bool animate )
{
bool first = !_boardRoot.IsValid();
if ( !first )
{
var old = _boardRoot;
_spots.RemoveAll( spot => spot.Owner == old );
old.Destroy();
}
// Between two of the inner build sites, so it never stands on a shrine.
var sites = SumpCavern.BuildSites;
float toward = sites.Count > 0 ? HubKit.YawToward( Sump.HubSpawn, sites[0] ) + 30f : 30f;
var at = HubKit.OnFloor( HubKit.Around( Sump.HubSpawn, toward, BoardDistance ) );
var b = HubBuilder.At( _root, "Noticeboard", at, FaceLanding( at ) );
_boardRoot = b.Root;
var rng = new HubRng( MisfitGenerator.Mix( SumpState.Seed, 0xB0A2D ) );
b.Box( "Board Post", new Vector3( 0f, -86f, 50f ), new Vector3( 6f, 6f, 124f ), HubKit.DarkWood, true );
b.Box( "Board Post", new Vector3( 0f, 86f, 50f ), new Vector3( 6f, 6f, 124f ), HubKit.DarkWood, true );
b.Box( "Board", new Vector3( 0f, 0f, 74f ), new Vector3( 4f, 176f, 88f ), HubKit.Shade( HubKit.Wood, 0.7f ) );
b.Box( "Board Roof", new Vector3( 4f, 0f, 122f ), new Vector3( 20f, 190f, 3f ), HubKit.Rust, false, Rotation.FromPitch( 9f ) );
// MISSING, in seven daubs of red.
for ( int i = 0; i < 7; i++ )
b.Box( "Heading", new Vector3( 2.5f, -30f + i * 10f, 111f + rng.R( -1f, 1f ) ), new Vector3( 0.8f, rng.R( 5f, 7.5f ), rng.R( 6f, 9f ) ), new Color( 0.7f, 0.1f, 0.08f ), false, Rotation.FromRoll( rng.R( -10f, 10f ) ) );
var misfits = SumpState.Misfits;
for ( int i = 0; i < misfits.Count && i < 9; i++ )
{
bool top = i < 5;
float y = top ? (i - 2) * 33f : (i - 6.5f) * 33f;
var poster = b.Group( "Poster", new Vector3( 2.6f, y, top ? 88f : 52f ), Rotation.FromRoll( rng.R( -6f, 6f ) ) );
BuildPoster( poster, misfits[i] );
}
BuildCounter( b );
var light = b.Light( "Board Light", new Vector3( 46f, 0f, 100f ), HubKit.Bulbs[0], 280f );
AddFlame( light, HubKit.Shade( HubKit.Bulbs[0], 0.5f ), 0.12f, 2.5f );
AddSpot( b.Root, b.World( new Vector3( 60f, 0f, 0f ) ), 110f, () => "E read the board", ReadBoard );
if ( first ) Finish( b, animate, RiseSeconds * 0.8f );
}
/// <summary>One poster: a likeness in the misfit's colours, two lines nobody can read, and either MISSING or a big tick.</summary>
static void BuildPoster( HubBuilder poster, MisfitProfile profile )
{
var green = new Color( 0.2f, 0.65f, 0.25f );
poster.Box( "Paper", Vector3.Zero, new Vector3( 1f, 27f, 33f ), profile.Healed ? HubKit.Shade( HubKit.Paper, 1.08f ) : HubKit.Paper );
poster.Box( "Poster Heading", new Vector3( 0.6f, 0f, 13f ), new Vector3( 0.5f, 20f, 3.5f ), profile.Healed ? green : new Color( 0.7f, 0.1f, 0.08f ) );
poster.Disc( "Likeness", new Vector3( 0.7f, 0f, 3f ), 7f, 0.6f, profile.Primary );
poster.Ball( "Likeness Eye", new Vector3( 1.2f, 2.5f, 4.5f ), 1.3f, profile.Secondary );
poster.Box( "Poster Line", new Vector3( 0.6f, 1f, -8f ), new Vector3( 0.5f, 19f, 1.2f ), HubKit.Ink );
poster.Box( "Poster Line", new Vector3( 0.6f, -3f, -11.5f ), new Vector3( 0.5f, 13f, 1.2f ), HubKit.Ink );
poster.Ball( "Pin", new Vector3( 0.9f, 0f, 15.6f ), 0.9f, HubKit.Tin );
if ( !profile.Healed ) return;
// Found.
poster.Rod( "Tick", new Vector3( 1.6f, 7f, 2f ), new Vector3( 1.6f, 2f, -6f ), 1.8f, green );
poster.Rod( "Tick", new Vector3( 1.6f, 2f, -6f ), new Vector3( 1.6f, -9f, 10f ), 1.8f, green );
}
/// <summary>The counter: a shelf under the board with a jar for everybody. A jar is lit once its misfit is helped.</summary>
static void BuildCounter( HubBuilder b )
{
b.Box( "Jar Shelf", new Vector3( 7f, 0f, 24f ), new Vector3( 14f, 176f, 3f ), HubKit.DarkWood );
var misfits = SumpState.Misfits;
for ( int i = 0; i < misfits.Count && i < 9; i++ )
{
var at = new Vector3( 8f, (i - (Math.Min( misfits.Count, 9 ) - 1) * 0.5f) * 18.5f, 25.5f );
if ( misfits[i].Healed )
{
b.Ball( "Lit Jar", at + Vector3.Up * 5f, new Vector3( 4.5f, 4.5f, 5.5f ), HubKit.Shade( misfits[i].Primary, 1.25f ) );
b.Box( "Jar Lid", at + Vector3.Up * 10.8f, new Vector3( 5f, 5f, 1.4f ), HubKit.Shade( misfits[i].Secondary, 0.8f ) );
}
else
{
b.Ball( "Empty Jar", at + Vector3.Up * 5f, new Vector3( 4.5f, 4.5f, 5.5f ), new Color( 0.12f, 0.14f, 0.15f ) );
}
}
}
/// <summary>Reading the board: one of the missing each time, and now and then the count.</summary>
void ReadBoard()
{
var misfits = SumpState.Misfits;
var missing = misfits.Where( m => !m.Healed ).ToList();
int healed = misfits.Count - missing.Count;
int read = _boardReads++;
if ( missing.Count == 0 )
{
Sump.Say( "NOTICEBOARD", "Nobody is missing. Every jar on the shelf is lit.", 6f );
return;
}
if ( read % 4 == 3 )
{
Sump.Say( "NOTICEBOARD", healed == 0
? $"Helped so far: none of {misfits.Count}. The jars are all dark."
: $"Helped so far: {healed} of {misfits.Count}. Somebody lights a jar for each.", 6f );
return;
}
var profile = missing[read % missing.Count];
var role = MisfitTables.FindRole( profile.Role );
Sump.Say( "MISSING", $"{MisfitVoice.ShortName( profile )}. Came as {role?.A ?? "a visitor"}. Afraid of {profile.Fear}. It {profile.Twitch}. If seen: stay near, stay slow, do not wave anything at it.", 8f );
}
// ---- Lamps --------------------------------------------------------------------------------------
/// <summary>
/// Lamps on the way from the landing to everything that exists, and a trail of them toward the
/// way down that gets one misfit's worth longer each time, reaching the hatch as it opens.
/// </summary>
void EnsureLamps( int healed, bool animate )
{
var landing = Sump.HubSpawn;
foreach ( var shrine in _shrines.Values )
LampPath( $"shrine_{shrine.Profile.Index}", landing, shrine.Position, false, animate );
if ( _radioRoot.IsValid() ) LampPath( "radio", landing, _radioAt, true, animate );
if ( _marketRoot.IsValid() ) LampPath( "market", landing, _marketAt, true, animate );
if ( healed <= 0 || !_downRoot.IsValid() ) return;
float distance = (_downAt - landing).WithZ( 0f ).Length;
int total = Math.Clamp( (int)(distance / MathF.Max( TrailLampSpacing, 100f )), 2, TrailLampsMax );
int lit = (int)MathF.Ceiling( total * Math.Clamp( healed / (float)Math.Max( SumpState.FinaleNeeds, 1 ), 0f, 1f ) );
for ( int k = 0; k < lit; k++ )
{
float t = 0.14f + 0.8f * (k + 0.5f) / total;
Lamp( $"down_{k}", landing + (_downAt - landing) * t, k % 2 == 0 ? 55f : -55f, k % 2 == 0, k, animate );
}
}
/// <summary>One lamp (two on a long path) beside the straight line between two places.</summary>
void LampPath( string key, Vector3 from, Vector3 to, bool light, bool animate )
{
float distance = (to - from).WithZ( 0f ).Length;
if ( distance < 350f ) return;
int count = distance > 760f ? 2 : 1;
for ( int k = 0; k < count; k++ )
{
float t = count == 1 ? 0.62f : 0.4f + k * 0.34f;
Lamp( $"{key}_{k}", from + (to - from) * t, k % 2 == 0 ? 48f : -48f, light && k == count - 1, k + key.Length, animate );
}
}
/// <summary>A crooked post with a jar of something glowing hung from it.</summary>
void Lamp( string key, Vector3 at, float aside, bool light, int variety, bool animate )
{
if ( !_lampKeys.Add( key ) ) return;
var along = (at - Sump.HubSpawn).WithZ( 0f );
var side = along.Length > 1f ? new Vector3( -along.y, along.x, 0f ).Normal : new Vector3( 0f, 1f, 0f );
var foot = HubKit.OnFloor( at + side * aside );
var colour = HubKit.Bulbs[Math.Abs( variety ) % HubKit.Bulbs.Length];
var b = HubBuilder.At( _root, "Path Lamp", foot, HubKit.YawToward( foot, at ) + 180f + (variety % 3 - 1) * 25f );
b.Rod( "Lamp Post", new Vector3( 0f, 0f, -8f ), new Vector3( 4f, 0f, 54f ), 3.2f, HubKit.DarkWood );
b.Rod( "Lamp Arm", new Vector3( 4f, 0f, 53f ), new Vector3( 15f, 0f, 58f ), 2.2f, HubKit.DarkWood );
b.Rod( "Lamp String", new Vector3( 14f, 0f, 57f ), new Vector3( 14f, 0f, 51f ), 0.7f, HubKit.Ink );
b.Box( "Jar Lid", new Vector3( 14f, 0f, 50.4f ), new Vector3( 5f, 5f, 1.4f ), HubKit.Tin );
b.Ball( "Jar Glow", new Vector3( 14f, 0f, 45.5f ), new Vector3( 4f, 4f, 5f ), colour );
b.Box( "Lamp Stone", new Vector3( -3f, 4f, 2f ), new Vector3( 12f, 10f, 8f ), HubKit.Rock, false, Rotation.FromYaw( variety * 31f ) );
if ( light && _pathLights < MaxPathLights )
{
_pathLights++;
AddFlame( b.Light( "Lamp Light", new Vector3( 14f, 0f, 40f ), colour, LampRadius ), HubKit.Shade( colour, 0.55f ), 0.2f, 3f + variety % 3 );
}
Finish( b, animate, 1.4f );
}
}