implement basic moderator flux math (unverified)

This commit is contained in:
CodedSakura 2026-08-10 17:12:01 +03:00
parent 617db13cb4
commit 2b542e5f34
5 changed files with 65 additions and 18 deletions

File diff suppressed because one or more lines are too long

View File

@ -39,7 +39,7 @@ registerLoadCallback(() => {
}); });
awaitEvent("config:end").then(() => { awaitEvent("config:end").then(() => {
void loadExampleFile("Pandora's Fission Reactor"); void loadExampleFile("neutron test");
}); });
queueMicrotask(() => emitEvent("dev-mode:end")); queueMicrotask(() => emitEvent("dev-mode:end"));

View File

@ -355,8 +355,14 @@ export function* getCellTooltip(cell) {
if ("nuclearcraft:overhaul_sfr:fuel_stats" in recipe.modules) { if ("nuclearcraft:overhaul_sfr:fuel_stats" in recipe.modules) {
const stats = recipe.modules["nuclearcraft:overhaul_sfr:fuel_stats"]; const stats = recipe.modules["nuclearcraft:overhaul_sfr:fuel_stats"];
if (stats.self_priming) { if (solverMetadata.primer) {
yield "Self-priming"; if (solverMetadata.primer.dom === cell) {
yield "Primed (self-priming)";
} else {
const direction = ["x", "y", "z"].flatMap((d) => solverMetadata.primer[d] !== cell.dataset[d] ? d : [])
.map(d => (Number(cell.dataset[d]) < Number(solverMetadata.primer[d]) ? "+" : "-") + d.toUpperCase())[0];
yield `Primed (${solverMetadata.primer.tile.modules["plannerator:display_name"].display_name}, ${direction})`;
}
} else { } else {
yield "Not primed"; yield "Not primed";
} }
@ -366,7 +372,7 @@ export function* getCellTooltip(cell) {
`Criticality: `, `Criticality: `,
{ {
type: "bold", type: "bold",
text: `0/${stats.criticality}`, text: `${solverMetadata.flux ?? 0}/${stats.criticality}`,
}, },
], ],
}; };

View File

