diff options
| author | camthesaxman <cameronghall@cox.net> | 2017-05-10 16:53:14 -0500 |
|---|---|---|
| committer | camthesaxman <cameronghall@cox.net> | 2017-05-10 16:53:14 -0500 |
| commit | 32153295edc1e93bd27894f75f2ab01f9140bed5 (patch) | |
| tree | 397bb2852fbacc95b66a2b121c0a7eeb31c5c44d /src/mail_data.c | |
| parent | e78f49f1efc2eadb674d00c00ffc9a4018b3cdbd (diff) | |
| parent | 242af849cb56ce0c4469c4e2be82a3ad5dbd3434 (diff) | |
Merge remote-tracking branch 'upstream/master' into decompile_battle_2
Diffstat (limited to 'src/mail_data.c')
| -rw-r--r-- | src/mail_data.c | 151 |
1 files changed, 134 insertions, 17 deletions
diff --git a/src/mail_data.c b/src/mail_data.c index 0794d268d..23d22e21f 100644 --- a/src/mail_data.c +++ b/src/mail_data.c @@ -1,23 +1,24 @@ #include "global.h" +#include "items.h" #include "name_string_util.h" #include "pokemon.h" #include "species.h" #include "text.h" -void sub_80A2B40(struct MailStruct *); -u16 sub_80A2D44(u16, u32); -bool8 itemid_is_mail(u16); -u16 sub_809D474(u32); +void ClearMailStruct(struct MailStruct *); +u16 SpeciesToMailSpecies(u16, u32); +bool8 ItemIsMail(u16); +u16 GetUnownLetterByPersonality(u32); -void sub_80A2B18(void) +void ClearMailData(void) { u8 i; for (i = 0; i < 16; i++) - sub_80A2B40(&gSaveBlock1.mail[i]); + ClearMailStruct(&gSaveBlock1.mail[i]); } -void sub_80A2B40(struct MailStruct *mail) +void ClearMailStruct(struct MailStruct *mail) { int i; @@ -34,16 +35,16 @@ void sub_80A2B40(struct MailStruct *mail) mail->itemId = 0; } -bool8 sub_80A2B94(struct Pokemon *mon) +bool8 MonHasMail(struct Pokemon *mon) { u16 heldItem = GetMonData(mon, MON_DATA_HELD_ITEM); - if (itemid_is_mail(heldItem) && GetMonData(mon, MON_DATA_MAIL) != 0xFF) + if (ItemIsMail(heldItem) && GetMonData(mon, MON_DATA_MAIL) != 0xFF) return TRUE; else return FALSE; } -u8 sub_80A2BC4(struct Pokemon *mon, u16 itemId) +u8 GiveMailToMon(struct Pokemon *mon, u16 itemId) { u16 _itemId; u8 heldItem[2]; @@ -72,9 +73,9 @@ u8 sub_80A2BC4(struct Pokemon *mon, u16 itemId) for (i = 0; i < 4; i++) gSaveBlock1.mail[id].trainerId[i] = gSaveBlock2.playerTrainerId[i]; - species = GetBoxMonData(mon, MON_DATA_SPECIES); - personality = GetBoxMonData(mon, MON_DATA_PERSONALITY); - gSaveBlock1.mail[id].species = sub_80A2D44(species, personality); + species = GetBoxMonData(&mon->box, MON_DATA_SPECIES); + personality = GetBoxMonData(&mon->box, MON_DATA_PERSONALITY); + gSaveBlock1.mail[id].species = SpeciesToMailSpecies(species, personality); gSaveBlock1.mail[id].itemId = _itemId; SetMonData(mon, MON_DATA_MAIL, &id); SetMonData(mon, MON_DATA_HELD_ITEM, heldItem); @@ -86,9 +87,125 @@ u8 sub_80A2BC4(struct Pokemon *mon, u16 itemId) return -1; } -u16 sub_80A2D44(u16 species, u32 personality) +u16 SpeciesToMailSpecies(u16 species, u32 personality) { - if (species != SPECIES_UNOWN) - return species; - return ((sub_809D474(personality) << 16) + (30000 << 16)) >> 16; + if (species == SPECIES_UNOWN) + { + int mailSpecies = GetUnownLetterByPersonality(personality) + 30000; + return mailSpecies; + } + + return species; +} + +u16 MailSpeciesToSpecies(u16 a1, u16 *a2) +{ + u16 result; + + if (a1 >= 30000 && a1 < (30000 + UNOWN_FORM_COUNT)) + { + result = SPECIES_UNOWN; + *a2 = a1 - 30000; + } + else + { + result = a1; + } + + return result; +} + +u8 GiveMailToMon2(struct Pokemon *mon, struct MailStruct *mail) +{ + u8 heldItem[2]; + u16 itemId = mail->itemId; + u8 mailId = GiveMailToMon(mon, itemId); + + if (mailId == 0xFF) + return 0xFF; + + gSaveBlock1.mail[mailId] = *mail; + + SetMonData(mon, MON_DATA_MAIL, &mailId); + + heldItem[0] = itemId; + heldItem[1] = itemId >> 8; + + SetMonData(mon, MON_DATA_HELD_ITEM, heldItem); + + return mailId; +} + +int unref_sub_80A2DF4(void) +{ + return 0; +} + +void TakeMailFromMon(struct Pokemon *mon) +{ + u8 heldItem[2]; + u8 mailId; + + if (MonHasMail(mon)) + { + mailId = GetMonData(mon, MON_DATA_MAIL); + gSaveBlock1.mail[mailId].itemId = 0; + mailId = 0xFF; + heldItem[0] = 0; + heldItem[1] = 0; + SetMonData(mon, MON_DATA_MAIL, &mailId); + SetMonData(mon, MON_DATA_HELD_ITEM, heldItem); + } +} + +void DeleteMail(u8 mailId) +{ + gSaveBlock1.mail[mailId].itemId = 0; +} + +u8 TakeMailFromMon2(struct Pokemon *mon) +{ + u8 i; + u8 newHeldItem[2]; + u8 newMailId; + + newHeldItem[0] = 0; + newHeldItem[1] = 0; + newMailId = 0xFF; + + for (i = 6; i < 16; i++) + { + if (gSaveBlock1.mail[i].itemId == 0) + { + memcpy(&gSaveBlock1.mail[i], &gSaveBlock1.mail[GetMonData(mon, MON_DATA_MAIL)], sizeof(struct MailStruct)); + gSaveBlock1.mail[GetMonData(mon, MON_DATA_MAIL)].itemId = 0; + SetMonData(mon, MON_DATA_MAIL, &newMailId); + SetMonData(mon, MON_DATA_HELD_ITEM, newHeldItem); + return i; + } + } + + return 0xFF; +} + +bool8 ItemIsMail(u16 itemId) +{ + switch (itemId) + { + case ITEM_ORANGE_MAIL: + case ITEM_HARBOR_MAIL: + case ITEM_GLITTER_MAIL: + case ITEM_MECH_MAIL: + case ITEM_WOOD_MAIL: + case ITEM_WAVE_MAIL: + case ITEM_BEAD_MAIL: + case ITEM_SHADOW_MAIL: + case ITEM_TROPIC_MAIL: + case ITEM_DREAM_MAIL: + case ITEM_FAB_MAIL: + case ITEM_RETRO_MAIL: + return TRUE; + default: + return FALSE; + } } |
