diff options
Diffstat (limited to 'src/scrcmd.c')
-rw-r--r-- | src/scrcmd.c | 157 |
1 files changed, 76 insertions, 81 deletions
diff --git a/src/scrcmd.c b/src/scrcmd.c index 6007fb493..2c18cb565 100644 --- a/src/scrcmd.c +++ b/src/scrcmd.c @@ -49,7 +49,6 @@ #include "tv.h" #include "window.h" #include "constants/event_objects.h" -#include "constants/maps.h" typedef u16 (*SpecialFunc)(void); typedef void (*NativeFunc)(void); @@ -58,11 +57,11 @@ EWRAM_DATA const u8 *gRamScriptRetAddr = NULL; static EWRAM_DATA u32 sAddressOffset = 0; // For relative addressing in vgoto etc., used by saved scripts (e.g. Mystery Event) static EWRAM_DATA u16 sPauseCounter = 0; static EWRAM_DATA u16 sMovingNpcId = 0; -static EWRAM_DATA u16 sMovingNpcMapBank = 0; -static EWRAM_DATA u16 sMovingNpcMapId = 0; +static EWRAM_DATA u16 sMovingNpcMapGroup = 0; +static EWRAM_DATA u16 sMovingNpcMapNum = 0; static EWRAM_DATA u16 sFieldEffectScriptId = 0; -static u8 gBrailleWindowId; +static u8 sBrailleWindowId; extern const SpecialFunc gSpecials[]; extern const u8 *gStdScripts[]; @@ -287,7 +286,7 @@ bool8 ScrCmd_returnram(struct ScriptContext *ctx) return FALSE; } -bool8 ScrCmd_killscript(struct ScriptContext *ctx) +bool8 ScrCmd_endram(struct ScriptContext *ctx) { ClearRamScript(); StopScript(ctx); @@ -296,9 +295,9 @@ bool8 ScrCmd_killscript(struct ScriptContext *ctx) bool8 ScrCmd_setmysteryeventstatus(struct ScriptContext *ctx) { - u8 value = ScriptReadByte(ctx); + u8 status = ScriptReadByte(ctx); - SetMysteryEventScriptStatus(value); + SetMysteryEventScriptStatus(status); return FALSE; } @@ -310,7 +309,7 @@ bool8 ScrCmd_loadword(struct ScriptContext *ctx) return FALSE; } -bool8 ScrCmd_loadbytefromaddr(struct ScriptContext *ctx) +bool8 ScrCmd_loadbytefromptr(struct ScriptContext *ctx) { u8 index = ScriptReadByte(ctx); @@ -318,7 +317,7 @@ bool8 ScrCmd_loadbytefromaddr(struct ScriptContext *ctx) return FALSE; } -bool8 ScrCmd_writebytetoaddr(struct ScriptContext *ctx) +bool8 ScrCmd_setptr(struct ScriptContext *ctx) { u8 value = ScriptReadByte(ctx); @@ -406,7 +405,7 @@ bool8 ScrCmd_compare_local_to_value(struct ScriptContext *ctx) return FALSE; } -bool8 ScrCmd_compare_local_to_addr(struct ScriptContext *ctx) +bool8 ScrCmd_compare_local_to_ptr(struct ScriptContext *ctx) { const u8 value1 = ctx->data[ScriptReadByte(ctx)]; const u8 value2 = *(const u8 *)ScriptReadWord(ctx); @@ -415,7 +414,7 @@ bool8 ScrCmd_compare_local_to_addr(struct ScriptContext *ctx) return FALSE; } -bool8 ScrCmd_compare_addr_to_local(struct ScriptContext *ctx) +bool8 ScrCmd_compare_ptr_to_local(struct ScriptContext *ctx) { const u8 value1 = *(const u8 *)ScriptReadWord(ctx); const u8 value2 = ctx->data[ScriptReadByte(ctx)]; @@ -424,7 +423,7 @@ bool8 ScrCmd_compare_addr_to_local(struct ScriptContext *ctx) return FALSE; } -bool8 ScrCmd_compare_addr_to_value(struct ScriptContext *ctx) +bool8 ScrCmd_compare_ptr_to_value(struct ScriptContext *ctx) { const u8 value1 = *(const u8 *)ScriptReadWord(ctx); const u8 value2 = ScriptReadByte(ctx); @@ -433,7 +432,7 @@ bool8 ScrCmd_compare_addr_to_value(struct ScriptContext *ctx) return FALSE; } -bool8 ScrCmd_compare_addr_to_addr(struct ScriptContext *ctx) +bool8 ScrCmd_compare_ptr_to_ptr(struct ScriptContext *ctx) { const u8 value1 = *(const u8 *)ScriptReadWord(ctx); const u8 value2 = *(const u8 *)ScriptReadWord(ctx); @@ -610,11 +609,9 @@ bool8 ScrCmd_animateflash(struct ScriptContext *ctx) return TRUE; } -bool8 ScrCmd_setflashradius(struct ScriptContext *ctx) +bool8 ScrCmd_setflashlevel(struct ScriptContext *ctx) { - u16 flashLevel = VarGet(ScriptReadHalfword(ctx)); - - Overworld_SetFlashLevel(flashLevel); + SetFlashLevel(VarGet(ScriptReadHalfword(ctx))); return FALSE; } @@ -649,17 +646,17 @@ bool8 ScrCmd_fadescreenswapbuffers(struct ScriptContext *ctx) switch (mode) { - case FADE_TO_BLACK: - case FADE_TO_WHITE: - default: - CpuCopy32(gPlttBufferUnfaded, gPaletteDecompressionBuffer, PLTT_DECOMP_BUFFER_SIZE); - FadeScreen(mode, 0); - break; - case FADE_FROM_BLACK: - case FADE_FROM_WHITE: - CpuCopy32(gPaletteDecompressionBuffer, gPlttBufferUnfaded, PLTT_DECOMP_BUFFER_SIZE); - FadeScreen(mode, 0); - break; + case FADE_TO_BLACK: + case FADE_TO_WHITE: + default: + CpuCopy32(gPlttBufferUnfaded, gPaletteDecompressionBuffer, PLTT_DECOMP_BUFFER_SIZE); + FadeScreen(mode, 0); + break; + case FADE_FROM_BLACK: + case FADE_FROM_WHITE: + CpuCopy32(gPaletteDecompressionBuffer, gPlttBufferUnfaded, PLTT_DECOMP_BUFFER_SIZE); + FadeScreen(mode, 0); + break; } SetupNativeScript(ctx, IsPaletteNotActive); @@ -668,9 +665,7 @@ bool8 ScrCmd_fadescreenswapbuffers(struct ScriptContext *ctx) static bool8 RunPauseTimer(void) { - sPauseCounter--; - - if (sPauseCounter == 0) + if (--sPauseCounter == 0) return TRUE; else return FALSE; @@ -711,13 +706,13 @@ bool8 ScrCmd_setweather(struct ScriptContext *ctx) { u16 weather = VarGet(ScriptReadHalfword(ctx)); - SetSav1Weather(weather); + SetSavedWeather(weather); return FALSE; } bool8 ScrCmd_resetweather(struct ScriptContext *ctx) { - SetSav1WeatherFromCurrMapHeader(); + SetSavedWeatherFromCurrMapHeader(); return FALSE; } @@ -794,7 +789,7 @@ bool8 ScrCmd_warphole(struct ScriptContext *ctx) if (mapGroup == MAP_GROUP(UNDEFINED) && mapNum == MAP_NUM(UNDEFINED)) SetWarpDestinationToFixedHoleWarp(x - MAP_OFFSET, y - MAP_OFFSET); else - SetWarpDestination(mapGroup, mapNum, -1, x - MAP_OFFSET, y - MAP_OFFSET); + SetWarpDestination(mapGroup, mapNum, WARP_ID_NONE, x - MAP_OFFSET, y - MAP_OFFSET); DoFallWarp(); ResetInitialPlayerAvatarState(); return TRUE; @@ -945,9 +940,9 @@ bool8 ScrCmd_waitfanfare(struct ScriptContext *ctx) bool8 ScrCmd_playbgm(struct ScriptContext *ctx) { u16 songId = ScriptReadHalfword(ctx); - bool8 val = ScriptReadByte(ctx); + bool8 save = ScriptReadByte(ctx); - if (val == TRUE) + if (save == TRUE) Overworld_SetSavedMusic(songId); PlayNewMapMusic(songId); return FALSE; @@ -1018,7 +1013,7 @@ bool8 ScrCmd_applymovement_at(struct ScriptContext *ctx) static bool8 WaitForMovementFinish(void) { - return ScriptMovement_IsObjectMovementFinished(sMovingNpcId, sMovingNpcMapId, sMovingNpcMapBank); + return ScriptMovement_IsObjectMovementFinished(sMovingNpcId, sMovingNpcMapNum, sMovingNpcMapGroup); } bool8 ScrCmd_waitmovement(struct ScriptContext *ctx) @@ -1027,8 +1022,8 @@ bool8 ScrCmd_waitmovement(struct ScriptContext *ctx) if (localId != 0) sMovingNpcId = localId; - sMovingNpcMapBank = gSaveBlock1Ptr->location.mapGroup; - sMovingNpcMapId = gSaveBlock1Ptr->location.mapNum; + sMovingNpcMapGroup = gSaveBlock1Ptr->location.mapGroup; + sMovingNpcMapNum = gSaveBlock1Ptr->location.mapNum; SetupNativeScript(ctx, WaitForMovementFinish); return TRUE; } @@ -1036,15 +1031,15 @@ bool8 ScrCmd_waitmovement(struct ScriptContext *ctx) bool8 ScrCmd_waitmovement_at(struct ScriptContext *ctx) { u16 localId = VarGet(ScriptReadHalfword(ctx)); - u8 mapBank; - u8 mapId; + u8 mapGroup; + u8 mapNum; if (localId != 0) sMovingNpcId = localId; - mapBank = ScriptReadByte(ctx); - mapId = ScriptReadByte(ctx); - sMovingNpcMapBank = mapBank; - sMovingNpcMapId = mapId; + mapGroup = ScriptReadByte(ctx); + mapNum = ScriptReadByte(ctx); + sMovingNpcMapGroup = mapGroup; + sMovingNpcMapNum = mapNum; SetupNativeScript(ctx, WaitForMovementFinish); return TRUE; } @@ -1101,7 +1096,7 @@ bool8 ScrCmd_setobjectxyperm(struct ScriptContext *ctx) u16 x = VarGet(ScriptReadHalfword(ctx)); u16 y = VarGet(ScriptReadHalfword(ctx)); - Overworld_SetObjEventTemplateCoords(localId, x, y); + SetObjEventTemplateCoords(localId, x, y); return FALSE; } @@ -1133,24 +1128,24 @@ bool8 ScrCmd_hideobject_at(struct ScriptContext *ctx) return FALSE; } -bool8 ScrCmd_setobjectpriority(struct ScriptContext *ctx) +bool8 ScrCmd_setobjectsubpriority(struct ScriptContext *ctx) { u16 localId = VarGet(ScriptReadHalfword(ctx)); u8 mapGroup = ScriptReadByte(ctx); u8 mapNum = ScriptReadByte(ctx); u8 priority = ScriptReadByte(ctx); - SetObjectPriority(localId, mapNum, mapGroup, priority + 83); + SetObjectSubpriority(localId, mapNum, mapGroup, priority + 83); return FALSE; } -bool8 ScrCmd_resetobjectpriority(struct ScriptContext *ctx) +bool8 ScrCmd_resetobjectsubpriority(struct ScriptContext *ctx) { u16 localId = VarGet(ScriptReadHalfword(ctx)); u8 mapGroup = ScriptReadByte(ctx); u8 mapNum = ScriptReadByte(ctx); - ResetObjectPriority(localId, mapNum, mapGroup); + ResetObjectSubpriority(localId, mapNum, mapGroup); return FALSE; } @@ -1178,29 +1173,29 @@ bool8 ScrCmd_setobjectmovementtype(struct ScriptContext *ctx) u16 localId = VarGet(ScriptReadHalfword(ctx)); u8 movementType = ScriptReadByte(ctx); - Overworld_SetObjEventTemplateMovementType(localId, movementType); + SetObjEventTemplateMovementType(localId, movementType); return FALSE; } bool8 ScrCmd_createvobject(struct ScriptContext *ctx) { u8 graphicsId = ScriptReadByte(ctx); - u8 objectEventId = ScriptReadByte(ctx); + u8 virtualObjId = ScriptReadByte(ctx); u16 x = VarGet(ScriptReadHalfword(ctx)); u32 y = VarGet(ScriptReadHalfword(ctx)); u8 elevation = ScriptReadByte(ctx); u8 direction = ScriptReadByte(ctx); - CreateObjectSprite(graphicsId, objectEventId, x, y, elevation, direction); + CreateVirtualObject(graphicsId, virtualObjId, x, y, elevation, direction); return FALSE; } bool8 ScrCmd_turnvobject(struct ScriptContext *ctx) { - u8 objectEventId = ScriptReadByte(ctx); + u8 virtualObjId = ScriptReadByte(ctx); u8 direction = ScriptReadByte(ctx); - TurnObjectEventSprite(objectEventId, direction); + TurnVirtualObject(virtualObjId, direction); return FALSE; } @@ -1311,7 +1306,7 @@ bool8 ScrCmd_messageinstant(struct ScriptContext *ctx) msg = (const u8 *)ctx->data[0]; LoadMessageBoxAndBorderGfx(); DrawDialogueFrame(0, 1); - AddTextPrinterParameterized(0, FONT_NORMAL, msg, 0, 1, 0, 0); + AddTextPrinterParameterized(0, FONT_NORMAL, msg, 0, 1, 0, NULL); return FALSE; } @@ -1463,7 +1458,9 @@ bool8 ScrCmd_showmonpic(struct ScriptContext *ctx) bool8 ScrCmd_hidemonpic(struct ScriptContext *ctx) { - bool8 (*func)(void) = ScriptMenu_GetPicboxWaitFunc(); + // The hide function returns a pointer to a function + // that returns true once the pic is hidden + bool8 (*func)(void) = ScriptMenu_HidePokemonPic(); if (func == NULL) return FALSE; @@ -1528,13 +1525,13 @@ bool8 ScrCmd_braillemessage(struct ScriptContext *ctx) yText = (yText - yWindow - 1) * 8; winTemplate = CreateWindowTemplate(0, xWindow, yWindow + 1, width, height, 0xF, 0x1); - gBrailleWindowId = AddWindow(&winTemplate); - LoadUserWindowBorderGfx(gBrailleWindowId, 0x214, 0xE0); - DrawStdWindowFrame(gBrailleWindowId, 0); - PutWindowTilemap(gBrailleWindowId); - FillWindowPixelBuffer(gBrailleWindowId, PIXEL_FILL(1)); - AddTextPrinterParameterized(gBrailleWindowId, FONT_BRAILLE, gStringVar4, xText, yText, TEXT_SKIP_DRAW, NULL); - CopyWindowToVram(gBrailleWindowId, COPYWIN_FULL); + sBrailleWindowId = AddWindow(&winTemplate); + LoadUserWindowBorderGfx(sBrailleWindowId, 0x214, 0xE0); + DrawStdWindowFrame(sBrailleWindowId, 0); + PutWindowTilemap(sBrailleWindowId); + FillWindowPixelBuffer(sBrailleWindowId, PIXEL_FILL(1)); + AddTextPrinterParameterized(sBrailleWindowId, FONT_BRAILLE, gStringVar4, xText, yText, TEXT_SKIP_DRAW, NULL); + CopyWindowToVram(sBrailleWindowId, COPYWIN_FULL); return FALSE; } @@ -1578,7 +1575,7 @@ bool8 ScrCmd_bufferpartymonnick(struct ScriptContext *ctx) u16 partyIndex = VarGet(ScriptReadHalfword(ctx)); GetMonData(&gPlayerParty[partyIndex], MON_DATA_NICKNAME, sScriptStringVars[stringVarIndex]); - StringGetEnd10(sScriptStringVars[stringVarIndex]); + StringGet_Nickname(sScriptStringVars[stringVarIndex]); return FALSE; } @@ -1638,12 +1635,12 @@ bool8 ScrCmd_bufferstdstring(struct ScriptContext *ctx) return FALSE; } -bool8 ScrCmd_buffercontesttype(struct ScriptContext *ctx) +bool8 ScrCmd_buffercontestname(struct ScriptContext *ctx) { u8 stringVarIndex = ScriptReadByte(ctx); - u16 index = VarGet(ScriptReadHalfword(ctx)); + u16 category = VarGet(ScriptReadHalfword(ctx)); - BufferContestName(sScriptStringVars[stringVarIndex], index); + BufferContestName(sScriptStringVars[stringVarIndex], category); return FALSE; } @@ -1656,7 +1653,7 @@ bool8 ScrCmd_bufferstring(struct ScriptContext *ctx) return FALSE; } -bool8 ScrCmd_vloadword(struct ScriptContext *ctx) +bool8 ScrCmd_vbuffermessage(struct ScriptContext *ctx) { const u8 *ptr = (u8 *)(ScriptReadWord(ctx) - sAddressOffset); @@ -1933,17 +1930,17 @@ bool8 ScrCmd_setberrytree(struct ScriptContext *ctx) u8 growthStage = ScriptReadByte(ctx); if (berry == 0) - PlantBerryTree(treeId, 0, growthStage, FALSE); + PlantBerryTree(treeId, berry, growthStage, FALSE); else PlantBerryTree(treeId, berry, growthStage, FALSE); return FALSE; } -bool8 ScrCmd_getpricereduction(struct ScriptContext *ctx) +bool8 ScrCmd_getpokenewsactive(struct ScriptContext *ctx) { u16 newsKind = VarGet(ScriptReadHalfword(ctx)); - gSpecialVar_Result = GetPriceReduction(newsKind); + gSpecialVar_Result = IsPokeNewsActive(newsKind); return FALSE; } @@ -1985,7 +1982,7 @@ bool8 ScrCmd_dofieldeffect(struct ScriptContext *ctx) return FALSE; } -bool8 ScrCmd_setfieldeffectarg(struct ScriptContext *ctx) +bool8 ScrCmd_setfieldeffectargument(struct ScriptContext *ctx) { u8 argNum = ScriptReadByte(ctx); @@ -2230,9 +2227,7 @@ bool8 ScrCmd_checkmoneventlegal(struct ScriptContext *ctx) return FALSE; } -// TODO: Should be renamed. Name implies general usage, but its specifically for Wonder Card -// See GetSavedRamScriptIfValid, which is NULL if ValidateSavedWonderCard returns FALSE -bool8 ScrCmd_gotoram(struct ScriptContext *ctx) +bool8 ScrCmd_trywondercardscript(struct ScriptContext *ctx) { const u8* script = GetSavedRamScriptIfValid(); @@ -2244,7 +2239,7 @@ bool8 ScrCmd_gotoram(struct ScriptContext *ctx) return FALSE; } -// Unused +// This warp is only used by the Union Room. // For the warp used by the Aqua Hideout, see DoTeleportTileWarp bool8 ScrCmd_warpspinenter(struct ScriptContext *ctx) { @@ -2273,8 +2268,8 @@ bool8 ScrCmd_setmonmetlocation(struct ScriptContext *ctx) static void CloseBrailleWindow(void) { - ClearStdWindowAndFrame(gBrailleWindowId, 1); - RemoveWindow(gBrailleWindowId); + ClearStdWindowAndFrame(sBrailleWindowId, 1); + RemoveWindow(sBrailleWindowId); } bool8 ScrCmd_buffertrainerclassname(struct ScriptContext *ctx) @@ -2300,7 +2295,7 @@ void SetMovingNpcId(u16 npcId) sMovingNpcId = npcId; } -bool8 ScrCmd_warpsootopolislegend(struct ScriptContext *ctx) +bool8 ScrCmd_warpwhitefade(struct ScriptContext *ctx) { u8 mapGroup = ScriptReadByte(ctx); u8 mapNum = ScriptReadByte(ctx); @@ -2309,7 +2304,7 @@ bool8 ScrCmd_warpsootopolislegend(struct ScriptContext *ctx) u16 y = VarGet(ScriptReadHalfword(ctx)); SetWarpDestination(mapGroup, mapNum, warpId, x, y); - DoSootopolisLegendWarp(); + DoWhiteFadeWarp(); ResetInitialPlayerAvatarState(); return TRUE; } |