diff options
Diffstat (limited to 'src/scrcmd.c')
-rw-r--r-- | src/scrcmd.c | 233 |
1 files changed, 69 insertions, 164 deletions
diff --git a/src/scrcmd.c b/src/scrcmd.c index 9d6f36a54..d3d28f923 100644 --- a/src/scrcmd.c +++ b/src/scrcmd.c @@ -1,143 +1,28 @@ #include "global.h" +#include "asm.h" +#include "battle_setup.h" +#include "berry.h" +#include "field_player_avatar.h" +#include "item.h" #include "script.h" #include "rng.h" #include "palette.h" #include "rtc.h" #include "pokemon.h" -#include "fieldmap.h" +#include "asm_fieldmap.h" #include "main.h" #include "menu.h" +#include "money.h" #include "decoration.h" #include "field_message_box.h" #include "sound.h" #include "string_util.h" -#include "flag.h" -#include "var.h" - -extern void ClearRamScript(void); -extern void sub_8126160(u8); -extern u8 AddBagItem(u16, u16); -extern u8 RemoveBagItem(u16, u16); -extern u8 CheckBagHasSpace(u16, u16); -extern u8 CheckBagHasItem(u16, u16); -extern u8 GetPocketByItemId(u16); -extern u8 AddPCItem(u16, u16); -extern u8 CheckPCHasItem(u16, u16); -extern u8 IsThereStorageSpaceForDecoration(u8); -extern s8 sub_81340A8(u8); -extern u8 sub_8134074(u8); -extern u8 sub_8133FE4(u8); -extern void sav12_xor_increment(u8); -extern void sub_8081594(u8); -extern void sub_8053CE4(u32); -extern void fade_screen(u8, u8); -extern void DoTimeBasedEvents(void); -extern void SetSav1Weather(u32); -extern void sub_80806E4(void); -extern void sub_808073C(void); -extern void activate_per_step_callback(u8); -extern void sub_8053D14(u16); -extern void warp1_set(s8, s8, s8, s8, s8); -extern void sub_8080E88(void); -extern void player_avatar_init_params_reset(void); -extern void sp13E_warp_to_last_warp(void); -extern void sub_8080EF0(void); -extern void sp13F_fall_to_last_warp(void); -extern void sub_8053720(s16, s16); -extern void PlayerGetDestCoords(u16 *, u16 *); -extern void sub_8080F68(void); -extern void saved_warp2_set_2(s8, s8, s8, s8, s8, s8); -extern void sub_8053690(s8, s8, s8, s8, s8); -extern void sub_80536E4(s8, s8, s8, s8, s8); -extern void sub_805363C(s8, s8, s8, s8, s8); -extern void sav1_set_battle_music_maybe(u16); -extern void sub_8053F84(void); -extern void sub_8053FB0(u16); -extern u8 exec_movement(u8, u8, u8, void *); -extern bool8 sub_80A212C(u8, u8, u8); -extern void RemoveFieldObjectByLocalIdAndMap(u8, u8, u8); -extern u8 show_sprite(u8, u8, u8); -extern void sub_805C0F8(u8, u8, u8, s16, s16); -extern void update_saveblock1_field_object_coords(u8, s16, s16); -extern void sub_805C78C(u8, u8, u8); -extern void npc_by_local_id_and_map_set_field_1_bit_x20(u8, u8, u8, u8); -extern void sub_805BCF0(u8, u8, u8, u8); -extern void sub_805BD48(u8, u8, u8); -extern u8 player_get_direction_lower_nybble(void); -extern u8 FieldObjectFaceOppositeDirection(void *, u8); -extern void FieldObjectTurnByLocalIdAndMap(u8, u8, u8, u8); -extern void update_saveblock1_field_object_movement_behavior(u8, u8); -extern u8 sub_805B410(u8, u8, s16, s16, u8, u8); -extern void sub_8064990(u8, u8); -extern bool32 is_c1_link_related_active(void); -extern void sub_8064D20(void); -extern bool8 sub_8064CFC(void); -extern void sub_8064DD8(void); -extern bool8 sub_8064DB4(void); -extern u8 GetFieldObjectIdByLocalIdAndMap(u8, u8, u8); -extern u8 FieldObjectClearAnimIfSpecialAnimFinished(void *); -extern void sub_80A2178(void); -extern void sub_806451C(void); -extern bool8 yes_no_box(u8, u8); -extern bool8 sub_80B5054(u8, u8, u8, u8); -extern bool8 sub_80B50B0(u8, u8, u8, u8, u8); -extern bool8 sub_80B5578(u8, u8, u8, u8, u8); -extern bool8 Multichoice(u8, u8, u8, u8); -extern bool8 sub_80B58C4(u16, u8, u8); -extern void *picbox_close(void); -extern void sub_8106630(u32); -extern void ShowContestWinner(void); -extern u8 GetLeadMonIndex(void); -extern void CopyItemName(u16, u8 *); -extern u8 sub_80BF0B8(u32); -extern void sub_80B79B8(u32 *, u32); -extern void sub_80B79E0(u32 *, u32); -extern bool8 IsEnoughMoney(u32, u32); -extern void sub_80B7C14(u32, u8, u8); -extern void RemoveMoneyLabelObject(u8, u8); -extern void sub_80B7BEC(u32, u8, u8); -extern void ShowCoinsWindow(u32, u8, u8); -extern void HideCoinsWindow(u8, u8); -extern void UpdateCoinsWindow(u32, u8, u8); -extern void *TrainerBattleConfigure(u8 *); -extern void sub_80825E4(void); -extern u8 *sub_80826E8(void); -extern u8 *sub_8082700(void); -extern u8 trainer_flag_check(u16); -extern void trainer_flag_set(u16); -extern void trainer_flag_clear(u16); -extern void ScriptWildBattle(u16, u8, u16); -extern void sub_8081B3C(void); -extern void CreatePokemartMenu(void *); -extern void CreateDecorationShop1Menu(void *); -extern void CreateDecorationShop2Menu(void *); -extern void PlaySlotMachine(u8, void *); -extern void PlantBerryTree(u8, u8, u8, bool8); -extern bool8 GetPriceReduction(u8); -extern void sub_80F99CC(void); -extern void sub_80C48C8(void); -extern void sub_80C4940(void); -extern void sub_80C4980(u8); -extern u32 FieldEffectStart(u8); -extern bool8 FieldEffectActiveListContains(u8); -extern void sub_8053588(u8); -extern void MapGridSetMetatileIdAt(u32, u32, u16); -extern u16 sub_8058790(u32, u32); -extern bool8 FieldAnimateDoorOpen(u32, u32); -extern bool8 FieldAnimateDoorClose(u32, u32); -extern bool8 FieldIsDoorAnimationRunning(void); -extern void FieldSetDoorOpened(u32, u32); -extern void FieldSetDoorClosed(u32, u32); -extern void ScriptAddElevatorMenuItem(u8, u8, u8, u8); -extern void ScriptShowElevatorMenu(void); -extern u16 GetCoins(void); -extern bool8 GiveCoins(u16); -extern bool8 TakeCoins(u16); -extern u8 ScriptGiveMon(u16, u8, u16, u32, u32, u8); -extern u8 ScriptGiveEgg(u16); -extern void ScriptSetMonMoveSlot(u8, u16, u8); -extern bool8 pokemon_has_move(struct Pokemon *, u16); -extern void c2_exit_to_overworld_1_continue_scripts_restart_music(void); +#include "event_data.h" +#include "rom4.h" +#include "weather.h" +#include "map_obj_lock.h" +#include "coins.h" +#include "field_effect.h" typedef u16 (*SpecialFunc)(void); typedef void (*NativeFunc)(void); @@ -170,11 +55,31 @@ extern u8 *gStdScripts_End[]; extern u8 gSpeciesNames[][11]; extern u8 gMoveNames[][13]; -extern u8 gScriptConditionTable[6][3]; -extern u8 * const gUnknown_083762F0[]; extern u8 * const gUnknown_083CE048[]; extern struct Decoration gDecorations[]; +// This is defined in here so the optimizer can't see its value when compiling +// script.c. +void * const gNullScriptPtr = NULL; + +static const u8 sScriptConditionTable[6][3] = +{ +// < = > + 1, 0, 0, // < + 0, 1, 0, // = + 0, 0, 1, // > + 1, 1, 0, // <= + 0, 1, 1, // >= + 1, 0, 1, // != +}; + +static u8 * const sScriptStringVars[] = +{ + gStringVar1, + gStringVar2, + gStringVar3, +}; + bool8 ScrCmd_snop(struct ScriptContext *ctx) { return FALSE; @@ -250,7 +155,7 @@ bool8 ScrCmd_jumpif(struct ScriptContext *ctx) { u8 condition = ScriptReadByte(ctx); u8 *ptr = (u8 *)ScriptReadWord(ctx); - if (gScriptConditionTable[condition][ctx->comparisonResult] == 1) + if (sScriptConditionTable[condition][ctx->comparisonResult] == 1) ScriptJump(ctx, ptr); return FALSE; } @@ -259,7 +164,7 @@ bool8 ScrCmd_callif(struct ScriptContext *ctx) { u8 condition = ScriptReadByte(ctx); u8 *ptr = (u8 *)ScriptReadWord(ctx); - if (gScriptConditionTable[condition][ctx->comparisonResult] == 1) + if (sScriptConditionTable[condition][ctx->comparisonResult] == 1) ScriptCall(ctx, ptr); return FALSE; } @@ -290,7 +195,7 @@ bool8 ScrCmd_if5(struct ScriptContext *ctx) { u8 condition = ScriptReadByte(ctx); u8 *ptr = (u8 *)(ScriptReadWord(ctx) - gUnknown_0202E8B0); - if (gScriptConditionTable[condition][ctx->comparisonResult] == 1) + if (sScriptConditionTable[condition][ctx->comparisonResult] == 1) ScriptJump(ctx, ptr); return FALSE; } @@ -299,7 +204,7 @@ bool8 ScrCmd_if6(struct ScriptContext *ctx) { u8 condition = ScriptReadByte(ctx); u8 *ptr = (u8 *)(ScriptReadWord(ctx) - gUnknown_0202E8B0); - if (gScriptConditionTable[condition][ctx->comparisonResult] == 1) + if (sScriptConditionTable[condition][ctx->comparisonResult] == 1) ScriptCall(ctx, ptr); return FALSE; } @@ -326,7 +231,7 @@ bool8 ScrCmd_jumpstdif(struct ScriptContext *ctx) { u8 condition = ScriptReadByte(ctx); u8 index = ScriptReadByte(ctx); - if (gScriptConditionTable[condition][ctx->comparisonResult] == 1) + if (sScriptConditionTable[condition][ctx->comparisonResult] == 1) { u8 **ptr = &gStdScripts[index]; if (ptr < gStdScripts_End) @@ -339,7 +244,7 @@ bool8 ScrCmd_callstdif(struct ScriptContext *ctx) { u8 condition = ScriptReadByte(ctx); u8 index = ScriptReadByte(ctx); - if (gScriptConditionTable[condition][ctx->comparisonResult] == 1) + if (sScriptConditionTable[condition][ctx->comparisonResult] == 1) { u8 **ptr = &gStdScripts[index]; if (ptr < gStdScripts_End) @@ -638,7 +543,7 @@ bool8 ScrCmd_checkflag(struct ScriptContext *ctx) bool8 ScrCmd_inccounter(struct ScriptContext *ctx) { - sav12_xor_increment(ScriptReadByte(ctx)); + IncrementGameStat(ScriptReadByte(ctx)); return FALSE; } @@ -673,9 +578,9 @@ bool8 ScrCmd_fadescreen(struct ScriptContext *ctx) bool8 ScrCmd_fadescreendelay(struct ScriptContext *ctx) { - u8 val1 = ScriptReadByte(ctx); - u8 val2 = ScriptReadByte(ctx); - fade_screen(val1, val2); + u8 duration = ScriptReadByte(ctx); + u8 delay = ScriptReadByte(ctx); + fade_screen(duration, delay); SetupNativeScript(ctx, sub_8066248); return TRUE; } @@ -735,13 +640,13 @@ bool8 ScrCmd_resetweather(struct ScriptContext *ctx) bool8 ScrCmd_doweather(struct ScriptContext *ctx) { - sub_808073C(); + DoCurrentWeather(); return FALSE; } bool8 ScrCmd_tileeffect(struct ScriptContext *ctx) { - activate_per_step_callback(ScriptReadByte(ctx)); + ActivatePerStepCallback(ScriptReadByte(ctx)); return FALSE; } @@ -1180,7 +1085,7 @@ bool8 ScrCmd_lockall(struct ScriptContext *ctx) } else { - sub_8064D20(); + ScriptFreezeMapObjects(); SetupNativeScript(ctx, sub_8064CFC); return TRUE; } @@ -1201,7 +1106,7 @@ bool8 ScrCmd_lock(struct ScriptContext *ctx) } else { - sub_8064D20(); + ScriptFreezeMapObjects(); SetupNativeScript(ctx, sub_8064CFC); } @@ -1217,7 +1122,7 @@ bool8 ScrCmd_releaseall(struct ScriptContext *ctx) objectId = GetFieldObjectIdByLocalIdAndMap(0xFF, 0, 0); FieldObjectClearAnimIfSpecialAnimFinished(&gMapObjects[objectId]); sub_80A2178(); - sub_806451C(); + UnfreezeMapObjects(); return FALSE; } @@ -1231,7 +1136,7 @@ bool8 ScrCmd_release(struct ScriptContext *ctx) objectId = GetFieldObjectIdByLocalIdAndMap(0xFF, 0, 0); FieldObjectClearAnimIfSpecialAnimFinished(&gMapObjects[objectId]); sub_80A2178(); - sub_806451C(); + UnfreezeMapObjects(); return FALSE; } @@ -1440,14 +1345,14 @@ bool8 ScrCmd_bufferpoke(struct ScriptContext *ctx) { u8 stringVarIndex = ScriptReadByte(ctx); u16 species = VarGet(ScriptReadHalfword(ctx)); - StringCopy(gUnknown_083762F0[stringVarIndex], gSpeciesNames[species]); + StringCopy(sScriptStringVars[stringVarIndex], gSpeciesNames[species]); return FALSE; } bool8 ScrCmd_bufferfirstpoke(struct ScriptContext *ctx) { u8 stringVarIndex = ScriptReadByte(ctx); - u8 *dest = gUnknown_083762F0[stringVarIndex]; + u8 *dest = sScriptStringVars[stringVarIndex]; u8 partyIndex = GetLeadMonIndex(); u32 species = GetMonData(&gPlayerParty[partyIndex], MON_DATA_SPECIES, NULL); StringCopy(dest, gSpeciesNames[species]); @@ -1458,8 +1363,8 @@ bool8 ScrCmd_bufferpartypoke(struct ScriptContext *ctx) { u8 stringVarIndex = ScriptReadByte(ctx); u16 partyIndex = VarGet(ScriptReadHalfword(ctx)); - GetMonData(&gPlayerParty[partyIndex], MON_DATA_NICKNAME, gUnknown_083762F0[stringVarIndex]); - StringGetEnd10(gUnknown_083762F0[stringVarIndex]); + GetMonData(&gPlayerParty[partyIndex], MON_DATA_NICKNAME, sScriptStringVars[stringVarIndex]); + StringGetEnd10(sScriptStringVars[stringVarIndex]); return FALSE; } @@ -1467,7 +1372,7 @@ bool8 ScrCmd_bufferitem(struct ScriptContext *ctx) { u8 stringVarIndex = ScriptReadByte(ctx); u16 itemId = VarGet(ScriptReadHalfword(ctx)); - CopyItemName(itemId, gUnknown_083762F0[stringVarIndex]); + CopyItemName(itemId, sScriptStringVars[stringVarIndex]); return FALSE; } @@ -1475,7 +1380,7 @@ bool8 ScrCmd_bufferdecor(struct ScriptContext *ctx) { u8 stringVarIndex = ScriptReadByte(ctx); u16 decorId = VarGet(ScriptReadHalfword(ctx)); - StringCopy(gUnknown_083762F0[stringVarIndex], gDecorations[decorId].name); + StringCopy(sScriptStringVars[stringVarIndex], gDecorations[decorId].name); return FALSE; } @@ -1483,7 +1388,7 @@ bool8 ScrCmd_bufferattack(struct ScriptContext *ctx) { u8 stringVarIndex = ScriptReadByte(ctx); u16 moveId = VarGet(ScriptReadHalfword(ctx)); - StringCopy(gUnknown_083762F0[stringVarIndex], gMoveNames[moveId]); + StringCopy(sScriptStringVars[stringVarIndex], gMoveNames[moveId]); return FALSE; } @@ -1492,7 +1397,7 @@ bool8 ScrCmd_buffernum(struct ScriptContext *ctx) u8 stringVarIndex = ScriptReadByte(ctx); u16 v1 = VarGet(ScriptReadHalfword(ctx)); u8 v2 = sub_80BF0B8(v1); - ConvertIntToDecimalStringN(gUnknown_083762F0[stringVarIndex], v1, 0, v2); + ConvertIntToDecimalStringN(sScriptStringVars[stringVarIndex], v1, 0, v2); return FALSE; } @@ -1500,7 +1405,7 @@ bool8 ScrCmd_bufferstd(struct ScriptContext *ctx) { u8 stringVarIndex = ScriptReadByte(ctx); u16 index = VarGet(ScriptReadHalfword(ctx)); - StringCopy(gUnknown_083762F0[stringVarIndex], gUnknown_083CE048[index]); + StringCopy(sScriptStringVars[stringVarIndex], gUnknown_083CE048[index]); return FALSE; } @@ -1508,7 +1413,7 @@ bool8 ScrCmd_buffertext(struct ScriptContext *ctx) { u8 stringVarIndex = ScriptReadByte(ctx); u8 *text = (u8 *)ScriptReadWord(ctx); - StringCopy(gUnknown_083762F0[stringVarIndex], text); + StringCopy(sScriptStringVars[stringVarIndex], text); return FALSE; } @@ -1524,7 +1429,7 @@ bool8 ScrCmd_vbuffer(struct ScriptContext *ctx) u8 stringVarIndex = ScriptReadByte(ctx); u32 addr = ScriptReadWord(ctx); u8 *src = (u8 *)(addr - gUnknown_0202E8B0); - u8 *dest = gUnknown_083762F0[stringVarIndex]; + u8 *dest = sScriptStringVars[stringVarIndex]; StringCopy(dest, src); return FALSE; } @@ -1713,7 +1618,7 @@ bool8 ScrCmd_setwildbattle(struct ScriptContext *ctx) bool8 ScrCmd_dowildbattle(struct ScriptContext *ctx) { - sub_8081B3C(); + StartBattle_ScriptedWild(); ScriptContext1_Stop(); return TRUE; } @@ -1812,7 +1717,7 @@ bool8 ScrCmd_setanimation(struct ScriptContext *ctx) return FALSE; } -bool8 sub_8067B48() +static bool8 sub_8067B48() { if (!FieldEffectActiveListContains(gUnknown_0202E8BC)) return TRUE; @@ -1890,7 +1795,7 @@ bool8 ScrCmd_setdoorclosed(struct ScriptContext *ctx) return FALSE; } -bool8 IsDoorAnimationStopped() +static bool8 IsDoorAnimationStopped() { if (!FieldIsDoorAnimationRunning()) return TRUE; @@ -1950,8 +1855,8 @@ bool8 ScrCmd_checkcoins(struct ScriptContext *ctx) bool8 ScrCmd_givecoins(struct ScriptContext *ctx) { - u16 v2 = VarGet(ScriptReadHalfword(ctx)); - if (GiveCoins(v2) == TRUE) + u16 coins = VarGet(ScriptReadHalfword(ctx)); + if (GiveCoins(coins) == TRUE) gScriptResult = 0; else gScriptResult = 1; @@ -1961,8 +1866,8 @@ bool8 ScrCmd_givecoins(struct ScriptContext *ctx) bool8 ScrCmd_removecoins(struct ScriptContext *ctx) { - u16 v2 = VarGet(ScriptReadHalfword(ctx)); - if (TakeCoins(v2) == TRUE) + u16 coins = VarGet(ScriptReadHalfword(ctx)); + if (TakeCoins(coins) == TRUE) gScriptResult = 0; else gScriptResult = 1; |