@bendyline/molen-ambient 0.0.9 → 0.0.11

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.
@@ -23,14 +23,19 @@ const KIND_SPEED = {
23
23
  path: 1.4,
24
24
  crossing: 1.4,
25
25
  rail: 20,
26
- tram: 12
26
+ tram: 12,
27
+ ferry: 8,
28
+ channel: 7
27
29
  };
28
30
  /** Classify a mapped feature; `undefined` for features no agent uses. */
29
31
  function classifyFeature(feature) {
30
32
  const cls = feature.class.toLowerCase();
31
33
  const sub = (feature.subclass ?? "").toLowerCase();
32
34
  if (cls === "aeroway" || /runway|taxiway|apron/.test(sub)) return sub === "runway" || cls === "runway" ? "runway" : void 0;
33
- if (cls === "ferry" || sub === "ferry") return void 0;
35
+ if (cls === "ferry" || sub === "ferry") return {
36
+ class: "water",
37
+ kind: "ferry"
38
+ };
34
39
  const kind = transportKind(feature);
35
40
  if (kind === "rail") {
36
41
  if (/disused|abandoned|construction|proposed|platform|station|miniature|funicular/.test(sub)) return void 0;
@@ -195,7 +200,7 @@ function featureDrafts(input, options) {
195
200
  }
196
201
  if (feature.tunnel === true && options.tunnels === "skip") continue;
197
202
  const kind = transportKind(feature);
198
- const width = classified.class === "walk" ? dmath.max(1.2, feature.width ?? 2.4) : classified.class === "rail" ? 3 : transportWidth(feature, kind);
203
+ const width = classified.class === "water" ? feature.width ?? 60 : classified.class === "walk" ? dmath.max(1.2, feature.width ?? 2.4) : classified.class === "rail" ? 3 : transportWidth(feature, kind);
199
204
  const lanes = classified.class === "road" ? roadLanes(feature, width).total : 2;
200
205
  const link = isTransportLink(feature);
201
206
  for (const line of joinTerrainLines(feature.lines)) for (const piece of clipPolyline(toWorld(line), minX, minZ, maxX, maxZ)) {
@@ -205,7 +210,7 @@ function featureDrafts(input, options) {
205
210
  points: piece,
206
211
  width,
207
212
  lanes,
208
- oneway: feature.oneway === true && classified.class === "road",
213
+ oneway: feature.oneway === true && (classified.class === "road" || classified.class === "water"),
209
214
  layer: feature.layer ?? 0,
210
215
  bridge: feature.bridge === true,
211
216
  tunnel: feature.tunnel === true,
@@ -227,6 +232,7 @@ function featureDrafts(input, options) {
227
232
  };
228
233
  }
229
234
  const POI_KINDS = new Set([
235
+ "ferry_terminal",
230
236
  "station",
231
237
  "tram_stop",
232
238
  "bus_stop",
@@ -291,6 +297,14 @@ function wayDraft(way) {
291
297
  ...way.speed !== void 0 ? { speed: way.speed } : {},
292
298
  ...way.name !== void 0 ? { name: way.name } : {}
293
299
  };
300
+ if (way.class === "water") return {
301
+ ...common,
302
+ class: "water",
303
+ kind: way.subclass === "ferry" ? "ferry" : "channel",
304
+ width: way.width ?? 60,
305
+ lanes: way.oneway ? 1 : 2,
306
+ oneway: way.oneway === true
307
+ };
294
308
  if (way.class === "rail") return {
295
309
  ...common,
296
310
  class: "rail",
@@ -326,7 +340,7 @@ function wayDraft(way) {
326
340
  function documentPois(doc) {
327
341
  const pois = [];
328
342
  for (const station of doc.stations ?? []) pois.push({
329
- kind: station.kind === "rail" ? "station" : "bus_stop",
343
+ kind: station.kind === "ferry" ? "ferry_terminal" : station.kind === "rail" ? "station" : "bus_stop",
330
344
  x: station.at[0],
331
345
  z: station.at[1],
332
346
  name: station.id,
@@ -412,7 +426,8 @@ const kind = z.enum([
412
426
  "car",
413
427
  "pedestrian",
414
428
  "train",
415
- "aircraft"
429
+ "aircraft",
430
+ "boat"
416
431
  ]);
417
432
  const ambientAgentSchema = z.strictObject({
418
433
  kind: kind.describe("Agent class."),
@@ -421,6 +436,7 @@ const ambientAgentSchema = z.strictObject({
421
436
  lane: z.string().describe("Lane id the agent is on (\"\" for aircraft)."),
422
437
  s: num.describe("Metres along the lane; negative while on the connector into it."),
423
438
  speed: num.nonnegative().describe("Speed along the lane in m/s."),
439
+ cruise: num.positive().describe("Vessel cruise limit in m/s.").optional(),
424
440
  prev: z.string().describe("Previous lane (its connector leads onto `lane`).").optional(),
425
441
  next: z.string().describe("Chosen next lane.").optional(),
426
442
  seed: z.int().nonnegative().describe("Per-agent seed for every random choice it makes."),
@@ -460,7 +476,9 @@ const ambientRoleSchema = z.strictObject({
460
476
  "car",
461
477
  "bus",
462
478
  "rail",
463
- "aircraft"
479
+ "aircraft",
480
+ "boat",
481
+ "ferry"
464
482
  ]).describe("Which ambient pool the type joins (buses drive with cars)."),
465
483
  length: num.positive().describe("Body length in metres (default from vehicle.spec).").optional(),
466
484
  width: num.positive().describe("Body width in metres (default from vehicle.spec).").optional(),
@@ -500,7 +518,8 @@ const waySchema = z.strictObject({
500
518
  "road",
501
519
  "rail",
502
520
  "path",
503
- "air"
521
+ "air",
522
+ "water"
504
523
  ]).describe("What moves on it."),
505
524
  subclass: z.string().describe("motorway, trunk, primary, secondary, tertiary, residential, service; rail/tram; crossing.").optional(),
506
525
  points: z.array(point).min(2).describe("[x, z] or [x, y, z] points in scene metres (y = road surface height)."),
@@ -529,7 +548,11 @@ const transportNetworkSchema = z.strictObject({
529
548
  stations: z.array(z.strictObject({
530
549
  id: z.string().min(1),
531
550
  at: vec2.describe("[x, z]; projected onto the nearest rail (rail) or footway (bus)."),
532
- kind: z.enum(["rail", "bus"]),
551
+ kind: z.enum([
552
+ "rail",
553
+ "bus",
554
+ "ferry"
555
+ ]),
533
556
  dwell: num.positive().describe("Dwell time in seconds.").optional()
534
557
  })).describe("Stops trains (and buses) serve.").optional(),
535
558
  signals: z.array(z.strictObject({
@@ -595,7 +618,7 @@ function registerAmbientSchema() {
595
618
  const owner = "ambient";
596
619
  const docsRef = "guide/ambient-life.md";
597
620
  registerComponent(AMBIENT_AGENT_COMPONENT, ambientAgentSchema, {
598
- description: "Kernel-owned state of an ambient NPC (car, pedestrian, train car or aircraft): its lane, position along it, speed and routing. Read it; the ambient systems write it.",
621
+ description: "Kernel-owned state of an ambient NPC (car, pedestrian, train car, aircraft or boat): its lane, position along it, speed and routing. Read it; the ambient systems write it.",
599
622
  owner,
600
623
  examples: [AMBIENT_AGENT_EXAMPLE],
601
624
  docsRef
@@ -610,7 +633,7 @@ function registerAmbientSchema() {
610
633
  docsRef
611
634
  }, { override: true });
612
635
  registerComponent(AMBIENT_ROLE_COMPONENT, ambientRoleSchema, {
613
- description: "On an entity type: makes it an ambient NPC candidate (car, bus, rail car or aircraft) with dimensions, speeds and spawn weight.",
636
+ description: "On an entity type: makes it an ambient NPC candidate (car, bus, rail car, aircraft, boat or ferry) with dimensions, speeds and spawn weight.",
614
637
  owner,
615
638
  examples: [{
616
639
  role: "car",
@@ -661,7 +684,8 @@ const AMBIENT_KINDS = [
661
684
  "car",
662
685
  "pedestrian",
663
686
  "train",
664
- "aircraft"
687
+ "aircraft",
688
+ "boat"
665
689
  ];
666
690
  const AmbientAgent = defineComponent(AMBIENT_AGENT_COMPONENT);
667
691
  const AmbientObserver = defineComponent(AMBIENT_OBSERVER_COMPONENT);
package/dist/kernel.d.mts CHANGED
@@ -1,3 +1,4 @@
1
+ import { a as WildlifeWorld, c as WILDLIFE_FAMILIES, d as WildlifeHabitat, f as WildlifeMotion, i as WildlifeBudget, l as WildlifeChoice, m as wildlifeSpeciesSchema, n as WILDLIFE_TICK_RATE, o as stepWildlife, p as WildlifeSpecies, r as WildlifeAgent, s as wildlifeCandidates, t as WILDLIFE_CELL_METERS, u as WildlifeFamily } from "./wildlife-B4EL0z-N.mjs";
1
2
  import { Quat } from "@bendyline/molen-kernel/determinism";
2
3
  import { ComponentType, JsonObject, World } from "@bendyline/molen-kernel/world";
3
4
  import { ComponentMap, EntityId, SceneManifest } from "@bendyline/molen-schema";
@@ -5,7 +6,7 @@ import { TerrainLinePath, TerrainPoiFeature, TerrainTransportationFeature } from
5
6
 
6
7
  //#region src/kernel/components.d.ts
7
8
  /** An ambient NPC class. */
8
- type AmbientKind = "car" | "pedestrian" | "train" | "aircraft";
9
+ type AmbientKind = "car" | "pedestrian" | "train" | "aircraft" | "boat";
9
10
  declare const AMBIENT_KINDS: readonly AmbientKind[];
10
11
  /** An aircraft corridor: a straight line flown at linearly varying altitude. */
11
12
  interface AmbientAirCorridor extends JsonObject {
@@ -24,6 +25,8 @@ interface AmbientAgentData extends JsonObject {
24
25
  lane: string;
25
26
  s: number;
26
27
  speed: number;
28
+ /** Vessel cruise limit, stored so checkpoint/replay does not depend on a mutable type pool. */
29
+ cruise?: number;
27
30
  prev?: string;
28
31
  next?: string;
29
32
  seed: number;
@@ -55,7 +58,7 @@ interface AmbientRoleVisual extends JsonObject {
55
58
  gearNodes?: string[];
56
59
  }
57
60
  interface AmbientRoleData extends JsonObject {
58
- role: "car" | "bus" | "rail" | "aircraft";
61
+ role: "car" | "bus" | "rail" | "aircraft" | "boat" | "ferry";
59
62
  length?: number;
60
63
  width?: number;
61
64
  height?: number;
@@ -127,8 +130,10 @@ interface AmbientPolicy {
127
130
  pedestrian: AmbientClassPolicy;
128
131
  train: AmbientClassPolicy;
129
132
  aircraft: AmbientClassPolicy;
133
+ boat: AmbientClassPolicy;
130
134
  driver: DriverParams;
131
135
  rail: DriverParams;
136
+ marine: DriverParams;
132
137
  }
133
138
  declare const DEFAULT_POLICY: AmbientPolicy;
134
139
  type DeepPartial<T> = { [K in keyof T]?: T[K] extends object ? DeepPartial<T[K]> : T[K] };
@@ -140,6 +145,7 @@ interface AmbientBudget {
140
145
  pedestrians?: number;
141
146
  trains?: number;
142
147
  aircraft?: number;
148
+ boats?: number;
143
149
  /** Outer spawn radius for cars; trains keep their ratio to it. */
144
150
  radius?: number;
145
151
  /** Outer spawn radius for pedestrians. */
@@ -159,9 +165,9 @@ declare function stoppingDistance(v: number, b: number): number;
159
165
  //#endregion
160
166
  //#region src/kernel/graph/types.d.ts
161
167
  /** Which agents a lane serves. */
162
- type TransportClass = "road" | "rail" | "walk" | "air";
168
+ type TransportClass = "road" | "rail" | "walk" | "air" | "water";
163
169
  /** Finer classification used for speeds, spawn preferences and routing weights. */
164
- type RoadKind = "motorway" | "trunk" | "primary" | "secondary" | "tertiary" | "street" | "living" | "service" | "path" | "crossing" | "rail" | "tram";
170
+ type RoadKind = "motorway" | "trunk" | "primary" | "secondary" | "tertiary" | "street" | "living" | "service" | "path" | "crossing" | "rail" | "tram" | "channel" | "ferry";
165
171
  type TurnKind = "straight" | "left" | "right" | "uturn" | "merge";
166
172
  /** An endpoint or split point shared by edges. */
167
173
  interface TransportNode {
@@ -231,7 +237,7 @@ interface TransportLane {
231
237
  interface LaneStop {
232
238
  /** Edge-path distance of the stop (convert with `laneCoordinate`). */
233
239
  readonly d: number;
234
- readonly kind: "station" | "bus" | "crossing" | "level-crossing";
240
+ readonly kind: "station" | "bus" | "ferry" | "crossing" | "level-crossing";
235
241
  /** Station/crossing id, used to remember a served stop. */
236
242
  readonly id: string;
237
243
  /** Stations: dwell time in seconds (default: a seeded 20–40 s). */
@@ -388,7 +394,7 @@ interface TileDrafts {
388
394
  declare function featureDrafts(input: TileDraftInput, options: FeatureDraftOptions): TileDrafts;
389
395
  /** POIs in world metres, filtered to the kinds agents care about. */
390
396
  interface WorldPoi {
391
- kind: "station" | "tram_stop" | "bus_stop" | "traffic_signals" | "give_way" | "crossing" | "aerodrome";
397
+ kind: "ferry_terminal" | "station" | "tram_stop" | "bus_stop" | "traffic_signals" | "give_way" | "crossing" | "aerodrome";
392
398
  x: number;
393
399
  z: number;
394
400
  name?: string;
@@ -402,7 +408,7 @@ declare const TRANSPORT_NETWORK_FORMAT: "molen/transport-network@1";
402
408
  type TransportNetworkPoint = [number, number] | [number, number, number];
403
409
  interface TransportNetworkWay {
404
410
  id?: string;
405
- class: "road" | "rail" | "path" | "air";
411
+ class: "road" | "rail" | "path" | "air" | "water";
406
412
  subclass?: string;
407
413
  points: TransportNetworkPoint[];
408
414
  oneway?: boolean;
@@ -417,7 +423,7 @@ interface TransportNetworkWay {
417
423
  interface TransportNetworkStation {
418
424
  id: string;
419
425
  at: [number, number];
420
- kind: "rail" | "bus";
426
+ kind: "rail" | "bus" | "ferry";
421
427
  dwell?: number;
422
428
  }
423
429
  interface TransportNetworkSignal {
@@ -539,7 +545,7 @@ interface TransportNetworkStats {
539
545
  }
540
546
  /** A script-added polyline. */
541
547
  interface AmbientPolyline {
542
- class: "road" | "rail" | "path";
548
+ class: "road" | "rail" | "path" | "water";
543
549
  subclass?: string;
544
550
  /** `[x, z]` or `[x, y, z]` points in scene metres. */
545
551
  points: ([number, number] | [number, number, number])[];
@@ -680,6 +686,8 @@ interface AmbientVehicleType {
680
686
  colors?: string[];
681
687
  /** Rail: cars per consist. */
682
688
  cars?: number;
689
+ /** Vessels: ferry service or general navigation channel. */
690
+ waterway?: "ferry" | "channel";
683
691
  }
684
692
  interface AmbientPedestrianType {
685
693
  preset: "human.adult" | "human.elder" | "human.child";
@@ -689,6 +697,7 @@ interface AmbientTypes {
689
697
  car: AmbientVehicleType[];
690
698
  train: AmbientVehicleType[];
691
699
  aircraft: AmbientVehicleType[];
700
+ boat: AmbientVehicleType[];
692
701
  pedestrian: AmbientPedestrianType[];
693
702
  }
694
703
  /** Common real-world car body colours, weighted by repetition. */
@@ -884,4 +893,4 @@ interface ObserverView {
884
893
  keep?: number;
885
894
  }
886
895
  //#endregion
887
- export { AMBIENT_AGENT_COMPONENT, AMBIENT_ENTITY, AMBIENT_KINDS, AMBIENT_OBSERVER_COMPONENT, AMBIENT_ROLE_COMPONENT, AMBIENT_STATE_COMPONENT, type AgentEnv, AmbientAgent, type AmbientAgentData, type AmbientAirCorridor, type AmbientBox, type AmbientBudget, type AmbientCapabilityOptions, type AmbientClassPolicy, type AmbientHandle, type AmbientKind, AmbientObserver, type AmbientObserverData, type AmbientObserverState, type AmbientOptions, type AmbientPedestrianType, type AmbientPolicy, type AmbientPolyline, AmbientRole, type AmbientRoleData, type AmbientRoleVisual, type AmbientSolid, type AmbientSpawnInfo, AmbientState, type AmbientStateData, type AmbientStats, type AmbientTemplate, type AmbientTileInput, type AmbientTypes, type AmbientVehicleType, CAR_COLORS, DEFAULT_POLICY, DEFAULT_TEMPLATES, DEFAULT_TYPES, type DeepPartial, type DriverParams, type EdgeDraft, type EdgeSpan, GRID_CELL, type JunctionArm, type JunctionControl, KIND_SPEED, LaneGrid, type LaneMovement, type LaneSample, type LaneStop, type ObserverView, type PlanarNode, type PlanarPiece, type PlanarResult, type RoadKind, type SignalColor, type SignalTiming, TRANSPORT_NETWORK_EXAMPLE, TRANSPORT_NETWORK_FORMAT, type TransportClass, type TransportCrossing, type TransportEdge, type TransportJunction, type TransportLane, TransportNetwork, type TransportNetworkAerodrome, type TransportNetworkDocument, type TransportNetworkOptions, type TransportNetworkPoint, type TransportNetworkSignal, type TransportNetworkStation, type TransportNetworkStats, type TransportNetworkWay, type TransportNode, type TransportRunway, type TurnKind, type WorldPoi, agentRotation, agentSample, allRed, ambientCapability, ambientOf, ambientScriptApi, chooseNext, classifyFeature, clipPolyline, edgeHeight, featureDrafts, fmix32, idmAcceleration, installAmbient, laneCoordinate, laneEdgeDistance, laneSample, mergePolicy, networkToDocument, pickWeighted, planarSplit, policyForBudget, pseudoAngle, registerAmbientSchema, sampleConnector, sampleLaneBody, signalColor, signalTiming, stepAgents, stoppingDistance, unit01, walkBack };
896
+ export { AMBIENT_AGENT_COMPONENT, AMBIENT_ENTITY, AMBIENT_KINDS, AMBIENT_OBSERVER_COMPONENT, AMBIENT_ROLE_COMPONENT, AMBIENT_STATE_COMPONENT, type AgentEnv, AmbientAgent, type AmbientAgentData, type AmbientAirCorridor, type AmbientBox, type AmbientBudget, type AmbientCapabilityOptions, type AmbientClassPolicy, type AmbientHandle, type AmbientKind, AmbientObserver, type AmbientObserverData, type AmbientObserverState, type AmbientOptions, type AmbientPedestrianType, type AmbientPolicy, type AmbientPolyline, AmbientRole, type AmbientRoleData, type AmbientRoleVisual, type AmbientSolid, type AmbientSpawnInfo, AmbientState, type AmbientStateData, type AmbientStats, type AmbientTemplate, type AmbientTileInput, type AmbientTypes, type AmbientVehicleType, CAR_COLORS, DEFAULT_POLICY, DEFAULT_TEMPLATES, DEFAULT_TYPES, type DeepPartial, type DriverParams, type EdgeDraft, type EdgeSpan, GRID_CELL, type JunctionArm, type JunctionControl, KIND_SPEED, LaneGrid, type LaneMovement, type LaneSample, type LaneStop, type ObserverView, type PlanarNode, type PlanarPiece, type PlanarResult, type RoadKind, type SignalColor, type SignalTiming, TRANSPORT_NETWORK_EXAMPLE, TRANSPORT_NETWORK_FORMAT, type TransportClass, type TransportCrossing, type TransportEdge, type TransportJunction, type TransportLane, TransportNetwork, type TransportNetworkAerodrome, type TransportNetworkDocument, type TransportNetworkOptions, type TransportNetworkPoint, type TransportNetworkSignal, type TransportNetworkStation, type TransportNetworkStats, type TransportNetworkWay, type TransportNode, type TransportRunway, type TurnKind, WILDLIFE_CELL_METERS, WILDLIFE_FAMILIES, WILDLIFE_TICK_RATE, type WildlifeAgent, type WildlifeBudget, type WildlifeChoice, type WildlifeFamily, type WildlifeHabitat, type WildlifeMotion, type WildlifeSpecies, type WildlifeWorld, type WorldPoi, agentRotation, agentSample, allRed, ambientCapability, ambientOf, ambientScriptApi, chooseNext, classifyFeature, clipPolyline, edgeHeight, featureDrafts, fmix32, idmAcceleration, installAmbient, laneCoordinate, laneEdgeDistance, laneSample, mergePolicy, networkToDocument, pickWeighted, planarSplit, policyForBudget, pseudoAngle, registerAmbientSchema, sampleConnector, sampleLaneBody, signalColor, signalTiming, stepAgents, stepWildlife, stoppingDistance, unit01, walkBack, wildlifeCandidates, wildlifeSpeciesSchema };