@wildshard/shard-format 0.51.0 → 0.53.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wildshard/shard-format",
3
- "version": "0.51.0",
3
+ "version": "0.53.0",
4
4
  "description": "The raw shardfile format: the spec, the validator and a validate CLI. The public, versioned contract every other repo builds on.",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {
@@ -422,6 +422,8 @@
422
422
  "./worldSceneWeld": "./src/format/worldSceneWeld.ts",
423
423
  "./worldScenes": "./src/format/worldScenes.ts",
424
424
  "./worldTargets": "./src/format/worldTargets.ts",
425
+ "./vehicles": "./src/format/vehicles.ts",
426
+ "./vehicle-lift": "./src/format/vehicle-lift.ts",
425
427
  "./worldUpdates": "./src/format/worldUpdates.ts",
426
428
  "./incomingCapPolicy": "./src/format/incoming-cap-policy.ts",
427
429
  "./strikeDebris": "./src/format/strike-debris.ts",
@@ -1,6 +1,6 @@
1
1
  import type { ShardEntryways } from './entryways.ts';
2
2
  import type { ShardProps } from './props.ts';
3
- import { propHullBounds } from './prop-hull.ts';
3
+ import { propCapsuleBounds, propHullBounds } from './prop-hull.ts';
4
4
  import type { ShardWater } from './water.ts';
5
5
  import { entryFootprints, clipEntryPolygon, obstructsEntry, type EntryVertex, type EntryFootprint } from './entryGeometry.ts';
6
6
  import { PropExtent, visitGlbTriangles } from './shardfile-assets.ts';
@@ -53,6 +53,7 @@ export function validateEntrywayClearance(source: { entryways: ShardEntryways; p
53
53
  for (const row of props.colliders) for (const shape of row.shapes) {
54
54
  if (shape.kind === 'box') boxTriangles(shape, inspect);
55
55
  else if (shape.kind === 'hull') { boxTriangles(propHullBounds(shape), inspect); }
56
+ else if (shape.kind === 'capsule') { boxTriangles(propCapsuleBounds(shape), inspect); }
56
57
  else {
57
58
  const dx = shape.to.x - shape.from.x, dz = shape.to.z - shape.from.z, run = Math.hypot(dx, dz) / shape.count, rise = (shape.to.y - shape.from.y) / shape.count;
58
59
  for (let i = 0; i < shape.count; i++) {
@@ -22,7 +22,7 @@ function boxTop(box: Box): EntryVertex[][] {
22
22
  function staticTops(rows: readonly ShardProps['colliders'][number][]): EntryVertex[][] {
23
23
  return rows.flatMap(row => row.shapes.flatMap(shape => {
24
24
  if (shape.kind === 'box') return boxTop(shape);
25
- if (shape.kind === 'hull') { return []; }
25
+ if (shape.kind === 'hull' || shape.kind === 'capsule') { return []; }
26
26
  const dx = shape.to.x - shape.from.x, dz = shape.to.z - shape.from.z, run = Math.hypot(dx, dz) / shape.count, rise = (shape.to.y - shape.from.y) / shape.count;
27
27
  return Array.from({ length: shape.count }, (_unused, i) => {
28
28
  const f = (i + 0.5) / shape.count, hy = Math.max(0.01, rise * (i + 1) / 2);
@@ -79,6 +79,7 @@ const DATA_SECTION_NAMES: Readonly<Record<keyof PlatformDataSections, true>> = {
79
79
  "world/targets": true,
80
80
  "world/scenes": true,
81
81
  "world/trees": true,
82
+ "world/vehicles": true,
82
83
  };
83
84
  /** Exact public platform names; schema implementations stay on the checked side. */
84
85
  export function isPlatformDataSection(name: string): name is keyof PlatformDataSections {
@@ -30,6 +30,8 @@ import { WorldMoversSchema } from './movers.ts';
30
30
  import { ReturnModulesSchema, type ReturnModuleRow, ViewModulesSchema, type ViewModuleRow } from './scriptContract.ts';
31
31
  import { NativeRuntimePlanSchema, type NativeRuntimePlanData } from './nativeRuntimePlan.ts';
32
32
  import { TreeSetSchema, type TreeSetRows } from './treeSetRows.ts';
33
+ import { VehiclesSchema } from './vehicles.ts';
34
+ import type { Vehicles } from './vehicles.ts';
33
35
 
34
36
  /** New plain-value sections supplement the unchanged v1 model assembled from the older section envelopes. */
35
37
  export interface PlatformDataSections {
@@ -64,6 +66,7 @@ export interface PlatformDataSections {
64
66
  'world/targets': WorldTargets;
65
67
  'world/scenes': WorldScenesSection;
66
68
  'world/trees': TreeSetRows;
69
+ 'world/vehicles': Vehicles;
67
70
  }
68
71
 
69
72
  /** Defining parsers for the first independently authored platform sections. */
@@ -99,6 +102,7 @@ export const PLATFORM_DATA_SECTIONS: Readonly<{ [Name in keyof PlatformDataSecti
99
102
  'world/targets': { schema: WorldTargetsSchema },
100
103
  'world/scenes': { schema: WorldScenesSchema },
101
104
  'world/trees': { schema: TreeSetSchema },
105
+ 'world/vehicles': { schema: VehiclesSchema },
102
106
  } as const;
103
107
 
104
108
  /** Client feature inputs that remain legacy root envelopes. These defining
@@ -155,4 +155,57 @@ function propHullBounds(shape: HullPose): HullBounds {
155
155
  }
156
156
  }
157
157
 
158
- export { propHullBounds, solidHullWithinCell }
158
+ type CapsulePose = Readonly<GlbVertex> & {
159
+ readonly halfHeight: number
160
+ readonly radius: number
161
+ readonly yaw?: number | undefined
162
+ readonly rot?: (Readonly<GlbVertex> & { readonly w: number }) | undefined
163
+ }
164
+ const BELOW = -1
165
+ const ABOVE = 1
166
+ const SIGNS = [BELOW, ABOVE] as const
167
+
168
+ /** OF22a3: a capsule's local bounding box corners, posed as the capsule is. */
169
+ function capsuleCorners(shape: CapsulePose): number[] {
170
+ const across = shape.radius
171
+ const along = shape.halfHeight + shape.radius
172
+ return SIGNS.flatMap((sx: number): number[] =>
173
+ SIGNS.flatMap((sy: number): number[] =>
174
+ SIGNS.flatMap((sz: number): number[] => [
175
+ sx * across,
176
+ sy * along,
177
+ sz * across,
178
+ ]),
179
+ ),
180
+ )
181
+ }
182
+
183
+ /** A conservative clearance envelope for the posed capsule. */
184
+ function propCapsuleBounds(shape: CapsulePose): HullBounds {
185
+ return propHullBounds({ ...shape, points: capsuleCorners(shape) })
186
+ }
187
+
188
+ /** OF22a3: both posed end caps, swollen by the radius, stay inside the cell. */
189
+ function solidCapsuleWithinCell(shape: CapsulePose): boolean {
190
+ const ends = pointsInWorld({
191
+ ...shape,
192
+ points: [ZERO, -shape.halfHeight, ZERO, ZERO, shape.halfHeight, ZERO],
193
+ })
194
+ return (
195
+ ends.length === SIGNS.length &&
196
+ ends.every(
197
+ (end: Readonly<GlbVertex>): boolean =>
198
+ Math.abs(end.x) + shape.radius <= CELL_HALF_WIDTH &&
199
+ Math.abs(end.z) + shape.radius <= CELL_HALF_WIDTH &&
200
+ end.y - shape.radius >= -CELL_BELOW &&
201
+ end.y + shape.radius <= CELL_ABOVE,
202
+ )
203
+ )
204
+ }
205
+
206
+ export {
207
+ propCapsuleBounds,
208
+ propHullBounds,
209
+ solidCapsuleWithinCell,
210
+ solidHullWithinCell,
211
+ }
@@ -4,7 +4,7 @@ import { isJsonData } from './json.ts';
4
4
  import { PropMaterialsSchema, propMaterialTextureRefs, validatePropMaterials } from './propMaterials.ts';
5
5
  import { SplatTerrainSchema, validateSplatTerrain } from './splatTerrain.ts';
6
6
  import { glbPoint, glbTransform } from './glbTriangles.ts';
7
- import { solidHullWithinCell } from './prop-hull.ts';
7
+ import { solidCapsuleWithinCell, solidHullWithinCell } from './prop-hull.ts';
8
8
  import type { GlbVertex } from './glbTriangles.ts';
9
9
 
10
10
  const ref = v.pipe(v.string(), v.regex(/^[a-f0-9]{64}$/u));
@@ -16,9 +16,18 @@ const height = v.pipe(v.number(), v.finite(), v.minValue(-CELL_BELOW), v.maxValu
16
16
  const finite = v.pipe(v.number(), v.finite());
17
17
  const extent = v.pipe(finite, v.minValue(0.005), v.maxValue(250));
18
18
  const point = v.strictObject({ x: coord, y: height, z: coord });
19
- const surface = v.optional(v.picklist(['wood', 'stone', 'grass', 'sand', 'rock', 'metal', 'earth', 'felt']));
19
+ /** OF22a3: a static solid's material is any engine contact material a bake tags (`planks`, `ground`, `flesh`, `shell` beside the body materials). */
20
+ const SURFACES = ['wood', 'stone', 'grass', 'sand', 'rock', 'metal', 'earth', 'felt', 'planks', 'ground', 'flesh', 'shell'] as const;
21
+ type PropSurface = typeof SURFACES[number];
22
+ const surface = v.optional(v.picklist(SURFACES));
23
+ const CONTACT_LEAST = 0;
24
+ const CONTACT_FRICTION_MAX = 2;
25
+ const GROUPS_MAX = 0xFF_FF_FF_FF;
26
+ /** OF22a3: a baked solid's own contact: its friction, and its Rapier interaction groups (membership high 16 bits, filter low 16). */
27
+ const contact = { friction: v.optional(v.pipe(v.number(), v.finite(), v.minValue(CONTACT_LEAST), v.maxValue(CONTACT_FRICTION_MAX))),
28
+ groups: v.optional(v.pipe(v.number(), v.integer(), v.minValue(CONTACT_LEAST), v.maxValue(GROUPS_MAX))) };
20
29
  const rotation = v.pipe(v.strictObject({ x: finite, y: finite, z: finite, w: finite }), v.check((q) => Math.abs(q.x ** 2 + q.y ** 2 + q.z ** 2 + q.w ** 2 - 1) < 1e-5, 'unit collider rotation'));
21
- const boxData = v.strictObject({ kind: v.literal('box'), x: coord, y: height, z: coord, hx: extent, hy: extent, hz: extent, yaw: v.optional(finite), rot: v.optional(rotation), surface });
30
+ const boxData = v.strictObject({ kind: v.literal('box'), x: coord, y: height, z: coord, hx: extent, hy: extent, hz: extent, yaw: v.optional(finite), rot: v.optional(rotation), surface, ...contact });
22
31
  function boxWithinCell(b: v.InferOutput<typeof boxData>): boolean {
23
32
  const q = b.rot ?? { x: 0, y: Math.sin((b.yaw ?? 0) / 2), z: 0, w: Math.cos((b.yaw ?? 0) / 2) };
24
33
  const transform = glbTransform({ translation: [b.x, b.y, b.z], rotation: [q.x, q.y, q.z, q.w] });
@@ -33,19 +42,27 @@ interface PropHull extends GlbVertex {
33
42
  yaw?: number | undefined;
34
43
  // oxlint-disable-next-line eslint/id-length -- Quaternion components are part of the wire.
35
44
  rot?: (GlbVertex & { w: number }) | undefined;
36
- surface?: 'wood' | 'stone' | 'grass' | 'sand' | 'rock' | 'metal' | 'earth' | 'felt' | undefined;
45
+ surface?: PropSurface | undefined;
46
+ friction?: number | undefined;
47
+ groups?: number | undefined;
37
48
  }
38
49
  const MIN_HULL_COORDS = 12;
39
- const MAX_HULL_COORDS = 192;
50
+ /** OF22a3: up to 256 points, the largest hull a bake keeps (Driftwood's is 168). */
51
+ const MAX_HULL_COORDS = 768;
40
52
  const AXES_PER_VERTEX = 3;
41
53
  const COLLIDER_UNIT = 1;
42
54
  const hullPoints = v.pipe(v.array(finite), v.minLength(MIN_HULL_COORDS), v.maxLength(MAX_HULL_COORDS));
43
55
  // oxlint-disable-next-line eslint/id-length -- A hull has the same cell-local pose as a prop box.
44
56
  const hullData = v.strictObject({ kind: v.literal('hull'), x: coord, y: height, z: coord, points: hullPoints,
45
- yaw: v.optional(finite), rot: v.optional(rotation), surface });
57
+ yaw: v.optional(finite), rot: v.optional(rotation), surface, ...contact });
46
58
  const hull = v.pipe(hullData, v.check<v.InferOutput<typeof hullData>, string>(solidHullWithinCell, 'solid hull within cell'));
47
- const treads = v.pipe(v.strictObject({ kind: v.literal('treads'), from: point, to: point, width: extent, count: v.pipe(v.number(), v.integer(), v.minValue(1), v.maxValue(256)), surface }), v.check((t) => Math.hypot(t.to.x - t.from.x, t.to.z - t.from.z) > 0 && t.to.y >= t.from.y && [t.from, t.to].every((p) => Math.abs(p.x) + t.width / 2 <= 250 && Math.abs(p.z) + t.width / 2 <= 250), 'bounded nondegenerate stair'));
48
- const collider = v.strictObject({ id, panel: v.nullable(id), initialActive: v.boolean(), shapes: v.pipe(v.array(v.variant('kind', [box, treads, hull])), v.minLength(1), v.maxLength(256)) });
59
+ const treads = v.pipe(v.strictObject({ kind: v.literal('treads'), from: point, to: point, width: extent, count: v.pipe(v.number(), v.integer(), v.minValue(1), v.maxValue(256)), surface, ...contact }), v.check((t) => Math.hypot(t.to.x - t.from.x, t.to.z - t.from.z) > 0 && t.to.y >= t.from.y && [t.from, t.to].every((p) => Math.abs(p.x) + t.width / 2 <= 250 && Math.abs(p.z) + t.width / 2 <= 250), 'bounded nondegenerate stair'));
60
+ /** OF22a3: an upright capsule (or turned by `yaw`/`rot`): the straight part's half height and the radius, whole inside the cell. */
61
+ // oxlint-disable-next-line eslint/id-length -- A capsule has the same cell-local pose as a prop box.
62
+ const capsuleData = v.strictObject({ kind: v.literal('capsule'), x: coord, y: height, z: coord, halfHeight: extent, radius: extent,
63
+ yaw: v.optional(finite), rot: v.optional(rotation), surface, ...contact });
64
+ const capsule = v.pipe(capsuleData, v.check<v.InferOutput<typeof capsuleData>, string>(solidCapsuleWithinCell, 'capsule within cell'));
65
+ const collider = v.strictObject({ id, panel: v.nullable(id), initialActive: v.boolean(), shapes: v.pipe(v.array(v.variant('kind', [box, treads, hull, capsule])), v.minLength(1), v.maxLength(256)) });
49
66
  const BODY_EXTENT_MIN = 0.005;
50
67
  const BODY_EXTENT_MAX = 8;
51
68
  const BODY_DENSITY_MIN = 1;
@@ -81,8 +98,9 @@ function bodiesAdmitted(section: { readonly bodies?: readonly { readonly id: str
81
98
  const owned = new Set(rows.map((row): string => row.panel));
82
99
  return ids.size === rows.length && owned.size === rows.length && rows.every((row): boolean => declared.has(row.panel) && !claimed.has(row.panel));
83
100
  }
84
- type CostedShape = Readonly<{ kind: 'treads'; count: number }> | Readonly<{ kind: 'hull'; points: readonly number[] }> | Readonly<{ kind: 'box' }>;
85
- const COLLIDER_BUDGET = 2048;
101
+ type CostedShape = Readonly<{ kind: 'treads'; count: number }> | Readonly<{ kind: 'hull'; points: readonly number[] }> | Readonly<{ kind: 'box' | 'capsule' }>;
102
+ /** OF22a3: a baked island's solids (Driftwood: about 13,500 units, which its native bake admits today) fit; a hull point costs one unit. */
103
+ const COLLIDER_BUDGET = 16_384;
86
104
  function withinColliderBudget(rows: readonly Readonly<{ shapes: readonly CostedShape[] }>[]): boolean {
87
105
  let total = 0;
88
106
  for (const row of rows) {
@@ -179,8 +197,10 @@ interface PropsDataFields {
179
197
  z: number;
180
198
  w: number;
181
199
  } | undefined;
182
- surface?: 'wood' | 'stone' | 'grass' | 'sand' | 'rock' | 'metal' | 'earth' | 'felt' | undefined;
183
- }) | PropHull | ({
200
+ surface?: PropSurface | undefined;
201
+ friction?: number | undefined;
202
+ groups?: number | undefined;
203
+ }) | PropHull | PropCapsule | ({
184
204
  kind: 'treads';
185
205
  from: {
186
206
  x: number;
@@ -194,7 +214,9 @@ interface PropsDataFields {
194
214
  };
195
215
  width: number;
196
216
  count: number;
197
- surface?: 'wood' | 'stone' | 'grass' | 'sand' | 'rock' | 'metal' | 'earth' | 'felt' | undefined;
217
+ surface?: PropSurface | undefined;
218
+ friction?: number | undefined;
219
+ groups?: number | undefined;
198
220
  }))[];
199
221
  })[];
200
222
  textures: ({
@@ -203,6 +225,18 @@ interface PropsDataFields {
203
225
  })[];
204
226
  bodies?: PropsBody[];
205
227
  }
228
+ /** OF22a3: a static capsule solid. */
229
+ interface PropCapsule extends GlbVertex {
230
+ kind: 'capsule';
231
+ halfHeight: number;
232
+ radius: number;
233
+ yaw?: number | undefined;
234
+ // oxlint-disable-next-line eslint/id-length -- Quaternion components are part of the wire.
235
+ rot?: (GlbVertex & { w: number }) | undefined;
236
+ surface?: PropSurface | undefined;
237
+ friction?: number | undefined;
238
+ groups?: number | undefined;
239
+ }
206
240
  /** SS9a: a point, or a cuboid's half extents, in metres. */
207
241
  interface PropsBodyVector { x: number; y: number; z: number }
208
242
  /** SS9a: one touchable panel's body. */
@@ -13,6 +13,7 @@ import type { ClientPlan } from './clientPlan.ts';
13
13
  import type { ReturnModuleRow, ViewModuleRow } from './scriptContract.ts';
14
14
  import type { WorldScenesSection } from './worldScenes.ts';
15
15
  import type { TreeSetRows } from './treeSetRows.ts';
16
+ import type { Vehicles } from './vehicles.ts';
16
17
  import type { HeldArmsRows } from './heldArms.ts';
17
18
  import type { HeldGearRows } from './heldGear.ts';
18
19
  import type { HeldFinishesRows } from './heldFinishes.ts';
@@ -85,6 +86,8 @@ export interface PlatformSections {
85
86
  'world/scenes': WorldScenesSection;
86
87
  /** Client-only baked forest tree set (game models/treeSet): a manifest's `trees.treeSet` and a forest page draw it. */
87
88
  'world/trees': TreeSetRows;
89
+ /** MIRROR-SALT-ZONE MSZ1: vehicle kinds (seats, hull, handling, sounds) and the docks they stand at. */
90
+ 'world/vehicles': Vehicles;
88
91
  'world/days': { readonly rows: Pick<Rows, 'days'> };
89
92
  'world/weather': { readonly rows: Pick<Rows, 'weather'> };
90
93
  'look/look': Pick<Shardfile, 'look' | 'presentation'>;
@@ -70,6 +70,7 @@ import { LookVignetteSchema } from './look-render.ts';
70
70
  import type { LookBloom, LookBloomInput, LookLight, LookLightInput, LookTone } from './look-light.ts';
71
71
  import { LookDetailsSchema, detailLayerRules } from './look-details.ts';
72
72
  import { LookLevelSchema, lookLevelRules } from './look-level.ts';
73
+ import { VehiclesSchema, vehicleRules } from './vehicles.ts';
73
74
  import type { LookLevel, LookLevelInput } from './look-level.ts';
74
75
  import type { LookDetail } from './look-details.ts';
75
76
  import type { LookVignette } from './look-render.ts';
@@ -317,6 +318,12 @@ export function shardfileRules(s: Shardfile, sections?: ReadonlyMap<string, unkn
317
318
  if (moves.passes !== undefined) { debrisStrikes.push(moves.passes.left, moves.passes.right); }
318
319
  }
319
320
  }
321
+ // MIRROR-SALT-ZONE MSZ1: a vehicle kind's panel and sounds resolve, and no dock takes a mover's id.
322
+ const vehicles = sections?.get('world/vehicles');
323
+ if (vehicles !== undefined) {
324
+ const parsed = v.safeParse(VehiclesSchema, vehicles);
325
+ errors.push(...parsed.success ? vehicleRules(parsed.output, s) : ['world/vehicles parses']);
326
+ }
320
327
  const metadata = sections?.get('actors/species-programs');
321
328
  const roster = metadata === undefined ? undefined : readSpeciesPrograms(metadata);
322
329
  const targets = [...s.rows.species, ...roster?.page ?? [], ...roster?.native ?? [], ...roster?.program?.species ?? []];
@@ -0,0 +1,347 @@
1
+ // oxlint-disable typescript/prefer-readonly-parameter-types, id-length, no-magic-numbers, max-statements, max-lines, max-lines-per-function -- valibot's output rows have mutable types and nothing here writes them; points are x, y, z tuples read by index 0 to 2, and one lift reads as one function
2
+ /**
3
+ * MIRROR-SALT-ZONE MSZ2 (meta J459 call 1 A): a steer carry becomes a vehicle, and back.
4
+ *
5
+ * `liftSteerVehicles` is the migration: each native carry `channel` mover with a `steer` driver (SS-MS2a1) becomes one
6
+ * `world/vehicles` kind (one driver seat at the carry's seat, the carry's prompts as its labels, its panel's
7
+ * `props.colliders` boxes as its hull, SS-GP5) and one shared dock at its rest, and leaves `movers`. A carry's numbers
8
+ * that a kind has no word for take today's behaviour: no reverse, a brake as quick as its acceleration, full grip and no
9
+ * drift. The `steer` driver row stays readable, for old revisions only.
10
+ *
11
+ * `vehicleCarryMovers` lowers each dock back to the steer carry an engine without the vehicle runtime (MSZ8) runs, with
12
+ * `vehicleCarryHulls` for its hull; a passenger seat has no carry, so it waits for MSZ9.
13
+ *
14
+ * Plain data and checks, no three.js.
15
+ */
16
+ import { lowerMoverMotion } from './moverMotion.ts'
17
+ import { parseVehicles } from './vehicles.ts'
18
+
19
+ import type { MoverCarry, MoverMotion } from './moverMotion.ts'
20
+ import type { MoverBox, MoverData } from './movers.ts'
21
+ import type { Shardfile } from './shardSchema.ts'
22
+ import type {
23
+ VehicleDock,
24
+ VehicleHullBox,
25
+ VehicleKind,
26
+ Vehicles,
27
+ } from './vehicles.ts'
28
+
29
+ /** One mover row. */
30
+ type MoverRow = MoverData[number]
31
+ /** The steer driver row. */
32
+ type SteerDriver = Extract<NonNullable<MoverRow['driver']>, { kind: 'steer' }>
33
+ /** What a lift reads: the movers, and the props whose panel colliders are a vehicle's hull. */
34
+ type LiftSource = Pick<Shardfile, 'movers' | 'props'>
35
+ /** What a lift gives: the vehicles, the movers left, and a line for each collider a hull could not take. */
36
+ interface Lifted {
37
+ vehicles: Vehicles
38
+ movers: MoverData
39
+ notes: string[]
40
+ }
41
+
42
+ /** The mass a lifted vehicle gets (kg); a carry has none. */
43
+ const LIFTED_MASS = 250
44
+ /** A lifted shared dock's respawn (s). */
45
+ const LIFTED_RESPAWN = 30
46
+ const MAX_HULL_BOXES = 16
47
+ const MAX_HULL_HALF = 8
48
+ const KIND_REACH = 16
49
+ const HALF = 0.5
50
+ const NONE = 0
51
+ const UP = 1
52
+ /** A lowered carry's board prompt reaches this far past the hull's widest half (m), and at most this far. */
53
+ const BOARD_MARGIN = 2
54
+ const BOARD_MOST = 10
55
+ /** The leave prompt sits this far over the seat (m) and reaches this far, as the SDK's steer carry did. */
56
+ const LEAVE_RISE = 1.2
57
+ const LEAVE_REACH = 2
58
+ const DRIVE_LABEL = 'Board'
59
+ const LEAVE_LABEL = 'Leave'
60
+ const FLAT = {
61
+ level: 0,
62
+ bankRamp: 0,
63
+ bob: [0, 0],
64
+ pitch: [0, 0],
65
+ roll: [0, 0, 0],
66
+ } as const satisfies MoverCarry['surface']
67
+ const MILLI = 1000
68
+
69
+ /** Round to a millimetre (or a milliradian), so a lifted row reads as authored. */
70
+ function milli(value: number): number {
71
+ return Math.round(value * MILLI) / MILLI
72
+ }
73
+ /** An angle wrapped into -π to π. */
74
+ function wrap(angle: number): number {
75
+ return Math.atan2(Math.sin(angle), Math.cos(angle))
76
+ }
77
+ /** Whether a mover row is a steer carry. */
78
+ function isSteerCarry(
79
+ row: MoverRow,
80
+ ): row is MoverRow & { driver: SteerDriver; carry: MoverCarry } {
81
+ return (
82
+ row.execution === 'native' &&
83
+ row.kind === 'channel' &&
84
+ row.driver?.kind === 'steer' &&
85
+ row.carry !== undefined
86
+ )
87
+ }
88
+
89
+ /** One world-space panel collider box as a hull box in the vehicle's frame (its rest and heading), or why it can't be. */
90
+ function hullBox(
91
+ shape: {
92
+ x: number
93
+ y: number
94
+ z: number
95
+ hx: number
96
+ hy: number
97
+ hz: number
98
+ yaw?: number | undefined
99
+ rot?: unknown
100
+ },
101
+ row: MoverRow,
102
+ ): VehicleHullBox | string {
103
+ if (shape.rot !== undefined) {
104
+ return `${row.id}: a turned (rot) collider box is no hull box`
105
+ }
106
+ const halves: [number, number, number] = [shape.hx, shape.hy, shape.hz]
107
+ if (halves.some((half: number): boolean => half > MAX_HULL_HALF)) {
108
+ return `${row.id}: a collider box over ${String(MAX_HULL_HALF)} m is no hull box`
109
+ }
110
+ const heading = row.euler.y
111
+ const dx = shape.x - row.at.x
112
+ const dz = shape.z - row.at.z
113
+ const at: [number, number, number] = [
114
+ milli(dx * Math.cos(heading) - dz * Math.sin(heading)),
115
+ milli(shape.y - row.at.y),
116
+ milli(dx * Math.sin(heading) + dz * Math.cos(heading)),
117
+ ]
118
+ if (at.some((axis: number): boolean => Math.abs(axis) > KIND_REACH)) {
119
+ return `${row.id}: a collider box ${String(KIND_REACH)} m or more from the rest is no hull box`
120
+ }
121
+ const yaw = milli(wrap((shape.yaw ?? NONE) - heading))
122
+ return yaw === NONE ? { at, half: halves } : { at, half: halves, yaw }
123
+ }
124
+
125
+ /** The handling a steer driver means. */
126
+ function steerHandling(driver: SteerDriver): VehicleKind['handling'] {
127
+ const { speed, turn, boost, accel, ground, wind } = driver
128
+ const still = {
129
+ speed,
130
+ reverse: NONE,
131
+ accel,
132
+ brake: accel,
133
+ turn,
134
+ grip: UP,
135
+ drift: NONE,
136
+ boost,
137
+ mass: LIFTED_MASS,
138
+ ground,
139
+ }
140
+ return wind === undefined
141
+ ? still
142
+ : {
143
+ ...still,
144
+ wind: { toward: [wind.toward[0], wind.toward[1]], push: wind.push },
145
+ }
146
+ }
147
+
148
+ /** One steer carry as a kind and its shared dock. */
149
+ function liftOne(
150
+ row: MoverRow & { driver: SteerDriver; carry: MoverCarry },
151
+ props: LiftSource['props'],
152
+ notes: string[],
153
+ ): [VehicleKind, VehicleDock] {
154
+ const { carry } = row
155
+ const shapes = (props?.colliders ?? [])
156
+ .filter((solid): boolean => solid.panel === row.id)
157
+ .flatMap(
158
+ (
159
+ solid,
160
+ ): NonNullable<LiftSource['props']>['colliders'][number]['shapes'] =>
161
+ solid.shapes,
162
+ )
163
+ const hull: VehicleHullBox[] = []
164
+ for (const shape of shapes) {
165
+ const box =
166
+ shape.kind === 'box'
167
+ ? hullBox(shape, row)
168
+ : `${row.id}: a ${shape.kind} collider is no hull box`
169
+ if (typeof box === 'string') {
170
+ notes.push(box)
171
+ } else if (hull.length < MAX_HULL_BOXES) {
172
+ hull.push(box)
173
+ } else {
174
+ notes.push(`${row.id}: a hull holds ${String(MAX_HULL_BOXES)} boxes`)
175
+ }
176
+ }
177
+ const [board, leave] = carry.prompts
178
+ const labels = {
179
+ ...(board.label === '' ? {} : { drive: board.label }),
180
+ ...(leave.label === '' ? {} : { leave: leave.label }),
181
+ }
182
+ const kind: VehicleKind = {
183
+ id: row.id,
184
+ panel: row.id,
185
+ ...(Object.keys(labels).length === NONE ? {} : { labels }),
186
+ seats: [
187
+ {
188
+ role: 'driver',
189
+ at: [NONE, carry.seat, NONE],
190
+ pose: 'stand',
191
+ leave: [...carry.landings[0]],
192
+ },
193
+ ],
194
+ hull,
195
+ handling: steerHandling(row.driver),
196
+ }
197
+ const dock: VehicleDock = {
198
+ id: row.id,
199
+ kind: row.id,
200
+ at: [row.at.x, row.at.y, row.at.z],
201
+ yaw: row.euler.y,
202
+ per: 'shared',
203
+ respawn: LIFTED_RESPAWN,
204
+ }
205
+ return [kind, dock]
206
+ }
207
+
208
+ /** MSZ2: every steer carry in `source.movers` as a `world/vehicles` kind and shared dock, and the movers without them. */
209
+ function liftSteerVehicles(source: LiftSource): Lifted {
210
+ const notes: string[] = []
211
+ const lifted = source.movers
212
+ .filter(isSteerCarry)
213
+ .map((row): [VehicleKind, VehicleDock] => liftOne(row, source.props, notes))
214
+ const vehicles = parseVehicles({
215
+ kinds: lifted.map(([kind]): VehicleKind => kind),
216
+ docks: lifted.map(([, dock]): VehicleDock => dock),
217
+ })
218
+ return {
219
+ vehicles,
220
+ movers: source.movers.filter((row): boolean => !isSteerCarry(row)),
221
+ notes,
222
+ }
223
+ }
224
+
225
+ /** A kind's driver seat (the schema admits exactly one). */
226
+ function driverSeat(kind: VehicleKind): VehicleKind['seats'][number] {
227
+ const seat = kind.seats.find((row): boolean => row.role === 'driver')
228
+ if (seat === undefined) {
229
+ throw new Error(`vehicle kind ${kind.id} has no driver seat`)
230
+ }
231
+ return seat
232
+ }
233
+
234
+ /** One dock as the steer carry today's engine runs (`entity` its mover entity). */
235
+ function carryRow(
236
+ dock: VehicleDock,
237
+ kind: VehicleKind,
238
+ entity: number,
239
+ ): MoverRow {
240
+ const seat = driverSeat(kind)
241
+ const at = { x: dock.at[0], y: dock.at[1], z: dock.at[2] }
242
+ const euler = { x: NONE, y: dock.yaw, z: NONE }
243
+ const { speed, turn, boost, accel, ground, wind } = kind.handling
244
+ const driver: SteerDriver = {
245
+ kind: 'steer',
246
+ speed,
247
+ turn,
248
+ boost,
249
+ accel,
250
+ ground,
251
+ ...(wind === undefined ? {} : { wind }),
252
+ }
253
+ const motion: MoverMotion = {
254
+ trigger: { kind: 'interact', permission: 0 },
255
+ driver,
256
+ }
257
+ const widest = Math.max(
258
+ NONE,
259
+ ...kind.hull.map(
260
+ (box): number =>
261
+ Math.hypot(box.at[0], box.at[2]) + Math.max(box.half[0], box.half[2]),
262
+ ),
263
+ )
264
+ const [sx, sy, sz] = seat.leave
265
+ const carry: MoverCarry = {
266
+ seat: seat.at[1],
267
+ landings: [
268
+ [sx, sy, sz],
269
+ [-sx, sy, sz],
270
+ ],
271
+ yaw: NONE,
272
+ surface: {
273
+ level: FLAT.level,
274
+ bankRamp: FLAT.bankRamp,
275
+ bob: [...FLAT.bob],
276
+ pitch: [...FLAT.pitch],
277
+ roll: [...FLAT.roll],
278
+ },
279
+ prompts: [
280
+ {
281
+ at: [NONE, UP, NONE],
282
+ radius: milli(Math.min(BOARD_MOST, widest + BOARD_MARGIN)),
283
+ label: kind.labels?.drive ?? DRIVE_LABEL,
284
+ },
285
+ {
286
+ at: [NONE, milli(seat.at[1] + LEAVE_RISE), NONE],
287
+ radius: LEAVE_REACH,
288
+ label: kind.labels?.leave ?? LEAVE_LABEL,
289
+ },
290
+ ],
291
+ }
292
+ return {
293
+ id: dock.id,
294
+ entity,
295
+ kind: 'channel',
296
+ at,
297
+ euler,
298
+ enabled: true,
299
+ boxes: [],
300
+ ...lowerMoverMotion(motion, { at, euler }),
301
+ ...motion,
302
+ carry,
303
+ execution: 'native',
304
+ }
305
+ }
306
+
307
+ /** Each dock as a steer carry, entities from `entity` up, for an engine without the vehicle runtime (MSZ8). */
308
+ function vehicleCarryMovers(vehicles: Vehicles, entity: number): MoverData {
309
+ const kinds = new Map(
310
+ vehicles.kinds.map((kind): [string, VehicleKind] => [kind.id, kind]),
311
+ )
312
+ return vehicles.docks.flatMap((dock, index): MoverRow[] => {
313
+ const kind = kinds.get(dock.kind)
314
+ return kind === undefined ? [] : [carryRow(dock, kind, entity + index)]
315
+ })
316
+ }
317
+
318
+ /** Each lowered dock's hull as mover boxes in its own frame, by mover id (as engine `vehicleHulls` gives a steer carry's). */
319
+ function vehicleCarryHulls(
320
+ vehicles: Vehicles,
321
+ ): ReadonlyMap<string, readonly MoverBox[]> {
322
+ const kinds = new Map(
323
+ vehicles.kinds.map((kind): [string, VehicleKind] => [kind.id, kind]),
324
+ )
325
+ const hulls = new Map<string, readonly MoverBox[]>()
326
+ for (const dock of vehicles.docks) {
327
+ const boxes = (kinds.get(dock.kind)?.hull ?? []).map((box): MoverBox => {
328
+ const turn = (box.yaw ?? NONE) * HALF
329
+ return {
330
+ x: box.at[0],
331
+ y: box.at[1],
332
+ z: box.at[2],
333
+ hx: box.half[0],
334
+ hy: box.half[1],
335
+ hz: box.half[2],
336
+ rot: { x: NONE, y: Math.sin(turn), z: NONE, w: Math.cos(turn) },
337
+ }
338
+ })
339
+ if (boxes.length > NONE) {
340
+ hulls.set(dock.id, boxes)
341
+ }
342
+ }
343
+ return hulls
344
+ }
345
+
346
+ export { liftSteerVehicles, vehicleCarryHulls, vehicleCarryMovers }
347
+ export type { LiftSource, Lifted }
@@ -0,0 +1,364 @@
1
+ // oxlint-disable typescript/prefer-readonly-parameter-types, eslint/max-lines -- valibot's output rows have mutable types and nothing here writes them; the section's types, schema and rules read as one
2
+ /**
3
+ * `world/vehicles` (meta MIRROR-SALT-ZONE MSZ1, J456, J459 call 1 A): the one way a shard declares vehicles a player gets
4
+ * into, sits in, drives and leaves. A **kind** is the vehicle: the panel every page poses, its seats, hull, handling,
5
+ * health and sounds. A **dock** is where one stands and comes back. Metres, seconds and radians throughout; a kind's
6
+ * points are in its own frame (x right, y up, z back, so forward is -z, as a steer carry's), a dock's in the cell's.
7
+ *
8
+ * Plain data and checks, no three.js.
9
+ */
10
+ import {
11
+ boolean,
12
+ check,
13
+ exactOptional,
14
+ finite,
15
+ literal,
16
+ maxLength,
17
+ maxValue,
18
+ minLength,
19
+ minValue,
20
+ number,
21
+ parse,
22
+ picklist,
23
+ pipe,
24
+ regex,
25
+ string,
26
+ strictObject,
27
+ tuple,
28
+ union,
29
+ array,
30
+ } from 'valibot'
31
+
32
+ import { WIRE_CELL } from './wireLimits.ts'
33
+
34
+ import type { GenericSchema } from 'valibot'
35
+
36
+ /** A point or extent: x, y and z. */
37
+ type Vec3 = [number, number, number]
38
+ /** One seat: who sits there, where (the body's base, in the kind's frame), how, and where leaving sets them down. */
39
+ interface VehicleSeat {
40
+ role: 'driver' | 'passenger'
41
+ at: Vec3
42
+ pose: 'sit' | 'stand'
43
+ leave: Vec3
44
+ }
45
+ /** One hull box in the kind's frame: its centre, half extents and turn about up. It rides the vehicle and stops anyone on foot, never a rider. */
46
+ interface VehicleHullBox {
47
+ at: Vec3
48
+ half: Vec3
49
+ yaw?: number
50
+ }
51
+ /** SS-MS2a2's sail push: the ground direction the wind blows toward (x, z; not zero) and the m/s a full sail adds. */
52
+ interface VehicleWind {
53
+ toward: [number, number]
54
+ push: number
55
+ }
56
+ /**
57
+ * How it drives: top `speed` and `reverse` (m/s), `accel` and `brake` (m/s²), `turn` (rad/s at full stick), `grip` (0
58
+ * slides like ice, 1 never slips), `drift` (0 to 1, how long a slide lasts), `boost` (top speed times 1 to 4), `mass` (kg,
59
+ * who gives way in a crash), `ground` (follow the ground under it, or keep its dock's height) and an optional sail `wind`.
60
+ */
61
+ interface VehicleHandling {
62
+ speed: number
63
+ reverse: number
64
+ accel: number
65
+ brake: number
66
+ turn: number
67
+ grip: number
68
+ drift: number
69
+ boost: number
70
+ mass: number
71
+ ground: boolean
72
+ wind?: VehicleWind
73
+ }
74
+ /** Audio cue ids (`audio.cues`) a kind plays: the engine loop, a skid from slip, an impact one-shot and a horn. */
75
+ interface VehicleSounds {
76
+ loop?: string
77
+ skid?: string
78
+ impact?: string
79
+ horn?: string
80
+ }
81
+ /** The prompt labels: get in as the driver, get in as a passenger, get out. */
82
+ interface VehicleLabels {
83
+ drive?: string
84
+ ride?: string
85
+ leave?: string
86
+ }
87
+ /** One vehicle kind. */
88
+ interface VehicleKind {
89
+ id: string
90
+ panel: string
91
+ labels?: VehicleLabels
92
+ seats: VehicleSeat[]
93
+ hull: VehicleHullBox[]
94
+ handling: VehicleHandling
95
+ health?: number
96
+ sounds?: VehicleSounds
97
+ }
98
+ /** Where a kind stands: one per player who comes (`player`) or one everyone shares (`shared`); back `respawn` s after it goes. */
99
+ interface VehicleDock {
100
+ id: string
101
+ kind: string
102
+ at: Vec3
103
+ yaw: number
104
+ per: 'player' | 'shared'
105
+ respawn: number
106
+ }
107
+ /** The `world/vehicles` section. */
108
+ interface Vehicles {
109
+ kinds: VehicleKind[]
110
+ docks: VehicleDock[]
111
+ }
112
+ type VehiclesInput = Vehicles
113
+ /** What a kind's references must find in the rest of the shard file. */
114
+ interface VehicleReferences {
115
+ readonly props: { readonly panels: readonly { readonly id: string }[] } | null
116
+ readonly audio: { readonly cues: readonly { readonly id: string }[] }
117
+ readonly movers: readonly { readonly id: string }[]
118
+ }
119
+
120
+ // MSZ1's bounds: kinds and docks a shard; seats and hull boxes a kind; metres, m/s, m/s², kg, seconds and characters.
121
+ const MAX_KINDS = 8
122
+ const MAX_DOCKS = 32
123
+ const MAX_SEATS = 4
124
+ const MAX_HULL_BOXES = 16
125
+ const MAX_HULL_HALF = 8
126
+ const KIND_REACH = 16
127
+ const SEAT_REACH = 10
128
+ const MAX_SPEED = 60
129
+ const MAX_ACCEL = 100
130
+ const MAX_BRAKE = 200
131
+ const MAX_TURN = Math.PI + Math.PI
132
+ const MAX_BOOST = 4
133
+ const MAX_PUSH = 20
134
+ const MAX_MASS = 50_000
135
+ const MAX_HEALTH = 100_000
136
+ const MAX_RESPAWN = 3600
137
+ const LEAST = 0.005
138
+ const MAX_TEXT = 128
139
+ const SOUND_SLOTS: readonly (keyof VehicleSounds)[] = [
140
+ 'loop',
141
+ 'skid',
142
+ 'impact',
143
+ 'horn',
144
+ ]
145
+ const NONE = 0
146
+ const ONE = 1
147
+ const ID = /^[a-z][a-z0-9.-]*$/u
148
+
149
+ /** A finite number from `low` to `high`. */
150
+ function bounded(low: number, high: number): GenericSchema<number> {
151
+ return pipe(number(), finite(), minValue(low), maxValue(high))
152
+ }
153
+ /** A point each of whose axes is within `reach` of the origin. */
154
+ function near(reach: number): GenericSchema<Vec3> {
155
+ const axis = bounded(-reach, reach)
156
+ return tuple([axis, axis, axis])
157
+ }
158
+ /** Whether no two ids are the same. */
159
+ function distinct(ids: readonly string[]): boolean {
160
+ return new Set(ids).size === ids.length
161
+ }
162
+ /** Whether no two kinds share an id. */
163
+ function kindIdsUnique(rows: VehicleKind[]): boolean {
164
+ return distinct(rows.map((row: VehicleKind): string => row.id))
165
+ }
166
+ /** Whether no two docks share an id. */
167
+ function dockIdsUnique(rows: VehicleDock[]): boolean {
168
+ return distinct(rows.map((row: VehicleDock): string => row.id))
169
+ }
170
+ /** Whether a seat is the driver's. */
171
+ function isDriver(row: VehicleSeat): boolean {
172
+ return row.role === 'driver'
173
+ }
174
+ /** Whether a kind has exactly one driver seat. */
175
+ function oneDriver(rows: VehicleSeat[]): boolean {
176
+ return (
177
+ rows.filter((row: VehicleSeat): boolean => isDriver(row)).length === ONE
178
+ )
179
+ }
180
+ /** Whether a sail's push names a direction. */
181
+ function blowsSomewhere(toward: [number, number]): boolean {
182
+ return toward.some((axis: number): boolean => axis !== NONE)
183
+ }
184
+ /** Whether it reverses no faster than its top speed. */
185
+ function reverseWithin(row: VehicleHandling): boolean {
186
+ return row.reverse <= row.speed
187
+ }
188
+ /** Whether every dock names a declared kind. */
189
+ function docksOfKinds(row: Vehicles): boolean {
190
+ const kinds = new Set(row.kinds.map((kind: VehicleKind): string => kind.id))
191
+ return row.docks.every((dock: VehicleDock): boolean => kinds.has(dock.kind))
192
+ }
193
+
194
+ const id = pipe(string(), regex(ID), maxLength(MAX_TEXT))
195
+ const text = pipe(string(), minLength(ONE), maxLength(MAX_TEXT))
196
+ const anyNumber = pipe(number(), finite())
197
+ const angle = bounded(-Math.PI, Math.PI)
198
+ const half = bounded(LEAST, MAX_HULL_HALF)
199
+ const cellAxis = bounded(-WIRE_CELL.half, WIRE_CELL.half)
200
+ const cellHeight = bounded(-WIRE_CELL.below, WIRE_CELL.above)
201
+ const seat = strictObject({
202
+ role: picklist(['driver', 'passenger']),
203
+ at: near(SEAT_REACH),
204
+ pose: picklist(['sit', 'stand']),
205
+ leave: near(KIND_REACH),
206
+ })
207
+ const hullBox = strictObject({
208
+ at: near(KIND_REACH),
209
+ half: tuple([half, half, half]),
210
+ yaw: exactOptional(angle),
211
+ })
212
+ const wind = strictObject({
213
+ toward: pipe(
214
+ tuple([anyNumber, anyNumber]),
215
+ check(blowsSomewhere, 'a wind push needs a direction'),
216
+ ),
217
+ push: bounded(NONE, MAX_PUSH),
218
+ })
219
+ const handling = pipe(
220
+ strictObject({
221
+ speed: bounded(LEAST, MAX_SPEED),
222
+ reverse: bounded(NONE, MAX_SPEED),
223
+ accel: bounded(LEAST, MAX_ACCEL),
224
+ brake: bounded(LEAST, MAX_BRAKE),
225
+ turn: bounded(LEAST, MAX_TURN),
226
+ grip: bounded(NONE, ONE),
227
+ drift: bounded(NONE, ONE),
228
+ boost: bounded(ONE, MAX_BOOST),
229
+ mass: bounded(ONE, MAX_MASS),
230
+ ground: boolean(),
231
+ wind: exactOptional(wind),
232
+ }),
233
+ check(reverseWithin, 'a vehicle reverses no faster than its top speed'),
234
+ )
235
+ const cue = pipe(string(), minLength(ONE), maxLength(MAX_TEXT))
236
+ const sounds = strictObject({
237
+ loop: exactOptional(cue),
238
+ skid: exactOptional(cue),
239
+ impact: exactOptional(cue),
240
+ horn: exactOptional(cue),
241
+ })
242
+ const labels = strictObject({
243
+ drive: exactOptional(text),
244
+ ride: exactOptional(text),
245
+ leave: exactOptional(text),
246
+ })
247
+ const seats = pipe(
248
+ array(seat),
249
+ minLength(ONE, 'a vehicle kind has at least one seat'),
250
+ maxLength(MAX_SEATS, `a vehicle kind has at most ${String(MAX_SEATS)} seats`),
251
+ check(oneDriver, 'a vehicle kind has exactly one driver seat'),
252
+ )
253
+ const hull = pipe(
254
+ array(hullBox),
255
+ maxLength(
256
+ MAX_HULL_BOXES,
257
+ `a vehicle hull has at most ${String(MAX_HULL_BOXES)} boxes`,
258
+ ),
259
+ )
260
+ const kind = strictObject({
261
+ id,
262
+ panel: id,
263
+ labels: exactOptional(labels),
264
+ seats,
265
+ hull,
266
+ handling,
267
+ health: exactOptional(bounded(ONE, MAX_HEALTH)),
268
+ sounds: exactOptional(sounds),
269
+ })
270
+ const dock = strictObject({
271
+ id,
272
+ kind: id,
273
+ at: tuple([cellAxis, cellHeight, cellAxis]),
274
+ yaw: angle,
275
+ per: union([literal('player'), literal('shared')]),
276
+ respawn: bounded(NONE, MAX_RESPAWN),
277
+ })
278
+ const kinds = pipe(
279
+ array(kind),
280
+ maxLength(
281
+ MAX_KINDS,
282
+ `a shard has at most ${String(MAX_KINDS)} vehicle kinds`,
283
+ ),
284
+ check(kindIdsUnique, 'vehicle kind ids are unique'),
285
+ )
286
+ const docks = pipe(
287
+ array(dock),
288
+ maxLength(
289
+ MAX_DOCKS,
290
+ `a shard has at most ${String(MAX_DOCKS)} vehicle docks`,
291
+ ),
292
+ check(dockIdsUnique, 'vehicle dock ids are unique'),
293
+ )
294
+
295
+ /** The `world/vehicles` section (MSZ1): unique ids, docks of declared kinds, at most 8 kinds and 32 docks. */
296
+ const VehiclesSchema: GenericSchema<VehiclesInput, Vehicles> = pipe(
297
+ strictObject({ kinds, docks }),
298
+ check(docksOfKinds, 'a vehicle dock names a declared kind'),
299
+ )
300
+
301
+ /** Refuse a malformed `world/vehicles` section, naming the bound it breaks. */
302
+ function parseVehicles(input: unknown): Vehicles {
303
+ return parse(VehiclesSchema, input)
304
+ }
305
+
306
+ /** Why one kind's panel or sounds do not resolve. */
307
+ function kindRules(
308
+ row: VehicleKind,
309
+ panels: ReadonlySet<string>,
310
+ cues: ReadonlySet<string>,
311
+ ): string[] {
312
+ const errors: string[] = []
313
+ if (!panels.has(row.panel)) {
314
+ errors.push(
315
+ `vehicle kind ${row.id} names the panel ${row.panel}, which props.panels does not declare`,
316
+ )
317
+ }
318
+ for (const slot of SOUND_SLOTS) {
319
+ const name = row.sounds?.[slot]
320
+ if (name !== undefined && !cues.has(name)) {
321
+ errors.push(
322
+ `vehicle kind ${row.id}'s ${slot} sound ${name} is not a declared audio cue`,
323
+ )
324
+ }
325
+ }
326
+ return errors
327
+ }
328
+
329
+ /** Each kind's panel is a declared prop panel, each sound a declared audio cue, and no dock reuses a mover's id. */
330
+ function vehicleRules(vehicles: Vehicles, source: VehicleReferences): string[] {
331
+ const panels = new Set(
332
+ source.props?.panels.map((row: { readonly id: string }): string => row.id),
333
+ )
334
+ const cues = new Set(
335
+ source.audio.cues.map((row: { readonly id: string }): string => row.id),
336
+ )
337
+ const movers = new Set(
338
+ source.movers.map((row: { readonly id: string }): string => row.id),
339
+ )
340
+ const kindErrors = vehicles.kinds.flatMap((row: VehicleKind): string[] =>
341
+ kindRules(row, panels, cues),
342
+ )
343
+ const dockErrors = vehicles.docks
344
+ .filter((row: VehicleDock): boolean => movers.has(row.id))
345
+ .map(
346
+ (row: VehicleDock): string => `vehicle dock ${row.id} has a mover's id`,
347
+ )
348
+ return [...kindErrors, ...dockErrors]
349
+ }
350
+
351
+ export { VehiclesSchema, parseVehicles, vehicleRules }
352
+ export type {
353
+ VehicleDock,
354
+ VehicleHandling,
355
+ VehicleHullBox,
356
+ VehicleKind,
357
+ VehicleLabels,
358
+ VehicleReferences,
359
+ VehicleSeat,
360
+ VehicleSounds,
361
+ VehicleWind,
362
+ Vehicles,
363
+ VehiclesInput,
364
+ }
@@ -225,6 +225,10 @@
225
225
  "world/trees": {
226
226
  "hosts": ["page productTreeSet", "page placeForestPageModels"]
227
227
  },
228
+ "world/vehicles": {
229
+ "hosts": [],
230
+ "note": "Read by the vehicle runtime (meta MIRROR-SALT-ZONE MSZ6 to MSZ9); until then the engine runs each dock as its steer carry (`vehicleCarryMovers`)."
231
+ },
228
232
  "world/water": {
229
233
  "hosts": ["page installClientWater", "page shardfileWater"]
230
234
  },