@adatechnology/game-vehicles 0.5.0 → 0.6.1

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 { MaterialId, Vec3, JointKind, ToolKind, DestructibleImpl, AnimationClipSpec, IgnitionRules, ObjectState, Enclosure } from '@adatechnology/game-contracts';
1
+ import { MaterialId, Vec3, JointKind, ToolKind, DeferredQueue, DestructibleImpl, AnimationClipSpec, IgnitionRules, DestructionEvent, ObjectState, Enclosure } from '@adatechnology/game-contracts';
2
2
 
3
3
  /**
4
4
  * Light mode ("lite"): the same vehicles with fewer triangles, for a whole street of them. Port of the `[LOD]` hooks of the team's Frota Leve
@@ -39,6 +39,18 @@ declare function createLod(options?: Partial<LodSettings>): LodSettings;
39
39
  */
40
40
  declare function wrapThreeForLod(TH: any, lod: LodSettings): any;
41
41
 
42
+ /** Smoke, fire and dust puffs handed to the host's effects world instead of the kit's own sprites. */
43
+ /** What `EffectSink.play` of `game-contracts` takes, as a structural type: this package does not depend on the contracts layer. */
44
+ interface ParticleEffectRequest {
45
+ readonly effect: string;
46
+ readonly point: [number, number, number];
47
+ readonly values: Readonly<Record<string, number>>;
48
+ }
49
+ /** The host's effects world as far as the puffs need it (`EffectSink` of `game-contracts` fits). */
50
+ interface ParticleEffects {
51
+ play(request: ParticleEffectRequest): unknown;
52
+ }
53
+
42
54
  /**
43
55
  * Damageable parts: what a bullet, a bat or a crash can hurt on a built vehicle, as boxes. Port of `coletarDanificaveis` and `tipoDaZona`
44
56
  * (frota-leve.js 14391-14405), driven by the zones the kit already derives, so it works for any vehicle of any pack.
@@ -571,8 +583,25 @@ interface VehicleKitOptions extends KitConfiguration {
571
583
  locale?: string | PartialLocaleStrings;
572
584
  /** Document used for canvas textures and the UI. Defaults to the global `document`. */
573
585
  document?: Document;
586
+ /**
587
+ * Where the material of every smoke, fire and dust puff comes from and goes back to: puffs change their own material every frame (opacity, rotation, dissolve), so each keeps one, but
588
+ * handing them to the host's pool keeps the shader program linked when the last puff dies. Without it each puff makes and disposes its own (deprecated, removed in the next major).
589
+ */
590
+ particleMaterials?: ParticleMaterials;
591
+ /**
592
+ * The host's effects world, read at each puff (the host attaches after the first build). With one, smoke, fire and dust go through it and its one budget; without one the kit draws its own
593
+ * sprites with their own cap (deprecated, removed in the next major).
594
+ */
595
+ effects?: () => ParticleEffects | undefined;
574
596
  plugins?: Plugin[];
575
597
  }
