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
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+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);
+21 -7
View File
@@ -2,7 +2,7 @@ import type { ClientContext, Color } from "cubi/client";
import type { ServerContext } from "cubi/server";
import { DOOR, FACILITY_DOOR } from "./shared.ts";
import { Alea } from "@paulaboks/rng";
import { MAIN_TILE, type Marker, type PlacedTile, plan_interior, tile_type, TILES } from "./interior.ts";
import { DOORWAY, MAIN_TILE, type Marker, type PlacedTile, plan_interior, tile_type, TILES } from "./interior.ts";
export { shared } from "./shared.ts";
@@ -148,7 +148,7 @@ const INTERIOR_ORIGIN = { x: 0, y: 60, z: 0 };
// how likely a doorway between two rooms is to get a door, otherwise it's left open
const DOOR_CHANCE = 0.8;
const INTERIOR_DOOR = "dangerous_business:factory_door";
const DOORWAY_WALL = "dangerous_business:sheet_wall";
const DOORWAY_WALL = "dangerous_business:concrete_brick_wall";
// how likely a vent spot is to get a vent, otherwise it's left empty
const VENT_CHANCE = 0.65;
const VENT = "dangerous_business:vent";
@@ -168,13 +168,12 @@ function generate_interior(ctx: ServerContext, config: InteriorGenerationConfig)
ctx.schematics.place(tile, { position, rotation });
}
for (const { x, y, z, facing, connected } of plan.doorways) {
if (!connected) {
ctx.world.set_block(x, y, z, DOORWAY_WALL);
ctx.world.set_block(x, y + 1, z, DOORWAY_WALL);
} else if (rng.next() < DOOR_CHANCE) {
const door = connected && rng.next() < DOOR_CHANCE;
if (!connected || door) wall_off_doorway(ctx, x, y, z, facing, door);
if (door) {
ctx.world.set_block(x, y, z, INTERIOR_DOOR, { facing, half: 0 });
ctx.world.set_block(x, y + 1, z, INTERIOR_DOOR, { facing, half: 1 });
} else {
} else if (connected) {
ctx.world.set_block(x, y, z, "cubi:air");
}
}
@@ -189,3 +188,18 @@ function generate_interior(ctx: ServerContext, config: InteriorGenerationConfig)
}
interior_tiles = plan.tiles;
}
// fills the opening a doorway is in, 3 wide and 4 tall like lethal3's or 1 by 2, leaving the doorway itself when a
// door goes there. only air and the doorway are filled, so the wall around a smaller opening stays as it is
function wall_off_doorway(ctx: ServerContext, x: number, y: number, z: number, facing: number, door: boolean) {
// along the wall
const [step_x, step_z] = facing % 2 === 0 ? [1, 0] : [0, 1];
for (let side = -1; side <= 1; side++) {
for (let up = 0; up < 4; up++) {
if (door && side === 0 && up < 2) continue;
const [at_x, at_y, at_z] = [x + side * step_x, y + up, z + side * step_z];
const id = ctx.world.get_block(at_x, at_y, at_z);
if (id === "cubi:air" || id === DOORWAY) ctx.world.set_block(at_x, at_y, at_z, DOORWAY_WALL);
}
}
}
+24
View File
@@ -121,3 +121,27 @@ Deno.test("vent spots are in the plan where their rooms put them, turned with th
assert(spots.length > 0);
assertEquals(result.vent_spots, spots);
});
Deno.test("a room with entries is only attached to another by them", () => {
const types: TileType[] = [
{ id: "test:main", size: [9, 6, 9], doorways: cross, vent_spots: [], weight: 0 },
{ id: "test:hallway", size: [9, 6, 9], doorways: cross, entries: [cross[0]], vent_spots: [], weight: 1 },
];
for (const seed of ["a", "b", "c"]) {
const result = plan_interior(new Alea(seed), types, {
main: "test:main",
origin: { x: 0, y: 0, z: 0 },
rooms: 20,
});
const connected = new Set(result.doorways.filter((d) => d.connected).map(({ x, y, z }) => `${x},${y},${z}`));
for (const { tile, position, rotation } of result.tiles.slice(1)) {
// the entry, the north doorway, where it is once the hallway is turned
let [x, z] = [cross[0].x, cross[0].z];
for (let i = 0; i < rotation / 90; i++) [x, z] = [-z, x];
assert(
connected.has(`${position.x + x},${position.y + cross[0].y},${position.z + z}`),
`${tile} at ${seed}`,
);
}
}
});