@ -1,4 +1,4 @@
import { emitEvent, listenTo } from "./events.js"; import { awaitEvent, emitEvent, listenTo } from "./events.js";
import { import {
getPlannerCellDom, getPlannerCellDom,
getPlannerCellsDom, getPlannerCellsDom,
@ -7,7 +7,7 @@ import {
getPlannerMultiblockType getPlannerMultiblockType
} from "./planner.js"; } from "./planner.js";
import { checkEquivalence, findFullEntry, findFullEntryFromAtlasMetadata } from "./ncpf-utils.js"; import { checkEquivalence, findFullEntry, findFullEntryFromAtlasMetadata } from "./ncpf-utils.js";
import { getMetadata, setCellMetadata, setDomMetadata } from "./metadata.js"; import { deleteMetadata, getMetadata, setCellMetadata, setDomMetadata } from "./metadata.js";
import { registerLoadCallback } from "./main.js"; import { registerLoadCallback } from "./main.js";
import { getAtlasMetadata } from "./atlas.js"; import { getAtlasMetadata } from "./atlas.js";
import { initialize3dArray } from "./js-utils.js"; import { initialize3dArray } from "./js-utils.js";
@ -36,10 +36,12 @@ export function resetSolver(design = undefined, designConfiguration) {
for (let y = 0; y < design.dimensions[1]; y++) { for (let y = 0; y < design.dimensions[1]; y++) {
for (let z = 0; z < design.dimensions[2]; z++) { for (let z = 0; z < design.dimensions[2]; z++) {
const block = designConfiguration.blocks[design.design[x][y][z]]; const block = designConfiguration.blocks[design.design[x][y][z]];
const cellDom = getPlannerCellDom(x, y, z);
deleteMetadata(cellDom);
if (!block || !block.modules || !block.modules["ncpf:block_recipes"]) continue; if (!block || !block.modules || !block.modules["ncpf:block_recipes"]) continue;
const blockRecipeIndex = designBlockRecipes.shift(); const blockRecipeIndex = designBlockRecipes.shift();
const blockRecipe = block.modules["ncpf:block_recipes"].recipes[blockRecipeIndex]; const blockRecipe = block.modules["ncpf:block_recipes"].recipes[blockRecipeIndex];
setCellMetadata(getPlannerCellDom(x, y, z), "block_recipe", blockRecipe); setCellMetadata(cellDom, "block_recipe", blockRecipe);
} }
} }
} }
@ -49,14 +51,14 @@ export function resetSolver(design = undefined, designConfiguration) {
emitEvent("solver:reset:done"); emitEvent("solver:reset:done");
} }
const sixAxes = [ const sixAxes = {
{x: -1, y: 0, z: 0}, "-X": { x: -1, y: 0, z: 0 },
{x: 0, y: -1, z: 0}, "-Y": { x: 0, y: -1, z: 0 },
{x: 0, y: 0, z: -1}, "-Z": { x: 0, y: 0, z: -1 },
{x: 1, y: 0, z: 0}, "+X": { x: 1, y: 0, z: 0 },
{x: 0, y: 1, z: 0}, "+Y": { x: 0, y: 1, z: 0 },
{x: 0, y: 0, z: 1}, "+Z": { x: 0, y: 0, z: 1 },
] };
function *travelUntil(grid, { x, y, z }, {x: dirX = 0, y: dirY = 0, z: dirZ = 0}, shouldStop = (pos) => false) { function *travelUntil(grid, { x, y, z }, {x: dirX = 0, y: dirY = 0, z: dirZ = 0}, shouldStop = (pos) => false) {
x = Number(x); x = Number(x);
y = Number(y); y = Number(y);
@ -71,7 +73,16 @@ function *travelUntil(grid, { x, y, z }, {x: dirX = 0, y: dirY = 0, z: dirZ = 0}
} }
} }
export function runSolver() { async function debugBlockSolver(data) {
const planner = getPlannerDom();
if (planner.dataset.debugSolver) {
emitEvent("solver:pause", data);
await awaitEvent("solver:continue");
}
}
export async function runSolver() {
emitEvent("solver:begin") emitEvent("solver:begin")
const multiblockType = getPlannerMultiblockType(); const multiblockType = getPlannerMultiblockType();
@ -103,7 +114,7 @@ export function runSolver() {
fuelCells.forEach(cell => { fuelCells.forEach(cell => {
const recipeList = cell.tile.modules["ncpf:block_recipes"].recipes; const recipeList = cell.tile.modules["ncpf:block_recipes"].recipes;
cell.recipe = recipeList.find(r => checkEquivalence(r, cell.metadata.block_recipe)); cell.recipe = recipeList.find(r => checkEquivalence(r, cell.metadata.block_recipe));
cell.axes = sixAxes.map(dir => [...travelUntil( cell.axes = Object.values(sixAxes).map(dir => [...travelUntil(
plannerBlocksGrid, plannerBlocksGrid,
cell, cell,
dir, dir,
@ -118,6 +129,7 @@ export function runSolver() {
if (block.tile.modules) { if (block.tile.modules) {
if (block.tile.modules["nuclearcraft:overhaul_sfr:fuel_cell"]) return true; if (block.tile.modules["nuclearcraft:overhaul_sfr:fuel_cell"]) return true;
if (block.tile.modules["nuclearcraft:overhaul_sfr:reflector"]) return true; if (block.tile.modules["nuclearcraft:overhaul_sfr:reflector"]) return true;
if (block.tile.modules["nuclearcraft:overhaul_sfr:irradiator"]) return true;
} }
return false; return false;
} }
@ -128,7 +140,32 @@ export function runSolver() {
const primerAxis = cell.axes.find(a => (a[a.length - 1]?.tile?.modules ?? {})["nuclearcraft:overhaul_sfr:neutron_source"]); const primerAxis = cell.axes.find(a => (a[a.length - 1]?.tile?.modules ?? {})["nuclearcraft:overhaul_sfr:neutron_source"]);
cell.primer = primerAxis[primerAxis.length - 1]; cell.primer = primerAxis[primerAxis.length - 1];
} }
setCellMetadata(cell.dom, "primer", cell.primer);
});
await debugBlockSolver("primed");
fuelCells.forEach(cell => {
Object.keys(sixAxes).map((name, i) => {
console.log(name, cell.axes[i]);
let moderatorSum = 0;
for (const block of cell.axes[i]) {
if (block.tile.modules["nuclearcraft:overhaul_sfr:moderator"]) {
moderatorSum += block.tile.modules["nuclearcraft:overhaul_sfr:moderator"].flux;
continue;
}
console.log(block);
if (block.tile.modules["nuclearcraft:overhaul_sfr:fuel_cell"] || block.tile.modules["nuclearcraft:overhaul_sfr:irradiator"]) {
block.flux = (block.flux ?? 0) + moderatorSum;
setCellMetadata(block.dom, "flux", block.flux);
}
if (block.tile.modules["nuclearcraft:overhaul_sfr:reflector"]) {
cell.flux = (cell.flux ?? 0) + moderatorSum * 2;
setCellMetadata(cell.dom, "flux", cell.flux);
}
break;
}
});
}); });
console.log(fuelCells);
} }
} }

View File

@ -268,6 +268,9 @@ input:not([type="checkbox"]):not([type="radio"]):not([type="file"]) {
inset: 0; inset: 0;
opacity: var(--overlay-opacity, 0.8); opacity: var(--overlay-opacity, 0.8);
} }
.planner--cell > .planner--overlay[data-overlay="block_recipe"] {
transform: scale(var(--recipe-scale-factor, 0.8));
}
.planner--resize { .planner--resize {
--resize-width: var(--width); --resize-width: var(--width);