test: bigger flat quick-test map, TestArea names why it found no area

The suite carves about 55 areas and ran out of open ground on hilly 250x250 maps. While -blaxzonestests is on the map is 325x325 on a flat or small-hills tile; any free colonist can prove reach.
This commit is contained in:
Fabian @ Blax Software 2026-11-29 20:49:47 +01:00
parent b479d55db8
commit 6158aa5ede
2 changed files with 76 additions and 15 deletions

View File

@ -146,6 +146,7 @@ namespace BlaxZonesTests
public static CellRect TestArea(int w, int h) public static CellRect TestArea(int w, int h)
{ {
Map map = Map; Map map = Map;
rejections.Clear();
Rand.PushState(7919 + usedAreas.Count); Rand.PushState(7919 + usedAreas.Count);
try try
{ {
@ -168,43 +169,54 @@ namespace BlaxZonesTests
{ {
Rand.PopState(); 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; return default;
} }
/// <summary>Why TestArea turned candidates down, filled per call and shown when nothing fits.</summary>
private static readonly Dictionary<string, int> rejections = new Dictionary<string, int>();
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) private static bool Usable(Map map, CellRect rect)
{ {
CellRect carved = rect.ExpandedBy(AreaMargin); CellRect carved = rect.ExpandedBy(AreaMargin);
CellRect keepOut = carved.ExpandedBy(3); CellRect keepOut = carved.ExpandedBy(3);
if (!keepOut.InBounds(map)) if (!keepOut.InBounds(map))
return false; return Reject("map edge");
foreach (CellRect used in usedAreas) foreach (CellRect used in usedAreas)
{ {
if (used.ExpandedBy(AreaMargin + 2).Overlaps(keepOut)) if (used.ExpandedBy(AreaMargin + 2).Overlaps(keepOut))
return false; return Reject("earlier area");
} }
foreach (Pawn p in map.mapPawns.AllPawnsSpawned) foreach (Pawn p in map.mapPawns.AllPawnsSpawned)
{ {
if (keepOut.Contains(p.Position)) if (keepOut.Contains(p.Position))
return false; return Reject("pawn");
} }
foreach (Building_OrbitalTradeBeacon b in map.listerBuildings.AllBuildingsColonistOfClass<Building_OrbitalTradeBeacon>()) foreach (Building_OrbitalTradeBeacon b in map.listerBuildings.AllBuildingsColonistOfClass<Building_OrbitalTradeBeacon>())
{ {
if (b.Position.InHorDistOf(carved.CenterCell, 12f + Math.Max(carved.Width, carved.Height) / 2f)) 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) foreach (IntVec3 c in keepOut)
{ {
if (map.zoneManager.ZoneAt(c) != null) if (map.zoneManager.ZoneAt(c) != null)
return false; return Reject("zone");
Building ed = c.GetEdifice(map); Building ed = c.GetEdifice(map);
if (ed != null && (ed.def.building?.isNaturalRock ?? false)) if (ed != null && (ed.def.building?.isNaturalRock ?? false))
return false; return Reject("rock");
RoofDef roof = c.GetRoof(map); RoofDef roof = c.GetRoof(map);
if (roof != null && roof.isThickRoof) if (roof != null && roof.isThickRoof)
return false; return Reject("thick roof");
if (ed != null && ed.Faction == Faction.OfPlayer) 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). // 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) foreach (IntVec3 c in carved)
@ -212,20 +224,26 @@ namespace BlaxZonesTests
foreach (Thing t in c.GetThingList(map)) foreach (Thing t in c.GetThingList(map))
{ {
if (!t.def.destroyable) 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. // A free colonist must reach a standable cell on the ring just outside the carved area.
List<Pawn> 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<Pawn> colonists = map.mapPawns.FreeColonistsSpawned.Where(p => !p.Dead && !p.Downed).ToList();
if (colonists.Count == 0) if (colonists.Count == 0)
return true; return true;
Pawn walker = colonists[0];
foreach (IntVec3 c in carved.ExpandedBy(1).EdgeCells) foreach (IntVec3 c in carved.ExpandedBy(1).EdgeCells)
{ {
if (c.Standable(map) && map.reachability.CanReach(walker.Position, c, PathEndMode.OnCell, TraverseParms.For(TraverseMode.PassDoors))) if (!c.Standable(map))
return true; 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) private static void Carve(Map map, CellRect area)

View File

@ -0,0 +1,43 @@
using HarmonyLib;
using RimWorld.Planet;
using Verse;
namespace BlaxZonesTests
{
/// <summary>
/// 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.
/// </summary>
[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;
}
}
}