Skip to content

Commit 263026e

Browse files
Merge pull request #2128 from DavidJCobb/re-battle-weather-anims
Identified task and sprite fields related to battle weather animations
2 parents 5a036ae + d83b067 commit 263026e

File tree

3 files changed

+172
-89
lines changed

3 files changed

+172
-89
lines changed

src/battle_anim_ice.c

Lines changed: 90 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,16 @@
1313
#include "constants/battle_anim.h"
1414
#include "constants/rgb.h"
1515

16+
enum {
17+
HAILSTRUCTTYPE_NEGATIVE_POS_MOD = 0,
18+
HAILSTRUCTTYPE_POSITIVE_POS_MOD = 1,
19+
HAILSTRUCTTYPE_FIXED_POSITION = 2,
20+
};
1621
struct HailStruct {
1722
s32 x:10;
1823
s32 y:10;
1924
s32 bPosition:8;
20-
s32 unk3:4;
25+
s32 type:4;
2126
};
2227

2328
static void AnimUnusedIceCrystalThrow(struct Sprite *);
@@ -371,16 +376,16 @@ const struct SpriteTemplate gPoisonGasCloudSpriteTemplate =
371376

372377
static const struct HailStruct sHailCoordData[] =
373378
{
374-
{.x = 100, .y = 120, .bPosition = B_POSITION_PLAYER_LEFT, .unk3 = 2},
375-
{.x = 85, .y = 120, .bPosition = B_POSITION_PLAYER_LEFT, .unk3 = 0},
376-
{.x = 242, .y = 120, .bPosition = B_POSITION_OPPONENT_LEFT, .unk3 = 1},
377-
{.x = 66, .y = 120, .bPosition = B_POSITION_PLAYER_RIGHT, .unk3 = 1},
378-
{.x = 182, .y = 120, .bPosition = B_POSITION_OPPONENT_RIGHT, .unk3 = 0},
379-
{.x = 60, .y = 120, .bPosition = B_POSITION_PLAYER_LEFT, .unk3 = 2},
380-
{.x = 214, .y = 120, .bPosition = B_POSITION_OPPONENT_LEFT, .unk3 = 0},
381-
{.x = 113, .y = 120, .bPosition = B_POSITION_PLAYER_LEFT, .unk3 = 1},
382-
{.x = 210, .y = 120, .bPosition = B_POSITION_OPPONENT_RIGHT, .unk3 = 1},
383-
{.x = 38, .y = 120, .bPosition = B_POSITION_PLAYER_RIGHT, .unk3 = 0},
379+
{.x = 100, .y = 120, .bPosition = B_POSITION_PLAYER_LEFT, .type = HAILSTRUCTTYPE_FIXED_POSITION},
380+
{.x = 85, .y = 120, .bPosition = B_POSITION_PLAYER_LEFT, .type = HAILSTRUCTTYPE_NEGATIVE_POS_MOD},
381+
{.x = 242, .y = 120, .bPosition = B_POSITION_OPPONENT_LEFT, .type = HAILSTRUCTTYPE_POSITIVE_POS_MOD},
382+
{.x = 66, .y = 120, .bPosition = B_POSITION_PLAYER_RIGHT, .type = HAILSTRUCTTYPE_POSITIVE_POS_MOD},
383+
{.x = 182, .y = 120, .bPosition = B_POSITION_OPPONENT_RIGHT, .type = HAILSTRUCTTYPE_NEGATIVE_POS_MOD},
384+
{.x = 60, .y = 120, .bPosition = B_POSITION_PLAYER_LEFT, .type = HAILSTRUCTTYPE_FIXED_POSITION},
385+
{.x = 214, .y = 120, .bPosition = B_POSITION_OPPONENT_LEFT, .type = HAILSTRUCTTYPE_NEGATIVE_POS_MOD},
386+
{.x = 113, .y = 120, .bPosition = B_POSITION_PLAYER_LEFT, .type = HAILSTRUCTTYPE_POSITIVE_POS_MOD},
387+
{.x = 210, .y = 120, .bPosition = B_POSITION_OPPONENT_RIGHT, .type = HAILSTRUCTTYPE_POSITIVE_POS_MOD},
388+
{.x = 38, .y = 120, .bPosition = B_POSITION_PLAYER_RIGHT, .type = HAILSTRUCTTYPE_NEGATIVE_POS_MOD},
384389
};
385390

386391
static const union AffineAnimCmd sAffineAnim_HailParticle_0[] =
@@ -1332,6 +1337,13 @@ static void MovePoisonGasCloud(struct Sprite *sprite)
13321337
}
13331338
}
13341339

