Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor move animations #4683

Merged
merged 15 commits into from
Jun 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2,190 changes: 620 additions & 1,570 deletions data/battle_anim_scripts.s

Large diffs are not rendered by default.

940 changes: 940 additions & 0 deletions include/battle_anim_scripts.h

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions include/pokemon.h
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,7 @@ struct MoveInfo
u8 contestCategory:3;
u8 contestComboStarterId;
u8 contestComboMoves[MAX_COMBO_MOVES];
const u8 *battleAnimScript;
};

#define EFFECTS_ARR(...) (const struct AdditionalEffect[]) {__VA_ARGS__}
Expand Down Expand Up @@ -866,5 +867,6 @@ u16 GetSpeciesPreEvolution(u16 species);
void HealPokemon(struct Pokemon *mon);
void HealBoxPokemon(struct BoxPokemon *boxMon);
const u8 *GetMoveName(u16 moveId);
const u8 *GetMoveAnimationScript(u16 moveId);

#endif // GUARD_POKEMON_H
63 changes: 63 additions & 0 deletions migration_scripts/battle_anim_moves_refactor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import re

def IsCommaMissing(line: str):
sanitized_line = line.removesuffix('\n').strip()
if sanitized_line.endswith('{') or sanitized_line.endswith('(') or sanitized_line.endswith(','):
return False
if not re.search(r'\.[A-Za-z0-9_]+', sanitized_line):
return False
return True

input_file = open('./src/data/moves_info.h', 'r')
lines = input_file.readlines()
input_file.close()


battle_anim_lines = []
moves_info_lines = []

move = None
bracketCount = 0
for line in lines:
m = re.search(r'\[MOVE_([A-Za-z0-9_]+)\] =', line)
if m:
move = m.group(1)
bracketCount = 0
battle_anim_lines.append('extern const u8 Move_' + move + '[];\n')

if move and re.search(r'\{', line):
bracketCount = bracketCount + 1

if move and re.search(r'\}', line):
if (bracketCount == 1):
moves_info_lines.append(8 * ' ' + '.battleAnimScript = Move_' + move + ',\n')
move = None
bracketCount = bracketCount - 1

comment_split = line.split('//')
if move and IsCommaMissing(comment_split[0]):
line = comment_split[0].removesuffix('\n') + ',' + line[len(comment_split[0]):-1] + '\n'


moves_info_lines.append(line)

output_file_mi = open('./src/data/moves_info.h', 'w')
output_file_mi.writelines(moves_info_lines)
output_file_mi.close()

output_file_bas = open('./include/battle_anim_scripts.h', 'w')
output_file_bas.writelines('#ifndef GUARD_BATTLE_ANIM_SCRIPTS_H\n')
output_file_bas.writelines('#define GUARD_BATTLE_ANIM_SCRIPTS_H\n\n')
output_file_bas.writelines(battle_anim_lines)
output_file_bas.writelines('\n#endif // GUARD_BATTLE_ANIM_SCRIPTS_H\n')
output_file_bas.close()

b_anim_scripts_s = open('./data/battle_anim_scripts.s', 'r')
lines = b_anim_scripts_s.read()
b_anim_scripts_s.close()

lines = re.sub(r'(Move_[A-Za-z0-9_]*)([:]+)', r'\1::', lines)

b_anim_scripts_s = open('./data/battle_anim_scripts.s', 'w')
b_anim_scripts_s.write(lines)
b_anim_scripts_s.close()
37 changes: 17 additions & 20 deletions src/battle_anim.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@

extern const u16 gMovesWithQuietBGM[];
extern const u8 *const gBattleAnims_General[];
extern const u8 *const gBattleAnims_Moves[];
extern const u8 *const gBattleAnims_Special[];
extern const u8 *const gBattleAnims_StatusConditions[];

Expand Down Expand Up @@ -234,7 +233,6 @@ static void Nop(void)
void LaunchBattleAnimation(u32 animType, u32 animId)
{
s32 i;
const u8 *const *animsTable;

if (gTestRunnerEnabled)
{
Expand All @@ -249,23 +247,6 @@ void LaunchBattleAnimation(u32 animType, u32 animId)
}
}

switch (animType)
{
case ANIM_TYPE_GENERAL:
default:
animsTable = gBattleAnims_General;
break;
case ANIM_TYPE_MOVE:
animsTable = gBattleAnims_Moves;
break;
case ANIM_TYPE_STATUS:
animsTable = gBattleAnims_StatusConditions;
break;
case ANIM_TYPE_SPECIAL:
animsTable = gBattleAnims_Special;
break;
}

sAnimHideHpBoxes = !(animType == ANIM_TYPE_MOVE && animId == MOVE_TRANSFORM);
if (animType != ANIM_TYPE_MOVE)
{
Expand Down Expand Up @@ -322,7 +303,23 @@ void LaunchBattleAnimation(u32 animType, u32 animId)

sMonAnimTaskIdArray[0] = TASK_NONE;
sMonAnimTaskIdArray[1] = TASK_NONE;
sBattleAnimScriptPtr = animsTable[animId];

switch (animType)
{
case ANIM_TYPE_GENERAL:
default:
sBattleAnimScriptPtr = gBattleAnims_General[animId];
break;
case ANIM_TYPE_MOVE:
sBattleAnimScriptPtr = GetMoveAnimationScript(animId);
break;
case ANIM_TYPE_STATUS:
sBattleAnimScriptPtr = gBattleAnims_StatusConditions[animId];
break;
case ANIM_TYPE_SPECIAL:
sBattleAnimScriptPtr = gBattleAnims_Special[animId];
break;
}
gAnimScriptActive = TRUE;
sAnimFramesToWait = 0;
gAnimScriptCallback = RunAnimScriptCommand;
Expand Down
2 changes: 1 addition & 1 deletion src/battle_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -3390,7 +3390,7 @@ const u8* FaintClearSetData(u32 battler)
gBattleStruct->zmove.toBeUsed[battler] = MOVE_NONE;
gBattleStruct->zmove.effect = EFFECT_HIT;
// Clear Dynamax data
UndoDynamax(battler);
UndoDynamax(battler);

return result;
}
Expand Down
Loading
Loading