Vents
This commit is contained in:
@@ -1,19 +1,19 @@
|
||||
// SPDX-FileCopyrightText: 2026 Paula Wisnievski
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
// planning dangerous business's facility interior: rooms fitted together at their doorways, made up here so the
|
||||
// tests don't depend on the mod's own rooms
|
||||
// planning dangerous business's facility interior: rooms fitted together at their doorways, with spots for vents in
|
||||
// them. the rooms are made up here so the tests don't depend on the mod's own
|
||||
import { assert, assertEquals } from "@std/assert";
|
||||
import { Alea } from "@paulaboks/rng";
|
||||
import {
|
||||
type Doorway,
|
||||
type InteriorPlan,
|
||||
type Marker,
|
||||
plan_interior,
|
||||
type TileType,
|
||||
} from "../mods/dangerous_business/scripts/interior.ts";
|
||||
|
||||
// a doorway in the middle of each wall of a 9 by 9 room, facing into it
|
||||
const cross: Doorway[] = [
|
||||
const cross: Marker[] = [
|
||||
{ x: 4, y: 1, z: 0, facing: 2 },
|
||||
{ x: 8, y: 1, z: 4, facing: 3 },
|
||||
{ x: 4, y: 1, z: 8, facing: 0 },
|
||||
@@ -21,22 +21,30 @@ const cross: Doorway[] = [
|
||||
];
|
||||
|
||||
const TYPES: TileType[] = [
|
||||
{ id: "test:main", size: [9, 6, 9], doorways: cross, weight: 0 },
|
||||
{ id: "test:hallway", size: [9, 6, 9], doorways: cross, weight: 10 },
|
||||
{ id: "test:main", size: [9, 6, 9], doorways: cross, vent_spots: [], weight: 0 },
|
||||
{ id: "test:hallway", size: [9, 6, 9], doorways: cross, vent_spots: [], weight: 10 },
|
||||
// two cells long, with doorways at one end and along one side
|
||||
{
|
||||
id: "test:long",
|
||||
size: [17, 6, 9],
|
||||
doorways: [{ x: 0, y: 1, z: 4, facing: 1 }, { x: 12, y: 1, z: 0, facing: 2 }],
|
||||
vent_spots: [{ x: 3, y: 5, z: 2, facing: 1 }],
|
||||
weight: 5,
|
||||
},
|
||||
{ id: "test:once", size: [9, 4, 9], doorways: [{ x: 4, y: 1, z: 0, facing: 2 }], weight: 5, one_time: true },
|
||||
{
|
||||
id: "test:once",
|
||||
size: [9, 4, 9],
|
||||
doorways: [{ x: 4, y: 1, z: 0, facing: 2 }],
|
||||
vent_spots: [],
|
||||
weight: 5,
|
||||
one_time: true,
|
||||
},
|
||||
];
|
||||
|
||||
const plan = (seed: string, rooms = 30) =>
|
||||
plan_interior(new Alea(seed), TYPES, { main: "test:main", origin: { x: 100, y: 50, z: -20 }, rooms });
|
||||
|
||||
// where each placed tile is and its doorways in the world, turned like a placed schematic
|
||||
// where each placed tile is and its markers in the world, turned like a placed schematic
|
||||
function placed(plan: InteriorPlan) {
|
||||
return plan.tiles.map(({ tile, position, rotation }) => {
|
||||
const type = TYPES.find((type) => type.id === tile)!;
|
||||
@@ -48,11 +56,11 @@ function placed(plan: InteriorPlan) {
|
||||
const [bx, bz] = turn(type.size[0] - 1, type.size[2] - 1);
|
||||
const min = [Math.min(ax, bx), position.y, Math.min(az, bz)];
|
||||
const max = [Math.max(ax, bx), position.y + type.size[1] - 1, Math.max(az, bz)];
|
||||
const doorways = type.doorways.map((doorway) => {
|
||||
const [x, z] = turn(doorway.x, doorway.z);
|
||||
return { x, y: position.y + doorway.y, z, facing: (doorway.facing + rotation / 90) % 4 };
|
||||
});
|
||||
return { tile, min, max, doorways };
|
||||
const in_world = (marker: Marker) => {
|
||||
const [x, z] = turn(marker.x, marker.z);
|
||||
return { x, y: position.y + marker.y, z, facing: (marker.facing + rotation / 90) % 4 };
|
||||
};
|
||||
return { tile, min, max, doorways: type.doorways.map(in_world), vent_spots: type.vent_spots.map(in_world) };
|
||||
});
|
||||
}
|
||||
|
||||
@@ -106,3 +114,10 @@ Deno.test("a one time room is in an interior once at most", () => {
|
||||
Deno.test("the same seed plans the same interior", () => {
|
||||
assertEquals(plan("same"), plan("same"));
|
||||
});
|
||||
|
||||
Deno.test("vent spots are in the plan where their rooms put them, turned with them", () => {
|
||||
const result = plan("vents");
|
||||
const spots = placed(result).flatMap((tile) => tile.vent_spots);
|
||||
assert(spots.length > 0);
|
||||
assertEquals(result.vent_spots, spots);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user