Clarify ql event data

This commit is contained in:
GriffinR
2022-11-11 08:49:57 -05:00
parent ae38640a3b
commit 45546ce350
20 changed files with 1237 additions and 1075 deletions
+1 -1
View File
@@ -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;
+2 -2
View File
@@ -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)
+2 -9
View File
@@ -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;
+129 -2
View File
@@ -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);
+1 -1
View File
@@ -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);
+1 -1
View File
@@ -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)
{
+2 -1
View File
@@ -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();
+31 -31
View File
@@ -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);
+7 -16
View File
@@ -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);
}
}
}
+3 -2
View File
@@ -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);
+7 -13
View File
@@ -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);
}
+1 -1
View File
@@ -1458,7 +1458,7 @@ static void OverworldBasic(void)
RunTasks();
AnimateSprites();
CameraUpdate();
sub_8115798();
SetQuestLogEvent_Arrived();
UpdateCameraPanning();
BuildOamBuffer();
UpdatePaletteFade();
+37 -43
View File
@@ -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)
+2 -2
View File
@@ -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)
{
+4 -2
View File
@@ -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 {
+48 -64
View File
@@ -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;
}
}
+900 -821
View File
File diff suppressed because it is too large Load Diff
+51 -54
View File
@@ -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)
+2 -1
View File
@@ -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();
+6 -8
View File
@@ -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)