@adatechnology/game-vehicles 0.2.0 → 0.4.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/README.md CHANGED
@@ -18,7 +18,7 @@ pnpm add @adatechnology/game-vehicles three
18
18
  Browser without a bundler (the global is `GameVehicles`):
19
19
 
20
20
  ```html
21
- <script src="https://unpkg.com/three@0.128.0/build/three.min.js"></script>
21
+ <script src="https://unpkg.com/three@0.160.1/build/three.min.js"></script>
22
22
  <script src="https://unpkg.com/@adatechnology/game-vehicles/dist/index.global.js"></script>
23
23
  <script>
24
24
  const kit = GameVehicles.createVehicleKit({ THREE })
@@ -64,6 +64,9 @@ scene.remove(c.root); kit.dispose(c)
64
64
  const hurt = kit.build('meteor', 'intact', state)
65
65
  scene.add(hurt.root)
66
66
 
67
+ // ...or name a registered scenario and build it in one call (explicit health / flags given alongside win)
68
+ const wreck = kit.build('meteor', 'intact', { scenario: 'burnt' })
69
+
67
70
  // 4. animate (particles, fluids, hood, rollover, explosions)
68
71
  kit.tick(hurt, dt)
69
72
  ```
@@ -89,7 +92,7 @@ and a band decided by the health:
89
92
  | 3 | `destroyed` | 1 to 25 | Heavy deformation, parts fall off |
90
93
  | 4 | `torn_off` | 0 | The part is gone |
91
94
 
92
- Bands only change the look when the band changes; `kit.build(key, state, zoneState)` rebuilds the vehicle and reapplies every zone.
95
+ Bands only change the look when the band changes; `kit.build(key, state, zoneState)` rebuilds the vehicle and reapplies every zone. `zoneState` may also carry `scenario: 'id or name'`: the scenario is computed on the vehicle being built (no probe build) and any `health` / `flags` given with it are merged on top. An unknown scenario damages nothing, like `zoneScenario`.
93
96
 
94
97
  **Content packs.** A pack is a plugin: `{ name, configure, install(kit) }`. `configure` accepts everything in the configuration table below and
95
98
  `install` can call `kit.register(...)`, `kit.scenario(...)`, `kit.defineFluid(...)`, `kit.on(...)` and so on. The engine never imports a pack.
@@ -139,7 +142,7 @@ created with, so `kit.t('mypack.some.key')` reads from it, with English as the f
139
142
  | Area | Methods |
140
143
  |---|---|
141
144
  | Registry | `register(spec, build)`, `find(key)`, `fleet`, `configure`, `plugin`, `on`/`hook`, `scenario`, `defineFluid` |
142
- | Lifecycle | `build(key, state?, zoneState?)`, `dispose(c)`, `tick(c, dt)`, `settle(c, seconds)`, `defaultDamage(c)` |
145
+ | Lifecycle | `build(key, state?, zoneState?)` (`zoneState.scenario` runs a scenario), `dispose(c)`, `tick(c, dt)`, `settle(c, seconds)`, `defaultDamage(c)` |
143
146
  | Zones | `bandOf(health)`, `zonesOf(c)`, `applyZones(c, state)`, `zoneScenario(c, id)`, `zoneOverall(c)`, `zoneAt(c, point)`, `zoneDamageAt(c, point, dir, force)`, `zonePoint(c, zone)`, `zoneEffect(zone, health?)`, `zoneOwner` |
144
147
  | Events | `impact(c, point, dir, force, options?)`, `zoneImpact(c, side, force)` (side: `front`, `rear`, `left`, `right` or `rolled`), `explode(c, options?)`, `blastDamage(c, amount)`, `roll(c, side?)`, `setHood(c, open)` |
145
148
  | Fluids and particles | `splat`, `puddle`, `wipe(c, mode)` (`wiper` or `rain`), `spawn`, `burst`, `addEmitter` |
@@ -175,6 +178,7 @@ kit.scenario({
175
178
  })
176
179
  const result = kit.zoneScenario(c, 'front') // { health, flags, scenario }
177
180
  const hurt = kit.build('meteor', 'intact', result)
