diff --git a/include/ground_effect.h b/include/ground_effect.h new file mode 100644 index 000000000..d13f99abf --- /dev/null +++ b/include/ground_effect.h @@ -0,0 +1,23 @@ +#ifndef GUARD_GROUND_EFFECT_H +#define GUARD_GROUND_EFFECT_H + +#include "structs/str_ground_script.h" + +void AllocGroundEffects(void); +void DeleteGroundEffects(void); +void FreeGroundEffects(void); +void GroundEffect_Select(s32 scriptID, s32 group, s32 sector); +void GroundEffect_Cancel(s32 scriptID, s32 sector); +void GroundEffect_CancelBlank(void); +s32 GroundEffect_Add(s32 _id, const GroundEffectData *effectData, s32 _group, s32 _sector); +void sub_80AD0C8(s32 _id, s32 flags); +Action *sub_80AD158(s32 index_); +bool8 GroundEffect_ExecuteScript(s32 index_, ActionUnkIds *a1, ScriptInfoSmall *script); +bool8 GroundEffectsNotifyAll(s32 index_); +bool8 GroundEffectsCancelAll(void); +s16 sub_80AD360(s32 index_, PixelPos *pos); +s16 sub_80AD3B4(s32 index_, PixelPos *pos); +void GroundEffect_Action(void); +void sub_80AD7AC(void); + +#endif // GUARD_GROUND_EFFECT_H diff --git a/src/code_809D148.c b/src/code_809D148.c index c042e4efe..c8703c807 100644 --- a/src/code_809D148.c +++ b/src/code_809D148.c @@ -7,6 +7,7 @@ #include "other_random.h" #include "ground_script.h" #include "ground_lives.h" +#include "ground_effect.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 s32 sub_80AD360(s16 a0, PixelPos *a1); extern bool8 sub_80A579C(PixelPos *a0, PixelPos *a1); void sub_809D25C(void) @@ -215,7 +215,7 @@ void sub_809D25C(void) gUnknown_20399E8.unk0 = 0; break; case 3: - val = sub_80AD360(gUnknown_20399E8.unk4, &gUnknown_20399E8.unk1C); + val = sub_80AD360((s16) gUnknown_20399E8.unk4, &gUnknown_20399E8.unk1C); if (val == (u16) -1) gUnknown_20399E8.unk0 = 0; break; diff --git a/src/ground_effect.c b/src/ground_effect.c index aa1a262a8..661d5c800 100644 --- a/src/ground_effect.c +++ b/src/ground_effect.c @@ -1,5 +1,6 @@ #include "global.h" #include "globaldata.h" +#include "ground_effect.h" #include "data_script.h" #include "ground_script.h" #include "ground_sprite.h" @@ -49,9 +50,6 @@ extern struct GroundEffectTypeData gGroundEffectTypes[]; extern bool8 GetPredefinedScript(Action *param_1, ScriptInfoSmall *script, s32 _index); -void GroundEffect_Delete(s32); -void DeleteGroundEffects(void); -s32 GroundEffect_Add(s32 _id,const GroundEffectData *effectData,s32 _group,s32 _sector); const struct GroundScriptHeader *GetGroundScript(s16 a0, DebugLocation *); bool8 GetCurrentDungeonBounds(PixelPos *, PixelPos *); @@ -60,12 +58,14 @@ extern void SetPredefinedScript(Action *param_1, s16 index, const ScriptCommand void sub_80A7714(struct UnkGroundSpriteStruct *); extern bool8 GroundScriptNotify(Action*, s32); extern bool8 GroundScript_Cancel(Action *r0); -s32 sub_80AD3E0(GroundEffect *, PixelPos *); extern bool8 sub_80A66F8(struct UnkGroundSpriteStruct *ptr); extern bool8 sub_80A671C(struct UnkGroundSpriteStruct *ptr); void sub_80A7720(struct UnkGroundSpriteStruct *ptr, PixelPos *pixelPos, s32 a2); +extern s16 HandleAction(Action *action, DebugLocation *debug); +static void GroundEffect_Delete(s32 _id); +static s32 sub_80AD3E0(GroundEffect *param_1, PixelPos *param_2); static s16 CallbackEffectGetIndex(void *ptr); static void CallbackEffectGetSize(void *effectPtr_, PixelPos *out); static void CallbackEffectSetHitboxPos(void *effectPtr_, PixelPos *posOrNull); @@ -174,7 +174,6 @@ void AllocGroundEffects(void) DeleteGroundEffects(); } - void DeleteGroundEffects(void) { s32 index; @@ -271,7 +270,8 @@ void GroundEffect_CancelBlank(void) } } -UNUSED s32 GroundEffect_Find(s32 a0_) { +UNUSED static s32 GroundEffect_Find(s32 a0_) +{ s32 index; s32 a0; GroundEffect *ptr; @@ -289,7 +289,7 @@ UNUSED s32 GroundEffect_Find(s32 a0_) { return -1; } -s32 GroundEffect_Add(s32 _id, const GroundEffectData *effectData,s32 _group,s32 _sector) +s32 GroundEffect_Add(s32 _id, const GroundEffectData *effectData, s32 _group, s32 _sector) { struct GroundEffectTypeData *puVar4; s32 group; @@ -393,7 +393,7 @@ s32 GroundEffect_Add(s32 _id, const GroundEffectData *effectData,s32 _group,s32 return id; } -void GroundEffect_Delete(s32 _id) +static void GroundEffect_Delete(s32 _id) { s32 id = (s16)_id; GroundEffect *parent = &gGroundEffects[id]; @@ -452,7 +452,7 @@ UNUSED static bool8 sub_80AD18C(s32 index_, ScriptInfoSmall *scriptInfo, s32 a2_ return FALSE; } -bool8 GroundEffect_ExecuteScript(s32 index_, void *a1, ScriptInfoSmall *script) +bool8 GroundEffect_ExecuteScript(s32 index_, ActionUnkIds *a1, ScriptInfoSmall *script) { s32 index = (s16)index_; GroundEffect *parent = &gGroundEffects[index]; @@ -560,7 +560,7 @@ s16 sub_80AD3B4(s32 index_, PixelPos *pos) return parent->kind; } -s32 sub_80AD3E0(GroundEffect *param_1,PixelPos *param_2) +static s32 sub_80AD3E0(GroundEffect *param_1, PixelPos *param_2) { PixelPos local_1c = {param_2->x - param_1->unk14.x, param_2->y - param_1->unk14.y}; PixelPos local_14 = {param_2->x + param_1->unk14.x, param_2->y + param_1->unk14.y}; @@ -576,7 +576,7 @@ s32 sub_80AD3E0(GroundEffect *param_1,PixelPos *param_2) } } -s32 sub_80AD430(GroundEffect *param_1,PixelPos *param_2) +static s32 sub_80AD430(GroundEffect *param_1, PixelPos *param_2) { PixelPos iVar2 = {param_1->unk124.x + param_2->x, param_1->unk124.y + param_2->y}; PixelPos uVar4 = {param_1->unk12C.x + param_2->x, param_1->unk12C.y + param_2->y}; @@ -693,7 +693,8 @@ static void CallbackEffectSetDirection(void *livesPtr_, s32 direction) } } -static void CallbackEffectSetEventIndex(void *livesPtr_, u16 a1) { +static void CallbackEffectSetEventIndex(void *livesPtr_, u16 a1) +{ struct GroundEffect *livesPtr = livesPtr_; u32 r1; @@ -717,7 +718,8 @@ static void CallbackEffectSetEventIndex(void *livesPtr_, u16 a1) { livesPtr->directionRelated = TRUE; } -static void CallbackEffectSetUnk_80AD670(void *objectPtr_, s32 a1_, s32 a2) { +static void CallbackEffectSetUnk_80AD670(void *objectPtr_, s32 a1_, s32 a2) +{ struct GroundEffect *livesPtr = objectPtr_; s32 a1Match = (s16) a1_; @@ -786,8 +788,6 @@ static s32 CallbackEffectMoveRelative(void *livesPtr_, PixelPos *pos) return sub_80AD430(livesPtr, pos); } -extern s16 HandleAction(Action *action, DebugLocation *debug); - void GroundEffect_Action(void) { GroundEffect *objectPtr; @@ -822,7 +822,6 @@ void sub_80AD7AC(void) s32 i; s32 minus1; - for (objectPtr = &gGroundEffects[0], i = 0, minus1 = -1; i < NUM_GROUND_EFFECTS; i = (s16)(i + 1), objectPtr++) { minus1 = (s16)minus1; diff --git a/src/ground_main.c b/src/ground_main.c index c54f864a2..3cace7b8b 100644 --- a/src/ground_main.c +++ b/src/ground_main.c @@ -27,6 +27,7 @@ #include "ground_lives.h" #include "ground_event.h" #include "ground_sprite.h" +#include "ground_effect.h" EWRAM_DATA u32 gUnknown_20398A8 = {0}; EWRAM_DATA s32 gUnknown_20398AC = {0}; @@ -73,7 +74,6 @@ extern bool8 sub_80048BC(void); extern u8 sub_80023E4(u32); extern bool8 sub_8099B94(void); extern void FreeGroundObjects(void); -extern void FreeGroundEffects(void); extern void sub_809D508(void); extern void nullsub_119(void); extern void sub_8099768(void); @@ -83,9 +83,7 @@ extern void sub_809975C(void); extern void sub_809D0AC(void); extern void sub_809D490(void); extern void AllocGroundObjects(void); -extern void AllocGroundEffects(void); extern void GroundObject_Action(void); -extern void GroundEffect_Action(void); extern void sub_809B474(void); extern void GroundScript_Unlock(); extern void sub_809D25C(void); @@ -101,7 +99,6 @@ extern void sub_809B638(void); extern void sub_8099750(void); extern void sub_809D0BC(void); extern void DeleteGroundObjects(void); -extern void DeleteGroundEffects(void); extern void nullsub_16(void); extern void UpdateAdventureAchievements(void); extern void xxx_call_update_bg_sound_input(void); diff --git a/src/ground_script.c b/src/ground_script.c index 5b4bac483..432e61ba2 100644 --- a/src/ground_script.c +++ b/src/ground_script.c @@ -51,21 +51,17 @@ #include "unk_ds_only_feature.h" #include "textbox.h" #include "ground_event.h" +#include "ground_effect.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 GroundEffect_ExecuteScript(s32, ActionUnkIds *, ScriptInfoSmall *); void GroundObject_Select(s32, s32 group, s32 sector); -void GroundEffect_Select(s32, s32 group, s32 sector); void GroundObject_Cancel(s32 group, s32 sector); -void GroundEffect_Cancel(s32 group, s32 sector); void GroundObject_CancelBlank(void); -void GroundEffect_CancelBlank(void); void GroundWeather_Select(s16); s16 GroundObject_Add(s16 id, GroundObjectData*, s16 group, s8 sector); -s16 GroundEffect_Add(s16 id, GroundEffectData*, 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 @@ -96,10 +92,7 @@ void sub_809D220(s32, s32, s32); void GroundScriptLockJumpZero(s16); s16 sub_80AC448(s16, PixelPos*); s32 sub_80AC49C(s16, PixelPos*); -s16 sub_80AD360(s16, PixelPos*); -s16 sub_80AD3B4(s16, PixelPos*); void DeleteGroundObjects(void); -void DeleteGroundEffects(void); s32 ExecuteScriptCommand(Action *action); bool8 sub_8099B94(void); PixelPos SetVecFromDirectionSpeed(s8, s32); @@ -114,16 +107,13 @@ s32 sub_80A14E8(Action *, u8, u32, s32); u8 sub_80990EC(struct DungeonSetupInfo *param_1, s32 param_2); extern u8 GroundObjectsCancelAll(void); -extern u8 GroundEffectsCancelAll(void); extern u8 IsTextboxOpen_809A750(void); extern Action *GroundObject_GetAction(s32); -extern Action *sub_80AD158(s32); extern void sub_809AB4C(s32, s32); extern void sub_809ABB4(s32, s32); extern void sub_809AC18(s32, s32); bool8 GroundObjectsNotifyAll(s16); -bool8 GroundEffectsNotifyAll(s16); void sub_8098C58(void); void sub_8098CC8(void); @@ -138,7 +128,6 @@ void sub_80A56A0(s32, s32); void sub_80A56F0(PixelPos *); void sub_80A5704(PixelPos *); void sub_80AC1B0(s16, s32); -void sub_80AD0C8(s16, s32); s32 sub_80A5984(); void sub_80A59A0(s32, s32 *, u16); extern bool8 sub_80A579C(PixelPos *a0, PixelPos *a1); @@ -1651,7 +1640,7 @@ s32 ExecuteScriptCommand(Action *action) sector = (s8)curCmd.argByte < 0 ? scriptData->script.sector : (s8)curCmd.argByte; &eff; }); - res = GroundEffect_Add(-1, eff, group, sector); + res = (s16) GroundEffect_Add(-1, eff, (s16) group, (s8) sector); if (res >= 0) { action->callbacks->getHitboxCenter(action->parentObject, &pos); sub_80AD3B4(res, &pos); @@ -2456,7 +2445,7 @@ s32 ExecuteScriptCommand(Action *action) } case 0x98: { s32 id = action->callbacks->getIndex(action->parentObject); - switch(action->unk8.unk0) { + switch (action->unk8.unk0) { case 1: sub_809D170(1, id); break; @@ -2472,7 +2461,7 @@ s32 ExecuteScriptCommand(Action *action) case 0x99: { s32 id = action->callbacks->getIndex(action->parentObject); PixelPos unk; - switch(action->unk8.unk0) { + switch (action->unk8.unk0) { case 1: sub_80A8FD8(id, &unk); sub_809D158(0, &unk); @@ -2495,7 +2484,7 @@ s32 ExecuteScriptCommand(Action *action) case 0x9b: { s32 id = action->callbacks->getIndex(action->parentObject); if (id < 0) break; - switch(action->unk8.unk0) { + switch (action->unk8.unk0) { case 1: sub_809D1A8(1, id, curCmd.argShort); return 2; @@ -2511,7 +2500,7 @@ s32 ExecuteScriptCommand(Action *action) case 0x9c: { s32 id = action->callbacks->getIndex(action->parentObject); PixelPos unk; - switch(action->unk8.unk0) { + switch (action->unk8.unk0) { case 1: sub_80A8FD8(id, &unk); sub_809D190(0, &unk, curCmd.argShort); @@ -2589,7 +2578,7 @@ s32 ExecuteScriptCommand(Action *action) case 0xa2: { s32 id = action->callbacks->getIndex(action->parentObject); PixelPos unk; - switch(action->unk8.unk0) { + switch (action->unk8.unk0) { case 1: sub_80A8FD8(id, &unk); sub_809D208(0, &unk, curCmd.argShort); @@ -3751,7 +3740,7 @@ s32 sub_80A14E8(Action *action, u8 idx, u32 r2, s32 r3) sp_308.height = 1; sp_308.pos = (CompactPos) {0}; sp_308.script = gFunctionScriptTable[406].script; // MOVE_DEBUG_CAMERA - ret = GroundEffect_Add(-1, &sp_308, r2, r3); + ret = (s16) GroundEffect_Add(-1, &sp_308, (s16) r2, (s8) r3); if(ret < 0) break; r7 = sub_80AD158(ret); sub_80A579C(&sp_340, &sp_348); diff --git a/src/ground_sprite.c b/src/ground_sprite.c index 786541f2a..fb35720a3 100644 --- a/src/ground_sprite.c +++ b/src/ground_sprite.c @@ -13,6 +13,7 @@ #include "sprite.h" #include "effect_sub_1.h" #include "pokemon.h" +#include "ground_effect.h" static IWRAM_INIT unkStruct_3001B7C *gUnknown_3001B7C = {NULL}; @@ -31,7 +32,6 @@ static EWRAM_INIT OpenedFile *gUnknown_203B4B4 = {NULL}; extern void sub_809971C(u16, const u8 *, s16); extern void sub_80997F4(u16, u16); extern void sub_80ACAD4(void); -extern void sub_80AD7AC(void); extern void sub_800E970(void); extern u8 sub_809D248(PixelPos *r0);