From 4c6a904db191c182c3b9cecdcbc0d5ea3b5c2173 Mon Sep 17 00:00:00 2001 From: Bryan Bishop Date: Mon, 11 Nov 2013 21:22:15 -0600 Subject: a quick function to set pokemon hp in battle --- pokemontools/vba/vba.py | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'pokemontools/vba/vba.py') diff --git a/pokemontools/vba/vba.py b/pokemontools/vba/vba.py index 10513c6..47cadd7 100644 --- a/pokemontools/vba/vba.py +++ b/pokemontools/vba/vba.py @@ -523,6 +523,13 @@ class crystal(object): self.vba.write_memory_at(0xd216, 0) self.vba.write_memory_at(0xd217, 1) + def set_battle_mon_hp(self, hp): + """ + Set the BattleMonHP variable to the given hp. + """ + self.vba.write_memory_at(0xc63c, hp / 0x100) + self.vba.write_memory_at(0xc63c + 1, hp % 0x100) + def nstep(self, steplimit=500): """ Steps the CPU forward and calls some functions in between each step. -- cgit v1.2.3 From 18449eea21096cf8b90e21ee7bcdc6da5e047df4 Mon Sep 17 00:00:00 2001 From: Bryan Bishop Date: Mon, 11 Nov 2013 21:27:28 -0600 Subject: function to check if it's the yes/no prompt This is the prompt that appears during battles for whether or not to switch pokemon when the other trainer is sending something else out. --- pokemontools/vba/vba.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'pokemontools/vba/vba.py') diff --git a/pokemontools/vba/vba.py b/pokemontools/vba/vba.py index 47cadd7..79eb77e 100644 --- a/pokemontools/vba/vba.py +++ b/pokemontools/vba/vba.py @@ -599,6 +599,23 @@ class crystal(object): def is_in_link_battle(self): return self.vba.read_memory_at(0xc2dc) != 0 + def is_battle_switch_prompt(self): + """ + Checks if the game is currently displaying the yes/no prompt for + whether or not to switch pokemon. + """ + # get on-screen text + text = self.get_text() + + requirements = [ + "YES", + "NO", + "Will ", + "change POKMON?", + ] + + return all([requirement in text for requirement in requirements]) + def unlock_flypoints(self): """ Unlocks different destinations for flying. -- cgit v1.2.3 From 2801a3545ffd4cde947cb6fee212fe3a4f759543 Mon Sep 17 00:00:00 2001 From: Bryan Bishop Date: Mon, 11 Nov 2013 21:48:01 -0600 Subject: update docstrings about the switch prompt --- pokemontools/vba/vba.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'pokemontools/vba/vba.py') diff --git a/pokemontools/vba/vba.py b/pokemontools/vba/vba.py index 79eb77e..58ed1bd 100644 --- a/pokemontools/vba/vba.py +++ b/pokemontools/vba/vba.py @@ -602,8 +602,12 @@ class crystal(object): def is_battle_switch_prompt(self): """ Checks if the game is currently displaying the yes/no prompt for - whether or not to switch pokemon. + whether or not to switch pokemon. This happens when the trainer is + switching pokemon out. """ + # TODO: this method should return False if the game options have been + # set to not use the battle switching style. + # get on-screen text text = self.get_text() -- cgit v1.2.3 From d9bb01f2c0aef6d270bc4e2da93af94ea210e8db Mon Sep 17 00:00:00 2001 From: Bryan Bishop Date: Mon, 11 Nov 2013 21:56:34 -0600 Subject: rename the switch prompt detector --- pokemontools/vba/vba.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'pokemontools/vba/vba.py') diff --git a/pokemontools/vba/vba.py b/pokemontools/vba/vba.py index 58ed1bd..67d3cf1 100644 --- a/pokemontools/vba/vba.py +++ b/pokemontools/vba/vba.py @@ -599,7 +599,7 @@ class crystal(object): def is_in_link_battle(self): return self.vba.read_memory_at(0xc2dc) != 0 - def is_battle_switch_prompt(self): + def is_trainer_switch_prompt(self): """ Checks if the game is currently displaying the yes/no prompt for whether or not to switch pokemon. This happens when the trainer is -- cgit v1.2.3 From d6cf3454c44fab60c6f83bc8fa3109f0c793fd2f Mon Sep 17 00:00:00 2001 From: Bryan Bishop Date: Mon, 11 Nov 2013 22:21:23 -0600 Subject: prepare for a wild-based detector This one isn't implemented yet but might as well get the wrapper functions out of the way. --- pokemontools/vba/vba.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'pokemontools/vba/vba.py') diff --git a/pokemontools/vba/vba.py b/pokemontools/vba/vba.py index 67d3cf1..6f863b6 100644 --- a/pokemontools/vba/vba.py +++ b/pokemontools/vba/vba.py @@ -620,6 +620,21 @@ class crystal(object): return all([requirement in text for requirement in requirements]) + def is_wild_switch_prompt(self): + """ + Detects if the battle is waiting for the player to choose whether or + not to continue to fight the wild pokemon. + """ + # TODO: make a better implementation + return False + + def is_switch_prompt(self): + """ + Detects both the trainer-style switch prompt and the wild-style switch + prompt. This is the yes/no prompt for whether to switch pokemon. + """ + return self.is_trainer_switch_prompt() or self.is_wild_switch_prompt() + def unlock_flypoints(self): """ Unlocks different destinations for flying. -- cgit v1.2.3 From 4087851f7c9c92791182ffa695073827c5433829 Mon Sep 17 00:00:00 2001 From: Bryan Bishop Date: Mon, 11 Nov 2013 22:39:37 -0600 Subject: wild switch prompt detector --- pokemontools/vba/vba.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'pokemontools/vba/vba.py') diff --git a/pokemontools/vba/vba.py b/pokemontools/vba/vba.py index 6f863b6..17d3be6 100644 --- a/pokemontools/vba/vba.py +++ b/pokemontools/vba/vba.py @@ -625,8 +625,16 @@ class crystal(object): Detects if the battle is waiting for the player to choose whether or not to continue to fight the wild pokemon. """ - # TODO: make a better implementation - return False + # get on-screen text + screen_text = self.get_text() + + requirements = [ + "YES", + "NO", + "Use next POKMON?", + ] + + return all([requirement in text for requirement in requirements]) def is_switch_prompt(self): """ -- cgit v1.2.3 From 5b35595c7a13792db782f8ebc21dccfcc1b56b9a Mon Sep 17 00:00:00 2001 From: Bryan Bishop Date: Mon, 11 Nov 2013 23:04:44 -0600 Subject: minor function to set battle type This needs to be replaced with something that loads variable names from wram.asm instead of manually repeating everything in python. --- pokemontools/vba/vba.py | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'pokemontools/vba/vba.py') diff --git a/pokemontools/vba/vba.py b/pokemontools/vba/vba.py index 17d3be6..e339f57 100644 --- a/pokemontools/vba/vba.py +++ b/pokemontools/vba/vba.py @@ -655,6 +655,12 @@ class crystal(object): self.vba.write_memory_at(0xDCA7, 0xFF) self.vba.write_memory_at(0xDCA8, 0xFF) + def set_battle_type(self, battle_type): + """ + Changes the battle type value. + """ + self.vba.write_memory_at(0xd230, battle_type) + def get_gender(self): """ Returns 'male' or 'female'. -- cgit v1.2.3 From 28393a5342a3f6ad3c1511f81ff86ab4fe9216a2 Mon Sep 17 00:00:00 2001 From: Bryan Bishop Date: Wed, 13 Nov 2013 21:44:21 -0600 Subject: fix a variable typo in wild prompt detector --- pokemontools/vba/vba.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'pokemontools/vba/vba.py') diff --git a/pokemontools/vba/vba.py b/pokemontools/vba/vba.py index 57e5e1b..d221fef 100644 --- a/pokemontools/vba/vba.py +++ b/pokemontools/vba/vba.py @@ -634,7 +634,7 @@ class crystal(object): "Use next POKMON?", ] - return all([requirement in text for requirement in requirements]) + return all([requirement in screen_text for requirement in requirements]) def is_switch_prompt(self): """ -- cgit v1.2.3 From 367485303a0b40a4aec1ead83adf7f90fce59834 Mon Sep 17 00:00:00 2001 From: Bryan Bishop Date: Wed, 13 Nov 2013 22:44:04 -0600 Subject: improve text_wait for in-battle situations --- pokemontools/vba/vba.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'pokemontools/vba/vba.py') diff --git a/pokemontools/vba/vba.py b/pokemontools/vba/vba.py index d221fef..5106004 100644 --- a/pokemontools/vba/vba.py +++ b/pokemontools/vba/vba.py @@ -462,16 +462,17 @@ class crystal(object): # date/time box (day choice) # 0x47ab is the one from the intro, 0x49ab is the one from mom. elif 0x47ab in stack or 0x49ab in stack: # was any([x in stack for x in range(0x46EE, 0x47AB)]) - print "probably at a date/time box ? exiting." - break + # if not in battle + if self.vba.read_memory_at(0xd22d) == 0: + print "probably at a date/time box ? exiting." + break # "How many minutes?" selection box elif 0x4826 in stack: print "probably at a \"How many minutes?\" box ? exiting." break - else: - self.vba.step(count=step_size) + self.vba.step(count=step_size) # if there is a callback, then call the callback and exit when the # callback returns True. This is especially useful during the -- cgit v1.2.3 From d8ab944d4354546d44d098b2c30ba82b6ff509ee Mon Sep 17 00:00:00 2001 From: Bryan Bishop Date: Wed, 13 Nov 2013 23:07:44 -0600 Subject: simplify the date/clock check in text_wait --- pokemontools/vba/vba.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'pokemontools/vba/vba.py') diff --git a/pokemontools/vba/vba.py b/pokemontools/vba/vba.py index 5106004..c7a0bf9 100644 --- a/pokemontools/vba/vba.py +++ b/pokemontools/vba/vba.py @@ -462,8 +462,7 @@ class crystal(object): # date/time box (day choice) # 0x47ab is the one from the intro, 0x49ab is the one from mom. elif 0x47ab in stack or 0x49ab in stack: # was any([x in stack for x in range(0x46EE, 0x47AB)]) - # if not in battle - if self.vba.read_memory_at(0xd22d) == 0: + if not self.is_in_battle(): print "probably at a date/time box ? exiting." break -- cgit v1.2.3 From dc0a7ac670915a089d1b1ba27df0b5daca2b56f3 Mon Sep 17 00:00:00 2001 From: Bryan Bishop Date: Thu, 14 Nov 2013 00:43:52 -0600 Subject: make get_text slightly more configurable Add params to the get_text() function to dump text tiles from screen. --- pokemontools/vba/vba.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'pokemontools/vba/vba.py') diff --git a/pokemontools/vba/vba.py b/pokemontools/vba/vba.py index c7a0bf9..204e102 100644 --- a/pokemontools/vba/vba.py +++ b/pokemontools/vba/vba.py @@ -718,14 +718,14 @@ class crystal(object): self.vba.write_memory_at(0xd8dc, 5) self.vba.write_memory_at(0xd8dd, 99) - def get_text(self, chars=chars): + def get_text(self, chars=chars, offset=0, bounds=1000): """ Returns alphanumeric text on the screen. Other characters will not be shown. """ output = "" - tiles = self.vba.memory[0xc4a0:0xc4a0 + 1000] + tiles = self.vba.memory[0xc4a0 + offset:0xc4a0 + offset + bounds] for each in tiles: if each in chars.keys(): thing = chars[each] -- cgit v1.2.3