Address review comments and more code cleanup with header files

This commit is contained in:
Seth Barberee
2023-11-05 13:04:47 -08:00
parent 937d4c954b
commit c5fec2205a
11 changed files with 193 additions and 181 deletions

View File

@@ -27,4 +27,10 @@ typedef struct unkStruct_203B490
extern unkStruct_203B490 *gUnknown_203B490;
#endif // GUARD_CODE_80958E8_H
void LoadMailInfo(void);
unkStruct_203B490 *GetMailInfo(void);
void InitializeMailJobsNews(void);
bool8 IsValidWonderMail(WonderMail *WonderMailData);
bool8 ValidateWonderMail(WonderMail *data);
#endif // GUARD_CODE_80958E8_H

View File

@@ -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);

View File

@@ -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
#endif // GUARD_MAILBOX_8095F8C_H

View File

@@ -9,6 +9,7 @@
extern const u8 gDungeonWaterType[];
void sub_804AE84(Position *pos);
bool8 IsTileGround(Tile *tile);
bool8 IsWaterTileset();

View File

@@ -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);

View File

@@ -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);

177
src/code_8075708.c Normal file
View File

@@ -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;
}

View File

@@ -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};

View File

@@ -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;
}

View File

@@ -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)
{

View File

@@ -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();
}
}
}