f9e22e872f
World scaled 3x (768x768) with all four towns at compass points, each running its own soul culture: North generational, South nature, West materialist (new profile), East selfish. Two new resources: Ore (metal tier) and Herb (medicine - mends health, reason to forage, trade good). Spatial hash grid replaces O(n^2) proximity scans (soul pressure, neighbor, teacher) - 3.6x headless speedup at ~80 NPCs. First social verb beyond work: pair-bonds - settled adults who keep warm company pair up; warmth now accrues from proximity not only gifts; bonds break at death. Reproduction deferred (bonds-first per plan). The four-town thesis fully realized on one engine (240-day run): North know 1.27 clean, South nourish 0.85 clean, West prosperous but debris 0.23, East hungriest 0.60 and lowest knowledge 1.08. Positive cultures stay soul-clean, negative ones carry real debris, all from behavior weights - nothing scripted. 99 bonds, 80 deaths, four living societies. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
187 lines
8.3 KiB
C#
187 lines
8.3 KiB
C#
using Godot;
|
||
|
||
namespace WorldSim;
|
||
|
||
/// <summary>
|
||
/// Top-down 2D view + debug roster (SPEC §9).
|
||
/// Draws straight from simulation state every frame — no per-NPC nodes,
|
||
/// no camera: fixed screen-space layout, map on the left, roster on the
|
||
/// right. The player-facing game has no meters; the designer sees everything.
|
||
/// </summary>
|
||
public partial class Visualization : Node2D
|
||
{
|
||
private GameManager _gm = null!;
|
||
|
||
// Layout: 1600×900 window — map fills the left square, panel the right.
|
||
private const float MapOffset = 10f;
|
||
private const float MapPixels = 880f;
|
||
private const float CellPixels = MapPixels / World.GridSize; // ~3.44
|
||
private const float PanelX = 910f;
|
||
private const float PanelWidth = 680f;
|
||
|
||
private static readonly Color PanelBg = new(0.10f, 0.10f, 0.12f);
|
||
private static readonly Color MapBg = new(0.13f, 0.13f, 0.15f);
|
||
private static readonly Color TextDim = new(0.65f, 0.65f, 0.70f);
|
||
private static readonly Color TextMain = new(0.92f, 0.92f, 0.95f);
|
||
|
||
public override void _Ready()
|
||
{
|
||
_gm = GetParent<GameManager>();
|
||
}
|
||
|
||
public override void _Process(double delta) => QueueRedraw();
|
||
|
||
private static Color StateColor(NpcState state) => state switch
|
||
{
|
||
NpcState.Gathering => Colors.White,
|
||
NpcState.Building => Colors.Orange,
|
||
NpcState.Trading => Colors.Yellow,
|
||
NpcState.Resting => new Color(0.45f, 0.45f, 0.95f),
|
||
NpcState.Socializing => new Color(0.9f, 0.4f, 0.9f),
|
||
_ => Colors.Red,
|
||
};
|
||
|
||
private static Vector2 MapPos(Vector2 gridPos) =>
|
||
new(MapOffset + gridPos.X * CellPixels, MapOffset + gridPos.Y * CellPixels);
|
||
|
||
public override void _Draw()
|
||
{
|
||
if (_gm.World == null) return;
|
||
var font = ThemeDB.FallbackFont;
|
||
|
||
// --- Backgrounds --------------------------------------------------
|
||
DrawRect(new Rect2(MapOffset, MapOffset, MapPixels, MapPixels), MapBg);
|
||
DrawRect(new Rect2(PanelX, 0, PanelWidth, 900), PanelBg);
|
||
|
||
// --- Map: resource nodes -----------------------------------------
|
||
foreach (var node in _gm.World.Nodes)
|
||
{
|
||
Color c = node.Kind switch
|
||
{
|
||
MaterialKind.Wood => new Color(0.20f, 0.55f, 0.20f),
|
||
MaterialKind.Stone => new Color(0.55f, 0.55f, 0.55f),
|
||
MaterialKind.Clay => new Color(0.75f, 0.45f, 0.25f),
|
||
MaterialKind.Water => new Color(0.25f, 0.45f, 0.85f),
|
||
MaterialKind.Food => new Color(0.80f, 0.30f, 0.40f),
|
||
MaterialKind.Ore => new Color(0.65f, 0.55f, 0.75f),
|
||
MaterialKind.Herb => new Color(0.45f, 0.80f, 0.55f),
|
||
_ => Colors.Magenta,
|
||
};
|
||
// Fade toward depletion so dying groves read at a glance
|
||
if (node.Kind != MaterialKind.Water)
|
||
c = c.Darkened(0.65f * (1f - node.Amount / node.MaxAmount));
|
||
var p = MapPos(node.Cell);
|
||
DrawRect(new Rect2(p.X, p.Y, CellPixels, CellPixels), c);
|
||
}
|
||
|
||
// --- Map: town labels --------------------------------------------
|
||
foreach (var town in _gm.Towns)
|
||
{
|
||
var tp = MapPos(town.Center);
|
||
DrawString(font, tp + new Vector2(-20f, -14f), town.Name.ToUpper(),
|
||
fontSize: 13, modulate: TextDim);
|
||
}
|
||
|
||
// --- Map: buildings ----------------------------------------------
|
||
for (int i = 0; i < _gm.Buildings.Count; i++)
|
||
{
|
||
var b = _gm.Buildings[i];
|
||
Color c = b.IsRuined ? new Color(0.25f, 0.23f, 0.20f)
|
||
: b.Kind == BuildingKind.Granary
|
||
? (b.IsComplete ? new Color(0.55f, 0.70f, 0.40f)
|
||
: new Color(0.45f, 0.52f, 0.32f))
|
||
: b.IsComplete ? new Color(0.9f, 0.85f, 0.6f).Darkened((1f - b.Condition) * 0.5f)
|
||
: new Color(0.6f, 0.5f, 0.3f);
|
||
float size = CellPixels + 3f + (b.CurrentStage + b.StageProgress) * 2f + b.Modules * 1.5f;
|
||
var p = MapPos(b.Site);
|
||
DrawRect(new Rect2(p.X - size / 2f, p.Y - size / 2f, size, size), c);
|
||
DrawString(font, p + new Vector2(size / 2f + 2f, 4f), $"{i + 1}",
|
||
fontSize: 10, modulate: TextDim);
|
||
}
|
||
|
||
// --- Map: NPCs with roster numbers -------------------------------
|
||
for (int i = 0; i < _gm.Npcs.Count; i++)
|
||
{
|
||
var npc = _gm.Npcs[i];
|
||
var p = MapPos(npc.Position);
|
||
// Selfish souls get a dark red ring — same dot, different halo.
|
||
if (npc.Soul.Type == SoulType.Selfish)
|
||
DrawCircle(p, 5.5f, new Color(0.75f, 0.15f, 0.15f));
|
||
// Debris dims the dot — encasement made visible.
|
||
DrawCircle(p, 3.5f, StateColor(npc.State).Darkened(npc.Imprint.Total * 0.7f));
|
||
DrawString(font, p + new Vector2(5f, -4f), $"{i + 1}",
|
||
fontSize: 11, modulate: TextMain);
|
||
}
|
||
|
||
// --- Panel: clock header -----------------------------------------
|
||
DrawString(font, new Vector2(PanelX + 16, 30),
|
||
$"Day {_gm.Day} · {_gm.SeasonName} {_gm.MinuteOfDay / 60:00}:{_gm.MinuteOfDay % 60:00} " +
|
||
$"{(_gm.IsNight ? "· night" : "· day")} {_gm.TicksPerRealSecond:0}x",
|
||
fontSize: 18, modulate: TextMain);
|
||
|
||
// --- Panel: villager roster --------------------------------------
|
||
float y = 66f;
|
||
DrawString(font, new Vector2(PanelX + 16, y), "VILLAGERS",
|
||
fontSize: 13, modulate: TextDim);
|
||
y += 10f;
|
||
|
||
for (int i = 0; i < _gm.Npcs.Count; i++)
|
||
{
|
||
var npc = _gm.Npcs[i];
|
||
y += 20f;
|
||
|
||
if (npc.Soul.Type == SoulType.Selfish)
|
||
DrawCircle(new Vector2(PanelX + 24, y - 5f), 6f, new Color(0.75f, 0.15f, 0.15f));
|
||
DrawCircle(new Vector2(PanelX + 24, y - 5f), 4.5f,
|
||
StateColor(npc.State).Darkened(npc.Imprint.Total * 0.7f));
|
||
DrawString(font, new Vector2(PanelX + 36, y),
|
||
$"{i + 1,2} {npc.State,-11} {npc.Activity}",
|
||
fontSize: 13, modulate: TextMain);
|
||
DrawString(font, new Vector2(PanelX + 390, y),
|
||
$"N {npc.Nourishment * 100,3:0} D {npc.Imprint.Total * 100,2:0}" +
|
||
$" K {npc.Know.Total,4:0.00} A {npc.AgeDays,3:0}" +
|
||
$" {npc.DominantStateToday().ToString().ToLower()[..4]}",
|
||
fontSize: 12, modulate: TextDim);
|
||
}
|
||
|
||
// --- Panel: buildings --------------------------------------------
|
||
y += 34f;
|
||
DrawString(font, new Vector2(PanelX + 16, y), "BUILDINGS",
|
||
fontSize: 13, modulate: TextDim);
|
||
y += 10f;
|
||
|
||
for (int i = 0; i < _gm.Buildings.Count; i++)
|
||
{
|
||
var b = _gm.Buildings[i];
|
||
y += 18f;
|
||
string status = b.IsRuined ? "RUIN"
|
||
: !b.IsComplete
|
||
? $"building: {b.Stages[b.CurrentStage].Name} {b.StageProgress * 100,3:0}%"
|
||
: b.Kind == BuildingKind.Granary
|
||
? $"granary food {b.FoodStock,5:0.0}/{Building.FoodStockCap:0}"
|
||
: $"cond {b.Condition * 100,3:0}% wood {b.UpkeepStock,4:0.0}/{Building.UpkeepStockCap:0}" +
|
||
$" mods {b.Modules}/{Building.ModuleCap} burn {b.DailyBurn:0.0}/day";
|
||
DrawString(font, new Vector2(PanelX + 36, y),
|
||
$"{i + 1} {b.Town,-5} {status}", fontSize: 12,
|
||
modulate: b.IsRuined ? TextDim : TextMain);
|
||
}
|
||
|
||
// --- Panel: world totals -----------------------------------------
|
||
y += 34f;
|
||
float wood = 0f, stone = 0f, clay = 0f, foodTotal = 0f;
|
||
foreach (var n in _gm.World.Nodes)
|
||
{
|
||
switch (n.Kind)
|
||
{
|
||
case MaterialKind.Wood: wood += n.Amount; break;
|
||
case MaterialKind.Stone: stone += n.Amount; break;
|
||
case MaterialKind.Clay: clay += n.Amount; break;
|
||
case MaterialKind.Food: foodTotal += n.Amount; break;
|
||
}
|
||
}
|
||
DrawString(font, new Vector2(PanelX + 16, y),
|
||
$"WORLD wood {wood:0} stone {stone:0} clay {clay:0} food {foodTotal:0}",
|
||
fontSize: 13, modulate: TextDim);
|
||
}
|
||
}
|