summaryrefslogtreecommitdiff
path: root/src/scrcmd.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/scrcmd.c')
-rw-r--r--src/scrcmd.c154
1 files changed, 92 insertions, 62 deletions
diff --git a/src/scrcmd.c b/src/scrcmd.c
index a8567a2bb..a394f2a55 100644
--- a/src/scrcmd.c
+++ b/src/scrcmd.c
@@ -1,36 +1,52 @@
#include "global.h"
-#include "asm.h"
#include "battle_setup.h"
#include "berry.h"
+#include "clock.h"
+#include "coins.h"
+#include "contest_link_80C2020.h"
+#include "contest_painting.h"
+#include "data2.h"
+#include "decoration.h"
+#include "decoration_inventory.h"
+#include "event_data.h"
+#include "field_door.h"
+#include "field_effect.h"
+#include "field_fadetransition.h"
+#include "field_map_obj.h"
+#include "field_map_obj_helpers.h"
+#include "field_message_box.h"
#include "field_player_avatar.h"
+#include "field_screen_effect.h"
+#include "field_specials.h"
+#include "field_tasks.h"
+#include "field_weather.h"
+#include "fieldmap.h"
#include "item.h"
-#include "script.h"
-#include "rng.h"
-#include "palette.h"
-#include "rtc.h"
-#include "pokemon.h"
-#include "asm_fieldmap.h"
#include "main.h"
+#include "map_obj_lock.h"
#include "menu.h"
#include "money.h"
-#include "decoration.h"
-#include "field_message_box.h"
+#include "mystery_event_script.h"
+#include "palette.h"
+#include "party_menu.h"
+#include "pokemon.h"
+#include "rng.h"
+#include "rom4.h"
+#include "rtc.h"
+#include "script.h"
+#include "script_menu.h"
+#include "script_movement.h"
+#include "script_pokemon_80C4.h"
+#include "script_pokemon_80F9.h"
+#include "shop.h"
+#include "slot_machine.h"
#include "sound.h"
#include "string_util.h"
-#include "flag.h"
-#include "var.h"
-#include "rom4.h"
-#include "weather.h"
-#include "map_obj_lock.h"
-#include "coins.h"
-#include "field_effect.h"
+#include "tv.h"
typedef u16 (*SpecialFunc)(void);
typedef void (*NativeFunc)(void);
-extern struct Pokemon gPlayerParty[6]; // 0x3004360
-extern struct Pokemon gEnemyParty[6]; // 0x30045C0
-
extern u32 gUnknown_0202E8AC;
extern u32 gUnknown_0202E8B0;
extern u16 gUnknown_0202E8B4;
@@ -53,13 +69,27 @@ extern SpecialFunc gSpecials[];
extern u8 *gStdScripts[];
extern u8 *gStdScripts_End[];
-extern u8 gSpeciesNames[][11];
-extern u8 gMoveNames[][13];
+// This is defined in here so the optimizer can't see its value when compiling
+// script.c.
+void * const gNullScriptPtr = NULL;
-extern u8 gScriptConditionTable[6][3];
-extern u8 * const gUnknown_083762F0[];
-extern u8 * const gUnknown_083CE048[];
-extern struct Decoration gDecorations[];
+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)
{
@@ -136,7 +166,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;
}
@@ -145,7 +175,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;
}
@@ -176,7 +206,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;
}
@@ -185,7 +215,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;
}
@@ -212,7 +242,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)
@@ -225,7 +255,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)
@@ -524,7 +554,7 @@ bool8 ScrCmd_checkflag(struct ScriptContext *ctx)
bool8 ScrCmd_inccounter(struct ScriptContext *ctx)
{
- sav12_xor_increment(ScriptReadByte(ctx));
+ IncrementGameStat(ScriptReadByte(ctx));
return FALSE;
}
@@ -542,7 +572,7 @@ bool8 ScrCmd_darken(struct ScriptContext *ctx)
return FALSE;
}
-bool8 sub_8066248(void)
+bool8 IsPaletteNotActive(void)
{
if (!gPaletteFade.active)
return TRUE;
@@ -553,16 +583,16 @@ bool8 sub_8066248(void)
bool8 ScrCmd_fadescreen(struct ScriptContext *ctx)
{
fade_screen(ScriptReadByte(ctx), 0);
- SetupNativeScript(ctx, sub_8066248);
+ SetupNativeScript(ctx, IsPaletteNotActive);
return TRUE;
}
bool8 ScrCmd_fadescreendelay(struct ScriptContext *ctx)
{
- u8 val1 = ScriptReadByte(ctx);
- u8 val2 = ScriptReadByte(ctx);
- fade_screen(val1, val2);
- SetupNativeScript(ctx, sub_8066248);
+ u8 duration = ScriptReadByte(ctx);
+ u8 delay = ScriptReadByte(ctx);
+ fade_screen(duration, delay);
+ SetupNativeScript(ctx, IsPaletteNotActive);
return TRUE;
}
@@ -621,13 +651,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;
}
@@ -1066,7 +1096,7 @@ bool8 ScrCmd_lockall(struct ScriptContext *ctx)
}
else
{
- sub_8064D20();
+ ScriptFreezeMapObjects();
SetupNativeScript(ctx, sub_8064CFC);
return TRUE;
}
@@ -1087,7 +1117,7 @@ bool8 ScrCmd_lock(struct ScriptContext *ctx)
}
else
{
- sub_8064D20();
+ ScriptFreezeMapObjects();
SetupNativeScript(ctx, sub_8064CFC);
}
@@ -1103,7 +1133,7 @@ bool8 ScrCmd_releaseall(struct ScriptContext *ctx)
objectId = GetFieldObjectIdByLocalIdAndMap(0xFF, 0, 0);
FieldObjectClearAnimIfSpecialAnimFinished(&gMapObjects[objectId]);
sub_80A2178();
- sub_806451C();
+ UnfreezeMapObjects();
return FALSE;
}
@@ -1117,7 +1147,7 @@ bool8 ScrCmd_release(struct ScriptContext *ctx)
objectId = GetFieldObjectIdByLocalIdAndMap(0xFF, 0, 0);
FieldObjectClearAnimIfSpecialAnimFinished(&gMapObjects[objectId]);
sub_80A2178();
- sub_806451C();
+ UnfreezeMapObjects();
return FALSE;
}
@@ -1151,7 +1181,7 @@ bool8 ScrCmd_closebutton(struct ScriptContext *ctx)
return FALSE;
}
-bool8 sub_80670C0()
+bool8 WaitForAorBPress(void)
{
if (gMain.newKeys & A_BUTTON)
return TRUE;
@@ -1162,7 +1192,7 @@ bool8 sub_80670C0()
bool8 ScrCmd_waitbutton(struct ScriptContext *ctx)
{
- SetupNativeScript(ctx, sub_80670C0);
+ SetupNativeScript(ctx, WaitForAorBPress);
return TRUE;
}
@@ -1326,14 +1356,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]);
@@ -1344,8 +1374,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;
}
@@ -1353,7 +1383,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;
}
@@ -1361,7 +1391,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;
}
@@ -1369,7 +1399,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;
}
@@ -1378,7 +1408,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;
}
@@ -1386,7 +1416,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].text);
return FALSE;
}
@@ -1394,7 +1424,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;
}
@@ -1410,7 +1440,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;
}
@@ -1599,7 +1629,7 @@ bool8 ScrCmd_setwildbattle(struct ScriptContext *ctx)
bool8 ScrCmd_dowildbattle(struct ScriptContext *ctx)
{
- sub_8081B3C();
+ StartBattle_ScriptedWild();
ScriptContext1_Stop();
return TRUE;
}
@@ -1836,8 +1866,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;
@@ -1847,8 +1877,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;