Mining Cut 3: field kinds, chunk visibility, the chunk query, and TargetRef
- FieldKindData, a catalog document (Q11): a kind's reflectivity per schematic cell and its generation weight. AetheriaStores routes it to the catalog. - AsteroidBeltData.Kind, key 10 (Q16 B). FieldKinds.Assign is the one pick (a weighted choice by a stable hash of the belt's key); FieldKinds.Ensure gives a kindless belt its kind and saves it. ZoneGenerator calls it at generation and Zone calls it on first load, so an old belt is assigned once by the same rule and keeps its kind after later catalog edits. - Zone.ChunkVisibility: Reflector's rule for a chunk -- kind cross-section x area in schematic cells x the light on it. Stored nowhere; a worn chunk dims, a broken one or a kindless belt's is dark. - Zone.ChunksNear: the one chunk query, skipping belts whose annulus cannot reach. AsteroidBelt gains InnerRadius for that skip. - TargetRef: an entity, a chunk, or none, with value equality and no ==. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
a1d27cfc04
commit
d76756fd68
4 changed files with 132 additions and 2 deletions
|
|
@ -5,6 +5,7 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using GameCult.Caching;
|
||||
using MessagePack;
|
||||
using Newtonsoft.Json;
|
||||
|
|
@ -102,6 +103,64 @@ public class AsteroidBeltData : BodyData
|
|||
{
|
||||
[JsonProperty("asteroids"), Key(9)]
|
||||
public Asteroid[] Asteroids;
|
||||
|
||||
// Mining Cut 3 (docs/mining-cut-refresh.md, Q16 B): the belt's field kind, chosen once and saved. Unset on a
|
||||
// belt from before this key existed (MessagePack leaves a missing trailing key at its default); Zone assigns
|
||||
// it on first load through FieldKinds.Ensure, the same function generation uses.
|
||||
[JsonProperty("kind"), Key(10)]
|
||||
public CultRecordRef<FieldKindData> Kind;
|
||||
}
|
||||
|
||||
// Mining Cut 3 (docs/mining-cut-refresh.md, Q11): a kind of debris field, an authored catalog record. A chunk's
|
||||
// reflectivity comes from its field's kind; Cut 5 adds the yield table.
|
||||
[CultDocument("aetheria.fieldkinddata", "1"), MessagePackObject, JsonObject(MemberSerialization.OptIn)]
|
||||
public class FieldKindData
|
||||
{
|
||||
[CultName, JsonProperty("name"), Key(0)]
|
||||
public string Name = "";
|
||||
|
||||
// Reflectivity per schematic cell of chunk area: a chunk reflects CrossSection × its area in cells × the light
|
||||
// on it (Zone.ChunkVisibility), the rule Reflector applies to a hull.
|
||||
[JsonProperty("crossSection"), Key(1)]
|
||||
public float CrossSection;
|
||||
|
||||
// How often generation picks this kind, relative to the others (FieldKinds.Assign). Zero never picks it.
|
||||
[JsonProperty("generationWeight"), Key(2)]
|
||||
public float GenerationWeight = 1;
|
||||
}
|
||||
|
||||
// Mining Cut 3 (Q16 B): the one owner of which kind a belt is.
|
||||
public static class FieldKinds
|
||||
{
|
||||
// A weighted pick among the catalog's kinds, by a stable hash of the belt's key: the same belt and the same
|
||||
// catalog always give the same kind. Kinds are ordered by key so the pick does not depend on store order.
|
||||
// Unset when the catalog has no kind with positive weight.
|
||||
public static CultRecordRef<FieldKindData> Assign(CultRecordKey field, CultCache catalog)
|
||||
{
|
||||
var kinds = catalog.GetAll<FieldKindData>()
|
||||
.Where(kind => kind.GenerationWeight > 0f)
|
||||
.Select(kind => (Key: catalog.RefOf(kind).Key, Weight: kind.GenerationWeight))
|
||||
.OrderBy(kind => kind.Key.Value, StringComparer.Ordinal)
|
||||
.ToArray();
|
||||
if (kinds.Length == 0) return default;
|
||||
|
||||
var pick = field.Value.StableHash() / 4294967296.0 * kinds.Sum(kind => (double) kind.Weight);
|
||||
foreach (var kind in kinds)
|
||||
{
|
||||
if (pick < kind.Weight) return new CultRecordRef<FieldKindData>(kind.Key);
|
||||
pick -= kind.Weight;
|
||||
}
|
||||
return new CultRecordRef<FieldKindData>(kinds[kinds.Length - 1].Key);
|
||||
}
|
||||
|
||||
// Gives a belt with no kind its kind and saves it; a belt that has one keeps it, whatever the catalog now says.
|
||||
// Generation (ZoneGenerator) and first load (Zone) both call this, so there is one assignment rule.
|
||||
public static void Ensure(CultRecordKey field, AsteroidBeltData belt, CultCache cache)
|
||||
{
|
||||
if (belt.Kind.IsSet()) return;
|
||||
belt.Kind = Assign(field, cache);
|
||||
if (belt.Kind.IsSet()) cache.Upsert(belt);
|
||||
}
|
||||
}
|
||||
|
||||
[CultDocument("aetheria.gasgiantdata", "1"), MessagePackObject, JsonObject(MemberSerialization.OptIn)]
|
||||
|
|
|
|||
Loading…
Reference in a new issue