pokeemerald/src/battle_anim_mon_movement.c

1138 lines
35 KiB
C
Raw Normal View History

2018-10-07 17:45:37 +02:00
#include "global.h"
#include "battle.h"
#include "battle_anim.h"
#include "sprite.h"
#include "task.h"
#include "trig.h"
2020-02-20 22:22:33 +01:00
static void AnimTask_ShakeMon_Step(u8 taskId);
static void AnimTask_ShakeMon2_Step(u8 taskId);
static void AnimTask_ShakeMonInPlace_Step(u8 taskId);
static void AnimTask_ShakeAndSinkMon_Step(u8 taskId);
static void AnimTask_TranslateMonElliptical_Step(u8 taskId);
2018-12-03 14:49:16 +01:00
static void DoHorizontalLunge(struct Sprite *sprite);
static void ReverseHorizontalLungeDirection(struct Sprite *sprite);
static void DoVerticalDip(struct Sprite *sprite);
2022-07-29 17:15:33 +02:00
static void ReverseVerticalDipDirection(struct Sprite *sprite);
2018-12-03 14:49:16 +01:00
static void SlideMonToOriginalPos(struct Sprite *sprite);
2020-02-20 22:22:33 +01:00
static void SlideMonToOriginalPos_Step(struct Sprite *sprite);
2018-12-03 14:49:16 +01:00
static void SlideMonToOffset(struct Sprite *sprite);
2020-02-20 06:04:42 +01:00
static void SlideMonToOffsetAndBack(struct Sprite *sprite);
2020-02-20 22:22:33 +01:00
static void SlideMonToOffsetAndBack_End(struct Sprite *sprite);
static void AnimTask_WindUpLunge_Step1(u8 taskId);
static void AnimTask_WindUpLunge_Step2(u8 taskId);
static void AnimTask_SwayMonStep(u8 taskId);
static void AnimTask_ScaleMonAndRestore_Step(u8 taskId);
static void AnimTask_RotateMonSpriteToSide_Step(u8 taskId);
static void AnimTask_ShakeTargetBasedOnMovePowerOrDmg_Step(u8 taskId);
static void AnimTask_SlideOffScreen_Step(u8 taskId);
2020-04-16 16:52:25 +02:00
static void AnimTask_RotateVerticallyStep(u8 taskId);
2018-10-07 17:45:37 +02:00
2018-12-03 13:37:32 +01:00
const struct SpriteTemplate gHorizontalLungeSpriteTemplate =
{
.tileTag = 0,
.paletteTag = 0,
.oam = &gDummyOamData,
.anims = gDummySpriteAnimTable,
.images = NULL,
.affineAnims = gDummySpriteAffineAnimTable,
.callback = DoHorizontalLunge,
};
const struct SpriteTemplate gVerticalDipSpriteTemplate =
{
.tileTag = 0,
.paletteTag = 0,
.oam = &gDummyOamData,
.anims = gDummySpriteAnimTable,
.images = NULL,
.affineAnims = gDummySpriteAffineAnimTable,
.callback = DoVerticalDip,
};
const struct SpriteTemplate gSlideMonToOriginalPosSpriteTemplate =
{
.tileTag = 0,
.paletteTag = 0,
.oam = &gDummyOamData,
.anims = gDummySpriteAnimTable,
.images = NULL,
.affineAnims = gDummySpriteAffineAnimTable,
.callback = SlideMonToOriginalPos,
};
const struct SpriteTemplate gSlideMonToOffsetSpriteTemplate =
{
.tileTag = 0,
.paletteTag = 0,
.oam = &gDummyOamData,
.anims = gDummySpriteAnimTable,
.images = NULL,
.affineAnims = gDummySpriteAffineAnimTable,
.callback = SlideMonToOffset,
};
2020-02-20 06:04:42 +01:00
const struct SpriteTemplate gSlideMonToOffsetAndBackSpriteTemplate =
2018-12-03 13:37:32 +01:00
{
.tileTag = 0,
.paletteTag = 0,
.oam = &gDummyOamData,
.anims = gDummySpriteAnimTable,
.images = NULL,
.affineAnims = gDummySpriteAffineAnimTable,
2020-02-20 06:04:42 +01:00
.callback = SlideMonToOffsetAndBack,
2018-12-03 13:37:32 +01:00
};
2018-10-07 17:45:37 +02:00
// Task to facilitate simple shaking of a pokemon's picture in battle.
// The shaking alternates between the original position and the target position.
// arg 0: anim battler
// arg 1: x pixel offset
// arg 2: y pixel offset
// arg 3: num times to shake
// arg 4: frame delay
void AnimTask_ShakeMon(u8 taskId)
{
u8 spriteId;
spriteId = GetAnimBattlerSpriteId(gBattleAnimArgs[0]);
2021-02-20 06:30:37 +01:00
if (spriteId == SPRITE_NONE)
2018-10-07 17:45:37 +02:00
{
DestroyAnimVisualTask(taskId);
return;
}
2021-07-07 15:11:52 +02:00
gSprites[spriteId].x2 = gBattleAnimArgs[1];
gSprites[spriteId].y2 = gBattleAnimArgs[2];
2018-10-07 19:19:13 +02:00
gTasks[taskId].data[0] = spriteId;
gTasks[taskId].data[1] = gBattleAnimArgs[3];
gTasks[taskId].data[2] = gBattleAnimArgs[4];
gTasks[taskId].data[3] = gBattleAnimArgs[4];
gTasks[taskId].data[4] = gBattleAnimArgs[1];
gTasks[taskId].data[5] = gBattleAnimArgs[2];
2020-02-20 22:22:33 +01:00
gTasks[taskId].func = AnimTask_ShakeMon_Step;
2022-08-17 17:44:20 +02:00
gTasks[taskId].func(taskId);
2018-10-07 17:45:37 +02:00
}
2020-02-20 22:22:33 +01:00
static void AnimTask_ShakeMon_Step(u8 taskId)
2018-10-07 17:45:37 +02:00
{
2018-10-07 19:19:13 +02:00
if (gTasks[taskId].data[3] == 0)
2018-10-07 17:45:37 +02:00
{
2021-07-07 15:11:52 +02:00
if (gSprites[gTasks[taskId].data[0]].x2 == 0)
2018-10-07 17:45:37 +02:00
{
2021-07-07 15:11:52 +02:00
gSprites[gTasks[taskId].data[0]].x2 = gTasks[taskId].data[4];
2018-10-07 17:45:37 +02:00
}
else
{
2021-07-07 15:11:52 +02:00
gSprites[gTasks[taskId].data[0]].x2 = 0;
2018-10-07 17:45:37 +02:00
}
2021-07-07 15:11:52 +02:00
if (gSprites[gTasks[taskId].data[0]].y2 == 0)
2018-10-07 17:45:37 +02:00
{
2021-07-07 15:11:52 +02:00
gSprites[gTasks[taskId].data[0]].y2 = gTasks[taskId].data[5];
2018-10-07 17:45:37 +02:00
}
else
{
2021-07-07 15:11:52 +02:00
gSprites[gTasks[taskId].data[0]].y2 = 0;
2018-10-07 17:45:37 +02:00
}
2018-10-07 19:19:13 +02:00
gTasks[taskId].data[3] = gTasks[taskId].data[2];
if (--gTasks[taskId].data[1] == 0)
2018-10-07 17:45:37 +02:00
{
2021-07-07 15:11:52 +02:00
gSprites[gTasks[taskId].data[0]].x2 = 0;
gSprites[gTasks[taskId].data[0]].y2 = 0;
2018-10-07 17:45:37 +02:00
DestroyAnimVisualTask(taskId);
return;
}
}
else
{
2018-10-07 19:19:13 +02:00
gTasks[taskId].data[3]--;
2018-10-07 17:45:37 +02:00
}
}
// Task to facilitate simple shaking of a pokemon's picture in battle.
// The shaking alternates between the positive and negative versions of the specified pixel offsets.
// arg 0: anim battler
// arg 1: x pixel offset
// arg 2: y pixel offset
// arg 3: num times to shake
// arg 4: frame delay
void AnimTask_ShakeMon2(u8 taskId)
{
u8 spriteId;
2022-08-17 17:44:20 +02:00
bool8 abort = FALSE;
2018-10-07 17:45:37 +02:00
u8 battlerId;
2020-02-15 00:11:04 +01:00
if (gBattleAnimArgs[0] < MAX_BATTLERS_COUNT)
2018-10-07 17:45:37 +02:00
{
spriteId = GetAnimBattlerSpriteId(gBattleAnimArgs[0]);
2021-02-20 06:30:37 +01:00
if (spriteId == SPRITE_NONE)
2022-08-17 17:44:20 +02:00
abort = TRUE;
2018-10-07 17:45:37 +02:00
}
else if (gBattleAnimArgs[0] != ANIM_ATTACKER_FORCE)
2018-10-07 17:45:37 +02:00
{
switch (gBattleAnimArgs[0])
{
case ANIM_PLAYER_LEFT:
2018-10-07 17:45:37 +02:00
battlerId = GetBattlerAtPosition(B_POSITION_PLAYER_LEFT);
break;
case ANIM_PLAYER_RIGHT:
2018-10-07 17:45:37 +02:00
battlerId = GetBattlerAtPosition(B_POSITION_PLAYER_RIGHT);
break;
case ANIM_OPPONENT_LEFT:
2018-10-07 17:45:37 +02:00
battlerId = GetBattlerAtPosition(B_POSITION_OPPONENT_LEFT);
break;
case ANIM_OPPONENT_RIGHT:
2018-10-07 17:45:37 +02:00
default:
battlerId = GetBattlerAtPosition(B_POSITION_OPPONENT_RIGHT);
break;
}
if (IsBattlerSpriteVisible(battlerId) == FALSE)
2022-08-17 17:44:20 +02:00
abort = TRUE;
2018-10-07 17:45:37 +02:00
spriteId = gBattlerSpriteIds[battlerId];
}
else
{
spriteId = gBattlerSpriteIds[gBattleAnimAttacker];
}
2022-08-17 17:44:20 +02:00
if (abort)
2018-10-07 17:45:37 +02:00
{
DestroyAnimVisualTask(taskId);
return;
}
2021-07-07 15:11:52 +02:00
gSprites[spriteId].x2 = gBattleAnimArgs[1];
gSprites[spriteId].y2 = gBattleAnimArgs[2];
2018-10-07 19:19:13 +02:00
gTasks[taskId].data[0] = spriteId;
gTasks[taskId].data[1] = gBattleAnimArgs[3];
gTasks[taskId].data[2] = gBattleAnimArgs[4];
gTasks[taskId].data[3] = gBattleAnimArgs[4];
gTasks[taskId].data[4] = gBattleAnimArgs[1];
gTasks[taskId].data[5] = gBattleAnimArgs[2];
2020-02-20 22:22:33 +01:00
gTasks[taskId].func = AnimTask_ShakeMon2_Step;
2018-10-07 19:19:13 +02:00
gTasks[taskId].func(taskId);
2018-10-07 17:45:37 +02:00
}
2020-02-20 22:22:33 +01:00
static void AnimTask_ShakeMon2_Step(u8 taskId)
2018-10-07 17:45:37 +02:00
{
2018-10-07 19:19:13 +02:00
if (gTasks[taskId].data[3] == 0)
2018-10-07 17:45:37 +02:00
{
2021-07-07 15:11:52 +02:00
if (gSprites[gTasks[taskId].data[0]].x2 == gTasks[taskId].data[4])
gSprites[gTasks[taskId].data[0]].x2 = -gTasks[taskId].data[4];
2018-10-07 17:45:37 +02:00
else
2021-07-07 15:11:52 +02:00
gSprites[gTasks[taskId].data[0]].x2 = gTasks[taskId].data[4];
2018-10-07 17:45:37 +02:00
2021-07-07 15:11:52 +02:00
if (gSprites[gTasks[taskId].data[0]].y2 == gTasks[taskId].data[5])
gSprites[gTasks[taskId].data[0]].y2 = -gTasks[taskId].data[5];
2018-10-07 17:45:37 +02:00
else
2021-07-07 15:11:52 +02:00
gSprites[gTasks[taskId].data[0]].y2 = gTasks[taskId].data[5];
2018-10-07 17:45:37 +02:00
2018-10-07 19:19:13 +02:00
gTasks[taskId].data[3] = gTasks[taskId].data[2];
if (--gTasks[taskId].data[1] == 0)
2018-10-07 17:45:37 +02:00
{
2021-07-07 15:11:52 +02:00
gSprites[gTasks[taskId].data[0]].x2 = 0;
gSprites[gTasks[taskId].data[0]].y2 = 0;
2018-10-07 17:45:37 +02:00
DestroyAnimVisualTask(taskId);
return;
}
}
else
{
2018-10-07 19:19:13 +02:00
gTasks[taskId].data[3]--;
2018-10-07 17:45:37 +02:00
}
}
// Task to facilitate simple shaking of a pokemon's picture in battle.
// The shaking alternates between the positive and negative versions of the specified pixel offsets
// with respect to the current location of the mon's picture.
// arg 0: battler
// arg 1: x offset
// arg 2: y offset
// arg 3: num shakes
// arg 4: delay
void AnimTask_ShakeMonInPlace(u8 taskId)
{
u8 spriteId = GetAnimBattlerSpriteId(gBattleAnimArgs[0]);
2021-02-20 06:30:37 +01:00
if (spriteId == SPRITE_NONE)
2018-10-07 17:45:37 +02:00
{
DestroyAnimVisualTask(taskId);
return;
}
2021-07-07 15:11:52 +02:00
gSprites[spriteId].x2 += gBattleAnimArgs[1];
gSprites[spriteId].y2 += gBattleAnimArgs[2];
2018-10-07 19:19:13 +02:00
gTasks[taskId].data[0] = spriteId;
gTasks[taskId].data[1] = 0;
gTasks[taskId].data[2] = gBattleAnimArgs[3];
gTasks[taskId].data[3] = 0;
gTasks[taskId].data[4] = gBattleAnimArgs[4];
gTasks[taskId].data[5] = gBattleAnimArgs[1] * 2;
gTasks[taskId].data[6] = gBattleAnimArgs[2] * 2;
2020-02-20 22:22:33 +01:00
gTasks[taskId].func = AnimTask_ShakeMonInPlace_Step;
2018-10-07 19:19:13 +02:00
gTasks[taskId].func(taskId);
2018-10-07 17:45:37 +02:00
}
2020-02-20 22:22:33 +01:00
static void AnimTask_ShakeMonInPlace_Step(u8 taskId)
2018-10-07 17:45:37 +02:00
{
2018-10-07 19:19:13 +02:00
if (gTasks[taskId].data[3] == 0)
2018-10-07 17:45:37 +02:00
{
2018-10-07 19:19:13 +02:00
if (gTasks[taskId].data[1] & 1)
2018-10-07 17:45:37 +02:00
{
2021-07-07 15:11:52 +02:00
gSprites[gTasks[taskId].data[0]].x2 += gTasks[taskId].data[5];
gSprites[gTasks[taskId].data[0]].y2 += gTasks[taskId].data[6];
2018-10-07 17:45:37 +02:00
}
else
{
2021-07-07 15:11:52 +02:00
gSprites[gTasks[taskId].data[0]].x2 -= gTasks[taskId].data[5];
gSprites[gTasks[taskId].data[0]].y2 -= gTasks[taskId].data[6];
2018-10-07 17:45:37 +02:00
}
2018-10-07 19:19:13 +02:00
gTasks[taskId].data[3] = gTasks[taskId].data[4];
if (++gTasks[taskId].data[1] >= gTasks[taskId].data[2])
2018-10-07 17:45:37 +02:00
{
2018-10-07 19:19:13 +02:00
if (gTasks[taskId].data[1] & 1)
2018-10-07 17:45:37 +02:00
{
2021-07-07 15:11:52 +02:00
gSprites[gTasks[taskId].data[0]].x2 += gTasks[taskId].data[5] / 2;
gSprites[gTasks[taskId].data[0]].y2 += gTasks[taskId].data[6] / 2;
2018-10-07 17:45:37 +02:00
}
else
{
2021-07-07 15:11:52 +02:00
gSprites[gTasks[taskId].data[0]].x2 -= gTasks[taskId].data[5] / 2;
gSprites[gTasks[taskId].data[0]].y2 -= gTasks[taskId].data[6] / 2;
2018-10-07 17:45:37 +02:00
}
DestroyAnimVisualTask(taskId);
return;
}
}
else
{
2018-10-07 19:19:13 +02:00
gTasks[taskId].data[3]--;
2018-10-07 17:45:37 +02:00
}
}
// Shakes a mon bg horizontally and moves it downward linearly.
// arg 0: battler
// arg 1: x offset
// arg 2: frame delay between each movement
// arg 3: downward speed (subpixel)
// arg 4: duration
void AnimTask_ShakeAndSinkMon(u8 taskId)
{
u8 spriteId = GetAnimBattlerSpriteId(gBattleAnimArgs[0]);
2021-06-08 12:13:40 +02:00
if (spriteId == SPRITE_NONE)
{
DestroyAnimVisualTask(taskId);
return;
}
2021-07-07 15:11:52 +02:00
gSprites[spriteId].x2 = gBattleAnimArgs[1];
2018-10-07 19:19:13 +02:00
gTasks[taskId].data[0] = spriteId;
gTasks[taskId].data[1] = gBattleAnimArgs[1];
gTasks[taskId].data[2] = gBattleAnimArgs[2];
gTasks[taskId].data[3] = gBattleAnimArgs[3];
gTasks[taskId].data[4] = gBattleAnimArgs[4];
2020-02-20 22:22:33 +01:00
gTasks[taskId].func = AnimTask_ShakeAndSinkMon_Step;
2018-10-07 19:19:13 +02:00
gTasks[taskId].func(taskId);
2018-10-07 17:45:37 +02:00
}
2020-02-20 22:22:33 +01:00
static void AnimTask_ShakeAndSinkMon_Step(u8 taskId)
2018-10-07 17:45:37 +02:00
{
2022-08-17 17:44:20 +02:00
u8 spriteId = gTasks[taskId].data[0];
s16 x = gTasks[taskId].data[1];
2018-10-07 19:19:13 +02:00
if (gTasks[taskId].data[2] == gTasks[taskId].data[8]++)
2018-10-07 17:45:37 +02:00
{
2018-10-07 19:19:13 +02:00
gTasks[taskId].data[8] = 0;
2021-07-07 15:11:52 +02:00
if (gSprites[spriteId].x2 == x)
2018-10-07 17:45:37 +02:00
x = -x;
2021-07-07 15:11:52 +02:00
gSprites[spriteId].x2 += x;
2018-10-07 17:45:37 +02:00
}
2018-10-07 19:19:13 +02:00
gTasks[taskId].data[1] = x;
gTasks[taskId].data[9] += gTasks[taskId].data[3];
2021-07-07 15:11:52 +02:00
gSprites[spriteId].y2 = gTasks[taskId].data[9] >> 8;
2018-10-07 19:19:13 +02:00
if (--gTasks[taskId].data[4] == 0)
2018-10-07 17:45:37 +02:00
{
DestroyAnimVisualTask(taskId);
return;
}
}
// Moves a mon bg picture along an elliptical path that begins
// and ends at the mon's origin location.
// arg 0: battler
// arg 1: ellipse width
// arg 2: ellipse height
// arg 3: num loops
// arg 4: speed (valid values are 0-5)
void AnimTask_TranslateMonElliptical(u8 taskId)
{
u8 i;
2022-08-17 17:44:20 +02:00
u8 wavePeriod = 1;
u8 spriteId = GetAnimBattlerSpriteId(gBattleAnimArgs[0]);
2018-10-07 17:45:37 +02:00
if (gBattleAnimArgs[4] > 5)
gBattleAnimArgs[4] = 5;
for (i = 0; i < gBattleAnimArgs[4]; i++)
{
wavePeriod <<= 1;
}
2018-10-07 19:19:13 +02:00
gTasks[taskId].data[0] = spriteId;
gTasks[taskId].data[1] = gBattleAnimArgs[1];
gTasks[taskId].data[2] = gBattleAnimArgs[2];
gTasks[taskId].data[3] = gBattleAnimArgs[3];
gTasks[taskId].data[4] = wavePeriod;
2020-02-20 22:22:33 +01:00
gTasks[taskId].func = AnimTask_TranslateMonElliptical_Step;
2018-10-07 19:19:13 +02:00
gTasks[taskId].func(taskId);
2018-10-07 17:45:37 +02:00
}
2020-02-20 22:22:33 +01:00
static void AnimTask_TranslateMonElliptical_Step(u8 taskId)
2018-10-07 17:45:37 +02:00
{
2018-10-07 19:19:13 +02:00
u8 spriteId = gTasks[taskId].data[0];
2021-07-07 15:11:52 +02:00
gSprites[spriteId].x2 = Sin(gTasks[taskId].data[5], gTasks[taskId].data[1]);
gSprites[spriteId].y2 = -Cos(gTasks[taskId].data[5], gTasks[taskId].data[2]);
gSprites[spriteId].y2 += gTasks[taskId].data[2];
2018-10-07 19:19:13 +02:00
gTasks[taskId].data[5] += gTasks[taskId].data[4];
gTasks[taskId].data[5] &= 0xff;
2018-10-07 17:45:37 +02:00
2018-10-07 19:19:13 +02:00
if (gTasks[taskId].data[5] == 0)
gTasks[taskId].data[3]--;
2018-10-07 17:45:37 +02:00
2018-10-07 19:19:13 +02:00
if (gTasks[taskId].data[3] == 0)
2018-10-07 17:45:37 +02:00
{
2021-07-07 15:11:52 +02:00
gSprites[spriteId].x2 = 0;
gSprites[spriteId].y2 = 0;
2018-10-07 17:45:37 +02:00
DestroyAnimVisualTask(taskId);
return;
}
}
// Moves a mon bg picture along an elliptical path that begins
// and ends at the mon's origin location. Reverses the direction
// of the path if it's not on the player's side of the battle.
// arg 0: battler
// arg 1: ellipse width
// arg 2: ellipse height
// arg 3: num loops
// arg 4: speed (valid values are 0-5)
void AnimTask_TranslateMonEllipticalRespectSide(u8 taskId)
{
if (GetBattlerSide(gBattleAnimAttacker) != B_SIDE_PLAYER)
gBattleAnimArgs[1] = -gBattleAnimArgs[1];
AnimTask_TranslateMonElliptical(taskId);
}
// Performs a simple horizontal lunge, where the mon moves
// horizontally, and then moves back in the opposite direction.
// arg 0: duration of single lunge direction
// arg 1: x pixel delta that is applied each frame
2018-12-03 14:49:16 +01:00
static void DoHorizontalLunge(struct Sprite *sprite)
2018-10-07 17:45:37 +02:00
{
sprite->invisible = TRUE;
if (GetBattlerSide(gBattleAnimAttacker) != B_SIDE_PLAYER)
sprite->data[1] = -gBattleAnimArgs[1];
else
sprite->data[1] = gBattleAnimArgs[1];
sprite->data[0] = gBattleAnimArgs[0];
sprite->data[2] = 0;
sprite->data[3] = gBattlerSpriteIds[gBattleAnimAttacker];
sprite->data[4] = gBattleAnimArgs[0];
StoreSpriteCallbackInData6(sprite, ReverseHorizontalLungeDirection);
2021-11-01 17:41:21 +01:00
sprite->callback = TranslateSpriteLinearById;
2018-10-07 17:45:37 +02:00
}
2018-12-03 14:49:16 +01:00
static void ReverseHorizontalLungeDirection(struct Sprite *sprite)
2018-10-07 17:45:37 +02:00
{
sprite->data[0] = sprite->data[4];
sprite->data[1] = -sprite->data[1];
2021-11-01 17:41:21 +01:00
sprite->callback = TranslateSpriteLinearById;
2018-10-07 17:45:37 +02:00
StoreSpriteCallbackInData6(sprite, DestroyAnimSprite);
}
// Performs a simple vertical dipping motion, where moves vertically, and then
// moves back in the opposite direction.
// arg 0: duration of single dip direction
// arg 1: y pixel delta that is applied each frame
// arg 2: battler
2018-12-03 14:49:16 +01:00
static void DoVerticalDip(struct Sprite *sprite)
2018-10-07 17:45:37 +02:00
{
u8 spriteId;
sprite->invisible = TRUE;
spriteId = GetAnimBattlerSpriteId(gBattleAnimArgs[2]);
sprite->data[0] = gBattleAnimArgs[0];
sprite->data[1] = 0;
sprite->data[2] = gBattleAnimArgs[1];
sprite->data[3] = spriteId;
sprite->data[4] = gBattleAnimArgs[0];
StoreSpriteCallbackInData6(sprite, ReverseVerticalDipDirection);
2021-11-01 17:41:21 +01:00
sprite->callback = TranslateSpriteLinearById;
2018-10-07 17:45:37 +02:00
}
2018-12-03 14:49:16 +01:00
static void ReverseVerticalDipDirection(struct Sprite *sprite)
2018-10-07 17:45:37 +02:00
{
sprite->data[0] = sprite->data[4];
sprite->data[2] = -sprite->data[2];
2021-11-01 17:41:21 +01:00
sprite->callback = TranslateSpriteLinearById;
2018-10-07 17:45:37 +02:00
StoreSpriteCallbackInData6(sprite, DestroyAnimSprite);
}
// Linearly slides a mon's bg picture back to its original sprite position.
// The sprite parameter is a dummy sprite used for facilitating the movement with its callback.
// arg 0: 1 = target or 0 = attacker
// arg 1: direction (0 = horizontal and vertical, 1 = horizontal only, 2 = vertical only)
// arg 2: duration
2018-12-03 14:49:16 +01:00
static void SlideMonToOriginalPos(struct Sprite *sprite)
2018-10-07 17:45:37 +02:00
{
u32 monSpriteId;
if (!gBattleAnimArgs[0])
monSpriteId = gBattlerSpriteIds[gBattleAnimAttacker];
else
monSpriteId = gBattlerSpriteIds[gBattleAnimTarget];
sprite->data[0] = gBattleAnimArgs[2];
2021-07-07 15:11:52 +02:00
sprite->data[1] = gSprites[monSpriteId].x + gSprites[monSpriteId].x2;
sprite->data[2] = gSprites[monSpriteId].x;
sprite->data[3] = gSprites[monSpriteId].y + gSprites[monSpriteId].y2;
sprite->data[4] = gSprites[monSpriteId].y;
2018-11-26 00:00:18 +01:00
InitSpriteDataForLinearTranslation(sprite);
2018-10-07 17:45:37 +02:00
sprite->data[3] = 0;
sprite->data[4] = 0;
2021-07-07 15:11:52 +02:00
sprite->data[5] = gSprites[monSpriteId].x2;
sprite->data[6] = gSprites[monSpriteId].y2;
2018-10-07 17:45:37 +02:00
sprite->invisible = TRUE;
if (gBattleAnimArgs[1] == 1)
sprite->data[2] = 0;
else if (gBattleAnimArgs[1] == 2)
sprite->data[1] = 0;
sprite->data[7] = gBattleAnimArgs[1];
sprite->data[7] |= monSpriteId << 8;
2020-02-20 22:22:33 +01:00
sprite->callback = SlideMonToOriginalPos_Step;
2018-10-07 17:45:37 +02:00
}
2020-02-20 22:22:33 +01:00
static void SlideMonToOriginalPos_Step(struct Sprite *sprite)
2018-10-07 17:45:37 +02:00
{
s8 monSpriteId;
u8 lo;
struct Sprite *monSprite;
lo = sprite->data[7] & 0xff;
monSpriteId = sprite->data[7] >> 8;
monSprite = &gSprites[monSpriteId];
if (sprite->data[0] == 0)
{
if (lo < 2)
2021-07-07 15:11:52 +02:00
monSprite->x2 = 0;
2018-10-07 17:45:37 +02:00
if (lo == 2 || lo == 0)
2021-07-07 15:11:52 +02:00
monSprite->y2 = 0;
2018-10-07 17:45:37 +02:00
DestroyAnimSprite(sprite);
}
else
{
sprite->data[0]--;
sprite->data[3] += sprite->data[1];
sprite->data[4] += sprite->data[2];
2021-07-07 15:11:52 +02:00
monSprite->x2 = (s8)(sprite->data[3] >> 8) + sprite->data[5];
monSprite->y2 = (s8)(sprite->data[4] >> 8) + sprite->data[6];
2018-10-07 17:45:37 +02:00
}
}
// Linearly translates a mon to a target offset. The horizontal offset
// is mirrored for the opponent's pokemon, and the vertical offset
// is only mirrored if arg 3 is set to 1.
// arg 0: 0 = attacker, 1 = target
// arg 1: target x pixel offset
// arg 2: target y pixel offset
// arg 3: mirror vertical translation for opposite battle side
// arg 4: duration
2018-12-03 14:49:16 +01:00
static void SlideMonToOffset(struct Sprite *sprite)
2018-10-07 17:45:37 +02:00
{
u8 battler;
u8 monSpriteId;
if (!gBattleAnimArgs[0])
battler = gBattleAnimAttacker;
else
battler = gBattleAnimTarget;
monSpriteId = gBattlerSpriteIds[battler];
if (GetBattlerSide(battler) != B_SIDE_PLAYER)
{
gBattleAnimArgs[1] = -gBattleAnimArgs[1];
if (gBattleAnimArgs[3] == 1)
{
gBattleAnimArgs[2] = -gBattleAnimArgs[2];
}
}
sprite->data[0] = gBattleAnimArgs[4];
2021-07-07 15:11:52 +02:00
sprite->data[1] = gSprites[monSpriteId].x;
sprite->data[2] = gSprites[monSpriteId].x + gBattleAnimArgs[1];
sprite->data[3] = gSprites[monSpriteId].y;
sprite->data[4] = gSprites[monSpriteId].y + gBattleAnimArgs[2];
2018-11-26 00:00:18 +01:00
InitSpriteDataForLinearTranslation(sprite);
2018-10-07 17:45:37 +02:00
sprite->data[3] = 0;
sprite->data[4] = 0;
sprite->data[5] = monSpriteId;
sprite->invisible = TRUE;
StoreSpriteCallbackInData6(sprite, DestroyAnimSprite);
2021-11-01 17:41:21 +01:00
sprite->callback = TranslateSpriteLinearByIdFixedPoint;
2018-10-07 17:45:37 +02:00
}
2020-02-20 06:04:42 +01:00
static void SlideMonToOffsetAndBack(struct Sprite *sprite)
2018-10-07 17:45:37 +02:00
{
u8 spriteId;
u8 battlerId;
sprite->invisible = TRUE;
2020-02-20 06:04:42 +01:00
2020-02-16 23:49:24 +01:00
if (gBattleAnimArgs[0] == ANIM_ATTACKER)
2018-10-07 17:45:37 +02:00
battlerId = gBattleAnimAttacker;
else
battlerId = gBattleAnimTarget;
2020-02-20 06:04:42 +01:00
2018-10-07 17:45:37 +02:00
spriteId = gBattlerSpriteIds[battlerId];
if (GetBattlerSide(battlerId))
{
gBattleAnimArgs[1] = -gBattleAnimArgs[1];
if (gBattleAnimArgs[3] == 1)
{
gBattleAnimArgs[2] = -gBattleAnimArgs[2];
}
}
sprite->data[0] = gBattleAnimArgs[4];
2021-07-07 15:11:52 +02:00
sprite->data[1] = gSprites[spriteId].x + gSprites[spriteId].x2;
2018-10-07 17:45:37 +02:00
sprite->data[2] = sprite->data[1] + gBattleAnimArgs[1];
2021-07-07 15:11:52 +02:00
sprite->data[3] = gSprites[spriteId].y + gSprites[spriteId].y2;
2018-10-07 17:45:37 +02:00
sprite->data[4] = sprite->data[3] + gBattleAnimArgs[2];
2018-11-26 00:00:18 +01:00
InitSpriteDataForLinearTranslation(sprite);
2021-07-07 15:11:52 +02:00
sprite->data[3] = gSprites[spriteId].x2 << 8;
sprite->data[4] = gSprites[spriteId].y2 << 8;
2018-10-07 17:45:37 +02:00
sprite->data[5] = spriteId;
sprite->data[6] = gBattleAnimArgs[5];
if (!gBattleAnimArgs[5])
{
StoreSpriteCallbackInData6(sprite, DestroyAnimSprite);
}
else
{
2020-02-20 22:22:33 +01:00
StoreSpriteCallbackInData6(sprite, SlideMonToOffsetAndBack_End);
2018-10-07 17:45:37 +02:00
}
2021-11-01 17:41:21 +01:00
sprite->callback = TranslateSpriteLinearByIdFixedPoint;
2018-10-07 17:45:37 +02:00
}
2020-02-20 22:22:33 +01:00
static void SlideMonToOffsetAndBack_End(struct Sprite *sprite)
2018-10-07 17:45:37 +02:00
{
2021-07-07 15:11:52 +02:00
gSprites[sprite->data[5]].x2 = 0;
gSprites[sprite->data[5]].y2 = 0;
2018-10-07 17:45:37 +02:00
DestroyAnimSprite(sprite);
}
// Task to facilitate a two-part translation animation, in which the sprite
// is first translated in an arc to one position. Then, it "lunges" to a target
// x offset. Used in TAKE_DOWN, for example.
// arg 0: anim bank
// arg 1: horizontal speed (subpixel)
// arg 2: wave amplitude
// arg 3: first duration
// arg 4: delay before starting lunge
// arg 5: target x offset for lunge
// arg 6: lunge duration
void AnimTask_WindUpLunge(u8 taskId)
{
s16 wavePeriod = 0x8000 / gBattleAnimArgs[3];
if (GetBattlerSide(gBattleAnimAttacker) != B_SIDE_PLAYER)
{
gBattleAnimArgs[1] = -gBattleAnimArgs[1];
gBattleAnimArgs[5] = -gBattleAnimArgs[5];
}
2018-10-07 19:19:13 +02:00
gTasks[taskId].data[0] = GetAnimBattlerSpriteId(gBattleAnimArgs[0]);
gTasks[taskId].data[1] = (gBattleAnimArgs[1] << 8) / gBattleAnimArgs[3];
gTasks[taskId].data[2] = gBattleAnimArgs[2];
gTasks[taskId].data[3] = gBattleAnimArgs[3];
gTasks[taskId].data[4] = gBattleAnimArgs[4];
gTasks[taskId].data[5] = (gBattleAnimArgs[5] << 8) / gBattleAnimArgs[6];
gTasks[taskId].data[6] = gBattleAnimArgs[6];
gTasks[taskId].data[7] = wavePeriod;
2020-02-20 22:22:33 +01:00
gTasks[taskId].func = AnimTask_WindUpLunge_Step1;
2018-10-07 17:45:37 +02:00
}
2020-02-20 22:22:33 +01:00
static void AnimTask_WindUpLunge_Step1(u8 taskId)
2018-10-07 17:45:37 +02:00
{
u8 spriteId;
2018-10-07 19:19:13 +02:00
spriteId = gTasks[taskId].data[0];
gTasks[taskId].data[11] += gTasks[taskId].data[1];
2021-07-07 15:11:52 +02:00
gSprites[spriteId].x2 = gTasks[taskId].data[11] >> 8;
gSprites[spriteId].y2 = Sin((u8)(gTasks[taskId].data[10] >> 8), gTasks[taskId].data[2]);
2018-10-07 19:19:13 +02:00
gTasks[taskId].data[10] += gTasks[taskId].data[7];
if (--gTasks[taskId].data[3] == 0)
2018-10-07 17:45:37 +02:00
{
2020-02-20 22:22:33 +01:00
gTasks[taskId].func = AnimTask_WindUpLunge_Step2;
2018-10-07 17:45:37 +02:00
}
}
2020-02-20 22:22:33 +01:00
static void AnimTask_WindUpLunge_Step2(u8 taskId)
2018-10-07 17:45:37 +02:00
{
u8 spriteId;
2018-10-07 19:19:13 +02:00
if (gTasks[taskId].data[4] > 0)
2018-10-07 17:45:37 +02:00
{
2018-10-07 19:19:13 +02:00
gTasks[taskId].data[4]--;
2018-10-07 17:45:37 +02:00
}
else
{
2018-10-07 19:19:13 +02:00
spriteId = gTasks[taskId].data[0];
gTasks[taskId].data[12] += gTasks[taskId].data[5];
2021-07-07 15:11:52 +02:00
gSprites[spriteId].x2 = (gTasks[taskId].data[12] >> 8) + (gTasks[taskId].data[11] >> 8);
2018-10-07 19:19:13 +02:00
if (--gTasks[taskId].data[6] == 0)
2018-10-07 17:45:37 +02:00
{
DestroyAnimVisualTask(taskId);
return;
}
}
}
2020-02-16 23:49:24 +01:00
// To move a mon off-screen when pushed out by Roar/Whirlwind
void AnimTask_SlideOffScreen(u8 taskId)
2018-10-07 17:45:37 +02:00
{
u8 spriteId;
switch (gBattleAnimArgs[0])
{
2020-02-16 23:49:24 +01:00
case ANIM_ATTACKER:
case ANIM_TARGET:
2018-10-07 17:45:37 +02:00
spriteId = GetAnimBattlerSpriteId(gBattleAnimArgs[0]);
break;
2020-02-16 23:49:24 +01:00
case ANIM_ATK_PARTNER:
2018-10-07 17:45:37 +02:00
if (!IsBattlerSpriteVisible(BATTLE_PARTNER(gBattleAnimAttacker)))
{
DestroyAnimVisualTask(taskId);
return;
}
spriteId = gBattlerSpriteIds[BATTLE_PARTNER(gBattleAnimAttacker)];
break;
2020-02-16 23:49:24 +01:00
case ANIM_DEF_PARTNER:
2018-10-07 17:45:37 +02:00
if (!IsBattlerSpriteVisible(BATTLE_PARTNER(gBattleAnimTarget)))
{
DestroyAnimVisualTask(taskId);
return;
}
spriteId = gBattlerSpriteIds[BATTLE_PARTNER(gBattleAnimTarget)];
break;
default:
DestroyAnimVisualTask(taskId);
return;
}
2018-10-07 19:19:13 +02:00
gTasks[taskId].data[0] = spriteId;
2018-10-07 17:45:37 +02:00
if (GetBattlerSide(gBattleAnimTarget) != B_SIDE_PLAYER)
{
2018-10-07 19:19:13 +02:00
gTasks[taskId].data[1] = gBattleAnimArgs[1];
2018-10-07 17:45:37 +02:00
}
else
{
2018-10-07 19:19:13 +02:00
gTasks[taskId].data[1] = -gBattleAnimArgs[1];
2018-10-07 17:45:37 +02:00
}
2020-02-20 22:22:33 +01:00
gTasks[taskId].func = AnimTask_SlideOffScreen_Step;
2018-10-07 17:45:37 +02:00
}
2020-02-20 22:22:33 +01:00
static void AnimTask_SlideOffScreen_Step(u8 taskId)
2018-10-07 17:45:37 +02:00
{
2018-10-07 19:19:13 +02:00
u8 spriteId = gTasks[taskId].data[0];
2021-07-07 15:11:52 +02:00
gSprites[spriteId].x2 += gTasks[taskId].data[1];
2022-08-17 17:44:20 +02:00
if (gSprites[spriteId].x2 + gSprites[spriteId].x < -32 || gSprites[spriteId].x2 + gSprites[spriteId].x > DISPLAY_WIDTH + 32)
2018-10-07 17:45:37 +02:00
{
DestroyAnimVisualTask(taskId);
return;
}
}
// Task that facilitates translating the mon bg picture back and forth
// in a swaying motion (uses Sine wave). It can sway either horizontally
// or vertically, but not both.
// arg 0: direction (0 = horizontal, 1 = vertical)
// arg 1: wave amplitude
// arg 2: wave period
// arg 3: num sways
// arg 4: which mon (0 = attacker, 1`= target)
void AnimTask_SwayMon(u8 taskId)
{
u8 spriteId;
if (GetBattlerSide(gBattleAnimAttacker) != B_SIDE_PLAYER)
gBattleAnimArgs[1] = -gBattleAnimArgs[1];
spriteId = GetAnimBattlerSpriteId(gBattleAnimArgs[4]);
2019-04-01 15:08:19 +02:00
if (spriteId == 0xff)
{
DestroyAnimVisualTask(taskId);
return;
}
2018-10-07 19:19:13 +02:00
gTasks[taskId].data[0] = gBattleAnimArgs[0];
gTasks[taskId].data[1] = gBattleAnimArgs[1];
gTasks[taskId].data[2] = gBattleAnimArgs[2];
gTasks[taskId].data[3] = gBattleAnimArgs[3];
gTasks[taskId].data[4] = spriteId;
2018-10-07 17:45:37 +02:00
if (gBattleAnimArgs[4] == 0)
2018-10-07 19:19:13 +02:00
gTasks[taskId].data[5] = gBattleAnimAttacker;
2018-10-07 17:45:37 +02:00
else
2018-10-07 19:19:13 +02:00
gTasks[taskId].data[5] = gBattleAnimTarget;
2018-10-07 17:45:37 +02:00
2018-10-07 19:19:13 +02:00
gTasks[taskId].data[12] = 1;
gTasks[taskId].func = AnimTask_SwayMonStep;
2018-10-07 17:45:37 +02:00
}
2020-02-20 22:22:33 +01:00
static void AnimTask_SwayMonStep(u8 taskId)
2018-10-07 17:45:37 +02:00
{
s16 sineValue;
u8 spriteId;
int waveIndex;
u16 sineIndex;
2018-10-07 19:19:13 +02:00
spriteId = gTasks[taskId].data[4];
sineIndex = gTasks[taskId].data[10] + gTasks[taskId].data[2];
gTasks[taskId].data[10] = sineIndex;
2018-10-07 17:45:37 +02:00
waveIndex = sineIndex >> 8;
2018-10-07 19:19:13 +02:00
sineValue = Sin(waveIndex, gTasks[taskId].data[1]);
2018-10-07 17:45:37 +02:00
2018-10-07 19:19:13 +02:00
if (gTasks[taskId].data[0] == 0)
2018-10-07 17:45:37 +02:00
{
2021-07-07 15:11:52 +02:00
gSprites[spriteId].x2 = sineValue;
2018-10-07 17:45:37 +02:00
}
else
{
2018-10-07 19:19:13 +02:00
if (GetBattlerSide(gTasks[taskId].data[5]) == B_SIDE_PLAYER)
2018-10-07 17:45:37 +02:00
{
2021-07-07 15:11:52 +02:00
gSprites[spriteId].y2 = (sineValue >= 0) ? sineValue : -sineValue;
2018-10-07 17:45:37 +02:00
}
else
{
2021-07-07 15:11:52 +02:00
gSprites[spriteId].y2 = (sineValue >= 0) ? -sineValue : sineValue;
2018-10-07 17:45:37 +02:00
}
}
2018-10-07 19:19:13 +02:00
if (((waveIndex >= 0x80u) && (gTasks[taskId].data[11] == 0) && (gTasks[taskId].data[12] == 1))
|| ((waveIndex < 0x7fu) && (gTasks[taskId].data[11] == 1) && (gTasks[taskId].data[12] == 0)))
2018-10-07 17:45:37 +02:00
{
2018-10-07 19:19:13 +02:00
gTasks[taskId].data[11] ^= 1;
gTasks[taskId].data[12] ^= 1;
if (--gTasks[taskId].data[3] == 0)
2018-10-07 17:45:37 +02:00
{
2021-07-07 15:11:52 +02:00
gSprites[spriteId].x2 = 0;
gSprites[spriteId].y2 = 0;
2018-10-07 17:45:37 +02:00
DestroyAnimVisualTask(taskId);
return;
}
}
}
// Scales a mon's sprite, and then scales back to its original dimensions.
// arg 0: x scale delta
// arg 1: y scale delta
// arg 2: duration
// arg 3: anim bank
// arg 4: sprite object mode
void AnimTask_ScaleMonAndRestore(u8 taskId)
{
2022-08-17 17:44:20 +02:00
u8 spriteId = GetAnimBattlerSpriteId(gBattleAnimArgs[3]);
2018-12-18 05:08:08 +01:00
PrepareBattlerSpriteForRotScale(spriteId, gBattleAnimArgs[4]);
2018-10-07 19:19:13 +02:00
gTasks[taskId].data[0] = gBattleAnimArgs[0];
gTasks[taskId].data[1] = gBattleAnimArgs[1];
gTasks[taskId].data[2] = gBattleAnimArgs[2];
gTasks[taskId].data[3] = gBattleAnimArgs[2];
gTasks[taskId].data[4] = spriteId;
gTasks[taskId].data[10] = 0x100;
gTasks[taskId].data[11] = 0x100;
2020-02-20 22:22:33 +01:00
gTasks[taskId].func = AnimTask_ScaleMonAndRestore_Step;
2018-10-07 17:45:37 +02:00
}
2020-02-20 22:22:33 +01:00
static void AnimTask_ScaleMonAndRestore_Step(u8 taskId)
2018-10-07 17:45:37 +02:00
{
u8 spriteId;
2018-10-07 19:19:13 +02:00
gTasks[taskId].data[10] += gTasks[taskId].data[0];
gTasks[taskId].data[11] += gTasks[taskId].data[1];
spriteId = gTasks[taskId].data[4];
2018-12-18 05:08:08 +01:00
SetSpriteRotScale(spriteId, gTasks[taskId].data[10], gTasks[taskId].data[11], 0);
2018-10-07 19:19:13 +02:00
if (--gTasks[taskId].data[2] == 0)
2018-10-07 17:45:37 +02:00
{
2018-10-07 19:19:13 +02:00
if (gTasks[taskId].data[3] > 0)
2018-10-07 17:45:37 +02:00
{
2018-10-07 19:19:13 +02:00
gTasks[taskId].data[0] = -gTasks[taskId].data[0];
gTasks[taskId].data[1] = -gTasks[taskId].data[1];
gTasks[taskId].data[2] = gTasks[taskId].data[3];
gTasks[taskId].data[3] = 0;
2018-10-07 17:45:37 +02:00
}
else
{
2018-12-18 05:08:08 +01:00
ResetSpriteRotScale(spriteId);
2018-10-07 17:45:37 +02:00
DestroyAnimVisualTask(taskId);
return;
}
}
}
2020-02-20 22:22:33 +01:00
void AnimTask_RotateMonSpriteToSide(u8 taskId)
2018-10-07 17:45:37 +02:00
{
u8 spriteId;
spriteId = GetAnimBattlerSpriteId(gBattleAnimArgs[2]);
2018-12-18 05:08:08 +01:00
PrepareBattlerSpriteForRotScale(spriteId, ST_OAM_OBJ_NORMAL);
2018-10-07 19:19:13 +02:00
gTasks[taskId].data[1] = 0;
gTasks[taskId].data[2] = gBattleAnimArgs[0];
2018-10-07 17:45:37 +02:00
if (gBattleAnimArgs[3] != 1)
{
2018-10-07 19:19:13 +02:00
gTasks[taskId].data[3] = 0;
2018-10-07 17:45:37 +02:00
}
else
{
2018-10-07 19:19:13 +02:00
gTasks[taskId].data[3] = gBattleAnimArgs[0] * gBattleAnimArgs[1];
2018-10-07 17:45:37 +02:00
}
2018-10-07 19:19:13 +02:00
gTasks[taskId].data[4] = gBattleAnimArgs[1];
gTasks[taskId].data[5] = spriteId;
gTasks[taskId].data[6] = gBattleAnimArgs[3];
2018-10-07 17:45:37 +02:00
if (IsContest())
{
2018-10-07 19:19:13 +02:00
gTasks[taskId].data[7] = 1;
2018-10-07 17:45:37 +02:00
}
else
{
2022-08-17 17:44:20 +02:00
if (gBattleAnimArgs[2] == ANIM_ATTACKER)
2018-10-07 17:45:37 +02:00
{
2022-08-27 06:59:12 +02:00
gTasks[taskId].data[7] = GetBattlerSide(gBattleAnimAttacker) == B_SIDE_PLAYER;
2018-10-07 17:45:37 +02:00
}
else
{
2022-08-27 06:59:12 +02:00
gTasks[taskId].data[7] = GetBattlerSide(gBattleAnimTarget) == B_SIDE_PLAYER;
2018-10-07 17:45:37 +02:00
}
}
2018-10-07 19:19:13 +02:00
if (gTasks[taskId].data[7])
2018-10-07 17:45:37 +02:00
{
if (!IsContest())
{
2018-10-07 19:19:13 +02:00
gTasks[taskId].data[3] *= -1;
gTasks[taskId].data[4] *= -1;
2018-10-07 17:45:37 +02:00
}
}
2020-02-20 22:22:33 +01:00
gTasks[taskId].func = AnimTask_RotateMonSpriteToSide_Step;
2018-10-07 17:45:37 +02:00
}
// Rotates mon to side and back to original position. For Peck and when a held item activates
void AnimTask_RotateMonToSideAndRestore(u8 taskId)
2018-10-07 17:45:37 +02:00
{
2022-08-17 17:44:20 +02:00
u8 spriteId = GetAnimBattlerSpriteId(gBattleAnimArgs[2]);
2018-12-18 05:08:08 +01:00
PrepareBattlerSpriteForRotScale(spriteId, ST_OAM_OBJ_NORMAL);
2018-10-07 19:19:13 +02:00
gTasks[taskId].data[1] = 0;
gTasks[taskId].data[2] = gBattleAnimArgs[0];
if (gBattleAnimArgs[2] == ANIM_ATTACKER)
2018-10-07 17:45:37 +02:00
{
if (GetBattlerSide(gBattleAnimAttacker))
{
gBattleAnimArgs[1] = -gBattleAnimArgs[1];
}
}
else
{
if (GetBattlerSide(gBattleAnimTarget))
{
gBattleAnimArgs[1] = -gBattleAnimArgs[1];
}
}
if (gBattleAnimArgs[3] != 1)
{
2018-10-07 19:19:13 +02:00
gTasks[taskId].data[3] = 0;
2018-10-07 17:45:37 +02:00
}
else
{
2018-10-07 19:19:13 +02:00
gTasks[taskId].data[3] = gBattleAnimArgs[0] * gBattleAnimArgs[1];
2018-10-07 17:45:37 +02:00
}
2018-10-07 19:19:13 +02:00
gTasks[taskId].data[4] = gBattleAnimArgs[1];
gTasks[taskId].data[5] = spriteId;
gTasks[taskId].data[6] = gBattleAnimArgs[3];
gTasks[taskId].data[7] = 1;
gTasks[taskId].data[3] *= -1;
gTasks[taskId].data[4] *= -1;
2020-02-20 22:22:33 +01:00
gTasks[taskId].func = AnimTask_RotateMonSpriteToSide_Step;
2018-10-07 17:45:37 +02:00
}
2020-02-20 22:22:33 +01:00
static void AnimTask_RotateMonSpriteToSide_Step(u8 taskId)
2018-10-07 17:45:37 +02:00
{
2018-10-07 19:19:13 +02:00
gTasks[taskId].data[3] += gTasks[taskId].data[4];
2018-12-18 05:08:08 +01:00
SetSpriteRotScale(gTasks[taskId].data[5], 0x100, 0x100, gTasks[taskId].data[3]);
2018-10-07 19:19:13 +02:00
if (gTasks[taskId].data[7])
2018-10-07 17:45:37 +02:00
{
2018-12-18 05:08:08 +01:00
SetBattlerSpriteYOffsetFromRotation(gTasks[taskId].data[5]);
2018-10-07 17:45:37 +02:00
}
2018-10-07 19:19:13 +02:00
if (++gTasks[taskId].data[1] >= gTasks[taskId].data[2])
2018-10-07 17:45:37 +02:00
{
2018-10-07 19:19:13 +02:00
switch (gTasks[taskId].data[6])
2018-10-07 17:45:37 +02:00
{
case 1:
2018-12-18 05:08:08 +01:00
ResetSpriteRotScale(gTasks[taskId].data[5]);
2018-10-07 17:45:37 +02:00
case 0:
default:
DestroyAnimVisualTask(taskId);
return;
case 2:
2018-10-07 19:19:13 +02:00
gTasks[taskId].data[1] = 0;
gTasks[taskId].data[4] *= -1;
gTasks[taskId].data[6] = 1;
2018-10-07 17:45:37 +02:00
break;
}
}
}
void SetupShakeBattlerBasedOnMovePowerOrDmg(u8 taskId, u8 animBattlerId)
2018-10-07 17:45:37 +02:00
{
if (!gBattleAnimArgs[0])
{
2018-10-07 19:19:13 +02:00
gTasks[taskId].data[15] = gAnimMovePower / 12;
if (gTasks[taskId].data[15] < 1)
2018-10-07 17:45:37 +02:00
{
2018-10-07 19:19:13 +02:00
gTasks[taskId].data[15] = 1;
2018-10-07 17:45:37 +02:00
}
2018-10-07 19:19:13 +02:00
if (gTasks[taskId].data[15] > 16)
2018-10-07 17:45:37 +02:00
{
2018-10-07 19:19:13 +02:00
gTasks[taskId].data[15] = 16;
2018-10-07 17:45:37 +02:00
}
}
else
{
2018-10-07 19:19:13 +02:00
gTasks[taskId].data[15] = gAnimMoveDmg / 12;
if (gTasks[taskId].data[15] < 1)
2018-10-07 17:45:37 +02:00
{
2018-10-07 19:19:13 +02:00
gTasks[taskId].data[15] = 1;
2018-10-07 17:45:37 +02:00
}
2018-10-07 19:19:13 +02:00
if (gTasks[taskId].data[15] > 16)
2018-10-07 17:45:37 +02:00
{
2018-10-07 19:19:13 +02:00
gTasks[taskId].data[15] = 16;
2018-10-07 17:45:37 +02:00
}
}
2018-10-07 19:19:13 +02:00
gTasks[taskId].data[14] = gTasks[taskId].data[15] / 2;
gTasks[taskId].data[13] = gTasks[taskId].data[14] + (gTasks[taskId].data[15] & 1);
gTasks[taskId].data[12] = 0;
gTasks[taskId].data[10] = gBattleAnimArgs[3];
gTasks[taskId].data[11] = gBattleAnimArgs[4];
gTasks[taskId].data[7] = GetAnimBattlerSpriteId(animBattlerId);
2021-07-07 15:11:52 +02:00
gTasks[taskId].data[8] = gSprites[gTasks[taskId].data[7]].x2;
gTasks[taskId].data[9] = gSprites[gTasks[taskId].data[7]].y2;
2018-10-07 19:19:13 +02:00
gTasks[taskId].data[0] = 0;
gTasks[taskId].data[1] = gBattleAnimArgs[1];
gTasks[taskId].data[2] = gBattleAnimArgs[2];
}
void AnimTask_ShakeTargetPartnerBasedOnMovePowerOrDmg(u8 taskId)
{
SetupShakeBattlerBasedOnMovePowerOrDmg(taskId, ANIM_DEF_PARTNER);
gTasks[taskId].func = AnimTask_ShakeTargetBasedOnMovePowerOrDmg_Step;
}
void AnimTask_ShakeTargetBasedOnMovePowerOrDmg(u8 taskId)
{
SetupShakeBattlerBasedOnMovePowerOrDmg(taskId, ANIM_TARGET);
2020-02-20 22:22:33 +01:00
gTasks[taskId].func = AnimTask_ShakeTargetBasedOnMovePowerOrDmg_Step;
2018-10-07 17:45:37 +02:00
}
2020-02-20 22:22:33 +01:00
static void AnimTask_ShakeTargetBasedOnMovePowerOrDmg_Step(u8 taskId)
2018-10-07 17:45:37 +02:00
{
struct Task *task = &gTasks[taskId];
if (++task->data[0] > task->data[1])
{
task->data[0] = 0;
task->data[12] = (task->data[12] + 1) & 1;
if (task->data[10])
{
if (task->data[12])
{
2021-07-07 15:11:52 +02:00
gSprites[task->data[7]].x2 = task->data[8] + task->data[13];
2018-10-07 17:45:37 +02:00
}
else
{
2021-07-07 15:11:52 +02:00
gSprites[task->data[7]].x2 = task->data[8] - task->data[14];
2018-10-07 17:45:37 +02:00
}
}
if (task->data[11])
{
if (task->data[12])
{
2021-07-07 15:11:52 +02:00
gSprites[task->data[7]].y2 = task->data[15];
2018-10-07 17:45:37 +02:00
}
else
{
2021-07-07 15:11:52 +02:00
gSprites[task->data[7]].y2 = 0;
2018-10-07 17:45:37 +02:00
}
}
if (!--task->data[2])
{
2021-07-07 15:11:52 +02:00
gSprites[task->data[7]].x2 = 0;
gSprites[task->data[7]].y2 = 0;
2018-10-07 17:45:37 +02:00
DestroyAnimVisualTask(taskId);
return;
}
}
}
2020-04-16 16:52:25 +02:00
#define tSpriteId data[0]
#define tRotSpeed data[1]
#define tRotCurr data[2]
#define tPhase data[3]
#define tFrames data[4]
#define tPlayerSide data[5]
#define tRotMax data[6] // Can't fully flip back sprites
void AnimTask_RotateVertically(u8 taskId)
{
u8 spriteId = GetAnimBattlerSpriteId(gBattleAnimArgs[0]);
PrepareBattlerSpriteForRotScale(spriteId, ST_OAM_OBJ_NORMAL);
gTasks[taskId].tSpriteId = spriteId;
gTasks[taskId].tRotCurr = 0;
gTasks[taskId].tPlayerSide = ((GetBattlerSide(GetAnimBattlerId(gBattleAnimArgs[0]))) == B_SIDE_PLAYER);
gTasks[taskId].tRotMax = gTasks[taskId].tPlayerSide ? 0x1FFF : 0x7FFE;
gTasks[taskId].tRotSpeed = gBattleAnimArgs[1];
gTasks[taskId].func = AnimTask_RotateVerticallyStep;
}
static void AnimTask_RotateVerticallyStep(u8 taskId)
{
switch (gTasks[taskId].tPhase)
{
case 0: // flip upside-down
gTasks[taskId].tRotCurr = min(abs(gTasks[taskId].tRotCurr + gTasks[taskId].tRotSpeed), gTasks[taskId].tRotMax);
SetSpriteRotScale(gTasks[taskId].tSpriteId, 0x100, 0x100, gTasks[taskId].tRotCurr);
if (gTasks[taskId].tPlayerSide)
SetBattlerSpriteYOffsetFromRotation(gTasks[taskId].tSpriteId);
if (gTasks[taskId].tRotCurr == gTasks[taskId].tRotMax)
gTasks[taskId].tPhase++;
break;
case 1: // Wait a bit
if (++gTasks[taskId].tFrames >= 75)
gTasks[taskId].tPhase++;
break;
case 2: // rotate back
if (gTasks[taskId].tRotCurr < gTasks[taskId].tRotSpeed)
gTasks[taskId].tRotCurr = 0;
else
gTasks[taskId].tRotCurr = gTasks[taskId].tRotCurr - gTasks[taskId].tRotSpeed;
SetSpriteRotScale(gTasks[taskId].tSpriteId, 0x100, 0x100, gTasks[taskId].tRotCurr);
if (gTasks[taskId].tPlayerSide)
SetBattlerSpriteYOffsetFromRotation(gTasks[taskId].tSpriteId);
if (gTasks[taskId].tRotCurr == 0)
gTasks[taskId].tPhase++;
break;
case 3: // end
ResetSpriteRotScale(gTasks[taskId].tSpriteId);
DestroyAnimVisualTask(taskId);
break;
}
}
#undef tSpriteId
#undef tRotSpeed
#undef tRotCurr
#undef tPhase
#undef tFrames
#undef tPlayerSide
#undef tRotMax