From c5fec2205a272b181cbfd225cef7cb49997b9ee4 Mon Sep 17 00:00:00 2001 From: Seth Barberee Date: Sun, 5 Nov 2023 13:04:47 -0800 Subject: [PATCH] Address review comments and more code cleanup with header files --- include/code_80958E8.h | 8 +- include/dungeon_ai.h | 1 - include/mailbox_8095F8C.h | 3 +- include/tile_types.h | 1 + ld_script.txt | 1 + src/code_2.c | 4 - src/code_8075708.c | 177 ++++++++++++++++++++++++++++++++++++++ src/code_80958E8.c | 1 - src/code_80958E8_1.c | 11 +-- src/dungeon_ai.c | 163 ----------------------------------- src/save.c | 4 +- 11 files changed, 193 insertions(+), 181 deletions(-) create mode 100644 src/code_8075708.c diff --git a/include/code_80958E8.h b/include/code_80958E8.h index e5678a4e7..76eaf3964 100644 --- a/include/code_80958E8.h +++ b/include/code_80958E8.h @@ -27,4 +27,10 @@ typedef struct unkStruct_203B490 extern unkStruct_203B490 *gUnknown_203B490; -#endif // GUARD_CODE_80958E8_H \ No newline at end of file +void LoadMailInfo(void); +unkStruct_203B490 *GetMailInfo(void); +void InitializeMailJobsNews(void); +bool8 IsValidWonderMail(WonderMail *WonderMailData); +bool8 ValidateWonderMail(WonderMail *data); + +#endif // GUARD_CODE_80958E8_H diff --git a/include/dungeon_ai.h b/include/dungeon_ai.h index 4e2716ff4..3334419b1 100644 --- a/include/dungeon_ai.h +++ b/include/dungeon_ai.h @@ -3,7 +3,6 @@ #include "structs/dungeon_entity.h" -u32 sub_8075818(Entity *entity); void sub_8075900(Entity *pokemon, u8 r1); void RunMonsterAI(Entity *pokemon, u32 unused); diff --git a/include/mailbox_8095F8C.h b/include/mailbox_8095F8C.h index fdd8d44db..7ec3e0959 100644 --- a/include/mailbox_8095F8C.h +++ b/include/mailbox_8095F8C.h @@ -3,8 +3,9 @@ #include "structs/str_wonder_mail.h" +s32 CountFilledMailboxSlots(void); WonderMail *GetMailboxSlotInfo(u8 index); bool8 IsMailSlotEmpty(u8 index); void ResetMailboxSlot(u8 index); -#endif // GUARD_MAILBOX_8095F8C_H \ No newline at end of file +#endif // GUARD_MAILBOX_8095F8C_H diff --git a/include/tile_types.h b/include/tile_types.h index 0c7edcd75..ef99fbdab 100644 --- a/include/tile_types.h +++ b/include/tile_types.h @@ -9,6 +9,7 @@ extern const u8 gDungeonWaterType[]; +void sub_804AE84(Position *pos); bool8 IsTileGround(Tile *tile); bool8 IsWaterTileset(); diff --git a/ld_script.txt b/ld_script.txt index 0cf487770..eef5ab97d 100755 --- a/ld_script.txt +++ b/ld_script.txt @@ -246,6 +246,7 @@ SECTIONS { src/dungeon_ai_items.o(.text); src/code_8073CF0.o(.text); asm/code_8073CF0.o(.text); + src/code_8075708.o(.text); src/dungeon_ai.o(.text); src/move_effects_target.o(.text); src/status.o(.text); diff --git a/src/code_2.c b/src/code_2.c index 2ed16fd56..4ac3996c4 100644 --- a/src/code_2.c +++ b/src/code_2.c @@ -33,15 +33,11 @@ extern void NDS_LoadOverlay_GroundMain(void); extern void sub_8014144(void); -extern void LoadGameOptions(void); -extern void LoadItemParameters(void); -extern void LoadMailInfo(void); extern void sub_800DAAC(void); extern void sub_800135C(void); extern void xxx_script_related_8001334(u32); extern void LoadTitleScreen(void); extern void sub_80095CC(u32, u32); -extern s32 GetFirstIndexofMailType(u8); extern void nullsub_33(void); extern u32 sub_80009D0(u32); diff --git a/src/code_8075708.c b/src/code_8075708.c new file mode 100644 index 000000000..7806225f8 --- /dev/null +++ b/src/code_8075708.c @@ -0,0 +1,177 @@ +#include "global.h" +#include "dungeon_ai.h" + +#include "constants/iq_skill.h" +#include "constants/item.h" +#include "constants/status.h" +#include "constants/type.h" +#include "dungeon_items.h" +#include "dungeon_map_access.h" +#include "dungeon_pokemon_attributes.h" +#include "dungeon_util.h" +#include "dungeon_visibility.h" +#include "tile_types.h" + +extern void sub_8049ED4(void); +extern void sub_8073D14(Entity *); +extern void sub_807FE9C(Entity *, Position *, u32, u32); + +void nullsub_97(Entity *entity) +{} + +void sub_8075708(Entity *entity) +{ + bool8 bVar1; + bool8 bVar2; + Tile *tile; + u8 *trapData; + Entity *trap; + EntityInfo *info; + + info = entity->info; + if (!EntityExists(entity)) { + return; + } + tile = GetTileAtEntitySafe(entity); + if (((IQSkillIsEnabled(entity, IQ_SUPER_MOBILE)) && (info->transformStatus != STATUS_MOBILE)) && + (!HasHeldItem(entity, ITEM_MOBILE_SCARF))) { + sub_804AE84(&entity->pos); + } + trap = tile->object; + if (trap == NULL) { + return; + } + + switch(GetEntityType(trap)) { + case ENTITY_TRAP: + trapData = (u8 *)GetTrapData(trap); + bVar1 = FALSE; + bVar2 = FALSE; + if ((IQSkillIsEnabled(entity, IQ_TRAP_SEER)) && (!trap->isVisible)) { + trap->isVisible = TRUE; + sub_8049ED4(); + bVar2 = TRUE; + } + + if (trapData[1] == 0) { + if (!trap->isVisible) goto _080757EC; + if (info->isNotTeamMember) goto _080757EC; + } + else { + if (trapData[1] == 1) { + if (!info->isNotTeamMember) goto _080757EC; + goto _ret; + } + if ((trapData[1] == 2) && (!info->isNotTeamMember)) { + bVar1 = TRUE; + } + _080757EC: + if (!bVar1) { + return; + } + } + _ret: + if (!bVar2) { + sub_807FE9C(entity, &entity->pos, 0, 1); + } + break; + case ENTITY_ITEM: + sub_8073D14(entity); + break; + case ENTITY_NOTHING: + case ENTITY_MONSTER: + case ENTITY_UNK_4: + case ENTITY_UNK_5: + break; + } +} + +u32 sub_8075818(Entity *entity) +{ + struct Tile *tile; + EntityInfo *entityInfo; + Entity *subEntity; + Item *item; + u8 *trapData; // TODO: turn into struct when more research is done.. + u8 r1; + + entityInfo = entity->info; + if(EntityExists(entity)) + { + tile = GetTileAtEntitySafe(entity); + if(IQSkillIsEnabled(entity, IQ_SUPER_MOBILE)) + if(!(tile->terrainType & (TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY))) + return 1; + subEntity = tile->object; + if(subEntity != NULL) + { + switch(GetEntityType(subEntity)) + { + case ENTITY_NOTHING: + case ENTITY_MONSTER: + case ENTITY_UNK_4: + case ENTITY_UNK_5: + break; + case ENTITY_TRAP: + trapData = (u8*) GetTrapData(subEntity); + r1 = 0; + if(trapData[1] == 0) + { + if(!subEntity->isVisible || entityInfo->isNotTeamMember) + goto flag_check; + else + goto error; + } + else if(trapData[1] == 1) + { + if(!entityInfo->isNotTeamMember) + goto flag_check; + else + goto error; + } + else if(trapData[1] == 2) + { + if(!entityInfo->isNotTeamMember) + r1 = 1; + } +flag_check: + if(r1 == 0) + break; + else + goto error; + case ENTITY_ITEM: + if(!entityInfo->isTeamLeader) + { + if(!(entityInfo->heldItem.flags & ITEM_FLAG_EXISTS)) + { + if(!(tile->terrainType & (TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY))) + { + if(entityInfo->isNotTeamMember) + break; + else + { + item = GetItemData(subEntity); + if(!(item->flags & ITEM_FLAG_IN_SHOP)) + { + return 1; + } + } + } + else + { + item = GetItemData(subEntity); + if(!(item->flags & ITEM_FLAG_IN_SHOP)) + { +error: + return 1; + } + } + } + } + break; + } + } + } + return 0; +} + diff --git a/src/code_80958E8.c b/src/code_80958E8.c index 7b8d7281c..bc1b39fe1 100644 --- a/src/code_80958E8.c +++ b/src/code_80958E8.c @@ -16,7 +16,6 @@ extern bool8 sub_809017C(DungeonLocation *); extern void ResetPelipperBoardSlot(u8); -extern bool8 ValidateWonderMail(WonderMail *); static EWRAM_DATA unkStruct_203B490 sUnknown_2039448 = {0}; diff --git a/src/code_80958E8_1.c b/src/code_80958E8_1.c index 3b4b8a5fa..f970a1f56 100644 --- a/src/code_80958E8_1.c +++ b/src/code_80958E8_1.c @@ -14,8 +14,6 @@ #include "event_flag.h" #include "rescue_team_info.h" - -extern bool8 IsValidWonderMail(WonderMail *WonderMailData); extern u8 sub_8095E38(WonderMail *, u8, u8, bool8); extern void sub_80965F4(); u8 sub_8097318(s16 param_1); @@ -28,7 +26,6 @@ bool8 sub_8096E80(u32); u8 sub_8095E78(void); void sub_8096078(void); -s32 CountFilledMailboxSlots(void); bool8 sub_80963B4(void); static void SortMailboxSlots(void) @@ -116,7 +113,7 @@ bool8 sub_80961D8(void) _slot: slot = GetMailboxSlotInfo(num); slot->mailType = 1; - slot->unk4.dungeon.id = 0x62; + slot->unk4.dungeon.id = NUM_DUNGEONS; slot->unk4.dungeon.floor = floor; goto _flag; _0809638E: @@ -172,7 +169,7 @@ bool8 sub_80963B4(void) { slot = GetMailboxSlotInfo(num); slot->mailType = 1; - slot->unk4.dungeon.id = 0x62; + slot->unk4.dungeon.id = NUM_DUNGEONS; slot->unk4.dungeon.floor = floor; flag = TRUE; } @@ -198,7 +195,7 @@ void sub_80963FC(void) slot->mailType = 5; slot->missionType = 0; slot->unk2 = 0; - slot->unk4.dungeon.id = 2; + slot->unk4.dungeon.id = DUNGEON_MT_STEEL; slot->unk4.dungeon.floor = 3; slot->unk4.seed = 0x00ffffff & Rand32Bit(); slot->clientSpecies = MONSTER_PIDGEY; @@ -224,7 +221,7 @@ void sub_8096488(void) } mail = GetMailboxSlotInfo(0); mail->mailType = 1; - mail->unk4.dungeon.id = 98; + mail->unk4.dungeon.id = NUM_DUNGEONS; mail->unk4.dungeon.floor = 0; } diff --git a/src/dungeon_ai.c b/src/dungeon_ai.c index 3812f19e1..4af9f49bc 100644 --- a/src/dungeon_ai.c +++ b/src/dungeon_ai.c @@ -43,169 +43,6 @@ extern void sub_807AB38(Entity *, u32); extern void sub_8041888(u32); extern u8 sub_803F428(s16 *); extern void sub_803E708(u32, u32); -void sub_804AE84(Position *pos); -extern void sub_8049ED4(); -extern void sub_8073D14(Entity *); -extern void sub_807FE9C(Entity *, Position *, u32, u32); - -void nullsub_97(Entity *entity) -{} - -void sub_8075708(Entity *entity) -{ - bool8 bVar1; - bool8 bVar2; - Tile *tile; - u8 *trapData; - Entity *trap; - EntityInfo *info; - - info = entity->info; - if (!EntityExists(entity)) { - return; - } - tile = GetTileAtEntitySafe(entity); - if (((IQSkillIsEnabled(entity, IQ_SUPER_MOBILE)) && (info->transformStatus != STATUS_MOBILE)) && - (!HasHeldItem(entity, ITEM_MOBILE_SCARF))) { - sub_804AE84(&entity->pos); - } - trap = tile->object; - if (trap == NULL) { - return; - } - - switch(GetEntityType(trap)) { - case ENTITY_TRAP: - trapData = (u8 *)GetTrapData(trap); - bVar1 = FALSE; - bVar2 = FALSE; - if ((IQSkillIsEnabled(entity, IQ_TRAP_SEER)) && (!trap->isVisible)) { - trap->isVisible = TRUE; - sub_8049ED4(); - bVar2 = TRUE; - } - - if (trapData[1] == 0) { - if (!trap->isVisible) goto _080757EC; - if (info->isNotTeamMember) goto _080757EC; - } - else { - if (trapData[1] == 1) { - if (!info->isNotTeamMember) goto _080757EC; - goto _ret; - } - if ((trapData[1] == 2) && (!info->isNotTeamMember)) { - bVar1 = TRUE; - } - _080757EC: - if (!bVar1) { - return; - } - } - _ret: - if (!bVar2) { - sub_807FE9C(entity, &entity->pos, 0, 1); - } - break; - case ENTITY_ITEM: - sub_8073D14(entity); - break; - case ENTITY_NOTHING: - case ENTITY_MONSTER: - case ENTITY_UNK_4: - case ENTITY_UNK_5: - break; - } -} - -u32 sub_8075818(Entity *entity) -{ - struct Tile *tile; - EntityInfo *entityInfo; - Entity *subEntity; - Item *item; - u8 *trapData; // TODO: turn into struct when more research is done.. - u8 r1; - - entityInfo = entity->info; - if(EntityExists(entity)) - { - tile = GetTileAtEntitySafe(entity); - if(IQSkillIsEnabled(entity, IQ_SUPER_MOBILE)) - if(!(tile->terrainType & (TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY))) - return 1; - subEntity = tile->object; - if(subEntity != NULL) - { - switch(GetEntityType(subEntity)) - { - case ENTITY_NOTHING: - case ENTITY_MONSTER: - case ENTITY_UNK_4: - case ENTITY_UNK_5: - break; - case ENTITY_TRAP: - trapData = (u8*) GetTrapData(subEntity); - r1 = 0; - if(trapData[1] == 0) - { - if(!subEntity->isVisible || entityInfo->isNotTeamMember) - goto flag_check; - else - goto error; - } - else if(trapData[1] == 1) - { - if(!entityInfo->isNotTeamMember) - goto flag_check; - else - goto error; - } - else if(trapData[1] == 2) - { - if(!entityInfo->isNotTeamMember) - r1 = 1; - } -flag_check: - if(r1 == 0) - break; - else - goto error; - case ENTITY_ITEM: - if(!entityInfo->isTeamLeader) - { - if(!(entityInfo->heldItem.flags & ITEM_FLAG_EXISTS)) - { - if(!(tile->terrainType & (TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY))) - { - if(entityInfo->isNotTeamMember) - break; - else - { - item = GetItemData(subEntity); - if(!(item->flags & ITEM_FLAG_IN_SHOP)) - { - return 1; - } - } - } - else - { - item = GetItemData(subEntity); - if(!(item->flags & ITEM_FLAG_IN_SHOP)) - { -error: - return 1; - } - } - } - } - break; - } - } - } - return 0; -} void sub_8075900(Entity *pokemon, u8 r1) { diff --git a/src/save.c b/src/save.c index 40b882dfe..89ae4d843 100644 --- a/src/save.c +++ b/src/save.c @@ -56,8 +56,6 @@ extern u32 sub_8097D60(u8 *, u32); extern u32 sub_8097D98(void* a, s32 b); extern void sub_800135C(void); extern void sub_80958E4(u32 *a, u32 b); -extern unkStruct_203B490 *GetMailInfo(void); -extern void InitializeMailJobsNews(void); extern void sub_80972F4(void); extern void sub_80974E8(void); @@ -520,4 +518,4 @@ UNUSED static void sub_8012334(struct UnkStruct_203B184 *r0) gGameOptionsRef = GetGameOptions(); gPlayTimeRef = GetPlayTime(); } -} \ No newline at end of file +}