Add playeritem enum and use ids and kinds in all Findentity calls

This commit is contained in:
Tal Hayon 2022-02-18 18:18:40 +02:00
parent 10f8096abd
commit 0e224cf232
20 changed files with 81 additions and 43 deletions

32
include/playeritem.h Normal file
View File

@ -0,0 +1,32 @@
#ifndef PLAYERITEM_H
#define PLAYERITEM_H
typedef enum {
PLAYER_ITEM_NONE,
PLAYER_ITEM_SWORD,
PLAYER_ITEM_BOMB,
PLAYER_ITEM_3,
PLAYER_ITEM_BOW,
PLAYER_ITEM_SHIELD,
PLAYER_ITEM_LANTERN,
PLAYER_ITEM_7,
PLAYER_ITEM_GUST_JAR,
PLAYER_ITEM_PACCI_CANE,
PLAYER_ITEM_A,
PLAYER_ITEM_B,
PLAYER_ITEM_C,
PLAYER_ITEM_CELL_OVERWRITE_SET,
PLAYER_ITEM_BOTTLE,
PLAYER_ITEM_SWORD_BEAM1,
PLAYER_ITEM_10,
PLAYER_ITEM_11,
PLAYER_ITEM_12,
PLAYER_ITEM_13,
PLAYER_ITEM_14,
PLAYER_ITEM_15,
PLAYER_ITEM_SWORD_BEAM2,
PLAYER_ITEM_17,
PLAYER_ITEM_CELL_OVERWRITE_SET2,
} PlayerItem;
#endif

View File

