diff options
author | Cameron Hall <camthesaxman@users.noreply.github.com> | 2017-10-01 14:51:04 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-01 14:51:04 -0500 |
commit | 9ba9993be18af162239838cfefe23f535e291ac0 (patch) | |
tree | be25184d91d099fe769ba5eda55f4898f128ce9c /src | |
parent | 83efcc9c3d1e81b78c2cd9ceab3ac6420a5f4070 (diff) | |
parent | ab3c40fbf6dd7e32d63ef8146edea900d10681d6 (diff) |
Merge pull request #436 from camthesaxman/script_cmd_renaming
Rename script commands
Diffstat (limited to 'src')
-rw-r--r-- | src/battle/battle_setup.c | 2 | ||||
-rw-r--r-- | src/engine/cable_club.c | 4 | ||||
-rw-r--r-- | src/engine/script.c | 68 | ||||
-rw-r--r-- | src/engine/sound.c | 2 | ||||
-rw-r--r-- | src/field/bike.c | 6 | ||||
-rw-r--r-- | src/field/coins.c | 26 | ||||
-rw-r--r-- | src/field/decoration.c | 2 | ||||
-rw-r--r-- | src/field/event_data.c | 4 | ||||
-rw-r--r-- | src/field/field_effect.c | 18 | ||||
-rw-r--r-- | src/field/field_fadetransition.c | 14 | ||||
-rw-r--r-- | src/field/field_map_obj.c | 22 | ||||
-rw-r--r-- | src/field/field_player_avatar.c | 4 | ||||
-rw-r--r-- | src/field/field_screen_effect.c | 2 | ||||
-rw-r--r-- | src/field/field_special_scene.c | 2 | ||||
-rw-r--r-- | src/field/field_specials.c | 6 | ||||
-rw-r--r-- | src/field/hof_pc.c | 2 | ||||
-rw-r--r-- | src/field/item_menu.c | 4 | ||||
-rw-r--r-- | src/field/item_use.c | 34 | ||||
-rw-r--r-- | src/field/overworld.c | 178 | ||||
-rw-r--r-- | src/field/scrcmd.c | 650 | ||||
-rw-r--r-- | src/field/secret_base.c | 2 | ||||
-rw-r--r-- | src/rom6.c | 2 | ||||
-rw-r--r-- | src/scene/evolution_scene.c | 4 | ||||
-rw-r--r-- | src/scene/new_game.c | 2 |
24 files changed, 603 insertions, 457 deletions
diff --git a/src/battle/battle_setup.c b/src/battle/battle_setup.c index 59e17e9eb..40949ed38 100644 --- a/src/battle/battle_setup.c +++ b/src/battle/battle_setup.c @@ -876,7 +876,7 @@ static void CB2_StartFirstBattle(void) static void CB2_EndFirstBattle(void) { - sav1_reset_battle_music_maybe(); + Overworld_ClearSavedMusic(); SetMainCallback2(c2_exit_to_overworld_1_continue_scripts_restart_music); } diff --git a/src/engine/cable_club.c b/src/engine/cable_club.c index 7a85f2b6c..c61a1d01c 100644 --- a/src/engine/cable_club.c +++ b/src/engine/cable_club.c @@ -68,7 +68,7 @@ static void sub_8083B6C(void); static void sub_8083CA4(u8 taskId); extern void sub_80831F8(u8 taskId); -extern void call_map_music_set_to_zero(void); +extern void Overworld_ResetMapMusic(void); extern void sub_810FEFC(void); extern void sub_8047CD8(void); extern void sub_805559C(void); @@ -708,7 +708,7 @@ static void sub_808382C(u8 taskId) static void sub_8083958(void) { - call_map_music_set_to_zero(); + Overworld_ResetMapMusic(); LoadPlayerParty(); SavePlayerBag(); sub_810FEFC(); diff --git a/src/engine/script.c b/src/engine/script.c index f049b96fc..8625cfdc2 100644 --- a/src/engine/script.c +++ b/src/engine/script.c @@ -3,6 +3,14 @@ #include "event_data.h" #define RAM_SCRIPT_MAGIC 51 +#define SCRIPT_STACK_SIZE 20 + +enum +{ + SCRIPT_MODE_STOPPED, + SCRIPT_MODE_BYTECODE, + SCRIPT_MODE_NATIVE, +}; EWRAM_DATA u8 *gUnknown_0202E8AC = NULL; @@ -19,66 +27,66 @@ void InitScriptContext(struct ScriptContext *ctx, void *cmdTable, void *cmdTable { s32 i; - ctx->mode = 0; - ctx->scriptPtr = 0; + ctx->mode = SCRIPT_MODE_STOPPED; + ctx->scriptPtr = NULL; ctx->stackDepth = 0; - ctx->nativePtr = 0; + ctx->nativePtr = NULL; ctx->cmdTable = cmdTable; ctx->cmdTableEnd = cmdTableEnd; for (i = 0; i < 4; i++) ctx->data[i] = 0; - for (i = 0; i < 20; i++) + for (i = 0; i < SCRIPT_STACK_SIZE; i++) ctx->stack[i] = 0; } u8 SetupBytecodeScript(struct ScriptContext *ctx, const u8 *ptr) { ctx->scriptPtr = ptr; - ctx->mode = 1; + ctx->mode = SCRIPT_MODE_BYTECODE; return 1; } void SetupNativeScript(struct ScriptContext *ctx, bool8 (*ptr)(void)) { - ctx->mode = 2; + ctx->mode = SCRIPT_MODE_NATIVE; ctx->nativePtr = ptr; } void StopScript(struct ScriptContext *ctx) { - ctx->mode = 0; - ctx->scriptPtr = 0; + ctx->mode = SCRIPT_MODE_STOPPED; + ctx->scriptPtr = NULL; } -u8 RunScriptCommand(struct ScriptContext *ctx) +bool8 RunScriptCommand(struct ScriptContext *ctx) { - if (ctx->mode == 0) - return 0; + if (ctx->mode == SCRIPT_MODE_STOPPED) + return FALSE; switch (ctx->mode) { - case 0: - return 0; - case 2: + case SCRIPT_MODE_STOPPED: + return FALSE; + case SCRIPT_MODE_NATIVE: if (ctx->nativePtr) { if (ctx->nativePtr() == TRUE) - ctx->mode = 1; - return 1; + ctx->mode = SCRIPT_MODE_BYTECODE; + return TRUE; } - ctx->mode = 1; - case 1: + ctx->mode = SCRIPT_MODE_BYTECODE; + case SCRIPT_MODE_BYTECODE: while (1) { u8 cmdCode; - ScrCmdFunc *func; + ScrCmdFunc *cmdFunc; - if (!ctx->scriptPtr) + if (ctx->scriptPtr == NULL) { - ctx->mode = 0; - return 0; + ctx->mode = SCRIPT_MODE_STOPPED; + return FALSE; } if (ctx->scriptPtr == gNullScriptPtr) @@ -89,25 +97,25 @@ u8 RunScriptCommand(struct ScriptContext *ctx) cmdCode = *(ctx->scriptPtr); ctx->scriptPtr++; - func = &ctx->cmdTable[cmdCode]; + cmdFunc = &ctx->cmdTable[cmdCode]; - if (func >= ctx->cmdTableEnd) + if (cmdFunc >= ctx->cmdTableEnd) { - ctx->mode = 0; - return 0; + ctx->mode = SCRIPT_MODE_STOPPED; + return FALSE; } - if ((*func)(ctx) == 1) - return 1; + if ((*cmdFunc)(ctx) == TRUE) + return TRUE; } } - return 1; + return TRUE; } u8 ScriptPush(struct ScriptContext *ctx, const u8 *ptr) { - if (ctx->stackDepth + 1 >= 20) + if (ctx->stackDepth + 1 >= SCRIPT_STACK_SIZE) { return 1; } diff --git a/src/engine/sound.c b/src/engine/sound.c index 91f5e06a3..a6a61c0b5 100644 --- a/src/engine/sound.c +++ b/src/engine/sound.c @@ -81,8 +81,6 @@ void MapMusicMain(void) PlayBGM(sCurrentMapMusic); break; case 2: - case 3: - case 4: break; case 5: if (IsBGMStopped()) diff --git a/src/field/bike.c b/src/field/bike.c index dae86bd88..8df901b40 100644 --- a/src/field/bike.c +++ b/src/field/bike.c @@ -935,13 +935,13 @@ void GetOnOffBike(u8 var) if (gPlayerAvatar.flags & (PLAYER_AVATAR_FLAG_MACH_BIKE | PLAYER_AVATAR_FLAG_ACRO_BIKE)) { SetPlayerAvatarTransitionFlags(PLAYER_AVATAR_FLAG_ON_FOOT); - sav1_reset_battle_music_maybe(); - sub_8053E90(); + Overworld_ClearSavedMusic(); + Overworld_PlaySpecialMapMusic(); } else { SetPlayerAvatarTransitionFlags(var); - sav1_set_battle_music_maybe(BGM_CYCLING); + Overworld_SetSavedMusic(BGM_CYCLING); Overworld_ChangeMusicTo(BGM_CYCLING); } } diff --git a/src/field/coins.c b/src/field/coins.c index 3c6356612..91a4b508d 100644 --- a/src/field/coins.c +++ b/src/field/coins.c @@ -6,47 +6,47 @@ #define MAX_COINS 9999 -void UpdateCoinsWindow(s32 a, u8 b, u8 c) +void UpdateCoinsWindow(s32 coins, u8 x, u8 y) { - PrintCoins(a, 4, b + 2, c + 1); + PrintCoins(coins, 4, x + 2, y + 1); } -void ShowCoinsWindow(u32 a, u8 b, u8 c) +void ShowCoinsWindow(u32 coins, u8 x, u8 y) { - MenuDrawTextWindow(b, c, b + 9, c + 3); - UpdateCoinsWindow(a, b, c); + MenuDrawTextWindow(x, y, x + 9, y + 3); + UpdateCoinsWindow(coins, x, y); } -void HideCoinsWindow(u8 a, u8 b) +void HideCoinsWindow(u8 x, u8 y) { - MenuZeroFillWindowRect(a, b, a + 9, b + 3); + MenuZeroFillWindowRect(x, y, x + 9, y + 3); } -void PrintCoins(s32 a, u8 b, u8 c, u8 d) +void PrintCoins(s32 coins, u8 b, u8 x, u8 y) { u8 string[16]; u8 *ptr; u8 r1; u8 foo; - ConvertIntToDecimalString(string, a); + ConvertIntToDecimalString(string, coins); r1 = (b * 6 + 0x21 - 8 * (b + 2)); - c = c - r1 / 8; + x = x - r1 / 8; foo = r1 % 8; ptr = gStringVar1; if (foo) { - ptr[0] = 0xFC; + ptr[0] = EXT_CTRL_CODE_BEGIN; ptr[1] = 0x11; ptr[2] = 8 - (foo); ptr += 3; } - ptr[0] = 0xFC; + ptr[0] = EXT_CTRL_CODE_BEGIN; ptr[1] = 0x11; ptr[2] = (b - StringLength(string)) * 6; ptr += 3; StringCopy(ptr, string); - MenuPrint(gOtherText_Coins2, c, d); + MenuPrint(gOtherText_Coins2, x, y); } u16 GetCoins(void) diff --git a/src/field/decoration.c b/src/field/decoration.c index 065afbfb6..e067191e9 100644 --- a/src/field/decoration.c +++ b/src/field/decoration.c @@ -2199,7 +2199,7 @@ void sub_80FF0E0(u8 taskId) void sub_80FF114(u8 taskId) { DrawWholeMapView(); - warp1_set(gSaveBlock1.location.mapGroup, gSaveBlock1.location.mapNum, -1, gTasks[taskId].data[3], gTasks[taskId].data[4]); + Overworld_SetWarpDestination(gSaveBlock1.location.mapGroup, gSaveBlock1.location.mapNum, -1, gTasks[taskId].data[3], gTasks[taskId].data[4]); warp_in(); } void sub_80FF160(u8 taskId) diff --git a/src/field/event_data.c b/src/field/event_data.c index ee475343f..43d49c417 100644 --- a/src/field/event_data.c +++ b/src/field/event_data.c @@ -114,10 +114,8 @@ u16 *GetVarPointer(u16 id) { if (id < 0x4000) return NULL; - - if ((s16)id >= 0) + if (id < 0x8000) return &gSaveBlock1.vars[id - 0x4000]; - return gSpecialVars[id - 0x8000]; } diff --git a/src/field/field_effect.c b/src/field/field_effect.c index 1bdf82991..afe020ac7 100644 --- a/src/field/field_effect.c +++ b/src/field/field_effect.c @@ -1213,7 +1213,7 @@ void task00_8084310(u8 taskId) } if (!FieldEffectActiveListContains(FLDEFF_USE_FLY)) { - flag_var_implications_of_teleport_(); + Overworld_ResetStateAfterFly(); warp_in(); SetMainCallback2(CB2_LoadMap); gFieldCallback = mapldr_08084390; @@ -1223,7 +1223,7 @@ void task00_8084310(u8 taskId) void mapldr_08084390(void) { - sub_8053E90(); + Overworld_PlaySpecialMapMusic(); pal_fill_black(); CreateTask(c3_080843F8, 0); gMapObjects[gPlayerAvatar.mapObjectId].mapobj_bit_13 = 1; @@ -1264,7 +1264,7 @@ extern void CameraObjectReset1(void); void sub_8086748(void) { - sub_8053E90(); + Overworld_PlaySpecialMapMusic(); pal_fill_for_map_transition(); ScriptContext2_Enable(); FreezeMapObjects(); @@ -1533,7 +1533,7 @@ void sub_8086C40(void) void sub_8086C94(void) { - sub_8053E90(); + Overworld_PlaySpecialMapMusic(); pal_fill_for_map_transition(); ScriptContext2_Enable(); CreateTask(sub_8086CBC, 0); @@ -1897,7 +1897,7 @@ void sub_8087470(u8); void mapldr_080851BC(void) { - sub_8053E90(); + Overworld_PlaySpecialMapMusic(); pal_fill_for_map_transition(); ScriptContext2_Enable(); gFieldCallback = NULL; @@ -2134,7 +2134,7 @@ void sub_8087A74(u8); void mapldr_080859D4(void) { - sub_8053E90(); + Overworld_PlaySpecialMapMusic(); pal_fill_for_map_transition(); ScriptContext2_Enable(); FreezeMapObjects(); @@ -2266,7 +2266,7 @@ void sub_8087D78(struct Task *task) { if (!gPaletteFade.active && sub_8054034() == TRUE) { - sub_8053570(); + Overworld_SetWarpDestToLastHealLoc(); warp_in(); SetMainCallback2(CB2_LoadMap); gFieldCallback = mapldr_08085D88; @@ -2278,7 +2278,7 @@ void sub_8087E1C(u8); void mapldr_08085D88(void) { - sub_8053E90(); + Overworld_PlaySpecialMapMusic(); pal_fill_for_map_transition(); ScriptContext2_Enable(); FreezeMapObjects(); @@ -2879,7 +2879,7 @@ u8 FldEff_UseSurf(void) u8 taskId; taskId = CreateTask(sub_8088954, 0xff); gTasks[taskId].data[15] = gFieldEffectArguments[0]; - sav1_reset_battle_music_maybe(); + Overworld_ClearSavedMusic(); Overworld_ChangeMusicTo(0x016d); return FALSE; } diff --git a/src/field/field_fadetransition.c b/src/field/field_fadetransition.c index d95177821..82776d18c 100644 --- a/src/field/field_fadetransition.c +++ b/src/field/field_fadetransition.c @@ -89,7 +89,7 @@ void task0A_asap_script_env_2_enable_and_set_ctx_running(u8 taskID) void sub_8080990(void) { ScriptContext2_Enable(); - sub_8053E90(); + Overworld_PlaySpecialMapMusic(); pal_fill_black(); CreateTask(task0A_asap_script_env_2_enable_and_set_ctx_running, 10); } @@ -130,7 +130,7 @@ void task_mpl_807DD60(u8 taskId) void sub_8080A3C(void) { ScriptContext2_Enable(); - sub_8053E90(); + Overworld_PlaySpecialMapMusic(); palette_bg_fill_black(); CreateTask(task_mpl_807DD60, 10); } @@ -165,7 +165,7 @@ void sub_8080A5C(u8 taskId) void sub_8080AC4(void) { ScriptContext2_Enable(); - sub_8053E90(); + Overworld_PlaySpecialMapMusic(); palette_bg_fill_black(); CreateTask(sub_8080A5C, 10); } @@ -188,7 +188,7 @@ void sub_8080AE4(void) void mapldr_default(void) { - sub_8053E90(); + Overworld_PlaySpecialMapMusic(); pal_fill_for_map_transition(); sub_8080AE4(); ScriptContext2_Enable(); @@ -196,7 +196,7 @@ void mapldr_default(void) void sub_8080B60(void) { - sub_8053E90(); + Overworld_PlaySpecialMapMusic(); pal_fill_black(); sub_8080AE4(); ScriptContext2_Enable(); @@ -204,7 +204,7 @@ void sub_8080B60(void) void sub_8080B78(void) { - sub_8053E90(); + Overworld_PlaySpecialMapMusic(); pal_fill_for_map_transition(); PlaySE(SE_TK_WARPOUT); CreateTask(task_map_chg_seq_0807E2CC, 10); @@ -354,7 +354,7 @@ void sub_8080E28(void) void sub_8080E44(void) { ScriptContext2_Enable(); - sub_8053E90(); + Overworld_PlaySpecialMapMusic(); pal_fill_black(); CreateTask(task_mpl_807E3C8, 10); } diff --git a/src/field/field_map_obj.c b/src/field/field_map_obj.c index 59319a16e..0cba448a9 100644 --- a/src/field/field_map_obj.c +++ b/src/field/field_map_obj.c @@ -2462,24 +2462,24 @@ extern void sub_8064970(struct Sprite *); extern void sub_8060470(s16 *, s16 *, s16, s16); extern void InitObjectPriorityByZCoord(); -u8 sub_805B410(u8 a, u8 b, s16 c, s16 d, u8 e, u8 f) +u8 sub_805B410(u8 graphicsId, u8 b, s16 x, s16 y, u8 elevation, u8 direction) { const struct MapObjectGraphicsInfo *gfxInfo; struct SpriteTemplate spriteTemplate; const struct SubspriteTable *subspriteTables; u8 spriteId; - gfxInfo = GetFieldObjectGraphicsInfo(a); - MakeObjectTemplateFromFieldObjectGraphicsInfo(a, sub_8064970, &spriteTemplate, &subspriteTables); + gfxInfo = GetFieldObjectGraphicsInfo(graphicsId); + MakeObjectTemplateFromFieldObjectGraphicsInfo(graphicsId, sub_8064970, &spriteTemplate, &subspriteTables); #ifdef NONMATCHING spriteTemplate.paletteTag = 0xFFFF; #else *(u16 *)&spriteTemplate.paletteTag = 0xFFFF; #endif - c += 7; - d += 7; - sub_8060470(&c, &d, 8, 16); - spriteId = CreateSpriteAtEnd(&spriteTemplate, c, d, 0); + x += 7; + y += 7; + sub_8060470(&x, &y, 8, 16); + spriteId = CreateSpriteAtEnd(&spriteTemplate, x, y, 0); if (spriteId != 64) { struct Sprite *sprite = &gSprites[spriteId]; @@ -2490,7 +2490,7 @@ u8 sub_805B410(u8 a, u8 b, s16 c, s16 d, u8 e, u8 f) sprite->oam.paletteNum = gfxInfo->paletteSlot; sprite->coordOffsetEnabled = TRUE; sprite->data0 = b; - sprite->data1 = e; + sprite->data1 = elevation; if (gfxInfo->paletteSlot == 10) npc_load_two_palettes__and_record(gfxInfo->paletteTag1, gfxInfo->paletteSlot); if (subspriteTables != NULL) @@ -2498,9 +2498,9 @@ u8 sub_805B410(u8 a, u8 b, s16 c, s16 d, u8 e, u8 f) SetSubspriteTables(sprite, subspriteTables); sprite->subspriteMode = 2; } - InitObjectPriorityByZCoord(sprite, e); - SetObjectSubpriorityByZCoord(e, sprite, 1); - StartSpriteAnim(sprite, FieldObjectDirectionToImageAnimId(f)); + InitObjectPriorityByZCoord(sprite, elevation); + SetObjectSubpriorityByZCoord(elevation, sprite, 1); + StartSpriteAnim(sprite, FieldObjectDirectionToImageAnimId(direction)); } return spriteId; } diff --git a/src/field/field_player_avatar.c b/src/field/field_player_avatar.c index e7947b704..6c1c9123a 100644 --- a/src/field/field_player_avatar.c +++ b/src/field/field_player_avatar.c @@ -1365,8 +1365,8 @@ void sub_805A20C(u8 a) u8 taskId; ScriptContext2_Enable(); - sav1_reset_battle_music_maybe(); - sub_8053F84(); + Overworld_ClearSavedMusic(); + Overworld_ChangeMusicToDefault(); gPlayerAvatar.flags &= ~PLAYER_AVATAR_FLAG_SURFING; gPlayerAvatar.flags |= PLAYER_AVATAR_FLAG_ON_FOOT; gPlayerAvatar.unk6 = 1; diff --git a/src/field/field_screen_effect.c b/src/field/field_screen_effect.c index 1464a99b1..0c76d254d 100644 --- a/src/field/field_screen_effect.c +++ b/src/field/field_screen_effect.c @@ -327,7 +327,7 @@ static void task50_0807F0C8(u8); void sub_8081924(void) { - sub_8054044(); + Overworld_FadeOutMapMusic(); CreateTask(task50_0807F0C8, 80); } diff --git a/src/field/field_special_scene.c b/src/field/field_special_scene.c index 38c076c51..d4b59c8a2 100644 --- a/src/field/field_special_scene.c +++ b/src/field/field_special_scene.c @@ -250,7 +250,7 @@ bool8 sub_80C7754(void) } else { - warp1_set(mapGroup, mapNum, -1, x, y); + Overworld_SetWarpDestination(mapGroup, mapNum, -1, x, y); return TRUE; } } diff --git a/src/field/field_specials.c b/src/field/field_specials.c index c23ea2ddc..36362d098 100644 --- a/src/field/field_specials.c +++ b/src/field/field_specials.c @@ -213,7 +213,7 @@ void UpdateCyclingRoadState(void) { if (VarGet(0x40a9) == 2 || VarGet(0x40a9) == 3) { VarSet(0x40a9, 0); - sav1_set_battle_music_maybe(SE_STOP); + Overworld_SetSavedMusic(SE_STOP); } } @@ -700,11 +700,11 @@ void CableCarWarp(void) { if (gSpecialVar_0x8004 != 0) { - warp1_set(MAP_GROUP_ROUTE112_CABLE_CAR_STATION, MAP_ID_ROUTE112_CABLE_CAR_STATION, -1, 6, 4); + Overworld_SetWarpDestination(MAP_GROUP_ROUTE112_CABLE_CAR_STATION, MAP_ID_ROUTE112_CABLE_CAR_STATION, -1, 6, 4); } else { - warp1_set(MAP_GROUP_MT_CHIMNEY_CABLE_CAR_STATION, MAP_ID_MT_CHIMNEY_CABLE_CAR_STATION, -1, 6, 4); + Overworld_SetWarpDestination(MAP_GROUP_MT_CHIMNEY_CABLE_CAR_STATION, MAP_ID_MT_CHIMNEY_CABLE_CAR_STATION, -1, 6, 4); } } diff --git a/src/field/hof_pc.c b/src/field/hof_pc.c index aeeb7fe17..267ed4274 100644 --- a/src/field/hof_pc.c +++ b/src/field/hof_pc.c @@ -28,7 +28,7 @@ void ReturnFromHallOfFamePC(void) static void ReshowPCMenuAfterHallOfFamePC(void) { ScriptContext2_Enable(); - sub_8053E90(); + Overworld_PlaySpecialMapMusic(); BeginNormalPaletteFade(0xFFFFFFFF, 0, 0x10, 0, 0); ScrSpecial_CreatePCMenu(); ScriptMenu_DisplayPCStartupPrompt(); diff --git a/src/field/item_menu.c b/src/field/item_menu.c index 7ff0e6174..c508bcacf 100644 --- a/src/field/item_menu.c +++ b/src/field/item_menu.c @@ -152,7 +152,7 @@ static u8 sReturnLocation; static const u8 *sPopupMenuActionList; // common -void (*gUnknown_03005D00)(u8) = NULL; +void (*gFieldItemUseCallback)(u8) = NULL; extern u16 gUnknown_030041B4; extern struct PocketScrollState gBagPocketScrollStates[]; extern struct ItemSlot *gCurrentBagPocketItemSlots; // selected pocket item slots @@ -2718,7 +2718,7 @@ void ExecuteItemUseFromBlackPalette(void) static void Task_CallItemUseOnFieldCallback(u8 taskId) { if (sub_807D770() == TRUE) - gUnknown_03005D00(taskId); + gFieldItemUseCallback(taskId); } void sub_80A5D04(void) diff --git a/src/field/item_use.c b/src/field/item_use.c index 8bc83bdc6..68da27fdb 100644 --- a/src/field/item_use.c +++ b/src/field/item_use.c @@ -36,7 +36,7 @@ #include "task.h" #include "vars.h" -extern void (*gUnknown_03005D00)(u8); +extern void (*gFieldItemUseCallback)(u8); extern void (*gFieldCallback)(void); extern void (*gUnknown_0300485C)(void); extern void (*gUnknown_03004AE4)(u8, u16, TaskFunc); @@ -106,11 +106,13 @@ void SetUpItemUseOnFieldCallback(u8 taskId) { if (gTasks[taskId].data[2] != 1) { - gFieldCallback = (void *)ExecuteItemUseFromBlackPalette; + gFieldCallback = ExecuteItemUseFromBlackPalette; ItemMenu_ConfirmNormalFade(taskId); } else - gUnknown_03005D00(taskId); + { + gFieldItemUseCallback(taskId); + } } void HandleDeniedItemUseMessage(u8 var1, u8 playerMenuStatus, const u8 *text) @@ -185,9 +187,9 @@ void ItemUseOutOfBattle_Bike(u8 taskId) } else { - if (Overworld_IsBikeAllowedOnCurrentMap() == TRUE && IsBikingDisallowedByPlayer() == FALSE) + if (Overworld_IsBikingAllowed() == TRUE && IsBikingDisallowedByPlayer() == FALSE) { - gUnknown_03005D00 = (void *)ItemUseOnFieldCB_Bike; + gFieldItemUseCallback = (void *)ItemUseOnFieldCB_Bike; SetUpItemUseOnFieldCallback(taskId); } else @@ -241,7 +243,7 @@ void ItemUseOutOfBattle_Rod(u8 taskId) { if (CanFish() == TRUE) { - gUnknown_03005D00 = (void *)ItemUseOnFieldCB_Rod; + gFieldItemUseCallback = (void *)ItemUseOnFieldCB_Rod; SetUpItemUseOnFieldCallback(taskId); } else @@ -257,7 +259,7 @@ void ItemUseOnFieldCB_Rod(u8 taskId) void ItemUseOutOfBattle_Itemfinder(u8 var) { IncrementGameStat(0x27); - gUnknown_03005D00 = (void *)ItemUseOnFieldCB_Itemfinder; + gFieldItemUseCallback = (void *)ItemUseOnFieldCB_Itemfinder; SetUpItemUseOnFieldCallback(var); } @@ -780,7 +782,7 @@ void sub_80C9C7C(u8 taskId) { if (IsPlayerFacingPlantedBerryTree() == TRUE) { - gUnknown_03005D00 = sub_80C9D00; + gFieldItemUseCallback = sub_80C9D00; gFieldCallback = ExecuteItemUseFromBlackPalette; gTasks[taskId].data[8] = (u32)c2_exit_to_overworld_2_switch >> 16; gTasks[taskId].data[9] = (u32)c2_exit_to_overworld_2_switch; @@ -805,7 +807,7 @@ void ItemUseOutOfBattle_WailmerPail(u8 taskId) { if (TryToWaterBerryTree() == TRUE) { - gUnknown_03005D00 = sub_80C9D74; + gFieldItemUseCallback = sub_80C9D74; SetUpItemUseOnFieldCallback(taskId); } else @@ -909,7 +911,7 @@ void sub_80C9FC0(u8 var) sub_80C9D98(var); } -void sub_80C9FDC(void) +static void PrepareItemUseMessage(void) { RemoveBagItem(gScriptItemId, 1); sub_80A3E0C(); @@ -922,7 +924,7 @@ void ItemUseOutOfBattle_Repel(u8 var) if (VarGet(VAR_REPEL_STEP_COUNT) == FALSE) { VarSet(VAR_REPEL_STEP_COUNT, ItemId_GetHoldEffectParam(gScriptItemId)); - sub_80C9FDC(); + PrepareItemUseMessage(); DisplayItemMessageOnField(var, gStringVar4, CleanUpItemMenuMessage, 1); } else @@ -975,10 +977,10 @@ void task08_080A1C44(u8 taskId) DestroyTask(taskId); } -void sub_80CA18C(u8 taskId) +void EscapeRopeCallback(u8 taskId) { - sub_8053014(); - sub_80C9FDC(); + Overworld_ResetStateAfterDigEscRope(); + PrepareItemUseMessage(); gTasks[taskId].data[0] = 0; DisplayItemMessageOnField(taskId, gStringVar4, task08_080A1C44, 0); } @@ -995,7 +997,7 @@ void ItemUseOutOfBattle_EscapeRope(u8 taskId) { if (CanUseEscapeRopeOnCurrMap() == TRUE) { - gUnknown_03005D00 = sub_80CA18C; + gFieldItemUseCallback = EscapeRopeCallback; SetUpItemUseOnFieldCallback(taskId); } else @@ -1114,7 +1116,7 @@ void ItemUseInBattle_Escape(u8 taskId) if((gBattleTypeFlags & BATTLE_TYPE_TRAINER) == FALSE) { - sub_80C9FDC(); + PrepareItemUseMessage(); DisplayItemMessageOnField(taskId, gStringVar4, sub_80A7094, 1); } else diff --git a/src/field/overworld.c b/src/field/overworld.c index 9b41a262d..d6f255409 100644 --- a/src/field/overworld.c +++ b/src/field/overworld.c @@ -91,7 +91,7 @@ extern struct MapHeader * const * const gMapGroups[]; extern s32 gMaxFlashLevel; EWRAM_DATA struct WarpData gUnknown_020297F0 = {0}; -EWRAM_DATA struct WarpData gUnknown_020297F8 = {0}; +EWRAM_DATA struct WarpData gWarpDestination = {0}; // new warp position EWRAM_DATA struct WarpData gUnknown_02029800 = {0}; EWRAM_DATA struct WarpData gUnknown_02029808 = {0}; EWRAM_DATA struct UnkPlayerStruct gUnknown_02029810 = {0}; @@ -195,12 +195,12 @@ static void DoWhiteOut(void) ScriptContext2_RunNewScript(S_WhiteOut); gSaveBlock1.money /= 2; ScrSpecial_HealPlayerParty(); - sub_8053050(); - sub_8053570(); + Overworld_ResetStateAfterWhiteOut(); + Overworld_SetWarpDestToLastHealLoc(); warp_in(); } -void flag_var_implications_of_teleport_(void) +void Overworld_ResetStateAfterFly(void) { player_avatar_init_params_reset(); FlagClear(SYS_CYCLING_ROAD); @@ -221,7 +221,7 @@ void Overworld_ResetStateAfterTeleport(void) ScriptContext2_RunNewScript(gUnknown_0819FC9F); } -void sub_8053014(void) +void Overworld_ResetStateAfterDigEscRope(void) { player_avatar_init_params_reset(); FlagClear(SYS_CYCLING_ROAD); @@ -231,7 +231,7 @@ void sub_8053014(void) FlagClear(SYS_USE_FLASH); } -void sub_8053050(void) +void Overworld_ResetStateAfterWhiteOut(void) { player_avatar_init_params_reset(); FlagClear(SYS_CYCLING_ROAD); @@ -283,9 +283,12 @@ void SetGameStat(u8 index, u32 value) gSaveBlock1.gameStats[index] = value; } -void sub_8053154(void) +void LoadMapObjTemplatesFromHeader(void) { + // Clear map object templates CpuFill32(0, gSaveBlock1.mapObjectTemplates, sizeof(gSaveBlock1.mapObjectTemplates)); + + // Copy map header events to save block CpuCopy32(gMapHeader.events->mapObjects, gSaveBlock1.mapObjectTemplates, gMapHeader.events->mapObjectCount * sizeof(struct MapObjectTemplate)); @@ -300,7 +303,7 @@ static void LoadSaveblockMapObjScripts(void) mapObjectTemplates[i].script = gMapHeader.events->mapObjects[i].script; } -void Overworld_SaveMapObjCoords(u8 localId, s16 x, s16 y) +void Overworld_SetMapObjTemplateCoords(u8 localId, s16 x, s16 y) { s32 i; for (i = 0; i < 64; i++) @@ -315,9 +318,10 @@ void Overworld_SaveMapObjCoords(u8 localId, s16 x, s16 y) } } -void Overworld_SaveMapObjMovementType(u8 localId, u8 movementType) +void Overworld_SetMapObjTemplateMovementType(u8 localId, u8 movementType) { s32 i; + for (i = 0; i < 64; i++) { struct MapObjectTemplate *mapObjectTemplate = &gSaveBlock1.mapObjectTemplates[i]; @@ -346,15 +350,15 @@ static struct MapData *get_mapdata_header(void) return NULL; } -static void warp_shift(void) +static void ApplyCurrentWarp(void) { gUnknown_020297F0 = gSaveBlock1.location; - gSaveBlock1.location = gUnknown_020297F8; + gSaveBlock1.location = gWarpDestination; gUnknown_02029800 = sDummyWarpData; gUnknown_02029808 = sDummyWarpData; } -static void warp_set(struct WarpData *warp, s8 mapGroup, s8 mapNum, s8 warpId, s8 x, s8 y) +static void SetWarpData(struct WarpData *warp, s8 mapGroup, s8 mapNum, s8 warpId, s8 x, s8 y) { warp->mapGroup = mapGroup; warp->mapNum = mapNum; @@ -385,7 +389,7 @@ struct MapHeader *const Overworld_GetMapHeaderByGroupAndId(u16 mapGroup, u16 map struct MapHeader *const warp1_get_mapheader(void) { - return Overworld_GetMapHeaderByGroupAndId(gUnknown_020297F8.mapGroup, gUnknown_020297F8.mapNum); + return Overworld_GetMapHeaderByGroupAndId(gWarpDestination.mapGroup, gWarpDestination.mapNum); } static void set_current_map_header_from_sav1_save_old_name(void) @@ -422,34 +426,34 @@ void sub_80533CC(void) void warp_in(void) { - warp_shift(); + ApplyCurrentWarp(); set_current_map_header_from_sav1_save_old_name(); sub_80533CC(); } -void warp1_set(s8 mapGroup, s8 mapNum, s8 warpId, s8 x, s8 y) +void Overworld_SetWarpDestination(s8 mapGroup, s8 mapNum, s8 warpId, s8 x, s8 y) { - warp_set(&gUnknown_020297F8, mapGroup, mapNum, warpId, x, y); + SetWarpData(&gWarpDestination, mapGroup, mapNum, warpId, x, y); } void warp1_set_2(s8 mapGroup, s8 mapNum, s8 warpId) { - warp1_set(mapGroup, mapNum, warpId, -1, -1); + Overworld_SetWarpDestination(mapGroup, mapNum, warpId, -1, -1); } void saved_warp2_set(int unused, s8 mapGroup, s8 mapNum, s8 warpId) { - warp_set(&gSaveBlock1.warp2, mapGroup, mapNum, warpId, gSaveBlock1.pos.x, gSaveBlock1.pos.y); + SetWarpData(&gSaveBlock1.warp2, mapGroup, mapNum, warpId, gSaveBlock1.pos.x, gSaveBlock1.pos.y); } void saved_warp2_set_2(int unused, s8 mapGroup, s8 mapNum, s8 warpId, s8 x, s8 y) { - warp_set(&gSaveBlock1.warp2, mapGroup, mapNum, warpId, x, y); + SetWarpData(&gSaveBlock1.warp2, mapGroup, mapNum, warpId, x, y); } void copy_saved_warp2_bank_and_enter_x_to_warp1(u8 unused) { - gUnknown_020297F8 = gSaveBlock1.warp2; + gWarpDestination = gSaveBlock1.warp2; } void sub_8053538(u8 a1) @@ -457,81 +461,82 @@ void sub_8053538(u8 a1) const struct HealLocation *warp = GetHealLocation(a1); if (warp) - warp1_set(warp->group, warp->map, -1, warp->x, warp->y); + Overworld_SetWarpDestination(warp->group, warp->map, -1, warp->x, warp->y); } -void sub_8053570(void) +void Overworld_SetWarpDestToLastHealLoc(void) { - gUnknown_020297F8 = gSaveBlock1.warp3; + gWarpDestination = gSaveBlock1.lastHealLocation; } -void sub_8053588(u8 a1) +void Overworld_SetHealLocationWarp(u8 healLocationId) { - const struct HealLocation *warp = GetHealLocation(a1); - if (warp) - warp_set(&gSaveBlock1.warp3, warp->group, warp->map, -1, warp->x, warp->y); + const struct HealLocation *healLocation = GetHealLocation(healLocationId); + + if (healLocation != NULL) + SetWarpData(&gSaveBlock1.lastHealLocation, healLocation->group, healLocation->map, -1, healLocation->x, healLocation->y); } void sub_80535C4(s16 a1, s16 a2) { - u8 v4 = Overworld_GetMapTypeOfSaveblockLocation(); - u8 v5 = GetMapTypeByGroupAndId(gUnknown_020297F8.mapGroup, gUnknown_020297F8.mapNum); - if (is_map_type_1_2_3_5_or_6(v4) && is_map_type_1_2_3_5_or_6(v5) != TRUE) + u8 currMapType = Overworld_GetMapTypeOfSaveblockLocation(); + u8 destMapType = GetMapTypeByGroupAndId(gWarpDestination.mapGroup, gWarpDestination.mapNum); + if (is_map_type_1_2_3_5_or_6(currMapType) && is_map_type_1_2_3_5_or_6(destMapType) != TRUE) sub_805363C(gSaveBlock1.location.mapGroup, gSaveBlock1.location.mapNum, -1, a1 - 7, a2 - 6); } void sub_805363C(s8 mapGroup, s8 mapNum, s8 warpId, s8 x, s8 y) { - warp_set(&gSaveBlock1.warp4, mapGroup, mapNum, warpId, x, y); + SetWarpData(&gSaveBlock1.warp4, mapGroup, mapNum, warpId, x, y); } void sub_8053678(void) { - gUnknown_020297F8 = gSaveBlock1.warp4; + gWarpDestination = gSaveBlock1.warp4; } void sub_8053690(s8 mapGroup, s8 mapNum, s8 warpId, s8 x, s8 y) { - warp_set(&gUnknown_02029800, mapGroup, mapNum, warpId, x, y); + SetWarpData(&gUnknown_02029800, mapGroup, mapNum, warpId, x, y); } -void warp1_set_to_warp2(void) +static void warp1_set_to_warp2(void) { - gUnknown_020297F8 = gUnknown_02029800; + gWarpDestination = gUnknown_02029800; } void sub_80536E4(s8 mapGroup, s8 mapNum, s8 warpId, s8 x, s8 y) { - warp_set(&gUnknown_02029808, mapGroup, mapNum, warpId, x, y); + SetWarpData(&gUnknown_02029808, mapGroup, mapNum, warpId, x, y); } void sub_8053720(s16 x, s16 y) { if (warp_data_is_not_neg_1(&gUnknown_02029808) == TRUE) { - gUnknown_020297F8 = gUnknown_020297F0; + gWarpDestination = gUnknown_020297F0; } else { - warp1_set(gUnknown_02029808.mapGroup, gUnknown_02029808.mapNum, -1, x, y); + Overworld_SetWarpDestination(gUnknown_02029808.mapGroup, gUnknown_02029808.mapNum, -1, x, y); } } void sub_8053778(void) { - gUnknown_020297F8 = gSaveBlock1.warp1; + gWarpDestination = gSaveBlock1.warp1; } void unref_sub_8053790(s8 mapGroup, s8 mapNum, s8 warpId, s8 x, s8 y) { - warp_set(&gSaveBlock1.warp1, mapGroup, mapNum, warpId, x, y); + SetWarpData(&gSaveBlock1.warp1, mapGroup, mapNum, warpId, x, y); } void sub_80537CC(u8 a1) { const struct HealLocation *warp = GetHealLocation(a1); if (warp) - warp_set(&gSaveBlock1.warp1, warp->group, warp->map, -1, warp->x, warp->y); + SetWarpData(&gSaveBlock1.warp1, warp->group, warp->map, -1, warp->x, warp->y); } void gpu_sync_bg_hide() @@ -539,7 +544,7 @@ void gpu_sync_bg_hide() gSaveBlock1.warp1 = gSaveBlock1.warp2; } -struct MapConnection *sub_8053818(u8 dir) +struct MapConnection *GetMapConnection(u8 dir) { s32 i; s32 count = gMapHeader.connections->count; @@ -557,10 +562,11 @@ struct MapConnection *sub_8053818(u8 dir) bool8 sub_8053850(u8 dir, u16 x, u16 y) { - struct MapConnection *connection = sub_8053818(dir); + struct MapConnection *connection = GetMapConnection(dir); + if (connection != NULL) { - warp1_set(connection->mapGroup, connection->mapNum, -1, x, y); + Overworld_SetWarpDestination(connection->mapGroup, connection->mapNum, -1, x, y); } else { @@ -586,11 +592,11 @@ void sub_80538F0(u8 mapGroup, u8 mapNum) { s32 i; - warp1_set(mapGroup, mapNum, -1, -1, -1); + Overworld_SetWarpDestination(mapGroup, mapNum, -1, -1, -1); sub_8053F0C(); - warp_shift(); + ApplyCurrentWarp(); set_current_map_header_from_sav1_save_old_name(); - sub_8053154(); + LoadMapObjTemplatesFromHeader(); ClearTempFieldEventData(); ResetCyclingRoadChallengeData(); prev_quest_postbuffer_cursor_backup_reset(); @@ -599,7 +605,7 @@ void sub_80538F0(u8 mapGroup, u8 mapNum) sub_80806E4(); ChooseAmbientCrySpecies(); SetDefaultFlashLevel(); - sav1_reset_battle_music_maybe(); + Overworld_ClearSavedMusic(); mapheader_run_script_with_tag_x3(); not_trainer_hill_battle_pyramid(); sub_8056D38(gMapHeader.mapData); @@ -623,7 +629,7 @@ void sub_8053994(u32 a1) bool8 v3; set_current_map_header_from_sav1_save_old_name(); - sub_8053154(); + LoadMapObjTemplatesFromHeader(); v2 = is_map_type_1_2_3_5_or_6(gMapHeader.mapType); v3 = Overworld_MapTypeIsIndoors(gMapHeader.mapType); ClearTempFieldEventData(); @@ -637,7 +643,7 @@ void sub_8053994(u32 a1) if (v2) FlagClear(SYS_USE_FLASH); SetDefaultFlashLevel(); - sav1_reset_battle_music_maybe(); + Overworld_ClearSavedMusic(); mapheader_run_script_with_tag_x3(); UpdateLocationHistoryForRoamer(); RoamerMoveToOtherLocationSet(); @@ -691,7 +697,7 @@ u8 sub_8053B00(struct UnkPlayerStruct *playerStruct, u16 a2, u8 a3) return 16; if (MetatileBehavior_IsSurfableWaterOrUnderwater(a2) == 1) return 8; - if (Overworld_IsBikeAllowedOnCurrentMap() != TRUE) + if (Overworld_IsBikingAllowed() != TRUE) return 1; if (playerStruct->player_field_0 == 2) return 2; @@ -729,7 +735,7 @@ u16 cur_mapdata_block_role_at_screen_center_acc_to_sav1(void) return MapGridGetMetatileBehaviorAt(gSaveBlock1.pos.x + 7, gSaveBlock1.pos.y + 7); } -bool32 Overworld_IsBikeAllowedOnCurrentMap(void) +bool32 Overworld_IsBikingAllowed(void) { // is player in cycling road entrance? if (gSaveBlock1.location.mapGroup == MAP_GROUP_ROUTE110_SEASIDE_CYCLING_ROAD_SOUTH_ENTRANCE @@ -830,10 +836,11 @@ static u16 GetLocationMusic(struct WarpData *warp) return Overworld_GetMapHeaderByGroupAndId(warp->mapGroup, warp->mapNum)->music; } -u16 sav1_map_get_music(void) +u16 GetCurrLocationDefaultMusic(void) { u16 music; + // Play the desert music only when the sandstorm is active on Route 111. if (gSaveBlock1.location.mapGroup == MAP_GROUP_ROUTE111 && gSaveBlock1.location.mapNum == MAP_ID_ROUTE111 && GetSav1Weather() == 8) @@ -853,9 +860,9 @@ u16 sav1_map_get_music(void) } } -u16 warp1_target_get_music(void) +u16 GetWarpDestinationMusic(void) { - u16 music = GetLocationMusic(&gUnknown_020297F8); + u16 music = GetLocationMusic(&gWarpDestination); if (music != 0x7FFF) { return music; @@ -870,19 +877,19 @@ u16 warp1_target_get_music(void) } } -void call_map_music_set_to_zero(void) +void Overworld_ResetMapMusic(void) { ResetMapMusic(); } -void sub_8053E90(void) +void Overworld_PlaySpecialMapMusic(void) { - u16 music = sav1_map_get_music(); + u16 music = GetCurrLocationDefaultMusic(); if (music != LEGENDARY_MUSIC) { - if (gSaveBlock1.battleMusic) - music = gSaveBlock1.battleMusic; + if (gSaveBlock1.savedMusic) + music = gSaveBlock1.savedMusic; else if (Overworld_GetMapTypeOfSaveblockLocation() == MAP_TYPE_UNDERWATER) music = BGM_DEEPDEEP; else if (TestPlayerAvatarFlags(PLAYER_AVATAR_FLAG_SURFING)) @@ -893,21 +900,21 @@ void sub_8053E90(void) PlayNewMapMusic(music); } -void sav1_set_battle_music_maybe(u16 songNum) +void Overworld_SetSavedMusic(u16 songNum) { - gSaveBlock1.battleMusic = songNum; + gSaveBlock1.savedMusic = songNum; } -void sav1_reset_battle_music_maybe(void) +void Overworld_ClearSavedMusic(void) { - gSaveBlock1.battleMusic = 0; + gSaveBlock1.savedMusic = 0; } void sub_8053F0C(void) { if (FlagGet(SPECIAL_FLAG_1) != TRUE) { - u16 newMusic = warp1_target_get_music(); + u16 newMusic = GetWarpDestinationMusic(); u16 currentMusic = GetCurrentMapMusic(); if (newMusic != LEGENDARY_MUSIC) { @@ -926,11 +933,11 @@ void sub_8053F0C(void) } } -void sub_8053F84(void) +void Overworld_ChangeMusicToDefault(void) { u16 currentMusic = GetCurrentMapMusic(); - if (currentMusic != sav1_map_get_music()) - FadeOutAndPlayNewMapMusic(sav1_map_get_music(), 8); + if (currentMusic != GetCurrLocationDefaultMusic()) + FadeOutAndPlayNewMapMusic(GetCurrLocationDefaultMusic(), 8); } void Overworld_ChangeMusicTo(u16 newMusic) @@ -951,7 +958,7 @@ u8 GetMapMusicFadeoutSpeed(void) void sub_8053FF8(void) { - u16 music = warp1_target_get_music(); + u16 music = GetWarpDestinationMusic(); if (FlagGet(SPECIAL_FLAG_1) != TRUE && music != GetCurrentMapMusic()) { u8 speed = GetMapMusicFadeoutSpeed(); @@ -964,7 +971,7 @@ bool8 sub_8054034(void) return IsNotWaitingForBGMStop(); } -void sub_8054044(void) +void Overworld_FadeOutMapMusic(void) { FadeOutMapMusic(4); } @@ -972,14 +979,16 @@ void sub_8054044(void) static void PlayAmbientCry(void) { s16 x, y; + s8 pan; + s8 volume; + PlayerGetDestCoords(&x, &y); - if (sIsAmbientCryWaterMon != TRUE - || MetatileBehavior_IsSurfableWaterOrUnderwater(MapGridGetMetatileBehaviorAt(x, y))) - { - s8 pan = (Random() % 88) + 212; - s8 volume = (Random() % 30) + 50; - PlayCry2(sAmbientCrySpecies, pan, volume, 1); - } + if (sIsAmbientCryWaterMon == TRUE + && !MetatileBehavior_IsSurfableWaterOrUnderwater(MapGridGetMetatileBehaviorAt(x, y))) + return; + pan = (Random() % 88) + 212; + volume = (Random() % 30) + 50; + PlayCry2(sAmbientCrySpecies, pan, volume, 1); } void UpdateAmbientCry(s16 *state, u16 *delayCounter) @@ -1149,6 +1158,7 @@ void OverworldBasic(void) sub_8072EDC(); } +// This CB2 is used when starting void CB2_OverworldBasic(void) { OverworldBasic(); @@ -1176,7 +1186,7 @@ void sub_80543DC(u16 (*a1)(u32)) void sub_80543E8(void) { - if (gFieldCallback) + if (gFieldCallback != NULL) gFieldCallback(); else mapldr_default(); @@ -1977,27 +1987,27 @@ void sub_8055280(u16 a1) u16 sub_80552B0(u32 a1) { - if (gMain.heldKeys & 0x40) + if (gMain.heldKeys & DPAD_UP) { return 19; } - else if (gMain.heldKeys & 0x80) + else if (gMain.heldKeys & DPAD_DOWN) { return 18; } - else if (gMain.heldKeys & 0x20) + else if (gMain.heldKeys & DPAD_LEFT) { return 20; } - else if (gMain.heldKeys & 0x10) + else if (gMain.heldKeys & DPAD_RIGHT) { return 21; } - else if (gMain.newKeys & 8) + else if (gMain.newKeys & START_BUTTON) { return 24; } - else if (gMain.newKeys & 1) + else if (gMain.newKeys & A_BUTTON) { return 25; } diff --git a/src/field/scrcmd.c b/src/field/scrcmd.c index 31a90158a..28584d4d0 100644 --- a/src/field/scrcmd.c +++ b/src/field/scrcmd.c @@ -91,12 +91,12 @@ static u8 * const sScriptStringVars[] = gStringVar3, }; -bool8 ScrCmd_snop(struct ScriptContext *ctx) +bool8 ScrCmd_nop(struct ScriptContext *ctx) { return FALSE; } -bool8 ScrCmd_snop1(struct ScriptContext *ctx) +bool8 ScrCmd_nop1(struct ScriptContext *ctx) { return FALSE; } @@ -107,9 +107,10 @@ bool8 ScrCmd_end(struct ScriptContext *ctx) return FALSE; } -bool8 ScrCmd_jumpasm(struct ScriptContext *ctx) +bool8 ScrCmd_gotonative(struct ScriptContext *ctx) { bool8 (*addr)(void) = (bool8 (*)(void))ScriptReadWord(ctx); + SetupNativeScript(ctx, addr); return TRUE; } @@ -117,20 +118,23 @@ bool8 ScrCmd_jumpasm(struct ScriptContext *ctx) bool8 ScrCmd_special(struct ScriptContext *ctx) { u16 index = ScriptReadHalfword(ctx); + gSpecials[index](); return FALSE; } -bool8 ScrCmd_specialval(struct ScriptContext *ctx) +bool8 ScrCmd_specialvar(struct ScriptContext *ctx) { u16 *var = GetVarPointer(ScriptReadHalfword(ctx)); + *var = gSpecials[ScriptReadHalfword(ctx)](); return FALSE; } -bool8 ScrCmd_callasm(struct ScriptContext *ctx) +bool8 ScrCmd_callnative(struct ScriptContext *ctx) { NativeFunc func = (NativeFunc)ScriptReadWord(ctx); + func(); return FALSE; } @@ -141,9 +145,10 @@ bool8 ScrCmd_waitstate(struct ScriptContext *ctx) return TRUE; } -bool8 ScrCmd_jump(struct ScriptContext *ctx) +bool8 ScrCmd_goto(struct ScriptContext *ctx) { u8 *ptr = (u8 *)ScriptReadWord(ctx); + ScriptJump(ctx, ptr); return FALSE; } @@ -156,25 +161,27 @@ bool8 ScrCmd_return(struct ScriptContext *ctx) bool8 ScrCmd_call(struct ScriptContext *ctx) { - u8 *ptr = (u8 *)ScriptReadWord(ctx); + ScriptCall(ctx, ptr); return FALSE; } -bool8 ScrCmd_jumpif(struct ScriptContext *ctx) +bool8 ScrCmd_goto_if(struct ScriptContext *ctx) { u8 condition = ScriptReadByte(ctx); u8 *ptr = (u8 *)ScriptReadWord(ctx); + if (sScriptConditionTable[condition][ctx->comparisonResult] == 1) ScriptJump(ctx, ptr); return FALSE; } -bool8 ScrCmd_callif(struct ScriptContext *ctx) +bool8 ScrCmd_call_if(struct ScriptContext *ctx) { u8 condition = ScriptReadByte(ctx); u8 *ptr = (u8 *)ScriptReadWord(ctx); + if (sScriptConditionTable[condition][ctx->comparisonResult] == 1) ScriptCall(ctx, ptr); return FALSE; @@ -184,13 +191,15 @@ bool8 ScrCmd_setvaddress(struct ScriptContext *ctx) { u32 addr1 = (u32)ctx->scriptPtr - 1; u32 addr2 = ScriptReadWord(ctx); + gUnknown_0202E8B0 = addr2 - addr1; return FALSE; } -bool8 ScrCmd_vjump(struct ScriptContext *ctx) +bool8 ScrCmd_vgoto(struct ScriptContext *ctx) { u32 addr = ScriptReadWord(ctx); + ScriptJump(ctx, (u8 *)(addr - gUnknown_0202E8B0)); return FALSE; } @@ -198,32 +207,36 @@ bool8 ScrCmd_vjump(struct ScriptContext *ctx) bool8 ScrCmd_vcall(struct ScriptContext *ctx) { u32 addr = ScriptReadWord(ctx); + ScriptCall(ctx, (u8 *)(addr - gUnknown_0202E8B0)); return FALSE; } -bool8 ScrCmd_if5(struct ScriptContext *ctx) +bool8 ScrCmd_vgoto_if(struct ScriptContext *ctx) { u8 condition = ScriptReadByte(ctx); u8 *ptr = (u8 *)(ScriptReadWord(ctx) - gUnknown_0202E8B0); + if (sScriptConditionTable[condition][ctx->comparisonResult] == 1) ScriptJump(ctx, ptr); return FALSE; } -bool8 ScrCmd_if6(struct ScriptContext *ctx) +bool8 ScrCmd_vcall_if(struct ScriptContext *ctx) { u8 condition = ScriptReadByte(ctx); u8 *ptr = (u8 *)(ScriptReadWord(ctx) - gUnknown_0202E8B0); + if (sScriptConditionTable[condition][ctx->comparisonResult] == 1) ScriptCall(ctx, ptr); return FALSE; } -bool8 ScrCmd_jumpstd(struct ScriptContext *ctx) +bool8 ScrCmd_gotostd(struct ScriptContext *ctx) { u8 index = ScriptReadByte(ctx); u8 **ptr = &gStdScripts[index]; + if (ptr < gStdScripts_End) ScriptJump(ctx, *ptr); return FALSE; @@ -233,15 +246,17 @@ bool8 ScrCmd_callstd(struct ScriptContext *ctx) { u8 index = ScriptReadByte(ctx); u8 **ptr = &gStdScripts[index]; + if (ptr < gStdScripts_End) ScriptCall(ctx, *ptr); return FALSE; } -bool8 ScrCmd_jumpstdif(struct ScriptContext *ctx) +bool8 ScrCmd_gotostd_if(struct ScriptContext *ctx) { u8 condition = ScriptReadByte(ctx); u8 index = ScriptReadByte(ctx); + if (sScriptConditionTable[condition][ctx->comparisonResult] == 1) { u8 **ptr = &gStdScripts[index]; @@ -251,10 +266,11 @@ bool8 ScrCmd_jumpstdif(struct ScriptContext *ctx) return FALSE; } -bool8 ScrCmd_callstdif(struct ScriptContext *ctx) +bool8 ScrCmd_callstd_if(struct ScriptContext *ctx) { u8 condition = ScriptReadByte(ctx); u8 index = ScriptReadByte(ctx); + if (sScriptConditionTable[condition][ctx->comparisonResult] == 1) { u8 **ptr = &gStdScripts[index]; @@ -264,50 +280,55 @@ bool8 ScrCmd_callstdif(struct ScriptContext *ctx) return FALSE; } -bool8 ScrCmd_jumpram(struct ScriptContext *ctx) +bool8 ScrCmd_gotoram(struct ScriptContext *ctx) { ScriptJump(ctx, (u8 *)gUnknown_0202E8AC); return FALSE; } -bool8 ScrCmd_die(struct ScriptContext *ctx) +bool8 ScrCmd_killscript(struct ScriptContext *ctx) { ClearRamScript(); StopScript(ctx); return TRUE; } -bool8 ScrCmd_setbyte(struct ScriptContext *ctx) +bool8 ScrCmd_setmysteryeventstatus(struct ScriptContext *ctx) { u8 value = ScriptReadByte(ctx); + SetMysteryEventScriptStatus(value); return FALSE; } -bool8 ScrCmd_loadptr(struct ScriptContext *ctx) +bool8 ScrCmd_loadword(struct ScriptContext *ctx) { u8 index = ScriptReadByte(ctx); + ctx->data[index] = ScriptReadWord(ctx); return FALSE; } -bool8 ScrCmd_loadbytefrompointer(struct ScriptContext *ctx) +bool8 ScrCmd_loadbytefromaddr(struct ScriptContext *ctx) { u8 index = ScriptReadByte(ctx); + ctx->data[index] = *(u8 *)ScriptReadWord(ctx); return FALSE; } -bool8 ScrCmd_writebytetooffset(struct ScriptContext *ctx) +bool8 ScrCmd_writebytetoaddr(struct ScriptContext *ctx) { u8 value = ScriptReadByte(ctx); + *(u8 *)ScriptReadWord(ctx) = value; return FALSE; } -bool8 ScrCmd_setbufferbyte(struct ScriptContext *ctx) +bool8 ScrCmd_loadbyte(struct ScriptContext *ctx) { u8 index = ScriptReadByte(ctx); + ctx->data[index] = ScriptReadByte(ctx); return FALSE; } @@ -315,14 +336,16 @@ bool8 ScrCmd_setbufferbyte(struct ScriptContext *ctx) bool8 ScrCmd_setptrbyte(struct ScriptContext *ctx) { u8 index = ScriptReadByte(ctx); + *(u8 *)ScriptReadWord(ctx) = ctx->data[index]; return FALSE; } -bool8 ScrCmd_copybuffers(struct ScriptContext *ctx) +bool8 ScrCmd_copylocal(struct ScriptContext *ctx) { u8 destIndex = ScriptReadByte(ctx); u8 srcIndex = ScriptReadByte(ctx); + ctx->data[destIndex] = ctx->data[srcIndex]; return FALSE; } @@ -359,73 +382,81 @@ u8 compare_012(u16 a1, u16 a2) { if (a1 < a2) return 0; - if (a1 == a2) return 1; - return 2; } -bool8 ScrCmd_comparebuffers(struct ScriptContext *ctx) +// comparelocaltolocal +bool8 ScrCmd_compare_local_to_local(struct ScriptContext *ctx) { u8 value1 = ctx->data[ScriptReadByte(ctx)]; u8 value2 = ctx->data[ScriptReadByte(ctx)]; + ctx->comparisonResult = compare_012(value1, value2); return FALSE; } -bool8 ScrCmd_comparebuffertobyte(struct ScriptContext *ctx) +// comparelocaltoimm +bool8 ScrCmd_compare_local_to_value(struct ScriptContext *ctx) { u8 value1 = ctx->data[ScriptReadByte(ctx)]; u8 value2 = ScriptReadByte(ctx); + ctx->comparisonResult = compare_012(value1, value2); return FALSE; } -bool8 ScrCmd_comparebuffertoptrbyte(struct ScriptContext *ctx) +bool8 ScrCmd_compare_local_to_addr(struct ScriptContext *ctx) { u8 value1 = ctx->data[ScriptReadByte(ctx)]; u8 value2 = *(u8 *)ScriptReadWord(ctx); + ctx->comparisonResult = compare_012(value1, value2); return FALSE; } -bool8 ScrCmd_compareptrbytetobuffer(struct ScriptContext *ctx) +bool8 ScrCmd_compare_addr_to_local(struct ScriptContext *ctx) { u8 value1 = *(u8 *)ScriptReadWord(ctx); u8 value2 = ctx->data[ScriptReadByte(ctx)]; + ctx->comparisonResult = compare_012(value1, value2); return FALSE; } -bool8 ScrCmd_compareptrbytetobyte(struct ScriptContext *ctx) +bool8 ScrCmd_compare_addr_to_value(struct ScriptContext *ctx) { u8 value1 = *(u8 *)ScriptReadWord(ctx); u8 value2 = ScriptReadByte(ctx); + ctx->comparisonResult = compare_012(value1, value2); return FALSE; } -bool8 ScrCmd_compareptrbytes(struct ScriptContext *ctx) +bool8 ScrCmd_compare_addr_to_addr(struct ScriptContext *ctx) { u8 value1 = *(u8 *)ScriptReadWord(ctx); u8 value2 = *(u8 *)ScriptReadWord(ctx); + ctx->comparisonResult = compare_012(value1, value2); return FALSE; } -bool8 ScrCmd_compare(struct ScriptContext *ctx) +bool8 ScrCmd_compare_var_to_value(struct ScriptContext *ctx) { u16 value1 = *GetVarPointer(ScriptReadHalfword(ctx)); u16 value2 = ScriptReadHalfword(ctx); + ctx->comparisonResult = compare_012(value1, value2); return FALSE; } -bool8 ScrCmd_comparevars(struct ScriptContext *ctx) +bool8 ScrCmd_compare_var_to_var(struct ScriptContext *ctx) { u16 *ptr1 = GetVarPointer(ScriptReadHalfword(ctx)); u16 *ptr2 = GetVarPointer(ScriptReadHalfword(ctx)); + ctx->comparisonResult = compare_012(*ptr1, *ptr2); return FALSE; } @@ -447,6 +478,7 @@ bool8 ScrCmd_subvar(struct ScriptContext *ctx) bool8 ScrCmd_random(struct ScriptContext *ctx) { u16 max = VarGet(ScriptReadHalfword(ctx)); + gScriptResult = Random() % max; return FALSE; } @@ -455,6 +487,7 @@ bool8 ScrCmd_additem(struct ScriptContext *ctx) { u16 itemId = VarGet(ScriptReadHalfword(ctx)); u32 quantity = VarGet(ScriptReadHalfword(ctx)); + gScriptResult = AddBagItem(itemId, (u8)quantity); return FALSE; } @@ -463,6 +496,7 @@ bool8 ScrCmd_removeitem(struct ScriptContext *ctx) { u16 itemId = VarGet(ScriptReadHalfword(ctx)); u32 quantity = VarGet(ScriptReadHalfword(ctx)); + gScriptResult = RemoveBagItem(itemId, (u8)quantity); return FALSE; } @@ -471,6 +505,7 @@ bool8 ScrCmd_checkitemspace(struct ScriptContext *ctx) { u16 itemId = VarGet(ScriptReadHalfword(ctx)); u32 quantity = VarGet(ScriptReadHalfword(ctx)); + gScriptResult = CheckBagHasSpace(itemId, (u8)quantity); return FALSE; } @@ -479,6 +514,7 @@ bool8 ScrCmd_checkitem(struct ScriptContext *ctx) { u16 itemId = VarGet(ScriptReadHalfword(ctx)); u32 quantity = VarGet(ScriptReadHalfword(ctx)); + gScriptResult = CheckBagHasItem(itemId, (u8)quantity); return FALSE; } @@ -486,6 +522,7 @@ bool8 ScrCmd_checkitem(struct ScriptContext *ctx) bool8 ScrCmd_checkitemtype(struct ScriptContext *ctx) { u16 itemId = VarGet(ScriptReadHalfword(ctx)); + gScriptResult = GetPocketByItemId(itemId); return FALSE; } @@ -494,6 +531,7 @@ bool8 ScrCmd_addpcitem(struct ScriptContext *ctx) { u16 itemId = VarGet(ScriptReadHalfword(ctx)); u16 quantity = VarGet(ScriptReadHalfword(ctx)); + gScriptResult = AddPCItem(itemId, quantity); return FALSE; } @@ -502,6 +540,7 @@ bool8 ScrCmd_checkpcitem(struct ScriptContext *ctx) { u16 itemId = VarGet(ScriptReadHalfword(ctx)); u16 quantity = VarGet(ScriptReadHalfword(ctx)); + gScriptResult = CheckPCHasItem(itemId, quantity); return FALSE; } @@ -509,6 +548,7 @@ bool8 ScrCmd_checkpcitem(struct ScriptContext *ctx) bool8 ScrCmd_adddecor(struct ScriptContext *ctx) { u32 decorId = VarGet(ScriptReadHalfword(ctx)); + gScriptResult = IsThereStorageSpaceForDecoration(decorId); return FALSE; } @@ -516,6 +556,7 @@ bool8 ScrCmd_adddecor(struct ScriptContext *ctx) bool8 ScrCmd_removedecor(struct ScriptContext *ctx) { u32 decorId = VarGet(ScriptReadHalfword(ctx)); + gScriptResult = sub_81340A8(decorId); return FALSE; } @@ -523,13 +564,15 @@ bool8 ScrCmd_removedecor(struct ScriptContext *ctx) bool8 ScrCmd_checkdecor(struct ScriptContext *ctx) { u32 decorId = VarGet(ScriptReadHalfword(ctx)); + gScriptResult = sub_8134074(decorId); return FALSE; } -bool8 ScrCmd_testdecor(struct ScriptContext *ctx) +bool8 ScrCmd_hasdecor(struct ScriptContext *ctx) { u32 decorId = VarGet(ScriptReadHalfword(ctx)); + gScriptResult = sub_8133FE4(decorId); return FALSE; } @@ -552,22 +595,23 @@ bool8 ScrCmd_checkflag(struct ScriptContext *ctx) return FALSE; } -bool8 ScrCmd_inccounter(struct ScriptContext *ctx) +bool8 ScrCmd_incrementgamestat(struct ScriptContext *ctx) { IncrementGameStat(ScriptReadByte(ctx)); return FALSE; } -bool8 ScrCmd_lighten(struct ScriptContext *ctx) +bool8 ScrCmd_animdarklevel(struct ScriptContext *ctx) { sub_8081594(ScriptReadByte(ctx)); ScriptContext1_Stop(); return TRUE; } -bool8 ScrCmd_darken(struct ScriptContext *ctx) +bool8 ScrCmd_setdarklevel(struct ScriptContext *ctx) { u16 flashLevel = VarGet(ScriptReadHalfword(ctx)); + Overworld_SetFlashLevel(flashLevel); return FALSE; } @@ -591,6 +635,7 @@ bool8 ScrCmd_fadescreendelay(struct ScriptContext *ctx) { u8 duration = ScriptReadByte(ctx); u8 delay = ScriptReadByte(ctx); + fade_screen(duration, delay); SetupNativeScript(ctx, IsPaletteNotActive); return TRUE; @@ -606,28 +651,29 @@ bool8 s28_pause_asm() return FALSE; } -bool8 ScrCmd_pause(struct ScriptContext *ctx) +bool8 ScrCmd_delay(struct ScriptContext *ctx) { sPauseCounter = ScriptReadHalfword(ctx); SetupNativeScript(ctx, s28_pause_asm); return TRUE; } -bool8 ScrCmd_compareflags(struct ScriptContext *ctx) +bool8 ScrCmd_initclock(struct ScriptContext *ctx) { u8 hour = VarGet(ScriptReadHalfword(ctx)); u8 minute = VarGet(ScriptReadHalfword(ctx)); + RtcInitLocalTimeOffset(hour, minute); return FALSE; } -bool8 ScrCmd_checkdailyflags(struct ScriptContext *ctx) +bool8 ScrCmd_dodailyevents(struct ScriptContext *ctx) { DoTimeBasedEvents(); return FALSE; } -bool8 ScrCmd_resetvars(struct ScriptContext *ctx) +bool8 ScrCmd_gettime(struct ScriptContext *ctx) { RtcCalcLocalTime(); gSpecialVar_0x8000 = gLocalTime.hours; @@ -638,8 +684,9 @@ bool8 ScrCmd_resetvars(struct ScriptContext *ctx) bool8 ScrCmd_setweather(struct ScriptContext *ctx) { - u16 value = VarGet(ScriptReadHalfword(ctx)); - SetSav1Weather(value); + u16 weather = VarGet(ScriptReadHalfword(ctx)); + + SetSav1Weather(weather); return FALSE; } @@ -661,47 +708,51 @@ bool8 ScrCmd_tileeffect(struct ScriptContext *ctx) return FALSE; } -bool8 ScrCmd_setmapfooter(struct ScriptContext *ctx) +bool8 ScrCmd_setmaplayoutindex(struct ScriptContext *ctx) { u16 value = VarGet(ScriptReadHalfword(ctx)); + sub_8053D14(value); return FALSE; } bool8 ScrCmd_warp(struct ScriptContext *ctx) { - u8 v1 = ScriptReadByte(ctx); - u8 v2 = ScriptReadByte(ctx); - u8 v3 = ScriptReadByte(ctx); - u16 v4 = VarGet(ScriptReadHalfword(ctx)); - s8 v5 = VarGet(ScriptReadHalfword(ctx)); - warp1_set(v1, v2, v3, v4, v5); + u8 mapGroup = ScriptReadByte(ctx); + u8 mapNum = ScriptReadByte(ctx); + u8 warpId = ScriptReadByte(ctx); + u16 x = VarGet(ScriptReadHalfword(ctx)); + u16 y = VarGet(ScriptReadHalfword(ctx)); + + Overworld_SetWarpDestination(mapGroup, mapNum, warpId, x, y); sub_8080E88(); player_avatar_init_params_reset(); return TRUE; } -bool8 ScrCmd_warpmuted(struct ScriptContext *ctx) +bool8 ScrCmd_warpsilent(struct ScriptContext *ctx) { - u8 v1 = ScriptReadByte(ctx); - u8 v2 = ScriptReadByte(ctx); - u8 v3 = ScriptReadByte(ctx); - u16 v4 = VarGet(ScriptReadHalfword(ctx)); - s8 v5 = VarGet(ScriptReadHalfword(ctx)); - warp1_set(v1, v2, v3, v4, v5); + u8 mapGroup = ScriptReadByte(ctx); + u8 mapNum = ScriptReadByte(ctx); + u8 warpId = ScriptReadByte(ctx); + u16 x = VarGet(ScriptReadHalfword(ctx)); + u16 y = VarGet(ScriptReadHalfword(ctx)); + + Overworld_SetWarpDestination(mapGroup, mapNum, warpId, x, y); sp13E_warp_to_last_warp(); player_avatar_init_params_reset(); return TRUE; } -bool8 ScrCmd_warpwalk(struct ScriptContext *ctx) +bool8 ScrCmd_warpdoor(struct ScriptContext *ctx) { - u8 v1 = ScriptReadByte(ctx); - u8 v2 = ScriptReadByte(ctx); - u8 v3 = ScriptReadByte(ctx); - u16 v4 = VarGet(ScriptReadHalfword(ctx)); - s8 v5 = VarGet(ScriptReadHalfword(ctx)); - warp1_set(v1, v2, v3, v4, v5); + u8 mapGroup = ScriptReadByte(ctx); + u8 mapNum = ScriptReadByte(ctx); + u8 warpId = ScriptReadByte(ctx); + u16 x = VarGet(ScriptReadHalfword(ctx)); + u16 y = VarGet(ScriptReadHalfword(ctx)); + + Overworld_SetWarpDestination(mapGroup, mapNum, warpId, x, y); sub_8080EF0(); player_avatar_init_params_reset(); return TRUE; @@ -709,18 +760,16 @@ bool8 ScrCmd_warpwalk(struct ScriptContext *ctx) bool8 ScrCmd_warphole(struct ScriptContext *ctx) { - u8 v1 = ScriptReadByte(ctx); - u8 v2 = ScriptReadByte(ctx); + u8 mapGroup = ScriptReadByte(ctx); + u8 mapNum = ScriptReadByte(ctx); u16 x; u16 y; PlayerGetDestCoords(&x, &y); - - if (v1 == 0xFF && v2 == 0xFF) + if (mapGroup == 0xFF && mapNum == 0xFF) sub_8053720(x - 7, y - 7); else - warp1_set(v1, v2, -1, x - 7, y - 7); - + Overworld_SetWarpDestination(mapGroup, mapNum, -1, x - 7, y - 7); sp13F_fall_to_last_warp(); player_avatar_init_params_reset(); return TRUE; @@ -728,78 +777,85 @@ bool8 ScrCmd_warphole(struct ScriptContext *ctx) bool8 ScrCmd_warpteleport(struct ScriptContext *ctx) { - u8 v1 = ScriptReadByte(ctx); - u8 v2 = ScriptReadByte(ctx); - u8 v3 = ScriptReadByte(ctx); - u16 v4 = VarGet(ScriptReadHalfword(ctx)); - s8 v5 = VarGet(ScriptReadHalfword(ctx)); - warp1_set(v1, v2, v3, v4, v5); + u8 mapGroup = ScriptReadByte(ctx); + u8 mapNum = ScriptReadByte(ctx); + u8 warpId = ScriptReadByte(ctx); + u16 x = VarGet(ScriptReadHalfword(ctx)); + u16 y = VarGet(ScriptReadHalfword(ctx)); + + Overworld_SetWarpDestination(mapGroup, mapNum, warpId, x, y); sub_8080F68(); player_avatar_init_params_reset(); return TRUE; } -bool8 ScrCmd_warp3(struct ScriptContext *ctx) +bool8 ScrCmd_setwarp(struct ScriptContext *ctx) { - u8 v1 = ScriptReadByte(ctx); - u8 v2 = ScriptReadByte(ctx); - u8 v3 = ScriptReadByte(ctx); - u16 v4 = VarGet(ScriptReadHalfword(ctx)); - s8 v5 = VarGet(ScriptReadHalfword(ctx)); - warp1_set(v1, v2, v3, v4, v5); + u8 mapGroup = ScriptReadByte(ctx); + u8 mapNum = ScriptReadByte(ctx); + u8 warpId = ScriptReadByte(ctx); + u16 x = VarGet(ScriptReadHalfword(ctx)); + u16 y = VarGet(ScriptReadHalfword(ctx)); + + Overworld_SetWarpDestination(mapGroup, mapNum, warpId, x, y); return FALSE; } -bool8 ScrCmd_warpplace(struct ScriptContext *ctx) +bool8 ScrCmd_setdynamicwarp(struct ScriptContext *ctx) { - u8 v1 = ScriptReadByte(ctx); - u8 v2 = ScriptReadByte(ctx); - u8 v3 = ScriptReadByte(ctx); - u16 v4 = VarGet(ScriptReadHalfword(ctx)); - s8 v5 = VarGet(ScriptReadHalfword(ctx)); - saved_warp2_set_2(0, v1, v2, v3, v4, v5); + u8 mapGroup = ScriptReadByte(ctx); + u8 mapNum = ScriptReadByte(ctx); + u8 warpId = ScriptReadByte(ctx); + u16 x = VarGet(ScriptReadHalfword(ctx)); + u16 y = VarGet(ScriptReadHalfword(ctx)); + + saved_warp2_set_2(0, mapGroup, mapNum, warpId, x, y); return FALSE; } -bool8 ScrCmd_warp4(struct ScriptContext *ctx) +bool8 ScrCmd_setdivewarp(struct ScriptContext *ctx) { - u8 v1 = ScriptReadByte(ctx); - u8 v2 = ScriptReadByte(ctx); - u8 v3 = ScriptReadByte(ctx); - u16 v4 = VarGet(ScriptReadHalfword(ctx)); - s8 v5 = VarGet(ScriptReadHalfword(ctx)); - sub_8053690(v1, v2, v3, v4, v5); + u8 mapGroup = ScriptReadByte(ctx); + u8 mapNum = ScriptReadByte(ctx); + u8 warpId = ScriptReadByte(ctx); + u16 x = VarGet(ScriptReadHalfword(ctx)); + u16 y = VarGet(ScriptReadHalfword(ctx)); + + sub_8053690(mapGroup, mapNum, warpId, x, y); return FALSE; } -bool8 ScrCmd_warp5(struct ScriptContext *ctx) +bool8 ScrCmd_setholewarp(struct ScriptContext *ctx) { - u8 v1 = ScriptReadByte(ctx); - u8 v2 = ScriptReadByte(ctx); - u8 v3 = ScriptReadByte(ctx); - u16 v4 = VarGet(ScriptReadHalfword(ctx)); - s8 v5 = VarGet(ScriptReadHalfword(ctx)); - sub_80536E4(v1, v2, v3, v4, v5); + u8 mapGroup = ScriptReadByte(ctx); + u8 mapNum = ScriptReadByte(ctx); + u8 warpId = ScriptReadByte(ctx); + u16 x = VarGet(ScriptReadHalfword(ctx)); + u16 y = VarGet(ScriptReadHalfword(ctx)); + + sub_80536E4(mapGroup, mapNum, warpId, x, y); return FALSE; } -bool8 ScrCmd_warp6(struct ScriptContext *ctx) +bool8 ScrCmd_setescapewarp(struct ScriptContext *ctx) { - u8 v1 = ScriptReadByte(ctx); - u8 v2 = ScriptReadByte(ctx); - u8 v3 = ScriptReadByte(ctx); - u16 v4 = VarGet(ScriptReadHalfword(ctx)); - s8 v5 = VarGet(ScriptReadHalfword(ctx)); - sub_805363C(v1, v2, v3, v4, v5); + u8 mapGroup = ScriptReadByte(ctx); + u8 mapNum = ScriptReadByte(ctx); + u8 warpId = ScriptReadByte(ctx); + u16 x = VarGet(ScriptReadHalfword(ctx)); + u16 y = VarGet(ScriptReadHalfword(ctx)); + + sub_805363C(mapGroup, mapNum, warpId, x, y); return FALSE; } bool8 ScrCmd_getplayerxy(struct ScriptContext *ctx) { - u16 *ptr1 = GetVarPointer(ScriptReadHalfword(ctx)); - u16 *ptr2 = GetVarPointer(ScriptReadHalfword(ctx)); - *ptr1 = gSaveBlock1.pos.x; - *ptr2 = gSaveBlock1.pos.y; + u16 *pX = GetVarPointer(ScriptReadHalfword(ctx)); + u16 *pY = GetVarPointer(ScriptReadHalfword(ctx)); + + *pX = gSaveBlock1.pos.x; + *pY = gSaveBlock1.pos.y; return FALSE; } @@ -809,7 +865,7 @@ bool8 ScrCmd_countpokemon(struct ScriptContext *ctx) return FALSE; } -bool8 ScrCmd_playsfx(struct ScriptContext *ctx) +bool8 ScrCmd_playse(struct ScriptContext *ctx) { PlaySE(ScriptReadHalfword(ctx)); return FALSE; @@ -823,13 +879,13 @@ static bool8 WaitForSoundEffectFinish() return FALSE; } -bool8 ScrCmd_checksound(struct ScriptContext *ctx) +bool8 ScrCmd_waitse(struct ScriptContext *ctx) { SetupNativeScript(ctx, WaitForSoundEffectFinish); return TRUE; } -bool8 ScrCmd_fanfare(struct ScriptContext *ctx) +bool8 ScrCmd_playfanfare(struct ScriptContext *ctx) { PlayFanfare(ScriptReadHalfword(ctx)); return FALSE; @@ -846,37 +902,39 @@ bool8 ScrCmd_waitfanfare(struct ScriptContext *ctx) return TRUE; } -bool8 ScrCmd_playmusic(struct ScriptContext *ctx) +bool8 ScrCmd_playbgm(struct ScriptContext *ctx) { u16 songId = ScriptReadHalfword(ctx); bool8 val = ScriptReadByte(ctx); + if (val == TRUE) - sav1_set_battle_music_maybe(songId); + Overworld_SetSavedMusic(songId); PlayNewMapMusic(songId); return FALSE; } -bool8 ScrCmd_playmusicbattle(struct ScriptContext *ctx) +bool8 ScrCmd_savebgm(struct ScriptContext *ctx) { - sav1_set_battle_music_maybe(ScriptReadHalfword(ctx)); + Overworld_SetSavedMusic(ScriptReadHalfword(ctx)); return FALSE; } -bool8 ScrCmd_fadedefault(struct ScriptContext *ctx) +bool8 ScrCmd_fadedefaultbgm(struct ScriptContext *ctx) { - sub_8053F84(); + Overworld_ChangeMusicToDefault(); return FALSE; } -bool8 ScrCmd_fademusic(struct ScriptContext *ctx) +bool8 ScrCmd_fadenewbgm(struct ScriptContext *ctx) { Overworld_ChangeMusicTo(ScriptReadHalfword(ctx)); return FALSE; } -bool8 ScrCmd_fadeout(struct ScriptContext *ctx) +bool8 ScrCmd_fadeoutbgm(struct ScriptContext *ctx) { u8 speed = ScriptReadByte(ctx); + if (speed != 0) FadeOutBGMTemporarily(4 * speed); else @@ -885,9 +943,10 @@ bool8 ScrCmd_fadeout(struct ScriptContext *ctx) return TRUE; } -bool8 ScrCmd_fadein(struct ScriptContext *ctx) +bool8 ScrCmd_fadeinbgm(struct ScriptContext *ctx) { u8 speed = ScriptReadByte(ctx); + if (speed != 0) FadeInBGM(4 * speed); else @@ -895,7 +954,7 @@ bool8 ScrCmd_fadein(struct ScriptContext *ctx) return FALSE; } -bool8 ScrCmd_move(struct ScriptContext *ctx) +bool8 ScrCmd_applymovement(struct ScriptContext *ctx) { u16 localId = VarGet(ScriptReadHalfword(ctx)); void *movementScript = (void *)ScriptReadWord(ctx); @@ -905,7 +964,7 @@ bool8 ScrCmd_move(struct ScriptContext *ctx) return FALSE; } -bool8 ScrCmd_movecoords(struct ScriptContext *ctx) +bool8 ScrCmd_applymovement_at(struct ScriptContext *ctx) { u16 localId = VarGet(ScriptReadHalfword(ctx)); void *movementScript = (void *)ScriptReadWord(ctx); @@ -922,7 +981,7 @@ static bool8 WaitForMovementFinish(void) return ScriptMovement_IsObjectMovementFinished(sMovingNpcId, sMovingNpcMapId, sMovingNpcMapBank); } -bool8 ScrCmd_waitmove(struct ScriptContext *ctx) +bool8 ScrCmd_waitmovement(struct ScriptContext *ctx) { u16 localId = VarGet(ScriptReadHalfword(ctx)); @@ -934,7 +993,7 @@ bool8 ScrCmd_waitmove(struct ScriptContext *ctx) return TRUE; } -bool8 ScrCmd_waitmovexy(struct ScriptContext *ctx) +bool8 ScrCmd_waitmovement_at(struct ScriptContext *ctx) { u16 localId = VarGet(ScriptReadHalfword(ctx)); u8 mapBank; @@ -950,97 +1009,108 @@ bool8 ScrCmd_waitmovexy(struct ScriptContext *ctx) return TRUE; } -bool8 ScrCmd_disappear(struct ScriptContext *ctx) +bool8 ScrCmd_removeobject(struct ScriptContext *ctx) { - u16 objectId = VarGet(ScriptReadHalfword(ctx)); - RemoveFieldObjectByLocalIdAndMap(objectId, gSaveBlock1.location.mapNum, gSaveBlock1.location.mapGroup); + u16 localId = VarGet(ScriptReadHalfword(ctx)); + + RemoveFieldObjectByLocalIdAndMap(localId, gSaveBlock1.location.mapNum, gSaveBlock1.location.mapGroup); return FALSE; } -bool8 ScrCmd_disappearxy(struct ScriptContext *ctx) +bool8 ScrCmd_removeobject_at(struct ScriptContext *ctx) { u16 objectId = VarGet(ScriptReadHalfword(ctx)); u8 mapGroup = ScriptReadByte(ctx); u8 mapNum = ScriptReadByte(ctx); + RemoveFieldObjectByLocalIdAndMap(objectId, mapNum, mapGroup); return FALSE; } -bool8 ScrCmd_reappear(struct ScriptContext *ctx) +bool8 ScrCmd_addobject(struct ScriptContext *ctx) { u16 objectId = VarGet(ScriptReadHalfword(ctx)); + show_sprite(objectId, gSaveBlock1.location.mapNum, gSaveBlock1.location.mapGroup); return FALSE; } -bool8 ScrCmd_reappearxy(struct ScriptContext *ctx) +bool8 ScrCmd_addobject_at(struct ScriptContext *ctx) { u16 objectId = VarGet(ScriptReadHalfword(ctx)); u8 mapGroup = ScriptReadByte(ctx); u8 mapNum = ScriptReadByte(ctx); + show_sprite(objectId, mapNum, mapGroup); return FALSE; } -bool8 ScrCmd_movesprite(struct ScriptContext *ctx) +bool8 ScrCmd_setobjectxy(struct ScriptContext *ctx) { - u16 v1 = VarGet(ScriptReadHalfword(ctx)); - u16 v2 = VarGet(ScriptReadHalfword(ctx)); - u32 v3 = VarGet(ScriptReadHalfword(ctx)); - sub_805C0F8(v1, gSaveBlock1.location.mapNum, gSaveBlock1.location.mapGroup, v2, v3); + u16 localId = VarGet(ScriptReadHalfword(ctx)); + u16 x = VarGet(ScriptReadHalfword(ctx)); + u16 y = VarGet(ScriptReadHalfword(ctx)); + + sub_805C0F8(localId, gSaveBlock1.location.mapNum, gSaveBlock1.location.mapGroup, x, y); return FALSE; } -bool8 ScrCmd_movespriteperm(struct ScriptContext *ctx) +bool8 ScrCmd_setobjectxyperm(struct ScriptContext *ctx) { - u16 v1 = VarGet(ScriptReadHalfword(ctx)); - u16 v2 = VarGet(ScriptReadHalfword(ctx)); - u32 v3 = VarGet(ScriptReadHalfword(ctx)); - Overworld_SaveMapObjCoords(v1, v2, v3); + u16 localId = VarGet(ScriptReadHalfword(ctx)); + u16 x = VarGet(ScriptReadHalfword(ctx)); + u16 y = VarGet(ScriptReadHalfword(ctx)); + + Overworld_SetMapObjTemplateCoords(localId, x, y); return FALSE; } -bool8 ScrCmd_moveoffscreen(struct ScriptContext *ctx) +bool8 ScrCmd_moveobjectoffscreen(struct ScriptContext *ctx) { - u16 v1 = VarGet(ScriptReadHalfword(ctx)); - sub_805C78C(v1, gSaveBlock1.location.mapNum, gSaveBlock1.location.mapGroup); + u16 localId = VarGet(ScriptReadHalfword(ctx)); + + sub_805C78C(localId, gSaveBlock1.location.mapNum, gSaveBlock1.location.mapGroup); return FALSE; } -bool8 ScrCmd_spritevisible(struct ScriptContext *ctx) +bool8 ScrCmd_showobject(struct ScriptContext *ctx) { - u16 v1 = VarGet(ScriptReadHalfword(ctx)); - u8 v2 = ScriptReadByte(ctx); - u8 v3 = ScriptReadByte(ctx); - npc_by_local_id_and_map_set_field_1_bit_x20(v1, v3, v2, 0); + u16 localId = VarGet(ScriptReadHalfword(ctx)); + u8 mapGroup = ScriptReadByte(ctx); + u8 mapNum = ScriptReadByte(ctx); + + npc_by_local_id_and_map_set_field_1_bit_x20(localId, mapNum, mapGroup, 0); return FALSE; } -bool8 ScrCmd_spriteinvisible(struct ScriptContext *ctx) +bool8 ScrCmd_hideobject(struct ScriptContext *ctx) { - u16 v1 = VarGet(ScriptReadHalfword(ctx)); - u8 v2 = ScriptReadByte(ctx); - u8 v3 = ScriptReadByte(ctx); - npc_by_local_id_and_map_set_field_1_bit_x20(v1, v3, v2, 1); + u16 localId = VarGet(ScriptReadHalfword(ctx)); + u8 mapGroup = ScriptReadByte(ctx); + u8 mapNum = ScriptReadByte(ctx); + + npc_by_local_id_and_map_set_field_1_bit_x20(localId, mapNum, mapGroup, 1); return FALSE; } -bool8 ScrCmd_spritelevelup(struct ScriptContext *ctx) +bool8 ScrCmd_setobjectpriority(struct ScriptContext *ctx) { - u16 v1 = VarGet(ScriptReadHalfword(ctx)); - u8 v2 = ScriptReadByte(ctx); - u8 v3 = ScriptReadByte(ctx); - u8 v4 = ScriptReadByte(ctx); - sub_805BCF0(v1, v3, v2, v4 + 83); + u16 localId = VarGet(ScriptReadHalfword(ctx)); + u8 mapGroup = ScriptReadByte(ctx); + u8 mapNum = ScriptReadByte(ctx); + u8 priority = ScriptReadByte(ctx); + + sub_805BCF0(localId, mapNum, mapGroup, priority + 83); return FALSE; } -bool8 ScrCmd_restorespritelevel(struct ScriptContext *ctx) +bool8 ScrCmd_resetobjectpriority(struct ScriptContext *ctx) { - u16 v1 = VarGet(ScriptReadHalfword(ctx)); - u8 v2 = ScriptReadByte(ctx); - u8 v3 = ScriptReadByte(ctx); - sub_805BD48(v1, v3, v2); + u16 localId = VarGet(ScriptReadHalfword(ctx)); + u8 mapGroup = ScriptReadByte(ctx); + u8 mapNum = ScriptReadByte(ctx); + + sub_805BD48(localId, mapNum, mapGroup); return FALSE; } @@ -1054,39 +1124,43 @@ bool8 ScrCmd_faceplayer(struct ScriptContext *ctx) return FALSE; } -bool8 ScrCmd_spriteface(struct ScriptContext *ctx) +bool8 ScrCmd_turnobject(struct ScriptContext *ctx) { u16 localId = VarGet(ScriptReadHalfword(ctx)); u8 direction = ScriptReadByte(ctx); + FieldObjectTurnByLocalIdAndMap(localId, gSaveBlock1.location.mapNum, gSaveBlock1.location.mapGroup, direction); return FALSE; } -bool8 ScrCmd_spritebehave(struct ScriptContext *ctx) +bool8 ScrCmd_setobjectmovementtype(struct ScriptContext *ctx) { - u16 v1 = VarGet(ScriptReadHalfword(ctx)); - u8 v2 = ScriptReadByte(ctx); - Overworld_SaveMapObjMovementType(v1, v2); + u16 localId = VarGet(ScriptReadHalfword(ctx)); + u8 movementType = ScriptReadByte(ctx); + + Overworld_SetMapObjTemplateMovementType(localId, movementType); return FALSE; } -bool8 ScrCmd_createvsprite(struct ScriptContext *ctx) +bool8 ScrCmd_createvobject(struct ScriptContext *ctx) { - u8 v1 = ScriptReadByte(ctx); + u8 graphicsId = ScriptReadByte(ctx); u8 v2 = ScriptReadByte(ctx); - u16 v3 = VarGet(ScriptReadHalfword(ctx)); - u32 v4 = VarGet(ScriptReadHalfword(ctx)); - u8 v5 = ScriptReadByte(ctx); - u8 v6 = ScriptReadByte(ctx); - sub_805B410(v1, v2, v3, v4, v5, v6); + u16 x = VarGet(ScriptReadHalfword(ctx)); + u32 y = VarGet(ScriptReadHalfword(ctx)); + u8 elevation = ScriptReadByte(ctx); + u8 direction = ScriptReadByte(ctx); + + sub_805B410(graphicsId, v2, x, y, elevation, direction); return FALSE; } -bool8 ScrCmd_vspriteface(struct ScriptContext *ctx) +bool8 ScrCmd_turnvobject(struct ScriptContext *ctx) { u8 v1 = ScriptReadByte(ctx); - u8 v2 = ScriptReadByte(ctx); - sub_8064990(v1, v2); + u8 direction = ScriptReadByte(ctx); + + sub_8064990(v1, direction); return FALSE; } @@ -1122,7 +1196,6 @@ bool8 ScrCmd_lock(struct ScriptContext *ctx) ScriptFreezeMapObjects(); SetupNativeScript(ctx, sub_8064CFC); } - return TRUE; } } @@ -1156,34 +1229,36 @@ bool8 ScrCmd_release(struct ScriptContext *ctx) bool8 ScrCmd_message(struct ScriptContext *ctx) { u8 *msg = (u8 *)ScriptReadWord(ctx); - if (!msg) + + if (msg == NULL) msg = (u8 *)ctx->data[0]; ShowFieldMessage(msg); return FALSE; } -bool8 ScrCmd_message2(struct ScriptContext *ctx) +bool8 ScrCmd_messageautoscroll(struct ScriptContext *ctx) { u8 *msg = (u8 *)ScriptReadWord(ctx); - if (!msg) + + if (msg == NULL) msg = (u8 *)ctx->data[0]; ShowFieldAutoScrollMessage(msg); return FALSE; } -bool8 ScrCmd_waittext(struct ScriptContext *ctx) +bool8 ScrCmd_waitmessage(struct ScriptContext *ctx) { SetupNativeScript(ctx, IsFieldMessageBoxHidden); return TRUE; } -bool8 ScrCmd_closebutton(struct ScriptContext *ctx) +bool8 ScrCmd_closemessage(struct ScriptContext *ctx) { HideFieldMessageBox(); return FALSE; } -bool8 WaitForAorBPress(void) +static bool8 WaitForAorBPress(void) { if (gMain.newKeys & A_BUTTON) return TRUE; @@ -1202,6 +1277,7 @@ bool8 ScrCmd_yesnobox(struct ScriptContext *ctx) { u8 left = ScriptReadByte(ctx); u8 top = ScriptReadByte(ctx); + if (ScriptMenu_YesNo(left, top) == TRUE) { ScriptContext1_Stop(); @@ -1219,6 +1295,7 @@ bool8 ScrCmd_multichoice(struct ScriptContext *ctx) u8 top = ScriptReadByte(ctx); u8 multichoiceId = ScriptReadByte(ctx); u8 ignoreBPress = ScriptReadByte(ctx); + if (ScriptMenu_Multichoice(left, top, multichoiceId, ignoreBPress) == TRUE) { ScriptContext1_Stop(); @@ -1230,13 +1307,14 @@ bool8 ScrCmd_multichoice(struct ScriptContext *ctx) } } -bool8 ScrCmd_multichoicedef(struct ScriptContext *ctx) +bool8 ScrCmd_multichoicedefault(struct ScriptContext *ctx) { u8 left = ScriptReadByte(ctx); u8 top = ScriptReadByte(ctx); u8 multichoiceId = ScriptReadByte(ctx); u8 defaultChoice = ScriptReadByte(ctx); u8 ignoreBPress = ScriptReadByte(ctx); + if (ScriptMenu_MultichoiceWithDefault(left, top, multichoiceId, ignoreBPress, defaultChoice) == TRUE) { ScriptContext1_Stop(); @@ -1248,23 +1326,25 @@ bool8 ScrCmd_multichoicedef(struct ScriptContext *ctx) } } -bool8 ScrCmd_showbox(struct ScriptContext *ctx) +bool8 ScrCmd_drawbox(struct ScriptContext *ctx) { u8 left = ScriptReadByte(ctx); u8 top = ScriptReadByte(ctx); u8 right = ScriptReadByte(ctx); u8 bottom = ScriptReadByte(ctx); + MenuDrawTextWindow(left, top, right, bottom); return FALSE; } -bool8 ScrCmd_multichoicerow(struct ScriptContext *ctx) +bool8 ScrCmd_multichoicegrid(struct ScriptContext *ctx) { u8 left = ScriptReadByte(ctx); u8 top = ScriptReadByte(ctx); u8 multichoiceId = ScriptReadByte(ctx); u8 numColumns = ScriptReadByte(ctx); u8 ignoreBPress = ScriptReadByte(ctx); + if (ScriptMenu_MultichoiceGrid(left, top, multichoiceId, ignoreBPress, numColumns) == TRUE) { ScriptContext1_Stop(); @@ -1276,23 +1356,25 @@ bool8 ScrCmd_multichoicerow(struct ScriptContext *ctx) } } -bool8 ScrCmd_hidebox(struct ScriptContext *ctx) +bool8 ScrCmd_erasebox(struct ScriptContext *ctx) { u8 left = ScriptReadByte(ctx); u8 top = ScriptReadByte(ctx); u8 right = ScriptReadByte(ctx); u8 bottom = ScriptReadByte(ctx); + MenuZeroFillWindowRect(left, top, right, bottom); return FALSE; } // unused -bool8 ScrCmd_clearbox(struct ScriptContext *ctx) +bool8 ScrCmd_drawboxtext(struct ScriptContext *ctx) { u8 left = ScriptReadByte(ctx); u8 top = ScriptReadByte(ctx); u8 multichoiceId = ScriptReadByte(ctx); u8 ignoreBPress = ScriptReadByte(ctx); + if (Multichoice(left, top, multichoiceId, ignoreBPress) == TRUE) { ScriptContext1_Stop(); @@ -1304,16 +1386,17 @@ bool8 ScrCmd_clearbox(struct ScriptContext *ctx) } } -bool8 ScrCmd_showpokepic(struct ScriptContext *ctx) +bool8 ScrCmd_drawpokepic(struct ScriptContext *ctx) { u16 species = VarGet(ScriptReadHalfword(ctx)); u8 x = ScriptReadByte(ctx); u8 y = ScriptReadByte(ctx); + ScriptMenu_ShowPokemonPic(species, x, y); return FALSE; } -bool8 ScrCmd_hidepokepic(struct ScriptContext *ctx) +bool8 ScrCmd_erasepokepic(struct ScriptContext *ctx) { bool8 (*func)(void) = ScriptMenu_GetPicboxWaitFunc(); @@ -1323,9 +1406,10 @@ bool8 ScrCmd_hidepokepic(struct ScriptContext *ctx) return TRUE; } -bool8 ScrCmd_showcontestwinner(struct ScriptContext *ctx) +bool8 ScrCmd_drawcontestwinner(struct ScriptContext *ctx) { u8 v1 = ScriptReadByte(ctx); + if (v1) sub_8106630(v1); ShowContestWinner(); @@ -1333,9 +1417,10 @@ bool8 ScrCmd_showcontestwinner(struct ScriptContext *ctx) return TRUE; } -bool8 ScrCmd_braillemsg(struct ScriptContext *ctx) +bool8 ScrCmd_braillemessage(struct ScriptContext *ctx) { u8 *ptr = (u8 *)ScriptReadWord(ctx); + u8 v2 = ptr[0]; u8 v3 = ptr[1]; u8 v4 = ptr[2]; @@ -1348,24 +1433,27 @@ bool8 ScrCmd_braillemsg(struct ScriptContext *ctx) return FALSE; } -bool8 ScrCmd_vtext(struct ScriptContext *ctx) +bool8 ScrCmd_vmessage(struct ScriptContext *ctx) { u32 v1 = ScriptReadWord(ctx); + ShowFieldMessage((u8 *)(v1 - gUnknown_0202E8B0)); return FALSE; } -bool8 ScrCmd_bufferpoke(struct ScriptContext *ctx) +bool8 ScrCmd_getspeciesname(struct ScriptContext *ctx) { u8 stringVarIndex = ScriptReadByte(ctx); u16 species = VarGet(ScriptReadHalfword(ctx)); + StringCopy(sScriptStringVars[stringVarIndex], gSpeciesNames[species]); return FALSE; } -bool8 ScrCmd_bufferfirstpoke(struct ScriptContext *ctx) +bool8 ScrCmd_getfirstpartypokename(struct ScriptContext *ctx) { u8 stringVarIndex = ScriptReadByte(ctx); + u8 *dest = sScriptStringVars[stringVarIndex]; u8 partyIndex = GetLeadMonIndex(); u32 species = GetMonData(&gPlayerParty[partyIndex], MON_DATA_SPECIES, NULL); @@ -1373,82 +1461,91 @@ bool8 ScrCmd_bufferfirstpoke(struct ScriptContext *ctx) return FALSE; } -bool8 ScrCmd_bufferpartypoke(struct ScriptContext *ctx) +bool8 ScrCmd_getpartypokename(struct ScriptContext *ctx) { u8 stringVarIndex = ScriptReadByte(ctx); u16 partyIndex = VarGet(ScriptReadHalfword(ctx)); + GetMonData(&gPlayerParty[partyIndex], MON_DATA_NICKNAME, sScriptStringVars[stringVarIndex]); StringGetEnd10(sScriptStringVars[stringVarIndex]); return FALSE; } -bool8 ScrCmd_bufferitem(struct ScriptContext *ctx) +bool8 ScrCmd_getitemname(struct ScriptContext *ctx) { u8 stringVarIndex = ScriptReadByte(ctx); u16 itemId = VarGet(ScriptReadHalfword(ctx)); + CopyItemName(itemId, sScriptStringVars[stringVarIndex]); return FALSE; } -bool8 ScrCmd_bufferdecor(struct ScriptContext *ctx) +bool8 ScrCmd_getdecorname(struct ScriptContext *ctx) { u8 stringVarIndex = ScriptReadByte(ctx); u16 decorId = VarGet(ScriptReadHalfword(ctx)); + StringCopy(sScriptStringVars[stringVarIndex], gDecorations[decorId].name); return FALSE; } -bool8 ScrCmd_bufferattack(struct ScriptContext *ctx) +bool8 ScrCmd_getmovename(struct ScriptContext *ctx) { u8 stringVarIndex = ScriptReadByte(ctx); u16 moveId = VarGet(ScriptReadHalfword(ctx)); + StringCopy(sScriptStringVars[stringVarIndex], gMoveNames[moveId]); return FALSE; } -bool8 ScrCmd_buffernum(struct ScriptContext *ctx) +bool8 ScrCmd_getnumberstring(struct ScriptContext *ctx) { u8 stringVarIndex = ScriptReadByte(ctx); u16 v1 = VarGet(ScriptReadHalfword(ctx)); u8 v2 = sub_80BF0B8(v1); + ConvertIntToDecimalStringN(sScriptStringVars[stringVarIndex], v1, 0, v2); return FALSE; } -bool8 ScrCmd_bufferstd(struct ScriptContext *ctx) +bool8 ScrCmd_getstdstring(struct ScriptContext *ctx) { u8 stringVarIndex = ScriptReadByte(ctx); u16 index = VarGet(ScriptReadHalfword(ctx)); + StringCopy(sScriptStringVars[stringVarIndex], gUnknown_083CE048[index]); return FALSE; } -bool8 ScrCmd_buffertext(struct ScriptContext *ctx) +bool8 ScrCmd_getstring(struct ScriptContext *ctx) { u8 stringVarIndex = ScriptReadByte(ctx); u8 *text = (u8 *)ScriptReadWord(ctx); + StringCopy(sScriptStringVars[stringVarIndex], text); return FALSE; } -bool8 ScrCmd_vloadptr(struct ScriptContext *ctx) +bool8 ScrCmd_vloadword(struct ScriptContext *ctx) { u8 *ptr = (u8 *)(ScriptReadWord(ctx) - gUnknown_0202E8B0); + StringExpandPlaceholders(gStringVar4, ptr); return FALSE; } -bool8 ScrCmd_vbuffer(struct ScriptContext *ctx) +bool8 ScrCmd_vgetstring(struct ScriptContext *ctx) { u8 stringVarIndex = ScriptReadByte(ctx); u32 addr = ScriptReadWord(ctx); + u8 *src = (u8 *)(addr - gUnknown_0202E8B0); u8 *dest = sScriptStringVars[stringVarIndex]; StringCopy(dest, src); return FALSE; } -bool8 ScrCmd_givepokemon(struct ScriptContext *ctx) +bool8 ScrCmd_givepoke(struct ScriptContext *ctx) { u16 species = VarGet(ScriptReadHalfword(ctx)); u8 level = ScriptReadByte(ctx); @@ -1456,6 +1553,7 @@ bool8 ScrCmd_givepokemon(struct ScriptContext *ctx) u32 unkParam1 = ScriptReadWord(ctx); u32 unkParam2 = ScriptReadWord(ctx); u8 unkParam3 = ScriptReadByte(ctx); + gScriptResult = ScriptGiveMon(species, level, item, unkParam1, unkParam2, unkParam3); return FALSE; } @@ -1463,6 +1561,7 @@ bool8 ScrCmd_givepokemon(struct ScriptContext *ctx) bool8 ScrCmd_giveegg(struct ScriptContext *ctx) { u16 species = VarGet(ScriptReadHalfword(ctx)); + gScriptResult = ScriptGiveEgg(species); return FALSE; } @@ -1472,14 +1571,16 @@ bool8 ScrCmd_setpokemove(struct ScriptContext *ctx) u8 partyIndex = ScriptReadByte(ctx); u8 slot = ScriptReadByte(ctx); u16 move = ScriptReadHalfword(ctx); + ScriptSetMonMoveSlot(partyIndex, move, slot); return FALSE; } -bool8 ScrCmd_checkattack(struct ScriptContext *ctx) +bool8 ScrCmd_checkpokemove(struct ScriptContext *ctx) { u8 i; u16 moveId = ScriptReadHalfword(ctx); + gScriptResult = 6; for (i = 0; i < 6; i++) { @@ -1501,15 +1602,17 @@ bool8 ScrCmd_givemoney(struct ScriptContext *ctx) { u32 amount = ScriptReadWord(ctx); u8 ignore = ScriptReadByte(ctx); + if (!ignore) AddMoney(&gSaveBlock1.money, amount); return FALSE; } -bool8 ScrCmd_paymoney(struct ScriptContext *ctx) +bool8 ScrCmd_takemoney(struct ScriptContext *ctx) { u32 amount = ScriptReadWord(ctx); u8 ignore = ScriptReadByte(ctx); + if (!ignore) RemoveMoney(&gSaveBlock1.money, amount); return FALSE; @@ -1519,60 +1622,67 @@ bool8 ScrCmd_checkmoney(struct ScriptContext *ctx) { u32 amount = ScriptReadWord(ctx); u8 ignore = ScriptReadByte(ctx); + if (!ignore) gScriptResult = IsEnoughMoney(gSaveBlock1.money, amount); return FALSE; } -bool8 ScrCmd_showmoney(struct ScriptContext *ctx) +bool8 ScrCmd_showmoneybox(struct ScriptContext *ctx) { u8 x = ScriptReadByte(ctx); u8 y = ScriptReadByte(ctx); u8 ignore = ScriptReadByte(ctx); + if (!ignore) OpenMoneyWindow(gSaveBlock1.money, x, y); return FALSE; } -bool8 ScrCmd_hidemoney(struct ScriptContext *ctx) +bool8 ScrCmd_hidemoneybox(struct ScriptContext *ctx) { u8 x = ScriptReadByte(ctx); u8 y = ScriptReadByte(ctx); + CloseMoneyWindow(x, y); return FALSE; } -bool8 ScrCmd_updatemoney(struct ScriptContext *ctx) +bool8 ScrCmd_updatemoneybox(struct ScriptContext *ctx) { - u8 v2 = ScriptReadByte(ctx); - u8 v3 = ScriptReadByte(ctx); + u8 x = ScriptReadByte(ctx); + u8 y = ScriptReadByte(ctx); u8 ignore = ScriptReadByte(ctx); + if (!ignore) - UpdateMoneyWindow(gSaveBlock1.money, v2, v3); + UpdateMoneyWindow(gSaveBlock1.money, x, y); return FALSE; } -bool8 ScrCmd_showcoins(struct ScriptContext *ctx) +bool8 ScrCmd_showcoinsbox(struct ScriptContext *ctx) { - u8 v2 = ScriptReadByte(ctx); - u8 v3 = ScriptReadByte(ctx); - ShowCoinsWindow(gSaveBlock1.coins, v2, v3); + u8 x = ScriptReadByte(ctx); + u8 y = ScriptReadByte(ctx); + + ShowCoinsWindow(gSaveBlock1.coins, x, y); return FALSE; } -bool8 ScrCmd_hidecoins(struct ScriptContext *ctx) +bool8 ScrCmd_hidecoinsbox(struct ScriptContext *ctx) { - u8 v2 = ScriptReadByte(ctx); - u8 v3 = ScriptReadByte(ctx); - HideCoinsWindow(v2, v3); + u8 x = ScriptReadByte(ctx); + u8 y = ScriptReadByte(ctx); + + HideCoinsWindow(x, y); return FALSE; } -bool8 ScrCmd_updatecoins(struct ScriptContext *ctx) +bool8 ScrCmd_updatecoinsbox(struct ScriptContext *ctx) { - u8 v2 = ScriptReadByte(ctx); - u8 v3 = ScriptReadByte(ctx); - UpdateCoinsWindow(gSaveBlock1.coins, v2, v3); + u8 x = ScriptReadByte(ctx); + u8 y = ScriptReadByte(ctx); + + UpdateCoinsWindow(gSaveBlock1.coins, x, y); return FALSE; } @@ -1582,19 +1692,19 @@ bool8 ScrCmd_trainerbattle(struct ScriptContext *ctx) return FALSE; } -bool8 ScrCmd_reptrainerbattle(struct ScriptContext *ctx) +bool8 ScrCmd_battlebegin(struct ScriptContext *ctx) { BattleSetup_StartTrainerBattle(); return TRUE; } -bool8 ScrCmd_endtrainerbattle(struct ScriptContext *ctx) +bool8 ScrCmd_ontrainerbattleend(struct ScriptContext *ctx) { ctx->scriptPtr = BattleSetup_GetScriptAddrAfterBattle(); return FALSE; } -bool8 ScrCmd_endtrainerbattle2(struct ScriptContext *ctx) +bool8 ScrCmd_ontrainerbattleendgoto(struct ScriptContext *ctx) { ctx->scriptPtr = BattleSetup_GetTrainerPostBattleScript(); return FALSE; @@ -1603,20 +1713,23 @@ bool8 ScrCmd_endtrainerbattle2(struct ScriptContext *ctx) bool8 ScrCmd_checktrainerflag(struct ScriptContext *ctx) { u16 index = VarGet(ScriptReadHalfword(ctx)); + ctx->comparisonResult = HasTrainerAlreadyBeenFought(index); return FALSE; } -bool8 ScrCmd_cleartrainerflag(struct ScriptContext *ctx) +bool8 ScrCmd_settrainerflag(struct ScriptContext *ctx) { u16 index = VarGet(ScriptReadHalfword(ctx)); + trainer_flag_set(index); return FALSE; } -bool8 ScrCmd_settrainerflag(struct ScriptContext *ctx) +bool8 ScrCmd_cleartrainerflag(struct ScriptContext *ctx) { u16 index = VarGet(ScriptReadHalfword(ctx)); + trainer_flag_clear(index); return FALSE; } @@ -1626,6 +1739,7 @@ bool8 ScrCmd_setwildbattle(struct ScriptContext *ctx) u16 species = ScriptReadHalfword(ctx); u8 level = ScriptReadByte(ctx); u16 item = ScriptReadHalfword(ctx); + CreateScriptedWildMon(species, level, item); return FALSE; } @@ -1640,6 +1754,7 @@ bool8 ScrCmd_dowildbattle(struct ScriptContext *ctx) bool8 ScrCmd_pokemart(struct ScriptContext *ctx) { void *ptr = (void *)ScriptReadWord(ctx); + CreatePokemartMenu(ptr); ScriptContext1_Stop(); return TRUE; @@ -1648,6 +1763,7 @@ bool8 ScrCmd_pokemart(struct ScriptContext *ctx) bool8 ScrCmd_pokemartdecor(struct ScriptContext *ctx) { void *ptr = (void *)ScriptReadWord(ctx); + CreateDecorationShop1Menu(ptr); ScriptContext1_Stop(); return TRUE; @@ -1656,24 +1772,27 @@ bool8 ScrCmd_pokemartdecor(struct ScriptContext *ctx) bool8 ScrCmd_pokemartbp(struct ScriptContext *ctx) { void *ptr = (void *)ScriptReadWord(ctx); + CreateDecorationShop2Menu(ptr); ScriptContext1_Stop(); return TRUE; } -bool8 ScrCmd_pokecasino(struct ScriptContext *ctx) +bool8 ScrCmd_playslotmachine(struct ScriptContext *ctx) { u8 v2 = VarGet(ScriptReadHalfword(ctx)); + PlaySlotMachine(v2, c2_exit_to_overworld_1_continue_scripts_restart_music); ScriptContext1_Stop(); return TRUE; } -bool8 ScrCmd_event_8a(struct ScriptContext *ctx) +bool8 ScrCmd_plantberrytree(struct ScriptContext *ctx) { u8 treeId = ScriptReadByte(ctx); u8 berry = ScriptReadByte(ctx); u8 growthStage = ScriptReadByte(ctx); + if (berry == 0) PlantBerryTree(treeId, 0, growthStage, FALSE); else @@ -1681,9 +1800,10 @@ bool8 ScrCmd_event_8a(struct ScriptContext *ctx) return FALSE; } -bool8 ScrCmd_event_96(struct ScriptContext *ctx) +bool8 ScrCmd_getpricereduction(struct ScriptContext *ctx) { u16 value = VarGet(ScriptReadHalfword(ctx)); + gScriptResult = GetPriceReduction(value); return FALSE; } @@ -1716,17 +1836,19 @@ bool8 ScrCmd_contestlinktransfer(struct ScriptContext *ctx) return TRUE; } -bool8 ScrCmd_doanimation(struct ScriptContext *ctx) +bool8 ScrCmd_dofieldeffect(struct ScriptContext *ctx) { u16 effectId = VarGet(ScriptReadHalfword(ctx)); + sFieldEffectScriptId = effectId; FieldEffectStart(sFieldEffectScriptId); return FALSE; } -bool8 ScrCmd_setanimation(struct ScriptContext *ctx) +bool8 ScrCmd_setfieldeffect(struct ScriptContext *ctx) { u8 argNum = ScriptReadByte(ctx); + gFieldEffectArguments[argNum] = (s16)VarGet(ScriptReadHalfword(ctx)); return FALSE; } @@ -1739,7 +1861,7 @@ static bool8 sub_8067B48() return FALSE; } -bool8 ScrCmd_checkanimation(struct ScriptContext *ctx) +bool8 ScrCmd_waitfieldeffect(struct ScriptContext *ctx) { sFieldEffectScriptId = VarGet(ScriptReadHalfword(ctx)); SetupNativeScript(ctx, sub_8067B48); @@ -1748,21 +1870,23 @@ bool8 ScrCmd_checkanimation(struct ScriptContext *ctx) bool8 ScrCmd_sethealplace(struct ScriptContext *ctx) { - u16 v2 = VarGet(ScriptReadHalfword(ctx)); - sub_8053588(v2); + u16 healLocationId = VarGet(ScriptReadHalfword(ctx)); + + Overworld_SetHealLocationWarp(healLocationId); return FALSE; } -bool8 ScrCmd_checkgender(struct ScriptContext *ctx) +bool8 ScrCmd_checkplayergender(struct ScriptContext *ctx) { gScriptResult = gSaveBlock2.playerGender; return FALSE; } -bool8 ScrCmd_pokecry(struct ScriptContext *ctx) +bool8 ScrCmd_playpokecry(struct ScriptContext *ctx) { u16 species = VarGet(ScriptReadHalfword(ctx)); u16 mode = VarGet(ScriptReadHalfword(ctx)); + PlayCry5(species, mode); return FALSE; } @@ -1779,6 +1903,7 @@ bool8 ScrCmd_setmaptile(struct ScriptContext *ctx) u16 y = VarGet(ScriptReadHalfword(ctx)); u16 tileId = VarGet(ScriptReadHalfword(ctx)); u16 v8 = VarGet(ScriptReadHalfword(ctx)); + x += 7; y += 7; if (!v8) @@ -1788,10 +1913,11 @@ bool8 ScrCmd_setmaptile(struct ScriptContext *ctx) return FALSE; } -bool8 ScrCmd_setdooropened(struct ScriptContext *ctx) +bool8 ScrCmd_opendoor(struct ScriptContext *ctx) { u16 x = VarGet(ScriptReadHalfword(ctx)); u16 y = VarGet(ScriptReadHalfword(ctx)); + x += 7; y += 7; PlaySE(GetDoorSoundEffect(x, y)); @@ -1799,10 +1925,11 @@ bool8 ScrCmd_setdooropened(struct ScriptContext *ctx) return FALSE; } -bool8 ScrCmd_setdoorclosed(struct ScriptContext *ctx) +bool8 ScrCmd_closedoor(struct ScriptContext *ctx) { u16 x = VarGet(ScriptReadHalfword(ctx)); u16 y = VarGet(ScriptReadHalfword(ctx)); + x += 7; y += 7; FieldAnimateDoorClose(x, y); @@ -1817,43 +1944,46 @@ static bool8 IsDoorAnimationStopped() return FALSE; } -bool8 ScrCmd_doorchange(struct ScriptContext *ctx) +bool8 ScrCmd_waitdooranim(struct ScriptContext *ctx) { SetupNativeScript(ctx, IsDoorAnimationStopped); return TRUE; } -bool8 ScrCmd_setdooropened2(struct ScriptContext *ctx) +bool8 ScrCmd_setdooropen(struct ScriptContext *ctx) { u16 x = VarGet(ScriptReadHalfword(ctx)); u16 y = VarGet(ScriptReadHalfword(ctx)); + x += 7; y += 7; FieldSetDoorOpened(x, y); return FALSE; } -bool8 ScrCmd_setdoorclosed2(struct ScriptContext *ctx) +bool8 ScrCmd_setdoorclosed(struct ScriptContext *ctx) { u16 x = VarGet(ScriptReadHalfword(ctx)); u16 y = VarGet(ScriptReadHalfword(ctx)); + x += 7; y += 7; FieldSetDoorClosed(x, y); return FALSE; } -bool8 ScrCmd_event_b1(struct ScriptContext *ctx) +bool8 ScrCmd_addelevmenuitem(struct ScriptContext *ctx) { u8 v3 = ScriptReadByte(ctx); u16 v5 = VarGet(ScriptReadHalfword(ctx)); u16 v7 = VarGet(ScriptReadHalfword(ctx)); u16 v9 = VarGet(ScriptReadHalfword(ctx)); + ScriptAddElevatorMenuItem(v3, v5, v7, v9); return FALSE; } -bool8 ScrCmd_event_b2(struct ScriptContext *ctx) +bool8 ScrCmd_showelevmenu(struct ScriptContext *ctx) { ScriptShowElevatorMenu(); ScriptContext1_Stop(); @@ -1870,21 +2000,21 @@ bool8 ScrCmd_checkcoins(struct ScriptContext *ctx) bool8 ScrCmd_givecoins(struct ScriptContext *ctx) { u16 coins = VarGet(ScriptReadHalfword(ctx)); + if (GiveCoins(coins) == TRUE) gScriptResult = 0; else gScriptResult = 1; - return FALSE; } -bool8 ScrCmd_removecoins(struct ScriptContext *ctx) +bool8 ScrCmd_takecoins(struct ScriptContext *ctx) { u16 coins = VarGet(ScriptReadHalfword(ctx)); + if (TakeCoins(coins) == TRUE) gScriptResult = 0; else gScriptResult = 1; - return FALSE; } diff --git a/src/field/secret_base.c b/src/field/secret_base.c index b2cd1f094..f221d7f16 100644 --- a/src/field/secret_base.c +++ b/src/field/secret_base.c @@ -301,7 +301,7 @@ void sub_80BBBEC(u8 taskid) s8 idx; if (!gPaletteFade.active) { idx = 4 * (gUnknown_020387DC / 10); - warp1_set(gSaveBlock1.location.mapGroup, gSaveBlock1.location.mapNum, -1, gUnknown_083D1374[idx + 2], gUnknown_083D1374[idx + 3]); + Overworld_SetWarpDestination(gSaveBlock1.location.mapGroup, gSaveBlock1.location.mapNum, -1, gUnknown_083D1374[idx + 2], gUnknown_083D1374[idx + 3]); warp_in(); gFieldCallback = sub_80BBB90; SetMainCallback2(CB2_LoadMap); diff --git a/src/rom6.c b/src/rom6.c index 3a5071034..b91a9b2c0 100644 --- a/src/rom6.c +++ b/src/rom6.c @@ -169,7 +169,7 @@ int SetUpFieldMove_Dig(void) static void sub_810B5D8(void) { - sub_8053014(); + Overworld_ResetStateAfterDigEscRope(); FieldEffectStart(FLDEFF_USE_DIG); gFieldEffectArguments[0] = gLastFieldPokeMenuOpened; } diff --git a/src/scene/evolution_scene.c b/src/scene/evolution_scene.c index 88f3e23a8..c8d7846c8 100644 --- a/src/scene/evolution_scene.c +++ b/src/scene/evolution_scene.c @@ -667,7 +667,7 @@ static void Task_EvolutionScene(u8 taskID) { u8 text[20]; - sub_8053E90(); + Overworld_PlaySpecialMapMusic(); gTasks[taskID].tBits |= TASK_BIT_LEARN_MOVE; gTasks[taskID].tLearnsFirstMove = FALSE; gTasks[taskID].tLearnMoveState = 0; @@ -691,7 +691,7 @@ static void Task_EvolutionScene(u8 taskID) if (!gPaletteFade.active) { if (!(gTasks[taskID].tBits & TASK_BIT_LEARN_MOVE)) - sub_8053E90(); + Overworld_PlaySpecialMapMusic(); if (!gTasks[taskID].tEvoWasStopped) CreateShedinja(gTasks[taskID].tPreEvoSpecies, mon); DestroyTask(taskID); diff --git a/src/scene/new_game.c b/src/scene/new_game.c index 3f9e9f5a1..6ab21c544 100644 --- a/src/scene/new_game.c +++ b/src/scene/new_game.c @@ -99,7 +99,7 @@ void sub_8052DE4(void) void WarpToTruck(void) { - warp1_set(25, 40, -1, -1, -1); // inside of truck + Overworld_SetWarpDestination(25, 40, -1, -1, -1); // inside of truck warp_in(); } |