fix GetBattleAnimMoveTargets logic (#3278)

* fix GetBattleAnimMoveTargets logic

* more efficient GetBattleAnimMoveTargets

---------

Co-authored-by: ghoulslash <pokevoyager0@gmail.com>
This commit is contained in:
ghoulslash 2023-09-05 03:21:14 -04:00 committed by GitHub
parent 2fa4206bf1
commit 675aa5db41
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 22 deletions

View File

@ -54,7 +54,8 @@
#define WEATHER_HAS_EFFECT ((!IsAbilityOnField(ABILITY_CLOUD_NINE) && !IsAbilityOnField(ABILITY_AIR_LOCK))) #define WEATHER_HAS_EFFECT ((!IsAbilityOnField(ABILITY_CLOUD_NINE) && !IsAbilityOnField(ABILITY_AIR_LOCK)))
#define IS_WHOLE_SIDE_ALIVE(battler)((IsBattlerAlive(battler) && IsBattlerAlive(BATTLE_PARTNER(battler)))) #define IS_WHOLE_SIDE_ALIVE(battler) ((IsBattlerAlive(battler) && IsBattlerAlive(BATTLE_PARTNER(battler))))
#define IS_ALIVE_AND_PRESENT(battler) (IsBattlerAlive(battler) && IsBattlerSpritePresent(battler))
// for Natural Gift and Fling // for Natural Gift and Fling
struct TypePower struct TypePower

View File

@ -435,32 +435,27 @@ static void Cmd_unloadspritegfx(void)
static u8 GetBattleAnimMoveTargets(u8 battlerArgIndex, u8 *targets) static u8 GetBattleAnimMoveTargets(u8 battlerArgIndex, u8 *targets)
{ {
u8 numTargets = 1; u8 numTargets = 0;
int idx = 0;
u32 battler = gBattleAnimArgs[battlerArgIndex];
switch (GetBattlerMoveTargetType(gBattleAnimAttacker, gAnimMoveIndex)) switch (GetBattlerMoveTargetType(gBattleAnimAttacker, gAnimMoveIndex))
{ {
case MOVE_TARGET_BOTH:
targets[0] = gBattleAnimArgs[battlerArgIndex];
numTargets = 1;
if (IsBattlerAlive(BATTLE_PARTNER(targets[0])))
{
targets[1] = BATTLE_PARTNER(targets[0]);
numTargets = 2;
}
break;
case MOVE_TARGET_FOES_AND_ALLY: case MOVE_TARGET_FOES_AND_ALLY:
targets[0] = gBattleAnimArgs[battlerArgIndex]; if (IS_ALIVE_AND_PRESENT(BATTLE_PARTNER(BATTLE_OPPOSITE(battler)))) {
numTargets = 1; targets[idx++] = BATTLE_PARTNER(BATTLE_OPPOSITE(battler));
if (IsBattlerAlive(BATTLE_PARTNER(targets[0])))
{
targets[1] = BATTLE_PARTNER(targets[0]);
numTargets++; numTargets++;
} }
// fallthrough
if (IsBattlerAlive(BATTLE_PARTNER(BATTLE_OPPOSITE(targets[0])))) case MOVE_TARGET_BOTH:
{ if (IS_ALIVE_AND_PRESENT(battler)) {
targets[2] = BATTLE_PARTNER(BATTLE_OPPOSITE(targets[0])); targets[idx++] = battler;
numTargets++; numTargets++;
} }
battler = BATTLE_PARTNER(battler);
if (IS_ALIVE_AND_PRESENT(battler)) {
targets[idx++] = battler;
numTargets++;
}
break; break;
default: default:
targets[0] = gBattleAnimArgs[battlerArgIndex]; // original targets[0] = gBattleAnimArgs[battlerArgIndex]; // original
@ -551,7 +546,9 @@ static void CreateSpriteOnTargets(const struct SpriteTemplate *template, u8 argV
subpriority = GetSubpriorityForMoveAnim(argVar); subpriority = GetSubpriorityForMoveAnim(argVar);
ntargets = GetBattleAnimMoveTargets(battlerArgIndex, targets); ntargets = GetBattleAnimMoveTargets(battlerArgIndex, targets);
if (ntargets == 0)
return;
for (i = 0; i < ntargets; i++) { for (i = 0; i < ntargets; i++) {
if (overwriteAnimTgt) if (overwriteAnimTgt)
@ -676,7 +673,9 @@ static void Cmd_createvisualtaskontargets(void)
} }
numArgs = GetBattleAnimMoveTargets(battlerArgIndex, targets); numArgs = GetBattleAnimMoveTargets(battlerArgIndex, targets);
if (numArgs == 0)
return;
for (i = 0; i < numArgs; i++) for (i = 0; i < numArgs; i++)
{ {
gBattleAnimArgs[battlerArgIndex] = targets[i]; gBattleAnimArgs[battlerArgIndex] = targets[i];