@adatechnology/game-vehicles-driving 0.2.11 → 0.2.13
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 +429 -7
- package/dist/index.global.js +415 -23
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +415 -23
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -242,6 +242,8 @@ interface SemiSimSpec {
|
|
|
242
242
|
centreHeight: number;
|
|
243
243
|
wheels: readonly SemiWheel[];
|
|
244
244
|
wheelRadius: number;
|
|
245
|
+
/** Radius of the bare rim, metres, when a wheel loses its tyre. Default `RIM_RADIUS_SHARE` of `wheelRadius`. */
|
|
246
|
+
rimRadius?: number;
|
|
245
247
|
fourWheelDrive: boolean;
|
|
246
248
|
/** Air drag: `0.5 * 1.2 * Cd * A`, in kg/m. */
|
|
247
249
|
drag: number;
|
|
@@ -288,6 +290,8 @@ interface SemiSimSpec {
|
|
|
288
290
|
interface VehicleCondition {
|
|
289
291
|
/** Health of each wheel in the order of `spec.wheels`. Under 0.2 the tyre is flat. */
|
|
290
292
|
tyres?: readonly number[];
|
|
293
|
+
/** Which wheels have lost their tyre, in the order of `spec.wheels`: the bare rim runs on the road (smaller, metal on asphalt). */
|
|
294
|
+
rims?: readonly boolean[];
|
|
291
295
|
engine?: number;
|
|
292
296
|
suspension?: number;
|
|
293
297
|
/** How much of the brake force is left, 0..1: worn or broken brakes, no brake fluid. */
|
|
@@ -296,6 +300,12 @@ interface VehicleCondition {
|
|
|
296
300
|
interface SemiInput extends DriveInput {
|
|
297
301
|
/** Forces a gear (1-based, 0 = neutral, -1 = reverse). Absent = automatic. */
|
|
298
302
|
gear?: number;
|
|
303
|
+
/** Clutch pedal, 0 released (engaged) to 1 pressed. Absent = no clutch (automatic). Released in gear at too low a speed without gas, the engine stalls. */
|
|
304
|
+
clutch?: number;
|
|
305
|
+
/** The starter turns this step. When given, it is the only way the engine starts again (no gas-pedal start). */
|
|
306
|
+
start?: boolean;
|
|
307
|
+
/** Share of the engine torque allowed this step, 0..1 (traction control cutting, an overheated engine in limp mode). Default 1. */
|
|
308
|
+
powerLimit?: number;
|
|
299
309
|
}
|
|
300
310
|
interface SemiGround {
|
|
301
311
|
/** Height of the ground under the point, metres. Default 0. */
|
|
@@ -403,12 +413,39 @@ interface BodyDimensions {
|
|
|
403
413
|
declare function semiSpecFromStats(stats: DesignStats, body: BodyDimensions, base?: Partial<SemiSimSpec>): SemiSimSpec;
|
|
404
414
|
|
|
405
415
|
/**
|
|
406
|
-
* The
|
|
407
|
-
*
|
|
408
|
-
*
|
|
416
|
+
* The driver aids the controls apply between the pedals and the engine: the drive profile (economy shifts early and softens the gas, sport holds the
|
|
417
|
+
* gears and sharpens it), traction control (cuts the torque while a driven wheel spins past its grip) and cruise control (holds the set speed with the
|
|
418
|
+
* gas; the brake or the clutch cancels it, the gas pedal overrides it while pressed). Pure functions over numbers, every threshold an option.
|
|
409
419
|
*/
|
|
420
|
+
type DriveProfile = 'eco' | 'normal' | 'sport';
|
|
421
|
+
interface ProfileTuning {
|
|
422
|
+
/** Multiplies the gas pedal. */
|
|
423
|
+
readonly throttle: number;
|
|
424
|
+
/** Upshift and downshift points, shares of the redline (the semi driver's `upshiftFraction` and `downshiftFraction`). */
|
|
425
|
+
readonly upshift: number;
|
|
426
|
+
readonly downshift: number;
|
|
427
|
+
}
|
|
428
|
+
declare const DRIVE_PROFILES: Readonly<Record<DriveProfile, ProfileTuning>>;
|
|
429
|
+
interface TractionOptions {
|
|
430
|
+
/** Grip in use of a driven wheel (1 = sliding) above which the torque is cut. */
|
|
431
|
+
readonly slip: number;
|
|
432
|
+
/** Torque left at full spin. */
|
|
433
|
+
readonly floor: number;
|
|
434
|
+
}
|
|
435
|
+
declare const DEFAULT_TRACTION: TractionOptions;
|
|
436
|
+
/** Share of the torque traction control lets through for the worst driven wheel's grip in use (1 = sliding). */
|
|
437
|
+
declare function tractionLimit(slips: readonly number[], options?: TractionOptions): number;
|
|
438
|
+
interface CruiseOptions {
|
|
439
|
+
/** Gas per m/s under the set speed. */
|
|
440
|
+
readonly gain: number;
|
|
441
|
+
/** Lowest speed it engages at, m/s (about 30 km/h). */
|
|
442
|
+
readonly minSpeed: number;
|
|
443
|
+
}
|
|
444
|
+
declare const DEFAULT_CRUISE: CruiseOptions;
|
|
445
|
+
/** Gas cruise control asks for to hold `target` at `speed` (m/s); none above the target, the car coasts down to it. */
|
|
446
|
+
declare function cruiseThrottle(target: number, speed: number, options?: CruiseOptions): number;
|
|
410
447
|
|
|
411
|
-
type ControlCommand = 'ignition' | 'gearbox' | 'gear_up' | 'gear_down' | 'parking_brake' | 'drive_mode' | 'lights' | 'high_beam' | 'fog_lights' | 'interior_light' | 'alarm' | 'radio' | 'radio_source' | 'exit' | 'indicator_left' | 'indicator_right' | 'hazard' | 'wipers' | 'seatbelt';
|
|
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';
|
|
412
449
|
type ControlKeyMap = {
|
|
413
450
|
readonly throttle: readonly string[];
|
|
414
451
|
readonly brake: readonly string[];
|
|
@@ -416,6 +453,12 @@ type ControlKeyMap = {
|
|
|
416
453
|
readonly right: readonly string[];
|
|
417
454
|
readonly handbrake: readonly string[];
|
|
418
455
|
readonly horn: readonly string[];
|
|
456
|
+
readonly clutch: readonly string[];
|
|
457
|
+
/** Flashes the high beam while held. */
|
|
458
|
+
readonly flash: readonly string[];
|
|
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[];
|
|
419
462
|
} & {
|
|
420
463
|
readonly [command in ControlCommand]: readonly string[];
|
|
421
464
|
};
|
|
@@ -427,7 +470,9 @@ type LampMode = 'off' | 'position' | 'low' | 'high';
|
|
|
427
470
|
type AlarmState = 'off' | 'armed' | 'ringing';
|
|
428
471
|
type RadioSource = 'radio' | 'tape';
|
|
429
472
|
type Indicator = 'off' | 'left' | 'right' | 'hazard';
|
|
430
|
-
type Wipers = 'off' | 'slow' | 'fast';
|
|
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';
|
|
431
476
|
interface ControlState {
|
|
432
477
|
ignition: boolean;
|
|
433
478
|
gearbox: Gearbox;
|
|
@@ -438,26 +483,59 @@ interface ControlState {
|
|
|
438
483
|
driveMode: DriveMode;
|
|
439
484
|
/** The front axle drives now (4x4, or automatic 4x4 that felt the rear slip). */
|
|
440
485
|
fourWheelEngaged: boolean;
|
|
486
|
+
/** `flash`: the high beam lit while the flash key is held, over any mode. */
|
|
441
487
|
lamps: {
|
|
442
488
|
mode: LampMode;
|
|
443
489
|
fog: boolean;
|
|
444
490
|
interior: boolean;
|
|
491
|
+
flash: boolean;
|
|
445
492
|
};
|
|
446
493
|
/** What the rear lamps show this step: brake (pedal or handbrake) and reversing. */
|
|
447
494
|
brakeLights: boolean;
|
|
448
495
|
reverseLights: boolean;
|
|
449
496
|
horn: boolean;
|
|
450
497
|
alarm: AlarmState;
|
|
498
|
+
/** `track`: the station or the song on the tape, 0-based (`radioTracks` of them). */
|
|
451
499
|
radio: {
|
|
452
500
|
on: boolean;
|
|
453
501
|
source: RadioSource;
|
|
502
|
+
track: number;
|
|
454
503
|
};
|
|
455
504
|
indicator: Indicator;
|
|
456
505
|
/** The indicator lamps are lit this instant (they blink at `blinkHz`); `tick` is true on the step the relay clicks. */
|
|
457
506
|
blinkOn: boolean;
|
|
458
507
|
tick: boolean;
|
|
459
508
|
wipers: Wipers;
|
|
509
|
+
/** The washer squirts while its key is held (the wipers sweep with it). */
|
|
510
|
+
washer: boolean;
|
|
460
511
|
seatbelt: boolean;
|
|
512
|
+
/** Clutch pedal, 0 up to 1 down (manual gearbox). */
|
|
513
|
+
clutch: number;
|
|
514
|
+
profile: DriveProfile;
|
|
515
|
+
tractionControl: boolean;
|
|
516
|
+
abs: boolean;
|
|
517
|
+
/** Cruise control: the speed it holds, m/s. */
|
|
518
|
+
cruise: {
|
|
519
|
+
on: boolean;
|
|
520
|
+
speed: number;
|
|
521
|
+
};
|
|
522
|
+
climate: {
|
|
523
|
+
on: boolean;
|
|
524
|
+
demist: boolean;
|
|
525
|
+
};
|
|
526
|
+
/** The starter turns this step. */
|
|
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;
|
|
461
539
|
}
|
|
462
540
|
type ControlEvent = {
|
|
463
541
|
type: 'command';
|
|
@@ -466,7 +544,14 @@ type ControlEvent = {
|
|
|
466
544
|
} | {
|
|
467
545
|
type: 'refused';
|
|
468
546
|
command: ControlCommand;
|
|
469
|
-
reason: 'no_four_wheel_drive' | 'no_fog_lamps' | 'ignition_off';
|
|
547
|
+
reason: 'no_four_wheel_drive' | 'no_fog_lamps' | 'ignition_off' | 'battery_flat' | 'too_slow' | 'no_key' | 'no_siren';
|
|
548
|
+
} | {
|
|
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';
|
|
470
555
|
};
|
|
471
556
|
interface VehicleControlOptions {
|
|
472
557
|
/** Forward gears of the gearbox. */
|
|
@@ -488,12 +573,36 @@ interface VehicleControlOptions {
|
|
|
488
573
|
blinkHz?: number;
|
|
489
574
|
/** The steering wheel coming back this far (0..1 of the lock) after a turn cancels the indicator, as the column does. Default 0.15. */
|
|
490
575
|
indicatorCancel?: number;
|
|
576
|
+
/** Stations or songs the radio steps through (`radio_track`). Default 3. */
|
|
577
|
+
radioTracks?: number;
|
|
578
|
+
/** The driver works the clutch (C) in manual: released in gear too slowly or without gas, the engine stalls. Default false (the clutch is automated). */
|
|
579
|
+
clutchPedal?: boolean;
|
|
580
|
+
/** The starter can turn the engine over (a battery with charge); asked at every crank. Default always. */
|
|
581
|
+
canCrank?: () => boolean;
|
|
582
|
+
/** A crank happened (takes the battery's energy). */
|
|
583
|
+
onCrank?: () => void;
|
|
584
|
+
/** Share of the torque the engine gives besides the aids (an overheated engine). Default 1. */
|
|
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;
|
|
491
594
|
onEvent?: (event: ControlEvent) => void;
|
|
492
595
|
}
|
|
493
596
|
/** What the controls read of the driver each step, and the one thing they change on it (which axles drive). */
|
|
494
597
|
interface ControlledDriver {
|
|
495
598
|
readonly spec: {
|
|
496
599
|
fourWheelDrive: boolean;
|
|
600
|
+
abs?: boolean;
|
|
601
|
+
upshiftFraction?: number;
|
|
602
|
+
downshiftFraction?: number;
|
|
603
|
+
readonly wheels?: ReadonlyArray<{
|
|
604
|
+
drive?: boolean;
|
|
605
|
+
}>;
|
|
497
606
|
};
|
|
498
607
|
readonly state: {
|
|
499
608
|
u: number;
|
|
@@ -526,6 +635,8 @@ type DamagedTyre = {
|
|
|
526
635
|
readonly z: number;
|
|
527
636
|
/** 0 flat or gone, 1 whole. */
|
|
528
637
|
readonly health: number;
|
|
638
|
+
/** The tyre is gone and the rim is on the road. */
|
|
639
|
+
readonly rim?: boolean;
|
|
529
640
|
};
|
|
530
641
|
type DamageReport = {
|
|
531
642
|
readonly tyres: readonly DamagedTyre[];
|
|
@@ -535,4 +646,315 @@ type DamageReport = {
|
|
|
535
646
|
};
|
|
536
647
|
declare function conditionFromDamage(spec: Pick<SemiSimSpec, 'wheels'>, report: DamageReport): VehicleCondition;
|
|
537
648
|
|
|
538
|
-
|
|
649
|
+
/**
|
|
650
|
+
* What keeps a car running besides the engine: the 12 V battery (the lamps, radio, wipers and alarm draw from it, the alternator charges it while
|
|
651
|
+
* the engine turns, and below what the starter needs the car does not start), the coolant temperature (it climbs with the work of the engine, the air
|
|
652
|
+
* through the radiator and the fan take it away, and a damaged radiator boils it: past `limpC` the engine loses power, past `seizeC` it dies) and the
|
|
653
|
+
* spare tyre (one flat wheel can be swapped for it). It reads the driver and the controls and changes only what a real car would: the engine state,
|
|
654
|
+
* the power it gives and the tyres. Every number is an option.
|
|
655
|
+
*/
|
|
656
|
+
|
|
657
|
+
interface ElectricalLoads {
|
|
658
|
+
/** Watts of each consumer while on. */
|
|
659
|
+
readonly position: number;
|
|
660
|
+
readonly low: number;
|
|
661
|
+
readonly high: number;
|
|
662
|
+
readonly fog: number;
|
|
663
|
+
readonly interior: number;
|
|
664
|
+
readonly radio: number;
|
|
665
|
+
readonly wipers: number;
|
|
666
|
+
readonly indicators: number;
|
|
667
|
+
readonly horn: number;
|
|
668
|
+
readonly alarm: number;
|
|
669
|
+
readonly brakeLights: number;
|
|
670
|
+
readonly climate: number;
|
|
671
|
+
/** An emergency vehicle's siren amplifier and its beacon (light bar). */
|
|
672
|
+
readonly siren: number;
|
|
673
|
+
readonly beacon: number;
|
|
674
|
+
}
|
|
675
|
+
interface VehicleSystemsOptions {
|
|
676
|
+
/** Battery capacity, watt-hours (a 12 V 60 Ah battery holds 720). */
|
|
677
|
+
batteryWh?: number;
|
|
678
|
+
/** Charge at the start, 0..1. */
|
|
679
|
+
charge?: number;
|
|
680
|
+
/** Alternator output, watts, at idle and from 2000 rpm up. */
|
|
681
|
+
alternatorW?: {
|
|
682
|
+
idle: number;
|
|
683
|
+
full: number;
|
|
684
|
+
};
|
|
685
|
+
/** Below this charge the starter does not turn the engine over. */
|
|
686
|
+
crankCharge?: number;
|
|
687
|
+
/** Energy of one start, watt-hours. */
|
|
688
|
+
startWh?: number;
|
|
689
|
+
loads?: Partial<ElectricalLoads>;
|
|
690
|
+
/** Air temperature, °C. */
|
|
691
|
+
ambientC?: number;
|
|
692
|
+
/** The thermostat holds the coolant here once warm. */
|
|
693
|
+
thermostatC?: number;
|
|
694
|
+
/** Limp mode above this (power cut), engine seizes above `seizeC`. */
|
|
695
|
+
limpC?: number;
|
|
696
|
+
seizeC?: number;
|
|
697
|
+
/** Warming of the coolant, °C per second at full power; cooling share of the gap to the air per second, at a stop and at 100 km/h. */
|
|
698
|
+
heatPerSecond?: number;
|
|
699
|
+
cooling?: {
|
|
700
|
+
stopped: number;
|
|
701
|
+
fast: number;
|
|
702
|
+
};
|
|
703
|
+
/** Spare tyres carried. */
|
|
704
|
+
spares?: number;
|
|
705
|
+
}
|
|
706
|
+
declare const DEFAULT_LOADS: ElectricalLoads;
|
|
707
|
+
type SystemsEvent = {
|
|
708
|
+
type: 'battery_flat';
|
|
709
|
+
} | {
|
|
710
|
+
type: 'overheating';
|
|
711
|
+
} | {
|
|
712
|
+
type: 'seized';
|
|
713
|
+
} | {
|
|
714
|
+
type: 'spare_fitted';
|
|
715
|
+
wheel: number;
|
|
716
|
+
} | {
|
|
717
|
+
type: 'no_spare';
|
|
718
|
+
};
|
|
719
|
+
interface SystemsState {
|
|
720
|
+
/** 0..1. */
|
|
721
|
+
charge: number;
|
|
722
|
+
/** Coolant, °C. */
|
|
723
|
+
coolantC: number;
|
|
724
|
+
/** 0 cold (the air) to 1 (the seize point), for a gauge. */
|
|
725
|
+
temperature: number;
|
|
726
|
+
overheating: boolean;
|
|
727
|
+
seized: boolean;
|
|
728
|
+
spares: number;
|
|
729
|
+
/** Net watts on the battery this step: positive charging, negative draining. */
|
|
730
|
+
netW: number;
|
|
731
|
+
}
|
|
732
|
+
interface SystemsDriver {
|
|
733
|
+
readonly state: Pick<SemiState, 'engineOn' | 'rpm' | 'u'>;
|
|
734
|
+
condition: VehicleCondition;
|
|
735
|
+
}
|
|
736
|
+
interface SystemsStepParams {
|
|
737
|
+
driver: SystemsDriver;
|
|
738
|
+
controls: ControlState;
|
|
739
|
+
/** The gas the engine got this step, 0..1. */
|
|
740
|
+
throttle: number;
|
|
741
|
+
dt: number;
|
|
742
|
+
/** What is left of the radiator, 0..1. Default 1. */
|
|
743
|
+
radiator?: number;
|
|
744
|
+
/** The coolant temperature from a damage model that tracks it (the vehicle destructible's `runEngine`): it replaces this model's own. */
|
|
745
|
+
coolantC?: number;
|
|
746
|
+
}
|
|
747
|
+
interface VehicleSystems {
|
|
748
|
+
readonly state: SystemsState;
|
|
749
|
+
/** The starter can turn the engine over now. */
|
|
750
|
+
canCrank(): boolean;
|
|
751
|
+
/** Takes the energy of one start. */
|
|
752
|
+
crank(): void;
|
|
753
|
+
/** Share of the torque the engine gives now (limp mode when hot). */
|
|
754
|
+
powerLimit(): number;
|
|
755
|
+
/** Advances `dt` seconds; `throttle` is the gas the engine got, `controls` what is switched on. */
|
|
756
|
+
step(params: SystemsStepParams): SystemsEvent[];
|
|
757
|
+
/** Swaps the flat tyre of `wheel` for the spare. */
|
|
758
|
+
fitSpare(driver: SystemsDriver, wheel: number): SystemsEvent;
|
|
759
|
+
/** Fills the battery (a jump start or a charger), 0..1 of the capacity. */
|
|
760
|
+
charge(share: number): void;
|
|
761
|
+
}
|
|
762
|
+
declare function createVehicleSystems(options?: VehicleSystemsOptions): VehicleSystems;
|
|
763
|
+
|
|
764
|
+
/**
|
|
765
|
+
* Who leaves the car in a crash. An occupant without a belt keeps the speed the car had (inertia) while the car stops: in a frontal crash past
|
|
766
|
+
* about 30 km/h of change in speed the body goes through the windshield, in a hard side impact or a rollover through the side window on the side it
|
|
767
|
+
* is thrown to. A belted occupant stays in (a belt holds a person to the seat up to crashes far harder than a road car survives). The glass breaks
|
|
768
|
+
* first; the body flies with most of the car's speed before the crash and a little lift. Pure numbers, every threshold an option.
|
|
769
|
+
*/
|
|
770
|
+
type EjectionExit = 'windshield' | 'left_window' | 'right_window' | 'rear_window';
|
|
771
|
+
interface EjectionOptions {
|
|
772
|
+
/** Change of speed, m/s, past which an unbelted occupant goes through the windshield (about 30 km/h). */
|
|
773
|
+
frontal: number;
|
|
774
|
+
/** Sideways change of speed, m/s, past which an unbelted occupant goes out of a side window. */
|
|
775
|
+
side: number;
|
|
776
|
+
/** Share of the speed before the crash the body keeps on the way out (the glass and the dash take the rest). */
|
|
777
|
+
keep: number;
|
|
778
|
+
/** Upward speed of the body leaving, m/s (it rides up over the dash). */
|
|
779
|
+
lift: number;
|
|
780
|
+
}
|
|
781
|
+
declare const DEFAULT_EJECTION: EjectionOptions;
|
|
782
|
+
interface CrashPulse {
|
|
783
|
+
/** Body-frame speed before and after the crash, m/s: forward and to the right. */
|
|
784
|
+
readonly before: {
|
|
785
|
+
readonly u: number;
|
|
786
|
+
readonly w: number;
|
|
787
|
+
};
|
|
788
|
+
readonly after: {
|
|
789
|
+
readonly u: number;
|
|
790
|
+
readonly w: number;
|
|
791
|
+
};
|
|
792
|
+
/** The car rolled over in it. */
|
|
793
|
+
readonly rolled?: boolean;
|
|
794
|
+
}
|
|
795
|
+
interface Ejection {
|
|
796
|
+
readonly exit: EjectionExit;
|
|
797
|
+
/** Body-frame velocity of the body leaving, m/s: forward, to the right, up. */
|
|
798
|
+
readonly velocity: readonly [number, number, number];
|
|
799
|
+
/** Change of speed of the crash, m/s (what the injuries scale with). */
|
|
800
|
+
readonly deltaV: number;
|
|
801
|
+
}
|
|
802
|
+
/** The ejection of one occupant, or null when the occupant stays in. */
|
|
803
|
+
declare function ejectionOf(pulse: CrashPulse, belted: boolean, options?: EjectionOptions): Ejection | null;
|
|
804
|
+
|
|
805
|
+
/**
|
|
806
|
+
* Parking sensors: the bumper's distance to the nearest obstacle in the way turns into the beep the cabin plays, slower far away, faster close,
|
|
807
|
+
* continuous at the last few centimetres. Pure numbers, the distances are options.
|
|
808
|
+
*/
|
|
809
|
+
interface ParkingSensorOptions {
|
|
810
|
+
/** Farther than this (metres) it stays quiet. */
|
|
811
|
+
readonly range: number;
|
|
812
|
+
/** Closer than this it beeps without pause. */
|
|
813
|
+
readonly solid: number;
|
|
814
|
+
/** Pause between beeps at the edge of the range and near `solid`, seconds. */
|
|
815
|
+
readonly slowest: number;
|
|
816
|
+
readonly fastest: number;
|
|
817
|
+
}
|
|
818
|
+
declare const DEFAULT_PARKING_SENSOR: ParkingSensorOptions;
|
|
819
|
+
/** Seconds between beeps for an obstacle `distance` metres from the bumper: null when quiet, 0 when continuous. */
|
|
820
|
+
declare function parkingBeepInterval(distance: number, options?: ParkingSensorOptions): number | null;
|
|
821
|
+
/**
|
|
822
|
+
* The bumper's distance to the nearest of `obstacles` (world x, z) in the vehicle's path: ahead when `forward`, behind otherwise. The vehicle is
|
|
823
|
+
* at (x, z) facing `heading` (unit x, z), `length` and `width` metres; obstacles off to the side of its width are not in the way.
|
|
824
|
+
*/
|
|
825
|
+
declare function bumperDistance(params: {
|
|
826
|
+
x: number;
|
|
827
|
+
z: number;
|
|
828
|
+
heading: readonly [number, number];
|
|
829
|
+
length: number;
|
|
830
|
+
width: number;
|
|
831
|
+
forward: boolean;
|
|
832
|
+
obstacles: ReadonlyArray<readonly [number, number]>;
|
|
833
|
+
}): number;
|
|
834
|
+
|
|
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 };
|