From 0fb8f2b67259a6493ffd3db56e935c81893274db Mon Sep 17 00:00:00 2001 From: enteryourinitials <59253562+enteryourinitials@users.noreply.github.com> Date: Tue, 1 Sep 2020 18:52:28 +1000 Subject: [PATCH 1/8] Block tilt warnings once game has tilted Any further tilt warnings that were triggered once the game tilted would affect the tilt warning count for the players next ball. This change will not trigger any further warnings once the game is in a tilted state and ensure their tilt warning count is at zero when the next ball begins. --- mpf/modes/tilt/code/tilt.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mpf/modes/tilt/code/tilt.py b/mpf/modes/tilt/code/tilt.py index 2419c0fb6..608a7b83a 100644 --- a/mpf/modes/tilt/code/tilt.py +++ b/mpf/modes/tilt/code/tilt.py @@ -114,7 +114,7 @@ def tilt_warning(self, **kwargs): del kwargs self.last_tilt_warning_switch = self.machine.clock.get_time() - if not self.machine.game or not self.machine.game.player or self.machine.game.ending: + if not self.machine.game or not self.machine.game.player or self.machine.game.ending or self.machine.game.tilted: return self.info_log("Tilt Warning") From 1b6c39efced3d4c971406603dbf1927e9d005c6b Mon Sep 17 00:00:00 2001 From: enteryourinitials <59253562+enteryourinitials@users.noreply.github.com> Date: Wed, 2 Sep 2020 00:12:55 +1000 Subject: [PATCH 2/8] Fixed line length with added condition in tilt warning --- mpf/modes/tilt/code/tilt.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/mpf/modes/tilt/code/tilt.py b/mpf/modes/tilt/code/tilt.py index 608a7b83a..178747bdc 100644 --- a/mpf/modes/tilt/code/tilt.py +++ b/mpf/modes/tilt/code/tilt.py @@ -114,7 +114,10 @@ def tilt_warning(self, **kwargs): del kwargs self.last_tilt_warning_switch = self.machine.clock.get_time() - if not self.machine.game or not self.machine.game.player or self.machine.game.ending or self.machine.game.tilted: + if not self.machine.game or \ + not self.machine.game.player or \ + self.machine.game.ending or \ + self.machine.game.tilted: return self.info_log("Tilt Warning") From 97e44ffa45f4cca1a090499253592016696441a0 Mon Sep 17 00:00:00 2001 From: enteryourinitials <59253562+enteryourinitials@users.noreply.github.com> Date: Wed, 2 Sep 2020 00:30:50 +1000 Subject: [PATCH 3/8] Removed extra white space on condition --- mpf/modes/tilt/code/tilt.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mpf/modes/tilt/code/tilt.py b/mpf/modes/tilt/code/tilt.py index 178747bdc..baf5b4f9a 100644 --- a/mpf/modes/tilt/code/tilt.py +++ b/mpf/modes/tilt/code/tilt.py @@ -114,10 +114,10 @@ def tilt_warning(self, **kwargs): del kwargs self.last_tilt_warning_switch = self.machine.clock.get_time() - if not self.machine.game or \ - not self.machine.game.player or \ - self.machine.game.ending or \ - self.machine.game.tilted: + if (not self.machine.game or + not self.machine.game.player or + self.machine.game.ending or + self.machine.game.tilted): return self.info_log("Tilt Warning") From 7b43a127e9e4d746877c3f98a0bd99d3fdcfd9ec Mon Sep 17 00:00:00 2001 From: enteryourinitials <59253562+enteryourinitials@users.noreply.github.com> Date: Wed, 2 Sep 2020 00:46:01 +1000 Subject: [PATCH 4/8] Fixed indentation --- mpf/modes/tilt/code/tilt.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mpf/modes/tilt/code/tilt.py b/mpf/modes/tilt/code/tilt.py index baf5b4f9a..b2bf3bd3c 100644 --- a/mpf/modes/tilt/code/tilt.py +++ b/mpf/modes/tilt/code/tilt.py @@ -118,7 +118,7 @@ def tilt_warning(self, **kwargs): not self.machine.game.player or self.machine.game.ending or self.machine.game.tilted): - return + return self.info_log("Tilt Warning") From fc1fd60b8f2481e8ca7155c5d351a02302b0bc16 Mon Sep 17 00:00:00 2001 From: enteryourinitials <59253562+enteryourinitials@users.noreply.github.com> Date: Wed, 2 Sep 2020 00:59:11 +1000 Subject: [PATCH 5/8] More indenting --- mpf/modes/tilt/code/tilt.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/mpf/modes/tilt/code/tilt.py b/mpf/modes/tilt/code/tilt.py index b2bf3bd3c..9043ef121 100644 --- a/mpf/modes/tilt/code/tilt.py +++ b/mpf/modes/tilt/code/tilt.py @@ -114,11 +114,9 @@ def tilt_warning(self, **kwargs): del kwargs self.last_tilt_warning_switch = self.machine.clock.get_time() - if (not self.machine.game or - not self.machine.game.player or - self.machine.game.ending or - self.machine.game.tilted): - return + if (not self.machine.game or not self.machine.game.player or + self.machine.game.ending or self.machine.game.tilted): + return self.info_log("Tilt Warning") From 483cab46da654dee154935e231d7b815652e355c Mon Sep 17 00:00:00 2001 From: Jan Kantert Date: Fri, 4 Sep 2020 21:57:40 +0200 Subject: [PATCH 6/8] add test for tilt carry over --- mpf/tests/test_Tilt.py | 169 ++++++++++++++++++++--------------------- 1 file changed, 83 insertions(+), 86 deletions(-) diff --git a/mpf/tests/test_Tilt.py b/mpf/tests/test_Tilt.py index 2265179c4..5e747930a 100644 --- a/mpf/tests/test_Tilt.py +++ b/mpf/tests/test_Tilt.py @@ -1,7 +1,8 @@ -from mpf.tests.MpfTestCase import MpfTestCase, test_config +from mpf.tests.MpfGameTestCase import MpfGameTestCase +from mpf.tests.MpfTestCase import test_config -class TestTilt(MpfTestCase): +class TestTilt(MpfGameTestCase): def get_config_file(self): return 'config.yaml' @@ -16,21 +17,24 @@ def _tilted(self, **kwargs): del kwargs self._is_tilted = True - @test_config("config_system_11_trough.yaml") - def test_tilt_in_outhole(self): - """Test that the ball does not stay in the outhole.""" + def _prepare_trough(self): + self.machine.ball_controller.num_balls_known = 0 + self.machine.switch_controller.process_switch('s_ball_switch1', 1) + self.machine.switch_controller.process_switch('s_ball_switch2', 1) + self.advance_time_and_run(2) + self.assertEqual(2, self.machine.ball_devices["bd_trough"].balls) + + def _add_tilt_handler(self): self._is_tilted = False self.machine.events.add_handler("tilt", self._tilted) - self.machine.ball_controller.num_balls_known = 0 - self.hit_switch_and_run('s_ball_switch1', 0) - self.hit_switch_and_run('s_ball_switch2', 0) - self.advance_time_and_run(2) + @test_config("config_system_11_trough.yaml") + def test_tilt_in_outhole(self): + """Test that the ball does not stay in the outhole.""" + self._add_tilt_handler() - self.assertEqual(None, self.machine.game) - self.assertEqual(2, self.machine.ball_controller.num_balls_known) - self.assertEqual(2, self.machine.ball_devices["bd_trough"].balls) - self.hit_and_release_switch("s_start") + self._prepare_trough() + self.start_game(2) self.advance_time_and_run(10) self.assertBallsOnPlayfield(0) @@ -64,20 +68,10 @@ def test_tilt_in_outhole(self): @test_config("config_mechanical_eject.yaml") def test_mechanical_eject(self): """Test that tilt triggers auto launch.""" - self._is_tilted = False - self.machine.events.add_handler("tilt", self._tilted) + self._add_tilt_handler() - self.machine.ball_controller.num_balls_known = 0 - self.machine.switch_controller.process_switch('s_ball_switch1', 1) - self.machine.switch_controller.process_switch('s_ball_switch2', 1) - self.advance_time_and_run(2) - - self.assertEqual(None, self.machine.game) - self.assertEqual(2, self.machine.ball_controller.num_balls_known) - self.assertEqual(2, self.machine.ball_devices["bd_trough"].balls) - self.machine.switch_controller.process_switch('s_start', 1) - self.machine.switch_controller.process_switch('s_start', 0) - self.advance_time_and_run(10) + self._prepare_trough() + self.start_game(2) self.assertBallsOnPlayfield(0) self.assertAvailableBallsOnPlayfield(1) @@ -102,20 +96,10 @@ def test_mechanical_eject(self): self.assertEqual(False, self.machine.game.tilted) def test_simple_tilt(self): - self._is_tilted = False - self.machine.events.add_handler("tilt", self._tilted) - - self.machine.ball_controller.num_balls_known = 0 - self.machine.switch_controller.process_switch('s_ball_switch1', 1) - self.machine.switch_controller.process_switch('s_ball_switch2', 1) - self.advance_time_and_run(2) + self._add_tilt_handler() - self.assertEqual(None, self.machine.game) - self.assertEqual(2, self.machine.ball_controller.num_balls_known) - self.assertEqual(2, self.machine.ball_devices["bd_trough"].balls) - self.machine.switch_controller.process_switch('s_start', 1) - self.machine.switch_controller.process_switch('s_start', 0) - self.advance_time_and_run(10) + self._prepare_trough() + self.start_game(2) # flipper actived self.assertTrue(self.machine.flippers["f_test"]._enabled) @@ -149,23 +133,12 @@ def test_simple_tilt(self): self.assertEqual(False, self.machine.game.tilted) def test_tilt_event(self): - self._is_tilted = False - self.machine.events.add_handler("tilt", self._tilted) - - self.machine.ball_controller.num_balls_known = 0 - self.machine.switch_controller.process_switch('s_ball_switch1', 1) - self.machine.switch_controller.process_switch('s_ball_switch2', 1) - self.advance_time_and_run(2) + self._add_tilt_handler() - self.assertEqual(None, self.machine.game) - self.assertEqual(2, self.machine.ball_controller.num_balls_known) - self.assertEqual(2, self.machine.ball_devices["bd_trough"].balls) - self.machine.switch_controller.process_switch('s_start', 1) - self.machine.switch_controller.process_switch('s_start', 0) - self.advance_time_and_run(10) + self._prepare_trough() + self.start_game(2) self.assertTrue(self.machine.mode_controller.is_active('tilt')) - self.assertNotEqual(None, self.machine.game) self.assertFalse(self._is_tilted) self.machine.events.post("tilt_event") @@ -185,20 +158,10 @@ def test_tilt_event(self): self.assertEqual(False, self.machine.game.tilted) def test_simple_tilt_ball_not_on_pf_yet(self): - self._is_tilted = False - self.machine.events.add_handler("tilt", self._tilted) + self._add_tilt_handler() - self.machine.ball_controller.num_balls_known = 0 - self.machine.switch_controller.process_switch('s_ball_switch1', 1) - self.machine.switch_controller.process_switch('s_ball_switch2', 1) - self.advance_time_and_run(2) - - self.assertEqual(None, self.machine.game) - self.assertEqual(2, self.machine.ball_controller.num_balls_known) - self.assertEqual(2, self.machine.ball_devices["bd_trough"].balls) - self.machine.switch_controller.process_switch('s_start', 1) - self.machine.switch_controller.process_switch('s_start', 0) - self.advance_time_and_run(1) + self._prepare_trough() + self.start_game(2) self.assertTrue(self.machine.mode_controller.is_active('tilt')) self.assertNotEqual(None, self.machine.game) @@ -217,23 +180,12 @@ def test_simple_tilt_ball_not_on_pf_yet(self): self.assertEqual(False, self.machine.game.tilted) def test_tilt_warning(self): - self._is_tilted = False - self.machine.events.add_handler("tilt", self._tilted) + self._add_tilt_handler() - self.machine.ball_controller.num_balls_known = 0 - self.machine.switch_controller.process_switch('s_ball_switch1', 1) - self.machine.switch_controller.process_switch('s_ball_switch2', 1) - self.advance_time_and_run(2) - - self.assertEqual(None, self.machine.game) - self.assertEqual(2, self.machine.ball_controller.num_balls_known) - self.assertEqual(2, self.machine.ball_devices["bd_trough"].balls) - self.machine.switch_controller.process_switch('s_start', 1) - self.machine.switch_controller.process_switch('s_start', 0) - self.advance_time_and_run(10) + self._prepare_trough() + self.start_game(2) self.assertTrue(self.machine.mode_controller.is_active('tilt')) - self.assertNotEqual(None, self.machine.game) self.assertFalse(self._is_tilted) @@ -272,13 +224,9 @@ def test_tilt_warning(self): self.assertEqual(False, self.machine.game.tilted) def test_slam_tilt(self): - self._is_tilted = False - self.machine.events.add_handler("tilt", self._tilted) + self._add_tilt_handler() - self.machine.ball_controller.num_balls_known = 0 - self.machine.switch_controller.process_switch('s_ball_switch1', 1) - self.machine.switch_controller.process_switch('s_ball_switch2', 1) - self.advance_time_and_run(2) + self._prepare_trough() self.assertEqual(None, self.machine.game) self.assertEqual(2, self.machine.ball_controller.num_balls_known) @@ -310,3 +258,52 @@ def test_slam_tilt(self): # test that it does not crash outside the game self.post_event("tilt_reset_warnings") self.advance_time_and_run() + + def test_carry_over(self): + self._add_tilt_handler() + self._prepare_trough() + self.start_two_player_game() + + self.advance_time_and_run(10) + self.assertBallsOnPlayfield(1) + self.assertPlayerVarEqual(0, "tilt_warnings") + + # tilt machine + self.hit_and_release_switch("s_tilt_warning") + self.advance_time_and_run(2) + self.assertFalse(self._is_tilted) + self.assertPlayerVarEqual(1, "tilt_warnings") + self.hit_and_release_switch("s_tilt_warning") + self.advance_time_and_run(2) + self.assertFalse(self._is_tilted) + self.assertPlayerVarEqual(2, "tilt_warnings") + + self.hit_and_release_switch("s_tilt_warning") + self.advance_time_and_run(2) + self.assertTrue(self._is_tilted) + self.assertPlayerVarEqual(3, "tilt_warnings") + + # tilt_warnings player var no longer increases because machine is tilted + self.hit_and_release_switch("s_tilt_warning") + self.advance_time_and_run(2) + self.assertPlayerVarEqual(3, "tilt_warnings") + self.hit_and_release_switch("s_tilt_warning") + self.advance_time_and_run(2) + self.assertPlayerVarEqual(3, "tilt_warnings") + self.hit_and_release_switch("s_tilt_warning") + self.advance_time_and_run(2) + self.assertPlayerVarEqual(3, "tilt_warnings") + self.assertPlayerNumber(1) + + self.drain_one_ball() + self.advance_time_and_run(10) + self.assertPlayerNumber(2) + self.assertPlayerVarEqual(0, "tilt_warnings") + self._is_tilted = False + + self.assertBallsOnPlayfield(1) + + self.hit_and_release_switch("s_tilt_warning") + self.advance_time_and_run(2) + self.assertPlayerVarEqual(1, "tilt_warnings") + self.assertFalse(self._is_tilted) From 7328a90c3545dfb5887698ab636f9778e6bab451 Mon Sep 17 00:00:00 2001 From: AndrewB Date: Mon, 7 Sep 2020 00:21:49 +1000 Subject: [PATCH 7/8] Added test for tilt carry over on single player --- AUTHORS | 1 + mpf/tests/test_Tilt.py | 60 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 60 insertions(+), 1 deletion(-) diff --git a/AUTHORS b/AUTHORS index 54d870bf4..b1546cfe9 100644 --- a/AUTHORS +++ b/AUTHORS @@ -26,6 +26,7 @@ their spare time, unpaid, for the love of pinball! * Kevin Lee Drum * Sean Irby * Mark Seiden + * Andrew Burch MPF is inspired by pyprocgame and skeletongame which were written by: diff --git a/mpf/tests/test_Tilt.py b/mpf/tests/test_Tilt.py index 5e747930a..3fef5e4ff 100644 --- a/mpf/tests/test_Tilt.py +++ b/mpf/tests/test_Tilt.py @@ -259,7 +259,7 @@ def test_slam_tilt(self): self.post_event("tilt_reset_warnings") self.advance_time_and_run() - def test_carry_over(self): + def test_carry_over_multiple_player(self): self._add_tilt_handler() self._prepare_trough() self.start_two_player_game() @@ -307,3 +307,61 @@ def test_carry_over(self): self.advance_time_and_run(2) self.assertPlayerVarEqual(1, "tilt_warnings") self.assertFalse(self._is_tilted) + + + def test_carry_over_single_player(self): + self._add_tilt_handler() + self._prepare_trough() + self.start_game() + + self.advance_time_and_run(10) + self.assertBallsOnPlayfield(1) + self.assertPlayerVarEqual(0, "tilt_warnings") + + # tilt machine + self.hit_and_release_switch("s_tilt_warning") + self.advance_time_and_run(2) + self.assertFalse(self._is_tilted) + self.assertPlayerVarEqual(1, "tilt_warnings") + self.hit_and_release_switch("s_tilt_warning") + self.advance_time_and_run(2) + self.assertFalse(self._is_tilted) + self.assertPlayerVarEqual(2, "tilt_warnings") + + self.hit_and_release_switch("s_tilt_warning") + self.advance_time_and_run(2) + self.assertTrue(self._is_tilted) + self.assertPlayerVarEqual(3, "tilt_warnings") + + # tilt_warnings player var no longer increases because machine is tilted + self.hit_and_release_switch("s_tilt_warning") + self.advance_time_and_run(2) + self.assertPlayerVarEqual(3, "tilt_warnings") + + # reset tilt warnings and ensure player var no longer increases until next ball + self.machine.game.player['tilt_warnings'] = 0 + + self.hit_and_release_switch("s_tilt_warning") + self.advance_time_and_run(2) + self.assertPlayerVarEqual(0, "tilt_warnings") + self.hit_and_release_switch("s_tilt_warning") + self.advance_time_and_run(2) + self.assertPlayerVarEqual(0, "tilt_warnings") + self.assertPlayerNumber(1) + + # advance to ball 2 + self.drain_one_ball() + self.advance_time_and_run(10) + self.assertPlayerNumber(1) + + self.assertPlayerVarEqual(0, "tilt_warnings") + self._is_tilted = False + + self.assertBallNumber(2) + self.assertBallsOnPlayfield(1) + + # generate tilt warning and ensure no carry over from previous ball + self.hit_and_release_switch("s_tilt_warning") + self.advance_time_and_run(2) + self.assertPlayerVarEqual(1, "tilt_warnings") + self.assertFalse(self._is_tilted) From 8fa529aacc1b163c71557adb61b591077d66c77e Mon Sep 17 00:00:00 2001 From: Jan Kantert Date: Mon, 4 Jan 2021 19:59:01 +0100 Subject: [PATCH 8/8] improve test to use a more sane tilt config --- .../tilt_defaults/config/config.yaml | 60 +++++++++++++++++++ mpf/tests/test_Tilt.py | 13 ++-- 2 files changed, 65 insertions(+), 8 deletions(-) create mode 100644 mpf/tests/machine_files/tilt_defaults/config/config.yaml diff --git a/mpf/tests/machine_files/tilt_defaults/config/config.yaml b/mpf/tests/machine_files/tilt_defaults/config/config.yaml new file mode 100644 index 000000000..175e10bd2 --- /dev/null +++ b/mpf/tests/machine_files/tilt_defaults/config/config.yaml @@ -0,0 +1,60 @@ +#config_version=5 + +modes: + - tilt + +playfields: + playfield: + default_source_device: bd_launcher + tags: default + +coils: + eject_coil1: + number: + eject_coil2: + number: + c_flipper: + number: + default_hold_power: 0.125 + +switches: + s_start: + number: + tags: start + s_ball_switch1: + number: + s_ball_switch2: + number: + s_ball_switch_launcher: + number: + s_tilt: + number: + tags: tilt + s_tilt_warning: + number: + tags: tilt_warning + s_slam_tilt: + number: + tags: slam_tilt + s_flipper: + number: + +ball_devices: + bd_trough: + eject_coil: eject_coil1 + ball_switches: s_ball_switch1, s_ball_switch2 + debug: true + confirm_eject_type: target + eject_targets: bd_launcher + tags: trough, drain, home + bd_launcher: + eject_coil: eject_coil2 + ball_switches: s_ball_switch_launcher + debug: true + confirm_eject_type: target + eject_timeouts: 6s, 10s + +flippers: + f_test: + main_coil: c_flipper + activation_switch: s_flipper diff --git a/mpf/tests/test_Tilt.py b/mpf/tests/test_Tilt.py index 3fef5e4ff..c1720bf07 100644 --- a/mpf/tests/test_Tilt.py +++ b/mpf/tests/test_Tilt.py @@ -1,5 +1,5 @@ from mpf.tests.MpfGameTestCase import MpfGameTestCase -from mpf.tests.MpfTestCase import test_config +from mpf.tests.MpfTestCase import test_config, test_config_directory class TestTilt(MpfGameTestCase): @@ -308,7 +308,7 @@ def test_carry_over_multiple_player(self): self.assertPlayerVarEqual(1, "tilt_warnings") self.assertFalse(self._is_tilted) - + @test_config_directory("tests/machine_files/tilt_defaults/") def test_carry_over_single_player(self): self._add_tilt_handler() self._prepare_trough() @@ -331,15 +331,12 @@ def test_carry_over_single_player(self): self.hit_and_release_switch("s_tilt_warning") self.advance_time_and_run(2) self.assertTrue(self._is_tilted) - self.assertPlayerVarEqual(3, "tilt_warnings") + self.assertPlayerVarEqual(0, "tilt_warnings") # tilt_warnings player var no longer increases because machine is tilted self.hit_and_release_switch("s_tilt_warning") self.advance_time_and_run(2) - self.assertPlayerVarEqual(3, "tilt_warnings") - - # reset tilt warnings and ensure player var no longer increases until next ball - self.machine.game.player['tilt_warnings'] = 0 + self.assertPlayerVarEqual(0, "tilt_warnings") self.hit_and_release_switch("s_tilt_warning") self.advance_time_and_run(2) @@ -354,11 +351,11 @@ def test_carry_over_single_player(self): self.advance_time_and_run(10) self.assertPlayerNumber(1) - self.assertPlayerVarEqual(0, "tilt_warnings") self._is_tilted = False self.assertBallNumber(2) self.assertBallsOnPlayfield(1) + self.assertPlayerVarEqual(0, "tilt_warnings") # generate tilt warning and ensure no carry over from previous ball self.hit_and_release_switch("s_tilt_warning")