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));
|
||||
|
||||
Reference in New Issue
Block a user