fix(game): preserve rule state across player turns

The rewrite reset wheel holes, top targets, collision latches, active records,
selected effects, and multiball readiness on every drain. The reconstructed
turn-state code instead saves all 175 live record states for the outgoing player
and restores the incoming player's mirror.

Add a per-player rule snapshot and save/load it at normal turn transitions.
Keep transient ball, claw, tilt, and presentation state global while retaining
each player's mechanism progress and contact/activation state across later
turns and extra balls.

Test Plan:
- `cargo test --all-targets` -- passed, 58 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:58:10 +02:00
parent 0c52100a7e
commit 64d41eb605
3 changed files with 83 additions and 7 deletions
+3
View File
@@ -10,6 +10,9 @@ and this project adheres to
### Fixed ### Fixed
- Preserve each player's complete rule-record state across turn changes instead
of globally clearing wheel holes, top targets, 176 active/contact slots,
selected effect, and multiball readiness on every drain.
- Store lock-hole and effect awards in the original per-player secondary score - Store lock-hole and effect awards in the original per-player secondary score
instead of a global bonus. The fifth hole now transfers instead of a global bonus. The fifth hole now transfers
`310000 * score_multiplier`, clears it, increments the multiplier and ball `310000 * score_multiplier`, clears it, increments the multiplier and ball
+1 -1
View File
@@ -25,7 +25,7 @@ implementation.
| Playfield collision layout | Recovered | All 109 active type-2 line objects and 40 static active type-1 circles are transcribed from the original 175-object registration table. The registration routine converts its sideways inputs with `screen = (y, x - 20)` and accumulates explicitly relative objects. Type-2 records retain every recovered Real48 normal/tangent response pair and registered one-sided orientation. Type-1 records retain their swept-circle radius, radial rebound, tangent coupling, and bumper kick. Each flipper uses its exact two line records plus moving tip circle in both positions. The upward edge transfer matches three live probes and the downstroke matches its live position-preserving `(3519,6302)` transfer; both are mirrored on the right. Object 174 is omitted because the original overwrites it with the live ball every frame. | | Playfield collision layout | Recovered | All 109 active type-2 line objects and 40 static active type-1 circles are transcribed from the original 175-object registration table. The registration routine converts its sideways inputs with `screen = (y, x - 20)` and accumulates explicitly relative objects. Type-2 records retain every recovered Real48 normal/tangent response pair and registered one-sided orientation. Type-1 records retain their swept-circle radius, radial rebound, tangent coupling, and bumper kick. Each flipper uses its exact two line records plus moving tip circle in both positions. The upward edge transfer matches three live probes and the downstroke matches its live position-preserving `(3519,6302)` transfer; both are mirrored on the right. Object 174 is omitted because the original overwrites it with the live ball every frame. |
| Ball launcher and nudge input | Recovered | The initial 32-bit fixed-point coordinates decode to `(325, 413)` in the right shooter lane. The port reproduces the initial `-375` millipixel Down event, 650 ms repeat delay, 40 ms repeats, release impulse, and randomized clamp below the original `-3800` maximum. Left Shift and keypad 3 apply their directional `(50-Random(20))*15` impulses; Space uses the recovered Real48 horizontal factor and `(60-Random(20))*15` vertical impulse. Each nudge adds 25 to the wrapping 16-bit tilt counter, compares it with `30+Random(10)`, and the detail timer decrements a nonzero counter once per callback. | | Ball launcher and nudge input | Recovered | The initial 32-bit fixed-point coordinates decode to `(325, 413)` in the right shooter lane. The port reproduces the initial `-375` millipixel Down event, 650 ms repeat delay, 40 ms repeats, release impulse, and randomized clamp below the original `-3800` maximum. Left Shift and keypad 3 apply their directional `(50-Random(20))*15` impulses; Space uses the recovered Real48 horizontal factor and `(60-Random(20))*15` vertical impulse. Each nudge adds 25 to the wrapping 16-bit tilt counter, compares it with `30+Random(10)`, and the detail timer decrements a nonzero counter once per callback. |
| Physics arithmetic | Recovered gameplay behavior | Production movement uses the original 10 ms millipixel substep, `+15` vertical acceleration, `3800` speed bound, point-path type-2 intersection, one-sided line response, swept type-1 circle response, and swept non-physical sensor contacts. It evaluates all records and applies the earliest contact along the substep. The original Borland seed update and high-word `Random(n)` mapping drive launcher variation, effects, claw terminals, and the recovered randomized magnetic-field impulse. Live probes cover ordinary rails, ordinary circles, a kicked bumper, lock holes, magnetic fields, all claw exits, and both flipper directions. Rust represents the original per-ball contact words as path-entry/inside latches; this is a source-structure difference rather than a missing collision route. | | Physics arithmetic | Recovered gameplay behavior | Production movement uses the original 10 ms millipixel substep, `+15` vertical acceleration, `3800` speed bound, point-path type-2 intersection, one-sided line response, swept type-1 circle response, and swept non-physical sensor contacts. It evaluates all records and applies the earliest contact along the substep. The original Borland seed update and high-word `Random(n)` mapping drive launcher variation, effects, claw terminals, and the recovered randomized magnetic-field impulse. Live probes cover ordinary rails, ordinary circles, a kicked bumper, lock holes, magnetic fields, all claw exits, and both flipper directions. Rust represents the original per-ball contact words as path-entry/inside latches; this is a source-structure difference rather than a missing collision route. |
| Rules | Recovered gameplay paths | Player count, controls, the five three-line bumper-value groups, four three-line TDK-diamond groups, five doubling-value lock holes, wheel-reset target, seven-way effect selector/consumer including multiball, permanent double scoring, and four exact media/extra-ball thresholds follow original help/code paths, globals, and object flags. The ninth diamond pays the original 24,464 completion value; the following completed bank enables double scoring, and later completions add 100,000 to the per-player secondary score. Claw contact and all initially active type-4 targets use recovered records. The top three targets score 500 each and independently enable the left, center, or right magnetic field record; each field pulls the ball upward until it exits and then deactivates. The claw state machine and release table have live differential coverage for all four random terminals. Remaining timing uncertainty is presentation batching at non-default detail settings, not gameplay routing. | | Rules | Recovered gameplay paths | Player count, controls, the five three-line bumper-value groups, four three-line TDK-diamond groups, five doubling-value lock holes, wheel-reset target, seven-way effect selector/consumer including multiball, permanent double scoring, and four exact media/extra-ball thresholds follow original help/code paths, globals, and object flags. The ninth diamond pays the original 24,464 completion value; the following completed bank enables double scoring, and later completions add 100,000 to the per-player secondary score. Turn changes mirror the original save/load of all 175 collision record states: wheel/top targets, active/contact slots, selected effect, and multiball readiness remain attached to their player. Claw contact and all initially active type-4 targets use recovered records. The top three targets score 500 each and independently enable the left, center, or right magnetic field record; each field pulls the ball upward until it exits and then deactivates. The claw state machine and release table have live differential coverage for all four random terminals. Remaining timing uncertainty is presentation batching at non-default detail settings, not gameplay routing. |
| Numeric scoring | Recovered gameplay values | Static scores come from the initialized 175-object ledger. Dynamic bumper progression, target-bank completion, diamond awards, 10k-160k lock bonuses, 310k transfer, six effect values, multiball mode, and all four media thresholds are transcribed from `1000:b476`, `1000:c4e1`, `1000:bc36`, and live state probes. Lock and effect awards share the original per-player secondary score and display multiplier; the fifth hole transfers and clears it, increments the multiplier, and grants the recovered ball award. Score mutation uses the original 32-bit wrapping behavior, and each add operation can advance at most one media threshold. | | Numeric scoring | Recovered gameplay values | Static scores come from the initialized 175-object ledger. Dynamic bumper progression, target-bank completion, diamond awards, 10k-160k lock bonuses, 310k transfer, six effect values, multiball mode, and all four media thresholds are transcribed from `1000:b476`, `1000:c4e1`, `1000:bc36`, and live state probes. Lock and effect awards share the original per-player secondary score and display multiplier; the fifth hole transfers and clears it, increments the multiplier, and grants the recovered ball award. Score mutation uses the original 32-bit wrapping behavior, and each add operation can advance at most one media threshold. |
| High scores | Compatible import | The original 276-byte table is decoded as ten `IWIK`-XOR-obfuscated little-endian scores plus ten 22-byte names, sorted, then migrated to portable JSON. | | High scores | Compatible import | The original 276-byte table is decoded as ten `IWIK`-XOR-obfuscated little-endian scores plus ten 22-byte names, sorted, then migrated to portable JSON. |
| Configuration | Behaviorally compatible | Sound, language, and five detail levels are retained. Storage moves from a local Win16 INI file to the platform user-data directory. | | Configuration | Behaviorally compatible | Sound, language, and five detail levels are retained. Storage moves from a local Win16 INI file to the platform user-data directory. |
+79 -6
View File
@@ -162,6 +162,7 @@ pub struct Player {
pub diamond_segments: u8, pub diamond_segments: u8,
pub double_score: bool, pub double_score: bool,
pub media_level: u8, pub media_level: u8,
rules: RuleState,
} }
impl Default for Player { impl Default for Player {
@@ -176,6 +177,7 @@ impl Default for Player {
diamond_segments: 0, diamond_segments: 0,
double_score: false, double_score: false,
media_level: 0, media_level: 0,
rules: RuleState::default(),
} }
} }
} }
@@ -200,6 +202,29 @@ enum MultiballState {
Ready, Ready,
} }
#[derive(Clone, Copy, Debug)]
struct RuleState {
wheel_holes: [bool; 5],
top_targets: [bool; 3],
trigger_contacts: [bool; 176],
object_active: [bool; 176],
target_effect: u8,
multiball_state: MultiballState,
}
impl Default for RuleState {
fn default() -> Self {
Self {
wheel_holes: [false; 5],
top_targets: [false; 3],
trigger_contacts: [false; 176],
object_active: initial_object_activity(),
target_effect: 0,
multiball_state: MultiballState::Unavailable,
}
}
}
fn initial_object_activity() -> [bool; 176] { fn initial_object_activity() -> [bool; 176] {
let mut active = [true; 176]; let mut active = [true; 176];
active[0] = false; active[0] = false;
@@ -1165,20 +1190,15 @@ impl Game {
} else { } else {
player.balls = player.balls.saturating_sub(1); player.balls = player.balls.saturating_sub(1);
} }
self.save_current_rule_state();
events.push(Event::Drain); events.push(Event::Drain);
events.push(Event::Sound(2008)); events.push(Event::Sound(2008));
self.top_targets.fill(false);
self.wheel_holes.fill(false);
self.tilted = false; self.tilted = false;
self.tilt_counter = 0; self.tilt_counter = 0;
self.tilt_counter_accumulator = 0.0; self.tilt_counter_accumulator = 0.0;
self.bumper_flash.fill(0.0); self.bumper_flash.fill(0.0);
self.wheel_animation = 0.0; self.wheel_animation = 0.0;
self.claw = Claw::default(); self.claw = Claw::default();
self.trigger_contacts.fill(false);
self.object_active = initial_object_activity();
self.target_effect = 0;
self.multiball_state = MultiballState::Unavailable;
self.secondary_ball = None; self.secondary_ball = None;
self.nudge_shake = 0.0; self.nudge_shake = 0.0;
self.launcher_charge = 0.0; self.launcher_charge = 0.0;
@@ -1191,6 +1211,7 @@ impl Game {
for _ in 0..self.players.len() { for _ in 0..self.players.len() {
if self.players[next].balls > 0 || self.players[next].extra_balls > 0 { if self.players[next].balls > 0 || self.players[next].extra_balls > 0 {
self.current_player = next; self.current_player = next;
self.load_current_rule_state();
self.ball = Ball::default(); self.ball = Ball::default();
return; return;
} }
@@ -1199,6 +1220,27 @@ impl Game {
self.finished = true; self.finished = true;
} }
fn save_current_rule_state(&mut self) {
self.players[self.current_player].rules = RuleState {
wheel_holes: self.wheel_holes,
top_targets: self.top_targets,
trigger_contacts: self.trigger_contacts,
object_active: self.object_active,
target_effect: self.target_effect,
multiball_state: self.multiball_state,
};
}
fn load_current_rule_state(&mut self) {
let state = self.players[self.current_player].rules;
self.wheel_holes = state.wheel_holes;
self.top_targets = state.top_targets;
self.trigger_contacts = state.trigger_contacts;
self.object_active = state.object_active;
self.target_effect = state.target_effect;
self.multiball_state = state.multiball_state;
}
fn live_wall_segment(&self, object_id: u8, resting: Segment) -> Segment { fn live_wall_segment(&self, object_id: u8, resting: Segment) -> Segment {
let (start, end) = match object_id { let (start, end) = match object_id {
66 if self.flippers.left_raised => (vec2(98.0, 382.0), vec2(131.0, 369.0)), 66 if self.flippers.left_raised => (vec2(98.0, 382.0), vec2(131.0, 369.0)),
@@ -1561,6 +1603,37 @@ mod tests {
assert!(game.ball.in_launcher); assert!(game.ball.in_launcher);
} }
#[test]
fn player_turns_save_and_restore_all_rule_record_state() {
let mut game = Game::new(2);
game.wheel_holes[2] = true;
game.top_targets[1] = true;
game.trigger_contacts[149] = true;
game.object_active[90] = false;
game.target_effect = 3;
game.multiball_state = MultiballState::Ready;
game.drain(&mut Vec::new());
assert_eq!(game.current_player, 1);
assert_eq!(game.wheel_holes, [false; 5]);
assert_eq!(game.top_targets, [false; 3]);
assert!(!game.trigger_contacts[149]);
assert!(game.object_active[90]);
assert_eq!(game.target_effect, 0);
assert_eq!(game.multiball_state, MultiballState::Unavailable);
game.wheel_holes[4] = true;
game.drain(&mut Vec::new());
assert_eq!(game.current_player, 0);
assert!(game.wheel_holes[2]);
assert!(!game.wheel_holes[4]);
assert!(game.top_targets[1]);
assert!(game.trigger_contacts[149]);
assert!(!game.object_active[90]);
assert_eq!(game.target_effect, 3);
assert_eq!(game.multiball_state, MultiballState::Ready);
}
#[test] #[test]
fn fast_ball_cannot_tunnel_through_the_top_rail() { fn fast_ball_cannot_tunnel_through_the_top_rail() {
let mut game = Game::new(1); let mut game = Game::new(1);