Skip to content

Commit

Permalink
Pokemon Emerald: Ensure dig tutor is always usable (ArchipelagoMW#3660)
Browse files Browse the repository at this point in the history
* Pokemon Emerald: Ensure dig tutor is always usable

* Pokemon Emerald: Clarify comment

Co-authored-by: Exempt-Medic <[email protected]>

---------

Co-authored-by: Exempt-Medic <[email protected]>
  • Loading branch information
Zunawe and Exempt-Medic authored Aug 16, 2024
1 parent 8109224 commit f5218fa
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions worlds/pokemon_emerald/rom.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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)
)

0 comments on commit f5218fa

Please sign in to comment.