diff options
author | Marcus Huderle <huderlem@gmail.com> | 2017-11-12 16:40:04 -0800 |
---|---|---|
committer | Marcus Huderle <huderlem@gmail.com> | 2017-11-12 16:40:04 -0800 |
commit | fbdf867ce7bce6239c34c53beaabbcd555302a4f (patch) | |
tree | 215f66989ae23e720917fe3d108f031bbfc230e0 | |
parent | 2e4c7d675cc25181996edcfb879ed9c6e41d0bcc (diff) |
Cleanup and document daycare.c
-rw-r--r-- | data/scripts/day_care.inc | 34 | ||||
-rw-r--r-- | data/specials.inc | 20 | ||||
-rw-r--r-- | include/daycare.h | 20 | ||||
-rw-r--r-- | include/flags.h | 3 | ||||
-rw-r--r-- | include/global.h | 12 | ||||
-rw-r--r-- | src/debug/mori_debug_menu.c | 20 | ||||
-rw-r--r-- | src/engine/record_mixing.c | 12 | ||||
-rw-r--r-- | src/field/daycare.c | 795 | ||||
-rw-r--r-- | src/field/field_control_avatar.c | 4 | ||||
-rw-r--r-- | src/pokemon/pokemon_summary_screen.c | 1 | ||||
-rw-r--r-- | src/scene/egg_hatch.c | 34 | ||||
-rw-r--r-- | src/script_pokemon_util_80C4BF0.c | 2 |
12 files changed, 532 insertions, 425 deletions
diff --git a/data/scripts/day_care.inc b/data/scripts/day_care.inc index f8151b86a..22d99f2a4 100644 --- a/data/scripts/day_care.inc +++ b/data/scripts/day_care.inc @@ -1,8 +1,8 @@ Route117_EventScript_1B222D:: @ 81B222D lock faceplayer - special sp0B5_daycare - specialvar RESULT, sp0B6_daycare + special GetDaycareMonNicknames + specialvar RESULT, GetDaycareState compare RESULT, 1 goto_if_eq Route117_EventScript_1B2262 compare RESULT, 2 @@ -22,7 +22,7 @@ Route117_EventScript_1B2262:: @ 81B2262 goto_if_eq Route117_EventScript_1B2298 msgbox Route117_Text_1B2745, 4 clearflag 134 - special sub_8041E7C + special RejectEggFromDayCare release end @@ -41,7 +41,7 @@ Route117_EventScript_1B22B2:: @ 81B22B2 waitmessage waitbutton msgbox Route117_Text_1B27CD, 4 - special sp0B8_daycare + special GiveEggFromDaycare clearflag 134 release end @@ -57,7 +57,7 @@ Route117_EventScript_1B22DE:: @ 81B22DE return Route117_EventScript_1B22E7:: @ 81B22E7 - special sp0B5_daycare + special GetDaycareMonNicknames msgbox Route117_Text_1B2710, 4 setvar 0x8004, 0 call Route117_EventScript_1B22CD @@ -65,9 +65,9 @@ Route117_EventScript_1B22E7:: @ 81B22E7 end Route117_EventScript_1B22FE:: @ 81B22FE - special sp0B5_daycare + special GetDaycareMonNicknames msgbox Route117_Text_1B2897, 4 - special sp0B9_daycare_relationship_comment + special SetDaycareCompatibilityString special ShowFieldMessageStringVar4 waitmessage waitbutton @@ -81,7 +81,7 @@ Route117_EventScript_1B22FE:: @ 81B22FE Route117_PokemonDayCare_EventScript_1B2327:: @ 81B2327 lock faceplayer - specialvar RESULT, sp0B6_daycare + specialvar RESULT, GetDaycareState compare RESULT, 1 goto_if_eq Route117_PokemonDayCare_EventScript_1B2407 compare RESULT, 2 @@ -108,14 +108,14 @@ Route117_PokemonDayCare_EventScript_1B236C:: @ 81B236C specialvar RESULT, sub_8095C10 compare RESULT, 0 goto_if_eq Route117_PokemonDayCare_EventScript_1B23FD - specialvar 0x8005, sub_8042328 + specialvar 0x8005, GetSelectedDaycareMonNickname waitse playpokecry 0x8005, 0 msgbox Route117_PokemonDayCare_Text_1B296E, 4 waitpokecry - special Daycare_SendPokemon_Special + special StoreSelectedPokemonInDaycare incrementgamestat GAME_STAT_USED_DAYCARE - specialvar RESULT, sp0B6_daycare + specialvar RESULT, GetDaycareState compare RESULT, 2 goto_if_eq Route117_PokemonDayCare_EventScript_1B23DA release @@ -153,7 +153,7 @@ Route117_PokemonDayCare_EventScript_1B2411:: @ 81B2411 return Route117_PokemonDayCare_EventScript_1B241A:: @ 81B241A - specialvar RESULT, sub_80417B8 + specialvar RESULT, GetNumLevelsGainedFromDaycare compare RESULT, 0 call_if 5, Route117_PokemonDayCare_EventScript_1B2411 return @@ -175,7 +175,7 @@ Route117_PokemonDayCare_EventScript_1B2469:: @ 81B2469 specialvar RESULT, CalculatePlayerPartyCount compare RESULT, 6 goto_if_eq Route117_PokemonDayCare_EventScript_1B2539 - specialvar RESULT, sp0B6_daycare + specialvar RESULT, GetDaycareState setvar 0x8004, 0 compare RESULT, 2 goto_if_eq Route117_PokemonDayCare_EventScript_1B24A8 @@ -188,7 +188,7 @@ Route117_PokemonDayCare_EventScript_1B2469:: @ 81B2469 end Route117_PokemonDayCare_EventScript_1B24A8:: @ 81B24A8 - special sub_8041770 + special GetDaycareCost msgbox Route117_PokemonDayCare_Text_1B2B49, 5 compare RESULT, 1 goto_if_eq Route117_PokemonDayCare_EventScript_1B24C4 @@ -206,7 +206,7 @@ Route117_PokemonDayCare_EventScript_1B24C4:: @ 81B24C4 Route117_PokemonDayCare_EventScript_1B24DE:: @ 81B24DE applymovement 1, Route117_PokemonDayCare_Movement_1B2543 waitmovement 0 - specialvar RESULT, sub_8041648 + specialvar RESULT, TakePokemonFromDaycare special sub_80B7D0C playse 95 msgbox Route117_PokemonDayCare_Text_1B2B75, 4 @@ -214,7 +214,7 @@ Route117_PokemonDayCare_EventScript_1B24DE:: @ 81B24DE playpokecry RESULT, 0 msgbox Route117_PokemonDayCare_Text_1B2B93, 4 waitpokecry - specialvar RESULT, sp0B6_daycare + specialvar RESULT, GetDaycareState compare RESULT, 2 goto_if_eq Route117_PokemonDayCare_EventScript_1B2520 goto Route117_PokemonDayCare_EventScript_1B23D0 @@ -276,7 +276,7 @@ Route117_PokemonDayCare_EventScript_1B2558:: @ 81B2558 compare RESULT, 2 goto_if_eq Route117_PokemonDayCare_EventScript_1B23D0 copyvar 0x8004, RESULT - specialvar RESULT, sub_8041648 + specialvar RESULT, TakePokemonFromDaycare msgbox Route117_PokemonDayCare_Text_1B2B75, 4 msgbox Route117_PokemonDayCare_Text_1B2A76, 4 release diff --git a/data/specials.inc b/data/specials.inc index 0b3648c4a..efa8da174 100644 --- a/data/specials.inc +++ b/data/specials.inc @@ -188,18 +188,18 @@ gSpecials:: def_special sub_80BDD18 def_special GabbyAndTySetScriptVarsToFieldObjectLocalIds def_special sub_810E300 - def_special sp0B5_daycare - def_special sp0B6_daycare - def_special sub_8041E7C - def_special sp0B8_daycare - def_special sp0B9_daycare_relationship_comment - def_special sub_8042328 - def_special Daycare_SendPokemon_Special + def_special GetDaycareMonNicknames + def_special GetDaycareState + def_special RejectEggFromDayCare + def_special GiveEggFromDaycare + def_special SetDaycareCompatibilityString + def_special GetSelectedDaycareMonNickname + def_special StoreSelectedPokemonInDaycare def_special ChooseSendDaycareMon def_special ShowDaycareLevelMenu - def_special sub_80417B8 - def_special sub_8041770 - def_special sub_8041648 + def_special GetNumLevelsGainedFromDaycare + def_special GetDaycareCost + def_special TakePokemonFromDaycare def_special ScriptHatchMon def_special EggHatch def_special sub_8042B4C diff --git a/include/daycare.h b/include/daycare.h index e46351d72..c612113b9 100644 --- a/include/daycare.h +++ b/include/daycare.h @@ -1,15 +1,17 @@ #ifndef GUARD_DAYCARE_H #define GUARD_DAYCARE_H -u8 Daycare_CountPokemon(struct DayCareData *); -void sub_8041324(struct BoxPokemon *, struct RecordMixingDayCareMail *); -void sub_8041790(u16 i); -u16 sub_8041870(u16); -void sub_8041940(void); -void sub_8041950(void); -void sub_8042044(struct Pokemon *mon, u16, u8); -u8 sub_80422A0(void); -u8 daycare_relationship_score_from_savegame(void); +u8 *GetMonNick(struct Pokemon *, u8 *); +u8 *GetBoxMonNick(struct BoxPokemon *, u8 *); +u8 CountPokemonInDaycare(struct DayCare *); +void InitDaycareMailRecordMixing(struct BoxPokemon *, struct RecordMixingDayCareMail *); +void Debug_AddDaycareSteps(u16 i); +u16 GetEggSpecies(u16); +void TriggerPendingDaycareEgg(void); +void TriggerPendingDaycareMaleEgg(void); +void CreateEgg(struct Pokemon *mon, u16, u8); +u8 ShouldEggHatch(void); +u8 GetDaycareCompatibilityScoreFromSave(void); bool8 NameHasGenderSymbol(const u8 *, u8); #endif // GUARD_DAYCARE_H diff --git a/include/flags.h b/include/flags.h index a60de6ea0..83fcdb383 100644 --- a/include/flags.h +++ b/include/flags.h @@ -1,6 +1,9 @@ #ifndef GUARD_FLAGS_H #define GUARD_FLAGS_H +// scripts +#define FLAG_PENDING_DAYCARE_EGG 0x86 + #define TRAINER_FLAG_START 0x500 // SYSTEM FLAGS diff --git a/include/global.h b/include/global.h index 647f66bc8..4921cf977 100644 --- a/include/global.h +++ b/include/global.h @@ -587,15 +587,15 @@ struct DayCareMail struct DayCareStepCountersEtc { u32 steps[2]; - u16 personalityLo; - u8 unk_11a; + u16 pendingEggPersonality; + u8 eggCycleStepsRemaining; }; struct RecordMixingDayCareMail { struct DayCareMail mail[2]; - u32 unk70; - u16 unk74[2]; + u32 numDaycareMons; + u16 itemsHeld[2]; // marks whether or not each daycare mon is currently holding an item. }; struct DayCareMisc @@ -604,7 +604,7 @@ struct DayCareMisc struct DayCareStepCountersEtc countersEtc; }; -struct DayCareData { +struct DayCare { struct BoxPokemon mons[2]; struct DayCareMisc misc; }; @@ -712,7 +712,7 @@ struct SaveBlock1 /* 0x02025734 */ /*0x2DD4*/ struct EasyChatPair easyChatPairs[5]; //Dewford trend [0] and some other stuff /*0x2DFC*/ u8 filler_2DFC[0x8]; /*0x2E04*/ SB_Struct sbStruct; - /*0x2F9C*/ struct DayCareData daycareData; + /*0x2F9C*/ struct DayCare daycare; /*0x30B8*/ struct LinkBattleRecord linkBattleRecords[5]; /*0x3108*/ u8 filler_3108[8]; /*0x3110*/ u8 giftRibbons[11]; diff --git a/src/debug/mori_debug_menu.c b/src/debug/mori_debug_menu.c index 1595ecd2e..e6ee243e8 100644 --- a/src/debug/mori_debug_menu.c +++ b/src/debug/mori_debug_menu.c @@ -50,13 +50,13 @@ u8 MoriDebugMenu_SearchChild(u8 a1, u8 a2, u8 *ptr) { u8 localPtr[52]; u16 monData; - u16 var; + u16 eggSpecies; monData = GetMonData(gPlayerParty, MON_DATA_SPECIES, ptr); - var = sub_8041870(monData); + eggSpecies = GetEggSpecies(monData); StringCopy(localPtr, gSpeciesNames[monData]); StringAppend(localPtr, gUnknown_0839B24D); - StringAppend(localPtr, gSpeciesNames[var]); + StringAppend(localPtr, gSpeciesNames[eggSpecies]); StringAppend(localPtr, gUnknown_0839B255); MenuZeroFillScreen(); MenuDrawTextWindow(0, 14, 30, 19); @@ -67,8 +67,8 @@ u8 MoriDebugMenu_SearchChild(u8 a1, u8 a2, u8 *ptr) s8 MoriDebugMenu_Egg(void) { - if ( Daycare_CountPokemon(&gSaveBlock1.daycareData) == 2 && daycare_relationship_score_from_savegame() ) - sub_8041940(); + if (CountPokemonInDaycare(&gSaveBlock1.daycare) == 2 && GetDaycareCompatibilityScoreFromSave() ) + TriggerPendingDaycareEgg(); CloseMenu(); return 1; @@ -76,8 +76,8 @@ s8 MoriDebugMenu_Egg(void) s8 MoriDebugMenu_MaleEgg(void) { - if ( Daycare_CountPokemon(&gSaveBlock1.daycareData) == 2 && daycare_relationship_score_from_savegame() ) - sub_8041950(); + if (CountPokemonInDaycare(&gSaveBlock1.daycare) == 2 && GetDaycareCompatibilityScoreFromSave() ) + TriggerPendingDaycareMaleEgg(); CloseMenu(); return 1; @@ -85,14 +85,14 @@ s8 MoriDebugMenu_MaleEgg(void) s8 MoriDebugMenu_1000Steps(void) { - sub_8041790(1000); + Debug_AddDaycareSteps(1000); CloseMenu(); return 1; } s8 MoriDebugMenu_10000Steps(void) { - sub_8041790(10000); + Debug_AddDaycareSteps(10000); CloseMenu(); return 1; } @@ -117,7 +117,7 @@ s8 MoriDebugMenu_BreedEgg(void) SetMonData(&gPlayerParty[loopCounter], MON_DATA_FRIENDSHIP, &friendship); } } - gSaveBlock1.daycareData.misc.countersEtc.unk_11a = -3; + gSaveBlock1.daycare.misc.countersEtc.eggCycleStepsRemaining = -3; CloseMenu(); return 1; } diff --git a/src/engine/record_mixing.c b/src/engine/record_mixing.c index 3ae0c4ea3..b30d57a4d 100644 --- a/src/engine/record_mixing.c +++ b/src/engine/record_mixing.c @@ -71,9 +71,9 @@ void RecordMixing_PrepareExchangePacket(void) memcpy(ewram_2018000.filler1004, gUnknown_083D0274, sizeof(ewram_2008000.filler1004)); memcpy(ewram_2018000.filler1044, gUnknown_083D0278, sizeof(ewram_2008000.filler1044)); memcpy(ewram_2018000.easyChatPairs, recordMixingEasyChatPairs, sizeof(ewram_2018000.easyChatPairs)); - gUnknown_02038738.mail[0] = gSaveBlock1.daycareData.misc.mail[0]; - gUnknown_02038738.mail[1] = gSaveBlock1.daycareData.misc.mail[1]; - sub_8041324(gSaveBlock1.daycareData.mons, &gUnknown_02038738); + gUnknown_02038738.mail[0] = gSaveBlock1.daycare.misc.mail[0]; + gUnknown_02038738.mail[1] = gSaveBlock1.daycare.misc.mail[1]; + InitDaycareMailRecordMixing(gSaveBlock1.daycare.mons, &gUnknown_02038738); memcpy(&ewram_2018000.filler10AC, gUnknown_083D0280, sizeof(struct RecordMixingDayCareMail)); memcpy(&ewram_2018000.battleTowerRecord, gBattleTowerPlayerRecord, sizeof(struct BattleTowerRecord)); @@ -524,11 +524,11 @@ void sub_80B9C6C(u8 *a, u32 b, u8 c, void *d) for (i = 0; i < r8; i++) { r6 = (struct DayCareMisc *)(a + b * i); - if (r6->unk70 != 0) + if (r6->numDaycareMons != 0) { - for (r7 = 0; r7 < r6->unk70; r7++) + for (r7 = 0; r7 < r6->numDaycareMons; r7++) { - if (r6->unk74[r7] == 0) + if (r6->itemsHeld[r7] == 0) sp1C[i][r7] = 1; } } diff --git a/src/field/daycare.c b/src/field/daycare.c index dd74f59e0..2b58a0d5d 100644 --- a/src/field/daycare.c +++ b/src/field/daycare.c @@ -1,47 +1,50 @@ #include "global.h" #include "daycare.h" -#include "pokemon.h" #include "event_data.h" -#include "species.h" +#include "field_effect.h" #include "items.h" -#include "text.h" -#include "string_util.h" #include "mail_data.h" +#include "main.h" +#include "menu.h" +#include "moves.h" #include "name_string_util.h" +#include "overworld.h" +#include "party_menu.h" +#include "pokemon.h" #include "pokemon_storage_system.h" #include "rng.h" -#include "moves.h" -#include "trade.h" -#include "strings2.h" -#include "party_menu.h" -#include "field_effect.h" -#include "main.h" -#include "menu.h" -#include "sound.h" -#include "songs.h" #include "script.h" -#include "overworld.h" +#include "songs.h" +#include "sound.h" +#include "species.h" +#include "string_util.h" +#include "strings2.h" +#include "text.h" +#include "trade.h" -IWRAM_DATA u16 gUnknown_03000470[52]; -IWRAM_DATA u16 gUnknown_030004D8[4]; -IWRAM_DATA u16 gUnknown_030004E0[4]; -IWRAM_DATA u16 gUnknown_030004E8[12]; -IWRAM_DATA u16 gUnknown_03000500[4]; +// RAM buffers used to assist with BuildEggMoveset() +IWRAM_DATA u16 gHatchedEggLevelUpMoves[52]; +IWRAM_DATA u16 gHatchedEggFatherMoves[4]; +IWRAM_DATA u16 gHatchedEggFinalMoves[4]; +IWRAM_DATA u16 gHatchedEggEggMoves[12]; +IWRAM_DATA u16 gHatchedEggMotherMoves[4]; -static void sub_80417F4(struct DayCareMail *); -static void sub_80420FC(struct Pokemon *, u16, struct DayCareData *); -static u8 daycare_relationship_score(struct DayCareData *); +extern u16 gMoveToLearn; + +static void ClearDaycareMail(struct DayCareMail *); +static void SetInitialEggData(struct Pokemon *, u16, struct DayCare *); +static u8 GetDaycareCompatibilityScore(struct DayCare *); #include "../data/pokemon/egg_moves.h" -const u8 *const gUnknown_08209AC4[] = { +static const u8 *const sCompatibilityMessages[] = { DaycareText_GetAlongVeryWell, DaycareText_GetAlong, DaycareText_DontLikeOther, DaycareText_PlayOther }; -const u8 gUnknown_08209AD4[] = _("タマゴ"); +const u8 sJapaneseEggNickname[] = _("タマゴ"); u8 *GetMonNick(struct Pokemon *mon, u8 *dest) { @@ -59,251 +62,284 @@ u8 *GetBoxMonNick(struct BoxPokemon *mon, u8 *dest) return StringCopy10(dest, nickname); } -u8 Daycare_CountPokemon(struct DayCareData *daycare_data) +u8 CountPokemonInDaycare(struct DayCare *daycare) { u8 i, count; count = 0; - for(i = 0;i <= 1;i++) - if(GetBoxMonData(&daycare_data->mons[i], MON_DATA_SPECIES) != 0) + for (i = 0; i < 2; i++) + { + if (GetBoxMonData(&daycare->mons[i], MON_DATA_SPECIES) != 0) count++; + } return count; } -void sub_8041324(struct BoxPokemon * box_pokemon, struct RecordMixingDayCareMail * daycareMailEtc) +void InitDaycareMailRecordMixing(struct BoxPokemon * daycareMons, struct RecordMixingDayCareMail * daycareMail) { u8 i; - u8 specCount; - specCount = 0; - for (i=0; i<2; i++) + u8 numDaycareMons = 0; + + for (i = 0; i < 2; i++) { - if (GetBoxMonData(&box_pokemon[i], MON_DATA_SPECIES) != SPECIES_NONE) + if (GetBoxMonData(&daycareMons[i], MON_DATA_SPECIES) != SPECIES_NONE) { - specCount ++; - if (GetBoxMonData(&box_pokemon[i], MON_DATA_HELD_ITEM) == ITEM_NONE) + numDaycareMons++; + if (GetBoxMonData(&daycareMons[i], MON_DATA_HELD_ITEM) == ITEM_NONE) { - daycareMailEtc->unk74[i] = 0; - } else + daycareMail->itemsHeld[i] = 0; + } + else { - daycareMailEtc->unk74[i] = 1; + daycareMail->itemsHeld[i] = 1; } - } else + } + else { - daycareMailEtc->unk74[i] = 1; + daycareMail->itemsHeld[i] = 1; } } - daycareMailEtc->unk70 = specCount; + + daycareMail->numDaycareMons = numDaycareMons; } -static s8 Daycare_FindEmptySpot(struct BoxPokemon * daycare_data) +static s8 Daycare_FindEmptySpot(struct BoxPokemon * daycareMons) { u8 i; - for(i = 0;i <= 1;i++) - if(GetBoxMonData(daycare_data + i, MON_DATA_SPECIES) == 0) + for (i = 0; i < 2; i++) + { + if (GetBoxMonData(&daycareMons[i], MON_DATA_SPECIES) == 0) return i; + } return -1; } -static void Daycare_SendPokemon(struct Pokemon * mon, struct DayCareData * daycare_data) +static void StorePokemonInDaycare(struct Pokemon * mon, struct DayCare * daycare) { - s8 empty_slot; + s8 emptySlot; u8 mail; u8 *names; - empty_slot = Daycare_FindEmptySpot(daycare_data->mons); - if(MonHasMail(mon)) { - StringCopy((names = daycare_data->misc.mail[empty_slot].names), gSaveBlock2.playerName); + emptySlot = Daycare_FindEmptySpot(daycare->mons); + if (MonHasMail(mon)) + { + StringCopy((names = daycare->misc.mail[emptySlot].names), gSaveBlock2.playerName); PadNameString(names, 0xFC); names += 8; GetMonNick(mon, names); mail = GetMonData(mon, MON_DATA_MAIL); - daycare_data->misc.mail[empty_slot].message = gSaveBlock1.mail[mail]; + daycare->misc.mail[emptySlot].message = gSaveBlock1.mail[mail]; TakeMailFromMon(mon); } - daycare_data->mons[empty_slot] = mon->box; - BoxMonRestorePP(&daycare_data->mons[empty_slot]); - daycare_data->misc.countersEtc.steps[empty_slot] = 0; + + daycare->mons[emptySlot] = mon->box; + BoxMonRestorePP(&daycare->mons[emptySlot]); + daycare->misc.countersEtc.steps[emptySlot] = 0; ZeroMonData(mon); party_compaction(); CalculatePlayerPartyCount(); } -void Daycare_SendPokemon_Special() +void StoreSelectedPokemonInDaycare(void) { - Daycare_SendPokemon(gPlayerParty + gLastFieldPokeMenuOpened, &gSaveBlock1.daycareData); + StorePokemonInDaycare(&gPlayerParty[gLastFieldPokeMenuOpened], &gSaveBlock1.daycare); } -static void sub_80414C0(struct DayCareData * daycare_data) +// Shifts the second daycare pokemon slot into the first slot. +static void ShiftDaycareSlots(struct DayCare * daycare) { - if((GetBoxMonData(&daycare_data->mons[1], MON_DATA_SPECIES) != 0) && GetBoxMonData(&daycare_data->mons[0], MON_DATA_SPECIES) == 0) + // This condition is only satisfied when the player takes out the first pokemon from the daycare. + if (GetBoxMonData(&daycare->mons[1], MON_DATA_SPECIES) != 0 && GetBoxMonData(&daycare->mons[0], MON_DATA_SPECIES) == 0) { - daycare_data->mons[0] = daycare_data->mons[1]; - ZeroBoxMonData(&daycare_data->mons[1]); - daycare_data->misc.mail[0] = daycare_data->misc.mail[1]; - daycare_data->misc.countersEtc.steps[0] = daycare_data->misc.countersEtc.steps[1]; - daycare_data->misc.countersEtc.steps[1] = 0; - sub_80417F4(&daycare_data->misc.mail[1]); + daycare->mons[0] = daycare->mons[1]; + ZeroBoxMonData(&daycare->mons[1]); + + daycare->misc.mail[0] = daycare->misc.mail[1]; + daycare->misc.countersEtc.steps[0] = daycare->misc.countersEtc.steps[1]; + daycare->misc.countersEtc.steps[1] = 0; + ClearDaycareMail(&daycare->misc.mail[1]); } } -u8 TryIncrementMonLevel(struct Pokemon *); -extern u16 gMoveToLearn; - -static void DayCare_LevelUpMoves(struct Pokemon * mon) +static void ApplyDaycareExperience(struct Pokemon * mon) { s32 i; - u8 r6; - u16 temp; + bool8 firstMove; + u16 learnedMove; for (i = 0; i < MAX_LEVEL; i++) { + // Add the mon's gained daycare experience level by level until it can't level up anymore. if (TryIncrementMonLevel(mon)) { - r6 = 1; - while ((temp = MonTryLearningNewMove(mon, r6)) != 0) + // Teach the mon new moves it learned while in the daycare. + firstMove = TRUE; + while ((learnedMove = MonTryLearningNewMove(mon, firstMove)) != 0) { - r6 = 0; - if (temp == 0xffff) + firstMove = FALSE; + if (learnedMove == 0xffff) + { + // Mon already knows 4 moves. DeleteFirstMoveAndGiveMoveToMon(mon, gMoveToLearn); + } } } else + { break; + } } + // Re-calculate the mons stats at its new level. CalculateMonStats(mon); } -static u16 sub_8041570(struct DayCareData * daycare_data, u8 slot) +static u16 TakeSelectedPokemonFromDaycare(struct DayCare * daycare, u8 slot) { u16 species; u32 experience; struct Pokemon pokemon; - GetBoxMonNick(&daycare_data->mons[slot], gStringVar1); - species = GetBoxMonData(&daycare_data->mons[slot], MON_DATA_SPECIES); - sub_803B4B4(&daycare_data->mons[slot], &pokemon); + GetBoxMonNick(&daycare->mons[slot], gStringVar1); + species = GetBoxMonData(&daycare->mons[slot], MON_DATA_SPECIES); + sub_803B4B4(&daycare->mons[slot], &pokemon); + if (GetMonData(&pokemon, MON_DATA_LEVEL) != MAX_LEVEL) { - experience = GetMonData(&pokemon, MON_DATA_EXP) + daycare_data->misc.countersEtc.steps[slot]; + experience = GetMonData(&pokemon, MON_DATA_EXP) + daycare->misc.countersEtc.steps[slot]; SetMonData(&pokemon, MON_DATA_EXP, &experience); - DayCare_LevelUpMoves(&pokemon); + ApplyDaycareExperience(&pokemon); } + gPlayerParty[PARTY_SIZE - 1] = pokemon; - if (daycare_data->misc.mail[slot].message.itemId) + if (daycare->misc.mail[slot].message.itemId) { - GiveMailToMon2(&gPlayerParty[PARTY_SIZE - 1], &daycare_data->misc.mail[slot].message); - sub_80417F4(&daycare_data->misc.mail[slot]); + GiveMailToMon2(&gPlayerParty[PARTY_SIZE - 1], &daycare->misc.mail[slot].message); + ClearDaycareMail(&daycare->misc.mail[slot]); } + party_compaction(); - ZeroBoxMonData(&daycare_data->mons[slot]); - daycare_data->misc.countersEtc.steps[slot] = 0; - sub_80414C0(daycare_data); + ZeroBoxMonData(&daycare->mons[slot]); + daycare->misc.countersEtc.steps[slot] = 0; + ShiftDaycareSlots(daycare); CalculatePlayerPartyCount(); return species; } -u16 sub_8041648() +u16 TakePokemonFromDaycare(void) { - return sub_8041570(&gSaveBlock1.daycareData, gSpecialVar_0x8004); + return TakeSelectedPokemonFromDaycare(&gSaveBlock1.daycare, gSpecialVar_0x8004); } -u8 Daycare_GetLevelAfterSteps(struct BoxPokemon * mon, u32 steps){ - struct BoxPokemon temp = *mon; - u32 new_exp = GetBoxMonData(mon, MON_DATA_EXP) + steps; - SetBoxMonData(&temp, MON_DATA_EXP, &new_exp); - return GetLevelFromBoxMonExp(&temp); +static u8 GetLevelAfterDaycareSteps(struct BoxPokemon * mon, u32 steps) +{ + struct BoxPokemon tempMon = *mon; + + u32 experience = GetBoxMonData(mon, MON_DATA_EXP) + steps; + SetBoxMonData(&tempMon, MON_DATA_EXP, &experience); + return GetLevelFromBoxMonExp(&tempMon); } -static u8 sub_80416A0(struct DayCareData *daycareData, u8 slot) +static u8 GetNumLevelsGainedFromSteps(struct DayCare *daycare, u8 slot) { u8 levelBefore; u8 levelAfter; - levelBefore = GetLevelFromBoxMonExp(&daycareData->mons[slot]); - levelAfter = Daycare_GetLevelAfterSteps(&daycareData->mons[slot], daycareData->misc.countersEtc.steps[slot]); + levelBefore = GetLevelFromBoxMonExp(&daycare->mons[slot]); + levelAfter = GetLevelAfterDaycareSteps(&daycare->mons[slot], daycare->misc.countersEtc.steps[slot]); return levelAfter - levelBefore; } -static u8 sub_80416E8(struct DayCareData *dayCareData, u8 slot) +static u8 GetNumLevelsGainedForDaycareSlot(struct DayCare *daycare, u8 slot) { - u8 levelDelta = sub_80416A0(dayCareData, slot); - GetBoxMonNick(&dayCareData->mons[slot], gStringVar1); - ConvertIntToDecimalStringN(gStringVar2, levelDelta, STR_CONV_MODE_LEFT_ALIGN, 2); - return levelDelta; + u8 numLevelsGained = GetNumLevelsGainedFromSteps(daycare, slot); + GetBoxMonNick(&daycare->mons[slot], gStringVar1); + ConvertIntToDecimalStringN(gStringVar2, numLevelsGained, STR_CONV_MODE_LEFT_ALIGN, 2); + return numLevelsGained; } -static u16 sub_8041728(struct DayCareData *dayCareData, u8 slot) +static u16 GetDaycareCostForSelectedMon(struct DayCare *daycare, u8 slot) { u16 cost; - u8 levelDelta = sub_80416A0(dayCareData, slot); - GetBoxMonNick(&dayCareData->mons[slot], gStringVar1); - cost = 100 + 100 * levelDelta; + u8 numLevelsGained = GetNumLevelsGainedFromSteps(daycare, slot); + GetBoxMonNick(&daycare->mons[slot], gStringVar1); + cost = 100 + 100 * numLevelsGained; ConvertIntToDecimalStringN(gStringVar2, cost, STR_CONV_MODE_LEFT_ALIGN, 5); return cost; } -void sub_8041770(void) +void GetDaycareCost(void) { - gSpecialVar_0x8005 = sub_8041728(&gSaveBlock1.daycareData, gSpecialVar_0x8004); + gSpecialVar_0x8005 = GetDaycareCostForSelectedMon(&gSaveBlock1.daycare, gSpecialVar_0x8004); } -void sub_8041790(u16 i) +void Debug_AddDaycareSteps(u16 numSteps) { - gSaveBlock1.daycareData.misc.countersEtc.steps[0] += i; - gSaveBlock1.daycareData.misc.countersEtc.steps[1] += i; + gSaveBlock1.daycare.misc.countersEtc.steps[0] += numSteps; + gSaveBlock1.daycare.misc.countersEtc.steps[1] += numSteps; } -u8 sub_80417B8(void) +u8 GetNumLevelsGainedFromDaycare(void) { - if (GetBoxMonData(&gSaveBlock1.daycareData.mons[gSpecialVar_0x8004], MON_DATA_SPECIES) != 0) - return sub_80416E8(&gSaveBlock1.daycareData, gSpecialVar_0x8004); + if (GetBoxMonData(&gSaveBlock1.daycare.mons[gSpecialVar_0x8004], MON_DATA_SPECIES) != 0) + return GetNumLevelsGainedForDaycareSlot(&gSaveBlock1.daycare, gSpecialVar_0x8004); + return 0; } -static void sub_80417F4(struct DayCareMail *mail) +static void ClearDaycareMail(struct DayCareMail *mail) { - u8 zero; u8 *names; u8 *names2; - int i; - zero = 0; - for (i = 7, names = mail->names + 7; i >= 0; i --) + s32 i; + u8 zero = 0; + + for (i = 7, names = &mail->names[7]; i >= 0; i--) + { *names-- = zero; - names2 = mail->names + 8; + } + + names2 = &mail->names[8]; zero = 0; - names = mail->names + 18; - do *names-- = zero; while ((int)names >= (int)names2); + names = &mail->names[18]; + do *names-- = zero; while ((s32)names >= (s32)names2); ClearMailStruct(&mail->message); } -void unref_sub_8041824(struct DayCareData *dayCareData) +void unref_sub_8041824(struct DayCare *daycare) { u8 slot; - for (slot = 0; slot < ARRAY_COUNT(dayCareData->mons); slot ++) + for (slot = 0; slot < ARRAY_COUNT(daycare->mons); slot++) { - ZeroBoxMonData(&dayCareData->mons[slot]); - dayCareData->misc.countersEtc.steps[slot] = 0; - sub_80417F4(&dayCareData->misc.mail[slot]); + ZeroBoxMonData(&daycare->mons[slot]); + daycare->misc.countersEtc.steps[slot] = 0; + ClearDaycareMail(&daycare->misc.mail[slot]); } - dayCareData->misc.countersEtc.personalityLo = 0; - dayCareData->misc.countersEtc.unk_11a = 0; + + daycare->misc.countersEtc.pendingEggPersonality = 0; + daycare->misc.countersEtc.eggCycleStepsRemaining = 0; } -u16 sub_8041870(u16 species) +// Determines what the species of an Egg would be based on the given species. +// It determines this by working backwards through the evolution chain of the +// given species. +u16 GetEggSpecies(u16 species) { int i, j, k; bool8 found; - for (i = 0; i < 5; i ++) + + // Working backwards up to 5 times seems arbitrary, since the maximum number + // of times would only be 3 for 3-stage evolutions. + for (i = 0; i < 5; i++) { found = FALSE; - for (j = 1; j < NUM_SPECIES; j ++) + for (j = 1; j < NUM_SPECIES; j++) { - for (k = 0; k < 5; k ++) + for (k = 0; k < 5; k++) { if (gEvolutionTable[j].evolutions[k].targetSpecies == species) { @@ -312,92 +348,118 @@ u16 sub_8041870(u16 species) break; } } + if (found) break; } - if (j == 412) + + if (j == NUM_SPECIES) break; } + return species; } -static void sub_80418F0(struct DayCareData *dayCareData) +static void _TriggerPendingDaycareEgg(struct DayCare *daycare) { - dayCareData->misc.countersEtc.personalityLo = (Random() % 0xfffe) + 1; - FlagSet(0x86); + daycare->misc.countersEtc.pendingEggPersonality = (Random() % 0xfffe) + 1; + FlagSet(FLAG_PENDING_DAYCARE_EGG); } -static void sub_804191C(struct DayCareData *dayCareData) +static void _TriggerPendingDaycareMaleEgg(struct DayCare *daycare) { - dayCareData->misc.countersEtc.personalityLo = Random() | 0x8000; - FlagSet(0x86); + daycare->misc.countersEtc.pendingEggPersonality = Random() | 0x8000; + FlagSet(FLAG_PENDING_DAYCARE_EGG); } -void sub_8041940(void) +void TriggerPendingDaycareEgg(void) { - sub_80418F0(&gSaveBlock1.daycareData); + _TriggerPendingDaycareEgg(&gSaveBlock1.daycare); } -void sub_8041950(void) +void TriggerPendingDaycareMaleEgg(void) { - sub_804191C(&gSaveBlock1.daycareData); + _TriggerPendingDaycareMaleEgg(&gSaveBlock1.daycare); } -static void sub_8041960(u8 *data, u8 idx) +// Removes the selected index from the given IV list and shifts the remaining +// elements to the left. +static void RemoveIVIndexFromList(u8 *ivs, u8 selectedIv) { - int i, j; - u8 temp[6]; - data[idx] = 0xff; - for (i = 0; i < 6; i ++) - temp[i] = data[i]; + s32 i, j; + u8 temp[NUM_STATS]; + + ivs[selectedIv] = 0xff; + for (i = 0; i < NUM_STATS; i++) + { + temp[i] = ivs[i]; + } + j = 0; - for (i = 0; i < 6; i ++) + for (i = 0; i < NUM_STATS; i++) + { if (temp[i] != 0xff) - data[j++] = temp[i]; + ivs[j++] = temp[i]; + } } -static void InheritIVs(struct Pokemon *egg, struct DayCareData *dayCareData) +static void InheritIVs(struct Pokemon *egg, struct DayCare *daycare) { u8 i; u8 selectedIvs[3]; - u8 allIvs[6]; - u8 whichParent[3]; + u8 availableIVs[NUM_STATS]; + u8 whichParent[ARRAY_COUNT(selectedIvs)]; u8 iv; - for (i = 0; i < 6; i ++) - allIvs[i] = i; - for (i = 0; i < 3; i ++) + + // Initialize a list of IV indices. + for (i = 0; i < NUM_STATS; i++) { - selectedIvs[i] = allIvs[Random() % (6 - i)]; - sub_8041960(allIvs, selectedIvs[i]); + availableIVs[i] = i; } - for (i = 0; i < 3; i ++) + + // Select the 3 IVs that will be inherited. + for (i = 0; i < ARRAY_COUNT(selectedIvs); i++) + { + // Randomly pick an IV from the available list. + selectedIvs[i] = availableIVs[Random() % (NUM_STATS - i)]; + + // Remove the selected IV index from the available IV indicies. + RemoveIVIndexFromList(availableIVs, selectedIvs[i]); + } + + // Determine which parent each of the selected IVs should inherit from. + for (i = 0; i < ARRAY_COUNT(selectedIvs); i++) + { whichParent[i] = Random() % 2; - for (i = 0; i < 3; i ++) + } + + // Set each of inherited IVs on the egg mon. + for (i = 0; i < ARRAY_COUNT(selectedIvs); i++) { switch (selectedIvs[i]) { case 0: - iv = GetBoxMonData(&dayCareData->mons[whichParent[i]], MON_DATA_HP_IV); + iv = GetBoxMonData(&daycare->mons[whichParent[i]], MON_DATA_HP_IV); SetMonData(egg, MON_DATA_HP_IV, &iv); break; case 1: - iv = GetBoxMonData(&dayCareData->mons[whichParent[i]], MON_DATA_ATK_IV); + iv = GetBoxMonData(&daycare->mons[whichParent[i]], MON_DATA_ATK_IV); SetMonData(egg, MON_DATA_ATK_IV, &iv); break; case 2: - iv = GetBoxMonData(&dayCareData->mons[whichParent[i]], MON_DATA_DEF_IV); + iv = GetBoxMonData(&daycare->mons[whichParent[i]], MON_DATA_DEF_IV); SetMonData(egg, MON_DATA_DEF_IV, &iv); break; case 3: - iv = GetBoxMonData(&dayCareData->mons[whichParent[i]], MON_DATA_SPEED_IV); + iv = GetBoxMonData(&daycare->mons[whichParent[i]], MON_DATA_SPEED_IV); SetMonData(egg, MON_DATA_SPEED_IV, &iv); break; case 4: - iv = GetBoxMonData(&dayCareData->mons[whichParent[i]], MON_DATA_SPATK_IV); + iv = GetBoxMonData(&daycare->mons[whichParent[i]], MON_DATA_SPATK_IV); SetMonData(egg, MON_DATA_SPATK_IV, &iv); break; case 5: - iv = GetBoxMonData(&dayCareData->mons[whichParent[i]], MON_DATA_SPDEF_IV); + iv = GetBoxMonData(&daycare->mons[whichParent[i]], MON_DATA_SPDEF_IV); SetMonData(egg, MON_DATA_SPDEF_IV, &iv); break; } @@ -407,17 +469,19 @@ static void InheritIVs(struct Pokemon *egg, struct DayCareData *dayCareData) #ifdef NONMATCHING static #endif -u8 pokemon_get_eggmoves(struct Pokemon *pokemon, u16 *eggMoves) +// Counts the number of egg moves a pokemon learns and stores the moves in +// the given array. +u8 GetEggMoves(struct Pokemon *pokemon, u16 *eggMoves) { u16 eggMoveIdx; - u16 numMovesFound; + u16 numEggMoves; u16 species; u16 i; - numMovesFound = 0; + numEggMoves = 0; eggMoveIdx = 0; species = GetMonData(pokemon, MON_DATA_SPECIES); - for (i = 0; i < ARRAY_COUNT(gEggMoves) - 1; i ++) + for (i = 0; i < ARRAY_COUNT(gEggMoves) - 1; i++) { if (gEggMoves[i] == species + EGG_MOVES_SPECIES_OFFSET) { @@ -425,57 +489,61 @@ u8 pokemon_get_eggmoves(struct Pokemon *pokemon, u16 *eggMoves) break; } } - for (i = 0; i < 10; i ++) + + for (i = 0; i < 10; i++) { if (gEggMoves[eggMoveIdx + i] > EGG_MOVES_SPECIES_OFFSET) { + // TODO: the curly braces around this if statement are required for a matching build. break; } + eggMoves[i] = gEggMoves[eggMoveIdx + i]; - numMovesFound++; + numEggMoves++; } - return numMovesFound; + + return numEggMoves; } #ifdef NONMATCHING - -void daycare_build_child_moveset(struct Pokemon *egg, struct BoxPokemon *dad, struct BoxPokemon *mom) +void BuildEggMoveset(struct Pokemon *egg, struct BoxPokemon *father, struct BoxPokemon *mother) { u16 numSharedParentMoves; u8 numLevelUpMoves; - u8 numEggMoves; + u16 numEggMoves; u16 i, j; numSharedParentMoves = 0; - for (i = 0; i < 4; i ++) + for (i = 0; i < 4; i++) { - gUnknown_03000500[i] = 0; - gUnknown_030004D8[i] = 0; - gUnknown_030004E0[i] = 0; + gHatchedEggMotherMoves[i] = 0; + gHatchedEggFatherMoves[i] = 0; + gHatchedEggFinalMoves[i] = 0; } - for (i = 0; i < 10; i ++) - gUnknown_030004E8[i] = 0; - for (i = 0; i < 50; i ++) - gUnknown_03000470[i] = 0; + for (i = 0; i < 10; i++) + gHatchedEggEggMoves[i] = 0; + for (i = 0; i < 50; i++) + gHatchedEggLevelUpMoves[i] = 0; - numLevelUpMoves = GetLevelUpMovesBySpecies(GetMonData(egg, MON_DATA_SPECIES), gUnknown_03000470); - for (i = 0; i < 4; i ++) + numLevelUpMoves = GetLevelUpMovesBySpecies(GetMonData(egg, MON_DATA_SPECIES), gHatchedEggLevelUpMoves); + for (i = 0; i < 4; i++) { - gUnknown_030004D8[i] = GetBoxMonData(dad, MON_DATA_MOVE1 + i); - gUnknown_03000500[i] = GetBoxMonData(mom, MON_DATA_MOVE1 + i); + gHatchedEggFatherMoves[i] = GetBoxMonData(father, MON_DATA_MOVE1 + i); + gHatchedEggMotherMoves[i] = GetBoxMonData(mother, MON_DATA_MOVE1 + i); } - numEggMoves = pokemon_get_eggmoves(egg, gUnknown_030004E8); - for (i = 0; i < 4; i ++) + numEggMoves = GetEggMoves(egg, gHatchedEggEggMoves); + + for (i = 0; i < 4; i++) { - if (gUnknown_030004D8[i] != MOVE_NONE) + if (gHatchedEggFatherMoves[i] != MOVE_NONE) { - for (j = 0; j < numEggMoves; j ++) + for (j = 0; j < (u32)numEggMoves; j++) { - if (gUnknown_030004D8[i] == gUnknown_030004E8[j]) + if (gHatchedEggFatherMoves[i] == gHatchedEggEggMoves[j]) { - if (GiveMoveToMon(egg, gUnknown_030004D8[i]) == 0xffff) - DeleteFirstMoveAndGiveMoveToMon(egg, gUnknown_030004D8[i]); + if (GiveMoveToMon(egg, gHatchedEggFatherMoves[i]) == 0xffff) + DeleteFirstMoveAndGiveMoveToMon(egg, gHatchedEggFatherMoves[i]); break; } } @@ -483,40 +551,41 @@ void daycare_build_child_moveset(struct Pokemon *egg, struct BoxPokemon *dad, st else break; } - for (i = 0; i < 4; i ++) + for (i = 0; i < 4; i++) { - if (gUnknown_030004D8[i] != MOVE_NONE) + if (gHatchedEggFatherMoves[i] != MOVE_NONE) { - for (j = 0; j < 50 + 8; j ++) + for (j = 0; j < NUM_TECHNICAL_MACHINES + NUM_HIDDEN_MACHINES; j++) { - if (gUnknown_030004D8[i] == ItemIdToBattleMoveId(ITEM_TM01 + j) && CanMonLearnTMHM(egg, j)) + if (gHatchedEggFatherMoves[i] == ItemIdToBattleMoveId(ITEM_TM01 + j) && CanMonLearnTMHM(egg, j)) { - if (GiveMoveToMon(egg, gUnknown_030004D8[i]) == 0xffff) - DeleteFirstMoveAndGiveMoveToMon(egg, gUnknown_030004D8[i]); + if (GiveMoveToMon(egg, gHatchedEggFatherMoves[i]) == 0xffff) + DeleteFirstMoveAndGiveMoveToMon(egg, gHatchedEggFatherMoves[i]); } } } } - for (i = 0; i < 4; i ++) + for (i = 0; i < 4; i++) { - if (gUnknown_030004D8[i] == MOVE_NONE) + if (gHatchedEggFatherMoves[i] == MOVE_NONE) break; - for (j = 0; j < 4; j ++) + for (j = 0; j < 4; j++) { - if (gUnknown_030004D8[i] == gUnknown_03000500[j] && gUnknown_030004D8[i] != MOVE_NONE) - gUnknown_030004E0[numSharedParentMoves++] = gUnknown_030004D8[i]; + if (gHatchedEggFatherMoves[i] == gHatchedEggMotherMoves[j] && gHatchedEggFatherMoves[i] != MOVE_NONE) + gHatchedEggFinalMoves[numSharedParentMoves++] = gHatchedEggFatherMoves[i]; } } - for (i = 0; i < 4; i ++) + + for (i = 0; i < 4; i++) { - if (gUnknown_030004E0[i] == MOVE_NONE) + if (gHatchedEggFinalMoves[i] == MOVE_NONE) break; - for (j = 0; j < numLevelUpMoves; j ++) + for (j = 0; j < numLevelUpMoves; j++) { - if (gUnknown_03000470[j] != MOVE_NONE && gUnknown_030004E0[i] == gUnknown_03000470[j]) + if (gHatchedEggLevelUpMoves[j] != MOVE_NONE && gHatchedEggFinalMoves[i] == gHatchedEggLevelUpMoves[j]) { - if (GiveMoveToMon(egg, gUnknown_030004E0[i]) == 0xffff) - DeleteFirstMoveAndGiveMoveToMon(egg, gUnknown_030004E0[i]); + if (GiveMoveToMon(egg, gHatchedEggFinalMoves[i]) == 0xffff) + DeleteFirstMoveAndGiveMoveToMon(egg, gHatchedEggFinalMoves[i]); break; } } @@ -524,7 +593,7 @@ void daycare_build_child_moveset(struct Pokemon *egg, struct BoxPokemon *dad, st } #else __attribute__((naked)) -void daycare_build_child_moveset(struct Pokemon *egg, struct BoxPokemon *dad, struct BoxPokemon *mom) +void BuildEggMoveset(struct Pokemon *egg, struct BoxPokemon *father, struct BoxPokemon *mother) { asm_unified("\tpush {r4-r7,lr}\n" "\tmov r7, r10\n" @@ -538,10 +607,10 @@ void daycare_build_child_moveset(struct Pokemon *egg, struct BoxPokemon *dad, st "\tmovs r0, 0\n" "\tstr r0, [sp]\n" "\tmovs r6, 0\n" - "\tldr r5, _08041CC8 @ =gUnknown_03000500\n" + "\tldr r5, _08041CC8 @ =gHatchedEggMotherMoves\n" "\tmovs r2, 0\n" - "\tldr r4, _08041CCC @ =gUnknown_030004D8\n" - "\tldr r3, _08041CD0 @ =gUnknown_030004E0\n" + "\tldr r4, _08041CCC @ =gHatchedEggFatherMoves\n" + "\tldr r3, _08041CD0 @ =gHatchedEggFinalMoves\n" "_08041BE4:\n" "\tlsls r1, r6, 1\n" "\tadds r0, r1, r5\n" @@ -556,7 +625,7 @@ void daycare_build_child_moveset(struct Pokemon *egg, struct BoxPokemon *dad, st "\tcmp r6, 0x3\n" "\tbls _08041BE4\n" "\tmovs r6, 0\n" - "\tldr r2, _08041CD4 @ =gUnknown_030004E8\n" + "\tldr r2, _08041CD4 @ =gHatchedEggEggMoves\n" "\tmovs r1, 0\n" "_08041C02:\n" "\tlsls r0, r6, 1\n" @@ -568,7 +637,7 @@ void daycare_build_child_moveset(struct Pokemon *egg, struct BoxPokemon *dad, st "\tcmp r6, 0x9\n" "\tbls _08041C02\n" "\tmovs r6, 0\n" - "\tldr r2, _08041CD8 @ =gUnknown_03000470\n" + "\tldr r2, _08041CD8 @ =gHatchedEggLevelUpMoves\n" "\tmovs r1, 0\n" "_08041C18:\n" "\tlsls r0, r6, 1\n" @@ -584,13 +653,13 @@ void daycare_build_child_moveset(struct Pokemon *egg, struct BoxPokemon *dad, st "\tbl GetMonData\n" "\tlsls r0, 16\n" "\tlsrs r0, 16\n" - "\tldr r1, _08041CD8 @ =gUnknown_03000470\n" + "\tldr r1, _08041CD8 @ =gHatchedEggLevelUpMoves\n" "\tbl GetLevelUpMovesBySpecies\n" "\tlsls r0, 24\n" "\tlsrs r0, 24\n" "\tstr r0, [sp, 0x4]\n" "\tmovs r6, 0\n" - "\tldr r1, _08041CCC @ =gUnknown_030004D8\n" + "\tldr r1, _08041CCC @ =gHatchedEggFatherMoves\n" "\tmov r8, r1\n" "_08041C46:\n" "\tadds r5, r6, 0\n" @@ -605,7 +674,7 @@ void daycare_build_child_moveset(struct Pokemon *egg, struct BoxPokemon *dad, st "\tmov r0, r9\n" "\tadds r1, r5, 0\n" "\tbl GetBoxMonData\n" - "\tldr r1, _08041CC8 @ =gUnknown_03000500\n" + "\tldr r1, _08041CC8 @ =gHatchedEggMotherMoves\n" "\tadds r4, r1\n" "\tstrh r0, [r4]\n" "\tadds r0, r6, 0x1\n" @@ -613,15 +682,15 @@ void daycare_build_child_moveset(struct Pokemon *egg, struct BoxPokemon *dad, st "\tlsrs r6, r0, 16\n" "\tcmp r6, 0x3\n" "\tbls _08041C46\n" - "\tldr r1, _08041CD4 @ =gUnknown_030004E8\n" + "\tldr r1, _08041CD4 @ =gHatchedEggEggMoves\n" "\tadds r0, r7, 0\n" - "\tbl pokemon_get_eggmoves\n" + "\tbl GetEggMoves\n" "\tlsls r0, 24\n" "\tlsrs r0, 24\n" "\tmov r8, r0\n" "\tmovs r6, 0\n" "_08041C82:\n" - "\tldr r0, _08041CCC @ =gUnknown_030004D8\n" + "\tldr r0, _08041CCC @ =gHatchedEggFatherMoves\n" "\tlsls r1, r6, 1\n" "\tadds r2, r1, r0\n" "\tldrh r1, [r2]\n" @@ -634,7 +703,7 @@ void daycare_build_child_moveset(struct Pokemon *egg, struct BoxPokemon *dad, st "\tadds r4, r2, 0\n" "\tldr r2, _08041CDC @ =0x0000ffff\n" "_08041C9A:\n" - "\tldr r0, _08041CD4 @ =gUnknown_030004E8\n" + "\tldr r0, _08041CD4 @ =gHatchedEggEggMoves\n" "\tlsls r1, r5, 1\n" "\tadds r1, r0\n" "\tldrh r0, [r4]\n" @@ -655,11 +724,11 @@ void daycare_build_child_moveset(struct Pokemon *egg, struct BoxPokemon *dad, st "\tbl DeleteFirstMoveAndGiveMoveToMon\n" "\tb _08041CEA\n" "\t.align 2, 0\n" - "_08041CC8: .4byte gUnknown_03000500\n" - "_08041CCC: .4byte gUnknown_030004D8\n" - "_08041CD0: .4byte gUnknown_030004E0\n" - "_08041CD4: .4byte gUnknown_030004E8\n" - "_08041CD8: .4byte gUnknown_03000470\n" + "_08041CC8: .4byte gHatchedEggMotherMoves\n" + "_08041CCC: .4byte gHatchedEggFatherMoves\n" + "_08041CD0: .4byte gHatchedEggFinalMoves\n" + "_08041CD4: .4byte gHatchedEggEggMoves\n" + "_08041CD8: .4byte gHatchedEggLevelUpMoves\n" "_08041CDC: .4byte 0x0000ffff\n" "_08041CE0:\n" "\tadds r0, r5, 0x1\n" @@ -671,7 +740,7 @@ void daycare_build_child_moveset(struct Pokemon *egg, struct BoxPokemon *dad, st "\tadds r0, r6, 0x1\n" "\tlsls r0, 16\n" "\tlsrs r6, r0, 16\n" - "\tldr r3, _08041E14 @ =gUnknown_030004D8\n" + "\tldr r3, _08041E14 @ =gHatchedEggFatherMoves\n" "\tmov r9, r3\n" "\tcmp r6, 0x3\n" "\tbls _08041C82\n" @@ -688,7 +757,7 @@ void daycare_build_child_moveset(struct Pokemon *egg, struct BoxPokemon *dad, st "\tcmp r1, 0\n" "\tbeq _08041D5C\n" "\tmovs r5, 0\n" - "\tldr r0, _08041E14 @ =gUnknown_030004D8\n" + "\tldr r0, _08041E14 @ =gHatchedEggFatherMoves\n" "\tadds r4, r2, r0\n" "\tldr r6, _08041E18 @ =0x0000ffff\n" "\tmov r9, r0\n" @@ -734,12 +803,12 @@ void daycare_build_child_moveset(struct Pokemon *egg, struct BoxPokemon *dad, st "\tmovs r6, 0\n" "\tmov r2, r9\n" "\tldrh r0, [r2]\n" - "\tldr r3, _08041E20 @ =gUnknown_030004E0\n" + "\tldr r3, _08041E20 @ =gHatchedEggFinalMoves\n" "\tmov r10, r3\n" "\tcmp r0, 0\n" "\tbeq _08041DC6\n" "\tmov r4, r9\n" - "\tldr r0, _08041E24 @ =gUnknown_03000500\n" + "\tldr r0, _08041E24 @ =gHatchedEggMotherMoves\n" "\tmov r9, r0\n" "\tmov r12, r10\n" "_08041D7C:\n" @@ -797,7 +866,7 @@ void daycare_build_child_moveset(struct Pokemon *egg, struct BoxPokemon *dad, st "\tbcs _08041E38\n" "\tldr r2, _08041E18 @ =0x0000ffff\n" "_08041DDE:\n" - "\tldr r1, _08041E28 @ =gUnknown_03000470\n" + "\tldr r1, _08041E28 @ =gHatchedEggLevelUpMoves\n" "\tlsls r0, r5, 1\n" "\tadds r0, r1\n" "\tldrh r1, [r0]\n" @@ -823,12 +892,12 @@ void daycare_build_child_moveset(struct Pokemon *egg, struct BoxPokemon *dad, st "\tbl DeleteFirstMoveAndGiveMoveToMon\n" "\tb _08041E38\n" "\t.align 2, 0\n" - "_08041E14: .4byte gUnknown_030004D8\n" + "_08041E14: .4byte gHatchedEggFatherMoves\n" "_08041E18: .4byte 0x0000ffff\n" "_08041E1C: .4byte 0x00000121\n" - "_08041E20: .4byte gUnknown_030004E0\n" - "_08041E24: .4byte gUnknown_03000500\n" - "_08041E28: .4byte gUnknown_03000470\n" + "_08041E20: .4byte gHatchedEggFinalMoves\n" + "_08041E24: .4byte gHatchedEggMotherMoves\n" + "_08041E28: .4byte gHatchedEggLevelUpMoves\n" "_08041E2C:\n" "\tadds r0, r5, 0x1\n" "\tlsls r0, 16\n" @@ -842,7 +911,7 @@ void daycare_build_child_moveset(struct Pokemon *egg, struct BoxPokemon *dad, st "\tlsrs r6, r0, 16\n" "\tcmp r6, 0x3\n" "\tbhi _08041E50\n" - "\tldr r0, _08041E60 @ =gUnknown_030004E0\n" + "\tldr r0, _08041E60 @ =gHatchedEggFinalMoves\n" "\tlsls r1, r6, 1\n" "\tadds r1, r0\n" "\tldrh r1, [r1]\n" @@ -859,166 +928,178 @@ void daycare_build_child_moveset(struct Pokemon *egg, struct BoxPokemon *dad, st "\tpop {r0}\n" "\tbx r0\n" "\t.align 2, 0\n" - "_08041E60: .4byte gUnknown_030004E0"); + "_08041E60: .4byte gHatchedEggFinalMoves"); } #endif -static void RemoveEggFromDayCare(struct DayCareData *dayCareData) +static void RemoveEggFromDayCare(struct DayCare *daycare) { - dayCareData->misc.countersEtc.personalityLo = 0; - dayCareData->misc.countersEtc.unk_11a = 0; + daycare->misc.countersEtc.pendingEggPersonality = 0; + daycare->misc.countersEtc.eggCycleStepsRemaining = 0; } -void sub_8041E7C(void) +void RejectEggFromDayCare(void) { - RemoveEggFromDayCare(&gSaveBlock1.daycareData); + RemoveEggFromDayCare(&gSaveBlock1.daycare); } -static void incense_effects(u16 *species, struct DayCareData *dayCareData) +static void AlterEggSpeciesWithIncenseItem(u16 *species, struct DayCare *daycare) { - u16 momItem, dadItem; + u16 motherItem, fatherItem; if (*species == SPECIES_WYNAUT || *species == SPECIES_AZURILL) { - momItem = GetBoxMonData(&dayCareData->mons[0], MON_DATA_HELD_ITEM); - dadItem = GetBoxMonData(&dayCareData->mons[1], MON_DATA_HELD_ITEM); - if (*species == SPECIES_WYNAUT && momItem != ITEM_LAX_INCENSE && dadItem != ITEM_LAX_INCENSE) + motherItem = GetBoxMonData(&daycare->mons[0], MON_DATA_HELD_ITEM); + fatherItem = GetBoxMonData(&daycare->mons[1], MON_DATA_HELD_ITEM); + if (*species == SPECIES_WYNAUT && motherItem != ITEM_LAX_INCENSE && fatherItem != ITEM_LAX_INCENSE) { *species = SPECIES_WOBBUFFET; } - if (*species == SPECIES_AZURILL && momItem != ITEM_SEA_INCENSE && dadItem != ITEM_SEA_INCENSE) + + if (*species == SPECIES_AZURILL && motherItem != ITEM_SEA_INCENSE && fatherItem != ITEM_SEA_INCENSE) { *species = SPECIES_MARILL; } } } -static u16 sub_8041EEC(struct DayCareData *dayCareData, u8 *a1) // inherit_species_from_mom +static u16 DetermineEggSpeciesAndParentSlots(struct DayCare *daycare, u8 *parentSlots) { u16 i; u16 species[2]; u16 eggSpecies; - u8 buffer; - for (i=0; i<2; i++) + + // Determine which of the daycare mons is the mother and father of the egg. + // The 0th index of the parentSlots array is considered the mother slot, and the + // 1st index is the father slot. + for (i = 0; i < 2; i++) { - species[i] = GetBoxMonData(&dayCareData->mons[i], MON_DATA_SPECIES); + species[i] = GetBoxMonData(&daycare->mons[i], MON_DATA_SPECIES); if (species[i] == SPECIES_DITTO) { - a1[0] = i ^ 1; - a1[1] = i; + parentSlots[0] = i ^ 1; + parentSlots[1] = i; } - else if (GetBoxMonGender(&dayCareData->mons[i]) == MON_FEMALE) + else if (GetBoxMonGender(&daycare->mons[i]) == MON_FEMALE) { - a1[0] = i; - a1[1] = i ^ 1; + parentSlots[0] = i; + parentSlots[1] = i ^ 1; } } - eggSpecies = sub_8041870(species[a1[0]]); - if (eggSpecies == SPECIES_NIDORAN_F && dayCareData->misc.countersEtc.personalityLo & 0x8000) + + eggSpecies = GetEggSpecies(species[parentSlots[0]]); + if (eggSpecies == SPECIES_NIDORAN_F && daycare->misc.countersEtc.pendingEggPersonality & 0x8000) { eggSpecies = SPECIES_NIDORAN_M; } - if (eggSpecies == SPECIES_ILLUMISE && dayCareData->misc.countersEtc.personalityLo & 0x8000) + if (eggSpecies == SPECIES_ILLUMISE && daycare->misc.countersEtc.pendingEggPersonality & 0x8000) { eggSpecies = SPECIES_VOLBEAT; } - if (species[a1[1]] == SPECIES_DITTO && GetBoxMonGender(&dayCareData->mons[a1[0]]) != MON_FEMALE) + + // Make Ditto the "mother" slot if the other daycare mon is male. + if (species[parentSlots[1]] == SPECIES_DITTO && GetBoxMonGender(&daycare->mons[parentSlots[0]]) != MON_FEMALE) { - buffer = a1[1]; - a1[1] = a1[0]; - a1[0] = buffer; + u8 temp = parentSlots[1]; + parentSlots[1] = parentSlots[0]; + parentSlots[0] = temp; } + return eggSpecies; } -static void sub_8041FC4(struct DayCareData *dayCareData) // give_egg +static void _GiveEggFromDaycare(struct DayCare *daycare) // give_egg { struct Pokemon egg; u16 species; - u8 parents[2]; + u8 parentSlots[2]; // 0th index is "mother" daycare slot, 1st is "father" u8 isEgg; - species = sub_8041EEC(dayCareData, parents); - incense_effects(&species, dayCareData); - sub_80420FC(&egg, species, dayCareData); - InheritIVs(&egg, dayCareData); - daycare_build_child_moveset(&egg, &dayCareData->mons[parents[1]], &dayCareData->mons[parents[0]]); + + species = DetermineEggSpeciesAndParentSlots(daycare, parentSlots); + AlterEggSpeciesWithIncenseItem(&species, daycare); + SetInitialEggData(&egg, species, daycare); + InheritIVs(&egg, daycare); + BuildEggMoveset(&egg, &daycare->mons[parentSlots[1]], &daycare->mons[parentSlots[0]]); isEgg = TRUE; SetMonData(&egg, MON_DATA_IS_EGG, &isEgg); gPlayerParty[5] = egg; party_compaction(); CalculatePlayerPartyCount(); - RemoveEggFromDayCare(dayCareData); + RemoveEggFromDayCare(daycare); } -void sub_8042044(struct Pokemon *mon, u16 species, u8 overwriteMetLocation) // scr_create_egg +void CreateEgg(struct Pokemon *mon, u16 species, bool8 setMetLocation) { u8 metLevel; u16 ball; u8 language; u8 metLocation; u8 isEgg; + CreateMon(mon, species, 5, 0x20, FALSE, 0, FALSE, 0); metLevel = 0; ball = ITEM_POKE_BALL; language = LANGUAGE_JAPANESE; SetMonData(mon, MON_DATA_POKEBALL, &ball); - SetMonData(mon, MON_DATA_NICKNAME, gUnknown_08209AD4); + SetMonData(mon, MON_DATA_NICKNAME, sJapaneseEggNickname); SetMonData(mon, MON_DATA_FRIENDSHIP, &gBaseStats[species].eggCycles); SetMonData(mon, MON_DATA_MET_LEVEL, &metLevel); SetMonData(mon, MON_DATA_LANGUAGE, &language); - if (overwriteMetLocation) + if (setMetLocation) { - metLocation = 0xfd; + metLocation = 253; // hot springs; see PokemonSummaryScreen_PrintEggTrainerMemo SetMonData(mon, MON_DATA_MET_LOCATION, &metLocation); } + isEgg = TRUE; SetMonData(mon, MON_DATA_IS_EGG, &isEgg); } -static void sub_80420FC(struct Pokemon *mon, u16 species, struct DayCareData *dayCareData) +static void SetInitialEggData(struct Pokemon *mon, u16 species, struct DayCare *daycare) { u32 personality; u16 ball; u8 metLevel; u8 language; - personality = dayCareData->misc.countersEtc.personalityLo | (Random() << 16); + + personality = daycare->misc.countersEtc.pendingEggPersonality | (Random() << 16); CreateMon(mon, species, 5, 0x20, TRUE, personality, FALSE, 0); metLevel = 0; ball = ITEM_POKE_BALL; language = LANGUAGE_JAPANESE; SetMonData(mon, MON_DATA_POKEBALL, &ball); - SetMonData(mon, MON_DATA_NICKNAME, gUnknown_08209AD4); + SetMonData(mon, MON_DATA_NICKNAME, sJapaneseEggNickname); SetMonData(mon, MON_DATA_FRIENDSHIP, &gBaseStats[species].eggCycles); SetMonData(mon, MON_DATA_MET_LEVEL, &metLevel); SetMonData(mon, MON_DATA_LANGUAGE, &language); } -void sp0B8_daycare(void) +void GiveEggFromDaycare(void) { - sub_8041FC4(&gSaveBlock1.daycareData); + _GiveEggFromDaycare(&gSaveBlock1.daycare); } #ifdef NONMATCHING -static bool8 sub_80421B0(struct DayCareData *dayCareData) +static bool8 _ShouldEggHatch(struct DayCare *daycare) { struct BoxPokemon *parent; u32 i; int v0; int steps; v0 = 0; - for (i=0, parent=&dayCareData->mons[0]; i<2; parent++, i++) + for (i=0, parent=&daycare->mons[0]; i<2; parent++, i++) { if (GetBoxMonData(parent, MON_DATA_SANITY_BIT2, v0)) { - dayCareData->misc.countersEtc.steps[i]++; + daycare->misc.countersEtc.steps[i]++; v0++; } } - if (dayCareData->misc.countersEtc.personalityLo == 0 && v0 == 2 && dayCareData->misc.extra.misc[4] == 0xff && daycare_relationship_score(dayCareData) > (u32)((u32)(Random() * 100) / 0xffff)) + if (daycare->misc.countersEtc.pendingEggPersonality == 0 && v0 == 2 && daycare->misc.extra.misc[4] == 0xff && GetDaycareCompatibilityScore(daycare) > (u32)((u32)(Random() * 100) / 0xffff)) { - sub_8041940(); + TriggerPendingDaycareEgg(); } - if ((++dayCareData->misc.countersEtc.unk_11a) == 0xff) + if ((++daycare->misc.countersEtc.eggCycleStepsRemaining) == 0xff) { for (i=0; i<gPlayerPartyCount; i++) { @@ -1039,7 +1120,7 @@ static bool8 sub_80421B0(struct DayCareData *dayCareData) } #else __attribute__((naked)) -static bool8 sub_80421B0(struct DayCareData *dayCareData) +static bool8 _ShouldEggHatch(struct DayCare *daycare) { asm_unified("\tpush {r4-r7,lr}\n" "\tsub sp, 0x8\n" @@ -1083,7 +1164,7 @@ static bool8 sub_80421B0(struct DayCareData *dayCareData) "\tcmp r0, 0xFF\n" "\tbne _08042226\n" "\tadds r0, r7, 0\n" - "\tbl daycare_relationship_score\n" + "\tbl GetDaycareCompatibilityScore\n" "\tadds r4, r0, 0\n" "\tlsls r4, 24\n" "\tlsrs r4, 24\n" @@ -1096,7 +1177,7 @@ static bool8 sub_80421B0(struct DayCareData *dayCareData) "\tbl __udivsi3\n" "\tcmp r4, r0\n" "\tbls _08042226\n" - "\tbl sub_8041940\n" + "\tbl TriggerPendingDaycareEgg\n" "_08042226:\n" "\tmovs r0, 0x8D\n" "\tlsls r0, 1\n" @@ -1162,68 +1243,81 @@ static bool8 sub_80421B0(struct DayCareData *dayCareData) } #endif -bool8 sub_80422A0(void) +bool8 ShouldEggHatch(void) { - return sub_80421B0(&gSaveBlock1.daycareData); + return _ShouldEggHatch(&gSaveBlock1.daycare); } -static bool8 sub_80422B4(struct DayCareData *dayCareData) +static bool8 IsEggPending(struct DayCare *daycare) { - return (u32)((-dayCareData->misc.countersEtc.personalityLo) | dayCareData->misc.countersEtc.personalityLo) >> 31; + return (u32)((-daycare->misc.countersEtc.pendingEggPersonality) | daycare->misc.countersEtc.pendingEggPersonality) >> 31; } -static void sub_80422C4(struct DayCareData *dayCareData) +static void _GetDaycareMonNicknames(struct DayCare *daycare) { u8 language; - if (GetBoxMonData(&dayCareData->mons[0], MON_DATA_SPECIES) != 0) + if (GetBoxMonData(&daycare->mons[0], MON_DATA_SPECIES) != 0) { - GetBoxMonNick(&dayCareData->mons[0], gStringVar1); - language = GetBoxMonData(&dayCareData->mons[0], MON_DATA_LANGUAGE); - GetBoxMonData(&dayCareData->mons[0], MON_DATA_OT_NAME, gStringVar3); + GetBoxMonNick(&daycare->mons[0], gStringVar1); + language = GetBoxMonData(&daycare->mons[0], MON_DATA_LANGUAGE); + GetBoxMonData(&daycare->mons[0], MON_DATA_OT_NAME, gStringVar3); ConvertInternationalString(gStringVar3, language); } - if (GetBoxMonData(&dayCareData->mons[1], MON_DATA_SPECIES) != 0) + + if (GetBoxMonData(&daycare->mons[1], MON_DATA_SPECIES) != 0) { - GetBoxMonNick(&dayCareData->mons[1], gStringVar2); + GetBoxMonNick(&daycare->mons[1], gStringVar2); } } -u16 sub_8042328(void) +u16 GetSelectedDaycareMonNickname(void) { GetBoxMonNick(&gPlayerParty[gLastFieldPokeMenuOpened].box, gStringVar1); return GetBoxMonData(&gPlayerParty[gLastFieldPokeMenuOpened].box, MON_DATA_SPECIES); } -void sp0B5_daycare(void) +void GetDaycareMonNicknames(void) { - sub_80422C4(&gSaveBlock1.daycareData); + _GetDaycareMonNicknames(&gSaveBlock1.daycare); } -u8 sp0B6_daycare(void) +u8 GetDaycareState(void) { - u8 monCount; - if (sub_80422B4(&gSaveBlock1.daycareData)) + // The daycare can be in 4 possible states: + // 0: default state--no deposited mons, no egg + // 1: there is an egg waiting for the player to pick it up + // 2: there is a single pokemon in the daycare + // 3: there are two pokemon in the daycare, no egg + + u8 numMons; + if (IsEggPending(&gSaveBlock1.daycare)) { + // There is an Egg waiting for the player. return 1; } - monCount = Daycare_CountPokemon(&gSaveBlock1.daycareData); - if (monCount != 0) + + numMons = CountPokemonInDaycare(&gSaveBlock1.daycare); + if (numMons != 0) { - return monCount + 1; + return numMons + 1; } + return 0; } #ifdef NONMATCHING static #endif -bool8 sub_80423A8(u16 *a, u16 *b) +bool8 EggGroupsOverlap(u16 *eggGroups1, u16 *eggGroups2) { - int i, j; + // Determine if the two given egg group lists contain any of the + // same egg groups. + s32 i, j; u16 *v0, *v1, v2; - for (i=0, v0=a; i<2; v0++, i++) + + for (i = 0, v0 = eggGroups1; i < 2; v0++, i++) { - for (j=0, v2=*v0, v1=b; j<2; v1++, j++) + for (j = 0, v2 = *v0, v1 = eggGroups2; j < 2; v1++, j++) { if (v2 == *v1) { @@ -1231,11 +1325,12 @@ bool8 sub_80423A8(u16 *a, u16 *b) } } } + return FALSE; } #ifdef NONMATCHING -static u8 daycare_relationship_score(struct DayCareData *dayCareData) +static u8 GetDaycareCompatibilityScore(struct DayCare *daycare) { u16 species[2]; u32 otIds[2]; @@ -1248,7 +1343,8 @@ static u8 daycare_relationship_score(struct DayCareData *dayCareData) u16 *egg1; u16 *egg2; struct BoxPokemon *parent; - for (i=0, parent=&dayCareData->mons[0], spc=species, ids=otIds, gnd=genders, egg1=&eggGroups[0][0], egg2=&eggGroups[0][1]; i<2; spc++, egg1+=2, egg2+=2, parent++, i++) + + for (i=0, parent=&daycare->mons[0], spc=species, ids=otIds, gnd=genders, egg1=&eggGroups[0][0], egg2=&eggGroups[0][1]; i<2; spc++, egg1+=2, egg2+=2, parent++, i++) { *spc = GetBoxMonData(parent, MON_DATA_SPECIES); *ids++ = GetBoxMonData(parent, MON_DATA_OT_ID); @@ -1280,7 +1376,7 @@ static u8 daycare_relationship_score(struct DayCareData *dayCareData) { return 0; } - if (!sub_80423A8(eggGroups[0], eggGroups[1])) + if (!EggGroupsOverlap(eggGroups[0], eggGroups[1])) { return 0; } @@ -1303,7 +1399,7 @@ static u8 daycare_relationship_score(struct DayCareData *dayCareData) } #else __attribute__((naked)) -static u8 daycare_relationship_score(struct DayCareData *dayCareData) +static u8 GetDaycareCompatibilityScore(struct DayCare *daycare) { asm_unified("\tpush {r4-r7,lr}\n" "\tmov r7, r10\n" @@ -1415,7 +1511,7 @@ static u8 daycare_relationship_score(struct DayCareData *dayCareData) "\tbeq _08042484\n" "\tadd r1, sp, 0x4\n" "\tmov r0, sp\n" - "\tbl sub_80423A8\n" + "\tbl EggGroupsOverlap\n" "\tlsls r0, 24\n" "\tcmp r0, 0\n" "\tbeq _08042484\n" @@ -1454,17 +1550,17 @@ static u8 daycare_relationship_score(struct DayCareData *dayCareData) } #endif -u8 daycare_relationship_score_from_savegame(void) +u8 GetDaycareCompatibilityScoreFromSave(void) { - return daycare_relationship_score(&gSaveBlock1.daycareData); + return GetDaycareCompatibilityScore(&gSaveBlock1.daycare); } -void sp0B9_daycare_relationship_comment(void) +void SetDaycareCompatibilityString(void) { u8 whichString; u8 relationshipScore; - relationshipScore = daycare_relationship_score_from_savegame(); + relationshipScore = GetDaycareCompatibilityScoreFromSave(); whichString = 0; if (relationshipScore == 0) whichString = 3; @@ -1474,7 +1570,8 @@ void sp0B9_daycare_relationship_comment(void) whichString = 1; if (relationshipScore == 70) whichString = 0; - StringCopy(gStringVar4, gUnknown_08209AC4[whichString]); + + StringCopy(gStringVar4, sCompatibilityMessages[whichString]); } #ifdef NONMATCHING @@ -1486,12 +1583,12 @@ bool8 NameHasGenderSymbol(const u8 *name, u8 genderRatio) // This portion is nonmatching flags[1] = 0; flags[0] = 0; - for (i = 0; name[i] != EOS; i ++) + for (i = 0; name[i] != EOS; i++) // End nonmatching portion { - if (name[i] == CHAR_MALE) flags[0] ++; - if (name[i] == CHAR_FEMALE) flags[1] ++; + if (name[i] == CHAR_MALE) flags[0]++; + if (name[i] == CHAR_FEMALE) flags[1]++; } if (genderRatio == MON_MALE && flags[0] && !flags[1]) return TRUE; if (genderRatio == MON_FEMALE && flags[1] && !flags[0]) return TRUE; @@ -1581,45 +1678,48 @@ static u8 *AppendGenderSymbol(u8 *name, u8 gender) if (!NameHasGenderSymbol(name, MON_MALE)) return StringAppend(name, gOtherText_MaleSymbol3); } - else if (gender == MON_FEMALE) { if (!NameHasGenderSymbol(name, MON_FEMALE)) return StringAppend(name, gOtherText_FemaleSymbol3); } + return StringAppend(name, gOtherText_GenderlessSymbol); } -static u8 *MonAppendGenderSymbol(u8 *name, struct BoxPokemon *boxMon) +static u8 *AppendMonGenderSymbol(u8 *name, struct BoxPokemon *boxMon) { return AppendGenderSymbol(name, GetBoxMonGender(boxMon)); } -static void DaycareLevelMenuGetText(struct DayCareData *dayCareData, u8 *dest) +static void GetDaycareLevelMenuText(struct DayCare *daycare, u8 *dest) { - u8 buffers[2][20]; + u8 monNames[2][20]; u8 i; + *dest = EOS; - for (i = 0; i < 2; i ++) + for (i = 0; i < 2; i++) { - GetBoxMonNick(&dayCareData->mons[i], buffers[i]); - MonAppendGenderSymbol(buffers[i], &dayCareData->mons[i]); + GetBoxMonNick(&daycare->mons[i], monNames[i]); + AppendMonGenderSymbol(monNames[i], &daycare->mons[i]); } - StringCopy(dest, buffers[0]); + + StringCopy(dest, monNames[0]); StringAppend(dest, gOtherText_NewLine2); - StringAppend(dest, buffers[1]); + StringAppend(dest, monNames[1]); StringAppend(dest, gOtherText_NewLine2); StringAppend(dest, gOtherText_CancelAndLv); } -static void DaycareLevelMenuGetLevelText(struct DayCareData *dayCareData, u8 *dest) +static void GetDaycareLevelMenuLevelText(struct DayCare *daycare, u8 *dest) { u8 i; u8 level; + *dest = EOS; - for (i = 0; i < 2; i ++) + for (i = 0; i < 2; i++) { - level = Daycare_GetLevelAfterSteps(&dayCareData->mons[i], dayCareData->misc.countersEtc.steps[i]); + level = GetLevelAfterDaycareSteps(&daycare->mons[i], daycare->misc.countersEtc.steps[i]); dest[0] = 0x34; dest[1] = 0xFC; dest[2] = 0x14; @@ -1630,10 +1730,11 @@ static void DaycareLevelMenuGetLevelText(struct DayCareData *dayCareData, u8 *de dest[2] = 0x00; dest = StringCopy(dest + 3, gOtherText_NewLine2); } + *dest = EOS; } -static void DaycareLevelMenuProcessKeyInput(u8 taskId) +static void HandleDaycareLevelMenuInput(u8 taskId) { if (gMain.newKeys & DPAD_UP) { @@ -1648,7 +1749,7 @@ static void DaycareLevelMenuProcessKeyInput(u8 taskId) { if (gTasks[taskId].data[0] != 2) { - gTasks[taskId].data[0] ++; + gTasks[taskId].data[0]++; MoveMenuCursor(+1); PlaySE(SE_SELECT); } @@ -1676,12 +1777,12 @@ void ShowDaycareLevelMenu(void) { u8 buffer[100]; MenuDrawTextWindow(15, 6, 29, 13); - DaycareLevelMenuGetText(&gSaveBlock1.daycareData, buffer); + GetDaycareLevelMenuText(&gSaveBlock1.daycare, buffer); MenuPrint(buffer, 16, 7); - DaycareLevelMenuGetLevelText(&gSaveBlock1.daycareData, buffer); + GetDaycareLevelMenuLevelText(&gSaveBlock1.daycare, buffer); MenuPrint_PixelCoords(buffer, 0xce, 0x38, TRUE); InitMenu(0, 16, 7, 3, 0, 13); - CreateTask(DaycareLevelMenuProcessKeyInput, 3); + CreateTask(HandleDaycareLevelMenuInput, 3); } void ChooseSendDaycareMon(void) diff --git a/src/field/field_control_avatar.c b/src/field/field_control_avatar.c index e9dd0e9a6..c7b4861d5 100644 --- a/src/field/field_control_avatar.c +++ b/src/field/field_control_avatar.c @@ -500,9 +500,9 @@ bool8 sub_8068894(void) ScriptContext1_SetupScript(gUnknown_081A14B8); return TRUE; } - if (sub_80422A0()) + if (ShouldEggHatch()) { - IncrementGameStat(13); + IncrementGameStat(GAME_STAT_HATCHED_EGGS); ScriptContext1_SetupScript(S_EggHatch); return TRUE; } diff --git a/src/pokemon/pokemon_summary_screen.c b/src/pokemon/pokemon_summary_screen.c index d1d226b80..70b9b7d94 100644 --- a/src/pokemon/pokemon_summary_screen.c +++ b/src/pokemon/pokemon_summary_screen.c @@ -52,6 +52,7 @@ void PokemonSummaryScreen_PrintEggTrainerMemo(struct Pokemon *mon, u8 left, u8 t if (locationMet == 255) { + // Eggs received from Pokemon Box. MenuPrint(gOtherText_EggNicePlace, left, top); return; } diff --git a/src/scene/egg_hatch.c b/src/scene/egg_hatch.c index d363e4bcd..6ea26e546 100644 --- a/src/scene/egg_hatch.c +++ b/src/scene/egg_hatch.c @@ -1,26 +1,27 @@ #include "global.h" -#include "pokemon.h" -#include "items.h" -#include "decompress.h" #include "data2.h" -#include "task.h" -#include "script.h" -#include "palette.h" -#include "overworld.h" -#include "main.h" +#include "daycare.h" +#include "decompress.h" #include "event_data.h" -#include "sound.h" +#include "ewram.h" +#include "items.h" +#include "main.h" +#include "menu.h" +#include "naming_screen.h" +#include "overworld.h" +#include "palette.h" +#include "pokemon.h" +#include "rng.h" +#include "script.h" #include "songs.h" -#include "text.h" -#include "text_window.h" +#include "sound.h" #include "string_util.h" #include "strings2.h" -#include "menu.h" -#include "naming_screen.h" +#include "task.h" +#include "text.h" +#include "text_window.h" #include "trig.h" -#include "rng.h" #include "trade.h" -#include "ewram.h" extern struct SpriteTemplate gUnknown_02024E8C; @@ -47,7 +48,6 @@ extern const struct SpriteSheet sUnknown_0820A3B8; extern const struct SpritePalette sUnknown_0820A3C0; bool8 GetSetPokedexFlag(u16 nationalNum, u8 caseID); -u8* GetMonNick(struct Pokemon* mon, u8* dst); u8 sav1_map_get_name(void); const struct CompressedSpritePalette* GetMonSpritePalStruct(struct Pokemon* mon); //gets pokemon palette address void sub_8080990(void); @@ -391,7 +391,7 @@ _08042B42:\n\ bool8 sub_8042B4C(void) { - return sub_8042ABC(&gSaveBlock1.daycareData, gSpecialVar_0x8004); + return sub_8042ABC(&gSaveBlock1.daycare, gSpecialVar_0x8004); } static u8 EggHatchCreateMonSprite(u8 a0, u8 switchID, u8 pokeID) diff --git a/src/script_pokemon_util_80C4BF0.c b/src/script_pokemon_util_80C4BF0.c index 011978a0c..1462a985d 100644 --- a/src/script_pokemon_util_80C4BF0.c +++ b/src/script_pokemon_util_80C4BF0.c @@ -573,7 +573,7 @@ u8 ScriptGiveEgg(u16 species) struct Pokemon mon; u8 isEgg; - sub_8042044(&mon, species, 1); + CreateEgg(&mon, species, TRUE); isEgg = TRUE; SetMonData(&mon, MON_DATA_IS_EGG, &isEgg); |