A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.
Hex tiles: desert_edge draws one tent model per camp tent (Refs #3077) (#3080)
Eyal Golan51cb7fa2daf6
diff --git a/changelog.d/e6-3077-desert-edge-one-tent.md b/changelog.d/e6-3077-desert-edge-one-tent.mdnew file mode 100644index 000000000..d90228ee3--- /dev/null+++ b/changelog.d/e6-3077-desert-edge-one-tent.md@@ -0,0 +1,7 @@+### Fixed+- The hex tiles' desert edge draws each Bedouin tent once (Refs #3077): each tent was a row of two or three boxes, and+ since Tal Heuberger's tent model arrived each box drew a whole tent, so a camp of three tents showed up to nine+ overlapping ones. Each tent is now one tent model as long as the row was. Where the tile draws no models it is still+ the row of dark boxes, and while the props stream in (or if they fail to load) each tent is one box as long as the+ tent, like other props. By arithmetic from the model's triangle count, the tile stays inside its 25,000-triangle+ budget.diff --git a/unity/Assets/Scripts/Map/HexTiles/Core/HexTileContext.cs b/unity/Assets/Scripts/Map/HexTiles/Core/HexTileContext.csindex 78586fb71..193134c44 100644--- a/unity/Assets/Scripts/Map/HexTiles/Core/HexTileContext.cs+++ b/unity/Assets/Scripts/Map/HexTiles/Core/HexTileContext.cs@@ -116,6 +116,16 @@ namespace Statecraft.HexTilespublic float Range(float min, float max) => min + (float)Rng.NextDouble() * (max - min);+ /// <summary>Whether <paramref name="model"/> draws as a model here rather than as its stand-in, decided as the board's+ /// renderer decides it (HexBoardRenderer.Emit): a streamed id (a hex prop while playing, a Collection alias) draws its+ /// prefab once the stream answers; any other id draws if HexModels finds its prefab (the AssetDatabase in the editor,+ /// else Resources). For a prototype whose stand-in is placed differently from its model (DesertEdge's tents).</summary>+ public bool DrawsModel(string model, Vector3 at)+ {+ var id = HexModels.Resolve(model, at);+ return HexCollectionFigures.Streams(id) || HexModels.Prefab(id) != null;+ }+/// <summary>A model sized by its largest footprint side, <paramref name="widthM"/> (buildings, rocks).</summary>public bool PlaceByWidth(string model, Vector3 at, float yawDeg, float widthM, StandIn standIn, Color? tint = null, float maxSlopeDeg = 30f) =>PlaceByWidthExact(model, at, yawDeg, widthM * HexScale.PieceScale, standIn, tint, maxSlopeDeg);diff --git a/unity/Assets/Scripts/Map/HexTiles/Prototypes/DesertEdge.cs b/unity/Assets/Scripts/Map/HexTiles/Prototypes/DesertEdge.csindex 783b71a7f..c8e17155a 100644--- a/unity/Assets/Scripts/Map/HexTiles/Prototypes/DesertEdge.cs+++ b/unity/Assets/Scripts/Map/HexTiles/Prototypes/DesertEdge.cs@@ -10,12 +10,14 @@ namespace Statecraft.HexTiles.Prototypes/// its banks. Desert rocks are scattered, two of them large. A Bedouin camp of three long, low, dark goat-hair tents/// sits on the far flank. There are no people or animals, few pieces, and the unit spot stays open.///- /// Each tent is two or three dark Box stand-ins in a row along its heading (until Tal Heuberger's tiles:desert_edge/tent- /// model arrives from the hex-props bundle, see HexProps), because the Box stand-in is fixed at 0.65 of its width tall. A row reads long and low; boxes sit just apart, so their tops- /// never overlap.+ /// Each tent is one of Tal Heuberger's tiles:desert_edge/tent models (the hex-props bundle, see HexProps), as long as a+ /// row of two or three boxes. Where the model does not draw (HexTileContext.DrawsModel), the tent is that row of dark Box+ /// stand-ins along its heading instead, because the Box stand-in is fixed at 0.65 of its width tall: a row reads long+ /// and low. One placement per box would draw a whole tent model per box (#3077).////// Triangle budget by arithmetic (caps below, with measured per-model counts): 6 acacias x ~1,160 = 6,960. 9 rocks x- /// ~700 = 6,300. 9 tent boxes x under 50 = under 450. Total under 13,800 of 25,000.</summary>+ /// ~700 = 6,300. 3 tents x 1,842 (the tent's OBJ) = 5,526. Total about 18,800 of 25,000. With the box rows instead, 9+ /// boxes x 16 = 144, total about 13,400.</summary>[HexPrototype("desert_edge", Kind = "nature")]public sealed class DesertEdge : IHexPrototype{@@ -78,12 +80,14 @@ namespace Statecraft.HexTiles.Prototypes}// 3. The Bedouin camp on the far flank: up to three tents along the contour, staggered up and down the slope,- // each a row of two or three dark boxes along its heading.+ // each one tent model along its heading, or a row of two or three dark boxes where the model does not draw.+ // Both draw the same random numbers, so the acacias and rocks after them are drawn alike.float campBearing = side + 180f + ctx.Range(-35f, 35f);var camp = ctx.At(campBearing, ctx.Range(0.52f, 0.58f));var radial = Flat(camp - ctx.Centre).normalized;var contour = new Vector3(radial.z, 0f, -radial.x);float[] stagger = { 0f, 0.07f, -0.02f };+ bool tentModel = ctx.DrawsModel(Tent, camp);for (int j = 0; j < MaxTents; j++){int boxes = 2 + ctx.Rng.Next(2);@@ -91,6 +95,15 @@ namespace Statecraft.HexTiles.Prototypesvar centre = camp + contour * ((j - 1) * 0.21f * s) + radial * (stagger[j] * s);var dir = Quaternion.Euler(0f, turn, 0f) * contour;float yaw = Mathf.Atan2(dir.x, dir.z) * Mathf.Rad2Deg;+ if (tentModel)+ {+ // The model's long side (its z) along the heading, as long as the row: the boxes' centres span+ // (boxes - 1) x 1.04 w and each draws w x PieceScale wide, and PlaceByWidth scales by PieceScale too.+ float length = w + (boxes - 1) * 1.04f * w / HexScale.PieceScale, r = 0.75f * length;+ if (ctx.InUnitSpot(centre, r) || NearWadi(centre, r + 0.03f * s)) continue;+ if (ctx.PlaceByWidth(Tent, centre, yaw, length, StandIn.Box, TentBlack, maxSlopeDeg: 40f)) taken.Add((centre, r));+ continue;+ }for (int b = 0; b < boxes; b++){var at = centre + dir * ((b - 0.5f * (boxes - 1)) * 1.04f * w);diff --git a/unity/Assets/Tests/EditMode/HexPropsTests.cs b/unity/Assets/Tests/EditMode/HexPropsTests.csindex c2398cf9c..68cee17d0 100644--- a/unity/Assets/Tests/EditMode/HexPropsTests.cs+++ b/unity/Assets/Tests/EditMode/HexPropsTests.cs@@ -215,6 +215,34 @@ public class HexPropsTestsAssert.That(ctx.Placements.Count(p => p.Model == id), Is.GreaterThan(0), tile + " places " + id);}+ /// <summary>#3077: desert_edge draws one tent model per camp tent, so at most its three (DesertEdge.MaxTents), both where+ /// the editor loads the tent from the AssetDatabase and where it streams (a player; here a test source). Each camp tent+ /// was a row of two or three placements of the tent id, and each drew a whole tent model, up to nine on the tile.</summary>+ [Test]+ public void TheDesertEdgeDrawsAtMostOneTentModelPerCampTent()+ {+ const string tent = "tiles:desert_edge/tent";+ var hexes = new[] { (2, -1, 1948), (-3, 5, 7), (11, -8, 31415), (0, 0, 1), (5, 2, 42) };+ void Check(string where)+ {+ foreach (var (q, r, seed) in hexes)+ {+ var ctx = new HexTileContext(q, r, new FlatSurface(), seed);+ HexPrototypes.Create("desert_edge").Build(ctx);+ Assert.That(ctx.Placements.Count(p => p.Model == tent), Is.InRange(1, 3), $"{where}: desert_edge ({q},{r}) seed {seed}: tent models");+ }+ }+ Assert.IsNotNull(HexModels.Prefab(tent), "the editor loads the tent from the AssetDatabase");+ Check("editor");+ HexCollectionFigures.PropSource = (_, __, ___) => { };+ try+ {+ Assert.IsTrue(HexCollectionFigures.Streams(tent));+ Check("streamed");+ }+ finally { HexCollectionFigures.PropSource = null; }+ }+static void Step(IEnumerator run, int frames){var stack = new Stack<IEnumerator>();