@adatechnology/game-interactables 0.10.0 → 0.11.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/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { CarryHands, Thumbnail, ItemControls } from '@adatechnology/game-contracts';
1
+ import { CarryHands, Thumbnail, ItemControls, ItemControlsHost, ReachedItem } from '@adatechnology/game-contracts';
2
2
  import { BodyId, SeamWorld, JointId, Vec3 as Vec3$1, Quat } from '@adatechnology/game-physics';
3
3
 
4
4
  /** A movable part (door, drawer, lid) moved by a physics engine instead of by `t` stepping at `Motion.speed`. */
@@ -433,7 +433,63 @@ type UseSpec = {
433
433
  basin: string;
434
434
  kind: 'urine' | 'feces';
435
435
  label: string;
436
- };
436
+ } | WashUseSpec | DrinkUseSpec;
437
+ /**
438
+ * What a use needs at hand (`WashUseSpec.needs`, `DrinkUseSpec.needs`): each entry is one thing it needs, a catalogue id or a list of ids any of which does (`['cup',
439
+ * 'wine_glass']`). The host finds it in the hand or within reach (`ItemControlsHost.itemAt`).
440
+ */
441
+ type UseNeed = string | readonly string[];
442
+ /** The dishes a sink washes (`WashUseSpec.dishes`): the catalogue ids that are dishes, the basin they lie dirty in, and where they go clean (the drainboard). */
443
+ interface WashDishesSpec {
444
+ readonly ids: readonly string[];
445
+ readonly basin: string;
446
+ /** Object-local spots on the drainboard, one per dish washed in turn (the last is reused when there are more dishes). */
447
+ readonly rack: readonly Vec3[];
448
+ }
449
+ /**
450
+ * Washing at a fixture (`do: 'wash'`): the fixture's water is opened (`opensFixture`), a dose is taken out of the consumable it needs (`dose`: detergent, soap), the
451
+ * thing is scrubbed into foam with the hand use `clip`, the running water rinses the foam off (as fast as the fixture runs) and the fixture is closed again. `surface`
452
+ * is what is washed: a part of the body (`hands`, `hair`, `body`, `mouth`) or, with `dishes`, each dirty dish in the basin, which ends clean on the rack.
453
+ */
454
+ interface WashUseSpec {
455
+ readonly id: string;
456
+ readonly do: 'wash';
457
+ readonly fixture: string;
458
+ readonly surface: string;
459
+ readonly clip: string;
460
+ readonly label: string;
461
+ readonly needs?: readonly UseNeed[];
462
+ /** The need a dose is taken out of (an index into `needs`), and how much (the item's usual dose when left out). */
463
+ readonly dose?: {
464
+ readonly need: number;
465
+ readonly amount?: number;
466
+ };
467
+ /** The use opens the fixture itself and closes it at the end. Default true. False: the water is the player's to open and close (a shower), the use never shuts it. */
468
+ readonly opensFixture?: boolean;
469
+ /** The use is only offered while the fixture runs (`needs_running` otherwise): washing under a shower already on. */
470
+ readonly requiresFlowing?: boolean;
471
+ readonly dishes?: WashDishesSpec;
472
+ /** Seconds of scrubbing per thing washed. Default `WASH_SCRUB_SECONDS`. */
473
+ readonly scrubSeconds?: number;
474
+ }
475
+ /**
476
+ * Drinking from a fixture (`do: 'drink'`): the hand takes the vessel it needs (a cup in the hand or within reach), holds it under the fixture while it runs until it is
477
+ * nearly full (`fillClip`), the fixture is closed, the vessel is drunk from (`clip`) and put back where it was.
478
+ */
479
+ interface DrinkUseSpec {
480
+ readonly id: string;
481
+ readonly do: 'drink';
482
+ readonly fixture: string;
483
+ readonly needs: readonly UseNeed[];
484
+ readonly clip: string;
485
+ readonly label: string;
486
+ /** The hand use while it fills. Default `fill_cup`. */
487
+ readonly fillClip?: string;
488
+ /** Default true. */
489
+ readonly opensFixture?: boolean;
490
+ /** Litres drunk at most (what is left stays in the vessel). Default `DRINK_LITRES`. */
491
+ readonly litres?: number;
492
+ }
437
493
  interface MirrorSpec {
438
494
  id: string;
439
495
  center: Vec3;
@@ -946,6 +1002,7 @@ interface WorldState {
946
1002
  defaultTank: string | null;
947
1003
  }
948
1004
 
1005
+ declare const FLOW_DEFAULTS: Readonly<Record<string, number>>;
949
1006
  declare function createWorld(options?: WorldOptions): World;
950
1007
 
951
1008
  /** FNV-1a hash of a string to a 32-bit unsigned integer. */
@@ -1154,6 +1211,19 @@ type WireRunsParams<THolder> = {
1154
1211
  /** The runs of a wire by what holds it, in order along it; two runs that follow each other share the point half way between their last and first readings. */
1155
1212
  declare function wireRuns<THolder>(params: WireRunsParams<THolder>): WireRun<THolder>[];
1156
1213
 
1214
+ /** An axis-aligned box as [min x, min y, min z, max x, max y, max z], metres. */
1215
+ type CastBox = readonly number[];
1216
+ /** Metres a collar, a foot or a cap may stand out of the member, each side. */
1217
+ declare const COLLAR_REACH = 0.03;
1218
+ /** Metres a foot or a cap may stand apart from the end of the member (the seam between two primitives drawn end to end). */
1219
+ declare const END_GAP = 0.005;
1220
+ /** A collar drawn round the stretch: most of its height on it (a band on the seam of two goes with the one it is mostly on). */
1221
+ declare function wrapsMember(member: CastBox, collar: CastBox): boolean;
1222
+ /** A foot under the stretch or a cap over it, no taller than it. */
1223
+ declare function endsMember(member: CastBox, end: CastBox): boolean;
1224
+ /** Whether `other` is cast with the stretch `member`: a collar round it, or a foot or a cap on its end. */
1225
+ declare function castWithMember(member: CastBox, other: CastBox): boolean;
1226
+
1157
1227
  /**
1158
1228
  * What an object does with the player's hand or on its own time (`ObjectSpec.uses`), for `createObjectControls`: a device's program that runs for its seconds, what
1159
1229
  * the hand holds put inside when it fits, a container emptied, a bowl filled from the hand, a basin soiled and washed by its flush. The rules are the data's: the
@@ -1172,6 +1242,8 @@ interface UsesState {
1172
1242
  readonly device: string;
1173
1243
  readonly left: number;
1174
1244
  } | null;
1245
+ /** The use at the water running now (`wash`, `drink`), by id. */
1246
+ readonly routine: string | null;
1175
1247
  }
1176
1248
 
1177
1249
  /**
@@ -1212,4 +1284,63 @@ declare function createObjectControls(options: ObjectControlsOptions): ObjectCon
1212
1284
  /** Whether a thing of `size` (any turn of it) goes into a box of `half` sizes: each of its sides, longest first, against the box's, longest first. */
1213
1285
  declare function fitsInVolume(size: readonly [number, number, number], half: Vec3): boolean;
1214
1286
 
1215
- export { type Action, type ActiveEmitter, type BasinSpec, type BowlSpec, type BurnerSpec, CONTROLLED_OBJECT, type Chain, type ChainSpec, type ColliderOptions, type ColliderSpec, type ContainerSpec, type DamageKind, type DamageSpec, type DestructionDelegate, type DestructionJoint, type DeviceKind, type DeviceSpec, type EmitterBowl, type EmitterKind, type EmitterSpec, type EnginePartDriver, type EnginePartOptions, type EnginePartPhysics, FLUSH_RUN_SECONDS, type FixtureEmitters, type FixtureKind, type FixtureSpec, type FuelSourceSpec, type HangTailParams, type Interactable, type InteractablesLocale, type InteractionSpec, type ItemCatalog, type ItemDef, type ItemStack, type LootEntry, type LootTable, type LootTables, type MirrorSpec, type Motion, type MotionKind, type ObjectControls, type ObjectControlsOptions, type ObjectControlsState, type ObjectSpec, type PartDestruction, type PartDriver, type PartPhysics, type PartSpec, type Pose, type Rect, type RunningEmitter, type SeatPose, type SeatResult, type SeatSpec, type SlotSpec, type SocketSpec, type SoftDriver, type SoftSpec, type Soil, type SolveSpanParams, type Span, type SpanMaterial, type SpanShape, type Strings, type SwitchSpec, type TankSpec, type TargetOptions, type Transform, type UseSpec, type UsesState, type Vec3, type WireRun, type WireRunsParams, type World, type WorldCollider, type WorldEvent, type WorldObject, type WorldOptions, type WorldState, alignY, buildChain, chainPoints, createEnginePartPhysics, createFixtureEmitters, createObjectControls, createWorld, disposeChain, fitsInVolume, fitsSize, fitsSlot, format, generateLoot, hangTail, hashString, localToWorld, locales, mergeColliders, pickLocale, polylineLength, poseOf, resolveStrings, rng, rotY, rotateAxis, solveSpan, spanStrength, wireRuns, worldToLocal };
1287
+ /**
1288
+ * The uses at a fixture's water (`do: 'wash'` and `do: 'drink'` of `ObjectSpec.uses`): whether they can run now (the things they need at hand, dishes dirty in the
1289
+ * basin, a vessel to drink from) and the routine each runs over its seconds once started: open the water, scrub foam in, let the water rinse it off, close the water;
1290
+ * or fill the vessel under the stream, close the water, drink and put the vessel back. Pure: the host lends the hand, the items, the body's hand uses and the foam
1291
+ * (`ItemControlsHost`); the water is the object's own fixture in its interactables world, so it runs as fast as the fixture does and stops when its tank is dry.
1292
+ */
1293
+
1294
+ /** Seconds of scrubbing per thing washed, when the use does not say. */
1295
+ declare const WASH_SCRUB_SECONDS = 3;
1296
+ /** Litres drunk at most from a vessel filled at a tap: a glass of water. */
1297
+ declare const DRINK_LITRES = 0.25;
1298
+ /** A vessel filled at a tap is stopped this full (share of what it takes). */
1299
+ declare const FILL_SHARE = 0.85;
1300
+ /** Litres a mouth drinks per second. */
1301
+ declare const DRINK_LPS = 0.06;
1302
+ /** Seconds the hand takes to reach the tap's lever, and to put a thing down. */
1303
+ declare const REACH_SECONDS = 0.6;
1304
+ /** Seconds the water may take to start running after the lever opens (the fixture flows from the next step) before the tap counts as dry. */
1305
+ declare const DRY_SECONDS = 0.5;
1306
+ type SinkUseSpec = WashUseSpec | DrinkUseSpec;
1307
+ type SinkVerdict = {
1308
+ readonly available: true;
1309
+ } | {
1310
+ readonly available: false;
1311
+ readonly reason: string;
1312
+ readonly vars?: Record<string, string>;
1313
+ };
1314
+ /** What a routine says when it ends: a locale key and its words. */
1315
+ interface RoutineEnd {
1316
+ readonly key: string;
1317
+ readonly ok: boolean;
1318
+ readonly vars?: Record<string, string>;
1319
+ }
1320
+ /** A use at the water running over its seconds. `step` answers the end once it is over. */
1321
+ interface SinkRoutine {
1322
+ readonly use: string;
1323
+ step(dt: number): RoutineEnd | null;
1324
+ }
1325
+ interface SinkRoutines {
1326
+ start(use: SinkUseSpec, host: ItemControlsHost): SinkRoutine;
1327
+ }
1328
+ interface SinkUsesOptions {
1329
+ readonly spec: ObjectSpec;
1330
+ readonly world: World;
1331
+ readonly objectId: string;
1332
+ }
1333
+ /** The item of each need, or the ids of the first need nothing answers. */
1334
+ declare function findNeeds(needs: readonly UseNeed[], host: ItemControlsHost): {
1335
+ readonly items: readonly ReachedItem[];
1336
+ readonly missing?: readonly string[];
1337
+ };
1338
+ /** The dirty dishes lying in the use's basin. */
1339
+ declare function dirtyDishes(use: WashUseSpec, spec: ObjectSpec, host: ItemControlsHost): readonly ReachedItem[];
1340
+ /** Whether a use at the water can run now, and why not (a locale key with its words). `flowing`: the use's fixture runs now. */
1341
+ declare function sinkVerdict(use: SinkUseSpec, spec: ObjectSpec, host: ItemControlsHost, flowing: boolean): SinkVerdict;
1342
+ /** Litres per second the fixture runs fully open. */
1343
+ declare const fixtureFlowLps: (fixture: FixtureSpec | undefined) => number;
1344
+ declare function createSinkRoutines(options: SinkUsesOptions): SinkRoutines;
1345
+
1346
+ export { type Action, type ActiveEmitter, type BasinSpec, type BowlSpec, type BurnerSpec, COLLAR_REACH, CONTROLLED_OBJECT, type CastBox, type Chain, type ChainSpec, type ColliderOptions, type ColliderSpec, type ContainerSpec, DRINK_LITRES, DRINK_LPS, DRY_SECONDS, type DamageKind, type DamageSpec, type DestructionDelegate, type DestructionJoint, type DeviceKind, type DeviceSpec, type DrinkUseSpec, END_GAP, type EmitterBowl, type EmitterKind, type EmitterSpec, type EnginePartDriver, type EnginePartOptions, type EnginePartPhysics, FILL_SHARE, FLOW_DEFAULTS, FLUSH_RUN_SECONDS, type FixtureEmitters, type FixtureKind, type FixtureSpec, type FuelSourceSpec, type HangTailParams, type Interactable, type InteractablesLocale, type InteractionSpec, type ItemCatalog, type ItemDef, type ItemStack, type LootEntry, type LootTable, type LootTables, type MirrorSpec, type Motion, type MotionKind, type ObjectControls, type ObjectControlsOptions, type ObjectControlsState, type ObjectSpec, type PartDestruction, type PartDriver, type PartPhysics, type PartSpec, type Pose, REACH_SECONDS, type Rect, type RoutineEnd, type RunningEmitter, type SeatPose, type SeatResult, type SeatSpec, type SinkRoutine, type SinkRoutines, type SinkUseSpec, type SinkUsesOptions, type SinkVerdict, type SlotSpec, type SocketSpec, type SoftDriver, type SoftSpec, type Soil, type SolveSpanParams, type Span, type SpanMaterial, type SpanShape, type Strings, type SwitchSpec, type TankSpec, type TargetOptions, type Transform, type UseNeed, type UseSpec, type UsesState, type Vec3, WASH_SCRUB_SECONDS, type WashDishesSpec, type WashUseSpec, type WireRun, type WireRunsParams, type World, type WorldCollider, type WorldEvent, type WorldObject, type WorldOptions, type WorldState, alignY, buildChain, castWithMember, chainPoints, createEnginePartPhysics, createFixtureEmitters, createObjectControls, createSinkRoutines, createWorld, dirtyDishes, disposeChain, endsMember, findNeeds, fitsInVolume, fitsSize, fitsSlot, fixtureFlowLps, format, generateLoot, hangTail, hashString, localToWorld, locales, mergeColliders, pickLocale, polylineLength, poseOf, resolveStrings, rng, rotY, rotateAxis, sinkVerdict, solveSpan, spanStrength, wireRuns, worldToLocal, wrapsMember };
@@ -21,19 +21,34 @@ var GameInteractables = (() => {
21
21
  // src/index.ts
22
22
  var index_exports = {};
23
23
  __export(index_exports, {
24
+ COLLAR_REACH: () => COLLAR_REACH,
24
25
  CONTROLLED_OBJECT: () => CONTROLLED_OBJECT,
26
+ DRINK_LITRES: () => DRINK_LITRES,
27
+ DRINK_LPS: () => DRINK_LPS,
28
+ DRY_SECONDS: () => DRY_SECONDS,
29
+ END_GAP: () => END_GAP,
30
+ FILL_SHARE: () => FILL_SHARE,
31
+ FLOW_DEFAULTS: () => FLOW_DEFAULTS,
25
32
  FLUSH_RUN_SECONDS: () => FLUSH_RUN_SECONDS,
33
+ REACH_SECONDS: () => REACH_SECONDS,
34
+ WASH_SCRUB_SECONDS: () => WASH_SCRUB_SECONDS,
26
35
  alignY: () => alignY,
27
36
  buildChain: () => buildChain,
37
+ castWithMember: () => castWithMember,
28
38
  chainPoints: () => chainPoints,
29
39
  createEnginePartPhysics: () => createEnginePartPhysics,
30
40
  createFixtureEmitters: () => createFixtureEmitters,
31
41
  createObjectControls: () => createObjectControls,
42
+ createSinkRoutines: () => createSinkRoutines,
32
43
  createWorld: () => createWorld,
44
+ dirtyDishes: () => dirtyDishes,
33
45
  disposeChain: () => disposeChain,
46
+ endsMember: () => endsMember,
47
+ findNeeds: () => findNeeds,
34
48
  fitsInVolume: () => fitsInVolume,
35
49
  fitsSize: () => fitsSize,
36
50
  fitsSlot: () => fitsSlot,
51
+ fixtureFlowLps: () => fixtureFlowLps,
37
52
  format: () => format,
38
53
  generateLoot: () => generateLoot,
39
54
  hangTail: () => hangTail,
@@ -48,10 +63,12 @@ var GameInteractables = (() => {
48
63
  rng: () => rng,
49
64
  rotY: () => rotY,
50
65
  rotateAxis: () => rotateAxis,
66
+ sinkVerdict: () => sinkVerdict,
51
67
  solveSpan: () => solveSpan,
52
68
  spanStrength: () => spanStrength,
53
69
  wireRuns: () => wireRuns,
54
- worldToLocal: () => worldToLocal
70
+ worldToLocal: () => worldToLocal,
71
+ wrapsMember: () => wrapsMember
55
72
  });
56
73
 
57
74
  // src/fixture-emitters.ts
@@ -276,7 +293,19 @@ var GameInteractables = (() => {
276
293
  done_program_stop: "{name} stopped",
277
294
  done_relieve_urine: "You peed in {name}",
278
295
  done_relieve_feces: "You pooed in {name}",
279
- done_clean: "{name} flushed clean"
296
+ done_clean: "{name} flushed clean",
297
+ "use.wash_dishes": "Wash the dishes",
298
+ "use.drink_water": "Drink water",
299
+ busy: "Already in use",
300
+ needs_running: "Turn the water on first",
301
+ needs_item: "You need {need}",
302
+ item_spent: "{item} is empty",
303
+ no_dirty_dishes: "No dirty dishes in the sink",
304
+ started_wash: "{label}\u2026",
305
+ started_drink: "{label}\u2026",
306
+ done_wash: "Washed and rinsed",
307
+ done_wash_dishes: "Dishes washed: {n} on the rack",
308
+ done_drink: "You drank {litres} l of water"
280
309
  },
281
310
  "pt-BR": {
282
311
  "prompt.open": "Abrir {name}",
@@ -329,7 +358,19 @@ var GameInteractables = (() => {
329
358
  done_program_stop: "{name} parou",
330
359
  done_relieve_urine: "Voc\xEA fez xixi em {name}",
331
360
  done_relieve_feces: "Voc\xEA fez coc\xF4 em {name}",
332
- done_clean: "Descarga dada: {name} limpo"
361
+ done_clean: "Descarga dada: {name} limpo",
362
+ "use.wash_dishes": "Lavar a lou\xE7a",
363
+ "use.drink_water": "Beber \xE1gua",
364
+ busy: "J\xE1 est\xE1 em uso",
365
+ needs_running: "Abra a \xE1gua primeiro",
366
+ needs_item: "Precisa de {need}",
367
+ item_spent: "{item} acabou",
368
+ no_dirty_dishes: "N\xE3o h\xE1 lou\xE7a suja na pia",
369
+ started_wash: "{label}\u2026",
370
+ started_drink: "{label}\u2026",
371
+ done_wash: "Lavado e enxaguado",
372
+ done_wash_dishes: "Lou\xE7a lavada: {n} no escorredor",
373
+ done_drink: "Voc\xEA bebeu {litres} l de \xE1gua"
333
374
  }
334
375
  };
335
376
  function pickLocale(locale) {
@@ -2490,6 +2531,29 @@ var GameInteractables = (() => {
2490
2531
  return runs;
2491
2532
  }
2492
2533
 
2534
+ // src/cast-with-member.ts
2535
+ var COLLAR_REACH = 0.03;
2536
+ var END_GAP = 5e-3;
2537
+ function centredOn(member, other) {
2538
+ for (const k of [0, 2]) {
2539
+ if (other[k] < member[k] - COLLAR_REACH || other[k + 3] > member[k + 3] + COLLAR_REACH) return false;
2540
+ if (Math.abs((other[k] + other[k + 3]) / 2 - (member[k] + member[k + 3]) / 2) > COLLAR_REACH) return false;
2541
+ }
2542
+ return true;
2543
+ }
2544
+ function wrapsMember(member, collar) {
2545
+ const overlap2 = Math.min(collar[4], member[4]) - Math.max(collar[1], member[1]);
2546
+ return overlap2 >= (collar[4] - collar[1]) / 2 && centredOn(member, collar);
2547
+ }
2548
+ function endsMember(member, end) {
2549
+ const under = Math.abs(end[4] - member[1]) <= END_GAP;
2550
+ const over = Math.abs(end[1] - member[4]) <= END_GAP;
2551
+ return (under || over) && end[4] - end[1] <= member[4] - member[1] && centredOn(member, end);
2552
+ }
2553
+ function castWithMember(member, other) {
2554
+ return wrapsMember(member, other) || endsMember(member, other);
2555
+ }
2556
+
2493
2557
  // src/fits-volume.ts
2494
2558
  function fitsInVolume(size, half) {
2495
2559
  const thing = [...size].sort((a, b) => b - a);
@@ -2497,6 +2561,183 @@ var GameInteractables = (() => {
2497
2561
  return thing.every((side, i) => side <= (room[i] ?? 0));
2498
2562
  }
2499
2563
 
2564
+ // src/sink-uses.ts
2565
+ var WASH_SCRUB_SECONDS = 3;
2566
+ var DRINK_LITRES = 0.25;
2567
+ var FILL_SHARE = 0.85;
2568
+ var DRINK_LPS = 0.06;
2569
+ var REACH_SECONDS = 0.6;
2570
+ var DRY_SECONDS = 0.5;
2571
+ var SCRUBBED_DIRT = 0.15;
2572
+ var YES = { available: true };
2573
+ var idsOf = (need) => typeof need === "string" ? [need] : need;
2574
+ function findNeeds(needs, host) {
2575
+ const items = [];
2576
+ for (const need of needs) {
2577
+ const item = host.itemAt?.(idsOf(need)) ?? null;
2578
+ if (!item) return { items, missing: idsOf(need) };
2579
+ items.push(item);
2580
+ }
2581
+ return { items };
2582
+ }
2583
+ function dirtyDishes(use, spec, host) {
2584
+ const dishes = use.dishes;
2585
+ const basin = dishes ? (spec.basins ?? []).find((b) => b.id === dishes.basin) : void 0;
2586
+ if (!dishes || !basin) return [];
2587
+ return (host.itemsInside?.(dishes.ids, basin.from, basin.to) ?? []).filter((item) => (item.dirt ?? 0) > 0);
2588
+ }
2589
+ function sinkVerdict(use, spec, host, flowing) {
2590
+ if (use.do === "wash" && use.requiresFlowing && !flowing) return { available: false, reason: "needs_running" };
2591
+ const found = findNeeds(use.needs ?? [], host);
2592
+ if (found.missing) return { available: false, reason: "needs_item", vars: { need: found.missing[0] ?? "" } };
2593
+ if (use.do === "drink") return YES;
2594
+ const dosed = use.dose ? found.items[use.dose.need] : void 0;
2595
+ if (dosed && (dosed.remaining ?? 1) <= 0) return { available: false, reason: "item_spent", vars: { item: dosed.name } };
2596
+ if (use.dishes && dirtyDishes(use, spec, host).length === 0) return { available: false, reason: "no_dirty_dishes" };
2597
+ return YES;
2598
+ }
2599
+ var fixtureFlowLps = (fixture) => fixture ? (fixture.flow ?? FLOW_DEFAULTS[fixture.kind] ?? 6) / 60 : 0;
2600
+ function runPhases(phases) {
2601
+ let index = 0;
2602
+ return (dt) => {
2603
+ if (index < phases.length && phases[index]?.(dt)) index++;
2604
+ return index >= phases.length;
2605
+ };
2606
+ }
2607
+ function wait(seconds) {
2608
+ let left = seconds;
2609
+ return (dt) => (left -= dt) <= 0;
2610
+ }
2611
+ function placePhase(host, item, spot) {
2612
+ return () => {
2613
+ if (spot) host.placeItem?.(item.objectId, [spot[0], spot[1], spot[2]]);
2614
+ return true;
2615
+ };
2616
+ }
2617
+ function createSinkRoutines(options) {
2618
+ const { spec, world, objectId } = options;
2619
+ const fixtureOf = (id) => (spec.fixtures ?? []).find((f) => f.id === id);
2620
+ const flowing = (use) => world.water.isFlowing(objectId, use.fixture);
2621
+ const water = (use) => flowing(use) ? fixtureFlowLps(fixtureOf(use.fixture)) : 0;
2622
+ const waterOf = (use) => {
2623
+ let dry = 0;
2624
+ return (dt) => {
2625
+ const flow = water(use);
2626
+ dry = flow > 0 ? 0 : dry + dt;
2627
+ return dry > DRY_SECONDS ? null : flow;
2628
+ };
2629
+ };
2630
+ const tapPhases = (use) => {
2631
+ let opened = false;
2632
+ const reach = wait(REACH_SECONDS);
2633
+ return {
2634
+ open: (dt) => {
2635
+ if (opened || use.opensFixture === false || flowing(use)) return true;
2636
+ if (!reach(dt)) return false;
2637
+ opened = world.setFixture(objectId, use.fixture, true);
2638
+ return true;
2639
+ },
2640
+ close: () => {
2641
+ if (opened) world.setFixture(objectId, use.fixture, false);
2642
+ return true;
2643
+ }
2644
+ };
2645
+ };
2646
+ const scrubAndRinse = (use, host, target, fail) => {
2647
+ const item = typeof target === "string" ? void 0 : target;
2648
+ const id = item?.objectId ?? target;
2649
+ const seconds = use.scrubSeconds ?? WASH_SCRUB_SECONDS;
2650
+ const dirt = item?.dirt ?? 0;
2651
+ let scrubbed = -1;
2652
+ const scrub = (dt) => {
2653
+ if (scrubbed < 0) {
2654
+ scrubbed = 0;
2655
+ host.playUse?.(use.clip, item?.objectId);
2656
+ }
2657
+ scrubbed = Math.min(seconds, scrubbed + dt);
2658
+ host.lather?.(id, dt / seconds);
2659
+ if (dirt > 0) host.setDirt?.(id, dirt - (dirt - Math.min(dirt, SCRUBBED_DIRT)) * (scrubbed / seconds));
2660
+ return scrubbed >= seconds;
2661
+ };
2662
+ const running = waterOf(use);
2663
+ const rinse = (dt) => {
2664
+ const flow = running(dt);
2665
+ if (flow === null) {
2666
+ fail({ key: "no_water", ok: false });
2667
+ return true;
2668
+ }
2669
+ if (flow <= 0 || (host.rinse?.(id, flow, dt) ?? 0) > 0) return false;
2670
+ if (dirt > 0) host.setDirt?.(id, 0);
2671
+ return true;
2672
+ };
2673
+ return [scrub, rinse];
2674
+ };
2675
+ const startWash = (use, host) => {
2676
+ const { items } = findNeeds(use.needs ?? [], host);
2677
+ let end = null;
2678
+ const fail = (reason) => {
2679
+ end ?? (end = reason);
2680
+ };
2681
+ const tap = tapPhases(use);
2682
+ const dosed = use.dose ? items[use.dose.need] : void 0;
2683
+ const dose = () => {
2684
+ if (dosed && host.takeDose?.(dosed.objectId, use.dose?.amount).taken === 0) fail({ key: "item_spent", ok: false, vars: { item: dosed.name } });
2685
+ return true;
2686
+ };
2687
+ const dishes = use.dishes ? dirtyDishes(use, spec, host) : [];
2688
+ const rack = use.dishes?.rack ?? [];
2689
+ const work = use.dishes ? dishes.flatMap((dish, index) => [...scrubAndRinse(use, host, dish, fail), placePhase(host, dish, rack[Math.min(index, rack.length - 1)])]) : scrubAndRinse(use, host, use.surface, fail);
2690
+ const guarded = work.map((phase) => (dt) => end !== null || phase(dt));
2691
+ const run = runPhases([tap.open, dose, ...guarded, tap.close]);
2692
+ const done = use.dishes ? { key: "done_wash_dishes", ok: true, vars: { n: String(dishes.length) } } : { key: "done_wash", ok: true, vars: { surface: use.surface } };
2693
+ return { use: use.id, step: (dt) => run(dt) ? end ?? done : null };
2694
+ };
2695
+ const startDrink = (use, host, vessel) => {
2696
+ const tap = tapPhases(use);
2697
+ const want = Math.min(use.litres ?? DRINK_LITRES, (vessel.liquid?.capacity ?? DRINK_LITRES) * FILL_SHARE);
2698
+ let filled = vessel.liquid?.kind === "water" ? vessel.liquid.litres : 0;
2699
+ let drunk = 0;
2700
+ let end = null;
2701
+ const take = () => {
2702
+ if (vessel.where !== "hand" && host.holdItem?.(vessel.objectId) === false) end = { key: "needs_item", ok: false, vars: { need: vessel.itemId } };
2703
+ else host.playUse?.(use.fillClip ?? "fill_cup", vessel.objectId);
2704
+ return true;
2705
+ };
2706
+ const running = waterOf(use);
2707
+ const fill = (dt) => {
2708
+ if (end) return true;
2709
+ const flow = running(dt);
2710
+ if (flow === null) {
2711
+ end = { key: "no_water", ok: false };
2712
+ return true;
2713
+ }
2714
+ if (flow <= 0) return false;
2715
+ const took = host.fillItem?.(vessel.objectId, "water", Math.min(flow * dt, want - filled)) ?? 0;
2716
+ filled += took;
2717
+ return filled >= want - 1e-6 || took <= 0;
2718
+ };
2719
+ let sipping = false;
2720
+ const drink = (dt) => {
2721
+ if (end) return true;
2722
+ if (!sipping) sipping = host.playUse?.(use.clip, vessel.objectId) ?? true;
2723
+ const sip = host.drinkItem?.(vessel.objectId, Math.min(DRINK_LPS * dt, filled - drunk)) ?? 0;
2724
+ drunk += sip;
2725
+ return drunk >= filled - 1e-6 || sip <= 0;
2726
+ };
2727
+ const giveBack = vessel.where === "reach" ? placePhase(host, vessel, vessel.at) : () => true;
2728
+ const run = runPhases([take, tap.open, fill, tap.close, drink, wait(REACH_SECONDS), giveBack]);
2729
+ return { use: use.id, step: (dt) => run(dt) ? end ?? { key: "done_drink", ok: true, vars: { litres: drunk.toFixed(2) } } : null };
2730
+ };
2731
+ return {
2732
+ start(use, host) {
2733
+ if (use.do === "wash") return startWash(use, host);
2734
+ const vessel = findNeeds(use.needs, host).items[0];
2735
+ if (!vessel) return { use: use.id, step: () => ({ key: "needs_item", ok: false, vars: { need: idsOf(use.needs[0] ?? "")[0] ?? "" } }) };
2736
+ return startDrink(use, host, vessel);
2737
+ }
2738
+ };
2739
+ }
2740
+
2500
2741
  // src/object-uses.ts
2501
2742
  var OPEN = 0.5;
2502
2743
  var PREFIX = "use.";
@@ -2506,7 +2747,7 @@ var GameInteractables = (() => {
2506
2747
  return `${Math.floor(s / 60)}:${String(s % 60).padStart(2, "0")}`;
2507
2748
  };
2508
2749
  var accepts = (bowl, hand) => (bowl.accepts ?? []).some((id) => hand.itemId === id || hand.itemId.endsWith(`_${id}`));
2509
- var YES = { available: true };
2750
+ var YES2 = { available: true };
2510
2751
  var no = (reason) => ({ available: false, reason });
2511
2752
  function createUses(options) {
2512
2753
  const { spec, world, objectId } = options;
@@ -2518,6 +2759,8 @@ var GameInteractables = (() => {
2518
2759
  const cleans = new Map((spec.fixtures ?? []).flatMap((f) => f.cleans ? [[f.id, f.cleans]] : []));
2519
2760
  let program = null;
2520
2761
  let lastHost = null;
2762
+ const sinkRoutines = createSinkRoutines({ spec, world, objectId });
2763
+ let routine = null;
2521
2764
  const typeKey = `type.${spec.type}`;
2522
2765
  const name = () => {
2523
2766
  const text = world.t(typeKey);
@@ -2529,15 +2772,15 @@ var GameInteractables = (() => {
2529
2772
  switch (use.do) {
2530
2773
  case "program":
2531
2774
  if (!world.power.isPowered(objectId, use.device)) return no("no_power");
2532
- return use.access && host.partOpening(use.access) >= OPEN ? no("needs_closed") : YES;
2775
+ return use.access && host.partOpening(use.access) >= OPEN ? no("needs_closed") : YES2;
2533
2776
  case "put_in": {
2534
2777
  const c = containers.get(use.container);
2535
2778
  if (!hand) return no("hand_empty");
2536
2779
  if (!c || !accessOpen(host, c.access)) return no("requires_open");
2537
- return fitsInVolume(hand.size, c.volume.half) ? YES : no("not_fit");
2780
+ return fitsInVolume(hand.size, c.volume.half) ? YES2 : no("not_fit");
2538
2781
  }
2539
2782
  case "empty":
2540
- return accessOpen(host, containers.get(use.container)?.access) ? YES : no("requires_open");
2783
+ return accessOpen(host, containers.get(use.container)?.access) ? YES2 : no("requires_open");
2541
2784
  case "fill": {
2542
2785
  const bowl = bowls.get(use.bowl);
2543
2786
  if (!bowl) return no("empty");
@@ -2545,12 +2788,23 @@ var GameInteractables = (() => {
2545
2788
  if (!hand) return no("hand_empty");
2546
2789
  if (bowl.holds === "water" && hand.liquid?.kind === "water" && hand.liquid.closed) return no("requires_open");
2547
2790
  const fits = bowl.holds === "water" ? hand.liquid?.kind === "water" && hand.liquid.litres > 0 : accepts(bowl, hand);
2548
- return fits ? YES : no("not_accepted");
2791
+ return fits ? YES2 : no("not_accepted");
2549
2792
  }
2550
2793
  case "relieve":
2551
- return YES;
2794
+ return YES2;
2795
+ case "wash":
2796
+ case "drink":
2797
+ return routine ? no("busy") : sinkVerdict(use, spec, host, world.water.isFlowing(objectId, use.fixture));
2552
2798
  }
2553
2799
  };
2800
+ const itemName = (id) => {
2801
+ const text = world.t(`item.${id}`);
2802
+ return text === `item.${id}` ? id.replace(/_/g, " ") : text;
2803
+ };
2804
+ const reasonOf = (v, use, host) => {
2805
+ const words = { ...textVars(use, host), ...v.vars };
2806
+ return world.t(v.reason, words.need ? { ...words, need: itemName(words.need) } : words);
2807
+ };
2554
2808
  const textVars = (use, host) => ({
2555
2809
  name: name(),
2556
2810
  item: host.hand()?.name ?? "",
@@ -2583,6 +2837,10 @@ var GameInteractables = (() => {
2583
2837
  soil.set(use.basin, SOIL_RANK[use.kind] > SOIL_RANK[now] ? use.kind : now);
2584
2838
  return { ok: true, text: world.t(`done_relieve_${use.kind}`, vars) };
2585
2839
  }
2840
+ case "wash":
2841
+ case "drink":
2842
+ routine = sinkRoutines.start(use, host);
2843
+ return { ok: true, text: world.t(`started_${use.do}`, { ...vars, label: world.t(use.label, vars) }) };
2586
2844
  }
2587
2845
  };
2588
2846
  const fill = (bowl, host, vars) => {
@@ -2597,6 +2855,13 @@ var GameInteractables = (() => {
2597
2855
  program = null;
2598
2856
  return world.t("done_program_stop", { name: name() });
2599
2857
  };
2858
+ const stepRoutine = (dt) => {
2859
+ const end = routine?.step(dt);
2860
+ if (!end) return;
2861
+ routine = null;
2862
+ const words = end.vars?.need ? { ...end.vars, need: itemName(end.vars.need) } : end.vars;
2863
+ lastHost?.say(world.t(end.key, { name: name(), ...words }));
2864
+ };
2600
2865
  const visible = (use) => use.do !== "program" || program === null;
2601
2866
  return {
2602
2867
  has: (id) => id.startsWith(PREFIX),
@@ -2606,7 +2871,7 @@ var GameInteractables = (() => {
2606
2871
  if (program) entries.push({ id: `${PREFIX}stop`, label: world.t("use.program.stop", { name: name(), left: clock(program.left) }), available: true });
2607
2872
  for (const use of all.filter(visible)) {
2608
2873
  const v = verdict(use, host);
2609
- entries.push({ id: `${PREFIX}${use.id}`, label: labelOf(use, host), available: v.available, ...v.available ? {} : { reason: world.t(v.reason, textVars(use, host)) } });
2874
+ entries.push({ id: `${PREFIX}${use.id}`, label: labelOf(use, host), available: v.available, ...v.available ? {} : { reason: reasonOf(v, use, host) } });
2610
2875
  }
2611
2876
  return entries;
2612
2877
  },
@@ -2616,9 +2881,10 @@ var GameInteractables = (() => {
2616
2881
  const use = all.find((u) => `${PREFIX}${u.id}` === id);
2617
2882
  if (!use || !visible(use)) return { ok: false, text: "" };
2618
2883
  const v = verdict(use, host);
2619
- return v.available ? runUse(use, host) : { ok: false, text: world.t(v.reason, textVars(use, host)) };
2884
+ return v.available ? runUse(use, host) : { ok: false, text: reasonOf(v, use, host) };
2620
2885
  },
2621
2886
  update(dt) {
2887
+ stepRoutine(dt);
2622
2888
  if (!program) return;
2623
2889
  program.left -= dt;
2624
2890
  if (program.left > 0) return;
@@ -2636,7 +2902,8 @@ var GameInteractables = (() => {
2636
2902
  state: () => ({
2637
2903
  bowls: Object.fromEntries(level),
2638
2904
  soil: Object.fromEntries(soil),
2639
- program: program ? { use: program.use.id, device: program.use.device, left: program.left } : null
2905
+ program: program ? { use: program.use.id, device: program.use.device, left: program.left } : null,
2906
+ routine: routine?.use ?? null
2640
2907
  })
2641
2908
  };
2642
2909
  }
@@ -2647,9 +2914,9 @@ var GameInteractables = (() => {
2647
2914
  var MAINS_TANK = "water";
2648
2915
  var HOST_KINDS = /* @__PURE__ */ new Set(["toggle_part", "open_container", "take", "read", "sit", "toggle_breaker"]);
2649
2916
  var PLUG_FALLBACK = [0, 0.3, 0];
2650
- function mainsSpec(spec) {
2917
+ function mainsSpec(spec, water) {
2651
2918
  const plugged = (spec.devices ?? []).filter((d) => d.socket !== void 0 && !d.circuit);
2652
- return { type: MAINS, sockets: plugged.map((d, i) => ({ id: `socket_${i}`, pos: d.plug ?? PLUG_FALLBACK })), tanks: [{ id: MAINS_TANK, capacity: 1e9 }] };
2919
+ return { type: MAINS, sockets: plugged.map((d, i) => ({ id: `socket_${i}`, pos: d.plug ?? PLUG_FALLBACK })), tanks: water ? [{ id: MAINS_TANK, capacity: 1e9 }] : [] };
2653
2920
  }
2654
2921
  function createObjectControls(options) {
2655
2922
  const { spec } = options;
@@ -2672,8 +2939,9 @@ var GameInteractables = (() => {
2672
2939
  forwarded.set(part, open);
2673
2940
  host?.setPart(part, open);
2674
2941
  };
2675
- world.add(MAINS, mainsSpec(spec), { x: 0, y: 0, z: 0, ry: 0 });
2676
- if (options.mains?.water ?? true) world.water.setDefaultTank(`${MAINS}:${MAINS_TANK}`);
2942
+ const piped = options.mains?.water ?? true;
2943
+ world.add(MAINS, mainsSpec(spec, piped), { x: 0, y: 0, z: 0, ry: 0 });
2944
+ if (piped) world.water.setDefaultTank(`${MAINS}:${MAINS_TANK}`);
2677
2945
  world.add(CONTROLLED_OBJECT, spec, { x: 0, y: 0, z: 0, ry: 0 });
2678
2946
  const uses = createUses({ spec, world, objectId: CONTROLLED_OBJECT });
2679
2947
  const programmedDevices = new Set((spec.uses ?? []).flatMap((u) => u.do === "program" ? [u.device] : []));