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
|
* Calculate the distance gained from a target speed boost, including
|
||||||
* acceleration to the boosted target speed and deceleration back to baseline.
|
* acceleration to the boosted target speed and deceleration back to baseline.
|
||||||
* @param speedBonus Difference between baseline and boosted speed in m/s
|
* @param speedBonus Difference between baseline and boosted speed in m/s
|
||||||
* @param accel Current acceleration value in m/s²
|
* @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.
|
* @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
|
* @param dur Duration of the boosted speed
|
||||||
* @returns Distance gained from the speed boost in m
|
* @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
|
// Actual effect of a target speed bonus looks like
|
||||||
// speed: __/-----\__
|
// speed: __/-----\__
|
||||||
// bonus: ======
|
// bonus: ======
|
||||||
// I.e., the speed bonus duration includes acceleration to the new speed
|
// I.e., the speed bonus duration includes acceleration to the new speed
|
||||||
// and does not include the acceleration back to baseline after it ends.
|
// and does not include the acceleration back to baseline after it ends.
|
||||||
const accelTime = speedBonus / accel;
|
const accelTime = accel !== null ? speedBonus / accel : 0;
|
||||||
const decelTime = -speedBonus / decel;
|
const decelTime = decel !== null ? -speedBonus / decel : 0;
|
||||||
if (accelTime >= dur) {
|
if (accelTime >= dur) {
|
||||||
// Acceleration is so low that the horse won't reach the boosted target
|
// Acceleration is so low that the horse won't reach the boosted target
|
||||||
// speed before the effect ends. E.g., G surface aptitude.
|
// speed before the effect ends. E.g., G surface aptitude.
|
||||||
const peakSpeed = accel * dur;
|
const peakSpeed = (accel ?? 0) * dur;
|
||||||
return 0.5 * (peakSpeed * dur - peakSpeed / decel);
|
return 0.5 * (peakSpeed * dur - peakSpeed / (decel ?? 0));
|
||||||
}
|
}
|
||||||
// speedBonus*(dur-accelTime) + speedBonus*accelTime/2 + speedBonus*decelTime/2
|
// speedBonus*(dur-accelTime) + speedBonus*accelTime/2 + speedBonus*decelTime/2
|
||||||
return speedBonus * (dur + 0.5 * (decelTime - accelTime));
|
return speedBonus * (dur + 0.5 * (decelTime - accelTime));
|
||||||
|
|||||||
@@ -54,24 +54,24 @@
|
|||||||
const ssY: Array<ComputedSeries | null> = $derived([
|
const ssY: Array<ComputedSeries | null> = $derived([
|
||||||
{
|
{
|
||||||
label: 'Aptitude S',
|
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',
|
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
|
frontApt < AptitudeLevel.A
|
||||||
? {
|
? {
|
||||||
label: `Aptitude ${AptitudeLevel[frontApt]}`,
|
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,
|
: null,
|
||||||
]);
|
]);
|
||||||
const lcY: Array<ComputedSeries | null> = $derived([
|
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([
|
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>
|
</script>
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
const { children, speed, dur, accel, decel }: Props = $props();
|
const { children, speed, dur, accel, decel }: Props = $props();
|
||||||
const decels = $derived([decel].flat(1));
|
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(' – '));
|
const text = $derived(gain.map(fmtp).join(' – '));
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user