1340+
#define tState data[0]
1341+
#define tSpriteCount data[1]
1342+
#define tHailAffineAnimNum data[2]
1343+
#define tHailStructId data[3]
1344+
#define tInitialDelayTimer data[4]
1345+
#define tHailSpawnTimer data[5]
1346+
13351347
void AnimTask_Hail(u8 taskId)
13361348
{
13371349
struct Task *task = &gTasks[taskId];
@@ -1342,71 +1354,86 @@ void AnimTask_Hail(u8 taskId)
13421354
static void AnimTask_Hail2(u8 taskId)
13431355
{
13441356
struct Task *task = &gTasks[taskId];
1345-
switch (task->data[0])
1357+
switch (task->tState)
13461358
{
13471359
case 0:
1348-
if (++task->data[4] > 2)
1360+
if (++task->tInitialDelayTimer > 2)
13491361
{
1350-
task->data[4] = 0;
1351-
task->data[5] = 0;
1352-
task->data[2] = 0;
1353-
task->data[0]++;
1362+
task->tInitialDelayTimer = 0;
1363+
task->tHailSpawnTimer = 0;
1364+
task->tHailAffineAnimNum = 0;
1365+
task->tState++;
13541366
}
13551367
break;
13561368
case 1:
1357-
if (task->data[5] == 0)
1369+
if (task->tHailSpawnTimer == 0)
13581370
{
1359-
if (GenerateHailParticle(task->data[3], task->data[2], taskId, 1))
1360-
task->data[1]++;
1371+
if (GenerateHailParticle(task->tHailStructId, task->tHailAffineAnimNum, taskId, 1))
1372+
task->tSpriteCount++;
13611373

1362-
if (++task->data[2] == 3)
1374+
if (++task->tHailAffineAnimNum == (int)ARRAY_COUNT(sAffineAnims_HailParticle))
13631375
{
1364-
if (++task->data[3] == 10)
1365-
task->data[0]++;
1376+
if (++task->tHailStructId == (int)ARRAY_COUNT(sHailCoordData))
1377+
task->tState++;
13661378
else
1367-
task->data[0]--;
1379+
task->tState--;
13681380
}
13691381
else
13701382
{
1371-
task->data[5] = 1;
1383+
task->tHailSpawnTimer = 1;
13721384
}
13731385

13741386
}
13751387
else
13761388
{
1377-
task->data[5]--;
1389+
task->tHailSpawnTimer--;
13781390
}
13791391
break;
13801392
case 2:
1381-
if (task->data[1] == 0)
1393+
if (task->tSpriteCount == 0)
13821394
DestroyAnimVisualTask(taskId);
13831395
break;
13841396
}
13851397
}
13861398

1399+
#undef tState
1400+
#undef tSpriteCount
1401+
#undef tHailAffineAnimNum
1402+
#undef tHailStructId
1403+
#undef tInitialDelayTimer
1404+
#undef tHailSpawnTimer
1405+
1406+
// Hail falling particle sprite vars
1407+
#define sSpawnImpactEffect data[0]
1408+
#define sTargetX data[3]
1409+
#define sTargetY data[4]
1410+
#define sAffineAnimNum data[5]
1411+
#define sOwnerTaskId data[6]
1412+
#define sOwnerTaskSpriteCountField data[7]
1413+
13871414
static bool8 GenerateHailParticle(u8 hailStructId, u8 affineAnimNum, u8 taskId, u8 c)
13881415
{
13891416
u8 id;
13901417
s16 battlerX, battlerY;
13911418
s16 spriteX;
1392-
bool8 possibleBool = FALSE;
1393-
s8 unk = sHailCoordData[hailStructId].unk3;
1419+
bool8 shouldSpawnImpactEffect = FALSE;
1420+
s8 type = sHailCoordData[hailStructId].type;
13941421

1395-
if (unk != 2)
1422+
if (type != HAILSTRUCTTYPE_FIXED_POSITION)
13961423
{
13971424
id = GetBattlerAtPosition(sHailCoordData[hailStructId].bPosition);
13981425
if (IsBattlerSpriteVisible(id))
13991426
{
1400-
possibleBool = TRUE;
1427+
shouldSpawnImpactEffect = TRUE;
14011428
battlerX = GetBattlerSpriteCoord(id, BATTLER_COORD_X_2);
14021429
battlerY = GetBattlerSpriteCoord(id, BATTLER_COORD_Y_PIC_OFFSET);
1403-
switch (unk)
1430+
switch (type)
14041431
{
1405-
case 0:
1432+
case HAILSTRUCTTYPE_NEGATIVE_POS_MOD:
14061433
battlerX -= GetBattlerSpriteCoordAttr(id, BATTLER_COORD_ATTR_WIDTH) / 6;
14071434
battlerY -= GetBattlerSpriteCoordAttr(id, BATTLER_COORD_ATTR_HEIGHT) / 6;
14081435
break;
1409-
case 1:
1436+
case HAILSTRUCTTYPE_POSITIVE_POS_MOD:
14101437
battlerX += GetBattlerSpriteCoordAttr(id, BATTLER_COORD_ATTR_WIDTH) / 6;
14111438
battlerY += GetBattlerSpriteCoordAttr(id, BATTLER_COORD_ATTR_HEIGHT) / 6;
14121439
break;
@@ -1432,12 +1459,12 @@ static bool8 GenerateHailParticle(u8 hailStructId, u8 affineAnimNum, u8 taskId,
14321459
else
14331460
{
14341461
StartSpriteAffineAnim(&gSprites[id], affineAnimNum);
1435-
gSprites[id].data[0] = possibleBool;
1436-
gSprites[id].data[3] = battlerX;
1437-
gSprites[id].data[4] = battlerY;
1438-
gSprites[id].data[5] = affineAnimNum;
1439-
gSprites[id].data[6] = taskId;
1440-
gSprites[id].data[7] = c;
1462+
gSprites[id].sSpawnImpactEffect = shouldSpawnImpactEffect;
1463+
gSprites[id].sTargetX = battlerX;
1464+
gSprites[id].sTargetY = battlerY;
1465+
gSprites[id].sAffineAnimNum = affineAnimNum;
1466+
gSprites[id].sOwnerTaskId = taskId;
1467+
gSprites[id].sOwnerTaskSpriteCountField = c;
14411468
return TRUE;
14421469
}
14431470
}
@@ -1449,43 +1476,58 @@ static void AnimHailBegin(struct Sprite *sprite)
14491476
sprite->x += 4;
14501477
sprite->y += 8;
14511478

1452-
if (sprite->x < sprite->data[3] && sprite->y < sprite->data[4])
1479+
if (sprite->x < sprite->sTargetX && sprite->y < sprite->sTargetY)
14531480
return;
14541481

1455-
if (sprite->data[0] == 1 && sprite->data[5] == 0)
1482+
if (sprite->sSpawnImpactEffect == 1 && sprite->sAffineAnimNum == 0)
14561483
{
14571484
spriteId = CreateSprite(&gIceCrystalHitLargeSpriteTemplate,
1458-
sprite->data[3], sprite->data[4], sprite->subpriority);
1485+
sprite->sTargetX, sprite->sTargetY, sprite->subpriority);
14591486

14601487
sprite->data[0] = spriteId;
14611488
if (spriteId != MAX_SPRITES)
14621489
{
1490+
// The sprite template we're using is shared amongst a few other
1491+
// places, which make the sprite flicker. That's not what we want
1492+
// here, though. Override the callback.
14631493
gSprites[sprite->data[0]].callback = AnimHailContinue;
1464-
gSprites[sprite->data[0]].data[6] = sprite->data[6];
1465-
gSprites[sprite->data[0]].data[7] = sprite->data[7];
1494+
gSprites[sprite->data[0]].sOwnerTaskId = sprite->sOwnerTaskId;
1495+
gSprites[sprite->data[0]].sOwnerTaskSpriteCountField = sprite->sOwnerTaskSpriteCountField;
14661496
}
14671497

14681498
FreeOamMatrix(sprite->oam.matrixNum);
14691499
DestroySprite(sprite);
14701500
}
14711501
else
14721502
{
1473-
gTasks[sprite->data[6]].data[sprite->data[7]]--;
1503+
gTasks[sprite->sOwnerTaskId].data[sprite->sOwnerTaskSpriteCountField]--;
14741504
FreeOamMatrix(sprite->oam.matrixNum);
14751505
DestroySprite(sprite);
14761506
}
14771507
}
14781508

1509+
#undef sSpawnImpactEffect
1510+
#undef sTargetX
1511+
#undef sTargetY
1512+
#undef sAffineAnimNum
1513+
1514+
// Hail impact VFX sprite vars
1515+
#define sTimer data[0]
1516+
14791517
static void AnimHailContinue(struct Sprite *sprite)
14801518
{
1481-
if (++sprite->data[0] == 20)
1519+
if (++sprite->sTimer == 20)
14821520
{
1483-
gTasks[sprite->data[6]].data[sprite->data[7]]--;
1521+
gTasks[sprite->sOwnerTaskId].data[sprite->sOwnerTaskSpriteCountField]--;
14841522
FreeOamMatrix(sprite->oam.matrixNum);
14851523
DestroySprite(sprite);
14861524
}
14871525
}
14881526

1527+
#undef sTimer
1528+
#undef sOwnerTaskId
1529+
#undef sOwnerTaskSpriteCountField
1530+
14891531
// Initializes the animation for Ice Ball.
14901532
// arg 0: initial x pixel offset
14911533
// arg 1: initial y pixel offset

0 commit comments

Comments
 (0)