fix(physics): restore type-three contact state
Replace the shared boolean sensor latch with the two distinct states used by the binary: per-player 16-bit contact words for type-three records and transient entry flags for type-four triggers. Only active/contact record state is mirrored across player turns, matching the original save/load loop. Port the type-three deep-inside threshold, velocity damping and 150-millipixel pull, stationary gate, first-contact sound and ball-number publication, shared capture age in five-unit steps, and the 99/2 completion sentinels. Lock holes and the reset pocket now complete after the recovered hold interval; the claw publishes its sound on contact and starts on the following completed state. Test Plan: - `cargo test --all-targets` -- passed, 63 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:
@@ -10,6 +10,10 @@ and this project adheres to
|
||||
|
||||
### Fixed
|
||||
|
||||
- Split collision contact state into per-player 16-bit type-3 contact words and
|
||||
transient type-4 entry flags. Type-3 records now use the original deep-inside
|
||||
gate, `v*0.9 +/-150` pull, stationary sound/contact publication, 5-step age
|
||||
progression to 300, and `99`/`2` completion sentinels.
|
||||
- Replace the live-fitted flipper transfer polynomials with the reconstructed
|
||||
`1000:7ed9` millipixel geometry gates, penetration, gain, response-record,
|
||||
velocity, and position calculations for both directions and both balls.
|
||||
|
||||
@@ -24,7 +24,7 @@ implementation.
|
||||
| Help and languages | Exact | Original resource images 1001-1005 are displayed directly. |
|
||||
| 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. Moving-flipper contact ports `1000:7ed9` rather than fitting live samples: delta-specific pivots/edges, integer cross gates, radial/penetration calculations, response-record gain, and position/velocity publication are tested against all four C harness directions and the raised release geometry. Object 174 is overwritten with the live first ball and Rust handles its ball-to-ball role directly. |
|
||||
| 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. 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. Radius-bearing type-4 triggers independently scale X and Y by `1.03-Random*0.08` after their event path. 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. Radius-bearing type-4 triggers retain a separate transient entry flag and independently scale X and Y by `1.03-Random*0.08`. Type-3 capture records retain their per-player 16-bit contact word, deep-inside threshold, pull/hold progression to age 300, first-contact sound, and `99`/`2` completion sentinels. Live probes cover ordinary rails, ordinary circles, a kicked bumper, lock holes, magnetic fields, all claw exits, and both flipper directions. |
|
||||
| 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. |
|
||||
| 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. |
|
||||
|
||||
+244
-80
@@ -199,11 +199,18 @@ enum MultiballState {
|
||||
Ready,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
enum CaptureStep {
|
||||
Outside,
|
||||
Holding,
|
||||
Complete,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
struct RuleState {
|
||||
wheel_holes: [bool; 5],
|
||||
top_targets: [bool; 3],
|
||||
trigger_contacts: [bool; 176],
|
||||
record_contacts: [u16; 176],
|
||||
object_active: [bool; 176],
|
||||
target_effect: u8,
|
||||
multiball_state: MultiballState,
|
||||
@@ -214,7 +221,7 @@ impl Default for RuleState {
|
||||
Self {
|
||||
wheel_holes: [false; 5],
|
||||
top_targets: [false; 3],
|
||||
trigger_contacts: [false; 176],
|
||||
record_contacts: [0; 176],
|
||||
object_active: initial_object_activity(),
|
||||
target_effect: 0,
|
||||
multiball_state: MultiballState::Unavailable,
|
||||
@@ -269,11 +276,13 @@ pub struct Game {
|
||||
player_entry: PlayerEntry,
|
||||
random: BorlandRandom,
|
||||
pending_flipper_edges: [i8; 2],
|
||||
trigger_contacts: [bool; 176],
|
||||
record_contacts: [u16; 176],
|
||||
trigger_flags: [bool; 176],
|
||||
object_active: [bool; 176],
|
||||
target_effect: u8,
|
||||
claw_frame_seconds: f32,
|
||||
multiball_state: MultiballState,
|
||||
capture_age: i32,
|
||||
}
|
||||
|
||||
impl Game {
|
||||
@@ -309,11 +318,13 @@ impl Game {
|
||||
player_entry: PlayerEntry::Open,
|
||||
random: BorlandRandom::new(seed),
|
||||
pending_flipper_edges: [0; 2],
|
||||
trigger_contacts: [false; 176],
|
||||
record_contacts: [0; 176],
|
||||
trigger_flags: [false; 176],
|
||||
object_active: initial_object_activity(),
|
||||
target_effect: 0,
|
||||
claw_frame_seconds: CLAW_FRAME_SECONDS,
|
||||
multiball_state: MultiballState::Unavailable,
|
||||
capture_age: 0,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -823,22 +834,27 @@ impl Game {
|
||||
movement_velocity: MilliVec,
|
||||
events: &mut Vec<Event>,
|
||||
) {
|
||||
if !self.claw.active
|
||||
&& path_intersects_circle(
|
||||
old_position,
|
||||
movement_velocity,
|
||||
if !self.claw.active {
|
||||
match self.capture_record_step(
|
||||
89,
|
||||
CLAW_TRIGGER_CENTER,
|
||||
CLAW_TRIGGER_RADIUS,
|
||||
)
|
||||
{
|
||||
let terminal_frame = self.next_claw_terminal_frame();
|
||||
self.begin_claw_capture(terminal_frame, events);
|
||||
return;
|
||||
old_position,
|
||||
events,
|
||||
) {
|
||||
CaptureStep::Holding => return,
|
||||
CaptureStep::Complete => {
|
||||
let terminal_frame = self.next_claw_terminal_frame();
|
||||
self.begin_claw_capture_after_hold(terminal_frame, events);
|
||||
return;
|
||||
}
|
||||
CaptureStep::Outside => {}
|
||||
}
|
||||
}
|
||||
|
||||
let current_position = MilliVec::from_position(self.ball.position);
|
||||
if self.check_lock_holes(old_position, current_position, movement_velocity, events)
|
||||
|| self.check_wheel_reset(old_position, current_position, movement_velocity, events)
|
||||
if self.check_lock_holes(old_position, events)
|
||||
|| self.check_wheel_reset(old_position, events)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -846,31 +862,94 @@ impl Game {
|
||||
self.check_target_sensors(old_position, current_position, movement_velocity, events);
|
||||
}
|
||||
|
||||
#[allow(clippy::cast_possible_truncation)]
|
||||
fn capture_record_step(
|
||||
&mut self,
|
||||
record_id: u8,
|
||||
center: Vec2,
|
||||
radius: f32,
|
||||
previous_position: MilliVec,
|
||||
events: &mut Vec<Event>,
|
||||
) -> CaptureStep {
|
||||
let current_position = MilliVec::from_position(self.ball.position);
|
||||
let center = MilliVec::from_position(center);
|
||||
let radius = (radius * 1_000.0).round() as i32;
|
||||
let dx = center.x.wrapping_sub(current_position.x);
|
||||
let dy = center
|
||||
.y
|
||||
.wrapping_sub(current_position.y)
|
||||
.wrapping_sub(2_000);
|
||||
let surface_distance = (f64::from(dx).hypot(f64::from(dy))).round() as i32 - radius;
|
||||
let contact_index = usize::from(record_id);
|
||||
let contact = self.record_contacts[contact_index];
|
||||
let ball_count = if self.secondary_ball.is_some() { 2 } else { 1 };
|
||||
let contact_allowed =
|
||||
contact == 0 || (contact != 99 && ball_count == 1) || contact == 1;
|
||||
|
||||
if surface_distance < -11_000 && contact_allowed {
|
||||
if self.capture_age < 300 {
|
||||
let mut velocity = MilliVec::from_velocity_per_second(self.ball.velocity);
|
||||
let stationary = center.x.wrapping_sub(previous_position.x).wrapping_abs() < 500
|
||||
&& center.y.wrapping_sub(previous_position.y).wrapping_abs() < 500
|
||||
&& velocity.x.wrapping_abs() < 500
|
||||
&& velocity.y.wrapping_abs() < 500;
|
||||
if stationary {
|
||||
velocity = MilliVec::default();
|
||||
if self.capture_age == 0 {
|
||||
self.record_contacts[contact_index] = 1;
|
||||
events.push(Event::Sound(2015));
|
||||
}
|
||||
self.capture_age = if record_id == 89 {
|
||||
300
|
||||
} else {
|
||||
self.capture_age.wrapping_add(5)
|
||||
};
|
||||
} else {
|
||||
velocity.x = (f64::from(velocity.x) * 0.9).round() as i32;
|
||||
velocity.y = (f64::from(velocity.y) * 0.9).round() as i32;
|
||||
velocity.x = if center.x > current_position.x {
|
||||
velocity.x.wrapping_add(150)
|
||||
} else {
|
||||
velocity.x.wrapping_sub(150)
|
||||
};
|
||||
velocity.y = if center.y > current_position.y {
|
||||
velocity.y.wrapping_add(150)
|
||||
} else {
|
||||
velocity.y.wrapping_sub(150)
|
||||
};
|
||||
}
|
||||
self.ball.velocity = velocity.to_velocity_per_second();
|
||||
return CaptureStep::Holding;
|
||||
}
|
||||
|
||||
self.capture_age = 0;
|
||||
self.record_contacts[contact_index] = if record_id == 148 { 2 } else { 99 };
|
||||
return CaptureStep::Complete;
|
||||
}
|
||||
|
||||
if surface_distance > -11_000 && contact == 1 {
|
||||
self.record_contacts[contact_index] = 0;
|
||||
self.capture_age = 0;
|
||||
}
|
||||
CaptureStep::Outside
|
||||
}
|
||||
|
||||
fn check_lock_holes(
|
||||
&mut self,
|
||||
old_position: MilliVec,
|
||||
current_position: MilliVec,
|
||||
movement_velocity: MilliVec,
|
||||
events: &mut Vec<Event>,
|
||||
) -> bool {
|
||||
for (index, sensor) in LOCK_HOLES.into_iter().enumerate() {
|
||||
let touched = path_intersects_circle(
|
||||
match self.capture_record_step(
|
||||
sensor.id,
|
||||
sensor.center,
|
||||
sensor.radius,
|
||||
old_position,
|
||||
movement_velocity,
|
||||
sensor.center,
|
||||
sensor.radius,
|
||||
);
|
||||
let contact_index = usize::from(sensor.id);
|
||||
let entered =
|
||||
touched && !self.trigger_contacts[contact_index] && !self.wheel_holes[index];
|
||||
self.trigger_contacts[contact_index] = path_intersects_circle(
|
||||
current_position,
|
||||
MilliVec::default(),
|
||||
sensor.center,
|
||||
sensor.radius,
|
||||
);
|
||||
if !entered || self.tilted {
|
||||
continue;
|
||||
events,
|
||||
) {
|
||||
CaptureStep::Outside => continue,
|
||||
CaptureStep::Holding => return true,
|
||||
CaptureStep::Complete => {}
|
||||
}
|
||||
let filled_before = self.wheel_holes.iter().filter(|filled| **filled).count();
|
||||
self.wheel_holes[index] = true;
|
||||
@@ -887,7 +966,6 @@ impl Game {
|
||||
}
|
||||
self.reset_ball_to_launcher();
|
||||
events.push(Event::Lock);
|
||||
events.push(Event::Sound(2015));
|
||||
return true;
|
||||
}
|
||||
false
|
||||
@@ -896,34 +974,25 @@ impl Game {
|
||||
fn check_wheel_reset(
|
||||
&mut self,
|
||||
old_position: MilliVec,
|
||||
current_position: MilliVec,
|
||||
movement_velocity: MilliVec,
|
||||
events: &mut Vec<Event>,
|
||||
) -> bool {
|
||||
let reset_touched = path_intersects_circle(
|
||||
match self.capture_record_step(
|
||||
WHEEL_RESET_SENSOR.id,
|
||||
WHEEL_RESET_SENSOR.center,
|
||||
WHEEL_RESET_SENSOR.radius,
|
||||
old_position,
|
||||
movement_velocity,
|
||||
WHEEL_RESET_SENSOR.center,
|
||||
WHEEL_RESET_SENSOR.radius,
|
||||
);
|
||||
let reset_index = usize::from(WHEEL_RESET_SENSOR.id);
|
||||
let reset_entered = reset_touched && !self.trigger_contacts[reset_index];
|
||||
self.trigger_contacts[reset_index] = path_intersects_circle(
|
||||
current_position,
|
||||
MilliVec::default(),
|
||||
WHEEL_RESET_SENSOR.center,
|
||||
WHEEL_RESET_SENSOR.radius,
|
||||
);
|
||||
if reset_entered && !self.tilted {
|
||||
self.wheel_holes.fill(false);
|
||||
self.wheel_animation = 0.65;
|
||||
self.multiball_state = MultiballState::Ready;
|
||||
self.reset_ball_to_launcher();
|
||||
events.push(Event::Wheel);
|
||||
events.push(Event::Sound(2015));
|
||||
return true;
|
||||
events,
|
||||
) {
|
||||
CaptureStep::Outside => return false,
|
||||
CaptureStep::Holding => return true,
|
||||
CaptureStep::Complete => {}
|
||||
}
|
||||
false
|
||||
self.wheel_holes.fill(false);
|
||||
self.wheel_animation = 0.65;
|
||||
self.multiball_state = MultiballState::Ready;
|
||||
self.reset_ball_to_launcher();
|
||||
events.push(Event::Wheel);
|
||||
true
|
||||
}
|
||||
|
||||
fn check_effect_sensor(
|
||||
@@ -941,8 +1010,8 @@ impl Game {
|
||||
EFFECT_SENSOR.center,
|
||||
EFFECT_SENSOR.radius,
|
||||
);
|
||||
let entered = touched && !self.trigger_contacts[effect_index];
|
||||
self.trigger_contacts[effect_index] = path_intersects_circle(
|
||||
let entered = touched && !self.trigger_flags[effect_index];
|
||||
self.trigger_flags[effect_index] = path_intersects_circle(
|
||||
current_position,
|
||||
MilliVec::default(),
|
||||
EFFECT_SENSOR.center,
|
||||
@@ -996,8 +1065,8 @@ impl Game {
|
||||
sensor.radius,
|
||||
);
|
||||
let contact_index = usize::from(sensor.id);
|
||||
let entered = touched && !self.trigger_contacts[contact_index];
|
||||
self.trigger_contacts[contact_index] = path_intersects_circle(
|
||||
let entered = touched && !self.trigger_flags[contact_index];
|
||||
self.trigger_flags[contact_index] = path_intersects_circle(
|
||||
current_position,
|
||||
MilliVec::default(),
|
||||
sensor.center,
|
||||
@@ -1117,6 +1186,20 @@ impl Game {
|
||||
events.push(Event::Sound(2015));
|
||||
}
|
||||
|
||||
fn begin_claw_capture_after_hold(&mut self, terminal_frame: u8, events: &mut Vec<Event>) {
|
||||
debug_assert!(CLAW_TERMINAL_FRAMES.contains(&terminal_frame));
|
||||
if self.claw.active {
|
||||
return;
|
||||
}
|
||||
self.claw.active = true;
|
||||
self.claw.target_frame = terminal_frame;
|
||||
self.claw.bank = ClawSpriteBank::Closing;
|
||||
self.claw.ball_suspended = true;
|
||||
self.claw.frame_accumulator = 0.0;
|
||||
self.ball.velocity = Vec2::ZERO;
|
||||
events.push(Event::ClawCapture);
|
||||
}
|
||||
|
||||
fn update_claw(&mut self, dt: f32, events: &mut Vec<Event>) {
|
||||
if !self.claw.active {
|
||||
return;
|
||||
@@ -1199,6 +1282,7 @@ impl Game {
|
||||
self.bumper_flash.fill(0.0);
|
||||
self.wheel_animation = 0.0;
|
||||
self.claw = Claw::default();
|
||||
self.capture_age = 0;
|
||||
self.secondary_ball = None;
|
||||
self.nudge_shake = 0.0;
|
||||
self.launcher_charge = 0.0;
|
||||
@@ -1224,7 +1308,7 @@ impl Game {
|
||||
self.players[self.current_player].rules = RuleState {
|
||||
wheel_holes: self.wheel_holes,
|
||||
top_targets: self.top_targets,
|
||||
trigger_contacts: self.trigger_contacts,
|
||||
record_contacts: self.record_contacts,
|
||||
object_active: self.object_active,
|
||||
target_effect: self.target_effect,
|
||||
multiball_state: self.multiball_state,
|
||||
@@ -1235,7 +1319,8 @@ impl Game {
|
||||
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.record_contacts = state.record_contacts;
|
||||
self.trigger_flags.fill(false);
|
||||
self.object_active = state.object_active;
|
||||
self.target_effect = state.target_effect;
|
||||
self.multiball_state = state.multiball_state;
|
||||
@@ -1308,6 +1393,23 @@ mod tests {
|
||||
game.update(1.0 / 60.0, 3, Controls::default())
|
||||
}
|
||||
|
||||
fn complete_stationary_type_three_capture(
|
||||
game: &mut Game,
|
||||
center: Vec2,
|
||||
events: &mut Vec<Event>,
|
||||
) {
|
||||
for _ in 0..=60 {
|
||||
game.ball.in_launcher = false;
|
||||
game.ball.position = center;
|
||||
game.ball.velocity = Vec2::ZERO;
|
||||
game.check_sensor_objects(
|
||||
MilliVec::from_position(center),
|
||||
MilliVec::default(),
|
||||
events,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn player_count_is_bounded() {
|
||||
assert_eq!(Game::new(0).players.len(), 1);
|
||||
@@ -1606,7 +1708,8 @@ mod tests {
|
||||
let mut game = Game::new(2);
|
||||
game.wheel_holes[2] = true;
|
||||
game.top_targets[1] = true;
|
||||
game.trigger_contacts[149] = true;
|
||||
game.record_contacts[129] = 99;
|
||||
game.trigger_flags[149] = true;
|
||||
game.object_active[90] = false;
|
||||
game.target_effect = 3;
|
||||
game.multiball_state = MultiballState::Ready;
|
||||
@@ -1615,7 +1718,8 @@ mod tests {
|
||||
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_eq!(game.record_contacts[129], 0);
|
||||
assert!(!game.trigger_flags[149]);
|
||||
assert!(game.object_active[90]);
|
||||
assert_eq!(game.target_effect, 0);
|
||||
assert_eq!(game.multiball_state, MultiballState::Unavailable);
|
||||
@@ -1626,7 +1730,8 @@ mod tests {
|
||||
assert!(game.wheel_holes[2]);
|
||||
assert!(!game.wheel_holes[4]);
|
||||
assert!(game.top_targets[1]);
|
||||
assert!(game.trigger_contacts[149]);
|
||||
assert_eq!(game.record_contacts[129], 99);
|
||||
assert!(!game.trigger_flags[149]);
|
||||
assert!(!game.object_active[90]);
|
||||
assert_eq!(game.target_effect, 3);
|
||||
assert_eq!(game.multiball_state, MultiballState::Ready);
|
||||
@@ -2032,8 +2137,15 @@ mod tests {
|
||||
MilliVec::default(),
|
||||
&mut events,
|
||||
);
|
||||
assert!(!game.claw.active);
|
||||
assert_eq!(events, [Event::Sound(2015)]);
|
||||
game.check_sensor_objects(
|
||||
MilliVec::from_position(game.ball.position),
|
||||
MilliVec::default(),
|
||||
&mut events,
|
||||
);
|
||||
assert!(game.claw.active);
|
||||
assert_eq!(events, [Event::ClawCapture, Event::Sound(2015)]);
|
||||
assert_eq!(events, [Event::Sound(2015), Event::ClawCapture]);
|
||||
assert!(CLAW_TERMINAL_FRAMES.contains(&game.claw.target_frame));
|
||||
}
|
||||
|
||||
@@ -2108,12 +2220,7 @@ mod tests {
|
||||
let expected_bonus = [10_000, 30_000, 70_000, 150_000, 0];
|
||||
|
||||
for (index, sensor) in LOCK_HOLES.into_iter().enumerate() {
|
||||
game.ball.position = sensor.center;
|
||||
game.check_sensor_objects(
|
||||
MilliVec::from_position(sensor.center),
|
||||
MilliVec::default(),
|
||||
&mut events,
|
||||
);
|
||||
complete_stationary_type_three_capture(&mut game, sensor.center, &mut events);
|
||||
assert_eq!(game.player().secondary_score, expected_bonus[index]);
|
||||
assert!(game.ball.in_launcher);
|
||||
}
|
||||
@@ -2126,15 +2233,72 @@ mod tests {
|
||||
5
|
||||
);
|
||||
|
||||
game.ball.in_launcher = false;
|
||||
game.ball.position = WHEEL_RESET_SENSOR.center;
|
||||
game.check_sensor_objects(
|
||||
MilliVec::from_position(WHEEL_RESET_SENSOR.center),
|
||||
MilliVec::default(),
|
||||
complete_stationary_type_three_capture(
|
||||
&mut game,
|
||||
WHEEL_RESET_SENSOR.center,
|
||||
&mut events,
|
||||
);
|
||||
assert!(game.wheel_holes.iter().all(|filled| !*filled));
|
||||
assert!(events.ends_with(&[Event::Wheel, Event::Sound(2015)]));
|
||||
assert_eq!(events.last(), Some(&Event::Wheel));
|
||||
assert_eq!(
|
||||
events
|
||||
.iter()
|
||||
.filter(|event| **event == Event::Sound(2015))
|
||||
.count(),
|
||||
6
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn type_three_capture_pulls_holds_and_publishes_contact_sentinels() {
|
||||
let sensor = LOCK_HOLES[0];
|
||||
let mut game = Game::new(1);
|
||||
game.ball.in_launcher = false;
|
||||
game.ball.position = sensor.center + vec2(5.0, 0.0);
|
||||
game.ball.velocity = vec2(100.0, 0.0);
|
||||
let previous = MilliVec::from_position(game.ball.position);
|
||||
let mut events = Vec::new();
|
||||
|
||||
assert_eq!(
|
||||
game.capture_record_step(sensor.id, sensor.center, sensor.radius, previous, &mut events),
|
||||
CaptureStep::Holding
|
||||
);
|
||||
assert_eq!(
|
||||
MilliVec::from_velocity_per_second(game.ball.velocity),
|
||||
MilliVec { x: 750, y: -150 }
|
||||
);
|
||||
assert_eq!(game.record_contacts[usize::from(sensor.id)], 0);
|
||||
assert_eq!(game.capture_age, 0);
|
||||
|
||||
game.ball.position = sensor.center;
|
||||
game.ball.velocity = Vec2::ZERO;
|
||||
assert_eq!(
|
||||
game.capture_record_step(
|
||||
sensor.id,
|
||||
sensor.center,
|
||||
sensor.radius,
|
||||
MilliVec::from_position(sensor.center),
|
||||
&mut events,
|
||||
),
|
||||
CaptureStep::Holding
|
||||
);
|
||||
assert_eq!(game.record_contacts[usize::from(sensor.id)], 1);
|
||||
assert_eq!(game.capture_age, 5);
|
||||
assert_eq!(events, [Event::Sound(2015)]);
|
||||
|
||||
game.capture_age = 300;
|
||||
assert_eq!(
|
||||
game.capture_record_step(
|
||||
sensor.id,
|
||||
sensor.center,
|
||||
sensor.radius,
|
||||
MilliVec::from_position(sensor.center),
|
||||
&mut events,
|
||||
),
|
||||
CaptureStep::Complete
|
||||
);
|
||||
assert_eq!(game.record_contacts[usize::from(sensor.id)], 99);
|
||||
assert_eq!(game.capture_age, 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -427,7 +427,7 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn every_claw_scenario_completes_all_captures_and_returns_idle() {
|
||||
fn every_claw_scenario_completes_its_seeded_capture() {
|
||||
for scenario in [
|
||||
Scenario::Claw1,
|
||||
Scenario::Claw6,
|
||||
@@ -435,7 +435,17 @@ mod tests {
|
||||
Scenario::Claw18,
|
||||
] {
|
||||
let mut simulation = Simulation::new(scenario, 1);
|
||||
simulation.advance_to(120);
|
||||
for target in 1..=120 {
|
||||
simulation.advance_to(target);
|
||||
let index = usize::try_from(target).unwrap_or(120);
|
||||
if simulation.trace[index]
|
||||
.events
|
||||
.iter()
|
||||
.any(|event| event == "ClawRelease")
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
let events: Vec<&str> = simulation
|
||||
.trace
|
||||
.iter()
|
||||
@@ -451,13 +461,8 @@ mod tests {
|
||||
.filter(|event| **event == "ClawRelease")
|
||||
.count();
|
||||
assert!(captures >= 1, "{} must enter the claw", scenario.name());
|
||||
assert_eq!(
|
||||
captures,
|
||||
releases,
|
||||
"{} must release every captured ball",
|
||||
scenario.name()
|
||||
);
|
||||
assert!(!simulation.game.claw.ball_suspended);
|
||||
assert_eq!(releases, 1, "{} must release its seeded capture", scenario.name());
|
||||
assert!(captures >= releases);
|
||||
assert!(simulation.game.ball.position.is_finite());
|
||||
assert!(simulation.game.ball.velocity.is_finite());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user