@adatechnology/game-vehicles-driving 0.2.28 → 0.2.30

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
@@ -20,3 +20,9 @@ The driver never touches a game: the host applies damage, shakes the camera, kil
20
20
  ## Semi-simulation
21
21
 
22
22
  `createSemiSimDriver(spec)` is the driving the Frota document asks for: a single rigid body with a low centre of mass, a spring and damper on each wheel measured against the ground under it (`world.ground(x, z)`), longitudinal and lateral tyre forces apart inside a friction circle, an automatic gearbox with a simulated RPM, a handbrake that locks the rear wheels, surfaces (`dry_asphalt` 1.0, `wet_asphalt` 0.75 with aquaplaning above 90 km/h, `dirt` 0.65, `grass` 0.55, `mud` 0.4 that bogs a vehicle without four-wheel drive, `blood` 0.5) and damage that changes how it drives (`driver.condition`: a flat tyre pulls to its side, a damaged suspension rolls more, an engine under 30% fails at full throttle and can die uphill). Fuel use follows the RPM, the cargo and the engine (up to +40% when wrecked). `semiSpecFromStats` builds a spec from the design ratings; `impactEnergy`, `bodyDamage`, `vehicleDamageFromImpact` and `speedLoss` are the run-over formulas of section 08. There is no team code for it: the document's numbers are the tests, and no golden is claimed.
23
+
24
+ ## Running over people (`createRunOver`, spec 008 T6.26)
25
+
26
+ `createRunOver(options)` runs in the `actors` phase of the tick: for each car above 1 m/s it asks the physics world for the agents (layer `agent`) under the car's box and strikes each once while it stays under the car. The approach speed goes to `runOver()` with the `RunOverRules`: `push` (below 3 m/s: the agent is moved aside and the car is held by `holdDrag`), `knock` (up to 8 m/s: `crowd.knockDown`, plus damage that grows with the energy) or `kill` (above: `crowd.kill`; the dying velocity goes to the corpse layer). The collision is perfectly inelastic: the car loses `m/(M+m)` of the approach and takes the impulse at the agent's point. The crowd is matched structurally (`RunOverCrowd`), so the package does not import `game-crowd`. The pair `vehicle`-`agent` is not a collision pair: an agent is never a wall.
27
+
28
+ Also, `vehicleDescFromSemi(spec, { chassis })` turns a semi-simulation spec into the engine's vehicle description (wheels, torque and tyre curves, gearbox, differentials), and `createPhysicsInputMapper()` maps the driving controls to its input.
package/dist/index.d.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import { BodyDesc, VehicleDesc, VehicleInput, Vec3, BodyId, PhysicsLoop } from '@adatechnology/game-physics';
2
+
1
3
  /** What the player (or an AI) asks of the vehicle in one step. */
