diff options
| author | theo3 <arisstephenson2@gmail.com> | 2020-08-07 22:32:51 -0700 |
|---|---|---|
| committer | theo3 <arisstephenson2@gmail.com> | 2020-08-07 22:32:51 -0700 |
| commit | 38d61ddd0de7e5c11caa33baa71e3d67ef479a1e (patch) | |
| tree | 1416ab9dbf6e3f4f4c12c044eba9ac93fa02f076 /src | |
| parent | 7d6faac955f6111f658f7b480ed884d3c6d09cf9 (diff) | |
| parent | 10819392f7a23c5390cbb3505e3ed1eea79bbe4b (diff) | |
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'src')
| -rw-r--r-- | src/entity.c | 423 | ||||
| -rw-r--r-- | src/manager/manager6.c | 33 | ||||
| -rw-r--r-- | src/npc/bigGoron.c | 54 | ||||
| -rw-r--r-- | src/npc/festari.c | 84 | ||||
| -rw-r--r-- | src/npc/postman.c | 34 | ||||
| -rw-r--r-- | src/object/cloud.c | 19 |
6 files changed, 542 insertions, 105 deletions
diff --git a/src/entity.c b/src/entity.c new file mode 100644 index 00000000..deedca95 --- /dev/null +++ b/src/entity.c @@ -0,0 +1,423 @@ +#include "global.h" +#include "entity.h" + +typedef struct OtherEntity { + struct OtherEntity* prev; + struct OtherEntity* next; + Entity* field_0x8; + u8 field_0xC[0x34]; +} OtherEntity; + +extern Entity gUnk_030011E8[7]; + +Entity* sub_0805E744(void) + +{ + Entity* ent = gUnk_030011E8; + + do { + if (ent->field_0x0 == NULL) { + return ent; + } + } while (ent++, ent < &gUnk_030011E8[7]); + + return NULL; +} + +extern Entity* GetEmptyEntity(); +OtherEntity* sub_0805E8D4(); + +typedef void* (*Getter)(void); + +void* sub_0805E768(int type) + +{ + Getter getter = NULL; + if (type == 9) { + getter = (Getter)sub_0805E8D4; + } else { + getter = (Getter)GetEmptyEntity; + } + return getter(); +} +typedef struct { + int field_0x0; + int field_0x4; + Entity* field_0x8; + int field_0xc; +} struct_03003DD0; + +extern struct_03003DD0 gUnk_03003DD0; +extern u32 _call_via_r0(u32*); +extern u32 gUnk_03005F24; +extern void sub_0805E79C(Entity*); + +void DeleteThisEntity(void) + +{ + sub_0805E79C(gUnk_03003DD0.field_0x8); + _call_via_r0((u32*)&gUnk_03005F24); + return; +} + +void DeleteEntity(Entity*); +void sub_0805E900(OtherEntity*); + +typedef void (*Deleter)(void*); + +void sub_0805E79C(Entity* ent) + +{ + Deleter deleter = NULL; + if (ent->entityType.type == 9) { + deleter = (Deleter)sub_0805E900; + } else { + deleter = (Deleter)DeleteEntity; + } + deleter(ent); +} + +extern void sub_080AE068(); +extern void sub_0801D230(); +extern void sub_0806FE84(); +extern void sub_080788E0(); +extern void sub_08078954(); +extern void sub_0805EC60(); +extern void sub_08017744(); +extern void sub_0805E92C(); +extern void sub_0807DB08(); +extern void sub_0806FBEC(); +extern void sub_0801DA0C(); +extern void sub_0804AA1C(); +extern void sub_0805EA98(); // Unlink + +void DeleteEntity(Entity* ent) + +{ + if (ent->field_0x4) { + sub_080AE068(ent); + sub_0801D230(ent); + sub_0806FE84(ent); + sub_080788E0(ent); + sub_08078954(ent); + sub_0805EC60(ent); + sub_08017744(ent); + sub_0805E92C(ent); + sub_0807DB08(ent); + sub_0806FBEC(ent); + sub_0801DA0C(ent->otherEntity); + ent->otherEntity = NULL; + if ((ent->entityType).type == '\x03') { + sub_0804AA1C(ent); + } + ent->flags = ent->flags & 0x7f; + ent->spriteSettings.b.draw = 0; + ent->field_0x3c = 0; + ent->bitfield = 0; + ent->field_0x42 = 0; + ent->currentHealth = 0; + sub_0805EA98(ent); + ent->field_0x4 = NULL; + ent->field_0x0 = (Entity*)0xffffffff; + } +} + +extern Entity gLinkEntity; +void sub_0805E870(Entity*); + +void sub_0805E84C(void) + +{ + Entity* ent = &gLinkEntity; + do { + if ((int)ent->field_0x0 < 0) { + sub_0805E870(ent); + } + } while (ent++, ent < (&gLinkEntity + 80)); + return; +} + +extern u8 gUnk_03003DBC; + +void sub_0805E870(Entity* ent) + +{ + DmaClear32(3, ent, sizeof(Entity)); + gUnk_03003DBC--; +} + +typedef struct struct_03003D70 { + void* field_0x0; + void* field_0x4; +} struct_03003D70; + +extern struct_03003D70 gUnk_03003D70[9]; +extern EntityType gUnk_03003DB8; + +void sub_0805E89C(void) + +{ + Entity* ent; + Entity* next; + struct_03003D70* it; + + it = gUnk_03003D70; + if (it->field_0x4) { + do { + for (ent = it->field_0x4; (u32)ent != (u32)it; ent = next) { + next = ent->field_0x4; + sub_0805E79C(ent); + } + } while (it++, it < (gUnk_03003D70 + 9)); + sub_0805E84C(); + } +} + +extern OtherEntity gUnk_02033290; + +OtherEntity* sub_0805E8D4(void) + +{ + OtherEntity* it; + for (it = &gUnk_02033290; it < (&gUnk_02033290 + 32); it++) { + if (it->prev == 0) { + return it; + } + } + return NULL; +} + +extern void _DmaZero(void*, u32); +extern u8 gUnk_020354B4; + +void sub_0805E900(OtherEntity* ent) + +{ + if (!ent->next) + return; + + sub_0805E92C(ent); + sub_0805EA98(ent); + _DmaZero(ent, 0x40); + gUnk_020354B4--; +} + +#include "area.h" + +void sub_0805E92C(u32 param_1) + +{ + if (param_1 == gArea.unk2) { + gArea.unk2 = 0; + gArea.unk3 = 0; + gArea.unk4 = 0; + } +} + +extern Entity gUnk_020369F0; +extern void sub_0801D66C(void* dst, void* src, size_t size); // dma copy +extern void sub_0805E98C(void); + +void sub_0805E958(void) + +{ + sub_0801D66C(&gUnk_03003D70, &gUnk_020369F0, 0x48); + sub_0805E98C(); +} + +void sub_0805E974(void) + +{ + sub_0801D66C(&gUnk_020369F0, &gUnk_03003D70, 0x48); +} + +void sub_0805E98C(void) + +{ + struct_03003D70* it; + + for (it = gUnk_03003D70; it < &gUnk_03003D70[9]; it++) { + it->field_0x0 = it; + it->field_0x4 = (Entity*)it; + } +} + +void sub_0805E9A8(void) + +{ + Entity* entry; + struct_03003D70* it; + + it = gUnk_03003D70; + do { + for (entry = it->field_0x4; (u32)entry != (u32)it; entry = entry->field_0x4) { + entry->flags &= 0xfd; + if ((entry->flags & 0x20) == 0) { + entry->flags |= 0x10; + } + } + } while (it++, it < (gUnk_03003D70 + 9)); +} + +void sub_0805E9F4(void) + +{ + Entity* ent; + Entity* next; + struct_03003D70* it; + + it = gUnk_03003D70; + do { + for (ent = it->field_0x4; (u32)ent != (u32)it; ent = next) { + next = ent->field_0x4; + if (ent->flags & 0x10) + sub_0805E79C(ent); + } + } while (it++, it < (gUnk_03003D70 + 9)); +} + +extern void sub_0805E374(Entity*); + +void sub_0805EA2C(Entity* ent, int kind) + +{ + Entity* prev; + struct_03003D70* next; + + next = (gUnk_03003D70 + kind); + ent->field_0x4 = (Entity*)next; + prev = next->field_0x0; + ent->field_0x0 = prev; + prev->field_0x4 = ent; + next->field_0x0 = ent; + if (ent->entityType.type != 9) { + ent->spritePriority.b0 = 4; + gUnk_03003DBC++; + } else { + gUnk_020354B4++; + } + sub_0805E374(ent); +} + +void sub_0805EA78(Entity* ent, int kind) + +{ + struct_03003D70* it; + + sub_0805EA98(ent); + it = &gUnk_03003D70[kind]; + ent->field_0x0 = (Entity*)it; + ent->field_0x4 = it->field_0x4; + ((Entity*)it->field_0x4)->field_0x0 = ent; + it->field_0x4 = ent; +} + +void sub_0805EA98(Entity* ent) + +{ + if (ent == gUnk_03003DD0.field_0x8) { + gUnk_03003DD0.field_0x8 = ent->field_0x0; + } + ent->field_0x0->field_0x4 = ent->field_0x4; + ent->field_0x4->field_0x0 = ent->field_0x0; +} + +int sub_0805EABC(Entity* ent) + +{ + Entity* ent2; + struct_03003D70 *it, *end; + + it = gUnk_03003D70; + end = (gUnk_03003D70 + 9); + do { + for (ent2 = (Entity*)it->field_0x4; (u32)ent2 != (u32)it; ent2 = ent2->field_0x4) { + if ((u32)ent2 != (u32)ent && ent2->entityType.type == ent->entityType.type && + ent2->entityType.subtype == ent->entityType.subtype) { + return 1; + } + } + } while (it++, it < end); + + return 0; +} + +Entity* sub_0805EB00(int type, int subtype, int kind) + +{ + Entity* it; + struct_03003D70* node; + + node = &gUnk_03003D70[kind]; + for (it = node->field_0x4; (u32)it != (u32)node; it = it->field_0x4) { + if (type == it->entityType.type && subtype == it->entityType.subtype) + return it; + } + return NULL; +} + +Entity* sub_0805EB2C(int type, int subtype, int kind, int form, int parameter) + +{ + Entity* it; + struct_03003D70* node; + + node = &gUnk_03003D70[kind]; + node = &gUnk_03003D70[kind]; + for (it = node->field_0x4; (u32)it != (u32)node; it = it->field_0x4) { + if (type == it->entityType.type && subtype == it->entityType.subtype && form == it->entityType.form && + parameter == it->entityType.parameter) + return it; + } + return NULL; +} + +Entity* sub_0805EB64(Entity* ent, int kind) + +{ + Entity* it; + struct_03003D70* end; + + end = &gUnk_03003D70[kind]; + for (it = ent->field_0x4; (u32)it != (u32)end; it = it->field_0x4) { + if (it->entityType.type == ent->entityType.type && it->entityType.subtype == ent->entityType.subtype) + return it; + } + return NULL; +} + +Entity* sub_0805EB9C(int type, int subtype) + +{ + Entity* it2; + struct_03003D70 *it, *end; + + it = gUnk_03003D70; + end = (gUnk_03003D70 + 9); + do { + for (it2 = (Entity*)it->field_0x4; (u32)it2 != (u32)it; it2 = it2->field_0x4) { + if ((type == (it2->entityType).type) && (subtype == (it2->entityType).subtype)) + return it2; + } + } while (it++, it < end); + + return 0; +} + +void sub_0805EBCC(void) + +{ + Entity* ent; + Entity* next; + struct_03003D70* it; + + it = gUnk_03003D70; + do { + for (ent = it->field_0x4; (u32)ent != (u32)it; ent = next) { + next = ent->field_0x4; + if (ent->entityType.type == 3) + DeleteEntity(ent); + } + } while (it++, it < (gUnk_03003D70 + 9)); + sub_0805E84C(); +} diff --git a/src/manager/manager6.c b/src/manager/manager6.c new file mode 100644 index 00000000..deb44026 --- /dev/null +++ b/src/manager/manager6.c @@ -0,0 +1,33 @@ +#include "global.h" +#include "entity.h" +#include "link.h" +#include "manager.h" + +extern void* GetCurrentRoomProperty(u8); +extern u32 CheckPlayerInRegion(u16, u16, u8, u8); +extern void DoExitTransition(void*); +extern void sub_0805E900(Entity*); + +void sub_08057CB4(Entity * this) { + u32 tmp; + UnkManagerHelperStruct* i; + if (this->action == 0){ + this->action = 1; + this->field_0x20 = (s32) GetCurrentRoomProperty(this->entityType.form); + if (this->field_0x20 == 0) { + sub_0805E900(this); + return; + } + } + if (this->actionDelay == 0 || gLinkState.field_0x10[2] == 0x1e) { + for (i = ((UnkManagerHelperStruct*) this->field_0x20);i->field_0x00 != 0xFFFF; i++) { + tmp = (i->field_0x07.all & 0x3); + if (((tmp & (gLinkEntity.collisionLayer)) != 0) && + (((gLinkState.flags.all & 0x80) != 0) || ((i->field_0x07.b.unk2) != 0)) && + (CheckPlayerInRegion(i->field_0x00,i->field_0x02,i->field_0x04,i->field_0x05) != 0) && + (gLinkEntity.height.HALF.HI == 0)) { + DoExitTransition(GetCurrentRoomProperty(i->field_0x06)); + } + } + } +} diff --git a/src/npc/bigGoron.c b/src/npc/bigGoron.c index 5096dfa0..3b3a5101 100644 --- a/src/npc/bigGoron.c +++ b/src/npc/bigGoron.c @@ -1,11 +1,11 @@ #include "global.h" #include "entity.h" #include "link.h" +#include "structures.h" extern void (*gUnk_081140D4[])(Entity*); extern u16 gUnk_081140CC[]; -extern u32 gScreenTransition; extern void sub_0805E3A0(Entity*, u32); extern void sub_0806D0B0(Entity*); extern void sub_0807DD64(Entity*); @@ -20,16 +20,11 @@ void BigGoron(Entity* this) { gUnk_081140D4[this->entityType.form](this); } -#ifdef NON_MATCHING void sub_0806CF30(Entity* this) { - u8 bVar1; - u32 uVar2; - int iVar3; - if (this->action == 0) { this->action = 1; this->previousActionFlag = 1; - this->field_0x68 = (this->x).HALF.HI; + this->field_0x68.HWORD = this->x.HALF.HI; sub_0805E3A0(this, 2); sub_0806D0B0(this); sub_0807DD64(this); @@ -37,39 +32,32 @@ void sub_0806CF30(Entity* this) { sub_0807DDAC(this, 0); sub_0807DDE4(this); } - if (this->previousActionFlag != 2) { - if (this->previousActionFlag < 3) { - if ((gScreenTransition & 3) == 0) { - iVar3 = this->x.HALF.HI; - if (gLinkEntity.x.HALF.HI < iVar3) { - if ((this->field_0x68 - 32) < iVar3) { - this->x.HALF.HI = -1; - } + switch (this->previousActionFlag) { + case 0: + case 1: + if (gScreenTransition.frameCount % 4 == 0) { + if (gLinkEntity.x.HALF.HI < this->x.HALF.HI && this->field_0x68.HWORD - 32 < this->x.HALF.HI) { + this->x.HALF.HI--; } - if (this->x.HALF.HI > gLinkEntity.x.HALF.HI) { - if (this->x.HALF.HI < (this->field_0x68 + 32)) { - this->x.HALF.HI += 1; - } + if (gLinkEntity.x.HALF.HI > this->x.HALF.HI && this->field_0x68.HWORD + 32 > this->x.HALF.HI) { + this->x.HALF.HI++; } } - } - } else { - bVar1 = this->actionDelay -= 1; - if (bVar1 == 0) { - uVar2 = Random(); - PlaySFX(gUnk_081140CC[uVar2 & 3]); - this->actionDelay = ((u8)uVar2 & 7) * 10 + 128; - } + break; + case 2: + if (--this->actionDelay == 0) { + u32 uVar2 = Random(); + PlaySFX(gUnk_081140CC[uVar2 % 4]); + this->actionDelay = ((u8)uVar2 & 7) * 16; + this->actionDelay += 128; + } + break; + case 3: + break; } sub_0806D02C(this); } -#else -NAKED -void sub_0806CF30(Entity* this) { - asm(".include \"asm/non_matching/bigGoron/sub_0806CF30.inc\""); -} -#endif void sub_0806D00C(Entity* this) { Entity* pEVar1; diff --git a/src/npc/festari.c b/src/npc/festari.c index b362359e..310db3fa 100644 --- a/src/npc/festari.c +++ b/src/npc/festari.c @@ -1,5 +1,6 @@ #include "global.h" #include "entity.h" +#include "functions.h" #include "npc.h" #include "link.h" @@ -30,58 +31,53 @@ void sub_0805FE10(Entity *this) sub_0807DD50(this); } -#if NON_MATCHING void sub_0805FE48(Entity *this) { - u8 bVar1; - u16 uVar2; - u32 uVar3; - u32 uVar4; + u8 bVar1; + u16 uVar2; + u32 uVar3; + u32 uVar4; - if (this->interactType == 2) { - this->action = 2; - this->interactType = 0; - InitAnimationForceUpdate(this, sub_0806F5A4(GetFacingDirection(this, &gLinkEntity))); - sub_0806F118(this); - } - else { - ExecuteScriptCommandSet(this, *(void **)&this->cutsceneBeh); - sub_0805FF2C(this, *(void **)&this->cutsceneBeh); - if (this->field_0x80 < 8) { - if ((this->field_0x82 & 1) != 0) { - uVar4 = (uVar4 & 0xfc) + (this->field_0xf >> 1); - } - else { - uVar4 = (uVar4 & 0xfc) + (this->animationState >> 1); - this->field_0xf = this->animationState; - } - } - if (uVar4 != this->animIndex) { - InitAnimationForceUpdate(this, uVar4); + if (this->interactType == 2) { + this->action = 2; + this->interactType = 0; + InitAnimationForceUpdate(this, sub_0806F5A4(GetFacingDirection(this, &gLinkEntity))); + sub_0806F118(this); } - UpdateAnimationSingleFrame(this); + else { + ExecuteScriptCommandSet(this, *(void **)&this->cutsceneBeh); + sub_0805FF2C(this, *(void **)&this->cutsceneBeh); + uVar4 = this->field_0x80.HWORD; + if (uVar4 < 8) { + if ((this->field_0x82.HWORD & 1) != 0) { + uVar4 = (uVar4 & 0xfc) + (this->field_0xf >> 1); + } + else { + uVar4 = (uVar4 & 0xfc) + (this->animationState >> 1); + this->field_0xf = this->animationState; + } + } + if (uVar4 != this->animIndex) { + InitAnimationForceUpdate(this, uVar4); + } + UpdateAnimationSingleFrame(this); - if (this->frames.b.f3) - { - switch (this->animIndex) { - case 8: - case 10: - case 11: - case 12: - this->field_0x80 = 0; + if (this->frames.b.f3) + { + switch (this->animIndex) { + case 8: + case 10: + case 11: + case 12: + this->field_0x80.HWORD = 0; + break; + } + } + if ((this->field_0x82.HWORD & (~this->field_0x82.HWORD + 1)) == 2) { + sub_0806ED78(this); } } - if ((this->field_0x82 & (~this->field_0x82 + 1)) == 2) { - sub_0806ED78(this); - } - } -} -#else -NAKED -void sub_0805FE48(Entity *this) { - asm(".include \"asm/non_matching/festari/sub_0805FE48.inc\""); } -#endif void sub_0805FF18(Entity *this) { diff --git a/src/npc/postman.c b/src/npc/postman.c index d920cba8..c26dc457 100644 --- a/src/npc/postman.c +++ b/src/npc/postman.c @@ -4,6 +4,7 @@ #include "npc.h" #include "textbox.h" #include "link.h" +#include "room.h" #include "structures.h" typedef struct { @@ -34,10 +35,16 @@ extern void sub_0800451C(Entity*); extern void sub_08078784(Entity*, u32); extern void sub_0807DEDC(Entity*, u32, u32, u32); +typedef struct { + s16 x; + s16 y; +} Coords16; + +extern Coords16 gUnk_0810A66C[]; +extern s8* gUnk_0810A918[]; + extern void (*const gUnk_0810AA24[])(Entity*); extern u32 gUnk_0810AA30[]; -extern u32** gUnk_0810A66C; -extern u32 gUnk_0810A918[]; extern struct_02033280 gUnk_02033280; void Postman(Entity* this) { @@ -208,21 +215,18 @@ void sub_080606D8(Entity* this) ShowNPCDialogue(this, &gUnk_0810AA30[iVar1 * 2]); } -#if 0 -void sub_08060700(Entity *arg0, u32 arg1) +void sub_08060700(Entity *entity, u32 arg1) { - sub_0807DEDC(arg0,arg1, - gUnk_0810A918[gUnk_0810A66C[arg0->field_0x68.HALF.HI][arg0->field_0x68.HALF.LO] * 4 + gRoomControls.roomOriginX], - gUnk_0810A918[gUnk_0810A66C[arg0->field_0x68.HALF.HI][arg0->field_0x68.HALF.LO] * 4 + gRoomControls.roomOriginY + 2]); - gUnk_02033280.unk |= 1; -} -#endif -NAKED void sub_08060700(Entity *arg0, u32 arg1) { - asm(".include \"asm/non_matching/postman/sub_08060700.inc\""); + s8* var0 = gUnk_0810A918[(s8)entity->field_0x68.HALF.LO]; + Coords16* coords = &gUnk_0810A66C[var0[(s8)entity->field_0x68.HALF.HI]]; + u32 x = coords->x + gRoomControls.roomOriginX; + u32 y = coords->y + gRoomControls.roomOriginY; + sub_0807DEDC(entity, arg1, x, y); + gUnk_02033280.unk |= 1; } void sub_0806075C(Entity *this) { - this->field_0x68.HALF.LO = 0xb; - this->field_0x68.HALF.HI = 0xff; -}
\ No newline at end of file + this->field_0x68.HALF.LO = 0xb; + this->field_0x68.HALF.HI = 0xff; +} diff --git a/src/object/cloud.c b/src/object/cloud.c index 96ffc659..54fa6621 100644 --- a/src/object/cloud.c +++ b/src/object/cloud.c @@ -156,28 +156,21 @@ void sub_0809F700(Entity* this) { } } -#ifdef NON_MATCHING Entity* sub_0809F770(Entity* this) { Entity* cloud; - s32 uVar1; + int uVar1; cloud = CreateObject(163, 1, 0); - if (cloud != NULL) { + if (cloud) { PositionEntityOnTop(this, cloud); uVar1 = Random(); - cloud->x.HALF.HI = ((cloud->x.HALF.HI - 16) + (uVar1 >> 0)) & 31; - cloud->y.HALF.HI = ((cloud->y.HALF.HI - 16) + (uVar1 >> 8)) & 31; - cloud->animationList = (u8)(uVar1 >> 16) & 3; - cloud->direction = 255; + cloud->x.HALF.HI += ((uVar1 >> 0) & 31) - 16; + cloud->y.HALF.HI += ((uVar1 >> 8) & 31) - 16; + cloud->frameIndex = (uVar1 >> 16) & 3; + cloud->direction = 0xFF; } return cloud; } -#else -NAKED -Entity* sub_0809F770(Entity* this) { - asm(".include \"asm/non_matching/cloud/sub_0809F770.inc\""); -} -#endif void sub_0809F7BC(Entity* this) { Entity* cloud; |
