Pokemon Emerald: Ensure dig tutor is always usable (#3660)

* Pokemon Emerald: Ensure dig tutor is always usable

* Pokemon Emerald: Clarify comment

Co-authored-by: Exempt-Medic <60412657+Exempt-Medic@users.noreply.github.com>

---------

Co-authored-by: Exempt-Medic <60412657+Exempt-Medic@users.noreply.github.com>
This commit is contained in:
Bryce Wilson 2024-08-16 13:23:47 -07:00 committed by GitHub
parent 81092247c6
commit f5218faea7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 15 additions and 5 deletions

View File

@ -817,6 +817,8 @@ def _randomize_opponent_battle_type(world: "PokemonEmeraldWorld", patch: Pokemon
def _randomize_move_tutor_moves(world: "PokemonEmeraldWorld", patch: PokemonEmeraldProcedurePatch, easter_egg: Tuple[int, int]) -> None:
FORTREE_MOVE_TUTOR_INDEX = 24
if easter_egg[0] == 2:
for i in range(30):
patch.write_token(
@ -840,18 +842,26 @@ def _randomize_move_tutor_moves(world: "PokemonEmeraldWorld", patch: PokemonEmer
# Always set Fortree move tutor to Dig
patch.write_token(
APTokenTypes.WRITE,
data.rom_addresses["gTutorMoves"] + (24 * 2),
data.rom_addresses["gTutorMoves"] + (FORTREE_MOVE_TUTOR_INDEX * 2),
struct.pack("<H", data.constants["MOVE_DIG"])
)
# Modify compatibility
if world.options.tm_tutor_compatibility.value != -1:
for species in data.species.values():
compatibility = bool_array_to_int([
world.random.randrange(0, 100) < world.options.tm_tutor_compatibility.value
for _ in range(32)
])
# Make sure Dig tutor has reasonable (>=50%) compatibility
if world.options.tm_tutor_compatibility.value < 50:
compatibility &= ~(1 << FORTREE_MOVE_TUTOR_INDEX)
if world.random.random() < 0.5:
compatibility |= 1 << FORTREE_MOVE_TUTOR_INDEX
patch.write_token(
APTokenTypes.WRITE,
data.rom_addresses["sTutorLearnsets"] + (species.species_id * 4),
struct.pack("<I", bool_array_to_int([
world.random.randrange(0, 100) < world.options.tm_tutor_compatibility.value
for _ in range(32)
]))
struct.pack("<I", compatibility)
)