Skip to content

Commit

Permalink
refactor strataflux
Browse files Browse the repository at this point in the history
  • Loading branch information
charredUtensil committed Jul 1, 2024
1 parent 5407e5d commit 1493faf
Show file tree
Hide file tree
Showing 12 changed files with 380 additions and 236 deletions.
1 change: 1 addition & 0 deletions src/core/architects/slugs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ const SLUG_HALL: PartialArchitect<unknown> = {
slugSpawnScript: (args) => {
const holes = getSlugHoles(args);
return slugSpawnScript(args, {
emerges: holes.map(([x, y]) => ({x, y, radius: 1})),
initialCooldown: { min: 60, max: 120 },
needCrystals: { base: args.plan.crystals * 2, increment: args.plan.crystals },
triggerPoints: holes,
Expand Down
18 changes: 14 additions & 4 deletions src/core/architects/utils/creature_spawners.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { eventChain, mkVars, scriptFragment, transformPoint } from "./script";

type CreatureSpawnerArgs = {
creature: CreatureTemplate;
emerges?: readonly Emerge[];
initialCooldown?: { min: number; max: number };
maxTriggerCount?: number;
meanWaveSize?: number;
Expand Down Expand Up @@ -36,12 +37,21 @@ const RETRIGGER_MODES = {

export type RetriggerMode = keyof typeof RETRIGGER_MODES;

function getEmerges(plan: Plan, rng: PseudorandomStream, waveSize: number) {
const emerges = plan.path.baseplates.map((bp) => {
type Emerge = {
readonly x: number,
readonly y: number,
readonly radius: number,
};

function getEmerges(plan: Plan): Emerge[] {
return plan.path.baseplates.map((bp) => {
const [x, y] = bp.center;
return { x: Math.floor(x), y: Math.floor(y), radius: bp.pearlRadius };
});
const result: typeof emerges = [];
}

function cycleEmerges(emerges: readonly Emerge[], rng: PseudorandomStream, waveSize: number) {
const result: Emerge[] = [];
while (result.length < waveSize) {
result.push(...rng.shuffle(emerges));
}
Expand Down Expand Up @@ -102,7 +112,7 @@ function creatureSpawnScript(
};

const discoveryPoint = getDiscoveryPoint(cavern, plan);
const emerges = getEmerges(plan, opts.rng, waveSize);
const emerges = cycleEmerges(opts.emerges ?? getEmerges(plan), opts.rng, waveSize);
const triggerPoints = opts.triggerPoints ?? getTriggerPoints(cavern, plan);

const v = mkVars(`p${plan.id}${opts.creature.inspectAbbrev}Spawner`, [
Expand Down
14 changes: 14 additions & 0 deletions src/core/lore/graphs/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,3 +178,17 @@ export const NOMADS_SETTLED = phraseGraph<State>(
.then(end);
},
);

export const FOUND_SLUG_NEST = phraseGraph<State>(
({ pg, state, start, end, cut, skip }) => {
start.then(
"I don't like the look of this.",
"Look at that!",
"Oh, dear.",
"This could be a problem!",
).then(
"It must be a nest of Slimy Slugs!",
"We need to keep these Slimy Slugs at bay.",
)
}
);
227 changes: 0 additions & 227 deletions src/core/transformers/03_plastic/03_strataflux.ts

This file was deleted.

9 changes: 9 additions & 0 deletions src/core/transformers/03_plastic/03_strataflux/base.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export const CORNER_OFFSETS = [
[-1, -1],
[0, -1],
[-1, 0],
[0, 0],
] as const;

export const HEIGHT_MIN = -600;
export const HEIGHT_MAX = 600;
85 changes: 85 additions & 0 deletions src/core/transformers/03_plastic/03_strataflux/corners.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import { Mutable } from "../../../common";
import { NSEW } from "../../../common/geometry";
import { Grid, MutableGrid } from "../../../common/grid";
import { filterTruthy } from "../../../common/utils";
import { StrataformedCavern } from "../02_strataform";
import { HEIGHT_MAX, HEIGHT_MIN } from "./base";
import getEdges from "./edges";

// IDEA: Don't use corners; use HeightNodes which do not have the x and y coord
// Start by finding lakes and assign everywhere in the lake the same HeightNode
// object. This will have some performance benefit, but also it means neighbors
// can be added between non-adjacent corners. As long as the relationship is
// defined symmetrically, there should be no issue with these as the algorithm
// doesn't require the space be Euclidean.

export type Corner = {
readonly target: number | undefined;
readonly x: number;
readonly y: number;
readonly neighbors: readonly {
readonly corner: Corner;
// The maximum upward slope moving from here to the neighbor.
readonly ascent: number;
// The maximum downward slope moving from here to the neighbor.
readonly descent: number;
}[];
collapseQueued: boolean;
min: number;
max: number;
range: number;
};

export default function getCorners(cavern: StrataformedCavern): Grid<Corner> {
const corners = new MutableGrid<Corner>();
for (let x = cavern.left; x <= cavern.right; x++) {
for (let y = cavern.top; y <= cavern.bottom; y++) {
const target = cavern.height.get(x, y);
// Corners on the border are adjusted to a height of 0 when loaded in Manic
// Miners. This means they should be compressed here, but this also gives
// strataflux a starting point for which corners have known heights.
const isBorder = (
x === cavern.left ||
x === cavern.right ||
y === cavern.top ||
y === cavern.bottom
);
corners.set(x, y, {
target,
x,
y,
neighbors: [],
collapseQueued: isBorder,
min: isBorder ? 0 : HEIGHT_MIN,
max: isBorder ? 0 : HEIGHT_MAX,
range: isBorder ? 0 : HEIGHT_MAX - HEIGHT_MIN,
})
}
}
// With the corner objects created, add all neighbors.
const {edgesH, edgesV} = getEdges(cavern);
corners.forEach((corner, x, y) => {
(corner.neighbors as Mutable<Corner['neighbors']>).push(
...filterTruthy(NSEW.map(([ox, oy]) => {
const c = corners.get(x + ox, y + oy);
if (!c) {
return undefined;
}
// Find the edge. Since these are indexed by the minimum, the edges in
// the positive direction are found at [x, y].
const e = (oy === 0 ? edgesH : edgesV).get(
x + Math.min(ox, 0),
y + Math.min(oy, 0),
);
if (!e) {
return undefined;
}
// Determine ascent and descent from the edge slopes.
return (ox + oy < 0)
? {corner: c, ascent: e.backwardSlope, descent: e.forwardSlope}
: {corner: c, ascent: e.forwardSlope, descent: e.backwardSlope};
}))
);
});
return corners;
}
Loading

0 comments on commit 1493faf

Please sign in to comment.