diff --git a/Tests/BlaxZonesTests/Source/Fixtures.cs b/Tests/BlaxZonesTests/Source/Fixtures.cs
index 1e668d1..d9d2c58 100644
--- a/Tests/BlaxZonesTests/Source/Fixtures.cs
+++ b/Tests/BlaxZonesTests/Source/Fixtures.cs
@@ -146,6 +146,7 @@ namespace BlaxZonesTests
public static CellRect TestArea(int w, int h)
{
Map map = Map;
+ rejections.Clear();
Rand.PushState(7919 + usedAreas.Count);
try
{
@@ -168,43 +169,54 @@ namespace BlaxZonesTests
{
Rand.PopState();
}
- T.Fail("TestArea: no free " + w + "x" + h + " area on this map");
+ T.Fail("TestArea: no free " + w + "x" + h + " area on this map (" + map.Size.x + "x" + map.Size.z + ", " + usedAreas.Count
+ + " areas handed out; rejected: " + string.Join(", ", rejections.OrderByDescending(kv => kv.Value).Select(kv => kv.Key + " " + kv.Value)) + ")");
return default;
}
+ /// Why TestArea turned candidates down, filled per call and shown when nothing fits.
+ private static readonly Dictionary rejections = new Dictionary();
+
+ private static bool Reject(string reason)
+ {
+ rejections.TryGetValue(reason, out int n);
+ rejections[reason] = n + 1;
+ return false;
+ }
+
private static bool Usable(Map map, CellRect rect)
{
CellRect carved = rect.ExpandedBy(AreaMargin);
CellRect keepOut = carved.ExpandedBy(3);
if (!keepOut.InBounds(map))
- return false;
+ return Reject("map edge");
foreach (CellRect used in usedAreas)
{
if (used.ExpandedBy(AreaMargin + 2).Overlaps(keepOut))
- return false;
+ return Reject("earlier area");
}
foreach (Pawn p in map.mapPawns.AllPawnsSpawned)
{
if (keepOut.Contains(p.Position))
- return false;
+ return Reject("pawn");
}
foreach (Building_OrbitalTradeBeacon b in map.listerBuildings.AllBuildingsColonistOfClass())
{
if (b.Position.InHorDistOf(carved.CenterCell, 12f + Math.Max(carved.Width, carved.Height) / 2f))
- return false;
+ return Reject("trade beacon");
}
foreach (IntVec3 c in keepOut)
{
if (map.zoneManager.ZoneAt(c) != null)
- return false;
+ return Reject("zone");
Building ed = c.GetEdifice(map);
if (ed != null && (ed.def.building?.isNaturalRock ?? false))
- return false;
+ return Reject("rock");
RoofDef roof = c.GetRoof(map);
if (roof != null && roof.isThickRoof)
- return false;
+ return Reject("thick roof");
if (ed != null && ed.Faction == Faction.OfPlayer)
- return false;
+ return Reject("player building");
}
// Carve can't remove a steam geyser or any other non-destroyable thing (Thing.cs:1045-1048 logs an error).
foreach (IntVec3 c in carved)
@@ -212,20 +224,26 @@ namespace BlaxZonesTests
foreach (Thing t in c.GetThingList(map))
{
if (!t.def.destroyable)
- return false;
+ return Reject("undestroyable thing");
}
}
// A free colonist must reach a standable cell on the ring just outside the carved area.
- List colonists = map.mapPawns.FreeColonistsSpawned.ToList();
+ // Any free colonist counts: one may stand in an earlier test's walled-off area, which would
+ // otherwise make every candidate on the map fail.
+ List colonists = map.mapPawns.FreeColonistsSpawned.Where(p => !p.Dead && !p.Downed).ToList();
if (colonists.Count == 0)
return true;
- Pawn walker = colonists[0];
foreach (IntVec3 c in carved.ExpandedBy(1).EdgeCells)
{
- if (c.Standable(map) && map.reachability.CanReach(walker.Position, c, PathEndMode.OnCell, TraverseParms.For(TraverseMode.PassDoors)))
- return true;
+ if (!c.Standable(map))
+ continue;
+ foreach (Pawn walker in colonists)
+ {
+ if (map.reachability.CanReach(walker.Position, c, PathEndMode.OnCell, TraverseParms.For(TraverseMode.PassDoors)))
+ return true;
+ }
}
- return false;
+ return Reject("no colonist can walk there");
}
private static void Carve(Map map, CellRect area)
diff --git a/Tests/BlaxZonesTests/Source/QuickTestMap.cs b/Tests/BlaxZonesTests/Source/QuickTestMap.cs
new file mode 100644
index 0000000..634db3c
--- /dev/null
+++ b/Tests/BlaxZonesTests/Source/QuickTestMap.cs
@@ -0,0 +1,43 @@
+using HarmonyLib;
+using RimWorld.Planet;
+using Verse;
+
+namespace BlaxZonesTests
+{
+ ///
+ /// The suite hands out about 55 carved test areas, each with clearance around it. The vanilla quick
+ /// test picks a random tile at 250x250 (Root_Play.cs:94-96), and a hilly or mountainous tile then runs
+ /// out of open ground halfway through the suite (seen 2026-11-29: 55 areas handed out, 574 candidates
+ /// rejected for rock). While -blaxzonestests is on, the quick-test map is 325x325 on a flat or
+ /// small-hills tile. The tile and every position on it still vary per run.
+ ///
+ [StaticConstructorOnStartup]
+ public static class QuickTestMap
+ {
+ public const int MapSize = 325;
+ private const int TileAttempts = 200;
+
+ static QuickTestMap()
+ {
+ if (!TestRunner.Enabled)
+ return;
+ new Harmony("blax.zones.tests.quicktestmap").Patch(
+ AccessTools.Method(typeof(Root_Play), nameof(Root_Play.SetupForQuickTestPlay)),
+ postfix: new HarmonyMethod(typeof(QuickTestMap), nameof(Postfix)));
+ }
+
+ public static void Postfix()
+ {
+ GameInitData init = Find.GameInitData;
+ init.mapSize = MapSize;
+ for (int i = 0; i < TileAttempts && !Open(init.startingTile); i++)
+ init.startingTile = TileFinder.RandomStartingTile();
+ }
+
+ private static bool Open(PlanetTile tile)
+ {
+ Hilliness h = Find.WorldGrid[tile].hilliness;
+ return h == Hilliness.Flat || h == Hilliness.SmallHills;
+ }
+ }
+}