@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.d.ts +159 -3
- package/dist/index.global.js +144 -4
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +144 -4
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -445,7 +445,7 @@ declare const DEFAULT_CRUISE: CruiseOptions;
|
|
|
445
445
|
/** Gas cruise control asks for to hold `target` at `speed` (m/s); none above the target, the car coasts down to it. */
|
|
446
446
|
declare function cruiseThrottle(target: number, speed: number, options?: CruiseOptions): number;
|
|
447
447
|
|
|
448
|
-
type ControlCommand = 'ignition' | 'gearbox' | 'gear_up' | 'gear_down' | 'parking_brake' | 'drive_mode' | 'lights' | 'high_beam' | 'fog_lights' | 'interior_light' | 'alarm' | 'radio' | 'radio_source' | 'radio_track' | 'exit' | 'indicator_left' | 'indicator_right' | 'hazard' | 'wipers' | 'seatbelt' | 'drive_profile' | 'traction_control' | 'abs' | 'cruise' | 'climate' | 'demist';
|
|
448
|
+
type ControlCommand = 'ignition' | 'gearbox' | 'gear_up' | 'gear_down' | 'parking_brake' | 'drive_mode' | 'lights' | 'high_beam' | 'fog_lights' | 'interior_light' | 'alarm' | 'radio' | 'radio_source' | 'radio_track' | 'exit' | 'indicator_left' | 'indicator_right' | 'hazard' | 'wipers' | 'seatbelt' | 'drive_profile' | 'traction_control' | 'abs' | 'cruise' | 'climate' | 'demist' | 'siren' | 'beacon' | 'glovebox';
|
|
449
449
|
type ControlKeyMap = {
|
|
450
450
|
readonly throttle: readonly string[];
|
|
451
451
|
readonly brake: readonly string[];
|
|
@@ -457,6 +457,8 @@ type ControlKeyMap = {
|
|
|
457
457
|
/** Flashes the high beam while held. */
|
|
458
458
|
readonly flash: readonly string[];
|
|
459
459
|
readonly washer: readonly string[];
|
|
460
|
+
/** Held without the key (`hasKey: false`): strips and joins the wires under the column until the engine turns over. */
|
|
461
|
+
readonly hotwire: readonly string[];
|
|
460
462
|
} & {
|
|
461
463
|
readonly [command in ControlCommand]: readonly string[];
|
|
462
464
|
};
|
|
@@ -469,6 +471,8 @@ type AlarmState = 'off' | 'armed' | 'ringing';
|
|
|
469
471
|
type RadioSource = 'radio' | 'tape';
|
|
470
472
|
type Indicator = 'off' | 'left' | 'right' | 'hazard';
|
|
471
473
|
type Wipers = 'off' | 'intermittent' | 'slow' | 'fast';
|
|
474
|
+
/** The siren's tone: the slow rise and fall, or the fast warble of a junction. */
|
|
475
|
+
type Siren = 'off' | 'wail' | 'yelp';
|
|
472
476
|
interface ControlState {
|
|
473
477
|
ignition: boolean;
|
|
474
478
|
gearbox: Gearbox;
|
|
@@ -521,6 +525,17 @@ interface ControlState {
|
|
|
521
525
|
};
|
|
522
526
|
/** The starter turns this step. */
|
|
523
527
|
cranking: boolean;
|
|
528
|
+
/** Without the key: how far the wires under the column are (0 untouched, 1 joined: the ignition is live), and whether they are joined now. */
|
|
529
|
+
hotwire: {
|
|
530
|
+
progress: number;
|
|
531
|
+
done: boolean;
|
|
532
|
+
};
|
|
533
|
+
siren: Siren;
|
|
534
|
+
/** The beacon (light bar) is on, and which of its two sides is lit this instant (it alternates at `beaconHz`). */
|
|
535
|
+
beacon: boolean;
|
|
536
|
+
beaconSide: 0 | 1;
|
|
537
|
+
/** The glovebox lid is open. */
|
|
538
|
+
glovebox: boolean;
|
|
524
539
|
}
|
|
525
540
|
type ControlEvent = {
|
|
526
541
|
type: 'command';
|
|
@@ -529,9 +544,14 @@ type ControlEvent = {
|
|
|
529
544
|
} | {
|
|
530
545
|
type: 'refused';
|
|
531
546
|
command: ControlCommand;
|
|
532
|
-
reason: 'no_four_wheel_drive' | 'no_fog_lamps' | 'ignition_off' | 'battery_flat' | 'too_slow';
|
|
547
|
+
reason: 'no_four_wheel_drive' | 'no_fog_lamps' | 'ignition_off' | 'battery_flat' | 'too_slow' | 'no_key' | 'no_siren';
|
|
533
548
|
} | {
|
|
534
549
|
type: 'cruise_cancelled';
|
|
550
|
+
}
|
|
551
|
+
/** The wires under the column: stripped (first touch), joined (the ignition is live and the starter turns). */
|
|
552
|
+
| {
|
|
553
|
+
type: 'hotwire';
|
|
554
|
+
stage: 'started' | 'joined';
|
|
535
555
|
};
|
|
536
556
|
interface VehicleControlOptions {
|
|
537
557
|
/** Forward gears of the gearbox. */
|
|
@@ -563,6 +583,14 @@ interface VehicleControlOptions {
|
|
|
563
583
|
onCrank?: () => void;
|
|
564
584
|
/** Share of the torque the engine gives besides the aids (an overheated engine). Default 1. */
|
|
565
585
|
powerLimit?: () => number;
|
|
586
|
+
/** The driver has the key. Default true. Without it the ignition refuses and the hotwire key (held) joins the wires. */
|
|
587
|
+
hasKey?: boolean;
|
|
588
|
+
/** Seconds of the hotwire key held to strip and join the wires. Default 8. */
|
|
589
|
+
hotwireSeconds?: number;
|
|
590
|
+
/** The vehicle has a siren and a beacon (an emergency vehicle). Default false: both refuse. */
|
|
591
|
+
emergency?: boolean;
|
|
592
|
+
/** The beacon's sides swap this many times a second. Default 2.5. */
|
|
593
|
+
beaconHz?: number;
|
|
566
594
|
onEvent?: (event: ControlEvent) => void;
|
|
567
595
|
}
|
|
568
596
|
/** What the controls read of the driver each step, and the one thing they change on it (which axles drive). */
|
|
@@ -640,6 +668,9 @@ interface ElectricalLoads {
|
|
|
640
668
|
readonly alarm: number;
|
|
641
669
|
readonly brakeLights: number;
|
|
642
670
|
readonly climate: number;
|
|
671
|
+
/** An emergency vehicle's siren amplifier and its beacon (light bar). */
|
|
672
|
+
readonly siren: number;
|
|
673
|
+
readonly beacon: number;
|
|
643
674
|
}
|
|
644
675
|
interface VehicleSystemsOptions {
|
|
645
676
|
/** Battery capacity, watt-hours (a 12 V 60 Ah battery holds 720). */
|
|
@@ -801,4 +832,129 @@ declare function bumperDistance(params: {
|
|
|
801
832
|
obstacles: ReadonlyArray<readonly [number, number]>;
|
|
802
833
|
}): number;
|
|
803
834
|
|
|
804
|
-
|
|
835
|
+
/**
|
|
836
|
+
* What a vehicle carries besides its people: the glovebox (reached from a front seat, or through an open front door, with its lid open) and the trunk
|
|
837
|
+
* (reached with the lid up, from behind). Each compartment holds item stacks by slot, up to a slot count and a weight; nothing is reached while it is
|
|
838
|
+
* shut, and the weight it carries is there for the driver to add to the vehicle's mass. Items are the host's (a game's catalog, `game-items`): a stack
|
|
839
|
+
* is its id, its count, the weight of one and whatever state the host keeps with it. Every number is an option.
|
|
840
|
+
*/
|
|
841
|
+
type CompartmentId = string;
|
|
842
|
+
interface CompartmentSpec {
|
|
843
|
+
readonly id: CompartmentId;
|
|
844
|
+
/** Stacks it holds. */
|
|
845
|
+
readonly slots: number;
|
|
846
|
+
/** Weight it takes, kg. */
|
|
847
|
+
readonly capacityKg: number;
|
|
848
|
+
/** How it is reached: `cabin` from a front seat or an open front door with its own lid open (a glovebox); `lid` with the trunk lid up. */
|
|
849
|
+
readonly access: 'cabin' | 'lid';
|
|
850
|
+
}
|
|
851
|
+
/** A stack in a compartment: the host's item id, how many and the weight of one; `data` is the host's own state of the stack (age, charge), kept as is. */
|
|
852
|
+
interface StorageStack {
|
|
853
|
+
readonly itemId: string;
|
|
854
|
+
readonly count: number;
|
|
855
|
+
readonly unitKg: number;
|
|
856
|
+
readonly data?: unknown;
|
|
857
|
+
}
|
|
858
|
+
/** What reaches the compartments now. */
|
|
859
|
+
interface StorageAccess {
|
|
860
|
+
/** Someone sits in a front seat. */
|
|
861
|
+
readonly seated: boolean;
|
|
862
|
+
/** A front door is open (someone standing outside reaches the glovebox). */
|
|
863
|
+
readonly frontDoorOpen: boolean;
|
|
864
|
+
/** The glovebox lid is open (`ControlState.glovebox`). */
|
|
865
|
+
readonly gloveboxOpen: boolean;
|
|
866
|
+
/** The trunk lid is up, 0..1 (open from 0.5). */
|
|
867
|
+
readonly lid: number;
|
|
868
|
+
}
|
|
869
|
+
type StoreResult = 'ok' | 'shut' | 'full' | 'too_heavy' | 'missing';
|
|
870
|
+
/** A glovebox: a few small things (papers, a torch, a charger), about 8 litres. */
|
|
871
|
+
declare const GLOVEBOX: CompartmentSpec;
|
|
872
|
+
/** The trunk of a car by its size in litres (a hatch 280, a sedan 450, an estate 600): a slot every 25 litres and a kilo for every 4 litres. */
|
|
873
|
+
declare const trunkFor: (litres?: number) => CompartmentSpec;
|
|
874
|
+
interface VehicleStorageOptions {
|
|
875
|
+
/** Default: a glovebox and a 450-litre trunk. A motorcycle passes none, a pickup its bed as a `lid` compartment. */
|
|
876
|
+
compartments?: readonly CompartmentSpec[];
|
|
877
|
+
}
|
|
878
|
+
interface VehicleStorage {
|
|
879
|
+
readonly compartments: readonly CompartmentSpec[];
|
|
880
|
+
/** The compartment can be reached now. */
|
|
881
|
+
reachable(id: CompartmentId, access: StorageAccess): boolean;
|
|
882
|
+
/** Stacks by slot (null an empty slot). */
|
|
883
|
+
contents(id: CompartmentId): ReadonlyArray<StorageStack | null>;
|
|
884
|
+
/** Weight in one compartment, or in all of them. */
|
|
885
|
+
loadKg(id?: CompartmentId): number;
|
|
886
|
+
/** Puts a stack in (it joins a stack of the same item without host state); refused while shut, without a free slot or over the weight. */
|
|
887
|
+
put(id: CompartmentId, stack: StorageStack, access: StorageAccess): StoreResult;
|
|
888
|
+
/** Takes the stack of a slot out; null while shut or empty. */
|
|
889
|
+
take(id: CompartmentId, slot: number, access: StorageAccess): StorageStack | null;
|
|
890
|
+
/** Fills a compartment at once, reachable or not (what was in it when the vehicle was found); what does not fit is left out and returned. */
|
|
891
|
+
stock(id: CompartmentId, stacks: readonly StorageStack[]): StorageStack[];
|
|
892
|
+
/** Empties every compartment (the vehicle goes away). */
|
|
893
|
+
clear(): void;
|
|
894
|
+
}
|
|
895
|
+
declare function createVehicleStorage(options?: VehicleStorageOptions): VehicleStorage;
|
|
896
|
+
|
|
897
|
+
/**
|
|
898
|
+
* The glass misting up from inside. The people in the cabin breathe water into its air and wet clothes from the rain bring more; the air
|
|
899
|
+
* that comes in (an open window, the fan, the air conditioning that dries it) takes it out. Fog forms when that moisture is past what the glass
|
|
900
|
+
* holds clear, which drops the colder the glass is than the cabin (a cold day, rain on the glass, speed); the demister blows dry, warm air on it and
|
|
901
|
+
* clears it in a few seconds once the engine is warm. The wipers clean only the outside: they do nothing to it. Every number is an option.
|
|
902
|
+
*/
|
|
903
|
+
interface WindshieldFogOptions {
|
|
904
|
+
/** Moisture of the air outside, 0..1. Default 0.6. */
|
|
905
|
+
outsideHumidity?: number;
|
|
906
|
+
/** Moisture one occupant breathes into the cabin, share of saturation per second. Default 0.004. */
|
|
907
|
+
breath?: number;
|
|
908
|
+
/** Moisture of wet clothes in the rain, per second at full rain. Default 0.002. */
|
|
909
|
+
wet?: number;
|
|
910
|
+
/** Air change of a shut cabin per second, and what a window fully down, the climate fan and the demister add to it. */
|
|
911
|
+
air?: {
|
|
912
|
+
shut: number;
|
|
913
|
+
window: number;
|
|
914
|
+
climate: number;
|
|
915
|
+
demist: number;
|
|
916
|
+
};
|
|
917
|
+
/** Degrees of glass below the cabin that bring the fog down to half the moisture (0 degrees: fog only at saturation). Default 15. */
|
|
918
|
+
coldSpan?: number;
|
|
919
|
+
/** Fog builds up, clears on its own and clears under the warm demister, share of the glass per second. */
|
|
920
|
+
rates?: {
|
|
921
|
+
build: number;
|
|
922
|
+
clear: number;
|
|
923
|
+
demist: number;
|
|
924
|
+
};
|
|
925
|
+
}
|
|
926
|
+
interface WindshieldFogState {
|
|
927
|
+
/** Moisture of the cabin's air, 0..1 (1 saturated). */
|
|
928
|
+
humidity: number;
|
|
929
|
+
/** Share of the glass misted, 0..1. */
|
|
930
|
+
fog: number;
|
|
931
|
+
}
|
|
932
|
+
interface WindshieldFogStep {
|
|
933
|
+
dt: number;
|
|
934
|
+
/** People inside. */
|
|
935
|
+
occupants: number;
|
|
936
|
+
/** Air temperature outside and in the cabin, °C. */
|
|
937
|
+
outsideC: number;
|
|
938
|
+
cabinC: number;
|
|
939
|
+
/** Rain on the glass, 0..1. */
|
|
940
|
+
rain?: number;
|
|
941
|
+
/** Speed, m/s: the wind over the glass cools it. */
|
|
942
|
+
speed?: number;
|
|
943
|
+
/** The windows' opening, 0..1 summed share (one window fully down is 0.25 of a four-door car's four). */
|
|
944
|
+
windows?: number;
|
|
945
|
+
climate: {
|
|
946
|
+
on: boolean;
|
|
947
|
+
demist: boolean;
|
|
948
|
+
};
|
|
949
|
+
/** How warm the engine is, 0..1 (the demister blows cold air from a cold engine: it dries but does not warm the glass). */
|
|
950
|
+
engineWarm?: number;
|
|
951
|
+
}
|
|
952
|
+
interface WindshieldFog {
|
|
953
|
+
readonly state: WindshieldFogState;
|
|
954
|
+
step(params: WindshieldFogStep): WindshieldFogState;
|
|
955
|
+
/** Sets the moisture and the fog at once (a car found shut in the rain). */
|
|
956
|
+
set(state: Partial<WindshieldFogState>): void;
|
|
957
|
+
}
|
|
958
|
+
declare function createWindshieldFog(options?: WindshieldFogOptions): WindshieldFog;
|
|
959
|
+
|
|
960
|
+
export { type AlarmState, type ArcadeOptions, type ArcadeSpec, type BodyDimensions, type CompartmentId, type CompartmentSpec, type ControlCommand, type ControlEvent, type ControlKeyMap, type ControlState, type ControlledDriver, type CrashPulse, type CrashRules, type CruiseOptions, DEFAULT_CONTROL_KEYS, DEFAULT_CRUISE, DEFAULT_EJECTION, DEFAULT_LOADS, DEFAULT_PARKING_SENSOR, DEFAULT_TRACTION, DRIVE_PROFILES, type DamageReport, type DamagedTyre, type DesignStats, type DriveInput, type DriveMode, type DriveProfile, type Driver, type DriverState, type DrivingBody, type DrivingEvent, type DrivingWorld, type Ejection, type EjectionExit, type EjectionOptions, type ElectricalLoads, type FuelModel, GLOVEBOX, type Gearbox, type Indicator, type LampMode, type ParkingSensorOptions, type ProfileTuning, type RadioSource, type RunOverOutcome, type RunOverRules, type SemiDriver, type SemiEvent, type SemiGround, type SemiInput, type SemiSimOptions, type SemiSimSpec, type SemiState, type SemiWheel, type SemiWorld, type Siren, type StepResult, type StorageAccess, type StorageStack, type StoreResult, type Surface, type SurfaceOptions, type SurfaceRegistry, type SystemsDriver, type SystemsEvent, type SystemsState, type SystemsStepParams, type TractionOptions, type VehicleCondition, type VehicleControlOptions, type VehicleControls, type VehicleStorage, type VehicleStorageOptions, type VehicleSystems, type VehicleSystemsOptions, type WindshieldFog, type WindshieldFogOptions, type WindshieldFogState, type WindshieldFogStep, type Wipers, bodyDamage, bumperDistance, conditionFromDamage, createArcadeDriver, createSemiSimDriver, createSurfaces, createVehicleControls, createVehicleStorage, createVehicleSystems, createWindshieldFog, cruiseThrottle, defaultArcadeSpec, defaultFuelModel, defaultSemiSpec, defaultSurfaces, ejectionOf, fuelRate, impactEnergy, parkingBeepInterval, runOver, semiSpecFromStats, speedLoss, surfaceGrip, tractionLimit, trunkFor, vehicleCorners, vehicleDamageFromImpact };
|
package/dist/index.global.js
CHANGED
|
@@ -28,6 +28,7 @@ var GameVehiclesDriving = (() => {
|
|
|
28
28
|
DEFAULT_PARKING_SENSOR: () => DEFAULT_PARKING_SENSOR,
|
|
29
29
|
DEFAULT_TRACTION: () => DEFAULT_TRACTION,
|
|
30
30
|
DRIVE_PROFILES: () => DRIVE_PROFILES,
|
|
31
|
+
GLOVEBOX: () => GLOVEBOX,
|
|
31
32
|
bodyDamage: () => bodyDamage,
|
|
32
33
|
bumperDistance: () => bumperDistance,
|
|
33
34
|
conditionFromDamage: () => conditionFromDamage,
|
|
@@ -35,7 +36,9 @@ var GameVehiclesDriving = (() => {
|
|
|
35
36
|
createSemiSimDriver: () => createSemiSimDriver,
|
|
36
37
|
createSurfaces: () => createSurfaces,
|
|
37
38
|
createVehicleControls: () => createVehicleControls,
|
|
39
|
+
createVehicleStorage: () => createVehicleStorage,
|
|
38
40
|
createVehicleSystems: () => createVehicleSystems,
|
|
41
|
+
createWindshieldFog: () => createWindshieldFog,
|
|
39
42
|
cruiseThrottle: () => cruiseThrottle,
|
|
40
43
|
defaultArcadeSpec: () => defaultArcadeSpec,
|
|
41
44
|
defaultFuelModel: () => defaultFuelModel,
|
|
@@ -50,6 +53,7 @@ var GameVehiclesDriving = (() => {
|
|
|
50
53
|
speedLoss: () => speedLoss,
|
|
51
54
|
surfaceGrip: () => surfaceGrip,
|
|
52
55
|
tractionLimit: () => tractionLimit,
|
|
56
|
+
trunkFor: () => trunkFor,
|
|
53
57
|
vehicleCorners: () => vehicleCorners,
|
|
54
58
|
vehicleDamageFromImpact: () => vehicleDamageFromImpact
|
|
55
59
|
});
|
|
@@ -678,6 +682,7 @@ var GameVehiclesDriving = (() => {
|
|
|
678
682
|
clutch: ["KeyC"],
|
|
679
683
|
flash: ["KeyX"],
|
|
680
684
|
washer: ["KeyZ"],
|
|
685
|
+
hotwire: ["KeyI"],
|
|
681
686
|
ignition: ["KeyI"],
|
|
682
687
|
gearbox: ["KeyM"],
|
|
683
688
|
gear_up: ["KeyE"],
|
|
@@ -703,9 +708,12 @@ var GameVehiclesDriving = (() => {
|
|
|
703
708
|
abs: ["Digit9"],
|
|
704
709
|
cruise: ["Digit0"],
|
|
705
710
|
climate: ["Minus"],
|
|
706
|
-
demist: ["Equal"]
|
|
711
|
+
demist: ["Equal"],
|
|
712
|
+
siren: ["Semicolon"],
|
|
713
|
+
beacon: ["Quote"],
|
|
714
|
+
glovebox: ["Slash"]
|
|
707
715
|
};
|
|
708
|
-
var HELD_KEYS = ["throttle", "brake", "left", "right", "handbrake", "horn", "clutch", "flash", "washer"];
|
|
716
|
+
var HELD_KEYS = ["throttle", "brake", "left", "right", "handbrake", "horn", "clutch", "flash", "washer", "hotwire"];
|
|
709
717
|
function createVehicleControls(options) {
|
|
710
718
|
const keys = { ...DEFAULT_CONTROL_KEYS, ...options.keys };
|
|
711
719
|
const auto4 = options.autoFourWheel ?? { slip: 0.18, releaseSeconds: 2 };
|
|
@@ -740,8 +748,17 @@ var GameVehiclesDriving = (() => {
|
|
|
740
748
|
abs: true,
|
|
741
749
|
cruise: { on: false, speed: 0 },
|
|
742
750
|
climate: { on: false, demist: false },
|
|
743
|
-
cranking: false
|
|
751
|
+
cranking: false,
|
|
752
|
+
hotwire: { progress: 0, done: false },
|
|
753
|
+
siren: "off",
|
|
754
|
+
beacon: false,
|
|
755
|
+
beaconSide: 0,
|
|
756
|
+
glovebox: false
|
|
744
757
|
};
|
|
758
|
+
const hasKey = options.hasKey !== false;
|
|
759
|
+
const hotwireSeconds = Math.max(0.1, options.hotwireSeconds ?? 8);
|
|
760
|
+
const beaconHz = options.beaconHz ?? 2.5;
|
|
761
|
+
let beaconClock = 0;
|
|
745
762
|
let crankAsked = false;
|
|
746
763
|
let lastSpeed = 0;
|
|
747
764
|
let engineRunning = !!options.running;
|
|
@@ -758,9 +775,11 @@ var GameVehiclesDriving = (() => {
|
|
|
758
775
|
const MODES = ["4x2", "4x4", "auto"];
|
|
759
776
|
const WIPERS = ["off", "intermittent", "slow", "fast"];
|
|
760
777
|
const PROFILES = ["eco", "normal", "sport"];
|
|
778
|
+
const SIRENS = ["off", "wail", "yelp"];
|
|
761
779
|
const command = (c) => {
|
|
762
780
|
switch (c) {
|
|
763
781
|
case "ignition":
|
|
782
|
+
if (!hasKey && !state.hotwire.done) return emit({ type: "refused", command: c, reason: "no_key" });
|
|
764
783
|
state.ignition = !state.ignition;
|
|
765
784
|
if (state.ignition && state.alarm !== "off") state.alarm = "off";
|
|
766
785
|
if (state.ignition) crankAsked = true;
|
|
@@ -854,6 +873,20 @@ var GameVehiclesDriving = (() => {
|
|
|
854
873
|
case "seatbelt":
|
|
855
874
|
state.seatbelt = !state.seatbelt;
|
|
856
875
|
break;
|
|
876
|
+
case "siren":
|
|
877
|
+
if (!options.emergency) return emit({ type: "refused", command: c, reason: "no_siren" });
|
|
878
|
+
state.siren = SIRENS[(SIRENS.indexOf(state.siren) + 1) % SIRENS.length];
|
|
879
|
+
if (state.siren !== "off") state.beacon = true;
|
|
880
|
+
break;
|
|
881
|
+
case "beacon":
|
|
882
|
+
if (!options.emergency) return emit({ type: "refused", command: c, reason: "no_siren" });
|
|
883
|
+
state.beacon = !state.beacon;
|
|
884
|
+
if (!state.beacon) state.siren = "off";
|
|
885
|
+
beaconClock = 0;
|
|
886
|
+
break;
|
|
887
|
+
case "glovebox":
|
|
888
|
+
state.glovebox = !state.glovebox;
|
|
889
|
+
break;
|
|
857
890
|
}
|
|
858
891
|
emit({ type: "command", command: c, state });
|
|
859
892
|
};
|
|
@@ -892,6 +925,23 @@ var GameVehiclesDriving = (() => {
|
|
|
892
925
|
else if (turned && way < cancelAt) state.indicator = "off";
|
|
893
926
|
}
|
|
894
927
|
} else state.blinkOn = false;
|
|
928
|
+
if (state.beacon) {
|
|
929
|
+
beaconClock += dt;
|
|
930
|
+
state.beaconSide = Math.floor(beaconClock * beaconHz) % 2;
|
|
931
|
+
}
|
|
932
|
+
if (!hasKey && !state.hotwire.done && !state.ignition && any(keys.hotwire)) {
|
|
933
|
+
if (state.hotwire.progress === 0) {
|
|
934
|
+
if (state.alarm === "armed") state.alarm = "ringing";
|
|
935
|
+
emit({ type: "hotwire", stage: "started" });
|
|
936
|
+
}
|
|
937
|
+
state.hotwire.progress = Math.min(1, state.hotwire.progress + dt / hotwireSeconds);
|
|
938
|
+
if (state.hotwire.progress >= 1) {
|
|
939
|
+
state.hotwire.done = true;
|
|
940
|
+
state.ignition = true;
|
|
941
|
+
crankAsked = true;
|
|
942
|
+
emit({ type: "hotwire", stage: "joined" });
|
|
943
|
+
}
|
|
944
|
+
}
|
|
895
945
|
state.horn = any(keys.horn);
|
|
896
946
|
state.lamps.flash = any(keys.flash);
|
|
897
947
|
state.washer = any(keys.washer);
|
|
@@ -980,7 +1030,7 @@ var GameVehiclesDriving = (() => {
|
|
|
980
1030
|
}
|
|
981
1031
|
|
|
982
1032
|
// src/systems.ts
|
|
983
|
-
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 };
|
|
1033
|
+
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 };
|
|
984
1034
|
var clamp3 = (x, a, b) => Math.max(a, Math.min(b, x));
|
|
985
1035
|
function createVehicleSystems(options = {}) {
|
|
986
1036
|
const loads = { ...DEFAULT_LOADS, ...options.loads };
|
|
@@ -1010,6 +1060,8 @@ var GameVehiclesDriving = (() => {
|
|
|
1010
1060
|
if (c.alarm !== "off") w += loads.alarm;
|
|
1011
1061
|
if (c.brakeLights) w += loads.brakeLights;
|
|
1012
1062
|
if (c.climate.on) w += loads.climate;
|
|
1063
|
+
if (c.siren !== "off") w += loads.siren;
|
|
1064
|
+
if (c.beacon) w += loads.beacon;
|
|
1013
1065
|
return w;
|
|
1014
1066
|
};
|
|
1015
1067
|
return {
|
|
@@ -1094,6 +1146,94 @@ var GameVehiclesDriving = (() => {
|
|
|
1094
1146
|
}
|
|
1095
1147
|
return best;
|
|
1096
1148
|
}
|
|
1149
|
+
|
|
1150
|
+
// src/storage.ts
|
|
1151
|
+
var GLOVEBOX = { id: "glovebox", slots: 6, capacityKg: 4, access: "cabin" };
|
|
1152
|
+
var trunkFor = (litres = 450) => ({ id: "trunk", slots: Math.max(4, Math.round(litres / 25)), capacityKg: Math.round(litres / 4), access: "lid" });
|
|
1153
|
+
var weightOf = (stack) => stack.unitKg * stack.count;
|
|
1154
|
+
function createVehicleStorage(options = {}) {
|
|
1155
|
+
const compartments = [...options.compartments ?? [GLOVEBOX, trunkFor()]];
|
|
1156
|
+
const slots = new Map(compartments.map((c) => [c.id, Array.from({ length: c.slots }, () => null)]));
|
|
1157
|
+
const specOf = (id) => compartments.find((c) => c.id === id);
|
|
1158
|
+
const load = (id) => (slots.get(id) ?? []).reduce((kg, s) => kg + (s ? weightOf(s) : 0), 0);
|
|
1159
|
+
const reachable = (id, access) => {
|
|
1160
|
+
const spec = specOf(id);
|
|
1161
|
+
if (!spec) return false;
|
|
1162
|
+
return spec.access === "lid" ? access.lid >= 0.5 : access.gloveboxOpen && (access.seated || access.frontDoorOpen);
|
|
1163
|
+
};
|
|
1164
|
+
const place = (id, stack) => {
|
|
1165
|
+
const spec = specOf(id);
|
|
1166
|
+
const list = slots.get(id);
|
|
1167
|
+
if (!spec || !list) return "missing";
|
|
1168
|
+
if (load(id) + weightOf(stack) > spec.capacityKg + 1e-9) return "too_heavy";
|
|
1169
|
+
const same = stack.data === void 0 ? list.findIndex((s) => s !== null && s.itemId === stack.itemId && s.data === void 0) : -1;
|
|
1170
|
+
if (same >= 0) {
|
|
1171
|
+
const s = list[same];
|
|
1172
|
+
list[same] = { ...s, count: s.count + stack.count };
|
|
1173
|
+
return "ok";
|
|
1174
|
+
}
|
|
1175
|
+
const free = list.indexOf(null);
|
|
1176
|
+
if (free < 0) return "full";
|
|
1177
|
+
list[free] = { ...stack };
|
|
1178
|
+
return "ok";
|
|
1179
|
+
};
|
|
1180
|
+
return {
|
|
1181
|
+
compartments,
|
|
1182
|
+
reachable,
|
|
1183
|
+
contents: (id) => [...slots.get(id) ?? []],
|
|
1184
|
+
loadKg: (id) => id === void 0 ? compartments.reduce((kg, c) => kg + load(c.id), 0) : load(id),
|
|
1185
|
+
put(id, stack, access) {
|
|
1186
|
+
if (!specOf(id)) return "missing";
|
|
1187
|
+
if (!reachable(id, access)) return "shut";
|
|
1188
|
+
return place(id, stack);
|
|
1189
|
+
},
|
|
1190
|
+
take(id, slot, access) {
|
|
1191
|
+
const list = slots.get(id);
|
|
1192
|
+
if (!list || !reachable(id, access)) return null;
|
|
1193
|
+
const stack = list[slot] ?? null;
|
|
1194
|
+
if (stack) list[slot] = null;
|
|
1195
|
+
return stack;
|
|
1196
|
+
},
|
|
1197
|
+
stock(id, stacks) {
|
|
1198
|
+
return stacks.filter((s) => place(id, s) !== "ok");
|
|
1199
|
+
},
|
|
1200
|
+
clear() {
|
|
1201
|
+
for (const list of slots.values()) list.fill(null);
|
|
1202
|
+
}
|
|
1203
|
+
};
|
|
1204
|
+
}
|
|
1205
|
+
|
|
1206
|
+
// src/windshield-fog.ts
|
|
1207
|
+
var clamp4 = (x, a, b) => Math.max(a, Math.min(b, x));
|
|
1208
|
+
function createWindshieldFog(options = {}) {
|
|
1209
|
+
const outside = options.outsideHumidity ?? 0.6;
|
|
1210
|
+
const breath = options.breath ?? 4e-3;
|
|
1211
|
+
const wet = options.wet ?? 2e-3;
|
|
1212
|
+
const air = options.air ?? { shut: 2e-3, window: 0.05, climate: 0.01, demist: 0.06 };
|
|
1213
|
+
const coldSpan = options.coldSpan ?? 15;
|
|
1214
|
+
const rates = options.rates ?? { build: 0.05, clear: 0.03, demist: 0.25 };
|
|
1215
|
+
const state = { humidity: outside, fog: 0 };
|
|
1216
|
+
return {
|
|
1217
|
+
state,
|
|
1218
|
+
step({ dt, occupants, outsideC, cabinC, rain = 0, speed = 0, windows = 0, climate, engineWarm = 1 }) {
|
|
1219
|
+
const exchange = air.shut + air.window * clamp4(windows, 0, 1) + (climate.on ? air.climate : 0) + (climate.demist ? air.demist : 0);
|
|
1220
|
+
const source = breath * Math.max(0, occupants) + wet * clamp4(rain, 0, 1) * (occupants > 0 ? 1 : 0);
|
|
1221
|
+
const towards = climate.on ? outside * 0.4 : outside;
|
|
1222
|
+
state.humidity = clamp4(state.humidity + (source - exchange * (state.humidity - towards)) * dt, 0, 1);
|
|
1223
|
+
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);
|
|
1224
|
+
const warmed = climate.demist ? cold * (1 - 0.9 * clamp4(engineWarm, 0, 1)) : cold;
|
|
1225
|
+
const clearUpTo = 1 - 0.5 * clamp4(warmed / coldSpan, 0, 1);
|
|
1226
|
+
const target = clamp4((state.humidity - clearUpTo) * 6, 0, 1);
|
|
1227
|
+
const down = climate.demist ? rates.demist * (0.3 + 0.7 * clamp4(engineWarm, 0, 1)) : rates.clear;
|
|
1228
|
+
state.fog = target > state.fog ? Math.min(target, state.fog + rates.build * dt) : Math.max(target, state.fog - down * dt);
|
|
1229
|
+
return state;
|
|
1230
|
+
},
|
|
1231
|
+
set(next) {
|
|
1232
|
+
if (next.humidity !== void 0) state.humidity = clamp4(next.humidity, 0, 1);
|
|
1233
|
+
if (next.fog !== void 0) state.fog = clamp4(next.fog, 0, 1);
|
|
1234
|
+
}
|
|
1235
|
+
};
|
|
1236
|
+
}
|
|
1097
1237
|
return __toCommonJS(index_exports);
|
|
1098
1238
|
})();
|
|
1099
1239
|
//# sourceMappingURL=index.global.js.map
|