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 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
struct TypePower

View File

@ -435,30 +435,25 @@ static void Cmd_unloadspritegfx(void)
static u8 GetBattleAnimMoveTargets(u8 battlerArgIndex, u8 *targets)
{
u8 numTargets = 1;
u8 numTargets = 0;
int idx = 0;
u32 battler = gBattleAnimArgs[battlerArgIndex];
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:
targets[0] = gBattleAnimArgs[battlerArgIndex];
numTargets = 1;
if (IsBattlerAlive(BATTLE_PARTNER(targets[0])))
{
targets[1] = BATTLE_PARTNER(targets[0]);
if (IS_ALIVE_AND_PRESENT(BATTLE_PARTNER(BATTLE_OPPOSITE(battler)))) {
targets[idx++] = BATTLE_PARTNER(BATTLE_OPPOSITE(battler));
numTargets++;
}
if (IsBattlerAlive(BATTLE_PARTNER(BATTLE_OPPOSITE(targets[0]))))
{
targets[2] = BATTLE_PARTNER(BATTLE_OPPOSITE(targets[0]));
// fallthrough
case MOVE_TARGET_BOTH:
if (IS_ALIVE_AND_PRESENT(battler)) {
targets[idx++] = battler;
numTargets++;
}
battler = BATTLE_PARTNER(battler);
if (IS_ALIVE_AND_PRESENT(battler)) {
targets[idx++] = battler;
numTargets++;
}
break;
@ -551,6 +546,8 @@ static void CreateSpriteOnTargets(const struct SpriteTemplate *template, u8 argV
subpriority = GetSubpriorityForMoveAnim(argVar);
ntargets = GetBattleAnimMoveTargets(battlerArgIndex, targets);
if (ntargets == 0)
return;
for (i = 0; i < ntargets; i++) {
@ -676,6 +673,8 @@ static void Cmd_createvisualtaskontargets(void)
}
numArgs = GetBattleAnimMoveTargets(battlerArgIndex, targets);
if (numArgs == 0)
return;
for (i = 0; i < numArgs; i++)
{