Back to Faultline
SOURCE / PINNED RELEASE

Made of little things.

Faultline

Release
da1ffaa5624c…
Author-recorded commit
60f5f03189db…
License
LICENSE
Author’s source reference
nostr://npub182jczunncwe0jn6frpqwq3e0qjws7yqqnc3auccqv9nte2dnd63scjm4rf/wss%3A%2F%2Fgit.napplet.soy%2F/n-6932b12c78c

Archive hash verified: 5a2e0492417ec4e7…. The source-to-build association is the author’s claim; it has not been independently rebuilt.

src/battlefields.ts
import type { Arena, Box, Vec } from './maps';
import { groundHeight, woodlandTerrain } from './terrain';
export type Material = 'plywood' | 'drywall' | 'brick' | 'glass';
// Fictional game resistance per arena unit, independent of color or architecture.
export const resistance: Record<Material, number> = {
  glass: 0.12,
  drywall: 0.55,
  plywood: 1.15,
  brick: 4.8,
};
function place(
  boxes: Box[],
  x: number,
  y: number,
  z: number,
  w: number,
  h: number,
  d: number,
  color: string,
  extra: Partial<Box> = {},
) {
  boxes.push({ x, y, z, w, h, d, color, solid: true, ...extra });
}
export function office(): Arena {
  const boxes: Box[] = [];
  const box = (
    x: number,
    y: number,
    z: number,
    w: number,
    h: number,
    d: number,
    c: string,
    extra: Partial<Box> = {},
  ) => place(boxes, x, y, z, w, h, d, c, extra);
  box(0, -0.5, 0, 48, 0.5, 48, '#9a9b93');
  for (const sign of [-1, 1]) {
    box(0, 0, sign * 23, 46, 3.8, 0.55, '#a47664', { material: 'brick' });
    box(sign * 23, 0, 0, 0.55, 3.8, 46, '#a47664', { material: 'brick' });
  }
  box(0, 3.75, 0, 46, 0.18, 46, '#d1d0bb', { roof: true });
  const furnishing = { material: 'plywood' as const },
    trim = { solid: false };
  function chair(x: number, z: number, back: number, color: string) {
    box(x, 0.38, z, 0.72, 0.17, 0.72, color, furnishing);
    box(x, 0, z, 0.17, 0.38, 0.17, '#4e5655');
    box(x, 0.54, z + back * 0.32, 0.7, 0.61, 0.11, color, furnishing);
  }
  // A cross corridor with four suites. Each suite has two doors and a glazed meeting room.
  let pane = 1;
  for (const sx of [-1, 1])
    for (const sz of [-1, 1]) {
      for (const [center, length] of [
        [6, 5],
        [17.5, 11],
      ]) {
        box(sx * center, 0, sz * 3.5, length, 3.72, 0.25, '#c2c5af', { material: 'drywall' });
        box(sx * 3.5, 0, sz * center, 0.25, 3.72, length, '#bec1b1', { material: 'drywall' });
      }
      box(sx * 13, 0, sz * 14, 8, 2.9, 0.17, '#b1cfd0', { material: 'glass', pane });
      pane *= 2;
      for (const x of [9, 17]) box(sx * x, 0, sz * 14, 0.12, 3, 0.26, '#525f61');
      box(sx * 13, 2.92, sz * 14, 8, 0.12, 0.26, '#596568');
      box(sx * 15, 0, sz * 8, 4.5, 0.87, 1.35, '#ab936e', { material: 'plywood' });
      box(sx * 19, 0, sz * 18, 2, 1.6, 1, '#87958a', { material: 'plywood' });
      box(sx * 7, 0, sz * 18, 0.2, 1.55, 5, '#a88d65', { material: 'plywood' });
      const accent = sx < 0 ? (sz < 0 ? '#668997' : '#9d765b') : sz < 0 ? '#9c9861' : '#718674';
      box(sx * 15, 1.01, sz * 8, 1.06, 0.6, 0.1, '#38494b', trim);
      box(sx * 15, 0.87, sz * 8, 0.15, 0.18, 0.12, '#454d4c', trim);
      chair(sx * 15, sz * 9.3, sz, accent);
      // Drawer faces and recessed handles distinguish the cabinets from wall panels.
      for (const y of [0.12, 0.58, 1.04]) {
        box(sx * 19, y, sz * 18.51, 1.77, 0.39, 0.03, '#738078', trim);
        box(sx * 19, y + 0.22, sz * 18.55, 0.36, 0.046, 0.06, '#404c48', trim);
      }
      box(sx * 16, 1.4, sz * 3.36, 4.2, 0.42, 0.045, accent, trim);
      box(sx * 13, 0.03, sz * 17, 7.6, 0.025, 4.5, accent, trim);
      if (sx === sz) {
        box(sx * 13, 0.0, sz * 18, 0.38, 0.75, 1.3, '#59625e', furnishing);
        box(sx * 13, 0.75, sz * 18, 3.3, 0.16, 1.7, '#ad9878', furnishing);
        for (const seat of [-1, 1]) chair(sx * 13 + seat * 0.87, sz * 19.3, sz, accent);
      } else {
        box(sx * 20, 0.0, sz * 10, 1.45, 0.48, 4, accent, furnishing);
        box(sx * 20.62, 0.48, sz * 10, 0.21, 0.63, 4, accent, furnishing);
        box(sx * 19, 0.32, sz * 13, 1.1, 0.13, 1.15, '#b39675', furnishing);
      }
      for (const z of [7, 17]) box(sx * 12, 3.66, sz * z, 3.8, 0.08, 0.62, '#f4eaca', { solid: false });
    }
  for (const k of [-18, -9, 0, 9, 18]) {
    box(0, 3.65, k, 1.4, 0.09, 2.8, '#f5ebcd', { solid: false });
    box(k, 3.65, 0, 2.8, 0.09, 1.4, '#f5ebcd', { solid: false });
  }
  box(0, 0.003, 0, 6, 0.015, 45, '#77858a', { solid: false });
  box(0, 0.004, 0, 45, 0.016, 6, '#77858a', { solid: false });
  return {
    name: 'North Annex',
    sector: 'NA–03',
    type: 'Office floor',
    description: 'Office suites, glazed conference rooms and intersecting carpeted corridors.',
    size: 24,
    boxes,
    sky: '#b7c8ce',
    spawns: [
      [-20, -20, 0.78],
      [20, 20, -2.36],
      [-20, 20, 2.36],
      [20, -20, -0.78],
      [0, -19, 0],
      [0, 19, Math.PI],
      [-19, 0, 1.57],
      [19, 0, -1.57],
    ],
    practiceContact: [-13, -13, -2.35],
  };
}
export function woodland(): Arena {
  const size = 52,
    terrain = woodlandTerrain(size),
    boxes: Box[] = [];
  const spawns: Vec[] = [
    [-41, -37, 0.73],
    [41, 37, -2.4],
    [-36, 41, 2.45],
    [36, -41, -0.7],
    [0, -44, 0],
    [0, 44, Math.PI],
    [-43, 0, 1.57],
    [43, 0, -1.57],
  ];
  const practiceContact: Vec = [-33, -28, -2.4];
  place(boxes, 0, -0.8, 0, 104, 0.8, 104, '#71805a');
  for (const s of [-1, 1]) {
    place(boxes, 0, 0, s * size, size * 2, 10, 0.8, '#626d59', { boundary: true });
    place(boxes, s * size, 0, 0, 0.8, 10, size * 2, '#626d59', { boundary: true });
  }
  // Trail fencing marks the perimeter. Beyond it a second tree line continues the skyline.
  for (const s of [-1, 1])
    for (let q = -48; q <= 48; q += 8)
      for (const vertical of [true, false]) {
        const x = vertical ? s * (size - 0.4) : q,
          z = vertical ? q : s * (size - 0.4),
          y = groundHeight(terrain, x, z);
        place(boxes, x, y - 0.15, z, 0.27, 1.55, 0.27, '#685b45', { solid: false });
        place(boxes, x, y + 0.75, z, vertical ? 0.14 : 8, 0.18, vertical ? 8 : 0.14, '#817659', {
          solid: false,
        });
        const tx = x + (vertical ? s * 6 : 0),
          tz = z + (vertical ? 0 : s * 6);
        place(boxes, tx, y - 0.3, tz, 7, 8 + 2 * Math.cos(q), 7, '#536c59', {
          solid: false,
          shape: 'pine',
        });
      }
  let seed = 143;
  const random = () => (seed = (Math.imul(seed, 1664525) + 1013904223) >>> 0) / 4294967296;
  for (let iz = -5; iz <= 5; iz++)
    for (let ix = -5; ix <= 5; ix++) {
      const x = ix * 9 + (random() - 0.5) * 5,
        z = iz * 9 + (random() - 0.5) * 5,
        y = groundHeight(terrain, x, z);
      // Preserve two winding trails, their crossing and clear landings around all spawns.
      if (
        Math.abs(x - 9 * Math.sin(z * 0.066)) < 4 ||
        Math.abs(z + 7 * Math.sin(x * 0.075)) < 4 ||
        [...spawns, practiceContact].some(([a, b]) => Math.hypot(a - x, b - z) < 4)
      )
        continue;
      if (random() < 0.27) {
        const w = 1.9 + random() * 2;
        place(boxes, x, y - 0.45, z, w, w * 0.73, w * 0.86, '#8b9182', { shape: 'stone' });
      } else {
        const h = 5 + random() * 4;
        place(boxes, x, y - 0.3, z, 0.72, h * 0.8, 0.72, '#66533e', { material: 'plywood' });
        for (let n = 0; n < 2; n++)
          place(
            boxes,
            x,
            y + h * (0.22 + n * 0.24),
            z,
            h * (0.61 - n * 0.17),
            h * (0.64 - n * 0.12),
            h * (0.61 - n * 0.17),
            n ? '#49664d' : '#374f41',
            { solid: false, shape: 'pine' },
          );
      }
    }
  return {
    name: 'Alder Ridge',
    sector: 'AR–04',
    type: 'Woodland highlands',
    description: 'Rolling pine ridges, boulder fields and two winding trails.',
    size,
    boxes,
    spawns,
    practiceContact,
    terrain,
    sky: '#abc6c9',
  };
}