From 45546ce3508deb0b2f659c8892161d444b91b08d Mon Sep 17 00:00:00 2001 From: GriffinR Date: Fri, 11 Nov 2022 08:49:57 -0500 Subject: [PATCH] Clarify ql event data --- include/battle.h | 2 +- include/constants/quest_log.h | 4 +- include/pokemon_storage_system_internal.h | 11 +- include/quest_log.h | 131 +- include/shop.h | 2 +- src/battle_script_commands.c | 2 +- src/berry_pouch.c | 3 +- src/field_specials.c | 62 +- src/item.c | 23 +- src/item_menu.c | 5 +- src/item_use.c | 20 +- src/overworld.c | 2 +- src/party_menu.c | 80 +- src/pokemon_storage_system_tasks.c | 4 +- src/quest_log.c | 6 +- src/quest_log_battle.c | 112 +- src/quest_log_events.c | 1721 +++++++++++---------- src/shop.c | 105 +- src/tm_case.c | 3 +- src/trade_scene.c | 14 +- 20 files changed, 1237 insertions(+), 1075 deletions(-) diff --git a/include/battle.h b/include/battle.h index 2a7b636e4..f3101bc5f 100644 --- a/include/battle.h +++ b/include/battle.h @@ -444,7 +444,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 f50643d24..0be304097 100644 --- a/include/constants/quest_log.h +++ b/include/constants/quest_log.h @@ -62,11 +62,11 @@ #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_OBTAINED_STORY_ITEM 40 #define QL_EVENT_41 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) 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 b50780277..f91920d0d 100644 --- a/include/quest_log.h +++ b/include/quest_log.h @@ -3,8 +3,9 @@ #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" // Parameter to QuestLog_OnEscalatorWarp #define QL_ESCALATOR_OUT 1 @@ -48,6 +49,132 @@ struct UnkStruct_203B044 u16 unk_2; }; +// 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; @@ -94,7 +221,7 @@ void sub_8112B3C(void); void RunQuestLogCB(void); void sub_8111C68(void); bool8 QuestLogScenePlaybackIsEnding(void); -void sub_8115798(void); +void SetQuestLogEvent_Arrived(void); bool8 QuestLog_ShouldEndSceneOnMapChange(void); void QuestLog_AdvancePlayhead_(void); void QuestLog_InitPalettesBackup(void); diff --git a/include/shop.h b/include/shop.h index 999c3b777..23490d4e1 100644 --- a/include/shop.h +++ b/include/shop.h @@ -12,7 +12,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 9afeb1e58..05b06ffc4 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/berry_pouch.c b/src/berry_pouch.c index e113fd2d9..1f0abccc7 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_get_market_price(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/field_specials.c b/src/field_specials.c index 84ffd75e3..f7cf2aadd 100644 --- a/src/field_specials.c +++ b/src/field_specials.c @@ -1810,7 +1810,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 +1881,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 763838133..bf8a2f3ac 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 ae8d98235..549984c15 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); }) @@ -1934,7 +1935,7 @@ static void Task_FinalizeSaleToShop(u8 taskId) PlaySE(SE_SHOP); RemoveBagItem(gSpecialVar_ItemId, data[8]); AddMoney(&gSaveBlock1Ptr->money, itemid_get_market_price(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); @@ -2009,7 +2010,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 a0dfc50f2..59f13b0af 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_SPECIES2); + data->species = GetMonData(pokemon, MON_DATA_SPECIES2); else - questLog->species = 0xFFFF; - SetQuestLogEvent(eventId, (void *)questLog); - Free(questLog); + data->species = 0xFFFF; + SetQuestLogEvent(eventId, (void *)data); + Free(data); } diff --git a/src/overworld.c b/src/overworld.c index 56308a9a4..4990ed8f5 100644 --- a/src/overworld.c +++ b/src/overworld.c @@ -1458,7 +1458,7 @@ static void OverworldBasic(void) RunTasks(); AnimateSprites(); CameraUpdate(); - sub_8115798(); + SetQuestLogEvent_Arrived(); UpdateCameraPanning(); BuildOamBuffer(); UpdatePaletteFade(); diff --git a/src/party_menu.c b/src/party_menu.c index f9f51c887..32fb78a57 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_SPECIES2); - buffer[1] = GetMonData(&gPlayerParty[gPartyMenu.slotId2], MON_DATA_SPECIES2); - SetQuestLogEvent(QL_EVENT_SWITCHED_PARTY_ORDER, buffer); - Free(buffer); + data->species1 = GetMonData(&gPlayerParty[gPartyMenu.slotId], MON_DATA_SPECIES2); + data->species2 = GetMonData(&gPlayerParty[gPartyMenu.slotId2], MON_DATA_SPECIES2); + 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_SPECIES2); - ptr[0] = item; - ptr[1] = item2; + data->species = GetMonData(mon, MON_DATA_SPECIES2); + 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_SPECIES2); - ptr->fieldMove = fieldMove; - switch (ptr->fieldMove) + data->species = GetMonData(mon, MON_DATA_SPECIES2); + 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_SPECIES2); - 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_SPECIES2); + 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 3911cf2c1..fcea4f18e 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_SPECIES2); } - questLogData = &gStorage->pokeStorageQuestLogData; + questLogData = &gStorage->questLogData; switch (action) { diff --git a/src/quest_log.c b/src/quest_log.c index 839e86362..8e6e676c7 100644 --- a/src/quest_log.c +++ b/src/quest_log.c @@ -46,12 +46,14 @@ All the data stored for each scene is in 'struct QuestLogScene', defined in include/global.h. The entirety of the Quest Log's save data is represented by an array of these scenes in SaveBlock1. - - "Event": - - "Action": TODO: Copy from quest_log.h + - "Event": + - "Command": + - "Script": + */ enum { diff --git a/src/quest_log_battle.c b/src/quest_log_battle.c index 9f1d376a9..3dc20f178 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 *); 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]; 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++) + 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[sp0].name[i]; + data->playerNames[1][i] = gLinkPlayers[sp4[0]].name[i]; + data->playerNames[2][i] = gLinkPlayers[sp4[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) { - s32 r5; + s32 i; s32 _optimized_out = 0; u8 r2 = gLinkPlayers[gBattleStruct->multiplayerId].id ^ 2; - for (r5 = 0; r5 < 4; r5++) + 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 (r2 == gLinkPlayers[i].id) + a0[0] = i; + else if (i != gBattleStruct->multiplayerId) + a1[_optimized_out++] = i; } } diff --git a/src/quest_log_events.c b/src/quest_log_events.c index 8651c8304..4901711a6 100644 --- a/src/quest_log_events.c +++ b/src/quest_log_events.c @@ -28,146 +28,430 @@ static EWRAM_DATA struct DeferredLinkEvent sDeferredEvent = {0}; EWRAM_DATA struct UnkStruct_203B044 gUnknown_203B044 = {0}; static EWRAM_DATA u8 sEventShouldNotRecordSteps = 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 bool8 TryDeferLinkEvent(u16, const u16 *); +static bool8 TryDeferTrainerBattleEvent(u16, const u16 *); +static bool8 IsEventWithSpecialEncounterSpecies(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 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 *) = { +typedef u16 *(*RecordEventFunc)(u16 *, const u16 *); + +static const RecordEventFunc sRecordEventFuncs[] = { [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_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_39] = NULL, - [QL_EVENT_OBTAINED_ITEM] = BufferQuestLogData_ObtainedItem, + [QL_EVENT_OBTAINED_STORY_ITEM] = (RecordEventFunc) RecordEvent_ObtainedStoryItem, [QL_EVENT_41] = NULL, - [QL_EVENT_ARRIVED] = BufferQuestLogData_ArrivedInLocation + [QL_EVENT_ARRIVED] = (RecordEventFunc) RecordEvent_ArrivedInLocation }; -void SetQuestLogEvent(u16 eventId, const u16 *eventData) +static const u16 *(*const sLoadEventFuncs[])(const u16 *) = { + [QL_EVENT_0] = NULL, + [QL_EVENT_1] = NULL, + [QL_EVENT_2] = 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_39] = NULL, + [QL_EVENT_OBTAINED_STORY_ITEM] = LoadEvent_ObtainedStoryItem, + [QL_EVENT_41] = NULL, + [QL_EVENT_ARRIVED] = LoadEvent_ArrivedInLocation +}; + +static const u8 sQuestLogEventCmdSizes[] = { + [QL_EVENT_0] = 8, + [QL_EVENT_1] = 8, + [QL_EVENT_2] = 8, + [QL_EVENT_SWITCHED_PARTY_ORDER] = 8, + [QL_EVENT_USED_ITEM] = 10, + [QL_EVENT_GAVE_HELD_ITEM] = 8, + [QL_EVENT_GAVE_HELD_ITEM_BAG] = 8, + [QL_EVENT_GAVE_HELD_ITEM_PC] = 8, + [QL_EVENT_TOOK_HELD_ITEM] = 8, + [QL_EVENT_SWAPPED_HELD_ITEM] = 10, + [QL_EVENT_SWAPPED_HELD_ITEM_PC] = 10, + [QL_EVENT_USED_PKMN_CENTER] = 4, + [QL_EVENT_LINK_TRADED] = 16, + [QL_EVENT_LINK_BATTLED_SINGLE] = 12, + [QL_EVENT_LINK_BATTLED_DOUBLE] = 12, + [QL_EVENT_LINK_BATTLED_MULTI] = 26, + [QL_EVENT_USED_UNION_ROOM] = 4, + [QL_EVENT_USED_UNION_ROOM_CHAT] = 4, + [QL_EVENT_LINK_TRADED_UNION] = 16, + [QL_EVENT_LINK_BATTLED_UNION] = 12, + [QL_EVENT_SWITCHED_MONS_BETWEEN_BOXES] = 10, + [QL_EVENT_SWITCHED_MONS_WITHIN_BOX] = 10, + [QL_EVENT_SWITCHED_PARTY_MON_FOR_PC_MON] = 10, + [QL_EVENT_MOVED_MON_BETWEEN_BOXES] = 8, + [QL_EVENT_MOVED_MON_WITHIN_BOX] = 8, + [QL_EVENT_WITHDREW_MON_PC] = 8, + [QL_EVENT_DEPOSITED_MON_PC] = 8, + [QL_EVENT_SWITCHED_MULTIPLE_MONS] = 6, + [QL_EVENT_DEPOSITED_ITEM_PC] = 6, + [QL_EVENT_WITHDREW_ITEM_PC] = 6, + [QL_EVENT_DEFEATED_GYM_LEADER] = 12, + [QL_EVENT_DEFEATED_WILD_MON] = 12, + [QL_EVENT_DEFEATED_E4_MEMBER] = 12, + [QL_EVENT_DEFEATED_CHAMPION] = 10, + [QL_EVENT_DEFEATED_TRAINER] = 12, + [QL_EVENT_DEPARTED] = 6, + [QL_EVENT_USED_FIELD_MOVE] = 8, + [QL_EVENT_BOUGHT_ITEM] = 14, + [QL_EVENT_SOLD_ITEM] = 14, + [QL_EVENT_39] = 2, + [QL_EVENT_OBTAINED_STORY_ITEM] = 8, + [QL_EVENT_41] = 4, + [QL_EVENT_ARRIVED] = 6 +}; + +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; @@ -177,46 +461,48 @@ void SetQuestLogEvent(u16 eventId, const u16 *eventData) 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_LinkSomething() == TRUE) + // Link events handled above. If we're in an active link, don't record any other events. + if (MenuHelpers_LinkSomething() == 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) - return; - - if (ShouldRegisterEvent_HandleGameCorner(eventId, eventData) == FALSE) + // If player departed Game Corner without using the slots, don't record it + if (ShouldRegisterEvent_DepartedGameCorner(eventId, data) == FALSE) return; if (gQuestLogPlaybackState == QL_PLAYBACK_STATE_0) { - if (ShouldRegisterEvent_HandlePartyActions(eventId, eventData) == TRUE) + if (ShouldRegisterEvent_HandlePartyActions(eventId, data) == TRUE) return; if (eventId != QL_EVENT_DEFEATED_WILD_MON || gUnknown_203AE04 == NULL) { - if (ShouldRegisterEvent_HandleDeparted(eventId, eventData) == FALSE) + if (ShouldRegisterEvent_HandleDeparted(eventId, data) == FALSE) return; StartRecordingQuestLogAction(eventId); } } - else if (eventId == QL_EVENT_OBTAINED_ITEM) + else if (eventId == QL_EVENT_OBTAINED_STORY_ITEM) return; SetQuestLogEventToActive(eventId); @@ -225,24 +511,24 @@ void SetQuestLogEvent(u16 eventId, const u16 *eventData) if (gUnknown_203AE04 == NULL) { gUnknown_203AE04 = gQuestLogRecordingPointer; - r1 = sQuestLogStorageCBs[eventId](gUnknown_203AE04, eventData); + r1 = sRecordEventFuncs[eventId](gUnknown_203AE04, data); } else { - sQuestLogStorageCBs[eventId](gUnknown_203AE04, eventData); + sRecordEventFuncs[eventId](gUnknown_203AE04, data); return; } } else { gUnknown_203AE04 = NULL; - r1 = sQuestLogStorageCBs[eventId](gQuestLogRecordingPointer, eventData); + r1 = sRecordEventFuncs[eventId](gQuestLogRecordingPointer, data); } if (r1 == NULL) { FinishRecordingQuestLogScene(); - r1 = ShouldRegisterEvent(eventId, eventData); + r1 = ShouldRegisterEvent(eventId, data); if (r1 == NULL) return; } @@ -305,14 +591,16 @@ 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; } @@ -334,11 +622,12 @@ static bool8 ShouldRegisterEvent_HandlePartyActions(u16 eventId, const u16 *even 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 @@ -354,12 +643,12 @@ void QL_EnableRecordingSteps(void) sEventShouldNotRecordSteps = 0; } -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; StartRecordingQuestLogAction(eventId); @@ -370,10 +659,10 @@ static u16 *ShouldRegisterEvent(u16 eventId, const u16 *eventData) else gUnknown_203AE04 = NULL; - return sQuestLogStorageCBs[eventId](gQuestLogRecordingPointer, 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; @@ -381,12 +670,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; } @@ -401,27 +691,27 @@ void QuestLog_StartRecordingInputsAfterDeferredEvent(void) if (sDeferredEvent.id != QL_EVENT_0) { u16 *resp; - sLastDepartedMap = 0; + sLastDepartedLocation = 0; StartRecordingQuestLogAction(sDeferredEvent.id); - resp = sQuestLogStorageCBs[sDeferredEvent.id](gQuestLogRecordingPointer, sDeferredEvent.data); + 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 != QL_PLAYBACK_STATE_0 || FlagGet(FLAG_SYS_GAME_CLEAR) || ShouldRegisterEvent_HandleBeatStoryTrainer(eventId, eventData) != TRUE) + if (gQuestLogPlaybackState != QL_PLAYBACK_STATE_0 || 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; } @@ -433,11 +723,11 @@ void QuestLogEvents_HandleEndTrainerBattle(void) u16 *resp; if (gQuestLogPlaybackState == QL_PLAYBACK_STATE_0) { - sLastDepartedMap = 0; + sLastDepartedLocation = 0; StartRecordingQuestLogAction(sDeferredEvent.id); } SetQuestLogEventToActive(sDeferredEvent.id); - resp = sQuestLogStorageCBs[sDeferredEvent.id](gQuestLogRecordingPointer, sDeferredEvent.data); + resp = sRecordEventFuncs[sDeferredEvent.id](gQuestLogRecordingPointer, sDeferredEvent.data); gQuestLogRecordingPointer = resp; TryRecordEvent41_IncCursor(1); ResetDeferredLinkEvent(); @@ -451,112 +741,24 @@ void TryRecordEvent41_IncCursor(u16 a0) 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 eventId = curPtr[0] & 0xfff; @@ -576,9 +778,9 @@ void sub_8113ABC(const u16 *a0) { const u8 *r2 = (const u8 *)(a0 + 2); if ((a0[0] & 0xFFF) != QL_EVENT_DEPARTED) - sLastDepartedMap = 0; + sLastDepartedLocation = 0; else - sLastDepartedMap = r2[1] + 1; + sLastDepartedLocation = r2[1] + 1; } bool8 sub_8113AE8(const u16 *a0) @@ -590,7 +792,7 @@ bool8 sub_8113AE8(const u16 *a0) if (r0[1] > gQuestLogCurActionIdx) return FALSE; - sQuestLogEventTextBufferCBs[(r0[0] & 0xFFF)](a0); + sLoadEventFuncs[(r0[0] & 0xFFF)](a0); gUnknown_203B044.id = r0[0]; gUnknown_203B044.unk_1 = (r0[0] & 0xF000) >> 12; if (gUnknown_203B044.unk_1 != 0) @@ -603,7 +805,7 @@ bool8 sub_8113B44(const u16 *a0) if (gUnknown_203B044.unk_2 == 0) return FALSE; - sQuestLogEventTextBufferCBs[gUnknown_203B044.id](a0); + sLoadEventFuncs[gUnknown_203B044.id](a0); gUnknown_203B044.unk_2++; if (gUnknown_203B044.unk_2 > gUnknown_203B044.unk_1) ResetUnk203B044(); @@ -630,7 +832,7 @@ static void SetQuestLogEventToActive(u16 eventId) void sub_8113BD8(void) { sNewlyEnteredMap = FALSE; - sLastDepartedMap = 0; + sLastDepartedLocation = 0; sPlayedTheSlots = FALSE; } @@ -745,11 +947,11 @@ u16 *sub_8113D94(u16 *a0, struct QuestLogAction * a1) return (u16 *)(r6 + 4); } -static u16 *RecordEvent(u16 eventId, u16 *dest) +static u16 *RecordEventHeader(u16 eventId, u16 *dest) { u8 cmdSize; - u16 *r5; - u8 r4; + u16 *record; + u8 i; u8 r1; if (gUnknown_203B044.unk_1 == 0) @@ -761,18 +963,18 @@ static u16 *RecordEvent(u16 eventId, u16 *dest) if (!sub_8110944(dest, cmdSize)) return NULL; - r5 = (void *)dest; + record = (void *)dest; if (gUnknown_203B044.unk_1 != 0) - r5 = (void *)r5 - (gUnknown_203B044.unk_1 * cmdSize + 4); + record = (void *)record - (gUnknown_203B044.unk_1 * cmdSize + 4); if (gUnknown_203B044.unk_1 == 5) { - for (r4 = 0; r4 < 4; r4++) + for (i = 0; i < 4; i++) { memcpy( - (void *)r5 + (r4 * cmdSize + 4), - (void *)r5 + ((r4 + 1) * cmdSize + 4), + (void *)record + ((i + 0) * cmdSize + 4), + (void *)record + ((i + 1) * cmdSize + 4), cmdSize ); } @@ -781,13 +983,13 @@ static u16 *RecordEvent(u16 eventId, u16 *dest) else r1 = gUnknown_203B044.unk_1; - r5[0] = eventId + (r1 << 12); - r5[1] = gQuestLogCurActionIdx; - r5 = (void *)r5 + (r1 * cmdSize + 4); - return r5; + record[0] = eventId + (r1 << 12); + record[1] = gQuestLogCurActionIdx; + record = (void *)record + (r1 * cmdSize + 4); + 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); return eventData; @@ -811,61 +1013,64 @@ static void QuestLog_GetSpeciesName(u16 species, u8 *dest, u8 stringVarId) } } -static u16 *BufferQuestLogData_SwitchedPartyOrder(u16 *dest, const u16 *eventData) +static u16 *RecordEvent_SwitchedPartyOrder(u16 *dest, const struct QuestLogEvent_SwitchedPartyOrder * data) { - u16 *r2 = RecordEvent(QL_EVENT_SWITCHED_PARTY_ORDER, dest); + 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 *dest, 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 = RecordEvent(QL_EVENT_USED_ITEM, dest); - 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) + if (data->itemId == ITEM_ESCAPE_ROPE) sEventShouldNotRecordSteps = 2; - 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 @@ -874,390 +1079,398 @@ 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_TM50) StringExpandPlaceholders(gStringVar4, gText_QuestLog_MonReplacedMoveWithHM); else StringExpandPlaceholders(gStringVar4, gText_QuestLog_MonReplacedMoveWithTM); } else { - if (r5[0] > ITEM_TM50) + if (rItemId > ITEM_TM50) StringExpandPlaceholders(gStringVar4, gText_QuestLog_MonLearnedMoveFromHM); else StringExpandPlaceholders(gStringVar4, gText_QuestLog_MonLearnedMoveFromTM); } break; } - return r5 + 3; + return record + 3; } -u16 *BufferQuestLogData_GiveTakeHeldItem(u16 eventId, u16 *dest, const u16 *eventData) +static u16 *RecordEvent_GiveTakeHeldItem(u16 eventId, u16 *dest, const struct QuestLogEvent_Item * data) { - u16 *r1 = RecordEvent(eventId, dest); - 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 *dest, const u16 *eventData) +static u16 *RecordEvent_GaveHeldItemFromPartyMenu(u16 *dest, const struct QuestLogEvent_Item * data) { - return BufferQuestLogData_GiveTakeHeldItem(QL_EVENT_GAVE_HELD_ITEM, dest, 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 *dest, const u16 *eventData) +static u16 *RecordEvent_GaveHeldItemFromBagMenu(u16 *dest, const struct QuestLogEvent_Item * data) { - return BufferQuestLogData_GiveTakeHeldItem(QL_EVENT_GAVE_HELD_ITEM_BAG, dest, 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 *dest, const u16 *eventData) +static u16 *RecordEvent_GaveHeldItemFromPC(u16 *dest, const struct QuestLogEvent_Item * data) { - return BufferQuestLogData_GiveTakeHeldItem(QL_EVENT_GAVE_HELD_ITEM_PC, dest, 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 *dest, const u16 *eventData) +static u16 *RecordEvent_TookHeldItem(u16 *dest, const struct QuestLogEvent_Item * data) { - return BufferQuestLogData_GiveTakeHeldItem(QL_EVENT_TOOK_HELD_ITEM, dest, 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 *dest, 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 = RecordEvent(eventId, dest); - 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 *dest, const u16 *eventData) +static u16 *RecordEvent_SwappedHeldItemFromBag(u16 *dest, const struct QuestLogEvent_SwappedHeldItem * data) { - return BufferQuestLogData_SwappedHeldItem_(QL_EVENT_SWAPPED_HELD_ITEM, dest, 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 *dest, const u16 *eventData) +static u16 *RecordEvent_SwappedHeldItemFromPC(u16 *dest, const struct QuestLogEvent_SwappedHeldItem * data) { - return BufferQuestLogData_SwappedHeldItem_(QL_EVENT_SWAPPED_HELD_ITEM_PC, dest, 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 *dest, const u16 *eventData) +#undef rTakenItemId +#undef rGivenItemId +#undef rSpecies + +// data argument will be a null pointer, no information needed for this event +static u16 *RecordEvent_UsedPkmnCenter(u16 *dest, const u16 * data) { - u16 *r4 = dest; + u16 *record = dest; if (gUnknown_203B044.id == QL_EVENT_USED_PKMN_CENTER && gUnknown_203B044.unk_1 != 0) - return r4; + return record; if (!sub_8110944(dest, sQuestLogEventCmdSizes[QL_EVENT_USED_PKMN_CENTER])) return NULL; - r4[0] = QL_EVENT_USED_PKMN_CENTER; - r4[1] = gQuestLogCurActionIdx; - 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 *dest, const u16 *eventData) +static u16 *RecordEvent_LinkTraded(u16 *dest, const struct QuestLogEvent_Traded * data) { - u16 *r4 = dest + 4; + u16 *nameDest = dest + 4; dest[0] = QL_EVENT_LINK_TRADED; dest[1] = gQuestLogCurActionIdx; - dest[2] = eventData[0]; - dest[3] = eventData[1]; - eventData += 2; - memcpy(r4, eventData, 7); - r4 += 4; - return r4; + 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 *dest, const u16 *eventData) +static u16 *RecordEvent_LinkBattledSingle(u16 *dest, const struct QuestLogEvent_LinkBattle * data) { + u8 * record; + dest[0] = QL_EVENT_LINK_BATTLED_SINGLE; dest[1] = gQuestLogCurActionIdx; - *((u8 *)dest + 4) = *((const u8 *)eventData + 0); - memcpy((u8 *)dest + 5, (const u8 *)eventData + 1, PLAYER_NAME_LENGTH); - dest += 6; - return dest; + 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 *dest, const u16 *eventData) +static u16 *RecordEvent_LinkBattledDouble(u16 *dest, const struct QuestLogEvent_LinkBattle * data) { + u8 * record; + dest[0] = QL_EVENT_LINK_BATTLED_DOUBLE; dest[1] = gQuestLogCurActionIdx; - *((u8 *)dest + 4) = *((const u8 *)eventData + 0); - memcpy((u8 *)dest + 5, (const u8 *)eventData + 1, PLAYER_NAME_LENGTH); - dest += 6; - return dest; + 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 *dest, const u16 *eventData) +static u16 *RecordEvent_LinkBattledMulti(u16 *dest, const struct QuestLogEvent_LinkBattle * data) { + u8 * record; + dest[0] = QL_EVENT_LINK_BATTLED_MULTI; dest[1] = gQuestLogCurActionIdx; - *((u8 *)dest + 4) = *((const u8 *)eventData + 0); - memcpy((u8 *)dest + 5, (const u8 *)eventData + 1, PLAYER_NAME_LENGTH); - memcpy((u8 *)dest + 12, (const u8 *)eventData + 8, PLAYER_NAME_LENGTH); - memcpy((u8 *)dest + 19, (const u8 *)eventData + 15, PLAYER_NAME_LENGTH); - dest += 13; - return dest; + 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 *dest, 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) { 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 *dest, 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) { 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 *dest, const u16 *eventData) +static u16 *RecordEvent_LinkTradedUnionRoom(u16 *dest, const struct QuestLogEvent_Traded * data) { - u8 *r4 = (u8 *)(dest + 4); + u8 *name = (u8 *)(dest + 4); dest[0] = QL_EVENT_LINK_TRADED_UNION; dest[1] = gQuestLogCurActionIdx; - dest[2] = eventData[0]; - dest[3] = eventData[1]; - memcpy(r4, eventData + 2, PLAYER_NAME_LENGTH); - r4 += 8; - return (u16 *)r4; + 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 *dest, const u16 *eventData) +static u16 *RecordEvent_LinkBattledUnionRoom(u16 *dest, const struct QuestLogEvent_LinkBattle * data) { dest[0] = QL_EVENT_LINK_BATTLED_UNION; dest[1] = gQuestLogCurActionIdx; - *(u8 *)&dest[2] = *(const u8 *)&eventData[0]; - memcpy((u8 *)dest + 5, (const u8 *)eventData + 1, PLAYER_NAME_LENGTH); - dest += 6; - return dest; + *(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 *dest, 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) { - dest = RecordEvent(QL_EVENT_SWITCHED_MONS_BETWEEN_BOXES, dest); - if (dest == NULL) + u16 * record = RecordEventHeader(QL_EVENT_SWITCHED_MONS_BETWEEN_BOXES, dest); + if (record == NULL) return NULL; - dest[0] = eventData[0]; - dest[1] = eventData[1]; - *((u8 *)dest + 4) = *((const u8 *)eventData + 4); - *((u8 *)dest + 5) = *((const u8 *)eventData + 5); - return dest + 3; + rSpecies1 = data->species1; + rSpecies2 = data->species2; + rBox1 = data->box1; + rBox2 = data->box2; + return record + 3; } -static const u16 *BufferQuestLogText_SwitchedMonsBetweenBoxes(const u16 *eventData) +// TODO +static const u16 *LoadEvent_SwitchedMonsBetweenBoxes(const u16 *eventData) { const u8 *boxIdxs; - eventData = sub_8113E88(QL_EVENT_SWITCHED_MONS_BETWEEN_BOXES, eventData); + eventData = LoadEvent(QL_EVENT_SWITCHED_MONS_BETWEEN_BOXES, eventData); boxIdxs = (const u8 *)eventData + 4; DynamicPlaceholderTextUtil_Reset(); DynamicPlaceholderTextUtil_SetPlaceholderPtr(0, GetBoxNamePtr(boxIdxs[0])); @@ -1268,9 +1481,9 @@ static const u16 *BufferQuestLogText_SwitchedMonsBetweenBoxes(const u16 *eventDa return eventData + 3; } -static u16 *BufferQuestLogData_SwitchedMonsWithinBox(u16 *dest, const u16 *eventData) +static u16 *RecordEvent_SwitchedMonsWithinBox(u16 *dest, const u16 *eventData) { - dest = RecordEvent(QL_EVENT_SWITCHED_MONS_WITHIN_BOX, dest); + dest = RecordEventHeader(QL_EVENT_SWITCHED_MONS_WITHIN_BOX, dest); if (dest == NULL) return NULL; dest[0] = eventData[0]; @@ -1279,10 +1492,10 @@ static u16 *BufferQuestLogData_SwitchedMonsWithinBox(u16 *dest, const u16 *event 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])); @@ -1292,11 +1505,11 @@ static const u16 *BufferQuestLogText_SwitchedMonsWithinBox(const u16 *eventData) return eventData + 3; } -static u16 *BufferQuestLogData_SwitchedPartyMonForPCMon(u16 *dest, const u16 *eventData) +static u16 *RecordEvent_SwitchedPartyMonForPCMon(u16 *dest, const u16 *eventData) { u16 *r2; u16 *ret; - r2 = RecordEvent(QL_EVENT_SWITCHED_PARTY_MON_FOR_PC_MON, dest); + r2 = RecordEventHeader(QL_EVENT_SWITCHED_PARTY_MON_FOR_PC_MON, dest); if (r2 == NULL) return NULL; ret = r2 + 2; @@ -1315,10 +1528,10 @@ static u16 *BufferQuestLogData_SwitchedPartyMonForPCMon(u16 *dest, const u16 *ev 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])); @@ -1328,11 +1541,11 @@ static const u16 *BufferQuestLogText_SwitchedPartyMonForPCMon(const u16 *eventDa return eventData + 3; } -static u16 *BufferQuestLogData_MovedMonBetweenBoxes(u16 *dest, const u16 *eventData) +static u16 *RecordEvent_MovedMonBetweenBoxes(u16 *dest, const u16 *eventData) { u16 *r2; u16 *ret; - r2 = RecordEvent(QL_EVENT_MOVED_MON_BETWEEN_BOXES, dest); + r2 = RecordEventHeader(QL_EVENT_MOVED_MON_BETWEEN_BOXES, dest); if (r2 == NULL) return NULL; r2[0] = eventData[0]; @@ -1342,10 +1555,10 @@ static u16 *BufferQuestLogData_MovedMonBetweenBoxes(u16 *dest, const u16 *eventD 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])); @@ -1355,10 +1568,10 @@ static const u16 *BufferQuestLogText_MovedMonBetweenBoxes(const u16 *eventData) return (const u16 *)boxIdxs + 1; } -static u16 *BufferQuestLogData_MovedMonWithinBox(u16 *dest, const u16 *eventData) +static u16 *RecordEvent_MovedMonWithinBox(u16 *dest, const u16 *eventData) { u16 *r2; - r2 = RecordEvent(QL_EVENT_MOVED_MON_WITHIN_BOX, dest); + r2 = RecordEventHeader(QL_EVENT_MOVED_MON_WITHIN_BOX, dest); if (r2 == NULL) return NULL; r2[0] = eventData[0]; @@ -1366,10 +1579,10 @@ static u16 *BufferQuestLogData_MovedMonWithinBox(u16 *dest, 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])); @@ -1378,10 +1591,10 @@ static const u16 *BufferQuestLogText_MovedMonWithinBox(const u16 *eventData) return (const u16 *)boxIdxs + 1; } -static u16 *BufferQuestLogData_WithdrewMonFromPC(u16 *dest, const u16 *eventData) +static u16 *RecordEvent_WithdrewMonFromPC(u16 *dest, const u16 *eventData) { u16 *r2; - r2 = RecordEvent(QL_EVENT_WITHDREW_MON_PC, dest); + r2 = RecordEventHeader(QL_EVENT_WITHDREW_MON_PC, dest); if (r2 == NULL) return NULL; r2[0] = eventData[0]; @@ -1389,10 +1602,10 @@ static u16 *BufferQuestLogData_WithdrewMonFromPC(u16 *dest, 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])); @@ -1401,10 +1614,10 @@ static const u16 *BufferQuestLogText_WithdrewMonFromPC(const u16 *eventData) return (const u16 *)boxIdxs + 1; } -static u16 *BufferQuestLogData_DepositedMonInPC(u16 *dest, const u16 *eventData) +static u16 *RecordEvent_DepositedMonInPC(u16 *dest, const u16 *eventData) { u16 *r2; - r2 = RecordEvent(QL_EVENT_DEPOSITED_MON_PC, dest); + r2 = RecordEventHeader(QL_EVENT_DEPOSITED_MON_PC, dest); if (r2 == NULL) return NULL; r2[0] = eventData[0]; @@ -1412,10 +1625,10 @@ static u16 *BufferQuestLogData_DepositedMonInPC(u16 *dest, 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); @@ -1424,10 +1637,10 @@ static const u16 *BufferQuestLogText_DepositedMonInPC(const u16 *eventData) return (const u16 *)boxIdxs + 1; } -static u16 *BufferQuestLogData_SwitchedMultipleMons(u16 *dest, const u16 *eventData) +static u16 *RecordEvent_SwitchedMultipleMons(u16 *dest, const u16 *eventData) { u16 *r2; - r2 = RecordEvent(QL_EVENT_SWITCHED_MULTIPLE_MONS, dest); + r2 = RecordEventHeader(QL_EVENT_SWITCHED_MULTIPLE_MONS, dest); if (r2 == NULL) return NULL; *((u8 *)r2 + 0) = *((const u8 *)eventData + 4); @@ -1435,9 +1648,9 @@ static u16 *BufferQuestLogData_SwitchedMultipleMons(u16 *dest, const u16 *eventD 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)) @@ -1448,63 +1661,79 @@ static const u16 *BufferQuestLogText_SwitchedMultipleMons(const u16 *eventData) return r4 + 1; } -static u16 *BufferQuestLogData_DepositedItemInPC(u16 *dest, 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) { - dest = RecordEvent(QL_EVENT_DEPOSITED_ITEM_PC, dest); - if (dest == NULL) + u16 * record = RecordEventHeader(QL_EVENT_DEPOSITED_ITEM_PC, dest); + if (record == NULL) return NULL; - dest[0] = eventData[0]; - return dest + 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 *dest, const u16 *eventData) +static u16 *RecordEvent_WithdrewItemFromPC(u16 *dest, const struct QuestLogEvent_Item * data) { - dest = RecordEvent(QL_EVENT_WITHDREW_ITEM_PC, dest); - if (dest == NULL) + u16 * record = RecordEventHeader(QL_EVENT_WITHDREW_ITEM_PC, dest); + if (record == NULL) return NULL; - dest[0] = eventData[0]; - return dest + 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 *dest, const u16 *eventData) +#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) { - dest = RecordEvent(eventId, dest); - if (dest == NULL) + u16 * record = RecordEventHeader(eventId, dest); + if (record == NULL) return NULL; - dest[0] = eventData[1]; - dest[1] = eventData[2]; - dest[2] = eventData[0]; - *((u8 *)dest + 6) = *((const u8 *)eventData + 7); - *((u8 *)dest + 7) = *((const u8 *)eventData + 6); - return dest + 4; + rSpeciesOpponent = data->speciesOpponent; + rSpeciesPlayer = data->speciesPlayer; + rTrainerId = data->trainerId; + rMapSec = data->mapSec; + rHpFractionId = data->hpFractionId; + return record + 4; } -static u16 *BufferQuestLogData_DefeatedGymLeader(u16 *dest, const u16 *eventData) +static u16 *RecordEvent_DefeatedGymLeader(u16 *dest, const struct QuestLogEvent_TrainerBattle * data) { sEventShouldNotRecordSteps = 1; - return BufferQuestLogData_DefeatedTrainer_(QL_EVENT_DEFEATED_GYM_LEADER, dest, eventData); + return RecordEvent_DefeatedTrainer(QL_EVENT_DEFEATED_GYM_LEADER, dest, data); } -static const u16 *BufferQuestLogText_DefeatedGymLeader(const u16 *eventData) +// TODO +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]); @@ -1517,30 +1746,30 @@ static const u16 *BufferQuestLogText_DefeatedGymLeader(const u16 *eventData) return eventData + 4; } -static u16 *BufferQuestLogData_DefeatedWildMon(u16 *dest, const u16 *eventData) +static u16 *RecordEvent_DefeatedWildMon(u16 *dest, const struct QuestLogEvent_WildBattle * data) { - u16 *r4 = dest; - u8 *r5 = (u8 *)dest + 8; - if (!sub_8110944(r4, sQuestLogEventCmdSizes[QL_EVENT_DEFEATED_WILD_MON])) + u16 *body = dest; + u8 *footer = (u8 *)dest + sizeof(struct QuestLogEvent_WildBattle); + if (!sub_8110944(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] = gQuestLogCurActionIdx; + 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])) @@ -1605,16 +1834,16 @@ static bool8 IsSpeciesFromSpecialEncounter(u16 species) return FALSE; } -static u16 *BufferQuestLogData_DefeatedEliteFourMember(u16 *dest, const u16 *eventData) +static u16 *RecordEvent_DefeatedEliteFourMember(u16 *dest, const struct QuestLogEvent_TrainerBattle * data) { sEventShouldNotRecordSteps = 1; - return BufferQuestLogData_DefeatedTrainer_(QL_EVENT_DEFEATED_E4_MEMBER, dest, eventData); + 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); @@ -1625,20 +1854,20 @@ static const u16 *BufferQuestLogText_DefeatedEliteFourMember(const u16 *eventDat return eventData + 4; } -static u16 *BufferQuestLogData_DefeatedChampion(u16 *dest, const u16 *eventData) +static u16 *RecordEvent_DefeatedChampion(u16 *dest, const struct QuestLogEvent_TrainerBattle * data) { if (!sub_8110944(dest, sQuestLogEventCmdSizes[QL_EVENT_DEFEATED_CHAMPION])) return NULL; dest[0] = QL_EVENT_DEFEATED_CHAMPION | (2 << 12); dest[1] = gQuestLogCurActionIdx; - dest[2] = eventData[1]; - dest[3] = eventData[2]; - *((u8 *)dest + 8) = *((const u8 *)eventData + 6); + dest[2] = data->speciesOpponent; + dest[3] = data->speciesPlayer; + *((u8 *)dest + 8) = data->hpFractionId; sEventShouldNotRecordSteps = 1; 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])) @@ -1669,15 +1898,15 @@ static const u16 *BufferQuestLogText_DefeatedChampion(const u16 *a0) return (const u16 *)(r5 + 2); } -static u16 *BufferQuestLogData_DefeatedTrainer(u16 *dest, const u16 *eventData) +static u16 *RecordEvent_DefeatedNormalTrainer(u16 *dest, const struct QuestLogEvent_TrainerBattle * data) { sEventShouldNotRecordSteps = 1; - return BufferQuestLogData_DefeatedTrainer_(QL_EVENT_DEFEATED_TRAINER, dest, eventData); + 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]); @@ -1697,248 +1926,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 *dest, const u16 *eventData) +static u16 *RecordEvent_DepartedLocation(u16 *dest, const struct QuestLogEvent_Departed * data) { - u16 *r2 = RecordEvent(QL_EVENT_DEPARTED, dest); - 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) + + rMapSec = data->mapSec; + rLocationId = data->locationId; + if (rLocationId == QL_LOCATION_SAFARI_ZONE) sEventShouldNotRecordSteps = 1; - return r2 + 1; + + 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 *dest, const u16 *eventData) +static u16 *RecordEvent_UsedFieldMove(u16 *dest, const struct QuestLogEvent_FieldMove * data) { - u8 *r3; - dest = RecordEvent(QL_EVENT_USED_FIELD_MOVE, dest); + u8 *record; + dest = RecordEventHeader(QL_EVENT_USED_FIELD_MOVE, dest); if (dest == NULL) return NULL; - dest[0] = eventData[0]; - r3 = (u8 *)dest + 2; - r3[0] = *((const u8 *)eventData + 2); - r3[1] = *((const u8 *)eventData + 3); - if (r3[0] == FIELD_MOVE_TELEPORT || r3[0] == FIELD_MOVE_DIG) + 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) sEventShouldNotRecordSteps = 2; else sEventShouldNotRecordSteps = 1; - return (u16 *)(r3 + 2); + 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) @@ -1947,7 +2048,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); @@ -1957,23 +2058,23 @@ static const u16 *BufferQuestLogText_UsedFieldMove(const u16 *eventData) return (const u16 *)(r5 + 2); } -static u16 *BufferQuestLogData_BoughtItem(u16 *dest, const u16 *eventData) +static u16 *RecordEvent_BoughtItem(u16 *dest, const struct QuestLogEvent_Shop * data) { - dest = RecordEvent(QL_EVENT_BOUGHT_ITEM, dest); + dest = RecordEventHeader(QL_EVENT_BOUGHT_ITEM, dest); if (dest == NULL) return NULL; - dest[0] = eventData[2]; - dest[1] = eventData[3]; - dest[2] = *((const u32 *)eventData) >> 16; - dest[3] = *((const u32 *)eventData); - *((u8 *)dest + 8) = *((const u8 *)eventData + 8); - *((u8 *)dest + 9) = 1; + 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(); @@ -1991,23 +2092,23 @@ static const u16 *BufferQuestLogText_BoughtItem(const u16 *eventData) return (const u16 *)(r7 + 2); } -static u16 *BufferQuestLogData_SoldItem(u16 *dest, const u16 *eventData) +static u16 *RecordEvent_SoldItem(u16 *dest, const struct QuestLogEvent_Shop * data) { - dest = RecordEvent(QL_EVENT_SOLD_ITEM, dest); + dest = RecordEventHeader(QL_EVENT_SOLD_ITEM, dest); if (dest == NULL) return NULL; - dest[0] = eventData[2]; - dest[1] = eventData[3]; - dest[2] = *((const u32 *)eventData) >> 16; - dest[3] = *((const u32 *)eventData); - *((u8 *)dest + 8) = *((const u8 *)eventData + 8); - *((u8 *)dest + 9) = *((const u8 *)eventData + 9); + 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(); @@ -2038,19 +2139,19 @@ static const u16 *BufferQuestLogText_SoldItem(const u16 *eventData) return (const u16 *)(r7 + 2); } -static u16 *BufferQuestLogData_ObtainedItem(u16 *dest, const u16 *eventData) +static u16 *RecordEvent_ObtainedStoryItem(u16 *dest, const struct QuestLogEvent_StoryItem * data) { - dest = RecordEvent(QL_EVENT_OBTAINED_ITEM, dest); + dest = RecordEventHeader(QL_EVENT_OBTAINED_STORY_ITEM, dest); if (dest == NULL) return NULL; - dest[0] = eventData[0]; - *((u8 *)dest + 2) = *((const u8 *)eventData + 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])); @@ -2058,27 +2159,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; @@ -2086,9 +2166,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)) { @@ -2105,38 +2185,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 *dest, const u16 *eventData) +static u16 *RecordEvent_ArrivedInLocation(u16 *dest, const u16 * data) { - dest = RecordEvent(QL_EVENT_ARRIVED, dest); + dest = RecordEventHeader(QL_EVENT_ARRIVED, dest); if (dest == NULL) return NULL; - dest[0] = eventData[0]; + 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/shop.c b/src/shop.c index a81e6e824..0ae2d7e02 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 infomration 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_get_market_price(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_get_market_price(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 18d1beafe..12263a23d 100644 --- a/src/tm_case.c +++ b/src/tm_case.c @@ -22,6 +22,7 @@ #include "menu_indicators.h" #include "constants/items.h" #include "constants/songs.h" +#include "constants/quest_log.h" #define TM_CASE_TM_TAG 400 @@ -1100,7 +1101,7 @@ static void Task_DoSaleOfTMs(u8 taskId) PlaySE(SE_SHOP); RemoveBagItem(gSpecialVar_ItemId, data[8]); AddMoney(&gSaveBlock1Ptr->money, itemid_get_market_price(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], &sTMCaseStaticResources.scrollOffset, &sTMCaseStaticResources.selectedRow); TMCaseSetup_GetTMCount(); TMCaseSetup_InitListMenuPositions(); diff --git a/src/trade_scene.c b/src/trade_scene.c index a946299b9..7ceed0d62 100644 --- a/src/trade_scene.c +++ b/src/trade_scene.c @@ -98,9 +98,7 @@ struct TradeAnimationResources { /*0xF0*/ u16 tradeSpecies[2]; /*0xF4*/ u16 cachedMapMusic; /*0xF6*/ u8 unk_F6; - /*0xF8*/ u16 monSpecies[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_InitTradeAnim_LinkTrade(void) case 10: BeginNormalPaletteFade(PALETTES_ALL, 0, 16, 0, RGB_BLACK); ShowBg(0); - sTradeData->monSpecies[0] = GetMonData(&gPlayerParty[gSelectedTradeMonPositions[0]], MON_DATA_SPECIES2); - sTradeData->monSpecies[1] = GetMonData(&gEnemyParty[gSelectedTradeMonPositions[1] % 6], MON_DATA_SPECIES2); - memcpy(sTradeData->linkPartnerName, gLinkPlayers[GetMultiplayerId() ^ 1].name, 7); + sTradeData->questLogData.speciesSent = GetMonData(&gPlayerParty[gSelectedTradeMonPositions[0]], MON_DATA_SPECIES2); + sTradeData->questLogData.speciesReceived = GetMonData(&gEnemyParty[gSelectedTradeMonPositions[1] % PARTY_SIZE], MON_DATA_SPECIES2); + memcpy(sTradeData->questLogData.partnerName, gLinkPlayers[GetMultiplayerId() ^ 1].name, PLAYER_NAME_LENGTH); gMain.state++; break; case 11: @@ -2575,11 +2573,11 @@ static void CB2_HandleTradeEnded(void) case 50: if (InUnionRoom()) { - SetQuestLogEvent(QL_EVENT_LINK_TRADED_UNION, sTradeData->monSpecies); + SetQuestLogEvent(QL_EVENT_LINK_TRADED_UNION, (void *)&sTradeData->questLogData); } else { - SetQuestLogEvent(QL_EVENT_LINK_TRADED, sTradeData->monSpecies); + SetQuestLogEvent(QL_EVENT_LINK_TRADED, (void *)&sTradeData->questLogData); IncrementGameStat(GAME_STAT_POKEMON_TRADES); } if (gWirelessCommType)