diff --git a/include/ground_object.h b/include/ground_object.h new file mode 100644 index 000000000..976f466ef --- /dev/null +++ b/include/ground_object.h @@ -0,0 +1,27 @@ +#ifndef GUARD_GROUND_OBJECT_H +#define GUARD_GROUND_OBJECT_H + +#include "structs/str_ground_script.h" + +void AllocGroundObjects(void); +void DeleteGroundObjects(void); +void FreeGroundObjects(void); +void GroundObject_Select(s32 scriptID, s32 group, s32 sector); +void GroundObject_Cancel(s32 scriptID, s32 sector); +void GroundObject_CancelBlank(void); +s32 GroundObject_Add(s32 id_, const GroundObjectData *objectData, s32 group_, s32 sector_); +void sub_80AC1B0(s32 index_, s32 flag); +Action *GroundObject_GetAction(s32 index_); +bool8 GroundObject_GetScript(s32 index_, ScriptInfoSmall *scriptInfo, s32 a2_); +bool8 GroundObject_ExecuteScript(s32 index_, ActionUnkIds *a1, ScriptInfoSmall *script); +bool8 GroundObjectsNotifyAll(s32 index_); +bool8 GroundObjectsCancelAll(void); +s16 GroundObject_GetFlags(s32 index_, s32 *flags); +s16 sub_80AC448(s32 index_, PixelPos *pos); +s16 sub_80AC49C(s32 index_, PixelPos *pos); +s32 sub_80AC4C8(s32 index, PixelPos *a0, PixelPos *a1); +s32 sub_80AC554(s32 flag, PixelPos *param_2,PixelPos *param_3); +void GroundObject_Action(void); +void sub_80ACAD4(void); + +#endif // GUARD_GROUND_OBJECT_H diff --git a/src/code_809D148.c b/src/code_809D148.c index c8703c807..7c4fbcacf 100644 --- a/src/code_809D148.c +++ b/src/code_809D148.c @@ -8,6 +8,7 @@ #include "ground_script.h" #include "ground_lives.h" #include "ground_effect.h" +#include "ground_object.h" struct unkStruct_20399E8 { @@ -190,7 +191,6 @@ u8 sub_809D248(PixelPos *r0) } // Todo: move these to appropriate header files -extern s32 sub_80AC448(s16 a0, PixelPos *a1); extern bool8 sub_80A579C(PixelPos *a0, PixelPos *a1); void sub_809D25C(void) @@ -210,7 +210,7 @@ void sub_809D25C(void) gUnknown_20399E8.unk0 = 0; break; case 2: - val = sub_80AC448(gUnknown_20399E8.unk4, &gUnknown_20399E8.unk1C); + val = sub_80AC448((s16) gUnknown_20399E8.unk4, &gUnknown_20399E8.unk1C); if (val == (u16) -1) gUnknown_20399E8.unk0 = 0; break; diff --git a/src/ground_lives.c b/src/ground_lives.c index dadc8920b..720217325 100644 --- a/src/ground_lives.c +++ b/src/ground_lives.c @@ -18,6 +18,7 @@ #include "friend_area_dialogue.h" #include "ground_lives_helper.h" #include "ground_sprite_monster.h" +#include "ground_object.h" struct GroundLivesMeta_Sub1 { @@ -107,20 +108,14 @@ extern u8 sub_809D248(PixelPos *r0); extern s16 HandleAction(Action *action, const DebugLocation *debug); extern bool8 sub_80A66F8(struct UnkGroundSpriteStruct *ptr); extern bool8 sub_80A671C(struct UnkGroundSpriteStruct *ptr); -extern s32 sub_80AC554(u32 a0, PixelPos *pixelPosArg1, PixelPos *pixelPosArg2); -extern s32 sub_80AC448(s32 id_, PixelPos *pixelPos); extern bool8 sub_80A595C(u32 a0, PixelPos *pixelPosArg1, PixelPos *pixelPosArg2); -extern void GroundObject_GetFlags(s32 id, s32 *a1); extern PixelPos SetVecFromDirectionSpeed(s32 r1, u32 r2); extern u8 sub_80A5934(s32 param_1, PixelPos *, PixelPos *); extern bool8 CheckMapCollision_80A585C(PixelPos *, PixelPos *); extern bool8 sub_80A58C8(PixelPos *, PixelPos *); -extern s32 sub_80AC4C8(u32 a0, PixelPos *, PixelPos *); extern bool8 sub_809B1C0(s32 a0, u32 kind, Pokemon *a2); extern bool8 GetPredefinedScript(Action *param_1, ScriptInfoSmall *script, s32 _index); extern bool8 sub_809D678(Action *action); -extern bool8 GroundObject_GetScript(s32 a0, ScriptInfoSmall *scriptInfo, s32 a2); -extern void GroundObject_ExecuteScript(s32, void *, ScriptInfoSmall *); extern bool8 GroundScriptNotify(Action *param_1, s32 param_2); extern bool8 GroundScript_Cancel(Action *r0); extern Pokemon *sub_80A8D54(s32); diff --git a/src/ground_main.c b/src/ground_main.c index 3cace7b8b..011c1331b 100644 --- a/src/ground_main.c +++ b/src/ground_main.c @@ -28,6 +28,7 @@ #include "ground_event.h" #include "ground_sprite.h" #include "ground_effect.h" +#include "ground_object.h" EWRAM_DATA u32 gUnknown_20398A8 = {0}; EWRAM_DATA s32 gUnknown_20398AC = {0}; @@ -73,7 +74,6 @@ extern bool8 sub_809AFAC(void); extern bool8 sub_80048BC(void); extern u8 sub_80023E4(u32); extern bool8 sub_8099B94(void); -extern void FreeGroundObjects(void); extern void sub_809D508(void); extern void nullsub_119(void); extern void sub_8099768(void); @@ -82,8 +82,6 @@ extern void sub_8099648(void); extern void sub_809975C(void); extern void sub_809D0AC(void); extern void sub_809D490(void); -extern void AllocGroundObjects(void); -extern void GroundObject_Action(void); extern void sub_809B474(void); extern void GroundScript_Unlock(); extern void sub_809D25C(void); @@ -98,7 +96,6 @@ extern void sub_80A5E70(void); extern void sub_809B638(void); extern void sub_8099750(void); extern void sub_809D0BC(void); -extern void DeleteGroundObjects(void); extern void nullsub_16(void); extern void UpdateAdventureAchievements(void); extern void xxx_call_update_bg_sound_input(void); diff --git a/src/ground_object.c b/src/ground_object.c index ddca38a9f..047e6f5d4 100644 --- a/src/ground_object.c +++ b/src/ground_object.c @@ -1,5 +1,6 @@ #include "global.h" #include "globaldata.h" +#include "ground_object.h" #include "structs/str_ground_script.h" #include "debug.h" #include "data_script.h" @@ -48,20 +49,24 @@ struct GroundObjectTypeData extern struct GroundObjectTypeData gGroundObjectTypes[]; void DeleteGroundObjects(void); -void GroundObject_Delete(s32); const struct GroundScriptHeader *GetGroundScript(s16 a0, DebugLocation *); void sub_80A7658(struct UnkGroundSpriteStruct *); extern bool8 GroundScriptNotify(Action*, s32); extern bool8 GroundScript_Cancel(Action *r0); +extern bool8 GetPredefinedScript(Action *param_1, ScriptInfoSmall *script, s32 _index); void SetPredefinedScript(Action *param_1, s16 index, const ScriptCommand *param_3); +extern bool8 sub_80A66F8(struct UnkGroundSpriteStruct *ptr); +extern bool8 sub_80A671C(struct UnkGroundSpriteStruct *ptr); +extern bool8 CheckMapCollision_80A585C(PixelPos *, PixelPos *); +extern s16 HandleAction(Action *action, DebugLocation *debug); +extern void sub_80A7664(struct UnkGroundSpriteStruct *ptr, PixelPos *pixelPos, s32 a2); extern bool8 GetCurrentDungeonBounds(PixelPos *a0, PixelPos *a1); void sub_80A75CC(void *, s32, s32, s32); - -s32 GroundObject_Add(s32 id_,const GroundObjectData *objectData,s32 group_,s32 sector_); - +static void GroundObject_Delete(s32 index_); +static s32 TryMoveObjectRelative_80AC6AC(GroundObject *param_1, PixelPos *param_2); static s16 CallbackObjectGetIndex(void *ptr); static void CallbackObjectGetSize(void *objectPtr_, PixelPos *out); static void CallbackObjectSetHitboxPos(void *objectPtr_, PixelPos *posOrNull); @@ -144,11 +149,6 @@ const u8 gGroundObjectFileName[]; - - - - - @@ -170,7 +170,7 @@ static const struct ScriptCommand gUnknown_8118350[] = { JUMP_LABEL(0), }; -const s16 gUnknown_81183A0[] = { +static const s16 gUnknown_81183A0[] = { -1, 0x800, 0x801, @@ -198,15 +198,13 @@ const s16 gUnknown_81183A0[] = { void AllocGroundObjects(void) { - GroundObject *ptr; s32 index; gGroundObjects = MemoryAlloc(sizeof(GroundObject) * NUM_GROUND_OBJECTS, 6); - for(index = 0, ptr = &gGroundObjects[index]; index < NUM_GROUND_OBJECTS; index = (s16)(index + 1), ptr++) - { - ptr->kind |= -1; + for (index = 0, ptr = &gGroundObjects[index]; index < NUM_GROUND_OBJECTS; index = (s16)(index + 1), ptr++) { + ptr->kind = -1; } DeleteGroundObjects(); } @@ -217,9 +215,8 @@ void DeleteGroundObjects(void) s32 index; ptr = &gGroundObjects[0]; - for(index = 0; index < NUM_GROUND_OBJECTS; index = (s16)(index + 1), ptr++) - { - if(ptr->kind != -1) + for (index = 0; index < NUM_GROUND_OBJECTS; index = (s16)(index + 1), ptr++) { + if (ptr->kind != -1) GroundObject_Delete(index); } } @@ -323,7 +320,7 @@ static s32 GroundObject_Find(s32 kind) return -1; } -s32 GroundObject_Add(s32 id_,const GroundObjectData *objectData,s32 group_,s32 sector_) +s32 GroundObject_Add(s32 id_, const GroundObjectData *objectData, s32 group_, s32 sector_) { s32 sVar3; s32 sVar4; @@ -490,7 +487,7 @@ s32 GroundObject_Add(s32 id_,const GroundObjectData *objectData,s32 group_,s32 s return id; } -void GroundObject_Delete(s32 index_) +static void GroundObject_Delete(s32 index_) { s32 index = (s16)index_; GroundObject *parent = &gGroundObjects[index]; @@ -506,20 +503,18 @@ void sub_80AC1B0(s32 index_, s32 flag) s32 index = (s16)index_; GroundObject *parent = &gGroundObjects[index]; - if(parent->kind != -1) - { + if (parent->kind != -1) { parent->flags |= flag; sub_80A6688(&parent->unk144, parent->flags); } } -void sub_80AC1F4(s32 index_, s32 flag) +static void sub_80AC1F4(s32 index_, s32 flag) { s32 index = (s16)index_; GroundObject *parent = &gGroundObjects[index]; - if(parent->kind != -1) - { + if (parent->kind != -1) { parent->flags &= (0x337fffff ^ flag); sub_80A6688(&parent->unk144, parent->flags); } @@ -530,15 +525,12 @@ Action *GroundObject_GetAction(s32 index_) s32 index = (s16)index_; GroundObject *parent = &gGroundObjects[index]; - if(parent->kind != -1) + if (parent->kind != -1) return &parent->action; else return NULL; } -extern bool8 GetPredefinedScript(Action *param_1, ScriptInfoSmall *script, s32 _index); - - bool8 GroundObject_GetScript(s32 index_, ScriptInfoSmall *scriptInfo, s32 a2_) { s32 index = (s16)index_; @@ -551,7 +543,7 @@ bool8 GroundObject_GetScript(s32 index_, ScriptInfoSmall *scriptInfo, s32 a2_) return FALSE; } -bool8 GroundObject_ExecuteScript(s32 index_, void *a1, ScriptInfoSmall *script) +bool8 GroundObject_ExecuteScript(s32 index_, ActionUnkIds *a1, ScriptInfoSmall *script) { s32 index = (s16)index_; GroundObject *parent = &gGroundObjects[index]; @@ -649,9 +641,6 @@ s16 sub_80AC448(s32 index_, PixelPos *pos) return parent->kind; } -extern s32 TryMoveObjectRelative_80AC6AC(GroundObject *, PixelPos *); - - s16 sub_80AC49C(s32 index_, PixelPos *pos) { s32 index = (s16)index_; @@ -662,7 +651,8 @@ s16 sub_80AC49C(s32 index_, PixelPos *pos) return parent->kind; } -s32 sub_80AC4C8(s32 index, PixelPos *a0, PixelPos *a1) { +s32 sub_80AC4C8(s32 index, PixelPos *a0, PixelPos *a1) +{ GroundObject *parent = &gGroundObjects[0]; s32 counter; @@ -706,9 +696,7 @@ s32 sub_80AC554(s32 flag, PixelPos *param_2,PixelPos *param_3) return -1; } -bool8 CheckMapCollision_80A585C(PixelPos *, PixelPos *); - -s32 GetObjectCollision_80AC5F4(GroundObject *param_1, PixelPos *param_2, PixelPos *param_3) +static s32 GetObjectCollision_80AC5F4(GroundObject *param_1, PixelPos *param_2, PixelPos *param_3) { PixelPos local_28 = { param_2->x / 2048 , param_2->y / 2048 }; PixelPos iVar1 = { (param_3->x - 1) / 2048, (param_3->y - 1) / 2048 }; @@ -725,7 +713,7 @@ s32 GetObjectCollision_80AC5F4(GroundObject *param_1, PixelPos *param_2, PixelPo return 0; } -s32 TryMoveObjectRelative_80AC6AC(GroundObject *param_1,PixelPos *param_2) +static s32 TryMoveObjectRelative_80AC6AC(GroundObject *param_1, PixelPos *param_2) { PixelPos local_1c; PixelPos local_14; @@ -749,7 +737,7 @@ s32 TryMoveObjectRelative_80AC6AC(GroundObject *param_1,PixelPos *param_2) } } -s32 TryMoveRelative_80AC720(GroundObject *param_1,PixelPos *param_2) +static s32 TryMoveRelative_80AC720(GroundObject *param_1,PixelPos *param_2) { s32 ret; bool8 bVar1; @@ -893,7 +881,8 @@ static void CallbackObjectSetDirection(void *livesPtr_, s32 direction) } } -static void CallbackObjectSetEventIndex(void *livesPtr_, u16 a1) { +static void CallbackObjectSetEventIndex(void *livesPtr_, u16 a1) +{ struct GroundObject *livesPtr = livesPtr_; u32 r1; @@ -917,8 +906,8 @@ static void CallbackObjectSetEventIndex(void *livesPtr_, u16 a1) { livesPtr->directionRelated = 1; } - -static void CallbackObjectSetUnk_80AC998(void *objectPtr_, s32 a1_, s32 a2) { +static void CallbackObjectSetUnk_80AC998(void *objectPtr_, s32 a1_, s32 a2) +{ struct GroundObject *livesPtr = objectPtr_; s32 a1Match = (s16) a1_; @@ -935,9 +924,6 @@ static void CallbackObjectSetUnk_80AC998(void *objectPtr_, s32 a1_, s32 a2) { livesPtr->unk140 = a1; } -extern bool8 sub_80A66F8(struct UnkGroundSpriteStruct *ptr); -extern bool8 sub_80A671C(struct UnkGroundSpriteStruct *ptr); - static bool8 CallbackObjectSpriteRelatedCheck_80AC9B8(void *objectPtr_) { struct GroundObject *livesPtr = objectPtr_; @@ -990,8 +976,6 @@ static s32 CallbackObjectMoveRelative(void *livesPtr_, PixelPos *pos) return TryMoveRelative_80AC720(livesPtr, pos); } -extern s16 HandleAction(Action *action, DebugLocation *debug); - void GroundObject_Action(void) { GroundObject *objectPtr; @@ -1020,8 +1004,6 @@ void GroundObject_Action(void) } } -void sub_80A7664(struct UnkGroundSpriteStruct *ptr, PixelPos *pixelPos, s32 a2); - void sub_80ACAD4(void) { GroundObject *objectPtr; diff --git a/src/ground_script.c b/src/ground_script.c index 432e61ba2..8e9099dde 100644 --- a/src/ground_script.c +++ b/src/ground_script.c @@ -52,16 +52,12 @@ #include "textbox.h" #include "ground_event.h" #include "ground_effect.h" +#include "ground_object.h" void GroundMap_Select(s16); void GroundMap_SelectDungeon(s32, DungeonLocation*, u32); void GroundMap_GetStationScript(ScriptInfoSmall *out, s16, s32, s32); -void GroundObject_ExecuteScript(s32, ActionUnkIds *, ScriptInfoSmall *); -void GroundObject_Select(s32, s32 group, s32 sector); -void GroundObject_Cancel(s32 group, s32 sector); -void GroundObject_CancelBlank(void); void GroundWeather_Select(s16); -s16 GroundObject_Add(s16 id, GroundObjectData*, s16 group, s8 sector); // Beware of the declarations without specified arguments, returning u32 or s32, these were quickly hacked in to get the code to compile and link // The return values are almost certainly NOT correct and will need to be rechecked when moving to header files @@ -90,9 +86,6 @@ void sub_809D1E4(s32, s32, s32); void sub_809D208(s32, PixelPos*, s32); void sub_809D220(s32, s32, s32); void GroundScriptLockJumpZero(s16); -s16 sub_80AC448(s16, PixelPos*); -s32 sub_80AC49C(s16, PixelPos*); -void DeleteGroundObjects(void); s32 ExecuteScriptCommand(Action *action); bool8 sub_8099B94(void); PixelPos SetVecFromDirectionSpeed(s8, s32); @@ -106,15 +99,11 @@ bool8 sub_809D234(void); s32 sub_80A14E8(Action *, u8, u32, s32); u8 sub_80990EC(struct DungeonSetupInfo *param_1, s32 param_2); -extern u8 GroundObjectsCancelAll(void); extern u8 IsTextboxOpen_809A750(void); -extern Action *GroundObject_GetAction(s32); extern void sub_809AB4C(s32, s32); extern void sub_809ABB4(s32, s32); extern void sub_809AC18(s32, s32); -bool8 GroundObjectsNotifyAll(s16); - void sub_8098C58(void); void sub_8098CC8(void); bool8 sub_80961D8(void); @@ -127,7 +116,6 @@ u8 sub_80964E4(); void sub_80A56A0(s32, s32); void sub_80A56F0(PixelPos *); void sub_80A5704(PixelPos *); -void sub_80AC1B0(s16, s32); s32 sub_80A5984(); void sub_80A59A0(s32, s32 *, u16); extern bool8 sub_80A579C(PixelPos *a0, PixelPos *a1); diff --git a/src/ground_sprite.c b/src/ground_sprite.c index fb35720a3..2cb580a3d 100644 --- a/src/ground_sprite.c +++ b/src/ground_sprite.c @@ -14,6 +14,7 @@ #include "effect_sub_1.h" #include "pokemon.h" #include "ground_effect.h" +#include "ground_object.h" static IWRAM_INIT unkStruct_3001B7C *gUnknown_3001B7C = {NULL}; @@ -31,7 +32,6 @@ static EWRAM_INIT OpenedFile *gUnknown_203B4B4 = {NULL}; // code_8098BDC.s extern void sub_809971C(u16, const u8 *, s16); extern void sub_80997F4(u16, u16); -extern void sub_80ACAD4(void); extern void sub_800E970(void); extern u8 sub_809D248(PixelPos *r0);