Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 | 295x 295x 258x 35x 53x 53x 420x 507x 708x 551x 22x 22x 28x 38x 154x 4x 90x 193x 420x 420x 420x 420x 517x 517x 517x 420x 377x 377x 37x 50x 37x 377x 383x 381x 80x 78x 77x 1146x 4x 1142x 940x 494x 494x 22x 26x 84x 31x 11x 320x 446x 158x 21x 267x 1297x 4x 1293x 1297x 1297x 738x 738x 738x 116x 116x 116x 9961x 29x | import { createLR2GoodAttackGauge, createLR2PerfectAttackGauge } from './lr2-attack.ts';
import type { GaugeGutsStep, GaugeSpec, JudgeWindowSetUs, RulesetId, RulesetWindowTables } from './definitions.ts';
import { resolvePlugoutCourseGauge, resolvePlugoutGaugeId, resolvePlugoutGradeStageStart } from './plugout.ts';
/**
* Course play (LR2 grade / expert / nonstop courses and beatoraja courses): which gauge a stage runs on and how a
* course's judge constraint narrows the windows. Shared by the engine and the replay simulator through
* `resolveRuleset`, like every other ruleset rule.
*/
/** A course's kind as the ruleset needs it: LR2 picks its course gauges by it; beatoraja does not distinguish. */
export type RulesetCourseKind = 'grade' | 'expert' | 'nonstop';
/** beatoraja's class-gauge table sets, chosen by a course's `gauge_*` constraint or else by the play mode. */
export type CourseGaugeSet = 'lr2' | '5k' | '7k' | '9k' | '24k';
/** beatoraja's `NO_GOOD` / `NO_GREAT` course constraints. */
export type CourseJudgeConstraint = 'no-good' | 'no-great';
/**
* LR2 advances at HP >= 2; the class gauges of the other rulesets require a positive value. The rule is the course
* gauge's own: a gauge of another source (`gauge.source`, #1171) keeps that source's rule under this ruleset's judging.
*/
export function isCourseStageFailed(
ruleset: string,
gauge: { final: number; failedMidPlay?: boolean; source?: string },
): boolean {
const source = gauge.source ?? ruleset.split('/')[0];
// plugout's course gauges fail as they empty, or (grade NORMAL / EASY) as their lives run out: a gauge left at 0 with
// lives to spare passes the stage.
if (source === 'plugout') return gauge.failedMidPlay === true;
return gauge.failedMidPlay === true || (source === 'lr2' ? gauge.final < 2 : gauge.final <= 0);
}
/**
* Whether a course run goes on after a stage the player gave up with ESC. The rule is the course gauge's own, as the
* stage failure rule is (`gauge.source`, #1171):
*
* - LR2 shows the given-up stage as FAILED and goes on to the next stage while the gauge is at 2 % or more, provided the
* stage judged a GOOD or better; otherwise it returns to the select screen (`LR2body.exe`). The course lamp is then
* FAILED, since a stage was left unplayed.
* - beatoraja's class gauges end the run: `BMSPlayer.stopPlay` fails the stage and fills its gauge log with 0 up to the
* chart's end, and `MusicResult` ends a course whose gauge stands at 0 or less. That-Which-Must-Not-Be-Named's courses
* run on these gauges and follow them.
* - plugout leaves nothing to follow, and its run ends there: Be-Music's choice, as before LR2's rule was told apart.
*
* A run that has no last stage (an endless RANDOM MIX) never goes on: ESC is how its player stops it.
*/
export function courseGoesOnAfterGivingUp(
ruleset: string,
result: {
gauge: { final: number; failedMidPlay?: boolean; source?: string };
judge: { pgreat: number; great: number; good: number };
},
): boolean {
return givenUpCourseStageShowsResult(ruleset, result) && !isCourseStageFailed(ruleset, result.gauge);
}
/**
* Whether a course stage the player gave up with ESC shows its result, as FAILED, before the run goes on or ends. LR2
* shows it once the stage judged a GOOD or better, whether or not the gauge holds; with none it returns to the select
* screen (`LR2body.exe`). Under a gauge of another source the run goes on to the course result with no stage result
* shown: Be-Music's narrower choice, since only LR2's screen flow is verified (`gauge.source`, #1171).
*/
export function givenUpCourseStageShowsResult(
ruleset: string,
result: {
gauge: { source?: string };
judge: { pgreat: number; great: number; good: number };
},
): boolean {
const source = result.gauge.source ?? ruleset.split('/')[0];
return source === 'lr2' && result.judge.pgreat + result.judge.great + result.judge.good > 0;
}
export interface RulesetCourseOptions {
kind: RulesetCourseKind;
/** The course's `gauge_*` constraint; without one beatoraja picks the set by play mode. LR2 ignores it. */
gaugeSet?: CourseGaugeSet;
judge?: CourseJudgeConstraint;
/**
* The gauge value carried in from the previous stage (every course gauge starts the first stage at 100). Clamped to
* the gauge's range.
*/
initialGauge?: number;
/** Every course gauge of the ladder, carried independently by gauge auto-shift (keyed by gauge id). */
initialGauges?: Readonly<Record<string, number>>;
}
type GaugeValues = GaugeSpec['values'];
/** LR2's low-HP damage reduction on course gauges: BAD / POOR / empty POOR × 0.6 below 32 % (OpenLR2 L1955-L1961). */
const LR2_COURSE_GUTS: readonly GaugeGutsStep[] = [{ threshold: 32, multiplier: 0.6 }];
function lr2CourseGauge(id: string, values: GaugeValues): GaugeSpec {
// Course HP starts at 100 with no 2 % floor (L24532-L24535, L1964) and is pinned at 0 once it falls below 2
// (L1971-L1975): a survival gauge with LR2's death border, whatever gauge the player picked.
return { id, min: 0, max: 100, initial: 100, border: 0, survival: true, death: 2, values, guts: LR2_COURSE_GUTS };
}
function scaleLR2Damage(values: GaugeValues, damage: number): GaugeValues {
return values.map((value) => (value < 0 ? value * damage : value)) as unknown as GaugeValues;
}
/**
* LR2's course gauges (OpenLR2 `LR2f.cpp` L27707-L27790). Grade courses: GROOVE / EASY play the grade gauge, HARD the
* grade HARD gauge, DEATH the grade DEATH gauge. EXPERT / NONSTOP courses have a GROOVE, EASY, HARD and DEATH line of
* their own. HARD damage scales by `damage` (LR2's TOTAL / note-count multiplier), as on single charts.
*/
function resolveLR2CourseGauge(gaugeId: string, damage: number): GaugeSpec {
switch (gaugeId) {
case 'P-ATTACK':
return createLR2PerfectAttackGauge();
case 'G-ATTACK':
return createLR2GoodAttackGauge(damage);
case 'GRADE-HARD':
return lr2CourseGauge(gaugeId, scaleLR2Damage([0.1, 0.1, 0.04, -6, -10, -2], damage));
case 'GRADE-DEATH':
case 'COURSE-DEATH':
return lr2CourseGauge(gaugeId, [0, 0, 0, -100, -100, 0]);
case 'COURSE':
return lr2CourseGauge(gaugeId, [0.1, 0.1, 0.04, -1.5, -2, -1.5]);
case 'COURSE-EASY':
return lr2CourseGauge(gaugeId, [0.12, 0.12, 0.048, -1.2, -1.6, -1.2]);
case 'COURSE-HARD':
return lr2CourseGauge(gaugeId, scaleLR2Damage([0.1, 0.1, 0.05, -6, -10, -2], damage));
default:
return lr2CourseGauge('GRADE', [0.1, 0.1, 0.04, -2, -3, -2]);
}
}
const CLASS_GUTS: readonly GaugeGutsStep[] = [
{ threshold: 5, multiplier: 0.4 },
{ threshold: 10, multiplier: 0.5 },
{ threshold: 15, multiplier: 0.6 },
{ threshold: 20, multiplier: 0.7 },
{ threshold: 25, multiplier: 0.8 },
];
const CLASS_LR2_GUTS: readonly GaugeGutsStep[] = [{ threshold: 30, multiplier: 0.6 }];
interface ClassGaugeRow {
values: GaugeValues;
guts: readonly GaugeGutsStep[];
}
/** beatoraja's `GaugeElementProperty` class gauges: `[CLASS, EXCLASS, EXHARDCLASS]` per table set. */
const CLASS_GAUGES: Readonly<Record<CourseGaugeSet, readonly [ClassGaugeRow, ClassGaugeRow, ClassGaugeRow]>> = {
'5k': [
{ values: [0.01, 0.01, 0, -0.5, -1, -0.5], guts: [] },
{ values: [0.01, 0.01, 0, -1, -2, -1], guts: [] },
{ values: [0.01, 0.01, 0, -2.5, -5, -2.5], guts: [] },
],
'7k': [
{ values: [0.15, 0.12, 0.06, -1.5, -3, -1.5], guts: CLASS_GUTS },
{ values: [0.15, 0.12, 0.03, -3, -6, -3], guts: [] },
{ values: [0.15, 0.06, 0, -5, -10, -5], guts: [] },
],
'9k': [
{ values: [0.15, 0.12, 0.06, -1.5, -3, -3], guts: CLASS_GUTS },
{ values: [0.15, 0.12, 0.03, -3, -6, -6], guts: [] },
{ values: [0.15, 0.06, 0, -5, -10, -10], guts: [] },
],
'24k': [
{ values: [0.2, 0.2, 0.1, -1.5, -3, -1.5], guts: CLASS_GUTS },
{ values: [0.2, 0.2, 0.1, -3, -6, -3], guts: [] },
{ values: [0.2, 0.1, 0, -5, -10, -5], guts: [] },
],
lr2: [
{ values: [0.1, 0.1, 0.05, -2, -3, -2], guts: CLASS_LR2_GUTS },
{ values: [0.1, 0.1, 0.05, -6, -10, -2], guts: CLASS_LR2_GUTS },
{ values: [0.1, 0.1, 0.05, -12, -20, -2], guts: [] },
],
};
const CLASS_GAUGE_IDS = ['CLASS', 'EXCLASS', 'EXHARDCLASS'] as const;
/**
* beatoraja's class gauges (`GaugeProperty`): min 0, max 100, start 100, border 0, no TOTAL modifier. A course plays
* on them whatever its kind (`GrooveGauge.create`).
*/
export function resolveClassGauge(gaugeId: string, gaugeSet: CourseGaugeSet): GaugeSpec {
const index = Math.max(0, CLASS_GAUGE_IDS.indexOf(gaugeId as (typeof CLASS_GAUGE_IDS)[number]));
const row = CLASS_GAUGES[gaugeSet][index];
return {
id: CLASS_GAUGE_IDS[index],
min: 0,
max: 100,
initial: 100,
border: 0,
survival: true,
// beatoraja runs its class gauges in Java `float` too; LR2's course HP is `double` (#1090).
...(gaugeSet === 'lr2' ? { values: row.values, guts: row.guts } : float32ClassGaugeRow(row)),
};
}
/** The float32 reading of each class gauge row, built once per row: the rows are constant. */
const FLOAT32_CLASS_GAUGE_ROWS = new WeakMap<ClassGaugeRow, Float32ClassGaugeRow>();
type Float32ClassGaugeRow = Pick<GaugeSpec, 'values' | 'guts'> & { float32: true };
function float32ClassGaugeRow(row: ClassGaugeRow): Float32ClassGaugeRow {
let float32 = FLOAT32_CLASS_GAUGE_ROWS.get(row);
if (float32 === undefined) {
float32 = {
values: row.values.map(Math.fround) as unknown as GaugeSpec['values'],
guts: row.guts.map((step) => ({ ...step, multiplier: Math.fround(step.multiplier) })),
float32: true,
};
FLOAT32_CLASS_GAUGE_ROWS.set(row, float32);
}
return float32;
}
/** The class-gauge set a play mode uses when the course names none (beatoraja's `BMSPlayerRule` per mode). */
export function resolveDefaultCourseGaugeSet(laneMode: string): CourseGaugeSet {
// A generic bmson keyboard plays beatoraja's KEYBOARD rule, as a single play does (#1089).
if (laneMode.endsWith(' KEY GENERIC')) return '24k';
if (laneMode.startsWith('5') || laneMode.startsWith('10')) return '5k';
if (laneMode.startsWith('9')) return '9k';
if (laneMode.startsWith('24') || laneMode.startsWith('48')) return '24k';
return '7k';
}
/**
* Maps the player's LR2-family gauge pick onto a ruleset's course gauge id.
*
* - `lr2`: grade courses play `GRADE` for GROOVE, EASY and G.ATTACK (the latter two reset at course start),
* `GRADE-HARD`, `GRADE-DEATH` or P.ATTACK. EXPERT / NONSTOP retain P.ATTACK / G.ATTACK and otherwise
* play `COURSE`, `COURSE-EASY`, `COURSE-HARD` or `COURSE-DEATH`.
* - beatoraja and That-Which-Must-Not-Be-Named: GROOVE / EASY play `CLASS`, HARD `EXCLASS`, DEATH `EXHARDCLASS` (`GrooveGauge.create`: types up
* to NORMAL → CLASS, HARD → EXCLASS, EX-HARD / HAZARD → EXHARDCLASS).
*/
export function resolveCourseGaugeId(rulesetId: RulesetId, kind: RulesetCourseKind, selectedGauge: string): string {
if (rulesetId !== 'lr2' && ['P-ATTACK', 'G-ATTACK'].includes(selectedGauge))
throw new RangeError('Attack gauges are available only for LR2.');
// plugout's course gauge follows the single-play gauge picked (`resolvePlugoutCourseGauge`).
if (rulesetId === 'plugout') return resolvePlugoutCourseGauge(resolvePlugoutGaugeId(selectedGauge), kind, 0).id;
if (rulesetId === 'lr2') {
const prefix = kind === 'grade' ? 'GRADE' : 'COURSE';
switch (selectedGauge) {
case 'P-ATTACK':
return 'P-ATTACK';
case 'G-ATTACK':
return kind === 'grade' ? 'GRADE' : 'G-ATTACK';
case 'HARD':
return `${prefix}-HARD`;
case 'DEATH':
case 'DEATH-CORRECTED':
return `${prefix}-DEATH`;
case 'EASY':
return kind === 'grade' ? 'GRADE' : 'COURSE-EASY';
default:
return prefix;
}
}
switch (selectedGauge) {
case 'HARD':
return 'EXCLASS';
case 'EX-HARD':
case 'DEATH':
case 'DEATH-CORRECTED':
return 'EXHARDCLASS';
default:
return 'CLASS';
}
}
/**
* The gauge a course stage runs on. `damage` is LR2's HARD damage multiplier for the stage's own chart; `laneMode`
* picks beatoraja's class-gauge set when the course names none. That-Which-Must-Not-Be-Named has no published class gauge, so it uses
* beatoraja's (the LR2-first policy falls back to beatoraja for what LR2 lacks).
*/
export function resolveCourseGauge(
rulesetId: RulesetId,
gaugeId: string,
course: RulesetCourseOptions,
laneMode: string,
damage: number,
noteCount = 0,
): GaugeSpec {
if (rulesetId !== 'lr2' && ['P-ATTACK', 'G-ATTACK'].includes(gaugeId))
throw new RangeError('Attack gauges are available only for LR2.');
const spec =
rulesetId === 'lr2'
? resolveLR2CourseGauge(gaugeId, damage)
: rulesetId === 'plugout'
? resolvePlugoutCourseGauge(gaugeId, course.kind, noteCount)
: resolveClassGauge(gaugeId, course.gaugeSet ?? resolveDefaultCourseGaugeSet(laneMode));
let initial = course.initialGauge;
if (initial === undefined || !Number.isFinite(initial)) return spec;
// plugout starts a grade stage at 0.01 % at least, so a stage left on lives plays its gauge again.
if (rulesetId === 'plugout' && course.kind === 'grade') initial = resolvePlugoutGradeStageStart(initial);
// Each resolver above builds a new spec, so it is set in place rather than copied.
spec.initial = Math.min(spec.max, Math.max(spec.min, initial));
return spec;
}
function collapseWindows(set: JudgeWindowSetUs, constraint: CourseJudgeConstraint): JudgeWindowSetUs {
const [pgreat, great, , bad] = set.judges;
const judges: JudgeWindowSetUs['judges'] =
constraint === 'no-great' ? [pgreat, pgreat, pgreat, bad] : [pgreat, great, great, bad];
return { ...set, judges };
}
/**
* beatoraja's `NO_GOOD` / `NO_GREAT` (`JudgeManager` L175-L184): the GOOD (and GREAT) window rate drops to 0, and
* `JudgeWindowRule.create` widens a window that ends up narrower than the one inside it back to that one. So `no-good`
* gives GOOD the GREAT window and `no-great` gives GREAT and GOOD the PGREAT window, on every table (notes, scratch and
* long-note ends alike, since `JudgeWindow` builds all four with the key rates).
*/
export function applyCourseJudgeConstraint(
tables: RulesetWindowTables,
constraint: CourseJudgeConstraint | undefined,
): RulesetWindowTables {
if (constraint === undefined) return tables;
return {
note: collapseWindows(tables.note, constraint),
scratch: collapseWindows(tables.scratch, constraint),
longNoteEnd: collapseWindows(tables.longNoteEnd, constraint),
longScratchEnd: collapseWindows(tables.longScratchEnd, constraint),
};
}
|