598
+ /** What the host's material pool (`MaterialPool` of `@adatechnology/game-render-three`) lends the particles: a structural type, because this package does not depend on the render layer. */
599
+ interface ParticleMaterials {
600
+ /** Makes (with `build`) a material the caller owns and changes per frame. */
601
+ own<TMaterial>(build: () => TMaterial): TMaterial;
602
+ /** Gives it back: the first of its program family is kept alive, the others are disposed. */
603
+ release(material: unknown): void;
604
+ }
576
605
  interface ImpactOptions {
577
606
  /** Do not leave a stain. */
578
607
  noStain?: boolean;
@@ -755,6 +784,30 @@ declare function rng(seed: number): () => number;
755
784
  /** FNV-1a hash of a string, used to derive seeds from vehicle keys and zone ids. */
756
785
  declare function strHash(s: string): number;
757
786
 
787
+ /**
788
+ * Armour levels of a vehicle, after NIJ 0108: the level says which rounds the glass and the steel stop, and how many hits they take
789
+ * before they give. Every number is configurable: a game passes its own table in `VehicleDestructibleOptions.armourLevels`.
790
+ */
791
+ type ArmourLevelId = 'IIIA' | 'III';
792
+ type ArmourLevel = {
793
+ /** Energy in joules a round needs to go through the armoured glass. */
794
+ readonly glassStops: number;
795
+ /** Joules of hits the armoured glass takes before it gives way. */
796
+ readonly glassHp: number;
797
+ /** Share of a stopped round's energy the glass takes as damage (it cracks round the hit and holds). */
798
+ readonly glassTakes: number;
799
+ /** How much harder the steel skin is than a plain car's. */
800
+ readonly steel: number;
801
+ };
802
+ /** IIIA: civilian armour, stops handguns up to .44 Magnum, a rifle goes through. III: armour against rifles up to 7.62x51 (cash in transit, military). */
803
+ declare const ARMOUR_LEVELS: Readonly<Record<ArmourLevelId, ArmourLevel>>;
804
+ /** The level a vehicle has: the host's option, else its spec (`armor`), else III for the old `armored`/`bullet` flags, else none. */
805
+ declare function armourLevelOf(meta: {
806
+ armor?: string;
807
+ armored?: boolean;
808
+ bullet?: boolean;
809
+ }, option?: ArmourLevelId | null): ArmourLevelId | null;
810
+
758
811
  /**
759
812
  * Part and joint model of a vehicle for the destruction contract: every damage zone becomes a part with a material, the mechanical parts the
760
813
  * zones do not cover (battery, alternator, gearbox, brakes, steering, shock absorbers, tow hitch, tyres, mirrors, pillars...) are added from the
@@ -782,6 +835,8 @@ interface PartDef {
782
835
  hp: number;
783
836
  /** The damage zone this part is, when it is one. */
784
837
  zoneId?: string;
838
+ /** The panes of a glass part no damage zone claims. */
839
+ panes?: any[];
785
840
  /** Fluid held, in litres. */
786
841
  contains?: {
787
842
  fluid: string;
@@ -791,7 +846,8 @@ interface PartDef {
791
846
  explodes?: {
792
847
  energy: number;
793
848
  radius: number;
794
- atC: number;
849
+ atC: number; /** The named explosion of game-vfx it plays (its fireball and its sound). */
850
+ effect?: string;
795
851
  };
796
852
  /** Temperature in Celsius at which the part catches fire (none: it does not burn). */
797
853
  ignitionC?: number;
@@ -820,6 +876,8 @@ interface VehicleModel {
820
876
  interface ModelOptions {
821
877
  /** Fit a tow hitch. Default: the spec flag `hitch`, else a seeded choice by vehicle kind. */
822
878
  hitch?: boolean;
879
+ /** Armour of the vehicle: its glass is laminated and as strong as the level says. */
880
+ armour?: ArmourLevel | null;
823
881
  }
824
882
  /** Joint kinds as the vehicle uses them: strength in joules of wear, the tools that undo them and the seconds of work. */
825
883
  declare const JOINT_RULES: Record<'hinge' | 'bolt' | 'weld' | 'glue' | 'clip', {
@@ -827,9 +885,31 @@ declare const JOINT_RULES: Record<'hinge' | 'bolt' | 'weld' | 'glue' | 'clip', {
827
885
  tools: ToolKind[];
828
886
  seconds: number;
829
887
  }>;
830
- /** Builds the part and joint model of a built vehicle. */
831
888
  declare function buildVehicleModel(kit: VehicleKit, c: VehicleContext, options?: ModelOptions): VehicleModel;
832
889
 
890
+ /** What one vehicle's visuals give the shared crease queue: the normal smoothing and the triangle indexes still to finish. */
891
+ interface CreaseWork {
892
+ /** Units waiting; 0 in the frame a panel was torn (that frame already paid for the cut). `frame` is the budget's frame counter. */
893
+ pendingUnits(frame?: number): number;
894
+ /** Runs one slice of the work (a smoothing step or a piece of the index warm-up) until `deadline` on `performance.now()`; false when there was nothing to run. */
895
+ runStep(deadline: number): boolean;
896
+ /** Finishes everything now. */
897
+ finishAll(): void;
898
+ /** While true the vehicle's own update leaves the work to the queue. */
899
+ setQueued(isQueued: boolean): void;
900
+ }
901
+ interface CreaseQueue {
902
+ /** The queue for a frame budget (id `vehicles.crease`, `DEFERRED_PRIORITY['vehicles.crease']`); asking for it changes nothing. */
903
+ deferredQueue(): DeferredQueue;
904
+ /** A vehicle's visuals join the queue; returns the function that takes them out (a rebuilt vehicle, a vehicle that goes away). */
905
+ track(work: CreaseWork): () => void;
906
+ }
907
+ /**
908
+ * One queue for every vehicle of a scene, run round robin over the vehicles with work, so that the first vehicle does not take the whole budget.
909
+ * Until a budget attaches it, each vehicle keeps smoothing in its own `update`.
910
+ */
911
+ declare function createCreaseQueue(): CreaseQueue;
912
+
833
913
  /**
834
914
  * `createVehicleDestructible`: a vehicle that follows the destruction contract of `@adatechnology/game-contracts` and brings its own rules.
835
915
  * Every damage zone and mechanical part is a part with a material, hits become events (dent, hole, crack, fracture, detach, leak, ignite,
@@ -860,6 +940,15 @@ interface VehicleDestructibleOptions {
860
940
  * Defaults and meaning of every number: `IgnitionRules` of `@adatechnology/game-contracts`.
861
941
  */
862
942
  ignition?: Partial<IgnitionRules>;
943
+ /** Armour level of this vehicle (`IIIA` civilian, `III` against rifles), or null for none. Default: its spec. */
944
+ armour?: ArmourLevelId | null;
945
+ /** Replaces or extends the armour table. */
946
+ armourLevels?: Partial<Record<ArmourLevelId, ArmourLevel>>;
947
+ /**
948
+ * One queue that smooths the normals of cut panels for every vehicle that shares it (`createCreaseQueue()`), run by a frame budget. Without it, or while
949
+ * nobody registered the queue with a budget, each vehicle smooths in its own `update` (2.5 ms a frame), as always.
950
+ */
951
+ creaseQueue?: CreaseQueue;
863
952
  }
864
953
  /** What the vehicle can do now, from the state of its hidden mechanics. */
865
954
  interface VehicleStatus {
@@ -894,7 +983,31 @@ interface VehicleDestructible extends DestructibleImpl {
894
983
  rollover(side?: number): void;
895
984
  /** Part ids that are no longer attached to the main body. */
896
985
  detachedParts(): string[];
986
+ /** What the damage leaves for driving: each tyre's health where it stands, the brakes, the engine and the shocks (0 gone .. 1 whole). */
987
+ driveReport(): DriveReport;
988
+ /**
989
+ * The engine ran for `seconds` at `load` (0 idle .. 1 full throttle): without coolant it heats up, steams and seizes in a few minutes;
990
+ * without oil it wears and seizes. Call it while the vehicle is driven. Answers the engine temperature, °C.
991
+ */
992
+ runEngine(seconds: number, load: number): number;
993
+ /**
994
+ * The vehicle rolled `meters` at `speed` m/s: a flat tyre wears through and tears off (a run-flat insert on an armoured vehicle carries it far
995
+ * at up to 80 km/h), then the bare rim grinds on the road throwing sparks. Answers how many rims are on the road.
996
+ */
997
+ rollFlat(meters: number, speed: number): number;
998
+ /** Pushes the drawn body in by `depth` metres around `point` (world), along `direction`: the crumple of a crash. Drawing only. */
999
+ crumple(point: Vec3, direction: Vec3, depth: number): void;
897
1000
  }
1001
+ type DriveReport = {
1002
+ readonly tyres: ReadonlyArray<{
1003
+ readonly x: number;
1004
+ readonly z: number;
1005
+ readonly health: number;
1006
+ }>;
1007
+ readonly brakes: number;
1008
+ readonly engine: number;
1009
+ readonly suspension: number;
1010
+ };
898
1011
  declare function createVehicleDestructible(kit: VehicleKit, vehicleCtx: VehicleContext, options?: VehicleDestructibleOptions): VehicleDestructible;
899
1012
 
900
1013
  interface VehicleItemOptions {
@@ -917,6 +1030,53 @@ interface VehicleItem {
917
1030
  */
918
1031
  declare function buildVehicleItem(kit: VehicleKit, key: string, options?: VehicleItemOptions): VehicleItem;
919
1032
 
1033
+ /**
1034
+ * A vehicle running into something: the energy of the crash, from the masses and the closing speed, becomes blunt hits spread over the
1035
+ * contact. A wide wall crushes the whole front evenly; a pillar or a post goes deep into a narrow strip; a lighter object takes most of
1036
+ * the change of speed and the vehicle little. Every number is configurable through `CrashRules`.
1037
+ */
1038
+
1039
+ type CrashRules = {
1040
+ /** Share of the deformation energy each blunt hit carries into the parts (the rest is the crumple of the structure itself). */
1041
+ readonly energyToDamage: number;
1042
+ /** Width one blunt hit stands for, metres. */
1043
+ readonly hitSpacing: number;
1044
+ /** Below this closing speed nothing deforms (a nudge), m/s. */
1045
+ readonly minSpeed: number;
1046
+ /** Heights over the contact point the blow also lands at, metres: the bumper takes it first, the front above it (hood, lights, grille) after. */
1047
+ readonly rows: readonly number[];
1048
+ /** How far the front crushes per m/s of change of speed, metres (a car into a wall at 50 km/h folds about half a metre), and at most. */
1049
+ readonly crushPerMs: number;
1050
+ readonly maxCrush: number;
1051
+ };
1052
+ declare const CRASH_RULES: CrashRules;
1053
+ type CrashOptions = {
1054
+ /** Where the vehicle touched the obstacle, world space. */
1055
+ readonly point: Vec3;
1056
+ /** The way the vehicle was moving into the obstacle, world space. */
1057
+ readonly direction: Vec3;
1058
+ /** Closing speed, m/s. */
1059
+ readonly speed: number;
1060
+ /** Mass of this vehicle, kg. */
1061
+ readonly massKg: number;
1062
+ /** Mass of what it hit, kg (`Infinity` for a wall, a pillar or anything anchored). */
1063
+ readonly otherMassKg: number;
1064
+ /** How wide the contact is, metres (a post 0.2, a wall the whole front). */
1065
+ readonly contactWidth: number;
1066
+ readonly source?: string;
1067
+ readonly rules?: Partial<CrashRules>;
1068
+ };
1069
+ type CrashResult = {
1070
+ /** Change of speed this vehicle takes, m/s. */
1071
+ readonly deltaV: number;
1072
+ /** Deformation energy this vehicle takes, joules. */
1073
+ readonly energy: number;
1074
+ readonly events: DestructionEvent[];
1075
+ };
1076
+ /** Change of speed of each body in a plastic collision: the lighter one takes more. */
1077
+ declare function crashDeltaV(speed: number, massKg: number, otherMassKg: number): number;
1078
+ declare function crashVehicle(d: VehicleDestructible, crash: CrashOptions): CrashResult;
1079
+
920
1080
  /**
921
1081
  * The cabin of a vehicle as a closed space for the smoke, dust and steam of the host's effects (`EffectSink.enclose` of the contracts): a shut car
922
1082
  * keeps the smoke out. It is open where it is in the real world: a door standing open, a window shattered, a door, glass or roof torn off or burnt
@@ -957,4 +1117,9 @@ declare function swingOf(vehicle: VehicleContext, partId: string): number;
957
1117
  */
958
1118
  declare function cabinEnclosure(source: CabinSource, options?: CabinEnclosureOptions): Enclosure | null;
959
1119
 
960
- export { type Band, type BandId, type BandIndex, type BandOverride, type BuildFunction, type BuildOptions, type BuildState, type BuildZoneState, CABIN_LEAK, type CabinBox, type CabinEnclosureOptions, type CabinSource, type DamageMapOptions, type DamageZone, type Damageable, type DamageableKind, type DamageableMaterial, type DamageableSide, type ExplodeOptions, type FlagEffect, type FluidDefinition, type ImpactOptions, JOINT_RULES, type JointDef, type KitConfiguration, type KitInternals, type KitTexts, LEGACY_STATES, LEGACY_ZONE_IDS, type LocalBox, type LocaleStrings, type LodSettings, type OverallHealth, type PartDef, type PartLabel, type PartRole, type PartialLocaleStrings, type Plugin, type ResolvedConfiguration, SEED_SALTS, type ScenarioContext, type ScenarioDefinition, type ScenarioResult, type SplatOptions, type ThreeObject, type ThreeVector, type Translate, type UiHelpers, type VehicleContext, type VehicleDestructible, type VehicleDestructibleOptions, type VehicleItem, type VehicleItemOptions, type VehicleKit, type VehicleKitOptions, type VehicleMeta, type VehicleModel, type VehiclePart, type VehicleSpec, type VehicleStatus, type ZoneDamageEntry, type ZoneEffect, type ZoneState, buildVehicleItem, buildVehicleModel, cabinBoxOf, cabinEnclosure, clamp, createLod, createTranslate, createVehicleDestructible, createVehicleKit, defaultDamageableKinds, defaultLodSettings, format, hash, legacyGlassId, legacyLightId, legacyZoneId, listLocales, registerLegacySeeds, registerLocale, resolveStrings, rng, smooth, strHash, swingOf, wrapThreeForLod };
1120
+ /** Glass cracks, shattering and tempered or laminated breakage textures. */
1121
+
1122
+ /** The material of a pane with cracks drawn on it. A host warms its program at load with any texture: the first crack is in the middle of a blast. */
1123
+ declare function crackedGlassMaterial(THREE: any, texture: unknown): any;
1124
+
1125
+ export { ARMOUR_LEVELS, type ArmourLevel, type ArmourLevelId, type Band, type BandId, type BandIndex, type BandOverride, type BuildFunction, type BuildOptions, type BuildState, type BuildZoneState, CABIN_LEAK, CRASH_RULES, type CabinBox, type CabinEnclosureOptions, type CabinSource, type CrashOptions, type CrashResult, type CrashRules, type CreaseQueue, type CreaseWork, type DamageMapOptions, type DamageZone, type Damageable, type DamageableKind, type DamageableMaterial, type DamageableSide, type DriveReport, type ExplodeOptions, type FlagEffect, type FluidDefinition, type ImpactOptions, JOINT_RULES, type JointDef, type KitConfiguration, type KitInternals, type KitTexts, LEGACY_STATES, LEGACY_ZONE_IDS, type LocalBox, type LocaleStrings, type LodSettings, type OverallHealth, type PartDef, type PartLabel, type PartRole, type PartialLocaleStrings, type ParticleEffectRequest, type ParticleEffects, type ParticleMaterials, type Plugin, type ResolvedConfiguration, SEED_SALTS, type ScenarioContext, type ScenarioDefinition, type ScenarioResult, type SplatOptions, type ThreeObject, type ThreeVector, type Translate, type UiHelpers, type VehicleContext, type VehicleDestructible, type VehicleDestructibleOptions, type VehicleItem, type VehicleItemOptions, type VehicleKit, type VehicleKitOptions, type VehicleMeta, type VehicleModel, type VehiclePart, type VehicleSpec, type VehicleStatus, type ZoneDamageEntry, type ZoneEffect, type ZoneState, armourLevelOf, buildVehicleItem, buildVehicleModel, cabinBoxOf, cabinEnclosure, clamp, crackedGlassMaterial, crashDeltaV, crashVehicle, createCreaseQueue, createLod, createTranslate, createVehicleDestructible, createVehicleKit, defaultDamageableKinds, defaultLodSettings, format, hash, legacyGlassId, legacyLightId, legacyZoneId, listLocales, registerLegacySeeds, registerLocale, resolveStrings, rng, smooth, strHash, swingOf, wrapThreeForLod };