summaryrefslogtreecommitdiff
path: root/pokemontools/vba/battle.py
diff options
context:
space:
mode:
authorBryan Bishop <kanzure@gmail.com>2013-11-13 22:43:35 -0600
committerBryan Bishop <kanzure@gmail.com>2013-11-13 22:43:35 -0600
commitdddc61e026163808da93ae3ca7121ec64b2bba8f (patch)
treea0953a5d2c2ae84761b87b0fcff9369b24113393 /pokemontools/vba/battle.py
parent79bc5088895d087b5338cb4519d7e5d748ce1faf (diff)
a really simple, broken battle strategy
Diffstat (limited to 'pokemontools/vba/battle.py')
-rw-r--r--pokemontools/vba/battle.py50
1 files changed, 46 insertions, 4 deletions
diff --git a/pokemontools/vba/battle.py b/pokemontools/vba/battle.py
index 409d9a8..1b582dd 100644
--- a/pokemontools/vba/battle.py
+++ b/pokemontools/vba/battle.py
@@ -260,8 +260,12 @@ class Battle(EmulatorController):
"""
Waits until the battle needs player input.
"""
- while not self.is_input_required():
- self.emulator.text_wait()
+ # callback causes text_wait to exit when the callback returns True
+ def is_in_battle_checker():
+ return (self.emulator.vba.read_memory_at(0xd22d) == 0)
+
+ while not self.is_input_required() and self.is_in_battle():
+ self.emulator.text_wait(callback=is_in_battle_checker)
# let the text draw so that the state is more obvious
self.emulator.vba.step(count=10)
@@ -276,9 +280,14 @@ class Battle(EmulatorController):
# xyz wants to battle, a wild foobar appeared
self.skip_start_text()
+ wild = (self.emulator.vba.read_memory_at(0xd22d) == 1)
+
while self.is_in_battle():
self.skip_until_input_required()
+ if not self.is_in_battle():
+ continue
+
if self.is_player_turn():
# battle hook provides input to handle this situation
self.handle_turn()
@@ -294,7 +303,8 @@ class Battle(EmulatorController):
# "how did i lose? wah"
# TODO: this doesn't happen for wild battles
- self.skip_end_text()
+ if not wild:
+ self.skip_end_text()
# TODO: return should indicate win/loss (blackout)
@@ -365,4 +375,36 @@ class SpamBattleStrategy(BattleStrategy):
"""
Always picks the first move of the current pokemon.
"""
- pass
+ self.fight(1)
+
+ def handle_trainer_switch_prompt(self):
+ """
+ The trainer is switching pokemon. The game asks yes/no for whether or
+ not the player would like to switch.
+ """
+ # decline
+ self.emulator.vba.press(["b"], hold=5, after=10)
+
+ def handle_wild_switch_prompt(self):
+ """
+ The wild pokemon defeated the party pokemon. This is the yes/no box for
+ whether to switch pokemon or not.
+ """
+ # why not just make a battle strategy that doesn't lose?
+ # TODO: Note that the longer "after" value is required here.
+ self.emulator.vba.press("a", hold=5, after=30)
+
+ self.handle_mandatory_switch()
+
+ def handle_mandatory_switch(self):
+ """
+ Something fainted, pick the next mon.
+ """
+
+ # TODO: make a better selector for which pokemon.
+
+ # now scroll down
+ self.emulator.vba.press("d", hold=5, after=10)
+
+ # select this mon
+ self.emulator.vba.press("a", hold=5, after=30)