fix(physics): preserve first-candidate scan semantics

Carry predicted position separately through exact record-ID chunks, apply magnetic rewrites only at records 6/153/154, and honor type-three/dynamic broadphase. Match raw 1000:c79c by resolving fixed candidate slot one rather than a later nearer record, and restore related capture-age, tilt, and stacked multiball scoring side effects.

Test Plan:
- bash original/tools/test_reconstructed_c.sh
- python3 original/tools/audit_reconstruction.py --require-complete
- cargo test --all-targets
- cargo clippy --all-targets --all-features -- -D warnings
- rumdl check original/C_RECONSTRUCTION_FINAL_AUDIT.md original/MECHANICS_PROGRESS.md tdkpin-rs/CHANGELOG.md tdkpin-rs/RECONSTRUCTION.md tdkpin-rs/README.md
- git diff --check
This commit is contained in:
2026-08-23 18:50:20 +02:00
parent f8dcceda5e
commit 2936c69c5c
3 changed files with 90 additions and 3 deletions
+4
View File
@@ -10,6 +10,10 @@ and this project adheres to
### Fixed
- Match central score/event side effects: every stored collision candidate
clears its ball slot's capture age, Tilt suppresses all score and rule-record
mutations, and active multiball doubles points before permanent Double can
double them again.
- Scan static, capture, trigger, magnetic, and dynamic record ranges in exact
ID order with a separately tracked prediction. Preserve the raw scanner's
first-detected-candidate quirk even when a later record is geometrically
+1 -1
View File
@@ -26,7 +26,7 @@ implementation.
| Ball launcher and nudge input | Recovered | The initial 32-bit fixed-point coordinates decode to `(325, 413)` in the right shooter lane. Each Down keydown subtracts `15*50 = 750` millipixels, release subtracts another `15*100 = 1500`, and the result follows the recovered randomized `-3800` lower and `-2280` weak upper clamp branches. The ten decoration frames use the same strict 750-millipixel thresholds. 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. With two balls, the key path still consumes those active-window draws, then applies its separately recovered fixed/shared random slot impulse to both saved velocities. 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 Real48 core | Production movement uses the original 10 ms millipixel substep, `+15` vertical acceleration, Real48 `3800/speed` clamp, type-2 distance/cross gates, type-1 midpoint normal, first-detected candidate selection, persistent Real48 spin, and the common impulse response. The scan follows record chunks 1-5, 6, 7-88, 89, 90-128, 129-133, 134-139, 140-152, 153-154, 155-173, and dynamic 174/175 while carrying prediction separately from mutable motion. Negative auxiliary thresholds and kick coefficients are retained for bumpers 51-53 and lines 55/74/107, including weak-hit score behavior, unscored-rail WAVE 2019, and tilt suppression. Type-3 reads the pre-movement coordinate for pull/hold, obeys its prediction broadphase, and contributes its recovered radial rim candidate when a nonzero contact is outside the deep zone. Type-4 randomization mutates motion before the selected candidate is resolved and before position publication; only rectangular magnetic records rewrite prediction. Detail callbacks freeze their starting ball count, run all 5/4/3/2/1 substeps for slot 1 before slot 2, stop a slot after its first collision/reset/removal, and apply effect-seven spawn requests after the current batch. Dynamic records 174/175 use their 21-pixel prediction bounds, transfer normal impulse to the other ball, then apply `normal_velocity-1000` to the moving ball; effect seven spawns record/slot 2 from record 148 coordinates `(17000,23000)` with exact `(0,3040)` velocity. Both slots traverse the same type-3/type-4 dispatcher. Capture age is saved per slot, contact words retain ball ownership, a completed multiball capture removes exactly that slot and promotes the survivor when needed, and effect seven's argument-2 guard prevents a third ball. The original Borland seed update, high-word `Random(n)`, and normalized Real48 random register result drive launcher variation, effects, claw terminals, magnetic fields, and trigger response. Type-4 triggers retain a shared transient entry flag; type-3 captures retain per-player 16-bit contact words, deep-inside pull/hold progression to age 300, first-contact sound, and `99`/`2` completion sentinels. Zero-spin C harnesses and retained-spin Wine probes are tested separately rather than conflated. |
| 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. Bumpers 51-53 and targets 140-147/150-152 use the original 5/20/10 active-callback countdowns and exact overlay-A render rectangles. Record 121 runs the six-callback DAT600 target rotation with exact 91x90 frames/target points and rotates the five contact/item values at state 6. Completing all five lock holes suspends physics for the full 281-callback panel animation, clears contact/item state at the recovered boundaries, and uses the exact WAVE 2013/2012/stop sequence. 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 rectangular field requires the previous position inside, applies its Real48/random pull, and deactivates when raw `1000:9b69` finds the resulting `07db/07df` prediction outside any edge. The claw state machine and release table have live differential coverage for all four random terminals. |
| 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. The central helper suppresses all mutation during Tilt, applies a 2x active-multiball factor, and then independently applies the permanent 2x factor, allowing the original 4x stack. 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 | Recovered visible flow; portable storage | The original 276-byte table is decoded as ten `IWIK`-XOR-obfuscated little-endian scores plus ten 22-byte names. Each player is checked immediately when their own last ball is lost; qualifying scores use the original signed-high/unsigned-low comparison and a `TDK Pinball Player`-prefilled name screen before the table is shown and play resumes. Persisted updates use portable JSON rather than rewriting the Win16 file. |
| 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. |
| Windows UI shell | Original gameplay surface with native host shell | Win16 window ownership and GDI calls are replaced by a fixed native window, but the visible game, idle table, help resources, automatic per-player high-score flow, original keys, and 640x460 logical pixels are retained. F2/F3 remain unassigned as in normal original operation; optional portable settings and table viewers use F10/F9 and do not replace gameplay input. |
+85 -2
View File
@@ -207,6 +207,13 @@ enum MultiballState {
Ready,
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
enum ScoreMode {
#[default]
Normal,
Multiball,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
enum CaptureStep {
Outside,
@@ -314,6 +321,7 @@ pub struct Game {
target_effect: u8,
claw_frame_seconds: f32,
multiball_state: MultiballState,
score_mode: ScoreMode,
}
impl Game {
@@ -355,6 +363,7 @@ impl Game {
target_effect: 0,
claw_frame_seconds: CLAW_FRAME_SECONDS,
multiball_state: MultiballState::Unavailable,
score_mode: ScoreMode::Normal,
}
}
@@ -481,6 +490,9 @@ impl Game {
let panel_active = self.update_panel_completion(events);
if !self.claw.ball_suspended && !panel_active {
let had_secondary_ball = self.secondary_ball.is_some();
if had_secondary_ball {
self.score_mode = ScoreMode::Multiball;
}
for _ in 0..substeps {
if self.fixed_update(STEP_SECONDS, events)
|| self.finished
@@ -489,6 +501,9 @@ impl Game {
break;
}
}
if had_secondary_ball && self.secondary_ball.is_none() {
self.score_mode = ScoreMode::Normal;
}
if had_secondary_ball && !self.finished && !self.claw.ball_suspended {
if self.secondary_ball.is_some() {
for _ in 0..substeps {
@@ -728,6 +743,9 @@ impl Game {
}
}
let collided = best_collision.is_some();
if collided {
ball.capture_age = 0;
}
let mut auxiliary_fired = false;
let (hit_wall, hit_circle) = if let Some((object_id, is_wall, response)) = best_collision {
velocity = response.velocity;
@@ -1132,6 +1150,9 @@ impl Game {
}
let mut hit = None;
let collided = best_collision.is_some();
if collided {
ball.capture_age = 0;
}
let mut auxiliary_fired = false;
if let Some((object_id, is_wall, response)) = best_collision {
velocity = response.velocity;
@@ -1149,6 +1170,7 @@ impl Game {
ball.position = old_position.add(velocity).to_position();
ball.velocity = velocity.to_velocity_per_second();
if hit == Some((2, true)) || ball.position.y > 470.0 {
self.score_mode = ScoreMode::Normal;
events.push(Event::Drain);
return true;
}
@@ -1180,11 +1202,14 @@ impl Game {
}
fn apply_wall_rule(&mut self, object_id: u8, events: &mut Vec<Event>) {
if self.tilted {
return;
}
let wall = WALLS
.iter()
.find(|wall| wall.id == object_id)
.expect("a wall collision id must reference a recovered wall");
if !self.tilted && wall.score != 0 {
if wall.score != 0 {
self.add_score(wall.score, events);
events.push(if object_id == 121 {
Event::Wheel
@@ -1643,6 +1668,7 @@ impl Game {
capture_age: 0,
});
self.multiball_state = MultiballState::Unavailable;
self.score_mode = ScoreMode::Multiball;
}
_ => {}
}
@@ -1875,11 +1901,16 @@ impl Game {
fn add_score(&mut self, points: u32, events: &mut Vec<Event>) {
const THRESHOLDS: [u32; 4] = [140_000, 650_000, 1_300_000, 4_000_000];
let multiplier = if self.player().double_score {
if self.tilted {
return;
}
let multiball_multiplier = if self.score_mode == ScoreMode::Multiball {
2
} else {
1
};
let permanent_multiplier = if self.player().double_score { 2 } else { 1 };
let multiplier = multiball_multiplier * permanent_multiplier;
let player = &mut self.players[self.current_player];
player.score = player.score.wrapping_add(points.wrapping_mul(multiplier));
let level = usize::from(player.media_level);
@@ -1895,6 +1926,7 @@ impl Game {
fn drain(&mut self, events: &mut Vec<Event>) {
if let Some(remaining_ball) = self.secondary_ball.take() {
self.ball = remaining_ball;
self.score_mode = ScoreMode::Normal;
events.push(Event::Drain);
return;
}
@@ -1921,6 +1953,7 @@ impl Game {
self.flippers = Flippers::default();
self.pending_flipper_edges.fill(0);
self.secondary_ball = None;
self.score_mode = ScoreMode::Normal;
self.nudge_shake = 0.0;
self.launcher_charge = 0.0;
self.launcher_was_down = false;
@@ -2357,6 +2390,39 @@ mod tests {
assert_eq!(game.player().secondary_score, 100_000);
}
#[test]
fn score_helper_stacks_multiball_and_permanent_double_and_honors_tilt() {
let mut game = Game::new(1);
let mut events = Vec::new();
game.score_mode = ScoreMode::Multiball;
game.add_score(100, &mut events);
assert_eq!(game.player().score, 200);
game.players[0].double_score = true;
game.add_score(100, &mut events);
assert_eq!(game.player().score, 600);
game.tilted = true;
game.add_score(100, &mut events);
assert_eq!(game.player().score, 600);
}
#[test]
fn tilted_collision_dispatch_leaves_rule_records_unchanged() {
let mut game = Game::new(1);
game.tilted = true;
let mut events = Vec::new();
game.apply_wall_rule(90, &mut events);
game.apply_wall_rule(84, &mut events);
assert!(game.object_active[90]);
assert_eq!(game.target_effect, 0);
assert!(!game.effect_target_active());
assert_eq!(game.player().score, 0);
assert!(events.is_empty());
}
#[test]
fn recovered_target_banks_deactivate_and_rearm_their_line_groups() {
let mut game = Game::new(1);
@@ -2687,6 +2753,23 @@ mod tests {
assert!(game.ball.velocity.y > 0.0);
}
#[test]
fn retained_collision_candidate_clears_the_slot_capture_age() {
let mut game = Game::new(1);
game.ball.in_launcher = false;
game.ball.position = vec2(270.0, 30.0);
game.ball.velocity = vec2(0.0, -380.0);
game.ball.capture_age = 42;
for _ in 0..5 {
if game.fixed_update(STEP_SECONDS, &mut Vec::new()) {
break;
}
}
assert_eq!(game.ball.capture_age, 0);
}
#[test]
fn collision_scan_selects_the_layer_from_the_previous_y_position() {
let mut game = Game::new(1);