fix(game): restore per-player secondary scoring

Replace the global bonus approximation with the original per-player secondary
score and multiplier. Lock holes now accumulate 10k, 20k, 40k, 80k, and 160k;
the fifth transfer applies the current multiplier, clears the secondary score,
increments that multiplier, and grants the recovered extra-ball count.

Route effects 1 through 5 into the same secondary score and make effect 6
transfer its displayed multiplied value before clearing it. Render that value
on the table and stop adding an unrelated global bonus during drain, preserving
secondary progress across balls as the original player state does.

Test Plan:
- `cargo test --all-targets` -- passed, 57 tests
- `cargo clippy --all-targets -- -D warnings` -- passed
- `rumdl check tdkpin-rs/CHANGELOG.md tdkpin-rs/RECONSTRUCTION.md` -- passed
- `git diff --cached --check` -- passed
This commit is contained in:
2026-08-23 16:56:59 +02:00
parent aae4671586
commit 0c52100a7e
4 changed files with 41 additions and 25 deletions
+1 -1
View File
@@ -543,7 +543,7 @@ impl App {
},
);
}
self.draw_right_aligned_digits(&game.bonus.to_string(), 605.0, 233.0);
self.draw_right_aligned_digits(&game.secondary_score_display().to_string(), 605.0, 233.0);
let media_level = game.player().media_level;
if media_level > 0 {
+34 -23
View File
@@ -155,6 +155,7 @@ impl Claw {
pub struct Player {
pub score: u32,
pub secondary_score: u32,
pub score_multiplier: u8,
pub balls: u8,
pub extra_balls: u8,
pub bumper_value: u32,
@@ -168,6 +169,7 @@ impl Default for Player {
Self {
score: 0,
secondary_score: 0,
score_multiplier: 1,
balls: 3,
extra_balls: 0,
bumper_value: 1_000,
@@ -223,7 +225,6 @@ pub struct Game {
pub current_player: usize,
pub ball: Ball,
pub secondary_ball: Option<Ball>,
pub bonus: u32,
pub wheel_holes: [bool; 5],
pub top_targets: [bool; 3],
pub tilted: bool,
@@ -264,7 +265,6 @@ impl Game {
current_player: 0,
ball: Ball::default(),
secondary_ball: None,
bonus: 0,
wheel_holes: [false; 5],
top_targets: [false; 3],
tilted: false,
@@ -299,6 +299,12 @@ impl Game {
&self.players[self.current_player]
}
pub fn secondary_score_display(&self) -> u32 {
self.player()
.secondary_score
.wrapping_mul(u32::from(self.player().score_multiplier))
}
pub fn launcher_frame(&self) -> usize {
LAUNCHER_FRAME_THRESHOLDS.partition_point(|threshold| self.launcher_charge >= *threshold)
}
@@ -569,7 +575,6 @@ impl Game {
&& self.bumper_cooldown <= 0.0
{
self.add_score(self.player().bumper_value, events);
self.bonus = self.bonus.saturating_add(100);
self.bumper_cooldown = 0.08;
self.bumper_flash[index] = 0.16;
events.push(Event::Bumper);
@@ -671,7 +676,6 @@ impl Game {
&& self.bumper_cooldown <= 0.0
{
self.add_score(self.player().bumper_value, events);
self.bonus = self.bonus.saturating_add(100);
self.bumper_cooldown = 0.08;
self.bumper_flash[index] = 0.16;
events.push(Event::Bumper);
@@ -832,12 +836,16 @@ impl Game {
}
let filled_before = self.wheel_holes.iter().filter(|filled| **filled).count();
self.wheel_holes[index] = true;
self.bonus = self
.bonus
.saturating_add(10_000_u32 << u32::try_from(filled_before).unwrap_or_default());
let award = 10_000_u32 << u32::try_from(filled_before).unwrap_or_default();
let player = &mut self.players[self.current_player];
player.secondary_score = player.secondary_score.wrapping_add(award);
if self.wheel_holes.iter().all(|filled| *filled) {
self.add_score(self.bonus, events);
self.bonus = 0;
let transfer = self.secondary_score_display();
self.add_score(transfer, events);
let player = &mut self.players[self.current_player];
player.secondary_score = 0;
player.score_multiplier = player.score_multiplier.wrapping_add(1);
player.extra_balls = player.extra_balls.wrapping_add(1);
}
self.reset_ball_to_launcher();
events.push(Event::Lock);
@@ -905,14 +913,16 @@ impl Game {
if entered && !self.tilted {
self.add_score(EFFECT_SENSOR.score, events);
match self.target_effect {
1 => self.bonus = self.bonus.saturating_add(10_000),
2 => self.bonus = self.bonus.saturating_add(20_000),
3 => self.bonus = self.bonus.saturating_add(50_000),
4 => self.bonus = self.bonus.saturating_add(100_000),
5 => self.bonus = self.bonus.saturating_add(200_000),
1..=5 => {
const ADDITIONS: [u32; 5] = [10_000, 20_000, 50_000, 100_000, 200_000];
let addition = ADDITIONS[usize::from(self.target_effect - 1)];
let player = &mut self.players[self.current_player];
player.secondary_score = player.secondary_score.wrapping_add(addition);
}
6 => {
self.add_score(self.bonus, events);
self.bonus = 0;
let transfer = self.secondary_score_display();
self.add_score(transfer, events);
self.players[self.current_player].secondary_score = 0;
}
7 => {
self.secondary_ball = Some(Ball {
@@ -1150,7 +1160,6 @@ impl Game {
return;
}
let player = &mut self.players[self.current_player];
player.score = player.score.saturating_add(self.bonus);
if player.extra_balls > 0 {
player.extra_balls -= 1;
} else {
@@ -1158,7 +1167,6 @@ impl Game {
}
events.push(Event::Drain);
events.push(Event::Sound(2008));
self.bonus = 0;
self.top_targets.fill(false);
self.wheel_holes.fill(false);
self.tilted = false;
@@ -1466,7 +1474,8 @@ mod tests {
&mut events,
);
assert_eq!(game.bonus, 50_000);
assert_eq!(game.player().secondary_score, 50_000);
assert_eq!(game.secondary_score_display(), 50_000);
assert_eq!(game.player().score, 2_000);
assert_eq!(game.target_effect, 0);
assert!(!game.effect_target_active());
@@ -1571,7 +1580,7 @@ mod tests {
fn tilt_latches_and_disables_flippers_and_scoring() {
let mut game = Game::new_with_seed(1, 7);
assert!(launch_ball(&mut game, 1).contains(&Event::Launch));
game.bonus = 4_000;
game.players[0].secondary_score = 4_000;
for _ in 0..2 {
game.update(
0.0,
@@ -1583,7 +1592,7 @@ mod tests {
);
}
assert!(game.tilted);
assert_eq!(game.bonus, 4_000);
assert_eq!(game.player().secondary_score, 4_000);
game.flippers.left_raised = true;
game.flippers.right_raised = true;
@@ -1998,7 +2007,7 @@ mod tests {
}
#[test]
fn wheel_holes_double_bonus_then_transfer_all_310k() {
fn wheel_holes_accumulate_and_transfer_the_per_player_secondary_score() {
let mut game = Game::new(1);
game.ball.in_launcher = false;
let mut events = Vec::new();
@@ -2011,10 +2020,12 @@ mod tests {
MilliVec::default(),
&mut events,
);
assert_eq!(game.bonus, expected_bonus[index]);
assert_eq!(game.player().secondary_score, expected_bonus[index]);
assert!(game.ball.in_launcher);
}
assert_eq!(game.player().score, 310_000);
assert_eq!(game.player().score_multiplier, 2);
assert_eq!(game.player().extra_balls, 2);
assert!(game.wheel_holes.iter().all(|filled| *filled));
assert_eq!(
events.iter().filter(|event| **event == Event::Lock).count(),