CREATURE_FORGE_PLAN Part 5. A third button on the Actors sidebar, beside New agent and New NPC. Pick what it does, how big it is and how bad it is; the card underneath describes what those settings will actually produce, because the argument for a derivation over a form is that it can be interrogated, and choosing between "brute" and "sentinel" from two nouns is not interrogating anything. The card is itself forged rather than written, so it cannot describe a creature the derivation would not make. generateCreature reads the catalogues out of the packs and calls the same forgeCreature the CLI calls. Natural attacks carry their body-plan declarations into flags.ringbrp.plans so the engine can read them. The plan asks that the panel and the CLI cannot diverge, and importing one derivation was most of that guarantee but not all of it: the two feed it from DIFFERENT catalogues — content.mjs on one side, the built compendium on the other. check-forge now builds the engine's view straight out of packs/weapons and requires both to forge the same creature. It found a divergence on its first run, in 40 of 90 pairs. The fallback took the first usable natural attack from the caller's list, and that list arrives in declaration order from content.mjs and in id order from the pack, so a tiny vesh brute was punching for the CLI and constricting at the table. The derivation may not depend on its caller's iteration order; it imposes its own now. Not yet verified in a running Foundry. The pure derivation is covered by 450 guarded combinations and the catalogue seam by the agreement check above, but Actor.create, the pack reads and the dialog itself are the part check-behaviour says outright it cannot reach. They need a world open, and that has not happened yet. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
173 lines
8.6 KiB
JavaScript
173 lines
8.6 KiB
JavaScript
/**
|
||
* Every creature the forge offers to make must be one the game accepts.
|
||
*
|
||
* The forge takes four knobs — role, size, tier, species — and a GM will reach for the
|
||
* combination nobody tried. A derivation that produces an invalid spec at one corner of
|
||
* that space is not a tool, it is a trap, and the corner it fails at is by definition
|
||
* the one nobody looked at.
|
||
*
|
||
* So all of it is derived here, every role × size × tier × species, and each result is
|
||
* put through the same validate() that guards the written bestiary. Four further things
|
||
* are asserted that validate() has no opinion about:
|
||
*
|
||
* - it can fight. A creature with no natural attack is the R-213 defect, made new
|
||
* rather than inherited.
|
||
* - what it fights with, its body can do. A bull that bites because the derivation
|
||
* silently fell back is a real bug this guard found on its first run.
|
||
* - the same seed gives the same creature. `explain` claims to name the rule behind
|
||
* each number; if the numbers are not reproducible that claim is a fiction.
|
||
* - every weapon and skill it names resolves against the catalogues.
|
||
*
|
||
* bun tools/check-forge.mjs
|
||
*/
|
||
import { forgeCreature, SIZE_BANDS, CREATURE_ROLES, FORGE_TIERS } from "../forge.mjs";
|
||
import { validate } from "./creature-schema.mjs";
|
||
import { WEAPONS, SKILL_CATALOGUE } from "./content.mjs";
|
||
import { LOCATION_TABLES } from "../anatomy.mjs";
|
||
import { SPECIES } from "../postings.mjs";
|
||
|
||
const WEAPON_BY_KEY = new Map(WEAPONS.map(w => [w.key, w]));
|
||
const SKILLS = new Set(SKILL_CATALOGUE.map(s => (s[1] ? `${s[0]}:${s[1]}` : s[0])));
|
||
const NATURAL = WEAPONS.filter(w => Array.isArray(w.plans)).map(w => w.key);
|
||
const catalogues = {
|
||
hasWeapon: k => WEAPON_BY_KEY.has(k),
|
||
plansFor: k => WEAPON_BY_KEY.get(k)?.plans ?? null,
|
||
naturalAttacks: NATURAL
|
||
};
|
||
|
||
import path from "node:path";
|
||
import { fileURLToPath } from "node:url";
|
||
const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
|
||
|
||
const problems = [];
|
||
let derived = 0, agreed = 0;
|
||
|
||
for (const role of Object.keys(CREATURE_ROLES)) {
|
||
for (const size of Object.keys(SIZE_BANDS)) {
|
||
for (const tier of Object.keys(FORGE_TIERS)) {
|
||
for (const species of Object.keys(SPECIES)) {
|
||
const where = `${role}/${size}/t${tier}/${species}`;
|
||
const req = { role, size, tier: Number(tier), species, seed: 5, key: `probe_${role}_${size}_${tier}_${species}` };
|
||
const { spec, trace, problems: derivProblems } = forgeCreature(req, catalogues);
|
||
if (derivProblems.length) { problems.push(`${where}: ${derivProblems.join("; ")}`); continue; }
|
||
derived++;
|
||
|
||
for (const p of validate(spec)) {
|
||
problems.push(`${where}: ${p.message ?? JSON.stringify(p)}`);
|
||
}
|
||
if (!spec.weapons.length) {
|
||
problems.push(`${where}: no natural attack — it would stand in the fight with nothing to do`);
|
||
}
|
||
// What it fights with, the body must be able to do — checked against the
|
||
// WEAPON's own declaration, not against any table the forge also reads for its
|
||
// filtering. The first version of this guard read the location table here and
|
||
// then never used it, while the success line claimed the check had been made:
|
||
// deleting the forge's body filter entirely left all 450 rows green.
|
||
if (!LOCATION_TABLES[spec.bodyPlan]) {
|
||
problems.push(`${where}: body plan "${spec.bodyPlan}" has no hit-location table`);
|
||
}
|
||
for (const w of spec.weapons) {
|
||
const plans = WEAPON_BY_KEY.get(w)?.plans;
|
||
if (Array.isArray(plans) && !plans.includes(spec.bodyPlan)) {
|
||
problems.push(`${where}: issued "${w}", which the catalogue says only a `
|
||
+ `${plans.join(" or ")} can make, to a ${spec.bodyPlan}`);
|
||
}
|
||
}
|
||
for (const w of spec.weapons) {
|
||
if (!WEAPON_BY_KEY.has(w)) { problems.push(`${where}: weapon "${w}" is in no catalogue`); continue; }
|
||
const fam = WEAPON_BY_KEY.get(w).fam;
|
||
const spc = WEAPON_BY_KEY.get(w).spec;
|
||
const skillKey = spc ? `${fam}:${spc}` : fam;
|
||
if (!spec.skills.some(s => (s.spec ? `${s.fam}:${s.spec}` : s.fam) === skillKey)) {
|
||
problems.push(`${where}: carries "${w}", which is fired by ${skillKey}, and has no such skill`);
|
||
}
|
||
}
|
||
for (const s of spec.skills) {
|
||
const k = s.spec ? `${s.fam}:${s.spec}` : s.fam;
|
||
if (!SKILLS.has(k)) problems.push(`${where}: skill "${k}" is not in the catalogue`);
|
||
if (!Number.isFinite(s.val) || s.val < 1) problems.push(`${where}: skill "${k}" has value ${s.val}`);
|
||
}
|
||
// Reproducible, or `explain` describes numbers that cannot be made again.
|
||
const again = forgeCreature(req, catalogues).spec;
|
||
if (JSON.stringify(again) !== JSON.stringify(spec)) {
|
||
problems.push(`${where}: the same seed produced a different creature — explain() is describing numbers it cannot reproduce`);
|
||
}
|
||
if (!trace.length) problems.push(`${where}: derived with an empty trace, so nothing can be explained`);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
/* ---- the panel and the CLI must not be able to diverge ----
|
||
*
|
||
* CREATURE_FORGE_PLAN Part 5 asks for an in-Foundry panel that cannot drift away from the
|
||
* command line, and the answer was to put the derivation in one module both import. That
|
||
* is most of the guarantee, and it is not all of it: the two feed that derivation from
|
||
* DIFFERENT catalogues. tools/forge.mjs reads content.mjs; generateCreature reads the
|
||
* built compendium, where `plans` rides in flags.ringbrp and is written by build-packs.
|
||
*
|
||
* So a declaration could be added to content.mjs, never reach the pack, and the table
|
||
* would quietly forge different creatures from the ones the CLI prints — with both sides
|
||
* still importing the same function and the plan's guarantee still apparently intact.
|
||
* This reads the built pack exactly as the engine does and requires the two to agree. */
|
||
{
|
||
const { ClassicLevel } = await import("classic-level");
|
||
const db = new ClassicLevel(path.join(ROOT, "packs", "weapons"), { valueEncoding: "json" });
|
||
await db.open();
|
||
const packed = new Map();
|
||
for await (const [, v] of db.iterator()) {
|
||
const k = v?.flags?.ringbrp?.key;
|
||
if (k) packed.set(k, v.flags.ringbrp.plans ?? null);
|
||
}
|
||
await db.close();
|
||
|
||
const fromPack = {
|
||
hasWeapon: k => packed.has(k),
|
||
plansFor: k => packed.get(k) ?? null,
|
||
naturalAttacks: [...packed].filter(([, p]) => Array.isArray(p)).map(([k]) => k)
|
||
};
|
||
if (!fromPack.naturalAttacks.length) {
|
||
problems.push(`the built weapons pack declares no body plans at all — build-packs is `
|
||
+ `dropping flags.ringbrp.plans, and the table would forge from an empty rule`);
|
||
}
|
||
let compared = 0;
|
||
for (const role of Object.keys(CREATURE_ROLES)) {
|
||
for (const size of Object.keys(SIZE_BANDS)) {
|
||
for (const species of Object.keys(SPECIES)) {
|
||
const req = { role, size, tier: 3, species, seed: 5, key: `agree_${role}_${size}_${species}` };
|
||
const viaSource = forgeCreature(req, catalogues).spec;
|
||
const viaPack = forgeCreature(req, fromPack).spec;
|
||
compared++;
|
||
if (JSON.stringify(viaSource) !== JSON.stringify(viaPack)) {
|
||
problems.push(`${role}/${size}/${species}: the CLI's catalogue and the built pack `
|
||
+ `forge different creatures — weapons ${viaSource?.weapons?.join(",")} vs `
|
||
+ `${viaPack?.weapons?.join(",")}`);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
if (!problems.length) agreed = compared;
|
||
}
|
||
|
||
/* A different seed must give a different creature, or the seed is decorative and every
|
||
forged creature at a tier is the same one wearing a different name. */
|
||
{
|
||
const a = forgeCreature({ role: "hunter", size: "medium", tier: 3, seed: 1 }, catalogues).spec;
|
||
const b = forgeCreature({ role: "hunter", size: "medium", tier: 3, seed: 99 }, catalogues).spec;
|
||
if (JSON.stringify(a.ch) === JSON.stringify(b.ch)) {
|
||
problems.push(`seeds 1 and 99 produced identical characteristics — the seed does nothing`);
|
||
}
|
||
}
|
||
|
||
if (problems.length) {
|
||
console.error(`check-forge: FAILED — ${problems.length} problem(s)`);
|
||
for (const p of problems.slice(0, 30)) console.error(" " + p);
|
||
if (problems.length > 30) console.error(` … and ${problems.length - 30} more`);
|
||
process.exit(1);
|
||
}
|
||
console.log(`check-forge: OK — ${derived} creatures derived across `
|
||
+ `${Object.keys(CREATURE_ROLES).length} roles × ${Object.keys(SIZE_BANDS).length} sizes × `
|
||
+ `${Object.keys(FORGE_TIERS).length} tiers × ${Object.keys(SPECIES).length} species, `
|
||
+ `every one valid, armed with something its body can use, and reproducible from its seed; `
|
||
+ `${agreed} of them forged identically from the built pack and from content.mjs`);
|