RynthSuite as of 2026-10-04 (internal c94715f): RynthOracle (based on Oracle of Dereth by Advis Eveldan) and RynthInventory, RynthAi patrol doorways and rooms, healing priority, strict monster priority, finish the wounded target, slayer weapons, arcs when clear, blasts like rings, learn unknown spells, looting fixes, release 2026.10.4.6

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Tom Bohar 2026-10-04 18:34:29 -04:00
commit 12ca25f911
426 changed files with 108239 additions and 7521 deletions

View file

@ -25,6 +25,17 @@ internal static class NavBake
private const float TiledCellSize = 0.5f;
private const int TiledTileSize = 384; // 384 * 0.5 = 192
/// <summary>--draw-geometry: bake from the drawing meshes like before (for comparisons only).</summary>
public static bool DrawMeshes;
private static CollisionGeometry? _collision;
/// <summary>One CollisionGeometry (and its model caches) per GeometryLoader.</summary>
public static CollisionGeometry Collision(RynthCore2.Raycast.GeometryLoader geo)
{
if (_collision == null || !ReferenceEquals(_collision.Geo, geo)) _collision = new CollisionGeometry(geo);
return _collision;
}
private static RcVec3f AcToRec(double ewX, double nsY, double upZ) => new((float)ewX, (float)upZ, (float)nsY);
private static (double ew, double ns, double up) RecToAc(RcVec3f v) => (v.X, v.Z, v.Y);
@ -49,8 +60,9 @@ internal static class NavBake
else { Tri(sw, se, nw); Tri(se, ne, nw); }
}
if (geo != null)
if (geo != null && DrawMeshes)
{
// The old input (--draw-geometry): the DRAWING polygons of static objects and scatter.
void Append(List<RynthCore2.Raycast.GeometryLoader.TexTri> tris)
{
foreach (var t in tris)
@ -66,20 +78,47 @@ internal static class NavBake
}
catch { }
}
else if (geo != null)
{
// What the game collides with (CollisionGeometry): physics polygons of the static
// objects and building shells, the walls/floors of the buildings' cells and the
// objects in them, and the scenery the server places, each with its real shape.
var cg = Collision(geo);
var tris = new List<CollisionGeometry.Tri>();
CollisionGeometry.Climb = AgentMaxClimb;
try { cg.AppendStatics(lb, tris, (x, y) => TerrainSampler.GetTerrainZ(land, x, y)); } catch { }
try { cg.AppendBuildingCells(lb, tris); } catch { }
try { cg.AppendScenery(lb, land, tris); } catch { }
foreach (var t in tris)
{
if (!Fin(t.A.X, t.A.Y, t.A.Z) || !Fin(t.B.X, t.B.Y, t.B.Z) || !Fin(t.C.X, t.C.Y, t.C.Z)) continue;
if (System.Numerics.Vector3.Cross(t.B - t.A, t.C - t.A).LengthSquared() < 1e-10f) continue; // degenerate
Tri(AddVtx(t.A.X, t.A.Y, t.A.Z), AddVtx(t.B.X, t.B.Y, t.B.Z), AddVtx(t.C.X, t.C.Y, t.C.Z));
}
}
return true;
}
/// <summary>
/// The navmesh's step height. 1 m keeps steep terrain (up to AC's walkable slope) connected at a
/// 0.5 m cell; a character only steps 0.6 m, and CollisionGeometry.RaiseIfLow turns objects
/// between the two into walls. --climb overrides it (tests only).
/// </summary>
public static float AgentMaxClimb = 1.0f;
private static RcNavMeshBuildSettings Settings(float radius, bool tiled, float cellSize)
{
float slopeDeg = (float)(Math.Acos(TerrainSampler.FloorZ) * 180.0 / Math.PI);
return new RcNavMeshBuildSettings
{
cellSize = cellSize, cellHeight = 0.20f,
agentHeight = 2.0f, agentRadius = radius, agentMaxClimb = 1.0f, agentMaxSlope = slopeDeg,
agentHeight = 2.0f, agentRadius = radius, agentMaxClimb = AgentMaxClimb, agentMaxSlope = slopeDeg,
minRegionSize = 8, mergedRegionSize = 20, partitioning = (int)RcPartition.WATERSHED,
filterLowHangingObstacles = true, filterLedgeSpans = true, filterWalkableLowHeightSpans = true,
edgeMaxLen = 12f, edgeMaxError = 1.3f, vertsPerPoly = VertsPerPoly, detailSampleDist = 6f, detailSampleMaxError = 1f,
tiled = tiled, tileSize = tiled ? TiledTileSize : 0, keepInterResults = true, buildAll = true,
// The solo bake reads the intermediate results (the .obj export); the tiled bake only
// needs the finished navmesh, and keeping every tile's heightfields cost 1.5-2.7 GB a chunk.
tiled = tiled, tileSize = tiled ? TiledTileSize : 0, keepInterResults = !tiled, buildAll = true,
};
}
@ -110,9 +149,23 @@ internal static class NavBake
public static void BakeRegionTiled(TerrainSampler sampler, RynthCore2.Raycast.GeometryLoader? geo,
int x0, int x1, int y0, int y1, string outDir, float agentRadius, out int tiles, out int empty)
{
tiles = 0; empty = 0;
BakeRegionTiled(sampler, geo, x0, x1, y0, y1, outDir, agentRadius, null, out tiles, out empty, out _);
}
/// <summary>
/// Tiled bake of x0..x1, y0..y1. <paramref name="keep"/> (optional) picks which
/// landblocks get a tile written (the others are baked as context only).
/// <paramref name="gridOk"/> is false when the chunk's tile grid came out off the
/// landblock grid (its tiles would not link to other chunks).
/// </summary>
public static void BakeRegionTiled(TerrainSampler sampler, RynthCore2.Raycast.GeometryLoader? geo,
int x0, int x1, int y0, int y1, string outDir, float agentRadius, Func<uint, bool>? keep,
out int tiles, out int empty, out bool gridOk, Func<int, int, bool>? gather = null)
{
tiles = 0; empty = 0; gridOk = true;
var verts = new List<float>(); var faces = new List<int>();
int gathered = 0;
int gMinX = 256, gMaxX = -1, gMinY = 256, gMaxY = -1; // landblocks that had terrain
// Gather a 1-landblock BORDER beyond the output rectangle so this chunk's
// edge tiles share geometry context with neighbouring chunks — that makes
// separately-baked chunks reconnect at their seams when both are loaded.
@ -120,10 +173,66 @@ internal static class NavBake
for (int y = y0 - 1; y <= y1 + 1; y++)
{
if (x < 0 || x > 255 || y < 0 || y > 255) continue;
if (AppendLandblock(sampler, geo, (uint)((x << 8) | y), verts, faces)) gathered++;
// gather: optional filter (the world bake leaves out open water that touches
// no landblock it keeps; Recast passes over empty tiles almost for free).
if (gather != null && !gather(x, y)) continue;
if (AppendLandblock(sampler, geo, (uint)((x << 8) | y), verts, faces))
{
gathered++;
gMinX = Math.Min(gMinX, x); gMaxX = Math.Max(gMaxX, x);
gMinY = Math.Min(gMinY, y); gMaxY = Math.Max(gMaxY, y);
}
}
if (gathered == 0) return;
// Pin the tile grid to the landblock grid. Recast lays its tiles out from the
// geometry's minimum corner, and a building or tree poking out past the border
// ring moved that corner by up to ~25 m: every chunk got its own grid offset,
// tiles no longer matched landblocks, and neighbouring chunks never linked at
// their seams. Dropping triangles that leave the gathered box puts the minimum
// corner back on the gathered terrain's corner, a multiple of 192. (The box is
// the landblocks that actually had terrain, so a missing ring column at the
// edge of the map can't leave an object vertex as the minimum.)
float boxMinX = gMinX * 192f, boxMaxX = (gMaxX + 1) * 192f;
float boxMinZ = gMinY * 192f, boxMaxZ = (gMaxY + 1) * 192f;
bool Inside(int v) => verts[v * 3] >= boxMinX && verts[v * 3] <= boxMaxX && verts[v * 3 + 2] >= boxMinZ && verts[v * 3 + 2] <= boxMaxZ;
// The bounds come from every vertex, used or not, so rebuild both lists.
var keptVerts = new List<float>(verts.Count); var keptFaces = new List<int>(faces.Count);
var remap = new Dictionary<int, int>();
int Keep(int v)
{
if (!remap.TryGetValue(v, out int n)) { n = keptVerts.Count / 3; keptVerts.Add(verts[v * 3]); keptVerts.Add(verts[v * 3 + 1]); keptVerts.Add(verts[v * 3 + 2]); remap[v] = n; }
return n;
}
// The ring is context for the chunk's edge tiles only, and Recast reads just
// (agent radius + 3 cells) = 4.5 m past a tile, so only a ContextMargin-wide strip of
// it is rasterized; the rest of the ring was baked into tiles that are thrown away.
// Two unused vertices keep the bounds (and so the grid and the height origin)
// exactly where the whole ring put them.
const float ContextMargin = 24f; // one terrain cell
float cMinX = x0 * 192f - ContextMargin, cMaxX = (x1 + 1) * 192f + ContextMargin;
float cMinZ = y0 * 192f - ContextMargin, cMaxZ = (y1 + 1) * 192f + ContextMargin;
bool NearChunk(int a, int b, int c)
{
float minX = Math.Min(verts[a * 3], Math.Min(verts[b * 3], verts[c * 3])), maxX = Math.Max(verts[a * 3], Math.Max(verts[b * 3], verts[c * 3]));
float minZ = Math.Min(verts[a * 3 + 2], Math.Min(verts[b * 3 + 2], verts[c * 3 + 2])), maxZ = Math.Max(verts[a * 3 + 2], Math.Max(verts[b * 3 + 2], verts[c * 3 + 2]));
return maxX >= cMinX && minX <= cMaxX && maxZ >= cMinZ && minZ <= cMaxZ;
}
float yMin = float.MaxValue, yMax = float.MinValue;
for (int f = 0; f < faces.Count; f += 3)
{
int a = faces[f], b = faces[f + 1], c = faces[f + 2];
if (!(Inside(a) && Inside(b) && Inside(c))) continue;
yMin = Math.Min(yMin, Math.Min(verts[a * 3 + 1], Math.Min(verts[b * 3 + 1], verts[c * 3 + 1])));
yMax = Math.Max(yMax, Math.Max(verts[a * 3 + 1], Math.Max(verts[b * 3 + 1], verts[c * 3 + 1])));
if (!NearChunk(a, b, c)) continue;
keptFaces.Add(Keep(a)); keptFaces.Add(Keep(b)); keptFaces.Add(Keep(c));
}
if (keptFaces.Count == 0) return;
keptVerts.Add(boxMinX); keptVerts.Add(yMin); keptVerts.Add(boxMinZ);
keptVerts.Add(boxMaxX); keptVerts.Add(yMax); keptVerts.Add(boxMaxZ);
verts = keptVerts; faces = keptFaces;
var geom = new RcSampleInputGeomProvider(verts.ToArray(), faces.ToArray());
geom.CalculateNormals();
var settings = Settings(agentRadius, tiled: true, cellSize: TiledCellSize);
@ -134,6 +243,11 @@ internal static class NavBake
RcVec3f bmin = geom.GetMeshBoundsMin();
int baseLbX = (int)Math.Round(bmin.X / 192.0); // Recast x = world EW = lbX*192
int baseLbZ = (int)Math.Round(bmin.Z / 192.0); // Recast z = world NS = lbY*192
if (Math.Abs(bmin.X - baseLbX * 192f) > 0.01f || Math.Abs(bmin.Z - baseLbZ * 192f) > 0.01f)
{
gridOk = false;
Console.WriteLine($" WARNING: grid offset ({bmin.X - baseLbX * 192f:F2}, {bmin.Z - baseLbZ * 192f:F2}) — these tiles won't link to other chunks");
}
for (int i = 0; i < nav.GetMaxTiles(); i++)
{
@ -147,6 +261,7 @@ internal static class NavBake
md.header.x = absLbX; // rewrite to ABSOLUTE landblock coords (world-positioned grid)
md.header.y = absLbY;
uint lb = (uint)((absLbX << 8) | absLbY);
if (keep != null && !keep(lb)) continue;
WriteTile(Path.Combine(outDir, $"nav_{lb:X4}.tile"), md);
tiles++;
}
@ -181,15 +296,21 @@ internal static class NavBake
return $"FindPath {st.Succeeded()} corridor={pc} reaches-0x{lbB:X4}={crosses}";
}
// Written to a .tmp and moved into place, so a bake stopped half way never
// leaves a truncated tile behind (a resumed batch bake trusts tiles on disk).
private static void WriteTile(string path, DtMeshData md)
{
using var fs = File.Create(path);
using var bw = new BinaryWriter(fs);
new DtMeshDataWriter().Write(bw, md, RcByteOrder.LITTLE_ENDIAN, false);
OutputGuard.Check(Path.GetDirectoryName(path)!);
string tmp = path + ".tmp";
using (var fs = File.Create(tmp))
using (var bw = new BinaryWriter(fs))
new DtMeshDataWriter().Write(bw, md, RcByteOrder.LITTLE_ENDIAN, false);
File.Move(tmp, path, overwrite: true);
}
private static void ExportDetailObj(string path, RcPolyMeshDetail d, uint lb)
{
OutputGuard.Check(Path.GetDirectoryName(path)!);
var sb = new StringBuilder();
sb.AppendLine($"# RynthNav detail mesh, landblock 0x{lb:X4}, AC frame (x=EW, y=NS, z=up)");
for (int i = 0; i < d.nverts; i++)