A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.
fix(map): sea-coloured camera clear and an outline on the selected hex
eyalgolan63f040ffb1f1
diff --git a/unity/Assets/Scripts/Map/MapBuilder.cs b/unity/Assets/Scripts/Map/MapBuilder.csindex 86b562d3c..2c6135478 100644--- a/unity/Assets/Scripts/Map/MapBuilder.cs+++ b/unity/Assets/Scripts/Map/MapBuilder.cs@@ -147,40 +147,54 @@ namespace Statecraft.Game.Mapdata.SetAlphamaps(0, 0, a);}+ /// <summary>Vertices of one draped hex ring (<see cref="DrapedRing"/>).</summary>+ public const int RingVertices = 6 * OverlaySegmentsPerEdge;++ /// <summary>Appends the <see cref="RingVertices"/> vertices of a hex outline of circumradius <paramref name="size"/>+ /// around <paramref name="centre"/> (world x, z), corners from HexMath. Each edge is split into OverlaySegmentsPerEdge+ /// sub-segments, clamped to the terrain bounds; each vertex sits <paramref name="clearance"/> above the highest+ /// terrain sampled along its two adjacent sub-segments, so the straight line between two vertices clears any ridge.+ /// The hex overlay and the selection outline share it.</summary>+ public static void DrapedRing(GeoFrame frame, TerrainData data, Vector2 centre, float size, float clearance, List<Vector3> verts)+ {+ int n = RingVertices;+ var corners = new Vector2[6]; var ground = new Vector2[n]; var segMax = new float[n];+ for (int i = 0; i < 6; i++) corners[i] = HexMath.Corner(centre, size, i);+ for (int i = 0; i < 6; i++)+ for (int s = 0; s < OverlaySegmentsPerEdge; s++)+ {+ var k = Vector2.Lerp(corners[i], corners[(i + 1) % 6], (float)s / OverlaySegmentsPerEdge);+ k.x = Mathf.Clamp(k.x, 0f, frame.WidthM); k.y = Mathf.Clamp(k.y, 0f, frame.LengthM);+ ground[i * OverlaySegmentsPerEdge + s] = k;+ }+ for (int j = 0; j < n; j++)+ {+ float m = float.MinValue;+ for (int t = 0; t <= OverlaySamplesPerSegment; t++)+ {+ var p = Vector2.Lerp(ground[j], ground[(j + 1) % n], (float)t / OverlaySamplesPerSegment);+ m = Mathf.Max(m, data.GetInterpolatedHeight(p.x / frame.WidthM, p.y / frame.LengthM));+ }+ segMax[j] = m;+ }+ for (int j = 0; j < n; j++)+ verts.Add(new Vector3(ground[j].x, Mathf.Max(segMax[(j + n - 1) % n], segMax[j]) + clearance, ground[j].y));+ }+/// <summary>Line mesh of every land hex outline. Each edge is split into OverlaySegmentsPerEdge sub-segments; vertices/// are clamped to the terrain bounds. Each vertex sits OverlayClearanceM above the highest terrain sampled along its/// two adjacent sub-segments, so the straight line between two vertices clears any ridge between them.</summary>static GameObject BuildHexOverlay(GeoFrame frame, HexFile hexes, TerrainData data, Material material, MapRuntimeAssets assets){float size = hexes.hex_size_km * 1000f;- int n = 6 * OverlaySegmentsPerEdge;+ int n = RingVertices;var verts = new List<Vector3>(); var idx = new List<int>();- var corners = new Vector2[6]; var ground = new Vector2[n]; var segMax = new float[n];foreach (var h in hexes.hexes){if (!h.land) continue;var c = frame.ToWorld(h.lon, h.lat, 0);- for (int i = 0; i < 6; i++) corners[i] = HexMath.Corner(new Vector2(c.x, c.z), size, i);- for (int i = 0; i < 6; i++)- for (int s = 0; s < OverlaySegmentsPerEdge; s++)- {- var k = Vector2.Lerp(corners[i], corners[(i + 1) % 6], (float)s / OverlaySegmentsPerEdge);- k.x = Mathf.Clamp(k.x, 0f, frame.WidthM); k.y = Mathf.Clamp(k.y, 0f, frame.LengthM);- ground[i * OverlaySegmentsPerEdge + s] = k;- }- for (int j = 0; j < n; j++)- {- float m = float.MinValue;- for (int t = 0; t <= OverlaySamplesPerSegment; t++)- {- var p = Vector2.Lerp(ground[j], ground[(j + 1) % n], (float)t / OverlaySamplesPerSegment);- m = Mathf.Max(m, data.GetInterpolatedHeight(p.x / frame.WidthM, p.y / frame.LengthM));- }- segMax[j] = m;- }int start = verts.Count;- for (int j = 0; j < n; j++)- verts.Add(new Vector3(ground[j].x, Mathf.Max(segMax[(j + n - 1) % n], segMax[j]) + OverlayClearanceM, ground[j].y));+ DrapedRing(frame, data, new Vector2(c.x, c.z), size, OverlayClearanceM, verts);for (int i = 0; i < n; i++) { idx.Add(start + i); idx.Add(start + (i + 1) % n); }}var mesh = assets.Own(new Mesh { name = "HexOverlay", indexFormat = UnityEngine.Rendering.IndexFormat.UInt32 });diff --git a/unity/Assets/Scripts/Map/MapPointer.cs b/unity/Assets/Scripts/Map/MapPointer.csindex d7dffa8e2..1bd07b2d7 100644--- a/unity/Assets/Scripts/Map/MapPointer.cs+++ b/unity/Assets/Scripts/Map/MapPointer.cs@@ -31,6 +31,7 @@ namespace Statecraft.Game.Map// only the terrain's own collider: other colliders (markers, future props) never decide which hex is clickedif (cam == null || collider == null || !collider.Raycast(cam.ScreenPointToRay(pos), out var hit, 1_000_000f)) return false;var hex = Pick(Map, hit.point);+ Map.Select(hex.q, hex.r); // the map marks the hex the info panel describesHexClicked?.Invoke(hex.q, hex.r);return true;}diff --git a/unity/Assets/Scripts/Map/MapScene.cs b/unity/Assets/Scripts/Map/MapScene.csindex bd8a902ba..79bfc4f51 100644--- a/unity/Assets/Scripts/Map/MapScene.cs+++ b/unity/Assets/Scripts/Map/MapScene.cs@@ -1,4 +1,5 @@using System;+using System.Collections.Generic;using System.IO;using Statecraft.Game.Boot;using UnityEngine;@@ -18,6 +19,67 @@ namespace Statecraft.Game.Mappublic Terrain Terrain { get; private set; }public Material MarkerMaterial => markerMaterial;+ /// <summary>The selected hex's outline: a child of the terrain (so a rebuild destroys it).</summary>+ public const string SelectionName = "HexSelection";+ /// <summary>Highlight colour of the selected hex (the UI's gold, brighter, to read against every biome).</summary>+ public static readonly Color SelectionColour = new Color(1f, 0.84f, 0.38f);+ /// <summary>Width of the outline band, as a fraction of the hex circumradius (about 600 m on a 5 km hex).</summary>+ public const float SelectionWidth = 0.12f;+ /// <summary>Height of the band above the hex overlay's lines, which it covers.</summary>+ public const float SelectionLiftM = 20f;+ static readonly int BaseColor = Shader.PropertyToID("_BaseColor");++ /// <summary>Outlines hex (q, r) with a band draped on the terrain in <see cref="SelectionColour"/>: the hex overlay's+ /// geometry (MapBuilder.DrapedRing, HexMath corners) and its editor-made material, coloured through a+ /// MaterialPropertyBlock (no runtime material). A hex that is not on the map hides the outline.</summary>+ public void Select(int q, int r)+ {+ if (Terrain == null || Hexes == null) return;+ var found = Terrain.transform.Find(SelectionName);+ var go = found != null ? found.gameObject : null;+ if (go == null)+ {+ go = new GameObject(SelectionName);+ go.transform.SetParent(Terrain.transform, false);+ var mesh = Terrain.GetComponent<MapRuntimeAssets>().Own(new Mesh { name = SelectionName });+ go.AddComponent<MeshFilter>().sharedMesh = mesh;+ var renderer = go.AddComponent<MeshRenderer>();+ renderer.sharedMaterial = overlayMaterial;+ renderer.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;+ var block = new MaterialPropertyBlock();+ block.SetColor(BaseColor, SelectionColour);+ renderer.SetPropertyBlock(block);+ }+ var mr = go.GetComponent<MeshRenderer>();+ HexJson hex = null;+ foreach (var h in Hexes.hexes) if (h.q == q && h.r == r) { hex = h; break; }+ if (hex == null) { mr.enabled = false; return; }+ var c = Frame.ToWorld(hex.lon, hex.lat, 0);+ var centre = new Vector2(c.x, c.z);+ float size = Hexes.hex_size_km * 1000f, clearance = MapBuilder.OverlayClearanceM + SelectionLiftM;+ var verts = new List<Vector3>(2 * MapBuilder.RingVertices);+ MapBuilder.DrapedRing(Frame, Terrain.terrainData, centre, size, clearance, verts);+ MapBuilder.DrapedRing(Frame, Terrain.terrainData, centre, size * (1f - SelectionWidth), clearance, verts);+ int n = MapBuilder.RingVertices;+ var tris = new List<int>(12 * n);+ for (int j = 0; j < n; j++)+ {+ // Both rings at the higher of the two, so the band clears the ground between them too.+ float y = Mathf.Max(verts[j].y, verts[n + j].y);+ verts[j] = new Vector3(verts[j].x, y, verts[j].z); verts[n + j] = new Vector3(verts[n + j].x, y, verts[n + j].z);+ }+ for (int j = 0; j < n; j++)+ {+ int a = j, b = (j + 1) % n, ai = n + j, bi = n + (j + 1) % n;+ tris.AddRange(new[] { a, ai, b, b, ai, bi, a, b, ai, b, bi, ai }); // both windings: seen from any yaw+ }+ var m = go.GetComponent<MeshFilter>().sharedMesh;+ m.Clear();+ m.SetVertices(verts); m.SetTriangles(tris, 0);+ m.RecalculateBounds();+ mr.enabled = true;+ }+public void Configure(Material terrain, Material overlay, Material marker){ terrainMaterial = terrain; overlayMaterial = overlay; markerMaterial = marker; }diff --git a/unity/Assets/Tests/EditMode/GameSceneTests.cs b/unity/Assets/Tests/EditMode/GameSceneTests.csindex bb246264b..4195a62d4 100644--- a/unity/Assets/Tests/EditMode/GameSceneTests.cs+++ b/unity/Assets/Tests/EditMode/GameSceneTests.cs@@ -169,6 +169,17 @@ public class GameSceneTestsvar pointer = Object.FindFirstObjectByType<MapPointer>();Assert.IsTrue(pointer.HandleClick(AimAtTelAviv()), "the ray hit the terrain");Assert.AreEqual("Tel Aviv", Ui.Q<Label>("info-title").text);+ // Playtest 1, item 10: the map marks the hex the info panel describes.+ var map = Object.FindFirstObjectByType<MapScene>();+ var sel = map.Terrain.transform.Find(MapScene.SelectionName);+ Assert.IsNotNull(sel, "the clicked hex is outlined");+ Assert.IsTrue(sel.GetComponent<MeshRenderer>().enabled);+ var tlv = Inputs.Content.SettlementHexes.Single(s => s.Id == "tel_aviv");+ var hex = Inputs.Content.HexAt(tlv.Q, tlv.R)!;+ var ground = map.Frame.ToWorld(hex.Lon, hex.Lat, 0);+ var b = sel.GetComponent<MeshFilter>().sharedMesh.bounds;+ Assert.AreEqual(ground.x, b.center.x, 100f, "the outline is on the clicked hex");+ Assert.AreEqual(ground.z, b.center.z, 100f);}/// <summary>Points the main camera straight down at Tel Aviv and returns the screen centre.</summary>