181
+ const same = kit.build('meteor', 'intact', { scenario: 'front' }) // the two steps in one call
178
182
  ```
179
183
 
180
184
  `x` has `c`, `meta`, `front`, `rear`, `length`, `width`, `clearance`, `top`, `rand()`, `set(zone, health)`, `flags`, `health`, `center` (of the zone
@@ -201,6 +205,13 @@ Plain DOM and SVG, no framework: `ui.damageMap(host, c, { selected, onSelect })`
201
205
  ones in a strip below); `ui.bandButtons`, `ui.legend`, `ui.healthBar({ text, bar }, c)`, `ui.scenarioButtons`. `ui.injectStyles()` adds minimal CSS
202
206
  (`--panel-2`, `--line` and `--muted` customise it).
203
207
 
208
+ ## Geometry
209
+
210
+ The kit's three is `shapeGeometries(THREE)` of `@adatechnology/game-shapes-three`, thinned by the light mode: boxes, cylinders, cones, spheres,
211
+ planes, circles, rings, tori, the tyre lathes and the straight-edged extrusions are made by game-shapes, bit-identical to three's
212
+ (`tests/exact-golden.test.ts`, and the fleet's and `game-vehicles-three`'s) and cached by parameters across vehicles. Tubes, curved
213
+ extrusions, the lofted bodies and the warps stay three's own or the kit's custom buffers. The IIFE build bundles game-shapes.
214
+
204
215
  ## Determinism and old seeds
205
216
 
206
217
  The random stream of a zone is seeded from the vehicle key, the zone id and the band. The first version of this engine used Portuguese ids, so ids
@@ -241,6 +252,12 @@ car.animations() // open/close clips for the doors, hood and trunk
241
252
 
242
253
  Fluids: the tank, the oil pan and the radiator hold fuel, oil and coolant; a hole below the level makes a `leak` event, a puddle and a falling level.
243
254
 
255
+ Fuel tank: a bullet that goes through it **leaks and does not set it alight by itself**. The leak lights (event `ignite`, then the usual fire and, for a petrol tank, the explosion) with
256
+ a spark of a hard round on the steel wall, an incendiary or tracer round, a burning part or burning fuel stain within `ignition.fireNear.radius`, or a blast. The chances of the round
257
+ come in `Hit.ignition` (the weapons build them from the core and jacket of the ammunition) and are weighed by how full the tank is (`fuel`, 0 to 1, the starting level; a nearly empty tank lights
258
+ easiest, a full one mostly leaks); diesel takes a spark far worse than petrol. `createVehicleDestructible(kit, vehicle, { fuel: 0.1, ignition: { fillCurve, fireNear, sparkTarget } })`;
259
+ the defaults and every number are `IgnitionRules` of `@adatechnology/game-contracts`.
260
+
244
261
  ## Português
245
262
 
246
263
  Motor genérico de veículos procedurais para three.js: carrocerias, vidros, faróis, rodas, interiores, capô e compartimento do motor, **zonas de dano
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ToolKind, JointKind, Vec3, MaterialId, DestructibleImpl, AnimationClipSpec } from '@adatechnology/game-contracts';
1
+ import { ToolKind, JointKind, Vec3, MaterialId, DestructibleImpl, AnimationClipSpec, IgnitionRules } 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
@@ -337,6 +337,8 @@ interface VehicleContext {
337
337
  meta: VehicleMeta;
338
338
  zones: DamageZone[];
339
339
  zoneState: ZoneState;
340
+ /** The scenario the vehicle was built in (`kit.build(key, state, { scenario })`), so a rebuild keeps it. */
341
+ scenario?: string;
340
342
  /** Deterministic random generator seeded from the vehicle key and state. */
341
343
  rand: () => number;
342
344
  parts: VehiclePart[];
@@ -418,6 +420,11 @@ interface ZoneState {
418
420
  health: Record<string, number>;
419
421
  flags: Record<string, boolean>;
420
422
  }
423
+ /** The zone-state argument of `kit.build`: a `ZoneState` plus an optional scenario to compute on the vehicle being built. */
424
+ interface BuildZoneState extends Partial<ZoneState> {
425
+ /** Id or name of a registered scenario (e.g. the fleet's `burnt`); explicit `health` / `flags` override its result. */
426
+ scenario?: string;
427
+ }
421
428
  interface ScenarioResult {
422
429
  health: Record<string, number>;
423
430
  flags: Record<string, boolean>;
@@ -662,7 +669,7 @@ interface VehicleKit {
662
669
  defineFluid(key: string, def: FluidDefinition): FluidDefinition;
663
670
  on(event: string, fn: (...args: any[]) => void): VehicleKit;
664
671
  hook(event: string, ...args: any[]): void;
665
- build(key: string, state?: BuildState, zoneState?: Partial<ZoneState>, options?: BuildOptions): VehicleContext;
672
+ build(key: string, state?: BuildState, zoneState?: BuildZoneState, options?: BuildOptions): VehicleContext;
666
673
  /** The damageable parts of a built vehicle as boxes (optionally in the frame of `matrix`). */
667
674
  damageables(c: VehicleContext, matrix?: ThreeObject): Damageable[];
668
675
  dispose(c: VehicleContext): void;
@@ -844,6 +851,15 @@ interface VehicleDestructibleOptions {
844
851
  headless?: boolean;
845
852
  /** Extra seed for the choices that are random in the real world (which way a broken steering pulls). */
846
853
  seed?: number;
854
+ /** How full the fuel tank starts, 0 to 1 (default 1). A nearly empty tank leaks little and lights easily (see `ignition`). */
855
+ fuel?: number;
856
+ /**
857
+ * What lights the fuel that leaks from a pierced tank: a plain bullet only leaks; a spark of a hard round on steel, an incendiary or tracer
858
+ * round, a fire within `fireNear.radius` (a burning part or a burning fuel stain) or a blast lights it, and then the usual fire and explosion
859
+ * follow. The chance of the round is in `Hit.ignition`; this is the target side (how full the tank is, what the wall is, the fire near).
860
+ * Defaults and meaning of every number: `IgnitionRules` of `@adatechnology/game-contracts`.
861
+ */
862
+ ignition?: Partial<IgnitionRules>;
847
863
  }
848
864
  /** What the vehicle can do now, from the state of its hidden mechanics. */
849
865
  interface VehicleStatus {
@@ -885,6 +901,8 @@ interface VehicleItemOptions {
885
901
  state?: BuildState;
886
902
  /** Build in the light mode of the kit (`kit.lod`): fewer segments and no interior, for crowds and for budgets. Default off. */
887
903
  lod?: boolean;
904
+ /** A registered damage scenario (id or name, e.g. the fleet's `burnt`) built into the vehicle, through `kit.build(key, state, { scenario })`. */
905
+ scenario?: string;
888
906
  }
889
907
  interface VehicleItem {
890
908
  /** Add this to the scene: origin at the centre of the footprint on the floor, front facing +z. */
@@ -899,4 +917,4 @@ interface VehicleItem {
899
917
  */
900
918
  declare function buildVehicleItem(kit: VehicleKit, key: string, options?: VehicleItemOptions): VehicleItem;
901
919
 
902
- export { type Band, type BandId, type BandIndex, type BandOverride, type BuildFunction, type BuildOptions, type BuildState, 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, clamp, createLod, createTranslate, createVehicleDestructible, createVehicleKit, defaultDamageableKinds, defaultLodSettings, format, hash, legacyGlassId, legacyLightId, legacyZoneId, listLocales, registerLegacySeeds, registerLocale, resolveStrings, rng, smooth, strHash, wrapThreeForLod };
920
+ export { type Band, type BandId, type BandIndex, type BandOverride, type BuildFunction, type BuildOptions, type BuildState, type BuildZoneState, 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, clamp, createLod, createTranslate, createVehicleDestructible, createVehicleKit, defaultDamageableKinds, defaultLodSettings, format, hash, legacyGlassId, legacyLightId, legacyZoneId, listLocales, registerLegacySeeds, registerLocale, resolveStrings, rng, smooth, strHash, wrapThreeForLod };