@adatechnology/game-vehicles-proving 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/dist/index.d.ts +228 -0
- package/dist/index.global.js +823 -0
- package/dist/index.global.js.map +1 -0
- package/dist/index.js +365 -0
- package/dist/index.js.map +1 -0
- package/package.json +50 -3
- package/README.md +0 -3
|
@@ -0,0 +1,823 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var GameVehiclesProving = (() => {
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
|
|
21
|
+
// src/index.ts
|
|
22
|
+
var index_exports = {};
|
|
23
|
+
__export(index_exports, {
|
|
24
|
+
DEFAULT_DENSITY: () => DEFAULT_DENSITY,
|
|
25
|
+
accelerationRange: () => accelerationRange,
|
|
26
|
+
brakeRange: () => brakeRange,
|
|
27
|
+
certify: () => certify,
|
|
28
|
+
createProvingTests: () => createProvingTests,
|
|
29
|
+
defaultProvingTests: () => defaultProvingTests,
|
|
30
|
+
defaultRangeTable: () => defaultRangeTable,
|
|
31
|
+
dryBrakeRange: () => dryBrakeRange,
|
|
32
|
+
expectedAcceleration: () => expectedAcceleration,
|
|
33
|
+
gateVehicles: () => gateVehicles,
|
|
34
|
+
inRange: () => inRange,
|
|
35
|
+
runTest: () => runTest,
|
|
36
|
+
startRun: () => startRun,
|
|
37
|
+
statusOf: () => statusOf,
|
|
38
|
+
subjectFromCard: () => subjectFromCard,
|
|
39
|
+
subjectSpec: () => subjectSpec,
|
|
40
|
+
topSpeedRange: () => topSpeedRange,
|
|
41
|
+
turnCircleRange: () => turnCircleRange,
|
|
42
|
+
wetBrakeRange: () => wetBrakeRange,
|
|
43
|
+
withResult: () => withResult
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
// ../game-contracts/dist/index.js
|
|
47
|
+
var DEFAULT_COST_ALLOCATION_BYTES = 1024 * 1024;
|
|
48
|
+
var DEFERRED_QUEUE_ID = {
|
|
49
|
+
DESTRUCTION_EVENTS: "destruction.events",
|
|
50
|
+
BREACH_PAINT: "floorplan.breach-paint",
|
|
51
|
+
AUDIO_VOICES: "audio.voices",
|
|
52
|
+
VEHICLE_CREASE: "vehicles.crease"
|
|
53
|
+
};
|
|
54
|
+
var DEFERRED_PRIORITY = {
|
|
55
|
+
[DEFERRED_QUEUE_ID.DESTRUCTION_EVENTS]: { priority: 300, phase: "present" },
|
|
56
|
+
[DEFERRED_QUEUE_ID.BREACH_PAINT]: { priority: 250, phase: "present" },
|
|
57
|
+
[DEFERRED_QUEUE_ID.AUDIO_VOICES]: { priority: 200, phase: "idle", reserveMs: 1 },
|
|
58
|
+
[DEFERRED_QUEUE_ID.VEHICLE_CREASE]: { priority: 100, phase: "idle" }
|
|
59
|
+
};
|
|
60
|
+
var WARNED_KEY = /* @__PURE__ */ Symbol.for("@adatechnology/game-contracts.warned");
|
|
61
|
+
var warnedKeys = () => {
|
|
62
|
+
const holder = globalThis;
|
|
63
|
+
return holder[WARNED_KEY] ?? (holder[WARNED_KEY] = /* @__PURE__ */ new Set());
|
|
64
|
+
};
|
|
65
|
+
var isProduction = () => {
|
|
66
|
+
try {
|
|
67
|
+
return process.env.NODE_ENV === "production";
|
|
68
|
+
} catch {
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
var isQuiet = () => globalThis.__GAME_KIT_QUIET__ === true;
|
|
73
|
+
var warnOnce = (key, message) => {
|
|
74
|
+
if (isQuiet() || isProduction()) return;
|
|
75
|
+
const seen = warnedKeys();
|
|
76
|
+
if (seen.has(key)) return;
|
|
77
|
+
seen.add(key);
|
|
78
|
+
console.warn(`[game-kit] ${message}`);
|
|
79
|
+
};
|
|
80
|
+
var UNSAFE_KEYS = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
|
|
81
|
+
var isPlainObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value) && Object.getPrototypeOf(value) === Object.prototype;
|
|
82
|
+
var deepMerge = (base, patch) => {
|
|
83
|
+
if (!patch) return base;
|
|
84
|
+
const result = { ...base };
|
|
85
|
+
for (const [key, value] of Object.entries(patch)) {
|
|
86
|
+
if (value === void 0 || UNSAFE_KEYS.has(key)) continue;
|
|
87
|
+
const current = result[key];
|
|
88
|
+
result[key] = isPlainObject(current) && isPlainObject(value) ? deepMerge(current, value) : value;
|
|
89
|
+
}
|
|
90
|
+
return result;
|
|
91
|
+
};
|
|
92
|
+
var mergeById = (shipped, extra) => {
|
|
93
|
+
const entries = /* @__PURE__ */ new Map();
|
|
94
|
+
for (const entry of [...shipped, ...extra ?? []]) entries.set(entry.id, entry);
|
|
95
|
+
return entries;
|
|
96
|
+
};
|
|
97
|
+
var applyPatches = (entries, patches) => {
|
|
98
|
+
for (const [id, patch] of Object.entries(patches ?? {})) {
|
|
99
|
+
const entry = entries.get(id);
|
|
100
|
+
if (entry) entries.set(id, deepMerge(entry, patch));
|
|
101
|
+
else warnOnce(`registry.patch.${id}`, `patch for "${id}" ignored: no entry has that id`);
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
var removeIds = (entries, ids) => {
|
|
105
|
+
for (const id of ids ?? []) {
|
|
106
|
+
if (!entries.delete(id)) warnOnce(`registry.remove.${id}`, `remove of "${id}" ignored: no entry has that id`);
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
var SURFACE_IDS = ["concrete", "asphalt", "wood", "tile", "dirt", "grass", "gravel", "sand", "metal", "water", "glass", "carpet"];
|
|
110
|
+
var GAIT_IDS = ["walk", "run"];
|
|
111
|
+
var LANDING_IDS = ["light", "heavy"];
|
|
112
|
+
var BODY_SOUND_IDS = [
|
|
113
|
+
"jump",
|
|
114
|
+
"cloth_rustle",
|
|
115
|
+
"body_fall",
|
|
116
|
+
"fall_damage",
|
|
117
|
+
"player_hurt",
|
|
118
|
+
"player_breath_run",
|
|
119
|
+
"player_death",
|
|
120
|
+
"bite",
|
|
121
|
+
"grab",
|
|
122
|
+
"punch_swing",
|
|
123
|
+
"punch_hit_body",
|
|
124
|
+
"punch_hit_face",
|
|
125
|
+
"punch_hit_object",
|
|
126
|
+
"kick_swing",
|
|
127
|
+
"kick_hit",
|
|
128
|
+
"kick_hit_object",
|
|
129
|
+
"shove_two_hands",
|
|
130
|
+
"knife_swing",
|
|
131
|
+
"knife_stab",
|
|
132
|
+
"knife_slash",
|
|
133
|
+
"knife_hit_object",
|
|
134
|
+
"blunt_swing",
|
|
135
|
+
"blunt_hit",
|
|
136
|
+
"blunt_hit_object",
|
|
137
|
+
"axe_swing",
|
|
138
|
+
"axe_chop",
|
|
139
|
+
"axe_hit_object"
|
|
140
|
+
];
|
|
141
|
+
var footstepSoundId = (surface, gait) => `footstep_${surface}_${gait}`;
|
|
142
|
+
var FOOTSTEP_SOUND_IDS = SURFACE_IDS.flatMap((surface) => GAIT_IDS.map((gait) => footstepSoundId(surface, gait)));
|
|
143
|
+
var LAND_SOUND_IDS = SURFACE_IDS.flatMap((surface) => LANDING_IDS.map((landing) => `land_${surface}_${landing}`));
|
|
144
|
+
var BODY_FOLEY_IDS = [...FOOTSTEP_SOUND_IDS, ...LAND_SOUND_IDS, ...BODY_SOUND_IDS];
|
|
145
|
+
|
|
146
|
+
// ../game-vehicles-driving/dist/index.js
|
|
147
|
+
var defaultFuelModel = { idleRate: 3e-4, fullRate: 35e-4, loadFactor: 0.5, damagedEngineExtra: 0.4 };
|
|
148
|
+
function fuelRate(model, rpmFraction, throttle, loadRatio, engineHealth) {
|
|
149
|
+
const base = model.idleRate + model.fullRate * Math.max(0, Math.min(1, rpmFraction)) * Math.max(0, Math.min(1, throttle));
|
|
150
|
+
return base * (1 + model.loadFactor * Math.max(0, loadRatio)) * (1 + model.damagedEngineExtra * (1 - Math.max(0, Math.min(1, engineHealth))));
|
|
151
|
+
}
|
|
152
|
+
var defaultSurfaces = [
|
|
153
|
+
{ id: "dry_asphalt", grip: 1 },
|
|
154
|
+
{ id: "wet_asphalt", grip: 0.75, aquaplaningKmh: 90, aquaplaningFactor: 0.4, aquaplaningBand: 30 },
|
|
155
|
+
{ id: "dirt", grip: 0.65 },
|
|
156
|
+
{ id: "grass", grip: 0.55 },
|
|
157
|
+
{ id: "mud", grip: 0.4, bogs: true },
|
|
158
|
+
/** Blood and bodies after a run-over; a driver applies it for a few seconds with `contaminate`. */
|
|
159
|
+
{ id: "blood", grip: 0.5 }
|
|
160
|
+
];
|
|
161
|
+
function createSurfaces(options = {}) {
|
|
162
|
+
const entries = mergeById(defaultSurfaces, options.packs?.flatMap((pack) => pack.surfaces ?? []));
|
|
163
|
+
applyPatches(entries, options.patch);
|
|
164
|
+
removeIds(entries, options.remove);
|
|
165
|
+
const fallback = entries.get("dry_asphalt") ?? { id: "dry_asphalt", grip: 1 };
|
|
166
|
+
return {
|
|
167
|
+
get: (id) => entries.get(id) ?? fallback,
|
|
168
|
+
get surfaces() {
|
|
169
|
+
return [...entries.values()];
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
function surfaceGrip(surface, speedMetresPerSecond) {
|
|
174
|
+
if (surface.aquaplaningKmh == null) return surface.grip;
|
|
175
|
+
const kmh2 = Math.abs(speedMetresPerSecond) * 3.6;
|
|
176
|
+
const band = surface.aquaplaningBand ?? 30;
|
|
177
|
+
const t = Math.max(0, Math.min(1, (kmh2 - surface.aquaplaningKmh) / band));
|
|
178
|
+
return surface.grip * (1 - (1 - (surface.aquaplaningFactor ?? 0.4)) * t);
|
|
179
|
+
}
|
|
180
|
+
var G = 9.81;
|
|
181
|
+
var clamp2 = (x, a, b) => Math.max(a, Math.min(b, x));
|
|
182
|
+
var MAX_SUBSTEP = 1 / 240;
|
|
183
|
+
var FLAT_BELOW = 0.2;
|
|
184
|
+
var STALL_HEALTH = 0.3;
|
|
185
|
+
var defaultSemiSpec = {
|
|
186
|
+
mass: 1300,
|
|
187
|
+
centreHeight: 0.5,
|
|
188
|
+
wheels: [
|
|
189
|
+
{ x: 1.3, z: -0.75, steer: true },
|
|
190
|
+
{ x: 1.3, z: 0.75, steer: true },
|
|
191
|
+
{ x: -1.3, z: -0.75, drive: true, handbrake: true },
|
|
192
|
+
{ x: -1.3, z: 0.75, drive: true, handbrake: true }
|
|
193
|
+
],
|
|
194
|
+
wheelRadius: 0.32,
|
|
195
|
+
fourWheelDrive: false,
|
|
196
|
+
drag: 0.4,
|
|
197
|
+
rolling: 0.015,
|
|
198
|
+
bogResistance: 0.3,
|
|
199
|
+
maxSteer: 0.55,
|
|
200
|
+
brakeForce: 14e3,
|
|
201
|
+
engine: { idleRpm: 900, peakRpm: 4200, redlineRpm: 6500, peakTorque: 220 },
|
|
202
|
+
gears: [3.6, 2.2, 1.5, 1.1, 0.85],
|
|
203
|
+
reverseRatio: 3.4,
|
|
204
|
+
finalDrive: 3.7,
|
|
205
|
+
efficiency: 0.85,
|
|
206
|
+
upshiftFraction: 0.85,
|
|
207
|
+
downshiftFraction: 0.35,
|
|
208
|
+
suspension: { restLength: 0.4, spring: 32e3, damper: 3200 },
|
|
209
|
+
tyre: { friction: 1.05, corneringStiffness: 9 },
|
|
210
|
+
tank: { capacity: 45 }
|
|
211
|
+
};
|
|
212
|
+
var torqueAt = (spec, rpm) => {
|
|
213
|
+
const e = spec.engine;
|
|
214
|
+
if (rpm >= e.redlineRpm) return 0;
|
|
215
|
+
const t = rpm <= e.peakRpm ? 0.7 + 0.3 * clamp2((rpm - e.idleRpm) / (e.peakRpm - e.idleRpm), 0, 1) : 1 - 0.4 * ((rpm - e.peakRpm) / (e.redlineRpm - e.peakRpm));
|
|
216
|
+
return e.peakTorque * t;
|
|
217
|
+
};
|
|
218
|
+
var SLIDING_GRIP = 0.75;
|
|
219
|
+
var LOCKED_STEER = 0.15;
|
|
220
|
+
var AMBIENT_C = 25;
|
|
221
|
+
var BRAKE_FADE_FROM_C = 350;
|
|
222
|
+
var BRAKE_FADE_TO_C = 650;
|
|
223
|
+
var BRAKE_FADED = 0.5;
|
|
224
|
+
var BRAKE_HEAT_CAPACITY = 3;
|
|
225
|
+
var BRAKE_COOL_S = 60;
|
|
226
|
+
function createSemiSimDriver(specification = {}, options = {}) {
|
|
227
|
+
const spec = { ...defaultSemiSpec, ...specification };
|
|
228
|
+
const surfaces = options.surfaces ?? createSurfaces();
|
|
229
|
+
const fuelModel = { ...defaultFuelModel, ...spec.tank };
|
|
230
|
+
const wheelbase = Math.max(...spec.wheels.map((w) => w.x)) - Math.min(...spec.wheels.map((w) => w.x));
|
|
231
|
+
const track = Math.max(...spec.wheels.map((w) => w.z)) - Math.min(...spec.wheels.map((w) => w.z));
|
|
232
|
+
const baseMass = spec.mass;
|
|
233
|
+
let cargo = 0;
|
|
234
|
+
let contamination = null;
|
|
235
|
+
const n = spec.wheels.length;
|
|
236
|
+
const state = {
|
|
237
|
+
x: 0,
|
|
238
|
+
z: 0,
|
|
239
|
+
yaw: 0,
|
|
240
|
+
u: 0,
|
|
241
|
+
w: 0,
|
|
242
|
+
yawRate: 0,
|
|
243
|
+
height: spec.suspension.restLength + spec.wheelRadius - spec.mass * G / (specification.wheels ? specification.wheels.length : defaultSemiSpec.wheels.length) / spec.suspension.spring,
|
|
244
|
+
heightRate: 0,
|
|
245
|
+
pitch: 0,
|
|
246
|
+
pitchRate: 0,
|
|
247
|
+
roll: 0,
|
|
248
|
+
rollRate: 0,
|
|
249
|
+
rpm: spec.engine.idleRpm,
|
|
250
|
+
gear: 1,
|
|
251
|
+
engineOn: true,
|
|
252
|
+
bogged: false,
|
|
253
|
+
fuel: spec.tank.capacity,
|
|
254
|
+
loads: new Array(n).fill(baseMass * G / n),
|
|
255
|
+
slip: new Array(n).fill(0),
|
|
256
|
+
steerAngle: 0
|
|
257
|
+
};
|
|
258
|
+
const driver = {
|
|
259
|
+
spec,
|
|
260
|
+
state,
|
|
261
|
+
condition: {},
|
|
262
|
+
setCargo(kg) {
|
|
263
|
+
cargo = Math.max(0, kg);
|
|
264
|
+
},
|
|
265
|
+
contaminate(surfaceId, seconds) {
|
|
266
|
+
contamination = { id: surfaceId, left: seconds };
|
|
267
|
+
},
|
|
268
|
+
refuel(litres) {
|
|
269
|
+
state.fuel = Math.min(spec.tank.capacity, state.fuel + litres);
|
|
270
|
+
},
|
|
271
|
+
place(x, z, yaw) {
|
|
272
|
+
state.x = x;
|
|
273
|
+
state.z = z;
|
|
274
|
+
state.yaw = yaw;
|
|
275
|
+
state.u = state.w = state.yawRate = 0;
|
|
276
|
+
},
|
|
277
|
+
step(input, dt, world = {}) {
|
|
278
|
+
const events = [];
|
|
279
|
+
const steps = Math.max(1, Math.ceil(dt / MAX_SUBSTEP));
|
|
280
|
+
const h = dt / steps;
|
|
281
|
+
for (let s = 0; s < steps; s++) substep(input, h, world, events);
|
|
282
|
+
return { state, events };
|
|
283
|
+
}
|
|
284
|
+
};
|
|
285
|
+
const stallWatch = { throttleTime: 0 };
|
|
286
|
+
function substep(input, dt, world, events) {
|
|
287
|
+
const cond = driver.condition;
|
|
288
|
+
const mass = baseMass + cargo;
|
|
289
|
+
const engineHealth = clamp2(cond.engine ?? 1, 0, 1);
|
|
290
|
+
const suspensionHealth = clamp2(cond.suspension ?? 1, 0, 1);
|
|
291
|
+
const brakeHealth = clamp2(cond.brakes ?? 1, 0, 1);
|
|
292
|
+
const inertia = (spec.yawInertia ?? baseMass * (wheelbase * wheelbase + track * track) / 12) * (mass / baseMass);
|
|
293
|
+
const pitchInertia = mass * (wheelbase * wheelbase + 1) / 12;
|
|
294
|
+
const rollInertia = mass * (track * track + 1) / 12;
|
|
295
|
+
if (contamination) {
|
|
296
|
+
contamination.left -= dt;
|
|
297
|
+
if (contamination.left <= 0) contamination = null;
|
|
298
|
+
}
|
|
299
|
+
const cs = Math.cos(state.yaw);
|
|
300
|
+
const sn = Math.sin(state.yaw);
|
|
301
|
+
const target = clamp2(input.steer, -1, 1) * spec.maxSteer;
|
|
302
|
+
state.steerAngle += (target - state.steerAngle) * Math.min(1, dt * 8);
|
|
303
|
+
let gear = state.gear;
|
|
304
|
+
if (input.gear != null) gear = input.gear;
|
|
305
|
+
else if (state.u < 0.5 && input.brake > 0 && input.throttle <= 0) gear = -1;
|
|
306
|
+
else if (gear <= 0 && !(gear === -1 && state.u < 0.5 && input.throttle <= 0)) gear = 1;
|
|
307
|
+
const ratioOf = (g) => g < 0 ? spec.reverseRatio : g === 0 ? 0 : spec.gears[g - 1];
|
|
308
|
+
const driveWheels = spec.wheels.map((w, i) => ({ w, i })).filter(({ w }) => spec.fourWheelDrive ? true : w.drive);
|
|
309
|
+
let driveSpeed = 0;
|
|
310
|
+
for (const { w } of driveWheels) driveSpeed += state.u + state.yawRate * w.z;
|
|
311
|
+
driveSpeed /= Math.max(1, driveWheels.length);
|
|
312
|
+
const wheelRpm = Math.abs(driveSpeed) / spec.wheelRadius * (60 / (2 * Math.PI));
|
|
313
|
+
if (input.gear == null && gear > 0) {
|
|
314
|
+
if (wheelRpm * ratioOf(gear) * spec.finalDrive > spec.engine.redlineRpm * spec.upshiftFraction && gear < spec.gears.length) gear++;
|
|
315
|
+
else if (gear > 1 && wheelRpm * ratioOf(gear) * spec.finalDrive < spec.engine.redlineRpm * spec.downshiftFraction) gear--;
|
|
316
|
+
}
|
|
317
|
+
if (gear !== state.gear) {
|
|
318
|
+
state.gear = gear;
|
|
319
|
+
events.push({ type: "shift", gear });
|
|
320
|
+
}
|
|
321
|
+
const reversing = state.gear < 0;
|
|
322
|
+
const accelInput = reversing ? input.brake : input.throttle;
|
|
323
|
+
const brakeInput = clamp2(reversing ? input.throttle : input.brake, 0, 1);
|
|
324
|
+
const ratio = ratioOf(state.gear) * spec.finalDrive;
|
|
325
|
+
state.rpm = clamp2(wheelRpm * ratio, spec.engine.idleRpm, spec.engine.redlineRpm + 200);
|
|
326
|
+
if (!state.engineOn || state.fuel <= 0) state.rpm = 0;
|
|
327
|
+
let throttle = clamp2(accelInput, 0, 1);
|
|
328
|
+
if (engineHealth < STALL_HEALTH && throttle > 0.8) {
|
|
329
|
+
stallWatch.throttleTime += dt;
|
|
330
|
+
if (state.pitch > 0.06 && stallWatch.throttleTime > 0.5 && state.engineOn) {
|
|
331
|
+
state.engineOn = false;
|
|
332
|
+
events.push({ type: "stall" });
|
|
333
|
+
}
|
|
334
|
+
throttle *= 0.5;
|
|
335
|
+
} else stallWatch.throttleTime = 0;
|
|
336
|
+
if (!state.engineOn && accelInput > 0 && Math.abs(state.u) < 0.5 && engineHealth >= STALL_HEALTH && state.fuel > 0) state.engineOn = true;
|
|
337
|
+
if (state.fuel <= 0 && state.engineOn) {
|
|
338
|
+
state.engineOn = false;
|
|
339
|
+
events.push({ type: "out_of_fuel" });
|
|
340
|
+
}
|
|
341
|
+
const engineTorque = state.engineOn ? torqueAt(spec, state.rpm) * throttle * (0.55 + 0.45 * engineHealth) : 0;
|
|
342
|
+
const driveForceTotal = state.gear === 0 ? 0 : (reversing ? -1 : 1) * engineTorque * ratio * spec.efficiency / spec.wheelRadius;
|
|
343
|
+
if (state.engineOn) {
|
|
344
|
+
const burned = fuelRate(fuelModel, state.rpm / spec.engine.redlineRpm, throttle, cargo / baseMass, engineHealth) * dt;
|
|
345
|
+
state.fuel = Math.max(0, state.fuel - burned);
|
|
346
|
+
}
|
|
347
|
+
const ride = spec.suspension.restLength;
|
|
348
|
+
let sumN = 0;
|
|
349
|
+
let sumNA = 0;
|
|
350
|
+
let sumNB = 0;
|
|
351
|
+
const wheelState = [];
|
|
352
|
+
let bogging = false;
|
|
353
|
+
for (let i = 0; i < n; i++) {
|
|
354
|
+
const w = spec.wheels[i];
|
|
355
|
+
const wx = state.x + w.x * cs + w.z * sn;
|
|
356
|
+
const wz = state.z - w.x * sn + w.z * cs;
|
|
357
|
+
const ground = world.ground ? world.ground(wx, wz) : {};
|
|
358
|
+
const surface = surfaces.get(contamination && contamination.left > 0 && surfaces.get(contamination.id).grip < surfaces.get(ground.surface ?? "dry_asphalt").grip ? contamination.id : ground.surface ?? "dry_asphalt");
|
|
359
|
+
const top = state.height + w.x * state.pitch - w.z * state.roll;
|
|
360
|
+
const length = top - (ground.height ?? 0) - spec.wheelRadius;
|
|
361
|
+
const compression = ride - length;
|
|
362
|
+
const rate = -(state.heightRate + w.x * state.pitchRate - w.z * state.rollRate);
|
|
363
|
+
const k = spec.suspension.spring * (0.5 + 0.5 * suspensionHealth);
|
|
364
|
+
const c = spec.suspension.damper * (0.5 + 0.5 * suspensionHealth);
|
|
365
|
+
const load = Math.max(0, k * compression + c * rate);
|
|
366
|
+
const tyreHealth = cond.tyres ? clamp2(cond.tyres[i] ?? 1, 0, 1) : 1;
|
|
367
|
+
const flat = tyreHealth < FLAT_BELOW;
|
|
368
|
+
const bog = !!surface.bogs && !spec.fourWheelDrive;
|
|
369
|
+
if (bog) bogging = true;
|
|
370
|
+
const grip = surfaceGrip(surface, state.u) * (flat ? 0.5 : 1);
|
|
371
|
+
wheelState.push({ n: load, grip, surface: surface.id, bog, flat });
|
|
372
|
+
sumN += load;
|
|
373
|
+
sumNA += load * w.x;
|
|
374
|
+
sumNB += load * w.z;
|
|
375
|
+
}
|
|
376
|
+
const brakeHeat = state.brakeHeat ?? AMBIENT_C;
|
|
377
|
+
const fade = 1 - clamp2((brakeHeat - BRAKE_FADE_FROM_C) / (BRAKE_FADE_TO_C - BRAKE_FADE_FROM_C), 0, 1) * (1 - BRAKE_FADED);
|
|
378
|
+
let brakeWork = 0;
|
|
379
|
+
let fFwd = 0;
|
|
380
|
+
let fRight = 0;
|
|
381
|
+
let torque = 0;
|
|
382
|
+
let pitchTorque = 0;
|
|
383
|
+
let rollTorque = 0;
|
|
384
|
+
const handbrake = !!input.handbrake;
|
|
385
|
+
const loadSum = Math.max(1, wheelState.reduce((a, b) => a + b.n, 0));
|
|
386
|
+
const drivenCount = Math.max(1, driveWheels.length);
|
|
387
|
+
for (let i = 0; i < n; i++) {
|
|
388
|
+
const w = spec.wheels[i];
|
|
389
|
+
const ws = wheelState[i];
|
|
390
|
+
const delta = w.steer ? state.steerAngle : 0;
|
|
391
|
+
const cd = Math.cos(delta);
|
|
392
|
+
const sd = Math.sin(delta);
|
|
393
|
+
const vxw = state.u + state.yawRate * w.z;
|
|
394
|
+
const vyw = state.w - state.yawRate * w.x;
|
|
395
|
+
const vl = vxw * cd - vyw * sd;
|
|
396
|
+
const vc = vxw * sd + vyw * cd;
|
|
397
|
+
const capacity = spec.tyre.friction * ws.grip * ws.n;
|
|
398
|
+
let fl = 0;
|
|
399
|
+
if (driveWheels.some((d) => d.i === i)) fl += driveForceTotal / drivenCount;
|
|
400
|
+
const locked = handbrake && w.handbrake;
|
|
401
|
+
const brakeShare = spec.brakeForce * brakeHealth * fade * brakeInput * ws.n / loadSum;
|
|
402
|
+
const moving = Math.abs(vl) > 0.05;
|
|
403
|
+
const lockedByBrake = spec.abs === false && moving && brakeShare > capacity;
|
|
404
|
+
if (locked || lockedByBrake) fl += moving ? -Math.sign(vl) * capacity * (lockedByBrake ? SLIDING_GRIP : 1) : 0;
|
|
405
|
+
else if (brakeShare > 0 && moving) fl += -Math.sign(vl) * brakeShare;
|
|
406
|
+
if (brakeShare > 0 && moving) brakeWork += Math.min(brakeShare, capacity) * Math.abs(vl) * dt;
|
|
407
|
+
const rolling = ws.bog && accelInput > 0 ? spec.bogResistance : spec.rolling * (ws.flat ? 6 : 1);
|
|
408
|
+
const alpha = Math.atan2(vc, Math.abs(vl) + 0.5);
|
|
409
|
+
let fc = -Math.tanh(spec.tyre.corneringStiffness * alpha) * capacity;
|
|
410
|
+
if (locked) fc *= 0.6;
|
|
411
|
+
if (lockedByBrake) fc *= LOCKED_STEER;
|
|
412
|
+
const total = Math.hypot(fl, fc);
|
|
413
|
+
let used = 1;
|
|
414
|
+
if (total > capacity && total > 0) used = capacity / total;
|
|
415
|
+
fl *= used;
|
|
416
|
+
fc *= used;
|
|
417
|
+
if (moving) fl += -Math.sign(vl) * rolling * ws.n;
|
|
418
|
+
const slipRatio = capacity > 0 ? clamp2(total / capacity, 0, 1) : 0;
|
|
419
|
+
state.slip[i] = slipRatio;
|
|
420
|
+
if (ws.surface === "wet_asphalt" && Math.abs(state.u) * 3.6 > (surfaces.get(ws.surface).aquaplaningKmh ?? 1e9) && slipRatio >= 0.99) events.push({ type: "aquaplaning", wheel: i });
|
|
421
|
+
const fx = fl * cd + fc * sd;
|
|
422
|
+
const fy = -fl * sd + fc * cd;
|
|
423
|
+
fFwd += fx;
|
|
424
|
+
fRight += fy;
|
|
425
|
+
torque += w.z * fx - w.x * fy;
|
|
426
|
+
pitchTorque += fx * spec.centreHeight;
|
|
427
|
+
rollTorque += -fy * spec.centreHeight;
|
|
428
|
+
}
|
|
429
|
+
const bogNow = bogging && Math.abs(state.u) < 1 && accelInput > 0;
|
|
430
|
+
if (bogNow && !state.bogged) events.push({ type: "bogged" });
|
|
431
|
+
state.bogged = bogNow;
|
|
432
|
+
state.brakeHeat = brakeHeat + brakeWork / (baseMass * BRAKE_HEAT_CAPACITY) - (brakeHeat - AMBIENT_C) * Math.min(1, dt / BRAKE_COOL_S);
|
|
433
|
+
fFwd += -spec.drag * state.u * Math.abs(state.u);
|
|
434
|
+
fRight += -spec.drag * state.w * Math.abs(state.w);
|
|
435
|
+
const du = fFwd / mass - state.yawRate * state.w;
|
|
436
|
+
const dw = fRight / mass + state.yawRate * state.u;
|
|
437
|
+
state.u += du * dt;
|
|
438
|
+
state.w += dw * dt;
|
|
439
|
+
if (Math.abs(state.u) < 0.02 && accelInput <= 0) state.u = 0;
|
|
440
|
+
state.yawRate += torque / inertia * dt;
|
|
441
|
+
state.yaw += state.yawRate * dt;
|
|
442
|
+
const csn = Math.cos(state.yaw);
|
|
443
|
+
const snn = Math.sin(state.yaw);
|
|
444
|
+
state.x += (state.u * csn + state.w * snn) * dt;
|
|
445
|
+
state.z += (-state.u * snn + state.w * csn) * dt;
|
|
446
|
+
const ay = (sumN - mass * G) / mass;
|
|
447
|
+
state.heightRate += ay * dt;
|
|
448
|
+
state.height += state.heightRate * dt;
|
|
449
|
+
state.pitchRate += (sumNA + pitchTorque) / pitchInertia * dt;
|
|
450
|
+
state.pitch += state.pitchRate * dt;
|
|
451
|
+
state.rollRate += (-sumNB + rollTorque) / rollInertia * dt;
|
|
452
|
+
state.roll += state.rollRate * dt;
|
|
453
|
+
for (let i = 0; i < n; i++) state.loads[i] = wheelState[i].n;
|
|
454
|
+
}
|
|
455
|
+
return driver;
|
|
456
|
+
}
|
|
457
|
+
function semiSpecFromStats(stats, body, base = {}) {
|
|
458
|
+
const spec = { ...defaultSemiSpec, ...base };
|
|
459
|
+
const half = body.wheelbase / 2;
|
|
460
|
+
const side = body.track / 2;
|
|
461
|
+
const driveAll = !!body.fourWheelDrive;
|
|
462
|
+
const wheels = [
|
|
463
|
+
{ x: half, z: -side, steer: true, drive: driveAll },
|
|
464
|
+
{ x: half, z: side, steer: true, drive: driveAll },
|
|
465
|
+
{ x: -half, z: -side, drive: true, handbrake: true },
|
|
466
|
+
{ x: -half, z: side, drive: true, handbrake: true }
|
|
467
|
+
];
|
|
468
|
+
const peakTorque = body.mass * (0.06 + 0.015 * stats.acceleration);
|
|
469
|
+
const engine = { ...spec.engine, peakTorque };
|
|
470
|
+
const top = stats.maxSpeedKmh / 3.6;
|
|
471
|
+
const lastRatio = engine.redlineRpm * 0.95 * 2 * Math.PI * spec.wheelRadius / (60 * top * spec.finalDrive);
|
|
472
|
+
const gears = [...spec.gears.slice(0, -1).map((g, i, all) => Math.max(g, lastRatio * 1.25 ** (all.length - i))), lastRatio];
|
|
473
|
+
const torqueAtTop = peakTorque * 0.76;
|
|
474
|
+
const thrust = torqueAtTop * lastRatio * spec.finalDrive * spec.efficiency / spec.wheelRadius;
|
|
475
|
+
const rollingForce = spec.rolling * body.mass * 9.81;
|
|
476
|
+
const drag = Math.max(0.01, (thrust - rollingForce) / (top * top));
|
|
477
|
+
const carRatio = defaultSemiSpec.brakeForce / (defaultSemiSpec.mass * 9.81);
|
|
478
|
+
const heavyShare = Math.max(0, Math.min(1, (body.mass - 2e3) / 8e3));
|
|
479
|
+
const brakeForce = base.brakeForce ?? body.mass * 9.81 * (carRatio + (0.6 - carRatio) * heavyShare);
|
|
480
|
+
return { ...spec, mass: body.mass, wheels, fourWheelDrive: driveAll, engine, gears, drag, brakeForce, tyre: { ...spec.tyre, friction: 0.8 + 0.03 * stats.handling } };
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
// src/ranges.ts
|
|
484
|
+
var lerpTable = (table, x) => {
|
|
485
|
+
if (x <= table[0][0]) return table[0][1];
|
|
486
|
+
for (let i = 1; i < table.length; i++) {
|
|
487
|
+
const [x1, y1] = table[i];
|
|
488
|
+
const [x0, y0] = table[i - 1];
|
|
489
|
+
if (x <= x1) return y0 + (y1 - y0) * (x - x0) / (x1 - x0);
|
|
490
|
+
}
|
|
491
|
+
return table[table.length - 1][1];
|
|
492
|
+
};
|
|
493
|
+
var defaultRangeTable = {
|
|
494
|
+
accelerationSeconds: [
|
|
495
|
+
[1, 34],
|
|
496
|
+
[3, 21],
|
|
497
|
+
[5, 14],
|
|
498
|
+
[7, 10],
|
|
499
|
+
[9, 6],
|
|
500
|
+
[10, 4.2]
|
|
501
|
+
],
|
|
502
|
+
accelerationSpread: 0.35,
|
|
503
|
+
topSpeedSpread: 0.1,
|
|
504
|
+
dryBrake: { default: [6.5, 11], heavy: [4.5, 8.5], agricultural: [3.5, 7.5], military: [4.5, 9] },
|
|
505
|
+
wetBrake: { default: [3.5, 8.5], heavy: [2.5, 7], agricultural: [2, 6], military: [2.5, 7] },
|
|
506
|
+
turnCircle: { default: [7, 13.5], motorcycles: [3, 9], suvs: [9, 15], pickups: [9, 16], vans: [9, 15], heavy: [10, 26], military: [9, 24], agricultural: [6, 16] },
|
|
507
|
+
mudFourWheelDrive: 10
|
|
508
|
+
};
|
|
509
|
+
var byClass = (table, category) => table[category] ?? table.default;
|
|
510
|
+
var expectedAcceleration = (table, subject, target) => {
|
|
511
|
+
const base = lerpTable(table.accelerationSeconds, subject.stats.acceleration);
|
|
512
|
+
return base * (target / 100);
|
|
513
|
+
};
|
|
514
|
+
var accelerationRange = (table, subject, target) => {
|
|
515
|
+
const t = expectedAcceleration(table, subject, target);
|
|
516
|
+
return { min: round(t * (1 - table.accelerationSpread)), max: round(t * (1 + table.accelerationSpread)) };
|
|
517
|
+
};
|
|
518
|
+
var topSpeedRange = (table, subject) => ({
|
|
519
|
+
min: round(subject.stats.maxSpeedKmh * (1 - table.topSpeedSpread)),
|
|
520
|
+
max: round(subject.stats.maxSpeedKmh * (1 + table.topSpeedSpread))
|
|
521
|
+
});
|
|
522
|
+
var brakeRange = (decel, kmh2) => {
|
|
523
|
+
const v = kmh2 / 3.6;
|
|
524
|
+
return { min: round(v * v / (2 * decel[1])), max: round(v * v / (2 * decel[0])) };
|
|
525
|
+
};
|
|
526
|
+
var dryBrakeRange = (table, subject, kmh2) => brakeRange(byClass(table.dryBrake, subject.category), kmh2);
|
|
527
|
+
var wetBrakeRange = (table, subject, kmh2) => brakeRange(byClass(table.wetBrake, subject.category), kmh2);
|
|
528
|
+
var turnCircleRange = (table, subject) => {
|
|
529
|
+
const [min, max] = byClass(table.turnCircle, subject.category);
|
|
530
|
+
return { min, max };
|
|
531
|
+
};
|
|
532
|
+
var inRange = (value, range) => (range.min == null || value >= range.min) && (range.max == null || value <= range.max);
|
|
533
|
+
var round = (x, digits = 1) => {
|
|
534
|
+
const k = 10 ** digits;
|
|
535
|
+
return Math.round(x * k) / k;
|
|
536
|
+
};
|
|
537
|
+
|
|
538
|
+
// src/run.ts
|
|
539
|
+
var subjectSpec = (subject) => ({ ...semiSpecFromStats(subject.stats, subject.body), ...subject.spec });
|
|
540
|
+
function startRun(test, subject, options = {}) {
|
|
541
|
+
const procedure = test.procedure;
|
|
542
|
+
if (test.kind !== "measured" || !procedure) throw new Error(`startRun: ${test.id} is not a measured test`);
|
|
543
|
+
const surfaces = options.surfaces ?? createSurfaces();
|
|
544
|
+
const driver = createSemiSimDriver(subjectSpec(subject), { surfaces });
|
|
545
|
+
driver.place(0, 0, 0);
|
|
546
|
+
const surface = procedure.surface ?? "dry_asphalt";
|
|
547
|
+
const world = { ground: () => ({ surface }) };
|
|
548
|
+
const memo = { target: procedure.target?.(subject) ?? 0, subject };
|
|
549
|
+
const trace = [];
|
|
550
|
+
const sampleEvery = options.sampleEvery ?? 0.1;
|
|
551
|
+
const fixed = options.fixedStep ?? 1 / 120;
|
|
552
|
+
let time = 0;
|
|
553
|
+
let done = false;
|
|
554
|
+
let nextSample = 0;
|
|
555
|
+
let carry = 0;
|
|
556
|
+
const tick = (h) => {
|
|
557
|
+
const input = procedure.input(driver.state, time, memo);
|
|
558
|
+
driver.step(input, h, world);
|
|
559
|
+
time += h;
|
|
560
|
+
if (time >= nextSample) {
|
|
561
|
+
trace.push([Math.round(time * 1e3) / 1e3, procedure.sample(driver.state, time, memo)]);
|
|
562
|
+
nextSample += sampleEvery;
|
|
563
|
+
}
|
|
564
|
+
if (procedure.finished(driver.state, time, memo) || time >= procedure.maxSeconds) done = true;
|
|
565
|
+
};
|
|
566
|
+
return {
|
|
567
|
+
test,
|
|
568
|
+
subject,
|
|
569
|
+
driver,
|
|
570
|
+
surface,
|
|
571
|
+
memo,
|
|
572
|
+
get time() {
|
|
573
|
+
return time;
|
|
574
|
+
},
|
|
575
|
+
get done() {
|
|
576
|
+
return done;
|
|
577
|
+
},
|
|
578
|
+
get trace() {
|
|
579
|
+
return trace;
|
|
580
|
+
},
|
|
581
|
+
step(dt) {
|
|
582
|
+
carry += dt;
|
|
583
|
+
while (!done && carry >= fixed) {
|
|
584
|
+
carry -= fixed;
|
|
585
|
+
tick(fixed);
|
|
586
|
+
}
|
|
587
|
+
},
|
|
588
|
+
result() {
|
|
589
|
+
const range = test.range?.(subject) ?? {};
|
|
590
|
+
const base = { test: test.id, kind: test.kind, unit: test.unit, range, trace: [...trace] };
|
|
591
|
+
if (!done) return { ...base, verdict: "pending", value: null, note: "running" };
|
|
592
|
+
const value = procedure.value(driver.state, time, memo);
|
|
593
|
+
const lowered = memo.target > 0 && /_100|_80/.test(test.id) && memo.target < (test.id.includes("80") ? 80 : 100);
|
|
594
|
+
const note = lowered ? `target ${memo.target} km/h` : void 0;
|
|
595
|
+
if (value == null) return { ...base, verdict: "fail", value: null, note: `did not finish in ${procedure.maxSeconds} s` };
|
|
596
|
+
return { ...base, verdict: inRange(value, range) ? "pass" : "fail", value, ...note ? { note } : {} };
|
|
597
|
+
}
|
|
598
|
+
};
|
|
599
|
+
}
|
|
600
|
+
function runTest(test, subject, options = {}) {
|
|
601
|
+
const run = startRun(test, subject, options);
|
|
602
|
+
const fixed = options.fixedStep ?? 1 / 120;
|
|
603
|
+
while (!run.done) run.step(fixed * 60);
|
|
604
|
+
return run.result();
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
// src/tests.ts
|
|
608
|
+
var KMH = 3.6;
|
|
609
|
+
var idle = { throttle: 0, brake: 0, steer: 0, handbrake: false };
|
|
610
|
+
var kmh = (s) => Math.abs(s.u) * KMH;
|
|
611
|
+
var travelled = (s, memo, key) => Math.hypot(s.x - memo[`${key}X`], s.z - memo[`${key}Z`]);
|
|
612
|
+
var reachable = (subject, wanted) => Math.min(wanted, Math.round(subject.stats.maxSpeedKmh * 0.8));
|
|
613
|
+
var brakeFrom = (wanted, surface) => ({
|
|
614
|
+
...surface ? { surface } : {},
|
|
615
|
+
maxSeconds: 90,
|
|
616
|
+
target: (subject) => reachable(subject, wanted),
|
|
617
|
+
input(state, _time, memo) {
|
|
618
|
+
if (!memo.braking && kmh(state) >= memo.target) {
|
|
619
|
+
memo.braking = true;
|
|
620
|
+
memo.brakeX = state.x;
|
|
621
|
+
memo.brakeZ = state.z;
|
|
622
|
+
}
|
|
623
|
+
return memo.braking ? { ...idle, brake: 1 } : { ...idle, throttle: 1 };
|
|
624
|
+
},
|
|
625
|
+
sample: (state) => kmh(state),
|
|
626
|
+
finished: (state, _t, memo) => !!memo.braking && kmh(state) < 0.3,
|
|
627
|
+
value: (state, _t, memo) => memo.braking ? round(travelled(state, memo, "brake")) : null
|
|
628
|
+
});
|
|
629
|
+
function defaultProvingTests(ranges = defaultRangeTable) {
|
|
630
|
+
return [
|
|
631
|
+
{
|
|
632
|
+
id: "accel_0_100",
|
|
633
|
+
kind: "measured",
|
|
634
|
+
domains: ["land"],
|
|
635
|
+
unit: "s",
|
|
636
|
+
procedure: {
|
|
637
|
+
maxSeconds: 90,
|
|
638
|
+
target: (subject) => reachable(subject, 100),
|
|
639
|
+
input: () => ({ ...idle, throttle: 1 }),
|
|
640
|
+
sample: (state) => kmh(state),
|
|
641
|
+
finished: (state, _t, memo) => kmh(state) >= memo.target,
|
|
642
|
+
value: (state, time, memo) => kmh(state) >= memo.target ? round(time, 2) : null
|
|
643
|
+
},
|
|
644
|
+
range: (subject) => accelerationRange(ranges, subject, reachable(subject, 100))
|
|
645
|
+
},
|
|
646
|
+
{
|
|
647
|
+
id: "top_speed",
|
|
648
|
+
kind: "measured",
|
|
649
|
+
domains: ["land"],
|
|
650
|
+
unit: "km/h",
|
|
651
|
+
procedure: {
|
|
652
|
+
maxSeconds: 150,
|
|
653
|
+
input: () => ({ ...idle, throttle: 1 }),
|
|
654
|
+
sample: (state) => kmh(state),
|
|
655
|
+
// stops when the speed has grown less than 0.5 km/h in the last 4 seconds
|
|
656
|
+
finished(state, time, memo) {
|
|
657
|
+
const history = memo.history ?? (memo.history = []);
|
|
658
|
+
history.push([time, kmh(state)]);
|
|
659
|
+
while (history.length > 1 && time - history[0][0] > 4) history.shift();
|
|
660
|
+
memo.best = Math.max(memo.best ?? 0, kmh(state));
|
|
661
|
+
return time > 8 && history.length > 1 && kmh(state) - history[0][1] < 0.5;
|
|
662
|
+
},
|
|
663
|
+
value: (_state, _t, memo) => round(memo.best ?? 0)
|
|
664
|
+
},
|
|
665
|
+
range: (subject) => topSpeedRange(ranges, subject)
|
|
666
|
+
},
|
|
667
|
+
{
|
|
668
|
+
id: "brake_100_0",
|
|
669
|
+
kind: "measured",
|
|
670
|
+
domains: ["land"],
|
|
671
|
+
unit: "m",
|
|
672
|
+
procedure: brakeFrom(100),
|
|
673
|
+
range: (subject) => dryBrakeRange(ranges, subject, reachable(subject, 100))
|
|
674
|
+
},
|
|
675
|
+
{
|
|
676
|
+
id: "turn_circle",
|
|
677
|
+
kind: "measured",
|
|
678
|
+
domains: ["land"],
|
|
679
|
+
unit: "m",
|
|
680
|
+
procedure: {
|
|
681
|
+
maxSeconds: 30,
|
|
682
|
+
target: () => 12,
|
|
683
|
+
// full lock at a walking pace, the throttle holding 12 km/h; after the circle settles the diameter is twice the speed over the yaw rate
|
|
684
|
+
input: (state, _t, memo) => ({ ...idle, steer: 1, throttle: kmh(state) < memo.target ? 0.5 : 0, brake: kmh(state) > memo.target + 3 ? 0.3 : 0 }),
|
|
685
|
+
sample: (state) => Math.abs(state.yawRate) > 1e-3 ? 2 * Math.abs(state.u) / Math.abs(state.yawRate) : 0,
|
|
686
|
+
finished(state, time, memo) {
|
|
687
|
+
if (time < 6) return false;
|
|
688
|
+
const d = Math.abs(state.yawRate) > 1e-3 ? 2 * Math.abs(state.u) / Math.abs(state.yawRate) : Infinity;
|
|
689
|
+
const samples = memo.samples ?? (memo.samples = []);
|
|
690
|
+
samples.push(d);
|
|
691
|
+
return samples.length > 240;
|
|
692
|
+
},
|
|
693
|
+
value(_state, _t, memo) {
|
|
694
|
+
const samples = memo.samples ?? [];
|
|
695
|
+
if (!samples.length) return null;
|
|
696
|
+
return round(samples.reduce((a, b) => a + b, 0) / samples.length);
|
|
697
|
+
}
|
|
698
|
+
},
|
|
699
|
+
range: (subject) => turnCircleRange(ranges, subject)
|
|
700
|
+
},
|
|
701
|
+
{
|
|
702
|
+
id: "wet_brake_80_0",
|
|
703
|
+
kind: "measured",
|
|
704
|
+
domains: ["land"],
|
|
705
|
+
unit: "m",
|
|
706
|
+
procedure: brakeFrom(80, "wet_asphalt"),
|
|
707
|
+
range: (subject) => wetBrakeRange(ranges, subject, reachable(subject, 80))
|
|
708
|
+
},
|
|
709
|
+
{
|
|
710
|
+
id: "mud_traction",
|
|
711
|
+
kind: "measured",
|
|
712
|
+
domains: ["land"],
|
|
713
|
+
unit: "m",
|
|
714
|
+
procedure: {
|
|
715
|
+
surface: "mud",
|
|
716
|
+
maxSeconds: 10,
|
|
717
|
+
input: () => ({ ...idle, throttle: 1 }),
|
|
718
|
+
sample: (state) => kmh(state),
|
|
719
|
+
finished: () => false,
|
|
720
|
+
value: (state) => round(Math.hypot(state.x, state.z))
|
|
721
|
+
},
|
|
722
|
+
// a four-wheel-drive vehicle has to get through; a two-wheel-drive one sinks, which is right, so it has no band
|
|
723
|
+
range: (subject) => subject.body.fourWheelDrive ? { min: ranges.mudFourWheelDrive } : {}
|
|
724
|
+
},
|
|
725
|
+
// seen by a person in the test room and signed off with a print
|
|
726
|
+
{ id: "cabin", kind: "visual", domains: ["land", "water", "air"], unit: "" },
|
|
727
|
+
{ id: "cameras", kind: "visual", domains: ["land", "water", "air"], unit: "" },
|
|
728
|
+
{ id: "mirrors", kind: "visual", domains: ["land"], unit: "" },
|
|
729
|
+
// rooms of the next phases: pending until each room reports
|
|
730
|
+
{ id: "terrain", kind: "room", domains: ["land"], unit: "", available: false },
|
|
731
|
+
{ id: "wind_tunnel", kind: "room", domains: ["land", "air"], unit: "", available: false },
|
|
732
|
+
{ id: "crash_test", kind: "room", domains: ["land"], unit: "", available: false },
|
|
733
|
+
{ id: "pedestrian", kind: "room", domains: ["land"], unit: "", available: false },
|
|
734
|
+
{ id: "performance", kind: "room", domains: ["land", "water", "air"], unit: "", available: false },
|
|
735
|
+
{ id: "buoyancy", kind: "room", domains: ["water"], unit: "", available: false },
|
|
736
|
+
{ id: "flight", kind: "room", domains: ["air"], unit: "", available: false }
|
|
737
|
+
];
|
|
738
|
+
}
|
|
739
|
+
function createProvingTests(options = {}) {
|
|
740
|
+
const given = options.ranges ?? {};
|
|
741
|
+
const ranges = {
|
|
742
|
+
...defaultRangeTable,
|
|
743
|
+
...given,
|
|
744
|
+
dryBrake: { ...defaultRangeTable.dryBrake, ...given.dryBrake },
|
|
745
|
+
wetBrake: { ...defaultRangeTable.wetBrake, ...given.wetBrake },
|
|
746
|
+
turnCircle: { ...defaultRangeTable.turnCircle, ...given.turnCircle }
|
|
747
|
+
};
|
|
748
|
+
const entries = mergeById(defaultProvingTests(ranges), options.packs?.flatMap((pack) => pack.tests ?? []));
|
|
749
|
+
applyPatches(entries, options.patch);
|
|
750
|
+
removeIds(entries, options.remove);
|
|
751
|
+
const list = () => [...entries.values()];
|
|
752
|
+
return {
|
|
753
|
+
get tests() {
|
|
754
|
+
return list();
|
|
755
|
+
},
|
|
756
|
+
get: (id) => entries.get(id),
|
|
757
|
+
forDomain: (domain) => list().filter((t) => t.domains.includes(domain)),
|
|
758
|
+
ranges
|
|
759
|
+
};
|
|
760
|
+
}
|
|
761
|
+
|
|
762
|
+
// src/certificate.ts
|
|
763
|
+
var statusOf = (results) => results.some((r) => r.verdict === "fail") ? "rejected" : results.every((r) => r.verdict === "pass") ? "approved" : "pending";
|
|
764
|
+
function certify(subject, options = {}) {
|
|
765
|
+
const tests = options.tests ?? createProvingTests();
|
|
766
|
+
const results = tests.forDomain(subject.domain).map((test) => {
|
|
767
|
+
const signed = options.signOffs?.find((s) => s.vehicle === subject.id && s.test === test.id);
|
|
768
|
+
const reported = options.reports?.find((r) => r.test === test.id);
|
|
769
|
+
if (reported) return reported;
|
|
770
|
+
if (test.kind === "measured" && test.procedure && subject.domain === "land") return runTest(test, subject, options);
|
|
771
|
+
if (signed)
|
|
772
|
+
return {
|
|
773
|
+
test: test.id,
|
|
774
|
+
kind: test.kind,
|
|
775
|
+
unit: test.unit,
|
|
776
|
+
range: {},
|
|
777
|
+
value: null,
|
|
778
|
+
verdict: signed.ok ? "pass" : "fail",
|
|
779
|
+
...signed.by ? { signedBy: signed.by } : {},
|
|
780
|
+
...signed.evidence ? { evidence: signed.evidence } : {},
|
|
781
|
+
...signed.note ? { note: signed.note } : {}
|
|
782
|
+
};
|
|
783
|
+
const note = test.kind === "visual" ? "awaiting sign-off in the test room" : test.kind === "room" ? "room not built yet" : "no runner for this domain yet";
|
|
784
|
+
return { test: test.id, kind: test.kind, unit: test.unit, range: {}, value: null, verdict: "pending", note };
|
|
785
|
+
});
|
|
786
|
+
return { vehicle: subject.id, domain: subject.domain, category: subject.category, status: statusOf(results), results };
|
|
787
|
+
}
|
|
788
|
+
function withResult(certificate, result) {
|
|
789
|
+
const results = certificate.results.some((r) => r.test === result.test) ? certificate.results.map((r) => r.test === result.test ? result : r) : [...certificate.results, result];
|
|
790
|
+
return { ...certificate, results, status: statusOf(results) };
|
|
791
|
+
}
|
|
792
|
+
function gateVehicles(ids, certificates, options = {}) {
|
|
793
|
+
const byId = new Map(certificates.map((c) => [c.vehicle, c]));
|
|
794
|
+
return ids.filter((id) => {
|
|
795
|
+
if (options.deny?.includes(id)) return false;
|
|
796
|
+
if (options.allow?.includes(id)) return true;
|
|
797
|
+
const status = byId.get(id)?.status ?? "pending";
|
|
798
|
+
return status === "approved" || status === "pending" && !!options.allowPending;
|
|
799
|
+
});
|
|
800
|
+
}
|
|
801
|
+
|
|
802
|
+
// src/fleet.ts
|
|
803
|
+
var DEFAULT_DENSITY = { motorcycles: 90, cars: 88, suvs: 90, pickups: 95, vans: 80, heavy: 120, agricultural: 150, military: 260, water: 60, air: 40 };
|
|
804
|
+
var DEFAULT_DOMAINS = { water: "water", air: "air" };
|
|
805
|
+
function subjectFromCard(id, card) {
|
|
806
|
+
const { dims, group } = card;
|
|
807
|
+
const mass = card.mass ?? Math.round((DEFAULT_DENSITY[group] ?? 90) * dims.length * dims.width * dims.height);
|
|
808
|
+
return {
|
|
809
|
+
id,
|
|
810
|
+
domain: (card.domains ?? DEFAULT_DOMAINS)[group] ?? "land",
|
|
811
|
+
category: group,
|
|
812
|
+
stats: { acceleration: card.stats.acceleration, handling: card.stats.handling, maxSpeedKmh: card.stats.maxSpeedKmh },
|
|
813
|
+
body: {
|
|
814
|
+
mass,
|
|
815
|
+
wheelbase: card.wheelbase ?? Math.round(dims.length * 0.6 * 100) / 100,
|
|
816
|
+
track: card.track ?? Math.round(dims.width * 0.82 * 100) / 100,
|
|
817
|
+
fourWheelDrive: !!card.fourWheelDrive
|
|
818
|
+
}
|
|
819
|
+
};
|
|
820
|
+
}
|
|
821
|
+
return __toCommonJS(index_exports);
|
|
822
|
+
})();
|
|
823
|
+
//# sourceMappingURL=index.global.js.map
|