diff --git a/asm/water.s b/asm/water.s index 693aceddd..04e450565 100644 --- a/asm/water.s +++ b/asm/water.s @@ -5,325 +5,6 @@ .text - thumb_func_start AnimTask_CreateRaindrops -AnimTask_CreateRaindrops: @ 8107188 - push {r4-r6,lr} - lsls r0, 24 - lsrs r0, 24 - adds r6, r0, 0 - ldr r1, =gTasks - lsls r0, r6, 2 - adds r0, r6 - lsls r0, 3 - adds r5, r0, r1 - movs r1, 0x8 - ldrsh r0, [r5, r1] - cmp r0, 0 - bne _081071B0 - ldr r1, =gBattleAnimArgs - ldrh r0, [r1] - strh r0, [r5, 0xA] - ldrh r0, [r1, 0x2] - strh r0, [r5, 0xC] - ldrh r0, [r1, 0x4] - strh r0, [r5, 0xE] -_081071B0: - ldrh r0, [r5, 0x8] - adds r0, 0x1 - strh r0, [r5, 0x8] - movs r2, 0x8 - ldrsh r0, [r5, r2] - movs r2, 0xC - ldrsh r1, [r5, r2] - bl __modsi3 - cmp r0, 0x1 - bne _081071F8 - bl Random2 - lsls r0, 16 - lsrs r0, 16 - movs r1, 0xF0 - bl __umodsi3 - adds r4, r0, 0 - lsls r4, 24 - lsrs r4, 24 - bl Random2 - lsls r0, 16 - lsrs r0, 16 - movs r1, 0x50 - bl __umodsi3 - adds r2, r0, 0 - lsls r2, 24 - lsrs r2, 24 - ldr r0, =gUnknown_08595020 - adds r1, r4, 0 - movs r3, 0x4 - bl CreateSprite -_081071F8: - movs r0, 0x8 - ldrsh r1, [r5, r0] - movs r2, 0xE - ldrsh r0, [r5, r2] - cmp r1, r0 - bne _0810720A - adds r0, r6, 0 - bl DestroyAnimVisualTask -_0810720A: - pop {r4-r6} - pop {r0} - bx r0 - .pool - thumb_func_end AnimTask_CreateRaindrops - - thumb_func_start sub_810721C -sub_810721C: @ 810721C - ldr r1, =sub_8107228 - str r1, [r0, 0x1C] - bx lr - .pool - thumb_func_end sub_810721C - - thumb_func_start sub_8107228 -sub_8107228: @ 8107228 - push {lr} - adds r2, r0, 0 - ldrh r0, [r2, 0x2E] - adds r0, 0x1 - strh r0, [r2, 0x2E] - lsls r0, 16 - asrs r0, 16 - cmp r0, 0xD - bgt _08107246 - ldrh r0, [r2, 0x24] - adds r0, 0x1 - strh r0, [r2, 0x24] - ldrh r0, [r2, 0x26] - adds r0, 0x4 - strh r0, [r2, 0x26] -_08107246: - adds r0, r2, 0 - adds r0, 0x3F - ldrb r1, [r0] - movs r0, 0x10 - ands r0, r1 - cmp r0, 0 - beq _0810725A - adds r0, r2, 0 - bl DestroySprite -_0810725A: - pop {r0} - bx r0 - thumb_func_end sub_8107228 - - thumb_func_start sub_8107260 -sub_8107260: @ 8107260 - push {r4-r6,lr} - adds r6, r0, 0 - ldr r5, =gBattleAnimAttacker - ldrb r0, [r5] - bl GetBattlerSide - lsls r0, 24 - cmp r0, 0 - beq _08107290 - ldrb r0, [r5] - movs r1, 0x2 - bl GetBattlerSpriteCoord - lsls r0, 24 - lsrs r0, 24 - ldr r4, =gBattleAnimArgs - ldrh r1, [r4] - subs r0, r1 - b _081072A2 - .pool -_08107290: - ldrb r0, [r5] - movs r1, 0x2 - bl GetBattlerSpriteCoord - lsls r0, 24 - ldr r4, =gBattleAnimArgs - lsrs r0, 24 - ldrh r1, [r4] - adds r0, r1 -_081072A2: - strh r0, [r6, 0x20] - ldrb r0, [r5] - movs r1, 0x3 - bl GetBattlerSpriteCoord - lsls r0, 24 - lsrs r0, 24 - ldrh r4, [r4, 0x2] - adds r0, r4 - strh r0, [r6, 0x22] - adds r2, r6, 0 - adds r2, 0x2C - ldrb r0, [r2] - movs r1, 0x40 - orrs r0, r1 - strb r0, [r2] - ldr r0, =gBattleAnimAttacker - ldrb r0, [r0] - bl GetBattlerSide - lsls r0, 24 - cmp r0, 0 - beq _081072D8 - ldr r1, =gBattleAnimArgs - ldrh r0, [r1, 0x4] - negs r0, r0 - strh r0, [r1, 0x4] -_081072D8: - ldr r5, =gBattleAnimArgs - ldrh r0, [r5, 0xC] - strh r0, [r6, 0x2E] - ldrh r0, [r6, 0x20] - strh r0, [r6, 0x30] - ldr r4, =gBattleAnimTarget - ldrb r0, [r4] - movs r1, 0x2 - bl GetBattlerSpriteCoord - lsls r0, 24 - lsrs r0, 24 - strh r0, [r6, 0x32] - ldrh r0, [r6, 0x22] - strh r0, [r6, 0x34] - ldrb r0, [r4] - movs r1, 0x3 - bl GetBattlerSpriteCoord - lsls r0, 24 - lsrs r0, 24 - strh r0, [r6, 0x36] - adds r0, r6, 0 - bl InitAnimLinearTranslation - ldr r0, =SpriteCallbackDummy - bl CreateInvisibleSpriteWithCallback - adds r4, r0, 0 - lsls r4, 24 - lsrs r4, 24 - strh r4, [r6, 0x38] - ldrb r0, [r5, 0x8] - movs r2, 0x4 - ldrsh r1, [r5, r2] - bl Sin - ldrh r1, [r6, 0x20] - subs r1, r0 - strh r1, [r6, 0x20] - ldrb r0, [r5, 0x8] - movs r2, 0x6 - ldrsh r1, [r5, r2] - bl Cos - ldrh r1, [r6, 0x22] - subs r1, r0 - strh r1, [r6, 0x22] - ldr r0, =gSprites - lsls r1, r4, 4 - adds r1, r4 - lsls r1, 2 - adds r1, r0 - ldrh r0, [r5, 0x4] - strh r0, [r1, 0x2E] - ldrh r0, [r5, 0x6] - strh r0, [r1, 0x30] - ldrh r0, [r5, 0xA] - strh r0, [r1, 0x32] - ldrb r0, [r5, 0x8] - lsls r0, 8 - strh r0, [r1, 0x34] - ldrh r0, [r5, 0xC] - strh r0, [r1, 0x36] - ldr r1, =sub_8107380 - str r1, [r6, 0x1C] - adds r0, r6, 0 - bl _call_via_r1 - pop {r4-r6} - pop {r0} - bx r0 - .pool - thumb_func_end sub_8107260 - - thumb_func_start sub_8107380 -sub_8107380: @ 8107380 - push {r4-r7,lr} - mov r7, r8 - push {r7} - sub sp, 0x4 - adds r5, r0, 0 - ldrh r1, [r5, 0x38] - lsls r1, 24 - lsrs r1, 24 - ldr r2, =gSprites - lsls r0, r1, 4 - adds r0, r1 - lsls r0, 2 - adds r7, r0, r2 - ldrh r4, [r7, 0x36] - lsls r4, 24 - lsrs r4, 24 - ldrh r0, [r7, 0x34] - mov r8, r0 - movs r0, 0x1 - strh r0, [r5, 0x2E] - adds r0, r5, 0 - bl TranslateAnimLinear - mov r1, r8 - lsrs r6, r1, 8 - movs r0, 0x2E - ldrsh r1, [r7, r0] - adds r0, r6, 0 - bl Sin - ldrh r1, [r5, 0x24] - adds r0, r1 - strh r0, [r5, 0x24] - movs r0, 0x30 - ldrsh r1, [r7, r0] - adds r0, r6, 0 - bl Cos - ldrh r1, [r5, 0x26] - adds r0, r1 - strh r0, [r5, 0x26] - ldrh r0, [r7, 0x32] - mov r1, r8 - adds r1, r0 - strh r1, [r7, 0x34] - subs r4, 0x1 - lsls r4, 24 - lsrs r4, 24 - cmp r4, 0 - beq _081073EC - strh r4, [r7, 0x36] - b _081073F6 - .pool -_081073EC: - ldr r0, =sub_8107408 - str r0, [r5, 0x1C] - adds r0, r7, 0 - bl DestroySprite -_081073F6: - add sp, 0x4 - pop {r3} - mov r8, r3 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end sub_8107380 - - thumb_func_start sub_8107408 -sub_8107408: @ 8107408 - push {lr} - adds r3, r0, 0 - adds r3, 0x2C - ldrb r2, [r3] - movs r1, 0x41 - negs r1, r1 - ands r1, r2 - strb r1, [r3] - ldr r1, =RunStoredCallbackWhenAnimEnds - str r1, [r0, 0x1C] - ldr r1, =sub_8107430 - bl StoreSpriteCallbackInData6 - pop {r0} - bx r0 - .pool - thumb_func_end sub_8107408 - thumb_func_start sub_8107430 sub_8107430: @ 8107430 push {lr} diff --git a/ld_script.txt b/ld_script.txt index 4fcd17bce..20750c97d 100644 --- a/ld_script.txt +++ b/ld_script.txt @@ -159,6 +159,7 @@ SECTIONS { src/item_use.o(.text); src/battle_anim_effects_1.o(.text); src/battle_anim_effects_2.o(.text); + src/water.o(.text); asm/water.o(.text); src/fire.o(.text); src/electric.o(.text); diff --git a/src/water.c b/src/water.c index 955526ccd..e69e0b54b 100644 --- a/src/water.c +++ b/src/water.c @@ -1,9 +1,20 @@ #include "global.h" +#include "battle.h" #include "battle_anim.h" +#include "random.h" +#include "sprite.h" +#include "task.h" +#include "trig.h" +#include "util.h" +#include "constants/battle.h" #include "constants/rgb.h" extern void sub_810721C(struct Sprite *); +extern void sub_8107228(struct Sprite *); extern void sub_8107260(struct Sprite *); +extern void sub_8107380(struct Sprite *); +extern void sub_8107408(struct Sprite *); +extern void sub_8107430(struct Sprite *); extern void sub_810744C(struct Sprite *); extern void sub_81075EC(struct Sprite *); extern void sub_8107730(struct Sprite *); @@ -440,3 +451,111 @@ const struct SpriteTemplate gUnknown_08595328 = .affineAnims = gUnknown_085952F4, .callback = sub_80A8EE4, }; + +void AnimTask_CreateRaindrops(u8 taskId) +{ + u8 x, y; + + if (gTasks[taskId].data[0] == 0) + { + gTasks[taskId].data[1] = gBattleAnimArgs[0]; + gTasks[taskId].data[2] = gBattleAnimArgs[1]; + gTasks[taskId].data[3] = gBattleAnimArgs[2]; + } + gTasks[taskId].data[0]++; + if (gTasks[taskId].data[0] % gTasks[taskId].data[2] == 1) + { + x = Random2() % 240; + y = Random2() % 80; + CreateSprite(&gUnknown_08595020, x, y, 4); + } + if (gTasks[taskId].data[0] == gTasks[taskId].data[3]) + DestroyAnimVisualTask(taskId); +} + +void sub_810721C(struct Sprite *sprite) +{ + sprite->callback = sub_8107228; +} + +void sub_8107228(struct Sprite *sprite) +{ + if (++sprite->data[0] <= 13) + { + sprite->pos2.x++; + sprite->pos2.y += 4; + } + if (sprite->animEnded != FALSE) + DestroySprite(sprite); +} + +void sub_8107260(struct Sprite *sprite) +{ + u8 spriteId; + + if (GetBattlerSide(gBattleAnimAttacker) != B_SIDE_PLAYER) + { + sprite->pos1.x = GetBattlerSpriteCoord(gBattleAnimAttacker, 2) - gBattleAnimArgs[0]; + sprite->pos1.y = GetBattlerSpriteCoord(gBattleAnimAttacker, 3) + gBattleAnimArgs[1]; + sprite->animPaused = TRUE; + } + else + { + sprite->pos1.x = GetBattlerSpriteCoord(gBattleAnimAttacker, 2) + gBattleAnimArgs[0]; + sprite->pos1.y = GetBattlerSpriteCoord(gBattleAnimAttacker, 3) + gBattleAnimArgs[1]; + sprite->animPaused = TRUE; + } + if (GetBattlerSide(gBattleAnimAttacker) != B_SIDE_PLAYER) + gBattleAnimArgs[2] = -gBattleAnimArgs[2]; + sprite->data[0] = gBattleAnimArgs[6]; + sprite->data[1] = sprite->pos1.x; + sprite->data[2] = GetBattlerSpriteCoord(gBattleAnimTarget, 2); + sprite->data[3] = sprite->pos1.y; + sprite->data[4] = GetBattlerSpriteCoord(gBattleAnimTarget, 3); + InitAnimLinearTranslation(sprite); + spriteId = CreateInvisibleSpriteWithCallback(SpriteCallbackDummy); + sprite->data[5] = spriteId; + sprite->pos1.x -= Sin((u8)gBattleAnimArgs[4], gBattleAnimArgs[2]); + sprite->pos1.y -= Cos((u8)gBattleAnimArgs[4], gBattleAnimArgs[3]); + gSprites[spriteId].data[0] = gBattleAnimArgs[2]; + gSprites[spriteId].data[1] = gBattleAnimArgs[3]; + gSprites[spriteId].data[2] = gBattleAnimArgs[5]; + gSprites[spriteId].data[3] = (u8)gBattleAnimArgs[4] * 256; + gSprites[spriteId].data[4] = gBattleAnimArgs[6]; + sprite->callback = sub_8107380; + sub_8107380(sprite); +} + +void sub_8107380(struct Sprite *sprite) +{ + u8 otherSpriteId = sprite->data[5]; + u8 timer = gSprites[otherSpriteId].data[4]; + u16 trigIndex = gSprites[otherSpriteId].data[3]; + + sprite->data[0] = 1; + TranslateAnimLinear(sprite); + sprite->pos2.x += Sin(trigIndex >> 8, gSprites[otherSpriteId].data[0]); + sprite->pos2.y += Cos(trigIndex >> 8, gSprites[otherSpriteId].data[1]); + gSprites[otherSpriteId].data[3] = trigIndex + gSprites[otherSpriteId].data[2]; + if (--timer != 0) + { + gSprites[otherSpriteId].data[4] = timer; + } + else + { + sprite->callback = sub_8107408; + DestroySprite(&gSprites[otherSpriteId]); + } +} + +/* void FuncNameHere(struct Sprite *sprite) +{ + +} */ + +void sub_8107408(struct Sprite *sprite) +{ + sprite->animPaused = FALSE; + sprite->callback = RunStoredCallbackWhenAnimEnds; + StoreSpriteCallbackInData6(sprite, sub_8107430); +}