2
4
  interface DriveInput {
3
5
  /** 0..1, accelerates (and brakes hard against a reverse move). */
@@ -233,6 +235,23 @@ interface SemiWheel {
233
235
  /** The handbrake locks it. */
234
236
  handbrake?: boolean;
235
237
  }
238
+ /** A cyclist in place of the engine: sustained power at the cadence it is held, and the bicycle's gears (wheel turns per crank turn, lowest first). */
239
+ interface SemiPedal {
240
+ readonly watts: number;
241
+ readonly cadenceRpm: number;
242
+ readonly gears: readonly number[];
243
+ }
244
+ /**
245
+ * The two tracks of a tracked vehicle (x ahead of the centre of mass): the distance between their centre lines, the rearmost and the foremost road wheel, how many there are per side
246
+ * and their radius. `wheels` of the spec stays the four-wheel stand-in the semi-simulation drives; the physics engine builds the road wheels from this.
247
+ */
248
+ interface SemiTracks {
249
+ readonly gauge: number;
250
+ readonly rearX: number;
251
+ readonly frontX: number;
252
+ readonly roadWheels: number;
253
+ readonly roadRadius: number;
254
+ }
236
255
  interface SemiSimSpec {
237
256
  /** Kilograms. */
238
257
  mass: number;
@@ -285,6 +304,10 @@ interface SemiSimSpec {
285
304
  tank: {
286
305
  capacity: number;
287
306
  } & Partial<FuelModel>;
307
+ /** A bicycle: the cyclist is the engine (the physics engine's vehicle takes the pedal; `engine` stays for the semi-simulation). */
308
+ pedal?: SemiPedal;
309
+ /** A tracked vehicle: the physics engine builds a tracked controller instead of a wheeled one. */
310
+ tracks?: SemiTracks;
288
311
  }
289
312
  /** What is wrong with the vehicle, each from 0 (gone) to 1 (new). The host fills it from `kit.zoneOverall` or from a destructible. */
290
313
  interface VehicleCondition {
@@ -392,6 +415,25 @@ declare const vehicleDamageFromImpact: (energy: number, frontArmor: number, fact
392
415
  /** Speed the vehicle loses: `bodyMass / (vehicleMass + bodyMass) * speed`. */
393
416
  declare const speedLoss: (bodyMass: number, vehicleMass: number, speed: number) => number;
394
417
 
418
+ /** What a vehicle is built as: the wheels it has, the engine and gearbox it carries, how it is driven. A car when a body says nothing. */
419
+ type VehicleType = 'car' | 'motorcycle' | 'bicycle' | 'truck' | 'tractor' | 'tracked';
420
+ /** One axle as the model has it: metres ahead of the middle of the vehicle, the distance between its outer wheels (0 for a single wheel) and the radius of its tyres. */
421
+ interface AxleDimensions {
422
+ readonly x: number;
423
+ readonly track: number;
424
+ readonly radius: number;
425
+ }
426
+ /** The tracks as the model has them (x ahead of the middle of the vehicle). */
427
+ interface TrackDimensions {
428
+ readonly gauge: number;
429
+ readonly rearX: number;
430
+ readonly frontX: number;
431
+ readonly roadWheels: number;
432
+ readonly radius: number;
433
+ }
434
+ /** A cyclist sustains this much: the middle of the 150-400 W range of design 14.2 (specs/008-motor-fisico-jolt/design/veiculos.md), at the cadence and with the gears of the T6.2 bicycle test. */
435
+ declare const CYCLIST: SemiPedal;
436
+
395
437
  /** The design ratings of a vehicle (the shape of `fleetStats` in `game-vehicles-fleet`; any object with these fields works). */
396
438
  interface DesignStats {
397
439
  /** 0-10. */
@@ -405,10 +447,17 @@ interface BodyDimensions {
405
447
  wheelbase: number;
406
448
  track: number;
407
449
  fourWheelDrive?: boolean;
450
+ /** What it is built as (a car when omitted): the wheels, the engine, the gearbox and the controller come from the type. */
451
+ type?: VehicleType;
452
+ /** The axles of the model, front first. Without them the vehicle has two, from `wheelbase` and `track` (a single wheel each for a two-wheeler). */
453
+ axles?: readonly AxleDimensions[];
454
+ /** A tracked vehicle's tracks. */
455
+ tracks?: TrackDimensions;
408
456
  }
409
457
  /**
410
- * A semi-simulation spec for a two-axle vehicle from its design ratings: the grip follows the handling, the torque follows the acceleration,
411
- * the air drag is set so that the top gear tops out at the design top speed, and the brake force follows the mass.
458
+ * A semi-simulation spec from the design ratings and the body: the grip follows the handling, the torque follows the acceleration (a motorcycle's from its real power to weight), the air drag
459
+ * is set so that the top gear tops out at the design top speed (a bicycle's from the cyclist's watts), and the brake force follows the mass. The `type` sets the wheels (two for a bike, one
460
+ * pair per axle for the rest, the model's own when `axles` is given), the engine and the gearbox, and a tracked vehicle gets its tracks.
412
461
  */
413
462
  declare function semiSpecFromStats(stats: DesignStats, body: BodyDimensions, base?: Partial<SemiSimSpec>): SemiSimSpec;
414
463
 
@@ -957,4 +1006,141 @@ interface WindshieldFog {
957
1006
  }
958
1007
  declare function createWindshieldFog(options?: WindshieldFogOptions): WindshieldFog;
959
1008
 
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 };
1009
+ /** A cyclist as the engine (the spec's own `pedal` when the options do not give one). */
1010
+ type PedalOptions = SemiPedal;
1011
+ interface VehicleFromSemiOptions {
1012
+ /** The body: shape, pose, user, velocity, layer. Its origin is the centre of mass (`centreAtOrigin` is set); mass and inertia come from the spec. */
1013
+ readonly chassis: Omit<BodyDesc, 'motion' | 'mass' | 'inertia' | 'centreAtOrigin'>;
1014
+ /** What is wrong with it now: a flat tyre or a bare rim rides on the rim's radius with its grip, a worn engine gives less, worn brakes brake less. */
1015
+ readonly condition?: VehicleCondition;
1016
+ readonly wheelWidth?: number;
1017
+ /** Rotational inertia of each wheel with its tyre, kg m^2: by default 0.0008 per kg of the vehicle (a bicycle: 0.1). */
1018
+ readonly wheelInertia?: number;
1019
+ /** A bicycle's engine in place of `spec.engine` (`spec.pedal` when omitted). */
1020
+ readonly pedal?: PedalOptions;
1021
+ }
1022
+ /**
1023
+ * The semi-simulation's vehicle as a physics-engine vehicle (design 7.1): the wheels where the spec has them (x to the left, z ahead, from the centre of mass),
1024
+ * the suspension as a frequency and a damping ratio from the spring and the corner's mass, the engine and gearbox, the tyres as the two grip curves, the brake
1025
+ * force split 60/40, the mass and the moments of the spec. Two wheels make a motorcycle (a bicycle with `pedal`). The ground's grip is the ground body's own
1026
+ * friction, and the air drag and the rolling resistance are `resistanceImpulse`.
1027
+ */
1028
+ declare const vehicleDescFromSemi: (spec: SemiSimSpec, options: VehicleFromSemiOptions) => VehicleDesc;
1029
+
1030
+ /** What the vehicle can do now (the fields of the destructible's `status()` this needs: any object with them works). */
1031
+ interface DriveStatus {
1032
+ /** Engine runs and the gearbox transmits. */
1033
+ readonly canDrive: boolean;
1034
+ /** 1 is normal; this many times longer to stop with worn or missing brakes. */
1035
+ readonly brakeFactor: number;
1036
+ /** -1..1: the sideways pull of a damaged steering or flat tyres (negative is left). */
1037
+ readonly steerPull: number;
1038
+ }
1039
+ interface PhysicsInputOptions {
1040
+ /** The steering follows its target by `min(1, steerResponse dt)`: the arcade's 5 per second. */
1041
+ readonly steerResponse?: number;
1042
+ /** Lock lost per m/s of speed (the steering assistance), and the share of it that is never lost. */
1043
+ readonly steerFalloff?: number;
1044
+ readonly steerFloor?: number;
1045
+ /** Below this speed (m/s), forward or back, a brake asks for reverse and a throttle for forward. */
1046
+ readonly reverseBelow?: number;
1047
+ /** Share of the full lock a full `steerPull` pulls with. */
1048
+ readonly pullShare?: number;
1049
+ }
1050
+ interface PhysicsInputParams {
1051
+ readonly input: SemiInput;
1052
+ /** Signed speed along the front of the vehicle, m/s. */
1053
+ readonly speed: number;
1054
+ /** Seconds since the last call. */
1055
+ readonly dt: number;
1056
+ readonly status?: Partial<DriveStatus>;
1057
+ }
1058
+ interface PhysicsInputMapper {
1059
+ /** The engine's input for this step. It keeps the filtered steering between calls. */
1060
+ map(params: PhysicsInputParams): VehicleInput;
1061
+ reset(): void;
1062
+ }
1063
+ /** Starting values, to be calibrated against the vehicle on the engine (T6.2b): the response is the arcade's, the assistance and the pull are not measured yet. */
1064
+ declare const DEFAULT_PHYSICS_INPUT: Required<PhysicsInputOptions>;
1065
+ /**
1066
+ * Pedals to the engine's input (design 7.2): throttle and brake cancel into one pedal; forward from a stop or above, hard brake against the move, reverse from
1067
+ * a stop; the power limit of traction control and a hurt engine cuts the throttle; the brake factor of a worn brake softens the brake; steering is the kit's
1068
+ * positive-left turned into the engine's positive-right, filtered, eased with the speed, and pulled by a damaged steering. A vehicle that cannot drive gets no
1069
+ * throttle (the brake and the steering still work).
1070
+ */
1071
+ declare const createPhysicsInputMapper: (options?: PhysicsInputOptions) => PhysicsInputMapper;
1072
+
1073
+ /**
1074
+ * The impulse (N s) the air and the tyres take from a vehicle moving at `velocity` (its horizontal part) over one step `dt`, for the body's centre of mass: `-drag |v| v dt` for the air
1075
+ * (the spec's drag is `0.5 rho Cd A`) and `-rolling m g dt` along the velocity for the tyres. Apply it every fixed step in the `actors` phase; the wheels' own
1076
+ * contact does not know either.
1077
+ */
1078
+ declare const resistanceImpulse: (spec: Pick<SemiSimSpec, "drag" | "rolling" | "mass">, velocity: Vec3, dt: number) => Vec3;
1079
+
1080
+ /** What the run-over needs of the crowd: `game-crowd`'s `Crowd` is one as it is, and nothing here imports it. */
1081
+ type RunOverCrowd = {
1082
+ readonly store: {
1083
+ readonly n: number;
1084
+ readonly x: Float32Array;
1085
+ readonly z: Float32Array;
1086
+ readonly vx: Float32Array;
1087
+ readonly vz: Float32Array;
1088
+ readonly mass: Float32Array;
1089
+ readonly identity: Uint32Array;
1090
+ };
1091
+ damage(index: number, hit: {
1092
+ readonly region: 1;
1093
+ readonly amount: number;
1094
+ readonly distance: number;
1095
+ }): {
1096
+ readonly died: boolean;
1097
+ };
1098
+ kill(index: number): void;
1099
+ knockDown(index: number, velocity: {
1100
+ readonly x: number;
1101
+ readonly z: number;
1102
+ }): void;
1103
+ };
1104
+ /** The kinematic capsules of the agents (`createAgentBodies` of `game-crowd`): capsule `i` follows agent `i`. */
1105
+ type RunOverAgents = {
1106
+ readonly count: number;
1107
+ bodyOf(index: number): BodyId | undefined;
1108
+ };
1109
+ /** A car the run-over watches: its chassis body and the half sizes of its box (x right, y up, z forward, as the engine's vehicles). */
1110
+ type RunOverVehicle = {
1111
+ readonly body: BodyId;
1112
+ readonly half: Vec3;
1113
+ };
1114
+ type RunOverHit = {
1115
+ readonly vehicle: BodyId;
1116
+ readonly agent: number;
1117
+ readonly outcome: RunOverOutcome;
1118
+ /** Closing speed (m/s) and the energy the hit dissipated: half the reduced mass times the closing speed squared (J). */
1119
+ readonly speed: number;
1120
+ readonly energy: number;
1121
+ /** What `RunOverRules.killVehicleDamage` says the car takes: 0 unless the body died. */
1122
+ readonly vehicleDamage: number;
1123
+ };
1124
+ type RunOverOptions = {
1125
+ readonly crowd: RunOverCrowd;
1126
+ readonly agents: RunOverAgents;
1127
+ readonly rules?: Partial<RunOverRules>;
1128
+ /** Told of each hit inside the fixed step (the host's sound, blood, damage to the car). */
1129
+ readonly onHit?: (hit: RunOverHit) => void;
1130
+ };
1131
+ type RunOver = {
1132
+ /** Watches a car from the next step on; returns the way to stop. */
1133
+ track(vehicle: RunOverVehicle): () => void;
1134
+ /** The velocity a body that dies in this very call carries (a `CorpseBodies.add` made in the crowd's `corpses` listener reads it); undefined outside a hit. */
1135
+ readonly dyingVelocity: Vec3 | undefined;
1136
+ dispose(): void;
1137
+ };
1138
+ /**
1139
+ * Cars against the crowd's agents, in the loop's `actors` phase (veiculos.md 7.8). The `vehicle` and `agent` layers do not meet, because an agent is kinematic and would stop a truck as a
1140
+ * wall: the car sweeps its box over the step against the `agent` layer instead. A body in the way meets the car as a perfectly inelastic hit (momentum kept: the car loses `m / (M + m)`
1141
+ * of the closing speed and the body leaves at the common speed), which `RunOverRules` classes by the closing speed: pushed aside below `knockSpeed` (the car held by `holdDrag`), knocked
1142
+ * down (damage `knockDamage` by the energy, stunned) up to `killSpeed`, killed above it. Whoever dies is told to the crowd with the car's velocity in `dyingVelocity`.
1143
+ */
1144
+ declare const createRunOver: (loop: PhysicsLoop, options: RunOverOptions) => RunOver;
1145
+
1146
+ export { type AlarmState, type ArcadeOptions, type ArcadeSpec, type AxleDimensions, type BodyDimensions, CYCLIST, 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_PHYSICS_INPUT, DEFAULT_TRACTION, DRIVE_PROFILES, type DamageReport, type DamagedTyre, type DesignStats, type DriveInput, type DriveMode, type DriveProfile, type DriveStatus, 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 PedalOptions, type PhysicsInputMapper, type PhysicsInputOptions, type PhysicsInputParams, type ProfileTuning, type RadioSource, type RunOver, type RunOverAgents, type RunOverCrowd, type RunOverHit, type RunOverOptions, type RunOverOutcome, type RunOverRules, type RunOverVehicle, type SemiDriver, type SemiEvent, type SemiGround, type SemiInput, type SemiPedal, type SemiSimOptions, type SemiSimSpec, type SemiState, type SemiTracks, 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 TrackDimensions, type TractionOptions, type VehicleCondition, type VehicleControlOptions, type VehicleControls, type VehicleFromSemiOptions, type VehicleStorage, type VehicleStorageOptions, type VehicleSystems, type VehicleSystemsOptions, type VehicleType, type WindshieldFog, type WindshieldFogOptions, type WindshieldFogState, type WindshieldFogStep, type Wipers, bodyDamage, bumperDistance, conditionFromDamage, createArcadeDriver, createPhysicsInputMapper, createRunOver, createSemiSimDriver, createSurfaces, createVehicleControls, createVehicleStorage, createVehicleSystems, createWindshieldFog, cruiseThrottle, defaultArcadeSpec, defaultFuelModel, defaultSemiSpec, defaultSurfaces, ejectionOf, fuelRate, impactEnergy, parkingBeepInterval, resistanceImpulse, runOver, semiSpecFromStats, speedLoss, surfaceGrip, tractionLimit, trunkFor, vehicleCorners, vehicleDamageFromImpact, vehicleDescFromSemi };