@ -83,7 +83,7 @@ void* sub_08077C54(UnkItemStruct* unk) {
Entity* sub_08077C94(ItemBehavior* arg0, u32 arg1) { Entity* sub_08077C94(ItemBehavior* arg0, u32 arg1) {
Entity* iVar1; Entity* iVar1;
iVar1 = FindEntityByID(8, gUnk_0811BE48[arg1].unk0[3], 2); iVar1 = FindEntityByID(PLAYER_ITEM, gUnk_0811BE48[arg1].unk0[3], 2);
if (iVar1 == NULL) { if (iVar1 == NULL) {
return NULL; return NULL;
} }

View File

@ -10,6 +10,7 @@
#include "game.h" #include "game.h"
#include "functions.h" #include "functions.h"
#include "save.h" #include "save.h"
#include "playeritem.h"
void sub_080249F4(Entity*); void sub_080249F4(Entity*);
void sub_08024940(Entity*); void sub_08024940(Entity*);
@ -659,7 +660,7 @@ bool32 sub_08024B38(Entity* this) {
} }
} }
ent = FindEntityByID(8, 2, 2); ent = FindEntityByID(PLAYER_ITEM, PLAYER_ITEM_BOMB, 2);
if (ent) { if (ent) {
do { do {
if (ent->action != 2 && ent->z.HALF.HI == 0 && sub_08049F1C(this, ent, 0xa0)) { if (ent->action != 2 && ent->z.HALF.HI == 0 && sub_08049F1C(this, ent, 0xa0)) {
@ -676,7 +677,7 @@ bool32 sub_08024B38(Entity* this) {
return iVar4; return iVar4;
} }
ent = FindEntityByID(6, 5, 6); ent = FindEntityByID(OBJECT, POT, 6);
if (ent) { if (ent) {
do { do {
if (ent->action == 1 && sub_08049F1C(this, ent, 0xa0)) { if (ent->action == 1 && sub_08049F1C(this, ent, 0xa0)) {

View File

@ -2,6 +2,7 @@
#include "coord.h" #include "coord.h"
#include "sound.h" #include "sound.h"
#include "functions.h" #include "functions.h"
#include "playeritem.h"
extern void (*const gUnk_0811BD98[])(ItemBehavior*, u32); extern void (*const gUnk_0811BD98[])(ItemBehavior*, u32);
@ -23,7 +24,8 @@ void sub_08075FF8(ItemBehavior* this, u32 arg1) {
if ((gPlayerState.jump_status | gPlayerState.field_0x3[1]) == 0) { if ((gPlayerState.jump_status | gPlayerState.field_0x3[1]) == 0) {
bombCount = 0; bombCount = 0;
for (entity = FindEntityByID(8, 2, 2); entity != NULL; entity = FindNextDuplicateID(entity, 2)) { for (entity = FindEntityByID(PLAYER_ITEM, PLAYER_ITEM_BOMB, 2); entity != NULL;
entity = FindNextDuplicateID(entity, 2)) {
bombCount += 1; bombCount += 1;
} }
maxBombs = this->behaviorID == 7 ? 3 : 1; maxBombs = this->behaviorID == 7 ? 3 : 1;

View File

@ -112,7 +112,7 @@ void sub_080754B8(ItemBehavior* this, u32 arg1) {
if (gPlayerEntity.frameSpriteSettings & 1) { if (gPlayerEntity.frameSpriteSettings & 1) {
iVar1 = sub_0807B014(); iVar1 = sub_0807B014();
if (iVar1 && FindEntityByID(PLAYER_ITEM, 15, 2) == 0) { if (iVar1 && FindEntityByID(PLAYER_ITEM, PLAYER_ITEM_SWORD_BEAM1, 2) == 0) {
CreatePlayerBomb(this, 0xf); CreatePlayerBomb(this, 0xf);
if (iVar1 == 0xf) { if (iVar1 == 0xf) {
gPlayerState.field_0xab = 5; gPlayerState.field_0xab = 5;

View File

@ -159,7 +159,7 @@ void sub_0805BB74(s32 lightLevel) {
} }
gArea.lightLevel = lightLevel; gArea.lightLevel = lightLevel;
gRoomVars.lightLevel = gArea.lightLevel; gRoomVars.lightLevel = gArea.lightLevel;
manager = (Manager22*)DeepFindEntityByID(9, 0x22); manager = (Manager22*)DeepFindEntityByID(MANAGER, 0x22);
if (manager) { if (manager) {
Manager22_Main(manager); Manager22_Main(manager);
gScreen.lcd.displayControl |= DISPCNT_BG3_ON; gScreen.lcd.displayControl |= DISPCNT_BG3_ON;

View File

@ -36,7 +36,7 @@ void CreateManager36(Entity* entity, ScriptExecutionContext* context) {
} }
void DeleteManager36(Entity* entity, ScriptExecutionContext* context) { void DeleteManager36(Entity* entity, ScriptExecutionContext* context) {
Entity* manager = FindEntity(9, 0x36, 6, context->intVariable, 0); Entity* manager = FindEntity(MANAGER, 0x36, 6, context->intVariable, 0);
if (manager != NULL) { if (manager != NULL) {
DeleteEntityAny(manager); DeleteEntityAny(manager);
} }

View File

@ -286,7 +286,7 @@ void sub_08059220(ManagerF* this) {
void sub_08059278(void) { void sub_08059278(void) {
ManagerF* tmp; ManagerF* tmp;
tmp = (ManagerF*)FindEntityByID(0x9, 0xF, 0x6); tmp = (ManagerF*)FindEntityByID(MANAGER, 0xF, 0x6);
if (tmp) { if (tmp) {
sub_08058ECC(tmp); sub_08058ECC(tmp);
} }

View File

@ -77,7 +77,7 @@ void sub_0806CF30(Entity* this) {
} }
Entity* sub_0806D00C(Entity* this) { Entity* sub_0806D00C(Entity* this) {
Entity* entity = FindEntity(7, 76, 7, 0, 0); Entity* entity = FindEntity(NPC, BIG_GORON, 7, 0, 0);
if (entity != NULL) { if (entity != NULL) {
this->parent = entity; this->parent = entity;
} }
@ -100,7 +100,7 @@ void sub_0806D0B0(Entity* this) {
} }
void sub_0806D0F8(void) { void sub_0806D0F8(void) {
Entity* entity = FindEntityByID(7, 0x4c, 7); Entity* entity = FindEntityByID(NPC, BIG_GORON, 7);
if (entity != NULL) { if (entity != NULL) {
sub_0806D0B0(entity); sub_0806D0B0(entity);
} }
@ -359,22 +359,22 @@ void sub_0806D66C(Entity* this) {
ASM_FUNC("asm/non_matching/bigGoron/sub_0806D67C.inc", void sub_0806D67C(Entity* this)) ASM_FUNC("asm/non_matching/bigGoron/sub_0806D67C.inc", void sub_0806D67C(Entity* this))
void sub_0806D6D0(void) { void sub_0806D6D0(void) {
Entity* entity = FindEntity(7, 0x4c, 7, 2, 0); Entity* entity = FindEntity(NPC, BIG_GORON, 7, 2, 0);
if (entity != NULL) { if (entity != NULL) {
entity->subAction = 2; entity->subAction = 2;
} }
entity = FindEntity(7, 0x4c, 7, 1, 0); entity = FindEntity(NPC, BIG_GORON, 7, 1, 0);
if (entity != NULL) { if (entity != NULL) {
entity->subAction = 1; entity->subAction = 1;
} }
} }
void sub_0806D70C(void) { void sub_0806D70C(void) {
Entity* entity = FindEntity(7, 0x4c, 7, 2, 0); Entity* entity = FindEntity(NPC, BIG_GORON, 7, 2, 0);
if (entity != NULL) { if (entity != NULL) {
entity->subAction = 0; entity->subAction = 0;
} }
entity = FindEntity(7, 0x4c, 7, 1, 0); entity = FindEntity(NPC, BIG_GORON, 7, 1, 0);
if (entity != NULL) { if (entity != NULL) {
entity->subAction = 0; entity->subAction = 0;
entity->spriteSettings.draw = 3; entity->spriteSettings.draw = 3;
@ -382,22 +382,22 @@ void sub_0806D70C(void) {
} }
void sub_0806D74C(void) { void sub_0806D74C(void) {
Entity* entity = FindEntity(7, 0x4c, 7, 2, 0); Entity* entity = FindEntity(NPC, BIG_GORON, 7, 2, 0);
if (entity != NULL) { if (entity != NULL) {
entity->subAction = 3; entity->subAction = 3;
} }
entity = FindEntity(7, 0x4c, 7, 1, 0); entity = FindEntity(NPC, BIG_GORON, 7, 1, 0);
if (entity != NULL) { if (entity != NULL) {
entity->subAction = 2; entity->subAction = 2;
} }
} }
void sub_0806D788(void) { void sub_0806D788(void) {
Entity* entity = FindEntity(7, 0x4c, 7, 2, 0); Entity* entity = FindEntity(NPC, BIG_GORON, 7, 2, 0);
if (entity != NULL) { if (entity != NULL) {
entity->subAction = 4; entity->subAction = 4;
} }
entity = FindEntity(7, 0x4c, 7, 1, 0); entity = FindEntity(NPC, BIG_GORON, 7, 1, 0);
if (entity != NULL) { if (entity != NULL) {
entity->subAction = 1; entity->subAction = 1;
} }
@ -408,14 +408,14 @@ void sub_0806D7C4(Entity* this, ScriptExecutionContext* context) {
this->x.HALF.HI = gPlayerEntity.x.HALF.HI; this->x.HALF.HI = gPlayerEntity.x.HALF.HI;
this->y.HALF.HI = gPlayerEntity.y.HALF.HI - 0x18; this->y.HALF.HI = gPlayerEntity.y.HALF.HI - 0x18;
entity = FindEntity(7, 0x4c, 7, 2, 0); entity = FindEntity(NPC, BIG_GORON, 7, 2, 0);
if (entity != NULL) { if (entity != NULL) {
sub_0807DEDC(this, context, entity->x.HALF.HI, entity->y.HALF.HI); sub_0807DEDC(this, context, entity->x.HALF.HI, entity->y.HALF.HI);
} }
} }
void sub_0806D804(Entity* this, ScriptExecutionContext* context) { void sub_0806D804(Entity* this, ScriptExecutionContext* context) {
Entity* entity = FindEntity(7, 0x4c, 7, 2, 0); Entity* entity = FindEntity(NPC, BIG_GORON, 7, 2, 0);
if (entity != NULL) { if (entity != NULL) {
this->x.HALF.HI = entity->x.HALF.HI; this->x.HALF.HI = entity->x.HALF.HI;
this->y.HALF.HI = entity->y.HALF.HI - 0x10; this->y.HALF.HI = entity->y.HALF.HI - 0x10;

View File

@ -1,6 +1,7 @@
#include "npc.h" #include "npc.h"
#include "object.h" #include "object.h"
#include "functions.h" #include "functions.h"
#include "playeritem.h"
extern void sub_080600F0(Entity*); extern void sub_080600F0(Entity*);
extern void sub_08060158(Entity*); extern void sub_08060158(Entity*);
@ -215,7 +216,7 @@ void sub_08060318(void) {
int i; int i;
for (i = 2; i >= 0; i--) { for (i = 2; i >= 0; i--) {
ent = FindEntityByID(8, 2, 2); ent = FindEntityByID(PLAYER_ITEM, PLAYER_ITEM_BOMB, 2);
if (ent != NULL) { if (ent != NULL) {
CreateDust(ent); CreateDust(ent);
DeleteEntity(ent); DeleteEntity(ent);

View File

@ -83,7 +83,7 @@ void sub_08069660(Entity* this) {
void sub_08069684(void) { void sub_08069684(void) {
Manager* mgr; Manager* mgr;
if (FindEntityByID(9, 0x31, 8) == NULL) { if (FindEntityByID(MANAGER, 0x31, 8) == NULL) {
mgr = GetEmptyManager(); mgr = GetEmptyManager();
if (mgr != NULL) { if (mgr != NULL) {
mgr->type = 9; mgr->type = 9;

View File

@ -1,12 +1,13 @@
#include "entity.h" #include "entity.h"
#include "script.h" #include "script.h"
#include "player.h" #include "player.h"
#include "npc.h"
ASM_FUNC("asm/non_matching/guardWithSpear/sub_0806407C.inc", ASM_FUNC("asm/non_matching/guardWithSpear/sub_0806407C.inc",
void sub_0806407C(Entity* this, ScriptExecutionContext* context)) void sub_0806407C(Entity* this, ScriptExecutionContext* context))
void sub_08064180(void) { void sub_08064180(void) {
Entity* entity = FindEntityByID(7, 0x15, 7); Entity* entity = FindEntityByID(NPC, GUARD_1, 7);
if (entity != NULL) { if (entity != NULL) {
DeleteEntity(entity); DeleteEntity(entity);
} }

View File

@ -56,12 +56,12 @@ void sub_08065900(Entity* this) {
void sub_08065914(Entity* this) { void sub_08065914(Entity* this) {
Entity* target; Entity* target;
target = FindEntityByID(7, 0x1F, 7); target = FindEntityByID(NPC, EPONA, 7);
if (target != NULL) { if (target != NULL) {
PositionRelative(this, target, Q_16_16(24.0), Q_16_16(-1.0)); PositionRelative(this, target, Q_16_16(24.0), Q_16_16(-1.0));
target->parent = this; target->parent = this;
} }
target = FindEntityByID(7, 0x20, 7); target = FindEntityByID(NPC, MILK_CART, 7);
if (target != NULL) { if (target != NULL) {
PositionRelative(this, target, Q_16_16(40.0), 0); PositionRelative(this, target, Q_16_16(40.0), 0);
target->parent = this; target->parent = this;

View File

@ -102,35 +102,35 @@ void sub_08063B68(Entity* this) {
} }
void sub_08063C14(void) { void sub_08063C14(void) {
Entity* entity = DeepFindEntityByID(7, 0x14); Entity* entity = DeepFindEntityByID(NPC, PINA);
if (entity != NULL) { if (entity != NULL) {
InitAnimationForceUpdate(entity, 8); InitAnimationForceUpdate(entity, 8);
} }
} }
void sub_08063C2C(void) { void sub_08063C2C(void) {
Entity* entity = DeepFindEntityByID(7, 0x14); Entity* entity = DeepFindEntityByID(NPC, PINA);
if (entity != NULL) { if (entity != NULL) {
InitAnimationForceUpdate(entity, 4); InitAnimationForceUpdate(entity, 4);
} }
} }
void sub_08063C44(void) { void sub_08063C44(void) {
Entity* entity = DeepFindEntityByID(7, 0x14); Entity* entity = DeepFindEntityByID(NPC, PINA);
if (entity != NULL) { if (entity != NULL) {
InitAnimationForceUpdate(entity, 0); InitAnimationForceUpdate(entity, 0);
} }
} }
void sub_08063C5C(void) { void sub_08063C5C(void) {
Entity* entity = DeepFindEntityByID(7, 0x14); Entity* entity = DeepFindEntityByID(NPC, PINA);
if (entity != NULL) { if (entity != NULL) {
InitAnimationForceUpdate(entity, 9); InitAnimationForceUpdate(entity, 9);
} }
} }
void sub_08063C74(void) { void sub_08063C74(void) {
Entity* entity = DeepFindEntityByID(7, 0x14); Entity* entity = DeepFindEntityByID(NPC, PINA);
if (entity != NULL) { if (entity != NULL) {
CreateSpeechBubbleExclamationMark(entity, 8, 0xffffffe8); CreateSpeechBubbleExclamationMark(entity, 8, 0xffffffe8);
} }

View File

@ -309,7 +309,7 @@ void sub_0806AB74(Entity* this) {
} }
void sub_0806AB9C(Entity* this, ScriptExecutionContext* context) { void sub_0806AB9C(Entity* this, ScriptExecutionContext* context) {
Entity* entity = FindEntity(7, 0x37, 7, 1, 0); Entity* entity = FindEntity(NPC, REM, 7, 1, 0);
if (entity != NULL) { if (entity != NULL) {
DeleteEntity(entity); DeleteEntity(entity);
} }

View File

@ -30,7 +30,7 @@ void sub_08066CF8(Entity* this) {
} }
void sub_08066D04(Entity* this) { void sub_08066D04(Entity* this) {
this->parent = DeepFindEntityByID(7, 0x2E); this->parent = DeepFindEntityByID(NPC, ZELDA_FOLLOWER);
} }
void sub_08066D14(Entity* this, ScriptExecutionContext* context) { void sub_08066D14(Entity* this, ScriptExecutionContext* context) {
@ -85,7 +85,7 @@ void sub_08066D94(Entity* this) {
void SetZeldaFollowTarget(Entity* this) { void SetZeldaFollowTarget(Entity* this) {
Entity* pEVar1; Entity* pEVar1;
pEVar1 = DeepFindEntityByID(7, 0x2E); pEVar1 = DeepFindEntityByID(NPC, ZELDA_FOLLOWER);
if (pEVar1 != NULL) { if (pEVar1 != NULL) {
CopyPosition(this, pEVar1); CopyPosition(this, pEVar1);
sub_080686C4(this, pEVar1); sub_080686C4(this, pEVar1);

View File

@ -34,7 +34,7 @@ void sub_0806EC20(Entity* ent) {
} }
void sub_0806EC38(void) { void sub_0806EC38(void) {
Entity* e = FindEntityByID(7, 0x58, 7); Entity* e = FindEntityByID(NPC, NPC_UNK_58, 7);
if (e != NULL) if (e != NULL)
DeleteEntity(e); DeleteEntity(e);
} }

View File

@ -2,6 +2,7 @@
#include "functions.h" #include "functions.h"
#include "message.h" #include "message.h"
#include "item.h" #include "item.h"
#include "npc.h"
extern void (*const BookActionFuncs[])(Entity*); extern void (*const BookActionFuncs[])(Entity*);
extern s8 const gUnk_08123D94[]; extern s8 const gUnk_08123D94[];
@ -152,7 +153,7 @@ void sub_0809B5EC(Entity* this) {
switch (this->subAction) { switch (this->subAction) {
case 0: { case 0: {
Entity* parent; Entity* parent;
parent = FindEntityByID(7, 26, 7); parent = FindEntityByID(NPC, STURGEON, 7);
if (!parent) { if (!parent) {
return; return;
} }

View File

@ -517,7 +517,7 @@ void sub_080873FC(void) {
SoundReq(SFX_APPARATE); SoundReq(SFX_APPARATE);
gRoomControls.camera_target = NULL; gRoomControls.camera_target = NULL;
while (ent = FindEntityByID(0x6, 0x1b, 0x6), ent != NULL) { while (ent = FindEntityByID(OBJECT, GREAT_FAIRY, 0x6), ent != NULL) {
DeleteEntity(ent); DeleteEntity(ent);
} }
} }
@ -546,7 +546,7 @@ void sub_08087424(Entity* this, ScriptExecutionContext* context) {
void sub_0808747C(Entity* this, ScriptExecutionContext* context) { void sub_0808747C(Entity* this, ScriptExecutionContext* context) {
u32 iVar1 = 0; u32 iVar1 = 0;
iVar1 = (u32)FindEntity(0x6, 0xf, 0x6, 0xb, 0x0); iVar1 = (u32)FindEntity(OBJECT, SPECIAL_FX, 0x6, 0xb, 0x0);
if (iVar1 != 0) { if (iVar1 != 0) {
iVar1 = 1; iVar1 = 1;
} }

View File

@ -195,7 +195,7 @@ void sub_08094B94(Object6AEntity* this) {
} }
void sub_08094BE0(Entity* this) { void sub_08094BE0(Entity* this) {
Entity* e = FindEntity(6, OBJECT_6A, 6, 0x22, 0); Entity* e = FindEntity(OBJECT, OBJECT_6A, 6, 0x22, 0);
if (e != NULL) { if (e != NULL) {
CopyPosition(&gPlayerEntity, e); CopyPosition(&gPlayerEntity, e);
e->z.HALF.HI = -12; e->z.HALF.HI = -12;
@ -257,14 +257,14 @@ void sub_08094CDC(Object6AEntity* this) {
} }
void sub_08094D10(Object6AEntity* this) { void sub_08094D10(Object6AEntity* this) {
Entity* e = FindEntity(6, 0x6a, 6, 3, 98); Entity* e = FindEntity(OBJECT, OBJECT_6A, 6, 3, 98);
if (e != NULL) { if (e != NULL) {
e->action = 0xFF; e->action = 0xFF;
} }
} }
void sub_08094D34(Object6AEntity* this) { void sub_08094D34(Object6AEntity* this) {
Entity* e = CreateObject(0x6a, 0x15, 0xd); Entity* e = CreateObject(OBJECT_6A, 0x15, 0xd);
if (e != NULL) { if (e != NULL) {
e->x.HALF.HI = gRoomControls.origin_x + Q_8_8(1.0); e->x.HALF.HI = gRoomControls.origin_x + Q_8_8(1.0);
e->y.HALF.HI = gRoomControls.origin_y + Q_8_8(2.345); e->y.HALF.HI = gRoomControls.origin_y + Q_8_8(2.345);
@ -273,7 +273,7 @@ void sub_08094D34(Object6AEntity* this) {
} }
void sub_08094D70(Object6AEntity* this) { void sub_08094D70(Object6AEntity* this) {
Entity* e = FindEntity(6, 0x6a, 6, 0x15, 0xd); Entity* e = FindEntity(OBJECT, OBJECT_6A, 6, 0x15, 0xd);
if (e != NULL) { if (e != NULL) {
e->action = 0xFF; e->action = 0xFF;
} }
@ -306,7 +306,7 @@ void sub_08094DD8(Object6AEntity* this) {
} }
void sub_08094E0C(Object6AEntity* this) { void sub_08094E0C(Object6AEntity* this) {
Entity* e = FindEntity(6, 0x6a, 6, 4, 0); Entity* e = FindEntity(OBJECT, OBJECT_6A, 6, 4, 0);
if (e != NULL) { if (e != NULL) {
e->action = 0xFF; e->action = 0xFF;
} }
@ -483,7 +483,7 @@ void sub_08095120(Object6AEntity* this) {
} }
void sub_08095164(Object6AEntity* this) { void sub_08095164(Object6AEntity* this) {
Entity* e = FindEntity(6, 0x6A, 6, 8, 0); Entity* e = FindEntity(OBJECT, OBJECT_6A, 6, 8, 0);
if (e != NULL) { if (e != NULL) {
InitAnimationForceUpdate(e, 3); InitAnimationForceUpdate(e, 3);
} }