Skip to content

Commit

Permalink
Egg Move Refactor (#4534)
Browse files Browse the repository at this point in the history
* Egg Move Refactor

* Update python file and fix formatting
  • Loading branch information
Bassoonian authored May 19, 2024
1 parent 334668b commit bc9f097
Show file tree
Hide file tree
Showing 15 changed files with 5,620 additions and 4,321 deletions.
2 changes: 2 additions & 0 deletions include/pokemon.h
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,7 @@ struct SpeciesInfo /*0x8C*/
// Move Data
/* 0x80 */ const struct LevelUpMove *levelUpLearnset;
/* 0x84 */ const u16 *teachableLearnset;
const u16 *eggMoveLearnset;
/* 0x88 */ const struct Evolution *evolutions;
/* 0x84 */ const u16 *formSpeciesIdTable;
/* 0x84 */ const struct FormChange *formChangeTable;
Expand Down Expand Up @@ -768,6 +769,7 @@ u16 GetSpeciesHeight(u16 species);
u16 GetSpeciesWeight(u16 species);
const struct LevelUpMove *GetSpeciesLevelUpLearnset(u16 species);
const u16 *GetSpeciesTeachableLearnset(u16 species);
const u16 *GetSpeciesEggMoves(u16 species);
const struct Evolution *GetSpeciesEvolutions(u16 species);
const u16 *GetSpeciesFormTable(u16 species);
const struct FormChange *GetSpeciesFormChanges(u16 species);
Expand Down
51 changes: 51 additions & 0 deletions migration_scripts/egg_move_refactor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import re
import glob

eggMoveSpecies = []

exceptions = [ # the following exceptions are hardcoded to streamline the process. you may need to manually check what happens in case you have added forms that work similar to these below
["ShellosWestSea", "Shellos"],
["OricorioBaile", "Oricorio"]
]

# convert egg_moves.h to the new format
with open("src/data/pokemon/egg_moves.h", "r") as f:
data = f.read()

data = re.sub(r"#define(.|\n)*const u16 gEggMoves\[\] = {", "static const u16 sNoneEggMoveLearnset[] = {\n MOVE_UNAVAILABLE,\n};\n", data) # remove and replace header
data = re.sub(r"\n EGG_MOVES_TERMINATOR\n};\n\n", "", data) # remove footer

for mon in re.findall(r"egg_moves\((.*),", data):
monname = re.sub(r"_", " ", mon).title().replace(" ", "")
for x in exceptions:
if monname == x[0]:
monname = x[1]
# add it to the list for later
eggMoveSpecies.append(monname)
# regex the egg_moves.h file
data = re.sub(r" egg_moves\(" + mon + r",", "static const u16 s%sEggMoveLearnset[] = {" % monname, data)

data = re.sub(r"\),\n", ",\n MOVE_UNAVAILABLE,\n};\n", data) # add terminator to each old macro

data = re.sub(r" MOVE_", " MOVE_", data) # fix indentation

with open("src/data/pokemon/egg_moves.h", "w") as f:
f.write(data)

# update gBaseStats

for file in glob.glob('./src/data/pokemon/species_info/gen_*_families.h'):
with open(file, "r") as f:
data = f.read()

# go through all Pokemon with teachable learnsets that are also in the list, then assign egg moves to them
for mon in eggMoveSpecies:
# first do the plain replacements outside of macros
data = re.sub(r"\.teachableLearnset = s" + mon + r"sTeachableLearnset,\n", ".teachableLearnset = s%sTeachableLearnset,\n .eggMoveLearnset = s%sEggMoveLearnset,\n" % (mon, mon), data)
# check for macros (since they require \ at the end of the line and do those manually)
macrocheck = re.findall(r"\.teachableLearnset = s" + mon + r"TeachableLearnset,( *)\\\\", data)
if len(macrocheck) > 0:
data = re.sub(r"\.teachableLearnset = s" + mon + r"TeachableLearnset," + macrocheck[0] + r"\\\\", ".teachableLearnset = s%sTeachableLearnset,%s\\\\\n .eggMoveLearnset = s%sEggMoveLearnset,%s\\\\" % (mon, macrocheck[0], mon, " " * (len(macrocheck[0]) + 4)), data)

with open(file, "w") as f:
f.write(data)
Loading

0 comments on commit bc9f097

Please sign in to comment.