zenno/lib: rearrange parameters in race.speedGain
This commit is contained in:
@@ -270,24 +270,24 @@ export function skillDuration(baseDur: number, raceLen: number): number {
|
||||
* Calculate the distance gained from a target speed boost, including
|
||||
* acceleration to the boosted target speed and deceleration back to baseline.
|
||||
* @param speedBonus Difference between baseline and boosted speed in m/s
|
||||
* @param accel Current acceleration value in m/s²
|
||||
* @param decel Current phase-based deceleration value in m/s², a negative value.
|
||||
* @param accel Current acceleration value in m/s², or null for instant acceleration
|
||||
* @param decel Current phase-based deceleration value in m/s², a negative value; or null for instant deceleration
|
||||
* @param dur Duration of the boosted speed
|
||||
* @returns Distance gained from the speed boost in m
|
||||
*/
|
||||
export function speedGain(speedBonus: number, accel: number, decel: number, dur: number): number {
|
||||
export function speedGain(speedBonus: number, dur: number, accel: number | null, decel: number | null): number {
|
||||
// Actual effect of a target speed bonus looks like
|
||||
// speed: __/-----\__
|
||||
// bonus: ======
|
||||
// I.e., the speed bonus duration includes acceleration to the new speed
|
||||
// and does not include the acceleration back to baseline after it ends.
|
||||
const accelTime = speedBonus / accel;
|
||||
const decelTime = -speedBonus / decel;
|
||||
const accelTime = accel !== null ? speedBonus / accel : 0;
|
||||
const decelTime = decel !== null ? -speedBonus / decel : 0;
|
||||
if (accelTime >= dur) {
|
||||
// Acceleration is so low that the horse won't reach the boosted target
|
||||
// speed before the effect ends. E.g., G surface aptitude.
|
||||
const peakSpeed = accel * dur;
|
||||
return 0.5 * (peakSpeed * dur - peakSpeed / decel);
|
||||
const peakSpeed = (accel ?? 0) * dur;
|
||||
return 0.5 * (peakSpeed * dur - peakSpeed / (decel ?? 0));
|
||||
}
|
||||
// speedBonus*(dur-accelTime) + speedBonus*accelTime/2 + speedBonus*decelTime/2
|
||||
return speedBonus * (dur + 0.5 * (decelTime - accelTime));
|
||||
|
||||
@@ -54,24 +54,24 @@
|
||||
const ssY: Array<ComputedSeries | null> = $derived([
|
||||
{
|
||||
label: 'Aptitude S',
|
||||
y: (x) => speedGain(spotStruggleSpeed(x), accel[0], decel[0], spotStruggleDuration(x, AptitudeLevel.S)) / HORSE_LENGTH,
|
||||
y: (x) => speedGain(spotStruggleSpeed(x), spotStruggleDuration(x, AptitudeLevel.S), accel[0], decel[0]) / HORSE_LENGTH,
|
||||
},
|
||||
{
|
||||
label: 'Aptitude A',
|
||||
y: (x) => speedGain(spotStruggleSpeed(x), accel[0], decel[0], spotStruggleDuration(x, AptitudeLevel.A)) / HORSE_LENGTH,
|
||||
y: (x) => speedGain(spotStruggleSpeed(x), spotStruggleDuration(x, AptitudeLevel.A), accel[0], decel[0]) / HORSE_LENGTH,
|
||||
},
|
||||
frontApt < AptitudeLevel.A
|
||||
? {
|
||||
label: `Aptitude ${AptitudeLevel[frontApt]}`,
|
||||
y: (x) => speedGain(spotStruggleSpeed(x), accel[0], decel[0], spotStruggleDuration(x, frontApt)) / HORSE_LENGTH,
|
||||
y: (x) => speedGain(spotStruggleSpeed(x), spotStruggleDuration(x, frontApt), accel[0], decel[0]) / HORSE_LENGTH,
|
||||
}
|
||||
: null,
|
||||
]);
|
||||
const lcY: Array<ComputedSeries | null> = $derived([
|
||||
{ label: 'Ideal Lane Combo', y: (x) => speedGain(moveLaneModifier(x), accel[0], decel[0], lcDur) / HORSE_LENGTH },
|
||||
{ label: 'Ideal Lane Combo', y: (x) => speedGain(moveLaneModifier(x), lcDur, accel[0], decel[0]) / HORSE_LENGTH },
|
||||
]);
|
||||
const yRule: HorizontalRule[] = $derived([
|
||||
{ y: speedGain(0.35, accel[1], decel[1], skillDuration(2.4, raceLen)) / HORSE_LENGTH, label: 'Professor of Curvature' },
|
||||
{ y: speedGain(0.35, skillDuration(2.4, raceLen), accel[1], decel[1]) / HORSE_LENGTH, label: 'Professor of Curvature' },
|
||||
]);
|
||||
</script>
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
const { children, speed, dur, accel, decel }: Props = $props();
|
||||
const decels = $derived([decel].flat(1));
|
||||
|
||||
const gain = $derived(decels.map((d) => speedGain(speed, accel, d, dur) / HORSE_LENGTH));
|
||||
const gain = $derived(decels.map((d) => speedGain(speed, dur, accel, d) / HORSE_LENGTH));
|
||||
const text = $derived(gain.map(fmtp).join(' – '));
|
||||
</script>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user