@adatechnology/game-vehicles-driving 0.2.12 → 0.2.14

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.js CHANGED
@@ -522,6 +522,7 @@ var DEFAULT_CONTROL_KEYS = {
522
522
  clutch: ["KeyC"],
523
523
  flash: ["KeyX"],
524
524
  washer: ["KeyZ"],
525
+ hotwire: ["KeyI"],
525
526
  ignition: ["KeyI"],
526
527
  gearbox: ["KeyM"],
527
528
  gear_up: ["KeyE"],
@@ -547,9 +548,12 @@ var DEFAULT_CONTROL_KEYS = {
547
548
  abs: ["Digit9"],
548
549
  cruise: ["Digit0"],
549
550
  climate: ["Minus"],
550
- demist: ["Equal"]
551
+ demist: ["Equal"],
552
+ siren: ["Semicolon"],
553
+ beacon: ["Quote"],
554
+ glovebox: ["Slash"]
551
555
  };
552
- var HELD_KEYS = ["throttle", "brake", "left", "right", "handbrake", "horn", "clutch", "flash", "washer"];
556
+ var HELD_KEYS = ["throttle", "brake", "left", "right", "handbrake", "horn", "clutch", "flash", "washer", "hotwire"];
553
557
  function createVehicleControls(options) {
554
558
  const keys = { ...DEFAULT_CONTROL_KEYS, ...options.keys };
555
559
  const auto4 = options.autoFourWheel ?? { slip: 0.18, releaseSeconds: 2 };
@@ -584,8 +588,17 @@ function createVehicleControls(options) {
584
588
  abs: true,
585
589
  cruise: { on: false, speed: 0 },
586
590
  climate: { on: false, demist: false },
587
- cranking: false
591
+ cranking: false,
592
+ hotwire: { progress: 0, done: false },
593
+ siren: "off",
594
+ beacon: false,
595
+ beaconSide: 0,
596
+ glovebox: false
588
597
  };
598
+ const hasKey = options.hasKey !== false;
599
+ const hotwireSeconds = Math.max(0.1, options.hotwireSeconds ?? 8);
600
+ const beaconHz = options.beaconHz ?? 2.5;
601
+ let beaconClock = 0;
589
602
  let crankAsked = false;
590
603
  let lastSpeed = 0;
591
604
  let engineRunning = !!options.running;
@@ -602,9 +615,11 @@ function createVehicleControls(options) {
602
615
  const MODES = ["4x2", "4x4", "auto"];
603
616
  const WIPERS = ["off", "intermittent", "slow", "fast"];
604
617
  const PROFILES = ["eco", "normal", "sport"];
618
+ const SIRENS = ["off", "wail", "yelp"];
605
619
  const command = (c) => {
606
620
  switch (c) {
607
621
  case "ignition":
622
+ if (!hasKey && !state.hotwire.done) return emit({ type: "refused", command: c, reason: "no_key" });
608
623
  state.ignition = !state.ignition;
609
624
  if (state.ignition && state.alarm !== "off") state.alarm = "off";
610
625
  if (state.ignition) crankAsked = true;
@@ -698,6 +713,20 @@ function createVehicleControls(options) {
698
713
  case "seatbelt":
699
714
  state.seatbelt = !state.seatbelt;
700
715
  break;
716
+ case "siren":
717
+ if (!options.emergency) return emit({ type: "refused", command: c, reason: "no_siren" });
718
+ state.siren = SIRENS[(SIRENS.indexOf(state.siren) + 1) % SIRENS.length];
719
+ if (state.siren !== "off") state.beacon = true;
720
+ break;
721
+ case "beacon":
722
+ if (!options.emergency) return emit({ type: "refused", command: c, reason: "no_siren" });
723
+ state.beacon = !state.beacon;
724
+ if (!state.beacon) state.siren = "off";
725
+ beaconClock = 0;
726
+ break;
727
+ case "glovebox":
728
+ state.glovebox = !state.glovebox;
729
+ break;
701
730
  }
702
731
  emit({ type: "command", command: c, state });
703
732
  };
@@ -736,6 +765,23 @@ function createVehicleControls(options) {
736
765
  else if (turned && way < cancelAt) state.indicator = "off";
737
766
  }
738
767
  } else state.blinkOn = false;
768
+ if (state.beacon) {
769
+ beaconClock += dt;
770
+ state.beaconSide = Math.floor(beaconClock * beaconHz) % 2;
771
+ }
772
+ if (!hasKey && !state.hotwire.done && !state.ignition && any(keys.hotwire)) {
773
+ if (state.hotwire.progress === 0) {
774
+ if (state.alarm === "armed") state.alarm = "ringing";
775
+ emit({ type: "hotwire", stage: "started" });
776
+ }
777
+ state.hotwire.progress = Math.min(1, state.hotwire.progress + dt / hotwireSeconds);
778
+ if (state.hotwire.progress >= 1) {
779
+ state.hotwire.done = true;
780
+ state.ignition = true;
781
+ crankAsked = true;
782
+ emit({ type: "hotwire", stage: "joined" });
783
+ }
784
+ }
739
785
  state.horn = any(keys.horn);
740
786
  state.lamps.flash = any(keys.flash);
741
787
  state.washer = any(keys.washer);
@@ -824,7 +870,7 @@ function conditionFromDamage(spec, report) {
824
870
  }
825
871
 
826
872
  // src/systems.ts
827
- var DEFAULT_LOADS = { position: 20, low: 110, high: 130, fog: 110, interior: 10, radio: 25, wipers: 60, indicators: 42, horn: 60, alarm: 5, brakeLights: 42, climate: 180 };
873
+ var DEFAULT_LOADS = { position: 20, low: 110, high: 130, fog: 110, interior: 10, radio: 25, wipers: 60, indicators: 42, horn: 60, alarm: 5, brakeLights: 42, climate: 180, siren: 100, beacon: 70 };
828
874
  var clamp3 = (x, a, b) => Math.max(a, Math.min(b, x));
829
875
  function createVehicleSystems(options = {}) {
830
876
  const loads = { ...DEFAULT_LOADS, ...options.loads };
@@ -854,6 +900,8 @@ function createVehicleSystems(options = {}) {
854
900
  if (c.alarm !== "off") w += loads.alarm;
855
901
  if (c.brakeLights) w += loads.brakeLights;
856
902
  if (c.climate.on) w += loads.climate;
903
+ if (c.siren !== "off") w += loads.siren;
904
+ if (c.beacon) w += loads.beacon;
857
905
  return w;
858
906
  };
859
907
  return {
@@ -938,6 +986,94 @@ function bumperDistance(params) {
938
986
  }
939
987
  return best;
940
988
  }
989
+
990
+ // src/storage.ts
991
+ var GLOVEBOX = { id: "glovebox", slots: 6, capacityKg: 4, access: "cabin" };
992
+ var trunkFor = (litres = 450) => ({ id: "trunk", slots: Math.max(4, Math.round(litres / 25)), capacityKg: Math.round(litres / 4), access: "lid" });
993
+ var weightOf = (stack) => stack.unitKg * stack.count;
994
+ function createVehicleStorage(options = {}) {
995
+ const compartments = [...options.compartments ?? [GLOVEBOX, trunkFor()]];
996
+ const slots = new Map(compartments.map((c) => [c.id, Array.from({ length: c.slots }, () => null)]));
997
+ const specOf = (id) => compartments.find((c) => c.id === id);
998
+ const load = (id) => (slots.get(id) ?? []).reduce((kg, s) => kg + (s ? weightOf(s) : 0), 0);
999
+ const reachable = (id, access) => {
1000
+ const spec = specOf(id);
1001
+ if (!spec) return false;
1002
+ return spec.access === "lid" ? access.lid >= 0.5 : access.gloveboxOpen && (access.seated || access.frontDoorOpen);
1003
+ };
1004
+ const place = (id, stack) => {
1005
+ const spec = specOf(id);
1006
+ const list = slots.get(id);
1007
+ if (!spec || !list) return "missing";
1008
+ if (load(id) + weightOf(stack) > spec.capacityKg + 1e-9) return "too_heavy";
1009
+ const same = stack.data === void 0 ? list.findIndex((s) => s !== null && s.itemId === stack.itemId && s.data === void 0) : -1;
1010
+ if (same >= 0) {
1011
+ const s = list[same];
1012
+ list[same] = { ...s, count: s.count + stack.count };
1013
+ return "ok";
1014
+ }
1015
+ const free = list.indexOf(null);
1016
+ if (free < 0) return "full";
1017
+ list[free] = { ...stack };
1018
+ return "ok";
1019
+ };
1020
+ return {
1021
+ compartments,
1022
+ reachable,
1023
+ contents: (id) => [...slots.get(id) ?? []],
1024
+ loadKg: (id) => id === void 0 ? compartments.reduce((kg, c) => kg + load(c.id), 0) : load(id),
1025
+ put(id, stack, access) {
1026
+ if (!specOf(id)) return "missing";
1027
+ if (!reachable(id, access)) return "shut";
1028
+ return place(id, stack);
1029
+ },
1030
+ take(id, slot, access) {
1031
+ const list = slots.get(id);
1032
+ if (!list || !reachable(id, access)) return null;
1033
+ const stack = list[slot] ?? null;
1034
+ if (stack) list[slot] = null;
1035
+ return stack;
1036
+ },
1037
+ stock(id, stacks) {
1038
+ return stacks.filter((s) => place(id, s) !== "ok");
1039
+ },
1040
+ clear() {
1041
+ for (const list of slots.values()) list.fill(null);
1042
+ }
1043
+ };
1044
+ }
1045
+
1046
+ // src/windshield-fog.ts
1047
+ var clamp4 = (x, a, b) => Math.max(a, Math.min(b, x));
1048
+ function createWindshieldFog(options = {}) {
1049
+ const outside = options.outsideHumidity ?? 0.6;
1050
+ const breath = options.breath ?? 4e-3;
1051
+ const wet = options.wet ?? 2e-3;
1052
+ const air = options.air ?? { shut: 2e-3, window: 0.05, climate: 0.01, demist: 0.06 };
1053
+ const coldSpan = options.coldSpan ?? 15;
1054
+ const rates = options.rates ?? { build: 0.05, clear: 0.03, demist: 0.25 };
1055
+ const state = { humidity: outside, fog: 0 };
1056
+ return {
1057
+ state,
1058
+ step({ dt, occupants, outsideC, cabinC, rain = 0, speed = 0, windows = 0, climate, engineWarm = 1 }) {
1059
+ const exchange = air.shut + air.window * clamp4(windows, 0, 1) + (climate.on ? air.climate : 0) + (climate.demist ? air.demist : 0);
1060
+ const source = breath * Math.max(0, occupants) + wet * clamp4(rain, 0, 1) * (occupants > 0 ? 1 : 0);
1061
+ const towards = climate.on ? outside * 0.4 : outside;
1062
+ state.humidity = clamp4(state.humidity + (source - exchange * (state.humidity - towards)) * dt, 0, 1);
1063
+ const cold = Math.max(0, cabinC - outsideC) * (1 - 0.7 * clamp4(windows, 0, 1)) + 6 * clamp4(rain, 0, 1) + 2 * clamp4(speed / 27.8, 0, 1);
1064
+ const warmed = climate.demist ? cold * (1 - 0.9 * clamp4(engineWarm, 0, 1)) : cold;
1065
+ const clearUpTo = 1 - 0.5 * clamp4(warmed / coldSpan, 0, 1);
1066
+ const target = clamp4((state.humidity - clearUpTo) * 6, 0, 1);
1067
+ const down = climate.demist ? rates.demist * (0.3 + 0.7 * clamp4(engineWarm, 0, 1)) : rates.clear;
1068
+ state.fog = target > state.fog ? Math.min(target, state.fog + rates.build * dt) : Math.max(target, state.fog - down * dt);
1069
+ return state;
1070
+ },
1071
+ set(next) {
1072
+ if (next.humidity !== void 0) state.humidity = clamp4(next.humidity, 0, 1);
1073
+ if (next.fog !== void 0) state.fog = clamp4(next.fog, 0, 1);
1074
+ }
1075
+ };
1076
+ }
941
1077
  export {
942
1078
  DEFAULT_CONTROL_KEYS,
943
1079
  DEFAULT_CRUISE,
@@ -946,6 +1082,7 @@ export {
946
1082
  DEFAULT_PARKING_SENSOR,
947
1083
  DEFAULT_TRACTION,
948
1084
  DRIVE_PROFILES,
1085
+ GLOVEBOX,
949
1086
  bodyDamage,
950
1087
  bumperDistance,
951
1088
  conditionFromDamage,
@@ -953,7 +1090,9 @@ export {
953
1090
  createSemiSimDriver,
954
1091
  createSurfaces,
955
1092
  createVehicleControls,
1093
+ createVehicleStorage,
956
1094
  createVehicleSystems,
1095
+ createWindshieldFog,
957
1096
  cruiseThrottle,
958
1097
  defaultArcadeSpec,
959
1098
  defaultFuelModel,
@@ -968,6 +1107,7 @@ export {
968
1107
  speedLoss,
969
1108
  surfaceGrip,
970
1109
  tractionLimit,
1110
+ trunkFor,
971
1111
  vehicleCorners,
972
1112
  vehicleDamageFromImpact
973
1113
  };