From 4023a0b288d758fc8e0ef4b7adea36cf5f39b10c Mon Sep 17 00:00:00 2001 From: Tal Hayon Date: Fri, 7 Jan 2022 04:42:12 +0200 Subject: [PATCH] Work on castorWildStatue --- .../castorWildsStatue/sub_080676E0.inc | 63 -------------- include/script.h | 36 ++++---- src/npc/castorWildsStatue.c | 86 ++++++++++++++++++- 3 files changed, 101 insertions(+), 84 deletions(-) delete mode 100644 asm/non_matching/castorWildsStatue/sub_080676E0.inc diff --git a/asm/non_matching/castorWildsStatue/sub_080676E0.inc b/asm/non_matching/castorWildsStatue/sub_080676E0.inc deleted file mode 100644 index 862de60f..00000000 --- a/asm/non_matching/castorWildsStatue/sub_080676E0.inc +++ /dev/null @@ -1,63 +0,0 @@ - .syntax unified - push {lr} - adds r3, r0, #0 - adds r2, r1, #0 - ldrb r0, [r2, #0x18] - cmp r0, #1 - beq _08067706 - cmp r0, #1 - bgt _080676F6 - cmp r0, #0 - beq _080676FC - b _08067734 -_080676F6: - cmp r0, #2 - beq _08067722 - b _08067734 -_080676FC: - movs r0, #1 - strb r0, [r2, #0x18] - movs r0, #0x20 - strb r0, [r2, #0x19] - b _08067742 -_08067706: - ldrb r1, [r2, #0x19] - lsrs r0, r1, #1 - subs r0, #0x10 - strh r0, [r3, #0x36] - subs r1, #1 - strb r1, [r2, #0x19] - lsls r1, r1, #0x18 - cmp r1, #0 - bne _08067742 - movs r0, #2 - strb r0, [r2, #0x18] - movs r0, #0x24 - strb r0, [r2, #0x19] - b _08067742 -_08067722: - ldrb r0, [r2, #0x19] - subs r0, #1 - strb r0, [r2, #0x19] - lsls r0, r0, #0x18 - cmp r0, #0 - bne _08067742 - movs r0, #3 - strb r0, [r2, #0x18] - b _08067742 -_08067734: - movs r1, #0xc0 - lsls r1, r1, #5 - adds r0, r3, #0 - bl GravityUpdate - cmp r0, #0 - beq _08067748 -_08067742: - ldr r1, _0806774C @ =gActiveScriptInfo - movs r0, #0 - strb r0, [r1, #6] -_08067748: - pop {pc} - .align 2, 0 -_0806774C: .4byte gActiveScriptInfo - .syntax divided diff --git a/include/script.h b/include/script.h index b59d8916..33ce1767 100644 --- a/include/script.h +++ b/include/script.h @@ -4,28 +4,28 @@ #include "entity.h" typedef struct ScriptExecutionContext { - u16* scriptInstructionPointer; - u32 intVariable; - u32 postScriptActions; - u8 unk_0C[0x4]; // unused - u16 wait; - u16 unk_12; - u32 condition; - u8 unk_18; - u8 unk_19; - u8 unk_1A; - u8 unk_1B; // unused - union SplitWord x; - union SplitWord y; + /*0x00*/ u16* scriptInstructionPointer; + /*0x03*/ u32 intVariable; + /*0x08*/ u32 postScriptActions; + /*0x0C*/ u8 unk_0C[0x4]; // unused + /*0x10*/ u16 wait; + /*0x12*/ u16 unk_12; + /*0x14*/ u32 condition; + /*0x18*/ u8 unk_18; + /*0x19*/ u8 unk_19; + /*0x1A*/ u8 unk_1A; + /*0x1B*/ u8 unk_1B; // unused + /*0x1C*/ union SplitWord x; + /*0x20*/ union SplitWord y; } ScriptExecutionContext; typedef struct { // Sync flags are used to synchronize scripts running on different entities - u32 syncFlags; - u16 commandIndex; - u8 commandSize; - u8 flags; - u8 unk_08; + /*0x0*/ u32 syncFlags; + /*0x4*/ u16 commandIndex; + /*0x6*/ u8 commandSize; + /*0x7*/ u8 flags; + /*0x8*/ u8 unk_08; } ActiveScriptInfo; extern ActiveScriptInfo gActiveScriptInfo; diff --git a/src/npc/castorWildsStatue.c b/src/npc/castorWildsStatue.c index 0a809793..c68f4020 100644 --- a/src/npc/castorWildsStatue.c +++ b/src/npc/castorWildsStatue.c @@ -15,6 +15,13 @@ extern s8 gUnk_08110E64[]; extern u32 gUnk_08110E68[]; +typedef struct { + s8 x; + s8 y; +} PACKED PosOffset; +extern PosOffset gUnk_08110E78[]; +extern PosOffset gUnk_08110E8A[]; + void CastorWildsStatue(Entity* this) { if ((this->flags & 2) != 0) { gUnk_08110E5C[this->action](this); @@ -113,14 +120,87 @@ void sub_0806757C(Entity* this) { } } -ASM_FUNC("asm/non_matching/castorWildsStatue/sub_080675D4.inc", void sub_080675D4(Entity* this)) +NONMATCH("asm/non_matching/castorWildsStatue/sub_080675D4.inc", void sub_080675D4(Entity* this)) { + PosOffset* gUnk = gUnk_08110E78; + u32 subAction = (this->subAction << 2) - 0xc; + s32 index = 8; + + do { + Entity* ent = CreateFx(this, 2, 0); + if (ent) { + ent->x.HALF.HI = gUnk->x + ent->x.HALF.HI; + ent->y.HALF.HI = gUnk->y + ent->y.HALF.HI; + ent->z.HALF.HI = subAction; + ent->collisionLayer = this->collisionLayer; + ent->spriteOrientation.flipY = this->spriteOrientation.flipY; + ent->spriteRendering.b3 = this->spriteRendering.b3; + ResolveEntityOnTop(this, ent); + } + index--; + gUnk += 1; + } while (index >= 0); + + gUnk = gUnk_08110E8A; + index = 3; + + do { + Entity* ent = CreateFx(this, 4, 0); + if (ent) { + ent->x.HALF.HI = gUnk->x + ent->x.HALF.HI; + ent->y.HALF.HI = gUnk->y + ent->y.HALF.HI; + ent->z.HALF.HI = subAction; + ent->collisionLayer = this->collisionLayer; + ent->spriteOrientation.flipY = this->spriteOrientation.flipY; + ent->spriteRendering.b3 = this->spriteRendering.b3; + ResolveEntityOnTop(this, ent); + } + index--; + gUnk += 1; + + } while (index >= 0); + + if (this->subAction > 2) { + this->spriteSettings.draw = 0; + } +} +END_NONMATCH void sub_080676D8(Entity* this) { this->subAction += 1; } -ASM_FUNC("asm/non_matching/castorWildsStatue/sub_080676E0.inc", - void sub_080676E0(Entity* this, ScriptExecutionContext* context)) +void sub_080676E0(Entity* this, ScriptExecutionContext* context) { + switch (context->unk_18) { + case 0: { + context->unk_18 = 1; + context->unk_19 = 0x20; + break; + } + case 1: { + this->z.HALF.HI = (context->unk_19 >> 1) - 0x10; + if (--context->unk_19 == 0) { + context->unk_18 = 2; + context->unk_19 = 0x24; + } + + break; + } + case 2: { + if (--context->unk_19 == 0) { + context->unk_18 = 3; + } + break; + } + default: { + if (GravityUpdate(this, 0x1800) == 0) { + return; + } + break; + } + } + + gActiveScriptInfo.commandSize = 0; +} void CastorWildsStatue_Fusion(Entity* this) { if (this->action == 0) {