Vaguely import every tile

This commit is contained in:
2026-11-21 10:33:28 -03:00
parent 04c9511b6c
commit 65865033c1
40 changed files with 71 additions and 9 deletions
+26 -2
View File
@@ -33,6 +33,9 @@ export interface TileType extends TileRules {
// each the bottom of a 1 by 2 opening in its outer wall, facing into the tile. tiles share their outer walls, so
// two tiles meeting at a doorway have it in the same place
doorways: Marker[];
// the doorways it can be attached to another tile by, all of them when left out. a tile that starts with a row of
// structure void, like lethal3's, is only entered there: that row is the wall of the tile it's entered from
entries?: Marker[];
// where a vent can go, facing the way the vent would
vent_spots: Marker[];
}
@@ -70,8 +73,21 @@ export const MAIN_TILE = "dangerous_business:main";
export const TILES: Record<string, TileRules> = {
[MAIN_TILE]: { weight: 0 },
"dangerous_business:2x1catwalk": { weight: 20 },
...looks("hallway", 25),
...looks("hallway_t", 15),
...looks("hallway_lt", 15),
...looks("hallway_rt", 15),
...looks("hallway_x", 15),
...looks("hallway_big_x", 3),
"dangerous_business:hallway_maze": { weight: 1 },
};
// a tile with three looks, name, name2 and name3, each as likely, together as likely as weight
function looks(name: string, weight: number): Record<string, TileRules> {
const rules = { weight: weight / 3 };
return Object.fromEntries(["", "2", "3"].map((look) => [`dangerous_business:${name}${look}`, rules]));
}
// how many times a plan that comes out with fewer rooms than it should is tried again
const PLAN_ATTEMPTS = 10;
@@ -80,11 +96,19 @@ export function tile_type(schematic: Schematic, rules: TileRules): TileType {
schematic.blocks
.filter((block) => schematic.palette[block.i].id === id)
.map(({ i, p: [x, y, z] }) => ({ x, y, z, facing: schematic.palette[i].s?.facing ?? 0 }));
const doorways = markers(DOORWAY);
// a doorway with nothing beside it along the wall is in the row of structure void
const blocks = new Set(schematic.blocks.map((block) => block.p.join()));
const entries = doorways.filter(({ x, y, z, facing }) => {
const [step_x, step_z] = facing % 2 === 0 ? [1, 0] : [0, 1];
return !blocks.has([x - step_x, y, z - step_z].join()) && !blocks.has([x + step_x, y, z + step_z].join());
});
return {
...rules,
id: schematic.id!,
size: schematic.size,
doorways: markers(DOORWAY),
doorways,
entries: entries.length ? entries : undefined,
vent_spots: markers(VENT_SPOT),
};
}
@@ -160,7 +184,7 @@ function try_plan(rng: { next(): number }, types: TileType[], config: InteriorPl
while (pool.size > 0) {
const type = pick(rng, pool);
pool.delete(type);
for (const own of shuffled(rng, type.doorways)) {
for (const own of shuffled(rng, type.entries ?? type.doorways)) {
// turned to face away from the tile it's attached to
const quarters = (doorway.facing + 2 - own.facing + 4) % 4;
const [x, z] = turned(own.x, own.z, quarters);