From 723c063ee0daa944be036f6949912da76a65457c Mon Sep 17 00:00:00 2001 From: 21aslade Date: Sat, 21 Aug 2021 23:04:24 -0600 Subject: book.c OK --- src/object/book.c | 238 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 238 insertions(+) create mode 100644 src/object/book.c (limited to 'src') diff --git a/src/object/book.c b/src/object/book.c new file mode 100644 index 00000000..fa560142 --- /dev/null +++ b/src/object/book.c @@ -0,0 +1,238 @@ +#include "entity.h" +#include "functions.h" +#include "player.h" +#include "script.h" +#include "flags.h" +#include "room.h" +#include "textbox.h" + +extern void (*const BookActionFuncs[])(Entity*); +extern s8 const gUnk_08123D94[]; + +u32 sub_0809B688(Entity*); +void sub_0809B6B0(Entity*, Entity*); + +void Book(Entity* this) { + BookActionFuncs[this->action](this); +} + +void sub_0809B3C4(Entity* this) { + u32 obtained; + + obtained = GetInventoryValue(this->type + 0x39); + if (this->type2 != 3) { + if (obtained) { + DeleteThisEntity(); + } + } else { + if (CheckLocalFlag(0x73)) { + DeleteThisEntity(); + } + + if (obtained != 2) { + this->spriteSettings.b.draw = 0; + } + } + + this->spriteOffsetY = 3; + if (CheckFlags(this->field_0x86.HWORD)) { + if (this->type2 == 0) { + this->y.HALF.HI += 48; + } + + this->type2 = 2; + } + + UpdateSpriteForCollisionLayer(this); + InitAnimationForceUpdate(this, this->type + 0x39); + + switch (this->type2) { + case 0: + this->action = 1; + this->actionDelay = 22; + this->field_0xf = 2; + this->field_0x80.HALF.LO = 0; + this->spritePriority.b0 = 3; + break; + case 1: { + u32 scroll; + u32 height; + this->action = 3; + scroll = (u16)gRoomControls.roomScrollY - 0x10; + height = (u16)this->y.HALF.HI - scroll; + this->height.HALF.HI -= height; + return; + } + case 2: + this->action = 4; + return; + case 3: + this->action = 5; + this->subAction = 0; + this->spritePriority.b0 = 3; + break; + default: + return; + } +} + +void sub_0809B4A8(Entity* this) { + sub_0800445C(this); + + if (this->field_0x80.HALF.LO != 0) { + this->field_0x80.HALF.LO--; + return; + } + + if (sub_0809B688(this)) { + if (--this->actionDelay) { + return; + } + + this->action = 2; + this->actionDelay = 30; + this->speed = 64; + this->direction = 16; + + gPlayerState.pushedObject = 0x9e; + gPlayerState.playerAction = 5; + gPlayerState.flags.all |= 1; + + gPlayerEntity.x.HALF.LO = 0; + gPlayerEntity.y.HALF.LO = 0; + gPlayerEntity.direction = gPlayerEntity.animationState << 2; + EnqueueSFX(0x10f); + } + else { + this->actionDelay = 0x16; + } +} + +void sub_0809B524(Entity* this) { + if (--this->actionDelay == 0) { + if (--this->field_0xf == 0) { + this->action = 3; + this->y.HALF.HI += 32; + this->height.HALF.HI -= 32; + } + else { + this->action = 1; + this->actionDelay = 22; + this->field_0x80.HALF.LO = 24; + } + } + + sub_0806F69C(this); +} + +void sub_0809B56C(Entity* this) { + Entity* fx; + + if (sub_080044EC(this, 0x2800) != 1) { + return; + } + + this->action = 4; + this->spritePriority.b0 = 4; + + SetFlag(this->field_0x86.HWORD); + + fx = CreateFx(this, 2, 0); + if (fx) { + ResolveEntityOnTop(this, fx); + } +} + +void sub_0809B5B4(Entity* this) { + if (gPlayerState.flags.all & 0x80) { + sub_0800445C(this); + } + else if (sub_08017850(this)) { + CreateItemEntity(this->type + 0x39, 0, 0); + DeleteThisEntity(); + } +} + +void sub_0809B5EC(Entity* this) { + if (this->spriteSettings.b.draw == 1) { + switch (this->subAction) { + case 0: { + Entity* parent; + parent = FindEntityByID(7, 26, 7); + if (!parent) return; + if (parent->x.HALF.HI < this->x.HALF.HI) return; + if (parent->animationState != 4) return; + + this->parent = parent; + this->subAction = 1; + sub_0809B6B0(this->parent, this); + break; + } + case 1: { + if (!this->parent || !this->parent->next) { + DeleteThisEntity(); + return; + } + sub_0809B6B0(this->parent, this); + break; + } + default: return; + } + + + } + else { + switch (this->subAction) { + default: { + DeleteThisEntity(); + break; + } + case 0: { + if (GetInventoryValue(this->type + 0x39) == 2) { + this->subAction = 1; + } + break; + } + case 1: { + u8 doTextBox = gTextBox.doTextBox & 0x7f; + if (!doTextBox) { + this->spriteSettings.b.draw = 1; + this->subAction = doTextBox; + } + break; + } + } + } +} + +u32 sub_0809B688(Entity* this) { + u32 ret; + + ret = sub_080041A0(this, &gPlayerEntity, 6, 12); + if (ret == 1 && gPlayerState.field_0xd != 16) { + ret = 0; + } + + return ret; +} + +void sub_0809B6B0(Entity* parent, Entity* this) { + s32 offset; + offset = (s32)gUnk_08123D94[parent->animationState >> 1] << 16; + + PositionRelative(parent, this, 0, offset); + + this->height.HALF.HI = -(this->type << 2); + this->spritePriority.b0 = 3 - this->type; +} + +void (*const BookActionFuncs[])(Entity*) = { + sub_0809B3C4, + sub_0809B4A8, + sub_0809B524, + sub_0809B56C, + sub_0809B5B4, + sub_0809B5EC +}; + +const s8 gUnk_08123D94[] = { -22, -20, -20, -20 }; \ No newline at end of file -- cgit v1.2.3 From d1b63497a79fba6b271dd3f70710bc698d8d1e62 Mon Sep 17 00:00:00 2001 From: 21aslade Date: Sun, 22 Aug 2021 12:50:45 -0600 Subject: clang format --- src/object/book.c | 39 ++++++++++++++++++--------------------- 1 file changed, 18 insertions(+), 21 deletions(-) (limited to 'src') diff --git a/src/object/book.c b/src/object/book.c index fa560142..ee53ef99 100644 --- a/src/object/book.c +++ b/src/object/book.c @@ -83,7 +83,7 @@ void sub_0809B4A8(Entity* this) { this->field_0x80.HALF.LO--; return; } - + if (sub_0809B688(this)) { if (--this->actionDelay) { return; @@ -102,8 +102,7 @@ void sub_0809B4A8(Entity* this) { gPlayerEntity.y.HALF.LO = 0; gPlayerEntity.direction = gPlayerEntity.animationState << 2; EnqueueSFX(0x10f); - } - else { + } else { this->actionDelay = 0x16; } } @@ -114,8 +113,7 @@ void sub_0809B524(Entity* this) { this->action = 3; this->y.HALF.HI += 32; this->height.HALF.HI -= 32; - } - else { + } else { this->action = 1; this->actionDelay = 22; this->field_0x80.HALF.LO = 24; @@ -146,8 +144,7 @@ void sub_0809B56C(Entity* this) { void sub_0809B5B4(Entity* this) { if (gPlayerState.flags.all & 0x80) { sub_0800445C(this); - } - else if (sub_08017850(this)) { + } else if (sub_08017850(this)) { CreateItemEntity(this->type + 0x39, 0, 0); DeleteThisEntity(); } @@ -159,9 +156,15 @@ void sub_0809B5EC(Entity* this) { case 0: { Entity* parent; parent = FindEntityByID(7, 26, 7); - if (!parent) return; - if (parent->x.HALF.HI < this->x.HALF.HI) return; - if (parent->animationState != 4) return; + if (!parent) { + return; + } + if (parent->x.HALF.HI < this->x.HALF.HI) { + return; + } + if (parent->animationState != 4) { + return; + } this->parent = parent; this->subAction = 1; @@ -176,12 +179,11 @@ void sub_0809B5EC(Entity* this) { sub_0809B6B0(this->parent, this); break; } - default: return; + default: + return; } - - } - else { + } else { switch (this->subAction) { default: { DeleteThisEntity(); @@ -196,7 +198,7 @@ void sub_0809B5EC(Entity* this) { case 1: { u8 doTextBox = gTextBox.doTextBox & 0x7f; if (!doTextBox) { - this->spriteSettings.b.draw = 1; + this->spriteSettings.b.draw = 1; this->subAction = doTextBox; } break; @@ -227,12 +229,7 @@ void sub_0809B6B0(Entity* parent, Entity* this) { } void (*const BookActionFuncs[])(Entity*) = { - sub_0809B3C4, - sub_0809B4A8, - sub_0809B524, - sub_0809B56C, - sub_0809B5B4, - sub_0809B5EC + sub_0809B3C4, sub_0809B4A8, sub_0809B524, sub_0809B56C, sub_0809B5B4, sub_0809B5EC, }; const s8 gUnk_08123D94[] = { -22, -20, -20, -20 }; \ No newline at end of file -- cgit v1.2.3