summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDizzyEggg <jajkodizzy@wp.pl>2017-12-24 00:08:55 +0100
committerDizzyEggg <jajkodizzy@wp.pl>2017-12-24 00:08:55 +0100
commit8cd4908fa3820b22a8b4e3d96780d725132549c4 (patch)
treebcc8e697ce7dd0d4ab532a61fccafbbdb6d2400e /src
parent6b5157b2a3b2d81f83a910b211834cde5cd3a238 (diff)
parent841ee0f2b25b39b923a9f800279df413edb8c66d (diff)
merge bike with master, fix conflicts
Diffstat (limited to 'src')
-rw-r--r--src/battle_2.c12
-rw-r--r--src/battle_bg.c4
-rw-r--r--src/battle_controller_safari.c7
-rw-r--r--src/battle_interface.c1
-rw-r--r--src/battle_message.c4
-rw-r--r--src/battle_script_commands.c2
-rw-r--r--src/battle_setup.c53
-rw-r--r--src/berry_blender.c12
-rw-r--r--src/bike.c4
-rw-r--r--src/daycare.c9
-rw-r--r--src/decoration.c24
-rw-r--r--src/egg_hatch.c2
-rw-r--r--src/evolution_scene.c20
-rwxr-xr-xsrc/field_map_obj.c22
-rwxr-xr-xsrc/field_special_scene.c2
-rw-r--r--src/hall_of_fame.c2
-rw-r--r--src/lilycove_lady.c4
-rw-r--r--src/new_game.c3
-rw-r--r--src/pokeball.c2
-rw-r--r--src/pokeblock.c1337
-rw-r--r--src/pokeblock_feed.c1108
-rw-r--r--src/pokemon_3.c40
-rwxr-xr-xsrc/pokemon_summary_screen.c8
-rw-r--r--src/safari_zone.c2
-rw-r--r--src/scrcmd.c4
-rw-r--r--src/secret_base.c24
-rw-r--r--src/sound.c2
-rw-r--r--src/trainer_see.c725
-rw-r--r--src/use_pokeblock.c230
-rw-r--r--src/wallclock.c2
30 files changed, 3527 insertions, 144 deletions
diff --git a/src/battle_2.c b/src/battle_2.c
index f8b4113f0..6752c4d4f 100644
--- a/src/battle_2.c
+++ b/src/battle_2.c
@@ -4738,9 +4738,9 @@ static void HandleEndTurn_BattleWon(void)
gBattlescriptCurrInstr = BattleScript_FrontierTrainerBattleWon;
if (gTrainerBattleOpponent_A == TRAINER_OPPONENT_3FE)
- PlayBGM(BGM_KACHI3);
+ PlayBGM(MUS_KACHI3);
else
- PlayBGM(BGM_KACHI1);
+ PlayBGM(MUS_KACHI1);
}
else if (gBattleTypeFlags & BATTLE_TYPE_TRAINER && !(gBattleTypeFlags & BATTLE_TYPE_LINK))
{
@@ -4751,7 +4751,7 @@ static void HandleEndTurn_BattleWon(void)
{
case TRAINER_CLASS_ELITE_FOUR:
case TRAINER_CLASS_CHAMPION:
- PlayBGM(BGM_KACHI5);
+ PlayBGM(MUS_KACHI5);
break;
case TRAINER_CLASS_TEAM_AQUA:
case TRAINER_CLASS_TEAM_MAGMA:
@@ -4759,13 +4759,13 @@ static void HandleEndTurn_BattleWon(void)
case TRAINER_CLASS_AQUA_LEADER:
case TRAINER_CLASS_MAGMA_ADMIN:
case TRAINER_CLASS_MAGMA_LEADER:
- PlayBGM(BGM_KACHI4);
+ PlayBGM(MUS_KACHI4);
break;
case TRAINER_CLASS_LEADER:
- PlayBGM(BGM_KACHI3);
+ PlayBGM(MUS_KACHI3);
break;
default:
- PlayBGM(BGM_KACHI1);
+ PlayBGM(MUS_KACHI1);
break;
}
}
diff --git a/src/battle_bg.c b/src/battle_bg.c
index 24a88c4f5..5d5bbf0e9 100644
--- a/src/battle_bg.c
+++ b/src/battle_bg.c
@@ -1,7 +1,7 @@
#include "global.h"
#include "battle.h"
#include "sprite.h"
-#include "constants\trainers.h"
+#include "constants/trainers.h"
#include "graphics.h"
#include "decompress.h"
#include "bg.h"
@@ -13,7 +13,7 @@
#include "task.h"
#include "trig.h"
#include "sound.h"
-#include "songs.h"
+#include "constants/songs.h"
#include "strings.h"
#include "window.h"
#include "text_window.h"
diff --git a/src/battle_controller_safari.c b/src/battle_controller_safari.c
index db4670523..64e6a0bc3 100644
--- a/src/battle_controller_safari.c
+++ b/src/battle_controller_safari.c
@@ -19,6 +19,7 @@
#include "reshow_battle_screen.h"
#include "pokeball.h"
#include "data2.h"
+#include "pokeblock.h"
extern u32 gBattleExecBuffer;
extern u8 gActiveBank;
@@ -291,13 +292,13 @@ static void CompleteOnSpecialAnimDone(void)
SafariBufferExecCompleted();
}
-static void OpenPokeblockCase(void)
+static void SafariOpenPokeblockCase(void)
{
if (!gPaletteFade.active)
{
gBattleBankFunc[gActiveBank] = CompleteWhenChosePokeblock;
FreeAllWindowBuffers();
- sub_81358F4();
+ OpenPokeblockCaseInBattle();
}
}
@@ -497,7 +498,7 @@ static void SafariHandleChooseItem(void)
s32 i;
BeginNormalPaletteFade(-1, 0, 0, 0x10, 0);
- gBattleBankFunc[gActiveBank] = OpenPokeblockCase;
+ gBattleBankFunc[gActiveBank] = SafariOpenPokeblockCase;
gBankInMenu = gActiveBank;
}
diff --git a/src/battle_interface.c b/src/battle_interface.c
index 95f1a1111..6a6bf00a2 100644
--- a/src/battle_interface.c
+++ b/src/battle_interface.c
@@ -177,7 +177,6 @@ extern const u16 gBattleInterface_BallDisplayPal[];
extern const u8 gHealthboxElementsGfxTable[][32];
// functions
-extern void AddTextPrinterParametrized2(u8 windowId, u8 fontId, u8 x, u8 y, u8 letterSpacing, u8 lineSpacing, struct TextColor *color, s8 speed, const u8 *str); // menu.h
extern void LoadBattleBarGfx(u8 arg0);
// this file's functions
diff --git a/src/battle_message.c b/src/battle_message.c
index 8a985102d..e37a4c30c 100644
--- a/src/battle_message.c
+++ b/src/battle_message.c
@@ -484,8 +484,8 @@ const u8 gText_PkmnBrokeFree[] = _("Oh, no!\nThe POKéMON broke free!");
const u8 gText_ItAppearedCaught[] = _("Aww!\nIt appeared to be caught!");
const u8 gText_AarghAlmostHadIt[] = _("Aargh!\nAlmost had it!");
const u8 gText_ShootSoClose[] = _("Shoot!\nIt was so close, too!");
-const u8 gText_GotchaPkmnCaught[] = _("Gotcha!\n{B_OPPONENT_MON1_NAME} was caught!{UNKNOWN_A}{PLAY_BGM BGM_KACHI22}\p");
-const u8 gText_GotchaPkmnCaught2[] = _("Gotcha!\n{B_OPPONENT_MON1_NAME} was caught!{UNKNOWN_A}{PLAY_BGM BGM_KACHI22}{PAUSE 127}");
+const u8 gText_GotchaPkmnCaught[] = _("Gotcha!\n{B_OPPONENT_MON1_NAME} was caught!{UNKNOWN_A}{PLAY_BGM MUS_KACHI22}\p");
+const u8 gText_GotchaPkmnCaught2[] = _("Gotcha!\n{B_OPPONENT_MON1_NAME} was caught!{UNKNOWN_A}{PLAY_BGM MUS_KACHI22}{PAUSE 127}");
const u8 gText_GiveNicknameCaptured[] = _("Give a nickname to the\ncaptured {B_OPPONENT_MON1_NAME}?");
const u8 gText_PkmnSentToPC[] = _("{B_OPPONENT_MON1_NAME} was sent to\n{B_PC_CREATOR_NAME} PC.");
const u8 gText_Someones[] = _("someone’s");
diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c
index 656f9f43a..43b802d0b 100644
--- a/src/battle_script_commands.c
+++ b/src/battle_script_commands.c
@@ -7121,7 +7121,7 @@ static void atk76_various(void)
gBattleOutcome = BATTLE_OPPONENT_TELEPORTED;
break;
case VARIOUS_PLAY_TRAINER_DEFEATED_MUSIC:
- EmitPlayFanfareOrBGM(0, BGM_KACHI1, TRUE);
+ EmitPlayFanfareOrBGM(0, MUS_KACHI1, TRUE);
MarkBufferBankForExecution(gActiveBank);
break;
}
diff --git a/src/battle_setup.c b/src/battle_setup.c
index 3d4f5afcc..6d7a97844 100644
--- a/src/battle_setup.c
+++ b/src/battle_setup.c
@@ -11,7 +11,7 @@
#include "constants/game_stat.h"
#include "event_data.h"
#include "constants/species.h"
-#include "songs.h"
+#include "constants/songs.h"
#include "metatile_behavior.h"
#include "constants/maps.h"
#include "field_player_avatar.h"
@@ -88,9 +88,6 @@ extern u32 GetGameStat(u8 statId);
extern u32 gBattleTypeFlags;
extern u8 gBattleOutcome;
extern void (*gFieldCallback)(void);
-extern u8 gApproachingTrainerId;
-extern u8 gNoOfApproachingTrainers;
-extern u16 gUnknown_03006080;
// this file's functions
static void DoBattlePikeWildBattle(void);
@@ -113,7 +110,7 @@ static void HandleRematchVarsOnBattleEnd(void);
static const u8 *GetIntroSpeechOfApproachingTrainer(void);
static const u8 *GetTrainerCantBattleSpeech(void);
-// ewram data
+// ewram vars
EWRAM_DATA static u16 sTrainerBattleMode = 0;
EWRAM_DATA u16 gTrainerBattleOpponent_A = 0;
EWRAM_DATA u16 gTrainerBattleOpponent_B = 0;
@@ -523,25 +520,25 @@ void BattleSetup_StartLegendaryBattle(void)
default:
case SPECIES_GROUDON:
gBattleTypeFlags |= BATTLE_TYPE_GROUDON;
- CreateBattleStartTask(B_TRANSITION_GROUDON, BGM_BATTLE34);
+ CreateBattleStartTask(B_TRANSITION_GROUDON, MUS_BATTLE34);
break;
case SPECIES_KYOGRE:
gBattleTypeFlags |= BATTLE_TYPE_KYOGRE;
- CreateBattleStartTask(B_TRANSITION_KYOGRE, BGM_BATTLE34);
+ CreateBattleStartTask(B_TRANSITION_KYOGRE, MUS_BATTLE34);
break;
case SPECIES_RAYQUAZA:
gBattleTypeFlags |= BATTLE_TYPE_RAYQUAZA;
- CreateBattleStartTask(B_TRANSITION_RAYQUAZA, BGM_BATTLE_LEGENDARY);
+ CreateBattleStartTask(B_TRANSITION_RAYQUAZA, MUS_VS_REKKU);
break;
case SPECIES_DEOXYS:
- CreateBattleStartTask(B_TRANSITION_BLUR, BGM_FRLG_BATTLE_DEOXYS);
+ CreateBattleStartTask(B_TRANSITION_BLUR, MUS_RG_VS_DEO);
break;
case SPECIES_LUGIA:
case SPECIES_HO_OH:
- CreateBattleStartTask(B_TRANSITION_BLUR, BGM_FRLG_BATTLE_LEGENDARY);
+ CreateBattleStartTask(B_TRANSITION_BLUR, MUS_RG_VS_DEN);
break;
case SPECIES_MEW:
- CreateBattleStartTask(B_TRANSITION_GRID_SQUARES, BGM_BATTLE_MEW);
+ CreateBattleStartTask(B_TRANSITION_GRID_SQUARES, MUS_VS_MEW);
break;
}
@@ -558,9 +555,9 @@ void StartGroudonKyogreBattle(void)
gBattleTypeFlags = BATTLE_TYPE_LEGENDARY | BATTLE_TYPE_KYOGRE_GROUDON;
if (gGameVersion == VERSION_RUBY)
- CreateBattleStartTask(B_TRANSITION_SHARDS, BGM_BATTLE34); // GROUDON
+ CreateBattleStartTask(B_TRANSITION_SHARDS, MUS_BATTLE34); // GROUDON
else
- CreateBattleStartTask(B_TRANSITION_RIPPLE, BGM_BATTLE34); // KYOGRE
+ CreateBattleStartTask(B_TRANSITION_RIPPLE, MUS_BATTLE34); // KYOGRE
IncrementGameStat(GAME_STAT_TOTAL_BATTLES);
IncrementGameStat(GAME_STAT_WILD_BATTLES);
@@ -593,7 +590,7 @@ void StartRegiBattle(void)
transitionId = B_TRANSITION_GRID_SQUARES;
break;
}
- CreateBattleStartTask(transitionId, BGM_BATTLE36);
+ CreateBattleStartTask(transitionId, MUS_BATTLE36);
IncrementGameStat(GAME_STAT_TOTAL_BATTLES);
IncrementGameStat(GAME_STAT_WILD_BATTLES);
@@ -1449,46 +1446,46 @@ void SetUpTrainerEncounterMusic(void)
switch (GetTrainerEncounterMusicId(trainerId))
{
case TRAINER_ENCOUNTER_MUSIC_MALE:
- music = BGM_BOYEYE;
+ music = MUS_BOYEYE;
break;
case TRAINER_ENCOUNTER_MUSIC_FEMALE:
- music = BGM_GIRLEYE;
+ music = MUS_GIRLEYE;
break;
case TRAINER_ENCOUNTER_MUSIC_GIRL:
- music = BGM_SYOUJOEYE;
+ music = MUS_SYOUJOEYE;
break;
case TRAINER_ENCOUNTER_MUSIC_INTENSE:
- music = BGM_HAGESHII;
+ music = MUS_HAGESHII;
break;
case TRAINER_ENCOUNTER_MUSIC_COOL:
- music = BGM_KAKKOII;
+ music = MUS_KAKKOII;
break;
case TRAINER_ENCOUNTER_MUSIC_AQUA:
- music = BGM_AQA_0;
+ music = MUS_AQA_0;
break;
case TRAINER_ENCOUNTER_MUSIC_MAGMA:
- music = BGM_MGM0;
+ music = MUS_MGM0;
break;
case TRAINER_ENCOUNTER_MUSIC_SWIMMER:
- music = BGM_SWIMEYE;
+ music = MUS_SWIMEYE;
break;
case TRAINER_ENCOUNTER_MUSIC_TWINS:
- music = BGM_HUTAGO;
+ music = MUS_HUTAGO;
break;
case TRAINER_ENCOUNTER_MUSIC_ELITE_FOUR:
- music = BGM_SITENNOU;
+ music = MUS_SITENNOU;
break;
case TRAINER_ENCOUNTER_MUSIC_HIKER:
- music = BGM_YAMA_EYE;
+ music = MUS_YAMA_EYE;
break;
case TRAINER_ENCOUNTER_MUSIC_INTERVIEWER:
- music = BGM_INTER_V;
+ music = MUS_INTER_V;
break;
case TRAINER_ENCOUNTER_MUSIC_RICH:
- music = BGM_TEST;
+ music = MUS_TEST;
break;
default:
- music = BGM_AYASII;
+ music = MUS_AYASII;
}
PlayNewMapMusic(music);
}
diff --git a/src/berry_blender.c b/src/berry_blender.c
index b1e8712a6..9aa80612c 100644
--- a/src/berry_blender.c
+++ b/src/berry_blender.c
@@ -134,8 +134,6 @@ extern u8 gInGameOpponentsNo;
extern u8 gUnknown_020322D5;
extern u8 gResultsWindowId;
-extern const u8 * const gPokeblockNames[];
-
// graphics
extern const u8 gBerryBlenderArrowTiles[];
extern const u8 gBerryBlenderStartTiles[];
@@ -1305,11 +1303,11 @@ static void sub_8080018(void)
sBerryBlenderData->field_4C = 128;
sBerryBlenderData->gameFrameTime = 0;
SetMainCallback2(sub_8081898);
- if (GetCurrentMapMusic() != BGM_CYCLING)
+ if (GetCurrentMapMusic() != MUS_CYCLING)
{
sBerryBlenderData->field_154 = GetCurrentMapMusic();
}
- PlayBGM(BGM_CYCLING);
+ PlayBGM(MUS_CYCLING);
break;
}
@@ -1604,10 +1602,10 @@ static void sub_80808D4(void)
sBerryBlenderData->field_120[i] = CreateTask(sUnknown_083399EC[i], 10 + i);
}
- if (GetCurrentMapMusic() != BGM_CYCLING)
+ if (GetCurrentMapMusic() != MUS_CYCLING)
sBerryBlenderData->field_154 = GetCurrentMapMusic();
- PlayBGM(BGM_CYCLING);
+ PlayBGM(MUS_CYCLING);
PlaySE(SE_MOTER);
Blender_ControlHitPitch();
break;
@@ -3522,7 +3520,7 @@ static void sub_8083F3C(u8 taskId)
{
if (gTasks[taskId].data[0] == 0)
{
- PlayFanfare(BGM_FANFA1);
+ PlayFanfare(MUS_FANFA1);
gTasks[taskId].data[0]++;
}
if (IsFanfareTaskInactive())
diff --git a/src/bike.c b/src/bike.c
index b97a6dba6..64af7c711 100644
--- a/src/bike.c
+++ b/src/bike.c
@@ -1000,8 +1000,8 @@ void GetOnOffBike(u8 transitionFlags)
else
{
SetPlayerAvatarTransitionFlags(transitionFlags);
- Overworld_SetSavedMusic(BGM_CYCLING);
- Overworld_ChangeMusicTo(BGM_CYCLING);
+ Overworld_SetSavedMusic(MUS_CYCLING);
+ Overworld_ChangeMusicTo(MUS_CYCLING);
}
}
diff --git a/src/daycare.c b/src/daycare.c
index ce9952531..59ee562bd 100644
--- a/src/daycare.c
+++ b/src/daycare.c
@@ -40,7 +40,7 @@ extern const u8 gDaycareText_PlayOther[];
extern u8 GetCursorSelectionMonId(void);
extern u16 ItemIdToBattleMoveId(u16);
-extern s32 ListMenuHandleInput(u8);
+extern s32 ListMenuHandleInputGetItemId(u8);
extern void sub_81AE6C8(u8, u16*, u16*);
extern void sub_819746C(u8, bool8);
extern void sub_81973FC(u8, bool8);
@@ -75,7 +75,7 @@ static const struct ListMenuItem sLevelMenuItems[] =
static const struct ListMenuTemplate sDaycareListMenuLevelTemplate =
{
.items = sLevelMenuItems,
- .unk_04 = sub_81AF078,
+ .moveCursorFunc = sub_81AF078,
.unk_08 = DaycarePrintMonInfo,
.totalItems = 3,
.maxShowed = 3,
@@ -90,7 +90,8 @@ static const struct ListMenuTemplate sDaycareListMenuLevelTemplate =
.unk_16_0 = TRUE,
.spaceBetweenItems = 0,
.unk_16_7 = FALSE,
- .unk_17_0 = 1
+ .unk_17_0 = 1,
+ .cursorKind = 0
};
static const u8 *const sCompatibilityMessages[] =
@@ -1256,7 +1257,7 @@ static void DaycarePrintMonInfo(u8 windowId, s32 daycareSlotId, u8 y)
static void Task_HandleDaycareLevelMenuInput(u8 taskId)
{
- u32 var = ListMenuHandleInput(gTasks[taskId].tMenuListTaskId);
+ u32 var = ListMenuHandleInputGetItemId(gTasks[taskId].tMenuListTaskId);
if (gMain.newKeys & A_BUTTON)
{
diff --git a/src/decoration.c b/src/decoration.c
index 987e628c5..faef779b7 100644
--- a/src/decoration.c
+++ b/src/decoration.c
@@ -792,17 +792,17 @@ void sub_8127330(u8 taskId)
for (i = 0; i < sDecorPCBuffer->unk_520 - 1; i ++)
{
sub_8127454(sDecorPCBuffer->names[i], gCurDecorInventoryItems[i]);
- sDecorPCBuffer->items[i].unk_00 = sDecorPCBuffer->names[i];
- sDecorPCBuffer->items[i].unk_04 = i;
+ sDecorPCBuffer->items[i].name = sDecorPCBuffer->names[i];
+ sDecorPCBuffer->items[i].id = i;
}
StringCopy(sDecorPCBuffer->names[i], gText_Cancel);
- sDecorPCBuffer->items[i].unk_00 = sDecorPCBuffer->names[i];
- sDecorPCBuffer->items[i].unk_04 = -2;
- gUnknown_03006310 = gUnknown_085A6BD0;
- gUnknown_03006310.unk_10 = sDecorMenuWindowIndices[1];
- gUnknown_03006310.totalItems = sDecorPCBuffer->unk_520;
- gUnknown_03006310.items = sDecorPCBuffer->items;
- gUnknown_03006310.maxShowed = sDecorPCBuffer->unk_521;
+ sDecorPCBuffer->items[i].name = sDecorPCBuffer->names[i];
+ sDecorPCBuffer->items[i].id = -2;
+ gMultiuseListMenuTemplate = gUnknown_085A6BD0;
+ gMultiuseListMenuTemplate.unk_10 = sDecorMenuWindowIndices[1];
+ gMultiuseListMenuTemplate.totalItems = sDecorPCBuffer->unk_520;
+ gMultiuseListMenuTemplate.items = sDecorPCBuffer->items;
+ gMultiuseListMenuTemplate.maxShowed = sDecorPCBuffer->unk_521;
}
void sub_8127454(u8 *dest, u16 decorId)
@@ -871,7 +871,7 @@ void sub_812759C(u8 taskId)
sub_81272C8();
sub_81272F8();
sub_8127330(taskId);
- data[13] = ListMenuInit(&gUnknown_03006310, sSecretBasePCSelectDecorPageNo, sSecretBasePCSelectDecorLineNo);
+ data[13] = ListMenuInit(&gMultiuseListMenuTemplate, sSecretBasePCSelectDecorPageNo, sSecretBasePCSelectDecorLineNo);
sub_8127500();
}
@@ -889,8 +889,8 @@ void sub_812764C(u8 taskId)
data = gTasks[taskId].data;
if (!gPaletteFade.active)
{
- input = ListMenuHandleInput(data[13]);
- get_coro_args_x18_x1A(data[13], &sSecretBasePCSelectDecorPageNo, &sSecretBasePCSelectDecorLineNo);
+ input = ListMenuHandleInputGetItemId(data[13]);
+ sub_81AE860(data[13], &sSecretBasePCSelectDecorPageNo, &sSecretBasePCSelectDecorLineNo);
switch (input)
{
case -1:
diff --git a/src/egg_hatch.c b/src/egg_hatch.c
index 7418fa72d..721ba4a4f 100644
--- a/src/egg_hatch.c
+++ b/src/egg_hatch.c
@@ -91,7 +91,7 @@ static void CreateRandomEggShardSprite(void);
static void CreateEggShardSprite(u8 x, u8 y, s16 data1, s16 data2, s16 data3, u8 spriteAnimIndex);
// IWRAM bss
-static IWRAM_DATA struct EggHatchData* sEggHatchData;
+static IWRAM_DATA struct EggHatchData *sEggHatchData;
// rom data
static const u16 sEggPalette[] = INCBIN_U16("graphics/pokemon/palettes/egg_palette.gbapal");
diff --git a/src/evolution_scene.c b/src/evolution_scene.c
index ea5c77399..85310eace 100644
--- a/src/evolution_scene.c
+++ b/src/evolution_scene.c
@@ -594,14 +594,14 @@ static void Task_EvolutionScene(u8 taskID)
case 3:
if (EvoScene_IsMonAnimFinished(sEvoStructPtr->preEvoSpriteID)) // wait for animation, play tu du SE
{
- PlaySE(BGM_ME_SHINKA);
+ PlaySE(MUS_ME_SHINKA);
gTasks[taskID].tState++;
}
break;
case 4: // play evolution music and fade screen black
if (!IsSEPlaying())
{
- PlayNewMapMusic(BGM_SHINKA);
+ PlayNewMapMusic(MUS_SHINKA);
gTasks[taskID].tState++;
BeginNormalPaletteFade(0x1C, 4, 0, 0x10, 0);
}
@@ -677,7 +677,7 @@ static void Task_EvolutionScene(u8 taskID)
{
StringExpandPlaceholders(gStringVar4, gText_CongratsPkmnEvolved);
BattleHandleAddTextPrinter(gStringVar4, 0);
- PlayBGM(BGM_FANFA5);
+ PlayBGM(MUS_FANFA5);
gTasks[taskID].tState++;
SetMonData(mon, MON_DATA_SPECIES, (void*)(&gTasks[taskID].tPostEvoSpecies));
CalculateMonStats(mon);
@@ -772,7 +772,7 @@ static void Task_EvolutionScene(u8 taskID)
if (!IsTextPrinterActive(0) && !IsSEPlaying())
{
BufferMoveToLearnIntoBattleTextBuff2();
- PlayFanfare(BGM_FANFA1);
+ PlayFanfare(MUS_FANFA1);
BattleStringExpandPlaceholdersToDisplayedString(gBattleStringsTable[STRINGID_PKMNLEARNEDMOVE - BATTLESTRINGS_ID_ADDER]);
BattleHandleAddTextPrinter(gDisplayedStringBattle, 0);
gTasks[taskID].tLearnsFirstMove = 0x40; // re-used as a counter
@@ -962,15 +962,15 @@ static void Task_TradeEvolutionScene(u8 taskID)
case 2:
if (IsCryFinished())
{
- m4aSongNumStop(BGM_SHINKA);
- PlaySE(BGM_ME_SHINKA);
+ m4aSongNumStop(MUS_SHINKA);
+ PlaySE(MUS_ME_SHINKA);
gTasks[taskID].tState++;
}
break;
case 3:
if (!IsSEPlaying())
{
- PlayBGM(BGM_SHINKA);
+ PlayBGM(MUS_SHINKA);
gTasks[taskID].tState++;
BeginNormalPaletteFade(0x1C, 4, 0, 0x10, 0);
}
@@ -1040,7 +1040,7 @@ static void Task_TradeEvolutionScene(u8 taskID)
{
StringExpandPlaceholders(gStringVar4, gText_CongratsPkmnEvolved);
sub_807F1A8(0, gStringVar4, 1);
- PlayFanfare(BGM_FANFA5);
+ PlayFanfare(MUS_FANFA5);
gTasks[taskID].tState++;
SetMonData(mon, MON_DATA_SPECIES, (&gTasks[taskID].tPostEvoSpecies));
CalculateMonStats(mon);
@@ -1073,7 +1073,7 @@ static void Task_TradeEvolutionScene(u8 taskID)
}
else
{
- PlayBGM(BGM_SHINKA);
+ PlayBGM(MUS_SHINKA);
sub_807F1A8(0, gText_CommunicationStandby5, 1);
gTasks[taskID].tState++;
}
@@ -1117,7 +1117,7 @@ static void Task_TradeEvolutionScene(u8 taskID)
if (!IsTextPrinterActive(0) && !IsSEPlaying())
{
BufferMoveToLearnIntoBattleTextBuff2();
- PlayFanfare(BGM_FANFA1);
+ PlayFanfare(MUS_FANFA1);
BattleStringExpandPlaceholdersToDisplayedString(gBattleStringsTable[STRINGID_PKMNLEARNEDMOVE - BATTLESTRINGS_ID_ADDER]);
sub_807F1A8(0, gDisplayedStringBattle, 1);
gTasks[taskID].tLearnsFirstMove = 0x40; // re-used as a counter
diff --git a/src/field_map_obj.c b/src/field_map_obj.c
index 6a99890a4..df80494b3 100755
--- a/src/field_map_obj.c
+++ b/src/field_map_obj.c
@@ -1174,11 +1174,11 @@ void npc_by_local_id_and_map_set_field_1_bit_x20(u8 localId, u8 mapNum, u8 mapGr
}
}
-void FieldObjectGetLocalIdAndMap(struct MapObject *mapObject, u8 *localId, u8 *mapNum, u8 *mapGroup)
+void FieldObjectGetLocalIdAndMap(struct MapObject *mapObject, void *localId, void *mapNum, void *mapGroup)
{
- *localId = mapObject->localId;
- *mapNum = mapObject->mapNum;
- *mapGroup = mapObject->mapGroup;
+ *(u8*)(localId) = mapObject->localId;
+ *(u8*)(mapNum) = mapObject->mapNum;
+ *(u8*)(mapGroup) = mapObject->mapGroup;
}
void sub_808E75C(s16 x, s16 y)
@@ -3231,7 +3231,7 @@ bool8 mss_npc_reset_oampriv3_1_unk2_unk3(struct MapObject *mapObject, struct Spr
bool8 sub_8091EC0(struct MapObject *mapObject, struct Sprite *sprite)
{
- if (gMapObjects[gPlayerAvatar.mapObjectId].mapobj_unk_1C == 0xFF || gPlayerAvatar.running1 == 2)
+ if (gMapObjects[gPlayerAvatar.mapObjectId].mapobj_unk_1C == 0xFF || gPlayerAvatar.tileTransitionState == 2)
{
return FALSE;
}
@@ -3410,7 +3410,7 @@ field_object_step(CopyPlayer2, gUnknown_0850DA90)
bool8 mss_08062EA4(struct MapObject *mapObject, struct Sprite *sprite)
{
- if (gMapObjects[gPlayerAvatar.mapObjectId].mapobj_unk_1C == 0xFF || gPlayerAvatar.running1 == 2)
+ if (gMapObjects[gPlayerAvatar.mapObjectId].mapobj_unk_1C == 0xFF || gPlayerAvatar.tileTransitionState == 2)
{
return FALSE;
}
@@ -3426,7 +3426,7 @@ void FieldObjectCB_TreeDisguise(struct Sprite *sprite)
mapObject = &gMapObjects[sprite->data[0]];
if (mapObject->mapobj_unk_21 == 0 || (mapObject->mapobj_unk_21 == 1 && !sprite->data[7]))
{
- FieldObjectGetLocalIdAndMap(mapObject, (u8 *)&gFieldEffectArguments[0], (u8 *)&gFieldEffectArguments[1], (u8 *)&gFieldEffectArguments[2]);
+ FieldObjectGetLocalIdAndMap(mapObject, &gFieldEffectArguments[0], &gFieldEffectArguments[1], &gFieldEffectArguments[2]);
mapObject->mapobj_unk_1A = FieldEffectStart(FLDEFF_TREE_DISGUISE);
mapObject->mapobj_unk_21 = 1;
sprite->data[7] ++;
@@ -3447,7 +3447,7 @@ void FieldObjectCB_MountainDisguise(struct Sprite *sprite)
mapObject = &gMapObjects[sprite->data[0]];
if (mapObject->mapobj_unk_21 == 0 || (mapObject->mapobj_unk_21 == 1 && !sprite->data[7]))
{
- FieldObjectGetLocalIdAndMap(mapObject, (u8 *)&gFieldEffectArguments[0], (u8 *)&gFieldEffectArguments[1], (u8 *)&gFieldEffectArguments[2]);
+ FieldObjectGetLocalIdAndMap(mapObject, &gFieldEffectArguments[0], &gFieldEffectArguments[1], &gFieldEffectArguments[2]);
mapObject->mapobj_unk_1A = FieldEffectStart(FLDEFF_MOUNTAIN_DISGUISE);
mapObject->mapobj_unk_21 = 1;
sprite->data[7] ++;
@@ -4694,7 +4694,7 @@ bool8 sub_80954CC(struct MapObject *mapObject, struct Sprite *sprite)
bool8 do_exclamation_mark_bubble_1(struct MapObject *mapObject, struct Sprite *sprite)
{
- FieldObjectGetLocalIdAndMap(mapObject, (u8 *)&gFieldEffectArguments[0], (u8 *)&gFieldEffectArguments[1], (u8 *)&gFieldEffectArguments[2]);
+ FieldObjectGetLocalIdAndMap(mapObject, &gFieldEffectArguments[0], &gFieldEffectArguments[1], &gFieldEffectArguments[2]);
FieldEffectStart(FLDEFF_EXCLAMATION_MARK_ICON_1);
sprite->data[2] = 1;
return TRUE;
@@ -4702,7 +4702,7 @@ bool8 do_exclamation_mark_bubble_1(struct MapObject *mapObject, struct Sprite *s
bool8 do_exclamation_mark_bubble_2(struct MapObject *mapObject, struct Sprite *sprite)
{
- FieldObjectGetLocalIdAndMap(mapObject, (u8 *)&gFieldEffectArguments[0], (u8 *)&gFieldEffectArguments[1], (u8 *)&gFieldEffectArguments[2]);
+ FieldObjectGetLocalIdAndMap(mapObject, &gFieldEffectArguments[0], &gFieldEffectArguments[1], &gFieldEffectArguments[2]);
FieldEffectStart(FLDEFF_EXCLAMATION_MARK_ICON_2);
sprite->data[2] = 1;
return TRUE;
@@ -4710,7 +4710,7 @@ bool8 do_exclamation_mark_bubble_2(struct MapObject *mapObject, struct Sprite *s
bool8 do_heart_bubble(struct MapObject *mapObject, struct Sprite *sprite)
{
- FieldObjectGetLocalIdAndMap(mapObject, (u8 *)&gFieldEffectArguments[0], (u8 *)&gFieldEffectArguments[1], (u8 *)&gFieldEffectArguments[2]);
+ FieldObjectGetLocalIdAndMap(mapObject, &gFieldEffectArguments[0], &gFieldEffectArguments[1], &gFieldEffectArguments[2]);
FieldEffectStart(FLDEFF_HEART_ICON);
sprite->data[2] = 1;
return TRUE;
diff --git a/src/field_special_scene.c b/src/field_special_scene.c
index d46ddeaa6..a704beaab 100755
--- a/src/field_special_scene.c
+++ b/src/field_special_scene.c
@@ -211,7 +211,7 @@ void Task_HandleTruckSequence(u8 taskId)
data[1]++;
if (data[1] == 90)
{
- PlaySE(SE_TRACK_HAIK);
+ PlaySE(SE_TRACK_HAIKI);
data[1] = 0;
data[0] = 5;
}
diff --git a/src/hall_of_fame.c b/src/hall_of_fame.c
index 239c5d690..2496b9564 100644
--- a/src/hall_of_fame.c
+++ b/src/hall_of_fame.c
@@ -424,7 +424,7 @@ static bool8 InitHallOfFameScreen(void)
if (!gPaletteFade.active)
{
SetMainCallback2(CB2_HallOfFame);
- PlayBGM(BGM_DENDOU);
+ PlayBGM(MUS_DENDOU);
return FALSE;
}
break;
diff --git a/src/lilycove_lady.c b/src/lilycove_lady.c
index 18fbdd64c..927b87c72 100644
--- a/src/lilycove_lady.c
+++ b/src/lilycove_lady.c
@@ -943,7 +943,7 @@ static void sub_818E6B0(u8 sheen)
}
}
-bool8 sub_818E704(struct Pokeblock *pokeblock)
+bool8 GivePokeblockToContestLady(struct Pokeblock *pokeblock)
{
u8 sheen;
bool8 response;
@@ -1079,7 +1079,7 @@ void sub_818E914(void)
void sub_818E92C(void)
{
- sub_81357FC(3, c2_exit_to_overworld_2_switch);
+ OpenPokeblockCase(3, c2_exit_to_overworld_2_switch);
}
void sub_818E940(void)
diff --git a/src/new_game.c b/src/new_game.c
index 12873fec9..89771e92b 100644
--- a/src/new_game.c
+++ b/src/new_game.c
@@ -33,7 +33,6 @@ extern void Overworld_SetWarpDestination(s8 mapBank, s8 mapNo, s8 warpNo, s8 xPo
extern void warp_in(void);
extern void sub_80BB358(void);
extern void ResetBagScrollPositions(void);
-extern void sub_813624C(void); // clears something pokeblock related
extern void ResetPokedex(void);
extern void sub_8084400(void);
extern void ClearMailData(void);
@@ -148,7 +147,7 @@ void sub_808447C(void)
ZeroPlayerPartyMons();
ZeroEnemyPartyMons();
ResetBagScrollPositions();
- sub_813624C();
+ ResetPokeblockScrollPositions();
}
void NewGameInitData(void)
diff --git a/src/pokeball.c b/src/pokeball.c
index 127ba8e9d..13969a5d1 100644
--- a/src/pokeball.c
+++ b/src/pokeball.c
@@ -885,7 +885,7 @@ static void sub_80760F8(struct Sprite *sprite)
{
gDoingBattleAnim = FALSE;
m4aMPlayAllStop();
- PlaySE(BGM_FANFA5);
+ PlaySE(MUS_FANFA5);
}
else if (sprite->data[4] == 315)
{
diff --git a/src/pokeblock.c b/src/pokeblock.c
new file mode 100644
index 000000000..737f2c6f3
--- /dev/null
+++ b/src/pokeblock.c
@@ -0,0 +1,1337 @@
+#include "global.h"
+#include "pokeblock.h"
+#include "bg.h"
+#include "strings.h"
+#include "text.h"
+#include "menu.h"
+#include "task.h"
+#include "menu_helpers.h"
+#include "new_menu_helpers.h"
+#include "pokemon.h"
+#include "graphics.h"
+#include "malloc.h"
+#include "main.h"
+#include "battle.h"
+#include "battle_controllers.h"
+#include "palette.h"
+#include "unknown_task.h"
+#include "list_menu.h"
+#include "gpu_regs.h"
+#include "decompress.h"
+#include "international_string_util.h"
+#include "item.h"
+#include "constants/items.h"
+#include "string_util.h"
+#include "constants/songs.h"
+#include "sound.h"
+#include "berry.h"
+#include "menu_indicators.h"
+#include "event_data.h"
+#include "battle_message.h"
+#include "safari_zone.h"
+#include "lilycove_lady.h"
+
+#define POKEBLOCK_MAX_FEEL 99
+#define FIELD_E75_COUNT 7
+
+struct PokeblockMenuStruct
+{
+ u8 tilemap[0x800];
+ void (*callbackOnUse)(void);
+ const u8 *pokeblockOptionsIds;
+ u8 optionsNo;
+ u8 caseId;
+ u8 itemsNo;
+ u8 maxShowed;
+ struct ListMenuItem items[POKEBLOCKS_COUNT + 1];
+ u8 menuItemsStrings[POKEBLOCKS_COUNT + 1][0x20]; // + 1 because of STOW CASE item
+ u8 pokeblockCaseSpriteId;
+ u8 field_E75[FIELD_E75_COUNT];
+ u8 unkTaskId;
+ bool8 isSwapping;
+ s16 gfxState;
+ u8 unused[8];
+};
+
+struct PokeblockSavedData
+{
+ void (*callback)(void);
+ u16 lastItemPos;
+ u16 lastItemPage;
+};
+
+enum
+{
+ PKBL_USE_ON_FIELD,
+ PKBL_TOSS,
+ PKBL_CANCEL,
+ PKBL_USE_IN_BATTLE,
+ PKBL_USE_ON_FEEDER,
+ PKBL_GIVE_TO_LADY
+};
+
+extern u16 gSpecialVar_ItemId;
+extern void (*gFieldCallback)(void);
+
+extern const u16 gUnknown_0860F074[];
+
+extern void c2_exit_to_overworld_2_switch(void);
+extern bool8 sub_81221EC(void);
+extern void sub_809882C(u8, u16, u8);
+extern void copy_textbox_border_tile_patterns_to_vram(u8, u16, u8);
+extern void sub_80AF168(void);
+
+// this file's functions
+static void CB2_InitPokeblockMenu(void);
+static bool8 InitPokeblockMenu(void);
+static bool8 LoadPokeblockMenuGfx(void);
+static void HandleInitBackgrounds(void);
+static void HandleInitWindows(void);
+static void SetMenuItemsCountAndMaxShowed(void);
+static void sub_81362E0(void);
+static void sub_8136344(void);
+static void HandlePokeblockListMenuItems(void);
+static void sub_81363BC(void);
+static void MovePokeblockMenuCursor(u32 pkblId, bool8 arg1, struct ListMenu *arg2);
+static void PutPokeblockInfoText(void);
+static void HandlePokeblockMenuCursor(u16 cursorPos, u16 arg1);
+static void PutPokeblockListMenuString(u8 *dst, u16 pkblId);
+static void Task_HandlePokeblockMenuInput(u8 taskId);
+static void PokeblockAction_UseOnField(u8 taskId);
+static void PokeblockAction_Toss(u8 taskId);
+static void PokeblockAction_Cancel(u8 taskId);
+static void PokeblockAction_UseInBattle(u8 taskId);
+static void PokeblockAction_UseOnPokeblockFeeder(u8 taskId);
+static void PokeblockAction_GiveToContestLady(u8 taskId);
+static void TossPokeblockChoice_Yes(u8 taskId);
+static void TossPokeblockChoice_No(u8 taskId);
+static void Task_FreeDataAndExitPokeblockCase(u8 taskId);
+static void Task_HandlePokeblockOptionsInput(u8 taskId);
+static void PutPokeblockOptionsWindow(u8 taskId);
+static void Task_HandlePokeblocksSwapInput(u8 taskId);
+static void sub_8136470(struct Sprite *sprite);
+static void sub_8135FCC(s32 pkblId);
+static void HandlePokeblocksSwap(u8 taskId, bool8 noSwap);
+static void UsePokeblockOnField(void);
+static void ReturnToPokeblockCaseOnField(void);
+static void CreateTossPokeblockYesNoMenu(u8 taskId);
+static void HandleErasePokeblock(u8 taskId);
+
+// ram variables
+EWRAM_DATA static struct PokeblockSavedData sSavedPokeblockData = {0};
+EWRAM_DATA static struct PokeblockMenuStruct *sPokeblockMenu = NULL;
+
+// const rom data
+const s8 gPokeblockFlavorCompatibilityTable[] =
+{
+ // Cool, Beauty, Cute, Smart, Tough
+ 0, 0, 0, 0, 0, // Hardy
+ 1, 0, 0, 0, -1, // Lonely
+ 1, 0, -1, 0, 0, // Brave
+ 1, -1, 0, 0, 0, // Adamant
+ 1, 0, 0, -1, 0, // Naughty
+ -1, 0, 0, 0, 1, // Bold
+ 0, 0, 0, 0, 0, // Docile
+ 0, 0, -1, 0, 1, // Relaxed
+ 0, -1, 0, 0, 1, // Impish
+ 0, 0, 0, -1, 1, // Lax
+ -1, 0, 1, 0, 0, // Timid
+ 0, 0, 1, 0, -1, // Hasty
+ 0, 0, 0, 0, 0, // Serious
+ 0, -1, 1, 0, 0, // Jolly
+ 0, 0, 1, -1, 0, // Naive
+ -1, 1, 0, 0, 0, // Modest
+ 0, 1, 0, 0, -1, // Mild
+ 0, 1, -1, 0, 0, // Quiet
+ 0, 0, 0, 0, 0, // Bashful
+ 0, 1, 0, -1, 0, // Rash
+ -1, 0, 0, 1, 0, // Calm
+ 0, 0, 0, 1, -1, // Gentle
+ 0, 0, -1, 1, 0, // Sassy
+ 0, -1, 0, 1, 0, // Careful
+ 0, 0, 0, 0, 0 // Quirky
+};
+
+static const struct BgTemplate sBgTemplatesForPokeblockMenu[] =
+{
+ {
+ .bg = 0,
+ .charBaseIndex = 0,
+ .mapBaseIndex = 31,
+ .screenSize = 0,
+ .paletteMode = 0,
+ .priority = 1,
+ .baseTile = 0
+ },
+ {
+ .bg = 1,
+ .charBaseIndex = 0,
+ .mapBaseIndex = 30,
+ .screenSize = 0,
+ .paletteMode = 0,
+ .priority = 0,
+ .baseTile = 0
+ },
+ {
+ .bg = 2,
+ .charBaseIndex = 3,
+ .mapBaseIndex = 29,
+ .screenSize = 0,
+ .paletteMode = 0,
+ .priority = 2,
+ .baseTile = 0
+ }
+};
+
+const u8 *const gPokeblockNames[] =
+{
+ NULL,
+ gText_RedPokeblock,
+ gText_BluePokeblock,
+ gText_PinkPokeblock,
+ gText_GreenPokeblock,
+ gText_YellowPokeblock,
+ gText_PurplePokeblock,
+ gText_IndigoPokeblock,
+ gText_BrownPokeblock,
+ gText_LiteBluePokeblock,
+ gText_OlivePokeblock,
+ gText_GrayPokeblock,
+ gText_BlackPokeblock,
+ gText_WhitePokeblock,
+ gText_GoldPokeblock
+};
+
+static const struct MenuAction sPokeblockMenuActions[] =
+{
+ {gMenuText_Use, PokeblockAction_UseOnField},
+ {gMenuText_Toss, PokeblockAction_Toss},
+ {gText_Cancel2, PokeblockAction_Cancel},
+ {gMenuText_Use, PokeblockAction_UseInBattle},
+ {gMenuText_Use, PokeblockAction_UseOnPokeblockFeeder},
+ {gMenuText_Give2, PokeblockAction_GiveToContestLady},
+};
+
+static const u8 sActionsOnField[] = {PKBL_USE_ON_FIELD, PKBL_TOSS, PKBL_CANCEL};
+static const u8 sActionsInBattle[] = {PKBL_USE_IN_BATTLE, PKBL_CANCEL};
+static const u8 sActionsOnPokeblockFeeder[] = {PKBL_USE_ON_FEEDER, PKBL_CANCEL};
+static const u8 sActionsWhenGivingToLady[] = {PKBL_GIVE_TO_LADY, PKBL_CANCEL};
+
+static const struct YesNoFuncTable sTossYesNoFuncTable = {TossPokeblockChoice_Yes, TossPokeblockChoice_No};
+
+static const u8 sContestStatsMonData[] = {MON_DATA_COOL, MON_DATA_BEAUTY, MON_DATA_CUTE, MON_DATA_SMART, MON_DATA_TOUGH};
+
+static const struct OamData sOamData_PokeblockCase =
+{
+ .y = 0,
+ .affineMode = 0,
+ .objMode = 0,
+ .mosaic = 0,
+ .bpp = 0,
+ .shape = 0,
+ .x = 0,
+ .matrixNum = 0,
+ .size = 3,
+ .tileNum = 0,
+ .priority = 2,
+ .paletteNum = 0,
+ .affineParam = 0,
+};
+
+static const union AnimCmd sSpriteAnim_PokeblockCase[] =
+{
+ ANIMCMD_FRAME(0, 0),
+ ANIMCMD_END
+};
+
+static const union AnimCmd *const sSpriteAnimTable_PokeblockCase[] =
+{
+ sSpriteAnim_PokeblockCase
+};
+
+static const union AffineAnimCmd sSpriteAffineAnim_85B26C8[] =
+{
+ AFFINEANIMCMD_FRAME(0, 0, -2, 2),
+ AFFINEANIMCMD_FRAME(0, 0, 2, 4),
+ AFFINEANIMCMD_FRAME(0, 0, -2, 4),
+ AFFINEANIMCMD_FRAME(0, 0, 2, 2),
+ AFFINEANIMCMD_END
+};
+
+static const union AffineAnimCmd *const sSpriteAffineAnimTable_85B26F0[] =
+{
+ sSpriteAffineAnim_85B26C8
+};
+
+const struct CompressedSpriteSheet gPokeblockCase_SpriteSheet =
+{
+ gMenuPokeblockDevice_Gfx, 0x800, GFX_TAG_POKEBLOCK_CASE
+};
+
+const struct CompressedSpritePalette gPokeblockCase_SpritePal =
+{
+ gMenuPokeblockDevice_Pal, GFX_TAG_POKEBLOCK_CASE
+};
+
+static const struct SpriteTemplate sSpriteTemplate_PokeblockCase =
+{
+ GFX_TAG_POKEBLOCK_CASE,
+ GFX_TAG_POKEBLOCK_CASE,
+ &sOamData_PokeblockCase,
+ sSpriteAnimTable_PokeblockCase,
+ NULL,
+ gDummySpriteAffineAnimTable,
+ SpriteCallbackDummy
+};
+
+static const struct TextColor sTextColorInPokeblockMenu = {0, 2, 3};
+
+static const struct Pokeblock sFavoritePokeblocksTable[] =
+{
+ { PBLOCK_CLR_RED, 20, 0, 0, 0, 0, 20},
+ { PBLOCK_CLR_BLUE, 0, 20, 0, 0, 0, 20},
+ { PBLOCK_CLR_PINK, 0, 0, 20, 0, 0, 20},
+ { PBLOCK_CLR_GREEN, 0, 0, 0, 20, 0, 20},
+ { PBLOCK_CLR_YELLOW, 0, 0, 0, 0, 20, 20}
+};
+
+static const struct WindowTemplate sWindowTemplatesForPokeblockMenu[] =
+{
+ {0, 2, 1, 9, 2, 0xF, 0x1E},
+ {0, 0xF, 1, 0xE, 0x12, 0xF, 0x30},
+ {0, 2, 0xD, 5, 2, 0xF, 0x12C},
+ {0, 2, 0xF, 5, 2, 0xF, 0x136},
+ {0, 2, 0x11, 5, 2, 0xF, 0x140},
+ {0, 8, 0xD, 5, 2, 0xF, 0x14A},
+ {0, 8, 0xF, 5, 2, 0xF, 0x154},
+ {0, 0xB, 0x11, 2, 2, 0xF, 0x15E},
+ {1, 7, 5, 6, 6, 0xF, 0x162},
+ {1, 7, 7, 6, 4, 0xF, 0x186},
+ {1, 2, 0xF, 0x1B, 4, 0xF, 0x19E},
+ DUMMY_WIN_TEMPLATE
+};
+
+static const struct WindowTemplate sTossPkblockWindowTemplate = {1, 0x15, 9, 5, 4, 0xF, 0x20A};
+
+static const struct ListMenuTemplate sPokeblockListMenuTemplate =
+{
+ .items = NULL,
+ .moveCursorFunc = MovePokeblockMenuCursor,
+ .unk_08 = NULL,
+ .totalItems = 0,
+ .maxShowed = 0,
+ .unk_10 = 1,
+ .unk_11 = 0,
+ .unk_12 = 1,
+ .cursor_Y = 0,
+ .upText_Y = 1,
+ .cursorColor = 2,
+ .fillColor = 0,
+ .cursorShadowColor = 3,
+ .unk_16_0 = FALSE,
+ .spaceBetweenItems = 32,
+ .unk_16_7 = FALSE,
+ .unk_17_0 = 1,
+ .cursorKind = 1
+};
+
+// code
+void OpenPokeblockCase(u8 caseId, void (*callback)(void))
+{
+ sPokeblockMenu = Alloc(sizeof(*sPokeblockMenu));
+ sPokeblockMenu->caseId = caseId;
+ sPokeblockMenu->callbackOnUse = NULL;
+ sPokeblockMenu->unkTaskId = 0xFF;
+ sPokeblockMenu->isSwapping = FALSE;
+ sSavedPokeblockData.callback = callback;
+
+ switch (sPokeblockMenu->caseId)
+ {
+ case PBLOCK_CASE_BATTLE:
+ sPokeblockMenu->pokeblockOptionsIds = sActionsInBattle;
+ sPokeblockMenu->optionsNo = ARRAY_COUNT(sActionsInBattle);
+ break;
+ case PBLOCK_CASE_FEEDER:
+ sPokeblockMenu->pokeblockOptionsIds = sActionsOnPokeblockFeeder;
+ sPokeblockMenu->optionsNo = ARRAY_COUNT(sActionsOnPokeblockFeeder);
+ break;
+ case PBLOCK_CASE_GIVE:
+ sPokeblockMenu->pokeblockOptionsIds = sActionsWhenGivingToLady;
+ sPokeblockMenu->optionsNo = ARRAY_COUNT(sActionsWhenGivingToLady);
+ break;
+ default:
+ sPokeblockMenu->pokeblockOptionsIds = sActionsOnField;
+ sPokeblockMenu->optionsNo = ARRAY_COUNT(sActionsOnField);
+ break;
+ }
+
+ SetMainCallback2(CB2_InitPokeblockMenu);
+}
+
+void OpenPokeblockCaseInBattle(void)
+{
+ OpenPokeblockCase(PBLOCK_CASE_BATTLE, SetCB2ToReshowScreenAfterMenu2);
+}
+
+void OpenPokeblockCaseOnFeeder(void)
+{
+ OpenPokeblockCase(PBLOCK_CASE_FEEDER, c2_exit_to_overworld_2_switch);
+}
+
+static void CB2_PokeblockMenu(void)
+{
+ RunTasks();
+ AnimateSprites();
+ BuildOamBuffer();
+ do_scheduled_bg_tilemap_copies_to_vram();
+ UpdatePaletteFade();
+}
+
+static void VBlankCB_PokeblockMenu(void)
+{
+ LoadOam();
+ ProcessSpriteCopyRequests();
+ TransferPlttBuffer();
+}
+
+static void CB2_InitPokeblockMenu(void)
+{
+ while (1)
+ {
+ if (sub_81221EC() == TRUE)
+ break;
+ if (InitPokeblockMenu() == TRUE)
+ break;
+ if (sub_81221AC() == TRUE)
+ break;
+ }
+}
+
+static bool8 InitPokeblockMenu(void)
+{
+ u8 taskId;
+
+ switch (gMain.state)
+ {
+ case 0:
+ SetVBlankHBlankCallbacksToNull();
+ clear_scheduled_bg_copies_to_vram();
+ gMain.state++;
+ break;
+ case 1:
+ remove_some_task();
+ gMain.state++;
+ break;
+ case 2:
+ FreeAllSpritePalettes();
+ gMain.state++;
+ break;
+ case 3:
+ ResetPaletteFade();
+ gPaletteFade.bufferTransferDisabled = 1;
+ gMain.state++;
+ break;
+ case 4:
+ ResetSpriteData();
+ gMain.state++;
+ break;
+ case 5:
+ if (sPokeblockMenu->caseId != PBLOCK_CASE_BATTLE)
+ ResetTasks();
+ gMain.state++;
+ break;
+ case 6:
+ HandleInitBackgrounds();
+ sPokeblockMenu->gfxState = 0;
+ gMain.state++;
+ break;
+ case 7:
+ if (!LoadPokeblockMenuGfx())
+ return FALSE;
+ gMain.state++;
+ break;
+ case 8:
+ SetMenuItemsCountAndMaxShowed();
+ sub_81362E0();
+ sub_8136344();
+ gMain.state++;
+ break;
+ case 9:
+ sPokeblockMenu->pokeblockCaseSpriteId = CreatePokeblockCaseSprite(56, 64, 0);
+ gMain.state++;
+ break;
+ case 10:
+ sub_8122344(&sPokeblockMenu->field_E75, FIELD_E75_COUNT);
+ gMain.state++;
+ break;
+ case 11:
+ HandlePokeblockMenuCursor(sSavedPokeblockData.lastItemPos, 0x1005);
+ gMain.state++;
+ break;
+ case 12:
+ HandleInitWindows();
+ gMain.state++;
+ break;
+ case 13:
+ HandlePokeblockListMenuItems();
+ gMain.state++;
+ break;
+ case 14:
+ sub_81363BC();
+ gMain.state++;
+ break;
+ case 15:
+ taskId = CreateTask(Task_HandlePokeblockMenuInput, 0);
+ gTasks[taskId].data[0] = ListMenuInit(&gMultiuseListMenuTemplate, sSavedPokeblockData.lastItemPage, sSavedPokeblockData.lastItemPos);
+ gMain.state++;
+ break;
+ case 16:
+ PutPokeblockInfoText();
+ gMain.state++;
+ break;
+ case 17:
+ BlendPalettes(-1, 0x10, 0);
+ gMain.state++;
+ break;
+ case 18:
+ BeginNormalPaletteFade(-1, 0, 0x10, 0, 0);
+ gPaletteFade.bufferTransferDisabled = 0;
+ gMain.state++;
+ break;
+ default:
+ SetVBlankCallback(VBlankCB_PokeblockMenu);
+ SetMainCallback2(CB2_PokeblockMenu);
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+static void HandleInitBackgrounds(void)
+{
+ ResetVramOamAndBgCntRegs();
+ ResetBgsAndClearDma3BusyFlags(0);
+ InitBgsFromTemplates(0, sBgTemplatesForPokeblockMenu, ARRAY_COUNT(sBgTemplatesForPokeblockMenu));
+ SetBgTilemapBuffer(2, sPokeblockMenu->tilemap);
+ ResetAllBgsCoordinates();
+ schedule_bg_copy_tilemap_to_vram(2);
+
+ SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_OBJ_ON | DISPCNT_OBJ_1D_MAP);
+
+ ShowBg(0);
+ ShowBg(1);
+ ShowBg(2);
+
+ SetGpuReg(REG_OFFSET_BLDCNT, 0);
+}
+
+static bool8 LoadPokeblockMenuGfx(void)
+{
+ switch (sPokeblockMenu->gfxState)
+ {
+ case 0:
+ reset_temp_tile_data_buffers();
+ decompress_and_copy_tile_data_to_vram(2, gMenuPokeblock_Gfx, 0, 0, 0);
+ sPokeblockMenu->gfxState++;
+ break;
+ case 1:
+ if (free_temp_tile_data_buffers_if_possible() != TRUE)
+ {
+ LZDecompressWram(gMenuPokeblock_Tilemap, sPokeblockMenu->tilemap);
+ sPokeblockMenu->gfxState++;
+ }
+ break;
+ case 2:
+ LoadCompressedPalette(gMenuPokeblock_Pal, 0, 0xC0);
+ sPokeblockMenu->gfxState++;
+ break;
+ case 3:
+ LoadCompressedObjectPic(&gPokeblockCase_SpriteSheet);
+ sPokeblockMenu->gfxState++;
+ break;
+ case 4:
+ LoadCompressedObjectPalette(&gPokeblockCase_SpritePal);
+ sPokeblockMenu->gfxState++;
+ break;
+ case 5:
+ LoadListMenuArrowsGfx();
+ sPokeblockMenu->gfxState = 0;
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+static void HandleInitWindows(void)
+{
+ u8 i;
+
+ InitWindows(sWindowTemplatesForPokeblockMenu);
+ DeactivateAllTextPrinters();
+ sub_809882C(0, 1, 0xE0);
+ copy_textbox_border_tile_patterns_to_vram(0, 0xA, 0xD0);
+ LoadPalette(gUnknown_0860F074, 0xF0, 0x20);
+
+ for (i = 0; i < ARRAY_COUNT(sWindowTemplatesForPokeblockMenu) - 1; i++)
+ {
+ FillWindowPixelBuffer(i, 0);
+ }
+
+ schedule_bg_copy_tilemap_to_vram(0);
+ schedule_bg_copy_tilemap_to_vram(1);
+}
+
+static void PrintOnPokeblockWindow(u8 windowId, const u8 *string, s32 x)
+{
+ AddTextPrinterParametrized2(windowId, 1, x, 1, 0, 0, &sTextColorInPokeblockMenu, 0, string);
+}
+
+static void PutPokeblockInfoText(void)
+{
+ u8 i;
+
+ const u8 *itemName = ItemId_GetItem(ITEM_POKEBLOCK_CASE)->name;
+ PrintOnPokeblockWindow(0, itemName, GetStringCenterAlignXOffset(1, itemName, 0x48));
+
+ PrintOnPokeblockWindow(2, gText_Spicy, 0);
+ PrintOnPokeblockWindow(3, gText_Dry, 0);
+ PrintOnPokeblockWindow(4, gText_Sweet, 0);
+ PrintOnPokeblockWindow(5, gText_Bitter, 0);
+ PrintOnPokeblockWindow(6, gText_Sour, 0);
+
+ for (i = 0; i < 8; i++)
+ {
+ PutWindowTilemap(i);
+ }
+}
+
+static void HandlePokeblockListMenuItems(void)
+{
+ u16 i;
+
+ for (i = 0; i < sPokeblockMenu->itemsNo - 1; i++)
+ {
+ PutPokeblockListMenuString(sPokeblockMenu->menuItemsStrings[i], i);
+ sPokeblockMenu->items[i].name = sPokeblockMenu->menuItemsStrings[i];
+ sPokeblockMenu->items[i].id = i;
+ }
+
+ StringCopy(sPokeblockMenu->menuItemsStrings[i], gText_StowCase);
+ sPokeblockMenu->items[i].name = sPokeblockMenu->menuItemsStrings[i];
+ sPokeblockMenu->items[i].id = LIST_B_PRESSED;
+
+ gMultiuseListMenuTemplate = sPokeblockListMenuTemplate;
+ gMultiuseListMenuTemplate.unk_17_0 = 7;
+ gMultiuseListMenuTemplate.totalItems = sPokeblockMenu->itemsNo;
+ gMultiuseListMenuTemplate.items = sPokeblockMenu->items;
+ gMultiuseListMenuTemplate.maxShowed = sPokeblockMenu->maxShowed;
+}
+
+static void PutPokeblockListMenuString(u8 *dst, u16 pkblId)
+{
+ struct Pokeblock *pkblock = &gSaveBlock1Ptr->pokeblocks[pkblId];
+ u8 *txtPtr = StringCopy(dst, gPokeblockNames[pkblock->color]);
+
+ *(txtPtr++) = EXT_CTRL_CODE_BEGIN;
+ *(txtPtr++) = 0x12;
+ *(txtPtr++) = 0x57;
+
+ ConvertIntToDecimalStringN(gStringVar1, GetHighestPokeblocksFlavorLevel(pkblock), STR_CONV_MODE_LEFT_ALIGN, 3);
+ StringExpandPlaceholders(txtPtr, gText_LvVar1);
+}
+
+static void MovePokeblockMenuCursor(u32 pkblId, bool8 arg1, struct ListMenu *arg2)
+{
+ if (arg1 != TRUE)
+ {
+ PlaySE(SE_SELECT);
+ gSprites[sPokeblockMenu->pokeblockCaseSpriteId].callback = sub_8136470;
+ }
+
+ if (!sPokeblockMenu->isSwapping)
+ sub_8135FCC(pkblId);
+}
+
+static void sub_8135FCC(s32 pkblId)
+{
+ u8 i;
+ struct Pokeblock *pokeblock;
+ u16 rectTilemapSrc[2];
+
+ FillWindowPixelBuffer(7, 0);
+
+ if (pkblId != LIST_B_PRESSED)
+ {
+ pokeblock = &gSaveBlock1Ptr->pokeblocks[pkblId];
+ rectTilemapSrc[0] = 0x17;
+ rectTilemapSrc[1] = 0x18;
+ for (i = 0; i < FLAVOR_COUNT; i++)
+ {
+ if (GetPokeblockData(pokeblock, PBLOCK_SPICY + i) > 0)
+ {
+ rectTilemapSrc[0] = (i << 0xC) + 0x17;
+ rectTilemapSrc[1] = (i << 0xC) + 0x18;
+ }
+ else
+ {
+ rectTilemapSrc[0] = 0xF;
+ rectTilemapSrc[1] = 0xF;
+ }
+ CopyToBgTilemapBufferRect(2, rectTilemapSrc, (i / 3 * 6) + 1, (i % 3 * 2) + 13, 1, 2);
+ }
+ ConvertIntToDecimalStringN(gStringVar1, GetPokeblocksFeel(pokeblock), STR_CONV_MODE_RIGHT_ALIGN, 2);
+ PrintOnPokeblockWindow(7, gStringVar1, 4);
+ }
+ else
+ {
+ rectTilemapSrc[0] = 0xF;
+ rectTilemapSrc[1] = 0xF;
+
+ for (i = 0; i < FLAVOR_COUNT; i++)
+ {
+ CopyToBgTilemapBufferRect(2, rectTilemapSrc, (i / 3 * 6) + 1, (i % 3 * 2) + 13, 1, 2);
+ }
+ CopyWindowToVram(7, 2);
+ }
+
+ schedule_bg_copy_tilemap_to_vram(0);
+ schedule_bg_copy_tilemap_to_vram(2);
+}
+
+static void HandlePokeblockMenuCursor(u16 cursorPos, u16 arg1)
+{
+ FillBgTilemapBufferRect_Palette0(2, arg1, 0xF, (cursorPos * 2) + 1, 0xE, 2);
+ schedule_bg_copy_tilemap_to_vram(2);
+}
+
+static void CompactPokeblockSlots(void)
+{
+ u16 i, j;
+
+ for (i = 0; i < POKEBLOCKS_COUNT - 1; i++)
+ {
+ for (j = i + 1; j < POKEBLOCKS_COUNT; j++)
+ {
+ if (gSaveBlock1Ptr->pokeblocks[i].color == 0)
+ {
+ struct Pokeblock temp = gSaveBlock1Ptr->pokeblocks[i];
+ gSaveBlock1Ptr->pokeblocks[i] = gSaveBlock1Ptr->pokeblocks[j];
+ gSaveBlock1Ptr->pokeblocks[j] = temp;
+ }
+ }
+ }
+}
+
+static void SwapSortPokeblocksInternalData(u32 id1, u32 id2)
+{
+ s16 i, count;
+ struct Pokeblock *pokeblocks = gSaveBlock1Ptr->pokeblocks;
+ struct Pokeblock *copyPokeblock1;
+
+ if (id1 == id2)
+ return;
+
+ copyPokeblock1 = Alloc(sizeof(struct Pokeblock));
+ *copyPokeblock1 = pokeblocks[id1];
+
+ if (id2 > id1)
+ {
+ id2--;
+ for (count = id2, i = id1; i < count; i++)
+ pokeblocks[i] = pokeblocks[i + 1];
+ }
+ else
+ {
+ for (count = id2, i = id1; i > count; i--)
+ pokeblocks[i] = pokeblocks[i - 1];
+ }
+
+ pokeblocks[id2] = *copyPokeblock1;
+ Free(copyPokeblock1);
+}
+
+void ResetPokeblockScrollPositions(void)
+{
+ sSavedPokeblockData.lastItemPos = 0;
+ sSavedPokeblockData.lastItemPage = 0;
+}
+
+static void SetMenuItemsCountAndMaxShowed(void)
+{
+ u16 i;
+
+ CompactPokeblockSlots();
+
+ for (sPokeblockMenu->itemsNo = 0, i = 0; i < POKEBLOCKS_COUNT; i++)
+ {
+ if (gSaveBlock1Ptr->pokeblocks[i].color != 0)
+ sPokeblockMenu->itemsNo++;
+ }
+
+ sPokeblockMenu->itemsNo++; // STOW CASE menu item
+
+ if (sPokeblockMenu->itemsNo > 9)
+ sPokeblockMenu->maxShowed = 9;
+ else
+ sPokeblockMenu->maxShowed = sPokeblockMenu->itemsNo;
+}
+
+static void sub_81362E0(void)
+{
+ if (sSavedPokeblockData.lastItemPage != 0)
+ {
+ if (sSavedPokeblockData.lastItemPage + sPokeblockMenu->maxShowed > sPokeblockMenu->itemsNo)
+ sSavedPokeblockData.lastItemPage = sPokeblockMenu->itemsNo - sPokeblockMenu->maxShowed;
+ }
+
+ if (sSavedPokeblockData.lastItemPage + sSavedPokeblockData.lastItemPos >= sPokeblockMenu->itemsNo)
+ {
+ if (sPokeblockMenu->itemsNo == 0)
+ sSavedPokeblockData.lastItemPos = 0;
+ else
+ sSavedPokeblockData.lastItemPos = sPokeblockMenu->itemsNo - 1;
+ }
+}
+
+static void sub_8136344(void)
+{
+ if (sSavedPokeblockData.lastItemPos > 4)
+ {
+ u8 i;
+
+ for (i = 0;
+ (i < sSavedPokeblockData.lastItemPos - 4) && (sSavedPokeblockData.lastItemPage + sPokeblockMenu->maxShowed != sPokeblockMenu->itemsNo);
+ sSavedPokeblockData.lastItemPos--, sSavedPokeblockData.lastItemPage++, i++);
+ }
+}
+
+static void sub_81363BC(void)
+{
+ if (sPokeblockMenu->unkTaskId == 0xFF)
+ {
+ sPokeblockMenu->unkTaskId = AddScrollIndicatorArrowPairParametrized(2, 0xB0, 8, 0x98, sPokeblockMenu->itemsNo - sPokeblockMenu->maxShowed,
+ 0x456, 0x456, &sSavedPokeblockData.lastItemPage);
+ }
+}
+
+static void sub_8136418(void)
+{
+ if (sPokeblockMenu->unkTaskId != 0xFF)
+ {
+ RemoveScrollIndicatorArrowPair(sPokeblockMenu->unkTaskId);
+ sPokeblockMenu->unkTaskId = 0xFF;
+ }
+}
+
+u8 CreatePokeblockCaseSprite(s16 x, s16 y, u8 subpriority)
+{
+ return CreateSprite(&sSpriteTemplate_PokeblockCase, x, y, subpriority);
+}
+
+static void sub_8136470(struct Sprite *sprite)
+{
+ if (sprite->data[0] > 1)
+ sprite->data[0] = 0;
+
+ switch (sprite->data[0])
+ {
+ case 0:
+ sprite->oam.affineMode = 1;
+ sprite->affineAnims = sSpriteAffineAnimTable_85B26F0;
+ InitSpriteAffineAnim(sprite);
+ sprite->data[0] = 1;
+ sprite->data[1] = 0;
+ break;
+ case 1:
+ if (++sprite->data[1] > 11)
+ {
+ sprite->oam.affineMode = 0;
+ sprite->data[0] = 0;
+ sprite->data[1] = 0;
+ FreeOamMatrix(sprite->oam.matrixNum);
+ sprite->callback = SpriteCallbackDummy;
+ }
+ break;
+ }
+}
+
+static void FadePaletteAndSetTaskToClosePokeblockCase(u8 taskId)
+{
+ BeginNormalPaletteFade(-1, 0, 0, 0x10, 0);
+ gTasks[taskId].func = Task_FreeDataAndExitPokeblockCase;
+}
+
+static void Task_FreeDataAndExitPokeblockCase(u8 taskId)
+{
+ s16 *data = gTasks[taskId].data;
+
+ if (!gPaletteFade.active)
+ {
+ if (sPokeblockMenu->caseId == PBLOCK_CASE_FEEDER || sPokeblockMenu->caseId == PBLOCK_CASE_GIVE)
+ gFieldCallback = sub_80AF168;
+
+ sub_81AE6C8(data[0], &sSavedPokeblockData.lastItemPage, &sSavedPokeblockData.lastItemPos);
+ sub_8136418();
+ ResetSpriteData();
+ FreeAllSpritePalettes();
+
+ if (sPokeblockMenu->callbackOnUse != NULL)
+ SetMainCallback2(sPokeblockMenu->callbackOnUse);
+ else
+ SetMainCallback2(sSavedPokeblockData.callback);
+
+ FreeAllWindowBuffers();
+ Free(sPokeblockMenu);
+ DestroyTask(taskId);
+ }
+}
+
+static void Task_HandlePokeblockMenuInput(u8 taskId)
+{
+ s16 *data = gTasks[taskId].data;
+
+ if (!gPaletteFade.active && sub_81221EC() != TRUE)
+ {
+ if (gMain.newKeys & SELECT_BUTTON)
+ {
+ sub_81AE860(data[0], &sSavedPokeblockData.lastItemPage, &sSavedPokeblockData.lastItemPos);
+ if (sSavedPokeblockData.lastItemPage + sSavedPokeblockData.lastItemPos != sPokeblockMenu->itemsNo - 1)
+ {
+ PlaySE(SE_SELECT);
+ HandlePokeblockMenuCursor(sSavedPokeblockData.lastItemPos, 0x2005);
+ data[2] = sSavedPokeblockData.lastItemPage + sSavedPokeblockData.lastItemPos;
+ sPokeblockMenu->isSwapping = TRUE;
+ gTasks[taskId].func = Task_HandlePokeblocksSwapInput;
+ }
+ }
+ else
+ {
+ u16 oldPosition = sSavedPokeblockData.lastItemPos;
+ s32 itemId = ListMenuHandleInputGetItemId(data[0]);
+
+ sub_81AE860(data[0], &sSavedPokeblockData.lastItemPage, &sSavedPokeblockData.lastItemPos);
+ if (oldPosition != sSavedPokeblockData.lastItemPos)
+ {
+ HandlePokeblockMenuCursor(oldPosition, 5);
+ HandlePokeblockMenuCursor(sSavedPokeblockData.lastItemPos, 0x1005);
+ }
+
+ switch (itemId)
+ {
+ case LIST_NOTHING_CHOSEN:
+ break;
+ case LIST_B_PRESSED:
+ PlaySE(SE_SELECT);
+ gSpecialVar_Result = 0xFFFF;
+ gSpecialVar_ItemId = 0;
+ FadePaletteAndSetTaskToClosePokeblockCase(taskId);
+ break;
+ default:
+ PlaySE(SE_SELECT);
+ gSpecialVar_ItemId = itemId;
+ PutPokeblockOptionsWindow(taskId);
+ break;
+ }
+ }
+ }
+}
+
+static void Task_HandlePokeblocksSwapInput(u8 taskId)
+{
+ s16 *data = gTasks[taskId].data;
+
+ if (sub_81221EC() == TRUE)
+ return;
+
+ if (gMain.newKeys & SELECT_BUTTON)
+ {
+ PlaySE(SE_SELECT);
+ sub_81AE860(data[0], &sSavedPokeblockData.lastItemPage, &sSavedPokeblockData.lastItemPos);
+ HandlePokeblocksSwap(taskId, FALSE);
+ }
+ else
+ {
+ u16 i = sSavedPokeblockData.lastItemPage;
+ u16 var = sSavedPokeblockData.lastItemPos;
+ s32 itemId = ListMenuHandleInputGetItemId(data[0]);
+
+ sub_81AE860(data[0], &sSavedPokeblockData.lastItemPage, &sSavedPokeblockData.lastItemPos);
+ if (i != sSavedPokeblockData.lastItemPage || var != sSavedPokeblockData.lastItemPos)
+ {
+ for (i = 0; i < 9; i++)
+ {
+ var = i + sSavedPokeblockData.lastItemPage;
+ if (var == data[2])
+ HandlePokeblockMenuCursor(i, 0x2005);
+ else
+ HandlePokeblockMenuCursor(i, 5);
+ }
+ }
+
+ sub_81223FC(sPokeblockMenu->field_E75, FIELD_E75_COUNT, 0);
+ sub_8122448(sPokeblockMenu->field_E75, FIELD_E75_COUNT, 0x80, (sSavedPokeblockData.lastItemPos * 16) + 8);
+
+ switch (itemId)
+ {
+ case LIST_NOTHING_CHOSEN:
+ break;
+ case LIST_B_PRESSED: // same id as STOW CASE field
+ PlaySE(SE_SELECT);
+ if (gMain.newKeys & A_BUTTON)
+ HandlePokeblocksSwap(taskId, FALSE);
+ else
+ HandlePokeblocksSwap(taskId, TRUE);
+ break;
+ default:
+ PlaySE(SE_SELECT);
+ HandlePokeblocksSwap(taskId, FALSE);
+ break;
+ }
+ }
+}
+
+static void HandlePokeblocksSwap(u8 taskId, bool8 noSwap)
+{
+ u8 i;
+ s16 *data = gTasks[taskId].data;
+ u16 swappedFromId = sSavedPokeblockData.lastItemPage + sSavedPokeblockData.lastItemPos;
+
+ sPokeblockMenu->isSwapping = FALSE;
+ sub_81AE6C8(data[0], &sSavedPokeblockData.lastItemPage, &sSavedPokeblockData.lastItemPos);
+
+ if (!noSwap && data[2] != swappedFromId && data[2] != swappedFromId - 1)
+ {
+ SwapSortPokeblocksInternalData(data[2], swappedFromId);
+ HandlePokeblockListMenuItems();
+ }
+
+ if (data[2] < swappedFromId)
+ sSavedPokeblockData.lastItemPos--;
+
+ data[0] = ListMenuInit(&gMultiuseListMenuTemplate, sSavedPokeblockData.lastItemPage, sSavedPokeblockData.lastItemPos);
+ schedule_bg_copy_tilemap_to_vram(0);
+ sub_81223FC(sPokeblockMenu->field_E75, FIELD_E75_COUNT, 1);
+
+ for (i = 0; i < 9; i++)
+ HandlePokeblockMenuCursor(i, 5);
+
+ HandlePokeblockMenuCursor(sSavedPokeblockData.lastItemPos, 0x1005);
+ gTasks[taskId].func = Task_HandlePokeblockMenuInput;
+}
+
+static void PutPokeblockOptionsWindow(u8 taskId)
+{
+ s16 *data = gTasks[taskId].data;
+
+ if (sPokeblockMenu->optionsNo == 3)
+ data[1] = 8;
+ else
+ data[1] = 9;
+
+ sub_8136418();
+ SetWindowBorderStyle(data[1], 0, 1, 0xE);
+ sub_81995E4(data[1], sPokeblockMenu->optionsNo, sPokeblockMenuActions, sPokeblockMenu->pokeblockOptionsIds);
+ InitMenuInUpperLeftCornerPlaySoundWhenAPressed(data[1], sPokeblockMenu->optionsNo, 0);
+ PutWindowTilemap(data[1]);
+ schedule_bg_copy_tilemap_to_vram(1);
+
+ gTasks[taskId].func = Task_HandlePokeblockOptionsInput;
+}
+
+static void Task_HandlePokeblockOptionsInput(u8 taskId)
+{
+ s8 itemId;
+
+ if (sub_81221EC() == TRUE)
+ return;
+
+ itemId = ProcessMenuInputNoWrapAround();
+ if (itemId == MENU_NOTHING_CHOSEN)
+ {
+ return;
+ }
+ else if (itemId == MENU_B_PRESSED)
+ {
+ PlaySE(SE_SELECT);
+ PokeblockAction_Cancel(taskId);
+ }
+ else
+ {
+ PlaySE(SE_SELECT);
+ sPokeblockMenuActions[sPokeblockMenu->pokeblockOptionsIds[itemId]].func.void_u8(taskId);
+ }
+}
+
+static void PokeblockAction_UseOnField(u8 taskId)
+{
+ sPokeblockMenu->callbackOnUse = UsePokeblockOnField;
+ FadePaletteAndSetTaskToClosePokeblockCase(taskId);
+}
+
+static void UsePokeblockOnField(void)
+{
+ ChooseMonToGivePokeblock(&gSaveBlock1Ptr->pokeblocks[gSpecialVar_ItemId], ReturnToPokeblockCaseOnField);
+}
+
+static void ReturnToPokeblockCaseOnField(void)
+{
+ OpenPokeblockCase(PBLOCK_CASE_FIELD, sSavedPokeblockData.callback);
+}
+
+static void PokeblockAction_Toss(u8 taskId)
+{
+ s16 *data = gTasks[taskId].data;
+
+ sub_8198070(data[1], FALSE);
+ StringCopy(gStringVar1, gPokeblockNames[gSaveBlock1Ptr->pokeblocks[gSpecialVar_ItemId].color]);
+ StringExpandPlaceholders(gStringVar4, gText_ThrowAwayVar1);
+ DisplayMessageAndContinueTask(taskId, 10, 10, 13, 1, GetPlayerTextSpeed(), gStringVar4, CreateTossPokeblockYesNoMenu);
+}
+
+static void CreateTossPokeblockYesNoMenu(u8 taskId)
+{
+ CreateYesNoMenuWithCallbacks(taskId, &sTossPkblockWindowTemplate, 1, 0, 2, 1, 0xE, &sTossYesNoFuncTable);
+}
+
+static void TossPokeblockChoice_Yes(u8 taskId)
+{
+ StringExpandPlaceholders(gStringVar4, gText_Var1ThrownAway);
+ DisplayMessageAndContinueTask(taskId, 10, 10, 13, 1, GetPlayerTextSpeed(), gStringVar4, HandleErasePokeblock);
+}
+
+static void HandleErasePokeblock(u8 taskId)
+{
+ if (gMain.newKeys & (A_BUTTON | B_BUTTON))
+ {
+ s16 *data;
+ u16 *lastPage, *lastPos;
+
+ TryClearPokeblock(gSpecialVar_ItemId);
+ PlaySE(SE_SELECT);
+
+ lastPage = &sSavedPokeblockData.lastItemPage;
+ lastPos = &sSavedPokeblockData.lastItemPos;
+ data = gTasks[taskId].data;
+
+ sub_81AE6C8(data[0], lastPage, lastPos);
+ HandlePokeblockMenuCursor(*lastPos, 5);
+ SetMenuItemsCountAndMaxShowed();
+ sub_81362E0();
+ HandlePokeblockListMenuItems();
+ data[0] = ListMenuInit(&gMultiuseListMenuTemplate, *lastPage, *lastPos);
+ HandlePokeblockMenuCursor(*lastPos, 0x1005);
+ schedule_bg_copy_tilemap_to_vram(0);
+ schedule_bg_copy_tilemap_to_vram(1);
+ TossPokeblockChoice_No(taskId);
+ }
+}
+
+static void TossPokeblockChoice_No(u8 taskId)
+{
+ sub_8197DF8(10, FALSE);
+ schedule_bg_copy_tilemap_to_vram(1);
+ sub_81363BC();
+ gTasks[taskId].func = Task_HandlePokeblockMenuInput;
+}
+
+static void PokeblockAction_UseInBattle(u8 taskId)
+{
+ u8 nature = GetNature(&gEnemyParty[0]);
+ s16 gain = PokeblockGetGain(nature, &gSaveBlock1Ptr->pokeblocks[gSpecialVar_ItemId]);
+ StringCopy(gBattleTextBuff1, gPokeblockNames[gSaveBlock1Ptr->pokeblocks[gSpecialVar_ItemId].color]);
+ TryClearPokeblock(gSpecialVar_ItemId);
+
+ gSpecialVar_ItemId = gSaveBlock1Ptr->pokeblocks[gSpecialVar_ItemId].color << 8;
+ if (gain == 0)
+ gSpecialVar_ItemId += 1;
+ else if (gain > 0)
+ gSpecialVar_ItemId += 2;
+ else
+ gSpecialVar_ItemId += 3;
+
+ FadePaletteAndSetTaskToClosePokeblockCase(taskId);
+}
+
+static void PokeblockAction_UseOnPokeblockFeeder(u8 taskId)
+{
+ SafariZoneActivatePokeblockFeeder(gSpecialVar_ItemId);
+ StringCopy(gStringVar1, gPokeblockNames[gSaveBlock1Ptr->pokeblocks[gSpecialVar_ItemId].color]);
+ gSpecialVar_Result = gSpecialVar_ItemId;
+ TryClearPokeblock(gSpecialVar_ItemId);
+ gSpecialVar_ItemId = 0;
+ FadePaletteAndSetTaskToClosePokeblockCase(taskId);
+}
+
+static void PokeblockAction_GiveToContestLady(u8 taskId)
+{
+ gSpecialVar_0x8004 = GivePokeblockToContestLady(&gSaveBlock1Ptr->pokeblocks[gSpecialVar_ItemId]);
+ gSpecialVar_Result = gSpecialVar_ItemId;
+ TryClearPokeblock(gSpecialVar_ItemId);
+ gSpecialVar_ItemId = 0;
+ FadePaletteAndSetTaskToClosePokeblockCase(taskId);
+}
+
+static void PokeblockAction_Cancel(u8 taskId)
+{
+ s16 *data = gTasks[taskId].data;
+
+ sub_8198070(data[1], FALSE);
+ schedule_bg_copy_tilemap_to_vram(1);
+ sub_81363BC();
+ gTasks[taskId].func = Task_HandlePokeblockMenuInput;
+}
+
+static void ClearPokeblock(u8 pkblId)
+{
+ gSaveBlock1Ptr->pokeblocks[pkblId].color = 0;
+ gSaveBlock1Ptr->pokeblocks[pkblId].spicy = 0;
+ gSaveBlock1Ptr->pokeblocks[pkblId].dry = 0;
+ gSaveBlock1Ptr->pokeblocks[pkblId].sweet = 0;
+ gSaveBlock1Ptr->pokeblocks[pkblId].bitter = 0;
+ gSaveBlock1Ptr->pokeblocks[pkblId].sour = 0;
+ gSaveBlock1Ptr->pokeblocks[pkblId].feel = 0;
+}
+
+void ClearPokeblocks(void)
+{
+ u8 i;
+
+ for (i = 0; i < POKEBLOCKS_COUNT; i++)
+ ClearPokeblock(i);
+}
+
+u8 GetHighestPokeblocksFlavorLevel(const struct Pokeblock *pokeblock)
+{
+ u8 i;
+ u8 maxFlavor = GetPokeblockData(pokeblock, PBLOCK_SPICY);
+
+ for (i = PBLOCK_SPICY; i < FLAVOR_COUNT; i++)
+ {
+ u8 currFlavor = GetPokeblockData(pokeblock, PBLOCK_SPICY + i);
+ if (maxFlavor < currFlavor)
+ maxFlavor = currFlavor;
+ }
+
+ return maxFlavor;
+}
+
+u8 GetPokeblocksFeel(const struct Pokeblock *pokeblock)
+{
+ u8 feel = GetPokeblockData(pokeblock, PBLOCK_FEEL);
+ if (feel > POKEBLOCK_MAX_FEEL)
+ feel = POKEBLOCK_MAX_FEEL;
+
+ return feel;
+}
+
+s8 GetFirstFreePokeblockSlot(void)
+{
+ u8 i;
+
+ for (i = 0; i < POKEBLOCKS_COUNT; i++)
+ {
+ if (gSaveBlock1Ptr->pokeblocks[i].color == 0)
+ return i;
+ }
+
+ return -1;
+}
+
+bool32 AddPokeblock(const struct Pokeblock *pokeblock)
+{
+ s8 slot = GetFirstFreePokeblockSlot();
+
+ if (slot == -1)
+ {
+ return FALSE;
+ }
+ else
+ {
+ gSaveBlock1Ptr->pokeblocks[slot] = *pokeblock;
+ return TRUE;
+ }
+}
+
+bool32 TryClearPokeblock(u8 pkblId)
+{
+ if (gSaveBlock1Ptr->pokeblocks[pkblId].color == 0)
+ {
+ return FALSE;
+ }
+ else
+ {
+ ClearPokeblock(pkblId);
+ return TRUE;
+ }
+}
+
+s16 GetPokeblockData(const struct Pokeblock *pokeblock, u8 field)
+{
+ if (field == PBLOCK_COLOR)
+ return pokeblock->color;
+ if (field == PBLOCK_SPICY)
+ return pokeblock->spicy;
+ if (field == PBLOCK_DRY)
+ return pokeblock->dry;
+ if (field == PBLOCK_SWEET)
+ return pokeblock->sweet;
+ if (field == PBLOCK_BITTER)
+ return pokeblock->bitter;
+ if (field == PBLOCK_SOUR)
+ return pokeblock->sour;
+ if (field == PBLOCK_FEEL)
+ return pokeblock->feel;
+
+ return 0;
+}
+
+s16 PokeblockGetGain(u8 nature, const struct Pokeblock *pokeblock)
+{
+ u8 flavor;
+ s16 curGain, totalGain = 0;
+
+ for (flavor = 0; flavor < FLAVOR_COUNT; flavor++)
+ {
+ curGain = GetPokeblockData(pokeblock, flavor + PBLOCK_SPICY);
+ if (curGain > 0)
+ totalGain += curGain * gPokeblockFlavorCompatibilityTable[5 * nature + flavor];
+ }
+
+ return totalGain;
+}
+
+void PokeblockCopyName(const struct Pokeblock *pokeblock, u8 *dest)
+{
+ u8 color = GetPokeblockData(pokeblock, PBLOCK_COLOR);
+ StringCopy(dest, gPokeblockNames[color]);
+}
+
+bool8 CopyMonFavoritePokeblockName(u8 nature, u8 *dest)
+{
+ u8 i;
+
+ for (i = 0; i < FLAVOR_COUNT; i++)
+ {
+ if (PokeblockGetGain(nature, &sFavoritePokeblocksTable[i]) > 0)
+ {
+ StringCopy(dest, gPokeblockNames[i + 1]);
+ return TRUE;
+ }
+ }
+
+ return FALSE;
+}
+
+u8 GetPokeblocksFlavor(const struct Pokeblock *pokeblock)
+{
+ s16 bestFlavor = 0;
+ s16 i;
+
+ for (i = 0; i < FLAVOR_COUNT; i++)
+ {
+ if (GetPokeblockData(pokeblock, bestFlavor + 1) < GetPokeblockData(pokeblock, i + 1))
+ bestFlavor = i;
+ }
+
+ return bestFlavor;
+}
diff --git a/src/pokeblock_feed.c b/src/pokeblock_feed.c
new file mode 100644
index 000000000..1bf40bbe5
--- /dev/null
+++ b/src/pokeblock_feed.c
@@ -0,0 +1,1108 @@
+#include "global.h"
+#include "pokeblock.h"
+#include "sprite.h"
+#include "task.h"
+#include "palette.h"
+#include "menu.h"
+#include "malloc.h"
+#include "pokemon.h"
+#include "blend_palette.h"
+#include "main.h"
+#include "menu_helpers.h"
+#include "bg.h"
+#include "gpu_regs.h"
+#include "data2.h"
+#include "decompress.h"
+#include "event_data.h"
+#include "strings.h"
+#include "string_util.h"
+#include "new_menu_helpers.h"
+#include "party_menu.h"
+#include "m4a.h"
+#include "sound.h"
+#include "trig.h"
+#include "graphics.h"
+#include "battle.h" // to get rid of once gMonSpritesGfxPtr is put elsewhere
+
+struct PokeblockFeedStruct
+{
+ struct Sprite *monSpritePtr;
+ struct Sprite savedMonSprite;
+ u8 tilemapBuffer[0x808];
+ s16 field_850[0x200];
+ s16 field_C50[0x200];
+ u8 field_1050;
+ u8 animId;
+ u8 field_1052;
+ bool8 noMonFlip;
+ u16 species;
+ u16 field_1056;
+ u16 field_1058;
+ u8 nature;
+ u8 monSpriteId_;
+ u8 field_105C;
+ u8 monSpriteId;
+ u8 pokeblockCaseSpriteId;
+ u8 pokeblockSpriteId;
+ s16 field_1060[15];
+ s16 loadGfxState;
+ u8 unused;
+};
+
+extern u16 gSpecialVar_ItemId;
+extern struct MusicPlayerInfo gMPlay_BGM;
+extern struct SpriteTemplate gUnknown_0202499C;
+
+extern const u8 gBattleTerrainPalette_Frontier[];
+extern const u8 gBattleTerrainTiles_Building[];
+extern const u8 gUnknown_08D9BA44[];
+extern const struct CompressedSpriteSheet gMonFrontPicTable[];
+extern const u16 gUnknown_0860F074[];
+
+extern bool8 sub_81221EC(void);
+extern void sub_806A068(u16, u8);
+extern void sub_809882C(u8, u16, u8);
+
+// this file's functions
+static void HandleInitBackgrounds(void);
+static void HandleInitWindows(void);
+static void LaunchPokeblockFeedTask(void);
+static void SetPokeblockSpritePal(u8 pokeblockCaseId);
+static void sub_817A5CC(void);
+static void sub_8148108(u8 spriteId, bool8 a1);
+static void DoPokeblockCaseThrowEffect(u8 spriteId, bool8 arg1);
+static void PrepareMonToMoveToPokeblock(u8 spriteId);
+static void Task_HandleMonAtePokeblock(u8 taskId);
+static void Task_PaletteFadeToReturn(u8 taskId);
+static void sub_817A634(void);
+static void sub_817A468(struct Sprite *sprite);
+static void sub_817AB68(void);
+static void sub_817AA54(void);
+static bool8 sub_817A91C(void);
+static bool8 FreeMonSpriteOamMatrix(void);
+static bool8 sub_817A9E4(void);
+static bool8 LoadMonAndSceneGfx(struct Pokemon *mon);
+static u8 CreatePokeblockSprite(void);
+static u8 CreatePokeblockCaseSpriteForFeeding(void);
+static u8 CreateMonSprite(struct Pokemon *mon);
+static void SpriteCB_ThrownPokeblock(struct Sprite* sprite);
+
+// ram variables
+EWRAM_DATA static struct PokeblockFeedStruct *sPokeblockFeed = NULL;
+EWRAM_DATA static struct CompressedSpritePalette sPokeblockSpritePal = {0};
+
+// const rom data
+static const u8 sNatureToMonPokeblockAnim[][2] =
+{
+ { 0, 0 }, // HARDY
+ { 3, 0 }, // LONELY
+ { 4, 1 }, // BRAVE
+ { 5, 0 }, // ADAMANT
+ { 10, 0 }, // NAUGHTY
+ { 13, 0 }, // BOLD
+ { 15, 0 }, // DOCILE
+ { 16, 2 }, // RELAXED
+ { 18, 0 }, // IMPISH
+ { 19, 0 }, // LAX
+ { 20, 0 }, // TIMID
+ { 25, 0 }, // HASTY
+ { 27, 3 }, // SERIOUS
+ { 28, 0 }, // JOLLY
+ { 29, 0 }, // NAIVE
+ { 33, 4 }, // MODEST
+ { 36, 0 }, // MILD
+ { 37, 0 }, // QUIET
+ { 39, 0 }, // BASHFUL
+ { 42, 0 }, // RASH
+ { 45, 0 }, // CALM
+ { 46, 5 }, // GENTLE
+ { 47, 6 }, // SASSY
+ { 48, 0 }, // CAREFUL
+ { 53, 0 }, // QUIRKY
+};
+
+static const s16 sMonPokeblockAnims[][10] =
+{
+ // HARDY
+ { 0, 4, 0, 8, 24, 0, 0, 0, 12, 0},
+ { 0, 4, 0, 16, 24, 0, 0, 0, 12, 0},
+ { 0, 4, 0, 32, 32, 0, 0, 0, 16, 1},
+
+ // LONELY
+ { 0, 3, 6, 0, 48, 0, 0, 0, 24, 1},
+
+ // BRAVE
+ { 64, 16, -24, 0, 32, 0, 0, 0, 0, 1},
+
+ // ADAMANT
+ { 0, 4, 8, 0, 16, 0, -8, 0, 0, 0},
+ { 0, 0, 0, 0, 16, 0, 0, 0, 0, 0},
+ { 0, 4, 8, 0, 16, 0, -8, 0, 0, 0},
+ { 0, 0, 0, 0, 16, 0, 0, 0, 0, 0},
+ { 0, 4, -16, 0, 4, 0, 16, 0, 0, 1},
+
+ // NAUGHTY
+ { 0, 3, 6, 0, 12, 0, 0, 0, 6, 0},
+ { 0, 3, -6, 0, 12, 0, 0, 0, 6, 0},
+ { 0, 16, 16, 0, 45, 1, 0, 0, 0, 1},
+
+ // BOLD
+ { 0, 16, 0, 24, 32, 0, 0, 0, 16, 0},
+ { 0, 16, 0, 23, 32, 0, 0, 0, 16, 1},
+
+ // DOCILE
+ { 0, 0, 0, 0, 80, 0, 0, 0, 0, 1},
+
+ // RELAXED
+ { 0, 2, 8, 0, 32, 0, 0, 0, 0, 0},
+ { 0, 2, -8, 0, 32, 0, 0, 0, 0, 1},
+
+ // IMPISH
+ { 0, 32, 2, 1, 48, 1, 0, 0, 24, 1},
+
+ // LAX
+ { 0, 2, 16, 16, 128, 0, 0, 0, 0, 1},
+
+ // TIMID
+ { 0, 2, -8, 0, 48, 0, -24, 0, 0, 0},
+ { 0, 0, 0, 0, 8, 0, 0, 0, 0, 0},
+ { 64, 32, 2, 0, 36, 0, 0, 0, 0, 0},
+ { 0, 0, 0, 0, 8, 0, 0, 0, 0, 0},
+ { 0, 2, 8, 0, 48, 0, 24, 0, 0, 1},
+
+ // HASTY
+ { 64, 24, 16, 0, 32, 0, 0, 0, 0, 0},
+ { 0, 28, 2, 1, 32, 1, 0, 0, 16, 1},
+
+ // SERIOUS
+ { 0, 0, 0, 0, 32, 0, 0, 0, 0, 1},
+
+ // JOLLY
+ { 64, 16, -16, 2, 48, 0, 0, 0, 32, 1},
+
+ // NAIVE
+ { 0, 12, -8, 4, 24, 0, 8, 0, 12, 0},
+ { 0, 12, 8, 8, 24, 0, -16, 0, 12, 0},
+ { 0, 12, -8, 16, 24, 0, 16, 0, 12, 0},
+ { 0, 12, 8, 28, 24, 0, -8, 0, 12, 1},
+
+ // MODEST
+ { 0, 0, 0, 0, 8, 0, 0, 0, 0, 0},
+ { 64, 16, -4, 0, 32, 0, 0, 0, 0, 0},
+ { 0, 0, 0, 0, 8, 0, 0, 0, 0, 1},
+
+ // MILD
+ { 128, 4, 0, 8, 64, 0, 0, 0, 0, 1},
+
+ // QUIET
+ { 0, 2, 16, 0, 48, 0, 0, 0, 0, 0},
+ { 128, 2, 16, 0, 48, 0, 0, 0, 0, 1},
+
+ // BASHFUL
+ { 0, 2, -4, 0, 48, 0, -48, 0, 0, 0},
+ { 0, 0, 0, 0, 80, 0, 0, 0, 0, 0},
+ { 0, 2, 8, 0, 24, 0, 48, 0, 0, 1},
+
+ // RASH
+ { 64, 4, 64, 58, 52, 0, -88, 0, 0, 0},
+ { 0, 0, 0, 0, 80, 0, 0, 0, 0, 0},
+ { 0, 24, 80, 0, 32, 0, 88, 0, 0, 1},
+
+ // CALM
+ { 0, 2, 16, 4, 64, 0, 0, 0, 0, 1},
+
+ // GENTLE
+ { 0, 0, 0, 0, 32, 0, 0, 0, 0, 1},
+
+ // SASSY
+ { 0, 0, 0, 0, 42, 0, 0, 0, 0, 1},
+
+ // CAREFUL
+ { 0, 4, 0, 8, 24, 0, 0, 0, 12, 0},
+ { 0, 0, 0, 0, 12, 0, 0, 0, 0, 0},
+ { 0, 4, 0, 12, 24, 0, 0, 0, 12, 0},
+ { 0, 0, 0, 0, 12, 0, 0, 0, 0, 0},
+ { 0, 4, 0, 4, 24, 0, 0, 0, 12, 1},
+
+ // QUIRKY
+ { 0, 4, 16, 12, 64, 0, 0, 0, 0, 0},
+ { 0, -4, 16, 12, 64, 0, 0, 0, 0, 1},
+};
+
+static const union AffineAnimCmd sSpriteAffineAnim_8411E90[] =
+{
+ AFFINEANIMCMD_FRAME(-0x100, 0x100, 0, 0),
+ AFFINEANIMCMD_END
+};
+
+static const union AffineAnimCmd sSpriteAffineAnim_8411EA0[] =
+{
+ AFFINEANIMCMD_FRAME(0, 0, 12, 1),
+ AFFINEANIMCMD_FRAME(0, 0, 0, 30),
+ AFFINEANIMCMD_FRAME(0, 0, -12, 1),
+ AFFINEANIMCMD_END
+};
+
+static const union AffineAnimCmd sSpriteAffineAnim_8411EC0[] =
+{
+ AFFINEANIMCMD_FRAME(-0x100, 0x100, 0, 0),
+ AFFINEANIMCMD_FRAME(0, 0, 12, 1),
+ AFFINEANIMCMD_FRAME(0, 0, 0, 28),
+ AFFINEANIMCMD_FRAME(0, 0, -4, 3),
+ AFFINEANIMCMD_END
+};
+
+static const union AffineAnimCmd sSpriteAffineAnim_8411EE8[] =
+{
+ AFFINEANIMCMD_FRAME(0x0, 0x0, 1, 16),
+ AFFINEANIMCMD_FRAME(0x0, 0x0, -1, 32),
+ AFFINEANIMCMD_FRAME(0x0, 0x0, 1, 16),
+ AFFINEANIMCMD_END
+};
+
+static const union AffineAnimCmd sSpriteAffineAnim_8411F08[] =
+{
+ AFFINEANIMCMD_FRAME(-0x100, 0x100, 0, 0),
+ AFFINEANIMCMD_FRAME(0x0, 0x0, 1, 16),
+ AFFINEANIMCMD_FRAME(0x0, 0x0, -1, 32),
+ AFFINEANIMCMD_FRAME(0x0, 0x0, 1, 16),
+ AFFINEANIMCMD_END
+};
+
+static const union AffineAnimCmd sSpriteAffineAnim_8411F30[] =
+{
+ AFFINEANIMCMD_FRAME(0x0, 0x0, -1, 8),
+ AFFINEANIMCMD_FRAME(0x0, 0x0, 0, 16),
+ AFFINEANIMCMD_FRAME(0x0, 0x0, 1, 8),
+ AFFINEANIMCMD_END
+};
+
+static const union AffineAnimCmd sSpriteAffineAnim_8411F50[] =
+{
+ AFFINEANIMCMD_FRAME(-0x100, 0x100, 0, 0),
+ AFFINEANIMCMD_FRAME(0x0, 0x0, -1, 8),
+ AFFINEANIMCMD_FRAME(0x0, 0x0, 0, 16),
+ AFFINEANIMCMD_FRAME(0x0, 0x0, 1, 8),
+ AFFINEANIMCMD_END
+};
+
+static const union AffineAnimCmd sSpriteAffineAnim_8411F78[] =
+{
+ AFFINEANIMCMD_FRAME(0x0, 0x0, -1, 8),
+ AFFINEANIMCMD_FRAME(0x0, 0x0, 0, 32),
+ AFFINEANIMCMD_FRAME(0x0, 0x0, 1, 8),
+ AFFINEANIMCMD_END
+};
+
+static const union AffineAnimCmd sSpriteAffineAnim_8411F98[] =
+{
+ AFFINEANIMCMD_FRAME(-0x100, 0x100, 0, 0),
+ AFFINEANIMCMD_FRAME(0x0, 0x0, -1, 8),
+ AFFINEANIMCMD_FRAME(0x0, 0x0, 0, 32),
+ AFFINEANIMCMD_FRAME(0x0, 0x0, 1, 8),
+ AFFINEANIMCMD_END
+};
+
+static const union AffineAnimCmd sSpriteAffineAnim_8411FC0[] =
+{
+ AFFINEANIMCMD_FRAME(0x0, 0x0, -1, 4),
+ AFFINEANIMCMD_FRAME(0x0, 0x0, 0, 24),
+ AFFINEANIMCMD_FRAME(0x0, 0x0, 1, 4),
+ AFFINEANIMCMD_END
+};
+
+static const union AffineAnimCmd sSpriteAffineAnim_8411FE0[] =
+{
+ AFFINEANIMCMD_FRAME(-0x100, 0x100, 0, 0),
+ AFFINEANIMCMD_FRAME(0x0, 0x0, -1, 4),
+ AFFINEANIMCMD_FRAME(0x0, 0x0, 0, 24),
+ AFFINEANIMCMD_FRAME(0x0, 0x0, 1, 4),
+ AFFINEANIMCMD_END
+};
+
+static const union AffineAnimCmd sSpriteAffineAnim_8412008[] =
+{
+ AFFINEANIMCMD_FRAME(0x0, 0x0, 1, 24),
+ AFFINEANIMCMD_FRAME(0x0, 0x0, 0, 16),
+ AFFINEANIMCMD_FRAME(0x0, 0x0, -12, 2),
+ AFFINEANIMCMD_END
+};
+
+static const union AffineAnimCmd sSpriteAffineAnim_8412028[] =
+{
+ AFFINEANIMCMD_FRAME(-0x100, 0x100, 0, 0),
+ AFFINEANIMCMD_FRAME(0x0, 0x0, 1, 24),
+ AFFINEANIMCMD_FRAME(0x0, 0x0, 0, 16),
+ AFFINEANIMCMD_FRAME(0x0, 0x0, -12, 2),
+ AFFINEANIMCMD_END
+};
+
+static const union AffineAnimCmd *const sSpriteAffineAnimTable_85F04FC[] =
+{
+ sSpriteAffineAnim_8411E90,
+ sSpriteAffineAnim_8411EA0,
+ sSpriteAffineAnim_8411EE8,
+ sSpriteAffineAnim_8411F30,
+ sSpriteAffineAnim_8411F78,
+ sSpriteAffineAnim_8411FC0,
+ sSpriteAffineAnim_8412008,
+ sSpriteAffineAnim_8411E90,
+ sSpriteAffineAnim_8411E90,
+ sSpriteAffineAnim_8411E90,
+ sSpriteAffineAnim_8411E90,
+ sSpriteAffineAnim_8411EC0,
+ sSpriteAffineAnim_8411F08,
+ sSpriteAffineAnim_8411F50,
+ sSpriteAffineAnim_8411F98,
+ sSpriteAffineAnim_8411FE0,
+ sSpriteAffineAnim_8412028,
+ sSpriteAffineAnim_8411E90,
+ sSpriteAffineAnim_8411E90,
+ sSpriteAffineAnim_8411E90,
+ sSpriteAffineAnim_8411E90,
+};
+
+static const struct BgTemplate sBackgroundTemplates[] =
+{
+ {
+ .bg = 0,
+ .charBaseIndex = 0,
+ .mapBaseIndex = 31,
+ .screenSize = 0,
+ .paletteMode = 0,
+ .priority = 0,
+ .baseTile = 0
+ },
+ {
+ .bg = 1,
+ .charBaseIndex = 2,
+ .mapBaseIndex = 30,
+ .screenSize = 0,
+ .paletteMode = 0,
+ .priority = 3,
+ .baseTile = 0
+ }
+};
+
+static const struct WindowTemplate sWindowTemplates[] =
+{
+ {0, 1, 0xF, 0x1C, 4, 0xF, 0xA},
+ DUMMY_WIN_TEMPLATE
+};
+
+static const u8* const sPokeblocksPals[] =
+{
+ gPokeblockRed_Pal,
+ gPokeblockBlue_Pal,
+ gPokeblockPink_Pal,
+ gPokeblockGreen_Pal,
+ gPokeblockYellow_Pal,
+ gPokeblockPurple_Pal,
+ gPokeblockIndigo_Pal,
+ gPokeblockBrown_Pal,
+ gPokeblockLiteBlue_Pal,
+ gPokeblockOlive_Pal,
+ gPokeblockGray_Pal,
+ gPokeblockBlack_Pal,
+ gPokeblockWhite_Pal,
+ gPokeblockGold_Pal
+};
+
+static const union AffineAnimCmd sSpriteAffineAnim_84120DC[] =
+{
+ AFFINEANIMCMD_FRAME(-0x100, 0x100, 0, 0),
+ AFFINEANIMCMD_END
+};
+
+static const union AffineAnimCmd *const sSpriteAffineAnimTable_MonNoFlip[] =
+{
+ sSpriteAffineAnim_84120DC
+};
+
+static const union AffineAnimCmd sSpriteAffineAnim_84120F0[] =
+{
+ AFFINEANIMCMD_FRAME(-0x100, 0x100, 0, 0),
+ AFFINEANIMCMD_FRAME(0x0, 0x0, -8, 1),
+ AFFINEANIMCMD_FRAME(0x0, 0x0, -8, 1),
+ AFFINEANIMCMD_FRAME(0x0, 0x0, -8, 1),
+ AFFINEANIMCMD_FRAME(0x0, 0x0, -8, 1),
+ AFFINEANIMCMD_FRAME(0x0, 0x0, 0, 8),
+ AFFINEANIMCMD_FRAME(0x0, 0x0, 16, 1),
+ AFFINEANIMCMD_FRAME(0x0, 0x0, 16, 1),
+ AFFINEANIMCMD_FRAME(0x0, 0x0, 16, 1),
+ AFFINEANIMCMD_FRAME(-0x100, 0x100, 0, 0),
+ AFFINEANIMCMD_END
+};
+
+static const union AffineAnimCmd sSpriteAffineAnim_8412148[] =
+{
+ AFFINEANIMCMD_FRAME(-0x100, 0x100, 0, 0),
+ AFFINEANIMCMD_FRAME(0x0, 0x0, 8, 1),
+ AFFINEANIMCMD_FRAME(0x0, 0x0, 8, 1),
+ AFFINEANIMCMD_FRAME(0x0, 0x0, 8, 1),
+ AFFINEANIMCMD_FRAME(0x0, 0x0, 8, 1),
+ AFFINEANIMCMD_FRAME(0x0, 0x0, 0, 8),
+ AFFINEANIMCMD_FRAME(0x0, 0x0, -16, 1),
+ AFFINEANIMCMD_FRAME(0x0, 0x0, -16, 1),
+ AFFINEANIMCMD_FRAME(0x0, 0x0, -16, 1),
+ AFFINEANIMCMD_FRAME(-0x100, 0x100, 0, 0),
+ AFFINEANIMCMD_END
+};
+
+static const union AffineAnimCmd *const sSpriteAffineAnimTable_85F0664[] =
+{
+ sSpriteAffineAnim_84120DC
+};
+
+static const union AffineAnimCmd *const sSpriteAffineAnimTable_85F0668[] =
+{
+ sSpriteAffineAnim_84120F0
+};
+
+static const union AffineAnimCmd *const sSpriteAffineAnimTable_85F066C[] =
+{
+ sSpriteAffineAnim_8412148
+};
+
+static const struct OamData sThrownPokeblockOamData =
+{
+ .y = 0,
+ .affineMode = 3,
+ .objMode = 0,
+ .mosaic = 0,
+ .bpp = 0,
+ .shape = 0,
+ .x = 0,
+ .matrixNum = 0,
+ .size = 0,
+ .tileNum = 0,
+ .priority = 1,
+ .paletteNum = 0,
+ .affineParam = 0,
+};
+
+static const union AnimCmd sThrownPokeblockSpriteAnim[] =
+{
+ ANIMCMD_FRAME(0, 0),
+ ANIMCMD_END
+};
+
+static const union AnimCmd *const sThrownPokeblockAnimTable[] =
+{
+ sThrownPokeblockSpriteAnim,
+};
+
+static const union AffineAnimCmd sSpriteAffineAnim_84121C0[] =
+{
+ AFFINEANIMCMD_FRAME(0x100, 0x100, 0, 0),
+ AFFINEANIMCMD_FRAME(-8, -8, 0, 1),
+ AFFINEANIMCMD_JUMP(1)
+};
+
+static const union AffineAnimCmd *const sThrownPokeblockAffineAnimTable[] =
+{
+ sSpriteAffineAnim_84121C0
+};
+
+static const struct CompressedSpriteSheet sPokeblock_SpriteSheet =
+{
+ gPokeblock_Gfx, 0x20, GFX_TAG_POKEBLOCK
+};
+
+static const struct SpriteTemplate sThrownPokeblockSpriteTemplate =
+{
+ .tileTag = GFX_TAG_POKEBLOCK,
+ .paletteTag = GFX_TAG_POKEBLOCK,
+ .oam = &sThrownPokeblockOamData,
+ .anims = sThrownPokeblockAnimTable,
+ .images = NULL,
+ .affineAnims = sThrownPokeblockAffineAnimTable,
+ .callback = SpriteCB_ThrownPokeblock
+};
+
+// code
+static void CB2_PokeblockFeed(void)
+{
+ RunTasks();
+ AnimateSprites();
+ BuildOamBuffer();
+ do_scheduled_bg_tilemap_copies_to_vram();
+ UpdatePaletteFade();
+}
+
+static void VBlankCB_PokeblockFeed(void)
+{
+ LoadOam();
+ ProcessSpriteCopyRequests();
+ TransferPlttBuffer();
+}
+
+static bool8 TransitionToPokeblockFeedScene(void)
+{
+ switch (gMain.state)
+ {
+ case 0:
+ sPokeblockFeed = AllocZeroed(sizeof(*sPokeblockFeed));
+ SetVBlankHBlankCallbacksToNull();
+ clear_scheduled_bg_copies_to_vram();
+ gMain.state++;
+ break;
+ case 1:
+ ResetPaletteFade();
+ gPaletteFade.bufferTransferDisabled = 1;
+ gMain.state++;
+ break;
+ case 2:
+ ResetSpriteData();
+ gMain.state++;
+ break;
+ case 3:
+ FreeAllSpritePalettes();
+ gMain.state++;
+ break;
+ case 4:
+ AllocateMonSpritesGfx();
+ gMain.state++;
+ break;
+ case 5:
+ HandleInitBackgrounds();
+ gMain.state++;
+ break;
+ case 6:
+ HandleInitWindows();
+ gMain.state++;
+ break;
+ case 7:
+ if (LoadMonAndSceneGfx(&gPlayerParty[gPokeblockMonId]))
+ {
+ gMain.state++;
+ }
+ break;
+ case 8:
+ sPokeblockFeed->pokeblockCaseSpriteId = CreatePokeblockCaseSpriteForFeeding();
+ gMain.state++;
+ break;
+ case 9:
+ sPokeblockFeed->monSpriteId = CreateMonSprite(&gPlayerParty[gPokeblockMonId]);
+ gMain.state++;
+ break;
+ case 10:
+ SetWindowBorderStyle(0, 1, 1, 14);
+ gMain.state++;
+ break;
+ case 11:
+ LaunchPokeblockFeedTask();
+ gMain.state++;
+ break;
+ case 12:
+ BlendPalettes(-1, 0x10, 0);
+ gMain.state++;
+ break;
+ case 13:
+ BeginNormalPaletteFade(-1, 0, 0x10, 0, 0);
+ gPaletteFade.bufferTransferDisabled = 0;
+ gMain.state++;
+ break;
+ default:
+ SetVBlankCallback(VBlankCB_PokeblockFeed);
+ SetMainCallback2(CB2_PokeblockFeed);
+ return TRUE;
+ }
+ return FALSE;
+}
+
+void CB2_PreparePokeblockFeedScene(void)
+{
+ while (1)
+ {
+ if (sub_81221EC() == TRUE)
+ break;
+ if (TransitionToPokeblockFeedScene() == TRUE)
+ break;
+ if (sub_81221AC() == TRUE)
+ break;
+ }
+}
+
+static void HandleInitBackgrounds(void)
+{
+ ResetVramOamAndBgCntRegs();
+
+ ResetBgsAndClearDma3BusyFlags(0);
+ InitBgsFromTemplates(0, sBackgroundTemplates, ARRAY_COUNT(sBackgroundTemplates));
+ SetBgTilemapBuffer(1, sPokeblockFeed->tilemapBuffer);
+ ResetAllBgsCoordinates();
+ schedule_bg_copy_tilemap_to_vram(1);
+
+ SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_OBJ_ON | DISPCNT_OBJ_1D_MAP);
+
+ ShowBg(0);
+ ShowBg(1);
+
+ SetGpuReg(REG_OFFSET_BLDCNT, 0);
+}
+
+static bool8 LoadMonAndSceneGfx(struct Pokemon *mon)
+{
+ u16 species;
+ u32 personality, trainerId;
+ const struct CompressedSpritePalette *palette;
+
+ switch (sPokeblockFeed->loadGfxState)
+ {
+ case 0:
+ species = GetMonData(mon, MON_DATA_SPECIES2);
+ personality = GetMonData(mon, MON_DATA_PERSONALITY);
+ HandleLoadSpecialPokePic_2(&gMonFrontPicTable[species], gMonSpritesGfxPtr->sprites[1], species, personality);
+ sPokeblockFeed->loadGfxState++;
+ break;
+ case 1:
+ species = GetMonData(mon, MON_DATA_SPECIES2);
+ personality = GetMonData(mon, MON_DATA_PERSONALITY);
+ trainerId = GetMonData(mon, MON_DATA_OT_ID);
+ palette = GetMonSpritePalStructFromOtIdPersonality(species, trainerId, personality);
+
+ LoadCompressedObjectPalette(palette);
+ sub_806A068(palette->tag, 1);
+ sPokeblockFeed->loadGfxState++;
+ break;
+ case 2:
+ LoadCompressedObjectPic(&gPokeblockCase_SpriteSheet);
+ sPokeblockFeed->loadGfxState++;
+ break;
+ case 3:
+ LoadCompressedObjectPalette(&gPokeblockCase_SpritePal);
+ sPokeblockFeed->loadGfxState++;
+ break;
+ case 4:
+ LoadCompressedObjectPic(&sPokeblock_SpriteSheet);
+ sPokeblockFeed->loadGfxState++;
+ break;
+ case 5:
+ SetPokeblockSpritePal(gSpecialVar_ItemId);
+ LoadCompressedObjectPalette(&sPokeblockSpritePal);
+ sPokeblockFeed->loadGfxState++;
+ break;
+ case 6:
+ reset_temp_tile_data_buffers();
+ decompress_and_copy_tile_data_to_vram(1, gBattleTerrainTiles_Building, 0, 0, 0);
+ sPokeblockFeed->loadGfxState++;
+ break;
+ case 7:
+ if (free_temp_tile_data_buffers_if_possible() != TRUE)
+ {
+ LZDecompressWram(gUnknown_08D9BA44, sPokeblockFeed->tilemapBuffer);
+ sPokeblockFeed->loadGfxState++;
+ }
+ break;
+ case 8:
+ LoadCompressedPalette(gBattleTerrainPalette_Frontier, 0x20, 0x60);
+ sPokeblockFeed->loadGfxState = 0;
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+static void HandleInitWindows(void)
+{
+ InitWindows(sWindowTemplates);
+ DeactivateAllTextPrinters();
+ sub_809882C(0, 1, 0xE0);
+ LoadPalette(gUnknown_0860F074, 0xF0, 0x20);
+ FillWindowPixelBuffer(0, 0);
+ PutWindowTilemap(0);
+ schedule_bg_copy_tilemap_to_vram(0);
+}
+
+static void SetPokeblockSpritePal(u8 pokeblockCaseId)
+{
+ u8 colorId = GetPokeblockData(&gSaveBlock1Ptr->pokeblocks[pokeblockCaseId], PBLOCK_COLOR);
+ sPokeblockSpritePal.data = sPokeblocksPals[colorId - 1];
+ sPokeblockSpritePal.tag = GFX_TAG_POKEBLOCK;
+}
+
+// defines for task data fields
+
+#define tFrames data[0]
+#define tData1 data[1]
+
+static void Task_HandlePokeblockFeed(u8 taskId)
+{
+ if (!gPaletteFade.active)
+ {
+ switch (gTasks[taskId].tFrames)
+ {
+ case 0:
+ sPokeblockFeed->field_1050 = 0;
+ sPokeblockFeed->field_1058 = 0;
+ sub_817A5CC();
+ break;
+ case 255:
+ DoPokeblockCaseThrowEffect(sPokeblockFeed->pokeblockCaseSpriteId, gTasks[taskId].tData1);
+ break;
+ case 269:
+ sPokeblockFeed->pokeblockSpriteId = CreatePokeblockSprite();
+ break;
+ case 281:
+ PrepareMonToMoveToPokeblock(sPokeblockFeed->monSpriteId);
+ break;
+ case 297:
+ gTasks[taskId].func = Task_HandleMonAtePokeblock;
+ return;
+ }
+
+ if (sPokeblockFeed->field_1058 < sPokeblockFeed->field_1056)
+ sub_817A634();
+ else if (sPokeblockFeed->field_1058 == sPokeblockFeed->field_1056)
+ gTasks[taskId].tFrames = 254;
+
+ sPokeblockFeed->field_1058++;
+ gTasks[taskId].tFrames++;
+ }
+}
+
+static void LaunchPokeblockFeedTask(void)
+{
+ u8 taskId = CreateTask(Task_HandlePokeblockFeed, 0);
+ gTasks[taskId].tFrames = 0;
+ gTasks[taskId].tData1 = 1;
+}
+
+static void Task_WaitForAtePokeblockText(u8 taskId)
+{
+ if (RunTextPrintersRetIsActive(0) != TRUE)
+ gTasks[taskId].func = Task_PaletteFadeToReturn;
+}
+
+static void Task_HandleMonAtePokeblock(u8 taskId)
+{
+ struct Pokemon *mon = &gPlayerParty[gPokeblockMonId];
+ struct Pokeblock *pokeblock = &gSaveBlock1Ptr->pokeblocks[gSpecialVar_ItemId];
+
+ gPokeblockGain = PokeblockGetGain(GetNature(mon), pokeblock);
+ GetMonNickname(mon, gStringVar1);
+ PokeblockCopyName(pokeblock, gStringVar2);
+
+ if (gPokeblockGain == 0)
+ StringExpandPlaceholders(gStringVar4, gText_Var1AteTheVar2);
+ else if (gPokeblockGain > 0)
+ StringExpandPlaceholders(gStringVar4, gText_Var1HappilyAteVar2);
+ else
+ StringExpandPlaceholders(gStringVar4, gText_Var1DisdainfullyAteVar2);
+
+ gTextFlags.flag_0 = 1;
+ AddTextPrinterParametrized(0, 1, gStringVar4, GetPlayerTextSpeed(), NULL, 2, 1, 3);
+ gTasks[taskId].func = Task_WaitForAtePokeblockText;
+}
+
+static void Task_ReturnAfterPaletteFade(u8 taskId)
+{
+ if (!gPaletteFade.active)
+ {
+ ResetSpriteData();
+ FreeAllSpritePalettes();
+ m4aMPlayVolumeControl(&gMPlay_BGM, -1, 0x100);
+ SetMainCallback2(gMain.savedCallback);
+ DestroyTask(taskId);
+ FreeAllWindowBuffers();
+ Free(sPokeblockFeed);
+ FreeMonSpritesGfx();
+ }
+}
+
+static void Task_PaletteFadeToReturn(u8 taskId)
+{
+ BeginNormalPaletteFade(-1, 0, 0, 0x10, 0);
+ gTasks[taskId].func = Task_ReturnAfterPaletteFade;
+}
+
+#undef tFrames
+#undef tData1
+
+// defines for mon sprite data fields
+
+#define tDelta data[0]
+#define tDeltaMod data[1]
+#define tSpecies data[2]
+
+static u8 CreateMonSprite(struct Pokemon* mon)
+{
+ u16 species = GetMonData(mon, MON_DATA_SPECIES2);
+ u8 spriteId = CreateSprite(&gUnknown_0202499C, 48, 80, 2);
+
+ sPokeblockFeed->species = species;
+ sPokeblockFeed->monSpriteId_ = spriteId;
+ sPokeblockFeed->nature = GetNature(mon);
+ gSprites[spriteId].tSpecies = species;
+ gSprites[spriteId].callback = SpriteCallbackDummy;
+
+ sPokeblockFeed->noMonFlip = TRUE;
+ if (!IsPokeSpriteNotFlipped(species))
+ {
+ gSprites[spriteId].affineAnims = sSpriteAffineAnimTable_MonNoFlip;
+ gSprites[spriteId].oam.affineMode = 3;
+ CalcCenterToCornerVec(&gSprites[spriteId], gSprites[spriteId].oam.shape, gSprites[spriteId].oam.size, gSprites[spriteId].oam.affineMode);
+ sPokeblockFeed->noMonFlip = FALSE;
+ }
+
+ return spriteId;
+}
+
+static void PrepareMonToMoveToPokeblock(u8 spriteId)
+{
+ gSprites[spriteId].pos1.x = 48;
+ gSprites[spriteId].pos1.y = 80;
+ gSprites[spriteId].tDelta = -8;
+ gSprites[spriteId].tDeltaMod = 1;
+ gSprites[spriteId].callback = sub_817A468;
+}
+
+static void sub_817A468(struct Sprite* sprite)
+{
+ sprite->pos1.x += 4;
+ sprite->pos1.y += sprite->tDelta;
+ sprite->tDelta += sprite->tDeltaMod;
+
+ if (sprite->tDelta == 0)
+ PlayCry1(sprite->tSpecies, 0);
+ if (sprite->tDelta == 9)
+ sprite->callback = SpriteCallbackDummy;
+}
+
+#undef tDelta
+#undef tDeltaMod
+#undef tSpecies
+
+static u8 CreatePokeblockCaseSpriteForFeeding(void)
+{
+ u8 spriteId = CreatePokeblockCaseSprite(188, 100, 2);
+ gSprites[spriteId].oam.affineMode = 1;
+ gSprites[spriteId].affineAnims = sSpriteAffineAnimTable_85F0664;
+ gSprites[spriteId].callback = SpriteCallbackDummy;
+ InitSpriteAffineAnim(&gSprites[spriteId]);
+ return spriteId;
+}
+
+static void DoPokeblockCaseThrowEffect(u8 spriteId, bool8 a1)
+{
+ FreeOamMatrix(gSprites[spriteId].oam.matrixNum);
+ gSprites[spriteId].oam.affineMode = 3;
+
+ if (!a1)
+ gSprites[spriteId].affineAnims = sSpriteAffineAnimTable_85F0668;
+ else
+ gSprites[spriteId].affineAnims = sSpriteAffineAnimTable_85F066C;
+
+ InitSpriteAffineAnim(&gSprites[spriteId]);
+}
+
+// defines for the pokeblock sprite data fields
+#define tDelta data[0]
+#define tDeltaMod data[1]
+
+static u8 CreatePokeblockSprite(void)
+{
+ u8 spriteId = CreateSprite(&sThrownPokeblockSpriteTemplate, 174, 84, 1);
+ gSprites[spriteId].tDelta = -12;
+ gSprites[spriteId].tDeltaMod = 1;
+ return spriteId;
+}
+
+static void SpriteCB_ThrownPokeblock(struct Sprite* sprite)
+{
+ sprite->pos1.x -= 4;
+ sprite->pos1.y += sprite->tDelta;
+ sprite->tDelta += sprite->tDeltaMod;
+ if (sprite->tDelta == 10)
+ DestroySprite(sprite);
+}
+
+#undef tDelta
+#undef tDeltaMod
+
+static void sub_817A5CC(void)
+{
+ u8 animId, i;
+ struct PokeblockFeedStruct *pokeblockFeed;
+
+ pokeblockFeed = sPokeblockFeed;
+ pokeblockFeed->field_1056 = 1;
+ animId = sNatureToMonPokeblockAnim[pokeblockFeed->nature][0];
+ for (i = 0; i < 8; i++, animId++)
+ {
+ pokeblockFeed->field_1056 += sMonPokeblockAnims[animId][4];
+ if (sMonPokeblockAnims[animId][9] == 1)
+ break;
+ }
+}
+
+static void sub_817A634(void)
+{
+ struct PokeblockFeedStruct *pokeblockFeed = sPokeblockFeed;
+
+ switch (pokeblockFeed->field_1050)
+ {
+ case 0:
+ pokeblockFeed->animId = sNatureToMonPokeblockAnim[pokeblockFeed->nature][0];
+ pokeblockFeed->monSpritePtr = &gSprites[pokeblockFeed->monSpriteId_];
+ pokeblockFeed->savedMonSprite = *pokeblockFeed->monSpritePtr;
+ pokeblockFeed->field_1050 = 10;
+ break;
+ case 1 ... 9:
+ break;
+ case 10:
+ sub_817A91C();
+ if (sNatureToMonPokeblockAnim[pokeblockFeed->nature][1] != 0)
+ {
+ pokeblockFeed->monSpritePtr->oam.affineMode = 3;
+ pokeblockFeed->monSpritePtr->oam.matrixNum = 0;
+ pokeblockFeed->monSpritePtr->affineAnims = sSpriteAffineAnimTable_85F04FC;
+ InitSpriteAffineAnim(pokeblockFeed->monSpritePtr);
+ }
+ pokeblockFeed->field_1050 = 50;
+ case 50:
+ if (sNatureToMonPokeblockAnim[pokeblockFeed->nature][1] != 0)
+ {
+ if (!pokeblockFeed->noMonFlip) // double negation, so mon's sprite is flipped
+ StartSpriteAffineAnim(pokeblockFeed->monSpritePtr, sNatureToMonPokeblockAnim[pokeblockFeed->nature][1] + 10);
+ else
+ StartSpriteAffineAnim(pokeblockFeed->monSpritePtr, sNatureToMonPokeblockAnim[pokeblockFeed->nature][1]);
+ }
+ pokeblockFeed->field_1050 = 60;
+ break;
+ case 60:
+ if (sub_817A9E4() == TRUE)
+ {
+ if (pokeblockFeed->field_1060[9] == 0)
+ {
+ pokeblockFeed->animId++;
+ sub_817A91C();
+ pokeblockFeed->field_1050 = 60;
+ }
+ else
+ {
+ FreeOamMatrix(pokeblockFeed->monSpritePtr->oam.matrixNum);
+ pokeblockFeed->field_1050 = 70;
+ }
+ }
+ break;
+ case 70:
+ FreeMonSpriteOamMatrix();
+ pokeblockFeed->animId = 0;
+ pokeblockFeed->field_1050 = 0;
+ break;
+ case 71 ... 90:
+ break;
+ }
+}
+
+static bool8 sub_817A91C(void)
+{
+ struct PokeblockFeedStruct *pokeblockFeed = sPokeblockFeed;
+ u8 i;
+
+ for (i = 0; i < 10; i++)
+ pokeblockFeed->field_1060[i] = sMonPokeblockAnims[pokeblockFeed->animId][i];
+
+ if (pokeblockFeed->field_1060[4] == 0)
+ {
+ return TRUE;
+ }
+ else
+ {
+ pokeblockFeed->field_1060[10] = Sin(pokeblockFeed->field_1060[0], pokeblockFeed->field_1060[2]);
+ pokeblockFeed->field_1060[11] = Cos(pokeblockFeed->field_1060[0], pokeblockFeed->field_1060[3]);
+ pokeblockFeed->field_1060[12] = pokeblockFeed->field_1060[4];
+ pokeblockFeed->field_1060[13] = pokeblockFeed->monSpritePtr->pos2.x;
+ pokeblockFeed->field_1060[14] = pokeblockFeed->monSpritePtr->pos2.y;
+ sub_817AB68();
+ pokeblockFeed->field_1060[4] = pokeblockFeed->field_1060[12];
+ sub_817AA54();
+ pokeblockFeed->field_1060[4] = pokeblockFeed->field_1060[12];
+ return FALSE;
+ }
+}
+
+static bool8 sub_817A9E4(void)
+{
+ u16 var = sPokeblockFeed->field_1060[12] - sPokeblockFeed->field_1060[4];
+
+ sPokeblockFeed->monSpritePtr->pos2.x = sPokeblockFeed->field_850[var];
+ sPokeblockFeed->monSpritePtr->pos2.y = sPokeblockFeed->field_C50[var];
+
+ if (--sPokeblockFeed->field_1060[4] == 0)
+ return TRUE;
+ else
+ return FALSE;
+}
+
+static bool8 FreeMonSpriteOamMatrix(void)
+{
+ FreeSpriteOamMatrix(sPokeblockFeed->monSpritePtr);
+ return FALSE;
+}
+
+static void sub_817AA54(void)
+{
+ struct PokeblockFeedStruct *pokeblockFeed = sPokeblockFeed;
+ u16 i;
+ u16 r8 = pokeblockFeed->field_1060[8];
+ u16 r7 = pokeblockFeed->field_1060[12] - r8;
+ s16 var3 = pokeblockFeed->field_1060[13] + pokeblockFeed->field_1060[6];
+ s16 r9 = pokeblockFeed->field_1060[14] + pokeblockFeed->field_1060[7];
+
+ for (i = 0; i < r7 - 1; i++)
+ {
+ s16 r1 = pokeblockFeed->field_850[r8 + i] - (var3);
+ s16 r4 = pokeblockFeed->field_C50[r8 + i] - r9;
+
+ pokeblockFeed->field_850[r8 + i] -= r1 * (i + 1) / r7;
+ pokeblockFeed->field_C50[r8 + i] -= r4 * (i + 1) / r7;
+ }
+
+ pokeblockFeed->field_850[(r8 + r7) - 1] = var3;
+ pokeblockFeed->field_C50[(r8 + r7) - 1] = r9;
+}
+
+static void sub_817AB68(void)
+{
+ struct PokeblockFeedStruct *pokeblockFeed = sPokeblockFeed;
+ bool8 var_24 = FALSE;
+ s16 r8 = pokeblockFeed->field_1060[13] - pokeblockFeed->field_1060[10];
+ s16 r7 = pokeblockFeed->field_1060[14] - pokeblockFeed->field_1060[11];
+
+ while (1)
+ {
+ u16 r5;
+ u16 r4;
+ u16 var;
+
+ var = abs(pokeblockFeed->field_1060[5]);
+ r5 = var + pokeblockFeed->field_1060[3];
+ pokeblockFeed->field_1060[3] = r5;
+
+ if (pokeblockFeed->field_1060[2] < 0)
+ var_24 = TRUE;
+
+ r4 = pokeblockFeed->field_1060[12] - pokeblockFeed->field_1060[4];
+
+ if (pokeblockFeed->field_1060[4] == 0)
+ break;
+
+ if (!var_24)
+ {
+ pokeblockFeed->field_850[r4] = Sin(pokeblockFeed->field_1060[0], pokeblockFeed->field_1060[2] + r5 / 0x100) + r8;
+ pokeblockFeed->field_C50[r4] = Cos(pokeblockFeed->field_1060[0], pokeblockFeed->field_1060[3] + r5 / 0x100) + r7;
+ }
+ else
+ {
+ pokeblockFeed->field_850[r4] = Sin(pokeblockFeed->field_1060[0], pokeblockFeed->field_1060[2] - r5 / 0x100) + r8;
+ pokeblockFeed->field_C50[r4] = Cos(pokeblockFeed->field_1060[0], pokeblockFeed->field_1060[3] - r5 / 0x100) + r7;
+ }
+
+ pokeblockFeed->field_1060[0] += pokeblockFeed->field_1060[1];
+ pokeblockFeed->field_1060[0] &= 0xFF;
+ pokeblockFeed->field_1060[4]--;
+ }
+}
diff --git a/src/pokemon_3.c b/src/pokemon_3.c
index d58b024a8..95ec4b6a2 100644
--- a/src/pokemon_3.c
+++ b/src/pokemon_3.c
@@ -21,6 +21,7 @@
#include "constants/abilities.h"
#include "pokemon_animation.h"
#include "pokedex.h"
+#include "pokeblock.h"
extern struct BattlePokemon gBattleMons[4];
extern struct BattleEnigmaBerry gEnigmaBerries[4];
@@ -58,7 +59,6 @@ extern const u8 gText_PkmnsXPreventsSwitching[];
extern const struct CompressedSpritePalette gMonPaletteTable[];
extern const struct CompressedSpritePalette gMonShinyPaletteTable[];
extern const u16 gHMMoves[];
-extern const s8 gPokeblockFlavorCompatibilityTable[];
extern const u8 gMonAnimationDelayTable[];
extern const u8 gMonFrontAnimIdsTable[];
@@ -1145,11 +1145,11 @@ void ClearBattleMonForms(void)
u16 GetBattleBGM(void)
{
if (gBattleTypeFlags & BATTLE_TYPE_KYOGRE_GROUDON)
- return BGM_BATTLE34;
+ return MUS_BATTLE34;
if (gBattleTypeFlags & BATTLE_TYPE_REGI)
- return BGM_BATTLE36;
+ return MUS_BATTLE36;
if (gBattleTypeFlags & (BATTLE_TYPE_LINK | BATTLE_TYPE_x2000000))
- return BGM_BATTLE20;
+ return MUS_BATTLE20;
if (gBattleTypeFlags & BATTLE_TYPE_TRAINER)
{
u8 trainerClass;
@@ -1165,24 +1165,24 @@ u16 GetBattleBGM(void)
{
case TRAINER_CLASS_AQUA_LEADER:
case TRAINER_CLASS_MAGMA_LEADER:
- return BGM_BATTLE30;
+ return MUS_BATTLE30;
case TRAINER_CLASS_TEAM_AQUA:
case TRAINER_CLASS_TEAM_MAGMA:
case TRAINER_CLASS_AQUA_ADMIN:
case TRAINER_CLASS_MAGMA_ADMIN:
- return BGM_BATTLE31;
+ return MUS_BATTLE31;
case TRAINER_CLASS_LEADER:
- return BGM_BATTLE32;
+ return MUS_BATTLE32;
case TRAINER_CLASS_CHAMPION:
- return BGM_BATTLE33;
+ return MUS_BATTLE33;
case TRAINER_CLASS_PKMN_TRAINER_3:
if (gBattleTypeFlags & BATTLE_TYPE_FRONTIER)
- return BGM_BATTLE35;
+ return MUS_BATTLE35;
if (!StringCompare(gTrainers[gTrainerBattleOpponent_A].trainerName, gText_BattleWallyName))
- return BGM_BATTLE20;
- return BGM_BATTLE35;
+ return MUS_BATTLE20;
+ return MUS_BATTLE35;
case TRAINER_CLASS_ELITE_FOUR:
- return BGM_BATTLE38;
+ return MUS_BATTLE38;
case TRAINER_CLASS_SALON_MAIDEN:
case TRAINER_CLASS_DOME_ACE:
case TRAINER_CLASS_PALACE_MAVEN:
@@ -1190,12 +1190,12 @@ u16 GetBattleBGM(void)
case TRAINER_CLASS_FACTORY_HEAD:
case TRAINER_CLASS_PIKE_QUEEN:
case TRAINER_CLASS_PYRAMID_KING:
- return BGM_BATTLE_FRONTIER_BRAIN;
+ return MUS_VS_FRONT;
default:
- return BGM_BATTLE20;
+ return MUS_BATTLE20;
}
}
- return BGM_BATTLE27;
+ return MUS_BATTLE27;
}
void PlayBattleBGM(void)
@@ -1298,21 +1298,21 @@ bool8 IsPokeSpriteNotFlipped(u16 species)
return gBaseStats[species].noFlip;
}
-s8 GetMonFlavorRelation(struct Pokemon *mon, u8 a2)
+s8 GetMonFlavorRelation(struct Pokemon *mon, u8 flavor)
{
u8 nature = GetNature(mon);
- return gPokeblockFlavorCompatibilityTable[nature * 5 + a2];
+ return gPokeblockFlavorCompatibilityTable[nature * 5 + flavor];
}
-s8 GetFlavorRelationByPersonality(u32 personality, u8 a2)
+s8 GetFlavorRelationByPersonality(u32 personality, u8 flavor)
{
u8 nature = GetNatureFromPersonality(personality);
- return gPokeblockFlavorCompatibilityTable[nature * 5 + a2];
+ return gPokeblockFlavorCompatibilityTable[nature * 5 + flavor];
}
bool8 IsTradedMon(struct Pokemon *mon)
{
- u8 otName[8];
+ u8 otName[OT_NAME_LENGTH + 1];
u32 otId;
GetMonData(mon, MON_DATA_OT_NAME, otName);
otId = GetMonData(mon, MON_DATA_OT_ID, 0);
diff --git a/src/pokemon_summary_screen.c b/src/pokemon_summary_screen.c
index b00979945..ba0c4dde7 100755
--- a/src/pokemon_summary_screen.c
+++ b/src/pokemon_summary_screen.c
@@ -73,7 +73,7 @@ extern void do_scheduled_bg_tilemap_copies_to_vram(void);
extern u8 sub_81221EC();
extern u8 sub_81221AC();
extern void SetVBlankHBlankCallbacksToNull();
-extern void sub_8121DA0();
+extern void ResetVramOamAndBgCntRegs();
extern void clear_scheduled_bg_copies_to_vram();
extern void remove_some_task();
extern void ResetBgsAndClearDma3BusyFlags(u32 leftoverFireRedLeafGreenVariable);
@@ -193,7 +193,7 @@ void sub_81C4A88();
void sub_81C4280();
void sub_81C0510(u8 taskId);
void sub_81C171C(u8 taskId);
-void sub_8121E10();
+void ResetAllBgsCoordinates();
u8 sub_81B205C(struct Pokemon* a);
void sub_81C1DA4(u16 a, s16 b);
void sub_81C1EFC(u16 a, s16 b, u16 c);
@@ -450,7 +450,7 @@ bool8 sub_81BFB10(void)
{
case 0:
SetVBlankHBlankCallbacksToNull();
- sub_8121DA0();
+ ResetVramOamAndBgCntRegs();
clear_scheduled_bg_copies_to_vram();
gMain.state++;
break;
@@ -578,7 +578,7 @@ void sub_81BFE24()
SetBgTilemapBuffer(1, &gUnknown_0203CF1C->unkTilemap2);
SetBgTilemapBuffer(2, &gUnknown_0203CF1C->unkTilemap1);
SetBgTilemapBuffer(3, &gUnknown_0203CF1C->unkTilemap0);
- sub_8121E10();
+ ResetAllBgsCoordinates();
schedule_bg_copy_tilemap_to_vram(1);
schedule_bg_copy_tilemap_to_vram(2);
schedule_bg_copy_tilemap_to_vram(3);
diff --git a/src/safari_zone.c b/src/safari_zone.c
index f1d59907d..ce1eb65bc 100644
--- a/src/safari_zone.c
+++ b/src/safari_zone.c
@@ -5,6 +5,7 @@
#include "main.h"
#include "battle.h"
#include "string_util.h"
+#include "pokeblock.h"
struct PokeblockFeeder
{
@@ -24,7 +25,6 @@ extern u8 EventScript_2A4B8A[];
extern u8 EventScript_2A4B6F[];
extern u8 EventScript_2A4B4C[];
extern u8 EventScript_2A4B9B[];
-extern const u8* const gPokeblockNames[];
extern void sub_80EE44C(u8, u8);
extern void IncrementGameStat(u8 index);
diff --git a/src/scrcmd.c b/src/scrcmd.c
index 1b10501fc..0557cd95e 100644
--- a/src/scrcmd.c
+++ b/src/scrcmd.c
@@ -2089,7 +2089,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 +2332,7 @@ bool8 ScrCmd_mossdeepgym4(struct ScriptContext *ctx)
bool8 ScrCmd_cmdD8(struct ScriptContext *ctx)
{
- gSelectedMapObject = sub_80B47BC();
+ gSelectedMapObject = GetCurrentApproachingTrainerMapObjectId();
return FALSE;
}
diff --git a/src/secret_base.c b/src/secret_base.c
index cc320e5d7..bf6bec1f8 100644
--- a/src/secret_base.c
+++ b/src/secret_base.c
@@ -1082,13 +1082,13 @@ void game_continue(u8 taskId)
if (sub_80E9878(i))
{
sub_80E9780(gUnknown_0203A020->names[count], i);
- gUnknown_0203A020->items[count].unk_00 = gUnknown_0203A020->names[count];
- gUnknown_0203A020->items[count].unk_04 = i;
+ gUnknown_0203A020->items[count].name = gUnknown_0203A020->names[count];
+ gUnknown_0203A020->items[count].id = i;
count ++;
}
}
- gUnknown_0203A020->items[count].unk_00 = gText_Cancel;
- gUnknown_0203A020->items[count].unk_04 = -2;
+ gUnknown_0203A020->items[count].name = gText_Cancel;
+ gUnknown_0203A020->items[count].id = -2;
data[0] = count + 1;
if (data[0] < 8)
{
@@ -1098,11 +1098,11 @@ void game_continue(u8 taskId)
{
data[3] = 8;
}
- gUnknown_03006310 = gUnknown_0858D07C;
- gUnknown_03006310.unk_10 = data[6];
- gUnknown_03006310.totalItems = data[0];
- gUnknown_03006310.items = gUnknown_0203A020->items;
- gUnknown_03006310.maxShowed = data[3];
+ gMultiuseListMenuTemplate = gUnknown_0858D07C;
+ gMultiuseListMenuTemplate.unk_10 = data[6];
+ gMultiuseListMenuTemplate.totalItems = data[0];
+ gMultiuseListMenuTemplate.items = gUnknown_0203A020->items;
+ gMultiuseListMenuTemplate.maxShowed = data[3];
}
void sub_80E9DEC(u32 a0, bool8 flag, struct ListMenu *menu)
@@ -1119,7 +1119,7 @@ void sub_80E9E00(u8 taskId)
data = gTasks[taskId].data;
SetStandardWindowBorderStyle(data[6], 0);
- data[5] = ListMenuInit(&gUnknown_03006310, data[2], data[1]);
+ data[5] = ListMenuInit(&gMultiuseListMenuTemplate, data[2], data[1]);
sub_80E9E44(taskId);
schedule_bg_copy_tilemap_to_vram(0);
}
@@ -1138,8 +1138,8 @@ void sub_80E9E90(u8 taskId)
s32 input;
data = gTasks[taskId].data;
- input = ListMenuHandleInput(data[5]);
- get_coro_args_x18_x1A(data[5], &data[2], &data[1]);
+ input = ListMenuHandleInputGetItemId(data[5]);
+ sub_81AE860(data[5], &data[2], &data[1]);
switch (input)
{
case -1:
diff --git a/src/sound.c b/src/sound.c
index 086fede67..0cb11d5a5 100644
--- a/src/sound.c
+++ b/src/sound.c
@@ -189,7 +189,7 @@ bool8 WaitFanfare(bool8 stop)
if (!stop)
m4aMPlayContinue(&gMPlay_BGM);
else
- m4aSongNumStart(SE_STOP);
+ m4aSongNumStart(MUS_DUMMY);
return TRUE;
}
diff --git a/src/trainer_see.c b/src/trainer_see.c
index b30f27347..53bc5cbbb 100644
--- a/src/trainer_see.c
+++ b/src/trainer_see.c
@@ -1,15 +1,170 @@
#include "global.h"
#include "trainer_see.h"
#include "battle_setup.h"
+#include "pokemon.h"
+#include "sprite.h"
+#include "field_effect.h"
+#include "field_map_obj.h"
+#include "field_player_avatar.h"
+#include "map_obj_8097404.h"
+#include "pokenav.h"
+#include "task.h"
+#include "util.h"
+#include "script.h"
+#include "event_data.h"
+#include "script_movement.h"
-extern u8 gApproachingTrainerId;
-extern u8 gNoOfApproachingTrainers;
-extern u8 gUnknown_030060AC;
-extern u16 gUnknown_03006080;
+extern bool8 InBattlePyramid(void);
+extern bool32 InTrainerHill(void);
+extern bool8 GetBattlePyramidTrainerFlag(u8 mapObjectId);
+extern bool8 GetTrainerHillTrainerFlag(u8 mapObjectId);
+extern void sub_809BE48(u16 npcId);
// this file's functions
-u8 CheckIfTrainerWantsBattle(u8 mapObjectId);
+static u8 CheckTrainer(u8 mapObjectId);
+static u8 GetTrainerApproachDistance(struct MapObject *trainerObj);
+static u8 CheckPathBetweenTrainerAndPlayer(struct MapObject *trainerObj, u8 approachDistance, u8 direction);
+static void TrainerApproachPlayer(struct MapObject *trainerObj, u8 range);
+static void Task_RunTrainerSeeFuncList(u8 taskId);
+static void Task_DestroyTrainerApproachTask(u8 taskId);
+static void SetIconSpriteData(struct Sprite *sprite, u16 fldEffId, u8 spriteAnimNum);
+static u8 GetTrainerApproachDistanceSouth(struct MapObject *trainerObj, s16 range, s16 x, s16 y);
+static u8 GetTrainerApproachDistanceNorth(struct MapObject *trainerObj, s16 range, s16 x, s16 y);
+static u8 GetTrainerApproachDistanceWest(struct MapObject *trainerObj, s16 range, s16 x, s16 y);
+static u8 GetTrainerApproachDistanceEast(struct MapObject *trainerObj, s16 range, s16 x, s16 y);
+
+static bool8 sub_80B4178(u8 taskId, struct Task *task, struct MapObject *trainerObj);
+static bool8 sub_80B417C(u8 taskId, struct Task *task, struct MapObject *trainerObj);
+static bool8 sub_80B41C0(u8 taskId, struct Task *task, struct MapObject *trainerObj);
+static bool8 sub_80B4200(u8 taskId, struct Task *task, struct MapObject *trainerObj);
+static bool8 sub_80B425C(u8 taskId, struct Task *task, struct MapObject *trainerObj);
+static bool8 sub_80B4318(u8 taskId, struct Task *task, struct MapObject *trainerObj);
+static bool8 sub_80B435C(u8 taskId, struct Task *task, struct MapObject *trainerObj);
+static bool8 sub_80B4390(u8 taskId, struct Task *task, struct MapObject *trainerObj);
+static bool8 sub_80B43AC(u8 taskId, struct Task *task, struct MapObject *trainerObj);
+static bool8 sub_80B43E0(u8 taskId, struct Task *task, struct MapObject *trainerObj);
+static bool8 sub_80B4438(u8 taskId, struct Task *task, struct MapObject *trainerObj);
+static bool8 sub_80B44AC(u8 taskId, struct Task *task, struct MapObject *trainerObj);
+
+static void SpriteCB_TrainerIcons(struct Sprite *sprite);
+
+// IWRAM common
+u16 gUnknown_03006080;
+u8 gUnknown_03006084[4];
+struct ApproachingTrainer gApproachingTrainers[2];
+u8 gNoOfApproachingTrainers;
+u8 gUnknown_030060AC;
+
+// EWRAM
+EWRAM_DATA u8 gApproachingTrainerId = 0;
+
+// const rom data
+static const u8 sEmotion_ExclamationMarkGfx[] = INCBIN_U8("graphics/misc/emotion_exclamation.4bpp");
+static const u8 sEmotion_QuestionMarkGfx[] = INCBIN_U8("graphics/misc/emotion_question.4bpp");
+static const u8 sEmotion_HeartGfx[] = INCBIN_U8("graphics/misc/emotion_heart.4bpp");
+
+static u8 (*const sDirectionalApproachDistanceFuncs[])(struct MapObject *trainerObj, s16 range, s16 x, s16 y) =
+{
+ GetTrainerApproachDistanceSouth,
+ GetTrainerApproachDistanceNorth,
+ GetTrainerApproachDistanceWest,
+ GetTrainerApproachDistanceEast,
+};
+
+static bool8 (*const sTrainerSeeFuncList[])(u8 taskId, struct Task *task, struct MapObject *trainerObj) =
+{
+ sub_80B4178,
+ sub_80B417C,
+ sub_80B41C0,
+ sub_80B4200,
+ sub_80B425C,
+ sub_80B4318,
+ sub_80B435C,
+ sub_80B4390,
+ sub_80B43AC,
+ sub_80B43E0,
+ sub_80B4438,
+ sub_80B44AC
+};
+
+static bool8 (*const sTrainerSeeFuncList2[])(u8 taskId, struct Task *task, struct MapObject *trainerObj) =
+{
+ sub_80B43AC,
+ sub_80B43E0,
+ sub_80B4438,
+ sub_80B44AC,
+};
+
+static const struct OamData sOamData_Icons =
+{
+ .y = 0,
+ .affineMode = 0,
+ .objMode = 0,
+ .mosaic = 0,
+ .bpp = 0,
+ .shape = 0,
+ .x = 0,
+ .matrixNum = 0,
+ .size = 1,
+ .tileNum = 0,
+ .priority = 1,
+ .paletteNum = 0,
+ .affineParam = 0,
+};
+
+static const struct SpriteFrameImage sSpriteImageTable_ExclamationQuestionMark[] =
+{
+ {sEmotion_ExclamationMarkGfx, 0x80},
+ {sEmotion_QuestionMarkGfx, 0x80}
+};
+
+static const struct SpriteFrameImage sSpriteImageTable_HeartIcon[] =
+{
+ {sEmotion_HeartGfx, 0x80}
+};
+
+static const union AnimCmd sSpriteAnim_Icons1[] =
+{
+ ANIMCMD_FRAME(0, 60),
+ ANIMCMD_END
+};
+
+static const union AnimCmd sSpriteAnim_Icons2[] =
+{
+ ANIMCMD_FRAME(1, 60),
+ ANIMCMD_END
+};
+
+static const union AnimCmd *const sSpriteAnimTable_Icons[] =
+{
+ sSpriteAnim_Icons1,
+ sSpriteAnim_Icons2
+};
+
+static const struct SpriteTemplate sSpriteTemplate_ExclamationQuestionMark =
+{
+ .tileTag = 0xffff,
+ .paletteTag = 0xffff,
+ .oam = &sOamData_Icons,
+ .anims = sSpriteAnimTable_Icons,
+ .images = sSpriteImageTable_ExclamationQuestionMark,
+ .affineAnims = gDummySpriteAffineAnimTable,
+ .callback = SpriteCB_TrainerIcons
+};
+
+static const struct SpriteTemplate sSpriteTemplate_HeartIcon =
+{
+ .tileTag = 0xffff,
+ .paletteTag = 0x1004,
+ .oam = &sOamData_Icons,
+ .anims = sSpriteAnimTable_Icons,
+ .images = sSpriteImageTable_HeartIcon,
+ .affineAnims = gDummySpriteAffineAnimTable,
+ .callback = SpriteCB_TrainerIcons
+};
+
+// code
bool8 CheckForTrainersWantingBattle(void)
{
u8 i;
@@ -26,7 +181,7 @@ bool8 CheckForTrainersWantingBattle(void)
if (gMapObjects[i].trainerType != 1 && gMapObjects[i].trainerType != 3)
continue;
- retVal = CheckIfTrainerWantsBattle(i);
+ retVal = CheckTrainer(i);
if (retVal == 2)
break; // two trainers have been found
@@ -66,3 +221,561 @@ bool8 CheckForTrainersWantingBattle(void)
return FALSE;
}
}
+
+static u8 CheckTrainer(u8 mapObjectId)
+{
+ const u8 *scriptPtr;
+ u8 ret = 1;
+ u8 approachDistance;
+
+ if (InTrainerHill() == TRUE)
+ scriptPtr = sub_81D62AC();
+ else
+ scriptPtr = GetFieldObjectScriptPointerByFieldObjectId(mapObjectId);
+
+ if (InBattlePyramid())
+ {
+ if (GetBattlePyramidTrainerFlag(mapObjectId))
+ return 0;
+ }
+ else if (InTrainerHill() == TRUE)
+ {
+ if (GetTrainerHillTrainerFlag(mapObjectId))
+ return 0;
+ }
+ else
+ {
+ if (GetTrainerFlagFromScriptPointer(scriptPtr))
+ return 0;
+ }
+
+ approachDistance = GetTrainerApproachDistance(&gMapObjects[mapObjectId]);
+
+ if (approachDistance != 0)
+ {
+ if (scriptPtr[1] == TRAINER_BATTLE_DOUBLE
+ || scriptPtr[1] == TRAINER_BATTLE_REMATCH_DOUBLE
+ || scriptPtr[1] == TRAINER_BATTLE_CONTINUE_SCRIPT_DOUBLE)
+ {
+ if (GetMonsStateToDoubles_2() != 0)
+ return 0;
+
+ ret = 2;
+ }
+
+ gApproachingTrainers[gNoOfApproachingTrainers].mapObjectId = mapObjectId;
+ gApproachingTrainers[gNoOfApproachingTrainers].trainerScriptPtr = scriptPtr;
+ gApproachingTrainers[gNoOfApproachingTrainers].radius = approachDistance;
+ TrainerApproachPlayer(&gMapObjects[mapObjectId], approachDistance - 1);
+ gNoOfApproachingTrainers++;
+
+ return ret;
+ }
+
+ return 0;
+}
+
+static u8 GetTrainerApproachDistance(struct MapObject *trainerObj)
+{
+ s16 x, y;
+ u8 i;
+ u8 approachDistance;
+
+ PlayerGetDestCoords(&x, &y);
+ if (trainerObj->trainerType == 1) // can only see in one direction
+ {
+ approachDistance = sDirectionalApproachDistanceFuncs[trainerObj->mapobj_unk_18 - 1](trainerObj, trainerObj->trainerRange_berryTreeId, x, y);
+ return CheckPathBetweenTrainerAndPlayer(trainerObj, approachDistance, trainerObj->mapobj_unk_18);
+ }
+ else // can see in all directions
+ {
+ for (i = 0; i < 4; i++)
+ {
+ approachDistance = sDirectionalApproachDistanceFuncs[i](trainerObj, trainerObj->trainerRange_berryTreeId, x, y);
+ if (CheckPathBetweenTrainerAndPlayer(trainerObj, approachDistance, i + 1)) // directions are 1-4 instead of 0-3. south north west east
+ return approachDistance;
+ }
+ }
+
+ return 0;
+}
+
+// Returns how far south the player is from trainer. 0 if out of trainer's sight.
+static u8 GetTrainerApproachDistanceSouth(struct MapObject *trainerObj, s16 range, s16 x, s16 y)
+{
+ if (trainerObj->coords2.x == x
+ && y > trainerObj->coords2.y
+ && y <= trainerObj->coords2.y + range)
+ return (y - trainerObj->coords2.y);
+ else
+ return 0;
+}
+
+// Returns how far north the player is from trainer. 0 if out of trainer's sight.
+static u8 GetTrainerApproachDistanceNorth(struct MapObject *trainerObj, s16 range, s16 x, s16 y)
+{
+ if (trainerObj->coords2.x == x
+ && y < trainerObj->coords2.y
+ && y >= trainerObj->coords2.y - range)
+ return (trainerObj->coords2.y - y);
+ else
+ return 0;
+}
+
+// Returns how far west the player is from trainer. 0 if out of trainer's sight.
+static u8 GetTrainerApproachDistanceWest(struct MapObject *trainerObj, s16 range, s16 x, s16 y)
+{
+ if (trainerObj->coords2.y == y
+ && x < trainerObj->coords2.x
+ && x >= trainerObj->coords2.x - range)
+ return (trainerObj->coords2.x - x);
+ else
+ return 0;
+}
+
+// Returns how far east the player is from trainer. 0 if out of trainer's sight.
+static u8 GetTrainerApproachDistanceEast(struct MapObject *trainerObj, s16 range, s16 x, s16 y)
+{
+ if (trainerObj->coords2.y == y
+ && x > trainerObj->coords2.x
+ && x <= trainerObj->coords2.x + range)
+ return (x - trainerObj->coords2.x);
+ else
+ return 0;
+}
+
+#define COLLISION_MASK (~1)
+
+static u8 CheckPathBetweenTrainerAndPlayer(struct MapObject *trainerObj, u8 approachDistance, u8 direction)
+{
+ s16 x, y;
+ u8 unk19_temp;
+ u8 unk19b_temp;
+ u8 i;
+ u8 collision;
+
+ if (approachDistance == 0)
+ return 0;
+
+ x = trainerObj->coords2.x;
+ y = trainerObj->coords2.y;
+
+ MoveCoords(direction, &x, &y);
+ for (i = 0; i < approachDistance - 1; i++, MoveCoords(direction, &x, &y))
+ {
+ collision = sub_8092C8C(trainerObj, x, y, direction);
+ if (collision != 0 && (collision & COLLISION_MASK))
+ return 0;
+ }
+
+ // preserve mapobj_unk_19 before clearing.
+ unk19_temp = trainerObj->range.as_nybbles.x;
+ unk19b_temp = trainerObj->range.as_nybbles.y;
+ trainerObj->range.as_nybbles.x = 0;
+ trainerObj->range.as_nybbles.y = 0;
+
+ collision = npc_block_way(trainerObj, x, y, direction);
+
+ trainerObj->range.as_nybbles.x = unk19_temp;
+ trainerObj->range.as_nybbles.y = unk19b_temp;
+ if (collision == 4)
+ return approachDistance;
+
+ return 0;
+}
+
+#define tFuncId data[0]
+#define tTrainerRange data[3]
+#define tOutOfAshSpriteId data[4]
+#define tTrainerMapObjectId data[7]
+
+static void TrainerApproachPlayer(struct MapObject *trainerObj, u8 range)
+{
+ struct Task *task;
+
+ gApproachingTrainers[gNoOfApproachingTrainers].taskId = CreateTask(Task_RunTrainerSeeFuncList, 0x50);
+ task = &gTasks[gApproachingTrainers[gNoOfApproachingTrainers].taskId];
+ task->tTrainerRange = range;
+ task->tTrainerMapObjectId = gApproachingTrainers[gNoOfApproachingTrainers].mapObjectId;
+}
+
+static void sub_80B40C8(TaskFunc followupFunc)
+{
+ u8 taskId;
+ TaskFunc taskFunc;
+
+ if (gApproachingTrainerId == 0)
+ taskId = gApproachingTrainers[0].taskId;
+ else
+ taskId = gApproachingTrainers[1].taskId;
+
+ taskFunc = Task_RunTrainerSeeFuncList;
+ SetTaskFuncWithFollowupFunc(taskId, taskFunc, followupFunc);
+ gTasks[taskId].tFuncId = 1;
+ taskFunc(taskId);
+}
+
+static void Task_RunTrainerSeeFuncList(u8 taskId)
+{
+ struct Task *task = &gTasks[taskId];
+ struct MapObject *trainerObj = &gMapObjects[task->tTrainerMapObjectId];
+
+ if (!trainerObj->active)
+ {
+ SwitchTaskToFollowupFunc(taskId);
+ }
+ else
+ {
+ while (sTrainerSeeFuncList[task->tFuncId](taskId, task, trainerObj));
+ }
+}
+
+static bool8 sub_80B4178(u8 taskId, struct Task *task, struct MapObject *trainerObj)
+{
+ return FALSE;
+}
+
+static bool8 sub_80B417C(u8 taskId, struct Task *task, struct MapObject *trainerObj)
+{
+ u8 direction;
+
+ FieldObjectGetLocalIdAndMap(trainerObj, &gFieldEffectArguments[0], &gFieldEffectArguments[1], &gFieldEffectArguments[2]);
+ FieldEffectStart(FLDEFF_EXCLAMATION_MARK_ICON_1);
+ direction = GetFaceDirectionAnimId(trainerObj->mapobj_unk_18);
+ FieldObjectSetSpecialAnim(trainerObj, direction);
+ task->tFuncId++;
+ return TRUE;
+}
+
+static bool8 sub_80B41C0(u8 taskId, struct Task *task, struct MapObject *trainerObj)
+{
+ if (FieldEffectActiveListContains(FLDEFF_EXCLAMATION_MARK_ICON_1))
+ {
+ return FALSE;
+ }
+ else
+ {
+ task->tFuncId++;
+ if (trainerObj->animPattern == 57 || trainerObj->animPattern == 58)
+ task->tFuncId = 6;
+ if (trainerObj->animPattern == 63)
+ task->tFuncId = 8;
+ return TRUE;
+ }
+}
+
+static bool8 sub_80B4200(u8 taskId, struct Task *task, struct MapObject *trainerObj)
+{
+ if (!(FieldObjectIsSpecialAnimOrDirectionSequenceAnimActive(trainerObj)) || FieldObjectClearAnimIfSpecialAnimFinished(trainerObj))
+ {
+ if (task->tTrainerRange)
+ {
+ FieldObjectSetSpecialAnim(trainerObj, GetGoSpeed0AnimId(trainerObj->mapobj_unk_18));
+ task->tTrainerRange--;
+ }
+ else
+ {
+ FieldObjectSetSpecialAnim(trainerObj, 0x3E);
+ task->tFuncId++;
+ }
+ }
+ return FALSE;
+}
+
+static bool8 sub_80B425C(u8 taskId, struct Task *task, struct MapObject *trainerObj)
+{
+ struct MapObject *playerObj;
+
+ if (FieldObjectIsSpecialAnimOrDirectionSequenceAnimActive(trainerObj) && !FieldObjectClearAnimIfSpecialAnimFinished(trainerObj))
+ return FALSE;
+
+ npc_set_running_behaviour_etc(trainerObj, npc_running_behaviour_by_direction(trainerObj->mapobj_unk_18));
+ sub_808F23C(trainerObj, npc_running_behaviour_by_direction(trainerObj->mapobj_unk_18));
+ sub_808F208(trainerObj);
+
+ playerObj = &gMapObjects[gPlayerAvatar.mapObjectId];
+ if (FieldObjectIsSpecialAnimOrDirectionSequenceAnimActive(playerObj) && !FieldObjectClearAnimIfSpecialAnimFinished(playerObj))
+ return FALSE;
+
+ sub_808BCE8();
+ FieldObjectSetSpecialAnim(&gMapObjects[gPlayerAvatar.mapObjectId], GetFaceDirectionAnimId(GetOppositeDirection(trainerObj->mapobj_unk_18)));
+ task->tFuncId++;
+ return FALSE;
+}
+
+static bool8 sub_80B4318(u8 taskId, struct Task *task, struct MapObject *trainerObj)
+{
+ struct MapObject *playerObj = &gMapObjects[gPlayerAvatar.mapObjectId];
+
+ if (!FieldObjectIsSpecialAnimOrDirectionSequenceAnimActive(playerObj)
+ || FieldObjectClearAnimIfSpecialAnimFinished(playerObj))
+ SwitchTaskToFollowupFunc(taskId);
+ return FALSE;
+}
+
+static bool8 sub_80B435C(u8 taskId, struct Task *task, struct MapObject *trainerObj)
+{
+ if (!FieldObjectIsSpecialAnimOrDirectionSequenceAnimActive(trainerObj)
+ || FieldObjectClearAnimIfSpecialAnimFinished(trainerObj))
+ {
+ FieldObjectSetSpecialAnim(trainerObj, 0x59);
+ task->tFuncId++;
+ }
+ return FALSE;
+}
+
+static bool8 sub_80B4390(u8 taskId, struct Task *task, struct MapObject *trainerObj)
+{
+ if (FieldObjectClearAnimIfSpecialAnimFinished(trainerObj))
+ task->tFuncId = 3;
+
+ return FALSE;
+}
+
+static bool8 sub_80B43AC(u8 taskId, struct Task *task, struct MapObject *trainerObj)
+{
+ if (!FieldObjectIsSpecialAnimOrDirectionSequenceAnimActive(trainerObj)
+ || FieldObjectClearAnimIfSpecialAnimFinished(trainerObj))
+ {
+ FieldObjectSetSpecialAnim(trainerObj, 0x3E);
+ task->tFuncId++;
+ }
+ return FALSE;
+}
+
+static bool8 sub_80B43E0(u8 taskId, struct Task *task, struct MapObject *trainerObj)
+{
+ if (FieldObjectCheckIfSpecialAnimFinishedOrInactive(trainerObj))
+ {
+ gFieldEffectArguments[0] = trainerObj->coords2.x;
+ gFieldEffectArguments[1] = trainerObj->coords2.y;
+ gFieldEffectArguments[2] = gSprites[trainerObj->spriteId].subpriority - 1;
+ gFieldEffectArguments[3] = 2;
+ task->tOutOfAshSpriteId = FieldEffectStart(FLDEFF_POP_OUT_OF_ASH);
+ task->tFuncId++;
+ }
+ return FALSE;
+}
+
+static bool8 sub_80B4438(u8 taskId, struct Task *task, struct MapObject *trainerObj)
+{
+ struct Sprite *sprite;
+
+ if (gSprites[task->tOutOfAshSpriteId].animCmdIndex == 2)
+ {
+ trainerObj->mapobj_bit_26 = 0;
+ trainerObj->mapobj_bit_2 = 1;
+
+ sprite = &gSprites[trainerObj->spriteId];
+ sprite->oam.priority = 2;
+ FieldObjectClearAnimIfSpecialAnimFinished(trainerObj);
+ FieldObjectSetSpecialAnim(trainerObj, sub_80934BC(trainerObj->mapobj_unk_18));
+ task->tFuncId++;
+ }
+
+ return FALSE;
+}
+
+static bool8 sub_80B44AC(u8 taskId, struct Task *task, struct MapObject *trainerObj)
+{
+ if (!FieldEffectActiveListContains(FLDEFF_POP_OUT_OF_ASH))
+ task->tFuncId = 3;
+
+ return FALSE;
+}
+
+#undef tFuncId
+#undef tTrainerRange
+#undef tOutOfAshSpriteId
+#undef tTrainerMapObjectId
+
+static void sub_80B44C8(u8 taskId)
+{
+ struct Task *task = &gTasks[taskId];
+ struct MapObject *mapObj;
+
+ // another mapObj loaded into by loadword?
+ LoadWordFromTwoHalfwords(&task->data[1], (u32 *)&mapObj);
+ if (!task->data[7])
+ {
+ FieldObjectClearAnim(mapObj);
+ task->data[7]++;
+ }
+ sTrainerSeeFuncList2[task->data[0]](taskId, task, mapObj);
+ if (task->data[0] == 3 && !FieldEffectActiveListContains(FLDEFF_POP_OUT_OF_ASH))
+ {
+ npc_set_running_behaviour_etc(mapObj, npc_running_behaviour_by_direction(mapObj->mapobj_unk_18));
+ sub_808F23C(mapObj, npc_running_behaviour_by_direction(mapObj->mapobj_unk_18));
+ DestroyTask(taskId);
+ }
+ else
+ {
+ mapObj->mapobj_bit_7 = 0;
+ }
+}
+
+void sub_80B4578(struct MapObject *var)
+{
+ StoreWordInTwoHalfwords(&gTasks[CreateTask(sub_80B44C8, 0)].data[1], (u32)var);
+}
+
+void EndTrainerApproach(void)
+{
+ sub_80B40C8(Task_DestroyTrainerApproachTask);
+}
+
+static void Task_DestroyTrainerApproachTask(u8 taskId)
+{
+ DestroyTask(taskId);
+ EnableBothScriptContexts();
+}
+
+void sub_80B45D0(void)
+{
+ if (gNoOfApproachingTrainers == 2)
+ {
+ if (gApproachingTrainerId == 0)
+ {
+ gApproachingTrainerId++;
+ gSpecialVar_Result = 1;
+ UnfreezeMapObjects();
+ sub_80974D0(gApproachingTrainers[1].mapObjectId);
+ }
+ else
+ {
+ gApproachingTrainerId = 0;
+ gSpecialVar_Result = 0;
+ }
+ }
+ else
+ {
+ gSpecialVar_Result = 0;
+ }
+}
+
+#define sLocalId data[0]
+#define sMapNum data[1]
+#define sMapGroup data[2]
+#define sData3 data[3]
+#define sData4 data[4]
+#define sFldEffId data[7]
+
+u8 FldEff_ExclamationMarkIcon1(void)
+{
+ u8 spriteId = CreateSpriteAtEnd(&sSpriteTemplate_ExclamationQuestionMark, 0, 0, 0x53);
+
+ if (spriteId != MAX_SPRITES)
+ SetIconSpriteData(&gSprites[spriteId], FLDEFF_EXCLAMATION_MARK_ICON_1, 0);
+
+ return 0;
+}
+
+u8 FldEff_ExclamationMarkIcon2(void)
+{
+ u8 spriteId = CreateSpriteAtEnd(&sSpriteTemplate_ExclamationQuestionMark, 0, 0, 0x52);
+
+ if (spriteId != MAX_SPRITES)
+ SetIconSpriteData(&gSprites[spriteId], FLDEFF_EXCLAMATION_MARK_ICON_2, 1);
+
+ return 0;
+}
+
+u8 FldEff_HeartIcon(void)
+{
+ u8 spriteId = CreateSpriteAtEnd(&sSpriteTemplate_HeartIcon, 0, 0, 0x52);
+
+ if (spriteId != MAX_SPRITES)
+ {
+ struct Sprite *sprite = &gSprites[spriteId];
+
+ SetIconSpriteData(sprite, FLDEFF_HEART_ICON, 0);
+ sprite->oam.paletteNum = 2;
+ }
+
+ return 0;
+}
+
+static void SetIconSpriteData(struct Sprite *sprite, u16 fldEffId, u8 spriteAnimNum)
+{
+ sprite->oam.priority = 1;
+ sprite->coordOffsetEnabled = 1;
+
+ sprite->sLocalId = gFieldEffectArguments[0];
+ sprite->sMapNum = gFieldEffectArguments[1];
+ sprite->sMapGroup = gFieldEffectArguments[2];
+ sprite->sData3 = -5;
+ sprite->sFldEffId = fldEffId;
+
+ StartSpriteAnim(sprite, spriteAnimNum);
+}
+
+static void SpriteCB_TrainerIcons(struct Sprite *sprite)
+{
+ u8 mapObjId;
+
+ if (TryGetFieldObjectIdByLocalIdAndMap(sprite->sLocalId, sprite->sMapNum, sprite->sMapGroup, &mapObjId)
+ || sprite->animEnded)
+ {
+ FieldEffectStop(sprite, sprite->sFldEffId);
+ }
+ else
+ {
+ struct Sprite *mapObjSprite = &gSprites[gMapObjects[mapObjId].spriteId];
+ sprite->sData4 += sprite->sData3;
+ sprite->pos1.x = mapObjSprite->pos1.x;
+ sprite->pos1.y = mapObjSprite->pos1.y - 16;
+ sprite->pos2.x = mapObjSprite->pos2.x;
+ sprite->pos2.y = mapObjSprite->pos2.y + sprite->sData4;
+ if (sprite->sData4)
+ sprite->sData3++;
+ else
+ sprite->sData3 = 0;
+ }
+}
+
+#undef sLocalId
+#undef sMapNum
+#undef sMapGroup
+#undef sData3
+#undef sData4
+#undef sFldEffId
+
+u8 GetCurrentApproachingTrainerMapObjectId(void)
+{
+ if (gApproachingTrainerId == 0)
+ return gApproachingTrainers[0].mapObjectId;
+ else
+ return gApproachingTrainers[1].mapObjectId;
+}
+
+u8 GetChosenApproachingTrainerMapObjectId(u8 arrayId)
+{
+ if (arrayId >= ARRAY_COUNT(gApproachingTrainers))
+ return 0;
+ else if (arrayId == 0)
+ return gApproachingTrainers[0].mapObjectId;
+ else
+ return gApproachingTrainers[1].mapObjectId;
+}
+
+void sub_80B4808(void)
+{
+ struct MapObject *trainerObj;
+
+ if (gUnknown_030060AC == 1)
+ {
+ trainerObj = &gMapObjects[gApproachingTrainers[gUnknown_03006080].mapObjectId];
+ gUnknown_03006084[0] = GetFaceDirectionAnimId(GetOppositeDirection(trainerObj->mapobj_unk_18));
+ gUnknown_03006084[1] = 0xFE;
+ ScriptMovement_StartObjectMovementScript(0xFF, gSaveBlock1Ptr->location.mapNum, gSaveBlock1Ptr->location.mapGroup, gUnknown_03006084);
+ }
+ else
+ {
+ trainerObj = &gMapObjects[gPlayerAvatar.mapObjectId];
+ gUnknown_03006084[0] = GetFaceDirectionAnimId(trainerObj->mapobj_unk_18);
+ gUnknown_03006084[1] = 0xFE;
+ ScriptMovement_StartObjectMovementScript(0xFF, gSaveBlock1Ptr->location.mapNum, gSaveBlock1Ptr->location.mapGroup, gUnknown_03006084);
+ }
+
+ sub_809BE48(0xFF);
+}
diff --git a/src/use_pokeblock.c b/src/use_pokeblock.c
new file mode 100644
index 000000000..12f475c93
--- /dev/null
+++ b/src/use_pokeblock.c
@@ -0,0 +1,230 @@
+#include "global.h"
+#include "main.h"
+#include "pokeblock.h"
+#include "malloc.h"
+#include "palette.h"
+#include "pokenav.h"
+#include "unknown_task.h"
+#include "text.h"
+#include "bg.h"
+#include "window.h"
+#include "text_window.h"
+
+struct UsePokeblockSubStruct
+{
+ void (*field_0)(void);
+ void (*callback)(void);
+ struct Pokeblock *pokeblock;
+ struct Pokemon *pokemon;
+ u8 stringBuffer[0x40];
+ u8 field_50;
+ u8 field_51;
+ u8 field_52;
+ u8 field_53;
+ u8 field_54;
+ u8 field_55;
+ u8 field_56;
+ u8 field_57[5];
+ u8 field_5c[5];
+ u8 field_61[5];
+ s16 field_66[5];
+};
+
+struct UsePokeblockStruct
+{
+ u8 field_0[0x7C58];
+ u8 field_7C58[0x378];
+ struct UsePokeblockSubStruct info;
+};
+
+extern u16 gKeyRepeatStartDelay;
+
+// this file's functions
+void sub_816636C(void (*func)(void));
+void sub_8166380(void);
+void sub_816631C(void);
+void sub_81662C0(void);
+void sub_8166564(void);
+void sub_8166304(void);
+void sub_81668F8(void);
+void sub_8167420(void);
+void sub_8167760(void);
+u8 sub_81672E4(u8 arg0);
+bool8 sub_8168328(void);
+bool8 sub_8167930(void);
+void sub_8167608(u8 arg0);
+void sub_8167BA0(u16 arg0, u8 copyToVramMode);
+
+extern const struct BgTemplate gUnknown_085DFCCC[4];
+extern const struct WindowTemplate gUnknown_085DFCDC[];
+
+// ram variables
+EWRAM_DATA struct UsePokeblockSubStruct *gUnknown_0203BC90 = NULL;
+EWRAM_DATA void (*gUnknown_0203BC94)(void) = NULL;
+EWRAM_DATA struct Pokeblock *gUnknown_0203BC98 = NULL;
+EWRAM_DATA u8 gPokeblockMonId = 0;
+EWRAM_DATA s16 gPokeblockGain = 0;
+EWRAM_DATA void *gUnknown_0203BCA0 = NULL;
+EWRAM_DATA void *gUnknown_0203BCA4 = NULL;
+EWRAM_DATA void *gUnknown_0203BCA8 = NULL;
+EWRAM_DATA struct UsePokeblockStruct *gUnknown_0203BCAC = NULL;
+
+// const rom data
+// todo: make it static once the file is decompiled
+
+// code
+void ChooseMonToGivePokeblock(struct Pokeblock *pokeblock, void (*callback)(void))
+{
+ gUnknown_0203BCAC = AllocZeroed(0x806C);
+ gUnknown_0203BC90 = &gUnknown_0203BCAC->info;
+ gUnknown_0203BC90->pokeblock = pokeblock;
+ gUnknown_0203BC90->callback = callback;
+ sub_816636C(sub_8166380);
+ SetMainCallback2(sub_816631C);
+}
+
+void CB2_ReturnAndChooseMonToGivePokeblock(void)
+{
+ gUnknown_0203BCAC = AllocZeroed(0x806C);
+ gUnknown_0203BC90 = &gUnknown_0203BCAC->info;
+ gUnknown_0203BC90->pokeblock = gUnknown_0203BC98;
+ gUnknown_0203BC90->callback = gUnknown_0203BC94;
+ gPokeblockMonId = sub_81672E4(gPokeblockMonId);
+ gUnknown_0203BC90->field_56 = gPokeblockMonId < 4 ? 0 : 1;
+ sub_816636C(sub_8166380);
+ SetMainCallback2(sub_81662C0);
+}
+
+void sub_81662C0(void)
+{
+ gUnknown_0203BC90->field_0();
+ AnimateSprites();
+ BuildOamBuffer();
+ UpdatePaletteFade();
+ if (gUnknown_0203BC90->field_0 == sub_8166564)
+ {
+ gUnknown_0203BC90->field_50 = 0;
+ SetMainCallback2(sub_8166304);
+ }
+}
+
+void sub_8166304(void)
+{
+ sub_81668F8();
+ AnimateSprites();
+ BuildOamBuffer();
+ UpdatePaletteFade();
+}
+
+void sub_816631C(void)
+{
+ gUnknown_0203BC90->field_0();
+ AnimateSprites();
+ BuildOamBuffer();
+ RunTextPrinters();
+ UpdatePaletteFade();
+}
+
+void sub_8166340(void)
+{
+ LoadOam();
+ ProcessSpriteCopyRequests();
+ TransferPlttBuffer();
+ sub_81D2108(gUnknown_0203BCAC->field_7C58);
+ sub_80BA0A8();
+}
+
+void sub_816636C(void (*func)(void))
+{
+ gUnknown_0203BC90->field_0 = func;
+ gUnknown_0203BC90->field_50 = 0;
+}
+
+void sub_8166380(void)
+{
+ switch (gUnknown_0203BC90->field_50)
+ {
+ case 0:
+ gUnknown_0203BCAC->field_0[0x7B10] = 0xFF;
+ sub_81D1ED4(gUnknown_0203BCAC->field_7C58);
+ gUnknown_0203BC90->field_50++;
+ break;
+ case 1:
+ ResetSpriteData();
+ FreeAllSpritePalettes();
+ gUnknown_0203BC90->field_50++;
+ break;
+ case 2:
+ SetVBlankCallback(NULL);
+ CpuFill32(0, (void*)(VRAM), VRAM_SIZE);
+ gUnknown_0203BC90->field_50++;
+ break;
+ case 3:
+ ResetBgsAndClearDma3BusyFlags(0);
+ InitBgsFromTemplates(0, gUnknown_085DFCCC, ARRAY_COUNT(gUnknown_085DFCCC));
+ InitWindows(gUnknown_085DFCDC);
+ DeactivateAllTextPrinters();
+ sub_809882C(0, 0x97, 0xE0);
+ gUnknown_0203BC90->field_50++;
+ break;
+ case 4:
+ gUnknown_0203BC90->field_50++;
+ break;
+ case 5:
+ if (!sub_8168328())
+ {
+ gUnknown_0203BC90->field_50++;
+ }
+ break;
+ case 6:
+ gKeyRepeatStartDelay = 20;
+ sub_8167420();
+ gUnknown_0203BC90->field_50++;
+ break;
+ case 7:
+ if (!sub_8167930())
+ {
+ gUnknown_0203BC90->field_50++;
+ }
+ break;
+ case 8:
+ sub_8167608(0);
+ sub_8167760();
+ gUnknown_0203BC90->field_50++;
+ break;
+ case 9:
+ if (!sub_81D312C(&gUnknown_0203BCAC->field_0[0x7B0E]))
+ {
+ gUnknown_0203BC90->field_50++;
+ }
+ break;
+ case 10:
+ gUnknown_0203BC90->field_50++;
+ break;
+ case 11:
+ sub_81D2754(gUnknown_0203BCAC->field_7C58, &gUnknown_0203BCAC->field_0[0x7C6C]);
+ sub_81D20AC(gUnknown_0203BCAC->field_7C58);
+ gUnknown_0203BC90->field_50++;
+ break;
+ case 12:
+ if (!sub_81D20BC(gUnknown_0203BCAC->field_7C58))
+ {
+ sub_81D1F84(gUnknown_0203BCAC->field_7C58, &gUnknown_0203BCAC->field_7C58[0x14], &gUnknown_0203BCAC->field_7C58[0x14]);
+ gUnknown_0203BC90->field_50++;
+ }
+ break;
+ case 13:
+ sub_81D2230(gUnknown_0203BCAC->field_7C58);
+ gUnknown_0203BC90->field_50++;
+ break;
+ case 14:
+ PutWindowTilemap(0);
+ PutWindowTilemap(1);
+ sub_8167BA0(0, 1);
+ gUnknown_0203BC90->field_50++;
+ break;
+ case 15:
+ sub_816636C(sub_8166564);
+ break;
+ }
+}
diff --git a/src/wallclock.c b/src/wallclock.c
index cd85de230..897576719 100644
--- a/src/wallclock.c
+++ b/src/wallclock.c
@@ -16,7 +16,7 @@
#include "task.h"
#include "strings.h"
#include "sound.h"
-#include "songs.h"
+#include "constants/songs.h"
#include "trig.h"
#include "decompress.h"