diff --git a/common_syms/field_control_avatar.txt b/common_syms/field_control_avatar.txt index 0b9b08091..c243b56ec 100644 --- a/common_syms/field_control_avatar.txt +++ b/common_syms/field_control_avatar.txt @@ -1 +1 @@ -gInputToStoreInQuestLogMaybe +gFieldInputRecord diff --git a/common_syms/quest_log.txt b/common_syms/quest_log.txt index d4c211bb0..e5e3ec49c 100644 --- a/common_syms/quest_log.txt +++ b/common_syms/quest_log.txt @@ -1,4 +1,4 @@ gQuestLogPlaybackState -sNumEventsInLogEntry +sMaxActionsInScene gQuestLogFieldInput -sCurQuestLogEntry +sCurSceneActions diff --git a/data/event_scripts.s b/data/event_scripts.s index d6aa4d512..96bbd0349 100644 --- a/data/event_scripts.s +++ b/data/event_scripts.s @@ -36,6 +36,7 @@ #include "constants/easy_chat.h" #include "constants/trainer_card.h" #include "constants/help_system.h" +#include "constants/trainer_fan_club.h" #include "constants/mystery_gift.h" .include "asm/macros.inc" .include "asm/macros/event.inc" diff --git a/graphics/quest_log/description_window.png b/graphics/quest_log/description_window.png new file mode 100644 index 000000000..05e676c09 Binary files /dev/null and b/graphics/quest_log/description_window.png differ diff --git a/graphics/unknown/unknown_8456638.bin b/graphics/unknown/unknown_8456638.bin deleted file mode 100644 index 53ea8cfb8..000000000 --- a/graphics/unknown/unknown_8456638.bin +++ /dev/null @@ -1 +0,0 @@ -»»»»ÌÌÌÌÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÌÌÌÌ»»»» \ No newline at end of file diff --git a/include/battle.h b/include/battle.h index dd9c3ffcb..3771ef33a 100644 --- a/include/battle.h +++ b/include/battle.h @@ -449,7 +449,7 @@ struct BattleStruct u16 castformPalette[MAX_BATTLERS_COUNT][16]; u8 wishPerishSongState; u8 wishPerishSongBattlerId; - u8 field_182; + u8 lastAttackerToFaintOpponent; // align 4 union { struct LinkBattlerHeader linkBattlerHeader; diff --git a/include/constants/quest_log.h b/include/constants/quest_log.h index 58efd6ea3..fe284ba13 100644 --- a/include/constants/quest_log.h +++ b/include/constants/quest_log.h @@ -5,6 +5,12 @@ #define QL_STATE_PLAYBACK 2 #define QL_STATE_PLAYBACK_LAST 3 +#define QL_PLAYBACK_STATE_STOPPED 0 +#define QL_PLAYBACK_STATE_RUNNING 1 +#define QL_PLAYBACK_STATE_RECORDING 2 +#define QL_PLAYBACK_STATE_ACTION_END 3 +#define QL_PLAYBACK_STATE_RECORDING_NO_DELAY 4 + #define QL_START_NORMAL 1 #define QL_START_WARP 2 @@ -16,9 +22,9 @@ #define QL_IS_PLAYBACK_STATE (gQuestLogState == QL_STATE_PLAYBACK || gQuestLogState == QL_STATE_PLAYBACK_LAST) -#define QL_EVENT_0 0 // Null -#define QL_EVENT_1 1 // Null -#define QL_EVENT_2 2 // Null +#define QL_EVENT_INPUT 0 // Null +#define QL_EVENT_GFX_CHANGE 1 // Null +#define QL_EVENT_MOVEMENT 2 // Null #define QL_EVENT_SWITCHED_PARTY_ORDER 3 #define QL_EVENT_USED_ITEM 4 #define QL_EVENT_GAVE_HELD_ITEM 5 @@ -55,12 +61,12 @@ #define QL_EVENT_USED_FIELD_MOVE 36 #define QL_EVENT_BOUGHT_ITEM 37 #define QL_EVENT_SOLD_ITEM 38 -#define QL_EVENT_39 39 // Null -#define QL_EVENT_OBTAINED_ITEM 40 -#define QL_EVENT_41 41 // Null +#define QL_EVENT_SCENE_END 39 // Null +#define QL_EVENT_OBTAINED_STORY_ITEM 40 +#define QL_EVENT_WAIT 41 // Null #define QL_EVENT_ARRIVED 42 -#define QL_EVENT_USED_POKEMART QL_EVENT_BOUGHT_ITEM - 1 // Used as a start pos for QL_EVENT_BOUGHT_ITEM / QL_EVENT_SOLD_ITEM +#define QL_EVENT_USED_POKEMART (QL_EVENT_BOUGHT_ITEM - 1) // Used as a start pos for QL_EVENT_BOUGHT_ITEM / QL_EVENT_SOLD_ITEM #define IS_LINK_QL_EVENT(event)((event) >= QL_EVENT_LINK_TRADED && (event) <= QL_EVENT_LINK_BATTLED_UNION) #define IS_VALID_QL_EVENT(event)((event) >= QL_EVENT_SWITCHED_PARTY_ORDER && (event) <= QL_EVENT_ARRIVED) @@ -128,28 +134,23 @@ #define QL_DEPARTED_MISC_BUILDING_1 8 #define QL_DEPARTED_MISC_BUILDING_2 9 -#define QL_INPUT_OFF 0 -#define QL_INPUT_UP 1 -#define QL_INPUT_DOWN 2 -#define QL_INPUT_LEFT 3 -#define QL_INPUT_RIGHT 4 -#define QL_INPUT_L 5 -#define QL_INPUT_R 6 -#define QL_INPUT_START 7 +#define QL_INPUT_OFF 0 +#define QL_INPUT_UP 1 +#define QL_INPUT_DOWN 2 +#define QL_INPUT_LEFT 3 +#define QL_INPUT_RIGHT 4 +#define QL_INPUT_L 5 +#define QL_INPUT_R 6 +#define QL_INPUT_START 7 #define QL_INPUT_SELECT 8 -#define QL_INPUT_A 9 -#define QL_INPUT_B 10 +#define QL_INPUT_A 9 +#define QL_INPUT_B 10 - -#define FANCLUB_MEMBER1 0 -#define FANCLUB_MEMBER2 1 -#define FANCLUB_MEMBER3 2 -#define FANCLUB_MEMBER4 3 -#define FANCLUB_MEMBER5 4 -#define FANCLUB_MEMBER6 5 -#define FANCLUB_MEMBER7 6 -#define FANCLUB_MEMBER8 7 - -#define NUM_TRAINER_FAN_CLUB_MEMBERS 8 +#define QL_ACTION_MOVEMENT 0 +#define QL_ACTION_GFX_CHANGE 1 +#define QL_ACTION_INPUT 2 +#define QL_ACTION_EMPTY 3 +#define QL_ACTION_WAIT 254 +#define QL_ACTION_SCENE_END 255 #endif //GUARD_CONSTANTS_QUEST_LOG_H diff --git a/include/constants/trainer_fan_club.h b/include/constants/trainer_fan_club.h new file mode 100644 index 000000000..86f5a6063 --- /dev/null +++ b/include/constants/trainer_fan_club.h @@ -0,0 +1,15 @@ +#ifndef GUARD_CONSTANTS_TRAINER_FAN_CLUB_H +#define GUARD_CONSTANTS_TRAINER_FAN_CLUB_H + +#define FANCLUB_MEMBER1 0 +#define FANCLUB_MEMBER2 1 +#define FANCLUB_MEMBER3 2 +#define FANCLUB_MEMBER4 3 +#define FANCLUB_MEMBER5 4 +#define FANCLUB_MEMBER6 5 +#define FANCLUB_MEMBER7 6 +#define FANCLUB_MEMBER8 7 + +#define NUM_TRAINER_FAN_CLUB_MEMBERS 8 + +#endif //GUARD_CONSTANTS_TRAINER_FAN_CLUB_H diff --git a/include/event_object_movement.h b/include/event_object_movement.h index 814c7b1ad..128189b0b 100644 --- a/include/event_object_movement.h +++ b/include/event_object_movement.h @@ -126,7 +126,7 @@ void MoveCoords(u8, s16 *, s16 *); bool8 ObjectEventIsHeldMovementActive(struct ObjectEvent *); u8 ObjectEventClearHeldMovementIfFinished(struct ObjectEvent *); u8 GetObjectEventIdByPosition(u16 x, u16 y, u8 elevation); -void UpdateQuestLogObjectEventCurrentMovement(struct ObjectEvent *, struct Sprite *); +void QL_UpdateObjectEventCurrentMovement(struct ObjectEvent *, struct Sprite *); bool8 ObjectEventSetHeldMovement(struct ObjectEvent *, u8); void ShiftStillObjectEventCoords(struct ObjectEvent *); void OverrideMovementTypeForObjectEvent(const struct ObjectEvent *, u8); diff --git a/include/field_control_avatar.h b/include/field_control_avatar.h index 25eaf45ae..a6631493d 100644 --- a/include/field_control_avatar.h +++ b/include/field_control_avatar.h @@ -21,7 +21,7 @@ struct FieldInput u8 dpadDirection; }; -extern struct FieldInput gInputToStoreInQuestLogMaybe; +extern struct FieldInput gFieldInputRecord; void RestartWildEncounterImmunitySteps(void); void ClearPoisonStepCounter(void); diff --git a/include/global.h b/include/global.h index 3c643f184..ab42b113c 100644 --- a/include/global.h +++ b/include/global.h @@ -550,7 +550,7 @@ struct RecordMixingDayCareMail bool16 holdsItem[DAYCARE_MON_COUNT]; }; -struct QuestLogNPCData +struct QuestLogObjectEventTemplate { u32 x:8; u32 negx:1; @@ -579,12 +579,12 @@ struct QuestLogObjectEvent /*0x01*/ u8 spriteAffineAnimPausedBackup:1; /*0x01*/ u8 disableJumpLandingGroundEffect:1; /*0x02*/ u8 fixedPriority:1; - /*0x02*/ u8 mapobj_unk_18:4; - /*0x02*/ u8 unused_02_5:3; - /*0x03*/ u8 mapobj_unk_0B_0:4; - /*0x03*/ u8 elevation:4; + /*0x02*/ u8 facingDirection:4; + /*0x02*/ u8 unused:3; + /*0x03*/ u8 currentElevation:4; + /*0x03*/ u8 previousElevation:4; /*0x04*/ u8 graphicsId; - /*0x05*/ u8 animPattern; + /*0x05*/ u8 movementType; /*0x06*/ u8 trainerType; /*0x07*/ u8 localId; /*0x08*/ u8 mapNum; @@ -597,21 +597,20 @@ struct QuestLogObjectEvent /*0x11*/ u8 animId; }; -struct QuestLog +// This represents all the data needed to display a single scene for the "Quest Log" when the player resumes playing. +// +struct QuestLogScene { - /*0x0000*/ u8 startType; + /*0x0000*/ u8 startType; // QL_START_NORMAL / QL_START_WARP /*0x0001*/ u8 mapGroup; /*0x0002*/ u8 mapNum; /*0x0003*/ u8 warpId; /*0x0004*/ s16 x; /*0x0006*/ s16 y; - /*0x0008*/ struct QuestLogObjectEvent unk_008[OBJECT_EVENTS_COUNT]; - - // These arrays hold the game state for - // playing back the quest log + /*0x0008*/ struct QuestLogObjectEvent objectEvents[OBJECT_EVENTS_COUNT]; /*0x0148*/ u8 flags[NUM_FLAG_BYTES]; /*0x02c8*/ u16 vars[VARS_COUNT]; - /*0x0468*/ struct QuestLogNPCData npcData[64]; + /*0x0468*/ struct QuestLogObjectEventTemplate objectEventTemplates[OBJECT_EVENT_TEMPLATES_COUNT]; /*0x0568*/ u16 script[128]; /*0x0668*/ u16 end[0]; }; @@ -780,7 +779,7 @@ struct SaveBlock1 /*0x0EE0*/ u8 flags[NUM_FLAG_BYTES]; /*0x1000*/ u16 vars[VARS_COUNT]; /*0x1200*/ u32 gameStats[NUM_GAME_STATS]; - /*0x1300*/ struct QuestLog questLog[QUEST_LOG_SCENE_COUNT]; + /*0x1300*/ struct QuestLogScene questLog[QUEST_LOG_SCENE_COUNT]; /*0x2CA0*/ u16 easyChatProfile[EASY_CHAT_BATTLE_WORDS_COUNT]; /*0x2CAC*/ u16 easyChatBattleStart[EASY_CHAT_BATTLE_WORDS_COUNT]; /*0x2CB8*/ u16 easyChatBattleWon[EASY_CHAT_BATTLE_WORDS_COUNT]; diff --git a/include/pokemon_storage_system_internal.h b/include/pokemon_storage_system_internal.h index 9c1984825..9bd3434a2 100644 --- a/include/pokemon_storage_system_internal.h +++ b/include/pokemon_storage_system_internal.h @@ -3,6 +3,7 @@ #include "pokemon_storage_system.h" #include "mon_markings.h" +#include "quest_log.h" // The maximum number of Pokémon icons that can appear on-screen. // By default the limit is 40 (though in practice only 37 can be). @@ -273,14 +274,6 @@ struct PokeStorageItemIcon u8 active; }; -struct PokeStorageQuestLogData -{ - u16 species1; - u16 species2; - u8 box1; - u8 box2; -}; - struct PokemonStorageSystemData { u8 state; @@ -426,7 +419,7 @@ struct PokemonStorageSystemData struct PokeStorageItemIcon itemIcons[MAX_ITEM_ICONS]; u16 movingItemId; u16 itemInfoWindowOffset; - struct PokeStorageQuestLogData pokeStorageQuestLogData; + struct QuestLogEvent_MovedBoxMon questLogData; u16 unusedField2; u16 displayMonPalOffset; u16 *displayMonTilePtr; diff --git a/include/quest_log.h b/include/quest_log.h index 4d3852618..279786985 100644 --- a/include/quest_log.h +++ b/include/quest_log.h @@ -3,63 +3,202 @@ #include "global.h" #include "quest_log_battle.h" -#include "constants/quest_log.h" #include "field_control_avatar.h" +#include "constants/quest_log.h" +#include "constants/battle.h" + +// Layout of Quest Log script commands +#define QL_CMD_EVENT_MASK 0x0FFF +#define QL_CMD_COUNT_SHIFT 12 +#define QL_CMD_COUNT_MASK (0xF << QL_CMD_COUNT_SHIFT) // Parameter to QuestLog_OnEscalatorWarp #define QL_ESCALATOR_OUT 1 #define QL_ESCALATOR_IN 2 -struct QuestLogEntry +struct QuestLogAction { - // When command == 2, these fields have different meanings - u8 localId; // cmd == 2: Pressed A/B, checked wild, held direction, took step - u8 mapNum; // cmd == 2: Always set to 0 - u8 mapGroup; // cmd == 2: Dpad direction - u8 animId; // cmd == 2: Always set to 0 + union { + struct { + u8 localId; + u8 mapNum; + u8 mapGroup; + u8 movementActionId; + } a; // Data when type == 0 + struct { + u8 localId; + u8 mapNum; + u8 mapGroup; + u8 gfxState; + } b; // Data when type == 1 + u8 fieldInput[4]; // Data when type == 2 + u8 raw[4]; + } data; u16 duration; - u8 command; + u8 type; }; -struct UnkStruct_203B044 +struct QuestLogRepeatEventTracker { u8 id; - u8 unk_1; - u16 unk_2; + u8 numRepeats; + u16 counter; +}; + +// Event data structs + +// QL_EVENT_SWITCHED_PARTY_ORDER +struct QuestLogEvent_SwitchedPartyOrder +{ + u16 species1; + u16 species2; +}; + +// QL_EVENT_USED_ITEM +// QL_EVENT_GAVE_HELD_ITEM +// QL_EVENT_GAVE_HELD_ITEM_BAG +// QL_EVENT_GAVE_HELD_ITEM_PC +// QL_EVENT_TOOK_HELD_ITEM +// QL_EVENT_DEPOSITED_ITEM_PC +// QL_EVENT_WITHDREW_ITEM_PC +struct QuestLogEvent_Item +{ + u16 itemId; + u16 unused; + u16 species; + u16 itemParam; +}; + +// QL_EVENT_SWAPPED_HELD_ITEM +// QL_EVENT_SWAPPED_HELD_ITEM_PC +struct QuestLogEvent_SwappedHeldItem +{ + u16 takenItemId; + u16 givenItemId; + u16 species; +}; + +// QL_EVENT_LINK_TRADED +// QL_EVENT_LINK_TRADED_UNION +struct QuestLogEvent_Traded +{ + u16 speciesSent; + u16 speciesReceived; + u8 partnerName[PLAYER_NAME_LENGTH]; +}; + +// QL_EVENT_LINK_BATTLED_SINGLE +// QL_EVENT_LINK_BATTLED_DOUBLE +// QL_EVENT_LINK_BATTLED_MULTI +// QL_EVENT_LINK_BATTLED_UNION +struct QuestLogEvent_LinkBattle +{ + u8 outcome; + u8 playerNames[MAX_BATTLERS_COUNT - 1][PLAYER_NAME_LENGTH]; +}; + +// QL_EVENT_SWITCHED_MONS_BETWEEN_BOXES +// QL_EVENT_SWITCHED_MONS_WITHIN_BOX +// QL_EVENT_SWITCHED_PARTY_MON_FOR_PC_MON +// QL_EVENT_MOVED_MON_BETWEEN_BOXES +// QL_EVENT_MOVED_MON_WITHIN_BOX +// QL_EVENT_WITHDREW_MON_PC +// QL_EVENT_DEPOSITED_MON_PC +// QL_EVENT_SWITCHED_MULTIPLE_MONS +struct QuestLogEvent_MovedBoxMon +{ + u16 species1; + u16 species2; + u8 box1; + u8 box2; +}; + +// QL_EVENT_DEFEATED_TRAINER +// QL_EVENT_DEFEATED_GYM_LEADER +// QL_EVENT_DEFEATED_E4_MEMBER +// QL_EVENT_DEFEATED_CHAMPION +struct QuestLogEvent_TrainerBattle +{ + u16 trainerId; + u16 speciesOpponent; + u16 speciesPlayer; + u8 hpFractionId; + u8 mapSec; +}; + +// QL_EVENT_DEFEATED_WILD_MON +struct QuestLogEvent_WildBattle +{ + u16 defeatedSpecies; + u16 caughtSpecies; + u8 mapSec; +}; + +// QL_EVENT_DEPARTED +struct QuestLogEvent_Departed +{ + u8 mapSec; + u8 locationId; +}; + +// QL_EVENT_USED_FIELD_MOVE +struct QuestLogEvent_FieldMove +{ + u16 species; + u8 fieldMove; + u8 mapSec; +}; + +// QL_EVENT_BOUGHT_ITEM +// QL_EVENT_SOLD_ITEM +struct QuestLogEvent_Shop +{ + u32 totalMoney; // Total amount of money spent buying or earned selling + u16 lastItemId; + u16 itemQuantity; // Total number of items bought or sold + u8 mapSec; + bool8 hasMultipleTransactions; + u8 logEventId; // Either 0 (empty), 1 (bought) or 2 (sold) +}; + +// QL_EVENT_OBTAINED_STORY_ITEM +struct QuestLogEvent_StoryItem +{ + u16 itemId; + u8 mapSec; }; extern u8 gQuestLogState; extern u8 gQuestLogPlaybackState; extern struct FieldInput gQuestLogFieldInput; -extern struct UnkStruct_203B044 gUnknown_203B044; -extern u16 *gUnknown_203AE04; -extern u16 *sEventRecordingPointer; -extern u16 sQuestLogCursor; +extern struct QuestLogRepeatEventTracker gQuestLogRepeatEventTracker; +extern u16 *gQuestLogDefeatedWildMonRecord; +extern u16 *gQuestLogRecordingPointer; +extern u16 gQuestLogCurActionIdx; void QuestLogRecordPlayerAvatarGfxTransition(u8); void SetQuestLogEvent(u16, const u16 *); void SetQLPlayedTheSlots(void); void QuestLog_RecordEnteredMap(u16); -u8 sub_8112CAC(void); -bool8 QuestLog_SchedulePlaybackCB(void (*func)(void)); +u8 QL_GetPlaybackState(void); +bool8 QL_AvoidDisplay(void (*func)(void)); void QuestLog_BackUpPalette(u16 offset, u16 size); void CommitQuestLogWindow1(void); void QuestLog_DrawPreviouslyOnQuestHeaderIfInPlaybackMode(void); void ResetQuestLog(void); void ResetTrainerFanClub(void); -void TrySetUpQuestLogScenes_ElseContinueFromSave(u8 taskId); +void TryStartQuestLogPlayback(u8 taskId); void SaveQuestLogData(void); void QuestLog_CutRecording(void); -u8 sub_8112CAC(void); void ResetDeferredLinkEvent(void); -void FinishRecordingQuestLogScene(void); +void QL_FinishRecordingScene(void); void QuestLogEvents_HandleEndTrainerBattle(void); void *QuestLogGetFlagOrVarPtr(bool8 isFlag, u16 idx); void QuestLogSetFlagOrVar(bool8 isFlag, u16 idx, u16 value); -void SetQuestLogRecordAndPlaybackPointers(void *oldSave); -void sub_811246C(struct Sprite *sprite); +void QL_AddASLROffset(void *oldSaveBlockPtr); +void QL_UpdateObject(struct Sprite *sprite); void QuestLogRecordNPCStep(u8 a0, u8 a1, u8 a2, u8 a3); -bool8 sub_8111C2C(void); +bool8 QL_IsTrainerSightDisabled(void); void QuestLog_OnEscalatorWarp(u8 direction); void QuestLogRecordPlayerAvatarGfxTransitionWithDuration(u8 movementActionId, u8 duration); void Special_UpdateTrainerFansAfterLinkBattle(void); @@ -67,39 +206,39 @@ void QuestLogRecordPlayerStep(u8 movementActionId); void QuestLogRecordPlayerStepWithDuration(u8 movementActionId, u8 duration); void QuestLogRecordNPCStepWithDuration(u8 localId, u8 mapNum, u8 mapGroup, u8 movementActionId, u8 duration); void QL_AfterRecordFishActionSuccessful(void); -void sub_8110920(void); -void sub_8111708(void); -void sub_81127F8(struct FieldInput * a0); -void sub_8112B3C(void); +void QL_ResetDefeatedWildMonRecord(void); +void QL_RestoreMapLayoutId(void); +void QL_RecordFieldInput(struct FieldInput * fieldInput); +void QL_TryRunActions(void); void RunQuestLogCB(void); -void sub_8111C68(void); +void QL_HandleInput(void); bool8 QuestLogScenePlaybackIsEnding(void); -void sub_8115798(void); +void SetQuestLogEvent_Arrived(void); bool8 QuestLog_ShouldEndSceneOnMapChange(void); void QuestLog_AdvancePlayhead_(void); void QuestLog_InitPalettesBackup(void); -void sub_8110FCC(void); +void QL_InitSceneObjectsAndActions(void); u8 GetQuestLogStartType(void); -void sub_81113E4(void); -void sub_8111438(void); -void StartRecordingQuestLogEntry(u16 eventId); -bool8 WillCommandOfSizeFitInSav1Record(u16 *cursor, size_t size); -bool8 sub_8110944(const void *a0, size_t cmdSize); +void QL_CopySaveState(void); +void QL_ResetPartyAndPC(void); +void QL_StartRecordingAction(u16 eventId); +bool8 QL_IsRoomToSaveAction(const void *cursor, size_t size); +bool8 QL_IsRoomToSaveEvent(const void *cursor, size_t size); -void sub_8113BD8(void); -void ResetUnk203B044(void); -u16 *TryRecordEvent39_NoParams(u16 *); -u16 *sub_8113C8C(u16 *, struct QuestLogEntry *); -u16 *sub_8113CC8(u16 *, struct QuestLogEntry *); -u16 *sub_8113D08(u16 *, struct QuestLogEntry *); -u16 *sub_8113D48(u16 *, struct QuestLogEntry *); -u16 *sub_8113D94(u16 *, struct QuestLogEntry *); +void QL_ResetEventStates(void); +void QL_ResetRepeatEventTracker(void); +u16 *QL_RecordAction_SceneEnd(u16 *); +u16 *QL_LoadAction_Wait(u16 *, struct QuestLogAction *); +u16 *QL_RecordAction_Input(u16 *, struct QuestLogAction *); +u16 *QL_LoadAction_Input(u16 *, struct QuestLogAction *); +u16 *QL_RecordAction_MovementOrGfxChange(u16 *, struct QuestLogAction *); +u16 *QL_LoadAction_MovementOrGfxChange(u16 *, struct QuestLogAction *); void QL_EnableRecordingSteps(void); -u16 *QuestLog_SkipCommand(u16 *, u16 **); -void sub_8113ABC(const u16 *); -u16 *sub_8113C20(u16 *, struct QuestLogEntry *); -bool8 sub_8113AE8(const u16 *); -bool8 sub_8113B44(const u16 *); -void TryRecordEvent41_IncCursor(u16); +u16 *QL_SkipCommand(u16 *, u16 **); +void QL_UpdateLastDepartedLocation(const u16 *); +u16 *QL_LoadAction_SceneEnd(u16 *, struct QuestLogAction *); +bool8 QL_LoadEvent(const u16 *); +bool8 QL_TryRepeatEvent(const u16 *); +void QL_RecordWait(u16); #endif //GUARD_QUEST_LOG_H diff --git a/include/quest_log_objects.h b/include/quest_log_objects.h index fbf73f504..ba27bdd09 100644 --- a/include/quest_log_objects.h +++ b/include/quest_log_objects.h @@ -3,8 +3,8 @@ #include "global.h" -void SetQuestLogObjectEventsData(struct QuestLog *); -void SetSav1ObjectEventsFromQuestLog(struct QuestLog *, struct ObjectEventTemplate *); -void sub_815A540(void); +void QL_RecordObjects(struct QuestLogScene *); +void QL_LoadObjects(struct QuestLogScene *, struct ObjectEventTemplate *); +void QL_TryStopSurfing(void); #endif //GUARD_QUEST_LOG_OBJECTS_H diff --git a/include/quest_log_player.h b/include/quest_log_player.h index 2b6bb182c..8f2608cb9 100644 --- a/include/quest_log_player.h +++ b/include/quest_log_player.h @@ -3,15 +3,19 @@ #include "global.h" -#define QL_PLAYER_GFX_NORMAL 0 -#define QL_PLAYER_GFX_BIKE 1 -#define QL_PLAYER_GFX_FISH 2 -#define QL_PLAYER_GFX_SURF 3 -#define QL_PLAYER_GFX_STOP_SURF_S 4 -#define QL_PLAYER_GFX_STOP_SURF_N 5 -#define QL_PLAYER_GFX_STOP_SURF_W 6 -#define QL_PLAYER_GFX_STOP_SURF_E 7 -#define QL_PLAYER_GFX_VSSEEKER 8 +enum { + QL_PLAYER_GFX_NORMAL, + QL_PLAYER_GFX_BIKE, + QL_PLAYER_GFX_FISH, + QL_PLAYER_GFX_SURF, + QL_PLAYER_GFX_STOP_SURF_S, + QL_PLAYER_GFX_STOP_SURF_N, + QL_PLAYER_GFX_STOP_SURF_W, + QL_PLAYER_GFX_STOP_SURF_E, + QL_PLAYER_GFX_VSSEEKER, + QL_PLAYER_GFX_NONE = 0xFF +}; + void QuestLogUpdatePlayerSprite(u8 state); bool32 QuestLogTryRecordPlayerAvatarGfxTransition(u8 state); diff --git a/include/script_menu.h b/include/script_menu.h index 3b62f459e..d3ce18b32 100644 --- a/include/script_menu.h +++ b/include/script_menu.h @@ -14,7 +14,7 @@ bool8 CreatePCMenu(void); void ScriptMenu_DisplayPCStartupPrompt(void); bool8 (*ScriptMenu_HidePokemonPic(void))(void); -void QLPlaybackCB_DestroyScriptMenuMonPicSprites(void); +void QL_DestroyAbortedDisplay(void); void PicboxCancel(void); #endif //GUARD_SCRIPT_MENU_H diff --git a/include/shop.h b/include/shop.h index 621249927..5e6d07783 100644 --- a/include/shop.h +++ b/include/shop.h @@ -10,7 +10,7 @@ void CreatePokemartMenu(const u16 *itemsForSale); void CreateDecorationShop1Menu(const u16 *); void CreateDecorationShop2Menu(const u16 *); u8 GetMartFontId(void); -void RecordItemPurchase(u16 a0, u16 a1, u8 a2); +void RecordItemTransaction(u16 itemId, u16 quantity, u8 logEventId); // buy_menu_helper void BuyMenuInitWindows(bool32 isSellingTM); diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index 41c023d32..c9ec79671 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -2882,7 +2882,7 @@ static void Cmd_tryfaintmon(void) if (gBattleResults.opponentFaintCounter < 255) gBattleResults.opponentFaintCounter++; gBattleResults.lastOpponentSpecies = GetMonData(&gEnemyParty[gBattlerPartyIndexes[gActiveBattler]], MON_DATA_SPECIES); - *(u8 *)(&gBattleStruct->field_182) = gBattlerAttacker; + *(u8 *)(&gBattleStruct->lastAttackerToFaintOpponent) = gBattlerAttacker; } if ((gHitMarker & HITMARKER_DESTINYBOND) && gBattleMons[gBattlerAttacker].hp != 0) { diff --git a/src/battle_setup.c b/src/battle_setup.c index 3ad8f180d..18b2a7acb 100644 --- a/src/battle_setup.c +++ b/src/battle_setup.c @@ -807,13 +807,13 @@ const u8 *BattleSetup_ConfigureTrainerBattle(const u8 *data) SetMapVarsToTrainer(); return EventScript_TryDoDoubleTrainerBattle; case TRAINER_BATTLE_REMATCH_DOUBLE: - FinishRecordingQuestLogScene(); + QL_FinishRecordingScene(); TrainerBattleLoadArgs(sDoubleBattleParams, data); SetMapVarsToTrainer(); gTrainerBattleOpponent_A = GetRematchTrainerId(gTrainerBattleOpponent_A); return EventScript_TryDoDoubleRematchBattle; case TRAINER_BATTLE_REMATCH: - FinishRecordingQuestLogScene(); + QL_FinishRecordingScene(); TrainerBattleLoadArgs(sOrdinaryBattleParams, data); SetMapVarsToTrainer(); gTrainerBattleOpponent_A = GetRematchTrainerId(gTrainerBattleOpponent_A); diff --git a/src/berry_pouch.c b/src/berry_pouch.c index ac9c0d318..545d1450c 100644 --- a/src/berry_pouch.c +++ b/src/berry_pouch.c @@ -29,6 +29,7 @@ #include "pokemon_storage_system.h" #include "constants/items.h" #include "constants/songs.h" +#include "constants/quest_log.h" struct BerryPouchStruct_203F36C { @@ -1384,7 +1385,7 @@ static void Task_SellBerries_PlaySfxAndRemoveBerries(u8 taskId) PlaySE(SE_SHOP); RemoveBagItem(gSpecialVar_ItemId, data[8]); AddMoney(&gSaveBlock1Ptr->money, ItemId_GetPrice(gSpecialVar_ItemId) / 2 * data[8]); - RecordItemPurchase(gSpecialVar_ItemId, data[8], 2); + RecordItemTransaction(gSpecialVar_ItemId, data[8], QL_EVENT_SOLD_ITEM - QL_EVENT_USED_POKEMART); DestroyListMenuTask(data[0], &sStaticCnt.listMenuScrollOffset, &sStaticCnt.listMenuSelectedRow); SortAndCountBerries(); SanitizeListMenuSelectionParams(); diff --git a/src/berry_powder.c b/src/berry_powder.c index 3b26b8ecd..d5090e0dd 100644 --- a/src/berry_powder.c +++ b/src/berry_powder.c @@ -114,15 +114,15 @@ void DisplayBerryPowderVendorMenu(void) { struct WindowTemplate template; - if (QuestLog_SchedulePlaybackCB(QLPlaybackCB_DestroyScriptMenuMonPicSprites) != TRUE) - { - template = SetWindowTemplateFields(0, 1, 1, 8, 3, 15, 32); - sBerryPowderVendorWindowId = AddWindow(&template); - FillWindowPixelBuffer(sBerryPowderVendorWindowId, 0); - PutWindowTilemap(sBerryPowderVendorWindowId); - LoadStdWindowGfx(sBerryPowderVendorWindowId, 0x21D, BG_PLTT_ID(13)); - DrawPlayerPowderAmount(sBerryPowderVendorWindowId, 0x21D, 13, GetBerryPowder()); - } + if (QL_AvoidDisplay(QL_DestroyAbortedDisplay) == TRUE) + return; + + template = SetWindowTemplateFields(0, 1, 1, 8, 3, 15, 32); + sBerryPowderVendorWindowId = AddWindow(&template); + FillWindowPixelBuffer(sBerryPowderVendorWindowId, 0); + PutWindowTilemap(sBerryPowderVendorWindowId); + LoadStdWindowGfx(sBerryPowderVendorWindowId, 0x21D, BG_PLTT_ID(13)); + DrawPlayerPowderAmount(sBerryPowderVendorWindowId, 0x21D, 13, GetBerryPowder()); } void RemoveBerryPowderVendorMenu(void) diff --git a/src/event_data.c b/src/event_data.c index 13ec93917..fa393a47c 100644 --- a/src/event_data.c +++ b/src/event_data.c @@ -192,15 +192,15 @@ u16 *GetVarPointer(u16 idx) { switch (gQuestLogPlaybackState) { - case 0: + case QL_PLAYBACK_STATE_STOPPED: default: break; - case 1: + case QL_PLAYBACK_STATE_RUNNING: ptr = QuestLogGetFlagOrVarPtr(FALSE, idx); if (ptr != NULL) gSaveBlock1Ptr->vars[idx - VARS_START] = *ptr; break; - case 2: + case QL_PLAYBACK_STATE_RECORDING: if (IsFlagOrVarStoredInQuestLog(idx - VARS_START, TRUE) == TRUE) { gLastQuestLogStoredFlagOrVarIdx = idx - VARS_START; @@ -263,15 +263,15 @@ u8 *GetFlagAddr(u16 idx) { switch (gQuestLogPlaybackState) { - case 0: + case QL_PLAYBACK_STATE_STOPPED: default: break; - case 1: + case QL_PLAYBACK_STATE_RUNNING: ptr = QuestLogGetFlagOrVarPtr(TRUE, idx); if (ptr != NULL) - gSaveBlock1Ptr->flags[idx >> 3] = *ptr; + gSaveBlock1Ptr->flags[idx / 8] = *ptr; break; - case 2: + case QL_PLAYBACK_STATE_RECORDING: if (IsFlagOrVarStoredInQuestLog(idx, FALSE) == TRUE) { gLastQuestLogStoredFlagOrVarIdx = idx; diff --git a/src/event_object_movement.c b/src/event_object_movement.c index da74befeb..43a5d86fe 100644 --- a/src/event_object_movement.c +++ b/src/event_object_movement.c @@ -1677,8 +1677,8 @@ void CopyObjectGraphicsInfoToSpriteTemplate(u16 graphicsId, void (*callback)(str do { - if (ScriptContext_IsEnabled() != TRUE && sub_8112CAC() == 1) - spriteTemplate->callback = sub_811246C; + if (ScriptContext_IsEnabled() != TRUE && QL_GetPlaybackState() == QL_PLAYBACK_STATE_RUNNING) + spriteTemplate->callback = QL_UpdateObject; else spriteTemplate->callback = callback; } while (0); @@ -5046,7 +5046,7 @@ bool8 ObjectEventIsHeldMovementActive(struct ObjectEvent *objectEvent) bool8 ObjectEventSetHeldMovement(struct ObjectEvent *objectEvent, u8 movementActionId) { - if(sub_8112CAC() == TRUE) + if (QL_GetPlaybackState() == QL_PLAYBACK_STATE_RUNNING) ObjectEventClearHeldMovementIfActive(objectEvent); else if (ObjectEventIsMovementOverridden(objectEvent)) return TRUE; @@ -5122,7 +5122,7 @@ void UpdateObjectEventCurrentMovement(struct ObjectEvent *objectEvent, struct Sp ObjectEventUpdateSubpriority(objectEvent, sprite); } -void UpdateQuestLogObjectEventCurrentMovement(struct ObjectEvent *objectEvent, struct Sprite *sprite) +void QL_UpdateObjectEventCurrentMovement(struct ObjectEvent *objectEvent, struct Sprite *sprite) { DoGroundEffects_OnSpawn(objectEvent, sprite); TryEnableObjectEventAnim(objectEvent, sprite); @@ -5262,15 +5262,13 @@ static bool8 ObjectEventExecSingleMovementAction(struct ObjectEvent *objectEvent return FALSE; } -static void ObjectEventSetSingleMovement(struct ObjectEvent *objectEvent, struct Sprite *sprite, u8 animId) +static void ObjectEventSetSingleMovement(struct ObjectEvent *objectEvent, struct Sprite *sprite, u8 movementActionId) { - objectEvent->movementActionId = animId; + objectEvent->movementActionId = movementActionId; sprite->data[2] = 0; - if (gQuestLogPlaybackState == 2) - { - QuestLogRecordNPCStep(objectEvent->localId, objectEvent->mapNum, objectEvent->mapGroup, animId); - } + if (gQuestLogPlaybackState == QL_PLAYBACK_STATE_RECORDING) + QuestLogRecordNPCStep(objectEvent->localId, objectEvent->mapNum, objectEvent->mapGroup, movementActionId); } static void FaceDirection(struct ObjectEvent *objectEvent, struct Sprite *sprite, u8 direction) diff --git a/src/field_control_avatar.c b/src/field_control_avatar.c index 6ef78e6f3..78c478db5 100644 --- a/src/field_control_avatar.c +++ b/src/field_control_avatar.c @@ -71,7 +71,7 @@ static bool8 TryDoorWarp(struct MapPosition * position, u16 metatileBehavior, u8 static s8 GetWarpEventAtPosition(struct MapHeader * mapHeader, u16 x, u16 y, u8 z); static const u8 *GetCoordEventScriptAtPosition(struct MapHeader * mapHeader, u16 x, u16 y, u8 z); -struct FieldInput gInputToStoreInQuestLogMaybe; +struct FieldInput gFieldInputRecord; void FieldClearPlayerInput(struct FieldInput *input) { @@ -203,8 +203,8 @@ int ProcessPlayerFieldInput(struct FieldInput *input) metatileAttributes = MapGridGetMetatileAttributeAt(position.x, position.y, METATILE_ATTRIBUTES_ALL); metatileBehavior = MapGridGetMetatileBehaviorAt(position.x, position.y); - FieldClearPlayerInput(&gInputToStoreInQuestLogMaybe); - gInputToStoreInQuestLogMaybe.dpadDirection = input->dpadDirection; + FieldClearPlayerInput(&gFieldInputRecord); + gFieldInputRecord.dpadDirection = input->dpadDirection; if (CheckForTrainersWantingBattle() == TRUE) return TRUE; @@ -222,7 +222,7 @@ int ProcessPlayerFieldInput(struct FieldInput *input) IncrementBirthIslandRockStepCount(); if (TryStartStepBasedScript(&position, metatileBehavior, playerDirection) == TRUE) { - gInputToStoreInQuestLogMaybe.tookStep = TRUE; + gFieldInputRecord.tookStep = TRUE; return TRUE; } } @@ -234,7 +234,7 @@ int ProcessPlayerFieldInput(struct FieldInput *input) metatileBehavior = MapGridGetMetatileBehaviorAt(position.x, position.y); if (TrySetUpWalkIntoSignpostScript(&position, metatileBehavior, playerDirection) == TRUE) { - gInputToStoreInQuestLogMaybe.checkStandardWildEncounter = TRUE; + gFieldInputRecord.checkStandardWildEncounter = TRUE; return TRUE; } GetPlayerPosition(&position); @@ -243,14 +243,14 @@ int ProcessPlayerFieldInput(struct FieldInput *input) } if (input->checkStandardWildEncounter && CheckStandardWildEncounter(metatileAttributes) == TRUE) { - gInputToStoreInQuestLogMaybe.checkStandardWildEncounter = TRUE; + gFieldInputRecord.checkStandardWildEncounter = TRUE; return TRUE; } if (input->heldDirection && input->dpadDirection == playerDirection) { if (TryArrowWarp(&position, metatileBehavior, playerDirection) == TRUE) { - gInputToStoreInQuestLogMaybe.heldDirection = TRUE; + gFieldInputRecord.heldDirection = TRUE; return TRUE; } } @@ -261,14 +261,14 @@ int ProcessPlayerFieldInput(struct FieldInput *input) { if (TrySetUpWalkIntoSignpostScript(&position, metatileBehavior, playerDirection) == TRUE) { - gInputToStoreInQuestLogMaybe.heldDirection = TRUE; + gFieldInputRecord.heldDirection = TRUE; return TRUE; } } if (input->pressedAButton && TryStartInteractionScript(&position, metatileBehavior, playerDirection) == TRUE) { - gInputToStoreInQuestLogMaybe.pressedAButton = TRUE; + gFieldInputRecord.pressedAButton = TRUE; return TRUE; } @@ -276,14 +276,14 @@ int ProcessPlayerFieldInput(struct FieldInput *input) { if (TryDoorWarp(&position, metatileBehavior, playerDirection) == TRUE) { - gInputToStoreInQuestLogMaybe.heldDirection2 = TRUE; + gFieldInputRecord.heldDirection2 = TRUE; return TRUE; } } if (input->pressedStartButton) { - gInputToStoreInQuestLogMaybe.pressedStartButton = TRUE; + gFieldInputRecord.pressedStartButton = TRUE; FlagSet(FLAG_OPENED_START_MENU); PlaySE(SE_WIN_OPEN); ShowStartMenu(); @@ -291,7 +291,7 @@ int ProcessPlayerFieldInput(struct FieldInput *input) } if (input->pressedSelectButton && UseRegisteredKeyItemOnField() == TRUE) { - gInputToStoreInQuestLogMaybe.pressedSelectButton = TRUE; + gFieldInputRecord.pressedSelectButton = TRUE; return TRUE; } diff --git a/src/field_player_avatar.c b/src/field_player_avatar.c index f4f83252f..aa9ca815d 100644 --- a/src/field_player_avatar.c +++ b/src/field_player_avatar.c @@ -1602,11 +1602,11 @@ void CreateStopSurfingTask_NoMusicChange(u8 direction) void SeafoamIslandsB4F_CurrentDumpsPlayerOnLand(void) { - if (gQuestLogPlaybackState != 1 && gQuestLogPlaybackState != 3) - { - QuestLogRecordPlayerAvatarGfxTransitionWithDuration(sQuestLogSurfDismountActionIds[DIR_NORTH], 16); - CreateStopSurfingTask(DIR_NORTH); - } + if (gQuestLogPlaybackState == QL_PLAYBACK_STATE_RUNNING || gQuestLogPlaybackState == QL_PLAYBACK_STATE_ACTION_END) + return; + + QuestLogRecordPlayerAvatarGfxTransitionWithDuration(sQuestLogSurfDismountActionIds[DIR_NORTH], 16); + CreateStopSurfingTask(DIR_NORTH); } static void Task_StopSurfingInit(u8 taskId) diff --git a/src/field_specials.c b/src/field_specials.c index 2d792eee0..c2a9944cc 100644 --- a/src/field_specials.c +++ b/src/field_specials.c @@ -1095,18 +1095,19 @@ void DrawElevatorCurrentFloorWindow(void) { const u8 *floorname; u32 strwidth; - if (QuestLog_SchedulePlaybackCB(QLPlaybackCB_DestroyScriptMenuMonPicSprites) != TRUE) - { - sElevatorCurrentFloorWindowId = AddWindow(&sElevatorCurrentFloorWindowTemplate); - LoadStdWindowGfx(sElevatorCurrentFloorWindowId, 0x21D, BG_PLTT_ID(13)); - DrawStdFrameWithCustomTileAndPalette(sElevatorCurrentFloorWindowId, FALSE, 0x21D, 13); - AddTextPrinterParameterized(sElevatorCurrentFloorWindowId, FONT_NORMAL, gText_NowOn, 0, 2, 0xFF, NULL); - floorname = sFloorNamePointers[gSpecialVar_0x8005]; - strwidth = GetStringWidth(FONT_NORMAL, floorname, 0); - AddTextPrinterParameterized(sElevatorCurrentFloorWindowId, FONT_NORMAL, floorname, 56 - strwidth, 16, 0xFF, NULL); - PutWindowTilemap(sElevatorCurrentFloorWindowId); - CopyWindowToVram(sElevatorCurrentFloorWindowId, COPYWIN_FULL); - } + + if (QL_AvoidDisplay(QL_DestroyAbortedDisplay) == TRUE) + return; + + sElevatorCurrentFloorWindowId = AddWindow(&sElevatorCurrentFloorWindowTemplate); + LoadStdWindowGfx(sElevatorCurrentFloorWindowId, 0x21D, BG_PLTT_ID(13)); + DrawStdFrameWithCustomTileAndPalette(sElevatorCurrentFloorWindowId, FALSE, 0x21D, 13); + AddTextPrinterParameterized(sElevatorCurrentFloorWindowId, FONT_NORMAL, gText_NowOn, 0, 2, 0xFF, NULL); + floorname = sFloorNamePointers[gSpecialVar_0x8005]; + strwidth = GetStringWidth(FONT_NORMAL, floorname, 0); + AddTextPrinterParameterized(sElevatorCurrentFloorWindowId, FONT_NORMAL, floorname, 56 - strwidth, 16, 0xFF, NULL); + PutWindowTilemap(sElevatorCurrentFloorWindowId); + CopyWindowToVram(sElevatorCurrentFloorWindowId, COPYWIN_FULL); } void CloseElevatorCurrentFloorWindow(void) @@ -1164,91 +1165,92 @@ void ListMenu(void) { u8 taskId; struct Task *task; - if (QuestLog_SchedulePlaybackCB(QLPlaybackCB_DestroyScriptMenuMonPicSprites) != TRUE) + + if (QL_AvoidDisplay(QL_DestroyAbortedDisplay) == TRUE) + return; + + taskId = CreateTask(Task_CreateScriptListMenu, 8); + task = &gTasks[taskId]; + switch (gSpecialVar_0x8004) { - taskId = CreateTask(Task_CreateScriptListMenu, 8); - task = &gTasks[taskId]; - switch (gSpecialVar_0x8004) - { - case LISTMENU_BADGES: - task->data[0] = 4; - task->data[1] = 9; - task->data[2] = 1; - task->data[3] = 1; - task->data[4] = 12; - task->data[5] = 7; - task->data[6] = 1; - task->data[15] = taskId; - break; - case LISTMENU_SILPHCO_FLOORS: - task->data[0] = 7; - task->data[1] = 12; - task->data[2] = 1; - task->data[3] = 1; - task->data[4] = 8; - task->data[5] = 12; - task->data[6] = 0; - task->data[15] = taskId; - task->data[7] = sElevatorScroll; - task->data[8] = sElevatorCursorPos; - break; - case LISTMENU_ROCKET_HIDEOUT_FLOORS: // Multichoice used instead - task->data[0] = 4; - task->data[1] = 4; - task->data[2] = 1; - task->data[3] = 1; - task->data[4] = 8; - task->data[5] = 8; - task->data[6] = 0; - task->data[15] = taskId; - break; - case LISTMENU_DEPT_STORE_FLOORS: // Multichoice used instead - task->data[0] = 4; - task->data[1] = 6; - task->data[2] = 1; - task->data[3] = 1; - task->data[4] = 8; - task->data[5] = 8; - task->data[6] = 0; - task->data[15] = taskId; - break; - case LISTMENU_WIRELESS_LECTURE_HEADERS: // Multichoice used instead - task->data[0] = 4; - task->data[1] = 4; - task->data[2] = 1; - task->data[3] = 1; - task->data[4] = 17; - task->data[5] = 8; - task->data[6] = 1; - task->data[15] = taskId; - break; - case LISTMENU_BERRY_POWDER: - task->data[0] = 7; - task->data[1] = 12; - task->data[2] = 16; - task->data[3] = 1; - task->data[4] = 17; - task->data[5] = 12; - task->data[6] = 0; - task->data[15] = taskId; - break; - case LISTMENU_TRAINER_TOWER_FLOORS: // Mulitchoice used instead - task->data[0] = 3; - task->data[1] = 3; - task->data[2] = 1; - task->data[3] = 1; - task->data[4] = 8; - task->data[5] = 6; - task->data[6] = 0; - task->data[15] = taskId; - break; - case 99: - break; - default: - gSpecialVar_Result = 0x7F; - DestroyTask(taskId); - break; - } + case LISTMENU_BADGES: + task->data[0] = 4; + task->data[1] = 9; + task->data[2] = 1; + task->data[3] = 1; + task->data[4] = 12; + task->data[5] = 7; + task->data[6] = 1; + task->data[15] = taskId; + break; + case LISTMENU_SILPHCO_FLOORS: + task->data[0] = 7; + task->data[1] = 12; + task->data[2] = 1; + task->data[3] = 1; + task->data[4] = 8; + task->data[5] = 12; + task->data[6] = 0; + task->data[15] = taskId; + task->data[7] = sElevatorScroll; + task->data[8] = sElevatorCursorPos; + break; + case LISTMENU_ROCKET_HIDEOUT_FLOORS: // Multichoice used instead + task->data[0] = 4; + task->data[1] = 4; + task->data[2] = 1; + task->data[3] = 1; + task->data[4] = 8; + task->data[5] = 8; + task->data[6] = 0; + task->data[15] = taskId; + break; + case LISTMENU_DEPT_STORE_FLOORS: // Multichoice used instead + task->data[0] = 4; + task->data[1] = 6; + task->data[2] = 1; + task->data[3] = 1; + task->data[4] = 8; + task->data[5] = 8; + task->data[6] = 0; + task->data[15] = taskId; + break; + case LISTMENU_WIRELESS_LECTURE_HEADERS: // Multichoice used instead + task->data[0] = 4; + task->data[1] = 4; + task->data[2] = 1; + task->data[3] = 1; + task->data[4] = 17; + task->data[5] = 8; + task->data[6] = 1; + task->data[15] = taskId; + break; + case LISTMENU_BERRY_POWDER: + task->data[0] = 7; + task->data[1] = 12; + task->data[2] = 16; + task->data[3] = 1; + task->data[4] = 17; + task->data[5] = 12; + task->data[6] = 0; + task->data[15] = taskId; + break; + case LISTMENU_TRAINER_TOWER_FLOORS: // Mulitchoice used instead + task->data[0] = 3; + task->data[1] = 3; + task->data[2] = 1; + task->data[3] = 1; + task->data[4] = 8; + task->data[5] = 6; + task->data[6] = 0; + task->data[15] = taskId; + break; + case 99: + break; + default: + gSpecialVar_Result = 0x7F; + DestroyTask(taskId); + break; } } @@ -1810,7 +1812,7 @@ static const struct { u16 inside_num; u16 outside_grp; u16 outside_num; -} sInsideOutsidePairs[51] = { +} sInsideOutsidePairs[] = { [QL_LOCATION_HOME] = {MAP(PALLET_TOWN_PLAYERS_HOUSE_1F), MAP(PALLET_TOWN)}, [QL_LOCATION_OAKS_LAB] = {MAP(PALLET_TOWN_PROFESSOR_OAKS_LAB), MAP(PALLET_TOWN)}, [QL_LOCATION_VIRIDIAN_GYM] = {MAP(VIRIDIAN_CITY_GYM), MAP(VIRIDIAN_CITY)}, @@ -1881,67 +1883,67 @@ void QuestLog_CheckDepartingIndoorsMap(void) } } -struct QuestLogDepartedData { - u8 map_section_id; - u8 entrance_id; -}; - void QuestLog_TryRecordDepartedLocation(void) { s16 x, y; - struct QuestLogDepartedData event_buffer; - u16 ql_entrance_id = VarGet(VAR_QL_ENTRANCE); - event_buffer.map_section_id = 0; - event_buffer.entrance_id = 0; + struct QuestLogEvent_Departed data; + u16 locationId = VarGet(VAR_QL_ENTRANCE); + data.mapSec = 0; + data.locationId = 0; if (FlagGet(FLAG_SYS_QL_DEPARTED)) { - if (ql_entrance_id == QL_LOCATION_VIRIDIAN_FOREST_1) + if (locationId == QL_LOCATION_VIRIDIAN_FOREST_1) { - if (gSaveBlock1Ptr->location.mapGroup == MAP_GROUP(ROUTE2_VIRIDIAN_FOREST_SOUTH_ENTRANCE) && (gSaveBlock1Ptr->location.mapNum == MAP_NUM(ROUTE2_VIRIDIAN_FOREST_SOUTH_ENTRANCE) || gSaveBlock1Ptr->location.mapNum == MAP_NUM(ROUTE2_VIRIDIAN_FOREST_NORTH_ENTRANCE))) + if (gSaveBlock1Ptr->location.mapGroup == MAP_GROUP(ROUTE2_VIRIDIAN_FOREST_SOUTH_ENTRANCE) + && (gSaveBlock1Ptr->location.mapNum == MAP_NUM(ROUTE2_VIRIDIAN_FOREST_SOUTH_ENTRANCE) + || gSaveBlock1Ptr->location.mapNum == MAP_NUM(ROUTE2_VIRIDIAN_FOREST_NORTH_ENTRANCE))) { - event_buffer.map_section_id = MAPSEC_ROUTE_2; + data.mapSec = MAPSEC_ROUTE_2; if (gSaveBlock1Ptr->location.mapNum == MAP_NUM(ROUTE2_VIRIDIAN_FOREST_SOUTH_ENTRANCE)) - event_buffer.entrance_id = ql_entrance_id; + data.locationId = locationId; else - event_buffer.entrance_id = ql_entrance_id + 1; - SetQuestLogEvent(QL_EVENT_DEPARTED, (void *)&event_buffer); + data.locationId = locationId + 1; + SetQuestLogEvent(QL_EVENT_DEPARTED, (const u16 *)&data); FlagClear(FLAG_SYS_QL_DEPARTED); return; } } - else if (ql_entrance_id == QL_LOCATION_LEAGUE_GATE_1) + else if (locationId == QL_LOCATION_LEAGUE_GATE_1) { - if (gSaveBlock1Ptr->location.mapGroup == MAP_GROUP(ROUTE22) && (gSaveBlock1Ptr->location.mapNum == MAP_NUM(ROUTE22) || gSaveBlock1Ptr->location.mapNum == MAP_NUM(ROUTE23))) + if (gSaveBlock1Ptr->location.mapGroup == MAP_GROUP(ROUTE22) && + (gSaveBlock1Ptr->location.mapNum == MAP_NUM(ROUTE22) + || gSaveBlock1Ptr->location.mapNum == MAP_NUM(ROUTE23))) { - event_buffer.map_section_id = Overworld_GetMapHeaderByGroupAndId(sInsideOutsidePairs[ql_entrance_id].inside_grp, sInsideOutsidePairs[ql_entrance_id].inside_num)->regionMapSectionId; + data.mapSec = Overworld_GetMapHeaderByGroupAndId(sInsideOutsidePairs[locationId].inside_grp, sInsideOutsidePairs[locationId].inside_num)->regionMapSectionId; if (gSaveBlock1Ptr->location.mapNum == MAP_NUM(ROUTE22)) - event_buffer.entrance_id = ql_entrance_id; + data.locationId = locationId; else - event_buffer.entrance_id = ql_entrance_id + 1; - SetQuestLogEvent(QL_EVENT_DEPARTED, (void *)&event_buffer); + data.locationId = locationId + 1; + SetQuestLogEvent(QL_EVENT_DEPARTED, (const u16 *)&data); FlagClear(FLAG_SYS_QL_DEPARTED); return; } } - if (gSaveBlock1Ptr->location.mapGroup == sInsideOutsidePairs[ql_entrance_id].outside_grp && gSaveBlock1Ptr->location.mapNum == sInsideOutsidePairs[ql_entrance_id].outside_num) + if (gSaveBlock1Ptr->location.mapGroup == sInsideOutsidePairs[locationId].outside_grp + && gSaveBlock1Ptr->location.mapNum == sInsideOutsidePairs[locationId].outside_num) { - event_buffer.map_section_id = Overworld_GetMapHeaderByGroupAndId(sInsideOutsidePairs[ql_entrance_id].inside_grp, sInsideOutsidePairs[ql_entrance_id].inside_num)->regionMapSectionId; - event_buffer.entrance_id = ql_entrance_id; - if (ql_entrance_id == QL_LOCATION_ROCK_TUNNEL_1) + data.mapSec = Overworld_GetMapHeaderByGroupAndId(sInsideOutsidePairs[locationId].inside_grp, sInsideOutsidePairs[locationId].inside_num)->regionMapSectionId; + data.locationId = locationId; + if (locationId == QL_LOCATION_ROCK_TUNNEL_1) { PlayerGetDestCoords(&x, &y); if (x != 15 || y != 26) - event_buffer.entrance_id++; + data.locationId++; } - else if (ql_entrance_id == QL_LOCATION_SEAFOAM_ISLANDS_1) + else if (locationId == QL_LOCATION_SEAFOAM_ISLANDS_1) { PlayerGetDestCoords(&x, &y); if (x != 67 || y != 15) - event_buffer.entrance_id++; + data.locationId++; } - SetQuestLogEvent(QL_EVENT_DEPARTED, (void *)&event_buffer); + SetQuestLogEvent(QL_EVENT_DEPARTED, (const u16 *)&data); FlagClear(FLAG_SYS_QL_DEPARTED); - if (ql_entrance_id == QL_LOCATION_ROCKET_HIDEOUT) + if (locationId == QL_LOCATION_ROCKET_HIDEOUT) { VarSet(VAR_QL_ENTRANCE, QL_LOCATION_GAME_CORNER); FlagSet(FLAG_SYS_QL_DEPARTED); diff --git a/src/item.c b/src/item.c index e072a5692..b414ee8dd 100644 --- a/src/item.c +++ b/src/item.c @@ -567,16 +567,8 @@ u16 BagGetQuantityByItemId(u16 itemId) void TrySetObtainedItemQuestLogEvent(u16 itemId) { - struct QuestLogStruct_809A824 - { - u16 itemId; - u8 mapSectionId; - } * ptr; - // Only some key items trigger this event - if - ( - itemId == ITEM_OAKS_PARCEL + if (itemId == ITEM_OAKS_PARCEL || itemId == ITEM_POKE_FLUTE || itemId == ITEM_SECRET_KEY || itemId == ITEM_BIKE_VOUCHER @@ -595,16 +587,15 @@ void TrySetObtainedItemQuestLogEvent(u16 itemId) || itemId == ITEM_TEA || itemId == ITEM_POWDER_JAR || itemId == ITEM_RUBY - || itemId == ITEM_SAPPHIRE - ) + || itemId == ITEM_SAPPHIRE) { if (itemId != ITEM_TOWN_MAP || (gSaveBlock1Ptr->location.mapGroup == MAP_GROUP(PALLET_TOWN_RIVALS_HOUSE) && gSaveBlock1Ptr->location.mapNum == MAP_NUM(PALLET_TOWN_RIVALS_HOUSE))) { - ptr = malloc(sizeof(*ptr)); - ptr->itemId = itemId; - ptr->mapSectionId = gMapHeader.regionMapSectionId; - SetQuestLogEvent(QL_EVENT_OBTAINED_ITEM, (void *)ptr); - free(ptr); + struct QuestLogEvent_StoryItem * data = malloc(sizeof(*data)); + data->itemId = itemId; + data->mapSec = gMapHeader.regionMapSectionId; + SetQuestLogEvent(QL_EVENT_OBTAINED_STORY_ITEM, (const u16 *)data); + free(data); } } } diff --git a/src/item_menu.c b/src/item_menu.c index c45f693d8..b0c288383 100644 --- a/src/item_menu.c +++ b/src/item_menu.c @@ -33,6 +33,7 @@ #include "tm_case.h" #include "constants/items.h" #include "constants/songs.h" +#include "constants/quest_log.h" #define FREE_IF_SET(ptr) ({ if (ptr) Free(ptr); }) @@ -1930,7 +1931,7 @@ static void Task_FinalizeSaleToShop(u8 taskId) PlaySE(SE_SHOP); RemoveBagItem(gSpecialVar_ItemId, data[8]); AddMoney(&gSaveBlock1Ptr->money, ItemId_GetPrice(gSpecialVar_ItemId) / 2 * data[8]); - RecordItemPurchase(gSpecialVar_ItemId, data[8], 2); + RecordItemTransaction(gSpecialVar_ItemId, data[8], QL_EVENT_SOLD_ITEM - QL_EVENT_USED_POKEMART); DestroyListMenuTask(data[0], &gBagMenuState.cursorPos[gBagMenuState.pocket], &gBagMenuState.itemsAbove[gBagMenuState.pocket]); Pocket_CalculateNItemsAndMaxShowed(gBagMenuState.pocket); PocketCalculateInitialCursorPosAndItemsAbove(gBagMenuState.pocket); @@ -2005,7 +2006,7 @@ static void Task_TryDoItemDeposit(u8 taskId) s16 *data = gTasks[taskId].data; if (AddPCItem(gSpecialVar_ItemId, data[8]) == TRUE) { - ItemUse_SetQuestLogEvent(28, 0, gSpecialVar_ItemId, 0xFFFF); + ItemUse_SetQuestLogEvent(QL_EVENT_DEPOSITED_ITEM_PC, 0, gSpecialVar_ItemId, 0xFFFF); CopyItemName(gSpecialVar_ItemId, gStringVar1); ConvertIntToDecimalStringN(gStringVar2, data[8], STR_CONV_MODE_LEFT_ALIGN, 3); StringExpandPlaceholders(gStringVar4, gText_DepositedStrVar2StrVar1s); diff --git a/src/item_use.c b/src/item_use.c index ce659673e..f42eb81f7 100644 --- a/src/item_use.c +++ b/src/item_use.c @@ -912,20 +912,14 @@ void FieldUseFunc_OakStopsYou(u8 taskId) void ItemUse_SetQuestLogEvent(u8 eventId, struct Pokemon *pokemon, u16 itemId, u16 param) { - struct UnkStruct_ItemUseQuestLog - { - u16 itemId; - u16 unk2; - u16 species; - u16 param; - } *questLog = Alloc(sizeof(*questLog)); + struct QuestLogEvent_Item *data = Alloc(sizeof(*data)); - questLog->itemId = itemId; - questLog->param = param; + data->itemId = itemId; + data->itemParam = param; if (pokemon != NULL) - questLog->species = GetMonData(pokemon, MON_DATA_SPECIES_OR_EGG); + data->species = GetMonData(pokemon, MON_DATA_SPECIES_OR_EGG); else - questLog->species = 0xFFFF; - SetQuestLogEvent(eventId, (void *)questLog); - Free(questLog); + data->species = 0xFFFF; + SetQuestLogEvent(eventId, (void *)data); + Free(data); } diff --git a/src/load_save.c b/src/load_save.c index 4d33ceeb8..b81e78acc 100644 --- a/src/load_save.c +++ b/src/load_save.c @@ -78,7 +78,7 @@ void SetSaveBlocksPointers(void) gPokemonStoragePtr = (void *)(&gPokemonStorage) + offset; SetBagPocketsPointers(); - SetQuestLogRecordAndPlaybackPointers(oldSave); + QL_AddASLROffset(oldSave); } void MoveSaveBlocks_ResetHeap(void) diff --git a/src/main.c b/src/main.c index f4305ec05..8ee89c994 100644 --- a/src/main.c +++ b/src/main.c @@ -213,7 +213,7 @@ static void InitMainCallbacks(void) gSaveBlock2Ptr = &gSaveBlock2; gSaveBlock1Ptr = &gSaveBlock1; gSaveBlock2.encryptionKey = 0; - gQuestLogPlaybackState = 0; + gQuestLogPlaybackState = QL_PLAYBACK_STATE_STOPPED; } static void CallCallbacks(void) diff --git a/src/main_menu.c b/src/main_menu.c index a99a51db4..5cef7c46e 100644 --- a/src/main_menu.c +++ b/src/main_menu.c @@ -478,7 +478,7 @@ static void Task_ExecuteMainMenuSelection(u8 taskId) gPlttBufferFaded[0] = RGB_BLACK; gExitStairsMovementDisabled = FALSE; FreeAllWindowBuffers(); - TrySetUpQuestLogScenes_ElseContinueFromSave(taskId); + TryStartQuestLogPlayback(taskId); break; case MAIN_MENU_MYSTERYGIFT: SetMainCallback2(CB2_InitMysteryGift); diff --git a/src/overworld.c b/src/overworld.c index 61e1a1db7..f3078c596 100644 --- a/src/overworld.c +++ b/src/overworld.c @@ -772,7 +772,7 @@ void LoadMapFromCameraTransition(u8 mapGroup, u8 mapNum) InitSecondaryTilesetAnimation(); UpdateLocationHistoryForRoamer(); RoamerMove(); - sub_8110920(); + QL_ResetDefeatedWildMonRecord(); DoCurrentWeather(); ResetFieldTasksArgs(); RunOnResumeMapScript(); @@ -803,7 +803,7 @@ static void LoadMapFromWarp(bool32 unused) TryRegenerateRenewableHiddenItems(); UpdateLocationHistoryForRoamer(); RoamerMoveToOtherLocationSet(); - sub_8110920(); + QL_ResetDefeatedWildMonRecord(); InitMap(); } @@ -818,8 +818,8 @@ static void QL_LoadMapNormal(void) SetSavedWeatherFromCurrMapHeader(); ChooseAmbientCrySpecies(); SetDefaultFlashLevel(); - sub_8110920(); - sub_8111708(); + QL_ResetDefeatedWildMonRecord(); + QL_RestoreMapLayoutId(); LoadSaveblockMapHeader(); InitMap(); } @@ -1390,7 +1390,7 @@ static void DoCB1_Overworld(u16 newKeys, u16 heldKeys) { struct FieldInput fieldInput; - sub_8112B3C(); + QL_TryRunActions(); UpdatePlayerAvatarTransitionState(); FieldClearPlayerInput(&fieldInput); FieldGetPlayerInput(&fieldInput, newKeys, heldKeys); @@ -1399,8 +1399,8 @@ static void DoCB1_Overworld(u16 newKeys, u16 heldKeys) { if (ProcessPlayerFieldInput(&fieldInput) == TRUE) { - if (gQuestLogPlaybackState == 2) - sub_81127F8(&gInputToStoreInQuestLogMaybe); + if (gQuestLogPlaybackState == QL_PLAYBACK_STATE_RECORDING) + QL_RecordFieldInput(&gFieldInputRecord); LockPlayerFieldControls(); DismissMapNamePopup(); } @@ -1416,9 +1416,9 @@ static void DoCB1_Overworld_QuestLogPlayback(void) { struct FieldInput fieldInput; - sub_8112B3C(); + QL_TryRunActions(); UpdatePlayerAvatarTransitionState(); - sub_8111C68(); + QL_HandleInput(); FieldClearPlayerInput(&fieldInput); fieldInput = gQuestLogFieldInput; FieldInput_HandleCancelSignpost(&fieldInput); @@ -1445,7 +1445,7 @@ void CB1_Overworld(void) { if (gMain.callback2 == CB2_Overworld) { - if (sub_8112CAC() == 1 || gQuestLogState == QL_STATE_PLAYBACK) + if (QL_GetPlaybackState() == QL_PLAYBACK_STATE_RUNNING || gQuestLogState == QL_STATE_PLAYBACK) DoCB1_Overworld_QuestLogPlayback(); else DoCB1_Overworld(gMain.newKeys, gMain.heldKeys); @@ -1458,7 +1458,7 @@ static void OverworldBasic(void) RunTasks(); AnimateSprites(); CameraUpdate(); - sub_8115798(); + SetQuestLogEvent_Arrived(); UpdateCameraPanning(); BuildOamBuffer(); UpdatePaletteFade(); @@ -2239,8 +2239,8 @@ static bool32 LoadMap_QLPlayback(u8 *state) InitOverworldBgs(); FieldClearVBlankHBlankCallbacks(); QuestLog_InitPalettesBackup(); - sub_81113E4(); - sub_8111438(); + QL_CopySaveState(); + QL_ResetPartyAndPC(); if (GetQuestLogStartType() == QL_START_WARP) { gExitStairsMovementDisabled = FALSE; @@ -2254,7 +2254,7 @@ static bool32 LoadMap_QLPlayback(u8 *state) (*state)++; break; case 1: - sub_8110FCC(); + QL_InitSceneObjectsAndActions(); (*state)++; break; case 2: @@ -2296,7 +2296,7 @@ static bool32 LoadMap_QLPlayback(u8 *state) break; case 10: InitTilesetAnimations(); - sub_815A540(); + QL_TryStopSurfing(); (*state)++; break; default: diff --git a/src/party_menu.c b/src/party_menu.c index ac97907c5..571dcf2c9 100644 --- a/src/party_menu.c +++ b/src/party_menu.c @@ -3355,12 +3355,12 @@ static void SwitchPartyMon(void) static void SetSwitchedPartyOrderQuestLogEvent(void) { - u16 *buffer = Alloc(2 * sizeof(u16)); + struct QuestLogEvent_SwitchedPartyOrder * data = Alloc(sizeof(*data)); - buffer[0] = GetMonData(&gPlayerParty[gPartyMenu.slotId], MON_DATA_SPECIES_OR_EGG); - buffer[1] = GetMonData(&gPlayerParty[gPartyMenu.slotId2], MON_DATA_SPECIES_OR_EGG); - SetQuestLogEvent(QL_EVENT_SWITCHED_PARTY_ORDER, buffer); - Free(buffer); + data->species1 = GetMonData(&gPlayerParty[gPartyMenu.slotId], MON_DATA_SPECIES_OR_EGG); + data->species2 = GetMonData(&gPlayerParty[gPartyMenu.slotId2], MON_DATA_SPECIES_OR_EGG); + SetQuestLogEvent(QL_EVENT_SWITCHED_PARTY_ORDER, (const u16 *)data); + Free(data); } // Finish switching mons or using Softboiled @@ -4131,67 +4131,61 @@ static bool8 SetUpFieldMove_Waterfall(void) static void SetSwappedHeldItemQuestLogEvent(struct Pokemon *mon, u16 item, u16 item2) { - u16 *ptr = Alloc(4 * sizeof(u16)); + struct QuestLogEvent_SwappedHeldItem *data = Alloc(sizeof(*data)); - ptr[2] = GetMonData(mon, MON_DATA_SPECIES_OR_EGG); - ptr[0] = item; - ptr[1] = item2; + data->species = GetMonData(mon, MON_DATA_SPECIES_OR_EGG); + data->takenItemId = item; + data->givenItemId = item2; if (gPartyMenu.action == PARTY_ACTION_GIVE_PC_ITEM) - SetQuestLogEvent(QL_EVENT_SWAPPED_HELD_ITEM_PC, ptr); + SetQuestLogEvent(QL_EVENT_SWAPPED_HELD_ITEM_PC, (void *)data); else - SetQuestLogEvent(QL_EVENT_SWAPPED_HELD_ITEM, ptr); - Free(ptr); + SetQuestLogEvent(QL_EVENT_SWAPPED_HELD_ITEM, (void *)data); + Free(data); } -struct FieldMoveWarpParams -{ - u16 species; - u8 fieldMove; - u8 regionMapSectionId; -}; - static void SetUsedFieldMoveQuestLogEvent(struct Pokemon *mon, u8 fieldMove) { - struct FieldMoveWarpParams *ptr = Alloc(sizeof(*ptr)); + struct QuestLogEvent_FieldMove *data = Alloc(sizeof(*data)); - ptr->species = GetMonData(mon, MON_DATA_SPECIES_OR_EGG); - ptr->fieldMove = fieldMove; - switch (ptr->fieldMove) + data->species = GetMonData(mon, MON_DATA_SPECIES_OR_EGG); + data->fieldMove = fieldMove; + switch (data->fieldMove) { case FIELD_MOVE_TELEPORT: - ptr->regionMapSectionId = Overworld_GetMapHeaderByGroupAndId(gSaveBlock1Ptr->lastHealLocation.mapGroup, gSaveBlock1Ptr->lastHealLocation.mapNum)->regionMapSectionId; + data->mapSec = Overworld_GetMapHeaderByGroupAndId(gSaveBlock1Ptr->lastHealLocation.mapGroup, gSaveBlock1Ptr->lastHealLocation.mapNum)->regionMapSectionId; break; case FIELD_MOVE_DIG: - ptr->regionMapSectionId = gMapHeader.regionMapSectionId; + data->mapSec = gMapHeader.regionMapSectionId; break; default: - ptr->regionMapSectionId = 0xFF; + data->mapSec = 0xFF; } - SetQuestLogEvent(QL_EVENT_USED_FIELD_MOVE, (u16 *)ptr); - Free(ptr); + SetQuestLogEvent(QL_EVENT_USED_FIELD_MOVE, (const u16 *)data); + Free(data); } void SetUsedFlyQuestLogEvent(const u8 *healLocCtrlData) { const struct MapHeader *mapHeader; - struct FieldMoveWarpParams *ptr2; + struct QuestLogEvent_FieldMove *data; struct { - s8 mapGroup; - s8 mapNum; - u32 unk_4; - } *ptr = Alloc(sizeof(*ptr)); + s8 group; + s8 num; + u32 unused; + } *map = Alloc(sizeof(*map)); - ptr->mapGroup = healLocCtrlData[0]; - ptr->mapNum = healLocCtrlData[1]; - mapHeader = Overworld_GetMapHeaderByGroupAndId(ptr->mapGroup, ptr->mapNum); - Free(ptr); - ptr2 = Alloc(4); - ptr2->species = GetMonData(&gPlayerParty[GetCursorSelectionMonId()], MON_DATA_SPECIES_OR_EGG); - ptr2->fieldMove = FIELD_MOVE_FLY; - ptr2->regionMapSectionId = mapHeader->regionMapSectionId; - SetQuestLogEvent(QL_EVENT_USED_FIELD_MOVE, (u16 *)ptr2); - Free(ptr2); + map->group = healLocCtrlData[0]; + map->num = healLocCtrlData[1]; + mapHeader = Overworld_GetMapHeaderByGroupAndId(map->group, map->num); + Free(map); + + data = Alloc(sizeof(*data)); + data->species = GetMonData(&gPlayerParty[GetCursorSelectionMonId()], MON_DATA_SPECIES_OR_EGG); + data->fieldMove = FIELD_MOVE_FLY; + data->mapSec = mapHeader->regionMapSectionId; + SetQuestLogEvent(QL_EVENT_USED_FIELD_MOVE, (const u16 *)data); + Free(data); } void CB2_ShowPartyMenuForItemUse(void) diff --git a/src/pokemon_storage_system_tasks.c b/src/pokemon_storage_system_tasks.c index 8388c7df4..fdc5250c3 100644 --- a/src/pokemon_storage_system_tasks.c +++ b/src/pokemon_storage_system_tasks.c @@ -2672,7 +2672,7 @@ static void InitCursorItemIcon(void) static void SetPokeStorageQuestLogEvent(u8 action) { u16 event; - struct PokeStorageQuestLogData *questLogData; + struct QuestLogEvent_MovedBoxMon *questLogData; u8 box1 = GetMovingMonOriginalBoxId(); u16 species1 = gStorage->displayMonSpecies; u16 species2; @@ -2687,7 +2687,7 @@ static void SetPokeStorageQuestLogEvent(u8 action) box2 = StorageGetCurrentBox(); species2 = GetCurrentBoxMonData(GetBoxCursorPosition(), MON_DATA_SPECIES_OR_EGG); } - questLogData = &gStorage->pokeStorageQuestLogData; + questLogData = &gStorage->questLogData; switch (action) { diff --git a/src/quest_log.c b/src/quest_log.c index 06d0d8b50..eb1169424 100644 --- a/src/quest_log.c +++ b/src/quest_log.c @@ -30,24 +30,31 @@ #include "constants/field_weather.h" #include "constants/event_object_movement.h" -struct TrainerFanClub -{ - u8 timer:7; - u8 gotInitialFans:1; - u8 fanFlags; +enum { + WIN_TOP_BAR, // Contains the "Previously on..." text + WIN_BOTTOM_BAR, // Empty, only briefly visible at the end or when the description window isn't covering it. + WIN_DESCRIPTION, + WIN_COUNT }; -#define TRAINER_FAN_CLUB ((struct TrainerFanClub *)GetVarPointer(VAR_FANCLUB_FAN_COUNTER)) +#define DESC_WIN_WIDTH (DISPLAY_WIDTH / 8) +#define DESC_WIN_HEIGHT 6 +#define DESC_WIN_SIZE (DESC_WIN_WIDTH * DESC_WIN_HEIGHT * TILE_SIZE_4BPP) -#define GET_TRAINER_FAN_CLUB_FLAG(flag) (fanClub->fanFlags >> (flag) & 1) -#define SET_TRAINER_FAN_CLUB_FLAG(flag) (fanClub->fanFlags |= 1 << (flag)) -#define FLIP_TRAINER_FAN_CLUB_FLAG(flag)(fanClub->fanFlags ^= 1 << (flag)) +// sQuestLogActionRecordBuffer should be large enough to fill a scene's script with the maximum number of actions +#define SCRIPT_BUFFER_SIZE (sizeof(gSaveBlock1Ptr->questLog[0].script) / sizeof(struct QuestLogAction)) -struct UnkStruct_203AE94 +enum { + END_MODE_NONE, + END_MODE_FINISH, + END_MODE_SCENE, +}; + +struct PlaybackControl { - u8 playbackSubstate:4; + u8 state:4; u8 playingEvent:2; - u8 sceneEndMode:2; + u8 endMode:2; u8 cursor; u8 timer; u8 overlapTimer; @@ -61,9 +68,9 @@ struct FlagOrVarRecord }; u8 gQuestLogPlaybackState; -u16 sNumEventsInLogEntry; +u16 sMaxActionsInScene; struct FieldInput gQuestLogFieldInput; -struct QuestLogEntry * sCurQuestLogEntry; +struct QuestLogAction * sCurSceneActions; static struct FlagOrVarRecord * sFlagOrVarRecords; static u16 sNumFlagsOrVars; @@ -71,18 +78,18 @@ static u16 sNumFlagsOrVars; static EWRAM_DATA u8 sCurrentSceneNum = 0; static EWRAM_DATA u8 sNumScenes = 0; EWRAM_DATA u8 gQuestLogState = 0; -static EWRAM_DATA u16 gUnknown_203ADFC = 0; -static EWRAM_DATA u8 sQuestLogHeaderWindowIds[3] = {0}; -EWRAM_DATA u16 *gUnknown_203AE04 = NULL; -EWRAM_DATA u16 *sEventRecordingPointer = NULL; -static EWRAM_DATA u16 *gUnknown_203AE0C[32] = {NULL}; +static EWRAM_DATA u16 sRecordSequenceStartIdx = 0; +static EWRAM_DATA u8 sWindowIds[WIN_COUNT] = {0}; +EWRAM_DATA u16 *gQuestLogDefeatedWildMonRecord = NULL; +EWRAM_DATA u16 *gQuestLogRecordingPointer = NULL; +static EWRAM_DATA u16 *sEventData[32] = {NULL}; static EWRAM_DATA void (* sQuestLogCB)(void) = NULL; static EWRAM_DATA u16 *sPalettesBackup = NULL; -static EWRAM_DATA struct UnkStruct_203AE94 sQuestLogCurrentScene = {0}; -static EWRAM_DATA struct QuestLogEntry sQuestLogSceneRecordBuffer[32] = {0}; -EWRAM_DATA u16 sQuestLogCursor = 0; -static EWRAM_DATA u8 sMovementScripts[64][2] = {{0}}; -static EWRAM_DATA u16 sNextStepDelay = 0; +static EWRAM_DATA struct PlaybackControl sPlaybackControl = {0}; +static EWRAM_DATA struct QuestLogAction sQuestLogActionRecordBuffer[SCRIPT_BUFFER_SIZE] = {0}; +EWRAM_DATA u16 gQuestLogCurActionIdx = 0; +static EWRAM_DATA u8 sMovementScripts[OBJECT_EVENT_TEMPLATES_COUNT][2] = {{0}}; +static EWRAM_DATA u16 sNextActionDelay = 0; static EWRAM_DATA u16 sLastQuestLogCursor = 0; static EWRAM_DATA u16 sFlagOrVarPlayhead = 0; @@ -90,85 +97,103 @@ static void QLogCB_Recording(void); static void QLogCB_Playback(void); static void SetPlayerInitialCoordsAtScene(u8); static void SetNPCInitialCoordsAtScene(u8); -static void TryRecordEvent39_GoToNextScene(void); -static void BackUpTrainerRematchesToVars(void); -static void BackUpMapLayoutToVar(void); +static void RecordSceneEnd(void); +static void BackUpTrainerRematches(void); +static void BackUpMapLayout(void); static void SetGameStateAtScene(u8); -static u8 TryRecordQuestLogEntrySequence(struct QuestLogEntry *); +static u8 TryRecordActionSequence(struct QuestLogAction *); static void Task_BeginQuestLogPlayback(u8); -static void QuestLogPlaybackSetObjectEventTemplates(u8); +static void QL_LoadObjectsAndTemplates(u8); static void QLPlayback_InitOverworldState(void); -static void QuestLog_GetSaneMonCounts(void); -static u16 QuestLog_GetSanePartyCount(void); -static u16 QuestLog_GetSaneBoxCount(void); -static void sub_8111688(void); -static void ReadQuestLogScriptFromSav1(u8, struct QuestLogEntry *); -static void QuestLog_BeginFadeAtEndOfScene(s8 delay); +static void SetPokemonCounts(void); +static u16 QuestLog_GetPartyCount(void); +static u16 QuestLog_GetBoxMonCount(void); +static void RestoreTrainerRematches(void); +static void ReadQuestLogScriptFromSav1(u8, struct QuestLogAction *); +static void DoSceneEndTransition(s8 delay); +static void DoSkipToEndTransition(s8 delay); static void QuestLog_AdvancePlayhead(void); static void QuestLog_StartFinalScene(void); -static void Task_RunPlaybackCB(u8); +static void Task_AvoidDisplay(u8); static void QuestLog_PlayCurrentEvent(void); static void HandleShowQuestLogMessage(void); static u8 GetQuestLogTextDisplayDuration(void); -static void DrawQuestLogSceneDescription(void); -static void sub_8111D90(u8); +static void DrawSceneDescription(void); +static void CopyDescriptionWindowTiles(u8); static void QuestLog_CloseTextWindow(void); -static void QuestLog_SkipToEndOfPlayback(s8 delay); static void QuestLog_WaitFadeAndCancelPlayback(void); static bool8 FieldCB2_FinalScene(void); static void Task_FinalScene_WaitFade(u8); static void Task_QuestLogScene_SavedGame(u8); static void Task_WaitAtEndOfQuestLog(u8); static void Task_EndQuestLog(u8); -static bool8 sub_81121D8(u8); +static bool8 RestoreScreenAfterPlayback(u8); static void QL_SlightlyDarkenSomePals(void); static void TogglePlaybackStateForOverworldLock(u8); -static void SetUpQuestLogEntry(u8, struct QuestLogEntry *, u16); +static void ResetActions(u8, struct QuestLogAction *, u16); static bool8 RecordHeadAtEndOfEntryOrScriptContext2Enabled(void); static bool8 RecordHeadAtEndOfEntry(void); -static void TryLoseFansFromPlayTimeAfterLinkBattle(struct TrainerFanClub *); -static void UpdateTrainerFanClubGameClear(struct TrainerFanClub *); -static u8 PlayerGainRandomTrainerFan(struct TrainerFanClub *); -static u16 GetNumFansOfPlayerInTrainerFanClub(struct TrainerFanClub *); -static void TryLoseFansFromPlayTime(struct TrainerFanClub *); -static bool16 IsFanClubMemberFanOfPlayer(struct TrainerFanClub *); -static void SetInitialFansOfPlayer(struct TrainerFanClub *); -static void BufferFanClubTrainerName(struct LinkBattleRecords *, u8, u8); -static void UpdateTrainerFansAfterLinkBattle(struct TrainerFanClub *); -static bool8 DidPlayerGetFirstFans(struct TrainerFanClub * ); -static void SetPlayerGotFirstFans(struct TrainerFanClub *); static bool8 InQuestLogDisabledLocation(void); static bool8 TrySetLinkQuestLogEvent(u16, const u16 *); static bool8 TrySetTrainerBattleQuestLogEvent(u16, const u16 *); -static const struct WindowTemplate sQuestLogHeaderWindowTemplates[3] = { - { 0, 0, 0, 30, 2, 15, 0x0e9 }, - { 0, 0, 18, 30, 2, 15, 0x0ad }, - { 0, 0, 14, 30, 6, 15, 0x14c } +static const struct WindowTemplate sWindowTemplates[WIN_COUNT] = { + [WIN_TOP_BAR] = { + .bg = 0, + .tilemapLeft = 0, + .tilemapTop = 0, + .width = 30, + .height = 2, + .paletteNum = 15, + .baseBlock = 0x0e9 + }, + [WIN_BOTTOM_BAR] = { + .bg = 0, + .tilemapLeft = 0, + .tilemapTop = 18, + .width = 30, + .height = 2, + .paletteNum = 15, + .baseBlock = 0x0ad + }, + [WIN_DESCRIPTION] = { + .bg = 0, + .tilemapLeft = 0, + .tilemapTop = 14, + .width = DESC_WIN_WIDTH, + .height = DESC_WIN_HEIGHT, + .paletteNum = 15, + .baseBlock = 0x14c + } }; static const u8 sTextColors[3] = {TEXT_DYNAMIC_COLOR_6, TEXT_COLOR_WHITE, TEXT_DYNAMIC_COLOR_3}; -static const u16 sUnknown_8456638[] = INCBIN_U16("graphics/unknown/unknown_8456638.bin"); +static const u16 sDescriptionWindow_Gfx[] = INCBIN_U16("graphics/quest_log/description_window.4bpp"); static const u8 sQuestLogTextLineYCoords[] = {17, 10, 3}; -void SetQuestLogRecordAndPlaybackPointers(void *oldPointer) +void QL_AddASLROffset(void *oldSaveBlockPtr) { - ptrdiff_t offset = (void *)gSaveBlock1Ptr - oldPointer; - if (gUnknown_203AE04) - gUnknown_203AE04 = (void *)gUnknown_203AE04 + offset; - if (gQuestLogState != 0) + // For some reason the caller passes the original pointer and the + // amount the save moved is recalculated, instead of just passing + // the offset to begin with. + ptrdiff_t offset = (void *)gSaveBlock1Ptr - oldSaveBlockPtr; + if (gQuestLogDefeatedWildMonRecord) + gQuestLogDefeatedWildMonRecord = (void *)gQuestLogDefeatedWildMonRecord + offset; + + if (gQuestLogState == 0) + return; + + if (gQuestLogRecordingPointer) + gQuestLogRecordingPointer = (void *)gQuestLogRecordingPointer + offset; + + if (gQuestLogState == QL_STATE_PLAYBACK) { - if (sEventRecordingPointer) - sEventRecordingPointer = (void *)sEventRecordingPointer + offset; - if (gQuestLogState == QL_STATE_PLAYBACK) - { - int r3; - for (r3 = 0; r3 < (int)NELEMS(gUnknown_203AE0C); r3++) - if (gUnknown_203AE0C[r3]) - gUnknown_203AE0C[r3] = (void *)gUnknown_203AE0C[r3] + offset; - } + int i; + for (i = 0; i < (int)ARRAY_COUNT(sEventData); i++) + if (sEventData[i]) + sEventData[i] = (void *)sEventData[i] + offset; } } @@ -178,21 +203,21 @@ void ResetQuestLog(void) sCurrentSceneNum = 0; gQuestLogState = 0; sQuestLogCB = NULL; - sEventRecordingPointer = NULL; - gUnknown_203AE04 = NULL; - sub_8113BD8(); + gQuestLogRecordingPointer = NULL; + gQuestLogDefeatedWildMonRecord = NULL; + QL_ResetEventStates(); ResetDeferredLinkEvent(); } -static void DestroySav1QuestLogEntry(u8 a0) +static void ClearSavedScene(u8 sceneNum) { - memset(gSaveBlock1Ptr->questLog + a0, 0, sizeof(struct QuestLog)); - gUnknown_203AE04 = NULL; + memset(&gSaveBlock1Ptr->questLog[sceneNum], 0, sizeof(gSaveBlock1Ptr->questLog[sceneNum])); + gQuestLogDefeatedWildMonRecord = NULL; } -void sub_8110920(void) +void QL_ResetDefeatedWildMonRecord(void) { - gUnknown_203AE04 = NULL; + gQuestLogDefeatedWildMonRecord = NULL; } void RunQuestLogCB(void) @@ -201,22 +226,23 @@ void RunQuestLogCB(void) sQuestLogCB(); } -bool8 sub_8110944(const void *a0, size_t cmdSize) +bool8 QL_IsRoomToSaveEvent(const void * cursor, size_t size) { - void *r2 = gSaveBlock1Ptr->questLog[sCurrentSceneNum].script; - void *r0 = gSaveBlock1Ptr->questLog[sCurrentSceneNum].end; - r0 -= cmdSize; - if ((const void *)a0 < r2 || (const void *)a0 > r0) + const void *start = gSaveBlock1Ptr->questLog[sCurrentSceneNum].script; + const void *end = gSaveBlock1Ptr->questLog[sCurrentSceneNum].end; + end -= size; + if (cursor < start || cursor > end) return FALSE; return TRUE; } -bool8 WillCommandOfSizeFitInSav1Record(u16 *cursor, size_t size) +// Identical to QL_IsRoomToSaveEvent +bool8 QL_IsRoomToSaveAction(const void * cursor, size_t size) { - void *start = gSaveBlock1Ptr->questLog[sCurrentSceneNum].script; - void *end = gSaveBlock1Ptr->questLog[sCurrentSceneNum].end; + const void *start = gSaveBlock1Ptr->questLog[sCurrentSceneNum].script; + const void *end = gSaveBlock1Ptr->questLog[sCurrentSceneNum].end; end -= size; - if ((void *)cursor < start || (void *)cursor > end) + if (cursor < start || cursor > end) return FALSE; return TRUE; } @@ -232,10 +258,10 @@ static void SetQuestLogState(u8 state) static void QLogCB_Recording(void) { - if (TryRecordQuestLogEntrySequence(sQuestLogSceneRecordBuffer) != 1) + if (TryRecordActionSequence(sQuestLogActionRecordBuffer) != 1) { - gQuestLogPlaybackState = 0; - TryRecordEvent39_GoToNextScene(); + gQuestLogPlaybackState = QL_PLAYBACK_STATE_STOPPED; + RecordSceneEnd(); gQuestLogState = 0; sQuestLogCB = NULL; } @@ -243,21 +269,21 @@ static void QLogCB_Recording(void) static void QLogCB_Playback(void) { - if (sQuestLogCurrentScene.playbackSubstate == 2) - sQuestLogCurrentScene.playbackSubstate = 0; + if (sPlaybackControl.state == 2) + sPlaybackControl.state = 0; - if (sQuestLogCurrentScene.sceneEndMode == 0) + if (sPlaybackControl.endMode == END_MODE_NONE) { - if (gQuestLogPlaybackState != 0 - || sQuestLogCurrentScene.playbackSubstate == 1 - || (sQuestLogCurrentScene.cursor < NELEMS(gUnknown_203AE0C) - && gUnknown_203AE0C[sQuestLogCurrentScene.cursor] != NULL)) + if (gQuestLogPlaybackState != QL_PLAYBACK_STATE_STOPPED + || sPlaybackControl.state == 1 + || (sPlaybackControl.cursor < ARRAY_COUNT(sEventData) + && sEventData[sPlaybackControl.cursor] != NULL)) QuestLog_PlayCurrentEvent(); else { - sQuestLogCurrentScene.sceneEndMode = 2; + sPlaybackControl.endMode = END_MODE_SCENE; LockPlayerFieldControls(); - QuestLog_BeginFadeAtEndOfScene(0); + DoSceneEndTransition(0); } } } @@ -272,33 +298,33 @@ u8 GetQuestLogStartType(void) return gSaveBlock1Ptr->questLog[sCurrentSceneNum].startType; } -void StartRecordingQuestLogEntry(u16 eventId) +void QL_StartRecordingAction(u16 eventId) { if (sCurrentSceneNum >= QUEST_LOG_SCENE_COUNT) sCurrentSceneNum = 0; - DestroySav1QuestLogEntry(sCurrentSceneNum); - ResetUnk203B044(); - sEventRecordingPointer = gSaveBlock1Ptr->questLog[sCurrentSceneNum].script; + ClearSavedScene(sCurrentSceneNum); + QL_ResetRepeatEventTracker(); + gQuestLogRecordingPointer = gSaveBlock1Ptr->questLog[sCurrentSceneNum].script; if (IS_LINK_QL_EVENT(eventId) || eventId == QL_EVENT_DEPARTED) gSaveBlock1Ptr->questLog[sCurrentSceneNum].startType = QL_START_WARP; else gSaveBlock1Ptr->questLog[sCurrentSceneNum].startType = QL_START_NORMAL; - QuestLog_GetSaneMonCounts(); + SetPokemonCounts(); SetPlayerInitialCoordsAtScene(sCurrentSceneNum); SetNPCInitialCoordsAtScene(sCurrentSceneNum); - BackUpTrainerRematchesToVars(); - BackUpMapLayoutToVar(); + BackUpTrainerRematches(); + BackUpMapLayout(); SetGameStateAtScene(sCurrentSceneNum); - gUnknown_203ADFC = 0; - SetUpQuestLogEntry(2, sQuestLogSceneRecordBuffer, 0x100); - TryRecordQuestLogEntrySequence(sQuestLogSceneRecordBuffer); + sRecordSequenceStartIdx = 0; + ResetActions(QL_PLAYBACK_STATE_RECORDING, sQuestLogActionRecordBuffer, sizeof(sQuestLogActionRecordBuffer)); + TryRecordActionSequence(sQuestLogActionRecordBuffer); SetQuestLogState(QL_STATE_RECORDING); } static void SetPlayerInitialCoordsAtScene(u8 sceneNum) { - struct QuestLog * questLog = &gSaveBlock1Ptr->questLog[sceneNum]; + struct QuestLogScene * questLog = &gSaveBlock1Ptr->questLog[sceneNum]; questLog->mapGroup = gSaveBlock1Ptr->location.mapGroup; questLog->mapNum = gSaveBlock1Ptr->location.mapNum; questLog->warpId = gSaveBlock1Ptr->location.warpId; @@ -308,112 +334,118 @@ static void SetPlayerInitialCoordsAtScene(u8 sceneNum) static void SetNPCInitialCoordsAtScene(u8 sceneNum) { - struct QuestLog * questLog = &gSaveBlock1Ptr->questLog[sceneNum]; + struct QuestLogScene * questLog = &gSaveBlock1Ptr->questLog[sceneNum]; u16 i; - SetQuestLogObjectEventsData(questLog); + QL_RecordObjects(questLog); - for (i = 0; i < NELEMS(gSaveBlock1Ptr->objectEventTemplates); i++) + for (i = 0; i < OBJECT_EVENT_TEMPLATES_COUNT; i++) { if (gSaveBlock1Ptr->objectEventTemplates[i].x < 0) { - questLog->npcData[i].x = -1 * gSaveBlock1Ptr->objectEventTemplates[i].x; - questLog->npcData[i].negx = TRUE; + questLog->objectEventTemplates[i].x = -1 * gSaveBlock1Ptr->objectEventTemplates[i].x; + questLog->objectEventTemplates[i].negx = TRUE; } else { - questLog->npcData[i].x = (u8)gSaveBlock1Ptr->objectEventTemplates[i].x; - questLog->npcData[i].negx = FALSE; + questLog->objectEventTemplates[i].x = (u8)gSaveBlock1Ptr->objectEventTemplates[i].x; + questLog->objectEventTemplates[i].negx = FALSE; } if (gSaveBlock1Ptr->objectEventTemplates[i].y < 0) { - questLog->npcData[i].y = (-gSaveBlock1Ptr->objectEventTemplates[i].y << 24) >> 24; - questLog->npcData[i].negy = TRUE; + questLog->objectEventTemplates[i].y = (-gSaveBlock1Ptr->objectEventTemplates[i].y << 24) >> 24; + questLog->objectEventTemplates[i].negy = TRUE; } else { - questLog->npcData[i].y = (u8)gSaveBlock1Ptr->objectEventTemplates[i].y; - questLog->npcData[i].negy = FALSE; + questLog->objectEventTemplates[i].y = (u8)gSaveBlock1Ptr->objectEventTemplates[i].y; + questLog->objectEventTemplates[i].negy = FALSE; } - questLog->npcData[i].elevation = gSaveBlock1Ptr->objectEventTemplates[i].objUnion.normal.elevation; - questLog->npcData[i].movementType = gSaveBlock1Ptr->objectEventTemplates[i].objUnion.normal.movementType; + questLog->objectEventTemplates[i].elevation = gSaveBlock1Ptr->objectEventTemplates[i].objUnion.normal.elevation; + questLog->objectEventTemplates[i].movementType = gSaveBlock1Ptr->objectEventTemplates[i].objUnion.normal.movementType; } } static void SetGameStateAtScene(u8 sceneNum) { - struct QuestLog * questLog = &gSaveBlock1Ptr->questLog[sceneNum]; + struct QuestLogScene * questLog = &gSaveBlock1Ptr->questLog[sceneNum]; - CpuCopy16(gSaveBlock1Ptr->flags, questLog->flags, NUM_FLAG_BYTES * sizeof(u8)); - CpuCopy16(gSaveBlock1Ptr->vars, questLog->vars, VARS_COUNT * sizeof(u16)); + CpuCopy16(gSaveBlock1Ptr->flags, questLog->flags, sizeof(gSaveBlock1Ptr->flags)); + CpuCopy16(gSaveBlock1Ptr->vars, questLog->vars, sizeof(gSaveBlock1Ptr->vars)); } -static void BackUpTrainerRematchesToVars(void) +static void BackUpTrainerRematches(void) { u16 i, j; - u16 sp0[4]; + u16 vars[4]; - for (i = 0; i < 4; i++) + // Save the contents of gSaveBlock1Ptr->trainerRematches to the 4 saveblock + // vars starting at VAR_QLBAK_TRAINER_REMATCHES. The rematch array is 100 bytes + // long, but each byte is only ever 0 or 1 to indicate that a rematch is available. + // They're compressed into single bits across 4 u16 save vars, which is only enough + // to save 64 elements of gSaveBlock1Ptr->trainerRematches. 64 however is the maximum + // that could ever be used, as its the maximum number of NPCs per map (OBJECT_EVENT_TEMPLATES_COUNT). + for (i = 0; i < ARRAY_COUNT(vars); i++) { - sp0[i] = 0; + vars[i] = 0; + + // 16 bits per var for (j = 0; j < 16; j++) { if (gSaveBlock1Ptr->trainerRematches[16 * i + j]) - { - sp0[i] += (1 << j); - } + vars[i] += (1 << j); } - VarSet(VAR_QLBAK_TRAINER_REMATCHES + i, sp0[i]); + VarSet(VAR_QLBAK_TRAINER_REMATCHES + i, vars[i]); } } -static void BackUpMapLayoutToVar(void) +static void BackUpMapLayout(void) { VarSet(VAR_QLBAK_MAP_LAYOUT, gSaveBlock1Ptr->mapLayoutId); } -static void TryRecordEvent39_GoToNextScene(void) +static void RecordSceneEnd(void) { - TryRecordEvent39_NoParams(sEventRecordingPointer); + QL_RecordAction_SceneEnd(gQuestLogRecordingPointer); if (++sCurrentSceneNum >= QUEST_LOG_SCENE_COUNT) sCurrentSceneNum = 0; } -static bool8 TryRecordQuestLogEntrySequence(struct QuestLogEntry * entry) +static bool8 TryRecordActionSequence(struct QuestLogAction * actions) { u16 i; - for (i = gUnknown_203ADFC; i < sQuestLogCursor; i++) + for (i = sRecordSequenceStartIdx; i < gQuestLogCurActionIdx; i++) { - if (sEventRecordingPointer == NULL) + if (gQuestLogRecordingPointer == NULL) return FALSE; - switch (entry[i].command) + switch (actions[i].type) { - case 0: - case 1: - sEventRecordingPointer = sub_8113D48(sEventRecordingPointer, &entry[i]); + case QL_ACTION_MOVEMENT: + case QL_ACTION_GFX_CHANGE: + gQuestLogRecordingPointer = QL_RecordAction_MovementOrGfxChange(gQuestLogRecordingPointer, &actions[i]); break; default: - sEventRecordingPointer = sub_8113CC8(sEventRecordingPointer, &entry[i]); + gQuestLogRecordingPointer = QL_RecordAction_Input(gQuestLogRecordingPointer, &actions[i]); break; } - if (sEventRecordingPointer == NULL) + if (gQuestLogRecordingPointer == NULL) { - gQuestLogPlaybackState = 0; + gQuestLogPlaybackState = QL_PLAYBACK_STATE_STOPPED; return FALSE; } } - if (gQuestLogPlaybackState == 0) + if (gQuestLogPlaybackState == QL_PLAYBACK_STATE_STOPPED) { - sEventRecordingPointer = TryRecordEvent39_NoParams(sEventRecordingPointer); + gQuestLogRecordingPointer = QL_RecordAction_SceneEnd(gQuestLogRecordingPointer); return FALSE; } - gUnknown_203ADFC = sQuestLogCursor; + sRecordSequenceStartIdx = gQuestLogCurActionIdx; return TRUE; } -void TrySetUpQuestLogScenes_ElseContinueFromSave(u8 taskId) +void TryStartQuestLogPlayback(u8 taskId) { u8 i; @@ -442,19 +474,19 @@ static void Task_BeginQuestLogPlayback(u8 taskId) { gSaveBlock1Ptr->location.mapGroup = MAP_GROUP(ROUTE1); gSaveBlock1Ptr->location.mapNum = MAP_NUM(ROUTE1); - gSaveBlock1Ptr->location.warpId = -1; + gSaveBlock1Ptr->location.warpId = WARP_ID_NONE; sCurrentSceneNum = 0; gDisableMapMusicChangeOnMapLoad = 1; DisableWildEncounters(TRUE); QLPlayback_InitOverworldState(); } -void sub_8110FCC(void) +void QL_InitSceneObjectsAndActions(void) { - ReadQuestLogScriptFromSav1(sCurrentSceneNum, sQuestLogSceneRecordBuffer); - ResetUnk203B044(); - SetUpQuestLogEntry(1, sQuestLogSceneRecordBuffer, 0x100); - QuestLogPlaybackSetObjectEventTemplates(sCurrentSceneNum); + ReadQuestLogScriptFromSav1(sCurrentSceneNum, sQuestLogActionRecordBuffer); + QL_ResetRepeatEventTracker(); + ResetActions(QL_PLAYBACK_STATE_RUNNING, sQuestLogActionRecordBuffer, sizeof(sQuestLogActionRecordBuffer)); + QL_LoadObjectsAndTemplates(sCurrentSceneNum); } static bool8 FieldCB2_QuestLogStartPlaybackWithWarpExit(void) @@ -462,8 +494,8 @@ static bool8 FieldCB2_QuestLogStartPlaybackWithWarpExit(void) LoadPalette(GetTextWindowPalette(4), BG_PLTT_ID(15), PLTT_SIZE_4BPP); SetQuestLogState(QL_STATE_PLAYBACK); FieldCB_DefaultWarpExit(); - sQuestLogCurrentScene = (struct UnkStruct_203AE94){}; - sQuestLogCurrentScene.playbackSubstate = 2; + sPlaybackControl = (struct PlaybackControl){}; + sPlaybackControl.state = 2; return 1; } @@ -472,8 +504,8 @@ static bool8 FieldCB2_QuestLogStartPlaybackStandingInPlace(void) LoadPalette(GetTextWindowPalette(4), BG_PLTT_ID(15), PLTT_SIZE_4BPP); SetQuestLogState(QL_STATE_PLAYBACK); FieldCB_WarpExitFadeFromBlack(); - sQuestLogCurrentScene = (struct UnkStruct_203AE94){}; - sQuestLogCurrentScene.playbackSubstate = 2; + sPlaybackControl = (struct PlaybackControl){}; + sPlaybackControl.state = 2; return 1; } @@ -481,10 +513,10 @@ void DrawPreviouslyOnQuestHeader(u8 sceneNum) { u8 i; - for (i = 0; i < NELEMS(sQuestLogHeaderWindowTemplates); i++) + for (i = 0; i < WIN_COUNT; i++) { - sQuestLogHeaderWindowIds[i] = AddWindow(&sQuestLogHeaderWindowTemplates[i]); - FillWindowPixelRect(sQuestLogHeaderWindowIds[i], 15, 0, 0, sQuestLogHeaderWindowTemplates[i].width * 8, sQuestLogHeaderWindowTemplates[i].height * 8); + sWindowIds[i] = AddWindow(&sWindowTemplates[i]); + FillWindowPixelRect(sWindowIds[i], 15, 0, 0, sWindowTemplates[i].width * 8, sWindowTemplates[i].height * 8); } StringExpandPlaceholders(gStringVar4, gText_QuestLog_PreviouslyOnYourQuest); @@ -496,46 +528,44 @@ void DrawPreviouslyOnQuestHeader(u8 sceneNum) StringAppend(gStringVar4, gStringVar1); } - AddTextPrinterParameterized4(sQuestLogHeaderWindowIds[0], FONT_NORMAL, 2, 2, 1, 2, sTextColors, 0, gStringVar4); - PutWindowTilemap(sQuestLogHeaderWindowIds[0]); - PutWindowTilemap(sQuestLogHeaderWindowIds[1]); - CopyWindowToVram(sQuestLogHeaderWindowIds[0], COPYWIN_GFX); - CopyWindowToVram(sQuestLogHeaderWindowIds[2], COPYWIN_GFX); - CopyWindowToVram(sQuestLogHeaderWindowIds[1], COPYWIN_FULL); + AddTextPrinterParameterized4(sWindowIds[WIN_TOP_BAR], FONT_NORMAL, 2, 2, 1, 2, sTextColors, 0, gStringVar4); + PutWindowTilemap(sWindowIds[WIN_TOP_BAR]); + PutWindowTilemap(sWindowIds[WIN_BOTTOM_BAR]); + CopyWindowToVram(sWindowIds[WIN_TOP_BAR], COPYWIN_GFX); + CopyWindowToVram(sWindowIds[WIN_DESCRIPTION], COPYWIN_GFX); + CopyWindowToVram(sWindowIds[WIN_BOTTOM_BAR], COPYWIN_FULL); } void CommitQuestLogWindow1(void) { - PutWindowTilemap(sQuestLogHeaderWindowIds[1]); - CopyWindowToVram(sQuestLogHeaderWindowIds[1], COPYWIN_MAP); + PutWindowTilemap(sWindowIds[WIN_BOTTOM_BAR]); + CopyWindowToVram(sWindowIds[WIN_BOTTOM_BAR], COPYWIN_MAP); } -static void QuestLogPlaybackSetObjectEventTemplates(u8 sceneNum) +static void QL_LoadObjectsAndTemplates(u8 sceneNum) { - struct QuestLog *questLog = &gSaveBlock1Ptr->questLog[sceneNum]; + struct QuestLogScene *questLog = &gSaveBlock1Ptr->questLog[sceneNum]; u16 i; - for (i = 0; i < 64; i++) + for (i = 0; i < OBJECT_EVENT_TEMPLATES_COUNT; i++) { - if (questLog->npcData[i].negx) - gSaveBlock1Ptr->objectEventTemplates[i].x = -questLog->npcData[i].x; + if (questLog->objectEventTemplates[i].negx) + gSaveBlock1Ptr->objectEventTemplates[i].x = -questLog->objectEventTemplates[i].x; else - gSaveBlock1Ptr->objectEventTemplates[i].x = questLog->npcData[i].x; - if (questLog->npcData[i].negy) - gSaveBlock1Ptr->objectEventTemplates[i].y = -(u8)questLog->npcData[i].y; + gSaveBlock1Ptr->objectEventTemplates[i].x = questLog->objectEventTemplates[i].x; + if (questLog->objectEventTemplates[i].negy) + gSaveBlock1Ptr->objectEventTemplates[i].y = -(u8)questLog->objectEventTemplates[i].y; else - gSaveBlock1Ptr->objectEventTemplates[i].y = questLog->npcData[i].y; - gSaveBlock1Ptr->objectEventTemplates[i].objUnion.normal.elevation = questLog->npcData[i].elevation; - gSaveBlock1Ptr->objectEventTemplates[i].objUnion.normal.movementType = questLog->npcData[i].movementType; + gSaveBlock1Ptr->objectEventTemplates[i].y = questLog->objectEventTemplates[i].y; + gSaveBlock1Ptr->objectEventTemplates[i].objUnion.normal.elevation = questLog->objectEventTemplates[i].elevation; + gSaveBlock1Ptr->objectEventTemplates[i].objUnion.normal.movementType = questLog->objectEventTemplates[i].movementType; } - SetSav1ObjectEventsFromQuestLog(questLog, gSaveBlock1Ptr->objectEventTemplates); + QL_LoadObjects(questLog, gSaveBlock1Ptr->objectEventTemplates); } static void QLPlayback_SetInitialPlayerPosition(u8 sceneNum, bool8 isWarp) { - struct WarpData sp0; - if (!isWarp) { gSaveBlock1Ptr->location.mapGroup = gSaveBlock1Ptr->questLog[sceneNum].mapGroup; @@ -546,12 +576,13 @@ static void QLPlayback_SetInitialPlayerPosition(u8 sceneNum, bool8 isWarp) } else { - sp0.mapGroup = gSaveBlock1Ptr->questLog[sceneNum].mapGroup; - sp0.mapNum = gSaveBlock1Ptr->questLog[sceneNum].mapNum; - sp0.warpId = gSaveBlock1Ptr->questLog[sceneNum].warpId; - sp0.x = gSaveBlock1Ptr->questLog[sceneNum].x; - sp0.y = gSaveBlock1Ptr->questLog[sceneNum].y; - Overworld_SetWarpDestinationFromWarp(&sp0); + struct WarpData warp; + warp.mapGroup = gSaveBlock1Ptr->questLog[sceneNum].mapGroup; + warp.mapNum = gSaveBlock1Ptr->questLog[sceneNum].mapNum; + warp.warpId = gSaveBlock1Ptr->questLog[sceneNum].warpId; + warp.x = gSaveBlock1Ptr->questLog[sceneNum].x; + warp.y = gSaveBlock1Ptr->questLog[sceneNum].y; + Overworld_SetWarpDestinationFromWarp(&warp); } } @@ -576,102 +607,97 @@ static void QLPlayback_InitOverworldState(void) } } -void sub_81113E4(void) +void QL_CopySaveState(void) { - struct QuestLog * questLog = &gSaveBlock1Ptr->questLog[sCurrentSceneNum]; + struct QuestLogScene * questLog = &gSaveBlock1Ptr->questLog[sCurrentSceneNum]; - CpuCopy16(questLog->flags, gSaveBlock1Ptr->flags, NUM_FLAG_BYTES * sizeof(u8)); - CpuCopy16(questLog->vars, gSaveBlock1Ptr->vars, VARS_COUNT * sizeof(u16)); - sub_8111688(); + CpuCopy16(questLog->flags, gSaveBlock1Ptr->flags, sizeof(gSaveBlock1Ptr->flags)); + CpuCopy16(questLog->vars, gSaveBlock1Ptr->vars, sizeof(gSaveBlock1Ptr->vars)); + RestoreTrainerRematches(); } -struct PokemonAndSomethingElse +// The number of bits allocated to store the number of pokemon in the PC +#define NUM_PC_COUNT_BITS 12 + +void QL_ResetPartyAndPC(void) { - struct Pokemon mon; - u16 sanePartyCount; - u16 saneBoxesCount; -}; + struct { + struct Pokemon mon; + u16 partyCount; + u16 boxMonCount; + } *prev = AllocZeroed(sizeof(*prev)); + u16 packedCounts, i, count, j; -void sub_8111438(void) -{ - struct PokemonAndSomethingElse *r9 = AllocZeroed(sizeof(struct PokemonAndSomethingElse)); - u16 r0, r3, r5, r6; + CreateMon(&prev->mon, SPECIES_RATTATA, 1, USE_RANDOM_IVS, FALSE, 0, OT_ID_PLAYER_ID, 0); + packedCounts = VarGet(VAR_QUEST_LOG_MON_COUNTS); + prev->partyCount = packedCounts >> NUM_PC_COUNT_BITS; + prev->boxMonCount = packedCounts % (1 << NUM_PC_COUNT_BITS); - CreateMon(&r9->mon, SPECIES_RATTATA, 1, 0x20, FALSE, 0, 0, 0); - r0 = VarGet(VAR_QUEST_LOG_MON_COUNTS); - r9->sanePartyCount = r0 >> 12; - r9->saneBoxesCount = r0 % 0x1000; - - r5 = QuestLog_GetSanePartyCount(); - if (r5 > r9->sanePartyCount) + count = QuestLog_GetPartyCount(); + if (count > prev->partyCount) { - for (r3 = 0; r3 < r5 - r9->sanePartyCount; r3++) - { - ZeroMonData(&gPlayerParty[5 - r3]); - } + for (i = 0; i < count - prev->partyCount; i++) + ZeroMonData(&gPlayerParty[PARTY_SIZE - 1 - i]); } - else if (r5 < r9->sanePartyCount) + else if (count < prev->partyCount) { - for (r3 = 0; r3 < 5; r3++) - { - ZeroBoxMonAt(0, r3); - } - for (r3 = r5; r3 < r9->sanePartyCount; r3++) - { - CopyMon(&gPlayerParty[r3], &r9->mon, sizeof(struct Pokemon)); - } + // Clear 5 slots in the PC? + for (i = 0; i < PARTY_SIZE - 1; i++) + ZeroBoxMonAt(0, i); + + // Replace the additional slots with placeholder Pokémon. + for (i = count; i < prev->partyCount; i++) + CopyMon(&gPlayerParty[i], &prev->mon, sizeof(struct Pokemon)); } - r5 = QuestLog_GetSaneBoxCount(); - if (r5 > r9->saneBoxesCount) + count = QuestLog_GetBoxMonCount(); + if (count > prev->boxMonCount) { - for (r3 = 0; r3 < 14; r3++) + for (i = 0; i < TOTAL_BOXES_COUNT; i++) { - for (r6 = 0; r6 < 30; r6++) + for (j = 0; j < IN_BOX_COUNT; j++) { - if (GetBoxMonDataAt(r3, r6, MON_DATA_SANITY_HAS_SPECIES)) + if (GetBoxMonDataAt(i, j, MON_DATA_SANITY_HAS_SPECIES)) { - ZeroBoxMonAt(r3, r6); - r5--; - if (r5 == r9->saneBoxesCount) + ZeroBoxMonAt(i, j); + if (--count == prev->boxMonCount) break; } } - if (r5 == r9->saneBoxesCount) + if (count == prev->boxMonCount) break; } } - else if (r5 < r9->saneBoxesCount) + else if (count < prev->boxMonCount) { - for (r3 = 0; r3 < TOTAL_BOXES_COUNT; r3++) + for (i = 0; i < TOTAL_BOXES_COUNT; i++) { - for (r6 = 0; r6 < IN_BOX_COUNT; r6++) + for (j = 0; j < IN_BOX_COUNT; j++) { - struct BoxPokemon * boxMon = GetBoxedMonPtr(r3, r6); + struct BoxPokemon * boxMon = GetBoxedMonPtr(i, j); if (!GetBoxMonData(boxMon, MON_DATA_SANITY_HAS_SPECIES)) { - CopyMon(boxMon, &r9->mon.box, sizeof(struct BoxPokemon)); - r5++; - if (r5 == r9->saneBoxesCount) + // Replace the additional slots with placeholder Pokémon. + CopyMon(boxMon, &prev->mon.box, sizeof(struct BoxPokemon)); + if (++count == prev->boxMonCount) break; } } - if (r5 == r9->saneBoxesCount) + if (count == prev->boxMonCount) break; } } - - Free(r9); + Free(prev); } -static void QuestLog_GetSaneMonCounts(void) +static void SetPokemonCounts(void) { - u16 partyCount = QuestLog_GetSanePartyCount(); - u16 boxesCount = QuestLog_GetSaneBoxCount(); - VarSet(VAR_QUEST_LOG_MON_COUNTS, (partyCount << 12) + boxesCount); + u16 partyCount = QuestLog_GetPartyCount(); + u16 boxesCount = QuestLog_GetBoxMonCount(); + VarSet(VAR_QUEST_LOG_MON_COUNTS, (partyCount << NUM_PC_COUNT_BITS) + boxesCount); } -static u16 QuestLog_GetSanePartyCount(void) +static u16 QuestLog_GetPartyCount(void) { u16 count = 0; u16 i; @@ -685,7 +711,7 @@ static u16 QuestLog_GetSanePartyCount(void) return count; } -static u16 QuestLog_GetSaneBoxCount(void) +static u16 QuestLog_GetBoxMonCount(void) { u16 count = 0; u16 i, j; @@ -702,86 +728,85 @@ static u16 QuestLog_GetSaneBoxCount(void) return count; } -static void sub_8111688(void) +// Inverse of BackUpTrainerRematches +static void RestoreTrainerRematches(void) { u16 i, j; - u16 sp0[4]; + u16 vars[4]; - for (i = 0; i < 4; i++) + for (i = 0; i < ARRAY_COUNT(vars); i++) { - sp0[i] = VarGet(VAR_QLBAK_TRAINER_REMATCHES + i); + vars[i] = VarGet(VAR_QLBAK_TRAINER_REMATCHES + i); + // 16 bits per var for (j = 0; j < 16; j++) { - if (sp0[i] & 1) + if (vars[i] & 1) gSaveBlock1Ptr->trainerRematches[16 * i + j] = 30; else gSaveBlock1Ptr->trainerRematches[16 * i + j] = 0; - sp0[i] >>= 1; + vars[i] >>= 1; } } } -void sub_8111708(void) +// Inverse of BackUpMapLayout +void QL_RestoreMapLayoutId(void) { - struct MapHeader sp0; - gSaveBlock1Ptr->mapLayoutId = VarGet(VAR_QLBAK_MAP_LAYOUT); if (gSaveBlock1Ptr->mapLayoutId == 0) { - sp0 = *Overworld_GetMapHeaderByGroupAndId(gSaveBlock1Ptr->location.mapGroup, gSaveBlock1Ptr->location.mapNum); - gSaveBlock1Ptr->mapLayoutId = sp0.mapLayoutId; + struct MapHeader header = *Overworld_GetMapHeaderByGroupAndId(gSaveBlock1Ptr->location.mapGroup, gSaveBlock1Ptr->location.mapNum); + gSaveBlock1Ptr->mapLayoutId = header.mapLayoutId; } } -static void ReadQuestLogScriptFromSav1(u8 sceneNum, struct QuestLogEntry * a1) +static void ReadQuestLogScriptFromSav1(u8 sceneNum, struct QuestLogAction * actions) { u16 i; - u16 *r4; - u16 r6 = 0; - u16 r9 = 0; + u16 *script; + u16 actionNum = 0; + u16 eventNum = 0; - memset(a1, 0, 32 * sizeof(struct QuestLogEntry)); - for (i = 0; i < NELEMS(gUnknown_203AE0C); i++) - { - gUnknown_203AE0C[i] = NULL; - } + memset(actions, 0, ARRAY_COUNT(sEventData) * sizeof(struct QuestLogAction)); + for (i = 0; i < ARRAY_COUNT(sEventData); i++) + sEventData[i] = NULL; - r4 = gSaveBlock1Ptr->questLog[sceneNum].script; - for (i = 0; i < 32; i++) + script = gSaveBlock1Ptr->questLog[sceneNum].script; + for (i = 0; i < ARRAY_COUNT(sEventData); i++) { - switch (r4[0] & 0xFFF) + switch (script[0] & QL_CMD_EVENT_MASK) { - case QL_EVENT_0: - r4 = sub_8113D08(r4, &a1[r6]); - r6++; + case QL_EVENT_INPUT: + script = QL_LoadAction_Input(script, &actions[actionNum]); + actionNum++; break; - case QL_EVENT_1: - case QL_EVENT_2: - r4 = sub_8113D94(r4, &a1[r6]); - r6++; + case QL_EVENT_GFX_CHANGE: + case QL_EVENT_MOVEMENT: + script = QL_LoadAction_MovementOrGfxChange(script, &actions[actionNum]); + actionNum++; break; - case QL_EVENT_39: - r4 = sub_8113C20(r4, &a1[r6]); - r6++; + case QL_EVENT_SCENE_END: + script = QL_LoadAction_SceneEnd(script, &actions[actionNum]); + actionNum++; break; - case QL_EVENT_41: - r4 = sub_8113C8C(r4, &a1[r6]); - r6++; + case QL_EVENT_WAIT: + script = QL_LoadAction_Wait(script, &actions[actionNum]); + actionNum++; break; - default: - r4 = QuestLog_SkipCommand(r4, &gUnknown_203AE0C[r9]); - if (r9 == 0) - sub_8113ABC(gUnknown_203AE0C[0]); - r9++; + default: // Normal event + script = QL_SkipCommand(script, &sEventData[eventNum]); + if (eventNum == 0) + QL_UpdateLastDepartedLocation(sEventData[0]); + eventNum++; break; } - if (r4 == NULL) + if (script == NULL) break; } } -static void QuestLog_BeginFadeAtEndOfScene(s8 delay) +static void DoSceneEndTransition(s8 delay) { FadeScreen(FADE_TO_BLACK, delay); sQuestLogCB = QuestLog_AdvancePlayhead; @@ -789,19 +814,19 @@ static void QuestLog_BeginFadeAtEndOfScene(s8 delay) static void QuestLog_AdvancePlayhead(void) { - if (!gPaletteFade.active) + if (gPaletteFade.active) + return; + + LockPlayerFieldControls(); + if (++sCurrentSceneNum < QUEST_LOG_SCENE_COUNT && gSaveBlock1Ptr->questLog[sCurrentSceneNum].startType != 0) { - LockPlayerFieldControls(); - if (++sCurrentSceneNum < QUEST_LOG_SCENE_COUNT && gSaveBlock1Ptr->questLog[sCurrentSceneNum].startType != 0) - { - sNumScenes--; - QLPlayback_InitOverworldState(); - } - else - { - gQuestLogPlaybackState = 0; - QuestLog_StartFinalScene(); - } + sNumScenes--; + QLPlayback_InitOverworldState(); + } + else + { + gQuestLogPlaybackState = QL_PLAYBACK_STATE_STOPPED; + QuestLog_StartFinalScene(); } } @@ -822,48 +847,62 @@ void QuestLog_AdvancePlayhead_(void) QuestLog_AdvancePlayhead(); } -bool8 QuestLog_SchedulePlaybackCB(void (*callback)(void)) +#define tTimer data[0] +#define tState data[1] +#define DATA_IDX_CALLBACK 14 // data[14] and data[15] + +// This is used to avoid recording or displaying certain windows or images, like a shop menu. +// During playback it returns TRUE (meaning the action should be avoided) and calls the +// provided callback, which would be used to e.g. destroy any resources that were set up to do +// whatever is being avoided. In all cases the provided callback will be QL_DestroyAbortedDisplay. +// If we are not currently in playback return FALSE (meaning allow the action to occur) and +// stop recording (if we are currently). +bool8 QL_AvoidDisplay(void (*callback)(void)) { u8 taskId; switch (gQuestLogState) { - case QL_STATE_RECORDING: - QuestLog_CutRecording(); - break; - case QL_STATE_PLAYBACK: - gQuestLogPlaybackState = 3; - taskId = CreateTask(Task_RunPlaybackCB, 80); - gTasks[taskId].data[0] = 0; - gTasks[taskId].data[1] = 0; - SetWordTaskArg(taskId, 14, (uintptr_t)callback); - return TRUE; + case QL_STATE_RECORDING: + QuestLog_CutRecording(); + break; + case QL_STATE_PLAYBACK: + gQuestLogPlaybackState = QL_PLAYBACK_STATE_ACTION_END; + taskId = CreateTask(Task_AvoidDisplay, 80); + gTasks[taskId].tTimer = 0; + gTasks[taskId].tState = 0; + SetWordTaskArg(taskId, DATA_IDX_CALLBACK, (uintptr_t)callback); + return TRUE; } return FALSE; } -static void Task_RunPlaybackCB(u8 taskId) +static void Task_AvoidDisplay(u8 taskId) { void (*routine)(void); s16 *data = gTasks[taskId].data; - switch (data[1]) + switch (tState) { case 0: - if (++data[0] == 0x7F) + // Instead of displaying anything, wait and then end the scene. + if (++tTimer == 127) { BeginNormalPaletteFade(PALETTES_ALL, 0, 0, 16, 0); - sQuestLogCurrentScene.sceneEndMode = 2; - data[1]++; + sPlaybackControl.endMode = END_MODE_SCENE; + tState++; } break; case 1: if (!gPaletteFade.active) { - gQuestLogPlaybackState = 0; - routine = (void (*)(void)) GetWordTaskArg(taskId, 14); + gQuestLogPlaybackState = QL_PLAYBACK_STATE_STOPPED; + + // Call the provided function (if any). In practice this is always QL_DestroyAbortedDisplay + routine = (void (*)(void)) GetWordTaskArg(taskId, DATA_IDX_CALLBACK); if (routine != NULL) routine(); + DestroyTask(taskId); sQuestLogCB = QuestLog_AdvancePlayhead; } @@ -871,48 +910,51 @@ static void Task_RunPlaybackCB(u8 taskId) } } +#undef tTimer +#undef tState + static void QuestLog_PlayCurrentEvent(void) { - if (sQuestLogCurrentScene.playbackSubstate == 1) + if (sPlaybackControl.state == 1) { - if (--sQuestLogCurrentScene.timer != 0) + if (--sPlaybackControl.timer != 0) return; - sQuestLogCurrentScene.playbackSubstate = 0; - sQuestLogCurrentScene.playingEvent = 1; + sPlaybackControl.state = 0; + sPlaybackControl.playingEvent = TRUE; TogglePlaybackStateForOverworldLock(2); } - if (sQuestLogCurrentScene.playingEvent == 1) + if (sPlaybackControl.playingEvent == TRUE) { - if (++sQuestLogCurrentScene.overlapTimer > 15) + if (++sPlaybackControl.overlapTimer > 15) { QuestLog_CloseTextWindow(); - sQuestLogCurrentScene.playingEvent = 0; - sQuestLogCurrentScene.overlapTimer = 0; + sPlaybackControl.playingEvent = FALSE; + sPlaybackControl.overlapTimer = 0; } } - if (sQuestLogCurrentScene.cursor < NELEMS(gUnknown_203AE0C)) + if (sPlaybackControl.cursor < ARRAY_COUNT(sEventData)) { - if (sub_8113B44(gUnknown_203AE0C[sQuestLogCurrentScene.cursor]) == 1) + if (QL_TryRepeatEvent(sEventData[sPlaybackControl.cursor]) == TRUE) HandleShowQuestLogMessage(); - else if (sub_8113AE8(gUnknown_203AE0C[sQuestLogCurrentScene.cursor]) == 1) + else if (QL_LoadEvent(sEventData[sPlaybackControl.cursor]) == TRUE) HandleShowQuestLogMessage(); } } static void HandleShowQuestLogMessage(void) { - if (sQuestLogCurrentScene.playbackSubstate == 0) + if (sPlaybackControl.state == 0) { - sQuestLogCurrentScene.playbackSubstate = 1; - sQuestLogCurrentScene.playingEvent = 0; - sQuestLogCurrentScene.overlapTimer = 0; - sQuestLogCurrentScene.timer = GetQuestLogTextDisplayDuration(); - if (gUnknown_203B044.unk_2 == 0) - sQuestLogCurrentScene.cursor++; - if (sQuestLogCurrentScene.cursor > 32) + sPlaybackControl.state = 1; + sPlaybackControl.playingEvent = FALSE; + sPlaybackControl.overlapTimer = 0; + sPlaybackControl.timer = GetQuestLogTextDisplayDuration(); + if (gQuestLogRepeatEventTracker.counter == 0) + sPlaybackControl.cursor++; + if (sPlaybackControl.cursor > ARRAY_COUNT(sEventData)) return; - DrawQuestLogSceneDescription(); + DrawSceneDescription(); } TogglePlaybackStateForOverworldLock(1); // lock } @@ -937,37 +979,40 @@ static u8 GetQuestLogTextDisplayDuration(void) return 0xFF; } -bool8 sub_8111C2C(void) +bool8 QL_IsTrainerSightDisabled(void) { if (gQuestLogState != QL_STATE_PLAYBACK) return FALSE; - if (gQuestLogPlaybackState == 0 || sQuestLogCurrentScene.playbackSubstate == 1 || sQuestLogCurrentScene.playbackSubstate == 2) + if (gQuestLogPlaybackState == QL_PLAYBACK_STATE_STOPPED || sPlaybackControl.state == 1 || sPlaybackControl.state == 2) return TRUE; return FALSE; } -void sub_8111C68(void) +void QL_HandleInput(void) { - if (sQuestLogCurrentScene.sceneEndMode == 0) + // Ignore input if we're currently ending a scene/playback + if (sPlaybackControl.endMode != END_MODE_NONE) + return; + + if (JOY_NEW(A_BUTTON)) { - if (JOY_NEW(A_BUTTON)) - { - sQuestLogCurrentScene.sceneEndMode = 2; - gQuestLogPlaybackState = 0; - QuestLog_BeginFadeAtEndOfScene(-3); - } - else if (JOY_NEW(B_BUTTON)) - { - sQuestLogCurrentScene.sceneEndMode = 1; - gQuestLogPlaybackState = 0; - QuestLog_SkipToEndOfPlayback(-3); - } + // Pressed A, skip to next scene + sPlaybackControl.endMode = END_MODE_SCENE; + gQuestLogPlaybackState = QL_PLAYBACK_STATE_STOPPED; + DoSceneEndTransition(-3); + } + else if (JOY_NEW(B_BUTTON)) + { + // Pressed B, end playback + sPlaybackControl.endMode = END_MODE_FINISH; + gQuestLogPlaybackState = QL_PLAYBACK_STATE_STOPPED; + DoSkipToEndTransition(-3); } } bool8 QuestLogScenePlaybackIsEnding(void) { - if (sQuestLogCurrentScene.sceneEndMode != 0) + if (sPlaybackControl.endMode != END_MODE_NONE) return TRUE; return FALSE; } @@ -978,7 +1023,7 @@ void QuestLog_DrawPreviouslyOnQuestHeaderIfInPlaybackMode(void) DrawPreviouslyOnQuestHeader(sNumScenes); } -static void DrawQuestLogSceneDescription(void) +static void DrawSceneDescription(void) { u16 i; u8 numLines = 0; @@ -989,59 +1034,57 @@ static void DrawQuestLogSceneDescription(void) numLines++; } - PutWindowTilemap(sQuestLogHeaderWindowIds[2]); - sub_8111D90(sQuestLogHeaderWindowIds[2]); - AddTextPrinterParameterized4(sQuestLogHeaderWindowIds[2], FONT_NORMAL, 2, sQuestLogTextLineYCoords[numLines], 1, 0, sTextColors, 0, gStringVar4); + PutWindowTilemap(sWindowIds[WIN_DESCRIPTION]); + CopyDescriptionWindowTiles(sWindowIds[WIN_DESCRIPTION]); + AddTextPrinterParameterized4(sWindowIds[WIN_DESCRIPTION], FONT_NORMAL, 2, sQuestLogTextLineYCoords[numLines], 1, 0, sTextColors, 0, gStringVar4); ScheduleBgCopyTilemapToVram(0); } -static void sub_8111D90(u8 a0) +static void CopyDescriptionWindowTiles(u8 windowId) { - const u16 *src = sUnknown_8456638; - u16 *buffer = Alloc(0x1680); + const u16 *src = sDescriptionWindow_Gfx; + u16 *buffer = Alloc(DESC_WIN_SIZE); u8 i, j, y; if (buffer) { - for (i = 0; i < 6; i++) + for (i = 0; i < DESC_WIN_HEIGHT; i++) { switch (i) { default: + // Middle tile y = 1; break; case 0: + // Top edge tile y = 0; break; - case 5: + case DESC_WIN_HEIGHT - 1: + // Bottom edge tile y = 2; break; } - // r6 = y * 32 - // r5 = 2 * (i % 16) - // r4 = j - for (j = 0; j < 30; j++) - { - CpuCopy32(src + 16 * y, buffer + 16 * (2 * (15 * i) + j), 32); - } + for (j = 0; j < DESC_WIN_WIDTH; j++) + CpuCopy32(src + 16 * y, buffer + 16 * (2 * (15 * i) + j), TILE_SIZE_4BPP); } - CopyToWindowPixelBuffer(a0, (const u8 *)buffer, 0x1680, 0); + CopyToWindowPixelBuffer(windowId, (const u8 *)buffer, DESC_WIN_SIZE, 0); Free(buffer); } } static void QuestLog_CloseTextWindow(void) { - ClearWindowTilemap(sQuestLogHeaderWindowIds[2]); - FillWindowPixelRect(sQuestLogHeaderWindowIds[2], 15, 0, 0, 0xf0, 0x30); - CopyWindowToVram(sQuestLogHeaderWindowIds[2], COPYWIN_GFX); - PutWindowTilemap(sQuestLogHeaderWindowIds[1]); - CopyWindowToVram(sQuestLogHeaderWindowIds[1], COPYWIN_MAP); + ClearWindowTilemap(sWindowIds[WIN_DESCRIPTION]); + FillWindowPixelRect(sWindowIds[WIN_DESCRIPTION], 15, 0, 0, 0xf0, 0x30); + CopyWindowToVram(sWindowIds[WIN_DESCRIPTION], COPYWIN_GFX); + PutWindowTilemap(sWindowIds[WIN_BOTTOM_BAR]); + CopyWindowToVram(sWindowIds[WIN_BOTTOM_BAR], COPYWIN_MAP); } -static void QuestLog_SkipToEndOfPlayback(s8 delay) +static void DoSkipToEndTransition(s8 delay) { FadeScreen(FADE_TO_BLACK, delay); sQuestLogCB = QuestLog_WaitFadeAndCancelPlayback; @@ -1056,9 +1099,9 @@ static void QuestLog_WaitFadeAndCancelPlayback(void) { if (gSaveBlock1Ptr->questLog[sCurrentSceneNum].startType == 0) break; - ReadQuestLogScriptFromSav1(sCurrentSceneNum, sQuestLogSceneRecordBuffer); + ReadQuestLogScriptFromSav1(sCurrentSceneNum, sQuestLogActionRecordBuffer); } - gQuestLogPlaybackState = 0; + gQuestLogPlaybackState = QL_PLAYBACK_STATE_STOPPED; QuestLog_StartFinalScene(); } } @@ -1103,11 +1146,11 @@ static void Task_QuestLogScene_SavedGame(u8 taskId) if (!gPaletteFade.active) { - if (sQuestLogCurrentScene.sceneEndMode != 1) + if (sPlaybackControl.endMode != END_MODE_FINISH) { GetMapNameGeneric(gStringVar1, gMapHeader.regionMapSectionId); StringExpandPlaceholders(gStringVar4, gText_QuestLog_SavedGameAtLocation); - DrawQuestLogSceneDescription(); + DrawSceneDescription(); } task->data[0] = 0; task->data[1] = 0; @@ -1123,7 +1166,7 @@ static void Task_WaitAtEndOfQuestLog(u8 taskId) { struct Task *task = &gTasks[taskId]; - if (JOY_NEW(A_BUTTON | B_BUTTON) || task->tTimer >= 127 || sQuestLogCurrentScene.sceneEndMode == 1) + if (JOY_NEW(A_BUTTON | B_BUTTON) || task->tTimer >= 127 || sPlaybackControl.endMode == END_MODE_FINISH) { QuestLog_CloseTextWindow(); task->tTimer = 0; @@ -1150,17 +1193,20 @@ static void Task_EndQuestLog(u8 taskId) gDisableMapMusicChangeOnMapLoad = 0; Overworld_PlaySpecialMapMusic(); QL_SlightlyDarkenSomePals(); - FillWindowPixelRect(sQuestLogHeaderWindowIds[0], 0xF, 0, 0, sQuestLogHeaderWindowTemplates[0].width * 8, sQuestLogHeaderWindowTemplates[0].height * 8); + FillWindowPixelRect(sWindowIds[WIN_TOP_BAR], + 0xF, 0, 0, + sWindowTemplates[WIN_TOP_BAR].width * 8, + sWindowTemplates[WIN_TOP_BAR].height * 8); tState++; break; case 1: - if (sub_81121D8(taskId)) + if (RestoreScreenAfterPlayback(taskId)) { - for (i = 0; i < 3; i++) + for (i = 0; i < WIN_COUNT; i++) { - ClearWindowTilemap(sQuestLogHeaderWindowIds[i]); - CopyWindowToVram(sQuestLogHeaderWindowIds[i], COPYWIN_MAP); - RemoveWindow(sQuestLogHeaderWindowIds[i]); + ClearWindowTilemap(sWindowIds[i]); + CopyWindowToVram(sWindowIds[i], COPYWIN_MAP); + RemoveWindow(sWindowIds[i]); } tTimer = 0; tState++; @@ -1173,11 +1219,11 @@ static void Task_EndQuestLog(u8 taskId) tState++; break; default: - if (sQuestLogCurrentScene.sceneEndMode == 1) + if (sPlaybackControl.endMode == END_MODE_FINISH) ShowMapNamePopup(TRUE); CpuCopy16(sPalettesBackup, gPlttBufferUnfaded, PLTT_SIZE); Free(sPalettesBackup); - sQuestLogCurrentScene = (struct UnkStruct_203AE94){}; + sPlaybackControl = (struct PlaybackControl){}; ClearPlayerHeldMovementAndUnfreezeObjectEvents(); UnlockPlayerFieldControls(); gTextFlags.autoScroll = FALSE; @@ -1192,20 +1238,29 @@ static void Task_EndQuestLog(u8 taskId) #undef tState #undef tTimer -static bool8 sub_81121D8(u8 taskId) +#define tTimer data[1] + +// Scroll the top and bottom windows offscreen and restore the screen tint to the original color. +static bool8 RestoreScreenAfterPlayback(u8 taskId) { s16 *data = gTasks[taskId].data; - if (data[1] > 15) + if (tTimer > 15) return TRUE; - CopyPaletteInvertedTint(&gPlttBufferUnfaded[BG_PLTT_ID(0) + 1], &gPlttBufferFaded[BG_PLTT_ID(0) + 1], 0xDF, 0x0F - data[1]); - CopyPaletteInvertedTint(&gPlttBufferUnfaded[OBJ_PLTT_ID(0)], &gPlttBufferFaded[OBJ_PLTT_ID(0)], 0x100, 0x0F - data[1]); - FillWindowPixelRect(sQuestLogHeaderWindowIds[0], 0x00, 0, sQuestLogHeaderWindowTemplates[0].height * 8 - 1 - data[1], sQuestLogHeaderWindowTemplates[0].width * 8, 1); - FillWindowPixelRect(sQuestLogHeaderWindowIds[1], 0x00, 0, data[1], sQuestLogHeaderWindowTemplates[1].width * 8, 1); - CopyWindowToVram(sQuestLogHeaderWindowIds[0], COPYWIN_GFX); - CopyWindowToVram(sQuestLogHeaderWindowIds[1], COPYWIN_GFX); - data[1]++; + CopyPaletteInvertedTint(&gPlttBufferUnfaded[BG_PLTT_ID(0) + 1], &gPlttBufferFaded[BG_PLTT_ID(0) + 1], 0xDF, 15 - tTimer); + CopyPaletteInvertedTint(&gPlttBufferUnfaded[OBJ_PLTT_ID(0)], &gPlttBufferFaded[OBJ_PLTT_ID(0)], 0x100, 15 - tTimer); + FillWindowPixelRect(sWindowIds[WIN_TOP_BAR], + 0x00, 0, + sWindowTemplates[WIN_TOP_BAR].height * 8 - 1 - tTimer, + sWindowTemplates[WIN_TOP_BAR].width * 8, 1); + FillWindowPixelRect(sWindowIds[WIN_BOTTOM_BAR], + 0x00, 0, + data[1], + sWindowTemplates[WIN_BOTTOM_BAR].width * 8, 1); + CopyWindowToVram(sWindowIds[WIN_TOP_BAR], COPYWIN_GFX); + CopyWindowToVram(sWindowIds[WIN_BOTTOM_BAR], COPYWIN_GFX); + tTimer++; return FALSE; } @@ -1222,38 +1277,38 @@ static void QL_SlightlyDarkenSomePals(void) Free(buffer); } -void FinishRecordingQuestLogScene(void) +void QL_FinishRecordingScene(void) { if (gQuestLogState == QL_STATE_RECORDING) { - TryRecordQuestLogEntrySequence(sQuestLogSceneRecordBuffer); - TryRecordEvent39_GoToNextScene(); + TryRecordActionSequence(sQuestLogActionRecordBuffer); + RecordSceneEnd(); gQuestLogState = 0; sQuestLogCB = NULL; - gUnknown_203AE04 = NULL; - sEventRecordingPointer = NULL; - gQuestLogPlaybackState = 0; + gQuestLogDefeatedWildMonRecord = NULL; + gQuestLogRecordingPointer = NULL; + gQuestLogPlaybackState = QL_PLAYBACK_STATE_STOPPED; } } void QuestLog_CutRecording(void) { - if (gQuestLogPlaybackState != 0 && gQuestLogState == QL_STATE_RECORDING) + if (gQuestLogPlaybackState != QL_PLAYBACK_STATE_STOPPED && gQuestLogState == QL_STATE_RECORDING) { - TryRecordQuestLogEntrySequence(sQuestLogSceneRecordBuffer); - TryRecordEvent41_IncCursor(1); - TryRecordEvent39_GoToNextScene(); - gQuestLogPlaybackState = 0; + TryRecordActionSequence(sQuestLogActionRecordBuffer); + QL_RecordWait(1); + RecordSceneEnd(); + gQuestLogPlaybackState = QL_PLAYBACK_STATE_STOPPED; gQuestLogState = 0; sQuestLogCB = NULL; } - gUnknown_203AE04 = NULL; - sEventRecordingPointer = NULL; + gQuestLogDefeatedWildMonRecord = NULL; + gQuestLogRecordingPointer = NULL; } static void SortQuestLogInSav1(void) { - struct QuestLog * buffer = AllocZeroed(QUEST_LOG_SCENE_COUNT * sizeof(struct QuestLog)); + struct QuestLogScene * buffer = AllocZeroed(sizeof(gSaveBlock1Ptr->questLog)); u8 i; u8 sceneNum = sCurrentSceneNum; u8 count = 0; @@ -1269,7 +1324,7 @@ static void SortQuestLogInSav1(void) sceneNum++; } sCurrentSceneNum = count % QUEST_LOG_SCENE_COUNT; - CpuCopy16(buffer, gSaveBlock1Ptr->questLog, QUEST_LOG_SCENE_COUNT * sizeof(struct QuestLog)); + CpuCopy16(buffer, gSaveBlock1Ptr->questLog, sizeof(gSaveBlock1Ptr->questLog)); Free(buffer); } @@ -1282,31 +1337,31 @@ void SaveQuestLogData(void) } } -void sub_811246C(struct Sprite *sprite) +void QL_UpdateObject(struct Sprite *sprite) { struct ObjectEvent *objectEvent = &gObjectEvents[sprite->data[0]]; if (objectEvent->localId == OBJ_EVENT_ID_PLAYER) { - if (sMovementScripts[0][0] != 0xFF) + if (sMovementScripts[0][0] != MOVEMENT_ACTION_NONE) { ObjectEventSetHeldMovement(objectEvent, sMovementScripts[0][0]); - sMovementScripts[0][0] = 0xFF; + sMovementScripts[0][0] = MOVEMENT_ACTION_NONE; } - if (sMovementScripts[0][1] != 0xFF) + if (sMovementScripts[0][1] != QL_PLAYER_GFX_NONE) { QuestLogUpdatePlayerSprite(sMovementScripts[0][1]); - sMovementScripts[0][1] = 0xFF; + sMovementScripts[0][1] = QL_PLAYER_GFX_NONE; } - UpdateQuestLogObjectEventCurrentMovement(objectEvent, sprite); + QL_UpdateObjectEventCurrentMovement(objectEvent, sprite); } else { - if (sMovementScripts[objectEvent->localId][0] != 0xFF) + if (sMovementScripts[objectEvent->localId][0] != MOVEMENT_ACTION_NONE) { ObjectEventSetHeldMovement(objectEvent, sMovementScripts[objectEvent->localId][0]); - sMovementScripts[objectEvent->localId][0] = 0xFF; + sMovementScripts[objectEvent->localId][0] = MOVEMENT_ACTION_NONE; } - UpdateQuestLogObjectEventCurrentMovement(objectEvent, sprite); + QL_UpdateObjectEventCurrentMovement(objectEvent, sprite); } } @@ -1314,14 +1369,14 @@ void QuestLogRecordNPCStep(u8 localId, u8 mapNum, u8 mapGroup, u8 movementAction { if (!RecordHeadAtEndOfEntryOrScriptContext2Enabled()) { - sCurQuestLogEntry[sQuestLogCursor].duration = sNextStepDelay; - sCurQuestLogEntry[sQuestLogCursor].command = 0; - sCurQuestLogEntry[sQuestLogCursor].localId = localId; - sCurQuestLogEntry[sQuestLogCursor].mapNum = mapNum; - sCurQuestLogEntry[sQuestLogCursor].mapGroup = mapGroup; - sCurQuestLogEntry[sQuestLogCursor].animId = movementActionId; - sQuestLogCursor++; - sNextStepDelay = 0; + sCurSceneActions[gQuestLogCurActionIdx].duration = sNextActionDelay; + sCurSceneActions[gQuestLogCurActionIdx].type = QL_ACTION_MOVEMENT; + sCurSceneActions[gQuestLogCurActionIdx].data.a.localId = localId; + sCurSceneActions[gQuestLogCurActionIdx].data.a.mapNum = mapNum; + sCurSceneActions[gQuestLogCurActionIdx].data.a.mapGroup = mapGroup; + sCurSceneActions[gQuestLogCurActionIdx].data.a.movementActionId = movementActionId; + gQuestLogCurActionIdx++; + sNextActionDelay = 0; } } @@ -1329,14 +1384,14 @@ void QuestLogRecordNPCStepWithDuration(u8 localId, u8 mapNum, u8 mapGroup, u8 mo { if (!RecordHeadAtEndOfEntry()) { - sCurQuestLogEntry[sQuestLogCursor].duration = sNextStepDelay; - sCurQuestLogEntry[sQuestLogCursor].command = 0; - sCurQuestLogEntry[sQuestLogCursor].localId = localId; - sCurQuestLogEntry[sQuestLogCursor].mapNum = mapNum; - sCurQuestLogEntry[sQuestLogCursor].mapGroup = mapGroup; - sCurQuestLogEntry[sQuestLogCursor].animId = movementActionId; - sQuestLogCursor++; - sNextStepDelay = duration; + sCurSceneActions[gQuestLogCurActionIdx].duration = sNextActionDelay; + sCurSceneActions[gQuestLogCurActionIdx].type = QL_ACTION_MOVEMENT; + sCurSceneActions[gQuestLogCurActionIdx].data.a.localId = localId; + sCurSceneActions[gQuestLogCurActionIdx].data.a.mapNum = mapNum; + sCurSceneActions[gQuestLogCurActionIdx].data.a.mapGroup = mapGroup; + sCurSceneActions[gQuestLogCurActionIdx].data.a.movementActionId = movementActionId; + gQuestLogCurActionIdx++; + sNextActionDelay = duration; } } @@ -1344,15 +1399,15 @@ void QuestLogRecordPlayerStep(u8 movementActionId) { if (!RecordHeadAtEndOfEntryOrScriptContext2Enabled()) { - if (movementActionId != sCurQuestLogEntry[sLastQuestLogCursor].animId || movementActionId > MOVEMENT_ACTION_FACE_RIGHT) + if (movementActionId != sCurSceneActions[sLastQuestLogCursor].data.a.movementActionId || movementActionId > MOVEMENT_ACTION_FACE_RIGHT) { - sCurQuestLogEntry[sQuestLogCursor].duration = sNextStepDelay; - sCurQuestLogEntry[sQuestLogCursor].command = 0; - sCurQuestLogEntry[sQuestLogCursor].localId = 0; - sCurQuestLogEntry[sQuestLogCursor].animId = movementActionId; - sLastQuestLogCursor = sQuestLogCursor; - sQuestLogCursor++; - sNextStepDelay = 0; + sCurSceneActions[gQuestLogCurActionIdx].duration = sNextActionDelay; + sCurSceneActions[gQuestLogCurActionIdx].type = QL_ACTION_MOVEMENT; + sCurSceneActions[gQuestLogCurActionIdx].data.a.localId = 0; + sCurSceneActions[gQuestLogCurActionIdx].data.a.movementActionId = movementActionId; + sLastQuestLogCursor = gQuestLogCurActionIdx; + gQuestLogCurActionIdx++; + sNextActionDelay = 0; } } } @@ -1361,45 +1416,45 @@ void QuestLogRecordPlayerStepWithDuration(u8 movementActionId, u8 duration) { if (!RecordHeadAtEndOfEntry()) { - sCurQuestLogEntry[sQuestLogCursor].duration = sNextStepDelay; - sCurQuestLogEntry[sQuestLogCursor].command = 0; - sCurQuestLogEntry[sQuestLogCursor].localId = 0; - sCurQuestLogEntry[sQuestLogCursor].animId = movementActionId; - sLastQuestLogCursor = sQuestLogCursor; - sQuestLogCursor++; - sNextStepDelay = duration; + sCurSceneActions[gQuestLogCurActionIdx].duration = sNextActionDelay; + sCurSceneActions[gQuestLogCurActionIdx].type = QL_ACTION_MOVEMENT; + sCurSceneActions[gQuestLogCurActionIdx].data.a.localId = 0; + sCurSceneActions[gQuestLogCurActionIdx].data.a.movementActionId = movementActionId; + sLastQuestLogCursor = gQuestLogCurActionIdx; + gQuestLogCurActionIdx++; + sNextActionDelay = duration; } } -void QuestLogRecordPlayerAvatarGfxTransition(u8 movementActionId) +void QuestLogRecordPlayerAvatarGfxTransition(u8 gfxState) { if (!RecordHeadAtEndOfEntry()) { - sCurQuestLogEntry[sQuestLogCursor].duration = sNextStepDelay; - sCurQuestLogEntry[sQuestLogCursor].command = 1; - sCurQuestLogEntry[sQuestLogCursor].localId = 0; - sCurQuestLogEntry[sQuestLogCursor].animId = movementActionId; - sQuestLogCursor++; - sNextStepDelay = 0; + sCurSceneActions[gQuestLogCurActionIdx].duration = sNextActionDelay; + sCurSceneActions[gQuestLogCurActionIdx].type = QL_ACTION_GFX_CHANGE; + sCurSceneActions[gQuestLogCurActionIdx].data.b.localId = 0; + sCurSceneActions[gQuestLogCurActionIdx].data.b.gfxState = gfxState; + gQuestLogCurActionIdx++; + sNextActionDelay = 0; } } -void QuestLogRecordPlayerAvatarGfxTransitionWithDuration(u8 movementActionId, u8 duration) +void QuestLogRecordPlayerAvatarGfxTransitionWithDuration(u8 gfxState, u8 duration) { if (!RecordHeadAtEndOfEntry()) { - sCurQuestLogEntry[sQuestLogCursor].duration = sNextStepDelay; - sCurQuestLogEntry[sQuestLogCursor].command = 1; - sCurQuestLogEntry[sQuestLogCursor].localId = 0; - sCurQuestLogEntry[sQuestLogCursor].animId = movementActionId; - sQuestLogCursor++; - sNextStepDelay = duration; + sCurSceneActions[gQuestLogCurActionIdx].duration = sNextActionDelay; + sCurSceneActions[gQuestLogCurActionIdx].type = QL_ACTION_GFX_CHANGE; + sCurSceneActions[gQuestLogCurActionIdx].data.b.localId = 0; + sCurSceneActions[gQuestLogCurActionIdx].data.b.gfxState = gfxState; + gQuestLogCurActionIdx++; + sNextActionDelay = duration; } } -void sub_81127F8(struct FieldInput * a0) +void QL_RecordFieldInput(struct FieldInput * fieldInput) { - if (sQuestLogCursor < sNumEventsInLogEntry) + if (gQuestLogCurActionIdx < sMaxActionsInScene) { // Retain only the following fields: // - pressedAButton @@ -1409,18 +1464,18 @@ void sub_81127F8(struct FieldInput * a0) // - tookStep // - pressedBButton // - dpadDirection - u32 r2 = *(u32 *)a0 & 0x00FF00F3; - sCurQuestLogEntry[sQuestLogCursor].duration = sNextStepDelay; - sCurQuestLogEntry[sQuestLogCursor].command = 2; - sCurQuestLogEntry[sQuestLogCursor].localId = r2; - sCurQuestLogEntry[sQuestLogCursor].mapNum = r2 >> 8; // always 0 - sCurQuestLogEntry[sQuestLogCursor].mapGroup = r2 >> 16; - sCurQuestLogEntry[sQuestLogCursor].animId = r2 >> 24; // always 0 - sQuestLogCursor++; + u32 data = *(u32 *)fieldInput & 0x00FF00F3; + sCurSceneActions[gQuestLogCurActionIdx].duration = sNextActionDelay; + sCurSceneActions[gQuestLogCurActionIdx].type = QL_ACTION_INPUT; + sCurSceneActions[gQuestLogCurActionIdx].data.fieldInput[0] = data; + sCurSceneActions[gQuestLogCurActionIdx].data.fieldInput[1] = data >> 8; // always 0 + sCurSceneActions[gQuestLogCurActionIdx].data.fieldInput[2] = data >> 16; + sCurSceneActions[gQuestLogCurActionIdx].data.fieldInput[3] = data >> 24; // always 0 + gQuestLogCurActionIdx++; if (ArePlayerFieldControlsLocked()) - sNextStepDelay = TRUE; + sNextActionDelay = 1; else - sNextStepDelay = FALSE; + sNextActionDelay = 0; } } @@ -1429,228 +1484,239 @@ static void TogglePlaybackStateForOverworldLock(u8 a0) switch (a0) { case 1: - if (gQuestLogPlaybackState == 1) - gQuestLogPlaybackState = 3; // Message visible, overworld locked + if (gQuestLogPlaybackState == QL_PLAYBACK_STATE_RUNNING) + gQuestLogPlaybackState = QL_PLAYBACK_STATE_ACTION_END; // Message visible, overworld locked break; case 2: - if (gQuestLogPlaybackState == 3) - gQuestLogPlaybackState = 1; // Overworld unlocked + if (gQuestLogPlaybackState == QL_PLAYBACK_STATE_ACTION_END) + gQuestLogPlaybackState = QL_PLAYBACK_STATE_RUNNING; // Overworld unlocked break; } } void QuestLog_OnEscalatorWarp(u8 direction) { - u8 r1 = sub_8112CAC(); + u8 state = QL_GetPlaybackState(); switch (direction) { case QL_ESCALATOR_OUT: // warp out - if (r1 == 1) - gQuestLogPlaybackState = 3; - else if (r1 == 2) + if (state == QL_PLAYBACK_STATE_RUNNING) + gQuestLogPlaybackState = QL_PLAYBACK_STATE_ACTION_END; + else if (state == QL_PLAYBACK_STATE_RECORDING) { - sCurQuestLogEntry[sQuestLogCursor].duration = sNextStepDelay; - sCurQuestLogEntry[sQuestLogCursor].command = 3; - sQuestLogCursor++; - sNextStepDelay = 0; - gQuestLogPlaybackState = 4; + sCurSceneActions[gQuestLogCurActionIdx].duration = sNextActionDelay; + sCurSceneActions[gQuestLogCurActionIdx].type = QL_ACTION_EMPTY; + gQuestLogCurActionIdx++; + sNextActionDelay = 0; + gQuestLogPlaybackState = QL_PLAYBACK_STATE_RECORDING_NO_DELAY; } break; case QL_ESCALATOR_IN: // warp in - if (r1 == 1) - gQuestLogPlaybackState = 1; - else if (r1 == 2) - gQuestLogPlaybackState = 2; + if (state == QL_PLAYBACK_STATE_RUNNING) + gQuestLogPlaybackState = QL_PLAYBACK_STATE_RUNNING; + else if (state == QL_PLAYBACK_STATE_RECORDING) + gQuestLogPlaybackState = QL_PLAYBACK_STATE_RECORDING; break; } } -static void SetUpQuestLogEntry(u8 kind, struct QuestLogEntry *entry, u16 size) +static void ResetActions(u8 kind, struct QuestLogAction *actions, u16 size) { int i; switch (kind) { default: - gQuestLogPlaybackState = 0; + gQuestLogPlaybackState = QL_PLAYBACK_STATE_STOPPED; break; - case 1: - sCurQuestLogEntry = entry; - sNumEventsInLogEntry = size / sizeof(*sCurQuestLogEntry); - for (i = 0; i < (s32)NELEMS(sMovementScripts); i++) + case QL_PLAYBACK_STATE_RUNNING: + sCurSceneActions = actions; + sMaxActionsInScene = size / sizeof(*sCurSceneActions); + for (i = 0; i < (s32)ARRAY_COUNT(sMovementScripts); i++) { - sMovementScripts[i][0] |= 0xFF; - sMovementScripts[i][1] |= 0xFF; + sMovementScripts[i][0] |= MOVEMENT_ACTION_NONE; + sMovementScripts[i][1] |= QL_PLAYER_GFX_NONE; } - sQuestLogCursor = 0; + gQuestLogCurActionIdx = 0; sLastQuestLogCursor = 0; gQuestLogFieldInput = (struct FieldInput){}; - sNextStepDelay = sCurQuestLogEntry[sQuestLogCursor].duration; - sMovementScripts[0][0] = sCurQuestLogEntry[sQuestLogCursor].animId; - sMovementScripts[0][1] = 0xFF; - gQuestLogPlaybackState = 1; + sNextActionDelay = sCurSceneActions[gQuestLogCurActionIdx].duration; + sMovementScripts[0][0] = sCurSceneActions[gQuestLogCurActionIdx].data.a.movementActionId; + sMovementScripts[0][1] = QL_PLAYER_GFX_NONE; + gQuestLogPlaybackState = QL_PLAYBACK_STATE_RUNNING; break; - case 2: - sCurQuestLogEntry = entry; - sNumEventsInLogEntry = size / sizeof(*sCurQuestLogEntry); - for (i = 0; i < sNumEventsInLogEntry; i++) + case QL_PLAYBACK_STATE_RECORDING: + sCurSceneActions = actions; + sMaxActionsInScene = size / sizeof(*sCurSceneActions); + for (i = 0; i < sMaxActionsInScene; i++) { - sCurQuestLogEntry[i] = (struct QuestLogEntry){ 0, 0, 0, 0, 0xFFFF, 0xFF }; + sCurSceneActions[i] = (struct QuestLogAction){ + .duration = 0xFFFF, + .type = QL_ACTION_SCENE_END + }; } - sQuestLogCursor = 0; - sNextStepDelay = 0; - sCurQuestLogEntry[sQuestLogCursor].duration = 0; - sCurQuestLogEntry[sQuestLogCursor].command = 0; - sCurQuestLogEntry[sQuestLogCursor].localId = 0; + gQuestLogCurActionIdx = 0; + sNextActionDelay = 0; + sCurSceneActions[gQuestLogCurActionIdx].duration = 0; + sCurSceneActions[gQuestLogCurActionIdx].type = QL_ACTION_MOVEMENT; + sCurSceneActions[gQuestLogCurActionIdx].data.a.localId = 0; switch (GetPlayerFacingDirection()) { case DIR_NONE: case DIR_SOUTH: - sCurQuestLogEntry[sQuestLogCursor].animId = MOVEMENT_ACTION_FACE_DOWN; + sCurSceneActions[gQuestLogCurActionIdx].data.a.movementActionId = MOVEMENT_ACTION_FACE_DOWN; break; case DIR_EAST: - sCurQuestLogEntry[sQuestLogCursor].animId = MOVEMENT_ACTION_FACE_RIGHT; + sCurSceneActions[gQuestLogCurActionIdx].data.a.movementActionId = MOVEMENT_ACTION_FACE_RIGHT; break; case DIR_NORTH: - sCurQuestLogEntry[sQuestLogCursor].animId = MOVEMENT_ACTION_FACE_UP; + sCurSceneActions[gQuestLogCurActionIdx].data.a.movementActionId = MOVEMENT_ACTION_FACE_UP; break; case DIR_WEST: - sCurQuestLogEntry[sQuestLogCursor].animId = MOVEMENT_ACTION_FACE_LEFT; + sCurSceneActions[gQuestLogCurActionIdx].data.a.movementActionId = MOVEMENT_ACTION_FACE_LEFT; break; } sLastQuestLogCursor = 0; - sQuestLogCursor++; - sCurQuestLogEntry[sQuestLogCursor].duration = 0; - sCurQuestLogEntry[sQuestLogCursor].command = 2; - sCurQuestLogEntry[sQuestLogCursor].localId = 0; - sCurQuestLogEntry[sQuestLogCursor].mapNum = 0; - sCurQuestLogEntry[sQuestLogCursor].mapGroup = 0; - sCurQuestLogEntry[sQuestLogCursor].animId = 0; - sQuestLogCursor++; - gQuestLogPlaybackState = 2; + gQuestLogCurActionIdx++; + sCurSceneActions[gQuestLogCurActionIdx].duration = 0; + sCurSceneActions[gQuestLogCurActionIdx].type = QL_ACTION_INPUT; + sCurSceneActions[gQuestLogCurActionIdx].data.fieldInput[0] = 0; + sCurSceneActions[gQuestLogCurActionIdx].data.fieldInput[1] = 0; + sCurSceneActions[gQuestLogCurActionIdx].data.fieldInput[2] = 0; + sCurSceneActions[gQuestLogCurActionIdx].data.fieldInput[3] = 0; + gQuestLogCurActionIdx++; + gQuestLogPlaybackState = QL_PLAYBACK_STATE_RECORDING; break; } } -void sub_8112B3C(void) +void QL_TryRunActions(void) { switch (gQuestLogPlaybackState) { - case 0: + case QL_PLAYBACK_STATE_STOPPED: + case QL_PLAYBACK_STATE_ACTION_END: + case QL_PLAYBACK_STATE_RECORDING_NO_DELAY: break; - case 1: + case QL_PLAYBACK_STATE_RUNNING: if (!RecordHeadAtEndOfEntryOrScriptContext2Enabled()) { - if (sNextStepDelay != 0) - sNextStepDelay--; + if (sNextActionDelay != 0) + { + sNextActionDelay--; + } else { do { - switch (sCurQuestLogEntry[sQuestLogCursor].command) + switch (sCurSceneActions[gQuestLogCurActionIdx].type) { - case 0: + case QL_ACTION_MOVEMENT: // NPC movement action - sMovementScripts[sCurQuestLogEntry[sQuestLogCursor].localId][0] = sCurQuestLogEntry[sQuestLogCursor].animId; + sMovementScripts[sCurSceneActions[gQuestLogCurActionIdx].data.a.localId][0] = sCurSceneActions[gQuestLogCurActionIdx].data.a.movementActionId; break; - case 1: + case QL_ACTION_GFX_CHANGE: // State transition - sMovementScripts[sCurQuestLogEntry[sQuestLogCursor].localId][1] = sCurQuestLogEntry[sQuestLogCursor].animId; + sMovementScripts[sCurSceneActions[gQuestLogCurActionIdx].data.b.localId][1] = sCurSceneActions[gQuestLogCurActionIdx].data.b.gfxState; break; - case 2: - // Player input command - *(u32 *)&gQuestLogFieldInput = ((sCurQuestLogEntry[sQuestLogCursor].animId << 24) | (sCurQuestLogEntry[sQuestLogCursor].mapGroup << 16) | (sCurQuestLogEntry[sQuestLogCursor].mapNum << 8) | (sCurQuestLogEntry[sQuestLogCursor].localId << 0)); + case QL_ACTION_INPUT: + // Player input + *(u32 *)&gQuestLogFieldInput = ((sCurSceneActions[gQuestLogCurActionIdx].data.fieldInput[3] << 24) + | (sCurSceneActions[gQuestLogCurActionIdx].data.fieldInput[2] << 16) + | (sCurSceneActions[gQuestLogCurActionIdx].data.fieldInput[1] << 8) + | (sCurSceneActions[gQuestLogCurActionIdx].data.fieldInput[0] << 0)); break; - case 3: + case QL_ACTION_EMPTY: // End - gQuestLogPlaybackState = 3; + gQuestLogPlaybackState = QL_PLAYBACK_STATE_ACTION_END; break; - case 0xFE: + case QL_ACTION_WAIT: + // Nothing. The wait action uses sNextActionDelay to add a pause to playback. + // When the counter is finished and this is reached there's nothing else that needs to be done. break; - case 0xFF: - gQuestLogPlaybackState = 0; + case QL_ACTION_SCENE_END: + gQuestLogPlaybackState = QL_PLAYBACK_STATE_STOPPED; break; } - if (gQuestLogPlaybackState == 0) + + if (gQuestLogPlaybackState == QL_PLAYBACK_STATE_STOPPED) break; - if (++sQuestLogCursor >= sNumEventsInLogEntry) + if (++gQuestLogCurActionIdx >= sMaxActionsInScene) { - gQuestLogPlaybackState = 0; + gQuestLogPlaybackState = QL_PLAYBACK_STATE_STOPPED; break; } - sNextStepDelay = sCurQuestLogEntry[sQuestLogCursor].duration; - } while (gQuestLogPlaybackState != 3 - && (sNextStepDelay == 0 || sNextStepDelay == 0xFFFF)); + sNextActionDelay = sCurSceneActions[gQuestLogCurActionIdx].duration; + + } while (gQuestLogPlaybackState != QL_PLAYBACK_STATE_ACTION_END && (sNextActionDelay == 0 || sNextActionDelay == 0xFFFF)); } } - else if (sQuestLogCursor >= sNumEventsInLogEntry) + else if (gQuestLogCurActionIdx >= sMaxActionsInScene) { - gQuestLogPlaybackState = 0; + gQuestLogPlaybackState = QL_PLAYBACK_STATE_STOPPED; } break; - case 2: + case QL_PLAYBACK_STATE_RECORDING: if (ArePlayerFieldControlsLocked() != TRUE) { - sNextStepDelay++; - if (sQuestLogCursor >= sNumEventsInLogEntry) - gQuestLogPlaybackState = 0; + sNextActionDelay++; + if (gQuestLogCurActionIdx >= sMaxActionsInScene) + gQuestLogPlaybackState = QL_PLAYBACK_STATE_STOPPED; } break; - case 3: - break; - case 4: - break; } } void QL_AfterRecordFishActionSuccessful(void) { - sNextStepDelay++; + sNextActionDelay++; } -u8 sub_8112CAC(void) +u8 QL_GetPlaybackState(void) { switch (gQuestLogPlaybackState) { - case 0: + case QL_PLAYBACK_STATE_STOPPED: default: - return 0; - case 1: - case 3: - return 1; - case 2: - case 4: - return 2; + return QL_PLAYBACK_STATE_STOPPED; + + case QL_PLAYBACK_STATE_RUNNING: + case QL_PLAYBACK_STATE_ACTION_END: + return QL_PLAYBACK_STATE_RUNNING; + + case QL_PLAYBACK_STATE_RECORDING: + case QL_PLAYBACK_STATE_RECORDING_NO_DELAY: + return QL_PLAYBACK_STATE_RECORDING; } } static bool8 RecordHeadAtEndOfEntryOrScriptContext2Enabled(void) { - if (sQuestLogCursor >= sNumEventsInLogEntry || ArePlayerFieldControlsLocked() == TRUE) + if (gQuestLogCurActionIdx >= sMaxActionsInScene || ArePlayerFieldControlsLocked() == TRUE) return TRUE; return FALSE; } static bool8 RecordHeadAtEndOfEntry(void) { - if (sQuestLogCursor >= sNumEventsInLogEntry) + if (gQuestLogCurActionIdx >= sMaxActionsInScene) return TRUE; return FALSE; } static const struct FlagOrVarRecord sDummyFlagOrVarRecord = { - 0, - FALSE, - 0x7FFF + .idx = 0, + .isFlag = FALSE, + .value = 0x7FFF }; void *QuestLogGetFlagOrVarPtr(bool8 isFlag, u16 idx) { void *response; - if (sQuestLogCursor == 0) + if (gQuestLogCurActionIdx == 0) return NULL; - if (sQuestLogCursor >= sNumEventsInLogEntry) + if (gQuestLogCurActionIdx >= sMaxActionsInScene) return NULL; if (sFlagOrVarPlayhead >= sNumFlagsOrVars) return NULL; @@ -1666,9 +1732,9 @@ void *QuestLogGetFlagOrVarPtr(bool8 isFlag, u16 idx) void QuestLogSetFlagOrVar(bool8 isFlag, u16 idx, u16 value) { - if (sQuestLogCursor == 0) + if (gQuestLogCurActionIdx == 0) return; - if (sQuestLogCursor >= sNumEventsInLogEntry) + if (gQuestLogCurActionIdx >= sMaxActionsInScene) return; if (sFlagOrVarPlayhead >= sNumFlagsOrVars) return; @@ -1678,23 +1744,24 @@ void QuestLogSetFlagOrVar(bool8 isFlag, u16 idx, u16 value) sFlagOrVarPlayhead++; } -void sub_8112E3C(u8 state, struct FlagOrVarRecord * records, u16 size) +// Unused +static void QuestLogResetFlagsOrVars(u8 state, struct FlagOrVarRecord * records, u16 size) { s32 i; if (state == 0 || state > QL_STATE_PLAYBACK) - gQuestLogPlaybackState = 0; + { + gQuestLogPlaybackState = QL_PLAYBACK_STATE_STOPPED; + } else { sFlagOrVarRecords = records; - sNumFlagsOrVars = size >> 2; + sNumFlagsOrVars = size / 4; sFlagOrVarPlayhead = 0; if (state == QL_STATE_PLAYBACK) { - for (i = 0; i < sNumEventsInLogEntry; i++) - { + for (i = 0; i < sMaxActionsInScene; i++) sFlagOrVarRecords[i] = sDummyFlagOrVarRecord; - } } } } diff --git a/src/quest_log_battle.c b/src/quest_log_battle.c index 9f1d376a9..a06368a8c 100644 --- a/src/quest_log_battle.c +++ b/src/quest_log_battle.c @@ -7,30 +7,15 @@ #include "quest_log.h" #include "constants/trainers.h" -struct QuestLogStruct_TrainerBattleRecord -{ - u16 v0; - u16 v2; - u16 v4; - u8 v6; - u8 v7; -}; - -struct QuestLogStruct_WildBattleRecord -{ - u16 defeatedSpecies; - u16 caughtSpecies; - u8 mapSec; -}; - -static void sub_812C334(s32 *, s32 *); +static void GetLinkMultiBattlePlayerIndexes(s32 *, s32 *); void TrySetQuestLogBattleEvent(void) { if (!(gBattleTypeFlags & (BATTLE_TYPE_LINK | BATTLE_TYPE_OLD_MAN_TUTORIAL | BATTLE_TYPE_POKEDUDE)) && (gBattleOutcome == B_OUTCOME_WON || gBattleOutcome == B_OUTCOME_CAUGHT)) { - struct QuestLogStruct_TrainerBattleRecord * questLogTrainerBattleRecord = Alloc(sizeof(struct QuestLogStruct_TrainerBattleRecord)); - struct QuestLogStruct_WildBattleRecord * questLogWildBattleRecord = Alloc(sizeof(struct QuestLogStruct_WildBattleRecord)); + // Why allocate both of these? Only one will ever be used at a time + struct QuestLogEvent_TrainerBattle * trainerData = Alloc(sizeof(*trainerData)); + struct QuestLogEvent_WildBattle * wildData = Alloc(sizeof(*wildData)); u16 eventId; u16 playerEndingHP; u16 playerMaxHP; @@ -52,81 +37,81 @@ void TrySetQuestLogBattleEvent(void) eventId = QL_EVENT_DEFEATED_TRAINER; break; } - questLogTrainerBattleRecord->v0 = gTrainerBattleOpponent_A; + trainerData->trainerId = gTrainerBattleOpponent_A; if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE) { - questLogTrainerBattleRecord->v2 = gBattleResults.lastOpponentSpecies; - if (GetBattlerSide(gBattleStruct->field_182) == B_SIDE_PLAYER) - questLogTrainerBattleRecord->v4 = gBattleMons[gBattleStruct->field_182].species; + trainerData->speciesOpponent = gBattleResults.lastOpponentSpecies; + + // Decide which of the pokemon on the player's side to mention as the victor + if (GetBattlerSide(gBattleStruct->lastAttackerToFaintOpponent) == B_SIDE_PLAYER) + trainerData->speciesPlayer = gBattleMons[gBattleStruct->lastAttackerToFaintOpponent].species; else if (gBattleMons[GetBattlerAtPosition(0)].hp != 0) - questLogTrainerBattleRecord->v4 = gBattleMons[GetBattlerAtPosition(0)].species; + trainerData->speciesPlayer = gBattleMons[GetBattlerAtPosition(0)].species; else - questLogTrainerBattleRecord->v4 = gBattleMons[GetBattlerAtPosition(2)].species; + trainerData->speciesPlayer = gBattleMons[GetBattlerAtPosition(2)].species; + playerEndingHP = gBattleMons[GetBattlerAtPosition(0)].hp + gBattleMons[GetBattlerAtPosition(2)].hp; playerMaxHP = gBattleMons[GetBattlerAtPosition(0)].maxHP + gBattleMons[GetBattlerAtPosition(2)].maxHP; } else { - questLogTrainerBattleRecord->v2 = gBattleResults.lastOpponentSpecies; - questLogTrainerBattleRecord->v4 = gBattleMons[GetBattlerAtPosition(0)].species; + trainerData->speciesOpponent = gBattleResults.lastOpponentSpecies; + trainerData->speciesPlayer = gBattleMons[GetBattlerAtPosition(0)].species; playerEndingHP = gBattleMons[GetBattlerAtPosition(0)].hp; playerMaxHP = gBattleMons[GetBattlerAtPosition(0)].maxHP; } - questLogTrainerBattleRecord->v7 = GetCurrentRegionMapSectionId(); - questLogTrainerBattleRecord->v6 = 0; + trainerData->mapSec = GetCurrentRegionMapSectionId(); + + // Calculate fractional HP loss (determines flavor text, e.g. "handily" vs "somehow" defeated trainer) + trainerData->hpFractionId = 0; if (playerEndingHP < playerMaxHP / 3 * 2) - questLogTrainerBattleRecord->v6 = 1; + trainerData->hpFractionId++; if (playerEndingHP < playerMaxHP / 3) - questLogTrainerBattleRecord->v6++; - SetQuestLogEvent(eventId, (const u16 *)questLogTrainerBattleRecord); + trainerData->hpFractionId++; + + SetQuestLogEvent(eventId, (const u16 *)trainerData); } else { if (gBattleOutcome == B_OUTCOME_WON) { - questLogWildBattleRecord->defeatedSpecies = GetMonData(gEnemyParty, MON_DATA_SPECIES); - questLogWildBattleRecord->caughtSpecies = SPECIES_NONE; + wildData->defeatedSpecies = GetMonData(gEnemyParty, MON_DATA_SPECIES); + wildData->caughtSpecies = SPECIES_NONE; } else // gBattleOutcome == B_OUTCOME_CAUGHT { - questLogWildBattleRecord->defeatedSpecies = SPECIES_NONE; - questLogWildBattleRecord->caughtSpecies = GetMonData(gEnemyParty, MON_DATA_SPECIES); + wildData->defeatedSpecies = SPECIES_NONE; + wildData->caughtSpecies = GetMonData(gEnemyParty, MON_DATA_SPECIES); } - questLogWildBattleRecord->mapSec = GetCurrentRegionMapSectionId(); - SetQuestLogEvent(QL_EVENT_DEFEATED_WILD_MON, (const u16 *)questLogWildBattleRecord); + wildData->mapSec = GetCurrentRegionMapSectionId(); + SetQuestLogEvent(QL_EVENT_DEFEATED_WILD_MON, (const u16 *)wildData); } - Free(questLogTrainerBattleRecord); - Free(questLogWildBattleRecord); + Free(trainerData); + Free(wildData); } } -struct QuestLogStruct_LinkBattleRecord -{ - u8 v0; - u8 v1[3][7]; -}; - void TrySetQuestLogLinkBattleEvent(void) { - s32 sp0; - s32 sp4[2]; + s32 partnerIdx; + s32 opponentIdxs[2]; u16 eventId; - s32 r3; + s32 i; bool32 inUnionRoom; if (gBattleTypeFlags & BATTLE_TYPE_LINK) { - struct QuestLogStruct_LinkBattleRecord * r5 = Alloc(sizeof(struct QuestLogStruct_LinkBattleRecord)); - r5->v0 = gBattleOutcome - 1; // 0 = won, 1 = lost, 2 = drew + struct QuestLogEvent_LinkBattle * data = Alloc(sizeof(*data)); + data->outcome = gBattleOutcome - 1; // 0 = won, 1 = lost, 2 = drew if (gBattleTypeFlags & BATTLE_TYPE_MULTI) { eventId = QL_EVENT_LINK_BATTLED_MULTI; - sub_812C334(&sp0, sp4); - for (r3 = 0; r3 < 7; r3++) + GetLinkMultiBattlePlayerIndexes(&partnerIdx, opponentIdxs); + for (i = 0; i < PLAYER_NAME_LENGTH; i++) { - r5->v1[0][r3] = gLinkPlayers[sp0].name[r3]; - r5->v1[1][r3] = gLinkPlayers[sp4[0]].name[r3]; - r5->v1[2][r3] = gLinkPlayers[sp4[1]].name[r3]; + data->playerNames[0][i] = gLinkPlayers[partnerIdx].name[i]; + data->playerNames[1][i] = gLinkPlayers[opponentIdxs[0]].name[i]; + data->playerNames[2][i] = gLinkPlayers[opponentIdxs[1]].name[i]; } } else @@ -141,26 +126,25 @@ void TrySetQuestLogLinkBattleEvent(void) if (inUnionRoom == TRUE) eventId = QL_EVENT_LINK_BATTLED_UNION; } - for (r3 = 0; r3 < 7; r3++) - { - r5->v1[0][r3] = gLinkPlayers[gBattleStruct->multiplayerId ^ 1].name[r3]; - } + + for (i = 0; i < PLAYER_NAME_LENGTH; i++) + data->playerNames[0][i] = gLinkPlayers[gBattleStruct->multiplayerId ^ 1].name[i]; } - SetQuestLogEvent(eventId, (const u16 *)r5); - Free(r5); + SetQuestLogEvent(eventId, (const u16 *)data); + Free(data); } } -static void sub_812C334(s32 * a0, s32 * a1) +static void GetLinkMultiBattlePlayerIndexes(s32 * partnerIdx, s32 * opponentIdxs) { - s32 r5; - s32 _optimized_out = 0; - u8 r2 = gLinkPlayers[gBattleStruct->multiplayerId].id ^ 2; - for (r5 = 0; r5 < 4; r5++) + s32 i; + s32 numOpponentsFound = 0; + u8 partnerId = gLinkPlayers[gBattleStruct->multiplayerId].id ^ 2; + for (i = 0; i < MAX_BATTLERS_COUNT; i++) { - if (r2 == gLinkPlayers[r5].id) - a0[0] = r5; - else if (r5 != gBattleStruct->multiplayerId) - a1[_optimized_out++] = r5; + if (partnerId == gLinkPlayers[i].id) + *partnerIdx = i; + else if (i != gBattleStruct->multiplayerId) + opponentIdxs[numOpponentsFound++] = i; } } diff --git a/src/quest_log_events.c b/src/quest_log_events.c index 6bf109676..87abb45c5 100644 --- a/src/quest_log_events.c +++ b/src/quest_log_events.c @@ -18,239 +18,534 @@ #include "constants/items.h" #include "constants/region_map_sections.h" +enum { + STEP_RECORDING_MODE_ENABLED, + STEP_RECORDING_MODE_DISABLED, + STEP_RECORDING_MODE_DISABLED_UNTIL_DEPART, +}; + struct DeferredLinkEvent { u16 id; u16 ALIGNED(4) data[14]; }; +#define CMD_HEADER_SIZE 4 +#define MAX_CMD_REPEAT 4 + static EWRAM_DATA struct DeferredLinkEvent sDeferredEvent = {0}; -EWRAM_DATA struct UnkStruct_203B044 gUnknown_203B044 = {0}; -static EWRAM_DATA u8 sEventShouldNotRecordSteps = 0; +EWRAM_DATA struct QuestLogRepeatEventTracker gQuestLogRepeatEventTracker = {0}; +static EWRAM_DATA u8 sStepRecordingMode = 0; static EWRAM_DATA bool8 sNewlyEnteredMap = FALSE; -static EWRAM_DATA u8 sLastDepartedMap = 0; +static EWRAM_DATA u8 sLastDepartedLocation = 0; static EWRAM_DATA bool8 sPlayedTheSlots = FALSE; static bool8 InQuestLogDisabledLocation(void); static bool8 ShouldRegisterEvent_HandlePartyActions(u16, const u16 *); static bool8 ShouldRegisterEvent_HandleBeatStoryTrainer(u16, const u16 *); static u16 *ShouldRegisterEvent(u16, const u16 *); -static bool8 TrySetLinkQuestLogEvent(u16, const u16 *); -static bool8 TrySetTrainerBattleQuestLogEvent(u16, const u16 *); -static bool8 IsQuestLogEventWithSpecialEncounterSpecies(u16, const u16 *); -static void SetQuestLogEventToActive(u16); -static u16 *TryRecordEvent41(u16 *, u16); -static u16 *BufferQuestLogData_SwitchedPartyOrder(u16 *, const u16 *); -static u16 *BufferQuestLogData_UsedItem(u16 *, const u16 *); -static u16 *BufferQuestLogData_GaveHeldItemFromPartyMenu(u16 *, const u16 *); -static u16 *BufferQuestLogData_GaveHeldItemFromBagMenu(u16 *, const u16 *); -static u16 *BufferQuestLogData_GaveHeldItemFromPC(u16 *, const u16 *); -static u16 *BufferQuestLogData_TookHeldItem(u16 *, const u16 *); -static u16 *BufferQuestLogData_SwappedHeldItem(u16 *, const u16 *); -static u16 *BufferQuestLogData_SwappedHeldItemFromPC(u16 *, const u16 *); -static u16 *BufferQuestLogData_UsedPkmnCenter(u16 *, const u16 *); -static u16 *BufferQuestLogData_LinkTraded(u16 *, const u16 *); -static u16 *BufferQuestLogData_LinkBattledSingle(u16 *, const u16 *); -static u16 *BufferQuestLogData_LinkBattledDouble(u16 *, const u16 *); -static u16 *BufferQuestLogData_LinkBattledMulti(u16 *, const u16 *); -static u16 *BufferQuestLogData_UsedUnionRoom(u16 *, const u16 *); -static u16 *BufferQuestLogData_UsedUnionRoomChat(u16 *, const u16 *); -static u16 *BufferQuestLogData_LinkTradedUnionRoom(u16 *, const u16 *); -static u16 *BufferQuestLogData_LinkBattledUnionRoom(u16 *, const u16 *); -static u16 *BufferQuestLogData_SwitchedMonsBetweenBoxes(u16 *, const u16 *); -static u16 *BufferQuestLogData_SwitchedMonsWithinBox(u16 *, const u16 *); -static u16 *BufferQuestLogData_SwitchedPartyMonForPCMon(u16 *, const u16 *); -static u16 *BufferQuestLogData_MovedMonBetweenBoxes(u16 *, const u16 *); -static u16 *BufferQuestLogData_MovedMonWithinBox(u16 *, const u16 *); -static u16 *BufferQuestLogData_WithdrewMonFromPC(u16 *, const u16 *); -static u16 *BufferQuestLogData_DepositedMonInPC(u16 *, const u16 *); -static u16 *BufferQuestLogData_SwitchedMultipleMons(u16 *, const u16 *); -static u16 *BufferQuestLogData_DepositedItemInPC(u16 *, const u16 *); -static u16 *BufferQuestLogData_WithdrewItemFromPC(u16 *, const u16 *); -static u16 *BufferQuestLogData_DefeatedGymLeader(u16 *, const u16 *); -static u16 *BufferQuestLogData_DefeatedWildMon(u16 *, const u16 *); -static u16 *BufferQuestLogData_DefeatedEliteFourMember(u16 *, const u16 *); -static u16 *BufferQuestLogData_DefeatedChampion(u16 *, const u16 *); -static u16 *BufferQuestLogData_DefeatedTrainer(u16 *, const u16 *); -static u16 *BufferQuestLogData_DepartedLocation(u16 *, const u16 *); -static u16 *BufferQuestLogData_UsedFieldMove(u16 *, const u16 *); -static u16 *BufferQuestLogData_BoughtItem(u16 *, const u16 *); -static u16 *BufferQuestLogData_SoldItem(u16 *, const u16 *); -static u16 *BufferQuestLogData_ObtainedItem(u16 *, const u16 *); -static u16 *BufferQuestLogData_ArrivedInLocation(u16 *, const u16 *); -static const u16 *BufferQuestLogText_SwitchedPartyOrder(const u16 *); -static const u16 *BufferQuestLogText_UsedItem(const u16 *); -static const u16 *BufferQuestLogText_GaveHeldItemFromPartyMenu(const u16 *); -static const u16 *BufferQuestLogText_GaveHeldItemFromBagMenu(const u16 *); -static const u16 *BufferQuestLogText_GaveHeldItemFromPC(const u16 *); -static const u16 *BufferQuestLogText_TookHeldItem(const u16 *); -static const u16 *BufferQuestLogText_SwappedHeldItem(const u16 *); -static const u16 *BufferQuestLogText_SwappedHeldItemFromPC(const u16 *); -static const u16 *BufferQuestLogText_UsedPkmnCenter(const u16 *); -static const u16 *BufferQuestLogText_LinkTraded(const u16 *); -static const u16 *BufferQuestLogText_LinkBattledSingle(const u16 *); -static const u16 *BufferQuestLogText_LinkBattledDouble(const u16 *); -static const u16 *BufferQuestLogText_LinkBattledMulti(const u16 *); -static const u16 *BufferQuestLogText_UsedUnionRoom(const u16 *); -static const u16 *BufferQuestLogText_UsedUnionRoomChat(const u16 *); -static const u16 *BufferQuestLogText_LinkTradedUnionRoom(const u16 *); -static const u16 *BufferQuestLogText_LinkBattledUnionRoom(const u16 *); -static const u16 *BufferQuestLogText_SwitchedMonsBetweenBoxes(const u16 *); -static const u16 *BufferQuestLogText_SwitchedMonsWithinBox(const u16 *); -static const u16 *BufferQuestLogText_SwitchedPartyMonForPCMon(const u16 *); -static const u16 *BufferQuestLogText_MovedMonBetweenBoxes(const u16 *); -static const u16 *BufferQuestLogText_MovedMonWithinBox(const u16 *); -static const u16 *BufferQuestLogText_WithdrewMonFromPC(const u16 *); -static const u16 *BufferQuestLogText_DepositedMonInPC(const u16 *); -static const u16 *BufferQuestLogText_SwitchedMultipleMons(const u16 *); -static const u16 *BufferQuestLogText_DepositedItemInPC(const u16 *); -static const u16 *BufferQuestLogText_WithdrewItemFromPC(const u16 *); -static const u16 *BufferQuestLogText_DefeatedGymLeader(const u16 *); -static const u16 *BufferQuestLogText_DefeatedWildMon(const u16 *); -static const u16 *BufferQuestLogText_DefeatedEliteFourMember(const u16 *); -static const u16 *BufferQuestLogText_DefeatedChampion(const u16 *); -static const u16 *BufferQuestLogText_DefeatedTrainer(const u16 *); -static const u16 *BufferQuestLogText_DepartedLocation(const u16 *); -static const u16 *BufferQuestLogText_UsedFieldMove(const u16 *); -static const u16 *BufferQuestLogText_BoughtItem(const u16 *); -static const u16 *BufferQuestLogText_SoldItem(const u16 *); -static const u16 *BufferQuestLogText_ObtainedItem(const u16 *); -static const u16 *BufferQuestLogText_ArrivedInLocation(const u16 *); +static bool8 TryDeferLinkEvent(u16, const u16 *); +static bool8 TryDeferTrainerBattleEvent(u16, const u16 *); +static bool8 IsEventWithSpecialEncounterSpecies(u16, const u16 *); +static void UpdateRepeatEventCounter(u16); +static u16 *QL_RecordAction_Wait(u16 *, u16); +static u16 *RecordEvent_SwitchedPartyOrder(u16 *, const struct QuestLogEvent_SwitchedPartyOrder *); +static u16 *RecordEvent_UsedItem(u16 *, const struct QuestLogEvent_Item *); +static u16 *RecordEvent_GaveHeldItemFromPartyMenu(u16 *, const struct QuestLogEvent_Item *); +static u16 *RecordEvent_GaveHeldItemFromBagMenu(u16 *, const struct QuestLogEvent_Item *); +static u16 *RecordEvent_GaveHeldItemFromPC(u16 *, const struct QuestLogEvent_Item *); +static u16 *RecordEvent_TookHeldItem(u16 *, const struct QuestLogEvent_Item *); +static u16 *RecordEvent_SwappedHeldItemFromBag(u16 *, const struct QuestLogEvent_SwappedHeldItem *); +static u16 *RecordEvent_SwappedHeldItemFromPC(u16 *, const struct QuestLogEvent_SwappedHeldItem *); +static u16 *RecordEvent_UsedPkmnCenter(u16 *, const u16 *); +static u16 *RecordEvent_LinkTraded(u16 *, const struct QuestLogEvent_Traded *); +static u16 *RecordEvent_LinkBattledSingle(u16 *, const struct QuestLogEvent_LinkBattle *); +static u16 *RecordEvent_LinkBattledDouble(u16 *, const struct QuestLogEvent_LinkBattle *); +static u16 *RecordEvent_LinkBattledMulti(u16 *, const struct QuestLogEvent_LinkBattle *); +static u16 *RecordEvent_UsedUnionRoom(u16 *, const u16 *); +static u16 *RecordEvent_UsedUnionRoomChat(u16 *, const u16 *); +static u16 *RecordEvent_LinkTradedUnionRoom(u16 *, const struct QuestLogEvent_Traded *); +static u16 *RecordEvent_LinkBattledUnionRoom(u16 *, const struct QuestLogEvent_LinkBattle *); +static u16 *RecordEvent_SwitchedMonsBetweenBoxes(u16 *, const struct QuestLogEvent_MovedBoxMon *); +static u16 *RecordEvent_SwitchedMonsWithinBox(u16 *, const u16 *); +static u16 *RecordEvent_SwitchedPartyMonForPCMon(u16 *, const u16 *); +static u16 *RecordEvent_MovedMonBetweenBoxes(u16 *, const u16 *); +static u16 *RecordEvent_MovedMonWithinBox(u16 *, const u16 *); +static u16 *RecordEvent_WithdrewMonFromPC(u16 *, const u16 *); +static u16 *RecordEvent_DepositedMonInPC(u16 *, const u16 *); +static u16 *RecordEvent_SwitchedMultipleMons(u16 *, const u16 *); +static u16 *RecordEvent_DepositedItemInPC(u16 *, const struct QuestLogEvent_Item *); +static u16 *RecordEvent_WithdrewItemFromPC(u16 *, const struct QuestLogEvent_Item *); +static u16 *RecordEvent_DefeatedGymLeader(u16 *, const struct QuestLogEvent_TrainerBattle *); +static u16 *RecordEvent_DefeatedWildMon(u16 *, const struct QuestLogEvent_WildBattle *); +static u16 *RecordEvent_DefeatedEliteFourMember(u16 *, const struct QuestLogEvent_TrainerBattle *); +static u16 *RecordEvent_DefeatedChampion(u16 *, const struct QuestLogEvent_TrainerBattle *); +static u16 *RecordEvent_DefeatedNormalTrainer(u16 *, const struct QuestLogEvent_TrainerBattle *); +static u16 *RecordEvent_DepartedLocation(u16 *, const struct QuestLogEvent_Departed *); +static u16 *RecordEvent_UsedFieldMove(u16 *, const struct QuestLogEvent_FieldMove *); +static u16 *RecordEvent_BoughtItem(u16 *, const struct QuestLogEvent_Shop *); +static u16 *RecordEvent_SoldItem(u16 *, const struct QuestLogEvent_Shop *); +static u16 *RecordEvent_ObtainedStoryItem(u16 *, const struct QuestLogEvent_StoryItem *); +static u16 *RecordEvent_ArrivedInLocation(u16 *, const u16 *); +static const u16 *LoadEvent_SwitchedPartyOrder(const u16 *); +static const u16 *LoadEvent_UsedItem(const u16 *); +static const u16 *LoadEvent_GaveHeldItemFromPartyMenu(const u16 *); +static const u16 *LoadEvent_GaveHeldItemFromBagMenu(const u16 *); +static const u16 *LoadEvent_GaveHeldItemFromPC(const u16 *); +static const u16 *LoadEvent_TookHeldItem(const u16 *); +static const u16 *LoadEvent_SwappedHeldItem(const u16 *); +static const u16 *LoadEvent_SwappedHeldItemFromPC(const u16 *); +static const u16 *LoadEvent_UsedPkmnCenter(const u16 *); +static const u16 *LoadEvent_LinkTraded(const u16 *); +static const u16 *LoadEvent_LinkBattledSingle(const u16 *); +static const u16 *LoadEvent_LinkBattledDouble(const u16 *); +static const u16 *LoadEvent_LinkBattledMulti(const u16 *); +static const u16 *LoadEvent_UsedUnionRoom(const u16 *); +static const u16 *LoadEvent_UsedUnionRoomChat(const u16 *); +static const u16 *LoadEvent_LinkTradedUnionRoom(const u16 *); +static const u16 *LoadEvent_LinkBattledUnionRoom(const u16 *); +static const u16 *LoadEvent_SwitchedMonsBetweenBoxes(const u16 *); +static const u16 *LoadEvent_SwitchedMonsWithinBox(const u16 *); +static const u16 *LoadEvent_SwitchedPartyMonForPCMon(const u16 *); +static const u16 *LoadEvent_MovedMonBetweenBoxes(const u16 *); +static const u16 *LoadEvent_MovedMonWithinBox(const u16 *); +static const u16 *LoadEvent_WithdrewMonFromPC(const u16 *); +static const u16 *LoadEvent_DepositedMonInPC(const u16 *); +static const u16 *LoadEvent_SwitchedMultipleMons(const u16 *); +static const u16 *LoadEvent_DepositedItemInPC(const u16 *); +static const u16 *LoadEvent_WithdrewItemFromPC(const u16 *); +static const u16 *LoadEvent_DefeatedGymLeader(const u16 *); +static const u16 *LoadEvent_DefeatedWildMon(const u16 *); +static const u16 *LoadEvent_DefeatedEliteFourMember(const u16 *); +static const u16 *LoadEvent_DefeatedChampion(const u16 *); +static const u16 *LoadEvent_DefeatedTrainer(const u16 *); +static const u16 *LoadEvent_DepartedLocation(const u16 *); +static const u16 *LoadEvent_UsedFieldMove(const u16 *); +static const u16 *LoadEvent_BoughtItem(const u16 *); +static const u16 *LoadEvent_SoldItem(const u16 *); +static const u16 *LoadEvent_ObtainedStoryItem(const u16 *); +static const u16 *LoadEvent_ArrivedInLocation(const u16 *); static bool8 IsSpeciesFromSpecialEncounter(u16); static bool8 ShouldRegisterEvent_HandleDeparted(u16, const u16 *); -static bool8 ShouldRegisterEvent_HandleGameCorner(u16, const u16 *); -static void BufferLinkPartnersName(u8 *); +static bool8 ShouldRegisterEvent_DepartedGameCorner(u16, const u16 *); +static void TranslateLinkPartnersName(u8 *); -static u16 *(*const sQuestLogStorageCBs[])(u16 *, const u16 *) = { - [QL_EVENT_0] = NULL, - [QL_EVENT_1] = NULL, - [QL_EVENT_2] = NULL, - [QL_EVENT_SWITCHED_PARTY_ORDER] = BufferQuestLogData_SwitchedPartyOrder, - [QL_EVENT_USED_ITEM] = BufferQuestLogData_UsedItem, - [QL_EVENT_GAVE_HELD_ITEM] = BufferQuestLogData_GaveHeldItemFromPartyMenu, - [QL_EVENT_GAVE_HELD_ITEM_BAG] = BufferQuestLogData_GaveHeldItemFromBagMenu, - [QL_EVENT_GAVE_HELD_ITEM_PC] = BufferQuestLogData_GaveHeldItemFromPC, - [QL_EVENT_TOOK_HELD_ITEM] = BufferQuestLogData_TookHeldItem, - [QL_EVENT_SWAPPED_HELD_ITEM] = BufferQuestLogData_SwappedHeldItem, - [QL_EVENT_SWAPPED_HELD_ITEM_PC] = BufferQuestLogData_SwappedHeldItemFromPC, - [QL_EVENT_USED_PKMN_CENTER] = BufferQuestLogData_UsedPkmnCenter, - [QL_EVENT_LINK_TRADED] = BufferQuestLogData_LinkTraded, - [QL_EVENT_LINK_BATTLED_SINGLE] = BufferQuestLogData_LinkBattledSingle, - [QL_EVENT_LINK_BATTLED_DOUBLE] = BufferQuestLogData_LinkBattledDouble, - [QL_EVENT_LINK_BATTLED_MULTI] = BufferQuestLogData_LinkBattledMulti, - [QL_EVENT_USED_UNION_ROOM] = BufferQuestLogData_UsedUnionRoom, - [QL_EVENT_USED_UNION_ROOM_CHAT] = BufferQuestLogData_UsedUnionRoomChat, - [QL_EVENT_LINK_TRADED_UNION] = BufferQuestLogData_LinkTradedUnionRoom, - [QL_EVENT_LINK_BATTLED_UNION] = BufferQuestLogData_LinkBattledUnionRoom, - [QL_EVENT_SWITCHED_MONS_BETWEEN_BOXES] = BufferQuestLogData_SwitchedMonsBetweenBoxes, - [QL_EVENT_SWITCHED_MONS_WITHIN_BOX] = BufferQuestLogData_SwitchedMonsWithinBox, - [QL_EVENT_SWITCHED_PARTY_MON_FOR_PC_MON] = BufferQuestLogData_SwitchedPartyMonForPCMon, - [QL_EVENT_MOVED_MON_BETWEEN_BOXES] = BufferQuestLogData_MovedMonBetweenBoxes, - [QL_EVENT_MOVED_MON_WITHIN_BOX] = BufferQuestLogData_MovedMonWithinBox, - [QL_EVENT_WITHDREW_MON_PC] = BufferQuestLogData_WithdrewMonFromPC, - [QL_EVENT_DEPOSITED_MON_PC] = BufferQuestLogData_DepositedMonInPC, - [QL_EVENT_SWITCHED_MULTIPLE_MONS] = BufferQuestLogData_SwitchedMultipleMons, - [QL_EVENT_DEPOSITED_ITEM_PC] = BufferQuestLogData_DepositedItemInPC, - [QL_EVENT_WITHDREW_ITEM_PC] = BufferQuestLogData_WithdrewItemFromPC, - [QL_EVENT_DEFEATED_GYM_LEADER] = BufferQuestLogData_DefeatedGymLeader, - [QL_EVENT_DEFEATED_WILD_MON] = BufferQuestLogData_DefeatedWildMon, - [QL_EVENT_DEFEATED_E4_MEMBER] = BufferQuestLogData_DefeatedEliteFourMember, - [QL_EVENT_DEFEATED_CHAMPION] = BufferQuestLogData_DefeatedChampion, - [QL_EVENT_DEFEATED_TRAINER] = BufferQuestLogData_DefeatedTrainer, - [QL_EVENT_DEPARTED] = BufferQuestLogData_DepartedLocation, - [QL_EVENT_USED_FIELD_MOVE] = BufferQuestLogData_UsedFieldMove, - [QL_EVENT_BOUGHT_ITEM] = BufferQuestLogData_BoughtItem, - [QL_EVENT_SOLD_ITEM] = BufferQuestLogData_SoldItem, - [QL_EVENT_39] = NULL, - [QL_EVENT_OBTAINED_ITEM] = BufferQuestLogData_ObtainedItem, - [QL_EVENT_41] = NULL, - [QL_EVENT_ARRIVED] = BufferQuestLogData_ArrivedInLocation +typedef u16 *(*RecordEventFunc)(u16 *, const u16 *); + +static const RecordEventFunc sRecordEventFuncs[] = { + [QL_EVENT_INPUT] = NULL, + [QL_EVENT_GFX_CHANGE] = NULL, + [QL_EVENT_MOVEMENT] = NULL, + [QL_EVENT_SWITCHED_PARTY_ORDER] = (RecordEventFunc) RecordEvent_SwitchedPartyOrder, + [QL_EVENT_USED_ITEM] = (RecordEventFunc) RecordEvent_UsedItem, + [QL_EVENT_GAVE_HELD_ITEM] = (RecordEventFunc) RecordEvent_GaveHeldItemFromPartyMenu, + [QL_EVENT_GAVE_HELD_ITEM_BAG] = (RecordEventFunc) RecordEvent_GaveHeldItemFromBagMenu, + [QL_EVENT_GAVE_HELD_ITEM_PC] = (RecordEventFunc) RecordEvent_GaveHeldItemFromPC, + [QL_EVENT_TOOK_HELD_ITEM] = (RecordEventFunc) RecordEvent_TookHeldItem, + [QL_EVENT_SWAPPED_HELD_ITEM] = (RecordEventFunc) RecordEvent_SwappedHeldItemFromBag, + [QL_EVENT_SWAPPED_HELD_ITEM_PC] = (RecordEventFunc) RecordEvent_SwappedHeldItemFromPC, + [QL_EVENT_USED_PKMN_CENTER] = (RecordEventFunc) RecordEvent_UsedPkmnCenter, + [QL_EVENT_LINK_TRADED] = (RecordEventFunc) RecordEvent_LinkTraded, + [QL_EVENT_LINK_BATTLED_SINGLE] = (RecordEventFunc) RecordEvent_LinkBattledSingle, + [QL_EVENT_LINK_BATTLED_DOUBLE] = (RecordEventFunc) RecordEvent_LinkBattledDouble, + [QL_EVENT_LINK_BATTLED_MULTI] = (RecordEventFunc) RecordEvent_LinkBattledMulti, + [QL_EVENT_USED_UNION_ROOM] = (RecordEventFunc) RecordEvent_UsedUnionRoom, + [QL_EVENT_USED_UNION_ROOM_CHAT] = (RecordEventFunc) RecordEvent_UsedUnionRoomChat, + [QL_EVENT_LINK_TRADED_UNION] = (RecordEventFunc) RecordEvent_LinkTradedUnionRoom, + [QL_EVENT_LINK_BATTLED_UNION] = (RecordEventFunc) RecordEvent_LinkBattledUnionRoom, + [QL_EVENT_SWITCHED_MONS_BETWEEN_BOXES] = (RecordEventFunc) RecordEvent_SwitchedMonsBetweenBoxes, + [QL_EVENT_SWITCHED_MONS_WITHIN_BOX] = (RecordEventFunc) RecordEvent_SwitchedMonsWithinBox, + [QL_EVENT_SWITCHED_PARTY_MON_FOR_PC_MON] = (RecordEventFunc) RecordEvent_SwitchedPartyMonForPCMon, + [QL_EVENT_MOVED_MON_BETWEEN_BOXES] = (RecordEventFunc) RecordEvent_MovedMonBetweenBoxes, + [QL_EVENT_MOVED_MON_WITHIN_BOX] = (RecordEventFunc) RecordEvent_MovedMonWithinBox, + [QL_EVENT_WITHDREW_MON_PC] = (RecordEventFunc) RecordEvent_WithdrewMonFromPC, + [QL_EVENT_DEPOSITED_MON_PC] = (RecordEventFunc) RecordEvent_DepositedMonInPC, + [QL_EVENT_SWITCHED_MULTIPLE_MONS] = (RecordEventFunc) RecordEvent_SwitchedMultipleMons, + [QL_EVENT_DEPOSITED_ITEM_PC] = (RecordEventFunc) RecordEvent_DepositedItemInPC, + [QL_EVENT_WITHDREW_ITEM_PC] = (RecordEventFunc) RecordEvent_WithdrewItemFromPC, + [QL_EVENT_DEFEATED_GYM_LEADER] = (RecordEventFunc) RecordEvent_DefeatedGymLeader, + [QL_EVENT_DEFEATED_WILD_MON] = (RecordEventFunc) RecordEvent_DefeatedWildMon, + [QL_EVENT_DEFEATED_E4_MEMBER] = (RecordEventFunc) RecordEvent_DefeatedEliteFourMember, + [QL_EVENT_DEFEATED_CHAMPION] = (RecordEventFunc) RecordEvent_DefeatedChampion, + [QL_EVENT_DEFEATED_TRAINER] = (RecordEventFunc) RecordEvent_DefeatedNormalTrainer, + [QL_EVENT_DEPARTED] = (RecordEventFunc) RecordEvent_DepartedLocation, + [QL_EVENT_USED_FIELD_MOVE] = (RecordEventFunc) RecordEvent_UsedFieldMove, + [QL_EVENT_BOUGHT_ITEM] = (RecordEventFunc) RecordEvent_BoughtItem, + [QL_EVENT_SOLD_ITEM] = (RecordEventFunc) RecordEvent_SoldItem, + [QL_EVENT_SCENE_END] = NULL, + [QL_EVENT_OBTAINED_STORY_ITEM] = (RecordEventFunc) RecordEvent_ObtainedStoryItem, + [QL_EVENT_WAIT] = NULL, + [QL_EVENT_ARRIVED] = (RecordEventFunc) RecordEvent_ArrivedInLocation }; -void SetQuestLogEvent(u16 eventId, const u16 *eventData) +static const u16 *(*const sLoadEventFuncs[])(const u16 *) = { + [QL_EVENT_INPUT] = NULL, + [QL_EVENT_GFX_CHANGE] = NULL, + [QL_EVENT_MOVEMENT] = NULL, + [QL_EVENT_SWITCHED_PARTY_ORDER] = LoadEvent_SwitchedPartyOrder, + [QL_EVENT_USED_ITEM] = LoadEvent_UsedItem, + [QL_EVENT_GAVE_HELD_ITEM] = LoadEvent_GaveHeldItemFromPartyMenu, + [QL_EVENT_GAVE_HELD_ITEM_BAG] = LoadEvent_GaveHeldItemFromBagMenu, + [QL_EVENT_GAVE_HELD_ITEM_PC] = LoadEvent_GaveHeldItemFromPC, + [QL_EVENT_TOOK_HELD_ITEM] = LoadEvent_TookHeldItem, + [QL_EVENT_SWAPPED_HELD_ITEM] = LoadEvent_SwappedHeldItem, + [QL_EVENT_SWAPPED_HELD_ITEM_PC] = LoadEvent_SwappedHeldItemFromPC, + [QL_EVENT_USED_PKMN_CENTER] = LoadEvent_UsedPkmnCenter, + [QL_EVENT_LINK_TRADED] = LoadEvent_LinkTraded, + [QL_EVENT_LINK_BATTLED_SINGLE] = LoadEvent_LinkBattledSingle, + [QL_EVENT_LINK_BATTLED_DOUBLE] = LoadEvent_LinkBattledDouble, + [QL_EVENT_LINK_BATTLED_MULTI] = LoadEvent_LinkBattledMulti, + [QL_EVENT_USED_UNION_ROOM] = LoadEvent_UsedUnionRoom, + [QL_EVENT_USED_UNION_ROOM_CHAT] = LoadEvent_UsedUnionRoomChat, + [QL_EVENT_LINK_TRADED_UNION] = LoadEvent_LinkTradedUnionRoom, + [QL_EVENT_LINK_BATTLED_UNION] = LoadEvent_LinkBattledUnionRoom, + [QL_EVENT_SWITCHED_MONS_BETWEEN_BOXES] = LoadEvent_SwitchedMonsBetweenBoxes, + [QL_EVENT_SWITCHED_MONS_WITHIN_BOX] = LoadEvent_SwitchedMonsWithinBox, + [QL_EVENT_SWITCHED_PARTY_MON_FOR_PC_MON] = LoadEvent_SwitchedPartyMonForPCMon, + [QL_EVENT_MOVED_MON_BETWEEN_BOXES] = LoadEvent_MovedMonBetweenBoxes, + [QL_EVENT_MOVED_MON_WITHIN_BOX] = LoadEvent_MovedMonWithinBox, + [QL_EVENT_WITHDREW_MON_PC] = LoadEvent_WithdrewMonFromPC, + [QL_EVENT_DEPOSITED_MON_PC] = LoadEvent_DepositedMonInPC, + [QL_EVENT_SWITCHED_MULTIPLE_MONS] = LoadEvent_SwitchedMultipleMons, + [QL_EVENT_DEPOSITED_ITEM_PC] = LoadEvent_DepositedItemInPC, + [QL_EVENT_WITHDREW_ITEM_PC] = LoadEvent_WithdrewItemFromPC, + [QL_EVENT_DEFEATED_GYM_LEADER] = LoadEvent_DefeatedGymLeader, + [QL_EVENT_DEFEATED_WILD_MON] = LoadEvent_DefeatedWildMon, + [QL_EVENT_DEFEATED_E4_MEMBER] = LoadEvent_DefeatedEliteFourMember, + [QL_EVENT_DEFEATED_CHAMPION] = LoadEvent_DefeatedChampion, + [QL_EVENT_DEFEATED_TRAINER] = LoadEvent_DefeatedTrainer, + [QL_EVENT_DEPARTED] = LoadEvent_DepartedLocation, + [QL_EVENT_USED_FIELD_MOVE] = LoadEvent_UsedFieldMove, + [QL_EVENT_BOUGHT_ITEM] = LoadEvent_BoughtItem, + [QL_EVENT_SOLD_ITEM] = LoadEvent_SoldItem, + [QL_EVENT_SCENE_END] = NULL, + [QL_EVENT_OBTAINED_STORY_ITEM] = LoadEvent_ObtainedStoryItem, + [QL_EVENT_WAIT] = NULL, + [QL_EVENT_ARRIVED] = LoadEvent_ArrivedInLocation +}; + +static const u8 sQuestLogEventCmdSizes[] = { + [QL_EVENT_INPUT] = 8, + [QL_EVENT_GFX_CHANGE] = 8, + [QL_EVENT_MOVEMENT] = 8, + [QL_EVENT_SWITCHED_PARTY_ORDER] = CMD_HEADER_SIZE + 4, + [QL_EVENT_USED_ITEM] = CMD_HEADER_SIZE + 6, + [QL_EVENT_GAVE_HELD_ITEM] = CMD_HEADER_SIZE + 4, + [QL_EVENT_GAVE_HELD_ITEM_BAG] = CMD_HEADER_SIZE + 4, + [QL_EVENT_GAVE_HELD_ITEM_PC] = CMD_HEADER_SIZE + 4, + [QL_EVENT_TOOK_HELD_ITEM] = CMD_HEADER_SIZE + 4, + [QL_EVENT_SWAPPED_HELD_ITEM] = CMD_HEADER_SIZE + 6, + [QL_EVENT_SWAPPED_HELD_ITEM_PC] = CMD_HEADER_SIZE + 6, + [QL_EVENT_USED_PKMN_CENTER] = CMD_HEADER_SIZE + 0, + [QL_EVENT_LINK_TRADED] = CMD_HEADER_SIZE + 12, + [QL_EVENT_LINK_BATTLED_SINGLE] = CMD_HEADER_SIZE + 8, + [QL_EVENT_LINK_BATTLED_DOUBLE] = CMD_HEADER_SIZE + 8, + [QL_EVENT_LINK_BATTLED_MULTI] = CMD_HEADER_SIZE + 22, + [QL_EVENT_USED_UNION_ROOM] = CMD_HEADER_SIZE + 0, + [QL_EVENT_USED_UNION_ROOM_CHAT] = CMD_HEADER_SIZE + 0, + [QL_EVENT_LINK_TRADED_UNION] = CMD_HEADER_SIZE + 12, + [QL_EVENT_LINK_BATTLED_UNION] = CMD_HEADER_SIZE + 8, + [QL_EVENT_SWITCHED_MONS_BETWEEN_BOXES] = CMD_HEADER_SIZE + 6, + [QL_EVENT_SWITCHED_MONS_WITHIN_BOX] = CMD_HEADER_SIZE + 6, + [QL_EVENT_SWITCHED_PARTY_MON_FOR_PC_MON] = CMD_HEADER_SIZE + 6, + [QL_EVENT_MOVED_MON_BETWEEN_BOXES] = CMD_HEADER_SIZE + 4, + [QL_EVENT_MOVED_MON_WITHIN_BOX] = CMD_HEADER_SIZE + 4, + [QL_EVENT_WITHDREW_MON_PC] = CMD_HEADER_SIZE + 4, + [QL_EVENT_DEPOSITED_MON_PC] = CMD_HEADER_SIZE + 4, + [QL_EVENT_SWITCHED_MULTIPLE_MONS] = CMD_HEADER_SIZE + 2, + [QL_EVENT_DEPOSITED_ITEM_PC] = CMD_HEADER_SIZE + 2, + [QL_EVENT_WITHDREW_ITEM_PC] = CMD_HEADER_SIZE + 2, + [QL_EVENT_DEFEATED_GYM_LEADER] = CMD_HEADER_SIZE + 8, + [QL_EVENT_DEFEATED_WILD_MON] = CMD_HEADER_SIZE + 8, + [QL_EVENT_DEFEATED_E4_MEMBER] = CMD_HEADER_SIZE + 8, + [QL_EVENT_DEFEATED_CHAMPION] = CMD_HEADER_SIZE + 6, + [QL_EVENT_DEFEATED_TRAINER] = CMD_HEADER_SIZE + 8, + [QL_EVENT_DEPARTED] = CMD_HEADER_SIZE + 2, + [QL_EVENT_USED_FIELD_MOVE] = CMD_HEADER_SIZE + 4, + [QL_EVENT_BOUGHT_ITEM] = CMD_HEADER_SIZE + 10, + [QL_EVENT_SOLD_ITEM] = CMD_HEADER_SIZE + 10, + [QL_EVENT_SCENE_END] = 2, + [QL_EVENT_OBTAINED_STORY_ITEM] = CMD_HEADER_SIZE + 4, + [QL_EVENT_WAIT] = 4, + [QL_EVENT_ARRIVED] = CMD_HEADER_SIZE + 2 +}; + +static const u8 *const sDefeatedOpponentFlavorTexts[] = { + gText_QuestLog_Handily, + gText_QuestLog_Tenaciously, + gText_QuestLog_Somehow +}; + +static const u8 *const sDefeatedChampionFlavorTexts[] = { + gText_QuestLog_Coolly, + gText_QuestLog_Somehow, + gText_QuestLog_Barely +}; + +static const u8 *const sBattleOutcomeTexts[] = { + [B_OUTCOME_WON - 1] = gText_QuestLog_Win, + [B_OUTCOME_LOST - 1] = gText_QuestLog_Loss, + [B_OUTCOME_DREW - 1] = gText_QuestLog_Draw, +}; + +static const u8 *const sLocationNameTexts[] = +{ + [QL_LOCATION_HOME] = gText_QuestLog_Home, + [QL_LOCATION_OAKS_LAB] = gText_QuestLog_OakResearchLab, + [QL_LOCATION_VIRIDIAN_GYM] = gText_QuestLog_Gym, + [QL_LOCATION_LEAGUE_GATE_1] = gText_QuestLog_PokemonLeagueGate, + [QL_LOCATION_LEAGUE_GATE_2] = gText_QuestLog_PokemonLeagueGate, + [QL_LOCATION_VIRIDIAN_FOREST_1] = gText_QuestLog_ViridianForest, + [QL_LOCATION_VIRIDIAN_FOREST_2] = gText_QuestLog_ViridianForest, + [QL_LOCATION_PEWTER_MUSEUM] = gText_QuestLog_PewterMuseumOfScience, + [QL_LOCATION_PEWTER_GYM] = gText_QuestLog_Gym, + [QL_LOCATION_MT_MOON_1] = gText_QuestLog_MtMoon, + [QL_LOCATION_MT_MOON_2] = gText_QuestLog_MtMoon, + [QL_LOCATION_CERULEAN_GYM] = gText_QuestLog_Gym, + [QL_LOCATION_BIKE_SHOP] = gText_QuestLog_BikeShop, + [QL_LOCATION_BILLS_HOUSE] = gText_QuestLog_BillsHouse, + [QL_LOCATION_DAY_CARE] = gText_QuestLog_DayCare, + [QL_LOCATION_UNDERGROUND_PATH_1] = gText_QuestLog_UndergroundPath, + [QL_LOCATION_UNDERGROUND_PATH_2] = gText_QuestLog_UndergroundPath, + [QL_LOCATION_PKMN_FAN_CLUB] = gText_QuestLog_PokemonFanClub, + [QL_LOCATION_VERMILION_GYM] = gText_QuestLog_Gym, + [QL_LOCATION_SS_ANNE] = gText_QuestLog_SSAnne, + [QL_LOCATION_DIGLETTS_CAVE_1] = gText_QuestLog_DiglettsCave, + [QL_LOCATION_DIGLETTS_CAVE_2] = gText_QuestLog_DiglettsCave, + [QL_LOCATION_ROCK_TUNNEL_1] = gText_QuestLog_RockTunnel, + [QL_LOCATION_ROCK_TUNNEL_2] = gText_QuestLog_RockTunnel, + [QL_LOCATION_POWER_PLANT] = gText_QuestLog_PowerPlant, + [QL_LOCATION_PKMN_TOWER] = gText_QuestLog_PokemonTower, + [QL_LOCATION_VOLUNTEER_HOUSE] = gText_QuestLog_VolunteerHouse, + [QL_LOCATION_NAME_RATERS_HOUSE] = gText_QuestLog_NameRatersHouse, + [QL_LOCATION_UNDERGROUND_PATH_3] = gText_QuestLog_UndergroundPath, + [QL_LOCATION_UNDERGROUND_PATH_4] = gText_QuestLog_UndergroundPath, + [QL_LOCATION_CELADON_DEPT_STORE] = gText_QuestLog_CeladonDeptStore, + [QL_LOCATION_CELADON_MANSION] = gText_QuestLog_CeladonMansion, + [QL_LOCATION_GAME_CORNER] = gText_QuestLog_RocketGameCorner, + [QL_LOCATION_CELADON_GYM] = gText_QuestLog_Gym, + [QL_LOCATION_CELADON_RESTAURANT] = gText_QuestLog_Restaurant, + [QL_LOCATION_ROCKET_HIDEOUT] = gText_QuestLog_RocketHideout, + [QL_LOCATION_SAFARI_ZONE] = gText_QuestLog_SafariZone, + [QL_LOCATION_FUCHSIA_GYM] = gText_QuestLog_Gym, + [QL_LOCATION_WARDENS_HOME] = gText_QuestLog_WardensHome, + [QL_LOCATION_FIGHTING_DOJO] = gText_QuestLog_FightingDojo, + [QL_LOCATION_SAFFRON_GYM] = gText_QuestLog_Gym, + [QL_LOCATION_SILPH_CO] = gText_QuestLog_SilphCo, + [QL_LOCATION_SEAFOAM_ISLANDS_1] = gText_QuestLog_SeafoamIslands, + [QL_LOCATION_SEAFOAM_ISLANDS_2] = gText_QuestLog_SeafoamIslands, + [QL_LOCATION_PKMN_MANSION] = gText_QuestLog_PokemonMansion, + [QL_LOCATION_CINNABAR_GYM] = gText_QuestLog_Gym, + [QL_LOCATION_CINNABAR_LAB] = gText_QuestLog_PokemonResearchLab, + [QL_LOCATION_VICTORY_ROAD_1] = gText_QuestLog_VictoryRoad, + [QL_LOCATION_VICTORY_ROAD_2] = gText_QuestLog_VictoryRoad, + [QL_LOCATION_PKMN_LEAGUE] = gText_QuestLog_PokemonLeague, + [QL_LOCATION_CERULEAN_CAVE] = gText_QuestLog_CeruleanCave +}; + +static const u8 *const sDepartedLocationTexts[] = +{ + [QL_DEPARTED_TOWN_BUILDING] = gText_QuestLog_DepartedPlaceInTownForNextDestination, + [QL_DEPARTED_MUSEUM] = gText_QuestLog_LeftTownsLocationForNextDestination, + [QL_DEPARTED_GAME_CORNER] = gText_QuestLog_PlayedGamesAtGameCorner, + [QL_DEPARTED_HOME] = gText_QuestLog_RestedAtHome, + [QL_DEPARTED_OAKS_LAB] = gText_QuestLog_LeftOaksLab, + [QL_DEPARTED_GYM] = gText_QuestLog_GymWasFullOfToughTrainers, + [QL_DEPARTED_SAFARI_ZONE] = gText_QuestLog_HadGreatTimeInSafariZone, + [QL_DEPARTED_CAVE] = gText_QuestLog_ManagedToGetOutOfLocation, + [QL_DEPARTED_MISC_BUILDING_1] = gText_QuestLog_DepartedTheLocationForNextDestination, + [QL_DEPARTED_MISC_BUILDING_2] = gText_QuestLog_DepartedFromLocationToNextDestination +}; + +static const u8 sLocationToDepartedTextId[] = +{ + [QL_LOCATION_HOME] = QL_DEPARTED_HOME, + [QL_LOCATION_OAKS_LAB] = QL_DEPARTED_OAKS_LAB, + [QL_LOCATION_VIRIDIAN_GYM] = QL_DEPARTED_GYM, + [QL_LOCATION_LEAGUE_GATE_1] = QL_DEPARTED_MISC_BUILDING_1, + [QL_LOCATION_LEAGUE_GATE_2] = QL_DEPARTED_MISC_BUILDING_1, + [QL_LOCATION_VIRIDIAN_FOREST_1] = QL_DEPARTED_CAVE, + [QL_LOCATION_VIRIDIAN_FOREST_2] = QL_DEPARTED_CAVE, + [QL_LOCATION_PEWTER_MUSEUM] = QL_DEPARTED_MUSEUM, + [QL_LOCATION_PEWTER_GYM] = QL_DEPARTED_GYM, + [QL_LOCATION_MT_MOON_1] = QL_DEPARTED_CAVE, + [QL_LOCATION_MT_MOON_2] = QL_DEPARTED_CAVE, + [QL_LOCATION_CERULEAN_GYM] = QL_DEPARTED_GYM, + [QL_LOCATION_BIKE_SHOP] = QL_DEPARTED_TOWN_BUILDING, + [QL_LOCATION_BILLS_HOUSE] = QL_DEPARTED_TOWN_BUILDING, + [QL_LOCATION_DAY_CARE] = QL_DEPARTED_TOWN_BUILDING, + [QL_LOCATION_UNDERGROUND_PATH_1] = QL_DEPARTED_MISC_BUILDING_1, + [QL_LOCATION_UNDERGROUND_PATH_2] = QL_DEPARTED_MISC_BUILDING_1, + [QL_LOCATION_PKMN_FAN_CLUB] = QL_DEPARTED_TOWN_BUILDING, + [QL_LOCATION_VERMILION_GYM] = QL_DEPARTED_GYM, + [QL_LOCATION_SS_ANNE] = QL_DEPARTED_MISC_BUILDING_1, + [QL_LOCATION_DIGLETTS_CAVE_1] = QL_DEPARTED_CAVE, + [QL_LOCATION_DIGLETTS_CAVE_2] = QL_DEPARTED_CAVE, + [QL_LOCATION_ROCK_TUNNEL_1] = QL_DEPARTED_CAVE, + [QL_LOCATION_ROCK_TUNNEL_2] = QL_DEPARTED_CAVE, + [QL_LOCATION_POWER_PLANT] = QL_DEPARTED_MISC_BUILDING_1, + [QL_LOCATION_PKMN_TOWER] = QL_DEPARTED_MISC_BUILDING_1, + [QL_LOCATION_VOLUNTEER_HOUSE] = QL_DEPARTED_TOWN_BUILDING, + [QL_LOCATION_NAME_RATERS_HOUSE] = QL_DEPARTED_TOWN_BUILDING, + [QL_LOCATION_UNDERGROUND_PATH_3] = QL_DEPARTED_MISC_BUILDING_1, + [QL_LOCATION_UNDERGROUND_PATH_4] = QL_DEPARTED_MISC_BUILDING_1, + [QL_LOCATION_CELADON_DEPT_STORE] = QL_DEPARTED_TOWN_BUILDING, + [QL_LOCATION_CELADON_MANSION] = QL_DEPARTED_TOWN_BUILDING, + [QL_LOCATION_GAME_CORNER] = QL_DEPARTED_GAME_CORNER, + [QL_LOCATION_CELADON_GYM] = QL_DEPARTED_GYM, + [QL_LOCATION_CELADON_RESTAURANT] = QL_DEPARTED_TOWN_BUILDING, + [QL_LOCATION_ROCKET_HIDEOUT] = QL_DEPARTED_MISC_BUILDING_1, + [QL_LOCATION_SAFARI_ZONE] = QL_DEPARTED_SAFARI_ZONE, + [QL_LOCATION_FUCHSIA_GYM] = QL_DEPARTED_GYM, + [QL_LOCATION_WARDENS_HOME] = QL_DEPARTED_TOWN_BUILDING, + [QL_LOCATION_FIGHTING_DOJO] = QL_DEPARTED_TOWN_BUILDING, + [QL_LOCATION_SAFFRON_GYM] = QL_DEPARTED_GYM, + [QL_LOCATION_SILPH_CO] = QL_DEPARTED_MISC_BUILDING_2, + [QL_LOCATION_SEAFOAM_ISLANDS_1] = QL_DEPARTED_CAVE, + [QL_LOCATION_SEAFOAM_ISLANDS_2] = QL_DEPARTED_CAVE, + [QL_LOCATION_PKMN_MANSION] = QL_DEPARTED_MISC_BUILDING_2, + [QL_LOCATION_CINNABAR_GYM] = QL_DEPARTED_GYM, + [QL_LOCATION_CINNABAR_LAB] = QL_DEPARTED_TOWN_BUILDING, + [QL_LOCATION_VICTORY_ROAD_1] = QL_DEPARTED_CAVE, + [QL_LOCATION_VICTORY_ROAD_2] = QL_DEPARTED_CAVE, + [QL_LOCATION_PKMN_LEAGUE] = QL_DEPARTED_MISC_BUILDING_1, + [QL_LOCATION_CERULEAN_CAVE] = QL_DEPARTED_CAVE +}; + +static const u8 sGymCityMapSecs[NUM_BADGES] = { + MAPSEC_PEWTER_CITY, + MAPSEC_CERULEAN_CITY, + MAPSEC_VERMILION_CITY, + MAPSEC_CELADON_CITY, + MAPSEC_FUCHSIA_CITY, + MAPSEC_SAFFRON_CITY, + MAPSEC_CINNABAR_ISLAND, + MAPSEC_VIRIDIAN_CITY, +}; + +static const u8 *const sUsedFieldMoveTexts[] = +{ + [FIELD_MOVE_FLASH] = gText_QuestLog_UsedFlash, + [FIELD_MOVE_CUT] = gText_QuestLog_UsedCut, + [FIELD_MOVE_FLY] = gText_QuestLog_UsedFly, + [FIELD_MOVE_STRENGTH] = gText_QuestLog_UsedStrength, + [FIELD_MOVE_SURF] = gText_QuestLog_UsedSurf, + [FIELD_MOVE_ROCK_SMASH] = gText_QuestLog_UsedRockSmash, + [FIELD_MOVE_WATERFALL] = gText_QuestLog_UsedWaterfall, + [FIELD_MOVE_TELEPORT] = gText_QuestLog_UsedTeleportToLocation, + [FIELD_MOVE_DIG] = gText_QuestLog_UsedDigInLocation, + [FIELD_MOVE_MILK_DRINK] = gText_QuestLog_UsedMilkDrink, + [FIELD_MOVE_SOFT_BOILED] = gText_QuestLog_UsedSoftboiled, + [FIELD_MOVE_SWEET_SCENT] = gText_QuestLog_UsedSweetScent +}; + +static const u16 sWorldMapFlags[] = +{ + FLAG_WORLD_MAP_VIRIDIAN_CITY, + FLAG_WORLD_MAP_PEWTER_CITY, + FLAG_WORLD_MAP_CERULEAN_CITY, + FLAG_WORLD_MAP_LAVENDER_TOWN, + FLAG_WORLD_MAP_VERMILION_CITY, + FLAG_WORLD_MAP_CELADON_CITY, + FLAG_WORLD_MAP_FUCHSIA_CITY, + FLAG_WORLD_MAP_CINNABAR_ISLAND, + FLAG_WORLD_MAP_INDIGO_PLATEAU_EXTERIOR, + FLAG_WORLD_MAP_SAFFRON_CITY, + FLAG_WORLD_MAP_ONE_ISLAND, + FLAG_WORLD_MAP_TWO_ISLAND, + FLAG_WORLD_MAP_THREE_ISLAND, + FLAG_WORLD_MAP_FOUR_ISLAND, + FLAG_WORLD_MAP_FIVE_ISLAND, + FLAG_WORLD_MAP_SEVEN_ISLAND, + FLAG_WORLD_MAP_SIX_ISLAND +}; + +void SetQuestLogEvent(u16 eventId, const u16 * data) { u16 *r1; - if (eventId == QL_EVENT_DEPARTED && sEventShouldNotRecordSteps == 2) + if (eventId == QL_EVENT_DEPARTED && sStepRecordingMode == STEP_RECORDING_MODE_DISABLED_UNTIL_DEPART) { QL_EnableRecordingSteps(); return; } QL_EnableRecordingSteps(); + if (gQuestLogState == QL_STATE_PLAYBACK) return; if (!IS_VALID_QL_EVENT(eventId)) return; + // Certain locations like Trainer Tower do not allow Quest Log events to be recorded if (InQuestLogDisabledLocation() == TRUE) return; - if (TrySetLinkQuestLogEvent(eventId, eventData) == TRUE) + if (TryDeferLinkEvent(eventId, data) == TRUE) return; - if (MenuHelpers_IsLinkActive() == TRUE) + // Link events handled above. If we're in an active link, don't record any other events. + if (MenuHelpers_IsLinkActive() == TRUE || InUnionRoom() == TRUE) return; - if (InUnionRoom() == TRUE) + if (TryDeferTrainerBattleEvent(eventId, data) == TRUE) return; - if (TrySetTrainerBattleQuestLogEvent(eventId, eventData) == TRUE) + // Wild battles with static encounter species (Snorlax, Mewtwo, etc.) are not recorded. + if (IsEventWithSpecialEncounterSpecies(eventId, data) == TRUE) return; - if (IsQuestLogEventWithSpecialEncounterSpecies(eventId, eventData) == TRUE) + // If player departed Game Corner without using the slots, don't record it + if (ShouldRegisterEvent_DepartedGameCorner(eventId, data) == FALSE) return; - if (ShouldRegisterEvent_HandleGameCorner(eventId, eventData) == FALSE) - return; - - if (gQuestLogPlaybackState == 0) + if (gQuestLogPlaybackState == QL_PLAYBACK_STATE_STOPPED) { - if (ShouldRegisterEvent_HandlePartyActions(eventId, eventData) == TRUE) + if (ShouldRegisterEvent_HandlePartyActions(eventId, data) == TRUE) return; - if (eventId != QL_EVENT_DEFEATED_WILD_MON || gUnknown_203AE04 == NULL) + if (eventId != QL_EVENT_DEFEATED_WILD_MON || gQuestLogDefeatedWildMonRecord == NULL) { - if (ShouldRegisterEvent_HandleDeparted(eventId, eventData) == FALSE) + if (ShouldRegisterEvent_HandleDeparted(eventId, data) == FALSE) return; - StartRecordingQuestLogEntry(eventId); + QL_StartRecordingAction(eventId); } } - else if (eventId == QL_EVENT_OBTAINED_ITEM) + else if (eventId == QL_EVENT_OBTAINED_STORY_ITEM) return; - SetQuestLogEventToActive(eventId); + UpdateRepeatEventCounter(eventId); if (eventId == QL_EVENT_DEFEATED_WILD_MON) { - if (gUnknown_203AE04 == NULL) + if (gQuestLogDefeatedWildMonRecord == NULL) { - gUnknown_203AE04 = sEventRecordingPointer; - r1 = sQuestLogStorageCBs[eventId](gUnknown_203AE04, eventData); + gQuestLogDefeatedWildMonRecord = gQuestLogRecordingPointer; + r1 = sRecordEventFuncs[eventId](gQuestLogDefeatedWildMonRecord, data); } else { - sQuestLogStorageCBs[eventId](gUnknown_203AE04, eventData); + sRecordEventFuncs[eventId](gQuestLogDefeatedWildMonRecord, data); return; } } else { - gUnknown_203AE04 = NULL; - r1 = sQuestLogStorageCBs[eventId](sEventRecordingPointer, eventData); + gQuestLogDefeatedWildMonRecord = NULL; + r1 = sRecordEventFuncs[eventId](gQuestLogRecordingPointer, data); } if (r1 == NULL) { - FinishRecordingQuestLogScene(); - r1 = ShouldRegisterEvent(eventId, eventData); - if (r1 == NULL) + QL_FinishRecordingScene(); + r1 = ShouldRegisterEvent(eventId, data); + if (!r1) return; } - sEventRecordingPointer = r1; - if (sEventShouldNotRecordSteps == 0) + gQuestLogRecordingPointer = r1; + if (sStepRecordingMode == STEP_RECORDING_MODE_ENABLED) return; - FinishRecordingQuestLogScene(); + QL_FinishRecordingScene(); } static bool8 InQuestLogDisabledLocation(void) @@ -258,33 +553,34 @@ static bool8 InQuestLogDisabledLocation(void) // In Trainer Tower if (gSaveBlock1Ptr->location.mapGroup == MAP_GROUP(TRAINER_TOWER_1F) && (gSaveBlock1Ptr->location.mapNum == MAP_NUM(TRAINER_TOWER_1F) - || gSaveBlock1Ptr->location.mapNum == MAP_NUM(TRAINER_TOWER_2F) - || gSaveBlock1Ptr->location.mapNum == MAP_NUM(TRAINER_TOWER_3F) - || gSaveBlock1Ptr->location.mapNum == MAP_NUM(TRAINER_TOWER_4F) - || gSaveBlock1Ptr->location.mapNum == MAP_NUM(TRAINER_TOWER_5F) - || gSaveBlock1Ptr->location.mapNum == MAP_NUM(TRAINER_TOWER_6F) - || gSaveBlock1Ptr->location.mapNum == MAP_NUM(TRAINER_TOWER_7F) - || gSaveBlock1Ptr->location.mapNum == MAP_NUM(TRAINER_TOWER_8F) - || gSaveBlock1Ptr->location.mapNum == MAP_NUM(TRAINER_TOWER_ROOF) - || gSaveBlock1Ptr->location.mapNum == MAP_NUM(TRAINER_TOWER_LOBBY) - || gSaveBlock1Ptr->location.mapNum == MAP_NUM(TRAINER_TOWER_ELEVATOR))) + || gSaveBlock1Ptr->location.mapNum == MAP_NUM(TRAINER_TOWER_2F) + || gSaveBlock1Ptr->location.mapNum == MAP_NUM(TRAINER_TOWER_3F) + || gSaveBlock1Ptr->location.mapNum == MAP_NUM(TRAINER_TOWER_4F) + || gSaveBlock1Ptr->location.mapNum == MAP_NUM(TRAINER_TOWER_5F) + || gSaveBlock1Ptr->location.mapNum == MAP_NUM(TRAINER_TOWER_6F) + || gSaveBlock1Ptr->location.mapNum == MAP_NUM(TRAINER_TOWER_7F) + || gSaveBlock1Ptr->location.mapNum == MAP_NUM(TRAINER_TOWER_8F) + || gSaveBlock1Ptr->location.mapNum == MAP_NUM(TRAINER_TOWER_ROOF) + || gSaveBlock1Ptr->location.mapNum == MAP_NUM(TRAINER_TOWER_LOBBY) + || gSaveBlock1Ptr->location.mapNum == MAP_NUM(TRAINER_TOWER_ELEVATOR))) return TRUE; // In pokemon trainer fan club - if (gSaveBlock1Ptr->location.mapGroup == MAP_GROUP(SAFFRON_CITY_POKEMON_TRAINER_FAN_CLUB) && gSaveBlock1Ptr->location.mapNum == MAP_NUM(SAFFRON_CITY_POKEMON_TRAINER_FAN_CLUB)) + if (gSaveBlock1Ptr->location.mapGroup == MAP_GROUP(SAFFRON_CITY_POKEMON_TRAINER_FAN_CLUB) + && gSaveBlock1Ptr->location.mapNum == MAP_NUM(SAFFRON_CITY_POKEMON_TRAINER_FAN_CLUB)) return TRUE; // In E-Reader house if (gSaveBlock1Ptr->location.mapGroup == MAP_GROUP(SEVEN_ISLAND_HOUSE_ROOM1) && (gSaveBlock1Ptr->location.mapNum == MAP_NUM(SEVEN_ISLAND_HOUSE_ROOM1) - || gSaveBlock1Ptr->location.mapNum == MAP_NUM(SEVEN_ISLAND_HOUSE_ROOM2))) + || gSaveBlock1Ptr->location.mapNum == MAP_NUM(SEVEN_ISLAND_HOUSE_ROOM2))) return TRUE; // In elevator if ((gSaveBlock1Ptr->location.mapGroup == MAP_GROUP(ROCKET_HIDEOUT_ELEVATOR) && gSaveBlock1Ptr->location.mapNum == MAP_NUM(ROCKET_HIDEOUT_ELEVATOR)) - || (gSaveBlock1Ptr->location.mapGroup == MAP_GROUP(SILPH_CO_ELEVATOR) && gSaveBlock1Ptr->location.mapNum == MAP_NUM(SILPH_CO_ELEVATOR)) - || (gSaveBlock1Ptr->location.mapGroup == MAP_GROUP(TRAINER_TOWER_ELEVATOR) && gSaveBlock1Ptr->location.mapNum == MAP_NUM(TRAINER_TOWER_ELEVATOR)) - || (gSaveBlock1Ptr->location.mapGroup == MAP_GROUP(CELADON_CITY_DEPARTMENT_STORE_ELEVATOR) && gSaveBlock1Ptr->location.mapNum == MAP_NUM(CELADON_CITY_DEPARTMENT_STORE_ELEVATOR))) + || (gSaveBlock1Ptr->location.mapGroup == MAP_GROUP(SILPH_CO_ELEVATOR) && gSaveBlock1Ptr->location.mapNum == MAP_NUM(SILPH_CO_ELEVATOR)) + || (gSaveBlock1Ptr->location.mapGroup == MAP_GROUP(TRAINER_TOWER_ELEVATOR) && gSaveBlock1Ptr->location.mapNum == MAP_NUM(TRAINER_TOWER_ELEVATOR)) + || (gSaveBlock1Ptr->location.mapGroup == MAP_GROUP(CELADON_CITY_DEPARTMENT_STORE_ELEVATOR) && gSaveBlock1Ptr->location.mapNum == MAP_NUM(CELADON_CITY_DEPARTMENT_STORE_ELEVATOR))) return TRUE; return FALSE; @@ -304,40 +600,43 @@ bool8 QuestLog_ShouldEndSceneOnMapChange(void) return FALSE; } -static bool8 ShouldRegisterEvent_HandlePartyActions(u16 eventId, const u16 *eventData) +static bool8 ShouldRegisterEvent_HandlePartyActions(u16 eventId, const u16 * data) { if (eventId == QL_EVENT_USED_FIELD_MOVE || eventId == QL_EVENT_USED_PKMN_CENTER) return TRUE; if (!FlagGet(FLAG_SYS_GAME_CLEAR)) { - if (eventId == QL_EVENT_SWITCHED_PARTY_ORDER || eventId == QL_EVENT_DEFEATED_WILD_MON || ShouldRegisterEvent_HandleBeatStoryTrainer(eventId, eventData) == TRUE) + if (eventId == QL_EVENT_SWITCHED_PARTY_ORDER + || eventId == QL_EVENT_DEFEATED_WILD_MON + || ShouldRegisterEvent_HandleBeatStoryTrainer(eventId, data) == TRUE) return TRUE; } if (!FlagGet(FLAG_SYS_CAN_LINK_WITH_RS)) { if (eventId == QL_EVENT_USED_ITEM - || eventId == QL_EVENT_GAVE_HELD_ITEM - || eventId == QL_EVENT_GAVE_HELD_ITEM_BAG - || eventId == QL_EVENT_GAVE_HELD_ITEM_PC - || eventId == QL_EVENT_TOOK_HELD_ITEM - || eventId == QL_EVENT_SWAPPED_HELD_ITEM - || eventId == QL_EVENT_SWAPPED_HELD_ITEM_PC - || eventId == QL_EVENT_SWITCHED_PARTY_MON_FOR_PC_MON - || eventId == QL_EVENT_WITHDREW_MON_PC - || eventId == QL_EVENT_DEPOSITED_MON_PC) + || eventId == QL_EVENT_GAVE_HELD_ITEM + || eventId == QL_EVENT_GAVE_HELD_ITEM_BAG + || eventId == QL_EVENT_GAVE_HELD_ITEM_PC + || eventId == QL_EVENT_TOOK_HELD_ITEM + || eventId == QL_EVENT_SWAPPED_HELD_ITEM + || eventId == QL_EVENT_SWAPPED_HELD_ITEM_PC + || eventId == QL_EVENT_SWITCHED_PARTY_MON_FOR_PC_MON + || eventId == QL_EVENT_WITHDREW_MON_PC + || eventId == QL_EVENT_DEPOSITED_MON_PC) return TRUE; } return FALSE; } -static bool8 ShouldRegisterEvent_HandleBeatStoryTrainer(u16 eventId, const u16 *eventData) +static bool8 ShouldRegisterEvent_HandleBeatStoryTrainer(u16 eventId, const u16 * genericData) { if (eventId == QL_EVENT_DEFEATED_TRAINER) { - u8 trainerClass = gTrainers[*eventData].trainerClass; + const struct QuestLogEvent_TrainerBattle * data = (struct QuestLogEvent_TrainerBattle *)genericData; + u8 trainerClass = gTrainers[data->trainerId].trainerClass; if (trainerClass == TRAINER_CLASS_RIVAL_EARLY || trainerClass == TRAINER_CLASS_RIVAL_LATE || trainerClass == TRAINER_CLASS_CHAMPION @@ -350,29 +649,29 @@ static bool8 ShouldRegisterEvent_HandleBeatStoryTrainer(u16 eventId, const u16 * void QL_EnableRecordingSteps(void) { - sEventShouldNotRecordSteps = 0; + sStepRecordingMode = STEP_RECORDING_MODE_ENABLED; } -static u16 *ShouldRegisterEvent(u16 eventId, const u16 *eventData) +static u16 *ShouldRegisterEvent(u16 eventId, const u16 * data) { - if (ShouldRegisterEvent_HandlePartyActions(eventId, eventData) == TRUE) + if (ShouldRegisterEvent_HandlePartyActions(eventId, data) == TRUE) return NULL; - if (ShouldRegisterEvent_HandleDeparted(eventId, eventData) == FALSE) + if (ShouldRegisterEvent_HandleDeparted(eventId, data) == FALSE) return NULL; - StartRecordingQuestLogEntry(eventId); - SetQuestLogEventToActive(eventId); + QL_StartRecordingAction(eventId); + UpdateRepeatEventCounter(eventId); if (eventId == QL_EVENT_DEFEATED_WILD_MON) - gUnknown_203AE04 = sEventRecordingPointer; + gQuestLogDefeatedWildMonRecord = gQuestLogRecordingPointer; else - gUnknown_203AE04 = NULL; + gQuestLogDefeatedWildMonRecord = NULL; - return sQuestLogStorageCBs[eventId](sEventRecordingPointer, eventData); + return sRecordEventFuncs[eventId](gQuestLogRecordingPointer, data); } -static bool8 TrySetLinkQuestLogEvent(u16 eventId, const u16 *eventData) +static bool8 TryDeferLinkEvent(u16 eventId, const u16 * data) { if (!IS_LINK_QL_EVENT(eventId)) return FALSE; @@ -380,12 +679,13 @@ static bool8 TrySetLinkQuestLogEvent(u16 eventId, const u16 *eventData) ResetDeferredLinkEvent(); sDeferredEvent.id = eventId; + // These two events have no data, so no need to copy if (eventId != QL_EVENT_USED_UNION_ROOM && eventId != QL_EVENT_USED_UNION_ROOM_CHAT) { if (eventId == QL_EVENT_LINK_TRADED || eventId == QL_EVENT_LINK_TRADED_UNION) - memcpy(sDeferredEvent.data, eventData, 12); + memcpy(sDeferredEvent.data, data, sizeof(struct QuestLogEvent_Traded)); else - memcpy(sDeferredEvent.data, eventData, 24); + memcpy(sDeferredEvent.data, data, sizeof(struct QuestLogEvent_LinkBattle)); } return TRUE; } @@ -397,396 +697,317 @@ void ResetDeferredLinkEvent(void) void QuestLog_StartRecordingInputsAfterDeferredEvent(void) { - if (sDeferredEvent.id != QL_EVENT_0) + if (sDeferredEvent.id != 0) { u16 *resp; - sLastDepartedMap = 0; - StartRecordingQuestLogEntry(sDeferredEvent.id); - resp = sQuestLogStorageCBs[sDeferredEvent.id](sEventRecordingPointer, sDeferredEvent.data); - sEventRecordingPointer = resp; + sLastDepartedLocation = 0; + QL_StartRecordingAction(sDeferredEvent.id); + resp = sRecordEventFuncs[sDeferredEvent.id](gQuestLogRecordingPointer, sDeferredEvent.data); + gQuestLogRecordingPointer = resp; ResetDeferredLinkEvent(); } } -static bool8 TrySetTrainerBattleQuestLogEvent(u16 eventId, const u16 *eventData) +static bool8 TryDeferTrainerBattleEvent(u16 eventId, const u16 * data) { if (eventId != QL_EVENT_DEFEATED_TRAINER - && eventId != QL_EVENT_DEFEATED_GYM_LEADER - && eventId != QL_EVENT_DEFEATED_E4_MEMBER - && eventId != QL_EVENT_DEFEATED_CHAMPION) + && eventId != QL_EVENT_DEFEATED_GYM_LEADER + && eventId != QL_EVENT_DEFEATED_E4_MEMBER + && eventId != QL_EVENT_DEFEATED_CHAMPION) return FALSE; ResetDeferredLinkEvent(); - if (gQuestLogPlaybackState != 0 || FlagGet(FLAG_SYS_GAME_CLEAR) || ShouldRegisterEvent_HandleBeatStoryTrainer(eventId, eventData) != TRUE) + if (gQuestLogPlaybackState != QL_PLAYBACK_STATE_STOPPED || FlagGet(FLAG_SYS_GAME_CLEAR) || ShouldRegisterEvent_HandleBeatStoryTrainer(eventId, data) != TRUE) { sDeferredEvent.id = eventId; - memcpy(sDeferredEvent.data, eventData, 8); + memcpy(sDeferredEvent.data, data, sizeof(struct QuestLogEvent_TrainerBattle)); } return TRUE; } void QuestLogEvents_HandleEndTrainerBattle(void) { - if (sDeferredEvent.id != QL_EVENT_0) + if (sDeferredEvent.id != 0) { u16 *resp; - if (gQuestLogPlaybackState == 0) + if (gQuestLogPlaybackState == QL_PLAYBACK_STATE_STOPPED) { - sLastDepartedMap = 0; - StartRecordingQuestLogEntry(sDeferredEvent.id); + sLastDepartedLocation = 0; + QL_StartRecordingAction(sDeferredEvent.id); } - SetQuestLogEventToActive(sDeferredEvent.id); - resp = sQuestLogStorageCBs[sDeferredEvent.id](sEventRecordingPointer, sDeferredEvent.data); - sEventRecordingPointer = resp; - TryRecordEvent41_IncCursor(1); + UpdateRepeatEventCounter(sDeferredEvent.id); + resp = sRecordEventFuncs[sDeferredEvent.id](gQuestLogRecordingPointer, sDeferredEvent.data); + gQuestLogRecordingPointer = resp; + QL_RecordWait(1); ResetDeferredLinkEvent(); - FinishRecordingQuestLogScene(); + QL_FinishRecordingScene(); } } -void TryRecordEvent41_IncCursor(u16 a0) +void QL_RecordWait(u16 duration) { - sEventRecordingPointer = TryRecordEvent41(sEventRecordingPointer, a0); - sQuestLogCursor++; + gQuestLogRecordingPointer = QL_RecordAction_Wait(gQuestLogRecordingPointer, duration); + gQuestLogCurActionIdx++; } -static bool8 IsQuestLogEventWithSpecialEncounterSpecies(u16 eventId, const u16 *eventData) +static bool8 IsEventWithSpecialEncounterSpecies(u16 eventId, const u16 * genericData) { + const struct QuestLogEvent_WildBattle * data; + if (eventId != QL_EVENT_DEFEATED_WILD_MON) return FALSE; - if (IsSpeciesFromSpecialEncounter(eventData[0]) == TRUE) + data = (struct QuestLogEvent_WildBattle *)genericData; + + if (IsSpeciesFromSpecialEncounter(data->defeatedSpecies) == TRUE) return TRUE; - if (IsSpeciesFromSpecialEncounter(eventData[1]) == TRUE) + if (IsSpeciesFromSpecialEncounter(data->caughtSpecies) == TRUE) return TRUE; return FALSE; } -static const u16 *(*const sQuestLogEventTextBufferCBs[])(const u16 *) = { - [QL_EVENT_0] = NULL, - [QL_EVENT_1] = NULL, - [QL_EVENT_2] = NULL, - [QL_EVENT_SWITCHED_PARTY_ORDER] = BufferQuestLogText_SwitchedPartyOrder, - [QL_EVENT_USED_ITEM] = BufferQuestLogText_UsedItem, - [QL_EVENT_GAVE_HELD_ITEM] = BufferQuestLogText_GaveHeldItemFromPartyMenu, - [QL_EVENT_GAVE_HELD_ITEM_BAG] = BufferQuestLogText_GaveHeldItemFromBagMenu, - [QL_EVENT_GAVE_HELD_ITEM_PC] = BufferQuestLogText_GaveHeldItemFromPC, - [QL_EVENT_TOOK_HELD_ITEM] = BufferQuestLogText_TookHeldItem, - [QL_EVENT_SWAPPED_HELD_ITEM] = BufferQuestLogText_SwappedHeldItem, - [QL_EVENT_SWAPPED_HELD_ITEM_PC] = BufferQuestLogText_SwappedHeldItemFromPC, - [QL_EVENT_USED_PKMN_CENTER] = BufferQuestLogText_UsedPkmnCenter, - [QL_EVENT_LINK_TRADED] = BufferQuestLogText_LinkTraded, - [QL_EVENT_LINK_BATTLED_SINGLE] = BufferQuestLogText_LinkBattledSingle, - [QL_EVENT_LINK_BATTLED_DOUBLE] = BufferQuestLogText_LinkBattledDouble, - [QL_EVENT_LINK_BATTLED_MULTI] = BufferQuestLogText_LinkBattledMulti, - [QL_EVENT_USED_UNION_ROOM] = BufferQuestLogText_UsedUnionRoom, - [QL_EVENT_USED_UNION_ROOM_CHAT] = BufferQuestLogText_UsedUnionRoomChat, - [QL_EVENT_LINK_TRADED_UNION] = BufferQuestLogText_LinkTradedUnionRoom, - [QL_EVENT_LINK_BATTLED_UNION] = BufferQuestLogText_LinkBattledUnionRoom, - [QL_EVENT_SWITCHED_MONS_BETWEEN_BOXES] = BufferQuestLogText_SwitchedMonsBetweenBoxes, - [QL_EVENT_SWITCHED_MONS_WITHIN_BOX] = BufferQuestLogText_SwitchedMonsWithinBox, - [QL_EVENT_SWITCHED_PARTY_MON_FOR_PC_MON] = BufferQuestLogText_SwitchedPartyMonForPCMon, - [QL_EVENT_MOVED_MON_BETWEEN_BOXES] = BufferQuestLogText_MovedMonBetweenBoxes, - [QL_EVENT_MOVED_MON_WITHIN_BOX] = BufferQuestLogText_MovedMonWithinBox, - [QL_EVENT_WITHDREW_MON_PC] = BufferQuestLogText_WithdrewMonFromPC, - [QL_EVENT_DEPOSITED_MON_PC] = BufferQuestLogText_DepositedMonInPC, - [QL_EVENT_SWITCHED_MULTIPLE_MONS] = BufferQuestLogText_SwitchedMultipleMons, - [QL_EVENT_DEPOSITED_ITEM_PC] = BufferQuestLogText_DepositedItemInPC, - [QL_EVENT_WITHDREW_ITEM_PC] = BufferQuestLogText_WithdrewItemFromPC, - [QL_EVENT_DEFEATED_GYM_LEADER] = BufferQuestLogText_DefeatedGymLeader, - [QL_EVENT_DEFEATED_WILD_MON] = BufferQuestLogText_DefeatedWildMon, - [QL_EVENT_DEFEATED_E4_MEMBER] = BufferQuestLogText_DefeatedEliteFourMember, - [QL_EVENT_DEFEATED_CHAMPION] = BufferQuestLogText_DefeatedChampion, - [QL_EVENT_DEFEATED_TRAINER] = BufferQuestLogText_DefeatedTrainer, - [QL_EVENT_DEPARTED] = BufferQuestLogText_DepartedLocation, - [QL_EVENT_USED_FIELD_MOVE] = BufferQuestLogText_UsedFieldMove, - [QL_EVENT_BOUGHT_ITEM] = BufferQuestLogText_BoughtItem, - [QL_EVENT_SOLD_ITEM] = BufferQuestLogText_SoldItem, - [QL_EVENT_39] = NULL, - [QL_EVENT_OBTAINED_ITEM] = BufferQuestLogText_ObtainedItem, - [QL_EVENT_41] = NULL, - [QL_EVENT_ARRIVED] = BufferQuestLogText_ArrivedInLocation -}; - -static const u8 sQuestLogEventCmdSizes[] = { - [QL_EVENT_0] = 0x08, - [QL_EVENT_1] = 0x08, - [QL_EVENT_2] = 0x08, - [QL_EVENT_SWITCHED_PARTY_ORDER] = 0x08, - [QL_EVENT_USED_ITEM] = 0x0a, - [QL_EVENT_GAVE_HELD_ITEM] = 0x08, - [QL_EVENT_GAVE_HELD_ITEM_BAG] = 0x08, - [QL_EVENT_GAVE_HELD_ITEM_PC] = 0x08, - [QL_EVENT_TOOK_HELD_ITEM] = 0x08, - [QL_EVENT_SWAPPED_HELD_ITEM] = 0x0a, - [QL_EVENT_SWAPPED_HELD_ITEM_PC] = 0x0a, - [QL_EVENT_USED_PKMN_CENTER] = 0x04, - [QL_EVENT_LINK_TRADED] = 0x10, - [QL_EVENT_LINK_BATTLED_SINGLE] = 0x0c, - [QL_EVENT_LINK_BATTLED_DOUBLE] = 0x0c, - [QL_EVENT_LINK_BATTLED_MULTI] = 0x1a, - [QL_EVENT_USED_UNION_ROOM] = 0x04, - [QL_EVENT_USED_UNION_ROOM_CHAT] = 0x04, - [QL_EVENT_LINK_TRADED_UNION] = 0x10, - [QL_EVENT_LINK_BATTLED_UNION] = 0x0c, - [QL_EVENT_SWITCHED_MONS_BETWEEN_BOXES] = 0x0a, - [QL_EVENT_SWITCHED_MONS_WITHIN_BOX] = 0x0a, - [QL_EVENT_SWITCHED_PARTY_MON_FOR_PC_MON] = 0x0a, - [QL_EVENT_MOVED_MON_BETWEEN_BOXES] = 0x08, - [QL_EVENT_MOVED_MON_WITHIN_BOX] = 0x08, - [QL_EVENT_WITHDREW_MON_PC] = 0x08, - [QL_EVENT_DEPOSITED_MON_PC] = 0x08, - [QL_EVENT_SWITCHED_MULTIPLE_MONS] = 0x06, - [QL_EVENT_DEPOSITED_ITEM_PC] = 0x06, - [QL_EVENT_WITHDREW_ITEM_PC] = 0x06, - [QL_EVENT_DEFEATED_GYM_LEADER] = 0x0c, - [QL_EVENT_DEFEATED_WILD_MON] = 0x0c, - [QL_EVENT_DEFEATED_E4_MEMBER] = 0x0c, - [QL_EVENT_DEFEATED_CHAMPION] = 0x0a, - [QL_EVENT_DEFEATED_TRAINER] = 0x0c, - [QL_EVENT_DEPARTED] = 0x06, - [QL_EVENT_USED_FIELD_MOVE] = 0x08, - [QL_EVENT_BOUGHT_ITEM] = 0x0e, - [QL_EVENT_SOLD_ITEM] = 0x0e, - [QL_EVENT_39] = 0x02, - [QL_EVENT_OBTAINED_ITEM] = 0x08, - [QL_EVENT_41] = 0x04, - [QL_EVENT_ARRIVED] = 0x06 -}; - -u16 *QuestLog_SkipCommand(u16 *curPtr, u16 **prevPtr_p) +u16 *QL_SkipCommand(u16 *curPtr, u16 **prevPtr_p) { - u16 eventId = curPtr[0] & 0xfff; - u16 cnt = curPtr[0] >> 12; + u16 eventId = curPtr[0] & QL_CMD_EVENT_MASK; + u16 count = curPtr[0] >> QL_CMD_COUNT_SHIFT; if (eventId == QL_EVENT_DEFEATED_CHAMPION) - cnt = 0; + count = 0; if (!IS_VALID_QL_EVENT(eventId)) return NULL; *prevPtr_p = curPtr; - return sQuestLogEventCmdSizes[eventId] + (sQuestLogEventCmdSizes[eventId] - 4) * cnt + (void *)curPtr; + return sQuestLogEventCmdSizes[eventId] + (sQuestLogEventCmdSizes[eventId] - CMD_HEADER_SIZE) * count + (void *)curPtr; } -void sub_8113ABC(const u16 *a0) +void QL_UpdateLastDepartedLocation(const u16 *a0) { const u8 *r2 = (const u8 *)(a0 + 2); - if ((a0[0] & 0xFFF) != QL_EVENT_DEPARTED) - sLastDepartedMap = 0; + if ((a0[0] & QL_CMD_EVENT_MASK) != QL_EVENT_DEPARTED) + sLastDepartedLocation = 0; else - sLastDepartedMap = r2[1] + 1; + sLastDepartedLocation = r2[1] + 1; } -bool8 sub_8113AE8(const u16 *a0) +bool8 QL_LoadEvent(const u16 *eventData) { - const u16 *r0 = a0; + const u16 *r0 = eventData; - if (a0 == NULL) // checks must be separate to match + if (eventData == NULL) return FALSE; - if (r0[1] > sQuestLogCursor) + if (r0[1] > gQuestLogCurActionIdx) return FALSE; - sQuestLogEventTextBufferCBs[(r0[0] & 0xFFF)](a0); - gUnknown_203B044.id = r0[0]; - gUnknown_203B044.unk_1 = (r0[0] & 0xF000) >> 12; - if (gUnknown_203B044.unk_1 != 0) - gUnknown_203B044.unk_2 = 1; + sLoadEventFuncs[(r0[0] & QL_CMD_EVENT_MASK)](eventData); + gQuestLogRepeatEventTracker.id = r0[0]; + gQuestLogRepeatEventTracker.numRepeats = (r0[0] & QL_CMD_COUNT_MASK) >> QL_CMD_COUNT_SHIFT; + if (gQuestLogRepeatEventTracker.numRepeats != 0) + gQuestLogRepeatEventTracker.counter = 1; return TRUE; } -bool8 sub_8113B44(const u16 *a0) +bool8 QL_TryRepeatEvent(const u16 *eventData) { - if (gUnknown_203B044.unk_2 == 0) + // This is the first for a new event, do nothing. Counter may be changed later by QL_LoadEvent. + if (gQuestLogRepeatEventTracker.counter == 0) return FALSE; - sQuestLogEventTextBufferCBs[gUnknown_203B044.id](a0); - gUnknown_203B044.unk_2++; - if (gUnknown_203B044.unk_2 > gUnknown_203B044.unk_1) - ResetUnk203B044(); + // Repeat event + sLoadEventFuncs[gQuestLogRepeatEventTracker.id](eventData); + if (++gQuestLogRepeatEventTracker.counter > gQuestLogRepeatEventTracker.numRepeats) + QL_ResetRepeatEventTracker(); return TRUE; } -void ResetUnk203B044(void) +void QL_ResetRepeatEventTracker(void) { - gUnknown_203B044 = (struct UnkStruct_203B044){}; + gQuestLogRepeatEventTracker = (struct QuestLogRepeatEventTracker){}; } -static void SetQuestLogEventToActive(u16 eventId) +static void UpdateRepeatEventCounter(u16 eventId) { - if (gUnknown_203B044.id != (u8)eventId || gUnknown_203B044.unk_2 != sQuestLogCursor) + if (gQuestLogRepeatEventTracker.id != (u8)eventId || gQuestLogRepeatEventTracker.counter != gQuestLogCurActionIdx) { - gUnknown_203B044.id = eventId; - gUnknown_203B044.unk_1 = 0; - gUnknown_203B044.unk_2 = sQuestLogCursor; + gQuestLogRepeatEventTracker.id = eventId; + gQuestLogRepeatEventTracker.numRepeats = 0; + gQuestLogRepeatEventTracker.counter = gQuestLogCurActionIdx; + } + // Allow 1 over the max. It will be recorded temporarily, ultimately replacing the oldest record. + else if (gQuestLogRepeatEventTracker.numRepeats < MAX_CMD_REPEAT + 1) + { + gQuestLogRepeatEventTracker.numRepeats++; } - else if (gUnknown_203B044.unk_1 < 5) - gUnknown_203B044.unk_1++; } -void sub_8113BD8(void) +void QL_ResetEventStates(void) { sNewlyEnteredMap = FALSE; - sLastDepartedMap = 0; + sLastDepartedLocation = 0; sPlayedTheSlots = FALSE; } -u16 *TryRecordEvent39_NoParams(u16 *a0) +u16 *QL_RecordAction_SceneEnd(u16 *a0) { - if (!WillCommandOfSizeFitInSav1Record(a0, sQuestLogEventCmdSizes[QL_EVENT_39])) + if (!QL_IsRoomToSaveAction(a0, sQuestLogEventCmdSizes[QL_EVENT_SCENE_END])) return NULL; - a0[0] = QL_EVENT_39; + a0[0] = QL_EVENT_SCENE_END; return a0 + 1; } -u16 *sub_8113C20(u16 *a0, struct QuestLogEntry * a1) +u16 *QL_LoadAction_SceneEnd(u16 *a0, struct QuestLogAction * a1) { - if (!WillCommandOfSizeFitInSav1Record(a0, sQuestLogEventCmdSizes[QL_EVENT_39])) + if (!QL_IsRoomToSaveAction(a0, sQuestLogEventCmdSizes[QL_EVENT_SCENE_END])) return NULL; - a1->command = 0xFF; + a1->type = QL_ACTION_SCENE_END; a1->duration = 0; - a1->localId = 0; - a1->mapNum = 0; - a1->mapGroup = 0; - a1->animId = 0; + a1->data.raw[0] = 0; + a1->data.raw[1] = 0; + a1->data.raw[2] = 0; + a1->data.raw[3] = 0; return a0 + 1; } -static u16 *TryRecordEvent41(u16 *a0, u16 a1) +static u16 *QL_RecordAction_Wait(u16 *a0, u16 duration) { - if (!WillCommandOfSizeFitInSav1Record(a0, sQuestLogEventCmdSizes[QL_EVENT_41])) + if (!QL_IsRoomToSaveAction(a0, sQuestLogEventCmdSizes[QL_EVENT_WAIT])) return NULL; - a0[0] = QL_EVENT_41; - a0[1] = a1; + a0[0] = QL_EVENT_WAIT; + a0[1] = duration; return a0 + 2; } -u16 *sub_8113C8C(u16 *a0, struct QuestLogEntry * a1) +u16 *QL_LoadAction_Wait(u16 *a0, struct QuestLogAction * a1) { - if (!WillCommandOfSizeFitInSav1Record(a0, sQuestLogEventCmdSizes[QL_EVENT_41])) + if (!QL_IsRoomToSaveAction(a0, sQuestLogEventCmdSizes[QL_EVENT_WAIT])) return NULL; - a1->command = 0xFE; + a1->type = QL_ACTION_WAIT; a1->duration = a0[1]; - a1->localId = 0; - a1->mapNum = 0; - a1->mapGroup = 0; - a1->animId = 0; + a1->data.raw[0] = 0; + a1->data.raw[1] = 0; + a1->data.raw[2] = 0; + a1->data.raw[3] = 0; return a0 + 2; } -u16 *sub_8113CC8(u16 *a0, struct QuestLogEntry * a1) +u16 *QL_RecordAction_Input(u16 *script, struct QuestLogAction * a1) { - u8 *r6 = (u8 *)a0 + 4; + u8 *r6 = (u8 *)script + 4; - if (!WillCommandOfSizeFitInSav1Record(a0, sQuestLogEventCmdSizes[QL_EVENT_0])) + if (!QL_IsRoomToSaveAction(script, sQuestLogEventCmdSizes[QL_EVENT_INPUT])) return NULL; - a0[0] = 0; - a0[1] = a1->duration; - r6[0] = a1->localId; - r6[1] = a1->mapNum; - r6[2] = a1->mapGroup; - r6[3] = a1->animId; + script[0] = QL_EVENT_INPUT; + script[1] = a1->duration; + r6[0] = a1->data.raw[0]; + r6[1] = a1->data.raw[1]; + r6[2] = a1->data.raw[2]; + r6[3] = a1->data.raw[3]; return (u16 *)(r6 + 4); } -u16 *sub_8113D08(u16 *a0, struct QuestLogEntry * a1) +u16 *QL_LoadAction_Input(u16 *a0, struct QuestLogAction * a1) { u8 *r6 = (u8 *)a0 + 4; - if (!WillCommandOfSizeFitInSav1Record(a0, sQuestLogEventCmdSizes[QL_EVENT_0])) + if (!QL_IsRoomToSaveAction(a0, sQuestLogEventCmdSizes[QL_EVENT_INPUT])) return NULL; - a1->command = 2; + a1->type = QL_ACTION_INPUT; a1->duration = a0[1]; - a1->localId = r6[0]; - a1->mapNum = r6[1]; - a1->mapGroup = r6[2]; - a1->animId = r6[3]; + a1->data.raw[0] = r6[0]; + a1->data.raw[1] = r6[1]; + a1->data.raw[2] = r6[2]; + a1->data.raw[3] = r6[3]; return (u16 *)(r6 + 4); } -u16 *sub_8113D48(u16 *a0, struct QuestLogEntry * a1) +u16 *QL_RecordAction_MovementOrGfxChange(u16 *script, struct QuestLogAction * a1) { - u16 *r4 = a0; - u8 *r6 = (u8 *)a0 + 4; + u16 *r4 = script; + u8 *r6 = (u8 *)script + 4; - if (!WillCommandOfSizeFitInSav1Record(r4, sQuestLogEventCmdSizes[QL_EVENT_2])) + if (!QL_IsRoomToSaveAction(r4, sQuestLogEventCmdSizes[QL_EVENT_MOVEMENT])) return NULL; - if (a1->command == 0) - r4[0] = 2; + if (a1->type == QL_ACTION_MOVEMENT) + r4[0] = QL_EVENT_MOVEMENT; else - r4[0] = 1; + r4[0] = QL_EVENT_GFX_CHANGE; r4[1] = a1->duration; - r6[0] = a1->localId; - r6[1] = a1->mapNum; - r6[2] = a1->mapGroup; - r6[3] = a1->animId; + r6[0] = a1->data.raw[0]; + r6[1] = a1->data.raw[1]; + r6[2] = a1->data.raw[2]; + r6[3] = a1->data.raw[3]; return (u16 *)(r6 + 4); } -u16 *sub_8113D94(u16 *a0, struct QuestLogEntry * a1) +u16 *QL_LoadAction_MovementOrGfxChange(u16 *a0, struct QuestLogAction * a1) { u16 *r5 = a0; u8 *r6 = (u8 *)a0 + 4; - if (!WillCommandOfSizeFitInSav1Record(r5, sQuestLogEventCmdSizes[QL_EVENT_2])) + if (!QL_IsRoomToSaveAction(r5, sQuestLogEventCmdSizes[QL_EVENT_MOVEMENT])) return NULL; - if (r5[0] == 2) - a1->command = 0; + if (r5[0] == QL_EVENT_MOVEMENT) + a1->type = QL_ACTION_MOVEMENT; else - a1->command = 1; + a1->type = QL_ACTION_GFX_CHANGE; a1->duration = r5[1]; - a1->localId = r6[0]; - a1->mapNum = r6[1]; - a1->mapGroup = r6[2]; - a1->animId = r6[3]; + a1->data.raw[0] = r6[0]; + a1->data.raw[1] = r6[1]; + a1->data.raw[2] = r6[2]; + a1->data.raw[3] = r6[3]; return (u16 *)(r6 + 4); } -u16 *sub_8113DE0(u16 eventId, u16 *a1) +static u16 *RecordEventHeader(u16 eventId, u16 *dest) { u8 cmdSize; - u16 *r5; - u8 r4; - u8 r1; + u16 *record; + u8 i; + u8 count; - if (gUnknown_203B044.unk_1 == 0) + if (gQuestLogRepeatEventTracker.numRepeats == 0) cmdSize = sQuestLogEventCmdSizes[eventId]; else - cmdSize = sQuestLogEventCmdSizes[eventId] - 4; - if (!sub_8110944(a1, cmdSize)) + cmdSize = sQuestLogEventCmdSizes[eventId] - CMD_HEADER_SIZE; // First will already have the header + + if (!QL_IsRoomToSaveEvent(dest, cmdSize)) return NULL; - r5 = (void *)a1; + record = (void *)dest; - if (gUnknown_203B044.unk_1 != 0) - r5 = (void *)r5 - (gUnknown_203B044.unk_1 * cmdSize + 4); + if (gQuestLogRepeatEventTracker.numRepeats != 0) + record = (void *)record - (gQuestLogRepeatEventTracker.numRepeats * cmdSize + CMD_HEADER_SIZE); - if (gUnknown_203B044.unk_1 == 5) + if (gQuestLogRepeatEventTracker.numRepeats == MAX_CMD_REPEAT + 1) { - for (r4 = 0; r4 < 4; r4++) + // Shift back one, replacing oldest + for (i = 0; i < MAX_CMD_REPEAT; i++) { memcpy( - (void *)r5 + (r4 * cmdSize + 4), - (void *)r5 + ((r4 + 1) * cmdSize + 4), + (void *)record + ((i + 0) * cmdSize + CMD_HEADER_SIZE), + (void *)record + ((i + 1) * cmdSize + CMD_HEADER_SIZE), cmdSize ); } - r1 = 4; + count = MAX_CMD_REPEAT; } else - r1 = gUnknown_203B044.unk_1; + count = gQuestLogRepeatEventTracker.numRepeats; - r5[0] = eventId + (r1 << 12); - r5[1] = sQuestLogCursor; - r5 = (void *)r5 + (r1 * cmdSize + 4); - return r5; + // Set header data (CMD_HEADER_SIZE) + record[0] = eventId + (count << QL_CMD_COUNT_SHIFT); + record[1] = gQuestLogCurActionIdx; + + // Move past header and event data + record = (void *)record + (count * cmdSize + CMD_HEADER_SIZE); + return record; } -static const u16 *sub_8113E88(u16 eventId, const u16 *eventData) +static const u16 *LoadEvent(u16 eventId, const u16 *eventData) { - eventData = (const void *)eventData + (gUnknown_203B044.unk_2 * (sQuestLogEventCmdSizes[eventId] - 4) + 4); + eventData = (const void *)eventData + (gQuestLogRepeatEventTracker.counter * (sQuestLogEventCmdSizes[eventId] - CMD_HEADER_SIZE) + CMD_HEADER_SIZE); return eventData; } @@ -808,61 +1029,64 @@ static void QuestLog_GetSpeciesName(u16 species, u8 *dest, u8 stringVarId) } } -static u16 *BufferQuestLogData_SwitchedPartyOrder(u16 *a0, const u16 *eventData) +static u16 *RecordEvent_SwitchedPartyOrder(u16 *dest, const struct QuestLogEvent_SwitchedPartyOrder * data) { - u16 *r2 = sub_8113DE0(QL_EVENT_SWITCHED_PARTY_ORDER, a0); + u16 *r2 = RecordEventHeader(QL_EVENT_SWITCHED_PARTY_ORDER, dest); if (r2 == NULL) return NULL; - r2[0] = eventData[0]; - r2[1] = eventData[1]; + r2[0] = data->species1; + r2[1] = data->species2; return r2 + 2; } -static const u16 *BufferQuestLogText_SwitchedPartyOrder(const u16 *eventData) +static const u16 *LoadEvent_SwitchedPartyOrder(const u16 *eventData) { - const u16 *r4 = sub_8113E88(QL_EVENT_SWITCHED_PARTY_ORDER, eventData); + const u16 *r4 = LoadEvent(QL_EVENT_SWITCHED_PARTY_ORDER, eventData); QuestLog_GetSpeciesName(r4[0], gStringVar1, 0); QuestLog_GetSpeciesName(r4[1], gStringVar2, 0); StringExpandPlaceholders(gStringVar4, gText_QuestLog_SwitchMon1WithMon2); - r4 += 2; - return r4; + return r4 + 2; } -static u16 *BufferQuestLogData_UsedItem(u16 *a0, const u16 *eventData) +#define rItemId record[0] +#define rSpecies record[1] +#define rItemParam record[2] + +static u16 *RecordEvent_UsedItem(u16 *dest, const struct QuestLogEvent_Item * data) { - u16 *r2 = sub_8113DE0(QL_EVENT_USED_ITEM, a0); - if (r2 == NULL) + u16 *record = RecordEventHeader(QL_EVENT_USED_ITEM, dest); + if (record == NULL) return NULL; - r2[0] = eventData[0]; - r2[1] = eventData[2]; - r2[2] = eventData[3]; + rItemId = data->itemId; + rSpecies = data->species; + rItemParam = data->itemParam; - if (eventData[0] == ITEM_ESCAPE_ROPE) - sEventShouldNotRecordSteps = 2; + if (data->itemId == ITEM_ESCAPE_ROPE) + sStepRecordingMode = STEP_RECORDING_MODE_DISABLED_UNTIL_DEPART; - return r2 + 3; + return record + 3; } -static const u16 *BufferQuestLogText_UsedItem(const u16 *eventData) +static const u16 *LoadEvent_UsedItem(const u16 *eventData) { - const u16 *r5 = sub_8113E88(QL_EVENT_USED_ITEM, eventData); + const u16 *record = LoadEvent(QL_EVENT_USED_ITEM, eventData); - switch (ItemId_GetPocket(r5[0])) + switch (ItemId_GetPocket(rItemId)) { case POCKET_ITEMS: case POCKET_POKE_BALLS: case POCKET_BERRY_POUCH: - StringCopy(gStringVar1, ItemId_GetName(r5[0])); - if (r5[0] == ITEM_ESCAPE_ROPE) + StringCopy(gStringVar1, ItemId_GetName(rItemId)); + if (rItemId == ITEM_ESCAPE_ROPE) { - GetMapNameGeneric(gStringVar2, (u8)r5[2]); + GetMapNameGeneric(gStringVar2, (u8)rItemParam); StringExpandPlaceholders(gStringVar4, gText_QuestLog_UsedEscapeRope); } - else if (r5[1] != 0xFFFF) + else if (rSpecies != 0xFFFF) { - QuestLog_GetSpeciesName(r5[1], gStringVar2, 0); + QuestLog_GetSpeciesName(rSpecies, gStringVar2, 0); StringExpandPlaceholders(gStringVar4, gText_QuestLog_UsedItemOnMonAtThisLocation); } else @@ -871,415 +1095,422 @@ static const u16 *BufferQuestLogText_UsedItem(const u16 *eventData) } break; case POCKET_KEY_ITEMS: - StringCopy(gStringVar1, ItemId_GetName(r5[0])); + StringCopy(gStringVar1, ItemId_GetName(rItemId)); StringExpandPlaceholders(gStringVar4, gText_QuestLog_UsedTheKeyItem); break; case POCKET_TM_CASE: - QuestLog_GetSpeciesName(r5[1], gStringVar1, 0); - StringCopy(gStringVar2, gMoveNames[ItemIdToBattleMoveId(r5[0])]); - if (r5[2] != 0xFFFF) + QuestLog_GetSpeciesName(rSpecies, gStringVar1, 0); + StringCopy(gStringVar2, gMoveNames[ItemIdToBattleMoveId(rItemId)]); + if (rItemParam != 0xFFFF) { - StringCopy(gStringVar3, gMoveNames[r5[2]]); - if (r5[0] > ITEM_TM50) + StringCopy(gStringVar3, gMoveNames[rItemParam]); + if (rItemId >= ITEM_HM01) StringExpandPlaceholders(gStringVar4, gText_QuestLog_MonReplacedMoveWithHM); else StringExpandPlaceholders(gStringVar4, gText_QuestLog_MonReplacedMoveWithTM); } else { - if (r5[0] > ITEM_TM50) + if (rItemId >= ITEM_HM01) StringExpandPlaceholders(gStringVar4, gText_QuestLog_MonLearnedMoveFromHM); else StringExpandPlaceholders(gStringVar4, gText_QuestLog_MonLearnedMoveFromTM); } break; } - return r5 + 3; + return record + 3; } -u16 *BufferQuestLogData_GiveTakeHeldItem(u16 eventId, u16 *a1, const u16 *eventData) +static u16 *RecordEvent_GiveTakeHeldItem(u16 eventId, u16 *dest, const struct QuestLogEvent_Item * data) { - u16 *r1 = sub_8113DE0(eventId, a1); - if (r1 == NULL) + u16 *record = RecordEventHeader(eventId, dest); + if (record == NULL) return NULL; - r1[0] = eventData[0]; - r1[1] = eventData[2]; - return r1 + 2; + rItemId = data->itemId; + rSpecies = data->species; + return record + 2; } -static u16 *BufferQuestLogData_GaveHeldItemFromPartyMenu(u16 *a0, const u16 *eventData) +static u16 *RecordEvent_GaveHeldItemFromPartyMenu(u16 *dest, const struct QuestLogEvent_Item * data) { - return BufferQuestLogData_GiveTakeHeldItem(QL_EVENT_GAVE_HELD_ITEM, a0, eventData); + return RecordEvent_GiveTakeHeldItem(QL_EVENT_GAVE_HELD_ITEM, dest, data); } -static const u16 *BufferQuestLogText_GaveHeldItemFromPartyMenu(const u16 *eventData) +static const u16 *LoadEvent_GaveHeldItemFromPartyMenu(const u16 * eventData) { - const u16 *r4 = sub_8113E88(QL_EVENT_GAVE_HELD_ITEM, eventData); - QuestLog_GetSpeciesName(r4[1], gStringVar1, 0); - StringCopy(gStringVar2, ItemId_GetName(r4[0])); + const u16 *record = LoadEvent(QL_EVENT_GAVE_HELD_ITEM, eventData); + QuestLog_GetSpeciesName(rSpecies, gStringVar1, 0); + StringCopy(gStringVar2, ItemId_GetName(rItemId)); StringExpandPlaceholders(gStringVar4, gText_QuestLog_GaveMonHeldItem); - r4 += 2; - return r4; + return record + 2; } -static u16 *BufferQuestLogData_GaveHeldItemFromBagMenu(u16 *a0, const u16 *eventData) +static u16 *RecordEvent_GaveHeldItemFromBagMenu(u16 *dest, const struct QuestLogEvent_Item * data) { - return BufferQuestLogData_GiveTakeHeldItem(QL_EVENT_GAVE_HELD_ITEM_BAG, a0, eventData); + return RecordEvent_GiveTakeHeldItem(QL_EVENT_GAVE_HELD_ITEM_BAG, dest, data); } -static const u16 *BufferQuestLogText_GaveHeldItemFromBagMenu(const u16 *eventData) +static const u16 *LoadEvent_GaveHeldItemFromBagMenu(const u16 *eventData) { - const u16 *r4 = sub_8113E88(QL_EVENT_GAVE_HELD_ITEM_BAG, eventData); - QuestLog_GetSpeciesName(r4[1], gStringVar1, 0); - StringCopy(gStringVar2, ItemId_GetName(r4[0])); + const u16 *record = LoadEvent(QL_EVENT_GAVE_HELD_ITEM_BAG, eventData); + QuestLog_GetSpeciesName(rSpecies, gStringVar1, 0); + StringCopy(gStringVar2, ItemId_GetName(rItemId)); StringExpandPlaceholders(gStringVar4, gText_QuestLog_GaveMonHeldItem2); - r4 += 2; - return r4; + return record + 2; } -static u16 *BufferQuestLogData_GaveHeldItemFromPC(u16 *a0, const u16 *eventData) +static u16 *RecordEvent_GaveHeldItemFromPC(u16 *dest, const struct QuestLogEvent_Item * data) { - return BufferQuestLogData_GiveTakeHeldItem(QL_EVENT_GAVE_HELD_ITEM_PC, a0, eventData); + return RecordEvent_GiveTakeHeldItem(QL_EVENT_GAVE_HELD_ITEM_PC, dest, data); } -static const u16 *BufferQuestLogText_GaveHeldItemFromPC(const u16 *eventData) +static const u16 *LoadEvent_GaveHeldItemFromPC(const u16 *eventData) { - const u16 *r4 = sub_8113E88(QL_EVENT_GAVE_HELD_ITEM_PC, eventData); + const u16 *record = LoadEvent(QL_EVENT_GAVE_HELD_ITEM_PC, eventData); - QuestLog_GetSpeciesName(r4[1], gStringVar2, 0); - StringCopy(gStringVar1, ItemId_GetName(r4[0])); + QuestLog_GetSpeciesName(rSpecies, gStringVar2, 0); + StringCopy(gStringVar1, ItemId_GetName(rItemId)); StringExpandPlaceholders(gStringVar4, gText_QuestLog_GaveMonHeldItemFromPC); - r4 += 2; - return r4; + return record + 2; } -static u16 *BufferQuestLogData_TookHeldItem(u16 *a0, const u16 *eventData) +static u16 *RecordEvent_TookHeldItem(u16 *dest, const struct QuestLogEvent_Item * data) { - return BufferQuestLogData_GiveTakeHeldItem(QL_EVENT_TOOK_HELD_ITEM, a0, eventData); + return RecordEvent_GiveTakeHeldItem(QL_EVENT_TOOK_HELD_ITEM, dest, data); } -static const u16 *BufferQuestLogText_TookHeldItem(const u16 *eventData) +static const u16 *LoadEvent_TookHeldItem(const u16 *eventData) { - const u16 *r4 = sub_8113E88(QL_EVENT_TOOK_HELD_ITEM, eventData); + const u16 *record = LoadEvent(QL_EVENT_TOOK_HELD_ITEM, eventData); - QuestLog_GetSpeciesName(r4[1], gStringVar1, 0); - StringCopy(gStringVar2, ItemId_GetName(r4[0])); + QuestLog_GetSpeciesName(rSpecies, gStringVar1, 0); + StringCopy(gStringVar2, ItemId_GetName(rItemId)); StringExpandPlaceholders(gStringVar4, gText_QuestLog_TookHeldItemFromMon); - r4 += 2; - return r4; + return record + 2; } -u16 *BufferQuestLogData_SwappedHeldItem_(u16 eventId, u16 *a1, const u16 *eventData) +#undef rItemId +#undef rSpecies +#undef rItemParam + +#define rTakenItemId record[0] +#define rGivenItemId record[1] +#define rSpecies record[2] + +static u16 *RecordEvent_SwappedHeldItem(u16 eventId, u16 *dest, const struct QuestLogEvent_SwappedHeldItem * data) { - u16 *r1 = sub_8113DE0(eventId, a1); - if (r1 == NULL) + u16 *record = RecordEventHeader(eventId, dest); + if (record == NULL) return NULL; - r1[0] = eventData[0]; - r1[1] = eventData[1]; - r1[2] = eventData[2]; - return r1 + 3; + rTakenItemId = data->takenItemId; + rGivenItemId = data->givenItemId; + rSpecies = data->species; + return record + 3; } -static u16 *BufferQuestLogData_SwappedHeldItem(u16 *a0, const u16 *eventData) +static u16 *RecordEvent_SwappedHeldItemFromBag(u16 *dest, const struct QuestLogEvent_SwappedHeldItem * data) { - return BufferQuestLogData_SwappedHeldItem_(QL_EVENT_SWAPPED_HELD_ITEM, a0, eventData); + return RecordEvent_SwappedHeldItem(QL_EVENT_SWAPPED_HELD_ITEM, dest, data); } -static const u16 *BufferQuestLogText_SwappedHeldItem(const u16 *eventData) +static const u16 *LoadEvent_SwappedHeldItem(const u16 *eventData) { - const u16 *r4 = sub_8113E88(QL_EVENT_SWAPPED_HELD_ITEM, eventData); - QuestLog_GetSpeciesName(r4[2], gStringVar1, 0); - StringCopy(gStringVar2, ItemId_GetName(r4[0])); // Item taken - StringCopy(gStringVar3, ItemId_GetName(r4[1])); // Item given + const u16 *record = LoadEvent(QL_EVENT_SWAPPED_HELD_ITEM, eventData); + QuestLog_GetSpeciesName(rSpecies, gStringVar1, 0); + StringCopy(gStringVar2, ItemId_GetName(rTakenItemId)); + StringCopy(gStringVar3, ItemId_GetName(rGivenItemId)); StringExpandPlaceholders(gStringVar4, gText_QuestLog_SwappedHeldItemsOnMon); - r4 += 3; - return r4; + return record + 3; } -static u16 *BufferQuestLogData_SwappedHeldItemFromPC(u16 *a0, const u16 *eventData) +static u16 *RecordEvent_SwappedHeldItemFromPC(u16 *dest, const struct QuestLogEvent_SwappedHeldItem * data) { - return BufferQuestLogData_SwappedHeldItem_(QL_EVENT_SWAPPED_HELD_ITEM_PC, a0, eventData); + return RecordEvent_SwappedHeldItem(QL_EVENT_SWAPPED_HELD_ITEM_PC, dest, data); } -static const u16 *BufferQuestLogText_SwappedHeldItemFromPC(const u16 *eventData) +static const u16 *LoadEvent_SwappedHeldItemFromPC(const u16 *eventData) { - const u16 *r4 = sub_8113E88(QL_EVENT_SWAPPED_HELD_ITEM_PC, eventData); - QuestLog_GetSpeciesName(r4[2], gStringVar2, 0); - StringCopy(gStringVar3, ItemId_GetName(r4[0])); - StringCopy(gStringVar1, ItemId_GetName(r4[1])); + const u16 *record = LoadEvent(QL_EVENT_SWAPPED_HELD_ITEM_PC, eventData); + QuestLog_GetSpeciesName(rSpecies, gStringVar2, 0); + StringCopy(gStringVar3, ItemId_GetName(rTakenItemId)); + StringCopy(gStringVar1, ItemId_GetName(rGivenItemId)); StringExpandPlaceholders(gStringVar4, gText_QuestLog_SwappedHeldItemFromPC); - r4 += 3; - return r4; + return record + 3; } -static u16 *BufferQuestLogData_UsedPkmnCenter(u16 *a0, const u16 *eventData) -{ - u16 *r4 = a0; - if (gUnknown_203B044.id == QL_EVENT_USED_PKMN_CENTER && gUnknown_203B044.unk_1 != 0) - return r4; +#undef rTakenItemId +#undef rGivenItemId +#undef rSpecies - if (!sub_8110944(a0, sQuestLogEventCmdSizes[QL_EVENT_USED_PKMN_CENTER])) +// data argument will be a null pointer, no information needed for this event +static u16 *RecordEvent_UsedPkmnCenter(u16 *dest, const u16 * data) +{ + u16 *record = dest; + if (gQuestLogRepeatEventTracker.id == QL_EVENT_USED_PKMN_CENTER && gQuestLogRepeatEventTracker.numRepeats != 0) + return record; + + if (!QL_IsRoomToSaveEvent(dest, sQuestLogEventCmdSizes[QL_EVENT_USED_PKMN_CENTER])) return NULL; - r4[0] = QL_EVENT_USED_PKMN_CENTER; - r4[1] = sQuestLogCursor; - return r4 + 2; + record[0] = QL_EVENT_USED_PKMN_CENTER; + record[1] = gQuestLogCurActionIdx; + return record + 2; } -static const u16 *BufferQuestLogText_UsedPkmnCenter(const u16 *a0) +static const u16 *LoadEvent_UsedPkmnCenter(const u16 *eventData) { StringExpandPlaceholders(gStringVar4, gText_QuestLog_MonsWereFullyRestoredAtCenter); - a0 += 2; - return a0; + return eventData + 2; } -static u16 *BufferQuestLogData_LinkTraded(u16 *a0, const u16 *eventData) +static u16 *RecordEvent_LinkTraded(u16 *dest, const struct QuestLogEvent_Traded * data) { - u16 *r4 = a0 + 4; + u16 *nameDest = dest + 4; - a0[0] = QL_EVENT_LINK_TRADED; - a0[1] = sQuestLogCursor; - a0[2] = eventData[0]; - a0[3] = eventData[1]; - eventData += 2; - memcpy(r4, eventData, 7); - r4 += 4; - return r4; + dest[0] = QL_EVENT_LINK_TRADED; + dest[1] = gQuestLogCurActionIdx; + dest[2] = data->speciesSent; + dest[3] = data->speciesReceived; + memcpy(nameDest, data->partnerName, PLAYER_NAME_LENGTH); + return nameDest + 4; } -static const u16 *BufferQuestLogText_LinkTraded(const u16 *a0) +static const u16 *LoadEvent_LinkTraded(const u16 *eventData) { - const u16 *r6 = a0 + 4; + const u16 *name = eventData + 4; memset(gStringVar1, EOS, PLAYER_NAME_LENGTH + 1); - memcpy(gStringVar1, r6, PLAYER_NAME_LENGTH); + memcpy(gStringVar1, name, PLAYER_NAME_LENGTH); - BufferLinkPartnersName(gStringVar1); - QuestLog_GetSpeciesName(a0[3], gStringVar2, 0); // Mon received - QuestLog_GetSpeciesName(a0[2], gStringVar3, 0); // Mon sent + TranslateLinkPartnersName(gStringVar1); + QuestLog_GetSpeciesName(eventData[3], gStringVar2, 0); // Mon received + QuestLog_GetSpeciesName(eventData[2], gStringVar3, 0); // Mon sent StringExpandPlaceholders(gStringVar4, gText_QuestLog_TradedMon1ForPersonsMon2); - r6 += 4; - return r6; + return name + 4; } -static const u8 *const sDefeatedOpponentFlavorTexts[] = { - gText_QuestLog_Handily, - gText_QuestLog_Tenaciously, - gText_QuestLog_Somehow -}; +#define rOutcome record[0] +#define rBattler1Name record[1] +#define rBattler2Name record[1 + PLAYER_NAME_LENGTH] +#define rBattler3Name record[1 + PLAYER_NAME_LENGTH * 2] -static const u8 *const sDefeatedChampionFlavorTexts[] = { - gText_QuestLog_Coolly, - gText_QuestLog_Somehow, - gText_QuestLog_Barely -}; - -static const u8 *const sBattleOutcomeTexts[] = { - gText_QuestLog_Win, - gText_QuestLog_Loss, - gText_QuestLog_Draw -}; - -static u16 *BufferQuestLogData_LinkBattledSingle(u16 *a0, const u16 *eventData) +static u16 *RecordEvent_LinkBattledSingle(u16 *dest, const struct QuestLogEvent_LinkBattle * data) { - a0[0] = QL_EVENT_LINK_BATTLED_SINGLE; - a0[1] = sQuestLogCursor; - *((u8 *)a0 + 4) = *((const u8 *)eventData + 0); - memcpy((u8 *)a0 + 5, (const u8 *)eventData + 1, PLAYER_NAME_LENGTH); - a0 += 6; - return a0; + u8 * record; + + dest[0] = QL_EVENT_LINK_BATTLED_SINGLE; + dest[1] = gQuestLogCurActionIdx; + record = (u8 *)(dest + 2); + + rOutcome = data->outcome; + memcpy(&rBattler1Name, data->playerNames[0], PLAYER_NAME_LENGTH); + return (u16 *)(record + 1 + PLAYER_NAME_LENGTH); } -static const u16 *BufferQuestLogText_LinkBattledSingle(const u16 *a0) +static const u16 *LoadEvent_LinkBattledSingle(const u16 *eventData) { + const u8 * record = (const u8 *)(eventData + 2); DynamicPlaceholderTextUtil_Reset(); memset(gStringVar1, EOS, PLAYER_NAME_LENGTH + 1); - memcpy(gStringVar1, (const u8 *)a0 + 5, PLAYER_NAME_LENGTH); - BufferLinkPartnersName(gStringVar1); + memcpy(gStringVar1, &rBattler1Name, PLAYER_NAME_LENGTH); + TranslateLinkPartnersName(gStringVar1); DynamicPlaceholderTextUtil_SetPlaceholderPtr(0, gStringVar1); - DynamicPlaceholderTextUtil_SetPlaceholderPtr(1, sBattleOutcomeTexts[((const u8 *)a0)[4]]); + DynamicPlaceholderTextUtil_SetPlaceholderPtr(1, sBattleOutcomeTexts[rOutcome]); DynamicPlaceholderTextUtil_ExpandPlaceholders(gStringVar4, gText_QuestLog_SingleBattleWithPersonResultedInOutcome); - a0 += 6; - return a0; + return (const u16 *)(record + 1 + PLAYER_NAME_LENGTH); } -static u16 *BufferQuestLogData_LinkBattledDouble(u16 *a0, const u16 *eventData) +static u16 *RecordEvent_LinkBattledDouble(u16 *dest, const struct QuestLogEvent_LinkBattle * data) { - a0[0] = QL_EVENT_LINK_BATTLED_DOUBLE; - a0[1] = sQuestLogCursor; - *((u8 *)a0 + 4) = *((const u8 *)eventData + 0); - memcpy((u8 *)a0 + 5, (const u8 *)eventData + 1, PLAYER_NAME_LENGTH); - a0 += 6; - return a0; + u8 * record; + + dest[0] = QL_EVENT_LINK_BATTLED_DOUBLE; + dest[1] = gQuestLogCurActionIdx; + record = (u8 *)(dest + 2); + + rOutcome = data->outcome; + memcpy(&rBattler1Name, data->playerNames[0], PLAYER_NAME_LENGTH); + return (u16 *)(record + 1 + PLAYER_NAME_LENGTH); } -static const u16 *BufferQuestLogText_LinkBattledDouble(const u16 *a0) +static const u16 *LoadEvent_LinkBattledDouble(const u16 *eventData) { + const u8 * record = (const u8 *)(eventData + 2); DynamicPlaceholderTextUtil_Reset(); memset(gStringVar1, EOS, PLAYER_NAME_LENGTH + 1); - memcpy(gStringVar1, (const u8 *)a0 + 5, PLAYER_NAME_LENGTH); - BufferLinkPartnersName(gStringVar1); + memcpy(gStringVar1, &rBattler1Name, PLAYER_NAME_LENGTH); + TranslateLinkPartnersName(gStringVar1); DynamicPlaceholderTextUtil_SetPlaceholderPtr(0, gStringVar1); - DynamicPlaceholderTextUtil_SetPlaceholderPtr(1, sBattleOutcomeTexts[((const u8 *)a0)[4]]); + DynamicPlaceholderTextUtil_SetPlaceholderPtr(1, sBattleOutcomeTexts[rOutcome]); DynamicPlaceholderTextUtil_ExpandPlaceholders(gStringVar4, gText_QuestLog_DoubleBattleWithPersonResultedInOutcome); - a0 += 6; - return a0; + return (const u16 *)(record + 1 + PLAYER_NAME_LENGTH); } -static u16 *BufferQuestLogData_LinkBattledMulti(u16 *a0, const u16 *eventData) +static u16 *RecordEvent_LinkBattledMulti(u16 *dest, const struct QuestLogEvent_LinkBattle * data) { - a0[0] = QL_EVENT_LINK_BATTLED_MULTI; - a0[1] = sQuestLogCursor; - *((u8 *)a0 + 4) = *((const u8 *)eventData + 0); - memcpy((u8 *)a0 + 5, (const u8 *)eventData + 1, PLAYER_NAME_LENGTH); - memcpy((u8 *)a0 + 12, (const u8 *)eventData + 8, PLAYER_NAME_LENGTH); - memcpy((u8 *)a0 + 19, (const u8 *)eventData + 15, PLAYER_NAME_LENGTH); - a0 += 13; - return a0; + u8 * record; + + dest[0] = QL_EVENT_LINK_BATTLED_MULTI; + dest[1] = gQuestLogCurActionIdx; + record = (u8 *)(dest + 2); + + rOutcome = data->outcome; + memcpy(&rBattler1Name, data->playerNames[0], PLAYER_NAME_LENGTH); + memcpy(&rBattler2Name, data->playerNames[1], PLAYER_NAME_LENGTH); + memcpy(&rBattler3Name, data->playerNames[2], PLAYER_NAME_LENGTH); + return (u16 *)(record + 1 + PLAYER_NAME_LENGTH * 3); } -static const u16 *BufferQuestLogText_LinkBattledMulti(const u16 *a0) +static const u16 *LoadEvent_LinkBattledMulti(const u16 *eventData) { + const u8 * record = (const u8 *)(eventData + 2); DynamicPlaceholderTextUtil_Reset(); memset(gStringVar1, EOS, PLAYER_NAME_LENGTH + 1); memset(gStringVar2, EOS, PLAYER_NAME_LENGTH + 1); memset(gStringVar3, EOS, PLAYER_NAME_LENGTH + 1); - StringCopy_PlayerName(gStringVar1, (const u8 *)a0 + 5); - StringCopy_PlayerName(gStringVar2, (const u8 *)a0 + 12); - StringCopy_PlayerName(gStringVar3, (const u8 *)a0 + 19); - BufferLinkPartnersName(gStringVar1); - BufferLinkPartnersName(gStringVar2); - BufferLinkPartnersName(gStringVar3); + StringCopy_PlayerName(gStringVar1, &rBattler1Name); + StringCopy_PlayerName(gStringVar2, &rBattler2Name); + StringCopy_PlayerName(gStringVar3, &rBattler3Name); + TranslateLinkPartnersName(gStringVar1); + TranslateLinkPartnersName(gStringVar2); + TranslateLinkPartnersName(gStringVar3); DynamicPlaceholderTextUtil_SetPlaceholderPtr(0, gSaveBlock2Ptr->playerName); DynamicPlaceholderTextUtil_SetPlaceholderPtr(1, gStringVar1); // partner DynamicPlaceholderTextUtil_SetPlaceholderPtr(2, gStringVar2); // opponent 1 DynamicPlaceholderTextUtil_SetPlaceholderPtr(3, gStringVar3); // opponent 2 - DynamicPlaceholderTextUtil_SetPlaceholderPtr(4, sBattleOutcomeTexts[((const u8 *)a0)[4]]); + DynamicPlaceholderTextUtil_SetPlaceholderPtr(4, sBattleOutcomeTexts[rOutcome]); DynamicPlaceholderTextUtil_ExpandPlaceholders(gStringVar4, gText_QuestLog_MultiBattleWithPeopleResultedInOutcome); - a0 += 13; - return a0; + return (const u16 *)(record + 1 + PLAYER_NAME_LENGTH * 3); } -static u16 *BufferQuestLogData_UsedUnionRoom(u16 *a0, const u16 *eventData) +// data argument will be a null pointer, no information needed for this event +static u16 *RecordEvent_UsedUnionRoom(u16 *dest, const u16 * data) { - a0[0] = QL_EVENT_USED_UNION_ROOM; - a0[1] = sQuestLogCursor; - return a0 + 2; + dest[0] = QL_EVENT_USED_UNION_ROOM; + dest[1] = gQuestLogCurActionIdx; + return dest + 2; } -static const u16 *BufferQuestLogText_UsedUnionRoom(const u16 *a0) +static const u16 *LoadEvent_UsedUnionRoom(const u16 *eventData) { StringExpandPlaceholders(gStringVar4, gText_QuestLog_MingledInUnionRoom); - a0 += 2; - return a0; + return eventData + 2; } -static u16 *BufferQuestLogData_UsedUnionRoomChat(u16 *a0, const u16 *eventData) +// data argument will be a null pointer, no information needed for this event +static u16 *RecordEvent_UsedUnionRoomChat(u16 *dest, const u16 * data) { - a0[0] = QL_EVENT_USED_UNION_ROOM_CHAT; - a0[1] = sQuestLogCursor; - return a0 + 2; + dest[0] = QL_EVENT_USED_UNION_ROOM_CHAT; + dest[1] = gQuestLogCurActionIdx; + return dest + 2; } -static const u16 *BufferQuestLogText_UsedUnionRoomChat(const u16 *a0) +static const u16 *LoadEvent_UsedUnionRoomChat(const u16 *eventData) { StringExpandPlaceholders(gStringVar4, gText_QuestLog_ChattedWithManyTrainers); - a0 += 2; - return a0; + return eventData + 2; } -static u16 *BufferQuestLogData_LinkTradedUnionRoom(u16 *a0, const u16 *eventData) +static u16 *RecordEvent_LinkTradedUnionRoom(u16 *dest, const struct QuestLogEvent_Traded * data) { - u8 *r4 = (u8 *)(a0 + 4); - a0[0] = QL_EVENT_LINK_TRADED_UNION; - a0[1] = sQuestLogCursor; - a0[2] = eventData[0]; - a0[3] = eventData[1]; - memcpy(r4, eventData + 2, PLAYER_NAME_LENGTH); - r4 += 8; - return (u16 *)r4; + u8 *name = (u8 *)(dest + 4); + dest[0] = QL_EVENT_LINK_TRADED_UNION; + dest[1] = gQuestLogCurActionIdx; + dest[2] = data->speciesSent; + dest[3] = data->speciesReceived; + memcpy(name, &data->partnerName, PLAYER_NAME_LENGTH); + return (u16 *)(name + 8); } -static const u16 *BufferQuestLogText_LinkTradedUnionRoom(const u16 *a0) +static const u16 *LoadEvent_LinkTradedUnionRoom(const u16 *a0) { const u8 *r6 = (const u8 *)(a0 + 4); memset(gStringVar1, EOS, PLAYER_NAME_LENGTH + 1); memcpy(gStringVar1, r6, PLAYER_NAME_LENGTH); - BufferLinkPartnersName(gStringVar1); + TranslateLinkPartnersName(gStringVar1); QuestLog_GetSpeciesName(a0[3], gStringVar2, 0); QuestLog_GetSpeciesName(a0[2], gStringVar3, 0); StringExpandPlaceholders(gStringVar4, gText_QuestLog_TradedMon1ForTrainersMon2); - r6 += 8; - return (const u16 *)r6; + return (const u16 *)(r6 + 8); } -static u16 *BufferQuestLogData_LinkBattledUnionRoom(u16 *a0, const u16 *eventData) +static u16 *RecordEvent_LinkBattledUnionRoom(u16 *dest, const struct QuestLogEvent_LinkBattle * data) { - a0[0] = QL_EVENT_LINK_BATTLED_UNION; - a0[1] = sQuestLogCursor; - *(u8 *)&a0[2] = *(const u8 *)&eventData[0]; - memcpy((u8 *)a0 + 5, (const u8 *)eventData + 1, PLAYER_NAME_LENGTH); - a0 += 6; - return a0; + dest[0] = QL_EVENT_LINK_BATTLED_UNION; + dest[1] = gQuestLogCurActionIdx; + *(u8 *)&dest[2] = data->outcome; + memcpy((u8 *)dest + 5, &data->playerNames[0], PLAYER_NAME_LENGTH); + return dest + 6; } -static const u16 *BufferQuestLogText_LinkBattledUnionRoom(const u16 *a0) +static const u16 *LoadEvent_LinkBattledUnionRoom(const u16 *eventData) { + const u8 * record = (const u8 *)(eventData + 2); + memset(gStringVar1, EOS, PLAYER_NAME_LENGTH + 1); - memcpy(gStringVar1, (const u8 *)a0 + 5, PLAYER_NAME_LENGTH); - BufferLinkPartnersName(gStringVar1); - StringCopy(gStringVar2, sBattleOutcomeTexts[*(const u8 *)&a0[2]]); + memcpy(gStringVar1, &rBattler1Name, PLAYER_NAME_LENGTH); + TranslateLinkPartnersName(gStringVar1); + StringCopy(gStringVar2, sBattleOutcomeTexts[rOutcome]); StringExpandPlaceholders(gStringVar4, gText_QuestLog_BattledTrainerEndedInOutcome); - a0 += 6; - return a0; + return (const u16 *)(record + 1 + PLAYER_NAME_LENGTH); } -static u16 *BufferQuestLogData_SwitchedMonsBetweenBoxes(u16 *a0, const u16 *eventData) +#undef rOutcome +#undef rBattler1Name +#undef rBattler2Name +#undef rBattler3Name + +#define rSpecies1 record[0] +#define rSpecies2 record[1] +#define rBox1 (*((u8*)&record[2] + 0)) // 1st byte of record[2] +#define rBox2 (*((u8*)&record[2] + 1)) // 2nd byte of record[2] + +static u16 *RecordEvent_SwitchedMonsBetweenBoxes(u16 *dest, const struct QuestLogEvent_MovedBoxMon * data) { - a0 = sub_8113DE0(QL_EVENT_SWITCHED_MONS_BETWEEN_BOXES, a0); - if (a0 == NULL) + u16 * record = RecordEventHeader(QL_EVENT_SWITCHED_MONS_BETWEEN_BOXES, dest); + if (record == NULL) return NULL; - a0[0] = eventData[0]; - a0[1] = eventData[1]; - *((u8 *)a0 + 4) = *((const u8 *)eventData + 4); - *((u8 *)a0 + 5) = *((const u8 *)eventData + 5); - return a0 + 3; + rSpecies1 = data->species1; + rSpecies2 = data->species2; + rBox1 = data->box1; + rBox2 = data->box2; + return record + 3; } -static const u16 *BufferQuestLogText_SwitchedMonsBetweenBoxes(const u16 *eventData) +static const u16 *LoadEvent_SwitchedMonsBetweenBoxes(const u16 *eventData) { const u8 *boxIdxs; - eventData = sub_8113E88(QL_EVENT_SWITCHED_MONS_BETWEEN_BOXES, eventData); - boxIdxs = (const u8 *)eventData + 4; + const u16 * r0 = LoadEvent(QL_EVENT_SWITCHED_MONS_BETWEEN_BOXES, eventData); + boxIdxs = (const u8 *)r0 + 4; DynamicPlaceholderTextUtil_Reset(); DynamicPlaceholderTextUtil_SetPlaceholderPtr(0, GetBoxNamePtr(boxIdxs[0])); - QuestLog_GetSpeciesName(eventData[0], NULL, 1); + QuestLog_GetSpeciesName(r0[0], NULL, 1); DynamicPlaceholderTextUtil_SetPlaceholderPtr(2, GetBoxNamePtr(boxIdxs[1])); - QuestLog_GetSpeciesName(eventData[1], NULL, 3); + QuestLog_GetSpeciesName(r0[1], NULL, 3); DynamicPlaceholderTextUtil_ExpandPlaceholders(gStringVar4, gText_QuestLog_SwitchedMonsBetweenBoxes); - return eventData + 3; + return r0 + 3; } -static u16 *BufferQuestLogData_SwitchedMonsWithinBox(u16 *a0, const u16 *eventData) +static u16 *RecordEvent_SwitchedMonsWithinBox(u16 *dest, const u16 *eventData) { - a0 = sub_8113DE0(QL_EVENT_SWITCHED_MONS_WITHIN_BOX, a0); - if (a0 == NULL) + dest = RecordEventHeader(QL_EVENT_SWITCHED_MONS_WITHIN_BOX, dest); + if (dest == NULL) return NULL; - a0[0] = eventData[0]; - a0[1] = eventData[1]; - *((u8 *)a0 + 4) = *((const u8 *)eventData + 4); - return a0 + 3; + dest[0] = eventData[0]; + dest[1] = eventData[1]; + *((u8 *)dest + 4) = *((const u8 *)eventData + 4); + return dest + 3; } -static const u16 *BufferQuestLogText_SwitchedMonsWithinBox(const u16 *eventData) +static const u16 *LoadEvent_SwitchedMonsWithinBox(const u16 *eventData) { const u8 *boxIdxs; - eventData = sub_8113E88(QL_EVENT_SWITCHED_MONS_WITHIN_BOX, eventData); + eventData = LoadEvent(QL_EVENT_SWITCHED_MONS_WITHIN_BOX, eventData); boxIdxs = (const u8 *)eventData + 4; DynamicPlaceholderTextUtil_Reset(); DynamicPlaceholderTextUtil_SetPlaceholderPtr(0, GetBoxNamePtr(boxIdxs[0])); @@ -1289,11 +1520,11 @@ static const u16 *BufferQuestLogText_SwitchedMonsWithinBox(const u16 *eventData) return eventData + 3; } -static u16 *BufferQuestLogData_SwitchedPartyMonForPCMon(u16 *a0, const u16 *eventData) +static u16 *RecordEvent_SwitchedPartyMonForPCMon(u16 *dest, const u16 *eventData) { u16 *r2; u16 *ret; - r2 = sub_8113DE0(QL_EVENT_SWITCHED_PARTY_MON_FOR_PC_MON, a0); + r2 = RecordEventHeader(QL_EVENT_SWITCHED_PARTY_MON_FOR_PC_MON, dest); if (r2 == NULL) return NULL; ret = r2 + 2; @@ -1312,10 +1543,10 @@ static u16 *BufferQuestLogData_SwitchedPartyMonForPCMon(u16 *a0, const u16 *even return ret + 1; } -static const u16 *BufferQuestLogText_SwitchedPartyMonForPCMon(const u16 *eventData) +static const u16 *LoadEvent_SwitchedPartyMonForPCMon(const u16 *eventData) { const u8 *boxIdxs; - eventData = sub_8113E88(QL_EVENT_SWITCHED_PARTY_MON_FOR_PC_MON, eventData); + eventData = LoadEvent(QL_EVENT_SWITCHED_PARTY_MON_FOR_PC_MON, eventData); boxIdxs = (const u8 *)eventData + 4; DynamicPlaceholderTextUtil_Reset(); DynamicPlaceholderTextUtil_SetPlaceholderPtr(0, GetBoxNamePtr(boxIdxs[0])); @@ -1325,11 +1556,11 @@ static const u16 *BufferQuestLogText_SwitchedPartyMonForPCMon(const u16 *eventDa return eventData + 3; } -static u16 *BufferQuestLogData_MovedMonBetweenBoxes(u16 *a0, const u16 *eventData) +static u16 *RecordEvent_MovedMonBetweenBoxes(u16 *dest, const u16 *eventData) { u16 *r2; u16 *ret; - r2 = sub_8113DE0(QL_EVENT_MOVED_MON_BETWEEN_BOXES, a0); + r2 = RecordEventHeader(QL_EVENT_MOVED_MON_BETWEEN_BOXES, dest); if (r2 == NULL) return NULL; r2[0] = eventData[0]; @@ -1339,10 +1570,10 @@ static u16 *BufferQuestLogData_MovedMonBetweenBoxes(u16 *a0, const u16 *eventDat return ret + 1; } -static const u16 *BufferQuestLogText_MovedMonBetweenBoxes(const u16 *eventData) +static const u16 *LoadEvent_MovedMonBetweenBoxes(const u16 *eventData) { const u8 *boxIdxs; - eventData = sub_8113E88(QL_EVENT_MOVED_MON_BETWEEN_BOXES, eventData); + eventData = LoadEvent(QL_EVENT_MOVED_MON_BETWEEN_BOXES, eventData); boxIdxs = (const u8 *)eventData + 2; DynamicPlaceholderTextUtil_Reset(); DynamicPlaceholderTextUtil_SetPlaceholderPtr(0, GetBoxNamePtr(boxIdxs[0])); @@ -1352,10 +1583,10 @@ static const u16 *BufferQuestLogText_MovedMonBetweenBoxes(const u16 *eventData) return (const u16 *)boxIdxs + 1; } -static u16 *BufferQuestLogData_MovedMonWithinBox(u16 *a0, const u16 *eventData) +static u16 *RecordEvent_MovedMonWithinBox(u16 *dest, const u16 *eventData) { u16 *r2; - r2 = sub_8113DE0(QL_EVENT_MOVED_MON_WITHIN_BOX, a0); + r2 = RecordEventHeader(QL_EVENT_MOVED_MON_WITHIN_BOX, dest); if (r2 == NULL) return NULL; r2[0] = eventData[0]; @@ -1363,10 +1594,10 @@ static u16 *BufferQuestLogData_MovedMonWithinBox(u16 *a0, const u16 *eventData) return r2 + 2; } -static const u16 *BufferQuestLogText_MovedMonWithinBox(const u16 *eventData) +static const u16 *LoadEvent_MovedMonWithinBox(const u16 *eventData) { const u8 *boxIdxs; - eventData = sub_8113E88(QL_EVENT_MOVED_MON_WITHIN_BOX, eventData); + eventData = LoadEvent(QL_EVENT_MOVED_MON_WITHIN_BOX, eventData); boxIdxs = (const u8 *)eventData + 2; DynamicPlaceholderTextUtil_Reset(); DynamicPlaceholderTextUtil_SetPlaceholderPtr(0, GetBoxNamePtr(boxIdxs[0])); @@ -1375,10 +1606,10 @@ static const u16 *BufferQuestLogText_MovedMonWithinBox(const u16 *eventData) return (const u16 *)boxIdxs + 1; } -static u16 *BufferQuestLogData_WithdrewMonFromPC(u16 *a0, const u16 *eventData) +static u16 *RecordEvent_WithdrewMonFromPC(u16 *dest, const u16 *eventData) { u16 *r2; - r2 = sub_8113DE0(QL_EVENT_WITHDREW_MON_PC, a0); + r2 = RecordEventHeader(QL_EVENT_WITHDREW_MON_PC, dest); if (r2 == NULL) return NULL; r2[0] = eventData[0]; @@ -1386,10 +1617,10 @@ static u16 *BufferQuestLogData_WithdrewMonFromPC(u16 *a0, const u16 *eventData) return r2 + 2; } -static const u16 *BufferQuestLogText_WithdrewMonFromPC(const u16 *eventData) +static const u16 *LoadEvent_WithdrewMonFromPC(const u16 *eventData) { const u8 *boxIdxs; - eventData = sub_8113E88(QL_EVENT_WITHDREW_MON_PC, eventData); + eventData = LoadEvent(QL_EVENT_WITHDREW_MON_PC, eventData); boxIdxs = (const u8 *)eventData + 2; DynamicPlaceholderTextUtil_Reset(); DynamicPlaceholderTextUtil_SetPlaceholderPtr(0, GetBoxNamePtr(boxIdxs[0])); @@ -1398,10 +1629,10 @@ static const u16 *BufferQuestLogText_WithdrewMonFromPC(const u16 *eventData) return (const u16 *)boxIdxs + 1; } -static u16 *BufferQuestLogData_DepositedMonInPC(u16 *a0, const u16 *eventData) +static u16 *RecordEvent_DepositedMonInPC(u16 *dest, const u16 *eventData) { u16 *r2; - r2 = sub_8113DE0(QL_EVENT_DEPOSITED_MON_PC, a0); + r2 = RecordEventHeader(QL_EVENT_DEPOSITED_MON_PC, dest); if (r2 == NULL) return NULL; r2[0] = eventData[0]; @@ -1409,10 +1640,10 @@ static u16 *BufferQuestLogData_DepositedMonInPC(u16 *a0, const u16 *eventData) return r2 + 2; } -static const u16 *BufferQuestLogText_DepositedMonInPC(const u16 *eventData) +static const u16 *LoadEvent_DepositedMonInPC(const u16 *eventData) { const u8 *boxIdxs; - eventData = sub_8113E88(QL_EVENT_DEPOSITED_MON_PC, eventData); + eventData = LoadEvent(QL_EVENT_DEPOSITED_MON_PC, eventData); boxIdxs = (const u8 *)eventData + 2; DynamicPlaceholderTextUtil_Reset(); QuestLog_GetSpeciesName(eventData[0], NULL, 0); @@ -1421,10 +1652,10 @@ static const u16 *BufferQuestLogText_DepositedMonInPC(const u16 *eventData) return (const u16 *)boxIdxs + 1; } -static u16 *BufferQuestLogData_SwitchedMultipleMons(u16 *a0, const u16 *eventData) +static u16 *RecordEvent_SwitchedMultipleMons(u16 *dest, const u16 *eventData) { u16 *r2; - r2 = sub_8113DE0(QL_EVENT_SWITCHED_MULTIPLE_MONS, a0); + r2 = RecordEventHeader(QL_EVENT_SWITCHED_MULTIPLE_MONS, dest); if (r2 == NULL) return NULL; *((u8 *)r2 + 0) = *((const u8 *)eventData + 4); @@ -1432,9 +1663,9 @@ static u16 *BufferQuestLogData_SwitchedMultipleMons(u16 *a0, const u16 *eventDat return r2 + 1; } -static const u16 *BufferQuestLogText_SwitchedMultipleMons(const u16 *eventData) +static const u16 *LoadEvent_SwitchedMultipleMons(const u16 *eventData) { - const u16 *r4 = sub_8113E88(QL_EVENT_SWITCHED_MULTIPLE_MONS, eventData); + const u16 *r4 = LoadEvent(QL_EVENT_SWITCHED_MULTIPLE_MONS, eventData); DynamicPlaceholderTextUtil_Reset(); DynamicPlaceholderTextUtil_SetPlaceholderPtr(0, GetBoxNamePtr(*((const u8 *)r4 + 0))); if (*((const u8 *)r4 + 0) == *((const u8 *)r4 + 1)) @@ -1445,63 +1676,78 @@ static const u16 *BufferQuestLogText_SwitchedMultipleMons(const u16 *eventData) return r4 + 1; } -static u16 *BufferQuestLogData_DepositedItemInPC(u16 *a0, const u16 *eventData) +#undef rSpecies1 +#undef rSpecies2 +#undef rBox1 +#undef rBox2 + +#define rItemId record[0] + +static u16 *RecordEvent_DepositedItemInPC(u16 *dest, const struct QuestLogEvent_Item * data) { - a0 = sub_8113DE0(QL_EVENT_DEPOSITED_ITEM_PC, a0); - if (a0 == NULL) + u16 * record = RecordEventHeader(QL_EVENT_DEPOSITED_ITEM_PC, dest); + if (record == NULL) return NULL; - a0[0] = eventData[0]; - return a0 + 1; + rItemId = data->itemId; + return record + 1; } -static const u16 *BufferQuestLogText_DepositedItemInPC(const u16 *eventData) +static const u16 *LoadEvent_DepositedItemInPC(const u16 *eventData) { - const u16 *r4 = sub_8113E88(QL_EVENT_DEPOSITED_ITEM_PC, eventData); - CopyItemName(r4[0], gStringVar1); + const u16 *record = LoadEvent(QL_EVENT_DEPOSITED_ITEM_PC, eventData); + CopyItemName(rItemId, gStringVar1); StringExpandPlaceholders(gStringVar4, gText_QuestLog_StoredItemInPC); - return r4 + 1; + return record + 1; } -static u16 *BufferQuestLogData_WithdrewItemFromPC(u16 *a0, const u16 *eventData) +static u16 *RecordEvent_WithdrewItemFromPC(u16 *dest, const struct QuestLogEvent_Item * data) { - a0 = sub_8113DE0(QL_EVENT_WITHDREW_ITEM_PC, a0); - if (a0 == NULL) + u16 * record = RecordEventHeader(QL_EVENT_WITHDREW_ITEM_PC, dest); + if (record == NULL) return NULL; - a0[0] = eventData[0]; - return a0 + 1; + rItemId = data->itemId; + return record + 1; } -static const u16 *BufferQuestLogText_WithdrewItemFromPC(const u16 *eventData) +static const u16 *LoadEvent_WithdrewItemFromPC(const u16 *eventData) { - const u16 *r4 = sub_8113E88(QL_EVENT_WITHDREW_ITEM_PC, eventData); - CopyItemName(r4[0], gStringVar1); + const u16 *record = LoadEvent(QL_EVENT_WITHDREW_ITEM_PC, eventData); + CopyItemName(rItemId, gStringVar1); StringExpandPlaceholders(gStringVar4, gText_QuestLog_WithdrewItemFromPC); - return r4 + 1; + return record + 1; } -u16 *BufferQuestLogData_DefeatedTrainer_(u16 eventId, u16 *a1, const u16 *a2) +#undef rItemId + +#define rSpeciesOpponent record[0] +#define rSpeciesPlayer record[1] +#define rTrainerId record[2] +#define rMapSec (*((u8*)&record[3] + 0)) // 1st byte of record[3] +#define rHpFractionId (*((u8*)&record[3] + 1)) // 2nd byte of record[3] + +static u16 *RecordEvent_DefeatedTrainer(u16 eventId, u16 *dest, const struct QuestLogEvent_TrainerBattle * data) { - a1 = sub_8113DE0(eventId, a1); - if (a1 == NULL) + u16 * record = RecordEventHeader(eventId, dest); + if (record == NULL) return NULL; - a1[0] = a2[1]; - a1[1] = a2[2]; - a1[2] = a2[0]; - *((u8 *)a1 + 6) = *((const u8 *)a2 + 7); - *((u8 *)a1 + 7) = *((const u8 *)a2 + 6); - return a1 + 4; + rSpeciesOpponent = data->speciesOpponent; + rSpeciesPlayer = data->speciesPlayer; + rTrainerId = data->trainerId; + rMapSec = data->mapSec; + rHpFractionId = data->hpFractionId; + return record + 4; } -static u16 *BufferQuestLogData_DefeatedGymLeader(u16 *a0, const u16 *eventData) +static u16 *RecordEvent_DefeatedGymLeader(u16 *dest, const struct QuestLogEvent_TrainerBattle * data) { - sEventShouldNotRecordSteps = 1; - return BufferQuestLogData_DefeatedTrainer_(QL_EVENT_DEFEATED_GYM_LEADER, a0, eventData); + sStepRecordingMode = STEP_RECORDING_MODE_DISABLED; + return RecordEvent_DefeatedTrainer(QL_EVENT_DEFEATED_GYM_LEADER, dest, data); } -static const u16 *BufferQuestLogText_DefeatedGymLeader(const u16 *eventData) +static const u16 *LoadEvent_DefeatedGymLeader(const u16 *eventData) { const u8 *r6; - eventData = sub_8113E88(QL_EVENT_DEFEATED_GYM_LEADER, eventData); + eventData = LoadEvent(QL_EVENT_DEFEATED_GYM_LEADER, eventData); r6 = (const u8 *)eventData + 6; DynamicPlaceholderTextUtil_Reset(); GetMapNameGeneric(gStringVar1, r6[0]); @@ -1514,33 +1760,33 @@ static const u16 *BufferQuestLogText_DefeatedGymLeader(const u16 *eventData) return eventData + 4; } -static u16 *BufferQuestLogData_DefeatedWildMon(u16 *a0, const u16 *eventData) +static u16 *RecordEvent_DefeatedWildMon(u16 *dest, const struct QuestLogEvent_WildBattle * data) { - u16 *r4 = a0; - u8 *r5 = (u8 *)a0 + 8; - if (!sub_8110944(r4, sQuestLogEventCmdSizes[QL_EVENT_DEFEATED_WILD_MON])) + u16 *body = dest; + u8 *footer = (u8 *)dest + sizeof(struct QuestLogEvent_WildBattle); + if (!QL_IsRoomToSaveEvent(body, sQuestLogEventCmdSizes[QL_EVENT_DEFEATED_WILD_MON])) return NULL; - if (r5[0] == 0 && r5[1] == 0) + if (footer[0] == 0 && footer[1] == 0) { - r4[0] = QL_EVENT_DEFEATED_WILD_MON; - r4[1] = sQuestLogCursor; + body[0] = QL_EVENT_DEFEATED_WILD_MON; + body[1] = gQuestLogCurActionIdx; } - if (eventData[0]) - r4[2] = eventData[0]; - if (eventData[1]) - r4[3] = eventData[1]; - if (eventData[0] && r5[0] != 0xFF) - r5[0]++; - if (eventData[1] && r5[1] != 0xFF) - r5[1]++; - r5[2] = *((const u8 *)eventData + 4); - return (u16 *)(r5 + 4); + if (data->defeatedSpecies != SPECIES_NONE) + body[2] = data->defeatedSpecies; + if (data->caughtSpecies != SPECIES_NONE) + body[3] = data->caughtSpecies; + if (data->defeatedSpecies != SPECIES_NONE && footer[0] != 0xFF) + footer[0]++; + if (data->caughtSpecies != SPECIES_NONE && footer[1] != 0xFF) + footer[1]++; + footer[2] = data->mapSec; + return (u16 *)(footer + 4); } -static const u16 *BufferQuestLogText_DefeatedWildMon(const u16 *a0) +static const u16 *LoadEvent_DefeatedWildMon(const u16 *a0) { const u8 *data; - if (!sub_8110944(a0, sQuestLogEventCmdSizes[QL_EVENT_DEFEATED_WILD_MON])) + if (!QL_IsRoomToSaveEvent(a0, sQuestLogEventCmdSizes[QL_EVENT_DEFEATED_WILD_MON])) return NULL; data = (const u8 *)a0 + 8; @@ -1602,16 +1848,16 @@ static bool8 IsSpeciesFromSpecialEncounter(u16 species) return FALSE; } -static u16 *BufferQuestLogData_DefeatedEliteFourMember(u16 *a0, const u16 *eventData) +static u16 *RecordEvent_DefeatedEliteFourMember(u16 *dest, const struct QuestLogEvent_TrainerBattle * data) { - sEventShouldNotRecordSteps = 1; - return BufferQuestLogData_DefeatedTrainer_(QL_EVENT_DEFEATED_E4_MEMBER, a0, eventData); + sStepRecordingMode = STEP_RECORDING_MODE_DISABLED; + return RecordEvent_DefeatedTrainer(QL_EVENT_DEFEATED_E4_MEMBER, dest, data); } -static const u16 *BufferQuestLogText_DefeatedEliteFourMember(const u16 *eventData) +static const u16 *LoadEvent_DefeatedEliteFourMember(const u16 *eventData) { const u8 *r5; - eventData = sub_8113E88(QL_EVENT_DEFEATED_E4_MEMBER, eventData); + eventData = LoadEvent(QL_EVENT_DEFEATED_E4_MEMBER, eventData); r5 = (const u8 *)eventData + 6; DynamicPlaceholderTextUtil_Reset(); DynamicPlaceholderTextUtil_SetPlaceholderPtr(0, gTrainers[eventData[2]].trainerName); @@ -1622,29 +1868,29 @@ static const u16 *BufferQuestLogText_DefeatedEliteFourMember(const u16 *eventDat return eventData + 4; } -static u16 *BufferQuestLogData_DefeatedChampion(u16 *a0, const u16 *eventData) +static u16 *RecordEvent_DefeatedChampion(u16 *dest, const struct QuestLogEvent_TrainerBattle * data) { - if (!sub_8110944(a0, sQuestLogEventCmdSizes[QL_EVENT_DEFEATED_CHAMPION])) + if (!QL_IsRoomToSaveEvent(dest, sQuestLogEventCmdSizes[QL_EVENT_DEFEATED_CHAMPION])) return NULL; - a0[0] = QL_EVENT_DEFEATED_CHAMPION | (2 << 12); - a0[1] = sQuestLogCursor; - a0[2] = eventData[1]; - a0[3] = eventData[2]; - *((u8 *)a0 + 8) = *((const u8 *)eventData + 6); - sEventShouldNotRecordSteps = 1; - return a0 + 5; + dest[0] = QL_EVENT_DEFEATED_CHAMPION | (2 << QL_CMD_COUNT_SHIFT); // Event will run two additional times, for each state in LoadEvent_DefeatedChampion + dest[1] = gQuestLogCurActionIdx; + dest[2] = data->speciesOpponent; + dest[3] = data->speciesPlayer; + *((u8 *)dest + 8) = data->hpFractionId; + sStepRecordingMode = STEP_RECORDING_MODE_DISABLED; + return dest + 5; } -static const u16 *BufferQuestLogText_DefeatedChampion(const u16 *a0) +static const u16 *LoadEvent_DefeatedChampion(const u16 *a0) { const u8 *r5; - if (!sub_8110944(a0, sQuestLogEventCmdSizes[QL_EVENT_DEFEATED_CHAMPION])) + if (!QL_IsRoomToSaveEvent(a0, sQuestLogEventCmdSizes[QL_EVENT_DEFEATED_CHAMPION])) return NULL; r5 = (const u8 *)a0 + 8; DynamicPlaceholderTextUtil_Reset(); - switch (gUnknown_203B044.unk_2) + switch (gQuestLogRepeatEventTracker.counter) { case 0: DynamicPlaceholderTextUtil_SetPlaceholderPtr(0, gSaveBlock2Ptr->playerName); @@ -1666,15 +1912,15 @@ static const u16 *BufferQuestLogText_DefeatedChampion(const u16 *a0) return (const u16 *)(r5 + 2); } -static u16 *BufferQuestLogData_DefeatedTrainer(u16 *a0, const u16 *eventData) +static u16 *RecordEvent_DefeatedNormalTrainer(u16 *dest, const struct QuestLogEvent_TrainerBattle * data) { - sEventShouldNotRecordSteps = 1; - return BufferQuestLogData_DefeatedTrainer_(QL_EVENT_DEFEATED_TRAINER, a0, eventData); + sStepRecordingMode = STEP_RECORDING_MODE_DISABLED; + return RecordEvent_DefeatedTrainer(QL_EVENT_DEFEATED_TRAINER, dest, data); } -static const u16 *BufferQuestLogText_DefeatedTrainer(const u16 *eventData) +static const u16 *LoadEvent_DefeatedTrainer(const u16 *eventData) { - const u16 *r5 = sub_8113E88(QL_EVENT_DEFEATED_TRAINER, eventData); + const u16 *r5 = LoadEvent(QL_EVENT_DEFEATED_TRAINER, eventData); const u8 *r6 = (const u8 *)r5 + 6; DynamicPlaceholderTextUtil_Reset(); GetMapNameGeneric(gStringVar1, r6[0]); @@ -1694,248 +1940,120 @@ static const u16 *BufferQuestLogText_DefeatedTrainer(const u16 *eventData) return (const u16 *)(r6 + 2); } -static const u8 *const sLocationNameTexts[] = - { - [QL_LOCATION_HOME] = gText_QuestLog_Home, - [QL_LOCATION_OAKS_LAB] = gText_QuestLog_OakResearchLab, - [QL_LOCATION_VIRIDIAN_GYM] = gText_QuestLog_Gym, - [QL_LOCATION_LEAGUE_GATE_1] = gText_QuestLog_PokemonLeagueGate, - [QL_LOCATION_LEAGUE_GATE_2] = gText_QuestLog_PokemonLeagueGate, - [QL_LOCATION_VIRIDIAN_FOREST_1] = gText_QuestLog_ViridianForest, - [QL_LOCATION_VIRIDIAN_FOREST_2] = gText_QuestLog_ViridianForest, - [QL_LOCATION_PEWTER_MUSEUM] = gText_QuestLog_PewterMuseumOfScience, - [QL_LOCATION_PEWTER_GYM] = gText_QuestLog_Gym, - [QL_LOCATION_MT_MOON_1] = gText_QuestLog_MtMoon, - [QL_LOCATION_MT_MOON_2] = gText_QuestLog_MtMoon, - [QL_LOCATION_CERULEAN_GYM] = gText_QuestLog_Gym, - [QL_LOCATION_BIKE_SHOP] = gText_QuestLog_BikeShop, - [QL_LOCATION_BILLS_HOUSE] = gText_QuestLog_BillsHouse, - [QL_LOCATION_DAY_CARE] = gText_QuestLog_DayCare, - [QL_LOCATION_UNDERGROUND_PATH_1] = gText_QuestLog_UndergroundPath, - [QL_LOCATION_UNDERGROUND_PATH_2] = gText_QuestLog_UndergroundPath, - [QL_LOCATION_PKMN_FAN_CLUB] = gText_QuestLog_PokemonFanClub, - [QL_LOCATION_VERMILION_GYM] = gText_QuestLog_Gym, - [QL_LOCATION_SS_ANNE] = gText_QuestLog_SSAnne, - [QL_LOCATION_DIGLETTS_CAVE_1] = gText_QuestLog_DiglettsCave, - [QL_LOCATION_DIGLETTS_CAVE_2] = gText_QuestLog_DiglettsCave, - [QL_LOCATION_ROCK_TUNNEL_1] = gText_QuestLog_RockTunnel, - [QL_LOCATION_ROCK_TUNNEL_2] = gText_QuestLog_RockTunnel, - [QL_LOCATION_POWER_PLANT] = gText_QuestLog_PowerPlant, - [QL_LOCATION_PKMN_TOWER] = gText_QuestLog_PokemonTower, - [QL_LOCATION_VOLUNTEER_HOUSE] = gText_QuestLog_VolunteerHouse, - [QL_LOCATION_NAME_RATERS_HOUSE] = gText_QuestLog_NameRatersHouse, - [QL_LOCATION_UNDERGROUND_PATH_3] = gText_QuestLog_UndergroundPath, - [QL_LOCATION_UNDERGROUND_PATH_4] = gText_QuestLog_UndergroundPath, - [QL_LOCATION_CELADON_DEPT_STORE] = gText_QuestLog_CeladonDeptStore, - [QL_LOCATION_CELADON_MANSION] = gText_QuestLog_CeladonMansion, - [QL_LOCATION_GAME_CORNER] = gText_QuestLog_RocketGameCorner, - [QL_LOCATION_CELADON_GYM] = gText_QuestLog_Gym, - [QL_LOCATION_CELADON_RESTAURANT] = gText_QuestLog_Restaurant, - [QL_LOCATION_ROCKET_HIDEOUT] = gText_QuestLog_RocketHideout, - [QL_LOCATION_SAFARI_ZONE] = gText_QuestLog_SafariZone, - [QL_LOCATION_FUCHSIA_GYM] = gText_QuestLog_Gym, - [QL_LOCATION_WARDENS_HOME] = gText_QuestLog_WardensHome, - [QL_LOCATION_FIGHTING_DOJO] = gText_QuestLog_FightingDojo, - [QL_LOCATION_SAFFRON_GYM] = gText_QuestLog_Gym, - [QL_LOCATION_SILPH_CO] = gText_QuestLog_SilphCo, - [QL_LOCATION_SEAFOAM_ISLANDS_1] = gText_QuestLog_SeafoamIslands, - [QL_LOCATION_SEAFOAM_ISLANDS_2] = gText_QuestLog_SeafoamIslands, - [QL_LOCATION_PKMN_MANSION] = gText_QuestLog_PokemonMansion, - [QL_LOCATION_CINNABAR_GYM] = gText_QuestLog_Gym, - [QL_LOCATION_CINNABAR_LAB] = gText_QuestLog_PokemonResearchLab, - [QL_LOCATION_VICTORY_ROAD_1] = gText_QuestLog_VictoryRoad, - [QL_LOCATION_VICTORY_ROAD_2] = gText_QuestLog_VictoryRoad, - [QL_LOCATION_PKMN_LEAGUE] = gText_QuestLog_PokemonLeague, - [QL_LOCATION_CERULEAN_CAVE] = gText_QuestLog_CeruleanCave - }; +#undef rSpeciesOpponent +#undef rSpeciesPlayer +#undef rTrainerId +#undef rMapSec +#undef rHpFractionId -static const u8 *const sDepartedLocationTexts[] = - { - [QL_DEPARTED_TOWN_BUILDING] = gText_QuestLog_DepartedPlaceInTownForNextDestination, - [QL_DEPARTED_MUSEUM] = gText_QuestLog_LeftTownsLocationForNextDestination, - [QL_DEPARTED_GAME_CORNER] = gText_QuestLog_PlayedGamesAtGameCorner, - [QL_DEPARTED_HOME] = gText_QuestLog_RestedAtHome, - [QL_DEPARTED_OAKS_LAB] = gText_QuestLog_LeftOaksLab, - [QL_DEPARTED_GYM] = gText_QuestLog_GymWasFullOfToughTrainers, - [QL_DEPARTED_SAFARI_ZONE] = gText_QuestLog_HadGreatTimeInSafariZone, - [QL_DEPARTED_CAVE] = gText_QuestLog_ManagedToGetOutOfLocation, - [QL_DEPARTED_MISC_BUILDING_1] = gText_QuestLog_DepartedTheLocationForNextDestination, - [QL_DEPARTED_MISC_BUILDING_2] = gText_QuestLog_DepartedFromLocationToNextDestination - }; +#define rMapSec record[0] +#define rLocationId record[1] -static const u8 sLocationToDepartedTextId[] = - { - [QL_LOCATION_HOME] = QL_DEPARTED_HOME, - [QL_LOCATION_OAKS_LAB] = QL_DEPARTED_OAKS_LAB, - [QL_LOCATION_VIRIDIAN_GYM] = QL_DEPARTED_GYM, - [QL_LOCATION_LEAGUE_GATE_1] = QL_DEPARTED_MISC_BUILDING_1, - [QL_LOCATION_LEAGUE_GATE_2] = QL_DEPARTED_MISC_BUILDING_1, - [QL_LOCATION_VIRIDIAN_FOREST_1] = QL_DEPARTED_CAVE, - [QL_LOCATION_VIRIDIAN_FOREST_2] = QL_DEPARTED_CAVE, - [QL_LOCATION_PEWTER_MUSEUM] = QL_DEPARTED_MUSEUM, - [QL_LOCATION_PEWTER_GYM] = QL_DEPARTED_GYM, - [QL_LOCATION_MT_MOON_1] = QL_DEPARTED_CAVE, - [QL_LOCATION_MT_MOON_2] = QL_DEPARTED_CAVE, - [QL_LOCATION_CERULEAN_GYM] = QL_DEPARTED_GYM, - [QL_LOCATION_BIKE_SHOP] = QL_DEPARTED_TOWN_BUILDING, - [QL_LOCATION_BILLS_HOUSE] = QL_DEPARTED_TOWN_BUILDING, - [QL_LOCATION_DAY_CARE] = QL_DEPARTED_TOWN_BUILDING, - [QL_LOCATION_UNDERGROUND_PATH_1] = QL_DEPARTED_MISC_BUILDING_1, - [QL_LOCATION_UNDERGROUND_PATH_2] = QL_DEPARTED_MISC_BUILDING_1, - [QL_LOCATION_PKMN_FAN_CLUB] = QL_DEPARTED_TOWN_BUILDING, - [QL_LOCATION_VERMILION_GYM] = QL_DEPARTED_GYM, - [QL_LOCATION_SS_ANNE] = QL_DEPARTED_MISC_BUILDING_1, - [QL_LOCATION_DIGLETTS_CAVE_1] = QL_DEPARTED_CAVE, - [QL_LOCATION_DIGLETTS_CAVE_2] = QL_DEPARTED_CAVE, - [QL_LOCATION_ROCK_TUNNEL_1] = QL_DEPARTED_CAVE, - [QL_LOCATION_ROCK_TUNNEL_2] = QL_DEPARTED_CAVE, - [QL_LOCATION_POWER_PLANT] = QL_DEPARTED_MISC_BUILDING_1, - [QL_LOCATION_PKMN_TOWER] = QL_DEPARTED_MISC_BUILDING_1, - [QL_LOCATION_VOLUNTEER_HOUSE] = QL_DEPARTED_TOWN_BUILDING, - [QL_LOCATION_NAME_RATERS_HOUSE] = QL_DEPARTED_TOWN_BUILDING, - [QL_LOCATION_UNDERGROUND_PATH_3] = QL_DEPARTED_MISC_BUILDING_1, - [QL_LOCATION_UNDERGROUND_PATH_4] = QL_DEPARTED_MISC_BUILDING_1, - [QL_LOCATION_CELADON_DEPT_STORE] = QL_DEPARTED_TOWN_BUILDING, - [QL_LOCATION_CELADON_MANSION] = QL_DEPARTED_TOWN_BUILDING, - [QL_LOCATION_GAME_CORNER] = QL_DEPARTED_GAME_CORNER, - [QL_LOCATION_CELADON_GYM] = QL_DEPARTED_GYM, - [QL_LOCATION_CELADON_RESTAURANT] = QL_DEPARTED_TOWN_BUILDING, - [QL_LOCATION_ROCKET_HIDEOUT] = QL_DEPARTED_MISC_BUILDING_1, - [QL_LOCATION_SAFARI_ZONE] = QL_DEPARTED_SAFARI_ZONE, - [QL_LOCATION_FUCHSIA_GYM] = QL_DEPARTED_GYM, - [QL_LOCATION_WARDENS_HOME] = QL_DEPARTED_TOWN_BUILDING, - [QL_LOCATION_FIGHTING_DOJO] = QL_DEPARTED_TOWN_BUILDING, - [QL_LOCATION_SAFFRON_GYM] = QL_DEPARTED_GYM, - [QL_LOCATION_SILPH_CO] = QL_DEPARTED_MISC_BUILDING_2, - [QL_LOCATION_SEAFOAM_ISLANDS_1] = QL_DEPARTED_CAVE, - [QL_LOCATION_SEAFOAM_ISLANDS_2] = QL_DEPARTED_CAVE, - [QL_LOCATION_PKMN_MANSION] = QL_DEPARTED_MISC_BUILDING_2, - [QL_LOCATION_CINNABAR_GYM] = QL_DEPARTED_GYM, - [QL_LOCATION_CINNABAR_LAB] = QL_DEPARTED_TOWN_BUILDING, - [QL_LOCATION_VICTORY_ROAD_1] = QL_DEPARTED_CAVE, - [QL_LOCATION_VICTORY_ROAD_2] = QL_DEPARTED_CAVE, - [QL_LOCATION_PKMN_LEAGUE] = QL_DEPARTED_MISC_BUILDING_1, - [QL_LOCATION_CERULEAN_CAVE] = QL_DEPARTED_CAVE - }; - -static const u8 sGymCityMapSecs[] = { - MAPSEC_PEWTER_CITY, - MAPSEC_CERULEAN_CITY, - MAPSEC_VERMILION_CITY, - MAPSEC_CELADON_CITY, - MAPSEC_FUCHSIA_CITY, - MAPSEC_SAFFRON_CITY, - MAPSEC_CINNABAR_ISLAND, - MAPSEC_VIRIDIAN_CITY -}; - -static const u8 *const sUsedFieldMoveTexts[] = - { - [FIELD_MOVE_FLASH] = gText_QuestLog_UsedFlash, - [FIELD_MOVE_CUT] = gText_QuestLog_UsedCut, - [FIELD_MOVE_FLY] = gText_QuestLog_UsedFly, - [FIELD_MOVE_STRENGTH] = gText_QuestLog_UsedStrength, - [FIELD_MOVE_SURF] = gText_QuestLog_UsedSurf, - [FIELD_MOVE_ROCK_SMASH] = gText_QuestLog_UsedRockSmash, - [FIELD_MOVE_WATERFALL] = gText_QuestLog_UsedWaterfall, - [FIELD_MOVE_TELEPORT] = gText_QuestLog_UsedTeleportToLocation, - [FIELD_MOVE_DIG] = gText_QuestLog_UsedDigInLocation, - [FIELD_MOVE_MILK_DRINK] = gText_QuestLog_UsedMilkDrink, - [FIELD_MOVE_SOFT_BOILED] = gText_QuestLog_UsedSoftboiled, - [FIELD_MOVE_SWEET_SCENT] = gText_QuestLog_UsedSweetScent - }; - -static u16 *BufferQuestLogData_DepartedLocation(u16 *a0, const u16 *eventData) +static u16 *RecordEvent_DepartedLocation(u16 *dest, const struct QuestLogEvent_Departed * data) { - u16 *r2 = sub_8113DE0(QL_EVENT_DEPARTED, a0); - if (r2 == NULL) + u8 *record = (u8 *)RecordEventHeader(QL_EVENT_DEPARTED, dest); + if (record == NULL) return NULL; - *((u8 *)r2 + 0) = *((const u8 *)eventData + 0); - if ((*((u8 *)r2 + 1) = *((const u8 *)eventData + 1)) == QL_LOCATION_SAFARI_ZONE) - sEventShouldNotRecordSteps = 1; - return r2 + 1; + + rMapSec = data->mapSec; + rLocationId = data->locationId; + if (rLocationId == QL_LOCATION_SAFARI_ZONE) + sStepRecordingMode = STEP_RECORDING_MODE_DISABLED; + + return (u16 *)(record + 2); } -static const u16 *BufferQuestLogText_DepartedLocation(const u16 *eventData) +static const u16 *LoadEvent_DepartedLocation(const u16 *eventData) { - u8 r4, locationId; - const u16 *r5 = sub_8113E88(QL_EVENT_DEPARTED, eventData); - const u8 *r5_2 = (const u8 *)r5 + 0; - locationId = r5_2[1]; - GetMapNameGeneric(gStringVar1, r5_2[0]); + u8 i, locationId; + const u8 *record = (const u8 *)LoadEvent(QL_EVENT_DEPARTED, eventData); + + locationId = rLocationId; + GetMapNameGeneric(gStringVar1, rMapSec); StringCopy(gStringVar2, sLocationNameTexts[locationId]); if (sLocationToDepartedTextId[locationId] == QL_DEPARTED_GYM) { - for (r4 = 0; r4 < NELEMS(sGymCityMapSecs); r4++) + for (i = 0; i < NUM_BADGES; i++) { - if (r5_2[0] != sGymCityMapSecs[r4]) + if (rMapSec != sGymCityMapSecs[i]) continue; - if (FlagGet(FLAG_BADGE01_GET + r4) == TRUE) + if (FlagGet(FLAG_BADGE01_GET + i) == TRUE) StringExpandPlaceholders(gStringVar4, gText_QuestLog_DepartedGym); else StringExpandPlaceholders(gStringVar4, gText_QuestLog_GymWasFullOfToughTrainers); break; } - if (r4 == 8) + if (i == NUM_BADGES) StringExpandPlaceholders(gStringVar4, sDepartedLocationTexts[sLocationToDepartedTextId[locationId]]); } else StringExpandPlaceholders(gStringVar4, sDepartedLocationTexts[sLocationToDepartedTextId[locationId]]); - return (const u16 *)(r5_2 + 2); + return (const u16 *)(record + 2); } +#undef rMapSec +#undef rLocationId + void SetQLPlayedTheSlots(void) { sPlayedTheSlots = TRUE; } -static bool8 ShouldRegisterEvent_HandleDeparted(u16 eventId, const u16 *eventData) +static bool8 ShouldRegisterEvent_HandleDeparted(u16 eventId, const u16 * genericData) { + const struct QuestLogEvent_Departed * data; + if (eventId != QL_EVENT_DEPARTED) { - sLastDepartedMap = 0; + sLastDepartedLocation = 0; return TRUE; } - if (sLastDepartedMap == *((u8 *)eventData + 1) + 1) + + data = (struct QuestLogEvent_Departed *)genericData; + + if (sLastDepartedLocation == data->locationId + 1) return FALSE; - sLastDepartedMap = *((u8 *)eventData + 1) + 1; + sLastDepartedLocation = data->locationId + 1; return TRUE; } -static bool8 ShouldRegisterEvent_HandleGameCorner(u16 eventId, const u16 *eventData) +static bool8 ShouldRegisterEvent_DepartedGameCorner(u16 eventId, const u16 * genericData) { + const struct QuestLogEvent_Departed * data; + if (eventId != QL_EVENT_DEPARTED) return TRUE; - // Bug: should be QL_LOCATION_GAME_CORNER + 1 - if (*((u8 *)eventData + 1) == QL_LOCATION_GAME_CORNER && !sPlayedTheSlots) + data = (struct QuestLogEvent_Departed *)genericData; + + if (data->locationId == QL_LOCATION_GAME_CORNER && !sPlayedTheSlots) return FALSE; sPlayedTheSlots = FALSE; return TRUE; } -static u16 *BufferQuestLogData_UsedFieldMove(u16 *a0, const u16 *eventData) +static u16 *RecordEvent_UsedFieldMove(u16 *dest, const struct QuestLogEvent_FieldMove * data) { - u8 *r3; - a0 = sub_8113DE0(QL_EVENT_USED_FIELD_MOVE, a0); - if (a0 == NULL) + u8 *record; + dest = RecordEventHeader(QL_EVENT_USED_FIELD_MOVE, dest); + if (dest == NULL) return NULL; - a0[0] = eventData[0]; - r3 = (u8 *)a0 + 2; - r3[0] = *((const u8 *)eventData + 2); - r3[1] = *((const u8 *)eventData + 3); - if (r3[0] == FIELD_MOVE_TELEPORT || r3[0] == FIELD_MOVE_DIG) - sEventShouldNotRecordSteps = 2; + dest[0] = data->species; + record = (u8 *)dest + 2; + record[0] = data->fieldMove; + record[1] = data->mapSec; + if (record[0] == FIELD_MOVE_TELEPORT || record[0] == FIELD_MOVE_DIG) + sStepRecordingMode = STEP_RECORDING_MODE_DISABLED_UNTIL_DEPART; else - sEventShouldNotRecordSteps = 1; - return (u16 *)(r3 + 2); + sStepRecordingMode = STEP_RECORDING_MODE_DISABLED; + return (u16 *)(record + 2); } -static const u16 *BufferQuestLogText_UsedFieldMove(const u16 *eventData) +static const u16 *LoadEvent_UsedFieldMove(const u16 *eventData) { - const u16 *r4 = sub_8113E88(QL_EVENT_USED_FIELD_MOVE, eventData); + const u16 *r4 = LoadEvent(QL_EVENT_USED_FIELD_MOVE, eventData); const u8 *r5 = (const u8 *)r4 + 2; QuestLog_GetSpeciesName(r4[0], gStringVar1, 0); if (r5[1] != 0xFF) @@ -1944,7 +2062,7 @@ static const u16 *BufferQuestLogText_UsedFieldMove(const u16 *eventData) // If used Teleport, get name of destination if (r5[0] == FIELD_MOVE_TELEPORT) { - if (r5[1] == 0x58) + if (r5[1] == MAPSEC_PALLET_TOWN) StringCopy(gStringVar3, gText_QuestLog_Home); else StringCopy(gStringVar3, gText_PokemonCenter); @@ -1954,23 +2072,23 @@ static const u16 *BufferQuestLogText_UsedFieldMove(const u16 *eventData) return (const u16 *)(r5 + 2); } -static u16 *BufferQuestLogData_BoughtItem(u16 *a0, const u16 *eventData) +static u16 *RecordEvent_BoughtItem(u16 *dest, const struct QuestLogEvent_Shop * data) { - a0 = sub_8113DE0(QL_EVENT_BOUGHT_ITEM, a0); - if (a0 == NULL) + dest = RecordEventHeader(QL_EVENT_BOUGHT_ITEM, dest); + if (dest == NULL) return NULL; - a0[0] = eventData[2]; - a0[1] = eventData[3]; - a0[2] = *((const u32 *)eventData) >> 16; - a0[3] = *((const u32 *)eventData); - *((u8 *)a0 + 8) = *((const u8 *)eventData + 8); - *((u8 *)a0 + 9) = 1; - return a0 + 5; + dest[0] = data->lastItemId; + dest[1] = data->itemQuantity; + dest[2] = data->totalMoney >> 16; + dest[3] = data->totalMoney; + *((u8 *)dest + 8) = data->mapSec; + *((u8 *)dest + 9) = TRUE; // data->hasMultipleTransactions ignored for some reason. It's assumed true if quantity >= 2 + return dest + 5; } -static const u16 *BufferQuestLogText_BoughtItem(const u16 *eventData) +static const u16 *LoadEvent_BoughtItem(const u16 *eventData) { - const u16 *r4 = sub_8113E88(QL_EVENT_BOUGHT_ITEM, eventData); + const u16 *r4 = LoadEvent(QL_EVENT_BOUGHT_ITEM, eventData); const u8 *r7 = (const u8 *)r4 + 8; u32 r6 = (r4[2] << 16) + r4[3]; DynamicPlaceholderTextUtil_Reset(); @@ -1988,23 +2106,23 @@ static const u16 *BufferQuestLogText_BoughtItem(const u16 *eventData) return (const u16 *)(r7 + 2); } -static u16 *BufferQuestLogData_SoldItem(u16 *a0, const u16 *eventData) +static u16 *RecordEvent_SoldItem(u16 *dest, const struct QuestLogEvent_Shop * data) { - a0 = sub_8113DE0(QL_EVENT_SOLD_ITEM, a0); - if (a0 == NULL) + dest = RecordEventHeader(QL_EVENT_SOLD_ITEM, dest); + if (dest == NULL) return NULL; - a0[0] = eventData[2]; - a0[1] = eventData[3]; - a0[2] = *((const u32 *)eventData) >> 16; - a0[3] = *((const u32 *)eventData); - *((u8 *)a0 + 8) = *((const u8 *)eventData + 8); - *((u8 *)a0 + 9) = *((const u8 *)eventData + 9); - return a0 + 5; + dest[0] = data->lastItemId; + dest[1] = data->itemQuantity; + dest[2] = data->totalMoney >> 16; + dest[3] = data->totalMoney; + *((u8 *)dest + 8) = data->mapSec; + *((u8 *)dest + 9) = data->hasMultipleTransactions; + return dest + 5; } -static const u16 *BufferQuestLogText_SoldItem(const u16 *eventData) +static const u16 *LoadEvent_SoldItem(const u16 *eventData) { - const u16 *r5 = sub_8113E88(QL_EVENT_SOLD_ITEM, eventData); + const u16 *r5 = LoadEvent(QL_EVENT_SOLD_ITEM, eventData); const u8 *r7 = (const u8 *) r5 + 8; u32 r6 = (r5[2] << 16) + r5[3]; DynamicPlaceholderTextUtil_Reset(); @@ -2035,19 +2153,19 @@ static const u16 *BufferQuestLogText_SoldItem(const u16 *eventData) return (const u16 *)(r7 + 2); } -static u16 *BufferQuestLogData_ObtainedItem(u16 *a0, const u16 *eventData) +static u16 *RecordEvent_ObtainedStoryItem(u16 *dest, const struct QuestLogEvent_StoryItem * data) { - a0 = sub_8113DE0(QL_EVENT_OBTAINED_ITEM, a0); - if (a0 == NULL) + dest = RecordEventHeader(QL_EVENT_OBTAINED_STORY_ITEM, dest); + if (dest == NULL) return NULL; - a0[0] = eventData[0]; - *((u8 *)a0 + 2) = *((const u8 *)eventData + 2); - return a0 + 2; + dest[0] = data->itemId; + *((u8 *)dest + 2) = data->mapSec; + return dest + 2; } -static const u16 *BufferQuestLogText_ObtainedItem(const u16 *eventData) +static const u16 *LoadEvent_ObtainedStoryItem(const u16 *eventData) { - const u16 *r4 = sub_8113E88(QL_EVENT_OBTAINED_ITEM, eventData); + const u16 *r4 = LoadEvent(QL_EVENT_OBTAINED_STORY_ITEM, eventData); const u8 *r5 = (const u8 *)r4 + 2; GetMapNameGeneric(gStringVar1, r5[0]); StringCopy(gStringVar2, ItemId_GetName(r4[0])); @@ -2055,27 +2173,6 @@ static const u16 *BufferQuestLogText_ObtainedItem(const u16 *eventData) return (const u16 *)(r5 + 2); } -static const u16 sQuestLogWorldMapFlags[] = - { - FLAG_WORLD_MAP_VIRIDIAN_CITY, - FLAG_WORLD_MAP_PEWTER_CITY, - FLAG_WORLD_MAP_CERULEAN_CITY, - FLAG_WORLD_MAP_LAVENDER_TOWN, - FLAG_WORLD_MAP_VERMILION_CITY, - FLAG_WORLD_MAP_CELADON_CITY, - FLAG_WORLD_MAP_FUCHSIA_CITY, - FLAG_WORLD_MAP_CINNABAR_ISLAND, - FLAG_WORLD_MAP_INDIGO_PLATEAU_EXTERIOR, - FLAG_WORLD_MAP_SAFFRON_CITY, - FLAG_WORLD_MAP_ONE_ISLAND, - FLAG_WORLD_MAP_TWO_ISLAND, - FLAG_WORLD_MAP_THREE_ISLAND, - FLAG_WORLD_MAP_FOUR_ISLAND, - FLAG_WORLD_MAP_FIVE_ISLAND, - FLAG_WORLD_MAP_SEVEN_ISLAND, - FLAG_WORLD_MAP_SIX_ISLAND - }; - void QuestLog_RecordEnteredMap(u16 worldMapFlag) { s32 i; @@ -2083,9 +2180,9 @@ void QuestLog_RecordEnteredMap(u16 worldMapFlag) if (QL_IS_PLAYBACK_STATE) return; - for (i = 0; i < (int)NELEMS(sQuestLogWorldMapFlags); i++) + for (i = 0; i < (int)ARRAY_COUNT(sWorldMapFlags); i++) { - if (worldMapFlag == sQuestLogWorldMapFlags[i]) + if (worldMapFlag == sWorldMapFlags[i]) { if (!FlagGet(worldMapFlag)) { @@ -2102,38 +2199,37 @@ void QuestLog_RecordEnteredMap(u16 worldMapFlag) } } -void sub_8115798(void) +void SetQuestLogEvent_Arrived(void) { - u16 sp0; if (!QL_IS_PLAYBACK_STATE) { if (sNewlyEnteredMap) { - sp0 = gMapHeader.regionMapSectionId; - SetQuestLogEvent(QL_EVENT_ARRIVED, &sp0); + u16 mapSec = gMapHeader.regionMapSectionId; + SetQuestLogEvent(QL_EVENT_ARRIVED, &mapSec); sNewlyEnteredMap = FALSE; } } } -static u16 *BufferQuestLogData_ArrivedInLocation(u16 *a0, const u16 *eventData) +static u16 *RecordEvent_ArrivedInLocation(u16 *dest, const u16 * data) { - a0 = sub_8113DE0(QL_EVENT_ARRIVED, a0); - if (a0 == NULL) + dest = RecordEventHeader(QL_EVENT_ARRIVED, dest); + if (dest == NULL) return NULL; - a0[0] = eventData[0]; - return a0 + 1; + dest[0] = data[0]; + return dest + 1; } -static const u16 *BufferQuestLogText_ArrivedInLocation(const u16 *eventData) +static const u16 *LoadEvent_ArrivedInLocation(const u16 *eventData) { - const u16 *r4 = sub_8113E88(QL_EVENT_ARRIVED, eventData); + const u16 *r4 = LoadEvent(QL_EVENT_ARRIVED, eventData); GetMapNameGeneric(gStringVar1, (u8)r4[0]); StringExpandPlaceholders(gStringVar4, gText_QuestLog_ArrivedInLocation); return r4 + 1; } -static void BufferLinkPartnersName(u8 *dest) +static void TranslateLinkPartnersName(u8 *dest) { s32 i; if (*dest++ == EXT_CTRL_CODE_BEGIN && *dest++ == EXT_CTRL_CODE_JPN) diff --git a/src/quest_log_objects.c b/src/quest_log_objects.c index 27f32b450..1e12ca437 100644 --- a/src/quest_log_objects.c +++ b/src/quest_log_objects.c @@ -4,95 +4,95 @@ #include "field_player_avatar.h" #include "metatile_behavior.h" -void SetQuestLogObjectEventsData(struct QuestLog * questLog) +void QL_RecordObjects(struct QuestLogScene * questLog) { u32 i; for (i = 0; i < OBJECT_EVENTS_COUNT; i++) { - questLog->unk_008[i].active = gObjectEvents[i].active; - questLog->unk_008[i].triggerGroundEffectsOnStop = gObjectEvents[i].triggerGroundEffectsOnStop; - questLog->unk_008[i].disableCoveringGroundEffects = gObjectEvents[i].disableCoveringGroundEffects; - questLog->unk_008[i].landingJump = gObjectEvents[i].landingJump; - questLog->unk_008[i].frozen = gObjectEvents[i].frozen; - questLog->unk_008[i].facingDirectionLocked = gObjectEvents[i].facingDirectionLocked; - questLog->unk_008[i].disableAnim = gObjectEvents[i].disableAnim; - questLog->unk_008[i].enableAnim = gObjectEvents[i].enableAnim; - questLog->unk_008[i].inanimate = gObjectEvents[i].inanimate; - questLog->unk_008[i].invisible = gObjectEvents[i].invisible; - questLog->unk_008[i].offScreen = gObjectEvents[i].offScreen; - questLog->unk_008[i].trackedByCamera = gObjectEvents[i].trackedByCamera; - questLog->unk_008[i].isPlayer = gObjectEvents[i].isPlayer; - questLog->unk_008[i].spriteAnimPausedBackup = gObjectEvents[i].spriteAnimPausedBackup; - questLog->unk_008[i].spriteAffineAnimPausedBackup = gObjectEvents[i].spriteAffineAnimPausedBackup; - questLog->unk_008[i].disableJumpLandingGroundEffect = gObjectEvents[i].disableJumpLandingGroundEffect; - questLog->unk_008[i].fixedPriority = gObjectEvents[i].fixedPriority; - questLog->unk_008[i].mapobj_unk_18 = gObjectEvents[i].facingDirection; - questLog->unk_008[i].mapobj_unk_0B_0 = gObjectEvents[i].currentElevation; - questLog->unk_008[i].elevation = gObjectEvents[i].previousElevation; - questLog->unk_008[i].graphicsId = gObjectEvents[i].graphicsId; - questLog->unk_008[i].animPattern = gObjectEvents[i].movementType; - questLog->unk_008[i].trainerType = gObjectEvents[i].trainerType; - questLog->unk_008[i].localId = gObjectEvents[i].localId; - questLog->unk_008[i].mapNum = gObjectEvents[i].mapNum; - questLog->unk_008[i].mapGroup = gObjectEvents[i].mapGroup; - questLog->unk_008[i].x = gObjectEvents[i].currentCoords.x; - questLog->unk_008[i].y = gObjectEvents[i].currentCoords.y; - questLog->unk_008[i].trainerRange_berryTreeId = gObjectEvents[i].trainerRange_berryTreeId; - questLog->unk_008[i].previousMetatileBehavior = gObjectEvents[i].previousMetatileBehavior; - questLog->unk_008[i].directionSequenceIndex = gObjectEvents[i].directionSequenceIndex; - questLog->unk_008[i].animId = gObjectEvents[i].playerCopyableMovement; + questLog->objectEvents[i].active = gObjectEvents[i].active; + questLog->objectEvents[i].triggerGroundEffectsOnStop = gObjectEvents[i].triggerGroundEffectsOnStop; + questLog->objectEvents[i].disableCoveringGroundEffects = gObjectEvents[i].disableCoveringGroundEffects; + questLog->objectEvents[i].landingJump = gObjectEvents[i].landingJump; + questLog->objectEvents[i].frozen = gObjectEvents[i].frozen; + questLog->objectEvents[i].facingDirectionLocked = gObjectEvents[i].facingDirectionLocked; + questLog->objectEvents[i].disableAnim = gObjectEvents[i].disableAnim; + questLog->objectEvents[i].enableAnim = gObjectEvents[i].enableAnim; + questLog->objectEvents[i].inanimate = gObjectEvents[i].inanimate; + questLog->objectEvents[i].invisible = gObjectEvents[i].invisible; + questLog->objectEvents[i].offScreen = gObjectEvents[i].offScreen; + questLog->objectEvents[i].trackedByCamera = gObjectEvents[i].trackedByCamera; + questLog->objectEvents[i].isPlayer = gObjectEvents[i].isPlayer; + questLog->objectEvents[i].spriteAnimPausedBackup = gObjectEvents[i].spriteAnimPausedBackup; + questLog->objectEvents[i].spriteAffineAnimPausedBackup = gObjectEvents[i].spriteAffineAnimPausedBackup; + questLog->objectEvents[i].disableJumpLandingGroundEffect = gObjectEvents[i].disableJumpLandingGroundEffect; + questLog->objectEvents[i].fixedPriority = gObjectEvents[i].fixedPriority; + questLog->objectEvents[i].facingDirection = gObjectEvents[i].facingDirection; + questLog->objectEvents[i].currentElevation = gObjectEvents[i].currentElevation; + questLog->objectEvents[i].previousElevation = gObjectEvents[i].previousElevation; + questLog->objectEvents[i].graphicsId = gObjectEvents[i].graphicsId; + questLog->objectEvents[i].movementType = gObjectEvents[i].movementType; + questLog->objectEvents[i].trainerType = gObjectEvents[i].trainerType; + questLog->objectEvents[i].localId = gObjectEvents[i].localId; + questLog->objectEvents[i].mapNum = gObjectEvents[i].mapNum; + questLog->objectEvents[i].mapGroup = gObjectEvents[i].mapGroup; + questLog->objectEvents[i].x = gObjectEvents[i].currentCoords.x; + questLog->objectEvents[i].y = gObjectEvents[i].currentCoords.y; + questLog->objectEvents[i].trainerRange_berryTreeId = gObjectEvents[i].trainerRange_berryTreeId; + questLog->objectEvents[i].previousMetatileBehavior = gObjectEvents[i].previousMetatileBehavior; + questLog->objectEvents[i].directionSequenceIndex = gObjectEvents[i].directionSequenceIndex; + questLog->objectEvents[i].animId = gObjectEvents[i].playerCopyableMovement; } } -void SetSav1ObjectEventsFromQuestLog(const struct QuestLog * questLog, const struct ObjectEventTemplate * templates) +void QL_LoadObjects(const struct QuestLogScene * questLog, const struct ObjectEventTemplate * templates) { u32 i, j; - const struct QuestLogObjectEvent * questLogObjectEvents = questLog->unk_008; + const struct QuestLogObjectEvent * questLogObjectEvents = questLog->objectEvents; CpuFill16(0, gObjectEvents, sizeof(gObjectEvents)); for (i = 0; i < OBJECT_EVENTS_COUNT; i++) { - gObjectEvents[i].active = questLogObjectEvents[i].active; - gObjectEvents[i].triggerGroundEffectsOnStop = questLogObjectEvents[i].triggerGroundEffectsOnStop; - gObjectEvents[i].disableCoveringGroundEffects = questLogObjectEvents[i].disableCoveringGroundEffects; - gObjectEvents[i].landingJump = questLogObjectEvents[i].landingJump; - gObjectEvents[i].frozen = questLogObjectEvents[i].frozen; - gObjectEvents[i].facingDirectionLocked = questLogObjectEvents[i].facingDirectionLocked; - gObjectEvents[i].disableAnim = questLogObjectEvents[i].disableAnim; - gObjectEvents[i].enableAnim = questLogObjectEvents[i].enableAnim; - gObjectEvents[i].inanimate = questLogObjectEvents[i].inanimate; - gObjectEvents[i].invisible = questLogObjectEvents[i].invisible; - gObjectEvents[i].offScreen = questLogObjectEvents[i].offScreen; - gObjectEvents[i].trackedByCamera = questLogObjectEvents[i].trackedByCamera; - gObjectEvents[i].isPlayer = questLogObjectEvents[i].isPlayer; - gObjectEvents[i].spriteAnimPausedBackup = questLogObjectEvents[i].spriteAnimPausedBackup; - gObjectEvents[i].spriteAffineAnimPausedBackup = questLogObjectEvents[i].spriteAffineAnimPausedBackup; + gObjectEvents[i].active = questLogObjectEvents[i].active; + gObjectEvents[i].triggerGroundEffectsOnStop = questLogObjectEvents[i].triggerGroundEffectsOnStop; + gObjectEvents[i].disableCoveringGroundEffects = questLogObjectEvents[i].disableCoveringGroundEffects; + gObjectEvents[i].landingJump = questLogObjectEvents[i].landingJump; + gObjectEvents[i].frozen = questLogObjectEvents[i].frozen; + gObjectEvents[i].facingDirectionLocked = questLogObjectEvents[i].facingDirectionLocked; + gObjectEvents[i].disableAnim = questLogObjectEvents[i].disableAnim; + gObjectEvents[i].enableAnim = questLogObjectEvents[i].enableAnim; + gObjectEvents[i].inanimate = questLogObjectEvents[i].inanimate; + gObjectEvents[i].invisible = questLogObjectEvents[i].invisible; + gObjectEvents[i].offScreen = questLogObjectEvents[i].offScreen; + gObjectEvents[i].trackedByCamera = questLogObjectEvents[i].trackedByCamera; + gObjectEvents[i].isPlayer = questLogObjectEvents[i].isPlayer; + gObjectEvents[i].spriteAnimPausedBackup = questLogObjectEvents[i].spriteAnimPausedBackup; + gObjectEvents[i].spriteAffineAnimPausedBackup = questLogObjectEvents[i].spriteAffineAnimPausedBackup; gObjectEvents[i].disableJumpLandingGroundEffect = questLogObjectEvents[i].disableJumpLandingGroundEffect; - gObjectEvents[i].fixedPriority = questLogObjectEvents[i].fixedPriority; - gObjectEvents[i].facingDirection = questLogObjectEvents[i].mapobj_unk_18; - gObjectEvents[i].currentElevation = questLogObjectEvents[i].mapobj_unk_0B_0; - gObjectEvents[i].previousElevation = questLogObjectEvents[i].elevation; - gObjectEvents[i].graphicsId = questLogObjectEvents[i].graphicsId; - gObjectEvents[i].movementType = questLogObjectEvents[i].animPattern; - gObjectEvents[i].trainerType = questLogObjectEvents[i].trainerType; - gObjectEvents[i].localId = questLogObjectEvents[i].localId; - gObjectEvents[i].mapNum = questLogObjectEvents[i].mapNum; - gObjectEvents[i].mapGroup = questLogObjectEvents[i].mapGroup; - gObjectEvents[i].currentCoords.x = questLogObjectEvents[i].x; - gObjectEvents[i].currentCoords.y = questLogObjectEvents[i].y; - gObjectEvents[i].trainerRange_berryTreeId = questLogObjectEvents[i].trainerRange_berryTreeId; - gObjectEvents[i].previousMetatileBehavior = questLogObjectEvents[i].previousMetatileBehavior; - gObjectEvents[i].directionSequenceIndex = questLogObjectEvents[i].directionSequenceIndex; - gObjectEvents[i].playerCopyableMovement = questLogObjectEvents[i].animId; + gObjectEvents[i].fixedPriority = questLogObjectEvents[i].fixedPriority; + gObjectEvents[i].facingDirection = questLogObjectEvents[i].facingDirection; + gObjectEvents[i].currentElevation = questLogObjectEvents[i].currentElevation; + gObjectEvents[i].previousElevation = questLogObjectEvents[i].previousElevation; + gObjectEvents[i].graphicsId = questLogObjectEvents[i].graphicsId; + gObjectEvents[i].movementType = questLogObjectEvents[i].movementType; + gObjectEvents[i].trainerType = questLogObjectEvents[i].trainerType; + gObjectEvents[i].localId = questLogObjectEvents[i].localId; + gObjectEvents[i].mapNum = questLogObjectEvents[i].mapNum; + gObjectEvents[i].mapGroup = questLogObjectEvents[i].mapGroup; + gObjectEvents[i].currentCoords.x = questLogObjectEvents[i].x; + gObjectEvents[i].currentCoords.y = questLogObjectEvents[i].y; + gObjectEvents[i].trainerRange_berryTreeId = questLogObjectEvents[i].trainerRange_berryTreeId; + gObjectEvents[i].previousMetatileBehavior = questLogObjectEvents[i].previousMetatileBehavior; + gObjectEvents[i].directionSequenceIndex = questLogObjectEvents[i].directionSequenceIndex; + gObjectEvents[i].playerCopyableMovement = questLogObjectEvents[i].animId; - for (j = 0; j < 0x40; j++) + for (j = 0; j < OBJECT_EVENT_TEMPLATES_COUNT; j++) { if (gObjectEvents[i].localId == templates[j].localId) { - gObjectEvents[i].initialCoords.x = templates[j].x + 7; - gObjectEvents[i].initialCoords.y = templates[j].y + 7; + gObjectEvents[i].initialCoords.x = templates[j].x + MAP_OFFSET; + gObjectEvents[i].initialCoords.y = templates[j].y + MAP_OFFSET; gObjectEvents[i].rangeX = templates[j].objUnion.normal.movementRangeX; gObjectEvents[i].rangeY = templates[j].objUnion.normal.movementRangeY; } @@ -129,7 +129,7 @@ void SetSav1ObjectEventsFromQuestLog(const struct QuestLog * questLog, const str CpuCopy16(gObjectEvents, gSaveBlock1Ptr->objectEvents, sizeof(gObjectEvents)); } -void sub_815A540(void) +void QL_TryStopSurfing(void) { if (gQuestLogState == QL_STATE_PLAYBACK) { diff --git a/src/quest_log_player.c b/src/quest_log_player.c index 8c2ef6196..a35be1009 100644 --- a/src/quest_log_player.c +++ b/src/quest_log_player.c @@ -42,7 +42,7 @@ void QuestLogUpdatePlayerSprite(u8 state) bool32 QuestLogTryRecordPlayerAvatarGfxTransition(u8 state) { - if (gQuestLogPlaybackState == 2) + if (gQuestLogPlaybackState == QL_PLAYBACK_STATE_RECORDING) { QuestLogRecordPlayerAvatarGfxTransition(state); return TRUE; @@ -77,7 +77,7 @@ static void QL_GfxTransition_Fish(void) struct ObjectEvent *objectEvent = &gObjectEvents[gPlayerAvatar.objectEventId]; struct Sprite *sprite = &gSprites[objectEvent->spriteId]; - if (gQuestLogPlaybackState == 1 || gQuestLogPlaybackState == 3) + if (gQuestLogPlaybackState == QL_PLAYBACK_STATE_RUNNING || gQuestLogPlaybackState == QL_PLAYBACK_STATE_ACTION_END) { u8 taskId; LockPlayerFieldControls(); diff --git a/src/scrcmd.c b/src/scrcmd.c index 1e7068d3f..d297f509e 100644 --- a/src/scrcmd.c +++ b/src/scrcmd.c @@ -1336,7 +1336,7 @@ static bool8 WaitForAorBPress(void) } } } - if (sub_8112CAC() == 1 || gQuestLogState == QL_STATE_PLAYBACK) + if (QL_GetPlaybackState() == QL_PLAYBACK_STATE_RUNNING || gQuestLogState == QL_STATE_PLAYBACK) { if (sQuestLogWaitButtonPressTimer == 120) return TRUE; @@ -1401,7 +1401,7 @@ bool8 ScrCmd_waitbuttonpress(struct ScriptContext * ctx) { sQuestLogScriptContextPtr = ctx; - if (sub_8112CAC() == 1 || gQuestLogState == QL_STATE_PLAYBACK) + if (QL_GetPlaybackState() == QL_PLAYBACK_STATE_RUNNING || gQuestLogState == QL_STATE_PLAYBACK) sQuestLogWaitButtonPressTimer = 0; SetupNativeScript(ctx, WaitForAorBPress); return TRUE; @@ -1818,7 +1818,7 @@ bool8 ScrCmd_showmoneybox(struct ScriptContext * ctx) u8 y = ScriptReadByte(ctx); u8 ignore = ScriptReadByte(ctx); - if (!ignore && QuestLog_SchedulePlaybackCB(QLPlaybackCB_DestroyScriptMenuMonPicSprites) != TRUE) + if (!ignore && QL_AvoidDisplay(QL_DestroyAbortedDisplay) != TRUE) DrawMoneyBox(GetMoney(&gSaveBlock1Ptr->money), x, y); return FALSE; } @@ -1848,7 +1848,7 @@ bool8 ScrCmd_showcoinsbox(struct ScriptContext * ctx) u8 x = ScriptReadByte(ctx); u8 y = ScriptReadByte(ctx); - if (QuestLog_SchedulePlaybackCB(QLPlaybackCB_DestroyScriptMenuMonPicSprites) != TRUE) + if (QL_AvoidDisplay(QL_DestroyAbortedDisplay) != TRUE) ShowCoinsWindow(GetCoins(), x, y); return FALSE; } diff --git a/src/script_menu.c b/src/script_menu.c index f8e67a1fa..25991e775 100644 --- a/src/script_menu.c +++ b/src/script_menu.c @@ -715,7 +715,7 @@ static void DrawVerticalMultichoiceMenu(u8 left, u8 top, u8 mcId, u8 ignoreBpres u8 windowId; const struct MenuAction * list; - if ((ignoreBpress & 2) || QuestLog_SchedulePlaybackCB(QLPlaybackCB_DestroyScriptMenuMonPicSprites) != TRUE) + if ((ignoreBpress & 2) || QL_AvoidDisplay(QL_DestroyAbortedDisplay) != TRUE) { ignoreBpress &= 1; count = sMultichoiceLists[mcId].count; @@ -860,11 +860,12 @@ bool8 ScriptMenu_YesNo(u8 unused, u8 stuff) if (FuncIsActiveTask(Task_YesNoMenu_HandleInput) == TRUE) return FALSE; gSpecialVar_Result = SCR_MENU_UNSET; - if (!QuestLog_SchedulePlaybackCB(QLPlaybackCB_DestroyScriptMenuMonPicSprites)) - { - DisplayYesNoMenuDefaultYes(); - CreateTask(Task_YesNoMenu_HandleInput, 80); - } + + if (QL_AvoidDisplay(QL_DestroyAbortedDisplay)) + return TRUE; + + DisplayYesNoMenuDefaultYes(); + CreateTask(Task_YesNoMenu_HandleInput, 80); return TRUE; } @@ -915,20 +916,22 @@ bool8 ScriptMenu_MultichoiceGrid(u8 left, u8 top, u8 multichoiceId, bool8 ignore if (FuncIsActiveTask(Hask_MultichoiceGridMenu_HandleInput) == TRUE) return FALSE; gSpecialVar_Result = SCR_MENU_UNSET; - if (QuestLog_SchedulePlaybackCB(QLPlaybackCB_DestroyScriptMenuMonPicSprites) != TRUE) - { - list = sMultichoiceLists[multichoiceId].list; - count = sMultichoiceLists[multichoiceId].count; - width = GetMenuWidthFromList(list, count) + 1; - rowCount = count / columnCount; - taskId = CreateTask(Hask_MultichoiceGridMenu_HandleInput, 80); - gTasks[taskId].tIgnoreBPress = ignoreBpress; - gTasks[taskId].tWindowId = CreateWindowFromRect(left, top, width * columnCount, rowCount * 2); - SetStdWindowBorderStyle(gTasks[taskId].tWindowId, FALSE); - MultichoiceGrid_PrintItems(gTasks[taskId].tWindowId, FONT_NORMAL_COPY_1, width * 8, 16, columnCount, rowCount, list); - MultichoiceGrid_InitCursor(gTasks[taskId].tWindowId, FONT_NORMAL_COPY_1, 0, 1, width * 8, columnCount, rowCount, 0); - ScheduleBgCopyTilemapToVram(0); - } + + if (QL_AvoidDisplay(QL_DestroyAbortedDisplay) == TRUE) + return TRUE; + + list = sMultichoiceLists[multichoiceId].list; + count = sMultichoiceLists[multichoiceId].count; + width = GetMenuWidthFromList(list, count) + 1; + rowCount = count / columnCount; + taskId = CreateTask(Hask_MultichoiceGridMenu_HandleInput, 80); + gTasks[taskId].tIgnoreBPress = ignoreBpress; + gTasks[taskId].tWindowId = CreateWindowFromRect(left, top, width * columnCount, rowCount * 2); + SetStdWindowBorderStyle(gTasks[taskId].tWindowId, FALSE); + MultichoiceGrid_PrintItems(gTasks[taskId].tWindowId, FONT_NORMAL_COPY_1, width * 8, 16, columnCount, rowCount, list); + MultichoiceGrid_InitCursor(gTasks[taskId].tWindowId, FONT_NORMAL_COPY_1, 0, 1, width * 8, columnCount, rowCount, 0); + ScheduleBgCopyTilemapToVram(0); + return TRUE; } @@ -1057,7 +1060,7 @@ bool8 ScriptMenu_ShowPokemonPic(u16 species, u8 x, u8 y) { u8 spriteId; u8 taskId; - if (QuestLog_SchedulePlaybackCB(QLPlaybackCB_DestroyScriptMenuMonPicSprites) == TRUE) + if (QL_AvoidDisplay(QL_DestroyAbortedDisplay) == TRUE) return TRUE; if (FindTaskIdByFunc(Task_ScriptShowMonPic) != TASK_NONE) return FALSE; @@ -1143,7 +1146,7 @@ bool8 OpenMuseumFossilPic(void) { u8 spriteId; u8 taskId; - if (QuestLog_SchedulePlaybackCB(QLPlaybackCB_DestroyScriptMenuMonPicSprites) == TRUE) + if (QL_AvoidDisplay(QL_DestroyAbortedDisplay) == TRUE) return TRUE; if (FindTaskIdByFunc(Task_WaitMuseumFossilPic) != TASK_NONE) return FALSE; @@ -1196,7 +1199,7 @@ static void DestroyScriptMenuWindow(u8 windowId) RemoveWindow(windowId); } -void QLPlaybackCB_DestroyScriptMenuMonPicSprites(void) +void QL_DestroyAbortedDisplay(void) { u8 taskId; s16 *data; @@ -1234,48 +1237,49 @@ void DrawSeagallopDestinationMenu(void) u8 windowId; u8 i; gSpecialVar_Result = SCR_MENU_UNSET; - if (QuestLog_SchedulePlaybackCB(QLPlaybackCB_DestroyScriptMenuMonPicSprites) != TRUE) - { - if (gSpecialVar_0x8005 == 1) - { - if (gSpecialVar_0x8004 < SEAGALLOP_FIVE_ISLAND) - destinationId = SEAGALLOP_FIVE_ISLAND; - else - destinationId = SEAGALLOP_FOUR_ISLAND; - numItems = 5; - top = 2; - } - else - { - destinationId = SEAGALLOP_VERMILION_CITY; - numItems = 6; - top = 0; - } - cursorWidth = GetMenuCursorDimensionByFont(FONT_NORMAL, 0); - fontHeight = GetFontAttribute(FONT_NORMAL, FONTATTR_MAX_LETTER_HEIGHT); - windowId = CreateWindowFromRect(17, top, 11, numItems * 2); - SetStdWindowBorderStyle(windowId, FALSE); - - // -2 excludes "Other" and "Exit", appended after the loop - for (i = 0; i < numItems - 2; i++) - { - if (destinationId != gSpecialVar_0x8004) - AddTextPrinterParameterized(windowId, FONT_NORMAL, sSeagallopDestStrings[destinationId], cursorWidth, i * 16 + 2, TEXT_SKIP_DRAW, NULL); - else - i--; - destinationId++; - // Wrap around - if (destinationId == SEAGALLOP_SEVEN_ISLAND + 1) - destinationId = SEAGALLOP_VERMILION_CITY; - } - AddTextPrinterParameterized(windowId, FONT_NORMAL, gText_Other, cursorWidth, i * 16 + 2, TEXT_SKIP_DRAW, NULL); - i++; - AddTextPrinterParameterized(windowId, FONT_NORMAL, gOtherText_Exit, cursorWidth, i * 16 + 2, TEXT_SKIP_DRAW, NULL); - Menu_InitCursor(windowId, FONT_NORMAL, 0, 2, 16, numItems, 0); - CreateMCMenuInputHandlerTask(FALSE, numItems, windowId, MULTICHOICE_NONE); - ScheduleBgCopyTilemapToVram(0); + if (QL_AvoidDisplay(QL_DestroyAbortedDisplay) == TRUE) + return; + + if (gSpecialVar_0x8005 == 1) + { + if (gSpecialVar_0x8004 < SEAGALLOP_FIVE_ISLAND) + destinationId = SEAGALLOP_FIVE_ISLAND; + else + destinationId = SEAGALLOP_FOUR_ISLAND; + numItems = 5; + top = 2; } + else + { + destinationId = SEAGALLOP_VERMILION_CITY; + numItems = 6; + top = 0; + } + cursorWidth = GetMenuCursorDimensionByFont(FONT_NORMAL, 0); + fontHeight = GetFontAttribute(FONT_NORMAL, FONTATTR_MAX_LETTER_HEIGHT); + windowId = CreateWindowFromRect(17, top, 11, numItems * 2); + SetStdWindowBorderStyle(windowId, FALSE); + + // -2 excludes "Other" and "Exit", appended after the loop + for (i = 0; i < numItems - 2; i++) + { + if (destinationId != gSpecialVar_0x8004) + AddTextPrinterParameterized(windowId, FONT_NORMAL, sSeagallopDestStrings[destinationId], cursorWidth, i * 16 + 2, TEXT_SKIP_DRAW, NULL); + else + i--; + destinationId++; + + // Wrap around + if (destinationId == SEAGALLOP_SEVEN_ISLAND + 1) + destinationId = SEAGALLOP_VERMILION_CITY; + } + AddTextPrinterParameterized(windowId, FONT_NORMAL, gText_Other, cursorWidth, i * 16 + 2, TEXT_SKIP_DRAW, NULL); + i++; + AddTextPrinterParameterized(windowId, FONT_NORMAL, gOtherText_Exit, cursorWidth, i * 16 + 2, TEXT_SKIP_DRAW, NULL); + Menu_InitCursor(windowId, FONT_NORMAL, 0, 2, 16, numItems, 0); + CreateMCMenuInputHandlerTask(FALSE, numItems, windowId, MULTICHOICE_NONE); + ScheduleBgCopyTilemapToVram(0); } u16 GetSelectedSeagallopDestination(void) diff --git a/src/shop.c b/src/shop.c index 46c0d755a..7ea8b3edf 100644 --- a/src/shop.c +++ b/src/shop.c @@ -69,17 +69,6 @@ struct ShopData /*0x18*/ u16 unk18; }; -struct MartHistory -{ - /*0x00*/ u32 unk0; - /*0x04*/ u16 unk4; - /*0x06*/ u16 unk6; - /*0x08*/ u8 unk8; - /*0x09*/ u8 unk9; - /*0x0A*/ u8 unkA; - /*0x0B*/ u8 unkB; -}; /* size = 12 */ - static EWRAM_DATA s16 sViewportObjectEvents[OBJECT_EVENTS_COUNT][4] = {0}; EWRAM_DATA struct ShopData gShopData = {0}; static EWRAM_DATA u8 sShopMenuWindowId = 0; @@ -89,7 +78,7 @@ EWRAM_DATA u16 (*gShopTilemapBuffer3)[0x400] = {0}; EWRAM_DATA u16 (*gShopTilemapBuffer4)[0x400] = {0}; EWRAM_DATA struct ListMenuItem *sShopMenuListMenu = {0}; static EWRAM_DATA u8 (*sShopMenuItemStrings)[13] = {0}; -EWRAM_DATA struct MartHistory gShopMenuHistory[2] = {0}; +EWRAM_DATA struct QuestLogEvent_Shop sHistory[2] = {0}; //Function Declarations static u8 CreateShopMenu(u8 a0); @@ -146,7 +135,7 @@ static void ExitBuyMenu(u8 taskId); static void Task_ExitBuyMenu(u8 taskId); static void DebugFunc_PrintPurchaseDetails(u8 taskId); static void DebugFunc_PrintShopMenuHistoryBeforeClearMaybe(void); -static void RecordQuestLogItemPurchase(void); +static void RecordTransactionForQuestLog(void); static const struct MenuAction sShopMenuActions_BuySellQuit[] = { @@ -305,7 +294,7 @@ static void CB2_GoToSellMenu(void) static void Task_HandleShopMenuQuit(u8 taskId) { ClearShopMenuWindow(); - RecordQuestLogItemPurchase(); + RecordTransactionForQuestLog(); DestroyTask(taskId); if (gShopData.callback != NULL) gShopData.callback(); @@ -995,7 +984,7 @@ static void BuyMenuTryMakePurchase(u8 taskId) { BuyMenuDisplayMessage(taskId, gText_HereYouGoThankYou, BuyMenuSubtractMoney); DebugFunc_PrintPurchaseDetails(taskId); - RecordItemPurchase(tItemId, tItemCount, 1); + RecordItemTransaction(tItemId, tItemCount, QL_EVENT_BOUGHT_ITEM - QL_EVENT_USED_POKEMART); } else { @@ -1066,59 +1055,67 @@ static void DebugFunc_PrintShopMenuHistoryBeforeClearMaybe(void) { } -void RecordItemPurchase(u16 item, u16 quantity, u8 a2) +// Records a transaction during a single shopping session. +// This is for the Quest Log to save information about the player's purchases/sales when they finish. +void RecordItemTransaction(u16 itemId, u16 quantity, u8 logEventId) { - struct MartHistory *history; + struct QuestLogEvent_Shop *history; - if (gShopMenuHistory[0].unkA == a2) + // There should only be a single entry for buying/selling respectively, + // so if one has already been created then get it first. + if (sHistory[0].logEventId == logEventId) { - history = &gShopMenuHistory[0]; + history = &sHistory[0]; } - else if (gShopMenuHistory[1].unkA == a2) + else if (sHistory[1].logEventId == logEventId) { - history = &gShopMenuHistory[1]; + history = &sHistory[1]; } else { - if (gShopMenuHistory[0].unkA == 0) - history = &gShopMenuHistory[0]; + // First transaction of this type, save it in an empty slot + if (sHistory[0].logEventId == 0) + history = &sHistory[0]; else - history = &gShopMenuHistory[1]; - history->unkA = a2; + history = &sHistory[1]; + history->logEventId = logEventId; + } + + // Set flag if this isn't the first time we've bought/sold in this session + if (history->lastItemId != ITEM_NONE) + history->hasMultipleTransactions = TRUE; + + history->lastItemId = itemId; + + // Add to number of items bought/sold + if (history->itemQuantity < 999) + { + history->itemQuantity += quantity; + if (history->itemQuantity > 999) + history->itemQuantity = 999; } - if (history->unk4 != 0) + // Add to amount of money spent buying or earned selling + if (history->totalMoney < 999999) { - history->unk9 = 1; - } - - history->unk4 = item; - if (history->unk6 < 999) - { - history->unk6 += quantity; - if (history->unk6 > 999) - history->unk6 = 999; - } - - if (history->unk0 < 999999) - { - history->unk0 += (ItemId_GetPrice(item) >> (a2 - 1)) * quantity; - if (history->unk0 > 999999) - history->unk0 = 999999; + // logEventId will either be 1 (bought) or 2 (sold) + // so for buying it will add the full price and selling will add half price + history->totalMoney += (ItemId_GetPrice(itemId) >> (logEventId - 1)) * quantity; + if (history->totalMoney > 999999) + history->totalMoney = 999999; } } -static void RecordQuestLogItemPurchase(void) +// Will record QL_EVENT_BOUGHT_ITEM and/or QL_EVENT_SOLD_ITEM, or nothing. +static void RecordTransactionForQuestLog(void) { - u16 v; - - v = gShopMenuHistory[0].unkA; - if (v != 0) - SetQuestLogEvent(v + QL_EVENT_USED_POKEMART, (const u16 *)&gShopMenuHistory[0]); + u16 eventId = sHistory[0].logEventId; + if (eventId != 0) + SetQuestLogEvent(eventId + QL_EVENT_USED_POKEMART, (const u16 *)&sHistory[0]); - v = gShopMenuHistory[1].unkA; - if (v != 0) - SetQuestLogEvent(v + QL_EVENT_USED_POKEMART, (const u16 *)&gShopMenuHistory[1]); + eventId = sHistory[1].logEventId; + if (eventId != 0) + SetQuestLogEvent(eventId + QL_EVENT_USED_POKEMART, (const u16 *)&sHistory[1]); } void CreatePokemartMenu(const u16 *itemsForSale) @@ -1127,9 +1124,9 @@ void CreatePokemartMenu(const u16 *itemsForSale) CreateShopMenu(MART_TYPE_REGULAR); SetShopMenuCallback(ScriptContext_Enable); DebugFunc_PrintShopMenuHistoryBeforeClearMaybe(); - memset(&gShopMenuHistory, 0, sizeof(gShopMenuHistory)); - gShopMenuHistory[0].unk8 = gMapHeader.regionMapSectionId; - gShopMenuHistory[1].unk8 = gMapHeader.regionMapSectionId; + memset(&sHistory, 0, sizeof(sHistory)); + sHistory[0].mapSec = gMapHeader.regionMapSectionId; + sHistory[1].mapSec = gMapHeader.regionMapSectionId; } void CreateDecorationShop1Menu(const u16 *itemsForSale) diff --git a/src/tm_case.c b/src/tm_case.c index dd5adb345..8975761a5 100644 --- a/src/tm_case.c +++ b/src/tm_case.c @@ -23,6 +23,7 @@ #include "menu_indicators.h" #include "constants/items.h" #include "constants/songs.h" +#include "constants/quest_log.h" // Any item in the TM Case with nonzero importance is considered an HM #define IS_HM(itemId) (ItemId_GetImportance(itemId) != 0) @@ -1292,7 +1293,7 @@ static void Task_DoSaleOfTMs(u8 taskId) PlaySE(SE_SHOP); RemoveBagItem(gSpecialVar_ItemId, tQuantitySelected); AddMoney(&gSaveBlock1Ptr->money, ItemId_GetPrice(gSpecialVar_ItemId) / 2 * tQuantitySelected); - RecordItemPurchase(gSpecialVar_ItemId, tQuantitySelected, 2); + RecordItemTransaction(gSpecialVar_ItemId, tQuantitySelected, QL_EVENT_SOLD_ITEM - QL_EVENT_USED_POKEMART); DestroyListMenuTask(tListTaskId, &sTMCaseStaticResources.scrollOffset, &sTMCaseStaticResources.selectedRow); TMCaseSetup_GetTMCount(); TMCaseSetup_InitListMenuPositions(); diff --git a/src/trade_scene.c b/src/trade_scene.c index 129774f34..2c3a0801d 100644 --- a/src/trade_scene.c +++ b/src/trade_scene.c @@ -107,9 +107,7 @@ struct { /*0xF0*/ u16 monSpecies[2]; /*0xF4*/ u16 cachedMapMusic; /*0xF6*/ u8 unk_F6; - /*0xF8*/ u16 questLogSpecies[2]; - /*0xFC*/ u8 linkPartnerName[7]; - /*0x103*/ u8 filler_103[1]; + /*0xF8*/ struct QuestLogEvent_Traded questLogData; /*0x104*/ u8 textColor[3]; /*0x107*/ u8 filler_107[1]; /*0x108*/ bool8 isCableTrade; @@ -883,9 +881,9 @@ void CB2_LinkTrade(void) case 10: BeginNormalPaletteFade(PALETTES_ALL, 0, 16, 0, RGB_BLACK); ShowBg(0); - sTradeAnim->questLogSpecies[TRADE_PLAYER] = GetMonData(&gPlayerParty[gSelectedTradeMonPositions[TRADE_PLAYER]], MON_DATA_SPECIES_OR_EGG); - sTradeAnim->questLogSpecies[TRADE_PARTNER] = GetMonData(&gEnemyParty[gSelectedTradeMonPositions[TRADE_PARTNER] % PARTY_SIZE], MON_DATA_SPECIES_OR_EGG); - memcpy(sTradeAnim->linkPartnerName, gLinkPlayers[GetMultiplayerId() ^ 1].name, PLAYER_NAME_LENGTH); + sTradeAnim->questLogData.speciesSent = GetMonData(&gPlayerParty[gSelectedTradeMonPositions[TRADE_PLAYER]], MON_DATA_SPECIES_OR_EGG); + sTradeAnim->questLogData.speciesReceived = GetMonData(&gEnemyParty[gSelectedTradeMonPositions[TRADE_PARTNER] % PARTY_SIZE], MON_DATA_SPECIES_OR_EGG); + memcpy(sTradeAnim->questLogData.partnerName, gLinkPlayers[GetMultiplayerId() ^ 1].name, PLAYER_NAME_LENGTH); gMain.state++; break; case 11: @@ -2599,11 +2597,11 @@ static void CB2_SaveAndEndTrade(void) case 50: if (InUnionRoom()) { - SetQuestLogEvent(QL_EVENT_LINK_TRADED_UNION, sTradeAnim->questLogSpecies); + SetQuestLogEvent(QL_EVENT_LINK_TRADED_UNION, (void *)&sTradeAnim->questLogData); } else { - SetQuestLogEvent(QL_EVENT_LINK_TRADED, sTradeAnim->questLogSpecies); + SetQuestLogEvent(QL_EVENT_LINK_TRADED, (void *)&sTradeAnim->questLogData); IncrementGameStat(GAME_STAT_POKEMON_TRADES); } if (gWirelessCommType) diff --git a/src/trainer_fan_club.c b/src/trainer_fan_club.c index cdb5dac85..69c860d2b 100644 --- a/src/trainer_fan_club.c +++ b/src/trainer_fan_club.c @@ -4,6 +4,7 @@ #include "event_data.h" #include "event_scripts.h" #include "random.h" +#include "constants/trainer_fan_club.h" struct TrainerFanClub { @@ -18,17 +19,6 @@ struct TrainerFanClub #define SET_TRAINER_FAN_CLUB_FLAG(flag) (fanClub->fanFlags |= 1 << (flag)) #define FLIP_TRAINER_FAN_CLUB_FLAG(flag)(fanClub->fanFlags ^= 1 << (flag)) -#define FANCLUB_MEMBER1 0 -#define FANCLUB_MEMBER2 1 -#define FANCLUB_MEMBER3 2 -#define FANCLUB_MEMBER4 3 -#define FANCLUB_MEMBER5 4 -#define FANCLUB_MEMBER6 5 -#define FANCLUB_MEMBER7 6 -#define FANCLUB_MEMBER8 7 - -#define NUM_TRAINER_FAN_CLUB_MEMBERS 8 - static void TryLoseFansFromPlayTimeAfterLinkBattle(struct TrainerFanClub *); static void UpdateTrainerFanClubGameClear(struct TrainerFanClub *); static u8 PlayerGainRandomTrainerFan(struct TrainerFanClub *); diff --git a/src/trainer_see.c b/src/trainer_see.c index 12d47f247..b66409c18 100644 --- a/src/trainer_see.c +++ b/src/trainer_see.c @@ -88,7 +88,7 @@ static const TrainerSeeFunc sTrainerSeeFuncList2[] = { bool8 CheckForTrainersWantingBattle(void) { u8 i; - if (sub_8111C2C() == TRUE) + if (QL_IsTrainerSightDisabled() == TRUE) return FALSE; for (i = 0; i < OBJECT_EVENTS_COUNT; i++) diff --git a/src/vs_seeker.c b/src/vs_seeker.c index be6b11baa..91136a51f 100644 --- a/src/vs_seeker.c +++ b/src/vs_seeker.c @@ -26,6 +26,13 @@ #include "constants/quest_log.h" #include "constants/trainer_types.h" +// Each trainer can have up to 6 parties, including their original party. +// Each rematch is unavailable until the player has progressed to a certain point in the story (see TryGetRematchTrainerIdGivenGameState). +// A list of the trainer ids for each party is in sRematches. If a party doesn't update for a progression point it will have SKIP instead, +// and that trainer id will be ignored. +#define MAX_REMATCH_PARTIES 6 +#define SKIP 0xFFFF + enum { VSSEEKER_NOT_CHARGED, @@ -47,13 +54,12 @@ typedef enum VSSEEKER_RESPONSE_FOUND_REMATCHES } VsSeekerResponseCode; -// static types -typedef struct VsSeekerData +struct RematchData { - u16 trainerIdxs[6]; + u16 trainerIdxs[MAX_REMATCH_PARTIES]; u16 mapGroup; // unused u16 mapNum; // unused -} VsSeekerData; +}; struct VsSeekerTrainerInfo { @@ -91,19 +97,19 @@ static void Task_VsSeeker_2(u8 taskId); static void GatherNearbyTrainerInfo(void); static void Task_VsSeeker_3(u8 taskId); static bool8 CanUseVsSeeker(void); -static u8 GetVsSeekerResponseInArea(const VsSeekerData * vsSeekerData); +static u8 GetVsSeekerResponseInArea(const struct RematchData * vsSeekerData); static u8 GetRematchTrainerIdGivenGameState(const u16 *trainerIdxs, u8 rematchIdx); -static u8 ShouldTryRematchBattleInternal(const VsSeekerData * vsSeekerData, u16 trainerBattleOpponent); -static u8 HasRematchTrainerAlreadyBeenFought(const VsSeekerData * vsSeekerData, u16 trainerBattleOpponent); -static int LookupVsSeekerOpponentInArray(const VsSeekerData * array, u16 trainerId); -static bool8 IsTrainerReadyForRematchInternal(const VsSeekerData * array, u16 trainerIdx); +static u8 ShouldTryRematchBattleInternal(const struct RematchData * vsSeekerData, u16 trainerBattleOpponent); +static u8 HasRematchTrainerAlreadyBeenFought(const struct RematchData * vsSeekerData, u16 trainerBattleOpponent); +static int LookupVsSeekerOpponentInArray(const struct RematchData * array, u16 trainerId); +static bool8 IsTrainerReadyForRematchInternal(const struct RematchData * array, u16 trainerIdx); static u8 GetRunningBehaviorFromGraphicsId(u8 graphicsId); static u16 GetTrainerFlagFromScript(const u8 * script); -static int GetRematchIdx(const VsSeekerData * vsSeekerData, u16 trainerFlagIdx); +static int GetRematchIdx(const struct RematchData * vsSeekerData, u16 trainerFlagIdx); static bool32 IsThisTrainerRematchable(u32 localId); static void ClearAllTrainerRematchStates(void); static bool8 IsTrainerVisibleOnScreen(struct VsSeekerTrainerInfo * trainerInfo); -static u8 GetNextAvailableRematchTrainer(const VsSeekerData * vsSeekerData, u16 trainerFlagNo, u8 * idxPtr); +static u8 GetNextAvailableRematchTrainer(const struct RematchData * vsSeekerData, u16 trainerFlagNo, u8 * idxPtr); static u8 GetRematchableTrainerLocalId(void); static void StartTrainerObjectMovementScript(struct VsSeekerTrainerInfo * trainerInfo, const u8 * script); static u8 GetCurVsSeekerResponse(s32 vsSeekerIdx, u16 trainerIdx); @@ -111,450 +117,447 @@ static void StartAllRespondantIdleMovements(void); static bool8 ObjectEventIdIsSane(u8 objectEventId); static u8 GetRandomFaceDirectionMovementType(); -// rodata -static const VsSeekerData sVsSeekerData[] = { - { {TRAINER_YOUNGSTER_BEN, TRAINER_YOUNGSTER_BEN_2, 0xFFFF, TRAINER_YOUNGSTER_BEN_3, TRAINER_YOUNGSTER_BEN_4}, - MAP_GROUP(ROUTE3), MAP_NUM(ROUTE3) }, - { {TRAINER_YOUNGSTER_CALVIN, TRAINER_YOUNGSTER_CALVIN}, - MAP_GROUP(ROUTE3), MAP_NUM(ROUTE3) }, - { {TRAINER_BUG_CATCHER_COLTON, TRAINER_BUG_CATCHER_COLTON_2, 0xFFFF, TRAINER_BUG_CATCHER_COLTON_3, 0xFFFF, TRAINER_BUG_CATCHER_COLTON_4}, - MAP_GROUP(ROUTE3), MAP_NUM(ROUTE3) }, +static const struct RematchData sRematches[] = { + { {TRAINER_YOUNGSTER_BEN, TRAINER_YOUNGSTER_BEN_2, SKIP, TRAINER_YOUNGSTER_BEN_3, TRAINER_YOUNGSTER_BEN_4}, MAP(ROUTE3) }, + { {TRAINER_YOUNGSTER_CALVIN, TRAINER_YOUNGSTER_CALVIN}, MAP(ROUTE3) }, + { {TRAINER_BUG_CATCHER_COLTON, TRAINER_BUG_CATCHER_COLTON_2, SKIP, TRAINER_BUG_CATCHER_COLTON_3, SKIP, TRAINER_BUG_CATCHER_COLTON_4}, + MAP(ROUTE3) }, { {TRAINER_BUG_CATCHER_GREG, TRAINER_BUG_CATCHER_GREG}, - MAP_GROUP(ROUTE3), MAP_NUM(ROUTE3) }, + MAP(ROUTE3) }, { {TRAINER_BUG_CATCHER_JAMES, TRAINER_BUG_CATCHER_JAMES}, - MAP_GROUP(ROUTE3), MAP_NUM(ROUTE3) }, - { {TRAINER_LASS_JANICE, TRAINER_LASS_JANICE_2, 0xFFFF, TRAINER_LASS_JANICE_3}, - MAP_GROUP(ROUTE3), MAP_NUM(ROUTE3) }, + MAP(ROUTE3) }, + { {TRAINER_LASS_JANICE, TRAINER_LASS_JANICE_2, SKIP, TRAINER_LASS_JANICE_3}, + MAP(ROUTE3) }, { {TRAINER_LASS_SALLY, TRAINER_LASS_SALLY}, - MAP_GROUP(ROUTE3), MAP_NUM(ROUTE3) }, + MAP(ROUTE3) }, { {TRAINER_LASS_ROBIN, TRAINER_LASS_ROBIN}, - MAP_GROUP(ROUTE3), MAP_NUM(ROUTE3) }, + MAP(ROUTE3) }, { {TRAINER_LASS_CRISSY, TRAINER_LASS_CRISSY}, - MAP_GROUP(ROUTE4), MAP_NUM(ROUTE4) }, - { {TRAINER_YOUNGSTER_TIMMY, TRAINER_YOUNGSTER_TIMMY_2, 0xFFFF, TRAINER_YOUNGSTER_TIMMY_3, 0xFFFF, TRAINER_YOUNGSTER_TIMMY_4}, - MAP_GROUP(ROUTE24), MAP_NUM(ROUTE24) }, + MAP(ROUTE4) }, + { {TRAINER_YOUNGSTER_TIMMY, TRAINER_YOUNGSTER_TIMMY_2, SKIP, TRAINER_YOUNGSTER_TIMMY_3, SKIP, TRAINER_YOUNGSTER_TIMMY_4}, + MAP(ROUTE24) }, { {TRAINER_BUG_CATCHER_CALE, TRAINER_BUG_CATCHER_CALE}, - MAP_GROUP(ROUTE24), MAP_NUM(ROUTE24) }, - { {TRAINER_LASS_RELI, TRAINER_LASS_RELI_2, 0xFFFF, TRAINER_LASS_RELI_3}, - MAP_GROUP(ROUTE24), MAP_NUM(ROUTE24) }, + MAP(ROUTE24) }, + { {TRAINER_LASS_RELI, TRAINER_LASS_RELI_2, SKIP, TRAINER_LASS_RELI_3}, + MAP(ROUTE24) }, { {TRAINER_LASS_ALI, TRAINER_LASS_ALI}, - MAP_GROUP(ROUTE24), MAP_NUM(ROUTE24) }, + MAP(ROUTE24) }, { {TRAINER_CAMPER_SHANE, TRAINER_CAMPER_SHANE}, - MAP_GROUP(ROUTE24), MAP_NUM(ROUTE24) }, + MAP(ROUTE24) }, { {TRAINER_CAMPER_ETHAN, TRAINER_CAMPER_ETHAN}, - MAP_GROUP(ROUTE24), MAP_NUM(ROUTE24) }, + MAP(ROUTE24) }, { {TRAINER_YOUNGSTER_JOEY, TRAINER_YOUNGSTER_JOEY}, - MAP_GROUP(ROUTE25), MAP_NUM(ROUTE25) }, + MAP(ROUTE25) }, { {TRAINER_YOUNGSTER_DAN, TRAINER_YOUNGSTER_DAN}, - MAP_GROUP(ROUTE25), MAP_NUM(ROUTE25) }, - { {TRAINER_YOUNGSTER_CHAD, TRAINER_YOUNGSTER_CHAD_2, 0xFFFF, TRAINER_YOUNGSTER_CHAD_3, TRAINER_YOUNGSTER_CHAD_4}, - MAP_GROUP(ROUTE25), MAP_NUM(ROUTE25) }, - { {TRAINER_PICNICKER_KELSEY, TRAINER_PICNICKER_KELSEY_2, 0xFFFF, TRAINER_PICNICKER_KELSEY_3, TRAINER_PICNICKER_KELSEY_4}, - MAP_GROUP(ROUTE25), MAP_NUM(ROUTE25) }, + MAP(ROUTE25) }, + { {TRAINER_YOUNGSTER_CHAD, TRAINER_YOUNGSTER_CHAD_2, SKIP, TRAINER_YOUNGSTER_CHAD_3, TRAINER_YOUNGSTER_CHAD_4}, + MAP(ROUTE25) }, + { {TRAINER_PICNICKER_KELSEY, TRAINER_PICNICKER_KELSEY_2, SKIP, TRAINER_PICNICKER_KELSEY_3, TRAINER_PICNICKER_KELSEY_4}, + MAP(ROUTE25) }, { {TRAINER_LASS_HALEY, TRAINER_LASS_HALEY}, - MAP_GROUP(ROUTE25), MAP_NUM(ROUTE25) }, - { {TRAINER_HIKER_FRANKLIN, 0xFFFF, TRAINER_HIKER_FRANKLIN_2}, - MAP_GROUP(ROUTE25), MAP_NUM(ROUTE25) }, + MAP(ROUTE25) }, + { {TRAINER_HIKER_FRANKLIN, SKIP, TRAINER_HIKER_FRANKLIN_2}, + MAP(ROUTE25) }, { {TRAINER_HIKER_NOB, TRAINER_HIKER_NOB}, - MAP_GROUP(ROUTE25), MAP_NUM(ROUTE25) }, + MAP(ROUTE25) }, { {TRAINER_HIKER_WAYNE, TRAINER_HIKER_WAYNE}, - MAP_GROUP(ROUTE25), MAP_NUM(ROUTE25) }, + MAP(ROUTE25) }, { {TRAINER_CAMPER_FLINT, TRAINER_CAMPER_FLINT}, - MAP_GROUP(ROUTE25), MAP_NUM(ROUTE25) }, + MAP(ROUTE25) }, { {TRAINER_BUG_CATCHER_KEIGO, TRAINER_BUG_CATCHER_KEIGO}, - MAP_GROUP(ROUTE6), MAP_NUM(ROUTE6) }, + MAP(ROUTE6) }, { {TRAINER_BUG_CATCHER_ELIJAH, TRAINER_BUG_CATCHER_ELIJAH}, - MAP_GROUP(ROUTE6), MAP_NUM(ROUTE6) }, - { {TRAINER_CAMPER_RICKY, TRAINER_CAMPER_RICKY_2, 0xFFFF, TRAINER_CAMPER_RICKY_3, 0xFFFF, TRAINER_CAMPER_RICKY_4}, - MAP_GROUP(ROUTE6), MAP_NUM(ROUTE6) }, - { {TRAINER_CAMPER_JEFF, TRAINER_CAMPER_JEFF_2, 0xFFFF, TRAINER_CAMPER_JEFF_3, 0xFFFF, TRAINER_CAMPER_JEFF_4}, - MAP_GROUP(ROUTE6), MAP_NUM(ROUTE6) }, + MAP(ROUTE6) }, + { {TRAINER_CAMPER_RICKY, TRAINER_CAMPER_RICKY_2, SKIP, TRAINER_CAMPER_RICKY_3, SKIP, TRAINER_CAMPER_RICKY_4}, + MAP(ROUTE6) }, + { {TRAINER_CAMPER_JEFF, TRAINER_CAMPER_JEFF_2, SKIP, TRAINER_CAMPER_JEFF_3, SKIP, TRAINER_CAMPER_JEFF_4}, + MAP(ROUTE6) }, { {TRAINER_PICNICKER_NANCY, TRAINER_PICNICKER_NANCY}, - MAP_GROUP(ROUTE6), MAP_NUM(ROUTE6) }, - { {TRAINER_PICNICKER_ISABELLE, TRAINER_PICNICKER_ISABELLE_2, 0xFFFF, TRAINER_PICNICKER_ISABELLE_3, TRAINER_PICNICKER_ISABELLE_4}, - MAP_GROUP(ROUTE6), MAP_NUM(ROUTE6) }, + MAP(ROUTE6) }, + { {TRAINER_PICNICKER_ISABELLE, TRAINER_PICNICKER_ISABELLE_2, SKIP, TRAINER_PICNICKER_ISABELLE_3, TRAINER_PICNICKER_ISABELLE_4}, + MAP(ROUTE6) }, { {TRAINER_YOUNGSTER_EDDIE, TRAINER_YOUNGSTER_EDDIE}, - MAP_GROUP(ROUTE11), MAP_NUM(ROUTE11) }, + MAP(ROUTE11) }, { {TRAINER_YOUNGSTER_DILLON, TRAINER_YOUNGSTER_DILLON}, - MAP_GROUP(ROUTE11), MAP_NUM(ROUTE11) }, - { {TRAINER_YOUNGSTER_YASU, 0xFFFF, TRAINER_YOUNGSTER_YASU_2, 0xFFFF, TRAINER_YOUNGSTER_YASU_3}, - MAP_GROUP(ROUTE11), MAP_NUM(ROUTE11) }, + MAP(ROUTE11) }, + { {TRAINER_YOUNGSTER_YASU, SKIP, TRAINER_YOUNGSTER_YASU_2, SKIP, TRAINER_YOUNGSTER_YASU_3}, + MAP(ROUTE11) }, { {TRAINER_YOUNGSTER_DAVE, TRAINER_YOUNGSTER_DAVE}, - MAP_GROUP(ROUTE11), MAP_NUM(ROUTE11) }, + MAP(ROUTE11) }, { {TRAINER_ENGINEER_BRAXTON, TRAINER_ENGINEER_BRAXTON}, - MAP_GROUP(ROUTE11), MAP_NUM(ROUTE11) }, - { {TRAINER_ENGINEER_BERNIE, 0xFFFF, 0xFFFF, TRAINER_ENGINEER_BERNIE_2}, - MAP_GROUP(ROUTE11), MAP_NUM(ROUTE11) }, + MAP(ROUTE11) }, + { {TRAINER_ENGINEER_BERNIE, SKIP, SKIP, TRAINER_ENGINEER_BERNIE_2}, + MAP(ROUTE11) }, { {TRAINER_GAMER_HUGO, TRAINER_GAMER_HUGO}, - MAP_GROUP(ROUTE11), MAP_NUM(ROUTE11) }, + MAP(ROUTE11) }, { {TRAINER_GAMER_JASPER, TRAINER_GAMER_JASPER}, - MAP_GROUP(ROUTE11), MAP_NUM(ROUTE11) }, + MAP(ROUTE11) }, { {TRAINER_GAMER_DIRK, TRAINER_GAMER_DIRK}, - MAP_GROUP(ROUTE11), MAP_NUM(ROUTE11) }, - { {TRAINER_GAMER_DARIAN, 0xFFFF, 0xFFFF, TRAINER_GAMER_DARIAN_2}, - MAP_GROUP(ROUTE11), MAP_NUM(ROUTE11) }, + MAP(ROUTE11) }, + { {TRAINER_GAMER_DARIAN, SKIP, SKIP, TRAINER_GAMER_DARIAN_2}, + MAP(ROUTE11) }, { {TRAINER_BUG_CATCHER_BRENT, TRAINER_BUG_CATCHER_BRENT}, - MAP_GROUP(ROUTE9), MAP_NUM(ROUTE9) }, + MAP(ROUTE9) }, { {TRAINER_BUG_CATCHER_CONNER, TRAINER_BUG_CATCHER_CONNER}, - MAP_GROUP(ROUTE9), MAP_NUM(ROUTE9) }, - { {TRAINER_CAMPER_CHRIS, 0xFFFF, TRAINER_CAMPER_CHRIS_2, TRAINER_CAMPER_CHRIS_3, 0xFFFF, TRAINER_CAMPER_CHRIS_4}, - MAP_GROUP(ROUTE9), MAP_NUM(ROUTE9) }, + MAP(ROUTE9) }, + { {TRAINER_CAMPER_CHRIS, SKIP, TRAINER_CAMPER_CHRIS_2, TRAINER_CAMPER_CHRIS_3, SKIP, TRAINER_CAMPER_CHRIS_4}, + MAP(ROUTE9) }, { {TRAINER_CAMPER_DREW, TRAINER_CAMPER_DREW}, - MAP_GROUP(ROUTE9), MAP_NUM(ROUTE9) }, - { {TRAINER_PICNICKER_ALICIA, 0xFFFF, TRAINER_PICNICKER_ALICIA_2, TRAINER_PICNICKER_ALICIA_3, 0xFFFF, TRAINER_PICNICKER_ALICIA_4}, - MAP_GROUP(ROUTE9), MAP_NUM(ROUTE9) }, + MAP(ROUTE9) }, + { {TRAINER_PICNICKER_ALICIA, SKIP, TRAINER_PICNICKER_ALICIA_2, TRAINER_PICNICKER_ALICIA_3, SKIP, TRAINER_PICNICKER_ALICIA_4}, + MAP(ROUTE9) }, { {TRAINER_PICNICKER_CAITLIN, TRAINER_PICNICKER_CAITLIN}, - MAP_GROUP(ROUTE9), MAP_NUM(ROUTE9) }, + MAP(ROUTE9) }, { {TRAINER_HIKER_ALAN, TRAINER_HIKER_ALAN}, - MAP_GROUP(ROUTE9), MAP_NUM(ROUTE9) }, + MAP(ROUTE9) }, { {TRAINER_HIKER_BRICE, TRAINER_HIKER_BRICE}, - MAP_GROUP(ROUTE9), MAP_NUM(ROUTE9) }, - { {TRAINER_HIKER_JEREMY, 0xFFFF, 0xFFFF, TRAINER_HIKER_JEREMY_2}, - MAP_GROUP(ROUTE9), MAP_NUM(ROUTE9) }, + MAP(ROUTE9) }, + { {TRAINER_HIKER_JEREMY, SKIP, SKIP, TRAINER_HIKER_JEREMY_2}, + MAP(ROUTE9) }, { {TRAINER_PICNICKER_HEIDI, TRAINER_PICNICKER_HEIDI}, - MAP_GROUP(ROUTE10), MAP_NUM(ROUTE10) }, + MAP(ROUTE10) }, { {TRAINER_PICNICKER_CAROL, TRAINER_PICNICKER_CAROL}, - MAP_GROUP(ROUTE10), MAP_NUM(ROUTE10) }, - { {TRAINER_POKEMANIAC_MARK, 0xFFFF, 0xFFFF, TRAINER_POKEMANIAC_MARK_2, 0xFFFF, TRAINER_POKEMANIAC_MARK_3}, - MAP_GROUP(ROUTE10), MAP_NUM(ROUTE10) }, - { {TRAINER_POKEMANIAC_HERMAN, 0xFFFF, 0xFFFF, TRAINER_POKEMANIAC_HERMAN_2, 0xFFFF, TRAINER_POKEMANIAC_HERMAN_3}, - MAP_GROUP(ROUTE10), MAP_NUM(ROUTE10) }, + MAP(ROUTE10) }, + { {TRAINER_POKEMANIAC_MARK, SKIP, SKIP, TRAINER_POKEMANIAC_MARK_2, SKIP, TRAINER_POKEMANIAC_MARK_3}, + MAP(ROUTE10) }, + { {TRAINER_POKEMANIAC_HERMAN, SKIP, SKIP, TRAINER_POKEMANIAC_HERMAN_2, SKIP, TRAINER_POKEMANIAC_HERMAN_3}, + MAP(ROUTE10) }, { {TRAINER_HIKER_CLARK, TRAINER_HIKER_CLARK}, - MAP_GROUP(ROUTE10), MAP_NUM(ROUTE10) }, - { {TRAINER_HIKER_TRENT, 0xFFFF, 0xFFFF, TRAINER_HIKER_TRENT_2}, - MAP_GROUP(ROUTE10), MAP_NUM(ROUTE10) }, + MAP(ROUTE10) }, + { {TRAINER_HIKER_TRENT, SKIP, SKIP, TRAINER_HIKER_TRENT_2}, + MAP(ROUTE10) }, { {TRAINER_LASS_PAIGE, TRAINER_LASS_PAIGE}, - MAP_GROUP(ROUTE8), MAP_NUM(ROUTE8) }, + MAP(ROUTE8) }, { {TRAINER_LASS_ANDREA, TRAINER_LASS_ANDREA}, - MAP_GROUP(ROUTE8), MAP_NUM(ROUTE8) }, - { {TRAINER_LASS_MEGAN, 0xFFFF, TRAINER_LASS_MEGAN_2, 0xFFFF, TRAINER_LASS_MEGAN_3}, - MAP_GROUP(ROUTE8), MAP_NUM(ROUTE8) }, + MAP(ROUTE8) }, + { {TRAINER_LASS_MEGAN, SKIP, TRAINER_LASS_MEGAN_2, SKIP, TRAINER_LASS_MEGAN_3}, + MAP(ROUTE8) }, { {TRAINER_LASS_JULIA, TRAINER_LASS_JULIA}, - MAP_GROUP(ROUTE8), MAP_NUM(ROUTE8) }, + MAP(ROUTE8) }, { {TRAINER_SUPER_NERD_AIDAN, TRAINER_SUPER_NERD_AIDAN}, - MAP_GROUP(ROUTE8), MAP_NUM(ROUTE8) }, - { {TRAINER_SUPER_NERD_GLENN, 0xFFFF, 0xFFFF, TRAINER_SUPER_NERD_GLENN_2}, - MAP_GROUP(ROUTE8), MAP_NUM(ROUTE8) }, + MAP(ROUTE8) }, + { {TRAINER_SUPER_NERD_GLENN, SKIP, SKIP, TRAINER_SUPER_NERD_GLENN_2}, + MAP(ROUTE8) }, { {TRAINER_SUPER_NERD_LESLIE, TRAINER_SUPER_NERD_LESLIE}, - MAP_GROUP(ROUTE8), MAP_NUM(ROUTE8) }, + MAP(ROUTE8) }, { {TRAINER_GAMER_STAN, TRAINER_GAMER_STAN}, - MAP_GROUP(ROUTE8), MAP_NUM(ROUTE8) }, - { {TRAINER_GAMER_RICH, 0xFFFF, 0xFFFF, TRAINER_GAMER_RICH_2}, - MAP_GROUP(ROUTE8), MAP_NUM(ROUTE8) }, - { {TRAINER_TWINS_ELI_ANNE, 0xFFFF, 0xFFFF, TRAINER_TWINS_ELI_ANNE_2}, - MAP_GROUP(ROUTE8), MAP_NUM(ROUTE8) }, + MAP(ROUTE8) }, + { {TRAINER_GAMER_RICH, SKIP, SKIP, TRAINER_GAMER_RICH_2}, + MAP(ROUTE8) }, + { {TRAINER_TWINS_ELI_ANNE, SKIP, SKIP, TRAINER_TWINS_ELI_ANNE_2}, + MAP(ROUTE8) }, { {TRAINER_BIKER_RICARDO, TRAINER_BIKER_RICARDO}, - MAP_GROUP(ROUTE8), MAP_NUM(ROUTE8) }, - { {TRAINER_BIKER_JAREN, 0xFFFF, 0xFFFF, TRAINER_BIKER_JAREN_2}, - MAP_GROUP(ROUTE8), MAP_NUM(ROUTE8) }, + MAP(ROUTE8) }, + { {TRAINER_BIKER_JAREN, SKIP, SKIP, TRAINER_BIKER_JAREN_2}, + MAP(ROUTE8) }, { {TRAINER_FISHERMAN_NED, TRAINER_FISHERMAN_NED}, - MAP_GROUP(ROUTE12), MAP_NUM(ROUTE12) }, + MAP(ROUTE12) }, { {TRAINER_FISHERMAN_CHIP, TRAINER_FISHERMAN_CHIP}, - MAP_GROUP(ROUTE12), MAP_NUM(ROUTE12) }, + MAP(ROUTE12) }, { {TRAINER_FISHERMAN_HANK, TRAINER_FISHERMAN_HANK}, - MAP_GROUP(ROUTE12), MAP_NUM(ROUTE12) }, - { {TRAINER_FISHERMAN_ELLIOT, 0xFFFF, 0xFFFF, TRAINER_FISHERMAN_ELLIOT_2}, - MAP_GROUP(ROUTE12), MAP_NUM(ROUTE12) }, + MAP(ROUTE12) }, + { {TRAINER_FISHERMAN_ELLIOT, SKIP, SKIP, TRAINER_FISHERMAN_ELLIOT_2}, + MAP(ROUTE12) }, { {TRAINER_FISHERMAN_ANDREW, TRAINER_FISHERMAN_ANDREW}, - MAP_GROUP(ROUTE12), MAP_NUM(ROUTE12) }, - { {TRAINER_ROCKER_LUCA, 0xFFFF, 0xFFFF, TRAINER_ROCKER_LUCA_2}, - MAP_GROUP(ROUTE12), MAP_NUM(ROUTE12) }, + MAP(ROUTE12) }, + { {TRAINER_ROCKER_LUCA, SKIP, SKIP, TRAINER_ROCKER_LUCA_2}, + MAP(ROUTE12) }, { {TRAINER_CAMPER_JUSTIN, TRAINER_CAMPER_JUSTIN}, - MAP_GROUP(ROUTE12), MAP_NUM(ROUTE12) }, - { {TRAINER_YOUNG_COUPLE_GIA_JES, 0xFFFF, 0xFFFF, TRAINER_YOUNG_COUPLE_GIA_JES_2, 0xFFFF, TRAINER_YOUNG_COUPLE_GIA_JES_3}, - MAP_GROUP(ROUTE12), MAP_NUM(ROUTE12) }, + MAP(ROUTE12) }, + { {TRAINER_YOUNG_COUPLE_GIA_JES, SKIP, SKIP, TRAINER_YOUNG_COUPLE_GIA_JES_2, SKIP, TRAINER_YOUNG_COUPLE_GIA_JES_3}, + MAP(ROUTE12) }, { {TRAINER_BIKER_JARED, TRAINER_BIKER_JARED}, - MAP_GROUP(ROUTE13), MAP_NUM(ROUTE13) }, + MAP(ROUTE13) }, { {TRAINER_BEAUTY_LOLA, TRAINER_BEAUTY_LOLA}, - MAP_GROUP(ROUTE13), MAP_NUM(ROUTE13) }, - { {TRAINER_BEAUTY_SHEILA, 0xFFFF, 0xFFFF, 0xFFFF, TRAINER_BEAUTY_SHEILA_2}, - MAP_GROUP(ROUTE13), MAP_NUM(ROUTE13) }, + MAP(ROUTE13) }, + { {TRAINER_BEAUTY_SHEILA, SKIP, SKIP, SKIP, TRAINER_BEAUTY_SHEILA_2}, + MAP(ROUTE13) }, { {TRAINER_BIRD_KEEPER_SEBASTIAN, TRAINER_BIRD_KEEPER_SEBASTIAN}, - MAP_GROUP(ROUTE13), MAP_NUM(ROUTE13) }, + MAP(ROUTE13) }, { {TRAINER_BIRD_KEEPER_PERRY, TRAINER_BIRD_KEEPER_PERRY}, - MAP_GROUP(ROUTE13), MAP_NUM(ROUTE13) }, - { {TRAINER_BIRD_KEEPER_ROBERT, 0xFFFF, 0xFFFF, TRAINER_BIRD_KEEPER_ROBERT_2, TRAINER_BIRD_KEEPER_ROBERT_3}, - MAP_GROUP(ROUTE13), MAP_NUM(ROUTE13) }, + MAP(ROUTE13) }, + { {TRAINER_BIRD_KEEPER_ROBERT, SKIP, SKIP, TRAINER_BIRD_KEEPER_ROBERT_2, TRAINER_BIRD_KEEPER_ROBERT_3}, + MAP(ROUTE13) }, { {TRAINER_PICNICKER_ALMA, TRAINER_PICNICKER_ALMA}, - MAP_GROUP(ROUTE13), MAP_NUM(ROUTE13) }, - { {TRAINER_PICNICKER_SUSIE, 0xFFFF, 0xFFFF, TRAINER_PICNICKER_SUSIE_2, TRAINER_PICNICKER_SUSIE_3, TRAINER_PICNICKER_SUSIE_4}, - MAP_GROUP(ROUTE13), MAP_NUM(ROUTE13) }, + MAP(ROUTE13) }, + { {TRAINER_PICNICKER_SUSIE, SKIP, SKIP, TRAINER_PICNICKER_SUSIE_2, TRAINER_PICNICKER_SUSIE_3, TRAINER_PICNICKER_SUSIE_4}, + MAP(ROUTE13) }, { {TRAINER_PICNICKER_VALERIE, TRAINER_PICNICKER_VALERIE}, - MAP_GROUP(ROUTE13), MAP_NUM(ROUTE13) }, + MAP(ROUTE13) }, { {TRAINER_PICNICKER_GWEN, TRAINER_PICNICKER_GWEN}, - MAP_GROUP(ROUTE13), MAP_NUM(ROUTE13) }, + MAP(ROUTE13) }, { {TRAINER_BIKER_MALIK, TRAINER_BIKER_MALIK}, - MAP_GROUP(ROUTE14), MAP_NUM(ROUTE14) }, - { {TRAINER_BIKER_LUKAS, 0xFFFF, 0xFFFF, 0xFFFF, TRAINER_BIKER_LUKAS_2}, - MAP_GROUP(ROUTE14), MAP_NUM(ROUTE14) }, + MAP(ROUTE14) }, + { {TRAINER_BIKER_LUKAS, SKIP, SKIP, SKIP, TRAINER_BIKER_LUKAS_2}, + MAP(ROUTE14) }, { {TRAINER_BIKER_ISAAC, TRAINER_BIKER_ISAAC}, - MAP_GROUP(ROUTE14), MAP_NUM(ROUTE14) }, + MAP(ROUTE14) }, { {TRAINER_BIKER_GERALD, TRAINER_BIKER_GERALD}, - MAP_GROUP(ROUTE14), MAP_NUM(ROUTE14) }, + MAP(ROUTE14) }, { {TRAINER_BIRD_KEEPER_DONALD, TRAINER_BIRD_KEEPER_DONALD}, - MAP_GROUP(ROUTE14), MAP_NUM(ROUTE14) }, - { {TRAINER_BIRD_KEEPER_BENNY, 0xFFFF, 0xFFFF, TRAINER_BIRD_KEEPER_BENNY_2, TRAINER_BIRD_KEEPER_BENNY_3}, - MAP_GROUP(ROUTE14), MAP_NUM(ROUTE14) }, + MAP(ROUTE14) }, + { {TRAINER_BIRD_KEEPER_BENNY, SKIP, SKIP, TRAINER_BIRD_KEEPER_BENNY_2, TRAINER_BIRD_KEEPER_BENNY_3}, + MAP(ROUTE14) }, { {TRAINER_BIRD_KEEPER_CARTER, TRAINER_BIRD_KEEPER_CARTER}, - MAP_GROUP(ROUTE14), MAP_NUM(ROUTE14) }, + MAP(ROUTE14) }, { {TRAINER_BIRD_KEEPER_MITCH, TRAINER_BIRD_KEEPER_MITCH}, - MAP_GROUP(ROUTE14), MAP_NUM(ROUTE14) }, + MAP(ROUTE14) }, { {TRAINER_BIRD_KEEPER_BECK, TRAINER_BIRD_KEEPER_BECK}, - MAP_GROUP(ROUTE14), MAP_NUM(ROUTE14) }, - { {TRAINER_BIRD_KEEPER_MARLON, 0xFFFF, 0xFFFF, TRAINER_BIRD_KEEPER_MARLON_2, TRAINER_BIRD_KEEPER_MARLON_3}, - MAP_GROUP(ROUTE14), MAP_NUM(ROUTE14) }, + MAP(ROUTE14) }, + { {TRAINER_BIRD_KEEPER_MARLON, SKIP, SKIP, TRAINER_BIRD_KEEPER_MARLON_2, TRAINER_BIRD_KEEPER_MARLON_3}, + MAP(ROUTE14) }, { {TRAINER_TWINS_KIRI_JAN, TRAINER_TWINS_KIRI_JAN}, - MAP_GROUP(ROUTE14), MAP_NUM(ROUTE14) }, + MAP(ROUTE14) }, { {TRAINER_BIKER_ERNEST, TRAINER_BIKER_ERNEST}, - MAP_GROUP(ROUTE15), MAP_NUM(ROUTE15) }, + MAP(ROUTE15) }, { {TRAINER_BIKER_ALEX, TRAINER_BIKER_ALEX}, - MAP_GROUP(ROUTE15), MAP_NUM(ROUTE15) }, - { {TRAINER_BEAUTY_GRACE, 0xFFFF, 0xFFFF, 0xFFFF, TRAINER_BEAUTY_GRACE_2}, - MAP_GROUP(ROUTE15), MAP_NUM(ROUTE15) }, + MAP(ROUTE15) }, + { {TRAINER_BEAUTY_GRACE, SKIP, SKIP, SKIP, TRAINER_BEAUTY_GRACE_2}, + MAP(ROUTE15) }, { {TRAINER_BEAUTY_OLIVIA, TRAINER_BEAUTY_OLIVIA}, - MAP_GROUP(ROUTE15), MAP_NUM(ROUTE15) }, + MAP(ROUTE15) }, { {TRAINER_BIRD_KEEPER_EDWIN, TRAINER_BIRD_KEEPER_EDWIN}, - MAP_GROUP(ROUTE15), MAP_NUM(ROUTE15) }, - { {TRAINER_BIRD_KEEPER_CHESTER, 0xFFFF, 0xFFFF, TRAINER_BIRD_KEEPER_CHESTER_2, TRAINER_BIRD_KEEPER_CHESTER_3}, - MAP_GROUP(ROUTE15), MAP_NUM(ROUTE15) }, + MAP(ROUTE15) }, + { {TRAINER_BIRD_KEEPER_CHESTER, SKIP, SKIP, TRAINER_BIRD_KEEPER_CHESTER_2, TRAINER_BIRD_KEEPER_CHESTER_3}, + MAP(ROUTE15) }, { {TRAINER_PICNICKER_YAZMIN, TRAINER_PICNICKER_YAZMIN}, - MAP_GROUP(ROUTE15), MAP_NUM(ROUTE15) }, + MAP(ROUTE15) }, { {TRAINER_PICNICKER_KINDRA, TRAINER_PICNICKER_KINDRA}, - MAP_GROUP(ROUTE15), MAP_NUM(ROUTE15) }, - { {TRAINER_PICNICKER_BECKY, 0xFFFF, 0xFFFF, TRAINER_PICNICKER_BECKY_2, TRAINER_PICNICKER_BECKY_3, TRAINER_PICNICKER_BECKY_4}, - MAP_GROUP(ROUTE15), MAP_NUM(ROUTE15) }, + MAP(ROUTE15) }, + { {TRAINER_PICNICKER_BECKY, SKIP, SKIP, TRAINER_PICNICKER_BECKY_2, TRAINER_PICNICKER_BECKY_3, TRAINER_PICNICKER_BECKY_4}, + MAP(ROUTE15) }, { {TRAINER_PICNICKER_CELIA, TRAINER_PICNICKER_CELIA}, - MAP_GROUP(ROUTE15), MAP_NUM(ROUTE15) }, - { {TRAINER_CRUSH_KIN_RON_MYA, 0xFFFF, 0xFFFF, TRAINER_CRUSH_KIN_RON_MYA_2, TRAINER_CRUSH_KIN_RON_MYA_3, TRAINER_CRUSH_KIN_RON_MYA_4}, - MAP_GROUP(ROUTE15), MAP_NUM(ROUTE15) }, + MAP(ROUTE15) }, + { {TRAINER_CRUSH_KIN_RON_MYA, SKIP, SKIP, TRAINER_CRUSH_KIN_RON_MYA_2, TRAINER_CRUSH_KIN_RON_MYA_3, TRAINER_CRUSH_KIN_RON_MYA_4}, + MAP(ROUTE15) }, { {TRAINER_BIKER_LAO, TRAINER_BIKER_LAO}, - MAP_GROUP(ROUTE16), MAP_NUM(ROUTE16) }, + MAP(ROUTE16) }, { {TRAINER_BIKER_HIDEO, TRAINER_BIKER_HIDEO}, - MAP_GROUP(ROUTE16), MAP_NUM(ROUTE16) }, - { {TRAINER_BIKER_RUBEN, 0xFFFF, 0xFFFF, 0xFFFF, TRAINER_BIKER_RUBEN_2}, - MAP_GROUP(ROUTE16), MAP_NUM(ROUTE16) }, + MAP(ROUTE16) }, + { {TRAINER_BIKER_RUBEN, SKIP, SKIP, SKIP, TRAINER_BIKER_RUBEN_2}, + MAP(ROUTE16) }, { {TRAINER_CUE_BALL_KOJI, TRAINER_CUE_BALL_KOJI}, - MAP_GROUP(ROUTE16), MAP_NUM(ROUTE16) }, + MAP(ROUTE16) }, { {TRAINER_CUE_BALL_LUKE, TRAINER_CUE_BALL_LUKE}, - MAP_GROUP(ROUTE16), MAP_NUM(ROUTE16) }, - { {TRAINER_CUE_BALL_CAMRON, 0xFFFF, 0xFFFF, 0xFFFF, TRAINER_CUE_BALL_CAMRON_2}, - MAP_GROUP(ROUTE16), MAP_NUM(ROUTE16) }, + MAP(ROUTE16) }, + { {TRAINER_CUE_BALL_CAMRON, SKIP, SKIP, SKIP, TRAINER_CUE_BALL_CAMRON_2}, + MAP(ROUTE16) }, { {TRAINER_YOUNG_COUPLE_LEA_JED, TRAINER_YOUNG_COUPLE_LEA_JED}, - MAP_GROUP(ROUTE16), MAP_NUM(ROUTE16) }, + MAP(ROUTE16) }, { {TRAINER_BIKER_BILLY, TRAINER_BIKER_BILLY}, - MAP_GROUP(ROUTE17), MAP_NUM(ROUTE17) }, + MAP(ROUTE17) }, { {TRAINER_BIKER_NIKOLAS, TRAINER_BIKER_NIKOLAS}, - MAP_GROUP(ROUTE17), MAP_NUM(ROUTE17) }, - { {TRAINER_BIKER_JAXON, 0xFFFF, 0xFFFF, 0xFFFF, TRAINER_BIKER_JAXON_2}, - MAP_GROUP(ROUTE17), MAP_NUM(ROUTE17) }, + MAP(ROUTE17) }, + { {TRAINER_BIKER_JAXON, SKIP, SKIP, SKIP, TRAINER_BIKER_JAXON_2}, + MAP(ROUTE17) }, { {TRAINER_BIKER_WILLIAM, TRAINER_BIKER_WILLIAM}, - MAP_GROUP(ROUTE17), MAP_NUM(ROUTE17) }, + MAP(ROUTE17) }, { {TRAINER_CUE_BALL_RAUL, TRAINER_CUE_BALL_RAUL}, - MAP_GROUP(ROUTE17), MAP_NUM(ROUTE17) }, - { {TRAINER_CUE_BALL_ISAIAH, 0xFFFF, 0xFFFF, 0xFFFF, TRAINER_CUE_BALL_ISAIAH_2}, - MAP_GROUP(ROUTE17), MAP_NUM(ROUTE17) }, + MAP(ROUTE17) }, + { {TRAINER_CUE_BALL_ISAIAH, SKIP, SKIP, SKIP, TRAINER_CUE_BALL_ISAIAH_2}, + MAP(ROUTE17) }, { {TRAINER_CUE_BALL_ZEEK, TRAINER_CUE_BALL_ZEEK}, - MAP_GROUP(ROUTE17), MAP_NUM(ROUTE17) }, + MAP(ROUTE17) }, { {TRAINER_CUE_BALL_JAMAL, TRAINER_CUE_BALL_JAMAL}, - MAP_GROUP(ROUTE17), MAP_NUM(ROUTE17) }, - { {TRAINER_CUE_BALL_COREY, 0xFFFF, 0xFFFF, 0xFFFF, TRAINER_CUE_BALL_COREY_2}, - MAP_GROUP(ROUTE17), MAP_NUM(ROUTE17) }, + MAP(ROUTE17) }, + { {TRAINER_CUE_BALL_COREY, SKIP, SKIP, SKIP, TRAINER_CUE_BALL_COREY_2}, + MAP(ROUTE17) }, { {TRAINER_BIKER_VIRGIL, TRAINER_BIKER_VIRGIL}, - MAP_GROUP(ROUTE17), MAP_NUM(ROUTE17) }, + MAP(ROUTE17) }, { {TRAINER_BIRD_KEEPER_WILTON, TRAINER_BIRD_KEEPER_WILTON}, - MAP_GROUP(ROUTE18), MAP_NUM(ROUTE18) }, + MAP(ROUTE18) }, { {TRAINER_BIRD_KEEPER_RAMIRO, TRAINER_BIRD_KEEPER_RAMIRO}, - MAP_GROUP(ROUTE18), MAP_NUM(ROUTE18) }, - { {TRAINER_BIRD_KEEPER_JACOB, 0xFFFF, 0xFFFF, TRAINER_BIRD_KEEPER_JACOB_2, TRAINER_BIRD_KEEPER_JACOB_3}, - MAP_GROUP(ROUTE18), MAP_NUM(ROUTE18) }, + MAP(ROUTE18) }, + { {TRAINER_BIRD_KEEPER_JACOB, SKIP, SKIP, TRAINER_BIRD_KEEPER_JACOB_2, TRAINER_BIRD_KEEPER_JACOB_3}, + MAP(ROUTE18) }, { {TRAINER_SWIMMER_MALE_RICHARD, TRAINER_SWIMMER_MALE_RICHARD}, - MAP_GROUP(ROUTE19), MAP_NUM(ROUTE19) }, + MAP(ROUTE19) }, { {TRAINER_SWIMMER_MALE_REECE, TRAINER_SWIMMER_MALE_REECE}, - MAP_GROUP(ROUTE19), MAP_NUM(ROUTE19) }, - { {TRAINER_SWIMMER_MALE_MATTHEW, 0xFFFF, 0xFFFF, 0xFFFF, TRAINER_SWIMMER_MALE_MATTHEW_2}, - MAP_GROUP(ROUTE19), MAP_NUM(ROUTE19) }, + MAP(ROUTE19) }, + { {TRAINER_SWIMMER_MALE_MATTHEW, SKIP, SKIP, SKIP, TRAINER_SWIMMER_MALE_MATTHEW_2}, + MAP(ROUTE19) }, { {TRAINER_SWIMMER_MALE_DOUGLAS, TRAINER_SWIMMER_MALE_DOUGLAS}, - MAP_GROUP(ROUTE19), MAP_NUM(ROUTE19) }, + MAP(ROUTE19) }, { {TRAINER_SWIMMER_MALE_DAVID, TRAINER_SWIMMER_MALE_DAVID}, - MAP_GROUP(ROUTE19), MAP_NUM(ROUTE19) }, - { {TRAINER_SWIMMER_MALE_TONY, 0xFFFF, 0xFFFF, 0xFFFF, TRAINER_SWIMMER_MALE_TONY_2}, - MAP_GROUP(ROUTE19), MAP_NUM(ROUTE19) }, + MAP(ROUTE19) }, + { {TRAINER_SWIMMER_MALE_TONY, SKIP, SKIP, SKIP, TRAINER_SWIMMER_MALE_TONY_2}, + MAP(ROUTE19) }, { {TRAINER_SWIMMER_MALE_AXLE, TRAINER_SWIMMER_MALE_AXLE}, - MAP_GROUP(ROUTE19), MAP_NUM(ROUTE19) }, + MAP(ROUTE19) }, { {TRAINER_SWIMMER_FEMALE_ANYA, TRAINER_SWIMMER_FEMALE_ANYA}, - MAP_GROUP(ROUTE19), MAP_NUM(ROUTE19) }, - { {TRAINER_SWIMMER_FEMALE_ALICE, 0xFFFF, 0xFFFF, 0xFFFF, TRAINER_SWIMMER_FEMALE_ALICE_2}, - MAP_GROUP(ROUTE19), MAP_NUM(ROUTE19) }, + MAP(ROUTE19) }, + { {TRAINER_SWIMMER_FEMALE_ALICE, SKIP, SKIP, SKIP, TRAINER_SWIMMER_FEMALE_ALICE_2}, + MAP(ROUTE19) }, { {TRAINER_SWIMMER_FEMALE_CONNIE, TRAINER_SWIMMER_FEMALE_CONNIE}, - MAP_GROUP(ROUTE19), MAP_NUM(ROUTE19) }, + MAP(ROUTE19) }, { {TRAINER_SIS_AND_BRO_LIA_LUC, TRAINER_SIS_AND_BRO_LIA_LUC}, - MAP_GROUP(ROUTE19), MAP_NUM(ROUTE19) }, + MAP(ROUTE19) }, { {TRAINER_SWIMMER_MALE_BARRY, TRAINER_SWIMMER_MALE_BARRY}, - MAP_GROUP(ROUTE20), MAP_NUM(ROUTE20) }, + MAP(ROUTE20) }, { {TRAINER_SWIMMER_MALE_DEAN, TRAINER_SWIMMER_MALE_DEAN}, - MAP_GROUP(ROUTE20), MAP_NUM(ROUTE20) }, - { {TRAINER_SWIMMER_MALE_DARRIN, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, TRAINER_SWIMMER_MALE_DARRIN_2}, - MAP_GROUP(ROUTE20), MAP_NUM(ROUTE20) }, + MAP(ROUTE20) }, + { {TRAINER_SWIMMER_MALE_DARRIN, SKIP, SKIP, SKIP, SKIP, TRAINER_SWIMMER_MALE_DARRIN_2}, + MAP(ROUTE20) }, { {TRAINER_SWIMMER_FEMALE_TIFFANY, TRAINER_SWIMMER_FEMALE_TIFFANY}, - MAP_GROUP(ROUTE20), MAP_NUM(ROUTE20) }, + MAP(ROUTE20) }, { {TRAINER_SWIMMER_FEMALE_NORA, TRAINER_SWIMMER_FEMALE_NORA}, - MAP_GROUP(ROUTE20), MAP_NUM(ROUTE20) }, - { {TRAINER_SWIMMER_FEMALE_MELISSA, 0xFFFF, 0xFFFF, 0xFFFF, TRAINER_SWIMMER_FEMALE_MELISSA_2}, - MAP_GROUP(ROUTE20), MAP_NUM(ROUTE20) }, + MAP(ROUTE20) }, + { {TRAINER_SWIMMER_FEMALE_MELISSA, SKIP, SKIP, SKIP, TRAINER_SWIMMER_FEMALE_MELISSA_2}, + MAP(ROUTE20) }, { {TRAINER_SWIMMER_FEMALE_SHIRLEY, TRAINER_SWIMMER_FEMALE_SHIRLEY}, - MAP_GROUP(ROUTE20), MAP_NUM(ROUTE20) }, + MAP(ROUTE20) }, { {TRAINER_BIRD_KEEPER_ROGER, TRAINER_BIRD_KEEPER_ROGER}, - MAP_GROUP(ROUTE20), MAP_NUM(ROUTE20) }, - { {TRAINER_PICNICKER_MISSY, 0xFFFF, 0xFFFF, 0xFFFF, TRAINER_PICNICKER_MISSY_2, TRAINER_PICNICKER_MISSY_3}, - MAP_GROUP(ROUTE20), MAP_NUM(ROUTE20) }, + MAP(ROUTE20) }, + { {TRAINER_PICNICKER_MISSY, SKIP, SKIP, SKIP, TRAINER_PICNICKER_MISSY_2, TRAINER_PICNICKER_MISSY_3}, + MAP(ROUTE20) }, { {TRAINER_PICNICKER_IRENE, TRAINER_PICNICKER_IRENE}, - MAP_GROUP(ROUTE20), MAP_NUM(ROUTE20) }, + MAP(ROUTE20) }, { {TRAINER_FISHERMAN_RONALD, TRAINER_FISHERMAN_RONALD}, - MAP_GROUP(ROUTE21_NORTH), MAP_NUM(ROUTE21_NORTH) }, + MAP(ROUTE21_NORTH) }, { {TRAINER_FISHERMAN_CLAUDE, TRAINER_FISHERMAN_CLAUDE}, - MAP_GROUP(ROUTE21_NORTH), MAP_NUM(ROUTE21_NORTH) }, - { {TRAINER_FISHERMAN_WADE, 0xFFFF, 0xFFFF, 0xFFFF, TRAINER_FISHERMAN_WADE_2}, - MAP_GROUP(ROUTE21_NORTH), MAP_NUM(ROUTE21_NORTH) }, + MAP(ROUTE21_NORTH) }, + { {TRAINER_FISHERMAN_WADE, SKIP, SKIP, SKIP, TRAINER_FISHERMAN_WADE_2}, + MAP(ROUTE21_NORTH) }, { {TRAINER_FISHERMAN_NOLAN, TRAINER_FISHERMAN_NOLAN}, - MAP_GROUP(ROUTE21_NORTH), MAP_NUM(ROUTE21_NORTH) }, + MAP(ROUTE21_NORTH) }, { {TRAINER_SWIMMER_MALE_SPENCER, TRAINER_SWIMMER_MALE_SPENCER}, - MAP_GROUP(ROUTE21_NORTH), MAP_NUM(ROUTE21_NORTH) }, - { {TRAINER_SWIMMER_MALE_JACK, 0xFFFF, 0xFFFF, 0xFFFF, TRAINER_SWIMMER_MALE_JACK_2}, - MAP_GROUP(ROUTE21_NORTH), MAP_NUM(ROUTE21_NORTH) }, + MAP(ROUTE21_NORTH) }, + { {TRAINER_SWIMMER_MALE_JACK, SKIP, SKIP, SKIP, TRAINER_SWIMMER_MALE_JACK_2}, + MAP(ROUTE21_NORTH) }, { {TRAINER_SWIMMER_MALE_JEROME, TRAINER_SWIMMER_MALE_JEROME}, - MAP_GROUP(ROUTE21_NORTH), MAP_NUM(ROUTE21_NORTH) }, + MAP(ROUTE21_NORTH) }, { {TRAINER_SWIMMER_MALE_ROLAND, TRAINER_SWIMMER_MALE_ROLAND}, - MAP_GROUP(ROUTE21_NORTH), MAP_NUM(ROUTE21_NORTH) }, - { {TRAINER_SIS_AND_BRO_LIL_IAN, 0xFFFF, 0xFFFF, 0xFFFF, TRAINER_SIS_AND_BRO_LIL_IAN_2, TRAINER_SIS_AND_BRO_LIL_IAN_3}, - MAP_GROUP(ROUTE21_NORTH), MAP_NUM(ROUTE21_NORTH) }, + MAP(ROUTE21_NORTH) }, + { {TRAINER_SIS_AND_BRO_LIL_IAN, SKIP, SKIP, SKIP, TRAINER_SIS_AND_BRO_LIL_IAN_2, TRAINER_SIS_AND_BRO_LIL_IAN_3}, + MAP(ROUTE21_NORTH) }, { {TRAINER_SWIMMER_FEMALE_MARIA, TRAINER_SWIMMER_FEMALE_MARIA}, - MAP_GROUP(ONE_ISLAND_KINDLE_ROAD), MAP_NUM(ONE_ISLAND_KINDLE_ROAD) }, + MAP(ONE_ISLAND_KINDLE_ROAD) }, { {TRAINER_SWIMMER_FEMALE_ABIGAIL, TRAINER_SWIMMER_FEMALE_ABIGAIL}, - MAP_GROUP(ONE_ISLAND_KINDLE_ROAD), MAP_NUM(ONE_ISLAND_KINDLE_ROAD) }, - { {TRAINER_SWIMMER_MALE_FINN, 0xFFFF, 0xFFFF, 0xFFFF, TRAINER_SWIMMER_MALE_FINN_2}, - MAP_GROUP(ONE_ISLAND_KINDLE_ROAD), MAP_NUM(ONE_ISLAND_KINDLE_ROAD) }, + MAP(ONE_ISLAND_KINDLE_ROAD) }, + { {TRAINER_SWIMMER_MALE_FINN, SKIP, SKIP, SKIP, TRAINER_SWIMMER_MALE_FINN_2}, + MAP(ONE_ISLAND_KINDLE_ROAD) }, { {TRAINER_SWIMMER_MALE_GARRETT, TRAINER_SWIMMER_MALE_GARRETT}, - MAP_GROUP(ONE_ISLAND_KINDLE_ROAD), MAP_NUM(ONE_ISLAND_KINDLE_ROAD) }, + MAP(ONE_ISLAND_KINDLE_ROAD) }, { {TRAINER_FISHERMAN_TOMMY, TRAINER_FISHERMAN_TOMMY}, - MAP_GROUP(ONE_ISLAND_KINDLE_ROAD), MAP_NUM(ONE_ISLAND_KINDLE_ROAD) }, - { {TRAINER_CRUSH_GIRL_SHARON, 0xFFFF, 0xFFFF, 0xFFFF, TRAINER_CRUSH_GIRL_SHARON_2, TRAINER_CRUSH_GIRL_SHARON_3}, - MAP_GROUP(ONE_ISLAND_KINDLE_ROAD), MAP_NUM(ONE_ISLAND_KINDLE_ROAD) }, - { {TRAINER_CRUSH_GIRL_TANYA, 0xFFFF, 0xFFFF, 0xFFFF, TRAINER_CRUSH_GIRL_TANYA_2, TRAINER_CRUSH_GIRL_TANYA_3}, - MAP_GROUP(ONE_ISLAND_KINDLE_ROAD), MAP_NUM(ONE_ISLAND_KINDLE_ROAD) }, - { {TRAINER_BLACK_BELT_SHEA, 0xFFFF, 0xFFFF, 0xFFFF, TRAINER_BLACK_BELT_SHEA_2, TRAINER_BLACK_BELT_SHEA_3}, - MAP_GROUP(ONE_ISLAND_KINDLE_ROAD), MAP_NUM(ONE_ISLAND_KINDLE_ROAD) }, - { {TRAINER_BLACK_BELT_HUGH, 0xFFFF, 0xFFFF, 0xFFFF, TRAINER_BLACK_BELT_HUGH_2, TRAINER_BLACK_BELT_HUGH_3}, - MAP_GROUP(ONE_ISLAND_KINDLE_ROAD), MAP_NUM(ONE_ISLAND_KINDLE_ROAD) }, + MAP(ONE_ISLAND_KINDLE_ROAD) }, + { {TRAINER_CRUSH_GIRL_SHARON, SKIP, SKIP, SKIP, TRAINER_CRUSH_GIRL_SHARON_2, TRAINER_CRUSH_GIRL_SHARON_3}, + MAP(ONE_ISLAND_KINDLE_ROAD) }, + { {TRAINER_CRUSH_GIRL_TANYA, SKIP, SKIP, SKIP, TRAINER_CRUSH_GIRL_TANYA_2, TRAINER_CRUSH_GIRL_TANYA_3}, + MAP(ONE_ISLAND_KINDLE_ROAD) }, + { {TRAINER_BLACK_BELT_SHEA, SKIP, SKIP, SKIP, TRAINER_BLACK_BELT_SHEA_2, TRAINER_BLACK_BELT_SHEA_3}, + MAP(ONE_ISLAND_KINDLE_ROAD) }, + { {TRAINER_BLACK_BELT_HUGH, SKIP, SKIP, SKIP, TRAINER_BLACK_BELT_HUGH_2, TRAINER_BLACK_BELT_HUGH_3}, + MAP(ONE_ISLAND_KINDLE_ROAD) }, { {TRAINER_CAMPER_BRYCE, TRAINER_CAMPER_BRYCE}, - MAP_GROUP(ONE_ISLAND_KINDLE_ROAD), MAP_NUM(ONE_ISLAND_KINDLE_ROAD) }, + MAP(ONE_ISLAND_KINDLE_ROAD) }, { {TRAINER_PICNICKER_CLAIRE, TRAINER_PICNICKER_CLAIRE}, - MAP_GROUP(ONE_ISLAND_KINDLE_ROAD), MAP_NUM(ONE_ISLAND_KINDLE_ROAD) }, - { {TRAINER_CRUSH_KIN_MIK_KIA, 0xFFFF, 0xFFFF, 0xFFFF, TRAINER_CRUSH_KIN_MIK_KIA_2, TRAINER_CRUSH_KIN_MIK_KIA_3}, - MAP_GROUP(ONE_ISLAND_KINDLE_ROAD), MAP_NUM(ONE_ISLAND_KINDLE_ROAD) }, + MAP(ONE_ISLAND_KINDLE_ROAD) }, + { {TRAINER_CRUSH_KIN_MIK_KIA, SKIP, SKIP, SKIP, TRAINER_CRUSH_KIN_MIK_KIA_2, TRAINER_CRUSH_KIN_MIK_KIA_3}, + MAP(ONE_ISLAND_KINDLE_ROAD) }, { {TRAINER_SWIMMER_FEMALE_AMARA, TRAINER_SWIMMER_FEMALE_AMARA}, - MAP_GROUP(ONE_ISLAND_TREASURE_BEACH), MAP_NUM(ONE_ISLAND_TREASURE_BEACH) }, + MAP(ONE_ISLAND_TREASURE_BEACH) }, { {TRAINER_AROMA_LADY_NIKKI, TRAINER_AROMA_LADY_NIKKI}, - MAP_GROUP(THREE_ISLAND_BOND_BRIDGE), MAP_NUM(THREE_ISLAND_BOND_BRIDGE) }, + MAP(THREE_ISLAND_BOND_BRIDGE) }, { {TRAINER_AROMA_LADY_VIOLET, TRAINER_AROMA_LADY_VIOLET}, - MAP_GROUP(THREE_ISLAND_BOND_BRIDGE), MAP_NUM(THREE_ISLAND_BOND_BRIDGE) }, - { {TRAINER_TUBER_AMIRA, 0xFFFF, 0xFFFF, 0xFFFF, TRAINER_TUBER_AMIRA_2}, - MAP_GROUP(THREE_ISLAND_BOND_BRIDGE), MAP_NUM(THREE_ISLAND_BOND_BRIDGE) }, + MAP(THREE_ISLAND_BOND_BRIDGE) }, + { {TRAINER_TUBER_AMIRA, SKIP, SKIP, SKIP, TRAINER_TUBER_AMIRA_2}, + MAP(THREE_ISLAND_BOND_BRIDGE) }, { {TRAINER_TUBER_ALEXIS, TRAINER_TUBER_ALEXIS}, - MAP_GROUP(THREE_ISLAND_BOND_BRIDGE), MAP_NUM(THREE_ISLAND_BOND_BRIDGE) }, + MAP(THREE_ISLAND_BOND_BRIDGE) }, { {TRAINER_SWIMMER_FEMALE_TISHA, TRAINER_SWIMMER_FEMALE_TISHA}, - MAP_GROUP(THREE_ISLAND_BOND_BRIDGE), MAP_NUM(THREE_ISLAND_BOND_BRIDGE) }, - { {TRAINER_TWINS_JOY_MEG, 0xFFFF, 0xFFFF, 0xFFFF, TRAINER_TWINS_JOY_MEG_2}, - MAP_GROUP(THREE_ISLAND_BOND_BRIDGE), MAP_NUM(THREE_ISLAND_BOND_BRIDGE) }, + MAP(THREE_ISLAND_BOND_BRIDGE) }, + { {TRAINER_TWINS_JOY_MEG, SKIP, SKIP, SKIP, TRAINER_TWINS_JOY_MEG_2}, + MAP(THREE_ISLAND_BOND_BRIDGE) }, { {TRAINER_PAINTER_DAISY, TRAINER_PAINTER_DAISY}, - MAP_GROUP(FIVE_ISLAND_RESORT_GORGEOUS), MAP_NUM(FIVE_ISLAND_RESORT_GORGEOUS) }, + MAP(FIVE_ISLAND_RESORT_GORGEOUS) }, { {TRAINER_PAINTER_CELINA, TRAINER_PAINTER_CELINA}, - MAP_GROUP(FIVE_ISLAND_RESORT_GORGEOUS), MAP_NUM(FIVE_ISLAND_RESORT_GORGEOUS) }, - { {TRAINER_PAINTER_RAYNA, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, TRAINER_PAINTER_RAYNA_2}, - MAP_GROUP(FIVE_ISLAND_RESORT_GORGEOUS), MAP_NUM(FIVE_ISLAND_RESORT_GORGEOUS) }, + MAP(FIVE_ISLAND_RESORT_GORGEOUS) }, + { {TRAINER_PAINTER_RAYNA, SKIP, SKIP, SKIP, SKIP, TRAINER_PAINTER_RAYNA_2}, + MAP(FIVE_ISLAND_RESORT_GORGEOUS) }, { {TRAINER_LADY_JACKI, TRAINER_LADY_JACKI}, - MAP_GROUP(FIVE_ISLAND_RESORT_GORGEOUS), MAP_NUM(FIVE_ISLAND_RESORT_GORGEOUS) }, + MAP(FIVE_ISLAND_RESORT_GORGEOUS) }, { {TRAINER_LADY_GILLIAN, TRAINER_LADY_GILLIAN}, - MAP_GROUP(FIVE_ISLAND_RESORT_GORGEOUS), MAP_NUM(FIVE_ISLAND_RESORT_GORGEOUS) }, - { {TRAINER_YOUNGSTER_DESTIN, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, TRAINER_YOUNGSTER_DESTIN_2}, - MAP_GROUP(FIVE_ISLAND_RESORT_GORGEOUS), MAP_NUM(FIVE_ISLAND_RESORT_GORGEOUS) }, + MAP(FIVE_ISLAND_RESORT_GORGEOUS) }, + { {TRAINER_YOUNGSTER_DESTIN, SKIP, SKIP, SKIP, SKIP, TRAINER_YOUNGSTER_DESTIN_2}, + MAP(FIVE_ISLAND_RESORT_GORGEOUS) }, { {TRAINER_SWIMMER_MALE_TOBY, TRAINER_SWIMMER_MALE_TOBY}, - MAP_GROUP(FIVE_ISLAND_RESORT_GORGEOUS), MAP_NUM(FIVE_ISLAND_RESORT_GORGEOUS) }, - { {TRAINER_PKMN_BREEDER_ALIZE, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, TRAINER_PKMN_BREEDER_ALIZE_2}, - MAP_GROUP(FIVE_ISLAND_WATER_LABYRINTH), MAP_NUM(FIVE_ISLAND_WATER_LABYRINTH) }, - { {TRAINER_BIRD_KEEPER_MILO, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, TRAINER_BIRD_KEEPER_MILO_2}, - MAP_GROUP(FIVE_ISLAND_MEMORIAL_PILLAR), MAP_NUM(FIVE_ISLAND_MEMORIAL_PILLAR) }, - { {TRAINER_BIRD_KEEPER_CHAZ, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, TRAINER_BIRD_KEEPER_CHAZ_2}, - MAP_GROUP(FIVE_ISLAND_MEMORIAL_PILLAR), MAP_NUM(FIVE_ISLAND_MEMORIAL_PILLAR) }, - { {TRAINER_BIRD_KEEPER_HAROLD, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, TRAINER_BIRD_KEEPER_HAROLD_2}, - MAP_GROUP(FIVE_ISLAND_MEMORIAL_PILLAR), MAP_NUM(FIVE_ISLAND_MEMORIAL_PILLAR) }, + MAP(FIVE_ISLAND_RESORT_GORGEOUS) }, + { {TRAINER_PKMN_BREEDER_ALIZE, SKIP, SKIP, SKIP, SKIP, TRAINER_PKMN_BREEDER_ALIZE_2}, + MAP(FIVE_ISLAND_WATER_LABYRINTH) }, + { {TRAINER_BIRD_KEEPER_MILO, SKIP, SKIP, SKIP, SKIP, TRAINER_BIRD_KEEPER_MILO_2}, + MAP(FIVE_ISLAND_MEMORIAL_PILLAR) }, + { {TRAINER_BIRD_KEEPER_CHAZ, SKIP, SKIP, SKIP, SKIP, TRAINER_BIRD_KEEPER_CHAZ_2}, + MAP(FIVE_ISLAND_MEMORIAL_PILLAR) }, + { {TRAINER_BIRD_KEEPER_HAROLD, SKIP, SKIP, SKIP, SKIP, TRAINER_BIRD_KEEPER_HAROLD_2}, + MAP(FIVE_ISLAND_MEMORIAL_PILLAR) }, { {TRAINER_FISHERMAN_TYLOR, TRAINER_FISHERMAN_TYLOR}, - MAP_GROUP(SIX_ISLAND_OUTCAST_ISLAND), MAP_NUM(SIX_ISLAND_OUTCAST_ISLAND) }, + MAP(SIX_ISLAND_OUTCAST_ISLAND) }, { {TRAINER_SWIMMER_MALE_MYMO, TRAINER_SWIMMER_MALE_MYMO}, - MAP_GROUP(SIX_ISLAND_OUTCAST_ISLAND), MAP_NUM(SIX_ISLAND_OUTCAST_ISLAND) }, - { {TRAINER_SWIMMER_FEMALE_NICOLE, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, TRAINER_SWIMMER_FEMALE_NICOLE_2}, - MAP_GROUP(SIX_ISLAND_OUTCAST_ISLAND), MAP_NUM(SIX_ISLAND_OUTCAST_ISLAND) }, + MAP(SIX_ISLAND_OUTCAST_ISLAND) }, + { {TRAINER_SWIMMER_FEMALE_NICOLE, SKIP, SKIP, SKIP, SKIP, TRAINER_SWIMMER_FEMALE_NICOLE_2}, + MAP(SIX_ISLAND_OUTCAST_ISLAND) }, { {TRAINER_SIS_AND_BRO_AVA_GEB, TRAINER_SIS_AND_BRO_AVA_GEB}, - MAP_GROUP(SIX_ISLAND_OUTCAST_ISLAND), MAP_NUM(SIX_ISLAND_OUTCAST_ISLAND) }, - { {TRAINER_PSYCHIC_JACLYN, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, TRAINER_PSYCHIC_JACLYN_2}, - MAP_GROUP(SIX_ISLAND_GREEN_PATH), MAP_NUM(SIX_ISLAND_GREEN_PATH) }, + MAP(SIX_ISLAND_OUTCAST_ISLAND) }, + { {TRAINER_PSYCHIC_JACLYN, SKIP, SKIP, SKIP, SKIP, TRAINER_PSYCHIC_JACLYN_2}, + MAP(SIX_ISLAND_GREEN_PATH) }, { {TRAINER_AROMA_LADY_ROSE, TRAINER_AROMA_LADY_ROSE}, - MAP_GROUP(SIX_ISLAND_WATER_PATH), MAP_NUM(SIX_ISLAND_WATER_PATH) }, + MAP(SIX_ISLAND_WATER_PATH) }, { {TRAINER_JUGGLER_EDWARD, TRAINER_JUGGLER_EDWARD}, - MAP_GROUP(SIX_ISLAND_WATER_PATH), MAP_NUM(SIX_ISLAND_WATER_PATH) }, - { {TRAINER_SWIMMER_MALE_SAMIR, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, TRAINER_SWIMMER_MALE_SAMIR_2}, - MAP_GROUP(SIX_ISLAND_WATER_PATH), MAP_NUM(SIX_ISLAND_WATER_PATH) }, + MAP(SIX_ISLAND_WATER_PATH) }, + { {TRAINER_SWIMMER_MALE_SAMIR, SKIP, SKIP, SKIP, SKIP, TRAINER_SWIMMER_MALE_SAMIR_2}, + MAP(SIX_ISLAND_WATER_PATH) }, { {TRAINER_SWIMMER_FEMALE_DENISE, TRAINER_SWIMMER_FEMALE_DENISE}, - MAP_GROUP(SIX_ISLAND_WATER_PATH), MAP_NUM(SIX_ISLAND_WATER_PATH) }, + MAP(SIX_ISLAND_WATER_PATH) }, { {TRAINER_TWINS_MIU_MIA, TRAINER_TWINS_MIU_MIA}, - MAP_GROUP(SIX_ISLAND_WATER_PATH), MAP_NUM(SIX_ISLAND_WATER_PATH) }, - { {TRAINER_HIKER_EARL, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, TRAINER_HIKER_EARL_2}, - MAP_GROUP(SIX_ISLAND_WATER_PATH), MAP_NUM(SIX_ISLAND_WATER_PATH) }, + MAP(SIX_ISLAND_WATER_PATH) }, + { {TRAINER_HIKER_EARL, SKIP, SKIP, SKIP, SKIP, TRAINER_HIKER_EARL_2}, + MAP(SIX_ISLAND_WATER_PATH) }, { {TRAINER_RUIN_MANIAC_STANLY, TRAINER_RUIN_MANIAC_STANLY}, - MAP_GROUP(SIX_ISLAND_RUIN_VALLEY), MAP_NUM(SIX_ISLAND_RUIN_VALLEY) }, + MAP(SIX_ISLAND_RUIN_VALLEY) }, { {TRAINER_RUIN_MANIAC_FOSTER, TRAINER_RUIN_MANIAC_FOSTER}, - MAP_GROUP(SIX_ISLAND_RUIN_VALLEY), MAP_NUM(SIX_ISLAND_RUIN_VALLEY) }, - { {TRAINER_RUIN_MANIAC_LARRY, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, TRAINER_RUIN_MANIAC_LARRY_2}, - MAP_GROUP(SIX_ISLAND_RUIN_VALLEY), MAP_NUM(SIX_ISLAND_RUIN_VALLEY) }, + MAP(SIX_ISLAND_RUIN_VALLEY) }, + { {TRAINER_RUIN_MANIAC_LARRY, SKIP, SKIP, SKIP, SKIP, TRAINER_RUIN_MANIAC_LARRY_2}, + MAP(SIX_ISLAND_RUIN_VALLEY) }, { {TRAINER_HIKER_DARYL, TRAINER_HIKER_DARYL}, - MAP_GROUP(SIX_ISLAND_RUIN_VALLEY), MAP_NUM(SIX_ISLAND_RUIN_VALLEY) }, - { {TRAINER_POKEMANIAC_HECTOR, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, TRAINER_POKEMANIAC_HECTOR_2}, - MAP_GROUP(SIX_ISLAND_RUIN_VALLEY), MAP_NUM(SIX_ISLAND_RUIN_VALLEY) }, - { {TRAINER_PSYCHIC_DARIO, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, TRAINER_PSYCHIC_DARIO_2}, - MAP_GROUP(SEVEN_ISLAND_TRAINER_TOWER), MAP_NUM(SEVEN_ISLAND_TRAINER_TOWER) }, - { {TRAINER_PSYCHIC_RODETTE, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, TRAINER_PSYCHIC_RODETTE_2}, - MAP_GROUP(SEVEN_ISLAND_TRAINER_TOWER), MAP_NUM(SEVEN_ISLAND_TRAINER_TOWER) }, + MAP(SIX_ISLAND_RUIN_VALLEY) }, + { {TRAINER_POKEMANIAC_HECTOR, SKIP, SKIP, SKIP, SKIP, TRAINER_POKEMANIAC_HECTOR_2}, + MAP(SIX_ISLAND_RUIN_VALLEY) }, + { {TRAINER_PSYCHIC_DARIO, SKIP, SKIP, SKIP, SKIP, TRAINER_PSYCHIC_DARIO_2}, + MAP(SEVEN_ISLAND_TRAINER_TOWER) }, + { {TRAINER_PSYCHIC_RODETTE, SKIP, SKIP, SKIP, SKIP, TRAINER_PSYCHIC_RODETTE_2}, + MAP(SEVEN_ISLAND_TRAINER_TOWER) }, { {TRAINER_AROMA_LADY_MIAH, TRAINER_AROMA_LADY_MIAH}, - MAP_GROUP(SEVEN_ISLAND_SEVAULT_CANYON_ENTRANCE), MAP_NUM(SEVEN_ISLAND_SEVAULT_CANYON_ENTRANCE) }, + MAP(SEVEN_ISLAND_SEVAULT_CANYON_ENTRANCE) }, { {TRAINER_YOUNG_COUPLE_EVE_JON, TRAINER_YOUNG_COUPLE_EVE_JON}, - MAP_GROUP(SEVEN_ISLAND_SEVAULT_CANYON_ENTRANCE), MAP_NUM(SEVEN_ISLAND_SEVAULT_CANYON_ENTRANCE) }, - { {TRAINER_JUGGLER_MASON, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, TRAINER_JUGGLER_MASON_2}, - MAP_GROUP(SEVEN_ISLAND_SEVAULT_CANYON_ENTRANCE), MAP_NUM(SEVEN_ISLAND_SEVAULT_CANYON_ENTRANCE) }, - { {TRAINER_PKMN_RANGER_NICOLAS, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, TRAINER_PKMN_RANGER_NICOLAS_2}, - MAP_GROUP(SEVEN_ISLAND_SEVAULT_CANYON_ENTRANCE), MAP_NUM(SEVEN_ISLAND_SEVAULT_CANYON_ENTRANCE) }, - { {TRAINER_PKMN_RANGER_MADELINE, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, TRAINER_PKMN_RANGER_MADELINE_2}, - MAP_GROUP(SEVEN_ISLAND_SEVAULT_CANYON_ENTRANCE), MAP_NUM(SEVEN_ISLAND_SEVAULT_CANYON_ENTRANCE) }, - { {TRAINER_CRUSH_GIRL_CYNDY, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, TRAINER_CRUSH_GIRL_CYNDY_2}, - MAP_GROUP(SEVEN_ISLAND_SEVAULT_CANYON), MAP_NUM(SEVEN_ISLAND_SEVAULT_CANYON) }, - { {TRAINER_TAMER_EVAN, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, TRAINER_TAMER_EVAN_2}, - MAP_GROUP(SEVEN_ISLAND_SEVAULT_CANYON), MAP_NUM(SEVEN_ISLAND_SEVAULT_CANYON) }, - { {TRAINER_PKMN_RANGER_JACKSON, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, TRAINER_PKMN_RANGER_JACKSON_2}, - MAP_GROUP(SEVEN_ISLAND_SEVAULT_CANYON), MAP_NUM(SEVEN_ISLAND_SEVAULT_CANYON) }, - { {TRAINER_PKMN_RANGER_KATELYN, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, TRAINER_PKMN_RANGER_KATELYN_2}, - MAP_GROUP(SEVEN_ISLAND_SEVAULT_CANYON), MAP_NUM(SEVEN_ISLAND_SEVAULT_CANYON) }, - { {TRAINER_COOLTRAINER_LEROY, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, TRAINER_COOLTRAINER_LEROY_2}, - MAP_GROUP(SEVEN_ISLAND_SEVAULT_CANYON), MAP_NUM(SEVEN_ISLAND_SEVAULT_CANYON) }, - { {TRAINER_COOLTRAINER_MICHELLE, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, TRAINER_COOLTRAINER_MICHELLE_2}, - MAP_GROUP(SEVEN_ISLAND_SEVAULT_CANYON), MAP_NUM(SEVEN_ISLAND_SEVAULT_CANYON) }, - { {TRAINER_COOL_COUPLE_LEX_NYA, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, TRAINER_COOL_COUPLE_LEX_NYA_2}, - MAP_GROUP(SEVEN_ISLAND_SEVAULT_CANYON), MAP_NUM(SEVEN_ISLAND_SEVAULT_CANYON) }, + MAP(SEVEN_ISLAND_SEVAULT_CANYON_ENTRANCE) }, + { {TRAINER_JUGGLER_MASON, SKIP, SKIP, SKIP, SKIP, TRAINER_JUGGLER_MASON_2}, + MAP(SEVEN_ISLAND_SEVAULT_CANYON_ENTRANCE) }, + { {TRAINER_PKMN_RANGER_NICOLAS, SKIP, SKIP, SKIP, SKIP, TRAINER_PKMN_RANGER_NICOLAS_2}, + MAP(SEVEN_ISLAND_SEVAULT_CANYON_ENTRANCE) }, + { {TRAINER_PKMN_RANGER_MADELINE, SKIP, SKIP, SKIP, SKIP, TRAINER_PKMN_RANGER_MADELINE_2}, + MAP(SEVEN_ISLAND_SEVAULT_CANYON_ENTRANCE) }, + { {TRAINER_CRUSH_GIRL_CYNDY, SKIP, SKIP, SKIP, SKIP, TRAINER_CRUSH_GIRL_CYNDY_2}, + MAP(SEVEN_ISLAND_SEVAULT_CANYON) }, + { {TRAINER_TAMER_EVAN, SKIP, SKIP, SKIP, SKIP, TRAINER_TAMER_EVAN_2}, + MAP(SEVEN_ISLAND_SEVAULT_CANYON) }, + { {TRAINER_PKMN_RANGER_JACKSON, SKIP, SKIP, SKIP, SKIP, TRAINER_PKMN_RANGER_JACKSON_2}, + MAP(SEVEN_ISLAND_SEVAULT_CANYON) }, + { {TRAINER_PKMN_RANGER_KATELYN, SKIP, SKIP, SKIP, SKIP, TRAINER_PKMN_RANGER_KATELYN_2}, + MAP(SEVEN_ISLAND_SEVAULT_CANYON) }, + { {TRAINER_COOLTRAINER_LEROY, SKIP, SKIP, SKIP, SKIP, TRAINER_COOLTRAINER_LEROY_2}, + MAP(SEVEN_ISLAND_SEVAULT_CANYON) }, + { {TRAINER_COOLTRAINER_MICHELLE, SKIP, SKIP, SKIP, SKIP, TRAINER_COOLTRAINER_MICHELLE_2}, + MAP(SEVEN_ISLAND_SEVAULT_CANYON) }, + { {TRAINER_COOL_COUPLE_LEX_NYA, SKIP, SKIP, SKIP, SKIP, TRAINER_COOL_COUPLE_LEX_NYA_2}, + MAP(SEVEN_ISLAND_SEVAULT_CANYON) }, { {TRAINER_RUIN_MANIAC_BRANDON, TRAINER_RUIN_MANIAC_BRANDON}, - MAP_GROUP(SEVEN_ISLAND_TANOBY_RUINS), MAP_NUM(SEVEN_ISLAND_TANOBY_RUINS) }, + MAP(SEVEN_ISLAND_TANOBY_RUINS) }, { {TRAINER_RUIN_MANIAC_BENJAMIN, TRAINER_RUIN_MANIAC_BENJAMIN}, - MAP_GROUP(SEVEN_ISLAND_TANOBY_RUINS), MAP_NUM(SEVEN_ISLAND_TANOBY_RUINS) }, + MAP(SEVEN_ISLAND_TANOBY_RUINS) }, { {TRAINER_PAINTER_EDNA, TRAINER_PAINTER_EDNA}, - MAP_GROUP(SEVEN_ISLAND_TANOBY_RUINS), MAP_NUM(SEVEN_ISLAND_TANOBY_RUINS) }, + MAP(SEVEN_ISLAND_TANOBY_RUINS) }, { {TRAINER_GENTLEMAN_CLIFFORD, TRAINER_GENTLEMAN_CLIFFORD}, - MAP_GROUP(SEVEN_ISLAND_TANOBY_RUINS), MAP_NUM(SEVEN_ISLAND_TANOBY_RUINS) }, + MAP(SEVEN_ISLAND_TANOBY_RUINS) }, }; static const u8 sMovementScript_Wait48[] = { @@ -760,7 +763,7 @@ void Task_VsSeeker_0(u8 taskId) } else if (respval == VSSEEKER_CAN_USE) { - ItemUse_SetQuestLogEvent(QL_EVENT_USED_ITEM, 0, gSpecialVar_ItemId, 0xffff); + ItemUse_SetQuestLogEvent(QL_EVENT_USED_ITEM, 0, gSpecialVar_ItemId, 0xFFFF); FieldEffectStart(FLDEFF_USE_VS_SEEKER); gTasks[taskId].func = Task_VsSeeker_1; gTasks[taskId].data[0] = 15; @@ -792,7 +795,7 @@ static void Task_VsSeeker_2(u8 taskId) data[1] = 0; data[2] = 0; VsSeekerResetInBagStepCounter(); - sVsSeeker->responseCode = GetVsSeekerResponseInArea(sVsSeekerData); + sVsSeeker->responseCode = GetVsSeekerResponseInArea(sRematches); ScriptMovement_StartObjectMovementScript(0xFF, gSaveBlock1Ptr->location.mapNum, gSaveBlock1Ptr->location.mapGroup, sMovementScript_Wait48); gTasks[taskId].func = Task_VsSeeker_3; } @@ -861,7 +864,7 @@ static u8 CanUseVsSeeker(void) } } -static u8 GetVsSeekerResponseInArea(const VsSeekerData * vsSeekerData) +static u8 GetVsSeekerResponseInArea(const struct RematchData * vsSeekerData) { u16 trainerIdx = 0; u16 rval = 0; @@ -933,7 +936,7 @@ void ClearRematchStateByTrainerId(void) { u8 objEventId = 0; struct ObjectEventTemplate *objectEventTemplates = gSaveBlock1Ptr->objectEventTemplates; - int vsSeekerDataIdx = LookupVsSeekerOpponentInArray(sVsSeekerData, gTrainerBattleOpponent_A); + int vsSeekerDataIdx = LookupVsSeekerOpponentInArray(sRematches, gTrainerBattleOpponent_A); if (vsSeekerDataIdx != -1) { @@ -943,7 +946,7 @@ void ClearRematchStateByTrainerId(void) { if ((objectEventTemplates[i].objUnion.normal.trainerType == TRAINER_TYPE_NORMAL || objectEventTemplates[i].objUnion.normal.trainerType == TRAINER_TYPE_BURIED) - && vsSeekerDataIdx == LookupVsSeekerOpponentInArray(sVsSeekerData, GetTrainerFlagFromScript(objectEventTemplates[i].script))) + && vsSeekerDataIdx == LookupVsSeekerOpponentInArray(sRematches, GetTrainerFlagFromScript(objectEventTemplates[i].script))) { struct ObjectEvent *objectEvent; @@ -965,28 +968,28 @@ static void TryGetRematchTrainerIdGivenGameState(const u16 * trainerIdxs, u8 * r { switch (*rematchIdx_p) { - case 0: - break; - case 1: - if (!FlagGet(FLAG_GOT_VS_SEEKER)) - *rematchIdx_p = GetRematchTrainerIdGivenGameState(trainerIdxs, *rematchIdx_p); - break; - case 2: - if (!FlagGet(FLAG_WORLD_MAP_CELADON_CITY)) - *rematchIdx_p = GetRematchTrainerIdGivenGameState(trainerIdxs, *rematchIdx_p); - break; - case 3: - if (!FlagGet(FLAG_WORLD_MAP_FUCHSIA_CITY)) - *rematchIdx_p = GetRematchTrainerIdGivenGameState(trainerIdxs, *rematchIdx_p); - break; - case 4: - if (!FlagGet(FLAG_SYS_GAME_CLEAR)) - *rematchIdx_p = GetRematchTrainerIdGivenGameState(trainerIdxs, *rematchIdx_p); - break; - case 5: - if (!FlagGet(FLAG_SYS_CAN_LINK_WITH_RS)) - *rematchIdx_p = GetRematchTrainerIdGivenGameState(trainerIdxs, *rematchIdx_p); - break; + case 0: + break; + case 1: + if (!FlagGet(FLAG_GOT_VS_SEEKER)) + *rematchIdx_p = GetRematchTrainerIdGivenGameState(trainerIdxs, *rematchIdx_p); + break; + case 2: + if (!FlagGet(FLAG_WORLD_MAP_CELADON_CITY)) + *rematchIdx_p = GetRematchTrainerIdGivenGameState(trainerIdxs, *rematchIdx_p); + break; + case 3: + if (!FlagGet(FLAG_WORLD_MAP_FUCHSIA_CITY)) + *rematchIdx_p = GetRematchTrainerIdGivenGameState(trainerIdxs, *rematchIdx_p); + break; + case 4: + if (!FlagGet(FLAG_SYS_GAME_CLEAR)) + *rematchIdx_p = GetRematchTrainerIdGivenGameState(trainerIdxs, *rematchIdx_p); + break; + case 5: + if (!FlagGet(FLAG_SYS_CAN_LINK_WITH_RS)) + *rematchIdx_p = GetRematchTrainerIdGivenGameState(trainerIdxs, *rematchIdx_p); + break; } } @@ -995,7 +998,7 @@ static u8 GetRematchTrainerIdGivenGameState(const u16 *trainerIdxs, u8 rematchId while (--rematchIdx != 0) { const u16 *rematch_p = trainerIdxs + rematchIdx; - if (*rematch_p != 0xFFFF) + if (*rematch_p != SKIP) return rematchIdx; } return 0; @@ -1003,20 +1006,20 @@ static u8 GetRematchTrainerIdGivenGameState(const u16 *trainerIdxs, u8 rematchId bool8 ShouldTryRematchBattle(void) { - if (ShouldTryRematchBattleInternal(sVsSeekerData, gTrainerBattleOpponent_A)) + if (ShouldTryRematchBattleInternal(sRematches, gTrainerBattleOpponent_A)) { return TRUE; } - return HasRematchTrainerAlreadyBeenFought(sVsSeekerData, gTrainerBattleOpponent_A); + return HasRematchTrainerAlreadyBeenFought(sRematches, gTrainerBattleOpponent_A); } -static bool8 ShouldTryRematchBattleInternal(const VsSeekerData *vsSeekerData, u16 trainerBattleOpponent) +static bool8 ShouldTryRematchBattleInternal(const struct RematchData *vsSeekerData, u16 trainerBattleOpponent) { s32 rematchIdx = GetRematchIdx(vsSeekerData, trainerBattleOpponent); if (rematchIdx == -1) return FALSE; - if (rematchIdx >= 0 && rematchIdx < NELEMS(sVsSeekerData)) + if (rematchIdx >= 0 && rematchIdx < NELEMS(sRematches)) { if (IsThisTrainerRematchable(gSpecialVar_LastTalked)) return TRUE; @@ -1024,7 +1027,7 @@ static bool8 ShouldTryRematchBattleInternal(const VsSeekerData *vsSeekerData, u1 return FALSE; } -static bool8 HasRematchTrainerAlreadyBeenFought(const VsSeekerData *vsSeekerData, u16 trainerBattleOpponent) +static bool8 HasRematchTrainerAlreadyBeenFought(const struct RematchData *vsSeekerData, u16 trainerBattleOpponent) { s32 rematchIdx = GetRematchIdx(vsSeekerData, trainerBattleOpponent); @@ -1041,19 +1044,19 @@ void ClearRematchStateOfLastTalked(void) SetBattledTrainerFlag(); } -static int LookupVsSeekerOpponentInArray(const VsSeekerData * array, u16 trainerId) +static int LookupVsSeekerOpponentInArray(const struct RematchData * array, u16 trainerId) { int i, j; - for (i = 0; i < NELEMS(sVsSeekerData); i++) + for (i = 0; i < NELEMS(sRematches); i++) { - for (j = 0; j < 6; j++) + for (j = 0; j < MAX_REMATCH_PARTIES; j++) { u16 testTrainerId; if (array[i].trainerIdxs[j] == 0) break; testTrainerId = array[i].trainerIdxs[j]; - if (testTrainerId == 0xFFFF) + if (testTrainerId == SKIP) continue; if (testTrainerId == trainerId) return i; @@ -1067,25 +1070,25 @@ int GetRematchTrainerId(u16 trainerId) { u8 i; u8 j; - j = GetNextAvailableRematchTrainer(sVsSeekerData, trainerId, &i); + j = GetNextAvailableRematchTrainer(sRematches, trainerId, &i); if (!j) return 0; - TryGetRematchTrainerIdGivenGameState(sVsSeekerData[i].trainerIdxs, &j); - return sVsSeekerData[i].trainerIdxs[j]; + TryGetRematchTrainerIdGivenGameState(sRematches[i].trainerIdxs, &j); + return sRematches[i].trainerIdxs[j]; } u8 IsTrainerReadyForRematch(void) { - return IsTrainerReadyForRematchInternal(sVsSeekerData, gTrainerBattleOpponent_A); + return IsTrainerReadyForRematchInternal(sRematches, gTrainerBattleOpponent_A); } -static bool8 IsTrainerReadyForRematchInternal(const VsSeekerData * array, u16 trainerId) +static bool8 IsTrainerReadyForRematchInternal(const struct RematchData * array, u16 trainerId) { int rematchTrainerIdx = LookupVsSeekerOpponentInArray(array, trainerId); if (rematchTrainerIdx == -1) return FALSE; - if (rematchTrainerIdx >= NELEMS(sVsSeekerData)) + if (rematchTrainerIdx >= NELEMS(sRematches)) return FALSE; if (!IsThisTrainerRematchable(gSpecialVar_LastTalked)) return FALSE; @@ -1177,11 +1180,11 @@ static u16 GetTrainerFlagFromScript(const u8 *script) return trainerFlag; } -static int GetRematchIdx(const VsSeekerData * vsSeekerData, u16 trainerFlagIdx) +static int GetRematchIdx(const struct RematchData * vsSeekerData, u16 trainerFlagIdx) { int i; - for (i = 0; i < NELEMS(sVsSeekerData); i++) + for (i = 0; i < NELEMS(sRematches); i++) { if (vsSeekerData[i].trainerIdxs[0] == trainerFlagIdx) return i; @@ -1223,20 +1226,20 @@ static bool8 IsTrainerVisibleOnScreen(struct VsSeekerTrainerInfo * trainerInfo) return FALSE; } -static u8 GetNextAvailableRematchTrainer(const VsSeekerData * vsSeekerData, u16 trainerFlagNo, u8 * idxPtr) +static u8 GetNextAvailableRematchTrainer(const struct RematchData * vsSeekerData, u16 trainerFlagNo, u8 * idxPtr) { int i, j; - for (i = 0; i < NELEMS(sVsSeekerData); i++) + for (i = 0; i < NELEMS(sRematches); i++) { if (vsSeekerData[i].trainerIdxs[0] == trainerFlagNo) { *idxPtr = i; - for (j = 1; j < 6; j++) + for (j = 1; j < MAX_REMATCH_PARTIES; j++) { - if (vsSeekerData[i].trainerIdxs[j] == 0) + if (vsSeekerData[i].trainerIdxs[j] == TRAINER_NONE) return j - 1; - if (vsSeekerData[i].trainerIdxs[j] == 0xffff) + if (vsSeekerData[i].trainerIdxs[j] == SKIP) continue; if (HasTrainerBeenFought(vsSeekerData[i].trainerIdxs[j])) continue; @@ -1259,7 +1262,7 @@ static u8 GetRematchableTrainerLocalId(void) { if (IsTrainerVisibleOnScreen(&sVsSeeker->trainerInfo[i]) == 1) { - if (HasTrainerBeenFought(sVsSeeker->trainerInfo[i].trainerIdx) != 1 || GetNextAvailableRematchTrainer(sVsSeekerData, sVsSeeker->trainerInfo[i].trainerIdx, &idx)) + if (HasTrainerBeenFought(sVsSeeker->trainerInfo[i].trainerIdx) != 1 || GetNextAvailableRematchTrainer(sRematches, sVsSeeker->trainerInfo[i].trainerIdx, &idx)) return sVsSeeker->trainerInfo[i].localId; } } @@ -1310,7 +1313,7 @@ static void StartAllRespondantIdleMovements(void) if (ObjectEventIdIsSane(sVsSeeker->trainerInfo[j].objectEventId) == 1) SetTrainerMovementType(objectEvent, sVsSeeker->runningBehaviourEtcArray[i]); OverrideMovementTypeForObjectEvent(objectEvent, sVsSeeker->runningBehaviourEtcArray[i]); - gSaveBlock1Ptr->trainerRematches[sVsSeeker->trainerInfo[j].localId] = GetNextAvailableRematchTrainer(sVsSeekerData, sVsSeeker->trainerInfo[j].trainerIdx, &dummy); + gSaveBlock1Ptr->trainerRematches[sVsSeeker->trainerInfo[j].localId] = GetNextAvailableRematchTrainer(sRematches, sVsSeeker->trainerInfo[j].trainerIdx, &dummy); } } }