detect the "mandatory switch" menu

This requires a slightly slower text_wait function. There is probably a
way to refactor that function in a way that doesn't cause cancer.
This commit is contained in:
Bryan Bishop
2013-11-11 00:55:54 -06:00
parent 1d9ecfa00f
commit 966985411f
3 changed files with 31 additions and 5 deletions

View File

@@ -67,8 +67,10 @@ class Battle(EmulatorController):
# 1) current pokemon hp is 0
# 2) game is polling for input
# TODO: detect the mandatory switch menu
return False
if "CANCEL Which ?" in self.emulator.get_text():
return True
else:
return False
def skip_start_text(self, max_loops=20):
"""

View File

@@ -431,12 +431,17 @@ class crystal(object):
# set CurSFX
self.vba.write_memory_at(0xc2bf, 0)
self.vba.press("a", hold=10, after=1)
self.vba.press("a", hold=10, after=50)
# check if CurSFX is SFX_READ_TEXT_2
if self.vba.read_memory_at(0xc2bf) == 0x8:
print "cursfx is set to SFX_READ_TEXT_2, looping.."
return self.text_wait(step_size=step_size, max_wait=max_wait, debug=debug, callback=callback, sfx_limit=sfx_limit)
if "CANCEL Which" in self.get_text():
print "probably the 'switch pokemon' menu"
return
else:
print "cursfx is set to SFX_READ_TEXT_2, looping.."
print self.get_text()
return self.text_wait(step_size=step_size, max_wait=max_wait, debug=debug, callback=callback, sfx_limit=sfx_limit)
else:
if sfx_limit > 0:
sfx_limit = sfx_limit - 1

View File

@@ -56,6 +56,25 @@ class BattleTests(unittest.TestCase):
# should not be asking for a switch so soon in the battle
self.assertFalse(self.battle.is_mandatory_switch())
def test_is_mandatory_switch(self):
self.battle.skip_start_text()
self.battle.skip_until_input_required()
# press "FIGHT"
self.vba.press(["a"], after=20)
# press the first move ("SCRATCH")
self.vba.press(["a"], after=20)
# set partymon1 hp to very low
self.vba.write_memory_at(0xc63c, 0)
self.vba.write_memory_at(0xc63d, 1)
# let the enemy attack and kill the pokemon
self.battle.skip_until_input_required()
self.assertTrue(self.battle.is_mandatory_switch())
def test_attack_loop(self):
self.battle.skip_start_text()
self.battle.skip_until_input_required()