GetBattleAnimMoveTargets fill absolute battler ids instead of relative anim ids (#4139)

Co-authored-by: ghoulslash <pokevoyager0@gmail.com>
Co-authored-by: DizzyEggg <jajkodizzy@wp.pl>
This commit is contained in:
ghoulslash 2024-02-06 03:05:26 -05:00 committed by GitHub
parent f89efad082
commit c2c97d3c1c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 68 additions and 39 deletions

View file

@ -414,8 +414,8 @@
// Below are used by AnimTask_ShakeMon2 and AnimTask_SetGrayscaleOrOriginalPal
#define ANIM_PLAYER_LEFT (MAX_BATTLERS_COUNT + 0)
#define ANIM_PLAYER_RIGHT (MAX_BATTLERS_COUNT + 1)
#define ANIM_OPPONENT_LEFT (MAX_BATTLERS_COUNT + 2)
#define ANIM_OPPONENT_LEFT (MAX_BATTLERS_COUNT + 1)
#define ANIM_PLAYER_RIGHT (MAX_BATTLERS_COUNT + 2)
#define ANIM_OPPONENT_RIGHT (MAX_BATTLERS_COUNT + 3)
#define ANIM_ATTACKER_FORCE (MAX_BATTLERS_COUNT + 4)

View file

@ -442,28 +442,44 @@ static void Cmd_unloadspritegfx(void)
static u8 GetBattleAnimMoveTargets(u8 battlerArgIndex, u8 *targets)
{
u8 numTargets = 0;
int idx = 0;
u32 battler = gBattleAnimArgs[battlerArgIndex];
switch (GetBattlerMoveTargetType(gBattleAnimAttacker, gAnimMoveIndex))
u32 battlerAnimId = gBattleAnimArgs[battlerArgIndex]; // ANIM_xx input
u32 i;
u32 ignoredTgt = gBattlerAttacker;
u32 target = GetBattlerMoveTargetType(gBattleAnimAttacker, gAnimMoveIndex);
switch (battlerAnimId)
{
case ANIM_ATTACKER:
case ANIM_ATK_PARTNER:
ignoredTgt = gBattlerTarget;
break;
case ANIM_TARGET:
case ANIM_DEF_PARTNER:
ignoredTgt = gBattlerAttacker;
break;
}
switch (target)
{
case MOVE_TARGET_FOES_AND_ALLY:
if (IS_ALIVE_AND_PRESENT(BATTLE_PARTNER(BATTLE_OPPOSITE(battler))))
if (battlerAnimId == ANIM_ATTACKER)
{
targets[idx++] = BATTLE_PARTNER(BATTLE_OPPOSITE(battler));
numTargets++;
targets[numTargets++] = gBattleAnimAttacker;
}
// fallthrough
case MOVE_TARGET_BOTH:
if (IS_ALIVE_AND_PRESENT(battler))
else
{
targets[idx++] = battler;
numTargets++;
for (i = 0; i < gBattlersCount; i++)
{
if (i != gBattleAnimAttacker && IS_ALIVE_AND_PRESENT(i))
targets[numTargets++] = i + MAX_BATTLERS_COUNT; // anim ids for battler ids
}
}
battler = BATTLE_PARTNER(battler);
if (IS_ALIVE_AND_PRESENT(battler))
break;
case MOVE_TARGET_BOTH: // all opponents
for (i = 0; i < gBattlersCount; i++)
{
targets[idx++] = battler;
numTargets++;
if (i != ignoredTgt && !IsAlly(i, ignoredTgt) && IS_ALIVE_AND_PRESENT(i))
targets[numTargets++] = i + MAX_BATTLERS_COUNT;
}
break;
default:
@ -541,7 +557,7 @@ static void Cmd_createsprite(void)
static void CreateSpriteOnTargets(const struct SpriteTemplate *template, u8 argVar, u8 battlerArgIndex, u8 argsCount, bool32 overwriteAnimTgt)
{
u32 i;
u32 i, battler;
u8 targets[MAX_BATTLERS_COUNT];
int ntargets;
s16 subpriority;
@ -560,12 +576,13 @@ static void CreateSpriteOnTargets(const struct SpriteTemplate *template, u8 argV
for (i = 0; i < ntargets; i++)
{
battler = GetAnimBattlerId(targets[i]);
if (overwriteAnimTgt)
gBattleAnimArgs[battlerArgIndex] = targets[i];
if (CreateSpriteAndAnimate(template,
GetBattlerSpriteCoord(targets[i], BATTLER_COORD_X_2),
GetBattlerSpriteCoord(targets[i], BATTLER_COORD_Y_PIC_OFFSET),
GetBattlerSpriteCoord(battler, BATTLER_COORD_X_2),
GetBattlerSpriteCoord(battler, BATTLER_COORD_Y_PIC_OFFSET),
subpriority) != MAX_SPRITES) // Don't increment the task count if the sprite couldn't be created(i.e. there are too many created sprites atm).
{
gAnimVisualTaskCount++;
@ -904,14 +921,20 @@ static void Cmd_monbg(void)
u8 GetAnimBattlerId(u8 wantedBattler)
{
if (wantedBattler == ANIM_ATTACKER)
switch (wantedBattler)
{
case ANIM_ATTACKER:
default:
return gBattleAnimAttacker;
else if (wantedBattler == ANIM_TARGET)
case ANIM_TARGET:
return gBattleAnimTarget;
else if (wantedBattler == ANIM_ATK_PARTNER)
case ANIM_ATK_PARTNER:
return BATTLE_PARTNER(gBattleAnimAttacker);
else
case ANIM_DEF_PARTNER:
return BATTLE_PARTNER(gBattleAnimTarget);
case ANIM_PLAYER_LEFT ... ANIM_OPPONENT_RIGHT:
return wantedBattler - MAX_BATTLERS_COUNT;
}
}
bool8 IsBattlerSpriteVisible(u8 battlerId)

View file

@ -309,45 +309,51 @@ u8 GetBattlerYCoordWithElevation(u8 battlerId)
u8 GetAnimBattlerSpriteId(u8 animBattler)
{
u8 *sprites;
u32 partner;
if (animBattler == ANIM_ATTACKER)
switch (animBattler)
{
case ANIM_ATTACKER:
if (IsBattlerSpritePresent(gBattleAnimAttacker))
{
sprites = gBattlerSpriteIds;
return sprites[gBattleAnimAttacker];
return gBattlerSpriteIds[gBattleAnimAttacker];
}
else
{
return SPRITE_NONE;
}
}
else if (animBattler == ANIM_TARGET)
{
break;
case ANIM_TARGET:
if (IsBattlerSpritePresent(gBattleAnimTarget))
{
sprites = gBattlerSpriteIds;
return sprites[gBattleAnimTarget];
return gBattlerSpriteIds[gBattleAnimTarget];
}
else
{
return SPRITE_NONE;
}
}
else if (animBattler == ANIM_ATK_PARTNER)
{
break;
case ANIM_ATK_PARTNER:
if (!IsBattlerSpriteVisible(BATTLE_PARTNER(gBattleAnimAttacker)))
return SPRITE_NONE;
else
return gBattlerSpriteIds[BATTLE_PARTNER(gBattleAnimAttacker)];
}
else
{
break;
case ANIM_DEF_PARTNER:
if (IsBattlerSpriteVisible(BATTLE_PARTNER(gBattleAnimTarget)))
return gBattlerSpriteIds[BATTLE_PARTNER(gBattleAnimTarget)];
else
return SPRITE_NONE;
break;
case ANIM_PLAYER_LEFT ... ANIM_OPPONENT_RIGHT:
partner = animBattler - MAX_BATTLERS_COUNT;
if (IsBattlerSpriteVisible(partner))
return gBattlerSpriteIds[partner];
else
return SPRITE_NONE;
break;
default:
return SPRITE_NONE;
}
}