summaryrefslogtreecommitdiff
path: root/src/scrcmd.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/scrcmd.c')
-rw-r--r--src/scrcmd.c302
1 files changed, 74 insertions, 228 deletions
diff --git a/src/scrcmd.c b/src/scrcmd.c
index 183b9bab5..a15ad666c 100644
--- a/src/scrcmd.c
+++ b/src/scrcmd.c
@@ -13,8 +13,7 @@
#include "field_door.h"
#include "field_effect.h"
#include "field_fadetransition.h"
-#include "field_map_obj.h"
-#include "field_map_obj_helpers.h"
+#include "event_object_movement.h"
#include "field_message_box.h"
#include "field_player_avatar.h"
#include "field_screen_effect.h"
@@ -25,16 +24,14 @@
#include "item.h"
#include "lilycove_lady.h"
#include "main.h"
-#include "map_obj_lock.h"
+#include "event_obj_lock.h"
#include "menu.h"
#include "money.h"
#include "mystery_event_script.h"
-#include "new_menu_helpers.h"
#include "palette.h"
#include "party_menu.h"
-#include "pokemon_3.h"
#include "pokemon_storage_system.h"
-#include "rng.h"
+#include "random.h"
#include "overworld.h"
#include "rtc.h"
#include "script.h"
@@ -64,13 +61,6 @@ static EWRAM_DATA u16 sMovingNpcMapBank = 0;
static EWRAM_DATA u16 sMovingNpcMapId = 0;
static EWRAM_DATA u16 sFieldEffectScriptId = 0;
-extern u16 gSpecialVar_0x8000;
-extern u16 gSpecialVar_0x8001;
-extern u16 gSpecialVar_0x8002;
-extern u16 gSpecialVar_0x8004;
-
-extern u16 gSpecialVar_Result;
-
extern u16 gSpecialVar_ContestCategory;
IWRAM_DATA u8 gUnknown_03000F30;
@@ -638,7 +628,7 @@ static bool8 IsPaletteNotActive(void)
bool8 ScrCmd_fadescreen(struct ScriptContext *ctx)
{
- fade_screen(ScriptReadByte(ctx), 0);
+ FadeScreen(ScriptReadByte(ctx), 0);
SetupNativeScript(ctx, IsPaletteNotActive);
return TRUE;
}
@@ -648,7 +638,7 @@ bool8 ScrCmd_fadescreenspeed(struct ScriptContext *ctx)
u8 mode = ScriptReadByte(ctx);
u8 speed = ScriptReadByte(ctx);
- fade_screen(mode, speed);
+ FadeScreen(mode, speed);
SetupNativeScript(ctx, IsPaletteNotActive);
return TRUE;
}
@@ -656,18 +646,18 @@ bool8 ScrCmd_fadescreenspeed(struct ScriptContext *ctx)
bool8 ScrCmd_fadescreenswapbuffers(struct ScriptContext *ctx)
{
u8 mode = ScriptReadByte(ctx);
-
+
switch (mode)
{
case 1:
default:
CpuCopy32(gPlttBufferUnfaded, gPaletteDecompressionBuffer, PLTT_DECOMP_BUFFER_SIZE);
- fade_screen(mode, 0);
+ FadeScreen(mode, 0);
break;
case 0:
case 2:
CpuCopy32(gPaletteDecompressionBuffer, gPlttBufferUnfaded, PLTT_DECOMP_BUFFER_SIZE);
- fade_screen(mode, 0);
+ FadeScreen(mode, 0);
break;
}
@@ -726,7 +716,7 @@ bool8 ScrCmd_setweather(struct ScriptContext *ctx)
bool8 ScrCmd_resetweather(struct ScriptContext *ctx)
{
- sub_80AEDBC();
+ SetSav1WeatherFromCurrMapHeader();
return FALSE;
}
@@ -1061,7 +1051,7 @@ bool8 ScrCmd_removeobject(struct ScriptContext *ctx)
{
u16 localId = VarGet(ScriptReadHalfword(ctx));
- RemoveFieldObjectByLocalIdAndMap(localId, gSaveBlock1Ptr->location.mapNum, gSaveBlock1Ptr->location.mapGroup);
+ RemoveEventObjectByLocalIdAndMap(localId, gSaveBlock1Ptr->location.mapNum, gSaveBlock1Ptr->location.mapGroup);
return FALSE;
}
@@ -1071,7 +1061,7 @@ bool8 ScrCmd_removeobject_at(struct ScriptContext *ctx)
u8 mapGroup = ScriptReadByte(ctx);
u8 mapNum = ScriptReadByte(ctx);
- RemoveFieldObjectByLocalIdAndMap(objectId, mapNum, mapGroup);
+ RemoveEventObjectByLocalIdAndMap(objectId, mapNum, mapGroup);
return FALSE;
}
@@ -1109,7 +1099,7 @@ bool8 ScrCmd_setobjectxyperm(struct ScriptContext *ctx)
u16 x = VarGet(ScriptReadHalfword(ctx));
u16 y = VarGet(ScriptReadHalfword(ctx));
- Overworld_SetMapObjTemplateCoords(localId, x, y);
+ Overworld_SetEventObjTemplateCoords(localId, x, y);
return FALSE;
}
@@ -1164,10 +1154,10 @@ bool8 ScrCmd_resetobjectpriority(struct ScriptContext *ctx)
bool8 ScrCmd_faceplayer(struct ScriptContext *ctx)
{
- if (gMapObjects[gSelectedMapObject].active)
+ if (gEventObjects[gSelectedEventObject].active)
{
- FieldObjectFaceOppositeDirection(&gMapObjects[gSelectedMapObject],
- player_get_direction_lower_nybble());
+ EventObjectFaceOppositeDirection(&gEventObjects[gSelectedEventObject],
+ GetPlayerFacingDirection());
}
return FALSE;
}
@@ -1177,7 +1167,7 @@ bool8 ScrCmd_turnobject(struct ScriptContext *ctx)
u16 localId = VarGet(ScriptReadHalfword(ctx));
u8 direction = ScriptReadByte(ctx);
- FieldObjectTurnByLocalIdAndMap(localId, gSaveBlock1Ptr->location.mapNum, gSaveBlock1Ptr->location.mapGroup, direction);
+ EventObjectTurnByLocalIdAndMap(localId, gSaveBlock1Ptr->location.mapNum, gSaveBlock1Ptr->location.mapGroup, direction);
return FALSE;
}
@@ -1186,7 +1176,7 @@ bool8 ScrCmd_setobjectmovementtype(struct ScriptContext *ctx)
u16 localId = VarGet(ScriptReadHalfword(ctx));
u8 movementType = ScriptReadByte(ctx);
- Overworld_SetMapObjTemplateMovementType(localId, movementType);
+ Overworld_SetEventObjTemplateMovementType(localId, movementType);
return FALSE;
}
@@ -1220,7 +1210,7 @@ bool8 ScrCmd_lockall(struct ScriptContext *ctx)
}
else
{
- ScriptFreezeMapObjects();
+ ScriptFreezeEventObjects();
SetupNativeScript(ctx, sub_80983C4);
return TRUE;
}
@@ -1234,14 +1224,14 @@ bool8 ScrCmd_lock(struct ScriptContext *ctx)
}
else
{
- if (gMapObjects[gSelectedMapObject].active)
+ if (gEventObjects[gSelectedEventObject].active)
{
- LockSelectedMapObject();
+ LockSelectedEventObject();
SetupNativeScript(ctx, sub_809847C);
}
else
{
- ScriptFreezeMapObjects();
+ ScriptFreezeEventObjects();
SetupNativeScript(ctx, sub_80983C4);
}
return TRUE;
@@ -1253,10 +1243,10 @@ bool8 ScrCmd_releaseall(struct ScriptContext *ctx)
u8 objectId;
HideFieldMessageBox();
- objectId = GetFieldObjectIdByLocalIdAndMap(0xFF, 0, 0);
- FieldObjectClearAnimIfSpecialAnimFinished(&gMapObjects[objectId]);
+ objectId = GetEventObjectIdByLocalIdAndMap(0xFF, 0, 0);
+ EventObjectClearHeldMovementIfFinished(&gEventObjects[objectId]);
sub_80D338C();
- UnfreezeMapObjects();
+ UnfreezeEventObjects();
return FALSE;
}
@@ -1265,12 +1255,12 @@ bool8 ScrCmd_release(struct ScriptContext *ctx)
u8 objectId;
HideFieldMessageBox();
- if (gMapObjects[gSelectedMapObject].active)
- FieldObjectClearAnimIfSpecialAnimFinished(&gMapObjects[gSelectedMapObject]);
- objectId = GetFieldObjectIdByLocalIdAndMap(0xFF, 0, 0);
- FieldObjectClearAnimIfSpecialAnimFinished(&gMapObjects[objectId]);
+ if (gEventObjects[gSelectedEventObject].active)
+ EventObjectClearHeldMovementIfFinished(&gEventObjects[gSelectedEventObject]);
+ objectId = GetEventObjectIdByLocalIdAndMap(0xFF, 0, 0);
+ EventObjectClearHeldMovementIfFinished(&gEventObjects[objectId]);
sub_80D338C();
- UnfreezeMapObjects();
+ UnfreezeEventObjects();
return FALSE;
}
@@ -1313,7 +1303,7 @@ bool8 ScrCmd_cmdDB(struct ScriptContext *ctx)
if (msg == NULL)
msg = (const u8 *)ctx->data[0];
sub_81973A4();
- sub_81973C4(0, 1);
+ NewMenuHelpers_DrawDialogueFrame(0, 1);
PrintTextOnWindow(0, 1, msg, 0, 1, 0, 0);
return FALSE;
}
@@ -1445,7 +1435,7 @@ bool8 ScrCmd_drawboxtext(struct ScriptContext *ctx)
u8 top = ScriptReadByte(ctx);
u8 multichoiceId = ScriptReadByte(ctx);
u8 ignoreBPress = ScriptReadByte(ctx);
-
+
/*if (Multichoice(left, top, multichoiceId, ignoreBPress) == TRUE)
{
ScriptContext1_Stop();
@@ -1485,199 +1475,55 @@ bool8 ScrCmd_showcontestwinner(struct ScriptContext *ctx)
return TRUE;
}
-// Lots of math, can't figure it out.
-/*
bool8 ScrCmd_braillemessage(struct ScriptContext *ctx)
{
u8 *ptr = (u8 *)ScriptReadWord(ctx);
- struct WindowTemplate template1;
- struct WindowTemplate template2;
- int i;
- u8 width;
- u8 height;
- int temp1;
- int temp2;
- u8 x;
- u8 y;
+ struct WindowTemplate winTemplate;
+ s32 i;
+ u8 width, height;
+ u8 xWindow, yWindow, xText, yText;
+ u8 temp;
StringExpandPlaceholders(gStringVar4, ptr + 6);
-
+
width = GetStringWidth(6, gStringVar4, -1) / 8;
-
+
if (width > 0x1C)
width = 0x1C;
-
+
for (i = 0, height = 4; gStringVar4[i] != 0xFF;)
{
if (gStringVar4[i++] == 0xFE)
height += 3;
}
-
+
if (height > 0x12)
height = 0x12;
-
- x = width + 2;
- temp1 = (0x1E - x) / 2;
- x = temp1 + 1;
- temp1 = ((x - temp1 - 1) * 8 + 3);
-
- y = height + 2;
- temp2 = (0x14 - y) / 2;
- y = temp2 + 2;
- temp2 = ((y - temp2 - 1) * 8);
-
- sub_8198A50(&template1, 0, x, y, width, height, 0xF, 0x1);
- template2 = template1;
- gUnknown_03000F30 = AddWindow(&template2);
- sub_809882C(gUnknown_03000F30, 0x214, 0xE0);
- sub_81973FC(gUnknown_03000F30, 0);
+
+ temp = width + 2;
+ xWindow = (0x1E - temp) / 2;
+
+ temp = height + 2;
+ yText = (0x14 - temp) / 2;
+
+ xText = xWindow;
+ xWindow += 1;
+
+ yWindow = yText;
+ yText += 2;
+
+ xText = (xWindow - xText - 1) * 8 + 3;
+ yText = (yText - yWindow - 1) * 8;
+
+ winTemplate = sub_8198A50(0, xWindow, yWindow + 1, width, height, 0xF, 0x1);
+ gUnknown_03000F30 = AddWindow(&winTemplate);
+ LoadUserWindowBorderGfx(gUnknown_03000F30, 0x214, 0xE0);
+ NewMenuHelpers_DrawStdWindowFrame(gUnknown_03000F30, 0);
PutWindowTilemap(gUnknown_03000F30);
FillWindowPixelBuffer(gUnknown_03000F30, 0x11);
- PrintTextOnWindow(gUnknown_03000F30, 6, gStringVar4, temp1, temp2, 0xFF, 0x0);
+ PrintTextOnWindow(gUnknown_03000F30, 6, gStringVar4, xText, yText, 0xFF, 0x0);
CopyWindowToVram(gUnknown_03000F30, 3);
return FALSE;
-}*/
-__attribute__((naked))
-bool8 ScrCmd_braillemessage(struct ScriptContext *ctx)
-{
- asm("push {r4-r7,lr}\n\
- mov r7, r8\n\
- push {r7}\n\
- sub sp, #0x20\n\
- bl ScriptReadWord\n\
- add r1, r0, #0\n\
- ldr r4, =gStringVar4\n\
- add r1, #0x6\n\
- add r0, r4, #0\n\
- bl StringExpandPlaceholders\n\
- mov r2, #0x1\n\
- neg r2, r2\n\
- mov r0, #0x6\n\
- add r1, r4, #0\n\
- bl GetStringWidth\n\
- lsr r0, #3\n\
- lsl r0, #24\n\
- lsr r7, r0, #24\n\
- cmp r7, #0x1C\n\
- bls _0809AE9C\n\
- mov r7, #0x1C\n\
-_0809AE9C:\n\
- mov r5, #0x4\n\
- ldrb r0, [r4]\n\
- add r2, r7, #0x2\n\
- add r1, sp, #0x18\n\
- mov r8, r1\n\
- cmp r0, #0xFF\n\
- beq _0809AEC0\n\
- add r1, r4, #0\n\
-_0809AEAC:\n\
- ldrb r0, [r1]\n\
- add r1, #0x1\n\
- cmp r0, #0xFE\n\
- bne _0809AEBA\n\
- add r0, r5, #0x3\n\
- lsl r0, #24\n\
- lsr r5, r0, #24\n\
-_0809AEBA:\n\
- ldrb r0, [r1]\n\
- cmp r0, #0xFF\n\
- bne _0809AEAC\n\
-_0809AEC0:\n\
- cmp r5, #0x12\n\
- bls _0809AEC6\n\
- mov r5, #0x12\n\
-_0809AEC6:\n\
- lsl r0, r2, #24\n\
- lsr r0, #24\n\
- mov r2, #0x1E\n\
- sub r2, r0\n\
- lsr r0, r2, #31\n\
- add r2, r0\n\
- asr r2, #1\n\
- lsl r2, #24\n\
- add r0, r5, #0x2\n\
- lsl r0, #24\n\
- lsr r0, #24\n\
- mov r4, #0x14\n\
- sub r4, r0\n\
- lsr r0, r4, #31\n\
- add r4, r0\n\
- asr r4, #1\n\
- lsl r4, #24\n\
- lsr r6, r2, #24\n\
- mov r0, #0x80\n\
- lsl r0, #17\n\
- add r2, r0\n\
- lsr r2, #24\n\
- lsr r3, r4, #24\n\
- mov r1, #0x80\n\
- lsl r1, #18\n\
- add r4, r1\n\
- lsr r4, #24\n\
- sub r6, r2, r6\n\
- sub r6, #0x1\n\
- lsl r6, #3\n\
- add r6, #0x3\n\
- lsl r6, #24\n\
- lsr r6, #24\n\
- sub r4, r3\n\
- sub r4, #0x1\n\
- lsl r4, #27\n\
- lsr r4, #24\n\
- add r3, #0x1\n\
- lsl r3, #24\n\
- lsr r3, #24\n\
- str r7, [sp]\n\
- str r5, [sp, #0x4]\n\
- mov r0, #0xF\n\
- str r0, [sp, #0x8]\n\
- mov r0, #0x1\n\
- str r0, [sp, #0xC]\n\
- add r0, sp, #0x10\n\
- mov r1, #0\n\
- bl sub_8198A50\n\
- ldr r0, [sp, #0x10]\n\
- ldr r1, [sp, #0x14]\n\
- str r0, [sp, #0x18]\n\
- str r1, [sp, #0x1C]\n\
- ldr r5, =gUnknown_03000F30\n\
- mov r0, r8\n\
- bl AddWindow\n\
- strb r0, [r5]\n\
- ldrb r0, [r5]\n\
- mov r1, #0x85\n\
- lsl r1, #2\n\
- mov r2, #0xE0\n\
- bl sub_809882C\n\
- ldrb r0, [r5]\n\
- mov r1, #0\n\
- bl sub_81973FC\n\
- ldrb r0, [r5]\n\
- bl PutWindowTilemap\n\
- ldrb r0, [r5]\n\
- mov r1, #0x11\n\
- bl FillWindowPixelBuffer\n\
- ldrb r0, [r5]\n\
- ldr r2, =gStringVar4\n\
- str r4, [sp]\n\
- mov r1, #0xFF\n\
- str r1, [sp, #0x4]\n\
- mov r1, #0\n\
- str r1, [sp, #0x8]\n\
- mov r1, #0x6\n\
- add r3, r6, #0\n\
- bl PrintTextOnWindow\n\
- ldrb r0, [r5]\n\
- mov r1, #0x3\n\
- bl CopyWindowToVram\n\
- mov r0, #0\n\
- add sp, #0x20\n\
- pop {r3}\n\
- mov r8, r3\n\
- pop {r4-r7}\n\
- pop {r1}\n\
- bx r1\n\
- .pool");
}
bool8 ScrCmd_cmdDA(struct ScriptContext *ctx)
@@ -1765,7 +1611,7 @@ bool8 ScrCmd_buffernumberstring(struct ScriptContext *ctx)
{
u8 stringVarIndex = ScriptReadByte(ctx);
u16 v1 = VarGet(ScriptReadHalfword(ctx));
- u8 v2 = sub_80EF370(v1);
+ u8 v2 = CountDigits(v1);
ConvertIntToDecimalStringN(sScriptStringVars[stringVarIndex], v1, 0, v2);
return FALSE;
@@ -1924,7 +1770,7 @@ bool8 ScrCmd_hidemoneybox(struct ScriptContext *ctx)
{
/*u8 x = ScriptReadByte(ctx);
u8 y = ScriptReadByte(ctx);*/
-
+
HideMoneyBox();
return FALSE;
}
@@ -1979,13 +1825,13 @@ bool8 ScrCmd_dotrainerbattle(struct ScriptContext *ctx)
return TRUE;
}
-bool8 ScrCmd_ontrainerbattleend(struct ScriptContext *ctx)
+bool8 ScrCmd_gotopostbattlescript(struct ScriptContext *ctx)
{
ctx->scriptPtr = BattleSetup_GetScriptAddrAfterBattle();
return FALSE;
}
-bool8 ScrCmd_ontrainerbattleendgoto(struct ScriptContext *ctx)
+bool8 ScrCmd_gotobeatenscript(struct ScriptContext *ctx)
{
ctx->scriptPtr = BattleSetup_GetTrainerPostBattleScript();
return FALSE;
@@ -1995,7 +1841,7 @@ bool8 ScrCmd_checktrainerflag(struct ScriptContext *ctx)
{
u16 index = VarGet(ScriptReadHalfword(ctx));
- ctx->comparisonResult = HasTrainerAlreadyBeenFought(index);
+ ctx->comparisonResult = HasTrainerBeenFought(index);
return FALSE;
}
@@ -2003,7 +1849,7 @@ bool8 ScrCmd_settrainerflag(struct ScriptContext *ctx)
{
u16 index = VarGet(ScriptReadHalfword(ctx));
- trainer_flag_set(index);
+ SetTrainerFlag(index);
return FALSE;
}
@@ -2011,7 +1857,7 @@ bool8 ScrCmd_cleartrainerflag(struct ScriptContext *ctx)
{
u16 index = VarGet(ScriptReadHalfword(ctx));
- trainer_flag_clear(index);
+ ClearTrainerFlag(index);
return FALSE;
}
@@ -2063,7 +1909,7 @@ bool8 ScrCmd_playslotmachine(struct ScriptContext *ctx)
{
u8 slotMachineIndex = VarGet(ScriptReadHalfword(ctx));
- PlaySlotMachine(slotMachineIndex, c2_exit_to_overworld_1_continue_scripts_restart_music);
+ PlaySlotMachine(slotMachineIndex, CB2_ReturnToFieldContinueScriptPlayMapMusic);
ScriptContext1_Stop();
return TRUE;
}
@@ -2089,7 +1935,7 @@ bool8 ScrCmd_getpricereduction(struct ScriptContext *ctx)
return FALSE;
}
-bool8 ScrCmd_choosecontestpkmn(struct ScriptContext *ctx)
+bool8 ScrCmd_choosecontestmon(struct ScriptContext *ctx)
{
sub_81B9404();
ScriptContext1_Stop();
@@ -2332,7 +2178,7 @@ bool8 ScrCmd_mossdeepgym4(struct ScriptContext *ctx)
bool8 ScrCmd_cmdD8(struct ScriptContext *ctx)
{
- gSelectedMapObject = sub_80B47BC();
+ gSelectedEventObject = GetCurrentApproachingTrainerEventObjectId();
return FALSE;
}
@@ -2344,7 +2190,7 @@ bool8 ScrCmd_cmdD9(struct ScriptContext *ctx)
}
else
{
- if (gMapObjects[gSelectedMapObject].active)
+ if (gEventObjects[gSelectedEventObject].active)
{
sub_8098630();
SetupNativeScript(ctx, sub_8098734);
@@ -2374,7 +2220,7 @@ bool8 ScrCmd_checkmonobedience(struct ScriptContext *ctx)
bool8 ScrCmd_cmdCF(struct ScriptContext *ctx)
{
const u8* v1 = sub_8099244();
-
+
if (v1)
{
((u8*)gUnknown_020375C0) = ctx->scriptPtr;
@@ -2392,7 +2238,7 @@ bool8 ScrCmd_warpD1(struct ScriptContext *ctx)
u16 y = VarGet(ScriptReadHalfword(ctx));
Overworld_SetWarpDestination(mapGroup, mapNum, warpId, x, y);
- sub_808D074(player_get_direction_lower_nybble());
+ sub_808D074(GetPlayerFacingDirection());
sub_80B0244();
player_avatar_init_params_reset();
return TRUE;