2017-12-03 19:19:11 +01:00
|
|
|
#include "global.h"
|
|
|
|
#include "mail.h"
|
2017-12-17 20:22:56 +01:00
|
|
|
#include "constants/items.h"
|
2017-12-03 19:19:11 +01:00
|
|
|
#include "pokemon.h"
|
|
|
|
#include "pokemon_icon.h"
|
|
|
|
#include "text.h"
|
|
|
|
#include "international_string_util.h"
|
2021-02-22 18:12:35 +01:00
|
|
|
#include "constants/easy_chat.h"
|
2017-12-03 19:19:11 +01:00
|
|
|
|
|
|
|
void ClearMailData(void)
|
|
|
|
{
|
|
|
|
u8 i;
|
|
|
|
|
|
|
|
for (i = 0; i < MAIL_COUNT; i++)
|
|
|
|
ClearMailStruct(&gSaveBlock1Ptr->mail[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClearMailStruct(struct MailStruct *mail)
|
|
|
|
{
|
|
|
|
s32 i;
|
|
|
|
|
|
|
|
for (i = 0; i < MAIL_WORDS_COUNT; i++)
|
2021-02-22 18:12:35 +01:00
|
|
|
mail->words[i] = EC_EMPTY_WORD;
|
2017-12-03 19:19:11 +01:00
|
|
|
|
2018-09-01 22:03:21 +02:00
|
|
|
for (i = 0; i < PLAYER_NAME_LENGTH + 1; i++)
|
2017-12-03 19:19:11 +01:00
|
|
|
mail->playerName[i] = EOS;
|
|
|
|
|
2021-02-20 21:15:38 +01:00
|
|
|
for (i = 0; i < TRAINER_ID_LENGTH; i++)
|
2017-12-03 19:19:11 +01:00
|
|
|
mail->trainerId[i] = 0;
|
|
|
|
|
|
|
|
mail->species = SPECIES_BULBASAUR;
|
|
|
|
mail->itemId = ITEM_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool8 MonHasMail(struct Pokemon *mon)
|
|
|
|
{
|
|
|
|
u16 heldItem = GetMonData(mon, MON_DATA_HELD_ITEM);
|
2021-02-20 21:15:38 +01:00
|
|
|
if (ItemIsMail(heldItem) && GetMonData(mon, MON_DATA_MAIL) != MAIL_NONE)
|
2017-12-03 19:19:11 +01:00
|
|
|
return TRUE;
|
|
|
|
else
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
u8 GiveMailToMon(struct Pokemon *mon, u16 itemId)
|
|
|
|
{
|
|
|
|
u8 heldItem[2];
|
|
|
|
u8 id, i;
|
|
|
|
u16 species;
|
|
|
|
u32 personality;
|
|
|
|
|
|
|
|
heldItem[0] = itemId;
|
|
|
|
heldItem[1] = itemId >> 8;
|
|
|
|
|
|
|
|
for (id = 0; id < PARTY_SIZE; id++)
|
|
|
|
{
|
2021-02-20 21:15:38 +01:00
|
|
|
if (gSaveBlock1Ptr->mail[id].itemId == ITEM_NONE)
|
2017-12-03 19:19:11 +01:00
|
|
|
{
|
|
|
|
for (i = 0; i < MAIL_WORDS_COUNT; i++)
|
2021-02-22 18:12:35 +01:00
|
|
|
gSaveBlock1Ptr->mail[id].words[i] = EC_EMPTY_WORD;
|
2017-12-03 19:19:11 +01:00
|
|
|
|
2021-02-20 21:15:38 +01:00
|
|
|
for (i = 0; i < PLAYER_NAME_LENGTH; i++)
|
2017-12-03 19:19:11 +01:00
|
|
|
gSaveBlock1Ptr->mail[id].playerName[i] = gSaveBlock2Ptr->playerName[i];
|
|
|
|
gSaveBlock1Ptr->mail[id].playerName[i] = EOS;
|
|
|
|
PadNameString(gSaveBlock1Ptr->mail[id].playerName, CHAR_SPACE);
|
|
|
|
|
2019-10-18 01:22:03 +02:00
|
|
|
for (i = 0; i < TRAINER_ID_LENGTH; i++)
|
2017-12-03 19:19:11 +01:00
|
|
|
gSaveBlock1Ptr->mail[id].trainerId[i] = gSaveBlock2Ptr->playerTrainerId[i];
|
|
|
|
|
|
|
|
species = GetBoxMonData(&mon->box, MON_DATA_SPECIES);
|
|
|
|
personality = GetBoxMonData(&mon->box, MON_DATA_PERSONALITY);
|
|
|
|
gSaveBlock1Ptr->mail[id].species = SpeciesToMailSpecies(species, personality);
|
|
|
|
gSaveBlock1Ptr->mail[id].itemId = itemId;
|
|
|
|
SetMonData(mon, MON_DATA_MAIL, &id);
|
|
|
|
SetMonData(mon, MON_DATA_HELD_ITEM, heldItem);
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-20 21:15:38 +01:00
|
|
|
return MAIL_NONE;
|
2017-12-03 19:19:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
u16 SpeciesToMailSpecies(u16 species, u32 personality)
|
|
|
|
{
|
|
|
|
if (species == SPECIES_UNOWN)
|
|
|
|
{
|
|
|
|
u32 species = GetUnownLetterByPersonality(personality) + 30000;
|
|
|
|
return species;
|
|
|
|
}
|
|
|
|
|
|
|
|
return species;
|
|
|
|
}
|
|
|
|
|
|
|
|
u16 MailSpeciesToSpecies(u16 mailSpecies, u16 *buffer)
|
|
|
|
{
|
|
|
|
u16 result;
|
|
|
|
|
2021-02-20 21:15:38 +01:00
|
|
|
if (mailSpecies >= 30000 && mailSpecies < (30000 + NUM_UNOWN_FORMS))
|
2017-12-03 19:19:11 +01:00
|
|
|
{
|
|
|
|
result = SPECIES_UNOWN;
|
|
|
|
*buffer = mailSpecies - 30000;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
result = mailSpecies;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
u8 GiveMailToMon2(struct Pokemon *mon, struct MailStruct *mail)
|
|
|
|
{
|
|
|
|
u8 heldItem[2];
|
|
|
|
u16 itemId = mail->itemId;
|
|
|
|
u8 mailId = GiveMailToMon(mon, itemId);
|
|
|
|
|
2021-02-20 21:15:38 +01:00
|
|
|
if (mailId == MAIL_NONE)
|
|
|
|
return MAIL_NONE;
|
2017-12-03 19:19:11 +01:00
|
|
|
|
|
|
|
gSaveBlock1Ptr->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;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool32 DummyMailFunc(void)
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TakeMailFromMon(struct Pokemon *mon)
|
|
|
|
{
|
|
|
|
u8 heldItem[2];
|
|
|
|
u8 mailId;
|
|
|
|
|
|
|
|
if (MonHasMail(mon))
|
|
|
|
{
|
|
|
|
mailId = GetMonData(mon, MON_DATA_MAIL);
|
|
|
|
gSaveBlock1Ptr->mail[mailId].itemId = ITEM_NONE;
|
2021-02-20 21:15:38 +01:00
|
|
|
mailId = MAIL_NONE;
|
2017-12-03 19:19:11 +01:00
|
|
|
heldItem[0] = ITEM_NONE;
|
|
|
|
heldItem[1] = ITEM_NONE << 8;
|
|
|
|
SetMonData(mon, MON_DATA_MAIL, &mailId);
|
|
|
|
SetMonData(mon, MON_DATA_HELD_ITEM, heldItem);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClearMailItemId(u8 mailId)
|
|
|
|
{
|
|
|
|
gSaveBlock1Ptr->mail[mailId].itemId = ITEM_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
u8 TakeMailFromMon2(struct Pokemon *mon)
|
|
|
|
{
|
|
|
|
u8 i;
|
|
|
|
u8 newHeldItem[2];
|
|
|
|
u8 newMailId;
|
|
|
|
|
|
|
|
newHeldItem[0] = ITEM_NONE;
|
|
|
|
newHeldItem[1] = ITEM_NONE << 8;
|
2021-02-20 21:15:38 +01:00
|
|
|
newMailId = MAIL_NONE;
|
2017-12-03 19:19:11 +01:00
|
|
|
|
|
|
|
for (i = PARTY_SIZE; i < MAIL_COUNT; i++)
|
|
|
|
{
|
|
|
|
if (gSaveBlock1Ptr->mail[i].itemId == ITEM_NONE)
|
|
|
|
{
|
|
|
|
memcpy(&gSaveBlock1Ptr->mail[i], &gSaveBlock1Ptr->mail[GetMonData(mon, MON_DATA_MAIL)], sizeof(struct MailStruct));
|
|
|
|
gSaveBlock1Ptr->mail[GetMonData(mon, MON_DATA_MAIL)].itemId = ITEM_NONE;
|
|
|
|
SetMonData(mon, MON_DATA_MAIL, &newMailId);
|
|
|
|
SetMonData(mon, MON_DATA_HELD_ITEM, newHeldItem);
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-20 21:15:38 +01:00
|
|
|
return MAIL_NONE;
|
2017-12-03 19:19:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2017-12-17 20:22:56 +01:00
|
|
|
}
|
2017-12-03 19:19:11 +01:00
|
|
|
}
|