diff --git a/data/event_scripts.s b/data/event_scripts.s index cf5695d3b..5e8a35f98 100644 --- a/data/event_scripts.s +++ b/data/event_scripts.s @@ -8,6 +8,7 @@ #include "constants/items.h" #include "constants/heal_locations.h" #include "constants/layouts.h" +#include "constants/map_scripts.h" #include "constants/maps.h" #include "constants/moves.h" #include "constants/songs.h" diff --git a/data/map_events.s b/data/map_events.s index c6f88d305..cd42bfe75 100644 --- a/data/map_events.s +++ b/data/map_events.s @@ -3,6 +3,7 @@ #include "constants/event_objects.h" #include "constants/flags.h" #include "constants/items.h" +#include "constants/map_scripts.h" #include "constants/maps.h" #include "constants/secret_bases.h" #include "constants/vars.h" diff --git a/data/mystery_event_msg.s b/data/mystery_event_msg.s index aa904b0bf..24a075181 100644 --- a/data/mystery_event_msg.s +++ b/data/mystery_event_msg.s @@ -1,5 +1,6 @@ #include "constants/flags.h" #include "constants/items.h" +#include "constants/map_scripts.h" #include "constants/moves.h" #include "constants/songs.h" #include "constants/species.h" diff --git a/include/constants/map_scripts.h b/include/constants/map_scripts.h new file mode 100644 index 000000000..d5fd40156 --- /dev/null +++ b/include/constants/map_scripts.h @@ -0,0 +1,12 @@ +#ifndef GUARD_CONSTANTS_MAP_SCRIPTS_H +#define GUARD_CONSTANTS_MAP_SCRIPTS_H + +#define MAP_SCRIPT_ON_LOAD 1 +#define MAP_SCRIPT_ON_FRAME_TABLE 2 +#define MAP_SCRIPT_ON_TRANSITION 3 +#define MAP_SCRIPT_ON_WARP_INTO_MAP_TABLE 4 +#define MAP_SCRIPT_ON_RESUME 5 +#define MAP_SCRIPT_ON_DIVE_WARP 6 +#define MAP_SCRIPT_ON_RETURN_TO_FIELD 7 + +#endif // GUARD_CONSTANTS_MAP_SCRIPTS_H \ No newline at end of file diff --git a/include/overworld.h b/include/overworld.h index 79cbf1da3..8caba0673 100644 --- a/include/overworld.h +++ b/include/overworld.h @@ -68,7 +68,7 @@ void SetContinueGameWarpToDynamicWarp(int unused); const struct MapConnection *GetMapConnection(u8 dir); bool8 SetDiveWarpEmerge(u16 x, u16 y); bool8 SetDiveWarpDive(u16 x, u16 y); -void mliX_load_map(u8 mapGroup, u8 mapNum); +void LoadMapFromCameraTransition(u8 mapGroup, u8 mapNum); void ResetInitialPlayerAvatarState(void); void StoreInitialPlayerAvatarState(void); bool32 Overworld_IsBikingAllowed(void); diff --git a/include/script.h b/include/script.h index 755ff19a3..386b388d0 100644 --- a/include/script.h +++ b/include/script.h @@ -43,16 +43,16 @@ void ScriptContext1_SetupScript(const u8 *ptr); void ScriptContext1_Stop(void); void EnableBothScriptContexts(void); void ScriptContext2_RunNewScript(const u8 *ptr); -u8 *mapheader_get_tagged_pointer(u8 tag); -void mapheader_run_script_by_tag(u8 tag); -u8 *mapheader_get_first_match_from_tagged_ptr_list(u8 tag); -void mapheader_run_script_with_tag_x1(void); -void mapheader_run_script_with_tag_x3(void); -void mapheader_run_script_with_tag_x5(void); -void mapheader_run_script_with_tag_x7(void); -void mapheader_run_script_with_tag_x6(void); -bool8 mapheader_run_first_tag2_script_list_match(void); -void mapheader_run_first_tag4_script_list_match(void); +u8 *MapHeaderGetScriptTable(u8 tag); +void MapHeaderRunScriptType(u8 tag); +u8 *MapHeaderCheckScriptTable(u8 tag); +void RunOnLoadMapScript(void); +void RunOnTransitionMapScript(void); +void RunOnResumeMapScript(void); +void RunOnReturnToFieldMapScript(void); +void RunOnDiveWarpMapScript(void); +bool8 TryRunOnFrameMapScript(void); +void TryRunOnWarpIntoMapScript(void); u32 CalculateRamScriptChecksum(void); void ClearRamScript(void); bool8 InitRamScript(const u8 *script, u16 scriptSize, u8 mapGroup, u8 mapNum, u8 objectId); diff --git a/src/battle_pyramid.c b/src/battle_pyramid.c index a2fa4120f..340c17c59 100644 --- a/src/battle_pyramid.c +++ b/src/battle_pyramid.c @@ -1590,7 +1590,7 @@ void GenerateBattlePyramidFloorLayout(u16 *backupMapData, bool8 setPlayerPositio layoutMap += mapLayout->width; } } - mapheader_run_script_with_tag_x1(); + RunOnLoadMapScript(); free(floorLayoutOffsets); } diff --git a/src/field_control_avatar.c b/src/field_control_avatar.c index 00dce4c7d..cffafaf9f 100644 --- a/src/field_control_avatar.c +++ b/src/field_control_avatar.c @@ -147,7 +147,7 @@ int ProcessPlayerFieldInput(struct FieldInput *input) if (CheckForTrainersWantingBattle() == TRUE) return TRUE; - if (mapheader_run_first_tag2_script_list_match() == 1) + if (TryRunOnFrameMapScript() == TRUE) return TRUE; if (input->pressedBButton && TrySetupDiveEmergeScript() == TRUE) diff --git a/src/fieldmap.c b/src/fieldmap.c index 7d9d079fc..cf5f0356e 100644 --- a/src/fieldmap.c +++ b/src/fieldmap.c @@ -53,7 +53,7 @@ void InitMap(void) { InitMapLayoutData(&gMapHeader); sub_80E8EE0(gMapHeader.events); - mapheader_run_script_with_tag_x1(); + RunOnLoadMapScript(); } void InitMapFromSavedGame(void) @@ -62,7 +62,7 @@ void InitMapFromSavedGame(void) sub_80E9238(0); sub_80E8EE0(gMapHeader.events); LoadSavedMapView(); - mapheader_run_script_with_tag_x1(); + RunOnLoadMapScript(); UpdateTVScreensOnMap(gBackupMapLayout.width, gBackupMapLayout.height); } @@ -775,7 +775,7 @@ bool8 CameraMove(int x, int y) old_y = gSaveBlock1Ptr->pos.y; connection = sub_8088950(direction, gSaveBlock1Ptr->pos.x, gSaveBlock1Ptr->pos.y); sub_80887F8(connection, direction, x, y); - mliX_load_map(connection->mapGroup, connection->mapNum); + LoadMapFromCameraTransition(connection->mapGroup, connection->mapNum); gCamera.active = TRUE; gCamera.x = old_x - gSaveBlock1Ptr->pos.x; gCamera.y = old_y - gSaveBlock1Ptr->pos.y; diff --git a/src/overworld.c b/src/overworld.c index 08fd94c1b..d5584efc3 100644 --- a/src/overworld.c +++ b/src/overworld.c @@ -761,7 +761,7 @@ static bool8 SetDiveWarp(u8 dir, u16 x, u16 y) } else { - mapheader_run_script_with_tag_x6(); + RunOnDiveWarpMapScript(); if (IsDummyWarp(&gFixedDiveWarp)) return FALSE; SetWarpDestinationToDiveWarp(); @@ -779,7 +779,7 @@ bool8 SetDiveWarpDive(u16 x, u16 y) return SetDiveWarp(CONNECTION_DIVE, x, y); } -void mliX_load_map(u8 mapGroup, u8 mapNum) +void LoadMapFromCameraTransition(u8 mapGroup, u8 mapNum) { s32 paletteIndex; @@ -800,7 +800,7 @@ void mliX_load_map(u8 mapGroup, u8 mapNum) ChooseAmbientCrySpecies(); SetDefaultFlashLevel(); Overworld_ClearSavedMusic(); - mapheader_run_script_with_tag_x3(); + RunOnTransitionMapScript(); InitMap(); copy_map_tileset2_to_vram_2(gMapHeader.mapLayout); apply_map_tileset2_palette(gMapHeader.mapLayout); @@ -813,7 +813,7 @@ void mliX_load_map(u8 mapGroup, u8 mapNum) RoamerMove(); DoCurrentWeather(); ResetFieldTasksArgs(); - mapheader_run_script_with_tag_x5(); + RunOnResumeMapScript(); if (gMapHeader.regionMapSectionId != MAPSEC_BATTLE_FRONTIER || gMapHeader.regionMapSectionId != sLastMapSectionId) ShowMapNamePopup(); @@ -852,7 +852,7 @@ static void mli0_load_map(u32 a1) FlagClear(FLAG_SYS_USE_FLASH); SetDefaultFlashLevel(); Overworld_ClearSavedMusic(); - mapheader_run_script_with_tag_x3(); + RunOnTransitionMapScript(); UpdateLocationHistoryForRoamer(); RoamerMoveToOtherLocationSet(); if (gMapHeader.mapLayoutId == LAYOUT_BATTLE_FRONTIER_BATTLE_PYRAMID_EMPTY_SQUARE) @@ -2126,7 +2126,7 @@ static void sub_8086988(u32 a1) sub_80AEE84(); if (!a1) SetUpFieldTasks(); - mapheader_run_script_with_tag_x5(); + RunOnResumeMapScript(); TryStartMirageTowerPulseBlendEffect(); } @@ -2136,7 +2136,7 @@ static void sub_80869DC(void) gTotalCameraPixelOffsetY = 0; ResetEventObjects(); TrySpawnEventObjects(0, 0); - mapheader_run_first_tag4_script_list_match(); + TryRunOnWarpIntoMapScript(); } static void mli4_mapscripts_and_other(void) @@ -2153,14 +2153,14 @@ static void mli4_mapscripts_and_other(void) SetPlayerAvatarTransitionFlags(player->transitionFlags); ResetInitialPlayerAvatarState(); TrySpawnEventObjects(0, 0); - mapheader_run_first_tag4_script_list_match(); + TryRunOnWarpIntoMapScript(); } static void sub_8086A68(void) { sub_808E16C(0, 0); RotatingGate_InitPuzzleAndGraphics(); - mapheader_run_script_with_tag_x7(); + RunOnReturnToFieldMapScript(); } static void sub_8086A80(void) diff --git a/src/script.c b/src/script.c index c61ae7183..dff99609b 100644 --- a/src/script.c +++ b/src/script.c @@ -241,7 +241,7 @@ void ScriptContext2_RunNewScript(const u8 *ptr) while (RunScriptCommand(&sScriptContext2) == TRUE); } -u8 *mapheader_get_tagged_pointer(u8 tag) +u8 *MapHeaderGetScriptTable(u8 tag) { const u8 *mapScripts = gMapHeader.mapScripts; @@ -261,16 +261,16 @@ u8 *mapheader_get_tagged_pointer(u8 tag) } } -void mapheader_run_script_by_tag(u8 tag) +void MapHeaderRunScriptType(u8 tag) { - u8 *ptr = mapheader_get_tagged_pointer(tag); + u8 *ptr = MapHeaderGetScriptTable(tag); if (ptr) ScriptContext2_RunNewScript(ptr); } -u8 *mapheader_get_first_match_from_tagged_ptr_list(u8 tag) +u8 *MapHeaderCheckScriptTable(u8 tag) { - u8 *ptr = mapheader_get_tagged_pointer(tag); + u8 *ptr = MapHeaderGetScriptTable(tag); if (!ptr) return NULL; @@ -291,45 +291,45 @@ u8 *mapheader_get_first_match_from_tagged_ptr_list(u8 tag) } } -void mapheader_run_script_with_tag_x1(void) +void RunOnLoadMapScript(void) { - mapheader_run_script_by_tag(1); + MapHeaderRunScriptType(1); } -void mapheader_run_script_with_tag_x3(void) +void RunOnTransitionMapScript(void) { - mapheader_run_script_by_tag(3); + MapHeaderRunScriptType(3); } -void mapheader_run_script_with_tag_x5(void) +void RunOnResumeMapScript(void) { - mapheader_run_script_by_tag(5); + MapHeaderRunScriptType(5); } -void mapheader_run_script_with_tag_x7(void) +void RunOnReturnToFieldMapScript(void) { - mapheader_run_script_by_tag(7); + MapHeaderRunScriptType(7); } -void mapheader_run_script_with_tag_x6(void) +void RunOnDiveWarpMapScript(void) { - mapheader_run_script_by_tag(6); + MapHeaderRunScriptType(6); } -bool8 mapheader_run_first_tag2_script_list_match(void) +bool8 TryRunOnFrameMapScript(void) { - u8 *ptr = mapheader_get_first_match_from_tagged_ptr_list(2); + u8 *ptr = MapHeaderCheckScriptTable(2); if (!ptr) - return 0; + return FALSE; ScriptContext1_SetupScript(ptr); - return 1; + return TRUE; } -void mapheader_run_first_tag4_script_list_match(void) +void TryRunOnWarpIntoMapScript(void) { - u8 *ptr = mapheader_get_first_match_from_tagged_ptr_list(4); + u8 *ptr = MapHeaderCheckScriptTable(4); if (ptr) ScriptContext2_RunNewScript(ptr); } diff --git a/src/trainer_hill.c b/src/trainer_hill.c index efe11b0c7..42b196abd 100644 --- a/src/trainer_hill.c +++ b/src/trainer_hill.c @@ -796,7 +796,7 @@ void sub_81D5FB4(u16 *mapArg) dst += 31; } - mapheader_run_script_with_tag_x1(); + RunOnLoadMapScript(); FreeDataStruct(); }