diff --git a/data/maps/BattleFrontier_RankingHall/scripts.inc b/data/maps/BattleFrontier_RankingHall/scripts.inc index 20b2b21c1..a6c62cf86 100644 --- a/data/maps/BattleFrontier_RankingHall/scripts.inc +++ b/data/maps/BattleFrontier_RankingHall/scripts.inc @@ -3,61 +3,61 @@ BattleFrontier_RankingHall_MapScripts:: BattleFrontier_RankingHall_EventScript_TowerSinglesRecords:: lockall - setvar VAR_0x8005, RANKING_HALL_BATTLE_TOWER_SINGLES + setvar VAR_0x8005, RANKING_HALL_TOWER_SINGLES goto BattleFrontier_RankingHall_EventScript_ShowRecords end BattleFrontier_RankingHall_EventScript_TowerDoublesRecords:: lockall - setvar VAR_0x8005, RANKING_HALL_BATTLE_TOWER_DOUBLES + setvar VAR_0x8005, RANKING_HALL_TOWER_DOUBLES goto BattleFrontier_RankingHall_EventScript_ShowRecords end BattleFrontier_RankingHall_EventScript_TowerMultisRecords:: lockall - setvar VAR_0x8005, RANKING_HALL_BATTLE_TOWER_MULTIS + setvar VAR_0x8005, RANKING_HALL_TOWER_MULTIS goto BattleFrontier_RankingHall_EventScript_ShowRecords end BattleFrontier_RankingHall_EventScript_TowerLinkRecords:: lockall - setvar VAR_0x8005, RANKING_HALL_BATTLE_TOWER_LINK + setvar VAR_0x8005, RANKING_HALL_TOWER_LINK goto BattleFrontier_RankingHall_EventScript_ShowRecords end BattleFrontier_RankingHall_EventScript_ArenaRecords:: lockall - setvar VAR_0x8005, RANKING_HALL_BATTLE_ARENA + setvar VAR_0x8005, RANKING_HALL_ARENA goto BattleFrontier_RankingHall_EventScript_ShowRecords end BattleFrontier_RankingHall_EventScript_PalaceRecords:: lockall - setvar VAR_0x8005, RANKING_HALL_BATTLE_PALACE + setvar VAR_0x8005, RANKING_HALL_PALACE goto BattleFrontier_RankingHall_EventScript_ShowRecords end BattleFrontier_RankingHall_EventScript_FactoryRecords:: lockall - setvar VAR_0x8005, RANKING_HALL_BATTLE_FACTORY + setvar VAR_0x8005, RANKING_HALL_FACTORY goto BattleFrontier_RankingHall_EventScript_ShowRecords end BattleFrontier_RankingHall_EventScript_DomeRecords:: lockall - setvar VAR_0x8005, RANKING_HALL_BATTLE_DOME + setvar VAR_0x8005, RANKING_HALL_DOME goto BattleFrontier_RankingHall_EventScript_ShowRecords end BattleFrontier_RankingHall_EventScript_PikeRecords:: lockall - setvar VAR_0x8005, RANKING_HALL_BATTLE_PIKE + setvar VAR_0x8005, RANKING_HALL_PIKE goto BattleFrontier_RankingHall_EventScript_ShowRecords end BattleFrontier_RankingHall_EventScript_PyramidRecords:: lockall - setvar VAR_0x8005, RANKING_HALL_BATTLE_PYRAMID + setvar VAR_0x8005, RANKING_HALL_PYRAMID goto BattleFrontier_RankingHall_EventScript_ShowRecords end diff --git a/include/constants/battle_frontier.h b/include/constants/battle_frontier.h index 68c5a42ef..b6d15e6b2 100644 --- a/include/constants/battle_frontier.h +++ b/include/constants/battle_frontier.h @@ -17,11 +17,6 @@ #define FACILITY_UNION_ROOM 8 #define FACILITY_MULTI_OR_EREADER 9 // Direct Corner multi battles, multi battle with Steven, and e-Reader battles -// Battle Frontier lvl modes. -#define FRONTIER_LVL_50 0 -#define FRONTIER_LVL_OPEN 1 -#define FRONTIER_LVL_TENT 2 - // Battle Frontier battle modes. #define FRONTIER_MODE_SINGLES 0 #define FRONTIER_MODE_DOUBLES 1 @@ -53,28 +48,28 @@ // These sets of facility ids would be redundant if the order was consistent // The order is important for this set so that all the non-link records can be continuous -#define RANKING_HALL_BATTLE_TOWER_SINGLES 0 -#define RANKING_HALL_BATTLE_TOWER_DOUBLES 1 -#define RANKING_HALL_BATTLE_TOWER_MULTIS 2 -#define RANKING_HALL_BATTLE_DOME 3 -#define RANKING_HALL_BATTLE_PALACE 4 -#define RANKING_HALL_BATTLE_ARENA 5 -#define RANKING_HALL_BATTLE_FACTORY 6 -#define RANKING_HALL_BATTLE_PIKE 7 -#define RANKING_HALL_BATTLE_PYRAMID 8 -#define RANKING_HALL_BATTLE_TOWER_LINK 9 +#define RANKING_HALL_TOWER_SINGLES 0 +#define RANKING_HALL_TOWER_DOUBLES 1 +#define RANKING_HALL_TOWER_MULTIS 2 +#define RANKING_HALL_DOME 3 +#define RANKING_HALL_PALACE 4 +#define RANKING_HALL_ARENA 5 +#define RANKING_HALL_FACTORY 6 +#define RANKING_HALL_PIKE 7 +#define RANKING_HALL_PYRAMID 8 +#define RANKING_HALL_TOWER_LINK 9 -#define FRONTIER_MANIAC_BATTLE_TOWER_SINGLES 0 -#define FRONTIER_MANIAC_BATTLE_TOWER_DOUBLES 1 -#define FRONTIER_MANIAC_BATTLE_TOWER_MULTIS 2 -#define FRONTIER_MANIAC_BATTLE_TOWER_LINK 3 -#define FRONTIER_MANIAC_BATTLE_DOME 4 -#define FRONTIER_MANIAC_BATTLE_FACTORY 5 -#define FRONTIER_MANIAC_BATTLE_PALACE 6 -#define FRONTIER_MANIAC_BATTLE_ARENA 7 -#define FRONTIER_MANIAC_BATTLE_PIKE 8 -#define FRONTIER_MANIAC_BATTLE_PYRAMID 9 -#define FRONTIER_MANIAC_FACILITY_COUNT 10 +#define FRONTIER_MANIAC_TOWER_SINGLES 0 +#define FRONTIER_MANIAC_TOWER_DOUBLES 1 +#define FRONTIER_MANIAC_TOWER_MULTIS 2 +#define FRONTIER_MANIAC_TOWER_LINK 3 +#define FRONTIER_MANIAC_DOME 4 +#define FRONTIER_MANIAC_FACTORY 5 +#define FRONTIER_MANIAC_PALACE 6 +#define FRONTIER_MANIAC_ARENA 7 +#define FRONTIER_MANIAC_PIKE 8 +#define FRONTIER_MANIAC_PYRAMID 9 +#define FRONTIER_MANIAC_FACILITY_COUNT 10 #define FRONTIER_MANIAC_MESSAGE_COUNT 3 diff --git a/include/constants/global.h b/include/constants/global.h index 1cece7975..46518697c 100644 --- a/include/constants/global.h +++ b/include/constants/global.h @@ -53,9 +53,19 @@ #define UNION_ROOM_KB_ROW_COUNT 10 #define GIFT_RIBBONS_COUNT 11 #define SAVED_TRENDS_COUNT 5 - #define PYRAMID_BAG_ITEMS_COUNT 10 -#define HALL_FACILITIES_COUNT 9 // 7 facilities for single mode + tower double mode + tower multi mode. + +// Number of facilities for Ranking Hall. +// 7 facilities for single mode + tower double mode + tower multi mode. +// Excludes link modes. See RANKING_HALL_* in include/constants/battle_frontier.h +#define HALL_FACILITIES_COUNT 9 +#define HALL_RECORDS_COUNT 3 + +// Battle Frontier level modes. +#define FRONTIER_LVL_50 0 +#define FRONTIER_LVL_OPEN 1 +#define FRONTIER_LVL_MODE_COUNT 2 +#define FRONTIER_LVL_TENT FRONTIER_LVL_MODE_COUNT // Special usage for indicating Battle Tent #define TRAINER_ID_LENGTH 4 #define MAX_MON_MOVES 4 diff --git a/include/daycare.h b/include/daycare.h index d6c0d4201..62a7918ff 100644 --- a/include/daycare.h +++ b/include/daycare.h @@ -3,10 +3,17 @@ #include "constants/daycare.h" +struct RecordMixingDaycareMail +{ + struct DaycareMail mail[DAYCARE_MON_COUNT]; + u32 numDaycareMons; + bool16 cantHoldItem[DAYCARE_MON_COUNT]; +}; + u8 *GetMonNickname2(struct Pokemon *mon, u8 *dest); u8 *GetBoxMonNickname(struct BoxPokemon *mon, u8 *dest); u8 CountPokemonInDaycare(struct DayCare *daycare); -void InitDaycareMailRecordMixing(struct DayCare *daycare, struct RecordMixingDaycareMail *daycareMail); +void InitDaycareMailRecordMixing(struct DayCare *daycare, struct RecordMixingDaycareMail *mixMail); void StoreSelectedPokemonInDaycare(void); u16 TakePokemonFromDaycare(void); void GetDaycareCost(void); diff --git a/include/global.h b/include/global.h index d14aa60f4..87c1d3d45 100644 --- a/include/global.h +++ b/include/global.h @@ -208,11 +208,10 @@ struct BerryPickingResults u8 field_F; }; -// two arrays for lvl50 and open level struct PyramidBag { - u16 itemId[2][PYRAMID_BAG_ITEMS_COUNT]; - u8 quantity[2][PYRAMID_BAG_ITEMS_COUNT]; + u16 itemId[FRONTIER_LVL_MODE_COUNT][PYRAMID_BAG_ITEMS_COUNT]; + u8 quantity[FRONTIER_LVL_MODE_COUNT][PYRAMID_BAG_ITEMS_COUNT]; }; struct BerryCrush @@ -353,8 +352,8 @@ struct BattleFrontier /*0xCB2*/ u16 curChallengeBattleNum; // Battle number / room number (Pike) / floor number (Pyramid) /*0xCB4*/ u16 trainerIds[20]; /*0xCDC*/ u32 winStreakActiveFlags; - /*0xCE0*/ u16 towerWinStreaks[4][2]; - /*0xCF0*/ u16 towerRecordWinStreaks[4][2]; + /*0xCE0*/ u16 towerWinStreaks[4][FRONTIER_LVL_MODE_COUNT]; + /*0xCF0*/ u16 towerRecordWinStreaks[4][FRONTIER_LVL_MODE_COUNT]; /*0xD00*/ u16 battledBrainFlags; /*0xD02*/ u16 towerSinglesStreak; // Never read /*0xD04*/ u16 towerNumWins; // Increments to MAX_STREAK but never read otherwise @@ -371,33 +370,33 @@ struct BattleFrontier /*0xD09*/ u8 domeUnused; /*0xD0A*/ u8 domeLvlMode; /*0xD0B*/ u8 domeBattleMode; - /*0xD0C*/ u16 domeWinStreaks[2][2]; - /*0xD14*/ u16 domeRecordWinStreaks[2][2]; - /*0xD1C*/ u16 domeTotalChampionships[2][2]; + /*0xD0C*/ u16 domeWinStreaks[2][FRONTIER_LVL_MODE_COUNT]; + /*0xD14*/ u16 domeRecordWinStreaks[2][FRONTIER_LVL_MODE_COUNT]; + /*0xD1C*/ u16 domeTotalChampionships[2][FRONTIER_LVL_MODE_COUNT]; /*0xD24*/ struct BattleDomeTrainer domeTrainers[DOME_TOURNAMENT_TRAINERS_COUNT]; /*0xD64*/ u16 domeMonIds[DOME_TOURNAMENT_TRAINERS_COUNT][FRONTIER_PARTY_SIZE]; /*0xDC4*/ u16 unused_DC4; /*0xDC6*/ u16 palacePrize; - /*0xDC8*/ u16 palaceWinStreaks[2][2]; - /*0xDD0*/ u16 palaceRecordWinStreaks[2][2]; + /*0xDC8*/ u16 palaceWinStreaks[2][FRONTIER_LVL_MODE_COUNT]; + /*0xDD0*/ u16 palaceRecordWinStreaks[2][FRONTIER_LVL_MODE_COUNT]; /*0xDD8*/ u16 arenaPrize; - /*0xDDA*/ u16 arenaWinStreaks[2]; - /*0xDDE*/ u16 arenaRecordStreaks[2]; - /*0xDE2*/ u16 factoryWinStreaks[2][2]; - /*0xDEA*/ u16 factoryRecordWinStreaks[2][2]; - /*0xDF6*/ u16 factoryRentsCount[2][2]; - /*0xDFA*/ u16 factoryRecordRentsCount[2][2]; + /*0xDDA*/ u16 arenaWinStreaks[FRONTIER_LVL_MODE_COUNT]; + /*0xDDE*/ u16 arenaRecordStreaks[FRONTIER_LVL_MODE_COUNT]; + /*0xDE2*/ u16 factoryWinStreaks[2][FRONTIER_LVL_MODE_COUNT]; + /*0xDEA*/ u16 factoryRecordWinStreaks[2][FRONTIER_LVL_MODE_COUNT]; + /*0xDF6*/ u16 factoryRentsCount[2][FRONTIER_LVL_MODE_COUNT]; + /*0xDFA*/ u16 factoryRecordRentsCount[2][FRONTIER_LVL_MODE_COUNT]; /*0xE02*/ u16 pikePrize; - /*0xE04*/ u16 pikeWinStreaks[2]; - /*0xE08*/ u16 pikeRecordStreaks[2]; - /*0xE0C*/ u16 pikeTotalStreaks[2]; + /*0xE04*/ u16 pikeWinStreaks[FRONTIER_LVL_MODE_COUNT]; + /*0xE08*/ u16 pikeRecordStreaks[FRONTIER_LVL_MODE_COUNT]; + /*0xE0C*/ u16 pikeTotalStreaks[FRONTIER_LVL_MODE_COUNT]; /*0xE10*/ u8 pikeHintedRoomIndex:3; /*0xE10*/ u8 pikeHintedRoomType:4; /*0xE10*/ u8 pikeHealingRoomsDisabled:1; /*0xE12*/ u16 pikeHeldItemsBackup[FRONTIER_PARTY_SIZE]; /*0xE18*/ u16 pyramidPrize; - /*0xE1A*/ u16 pyramidWinStreaks[2]; - /*0xE1E*/ u16 pyramidRecordStreaks[2]; + /*0xE1A*/ u16 pyramidWinStreaks[FRONTIER_LVL_MODE_COUNT]; + /*0xE1E*/ u16 pyramidRecordStreaks[FRONTIER_LVL_MODE_COUNT]; /*0xE22*/ u16 pyramidRandoms[4]; /*0xE2A*/ u8 pyramidTrainerFlags; /*0xE2C*/ struct PyramidBag pyramidBag; @@ -411,8 +410,8 @@ struct BattleFrontier /*0xEBC*/ u32 battlesCount; /*0xEC0*/ u16 domeWinningMoves[DOME_TOURNAMENT_TRAINERS_COUNT]; /*0xEE0*/ u8 trainerFlags; - /*0xEE1*/ u8 opponentNames[2][PLAYER_NAME_LENGTH + 1]; - /*0xEF1*/ u8 opponentTrainerIds[2][TRAINER_ID_LENGTH]; + /*0xEE1*/ u8 opponentNames[FRONTIER_LVL_MODE_COUNT][PLAYER_NAME_LENGTH + 1]; + /*0xEF1*/ u8 opponentTrainerIds[FRONTIER_LVL_MODE_COUNT][TRAINER_ID_LENGTH]; /*0xEF9*/ u8 unk_EF9:7; // Never read /*0xEF9*/ u8 savedGame:1; /*0xEFA*/ u8 unused_EFA; @@ -488,8 +487,8 @@ struct SaveBlock2 /*0x1EC*/ struct BerryCrush berryCrush; /*0x1FC*/ struct PokemonJumpRecords pokeJump; /*0x20C*/ struct BerryPickingResults berryPick; - /*0x21C*/ struct RankingHall1P hallRecords1P[HALL_FACILITIES_COUNT][2][3]; // From record mixing. - /*0x57C*/ struct RankingHall2P hallRecords2P[2][3]; // From record mixing. + /*0x21C*/ struct RankingHall1P hallRecords1P[HALL_FACILITIES_COUNT][FRONTIER_LVL_MODE_COUNT][HALL_RECORDS_COUNT]; // From record mixing. + /*0x57C*/ struct RankingHall2P hallRecords2P[FRONTIER_LVL_MODE_COUNT][HALL_RECORDS_COUNT]; // From record mixing. /*0x624*/ u16 contestLinkResults[CONTEST_CATEGORIES_COUNT][CONTESTANT_COUNT]; /*0x64C*/ struct BattleFrontier frontier; }; // sizeof=0xF2C @@ -597,15 +596,6 @@ struct DewfordTrend u16 words[2]; }; /*size = 0x8*/ -struct MailStruct -{ - /*0x00*/ u16 words[MAIL_WORDS_COUNT]; - /*0x12*/ u8 playerName[PLAYER_NAME_LENGTH + 1]; - /*0x1A*/ u8 trainerId[TRAINER_ID_LENGTH]; - /*0x1E*/ u16 species; - /*0x20*/ u16 itemId; -}; - struct MauvilleManCommon { u8 id; @@ -671,20 +661,6 @@ typedef union OldMan u8 filler[0x40]; } OldMan; -struct RecordMixing_UnknownStructSub -{ - u32 unk0; - u8 data[0x34]; - //u8 data[0x38]; -}; - -struct RecordMixing_UnknownStruct -{ - struct RecordMixing_UnknownStructSub data[2]; - u32 unk70; - u16 unk74[0x2]; -}; - #define LINK_B_RECORDS_COUNT 5 struct LinkBattleRecord @@ -727,10 +703,19 @@ struct ContestWinner u8 contestRank; }; +struct Mail +{ + /*0x00*/ u16 words[MAIL_WORDS_COUNT]; + /*0x12*/ u8 playerName[PLAYER_NAME_LENGTH + 1]; + /*0x1A*/ u8 trainerId[TRAINER_ID_LENGTH]; + /*0x1E*/ u16 species; + /*0x20*/ u16 itemId; +}; + struct DaycareMail { - struct MailStruct message; - u8 OT_name[PLAYER_NAME_LENGTH + 1]; + struct Mail message; + u8 otName[PLAYER_NAME_LENGTH + 1]; u8 monName[POKEMON_NAME_LENGTH + 1]; u8 gameLanguage:4; u8 monLanguage:4; @@ -750,13 +735,6 @@ struct DayCare u8 stepCounter; }; -struct RecordMixingDaycareMail -{ - struct DaycareMail mail[DAYCARE_MON_COUNT]; - u32 numDaycareMons; - bool16 holdsItem[DAYCARE_MON_COUNT]; -}; - struct LilycoveLadyQuiz { /*0x000*/ u8 id; @@ -1019,7 +997,7 @@ struct SaveBlock1 /*0x2BBC*/ u16 easyChatBattleStart[EASY_CHAT_BATTLE_WORDS_COUNT]; /*0x2BC8*/ u16 easyChatBattleWon[EASY_CHAT_BATTLE_WORDS_COUNT]; /*0x2BD4*/ u16 easyChatBattleLost[EASY_CHAT_BATTLE_WORDS_COUNT]; - /*0x2BE0*/ struct MailStruct mail[MAIL_COUNT]; + /*0x2BE0*/ struct Mail mail[MAIL_COUNT]; /*0x2E20*/ u8 additionalPhrases[8]; // bitfield for 33 additional phrases in easy chat system /*0x2E28*/ OldMan oldMan; /*0x2e64*/ struct DewfordTrend dewfordTrends[SAVED_TRENDS_COUNT]; diff --git a/include/mail.h b/include/mail.h index 042586653..8236811cb 100644 --- a/include/mail.h +++ b/include/mail.h @@ -15,16 +15,16 @@ || itemId == ITEM_RETRO_MAIL)) // mail.h -void ReadMail(struct MailStruct *mail, void (*callback)(void), bool8 flag); +void ReadMail(struct Mail *mail, void (*callback)(void), bool8 flag); // mail_data.h -void ClearMailData(void); -void ClearMailStruct(struct MailStruct *mail); +void ClearAllMail(void); +void ClearMail(struct Mail *mail); bool8 MonHasMail(struct Pokemon *mon); -u8 GiveMailToMon(struct Pokemon *mon, u16 itemId); +u8 GiveMailToMonByItemId(struct Pokemon *mon, u16 itemId); u16 SpeciesToMailSpecies(u16 species, u32 personality); u16 MailSpeciesToSpecies(u16 mailSpecies, u16 *buffer); -u8 GiveMailToMon2(struct Pokemon *mon, struct MailStruct *mail); +u8 GiveMailToMon(struct Pokemon *mon, struct Mail *mail); void TakeMailFromMon(struct Pokemon *mon); void ClearMailItemId(u8 mailId); u8 TakeMailFromMon2(struct Pokemon *mon); diff --git a/include/record_mixing.h b/include/record_mixing.h index 4cd231e8a..fec4952b8 100644 --- a/include/record_mixing.h +++ b/include/record_mixing.h @@ -3,8 +3,8 @@ struct PlayerHallRecords { - struct RankingHall1P onePlayer[9][2]; - struct RankingHall2P twoPlayers[2]; + struct RankingHall1P onePlayer[HALL_FACILITIES_COUNT][FRONTIER_LVL_MODE_COUNT]; + struct RankingHall2P twoPlayers[FRONTIER_LVL_MODE_COUNT]; }; void RecordMixingPlayerSpotTriggered(void); diff --git a/include/trade.h b/include/trade.h index 05a905ab3..a0cb320a8 100644 --- a/include/trade.h +++ b/include/trade.h @@ -4,13 +4,9 @@ #include "link_rfu.h" #include "constants/trade.h" -// Exported type declarations - -// Exported RAM declarations -extern struct MailStruct gTradeMail[PARTY_SIZE]; +extern struct Mail gTradeMail[PARTY_SIZE]; extern u8 gSelectedTradeMonPositions[2]; -// Exported ROM declarations extern const struct WindowTemplate gTradeEvolutionSceneYesNoWindowTemplate; s32 GetGameProgressForLinkTrade(void); diff --git a/src/battle_tower.c b/src/battle_tower.c index e3712def2..b2f81cc1a 100644 --- a/src/battle_tower.c +++ b/src/battle_tower.c @@ -1830,7 +1830,7 @@ static void FillFactoryFrontierTrainerParty(u16 trainerId, u8 firstMonId) { u8 lvlMode = gSaveBlock2Ptr->frontier.lvlMode; // Unused variable. u8 battleMode = VarGet(VAR_FRONTIER_BATTLE_MODE); - u8 challengeNum = gSaveBlock2Ptr->frontier.towerWinStreaks[battleMode][0] / 7; + u8 challengeNum = gSaveBlock2Ptr->frontier.towerWinStreaks[battleMode][FRONTIER_LVL_50] / 7; if (gSaveBlock2Ptr->frontier.curChallengeBattleNum < 6) fixedIV = GetFactoryMonFixedIV(challengeNum, 0); else diff --git a/src/data/trade.h b/src/data/trade.h index 7088633a8..b26072763 100644 --- a/src/data/trade.h +++ b/src/data/trade.h @@ -19,7 +19,7 @@ static const u32 sUnusedStructSizes[] = sizeof(struct SaveBlock1), sizeof(struct MapHeader), // 0x00000530, in RS - sizeof(struct MailStruct), //or ObjectEvent / ObjectEventGraphicsInfo + sizeof(struct Mail), //or ObjectEvent / ObjectEventGraphicsInfo sizeof(struct Pokemon), //or TrainerCard 0x00000528 // 0x000004D8, in RS }; diff --git a/src/daycare.c b/src/daycare.c index 8dd751531..8105c2e9c 100644 --- a/src/daycare.c +++ b/src/daycare.c @@ -25,7 +25,6 @@ extern const struct Evolution gEvolutionTable[][EVOS_PER_MON]; -// this file's functions static void ClearDaycareMonMail(struct DaycareMail *mail); static void SetInitialEggData(struct Pokemon *mon, u16 species, struct DayCare *daycare); static u8 GetDaycareCompatibilityScore(struct DayCare *daycare); @@ -122,7 +121,7 @@ u8 CountPokemonInDaycare(struct DayCare *daycare) return count; } -void InitDaycareMailRecordMixing(struct DayCare *daycare, struct RecordMixingDaycareMail *daycareMail) +void InitDaycareMailRecordMixing(struct DayCare *daycare, struct RecordMixingDaycareMail *mixMail) { u8 i; u8 numDaycareMons = 0; @@ -133,17 +132,18 @@ void InitDaycareMailRecordMixing(struct DayCare *daycare, struct RecordMixingDay { numDaycareMons++; if (GetBoxMonData(&daycare->mons[i].mon, MON_DATA_HELD_ITEM) == ITEM_NONE) - daycareMail->holdsItem[i] = FALSE; + mixMail->cantHoldItem[i] = FALSE; else - daycareMail->holdsItem[i] = TRUE; + mixMail->cantHoldItem[i] = TRUE; } else { - daycareMail->holdsItem[i] = TRUE; + // Daycare slot empty + mixMail->cantHoldItem[i] = TRUE; } } - daycareMail->numDaycareMons = numDaycareMons; + mixMail->numDaycareMons = numDaycareMons; } static s8 Daycare_FindEmptySpot(struct DayCare *daycare) @@ -165,7 +165,7 @@ static void StorePokemonInDaycare(struct Pokemon *mon, struct DaycareMon *daycar { u8 mailId; - StringCopy(daycareMon->mail.OT_name, gSaveBlock2Ptr->playerName); + StringCopy(daycareMon->mail.otName, gSaveBlock2Ptr->playerName); GetMonNickname2(mon, daycareMon->mail.monName); StripExtCtrlCodes(daycareMon->mail.monName); daycareMon->mail.gameLanguage = GAME_LANGUAGE; @@ -262,7 +262,7 @@ static u16 TakeSelectedPokemonFromDaycare(struct DaycareMon *daycareMon) gPlayerParty[PARTY_SIZE - 1] = pokemon; if (daycareMon->mail.message.itemId) { - GiveMailToMon2(&gPlayerParty[PARTY_SIZE - 1], &daycareMon->mail.message); + GiveMailToMon(&gPlayerParty[PARTY_SIZE - 1], &daycareMon->mail.message); ClearDaycareMonMail(&daycareMon->mail); } @@ -352,11 +352,11 @@ static void ClearDaycareMonMail(struct DaycareMail *mail) s32 i; for (i = 0; i < PLAYER_NAME_LENGTH + 1; i++) - mail->OT_name[i] = 0; + mail->otName[i] = 0; for (i = 0; i < POKEMON_NAME_LENGTH + 1; i++) mail->monName[i] = 0; - ClearMailStruct(&mail->message); + ClearMail(&mail->message); } static void ClearDaycareMon(struct DaycareMon *daycareMon) diff --git a/src/dewford_trend.c b/src/dewford_trend.c index d193ef1f5..bba2085e8 100644 --- a/src/dewford_trend.c +++ b/src/dewford_trend.c @@ -271,9 +271,7 @@ void ReceiveDewfordTrendData(struct DewfordTrend *linkedTrends, size_t size, u8 // Only overwrrite it if it's "trendier" temp = &savedTrendsBuffer[idx]; if (temp->trendiness < src->trendiness) - { *temp = *src; - } } src++; } diff --git a/src/egg_hatch.c b/src/egg_hatch.c index b8ab1b91e..e491b7b14 100644 --- a/src/egg_hatch.c +++ b/src/egg_hatch.c @@ -396,10 +396,10 @@ static bool8 _CheckDaycareMonReceivedMail(struct DayCare *daycare, u8 daycareId) GetBoxMonNickname(&daycareMon->mon, nickname); if (daycareMon->mail.message.itemId != ITEM_NONE && (StringCompareWithoutExtCtrlCodes(nickname, daycareMon->mail.monName) != 0 - || StringCompareWithoutExtCtrlCodes(gSaveBlock2Ptr->playerName, daycareMon->mail.OT_name) != 0)) + || StringCompareWithoutExtCtrlCodes(gSaveBlock2Ptr->playerName, daycareMon->mail.otName) != 0)) { StringCopy(gStringVar1, nickname); - TVShowConvertInternationalString(gStringVar2, daycareMon->mail.OT_name, daycareMon->mail.gameLanguage); + TVShowConvertInternationalString(gStringVar2, daycareMon->mail.otName, daycareMon->mail.gameLanguage); TVShowConvertInternationalString(gStringVar3, daycareMon->mail.monName, daycareMon->mail.monLanguage); return TRUE; } diff --git a/src/field_screen_effect.c b/src/field_screen_effect.c index 65611c0f1..e573fe5ab 100644 --- a/src/field_screen_effect.c +++ b/src/field_screen_effect.c @@ -235,9 +235,7 @@ void Task_ReturnToFieldRecordMixing(u8 taskId) break; case 1: if (IsLinkTaskFinished()) - { task->tState++; - } break; case 2: StartSendingKeysToLink(); diff --git a/src/field_specials.c b/src/field_specials.c index ab02f9938..3285ea9a4 100644 --- a/src/field_specials.c +++ b/src/field_specials.c @@ -2071,61 +2071,61 @@ void ShowFrontierManiacMessage(void) { static const u8 *const sFrontierManiacMessages[][FRONTIER_MANIAC_MESSAGE_COUNT] = { - [FRONTIER_MANIAC_BATTLE_TOWER_SINGLES] = + [FRONTIER_MANIAC_TOWER_SINGLES] = { BattleFrontier_Lounge2_Text_SalonMaidenIsThere, BattleFrontier_Lounge2_Text_SalonMaidenSilverMons, BattleFrontier_Lounge2_Text_SalonMaidenGoldMons }, - [FRONTIER_MANIAC_BATTLE_TOWER_DOUBLES] = + [FRONTIER_MANIAC_TOWER_DOUBLES] = { BattleFrontier_Lounge2_Text_DoubleBattleAdvice1, BattleFrontier_Lounge2_Text_DoubleBattleAdvice2, BattleFrontier_Lounge2_Text_DoubleBattleAdvice3 }, - [FRONTIER_MANIAC_BATTLE_TOWER_MULTIS] = + [FRONTIER_MANIAC_TOWER_MULTIS] = { BattleFrontier_Lounge2_Text_MultiBattleAdvice, BattleFrontier_Lounge2_Text_MultiBattleAdvice, BattleFrontier_Lounge2_Text_MultiBattleAdvice }, - [FRONTIER_MANIAC_BATTLE_TOWER_LINK] = + [FRONTIER_MANIAC_TOWER_LINK] = { BattleFrontier_Lounge2_Text_LinkMultiBattleAdvice, BattleFrontier_Lounge2_Text_LinkMultiBattleAdvice, BattleFrontier_Lounge2_Text_LinkMultiBattleAdvice }, - [FRONTIER_MANIAC_BATTLE_DOME] = + [FRONTIER_MANIAC_DOME] = { BattleFrontier_Lounge2_Text_DomeAceIsThere, BattleFrontier_Lounge2_Text_DomeAceSilverMons, BattleFrontier_Lounge2_Text_DomeAceGoldMons }, - [FRONTIER_MANIAC_BATTLE_FACTORY] = + [FRONTIER_MANIAC_FACTORY] = { BattleFrontier_Lounge2_Text_FactoryHeadIsThere, BattleFrontier_Lounge2_Text_FactoryHeadSilverMons, BattleFrontier_Lounge2_Text_FactoryHeadGoldMons }, - [FRONTIER_MANIAC_BATTLE_PALACE] = + [FRONTIER_MANIAC_PALACE] = { BattleFrontier_Lounge2_Text_PalaceMavenIsThere, BattleFrontier_Lounge2_Text_PalaceMavenSilverMons, BattleFrontier_Lounge2_Text_PalaceMavenGoldMons }, - [FRONTIER_MANIAC_BATTLE_ARENA] = + [FRONTIER_MANIAC_ARENA] = { BattleFrontier_Lounge2_Text_ArenaTycoonIsThere, BattleFrontier_Lounge2_Text_ArenaTycoonSilverMons, BattleFrontier_Lounge2_Text_ArenaTycoonGoldMons }, - [FRONTIER_MANIAC_BATTLE_PIKE] = + [FRONTIER_MANIAC_PIKE] = { BattleFrontier_Lounge2_Text_PikeQueenIsThere, BattleFrontier_Lounge2_Text_PikeQueenSilverMons, BattleFrontier_Lounge2_Text_PikeQueenGoldMons }, - [FRONTIER_MANIAC_BATTLE_PYRAMID] = + [FRONTIER_MANIAC_PYRAMID] = { BattleFrontier_Lounge2_Text_PyramidKingIsThere, BattleFrontier_Lounge2_Text_PyramidKingSilverMons, @@ -2135,16 +2135,16 @@ void ShowFrontierManiacMessage(void) static const u8 sFrontierManiacStreakThresholds[][FRONTIER_MANIAC_MESSAGE_COUNT - 1] = { - [FRONTIER_MANIAC_BATTLE_TOWER_SINGLES] = { 21, 56 }, - [FRONTIER_MANIAC_BATTLE_TOWER_DOUBLES] = { 21, 35 }, - [FRONTIER_MANIAC_BATTLE_TOWER_MULTIS] = { 255, 255 }, - [FRONTIER_MANIAC_BATTLE_TOWER_LINK] = { 255, 255 }, - [FRONTIER_MANIAC_BATTLE_DOME] = { 2, 4 }, - [FRONTIER_MANIAC_BATTLE_FACTORY] = { 7, 21 }, - [FRONTIER_MANIAC_BATTLE_PALACE] = { 7, 21 }, - [FRONTIER_MANIAC_BATTLE_ARENA] = { 14, 28 }, - [FRONTIER_MANIAC_BATTLE_PIKE] = { 13, 112 }, //BUG: 112 (0x70) is probably a mistake; the Pike Queen is battled twice well before that - [FRONTIER_MANIAC_BATTLE_PYRAMID] = { 7, 56 } + [FRONTIER_MANIAC_TOWER_SINGLES] = { 21, 56 }, + [FRONTIER_MANIAC_TOWER_DOUBLES] = { 21, 35 }, + [FRONTIER_MANIAC_TOWER_MULTIS] = { 255, 255 }, + [FRONTIER_MANIAC_TOWER_LINK] = { 255, 255 }, + [FRONTIER_MANIAC_DOME] = { 2, 4 }, + [FRONTIER_MANIAC_FACTORY] = { 7, 21 }, + [FRONTIER_MANIAC_PALACE] = { 7, 21 }, + [FRONTIER_MANIAC_ARENA] = { 14, 28 }, + [FRONTIER_MANIAC_PIKE] = { 13, 112 }, //BUG: 112 (0x70) is probably a mistake; the Pike Queen is battled twice well before that + [FRONTIER_MANIAC_PYRAMID] = { 7, 56 } }; u8 i; @@ -2153,10 +2153,10 @@ void ShowFrontierManiacMessage(void) switch (facility) { - case FRONTIER_MANIAC_BATTLE_TOWER_SINGLES: - case FRONTIER_MANIAC_BATTLE_TOWER_DOUBLES: - case FRONTIER_MANIAC_BATTLE_TOWER_MULTIS: - case FRONTIER_MANIAC_BATTLE_TOWER_LINK: + case FRONTIER_MANIAC_TOWER_SINGLES: + case FRONTIER_MANIAC_TOWER_DOUBLES: + case FRONTIER_MANIAC_TOWER_MULTIS: + case FRONTIER_MANIAC_TOWER_LINK: if (gSaveBlock2Ptr->frontier.towerWinStreaks[facility][FRONTIER_LVL_50] >= gSaveBlock2Ptr->frontier.towerWinStreaks[facility][FRONTIER_LVL_OPEN]) { @@ -2167,7 +2167,7 @@ void ShowFrontierManiacMessage(void) winStreak = gSaveBlock2Ptr->frontier.towerWinStreaks[facility][FRONTIER_LVL_OPEN]; } break; - case FRONTIER_MANIAC_BATTLE_DOME: + case FRONTIER_MANIAC_DOME: if (gSaveBlock2Ptr->frontier.domeWinStreaks[FRONTIER_MODE_SINGLES][FRONTIER_LVL_50] >= gSaveBlock2Ptr->frontier.domeWinStreaks[FRONTIER_MODE_SINGLES][FRONTIER_LVL_OPEN]) { @@ -2178,7 +2178,7 @@ void ShowFrontierManiacMessage(void) winStreak = gSaveBlock2Ptr->frontier.domeWinStreaks[FRONTIER_MODE_SINGLES][FRONTIER_LVL_OPEN]; } break; - case FRONTIER_MANIAC_BATTLE_FACTORY: + case FRONTIER_MANIAC_FACTORY: if (gSaveBlock2Ptr->frontier.factoryWinStreaks[FRONTIER_MODE_SINGLES][FRONTIER_LVL_50] >= gSaveBlock2Ptr->frontier.factoryWinStreaks[FRONTIER_MODE_SINGLES][FRONTIER_LVL_OPEN]) { @@ -2189,7 +2189,7 @@ void ShowFrontierManiacMessage(void) winStreak = gSaveBlock2Ptr->frontier.factoryWinStreaks[FRONTIER_MODE_SINGLES][FRONTIER_LVL_OPEN]; } break; - case FRONTIER_MANIAC_BATTLE_PALACE: + case FRONTIER_MANIAC_PALACE: if (gSaveBlock2Ptr->frontier.palaceWinStreaks[FRONTIER_MODE_SINGLES][FRONTIER_LVL_50] >= gSaveBlock2Ptr->frontier.palaceWinStreaks[FRONTIER_MODE_SINGLES][FRONTIER_LVL_OPEN]) { @@ -2200,7 +2200,7 @@ void ShowFrontierManiacMessage(void) winStreak = gSaveBlock2Ptr->frontier.palaceWinStreaks[FRONTIER_MODE_SINGLES][FRONTIER_LVL_OPEN]; } break; - case FRONTIER_MANIAC_BATTLE_ARENA: + case FRONTIER_MANIAC_ARENA: if (gSaveBlock2Ptr->frontier.arenaWinStreaks[FRONTIER_LVL_50] >= gSaveBlock2Ptr->frontier.arenaWinStreaks[FRONTIER_LVL_OPEN]) { @@ -2211,7 +2211,7 @@ void ShowFrontierManiacMessage(void) winStreak = gSaveBlock2Ptr->frontier.arenaWinStreaks[FRONTIER_LVL_OPEN]; } break; - case FRONTIER_MANIAC_BATTLE_PIKE: + case FRONTIER_MANIAC_PIKE: if (gSaveBlock2Ptr->frontier.pikeWinStreaks[FRONTIER_LVL_50] >= gSaveBlock2Ptr->frontier.pikeWinStreaks[FRONTIER_LVL_OPEN]) { @@ -2222,7 +2222,7 @@ void ShowFrontierManiacMessage(void) winStreak = gSaveBlock2Ptr->frontier.pikeWinStreaks[FRONTIER_LVL_OPEN]; } break; - case FRONTIER_MANIAC_BATTLE_PYRAMID: + case FRONTIER_MANIAC_PYRAMID: if (gSaveBlock2Ptr->frontier.pyramidWinStreaks[FRONTIER_LVL_50] >= gSaveBlock2Ptr->frontier.pyramidWinStreaks[FRONTIER_LVL_OPEN]) { diff --git a/src/frontier_util.c b/src/frontier_util.c index 352c14b01..bb758de4b 100644 --- a/src/frontier_util.c +++ b/src/frontier_util.c @@ -683,16 +683,16 @@ const u16 gFrontierBannedSpecies[] = static const u8 *const sRecordsWindowChallengeTexts[][2] = { - [RANKING_HALL_BATTLE_TOWER_SINGLES] = {gText_BattleTower2, gText_FacilitySingle}, - [RANKING_HALL_BATTLE_TOWER_DOUBLES] = {gText_BattleTower2, gText_FacilityDouble}, - [RANKING_HALL_BATTLE_TOWER_MULTIS] = {gText_BattleTower2, gText_FacilityMulti}, - [RANKING_HALL_BATTLE_DOME] = {gText_BattleDome, gText_FacilitySingle}, - [RANKING_HALL_BATTLE_PALACE] = {gText_BattlePalace, gText_FacilitySingle}, - [RANKING_HALL_BATTLE_ARENA] = {gText_BattleArena, gText_Facility}, - [RANKING_HALL_BATTLE_FACTORY] = {gText_BattleFactory, gText_FacilitySingle}, - [RANKING_HALL_BATTLE_PIKE] = {gText_BattlePike, gText_Facility}, - [RANKING_HALL_BATTLE_PYRAMID] = {gText_BattlePyramid, gText_Facility}, - [RANKING_HALL_BATTLE_TOWER_LINK] = {gText_BattleTower2, gText_FacilityLink}, + [RANKING_HALL_TOWER_SINGLES] = {gText_BattleTower2, gText_FacilitySingle}, + [RANKING_HALL_TOWER_DOUBLES] = {gText_BattleTower2, gText_FacilityDouble}, + [RANKING_HALL_TOWER_MULTIS] = {gText_BattleTower2, gText_FacilityMulti}, + [RANKING_HALL_DOME] = {gText_BattleDome, gText_FacilitySingle}, + [RANKING_HALL_PALACE] = {gText_BattlePalace, gText_FacilitySingle}, + [RANKING_HALL_ARENA] = {gText_BattleArena, gText_Facility}, + [RANKING_HALL_FACTORY] = {gText_BattleFactory, gText_FacilitySingle}, + [RANKING_HALL_PIKE] = {gText_BattlePike, gText_Facility}, + [RANKING_HALL_PYRAMID] = {gText_BattlePyramid, gText_Facility}, + [RANKING_HALL_TOWER_LINK] = {gText_BattleTower2, gText_FacilityLink}, }; static const u8 *const sLevelModeText[] = @@ -703,16 +703,16 @@ static const u8 *const sLevelModeText[] = static const u8 *const sHallFacilityToRecordsText[] = { - [RANKING_HALL_BATTLE_TOWER_SINGLES] = gText_FrontierFacilityWinStreak, - [RANKING_HALL_BATTLE_TOWER_DOUBLES] = gText_FrontierFacilityWinStreak, - [RANKING_HALL_BATTLE_TOWER_MULTIS] = gText_FrontierFacilityWinStreak, - [RANKING_HALL_BATTLE_DOME] = gText_FrontierFacilityClearStreak, - [RANKING_HALL_BATTLE_PALACE] = gText_FrontierFacilityWinStreak, - [RANKING_HALL_BATTLE_ARENA] = gText_FrontierFacilityKOsStreak, - [RANKING_HALL_BATTLE_FACTORY] = gText_FrontierFacilityWinStreak, - [RANKING_HALL_BATTLE_PIKE] = gText_FrontierFacilityRoomsCleared, - [RANKING_HALL_BATTLE_PYRAMID] = gText_FrontierFacilityFloorsCleared, - [RANKING_HALL_BATTLE_TOWER_LINK] = gText_FrontierFacilityWinStreak, + [RANKING_HALL_TOWER_SINGLES] = gText_FrontierFacilityWinStreak, + [RANKING_HALL_TOWER_DOUBLES] = gText_FrontierFacilityWinStreak, + [RANKING_HALL_TOWER_MULTIS] = gText_FrontierFacilityWinStreak, + [RANKING_HALL_DOME] = gText_FrontierFacilityClearStreak, + [RANKING_HALL_PALACE] = gText_FrontierFacilityWinStreak, + [RANKING_HALL_ARENA] = gText_FrontierFacilityKOsStreak, + [RANKING_HALL_FACTORY] = gText_FrontierFacilityWinStreak, + [RANKING_HALL_PIKE] = gText_FrontierFacilityRoomsCleared, + [RANKING_HALL_PYRAMID] = gText_FrontierFacilityFloorsCleared, + [RANKING_HALL_TOWER_LINK] = gText_FrontierFacilityWinStreak, }; static const u16 sFrontierBrainTrainerIds[NUM_FRONTIER_FACILITIES] = @@ -2261,28 +2261,28 @@ static void Print2PRecord(s32 position, s32 x, s32 y, struct RankingHall2P *hall if (winStreak > MAX_STREAK) winStreak = MAX_STREAK; ConvertIntToDecimalStringN(gStringVar2, winStreak, STR_CONV_MODE_RIGHT_ALIGN, 4); - StringExpandPlaceholders(gStringVar4, sHallFacilityToRecordsText[RANKING_HALL_BATTLE_TOWER_LINK]); - AddTextPrinterParameterized(gRecordsWindowId, 1, gStringVar4, GetStringRightAlignXOffset(1, sHallFacilityToRecordsText[RANKING_HALL_BATTLE_TOWER_LINK], 0xC8), (8 * (y + 5 * position)) + 1, TEXT_SPEED_FF, NULL); + StringExpandPlaceholders(gStringVar4, sHallFacilityToRecordsText[RANKING_HALL_TOWER_LINK]); + AddTextPrinterParameterized(gRecordsWindowId, 1, gStringVar4, GetStringRightAlignXOffset(1, sHallFacilityToRecordsText[RANKING_HALL_TOWER_LINK], 0xC8), (8 * (y + 5 * position)) + 1, TEXT_SPEED_FF, NULL); } } static void Fill1PRecords(struct RankingHall1P *dst, s32 hallFacilityId, s32 lvlMode) { s32 i, j; - struct RankingHall1P record1P[4]; + struct RankingHall1P record1P[HALL_RECORDS_COUNT + 1]; struct PlayerHallRecords *playerHallRecords = calloc(1, sizeof(struct PlayerHallRecords)); GetPlayerHallRecords(playerHallRecords); - for (i = 0; i < 3; i++) + for (i = 0; i < HALL_RECORDS_COUNT; i++) record1P[i] = gSaveBlock2Ptr->hallRecords1P[hallFacilityId][lvlMode][i]; - record1P[3] = playerHallRecords->onePlayer[hallFacilityId][lvlMode]; + record1P[HALL_RECORDS_COUNT] = playerHallRecords->onePlayer[hallFacilityId][lvlMode]; - for (i = 0; i < 3; i++) + for (i = 0; i < HALL_RECORDS_COUNT; i++) { s32 highestWinStreak = 0; s32 highestId = 0; - for (j = 0; j < 4; j++) + for (j = 0; j < HALL_RECORDS_COUNT + 1; j++) { if (record1P[j].winStreak > highestWinStreak) { @@ -2290,8 +2290,8 @@ static void Fill1PRecords(struct RankingHall1P *dst, s32 hallFacilityId, s32 lvl highestWinStreak = record1P[j].winStreak; } } - if (record1P[3].winStreak >= highestWinStreak) - highestId = 3; + if (record1P[HALL_RECORDS_COUNT].winStreak >= highestWinStreak) + highestId = HALL_RECORDS_COUNT; dst[i] = record1P[highestId]; record1P[highestId].winStreak = 0; @@ -2346,7 +2346,7 @@ static void PrintHallRecords(s32 hallFacilityId, s32 lvlMode) AddTextPrinterParameterized(gRecordsWindowId, 1, gStringVar4, 0, 1, TEXT_SPEED_FF, NULL); x = GetStringRightAlignXOffset(1, sLevelModeText[lvlMode], 0xD0); AddTextPrinterParameterized(gRecordsWindowId, 1, sLevelModeText[lvlMode], x, 1, TEXT_SPEED_FF, NULL); - if (hallFacilityId == RANKING_HALL_BATTLE_TOWER_LINK) + if (hallFacilityId == RANKING_HALL_TOWER_LINK) { gSaveBlock2Ptr->frontier.opponentNames[0][PLAYER_NAME_LENGTH] = EOS; gSaveBlock2Ptr->frontier.opponentNames[1][PLAYER_NAME_LENGTH] = EOS; @@ -2393,9 +2393,9 @@ void ClearRankingHallRecords(void) for (i = 0; i < HALL_FACILITIES_COUNT; i++) { - for (j = 0; j < 2; j++) + for (j = 0; j < FRONTIER_LVL_MODE_COUNT; j++) { - for (k = 0; k < 3; k++) + for (k = 0; k < HALL_RECORDS_COUNT; k++) { CopyTrainerId(gSaveBlock2Ptr->hallRecords1P[i][j][k].id, ZERO); gSaveBlock2Ptr->hallRecords1P[i][j][k].name[0] = EOS; @@ -2404,9 +2404,9 @@ void ClearRankingHallRecords(void) } } - for (j = 0; j < 2; j++) + for (j = 0; j < FRONTIER_LVL_MODE_COUNT; j++) { - for (k = 0; k < 3; k++) + for (k = 0; k < HALL_RECORDS_COUNT; k++) { CopyTrainerId(gSaveBlock2Ptr->hallRecords2P[j][k].id1, ZERO); CopyTrainerId(gSaveBlock2Ptr->hallRecords2P[j][k].id2, ZERO); diff --git a/src/item_use.c b/src/item_use.c index 0a3181608..4525cd7f9 100755 --- a/src/item_use.c +++ b/src/item_use.c @@ -182,7 +182,7 @@ u8 CheckIfItemIsTMHMOrEvolutionStone(u16 itemId) // Mail in the bag menu can't have a message but it can be checked (view the mail background, no message) static void CB2_CheckMail(void) { - struct MailStruct mail; + struct Mail mail; mail.itemId = gSpecialVar_ItemId; ReadMail(&mail, CB2_ReturnToBagMenuPocket, 0); } diff --git a/src/load_save.c b/src/load_save.c index 0112f2a8f..1ba5a1600 100644 --- a/src/load_save.c +++ b/src/load_save.c @@ -25,7 +25,7 @@ struct LoadedSaveData /*0x00F0*/ struct ItemSlot pokeBalls[BAG_POKEBALLS_COUNT]; /*0x0130*/ struct ItemSlot TMsHMs[BAG_TMHM_COUNT]; /*0x0230*/ struct ItemSlot berries[BAG_BERRIES_COUNT]; - /*0x02E8*/ struct MailStruct mail[MAIL_COUNT]; + /*0x02E8*/ struct Mail mail[MAIL_COUNT]; }; // EWRAM DATA diff --git a/src/mail.c b/src/mail.c index 50ff553aa..8bb6f6991 100644 --- a/src/mail.c +++ b/src/mail.c @@ -61,7 +61,7 @@ struct MailRead /*0x0200*/ u8 playerName[12]; /*0x020C*/ MainCallback exitCallback; /*0x0210*/ MainCallback callback; - /*0x0214*/ struct MailStruct *mail; + /*0x0214*/ struct Mail *mail; /*0x0218*/ bool8 hasText; /*0x0219*/ u8 signatureWidth; /*0x021a*/ u8 mailType; @@ -443,7 +443,7 @@ static const struct MailLayout sMailLayouts_Tall[] = { }, }; -void ReadMail(struct MailStruct *mail, void (*exitCallback)(void), bool8 hasText) +void ReadMail(struct Mail *mail, void (*exitCallback)(void), bool8 hasText) { u16 buffer[2]; u16 species; diff --git a/src/mail_data.c b/src/mail_data.c index 2ae9bedab..683bd854e 100644 --- a/src/mail_data.c +++ b/src/mail_data.c @@ -7,15 +7,17 @@ #include "international_string_util.h" #include "constants/easy_chat.h" -void ClearMailData(void) +#define UNOWN_OFFSET 30000 + +void ClearAllMail(void) { u8 i; for (i = 0; i < MAIL_COUNT; i++) - ClearMailStruct(&gSaveBlock1Ptr->mail[i]); + ClearMail(&gSaveBlock1Ptr->mail[i]); } -void ClearMailStruct(struct MailStruct *mail) +void ClearMail(struct Mail *mail) { s32 i; @@ -41,7 +43,7 @@ bool8 MonHasMail(struct Pokemon *mon) return FALSE; } -u8 GiveMailToMon(struct Pokemon *mon, u16 itemId) +u8 GiveMailToMonByItemId(struct Pokemon *mon, u16 itemId) { u8 heldItem[2]; u8 id, i; @@ -83,7 +85,7 @@ u16 SpeciesToMailSpecies(u16 species, u32 personality) { if (species == SPECIES_UNOWN) { - u32 species = GetUnownLetterByPersonality(personality) + 30000; + u32 species = GetUnownLetterByPersonality(personality) + UNOWN_OFFSET; return species; } @@ -94,10 +96,10 @@ u16 MailSpeciesToSpecies(u16 mailSpecies, u16 *buffer) { u16 result; - if (mailSpecies >= 30000 && mailSpecies < (30000 + NUM_UNOWN_FORMS)) + if (mailSpecies >= UNOWN_OFFSET && mailSpecies < UNOWN_OFFSET + NUM_UNOWN_FORMS) { result = SPECIES_UNOWN; - *buffer = mailSpecies - 30000; + *buffer = mailSpecies - UNOWN_OFFSET; } else { @@ -107,11 +109,11 @@ u16 MailSpeciesToSpecies(u16 mailSpecies, u16 *buffer) return result; } -u8 GiveMailToMon2(struct Pokemon *mon, struct MailStruct *mail) +u8 GiveMailToMon(struct Pokemon *mon, struct Mail *mail) { u8 heldItem[2]; u16 itemId = mail->itemId; - u8 mailId = GiveMailToMon(mon, itemId); + u8 mailId = GiveMailToMonByItemId(mon, itemId); if (mailId == MAIL_NONE) return MAIL_NONE; @@ -169,7 +171,7 @@ u8 TakeMailFromMon2(struct Pokemon *mon) { if (gSaveBlock1Ptr->mail[i].itemId == ITEM_NONE) { - memcpy(&gSaveBlock1Ptr->mail[i], &gSaveBlock1Ptr->mail[GetMonData(mon, MON_DATA_MAIL)], sizeof(struct MailStruct)); + memcpy(&gSaveBlock1Ptr->mail[i], &gSaveBlock1Ptr->mail[GetMonData(mon, MON_DATA_MAIL)], sizeof(struct Mail)); gSaveBlock1Ptr->mail[GetMonData(mon, MON_DATA_MAIL)].itemId = ITEM_NONE; SetMonData(mon, MON_DATA_MAIL, &newMailId); SetMonData(mon, MON_DATA_HELD_ITEM, newHeldItem); diff --git a/src/match_call.c b/src/match_call.c index b71fc8322..df6b08725 100644 --- a/src/match_call.c +++ b/src/match_call.c @@ -1902,7 +1902,7 @@ static u16 GetFrontierStreakInfo(u16 facilityId, u32 *topicTextId) case FRONTIER_FACILITY_DOME: for (i = 0; i < 2; i++) { - for (j = 0; j < 2; j++) + for (j = 0; j < FRONTIER_LVL_MODE_COUNT; j++) { if (streak < gSaveBlock2Ptr->frontier.domeRecordWinStreaks[i][j]) streak = gSaveBlock2Ptr->frontier.domeRecordWinStreaks[i][j]; @@ -1915,7 +1915,7 @@ static u16 GetFrontierStreakInfo(u16 facilityId, u32 *topicTextId) #else case FRONTIER_FACILITY_FACTORY: #endif - for (i = 0; i < 2; i++) + for (i = 0; i < FRONTIER_LVL_MODE_COUNT; i++) { if (streak < gSaveBlock2Ptr->frontier.pikeRecordStreaks[i]) streak = gSaveBlock2Ptr->frontier.pikeRecordStreaks[i]; @@ -1925,7 +1925,7 @@ static u16 GetFrontierStreakInfo(u16 facilityId, u32 *topicTextId) case FRONTIER_FACILITY_TOWER: for (i = 0; i < 4; i++) { - for (j = 0; j < 2; j++) + for (j = 0; j < FRONTIER_LVL_MODE_COUNT; j++) { if (streak < gSaveBlock2Ptr->frontier.towerRecordWinStreaks[i][j]) streak = gSaveBlock2Ptr->frontier.towerRecordWinStreaks[i][j]; @@ -1936,7 +1936,7 @@ static u16 GetFrontierStreakInfo(u16 facilityId, u32 *topicTextId) case FRONTIER_FACILITY_PALACE: for (i = 0; i < 2; i++) { - for (j = 0; j < 2; j++) + for (j = 0; j < FRONTIER_LVL_MODE_COUNT; j++) { if (streak < gSaveBlock2Ptr->frontier.palaceRecordWinStreaks[i][j]) streak = gSaveBlock2Ptr->frontier.palaceRecordWinStreaks[i][j]; @@ -1951,7 +1951,7 @@ static u16 GetFrontierStreakInfo(u16 facilityId, u32 *topicTextId) #endif for (i = 0; i < 2; i++) { - for (j = 0; j < 2; j++) + for (j = 0; j < FRONTIER_LVL_MODE_COUNT; j++) { if (streak < gSaveBlock2Ptr->frontier.factoryRecordWinStreaks[i][j]) streak = gSaveBlock2Ptr->frontier.factoryRecordWinStreaks[i][j]; @@ -1960,7 +1960,7 @@ static u16 GetFrontierStreakInfo(u16 facilityId, u32 *topicTextId) *topicTextId = GEN_TOPIC_STREAK_RECORD - 1; break; case FRONTIER_FACILITY_ARENA: - for (i = 0; i < 2; i++) + for (i = 0; i < FRONTIER_LVL_MODE_COUNT; i++) { if (streak < gSaveBlock2Ptr->frontier.arenaRecordStreaks[i]) streak = gSaveBlock2Ptr->frontier.arenaRecordStreaks[i]; @@ -1968,7 +1968,7 @@ static u16 GetFrontierStreakInfo(u16 facilityId, u32 *topicTextId) *topicTextId = GEN_TOPIC_STREAK_RECORD - 1; break; case FRONTIER_FACILITY_PYRAMID: - for (i = 0; i < 2; i++) + for (i = 0; i < FRONTIER_LVL_MODE_COUNT; i++) { if (streak < gSaveBlock2Ptr->frontier.pyramidRecordStreaks[i]) streak = gSaveBlock2Ptr->frontier.pyramidRecordStreaks[i]; diff --git a/src/mystery_event_script.c b/src/mystery_event_script.c index 176eab7fc..f590bcde6 100644 --- a/src/mystery_event_script.c +++ b/src/mystery_event_script.c @@ -302,7 +302,7 @@ bool8 MEScrCmd_setrecordmixinggift(struct ScriptContext *ctx) bool8 MEScrCmd_givepokemon(struct ScriptContext *ctx) { - struct MailStruct mail; + struct Mail mail; struct Pokemon pokemon; u16 species; u16 heldItem; @@ -326,7 +326,7 @@ bool8 MEScrCmd_givepokemon(struct ScriptContext *ctx) else { memcpy(&gPlayerParty[PARTY_SIZE - 1], pokemonPtr, sizeof(struct Pokemon)); - memcpy(&mail, mailPtr, sizeof(struct MailStruct)); + memcpy(&mail, mailPtr, sizeof(struct Mail)); if (species != SPECIES_EGG) { @@ -337,7 +337,7 @@ bool8 MEScrCmd_givepokemon(struct ScriptContext *ctx) heldItem = GetMonData(&gPlayerParty[PARTY_SIZE - 1], MON_DATA_HELD_ITEM); if (ItemIsMail(heldItem)) - GiveMailToMon2(&gPlayerParty[PARTY_SIZE - 1], &mail); + GiveMailToMon(&gPlayerParty[PARTY_SIZE - 1], &mail); CompactPartySlots(); CalculatePlayerPartyCount(); StringExpandPlaceholders(gStringVar4, gText_MysteryGiftSentOver); diff --git a/src/new_game.c b/src/new_game.c index 2a950efbc..5bb3d44c5 100644 --- a/src/new_game.c +++ b/src/new_game.c @@ -158,7 +158,7 @@ void NewGameInitData(void) ResetPokedex(); ClearFrontierRecord(); ClearSav1(); - ClearMailData(); + ClearAllMail(); gSaveBlock2Ptr->specialSaveWarpFlags = 0; gSaveBlock2Ptr->gcnLinkFlags = 0; InitPlayerTrainerId(); diff --git a/src/party_menu.c b/src/party_menu.c index 9829d62e9..95a4852db 100755 --- a/src/party_menu.c +++ b/src/party_menu.c @@ -1726,7 +1726,7 @@ static void GiveItemToMon(struct Pokemon *mon, u16 item) if (ItemIsMail(item) == TRUE) { - if (GiveMailToMon(mon, item) == 0xFF) + if (GiveMailToMonByItemId(mon, item) == MAIL_NONE) return; } itemBytes[0] = item; @@ -5468,7 +5468,7 @@ void ChooseMonToGiveMailFromMailbox(void) static void TryGiveMailToSelectedMon(u8 taskId) { struct Pokemon *mon = &gPlayerParty[gPartyMenu.slotId]; - struct MailStruct *mail; + struct Mail *mail; gPartyMenuUseExitCallback = FALSE; mail = &gSaveBlock1Ptr->mail[gPlayerPCItemPageInfo.itemsAbove + PARTY_SIZE + gPlayerPCItemPageInfo.cursorPos]; @@ -5478,8 +5478,8 @@ static void TryGiveMailToSelectedMon(u8 taskId) } else { - GiveMailToMon2(mon, mail); - ClearMailStruct(mail); + GiveMailToMon(mon, mail); + ClearMail(mail); DisplayPartyMenuMessage(gText_MailTransferredFromMailbox, TRUE); } ScheduleBgCopyTilemapToVram(2); diff --git a/src/player_pc.c b/src/player_pc.c index 507fc6558..a4e7505b4 100644 --- a/src/player_pc.c +++ b/src/player_pc.c @@ -674,7 +674,7 @@ static u8 GetMailboxMailCount(void) static void Mailbox_CompactMailList(void) { - struct MailStruct temp; + struct Mail temp; u8 i, j; for (i = PARTY_SIZE; i < MAIL_COUNT - 1; i++) @@ -850,7 +850,7 @@ static void Mailbox_HandleConfirmMoveToBag(u8 taskId) static void Mailbox_DoMailMoveToBag(u8 taskId) { - struct MailStruct *mail = &gSaveBlock1Ptr->mail[gPlayerPCItemPageInfo.itemsAbove + PARTY_SIZE + gPlayerPCItemPageInfo.cursorPos]; + struct Mail *mail = &gSaveBlock1Ptr->mail[gPlayerPCItemPageInfo.itemsAbove + PARTY_SIZE + gPlayerPCItemPageInfo.cursorPos]; if (!AddBagItem(mail->itemId, 1)) { DisplayItemMessageOnField(taskId, gText_BagIsFull, Mailbox_Cancel); @@ -858,7 +858,7 @@ static void Mailbox_DoMailMoveToBag(u8 taskId) else { DisplayItemMessageOnField(taskId, gText_MailToBagMessageErased, Mailbox_Cancel); - ClearMailStruct(mail); + ClearMail(mail); Mailbox_CompactMailList(); gPlayerPCItemPageInfo.count--; if (gPlayerPCItemPageInfo.count < (gPlayerPCItemPageInfo.pageItems + gPlayerPCItemPageInfo.itemsAbove) && gPlayerPCItemPageInfo.itemsAbove != 0) diff --git a/src/record_mixing.c b/src/record_mixing.c index ad97b6af5..fe51667f4 100644 --- a/src/record_mixing.c +++ b/src/record_mixing.c @@ -35,16 +35,21 @@ #include "constants/battle_frontier.h" #include "dewford_trend.h" +// Number of bytes of the record transferred at a time +#define BUFFER_CHUNK_SIZE 200 -// Static type declarations +#define NUM_SWAP_COMBOS 3 + +// Used by several tasks in this file +#define tState data[0] struct RecordMixingHallRecords { - struct RankingHall1P hallRecords1P[HALL_FACILITIES_COUNT][2][6]; - struct RankingHall2P hallRecords2P[2][6]; + struct RankingHall1P hallRecords1P[HALL_FACILITIES_COUNT][FRONTIER_LVL_MODE_COUNT][HALL_RECORDS_COUNT * 2]; + struct RankingHall2P hallRecords2P[FRONTIER_LVL_MODE_COUNT][HALL_RECORDS_COUNT * 2]; }; -struct PlayerRecordsRS +struct PlayerRecordRS { struct SecretBase secretBases[SECRET_BASES_COUNT]; TVShow tvShows[TV_SHOWS_COUNT]; @@ -54,10 +59,10 @@ struct PlayerRecordsRS struct RecordMixingDaycareMail daycareMail; struct RSBattleTowerRecord battleTowerRecord; u16 giftItem; - u16 filler11C8[0x32]; + u16 padding[50]; }; -struct PlayerRecordsEmerald +struct PlayerRecordEmerald { /* 0x0000 */ struct SecretBase secretBases[SECRET_BASES_COUNT]; /* 0x0c80 */ TVShow tvShows[TV_SHOWS_COUNT]; @@ -70,73 +75,67 @@ struct PlayerRecordsEmerald /* 0x1214 */ LilycoveLady lilycoveLady; /* 0x1254 */ struct Apprentice apprentices[2]; /* 0x12dc */ struct PlayerHallRecords hallRecords; - /* 0x1434 */ u8 field_1434[0x10]; + /* 0x1434 */ u8 padding[16]; }; // 0x1444 -union PlayerRecords +union PlayerRecord { - struct PlayerRecordsRS ruby; - struct PlayerRecordsEmerald emerald; + struct PlayerRecordRS ruby; + struct PlayerRecordEmerald emerald; }; -// Static RAM declarations - -static bool8 gUnknown_03001130; +static bool8 sReadyToReceive; static struct SecretBase *sSecretBasesSave; static TVShow *sTvShowsSave; static PokeNews *sPokeNewsSave; static OldMan *sOldManSave; static struct DewfordTrend *sDewfordTrendsSave; -static struct RecordMixingDaycareMail *sDaycareMailSave; +static struct RecordMixingDaycareMail *sRecordMixMailSave; static void *sBattleTowerSave; static LilycoveLady *sLilycoveLadySave; static void *sApprenticesSave; static void *sBattleTowerSave_Duplicate; static u32 sRecordStructSize; -static u8 gUnknown_03001160; +static u8 sDaycareMailRandSum; static struct PlayerHallRecords *gUnknown_03001168[3]; -static EWRAM_DATA struct RecordMixingDaycareMail sDaycareMail = {0}; -static EWRAM_DATA union PlayerRecords *sReceivedRecords = NULL; -static EWRAM_DATA union PlayerRecords *sSentRecord = NULL; +static EWRAM_DATA struct RecordMixingDaycareMail sRecordMixMail = {0}; +static EWRAM_DATA union PlayerRecord *sReceivedRecords = NULL; +static EWRAM_DATA union PlayerRecord *sSentRecord = NULL; -// Static ROM declarations - -static void Task_RecordMixing_Main(u8 taskId); -static void Task_MixingRecordsRecv(u8 taskId); -static void Task_SendPacket(u8 taskId); -static void Task_CopyReceiveBuffer(u8 taskId); -static void Task_SendPacket_SwitchToReceive(u8 taskId); -static void *LoadPtrFromTaskData(const u16 *asShort); -static void StorePtrInTaskData(void *records, u16 *a1); +static void Task_RecordMixing_Main(u8); +static void Task_MixingRecordsRecv(u8); +static void Task_SendPacket(u8); +static void Task_CopyReceiveBuffer(u8); +static void Task_SendPacket_SwitchToReceive(u8); +static void *LoadPtrFromTaskData(const u16 *); +static void StorePtrInTaskData(void *, u16 *); static u8 GetMultiplayerId_(void); static void *GetPlayerRecvBuffer(u8); static void ReceiveOldManData(OldMan *, size_t, u8); -static void ReceiveBattleTowerData(void *battleTowerRecord, size_t, u8); +static void ReceiveBattleTowerData(void *, size_t, u8); static void ReceiveLilycoveLadyData(LilycoveLady *, size_t, u8); -static void sub_80E7B2C(const u8 *); +static void CalculateDaycareMailRandSum(const u8 *); static void ReceiveDaycareMailData(struct RecordMixingDaycareMail *, size_t, u8, TVShow *); -static void ReceiveGiftItem(u16 *item, u8 which); -static void Task_DoRecordMixing(u8 taskId); -static void GetSavedApprentices(struct Apprentice *dst, struct Apprentice *src); -static void ReceiveApprenticeData(struct Apprentice *mixApprentice, size_t recordSize, u32 multiplayerId); -static void ReceiveRankingHallRecords(struct PlayerHallRecords *hallRecords, size_t arg1, u32 arg2); -static void GetRecordMixingDaycareMail(struct RecordMixingDaycareMail *dst); -static void SanitizeDaycareMailForRuby(struct RecordMixingDaycareMail *src); -static void SanitizeEmeraldBattleTowerRecord(struct EmeraldBattleTowerRecord *arg0); -static void SanitizeRubyBattleTowerRecord(struct RSBattleTowerRecord *src); +static void ReceiveGiftItem(u16 *, u8 ); +static void Task_DoRecordMixing(u8); +static void GetSavedApprentices(struct Apprentice *, struct Apprentice *); +static void ReceiveApprenticeData(struct Apprentice *, size_t, u32); +static void ReceiveRankingHallRecords(struct PlayerHallRecords *, size_t, u32); +static void GetRecordMixingDaycareMail(struct RecordMixingDaycareMail *); +static void SanitizeDaycareMailForRuby(struct RecordMixingDaycareMail *); +static void SanitizeEmeraldBattleTowerRecord(struct EmeraldBattleTowerRecord *); +static void SanitizeRubyBattleTowerRecord(struct RSBattleTowerRecord *); -// .rodata +static const u8 sPlayerIdxOrders_2Player[] = {1, 0}; -static const u8 gUnknown_0858CF8C[] = {1, 0}; - -static const u8 gUnknown_0858CF8E[][3] = +static const u8 sPlayerIdxOrders_3Player[][3] = { {1, 2, 0}, {2, 0, 1}, }; -static const u8 gUnknown_0858CF94[][4] = +static const u8 sPlayerIdxOrders_4Player[][4] = { {1, 0, 3, 2}, {3, 0, 1, 2}, @@ -149,24 +148,21 @@ static const u8 gUnknown_0858CF94[][4] = {3, 2, 1, 0}, }; -static const u8 gUnknown_0858CFB8[3][2] = +// When 3 players can swap mail 2 players are randomly selected and the 3rd is left out +static const u8 sDaycareMailSwapIds_3Player[NUM_SWAP_COMBOS][2] = { {0, 1}, {1, 2}, {2, 0}, }; -static const u8 gUnknown_0858CFBE[3][4] = +static const u8 sDaycareMailSwapIds_4Player[NUM_SWAP_COMBOS][4] = { - {0, 1, 2, 3}, - {0, 2, 1, 3}, - {0, 3, 2, 1}, + {0, 1, 2, 3}, // 0 swaps with 1, 2 swaps with 3 + {0, 2, 1, 3}, + {0, 3, 2, 1}, }; -// .text - -#define BUFFER_CHUNK_SIZE 200 - void RecordMixingPlayerSpotTriggered(void) { CreateTask_EnterCableClubSeat(Task_RecordMixing_Main); @@ -180,14 +176,14 @@ static void SetSrcLookupPointers(void) sPokeNewsSave = gSaveBlock1Ptr->pokeNews; sOldManSave = &gSaveBlock1Ptr->oldMan; sDewfordTrendsSave = gSaveBlock1Ptr->dewfordTrends; - sDaycareMailSave = &sDaycareMail; + sRecordMixMailSave = &sRecordMixMail; sBattleTowerSave = &gSaveBlock2Ptr->frontier.towerPlayer; sLilycoveLadySave = &gSaveBlock1Ptr->lilycoveLady; sApprenticesSave = gSaveBlock2Ptr->apprentices; sBattleTowerSave_Duplicate = &gSaveBlock2Ptr->frontier.towerPlayer; } -static void PrepareUnknownExchangePacket(struct PlayerRecordsRS *dest) +static void PrepareUnknownExchangePacket(struct PlayerRecordRS *dest) { memcpy(dest->secretBases, sSecretBasesSave, sizeof(dest->secretBases)); memcpy(dest->tvShows, sTvShowsSave, sizeof(dest->tvShows)); @@ -202,7 +198,7 @@ static void PrepareUnknownExchangePacket(struct PlayerRecordsRS *dest) dest->giftItem = GetRecordMixingGift(); } -static void PrepareExchangePacketForRubySapphire(struct PlayerRecordsRS *dest) +static void PrepareExchangePacketForRubySapphire(struct PlayerRecordRS *dest) { memcpy(dest->secretBases, sSecretBasesSave, sizeof(dest->secretBases)); ClearJapaneseSecretBases(dest->secretBases); @@ -254,36 +250,36 @@ static void PrepareExchangePacket(void) } } -static void ReceiveExchangePacket(u32 which) +static void ReceiveExchangePacket(u32 multiplayerId) { if (Link_AnyPartnersPlayingRubyOrSapphire()) { // Ruby/Sapphire - sub_80E7B2C((void *)sReceivedRecords->ruby.tvShows); - ReceiveSecretBasesData(sReceivedRecords->ruby.secretBases, sizeof(struct PlayerRecordsRS), which); - ReceiveDaycareMailData(&sReceivedRecords->ruby.daycareMail, sizeof(struct PlayerRecordsRS), which, sReceivedRecords->ruby.tvShows); - ReceiveBattleTowerData(&sReceivedRecords->ruby.battleTowerRecord, sizeof(struct PlayerRecordsRS), which); - ReceiveTvShowsData(sReceivedRecords->ruby.tvShows, sizeof(struct PlayerRecordsRS), which); - ReceivePokeNewsData(sReceivedRecords->ruby.pokeNews, sizeof(struct PlayerRecordsRS), which); - ReceiveOldManData(&sReceivedRecords->ruby.oldMan, sizeof(struct PlayerRecordsRS), which); - ReceiveDewfordTrendData(sReceivedRecords->ruby.dewfordTrends, sizeof(struct PlayerRecordsRS), which); - ReceiveGiftItem(&sReceivedRecords->ruby.giftItem, which); + CalculateDaycareMailRandSum((void *)sReceivedRecords->ruby.tvShows); + ReceiveSecretBasesData(sReceivedRecords->ruby.secretBases, sizeof(sReceivedRecords->ruby), multiplayerId); + ReceiveDaycareMailData(&sReceivedRecords->ruby.daycareMail, sizeof(sReceivedRecords->ruby), multiplayerId, sReceivedRecords->ruby.tvShows); + ReceiveBattleTowerData(&sReceivedRecords->ruby.battleTowerRecord, sizeof(sReceivedRecords->ruby), multiplayerId); + ReceiveTvShowsData(sReceivedRecords->ruby.tvShows, sizeof(sReceivedRecords->ruby), multiplayerId); + ReceivePokeNewsData(sReceivedRecords->ruby.pokeNews, sizeof(sReceivedRecords->ruby), multiplayerId); + ReceiveOldManData(&sReceivedRecords->ruby.oldMan, sizeof(sReceivedRecords->ruby), multiplayerId); + ReceiveDewfordTrendData(sReceivedRecords->ruby.dewfordTrends, sizeof(sReceivedRecords->ruby), multiplayerId); + ReceiveGiftItem(&sReceivedRecords->ruby.giftItem, multiplayerId); } else { // Emerald - sub_80E7B2C((void *)sReceivedRecords->emerald.tvShows); - ReceiveSecretBasesData(sReceivedRecords->emerald.secretBases, sizeof(struct PlayerRecordsEmerald), which); - ReceiveTvShowsData(sReceivedRecords->emerald.tvShows, sizeof(struct PlayerRecordsEmerald), which); - ReceivePokeNewsData(sReceivedRecords->emerald.pokeNews, sizeof(struct PlayerRecordsEmerald), which); - ReceiveOldManData(&sReceivedRecords->emerald.oldMan, sizeof(struct PlayerRecordsEmerald), which); - ReceiveDewfordTrendData(sReceivedRecords->emerald.dewfordTrends, sizeof(struct PlayerRecordsEmerald), which); - ReceiveDaycareMailData(&sReceivedRecords->emerald.daycareMail, sizeof(struct PlayerRecordsEmerald), which, sReceivedRecords->emerald.tvShows); - ReceiveBattleTowerData(&sReceivedRecords->emerald.battleTowerRecord, sizeof(struct PlayerRecordsEmerald), which); - ReceiveGiftItem(&sReceivedRecords->emerald.giftItem, which); - ReceiveLilycoveLadyData(&sReceivedRecords->emerald.lilycoveLady, sizeof(struct PlayerRecordsEmerald), which); - ReceiveApprenticeData(sReceivedRecords->emerald.apprentices, sizeof(struct PlayerRecordsEmerald), (u8) which); - ReceiveRankingHallRecords(&sReceivedRecords->emerald.hallRecords, sizeof(struct PlayerRecordsEmerald), (u8) which); + CalculateDaycareMailRandSum((void *)sReceivedRecords->emerald.tvShows); + ReceiveSecretBasesData(sReceivedRecords->emerald.secretBases, sizeof(sReceivedRecords->emerald), multiplayerId); + ReceiveTvShowsData(sReceivedRecords->emerald.tvShows, sizeof(sReceivedRecords->emerald), multiplayerId); + ReceivePokeNewsData(sReceivedRecords->emerald.pokeNews, sizeof(sReceivedRecords->emerald), multiplayerId); + ReceiveOldManData(&sReceivedRecords->emerald.oldMan, sizeof(sReceivedRecords->emerald), multiplayerId); + ReceiveDewfordTrendData(sReceivedRecords->emerald.dewfordTrends, sizeof(sReceivedRecords->emerald), multiplayerId); + ReceiveDaycareMailData(&sReceivedRecords->emerald.daycareMail, sizeof(sReceivedRecords->emerald), multiplayerId, sReceivedRecords->emerald.tvShows); + ReceiveBattleTowerData(&sReceivedRecords->emerald.battleTowerRecord, sizeof(sReceivedRecords->emerald), multiplayerId); + ReceiveGiftItem(&sReceivedRecords->emerald.giftItem, multiplayerId); + ReceiveLilycoveLadyData(&sReceivedRecords->emerald.lilycoveLady, sizeof(sReceivedRecords->emerald), multiplayerId); + ReceiveApprenticeData(sReceivedRecords->emerald.apprentices, sizeof(sReceivedRecords->emerald), (u8) multiplayerId); + ReceiveRankingHallRecords(&sReceivedRecords->emerald.hallRecords, sizeof(sReceivedRecords->emerald), (u8) multiplayerId); } } @@ -307,10 +303,11 @@ static void Task_RecordMixing_SoundEffect(u8 taskId) #undef tCounter -#define tState data[0] -#define tSndEffTaskId data[15] +#define tTimer data[8] +#define tLinkTaskId data[10] +#define tSoundTaskId data[15] -// Note: Currently, special var 8005 contains the player's spot id. +// Note: gSpecialVar_0x8005 here contains the player's spot id. static void Task_RecordMixing_Main(u8 taskId) { s16 *data = gTasks[taskId].data; @@ -318,56 +315,54 @@ static void Task_RecordMixing_Main(u8 taskId) switch (tState) { case 0: // init - sSentRecord = malloc(sizeof(union PlayerRecords)); - sReceivedRecords = malloc(sizeof(union PlayerRecords) * MAX_LINK_PLAYERS); + sSentRecord = malloc(sizeof(*sSentRecord)); + sReceivedRecords = malloc(sizeof(*sReceivedRecords) * MAX_LINK_PLAYERS); SetLocalLinkPlayerId(gSpecialVar_0x8005); VarSet(VAR_TEMP_0, 1); - gUnknown_03001130 = FALSE; + sReadyToReceive = FALSE; PrepareExchangePacket(); CreateRecordMixingLights(); tState = 1; - data[10] = CreateTask(Task_MixingRecordsRecv, 80); - tSndEffTaskId = CreateTask(Task_RecordMixing_SoundEffect, 81); + tLinkTaskId = CreateTask(Task_MixingRecordsRecv, 80); + tSoundTaskId = CreateTask(Task_RecordMixing_SoundEffect, 81); break; case 1: // wait for Task_MixingRecordsRecv - if (!gTasks[data[10]].isActive) + if (!gTasks[tLinkTaskId].isActive) { tState = 2; FlagSet(FLAG_SYS_MIX_RECORD); DestroyRecordMixingLights(); - DestroyTask(tSndEffTaskId); + DestroyTask(tSoundTaskId); } break; case 2: - data[10] = CreateTask(Task_DoRecordMixing, 10); + tLinkTaskId = CreateTask(Task_DoRecordMixing, 10); tState = 3; PlaySE(SE_M_BATON_PASS); break; case 3: // wait for Task_DoRecordMixing - if (!gTasks[data[10]].isActive) + if (!gTasks[tLinkTaskId].isActive) { tState = 4; if (gWirelessCommType == 0) - data[10] = CreateTask_ReestablishCableClubLink(); + tLinkTaskId = CreateTask_ReestablishCableClubLink(); PrintTextOnRecordMixing(gText_RecordMixingComplete); - data[8] = 0; + tTimer = 0; } break; case 4: // wait 60 frames - if (++data[8] > 60) + if (++tTimer > 60) tState = 5; break; - case 5: - if (!gTasks[data[10]].isActive) + case 5: // Wait for the task created by CreateTask_ReestablishCableClubLink + if (!gTasks[tLinkTaskId].isActive) { free(sReceivedRecords); free(sSentRecord); SetLinkWaitingForScript(); if (gWirelessCommType != 0) - { CreateTask(Task_ReturnToFieldRecordMixing, 10); - } ClearDialogWindowAndFrame(0, 1); DestroyTask(taskId); EnableBothScriptContexts(); @@ -376,26 +371,38 @@ static void Task_RecordMixing_Main(u8 taskId) } } -#undef tState -#undef tSndEffTaskId +#undef tTimer +#undef tLinkTaskId +#undef tSoundTaskId + +// Task data for Task_MixingRecordsRecv and subsequent tasks +#define tSentRecord data[2] // Used to store a ptr, so data[2] and data[3] +#define tNumChunksSent data[4] +#define tMultiplayerId data[5] +#define tCopyTaskId data[10] + +// Task data for Task_CopyReceiveBuffer +#define tParentTaskId data[0] +#define tNumChunksRecv(i) data[1 + (i)] // Number of chunks of the record received per player +#define tRecvRecords data[5] // Used to store a ptr, so data[5] and data[6] static void Task_MixingRecordsRecv(u8 taskId) { struct Task *task = &gTasks[taskId]; - switch (task->data[0]) + switch (task->tState) { case 0: PrintTextOnRecordMixing(gText_MixingRecords); task->data[8] = 0x708; - task->data[0] = 400; + task->tState = 400; ClearLinkCallback_2(); break; case 100: // wait 20 frames if (++task->data[12] > 20) { task->data[12] = 0; - task->data[0] = 101; + task->tState = 101; } break; case 101: @@ -406,14 +413,14 @@ static void Task_MixingRecordsRecv(u8 taskId) if (players == GetSavedPlayerCount()) { PlaySE(SE_PIN); - task->data[0] = 201; + task->tState = 201; task->data[12] = 0; } } else { PlaySE(SE_BOO); - task->data[0] = 301; + task->tState = 301; } } break; @@ -422,17 +429,17 @@ static void Task_MixingRecordsRecv(u8 taskId) if (GetSavedPlayerCount() == GetLinkPlayerCount_2() && ++task->data[12] > (GetLinkPlayerCount_2() * 30)) { CheckShouldAdvanceLinkState(); - task->data[0] = 1; + task->tState = 1; } break; case 301: if (GetSavedPlayerCount() == GetLinkPlayerCount_2()) - task->data[0] = 1; + task->tState = 1; break; case 400: // wait 20 frames if (++task->data[12] > 20) { - task->data[0] = 1; + task->tState = 1; task->data[12] = 0; } break; @@ -440,7 +447,7 @@ static void Task_MixingRecordsRecv(u8 taskId) if (gReceivedRemoteLinkPlayers != 0) { ConvertIntToDecimalStringN(gStringVar1, GetMultiplayerId_(), STR_CONV_MODE_LEADING_ZEROS, 2); - task->data[0] = 5; + task->tState = 5; } break; case 2: @@ -448,35 +455,34 @@ static void Task_MixingRecordsRecv(u8 taskId) u8 subTaskId; task->data[6] = GetLinkPlayerCount_2(); - task->data[0] = 0; - task->data[5] = GetMultiplayerId_(); + task->tState = 0; + task->tMultiplayerId = GetMultiplayerId_(); task->func = Task_SendPacket; if (Link_AnyPartnersPlayingRubyOrSapphire()) { - StorePtrInTaskData(sSentRecord, (u16 *)&task->data[2]); + StorePtrInTaskData(sSentRecord, &task->tSentRecord); subTaskId = CreateTask(Task_CopyReceiveBuffer, 80); - task->data[10] = subTaskId; - gTasks[subTaskId].data[0] = taskId; - StorePtrInTaskData(sReceivedRecords, (u16 *)&gTasks[subTaskId].data[5]); - sRecordStructSize = sizeof(struct PlayerRecordsRS); + task->tCopyTaskId = subTaskId; + gTasks[subTaskId].tParentTaskId = taskId; + StorePtrInTaskData(sReceivedRecords, &gTasks[subTaskId].tRecvRecords); + sRecordStructSize = sizeof(struct PlayerRecordRS); } else { - StorePtrInTaskData(sSentRecord, (u16 *)&task->data[2]); + StorePtrInTaskData(sSentRecord, &task->tSentRecord); subTaskId = CreateTask(Task_CopyReceiveBuffer, 80); - task->data[10] = subTaskId; - gTasks[subTaskId].data[0] = taskId; - StorePtrInTaskData(sReceivedRecords, (u16 *)&gTasks[subTaskId].data[5]); - sRecordStructSize = sizeof(struct PlayerRecordsEmerald); + task->tCopyTaskId = subTaskId; + gTasks[subTaskId].tParentTaskId = taskId; + StorePtrInTaskData(sReceivedRecords, &gTasks[subTaskId].tRecvRecords); + sRecordStructSize = sizeof(struct PlayerRecordEmerald); } - // Note: This task is destroyed by Task_CopyReceiveBuffer when it's done. } break; case 5: // wait 60 frames if (++task->data[10] > 60) { task->data[10] = 0; - task->data[0] = 2; + task->tState = 2; } break; } @@ -485,34 +491,34 @@ static void Task_MixingRecordsRecv(u8 taskId) static void Task_SendPacket(u8 taskId) { struct Task *task = &gTasks[taskId]; - // does this send the data 24 times? - - switch (task->data[0]) + switch (task->tState) { - case 0: // Copy record data to send buffer + case 0: // Copy record data chunk to send buffer { - void *recordData = LoadPtrFromTaskData(&task->data[2]) + task->data[4] * BUFFER_CHUNK_SIZE; + void *recordData = LoadPtrFromTaskData(&task->tSentRecord) + task->tNumChunksSent * BUFFER_CHUNK_SIZE; memcpy(gBlockSendBuffer, recordData, BUFFER_CHUNK_SIZE); - task->data[0]++; + task->tState++; } break; case 1: if (GetMultiplayerId() == 0) SendBlockRequest(BLOCK_REQ_SIZE_200); - task->data[0]++; + task->tState++; break; case 2: break; case 3: - task->data[4]++; - if (task->data[4] == sRecordStructSize / 200 + 1) - task->data[0]++; + // If sent final chunk of record, move on to next state. + // Otherwise return to first state and send next chunk. + task->tNumChunksSent++; + if (task->tNumChunksSent == sRecordStructSize / BUFFER_CHUNK_SIZE + 1) + task->tState++; else - task->data[0] = 0; + task->tState = 0; break; case 4: - if (!gTasks[task->data[10]].isActive) + if (!gTasks[task->tCopyTaskId].isActive) task->func = Task_SendPacket_SwitchToReceive; break; } @@ -527,38 +533,35 @@ static void Task_CopyReceiveBuffer(u8 taskId) if (status == GetLinkPlayerCountAsBitFlags()) { u8 i; - for (i = 0; i < GetLinkPlayerCount(); i++) { - void *dest; - void *src; - if ((status >> i) & 1) { - dest = LoadPtrFromTaskData((u16 *)&task->data[5]) + task->data[i + 1] * BUFFER_CHUNK_SIZE + sRecordStructSize * i; - src = GetPlayerRecvBuffer(i); - if ((task->data[i + 1] + 1) * BUFFER_CHUNK_SIZE > sRecordStructSize) - memcpy(dest, src, sRecordStructSize - task->data[i + 1] * BUFFER_CHUNK_SIZE); + void *dest = LoadPtrFromTaskData(&task->tRecvRecords) + task->tNumChunksRecv(i) * BUFFER_CHUNK_SIZE + sRecordStructSize * i; + void *src = GetPlayerRecvBuffer(i); + if ((task->tNumChunksRecv(i) + 1) * BUFFER_CHUNK_SIZE > sRecordStructSize) + memcpy(dest, src, sRecordStructSize - task->tNumChunksRecv(i) * BUFFER_CHUNK_SIZE); else memcpy(dest, src, BUFFER_CHUNK_SIZE); ResetBlockReceivedFlag(i); - task->data[i + 1]++; - if (task->data[i + 1] == sRecordStructSize / BUFFER_CHUNK_SIZE + 1) + task->tNumChunksRecv(i)++; + if (task->tNumChunksRecv(i) == sRecordStructSize / BUFFER_CHUNK_SIZE + 1) handledPlayers++; } } - gTasks[task->data[0]].data[0]++; + gTasks[task->tParentTaskId].tState++; } if (handledPlayers == GetLinkPlayerCount()) DestroyTask(taskId); } -static void sub_80E776C(u8 taskId) +static void Task_WaitReceivePacket(u8 taskId) { struct Task *task = &gTasks[taskId]; - if (!gTasks[task->data[10]].isActive) + // Wait for Task_CopyReceiveBuffer to finish + if (!gTasks[task->tCopyTaskId].isActive) DestroyTask(taskId); } @@ -566,15 +569,15 @@ static void Task_ReceivePacket(u8 taskId) { struct Task *task = &gTasks[taskId]; - task->func = sub_80E776C; - if (gUnknown_03001130 == TRUE) - ReceiveExchangePacket(task->data[5]); + task->func = Task_WaitReceivePacket; + if (sReadyToReceive == TRUE) + ReceiveExchangePacket(task->tMultiplayerId); } static void Task_SendPacket_SwitchToReceive(u8 taskId) { gTasks[taskId].func = Task_ReceivePacket; - gUnknown_03001130 = TRUE; + sReadyToReceive = TRUE; } static void *LoadPtrFromTaskData(const u16 *asShort) @@ -607,46 +610,46 @@ static void ShufflePlayerIndices(u32 *data) switch (players) { case 2: - for (i = 0; i < 2; i++) - data[i] = gUnknown_0858CF8C[i]; + for (i = 0; i < ARRAY_COUNT(sPlayerIdxOrders_2Player); i++) + data[i] = sPlayerIdxOrders_2Player[i]; break; case 3: - linkTrainerId = GetLinkPlayerTrainerId(0) % 2; - for (i = 0; i < 3; i++) - data[i] = gUnknown_0858CF8E[linkTrainerId][i]; + linkTrainerId = GetLinkPlayerTrainerId(0) % ARRAY_COUNT(sPlayerIdxOrders_3Player); + for (i = 0; i < ARRAY_COUNT(sPlayerIdxOrders_3Player[0]); i++) + data[i] = sPlayerIdxOrders_3Player[linkTrainerId][i]; break; case 4: - linkTrainerId = GetLinkPlayerTrainerId(0) % 9; - for (i = 0; i < 4; i++) - data[i] = gUnknown_0858CF94[linkTrainerId][i]; + linkTrainerId = GetLinkPlayerTrainerId(0) % ARRAY_COUNT(sPlayerIdxOrders_4Player); + for (i = 0; i < ARRAY_COUNT(sPlayerIdxOrders_4Player[0]); i++) + data[i] = sPlayerIdxOrders_4Player[linkTrainerId][i]; break; } } -static void ReceiveOldManData(OldMan *oldMan, size_t recordSize, u8 which) +static void ReceiveOldManData(OldMan *records, size_t recordSize, u8 multiplayerId) { u8 version; u16 language; - OldMan *dest; + OldMan *oldMan; u32 mixIndices[MAX_LINK_PLAYERS]; ShufflePlayerIndices(mixIndices); - dest = (void *)oldMan + recordSize * mixIndices[which]; - version = gLinkPlayers[mixIndices[which]].version; - language = gLinkPlayers[mixIndices[which]].language; + oldMan = (void *)records + recordSize * mixIndices[multiplayerId]; + version = gLinkPlayers[mixIndices[multiplayerId]].version; + language = gLinkPlayers[mixIndices[multiplayerId]].language; if (Link_AnyPartnersPlayingRubyOrSapphire()) - SanitizeReceivedRubyOldMan(dest, version, language); + SanitizeReceivedRubyOldMan(oldMan, version, language); else - SanitizeReceivedEmeraldOldMan(dest, version, language); + SanitizeReceivedEmeraldOldMan(oldMan, version, language); - memcpy(sOldManSave, (void *)oldMan + recordSize * mixIndices[which], sizeof(OldMan)); + memcpy(sOldManSave, (void *)records + recordSize * mixIndices[multiplayerId], sizeof(OldMan)); ResetMauvilleOldManFlag(); } -static void ReceiveBattleTowerData(void *battleTowerRecord, size_t recordSize, u8 which) +static void ReceiveBattleTowerData(void *records, size_t recordSize, u8 multiplayerId) { - struct EmeraldBattleTowerRecord *dest; + struct EmeraldBattleTowerRecord *battleTowerRecord; struct BattleTowerPokemon *btPokemon; u32 mixIndices[MAX_LINK_PLAYERS]; s32 i; @@ -654,77 +657,90 @@ static void ReceiveBattleTowerData(void *battleTowerRecord, size_t recordSize, u ShufflePlayerIndices(mixIndices); if (Link_AnyPartnersPlayingRubyOrSapphire()) { - if (RubyBattleTowerRecordToEmerald((void *)battleTowerRecord + recordSize * mixIndices[which], (void *)battleTowerRecord + recordSize * which) == TRUE) + if (RubyBattleTowerRecordToEmerald((void *)records + recordSize * mixIndices[multiplayerId], (void *)records + recordSize * multiplayerId) == TRUE) { - dest = (void *)battleTowerRecord + recordSize * which; - dest->language = gLinkPlayers[mixIndices[which]].language; - CalcEmeraldBattleTowerChecksum(dest); + battleTowerRecord = (void *)records + recordSize * multiplayerId; + battleTowerRecord->language = gLinkPlayers[mixIndices[multiplayerId]].language; + CalcEmeraldBattleTowerChecksum(battleTowerRecord); } } else { - memcpy((void *)battleTowerRecord + recordSize * which, (void *)battleTowerRecord + recordSize * mixIndices[which], sizeof(struct EmeraldBattleTowerRecord)); - dest = (void *)battleTowerRecord + recordSize * which; + memcpy((void *)records + recordSize * multiplayerId, (void *)records + recordSize * mixIndices[multiplayerId], sizeof(struct EmeraldBattleTowerRecord)); + battleTowerRecord = (void *)records + recordSize * multiplayerId; for (i = 0; i < MAX_FRONTIER_PARTY_SIZE; i++) { - btPokemon = &dest->party[i]; + btPokemon = &battleTowerRecord->party[i]; if (btPokemon->species != SPECIES_NONE && IsStringJapanese(btPokemon->nickname)) ConvertInternationalString(btPokemon->nickname, LANGUAGE_JAPANESE); } - CalcEmeraldBattleTowerChecksum(dest); + CalcEmeraldBattleTowerChecksum(battleTowerRecord); } - PutNewBattleTowerRecord((void *)battleTowerRecord + recordSize * which); + PutNewBattleTowerRecord((void *)records + recordSize * multiplayerId); } -static void ReceiveLilycoveLadyData(LilycoveLady *lilycoveLady, size_t recordSize, u8 which) +static void ReceiveLilycoveLadyData(LilycoveLady *records, size_t recordSize, u8 multiplayerId) { - LilycoveLady *dest; + LilycoveLady *lilycoveLady; u32 mixIndices[MAX_LINK_PLAYERS]; ShufflePlayerIndices(mixIndices); - memcpy((void *)lilycoveLady + recordSize * which, sLilycoveLadySave, sizeof(LilycoveLady)); + memcpy((void *)records + recordSize * multiplayerId, sLilycoveLadySave, sizeof(LilycoveLady)); if (GetLilycoveLadyId() == 0) { - dest = malloc(sizeof(LilycoveLady)); - if (dest == NULL) + lilycoveLady = malloc(sizeof(*lilycoveLady)); + if (lilycoveLady == NULL) return; - memcpy(dest, sLilycoveLadySave, sizeof(LilycoveLady)); + memcpy(lilycoveLady, sLilycoveLadySave, sizeof(LilycoveLady)); } else { - dest = NULL; + lilycoveLady = NULL; } - memcpy(sLilycoveLadySave, (void *)lilycoveLady + recordSize * mixIndices[which], sizeof(LilycoveLady)); + memcpy(sLilycoveLadySave, (void *)records + recordSize * mixIndices[multiplayerId], sizeof(LilycoveLady)); ResetLilycoveLadyForRecordMix(); - if (dest != NULL) + if (lilycoveLady != NULL) { - QuizLadyClearQuestionForRecordMix(dest); - free(dest); + QuizLadyClearQuestionForRecordMix(lilycoveLady); + free(lilycoveLady); } } -static u8 sub_80E7A9C(struct DaycareMail *rmMail) +static u8 GetDaycareMailItemId(struct DaycareMail *mail) { - return rmMail->message.itemId; + return mail->message.itemId; } -static void sub_80E7AA4(struct RecordMixingDaycareMail *src, size_t recordSize, u8 (*idxs)[2], u8 which0, u8 which1) -{ - struct DaycareMail buffer; - struct RecordMixingDaycareMail *mail1; - struct RecordMixingDaycareMail *mail2; +// Indexes for a 2 element array used to store the multiplayer id and daycare +// slot that correspond to a daycare Pokémon that can hold an item. +enum { + MULTIPLAYER_ID, + DAYCARE_SLOT, +}; - mail1 = (void *)src + recordSize * idxs[which0][0]; - memcpy(&buffer, &mail1->mail[idxs[which0][1]], sizeof(struct DaycareMail)); - mail2 = (void *)src + recordSize * idxs[which1][0]; - memcpy(&mail1->mail[idxs[which0][1]], &mail2->mail[idxs[which1][1]], sizeof(struct DaycareMail)); - memcpy(&mail2->mail[idxs[which1][1]], &buffer, sizeof(struct DaycareMail)); +static void SwapDaycareMail(struct RecordMixingDaycareMail *records, size_t recordSize, u8 (*idxs)[2], u8 playerSlot1, u8 playerSlot2) +{ + struct DaycareMail temp; + struct RecordMixingDaycareMail *mixMail1, *mixMail2; + + // 1st player's daycare mail --> temp + mixMail1 = (void *)records + recordSize * idxs[playerSlot1][MULTIPLAYER_ID]; + memcpy(&temp, &mixMail1->mail[idxs[playerSlot1][DAYCARE_SLOT]], sizeof(struct DaycareMail)); + + // 2nd player's daycare mail --> 1st player's daycare mail + mixMail2 = (void *)records + recordSize * idxs[playerSlot2][MULTIPLAYER_ID]; + memcpy(&mixMail1->mail[idxs[playerSlot1][DAYCARE_SLOT]], &mixMail2->mail[idxs[playerSlot2][DAYCARE_SLOT]], sizeof(struct DaycareMail)); + + // temp --> 2nd player's daycare mail + memcpy(&mixMail2->mail[idxs[playerSlot2][DAYCARE_SLOT]], &temp, sizeof(struct DaycareMail)); } -static void sub_80E7B2C(const u8 *src) +// This sum is used to determine which players will swap daycare mail if there are more than 2 players who can. +// The TV show data is used to calculate this sum. +static void CalculateDaycareMailRandSum(const u8 *src) { u8 sum; s32 i; @@ -733,73 +749,80 @@ static void sub_80E7B2C(const u8 *src) for (i = 0; i < 256; i++) sum += src[i]; - gUnknown_03001160 = sum; + sDaycareMailRandSum = sum; } -static u8 sub_80E7B54(void) +static u8 GetDaycareMailRandSum(void) { - return gUnknown_03001160; + return sDaycareMailRandSum; } -static void ReceiveDaycareMailData(struct RecordMixingDaycareMail *src, size_t recordSize, u8 which, TVShow *shows) +static void ReceiveDaycareMailData(struct RecordMixingDaycareMail *records, size_t recordSize, u8 multiplayerId, TVShow *shows) { u16 i, j; u8 linkPlayerCount; u8 tableId; - struct RecordMixingDaycareMail *_src; - u8 which0, which1; + struct RecordMixingDaycareMail *mixMail; + u8 playerSlot1, playerSlot2; void *ptr; - u8 sp04[4]; - u8 sp08[4]; - struct RecordMixingDaycareMail *sp0c[4]; - u8 sp1c[4][2]; - u8 sp24[4][2]; - u8 sp34; + u8 unusedArr1[MAX_LINK_PLAYERS]; + u8 unusedArr2[MAX_LINK_PLAYERS]; + struct RecordMixingDaycareMail *unusedMixMail[MAX_LINK_PLAYERS]; + bool8 canHoldItem[MAX_LINK_PLAYERS][DAYCARE_MON_COUNT]; + u8 idxs[MAX_LINK_PLAYERS][2]; + u8 numDaycareCanHold; u16 oldSeed; bool32 anyRS; + // Seed RNG to the first player's trainer id so that + // every player has the same random swap occur + // (see the other use of Random2 in this function) oldSeed = Random2(); SeedRng2(gLinkPlayers[0].trainerId); linkPlayerCount = GetLinkPlayerCount(); - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_LINK_PLAYERS; i++) { - sp04[i] = 0xFF; - sp08[i] = 0; - sp1c[i][0] = 0; - sp1c[i][1] = 0; + unusedArr1[i] = 0xFF; + unusedArr2[i] = 0; + canHoldItem[i][0] = FALSE; + canHoldItem[i][1] = FALSE; } + // Handle language differences if RS / Japanese players are present anyRS = Link_AnyPartnersPlayingRubyOrSapphire(); for (i = 0; i < GetLinkPlayerCount(); i++) { u32 language, version; - _src = (void *)src + i * recordSize; + mixMail = (void *)records + i * recordSize; language = gLinkPlayers[i].language; version = gLinkPlayers[i].version & 0xFF; - for (j = 0; j < _src->numDaycareMons; j++) + + for (j = 0; j < mixMail->numDaycareMons; j++) { u16 otNameLanguage, nicknameLanguage; - struct DaycareMail *recordMixingMail = &_src->mail[j]; + struct DaycareMail *daycareMail = &mixMail->mail[j]; - if (!recordMixingMail->message.itemId) + if (daycareMail->message.itemId == ITEM_NONE) continue; if (anyRS) { - if (StringLength(recordMixingMail->OT_name) <= 5) + // Handle OT name language + if (StringLength(daycareMail->otName) <= 5) { otNameLanguage = LANGUAGE_JAPANESE; } else { - StripExtCtrlCodes(recordMixingMail->OT_name); + StripExtCtrlCodes(daycareMail->otName); otNameLanguage = language; } - if (recordMixingMail->monName[0] == EXT_CTRL_CODE_BEGIN && recordMixingMail->monName[1] == EXT_CTRL_CODE_JPN) + // Handle nickname langugae + if (daycareMail->monName[0] == EXT_CTRL_CODE_BEGIN && daycareMail->monName[1] == EXT_CTRL_CODE_JPN) { - StripExtCtrlCodes(recordMixingMail->monName); + StripExtCtrlCodes(daycareMail->monName); nicknameLanguage = LANGUAGE_JAPANESE; } else @@ -807,121 +830,145 @@ static void ReceiveDaycareMailData(struct RecordMixingDaycareMail *src, size_t r nicknameLanguage = language; } + // Set languages if (version == VERSION_RUBY || version == VERSION_SAPPHIRE) { - recordMixingMail->gameLanguage = otNameLanguage; - recordMixingMail->monLanguage = nicknameLanguage; + daycareMail->gameLanguage = otNameLanguage; + daycareMail->monLanguage = nicknameLanguage; } } else if (language == LANGUAGE_JAPANESE) { - if (IsStringJapanese(recordMixingMail->OT_name)) - recordMixingMail->gameLanguage = LANGUAGE_JAPANESE; + if (IsStringJapanese(daycareMail->otName)) + daycareMail->gameLanguage = LANGUAGE_JAPANESE; else - recordMixingMail->gameLanguage = GAME_LANGUAGE; + daycareMail->gameLanguage = GAME_LANGUAGE; - if (IsStringJapanese(recordMixingMail->monName)) - recordMixingMail->monLanguage = LANGUAGE_JAPANESE; + if (IsStringJapanese(daycareMail->monName)) + daycareMail->monLanguage = LANGUAGE_JAPANESE; else - recordMixingMail->monLanguage = GAME_LANGUAGE; + daycareMail->monLanguage = GAME_LANGUAGE; } } } - sp34 = 0; + // For each player, get which of their daycare Pokémon can hold items + // (can't hold items if already holding one, or if daycare slot is empty). + // Note that when deposited in the daycare, Pokémon have their mail taken + // from them and returned upon withdrawal, which means daycare Pokémon that + // have associated mail do not have a held item. + // Because not holding an item is the only determination for a swap, this also + // means that a "swap" can occur even if neither Pokémon has associated mail. + numDaycareCanHold = 0; for (i = 0; i < linkPlayerCount; i++) { - _src = (void *)src + i * recordSize; - if (_src->numDaycareMons == 0) + mixMail = (void *)records + i * recordSize; + if (mixMail->numDaycareMons == 0) continue; - for (j = 0; j < _src->numDaycareMons; j++) + for (j = 0; j < mixMail->numDaycareMons; j++) { - if (!_src->holdsItem[j]) - sp1c[i][j] = 1; + if (!mixMail->cantHoldItem[j]) + canHoldItem[i][j] = TRUE; } } + // Fill the idxs array with data about which players + // and which daycare slots should swap mail. j = 0; for (i = 0; i < linkPlayerCount; i++) { - _src = (void *)src + i * recordSize; - if (sp1c[i][0] == TRUE || sp1c[i][1] == TRUE) - sp34++; + mixMail = (void *)records + i * recordSize; + + // Count number of players that have at least + // one daycare Pokémon with no held item + if (canHoldItem[i][0] == TRUE || canHoldItem[i][1] == TRUE) + numDaycareCanHold++; - if (sp1c[i][0] == TRUE && sp1c[i][1] == FALSE) + if (canHoldItem[i][0] == TRUE && canHoldItem[i][1] == FALSE) { - sp24[j][0] = i; - sp24[j][1] = 0; + // Only daycare slot 0 can hold an item for this player, record it + idxs[j][MULTIPLAYER_ID] = i; + idxs[j][DAYCARE_SLOT] = 0; j++; } - else if (sp1c[i][0] == FALSE && sp1c[i][1] == TRUE) + else if (canHoldItem[i][0] == FALSE && canHoldItem[i][1] == TRUE) { - sp24[j][0] = i; - sp24[j][1] = 1; + // Only daycare slot 1 can hold an item for this player, record it + idxs[j][MULTIPLAYER_ID] = i; + idxs[j][DAYCARE_SLOT] = 1; j++; } - else if (sp1c[i][0] == TRUE && sp1c[i][1] == TRUE) + else if (canHoldItem[i][0] == TRUE && canHoldItem[i][1] == TRUE) { - u32 var1, var2; + // Both daycare slots can hold an item, choose which one to use. + // If either one is the only one to have associated mail, use that one. + // If both do or don't have associated mail, choose one randomly. + u32 itemId1, itemId2; + idxs[j][MULTIPLAYER_ID] = i; + itemId1 = GetDaycareMailItemId(&mixMail->mail[0]); + itemId2 = GetDaycareMailItemId(&mixMail->mail[1]); + + if ((!itemId1 && !itemId2) || (itemId1 && itemId2)) + idxs[j][DAYCARE_SLOT] = Random2() % 2; + else if (itemId1 && !itemId2) + idxs[j][DAYCARE_SLOT] = 0; + else if (!itemId1 && itemId2) + idxs[j][DAYCARE_SLOT] = 1; - sp24[j][0] = i; - var1 = sub_80E7A9C(&_src->mail[0]); - var2 = sub_80E7A9C(&_src->mail[1]); - if (!(var1 || var2) || (var1 && var2)) - { - sp24[j][1] = Random2() % 2; - } - else if (var1 && !var2) - { - sp24[j][1] = 0; - } - else if (!var1 && var2) - { - sp24[j][1] = 1; - } j++; } } - for (i = 0; i < 4; i++) + // Copy the player's record mix mail 4 times to an array that's never read. + for (i = 0; i < MAX_LINK_PLAYERS; i++) { - _src = &src[which * recordSize]; - sp0c[i] = _src; + mixMail = &records[multiplayerId * recordSize]; + unusedMixMail[i] = mixMail; } - tableId = sub_80E7B54() % 3; - switch (sp34) + // Choose a random table id to determine who will + // swap if there are more than 2 candidate players. + tableId = GetDaycareMailRandSum() % NUM_SWAP_COMBOS; + switch (numDaycareCanHold) { case 2: - sub_80E7AA4(src, recordSize, sp24, 0, 1); + // 2 players can swap, just perform swap. + SwapDaycareMail(records, recordSize, idxs, 0, 1); break; case 3: - which0 = gUnknown_0858CFB8[tableId][0]; - which1 = gUnknown_0858CFB8[tableId][1]; - sub_80E7AA4(src, recordSize, sp24, which0, which1); + // 3 players can swap, select 2 and leave the 3rd out + playerSlot1 = sDaycareMailSwapIds_3Player[tableId][0]; + playerSlot2 = sDaycareMailSwapIds_3Player[tableId][1]; + SwapDaycareMail(records, recordSize, idxs, playerSlot1, playerSlot2); break; case 4: - ptr = sp24; - which0 = gUnknown_0858CFBE[tableId][0]; - which1 = gUnknown_0858CFBE[tableId][1]; - sub_80E7AA4(src, recordSize, ptr, which0, which1); - which0 = gUnknown_0858CFBE[tableId][2]; - which1 = gUnknown_0858CFBE[tableId][3]; - sub_80E7AA4(src, recordSize, ptr, which0, which1); + // 4 players can swap, select which 2 pairings will swap + ptr = idxs; + + // Swap pair 1 + playerSlot1 = sDaycareMailSwapIds_4Player[tableId][0]; + playerSlot2 = sDaycareMailSwapIds_4Player[tableId][1]; + SwapDaycareMail(records, recordSize, ptr, playerSlot1, playerSlot2); + + // Swap pair 2 + playerSlot1 = sDaycareMailSwapIds_4Player[tableId][2]; + playerSlot2 = sDaycareMailSwapIds_4Player[tableId][3]; + SwapDaycareMail(records, recordSize, ptr, playerSlot1, playerSlot2); break; } - _src = (void *)src + which * recordSize; - memcpy(&gSaveBlock1Ptr->daycare.mons[0].mail, &_src->mail[0], sizeof(struct DaycareMail)); - memcpy(&gSaveBlock1Ptr->daycare.mons[1].mail, &_src->mail[1], sizeof(struct DaycareMail)); + // Save player's record mixed mail to the daycare (in case it has changed) + mixMail = (void *)records + multiplayerId * recordSize; + memcpy(&gSaveBlock1Ptr->daycare.mons[0].mail, &mixMail->mail[0], sizeof(struct DaycareMail)); + memcpy(&gSaveBlock1Ptr->daycare.mons[1].mail, &mixMail->mail[1], sizeof(struct DaycareMail)); SeedRng(oldSeed); } -static void ReceiveGiftItem(u16 *item, u8 which) +static void ReceiveGiftItem(u16 *item, u8 multiplayerId) { - if (which != 0 && *item != ITEM_NONE && GetPocketByItemId(*item) == POCKET_KEY_ITEMS) + if (multiplayerId != 0 && *item != ITEM_NONE && GetPocketByItemId(*item) == POCKET_KEY_ITEMS) { if (!CheckBagHasItem(*item, 1) && !CheckPCHasItem(*item, 1) && AddBagItem(*item, 1)) { @@ -941,29 +988,28 @@ static void Task_DoRecordMixing(u8 taskId) { struct Task *task = &gTasks[taskId]; - switch (task->data[0]) + switch (task->tState) { case 0: - task->data[0]++; + task->tState++; break; case 1: if (Link_AnyPartnersPlayingRubyOrSapphire()) - task->data[0]++; + task->tState++; else - task->data[0] = 6; + task->tState = 6; break; - - // Mixing Ruby/Sapphire records. case 2: + // Mixing Ruby/Sapphire records. SetContinueGameWarpStatusToDynamicWarp(); FullSaveGame(); - task->data[0]++; + task->tState++; break; case 3: if (CheckSaveFile()) { ClearContinueGameWarpStatus2(); - task->data[0] = 4; + task->tState = 4; task->data[1] = 0; } break; @@ -971,10 +1017,11 @@ static void Task_DoRecordMixing(u8 taskId) if (++task->data[1] > 10) { SetCloseLinkCallback(); - task->data[0]++; + task->tState++; } break; case 5: + // Finish mixing Ruby/Sapphire records if (gReceivedRemoteLinkPlayers == FALSE) DestroyTask(taskId); break; @@ -984,7 +1031,7 @@ static void Task_DoRecordMixing(u8 taskId) if (!Rfu_SetLinkRecovery(FALSE)) { CreateTask(Task_LinkSave, 5); - task->data[0]++; + task->tState++; } break; case 7: // wait for Task_LinkSave to finish. @@ -993,17 +1040,17 @@ static void Task_DoRecordMixing(u8 taskId) if (gWirelessCommType) { Rfu_SetLinkRecovery(TRUE); - task->data[0] = 8; + task->tState = 8; } else { - task->data[0] = 4; + task->tState = 4; } } break; case 8: SetLinkStandbyCallback(); - task->data[0]++; + task->tState++; break; case 9: if (IsLinkTaskFinished()) @@ -1012,8 +1059,6 @@ static void Task_DoRecordMixing(u8 taskId) } } -// New Emerald functions - static void GetSavedApprentices(struct Apprentice *dst, struct Apprentice *src) { s32 i, id; @@ -1031,7 +1076,7 @@ static void GetSavedApprentices(struct Apprentice *dst, struct Apprentice *src) numMixApprentices = 0; for (i = 0; i < 2; i++) { - id = ((i + gSaveBlock2Ptr->playerApprentice.saveId) % (APPRENTICE_COUNT - 1)) + 1; + id = (i + gSaveBlock2Ptr->playerApprentice.saveId) % (APPRENTICE_COUNT - 1) + 1; if (src[id].playerName[0] != EOS) { if (GetTrainerId(src[id].playerId) != GetTrainerId(gSaveBlock2Ptr->playerTrainerId)) @@ -1074,7 +1119,7 @@ void GetPlayerHallRecords(struct PlayerHallRecords *dst) for (i = 0; i < HALL_FACILITIES_COUNT; i++) { - for (j = 0; j < 2; j++) + for (j = 0; j < FRONTIER_LVL_MODE_COUNT; j++) { CopyTrainerId(dst->onePlayer[i][j].id, gSaveBlock2Ptr->playerTrainerId); dst->onePlayer[i][j].language = GAME_LANGUAGE; @@ -1082,7 +1127,7 @@ void GetPlayerHallRecords(struct PlayerHallRecords *dst) } } - for (j = 0; j < 2; j++) + for (j = 0; j < FRONTIER_LVL_MODE_COUNT; j++) { dst->twoPlayers[j].language = GAME_LANGUAGE; CopyTrainerId(dst->twoPlayers[j].id1, gSaveBlock2Ptr->playerTrainerId); @@ -1091,17 +1136,17 @@ void GetPlayerHallRecords(struct PlayerHallRecords *dst) StringCopy(dst->twoPlayers[j].name2, gSaveBlock2Ptr->frontier.opponentNames[j]); } - for (i = 0; i < 2; i++) + for (i = 0; i < FRONTIER_LVL_MODE_COUNT; i++) { - dst->onePlayer[0][i].winStreak = gSaveBlock2Ptr->frontier.towerRecordWinStreaks[FRONTIER_MODE_SINGLES][i]; - dst->onePlayer[1][i].winStreak = gSaveBlock2Ptr->frontier.towerRecordWinStreaks[FRONTIER_MODE_DOUBLES][i]; - dst->onePlayer[2][i].winStreak = gSaveBlock2Ptr->frontier.towerRecordWinStreaks[FRONTIER_MODE_MULTIS][i]; - dst->onePlayer[3][i].winStreak = gSaveBlock2Ptr->frontier.domeRecordWinStreaks[FRONTIER_MODE_SINGLES][i]; - dst->onePlayer[4][i].winStreak = gSaveBlock2Ptr->frontier.palaceRecordWinStreaks[FRONTIER_MODE_SINGLES][i]; - dst->onePlayer[5][i].winStreak = gSaveBlock2Ptr->frontier.arenaRecordStreaks[i]; - dst->onePlayer[6][i].winStreak = gSaveBlock2Ptr->frontier.factoryRecordWinStreaks[FRONTIER_MODE_SINGLES][i]; - dst->onePlayer[7][i].winStreak = gSaveBlock2Ptr->frontier.pikeRecordStreaks[i]; - dst->onePlayer[8][i].winStreak = gSaveBlock2Ptr->frontier.pyramidRecordStreaks[i]; + dst->onePlayer[RANKING_HALL_TOWER_SINGLES][i].winStreak = gSaveBlock2Ptr->frontier.towerRecordWinStreaks[FRONTIER_MODE_SINGLES][i]; + dst->onePlayer[RANKING_HALL_TOWER_DOUBLES][i].winStreak = gSaveBlock2Ptr->frontier.towerRecordWinStreaks[FRONTIER_MODE_DOUBLES][i]; + dst->onePlayer[RANKING_HALL_TOWER_MULTIS][i].winStreak = gSaveBlock2Ptr->frontier.towerRecordWinStreaks[FRONTIER_MODE_MULTIS][i]; + dst->onePlayer[RANKING_HALL_DOME][i].winStreak = gSaveBlock2Ptr->frontier.domeRecordWinStreaks[FRONTIER_MODE_SINGLES][i]; + dst->onePlayer[RANKING_HALL_PALACE][i].winStreak = gSaveBlock2Ptr->frontier.palaceRecordWinStreaks[FRONTIER_MODE_SINGLES][i]; + dst->onePlayer[RANKING_HALL_ARENA][i].winStreak = gSaveBlock2Ptr->frontier.arenaRecordStreaks[i]; + dst->onePlayer[RANKING_HALL_FACTORY][i].winStreak = gSaveBlock2Ptr->frontier.factoryRecordWinStreaks[FRONTIER_MODE_SINGLES][i]; + dst->onePlayer[RANKING_HALL_PIKE][i].winStreak = gSaveBlock2Ptr->frontier.pikeRecordStreaks[i]; + dst->onePlayer[RANKING_HALL_PYRAMID][i].winStreak = gSaveBlock2Ptr->frontier.pyramidRecordStreaks[i]; dst->twoPlayers[i].winStreak = gSaveBlock2Ptr->frontier.towerRecordWinStreaks[FRONTIER_MODE_LINK_MULTIS][i]; } @@ -1115,28 +1160,26 @@ static bool32 IsApprenticeAlreadySaved(struct Apprentice *mixApprentice, struct { if (GetTrainerId(mixApprentice->playerId) == GetTrainerId(apprentices[i].playerId) && mixApprentice->number == apprentices[i].number) - { return TRUE; - } } return FALSE; } -static void ReceiveApprenticeData(struct Apprentice *mixApprentice, size_t recordSize, u32 multiplayerId) +static void ReceiveApprenticeData(struct Apprentice *records, size_t recordSize, u32 multiplayerId) { s32 i, numApprentices, apprenticeId; - struct Apprentice *mixApprenticePtr; + struct Apprentice *mixApprentice; u32 mixIndices[MAX_LINK_PLAYERS]; u32 apprenticeSaveId; ShufflePlayerIndices(mixIndices); - mixApprenticePtr = (void*)(mixApprentice) + (recordSize * mixIndices[multiplayerId]); + mixApprentice = (void*)records + (recordSize * mixIndices[multiplayerId]); numApprentices = 0; apprenticeId = 0; for (i = 0; i < 2; i++) { - if (mixApprenticePtr[i].playerName[0] != EOS && !IsApprenticeAlreadySaved(&mixApprenticePtr[i], &gSaveBlock2Ptr->apprentices[0])) + if (mixApprentice[i].playerName[0] != EOS && !IsApprenticeAlreadySaved(&mixApprentice[i], &gSaveBlock2Ptr->apprentices[0])) { numApprentices++; apprenticeId = i; @@ -1147,14 +1190,14 @@ static void ReceiveApprenticeData(struct Apprentice *mixApprentice, size_t recor { case 1: apprenticeSaveId = gSaveBlock2Ptr->playerApprentice.saveId + 1; - gSaveBlock2Ptr->apprentices[apprenticeSaveId] = mixApprenticePtr[apprenticeId]; + gSaveBlock2Ptr->apprentices[apprenticeSaveId] = mixApprentice[apprenticeId]; gSaveBlock2Ptr->playerApprentice.saveId = (gSaveBlock2Ptr->playerApprentice.saveId + 1) % (APPRENTICE_COUNT - 1); break; case 2: for (i = 0; i < 2; i++) { apprenticeSaveId = ((i ^ 1) + gSaveBlock2Ptr->playerApprentice.saveId) % (APPRENTICE_COUNT - 1) + 1; - gSaveBlock2Ptr->apprentices[apprenticeSaveId] = mixApprenticePtr[i]; + gSaveBlock2Ptr->apprentices[apprenticeSaveId] = mixApprentice[i]; } gSaveBlock2Ptr->playerApprentice.saveId = (gSaveBlock2Ptr->playerApprentice.saveId + 2) % (APPRENTICE_COUNT - 1); break; @@ -1183,15 +1226,15 @@ static void sub_80E8578(struct RecordMixingHallRecords *dst, void *hallRecords, for (i = 0; i < HALL_FACILITIES_COUNT; i++) { - for (j = 0; j < 2; j++) + for (j = 0; j < FRONTIER_LVL_MODE_COUNT; j++) { - for (k = 0; k < 3; k++) + for (k = 0; k < HALL_RECORDS_COUNT; k++) dst->hallRecords1P[i][j][k] = gSaveBlock2Ptr->hallRecords1P[i][j][k]; for (k = 0; k < linkPlayerCount - 1; k++) { var_68 = 0; - for (l = 0; l < 3; l++) + for (l = 0; l < HALL_RECORDS_COUNT; l++) { if (GetTrainerId(dst->hallRecords1P[i][j][l].id) == GetTrainerId(gUnknown_03001168[k]->onePlayer[i][j].id)) { @@ -1201,20 +1244,20 @@ static void sub_80E8578(struct RecordMixingHallRecords *dst, void *hallRecords, } } if (var_68 == 0) - dst->hallRecords1P[i][j][k + 3] = gUnknown_03001168[k]->onePlayer[i][j]; + dst->hallRecords1P[i][j][k + HALL_RECORDS_COUNT] = gUnknown_03001168[k]->onePlayer[i][j]; } } } - for (j = 0; j < 2; j++) + for (j = 0; j < FRONTIER_LVL_MODE_COUNT; j++) { - for (k = 0; k < 3; k++) + for (k = 0; k < HALL_RECORDS_COUNT; k++) dst->hallRecords2P[j][k] = gSaveBlock2Ptr->hallRecords2P[j][k]; for (k = 0; k < linkPlayerCount - 1; k++) { var_68 = 0; - for (l = 0; l < 3; l++) + for (l = 0; l < HALL_RECORDS_COUNT; l++) { if (GetTrainerId(dst->hallRecords2P[j][l].id1) == GetTrainerId(gUnknown_03001168[k]->twoPlayers[j].id1) && GetTrainerId(dst->hallRecords2P[j][l].id2) == GetTrainerId(gUnknown_03001168[k]->twoPlayers[j].id2)) @@ -1225,7 +1268,7 @@ static void sub_80E8578(struct RecordMixingHallRecords *dst, void *hallRecords, } } if (var_68 == 0) - dst->hallRecords2P[j][k + 3] = gUnknown_03001168[k]->twoPlayers[j]; + dst->hallRecords2P[j][k + HALL_RECORDS_COUNT] = gUnknown_03001168[k]->twoPlayers[j]; } } } @@ -1234,7 +1277,7 @@ static void sub_80E8880(struct RankingHall1P *arg0, struct RankingHall1P *arg1) { s32 i, j; - for (i = 0; i < 3; i++) + for (i = 0; i < HALL_RECORDS_COUNT; i++) { s32 highestWinStreak = 0; s32 highestId = -1; @@ -1280,36 +1323,36 @@ static void sub_80E88CC(struct RankingHall2P *arg0, struct RankingHall2P *arg1) } } -static void sub_80E8924(struct RecordMixingHallRecords *arg0) +static void sub_80E8924(struct RecordMixingHallRecords *mixHallRecords) { s32 i, j; for (i = 0; i < HALL_FACILITIES_COUNT; i++) { - for (j = 0; j < 2; j++) - sub_80E8880(gSaveBlock2Ptr->hallRecords1P[i][j], arg0->hallRecords1P[i][j]); + for (j = 0; j < FRONTIER_LVL_MODE_COUNT; j++) + sub_80E8880(gSaveBlock2Ptr->hallRecords1P[i][j], mixHallRecords->hallRecords1P[i][j]); } - for (j = 0; j < 2; j++) - sub_80E88CC(gSaveBlock2Ptr->hallRecords2P[j], arg0->hallRecords2P[j]); + for (j = 0; j < FRONTIER_LVL_MODE_COUNT; j++) + sub_80E88CC(gSaveBlock2Ptr->hallRecords2P[j], mixHallRecords->hallRecords2P[j]); } static void ReceiveRankingHallRecords(struct PlayerHallRecords *hallRecords, size_t recordSize, u32 arg2) { u8 linkPlayerCount = GetLinkPlayerCount(); - struct RecordMixingHallRecords *largeStructPtr = AllocZeroed(sizeof(struct RecordMixingHallRecords)); + struct RecordMixingHallRecords *mixHallRecords = AllocZeroed(sizeof(*mixHallRecords)); - sub_80E8578(largeStructPtr, hallRecords, recordSize, arg2, linkPlayerCount); - sub_80E8924(largeStructPtr); + sub_80E8578(mixHallRecords, hallRecords, recordSize, arg2, linkPlayerCount); + sub_80E8924(mixHallRecords); - Free(largeStructPtr); + Free(mixHallRecords); } static void GetRecordMixingDaycareMail(struct RecordMixingDaycareMail *dst) { - sDaycareMail.mail[0] = gSaveBlock1Ptr->daycare.mons[0].mail; - sDaycareMail.mail[1] = gSaveBlock1Ptr->daycare.mons[1].mail; - InitDaycareMailRecordMixing(&gSaveBlock1Ptr->daycare, &sDaycareMail); - *dst = *sDaycareMailSave; + sRecordMixMail.mail[0] = gSaveBlock1Ptr->daycare.mons[0].mail; + sRecordMixMail.mail[1] = gSaveBlock1Ptr->daycare.mons[1].mail; + InitDaycareMailRecordMixing(&gSaveBlock1Ptr->daycare, &sRecordMixMail); + *dst = *sRecordMixMailSave; } static void SanitizeDaycareMailForRuby(struct RecordMixingDaycareMail *src) @@ -1319,10 +1362,10 @@ static void SanitizeDaycareMailForRuby(struct RecordMixingDaycareMail *src) for (i = 0; i < src->numDaycareMons; i++) { struct DaycareMail *mail = &src->mail[i]; - if (mail->message.itemId != 0) + if (mail->message.itemId != ITEM_NONE) { if (mail->gameLanguage != LANGUAGE_JAPANESE) - PadNameString(mail->OT_name, EXT_CTRL_CODE_BEGIN); + PadNameString(mail->otName, EXT_CTRL_CODE_BEGIN); ConvertInternationalString(mail->monName, mail->monLanguage); } diff --git a/src/trade.c b/src/trade.c index d1fc14efe..00db3c232 100644 --- a/src/trade.c +++ b/src/trade.c @@ -101,7 +101,7 @@ static EWRAM_DATA u8 *sMenuTextAllocBuffer = NULL; // See the corresponding GFXTAGs in src/data/trade.h static EWRAM_DATA u8 *sMenuTextTileBuffers[GFXTAG_MENU_TEXT_COUNT] = {NULL}; -EWRAM_DATA struct MailStruct gTradeMail[PARTY_SIZE] = {0}; +EWRAM_DATA struct Mail gTradeMail[PARTY_SIZE] = {0}; EWRAM_DATA u8 gSelectedTradeMonPositions[2] = {0}; static EWRAM_DATA struct { /*0x0000*/ u8 bg2hofs; @@ -144,7 +144,7 @@ static EWRAM_DATA struct { } *sTradeMenuData = {NULL}; static EWRAM_DATA struct { - /*0x00*/ struct Pokemon mon; + /*0x00*/ struct Pokemon tempMon; // Used as a temp variable when swapping Pokémon /*0x64*/ u32 timer; /*0x68*/ u32 monPersonalities[2]; /*0x70*/ u8 filler_70[2]; @@ -238,7 +238,7 @@ static void SpriteCB_BouncingPokeballDepart(struct Sprite *); static void SpriteCB_BouncingPokeballDepartEnd(struct Sprite *); static void SpriteCB_BouncingPokeballArrive(struct Sprite *); static void BufferInGameTradeMonName(void); -static void SetInGameTradeMail(struct MailStruct *, const struct InGameTrade *); +static void SetInGameTradeMail(struct Mail *, const struct InGameTrade *); static void CB2_UpdateLinkTrade(void); static void CB2_TryFinishTrade(void); static void CB2_SaveAndEndTrade(void); @@ -1054,7 +1054,7 @@ static bool8 BufferTradeParties(void) } break; case 13: - Trade_Memcpy(gBlockSendBuffer, gSaveBlock1Ptr->mail, PARTY_SIZE * sizeof(struct MailStruct) + 4); + Trade_Memcpy(gBlockSendBuffer, gSaveBlock1Ptr->mail, PARTY_SIZE * sizeof(struct Mail) + 4); sTradeMenuData->bufferPartyState++; break; case 15: @@ -1065,7 +1065,7 @@ static bool8 BufferTradeParties(void) case 16: if (_GetBlockReceivedStatus() == 3) { - Trade_Memcpy(gTradeMail, gBlockRecvBuffer[id ^ 1], PARTY_SIZE * sizeof(struct MailStruct)); + Trade_Memcpy(gTradeMail, gBlockRecvBuffer[id ^ 1], PARTY_SIZE * sizeof(struct Mail)); TradeResetReceivedFlags(); sTradeMenuData->bufferPartyState++; } @@ -3043,18 +3043,16 @@ static void TradeMons(u8 playerPartyIdx, u8 partnerPartyIdx) u16 partnerMail = GetMonData(partnerMon, MON_DATA_MAIL); if (playerMail != MAIL_NONE) - ClearMailStruct(&gSaveBlock1Ptr->mail[playerMail]); + ClearMail(&gSaveBlock1Ptr->mail[playerMail]); - sTradeData->mon = *playerMon; - *playerMon = *partnerMon; - *partnerMon = sTradeData->mon; + SWAP(*playerMon, *partnerMon, sTradeData->tempMon); friendship = 70; if (!GetMonData(playerMon, MON_DATA_IS_EGG)) SetMonData(playerMon, MON_DATA_FRIENDSHIP, &friendship); if (partnerMail != MAIL_NONE) - GiveMailToMon2(playerMon, &gTradeMail[partnerMail]); + GiveMailToMon(playerMon, &gTradeMail[partnerMail]); UpdatePokedexForReceivedMon(playerPartyIdx); if (gReceivedRemoteLinkPlayers) @@ -4492,7 +4490,7 @@ static void _CreateInGameTradePokemon(u8 whichPlayerMon, u8 whichInGameTrade) const struct InGameTrade *inGameTrade = &sIngameTrades[whichInGameTrade]; u8 level = GetMonData(&gPlayerParty[whichPlayerMon], MON_DATA_LEVEL); - struct MailStruct mail; + struct Mail mail; u8 metLocation = METLOC_IN_GAME_TRADE; u8 isMail; struct Pokemon *pokemon = &gEnemyParty[0]; @@ -4535,7 +4533,7 @@ static void _CreateInGameTradePokemon(u8 whichPlayerMon, u8 whichInGameTrade) CalculateMonStats(&gEnemyParty[0]); } -static void SetInGameTradeMail(struct MailStruct *mail, const struct InGameTrade *trade) { +static void SetInGameTradeMail(struct Mail *mail, const struct InGameTrade *trade) { s32 i; for (i = 0; i < MAIL_WORDS_COUNT; i++) diff --git a/src/union_room.c b/src/union_room.c index db2d0247b..a889490f1 100644 --- a/src/union_room.c +++ b/src/union_room.c @@ -1495,14 +1495,14 @@ static void Task_StartUnionRoomTrade(u8 taskId) } break; case 2: - memcpy(gBlockSendBuffer, gSaveBlock1Ptr->mail, sizeof(struct MailStruct) * PARTY_SIZE + 4); - if (SendBlock(0, gBlockSendBuffer, sizeof(struct MailStruct) * PARTY_SIZE + 4)) + memcpy(gBlockSendBuffer, gSaveBlock1Ptr->mail, sizeof(struct Mail) * PARTY_SIZE + 4); + if (SendBlock(0, gBlockSendBuffer, sizeof(struct Mail) * PARTY_SIZE + 4)) gTasks[taskId].data[0]++; break; case 3: if (GetBlockReceivedStatus() == 3) { - memcpy(gTradeMail, gBlockRecvBuffer[GetMultiplayerId() ^ 1], sizeof(struct MailStruct) * PARTY_SIZE); + memcpy(gTradeMail, gBlockRecvBuffer[GetMultiplayerId() ^ 1], sizeof(struct Mail) * PARTY_SIZE); ResetBlockReceivedFlags(); gSelectedTradeMonPositions[TRADE_PLAYER] = monId; gSelectedTradeMonPositions[TRADE_PARTNER] = PARTY_SIZE;