From fa53dc24bde642817aa85983d53c8898bb8d70b9 Mon Sep 17 00:00:00 2001 From: octorock <79596758+octorock@users.noreply.github.com> Date: Sun, 30 Jan 2022 00:19:14 +0100 Subject: [PATCH] Decompile SmallIceBlock --- asm/object/smallIceBlock.s | 742 ------------------------------ data/const/object/smallIceBlock.s | 18 - src/object/smallIceBlock.c | 330 +++++++++++++ 3 files changed, 330 insertions(+), 760 deletions(-) delete mode 100644 asm/object/smallIceBlock.s delete mode 100644 data/const/object/smallIceBlock.s create mode 100644 src/object/smallIceBlock.c diff --git a/asm/object/smallIceBlock.s b/asm/object/smallIceBlock.s deleted file mode 100644 index 71c8cbec..00000000 --- a/asm/object/smallIceBlock.s +++ /dev/null @@ -1,742 +0,0 @@ - .include "asm/macros.inc" - - .include "constants/constants.inc" - - .syntax unified - - .text - - - thumb_func_start SmallIceBlock -SmallIceBlock: @ 0x080991A4 - push {lr} - adds r2, r0, #0 - ldrb r0, [r2, #0xa] - cmp r0, #2 - bhi _080991C4 - ldr r0, _080991C0 @ =gUnk_08123734 - ldrb r1, [r2, #0xc] - lsls r1, r1, #2 - adds r1, r1, r0 - ldr r1, [r1] - adds r0, r2, #0 - bl _call_via_r1 - b _080991CA - .align 2, 0 -_080991C0: .4byte gUnk_08123734 -_080991C4: - adds r0, r2, #0 - bl sub_080996AC -_080991CA: - pop {pc} - - thumb_func_start sub_080991CC -sub_080991CC: @ 0x080991CC - push {r4, lr} - adds r4, r0, #0 - ldrb r0, [r4, #0xa] - cmp r0, #2 - bgt _080991EC - cmp r0, #0 - blt _080991EC - adds r0, r4, #0 - adds r0, #0x86 - ldrh r0, [r0] - bl CheckFlags - cmp r0, #0 - beq _080991EC - bl DeleteThisEntity -_080991EC: - movs r2, #1 - strb r2, [r4, #0xc] - ldrb r1, [r4, #0x10] - movs r0, #0x80 - orrs r0, r1 - strb r0, [r4, #0x10] - ldrb r1, [r4, #0x11] - movs r0, #0x10 - rsbs r0, r0, #0 - ands r0, r1 - movs r1, #3 - orrs r0, r1 - strb r0, [r4, #0x11] - adds r1, r4, #0 - adds r1, #0x3c - movs r0, #7 - strb r0, [r1] - adds r1, #4 - movs r0, #0x48 - strb r0, [r1] - adds r0, r4, #0 - adds r0, #0x3f - strb r2, [r0] - subs r1, #5 - movs r0, #0x80 - strb r0, [r1] - ldr r0, _08099244 @ =gUnk_080FD408 - str r0, [r4, #0x48] - adds r0, r4, #0 - bl sub_08099468 - ldrb r1, [r4, #0xa] - adds r0, r4, #0 - bl InitializeAnimation - movs r0, #0x84 - movs r1, #3 - movs r2, #0 - bl CreateObject - cmp r0, #0 - beq _08099242 - str r4, [r0, #0x50] -_08099242: - pop {r4, pc} - .align 2, 0 -_08099244: .4byte gUnk_080FD408 - - thumb_func_start sub_08099248 -sub_08099248: @ 0x08099248 - push {r4, r5, r6, r7, lr} - adds r4, r0, #0 - bl sub_0809963C - cmp r0, #0 - beq _08099280 - movs r1, #0 - movs r0, #3 - strb r0, [r4, #0xc] - strb r1, [r4, #0xe] - ldr r0, _0809927C @ =0x000001B3 - bl EnqueueSFX - adds r0, r4, #0 - bl sub_08099330 - ldrb r0, [r4, #0xa] - cmp r0, #0 - bne _0809930E - adds r0, r4, #0 - adds r0, #0x86 - ldrh r0, [r0] - bl SetFlag - b _0809930E - .align 2, 0 -_0809927C: .4byte 0x000001B3 -_08099280: - adds r0, r4, #0 - bl sub_0800442E - cmp r0, #0 - bne _0809930E - adds r7, r4, #0 - adds r7, #0x70 - ldrh r0, [r7] - adds r6, r4, #0 - adds r6, #0x38 - ldrb r1, [r6] - bl GetTileType - adds r5, r0, #0 - ldr r0, _080992B8 @ =0x0000405A - cmp r5, r0 - beq _0809930E - adds r0, r5, #0 - bl sub_08099618 - cmp r0, #1 - beq _080992BC - cmp r0, #1 - blo _080992DC - cmp r0, #2 - beq _08099308 - b _0809930E - .align 2, 0 -_080992B8: .4byte 0x0000405A -_080992BC: - movs r0, #2 - strb r0, [r4, #0xc] - movs r0, #0x16 - strb r0, [r4, #0xe] - adds r0, r5, #0 - subs r0, #0x5b - movs r1, #3 - ands r0, r1 - lsls r0, r0, #3 - strb r0, [r4, #0x15] - movs r0, #0x20 - strh r0, [r4, #0x24] - adds r0, r4, #0 - bl sub_080994B8 - b _0809930E -_080992DC: - movs r0, #0xf - movs r1, #0xd - movs r2, #0 - bl CreateObject - adds r1, r0, #0 - cmp r1, #0 - beq _080992F2 - adds r0, r4, #0 - bl CopyPosition -_080992F2: - adds r0, r4, #0 - adds r0, #0x6c - ldrh r0, [r0] - ldrh r1, [r7] - ldrb r2, [r6] - bl SetTile - adds r0, r4, #0 - bl DeleteEntity - b _0809930E -_08099308: - adds r0, r4, #0 - adds r0, #0x6c - strh r5, [r0] -_0809930E: - pop {r4, r5, r6, r7, pc} - - thumb_func_start sub_08099310 -sub_08099310: @ 0x08099310 - push {r4, lr} - adds r4, r0, #0 - bl sub_0809953C - cmp r0, #0 - beq _0809932E - movs r0, #1 - strb r0, [r4, #0xc] - adds r0, r4, #0 - bl sub_08099468 - movs r0, #0xd9 - lsls r0, r0, #1 - bl EnqueueSFX -_0809932E: - pop {r4, pc} - - thumb_func_start sub_08099330 -sub_08099330: @ 0x08099330 - push {r4, lr} - adds r4, r0, #0 - bl sub_0809963C - adds r1, r0, #0 - cmp r1, #0 - bne _0809935E - ldrb r0, [r4, #0xe] - cmp r0, #1 - bls _0809934A - subs r0, #2 - strb r0, [r4, #0xe] - b _0809934C -_0809934A: - strb r1, [r4, #0xe] -_0809934C: - ldrb r0, [r4, #0xe] - cmp r0, #0 - bne _08099364 - movs r0, #1 - strb r0, [r4, #0xc] - adds r0, r4, #0 - bl sub_0805EC60 - b _080993CA -_0809935E: - ldrb r0, [r4, #0xe] - adds r0, #1 - strb r0, [r4, #0xe] -_08099364: - movs r1, #0x80 - lsls r1, r1, #1 - ldr r2, _0809939C @ =gUnk_08123748 - ldrb r0, [r4, #0xe] - lsrs r0, r0, #5 - lsls r0, r0, #1 - adds r0, r0, r2 - ldrh r2, [r0] - adds r0, r4, #0 - movs r3, #0 - bl sub_0805EC9C - ldrb r0, [r4, #0xa] - cmp r0, #1 - bne _080993A0 - adds r0, r4, #0 - adds r0, #0x86 - ldrh r3, [r0] - adds r0, r4, #0 - movs r1, #0x53 - movs r2, #0 - bl sub_080A2A3C - movs r0, #0x72 - bl SoundReq - b _080993BA - .align 2, 0 -_0809939C: .4byte gUnk_08123748 -_080993A0: - cmp r0, #2 - bne _080993BA - adds r0, r4, #0 - adds r0, #0x86 - ldrh r3, [r0] - adds r0, r4, #0 - movs r1, #0x52 - movs r2, #0 - bl sub_080A2A3C - movs r0, #0x72 - bl SoundReq -_080993BA: - movs r0, #4 - strb r0, [r4, #0xc] - movs r0, #0x3c - strb r0, [r4, #0xe] - ldrb r1, [r4, #0x10] - movs r0, #0x7f - ands r0, r1 - strb r0, [r4, #0x10] -_080993CA: - pop {r4, pc} - - thumb_func_start sub_080993CC -sub_080993CC: @ 0x080993CC - push {r4, r5, r6, lr} - adds r5, r0, #0 - ldrb r0, [r5, #0xe] - subs r1, r0, #1 - strb r1, [r5, #0xe] - lsls r0, r1, #0x18 - cmp r0, #0 - bne _080993E2 - bl DeleteThisEntity - b _08099466 -_080993E2: - lsls r0, r1, #0x18 - lsrs r0, r0, #0x18 - cmp r0, #0x30 - bne _08099400 - adds r0, r5, #0 - adds r0, #0x6c - ldrh r0, [r0] - adds r1, r5, #0 - adds r1, #0x70 - ldrh r1, [r1] - adds r2, r5, #0 - adds r2, #0x38 - ldrb r2, [r2] - bl SetTile -_08099400: - movs r1, #0x80 - lsls r1, r1, #1 - ldrb r0, [r5, #0xe] - movs r2, #0x3c - subs r2, r2, r0 - lsls r2, r2, #5 - adds r2, r2, r1 - adds r0, r5, #0 - movs r3, #0 - bl sub_0805EC9C - ldrb r1, [r5, #0xe] - movs r0, #1 - ands r0, r1 - cmp r0, #0 - beq _08099466 - movs r0, #0xf - movs r1, #0x11 - movs r2, #0x40 - bl CreateObject - adds r6, r0, #0 - cmp r6, #0 - beq _08099466 - bl Random - adds r4, r0, #0 - asrs r0, r4, #0x10 - movs r1, #9 - bl __modsi3 - adds r2, r0, #0 - subs r2, #4 - movs r3, #0xf - ands r3, r4 - adds r4, r6, #0 - adds r4, #0x29 - ldrb r1, [r4] - movs r0, #8 - rsbs r0, r0, #0 - ands r0, r1 - movs r1, #3 - orrs r0, r1 - strb r0, [r4] - lsls r2, r2, #0x10 - rsbs r3, r3, #0 - lsls r3, r3, #0x10 - adds r0, r5, #0 - adds r1, r6, #0 - bl PositionRelative -_08099466: - pop {r4, r5, r6, pc} - - thumb_func_start sub_08099468 -sub_08099468: @ 0x08099468 - push {r4, r5, r6, lr} - adds r6, r0, #0 - movs r0, #0x2e - ldrsh r1, [r6, r0] - ldr r2, _080994B0 @ =gRoomControls - ldrh r0, [r2, #6] - subs r1, r1, r0 - asrs r1, r1, #4 - movs r3, #0x3f - ands r1, r3 - movs r4, #0x32 - ldrsh r0, [r6, r4] - ldrh r2, [r2, #8] - subs r0, r0, r2 - asrs r0, r0, #4 - ands r0, r3 - lsls r0, r0, #6 - orrs r1, r0 - adds r4, r6, #0 - adds r4, #0x70 - strh r1, [r4] - ldrh r0, [r4] - adds r5, r6, #0 - adds r5, #0x38 - ldrb r1, [r5] - bl GetTileIndex - adds r1, r6, #0 - adds r1, #0x6c - strh r0, [r1] - ldr r0, _080994B4 @ =0x0000405A - ldrh r1, [r4] - ldrb r2, [r5] - bl SetTile - pop {r4, r5, r6, pc} - .align 2, 0 -_080994B0: .4byte gRoomControls -_080994B4: .4byte 0x0000405A - - thumb_func_start sub_080994B8 -sub_080994B8: @ 0x080994B8 - push {r4, r5, r6, lr} - adds r5, r0, #0 - ldr r0, _08099530 @ =0x000001B1 - bl EnqueueSFX - adds r0, r5, #0 - adds r0, #0x6c - ldrh r0, [r0] - adds r6, r5, #0 - adds r6, #0x70 - ldrh r1, [r6] - adds r4, r5, #0 - adds r4, #0x38 - ldrb r2, [r4] - bl SetTile - ldrb r0, [r4] - cmp r0, #2 - bne _080994F8 - ldrh r0, [r6] - movs r1, #1 - bl GetTileType - ldr r1, _08099534 @ =0x0000405A - cmp r0, r1 - bne _080994F8 - movs r0, #0xc4 - lsls r0, r0, #2 - ldrh r1, [r6] - movs r2, #1 - bl sub_08000152 -_080994F8: - adds r2, r5, #0 - adds r2, #0x70 - ldr r1, _08099538 @ =gUnk_080B4488 - ldrb r0, [r5, #0x15] - lsrs r0, r0, #3 - lsls r0, r0, #1 - adds r0, r0, r1 - movs r1, #0 - ldrsh r0, [r0, r1] - ldrh r2, [r2] - adds r0, r0, r2 - adds r1, r5, #0 - adds r1, #0x38 - ldrb r1, [r1] - bl GetTileType - lsls r0, r0, #0x10 - lsrs r0, r0, #0x10 - cmp r0, #0x79 - beq _08099524 - cmp r0, #0x77 - bne _0809952C -_08099524: - adds r1, r5, #0 - adds r1, #0x63 - movs r0, #0xfe - strb r0, [r1] -_0809952C: - pop {r4, r5, r6, pc} - .align 2, 0 -_08099530: .4byte 0x000001B1 -_08099534: .4byte 0x0000405A -_08099538: .4byte gUnk_080B4488 - - thumb_func_start sub_0809953C -sub_0809953C: @ 0x0809953C - push {r4, lr} - adds r4, r0, #0 - bl sub_0800442E - cmp r0, #0 - bne _08099612 - adds r0, r4, #0 - bl sub_080AEFE0 - adds r0, r4, #0 - bl sub_0800445C - ldrb r1, [r4, #0xe] - cmp r1, #0 - beq _08099570 - ldrh r0, [r4, #0x24] - adds r0, #0x10 - strh r0, [r4, #0x24] - subs r0, r1, #1 - strb r0, [r4, #0xe] - lsls r0, r0, #0x18 - cmp r0, #0 - bne _08099570 - movs r0, #0x80 - lsls r0, r0, #2 - strh r0, [r4, #0x24] -_08099570: - ldrb r0, [r4, #0x15] - lsrs r0, r0, #3 - cmp r0, #1 - beq _080995A0 - cmp r0, #1 - bgt _08099582 - cmp r0, #0 - beq _08099588 - b _080995E6 -_08099582: - cmp r0, #2 - beq _080995BA - b _080995E6 -_08099588: - ldrh r1, [r4, #0x2a] - movs r0, #0xe - ands r0, r1 - cmp r0, #0 - beq _08099612 - ldrh r1, [r4, #0x32] - movs r0, #0xf - ands r0, r1 - subs r0, #7 - cmp r0, #2 - bls _080995D0 - b _080995DE -_080995A0: - ldrh r1, [r4, #0x2a] - movs r0, #0xe0 - lsls r0, r0, #8 - ands r0, r1 - cmp r0, #0 - beq _08099612 - ldrh r1, [r4, #0x2e] - movs r0, #0xf - ands r0, r1 - subs r0, #7 - cmp r0, #2 - bls _080995FE - b _080995DE -_080995BA: - ldrh r1, [r4, #0x2a] - movs r0, #0xe0 - ands r0, r1 - cmp r0, #0 - beq _08099612 - ldrh r1, [r4, #0x32] - movs r0, #0xf - ands r0, r1 - subs r0, #7 - cmp r0, #2 - bhi _080995DE -_080995D0: - movs r0, #0x10 - rsbs r0, r0, #0 - ands r0, r1 - adds r0, #8 - strh r0, [r4, #0x32] - movs r0, #1 - b _08099614 -_080995DE: - adds r0, r4, #0 - bl sub_0809969C - b _08099612 -_080995E6: - ldrh r1, [r4, #0x2a] - movs r0, #0xe0 - lsls r0, r0, #4 - ands r0, r1 - cmp r0, #0 - beq _08099612 - ldrh r1, [r4, #0x2e] - movs r0, #0xf - ands r0, r1 - subs r0, #7 - cmp r0, #2 - bhi _0809960C -_080995FE: - movs r0, #0x10 - rsbs r0, r0, #0 - ands r0, r1 - adds r0, #8 - strh r0, [r4, #0x2e] - movs r0, #1 - b _08099614 -_0809960C: - adds r0, r4, #0 - bl sub_0809969C -_08099612: - movs r0, #0 -_08099614: - pop {r4, pc} - .align 2, 0 - - thumb_func_start sub_08099618 -sub_08099618: @ 0x08099618 - push {lr} - adds r2, r0, #0 - ldr r1, _08099620 @ =gUnk_08123750 - b _08099630 - .align 2, 0 -_08099620: .4byte gUnk_08123750 -_08099624: - ldrh r0, [r1] - cmp r0, r2 - bne _0809962E - ldrh r0, [r1, #2] - b _08099638 -_0809962E: - adds r1, #4 -_08099630: - ldrh r0, [r1] - cmp r0, #0 - bne _08099624 - movs r0, #0 -_08099638: - pop {pc} - .align 2, 0 - - thumb_func_start sub_0809963C -sub_0809963C: @ 0x0809963C - push {r4, r5, r6, lr} - adds r5, r0, #0 - ldrb r0, [r5, #0xb] - cmp r0, #0 - beq _08099684 - bl GetCurrentRoomProperty - adds r4, r0, #0 - ldrh r0, [r4] - bl CheckFlags - cmp r0, #0 - beq _08099684 - ldr r0, _08099694 @ =gRoomControls - ldrh r1, [r0, #6] - ldrh r2, [r4, #2] - adds r1, r1, r2 - lsls r1, r1, #0x10 - lsrs r1, r1, #0x10 - ldrh r0, [r0, #8] - ldrh r6, [r4, #4] - adds r0, r0, r6 - lsls r0, r0, #0x10 - lsrs r3, r0, #0x10 - ldrh r2, [r4, #6] - movs r6, #0x2e - ldrsh r0, [r5, r6] - subs r0, r0, r1 - cmp r2, r0 - blo _08099684 - ldrh r1, [r4, #8] - movs r2, #0x32 - ldrsh r0, [r5, r2] - subs r0, r0, r3 - cmp r1, r0 - bhs _08099698 -_08099684: - adds r0, r5, #0 - adds r0, #0x41 - ldrb r0, [r0] - cmp r0, #0x87 - beq _08099698 - movs r0, #0 - b _0809969A - .align 2, 0 -_08099694: .4byte gRoomControls -_08099698: - movs r0, #1 -_0809969A: - pop {r4, r5, r6, pc} - - thumb_func_start sub_0809969C -sub_0809969C: @ 0x0809969C - push {lr} - movs r1, #0xd - movs r2, #0 - bl CreateFx - bl DeleteThisEntity - pop {pc} - - thumb_func_start sub_080996AC -sub_080996AC: @ 0x080996AC - push {r4, lr} - adds r4, r0, #0 - ldr r0, [r4, #0x50] - ldr r0, [r0, #4] - cmp r0, #0 - bne _080996BC - bl DeleteThisEntity -_080996BC: - ldrb r0, [r4, #0xc] - cmp r0, #0 - bne _080996CE - movs r0, #1 - strb r0, [r4, #0xc] - adds r0, r4, #0 - movs r1, #3 - bl InitializeAnimation -_080996CE: - ldr r0, [r4, #0x50] - ldrb r0, [r0, #0xc] - cmp r0, #2 - bhi _08099726 - ldrb r1, [r4, #0x18] - movs r0, #4 - rsbs r0, r0, #0 - ands r0, r1 - movs r1, #1 - orrs r0, r1 - strb r0, [r4, #0x18] - adds r2, r4, #0 - adds r2, #0x5a - ldrb r1, [r2] - movs r0, #1 - ands r0, r1 - cmp r0, #0 - beq _08099706 - movs r0, #0 - strb r0, [r2] - bl Random - movs r1, #0x78 - ands r0, r1 - adds r0, #0x78 - adds r1, r4, #0 - adds r1, #0x59 - strb r0, [r1] -_08099706: - adds r0, r4, #0 - bl GetNextFrame - ldr r0, [r4, #0x50] - adds r1, r4, #0 - bl CopyPositionAndSpriteOffset - ldrh r0, [r4, #0x32] - adds r0, #1 - strh r0, [r4, #0x32] - adds r1, r4, #0 - adds r1, #0x63 - ldrb r0, [r1] - subs r0, #0x11 - strb r0, [r1] - b _08099730 -_08099726: - ldrb r1, [r4, #0x18] - movs r0, #4 - rsbs r0, r0, #0 - ands r0, r1 - strb r0, [r4, #0x18] -_08099730: - pop {r4, pc} - .align 2, 0 diff --git a/data/const/object/smallIceBlock.s b/data/const/object/smallIceBlock.s deleted file mode 100644 index 9107a43f..00000000 --- a/data/const/object/smallIceBlock.s +++ /dev/null @@ -1,18 +0,0 @@ - .include "asm/macros.inc" - .include "constants/constants.inc" - - .section .rodata - .align 2 - -gUnk_08123734:: @ 08123734 - .4byte sub_080991CC - .4byte sub_08099248 - .4byte sub_08099310 - .4byte sub_08099330 - .4byte sub_080993CC - -gUnk_08123748:: @ 08123748 - .incbin "smallIceBlock/gUnk_08123748.bin" - -gUnk_08123750:: @ 08123750 - .incbin "smallIceBlock/gUnk_08123750.bin" diff --git a/src/object/smallIceBlock.c b/src/object/smallIceBlock.c new file mode 100644 index 00000000..63542a02 --- /dev/null +++ b/src/object/smallIceBlock.c @@ -0,0 +1,330 @@ +/** + * @file smallIceBlock.c + * @ingroup Objects + * + * @brief Small Ice Block object + */ + +#define NENT_DEPRECATED +#include "global.h" +#include "object.h" +#include "functions.h" + +typedef struct { + /*0x00*/ Entity base; + /*0x68*/ u8 unk_68[0x4]; + /*0x6c*/ u16 unk_6c; + /*0x6e*/ u8 unk_6e[0x2]; + /*0x70*/ u16 unk_70; + /*0x72*/ u8 unk_72[0x14]; + /*0x86*/ u16 unk_86; +} SmallIceBlockEntity; + +extern const Hitbox gUnk_080FD408; +extern const s16 gUnk_080B4488[]; + +void sub_080996AC(SmallIceBlockEntity*); +void sub_08099468(SmallIceBlockEntity*); +bool32 sub_0809963C(SmallIceBlockEntity*); +u32 sub_08099618(u32); +void sub_080994B8(SmallIceBlockEntity*); +void SmallIceBlock_Action3(SmallIceBlockEntity*); +bool32 sub_0809953C(SmallIceBlockEntity*); +void sub_0809969C(SmallIceBlockEntity*); + +extern void (*const gUnk_08123734[])(SmallIceBlockEntity*); +extern const u16 gUnk_08123748[]; +extern const u16 gUnk_08123750[]; + +void SmallIceBlock(SmallIceBlockEntity* this) { + if (super->type < 3) { + gUnk_08123734[super->action](this); + } else { + sub_080996AC(this); + } +} + +void SmallIceBlock_Init(SmallIceBlockEntity* this) { + Entity* obj; + + switch (super->type) { + case 0: + case 1: + case 2: + if (CheckFlags(this->unk_86)) { + DeleteThisEntity(); + } + } + super->action = 1; + super->flags |= 0x80; + super->updatePriority = 3; + super->field_0x3c = 7; + super->hurtType = 0x48; + super->hitType = 1; + super->flags2 = 0x80; + super->hitbox = (Hitbox*)&gUnk_080FD408; + sub_08099468(this); + InitializeAnimation(super, super->type); + obj = CreateObject(SMALL_ICE_BLOCK, 3, 0); + if (obj != NULL) { + obj->parent = super; + } +} + +void SmallIceBlock_Action1(SmallIceBlockEntity* this) { + u32 tileType; + Entity* obj; + + if (sub_0809963C(this)) { + super->action = 3; + super->actionDelay = 0; + EnqueueSFX(SFX_ICE_BLOCK_MELT); + SmallIceBlock_Action3(this); + if (super->type == 0) { + SetFlag(this->unk_86); + } + } else { + if (!sub_0800442E(super)) { + tileType = GetTileType(this->unk_70, super->collisionLayer); + if (tileType != 0x405a) { + switch (sub_08099618(tileType)) { + case 1: + super->action = 2; + super->actionDelay = 0x16; + super->direction = ((tileType - 0x5b) & 3) << 3; + super->speed = 0x20; + sub_080994B8(this); + break; + case 0: + obj = CreateObject(SPECIAL_FX, 0xd, 0); + if (obj != NULL) { + CopyPosition(super, obj); + } + SetTile(this->unk_6c, this->unk_70, super->collisionLayer); + DeleteEntity(super); + break; + + case 2: + this->unk_6c = (u16)tileType; + break; + } + } + } + } +} + +void SmallIceBlock_Action2(SmallIceBlockEntity* this) { + if (sub_0809953C(this)) { + super->action = 1; + sub_08099468(this); + EnqueueSFX(SFX_ICE_BLOCK_STOP); + } +} + +void SmallIceBlock_Action3(SmallIceBlockEntity* this) { + if (sub_0809963C(this) == 0) { + if (super->actionDelay >= 2) { + super->actionDelay -= 2; + } else { + super->actionDelay = 0; + } + if (super->actionDelay == 0) { + super->action = 1; + sub_0805EC60(super); + return; + } + } else { + super->actionDelay++; + } + sub_0805EC9C(super, 0x100, gUnk_08123748[super->actionDelay >> 5], 0); + if (super->type == 1) { + sub_080A2A3C(super, 0x53, 0, this->unk_86); + SoundReq(SFX_SECRET); + } else if (super->type == 2) { + sub_080A2A3C(super, 0x52, 0, this->unk_86); + SoundReq(SFX_SECRET); + } + super->action = 4; + super->actionDelay = 0x3c; + super->flags &= 0x7f; +} + +void SmallIceBlock_Action4(SmallIceBlockEntity* this) { + Entity* obj; + s32 rand; + s32 x; + s32 y; + + if (--super->actionDelay == 0) { + DeleteThisEntity(); + } else { + if (super->actionDelay == 0x30) { + SetTile(this->unk_6c, this->unk_70, super->collisionLayer); + } + sub_0805EC9C(super, 0x100, (0x3c - super->actionDelay) * 0x20 + 0x100, 0); + if ((super->actionDelay & 1) != 0) { + obj = CreateObject(SPECIAL_FX, 0x11, 0x40); + if (obj != NULL) { + rand = Random(); + x = ((rand >> 0x10) % 9) - 4; + y = rand & 0xf; + obj->spritePriority.b0 = 3; + PositionRelative(super, obj, x * 0x10000, -y * 0x10000); + } + } + } +} + +void sub_08099468(SmallIceBlockEntity* this) { + this->unk_70 = COORD_TO_TILE(super); + this->unk_6c = GetTileIndex(this->unk_70, super->collisionLayer); + SetTile(0x405a, this->unk_70, super->collisionLayer); +} + +void sub_080994B8(SmallIceBlockEntity* this) { + u16 tileType; + + EnqueueSFX(SFX_ICE_BLOCK_SLIDE); + SetTile(this->unk_6c, this->unk_70, super->collisionLayer); + if ((super->collisionLayer == 2) && (GetTileType(this->unk_70, 1) == 0x405a)) { + sub_08000152(0x310, this->unk_70, 1); + } + tileType = GetTileType(this->unk_70 + gUnk_080B4488[super->direction >> 3], super->collisionLayer); + if (tileType == 0x79 || tileType == 0x77) { + super->spriteOffsetY = -2; + } +} + +bool32 sub_0809953C(SmallIceBlockEntity* this) { + u8 bVar1; + u8 uVar2; + u32 uVar3; + u16 uVar4; + + uVar3 = sub_0800442E(super); + if (uVar3 != 0) { + return 0; + } + sub_080AEFE0(super); + sub_0800445C(super); + if (super->actionDelay != 0) { + super->speed += 0x10; + if (--super->actionDelay == 0) { + super->speed = 0x200; + } + } + switch (super->direction >> 3) { + case 0: + if ((super->collisions & 0xe) == 0) { + return 0; + } + if ((u32)(super->y.HALF.HI & 0xf) - 7 < 3) { + super->y.HALF.HI = (super->y.HALF.HI & 0xfff0) + 8; + return 1; + } + sub_0809969C(this); + break; + case 1: + if ((super->collisions & 0xe000) == 0) { + return FALSE; + } + if ((u32)(super->x.HALF.HI & 0xf) - 7 < 3) { + super->x.HALF.HI = (super->x.HALF.HI & 0xfff0) + 8; + return TRUE; + } + sub_0809969C(this); + break; + case 2: + if ((super->collisions & 0xe0) == 0) { + return FALSE; + } + if ((u32)(super->y.HALF.HI & 0xf) - 7 < 3) { + super->y.HALF.HI = (super->y.HALF.HI & 0xfff0) + 8; + return TRUE; + } + sub_0809969C(this); + break; + default: + if ((super->collisions & 0xe00) != 0) { + if ((u32)(super->x.HALF.HI & 0xf) - 7 < 3) { + super->x.HALF.HI = (super->x.HALF.HI & 0xfff0) + 8; + return TRUE; + } + sub_0809969C(this); + } + break; + } + return FALSE; +} + +u32 sub_08099618(u32 param_1) { + const u16* it; + for (it = gUnk_08123750; *it != 0; it += 2) { + if (*it == param_1) { + return it[1]; + } + } + return 0; +} + +bool32 sub_0809963C(SmallIceBlockEntity* this) { + u16* var; + u16 x; + u16 y; + + if (super->type2 != 0) { + var = (u16*)GetCurrentRoomProperty(super->type2); + if (CheckFlags(var[0])) { + x = var[1] + gRoomControls.origin_x; + y = var[2] + gRoomControls.origin_y; + if (var[3] >= (u32)(super->x.HALF.HI - x) && var[4] >= (u32)(super->y.HALF.HI - y)) { + return TRUE; + } + } + } + if (super->bitfield == 0x87) { + return TRUE; + } + return FALSE; +} + +void sub_0809969C(SmallIceBlockEntity* this) { + CreateFx(super, 0xd, 0); + DeleteThisEntity(); +} + +void sub_080996AC(SmallIceBlockEntity* this) { + if ((super->parent)->next == NULL) { + DeleteThisEntity(); + } + if (super->action == 0) { + super->action = 1; + InitializeAnimation(super, 3); + } + if ((super->parent)->action < 3) { + super->spriteSettings.draw = 1; + if ((super->frame & 1) != 0) { + super->frame = 0; + super->frameDuration = (Random() & 0x78) + 0x78; + } + GetNextFrame(super); + CopyPositionAndSpriteOffset(super->parent, super); + super->y.HALF.HI += 1; + super->spriteOffsetY -= 0x11; + } else { + super->spriteSettings.draw = 0; + } +} + +void (*const gUnk_08123734[])(SmallIceBlockEntity*) = { + SmallIceBlock_Init, SmallIceBlock_Action1, SmallIceBlock_Action2, SmallIceBlock_Action3, SmallIceBlock_Action4, +}; +const u16 gUnk_08123748[] = { + 256, + 264, + 271, + 277, +}; +const u16 gUnk_08123750[] = { + 0x405b, 1, 0x405c, 1, 0x405d, 1, 0x405e, 1, 0x7a, 2, 0x78, 2, 0, +};