condense files and cleanup

This commit is contained in:
Seth Barberee 2024-06-03 12:03:04 -07:00
parent 5438b247a3
commit 6aeb342553
19 changed files with 1001 additions and 1052 deletions

View File

@ -11,6 +11,15 @@ typedef struct subStruct_203B490
/* 0x8 */ s32 checksum; // really dumb checksum that just adds all the fields of WonderMail struct
} subStruct_203B490;
// size: 0x8
struct unkStruct_8096AF8
{
bool8 unk0;
/* 0x2 */ u16 clientSpecies;
/* 0x4 */ u16 targetSpecies;
};
// size: 0x32C?
typedef struct unkStruct_203B490
{
@ -35,5 +44,27 @@ s32 CountFilledMailboxSlots(void);
WonderMail *GetMailboxSlotInfo(u8 index);
bool8 IsMailSlotEmpty(u8 index);
void ResetMailboxSlot(u8 index);
bool8 AcceptJob(WonderMail *mail);
s32 CountJobsinDungeon(u8 dungeon);
WonderMail *GetJobSlotInfo(u8 index);
s32 GetNumAcceptedJobs(void);
bool8 IsJobSlotEmpty(u8 index);
bool8 IsMailinJobSlot(WonderMail *mail);
void ResetJobSlot(u8 index);
bool8 sub_809693C(WonderMail *mail);
void sub_8096AF8(struct unkStruct_8096AF8 *, u8 slotIndex, u8 dungeon);
bool8 sub_8096C08(u8 *jobIndex);
WonderMail *GetPelipperBoardSlotInfo(u8);
bool8 IsPelipperBoardSlotEmpty(u8);
void ResetPelipperBoardSlot(u8);
void sub_80965F4(void);
void sub_8096C80(void);
void ReceivePKMNNews(u8 index);
bool8 CheckPKMNNewsSlot(u8 index);
void SortJobSlots(void);
u8 *sub_8096DD8(void);
u8 *sub_8096DE8(void);
u8 sub_8096E2C(void);
void sub_8096EEC(WonderMail *mail);
#endif // GUARD_CODE_80958E8_H

View File

@ -1,30 +0,0 @@
#ifndef GUARD_CODE_80958E8_1_H
#define GUARD_CODE_80958E8_1_H
#include "structs/str_wonder_mail.h"
// size: 0x8
struct unkStruct_8096AF8
{
bool8 unk0;
/* 0x2 */ u16 clientSpecies;
/* 0x4 */ u16 targetSpecies;
};
bool8 AcceptJob(WonderMail *mail);
s32 CountJobsinDungeon(u8 dungeon);
WonderMail *GetJobSlotInfo(u8 index);
s32 GetNumAcceptedJobs(void);
bool8 IsJobSlotEmpty(u8 index);
bool8 IsMailinJobSlot(WonderMail *mail);
void ResetJobSlot(u8 index);
bool8 sub_809693C(WonderMail *mail);
void sub_8096AF8(struct unkStruct_8096AF8 *, u8 slotIndex, u8 dungeon);
bool8 sub_8096C08(u8 *jobIndex);
// code_80958E8_1.s
extern WonderMail *GetPelipperBoardSlotInfo(u8);
extern bool8 IsPelipperBoardSlotEmpty(u8);
#endif // GUARD_CODE_80958E8_1_H

View File

@ -1,15 +0,0 @@
#ifndef GUARD_CODE_8096AF8_H
#define GUARD_CODE_8096AF8_H
#include "structs/str_wonder_mail.h"
extern void sub_8096C80(void);
void ReceivePKMNNews(u8 index);
bool8 CheckPKMNNewsSlot(u8 index);
void SortJobSlots(void);
u8 *sub_8096DD8(void);
u8 *sub_8096DE8(void);
u8 sub_8096E2C(void);
void sub_8096EEC(WonderMail *mail);
#endif // GUARD_CODE_8096AF8_H

View File

@ -323,7 +323,6 @@ SECTIONS {
src/play_time.o(.text);
src/code_8094F88.o(.text);
src/code_80958E8.o(.text);
src/code_80958E8_1.o(.text);
src/code_80972F4.o(.text);
src/code_8097504.o(.text);
src/code_8097670.o(.text);

View File

@ -8,7 +8,7 @@
#include "code_80227B8.h"
#include "code_8023868.h"
#include "code_8024458.h"
#include "code_8096AF8.h"
#include "code_80958E8.h"
#include "common_strings.h"
#include "constants/friend_area.h"
#include "event_flag.h"
@ -623,4 +623,4 @@ static void LoadTeamRankBadge(u32 a0, u32 a1, u32 a2)
teamBadgePic = &teamBadgePic[rank * 128];
sub_8007E20(a0, a1, a2, 16, 16, teamBadgePic, 14);
CloseFile(teamBadgeFile);
}
}

View File

@ -4,8 +4,7 @@
#include "code_802DB28.h"
#include "code_802F204.h"
#include "code_803C1D0.h"
#include "code_80958E8_1.h"
#include "code_8096AF8.h"
#include "code_80958E8.h"
#include "exclusive_pokemon.h"
#include "input.h"
#include "items.h"

View File

@ -2,7 +2,7 @@
#include "code_803C1D0.h"
#include "code_8094F88.h"
#include "code_80958E8.h"
#include "code_80958E8_1.h"
#include "code_80958E8.h"
#include "code_80A26CC.h"
#include "constants/dungeon.h"
#include "constants/friend_area.h"
@ -15,18 +15,28 @@
#include "pokemon.h"
#include "pokemon_3.h"
#include "pokemon_mail.h"
#include "event_flag.h"
#include "rescue_team_info.h"
extern bool8 sub_809017C(DungeonLocation *);
extern void ResetPelipperBoardSlot(u8);
extern void sub_803C37C(struct DungeonLocation *, u8, u8 *);
extern u8 sub_8097318(s16 param_1);
bool8 sub_8095E38(WonderMail *mail, u8 dungeon, u32 floor, u8 param_4);
u8 sub_8095F28(u8 param_1);
bool8 GenerateMailJobDungeonInfo(WonderMail *mail);
extern void sub_803C4F0(WonderMail *);
extern void sub_803C3E0(WonderMail *);
extern void sub_803C45C(WonderMail *);
extern void sub_803C610(WonderMail *);
extern void sub_803C580(WonderMail *);
extern void sub_803C37C(struct DungeonLocation *, u8, u8 *);
bool8 GenerateMailJobInfo(WonderMail *);
bool8 sub_8096E80(u8);
u8 sub_8095E78(void);
void sub_8096078(void);
bool8 sub_80963B4(void);
void SaveWonderMail(struct unkStruct_8094924 *a, WonderMail *b);
void RestoreWonderMail(struct unkStruct_8094924 *a, WonderMail *b);
s32 CalculateMailChecksum(WonderMail *mail);
extern void SaveDungeonLocation(struct unkStruct_8094924*, DungeonLocation*);
extern void RestoreDungeonLocation(struct unkStruct_8094924*, DungeonLocation*);
extern u8 gUnknown_8109984[];
@ -746,3 +756,939 @@ void sub_8096078(void)
gUnknown_203B490->mailboxSlots[counter2].mailType = 0;
}
}
static void SortMailboxSlots(void)
{
s32 r1;
s32 r6;
WonderMail job;
for(r1 = 0; r1 < NUM_MAILBOX_SLOTS - 1; r1++)
{
for(r6 = r1 + 1; r6 < NUM_MAILBOX_SLOTS; r6++)
{
if(gUnknown_203B490->mailboxSlots[r6].mailType != 0)
{
if((gUnknown_203B490->mailboxSlots[r1].unk4.dungeon.id > gUnknown_203B490->mailboxSlots[r6].unk4.dungeon.id) ||
((gUnknown_203B490->mailboxSlots[r1].unk4.dungeon.id == gUnknown_203B490->mailboxSlots[r6].unk4.dungeon.id) &&
(gUnknown_203B490->mailboxSlots[r1].unk4.dungeon.floor > gUnknown_203B490->mailboxSlots[r6].unk4.dungeon.floor)))
{
job = gUnknown_203B490->mailboxSlots[r1];
gUnknown_203B490->mailboxSlots[r1] = gUnknown_203B490->mailboxSlots[r6];
gUnknown_203B490->mailboxSlots[r6] = job;
}
}
}
}
}
void sub_80961B4(void)
{
if (sub_8096E2C() != 0) {
gUnknown_203B490->unk328 = TRUE;
}
}
bool8 sub_80961D8(void)
{
s32 num;
s32 index;
u32 floor;
s32 friendAreaReward;
WonderMail *slot;
bool8 flag = FALSE;
num = CountFilledMailboxSlots();
index = RandRange(num, NUM_MAILBOX_SLOTS);
if(num >= NUM_MAILBOX_SLOTS) return 0;
if(!gUnknown_203B490->unk328)
return 0;
else
{
gUnknown_203B490->unk328 = flag;
}
floor = 0x38;
if(sub_8001D08(0xA, 0x31, 0x1))
{
if(!gUnknown_203B490->PKMNNewsReceived[0x35])
if(!sub_8096E80(0x35)) floor = 0x35;
}
if(sub_80023E4(0xF))
{
if(!gUnknown_203B490->PKMNNewsReceived[0x34])
if(!sub_8096E80(0x34)) floor = 0x34;
if(!gUnknown_203B490->PKMNNewsReceived[0x33])
if(!sub_8096E80(0x33)) floor = 0x33;
if(!gUnknown_203B490->PKMNNewsReceived[0x32])
if(!sub_8096E80(0x32)) floor = 0x32;
}
if(GetRescueTeamRank() == LUCARIO_RANK)
{
if(!gUnknown_203B490->PKMNNewsReceived[0x36])
if(!sub_8096E80(0x36)) floor = 0x36;
}
if(sub_80023E4(6))
{
if(!gUnknown_203B490->PKMNNewsReceived[0x37])
if(!sub_8096E80(0x37)) floor = 0x37;
}
if(floor != 0x38) goto _slot;
if(num > index) goto _08096392;
floor = sub_8096E2C();
if(!sub_80023E4(0xE) && (floor > 2)) goto _0809638E;
if (floor > 0x31) goto _0809638E;
_slot:
slot = GetMailboxSlotInfo(num);
slot->mailType = 1;
slot->unk4.dungeon.id = NUM_DUNGEONS;
slot->unk4.dungeon.floor = floor;
goto _flag;
_0809638E:
for(; num <= index; num++)
{
slot = GetMailboxSlotInfo(num);
if(GenerateMailJobInfo(slot))
{
friendAreaReward = sub_8095E78();
if(!sub_803C1D0(&slot->unk4.dungeon, slot->missionType)) friendAreaReward = FRIEND_AREA_NONE;
slot->rewardType = RandRange(MONEY1, END_REWARDS);
if(slot->rewardType == FRIEND_AREA)
{
if(friendAreaReward == FRIEND_AREA_NONE)
{
slot->rewardType = MONEY1;
flag = TRUE;
}
else
{
slot->friendAreaReward = friendAreaReward;
flag = TRUE;
}
}
else
{
_flag:
flag = TRUE;
}
} else break;
}
_08096392:
if(sub_80963B4())
flag = TRUE;
sub_8096078();
SortMailboxSlots();
return flag;
}
bool8 sub_80963B4(void)
{
u8 floor;
s32 num;
WonderMail *slot;
bool8 flag = FALSE;
floor = sub_8096E2C();
num = CountFilledMailboxSlots();
if(num >= NUM_MAILBOX_SLOTS) return FALSE;
if(sub_80023E4(0xE))
{
if(floor < 0x32)
{
slot = GetMailboxSlotInfo(num);
slot->mailType = 1;
slot->unk4.dungeon.id = NUM_DUNGEONS;
slot->unk4.dungeon.floor = floor;
flag = TRUE;
}
}
return flag;
}
void sub_80963FC(void)
{
s32 index;
WonderMail *slot;
for(index = 0; index < NUM_MAILBOX_SLOTS; index++)
{
slot = GetMailboxSlotInfo(index);
if(slot->mailType != 1)
{
ResetMailboxSlot(index);
}
}
sub_8096078();
slot = GetMailboxSlotInfo(CountFilledMailboxSlots());
slot->mailType = 5;
slot->missionType = 0;
slot->unk2 = 0;
slot->unk4.dungeon.id = DUNGEON_MT_STEEL;
slot->unk4.dungeon.floor = 3;
slot->unk4.seed = 0x00ffffff & Rand32Bit();
slot->clientSpecies = MONSTER_PIDGEY;
slot->targetSpecies = MONSTER_PIDGEY;
slot->targetItem = sub_8095F28(slot->unk4.dungeon.id);
slot->rewardType = MONEY1;
do
{
sub_803C37C(&slot->unk4.dungeon, slot->missionType, &slot->itemReward);
} while (slot->targetItem == slot->itemReward);
slot->friendAreaReward = FRIEND_AREA_NONE;
sub_8096078();
SortMailboxSlots();
}
void sub_8096488(void)
{
WonderMail *mail;
s32 index;
for(index = 0; index < NUM_MAILBOX_SLOTS; index++){
ResetMailboxSlot(index);
}
mail = GetMailboxSlotInfo(0);
mail->mailType = 1;
mail->unk4.dungeon.id = NUM_DUNGEONS;
mail->unk4.dungeon.floor = 0;
}
bool8 sub_80964B4(void)
{
if ((!gUnknown_203B490->PKMNNewsReceived[0x35]) && (sub_8096E80(0x35) == 0)) {
return FALSE;
}
else {
return TRUE;
}
}
bool8 sub_80964E4(void)
{
if ((!gUnknown_203B490->PKMNNewsReceived[0x36]) && (sub_8096E80(0x36) == 0)) {
return FALSE;
}
else {
return TRUE;
}
}
s32 CountFilledPelipperBoardSlots(void)
{
s32 index;
s32 slots;
slots = 0;
for(index = 0; index < MAX_ACCEPTED_JOBS; index++) {
if (!IsPelipperBoardSlotEmpty(index)) {
slots++;
}
}
return slots;
}
UNUSED bool8 sub_8096538(WonderMail *mail)
{
s32 index;
for(index = 0; index < MAX_ACCEPTED_JOBS; index++)
{
if(gUnknown_203B490->pelipperBoardJobs[index].mailType == 0)
{
gUnknown_203B490->pelipperBoardJobs[index] = *mail;
return FALSE;
}
}
return TRUE;
}
WonderMail *GetPelipperBoardSlotInfo(u8 index)
{
return &gUnknown_203B490->pelipperBoardJobs[index];
}
bool8 IsPelipperBoardSlotEmpty(u8 index)
{
if (gUnknown_203B490->pelipperBoardJobs[index].mailType == 0)
return TRUE;
else
return FALSE;
}
void ResetPelipperBoardSlot(u8 index)
{
gUnknown_203B490->pelipperBoardJobs[index].mailType = MAIL_TYPE_NONE;
gUnknown_203B490->pelipperBoardJobs[index].unk4.dungeon.id = 99;
gUnknown_203B490->pelipperBoardJobs[index].unk4.dungeon.floor = 0;
gUnknown_203B490->pelipperBoardJobs[index].rewardType = 0;
}
void sub_80965F4(void)
{
int counter1; // r5
int counter2;
counter1 = 0;
counter2 = 0;
do {
for( ; counter1 < 8; counter1++)
{
if (gUnknown_203B490->pelipperBoardJobs[counter1].mailType != 0)
break;
}
if (counter1 == 8) {
break;
}
if (counter1 > counter2) {
gUnknown_203B490->pelipperBoardJobs[counter2] = gUnknown_203B490->pelipperBoardJobs[counter1];
}
counter1++;
counter2++;
} while( 1 );
for(; counter2 < 8; counter2++)
{
gUnknown_203B490->pelipperBoardJobs[counter2].mailType = 0;
}
}
void SortPelipperJobs(void)
{
s32 index1;
s32 index2;
WonderMail mail;
for(index1 = 0; index1 < MAX_ACCEPTED_JOBS - 1; index1++)
{
for(index2 = index1 + 1; index2 < MAX_ACCEPTED_JOBS; index2++)
{
if(gUnknown_203B490->pelipperBoardJobs[index2].mailType != MAIL_TYPE_NONE)
{
if((gUnknown_203B490->pelipperBoardJobs[index1].unk4.dungeon.id > gUnknown_203B490->pelipperBoardJobs[index2].unk4.dungeon.id) ||
((gUnknown_203B490->pelipperBoardJobs[index1].unk4.dungeon.id == gUnknown_203B490->pelipperBoardJobs[index2].unk4.dungeon.id) && (gUnknown_203B490->pelipperBoardJobs[index1].unk4.dungeon.floor > gUnknown_203B490->pelipperBoardJobs[index2].unk4.dungeon.floor)))
{
mail = gUnknown_203B490->pelipperBoardJobs[index1];
gUnknown_203B490->pelipperBoardJobs[index1] = gUnknown_203B490->pelipperBoardJobs[index2];
gUnknown_203B490->pelipperBoardJobs[index2] = mail;
}
}
}
}
}
void GeneratePelipperJobs(void)
{
s32 range;
WonderMail *mail;
s32 index;
range = RandRange(4,8);
for(index = 0; index < MAX_ACCEPTED_JOBS; index++)
{
gUnknown_203B490->pelipperBoardJobs[index].mailType = MAIL_TYPE_NONE;
}
index = 0;
if (sub_8097318(0xe) != 0) {
mail = GetPelipperBoardSlotInfo(0);
mail->mailType = MAIL_TYPE_UNK2;
mail->missionType = WONDER_MAIL_MISSION_TYPE_UNK6;
mail->unk2 = 1;
mail->unk4.dungeon.id = DUNGEON_UPROAR_FOREST;
mail->unk4.dungeon.floor = 10;
mail->unk4.seed = Rand32Bit() & 0xffffff;
mail->clientSpecies = MONSTER_WYNAUT;
mail->targetSpecies = MONSTER_MANKEY;
mail->targetItem = 0;
mail->rewardType = ITEM;
mail->itemReward = ITEM_REVIVER_SEED;
mail->friendAreaReward = 0;
index = 1;
}
if (sub_8097318(0xf) != 0) {
mail = GetPelipperBoardSlotInfo(index);
mail->mailType = MAIL_TYPE_UNK3;
mail->missionType = WONDER_MAIL_MISSION_TYPE_UNK6;
mail->unk2 = 2;
mail->unk4.dungeon.id = DUNGEON_HOWLING_FOREST;
mail->unk4.dungeon.floor = 15;
mail->unk4.seed = Rand32Bit() & 0xffffff;
mail->clientSpecies = MONSTER_SMEARGLE;
mail->targetSpecies = MONSTER_SMEARGLE;
mail->targetItem = 0;
mail->rewardType = ITEM;
mail->itemReward = ITEM_REVIVER_SEED;
mail->friendAreaReward = 0;
index++;
}
if (sub_8097318(0x1c) != 0) {
mail = GetPelipperBoardSlotInfo(index);
mail->mailType = MAIL_TYPE_UNK4;
mail->missionType = WONDER_MAIL_MISSION_TYPE_UNK6;
mail->unk2 = 3;
mail->unk4.dungeon.id = DUNGEON_WISH_CAVE;
mail->unk4.dungeon.floor = 20;
mail->unk4.seed = Rand32Bit() & 0xffffff;
mail->clientSpecies = MONSTER_MEDICHAM;
mail->targetSpecies = MONSTER_MEDICHAM;
mail->targetItem = 0;
mail->rewardType = ITEM;
mail->itemReward = ITEM_REVIVER_SEED;
mail->friendAreaReward = 0;
index++;
}
for (; index <= range; index++) {
if (!GenerateMailJobInfo(&gUnknown_203B490->pelipperBoardJobs[index])) break;
gUnknown_203B490->pelipperBoardJobs[index].rewardType = RandRange(MONEY, BLANK_4);
}
sub_80965F4();
SortPelipperJobs();
}
bool8 IsMailinJobSlot(WonderMail *mail)
{
WonderMail *jobSlot;
s32 index;
for(index = 0, jobSlot = &gUnknown_203B490->jobSlots[0]; index < MAX_ACCEPTED_JOBS; jobSlot++, index++)
{
if(jobSlot->mailType != MAIL_TYPE_NONE)
if(mail->missionType == jobSlot->missionType)
if(mail->unk2 == jobSlot->unk2)
if(mail->unk4.dungeon.id == jobSlot->unk4.dungeon.id)
if(mail->unk4.dungeon.floor == jobSlot->unk4.dungeon.floor)
if(mail->unk4.seed == jobSlot->unk4.seed)
if(mail->clientSpecies == jobSlot->clientSpecies)
if(mail->targetSpecies == jobSlot->targetSpecies)
if(mail->targetItem == jobSlot->targetItem)
if(mail->rewardType == jobSlot->rewardType)
if(mail->itemReward == jobSlot->itemReward)
if(mail->friendAreaReward == jobSlot->friendAreaReward)
return TRUE;
}
return FALSE;
}
bool8 sub_809693C(WonderMail *mail)
{
u8 dungeonIndex;
u8 floor;
bool8 escortMission;
s32 index;
dungeonIndex = mail->unk4.dungeon.id;
floor = mail->unk4.dungeon.floor;
escortMission = FALSE;
if (!IsValidWonderMail(mail)) {
return FALSE;
}
else
{
if(mail->missionType == WONDER_MAIL_MISSION_TYPE_ESCORT_CLIENT)
escortMission = TRUE;
for(index = 0; index < MAX_ACCEPTED_JOBS; index++)
{
if ((gUnknown_203B490->jobSlots[index].mailType == MAIL_TYPE_TAKEN_JOB) &&
(sub_8095E38(&gUnknown_203B490->jobSlots[index],dungeonIndex,floor,escortMission) != 0))
{
return TRUE;
}
}
}
return FALSE;
}
s32 GetNumAcceptedJobs(void)
{
s32 index;
s32 count;
count = 0;
for(index = 0; index < MAX_ACCEPTED_JOBS; index++)
{
if (!IsJobSlotEmpty(index)) {
count++;
}
}
return count;
}
s32 CountJobsinDungeon(u8 dungeon)
{
WonderMail *mail;
s32 index;
s32 count;
count = 0;
for(index = 0; index < MAX_ACCEPTED_JOBS; index++)
{
mail = GetJobSlotInfo(index);
if ((mail->unk4.dungeon.id == dungeon) &&
(((mail->mailType == MAIL_TYPE_TAKEN_JOB || (mail->mailType == MAIL_TYPE_UNK8)) || (mail->mailType == MAIL_TYPE_UNK9)))) {
count++;
}
}
return count;
}
bool8 sub_8096A08(u8 dungeon, PokemonStruct1 *pokemon)
{
WonderMail *mail;
s32 index;
u32 local_14;
s32 temp;
for(index = 0; index < MAX_ACCEPTED_JOBS; index++)
{
mail = GetJobSlotInfo(index);
if(mail->unk4.dungeon.id == dungeon)
if(mail->mailType == MAIL_TYPE_TAKEN_JOB)
if(mail->missionType == WONDER_MAIL_MISSION_TYPE_ESCORT_CLIENT)
{
temp = 0xffffff00;
local_14 &= temp;
temp = 0x4A;
local_14 |= temp;
temp = 0xffff00ff;
local_14 &= temp;
temp = 0x100;
local_14 |= temp;
sub_808CFD0(pokemon,mail->clientSpecies,NULL,0,(DungeonLocation *) &local_14,NULL);
return TRUE;
}
}
return FALSE;
}
bool8 AcceptJob(WonderMail *mail)
{
s32 index;
for(index = 0; index < MAX_ACCEPTED_JOBS; index++)
{
if(gUnknown_203B490->jobSlots[index].mailType == MAIL_TYPE_NONE)
{
gUnknown_203B490->jobSlots[index] = *mail;
return FALSE;
}
}
return TRUE;
}
WonderMail *GetJobSlotInfo(u8 index)
{
return &gUnknown_203B490->jobSlots[index];
}
bool8 IsJobSlotEmpty(u8 index)
{
if(gUnknown_203B490->jobSlots[index].mailType == MAIL_TYPE_NONE)
return TRUE;
else
return FALSE;
}
void sub_8096AF8(struct unkStruct_8096AF8 *param_1, u8 slotIndex,u8 dungeon)
{
WonderMail *jobSlot;
Item *item;
s32 index;
jobSlot = GetJobSlotInfo(slotIndex);
param_1->unk0 = FALSE;
param_1->clientSpecies = jobSlot->clientSpecies;
param_1->targetSpecies = MONSTER_NONE;
if (jobSlot->unk4.dungeon.id == dungeon) {
switch(jobSlot->missionType) {
case WONDER_MAIL_MISSION_TYPE_FIND_ITEM:
if (jobSlot->mailType == MAIL_TYPE_TAKEN_JOB) {
for(index = 0; index < INVENTORY_SIZE; index++)
{
item = &gTeamInventoryRef->teamItems[index];
if (((item->flags & ITEM_FLAG_EXISTS)) && (item->id == jobSlot->targetItem)) {
param_1->unk0 = TRUE;
}
}
}
break;
case WONDER_MAIL_MISSION_TYPE_RESCUE_CLIENT:
case WONDER_MAIL_MISSION_TYPE_DELIVER_ITEM:
if (jobSlot->mailType == MAIL_TYPE_UNK9) {
param_1->unk0 = TRUE;
}
break;
case WONDER_MAIL_MISSION_TYPE_RESCUE_TARGET:
case WONDER_MAIL_MISSION_TYPE_ESCORT_CLIENT:
if (jobSlot->mailType == MAIL_TYPE_UNK9) {
param_1->unk0 = TRUE;
param_1->targetSpecies = jobSlot->targetSpecies;
}
break;
}
}
}
// Unused
s16 sub_8096B98(u8 dungeon)
{
WonderMail *mail;
s32 index;
for(index = 0; index < MAX_ACCEPTED_JOBS; index++)
{
mail = GetJobSlotInfo(index);
if(mail->mailType == MAIL_TYPE_TAKEN_JOB)
if(mail->missionType == WONDER_MAIL_MISSION_TYPE_ESCORT_CLIENT)
if(mail->unk4.dungeon.id == dungeon)
return mail->targetSpecies;
}
return 0;
}
void sub_8096BD0(void)
{
s32 index;
WonderMail *mail;
for(mail = &gUnknown_203B490->jobSlots[0], index = 0; index < MAX_ACCEPTED_JOBS; mail++, index++)
{
switch(mail->mailType)
{
case MAIL_TYPE_UNK7:
case MAIL_TYPE_UNK8:
case MAIL_TYPE_UNK9:
ResetJobSlot(index);
break;
}
}
sub_8096C80();
SortJobSlots();
}
bool8 sub_8096C08(u8 *jobIndex)
{
s32 index;
WonderMail *mail;
for(mail = &gUnknown_203B490->jobSlots[0], index = 0; index < MAX_ACCEPTED_JOBS; mail++, index++)
{
if(mail->mailType > 4 && mail->unk2 == 4)
{
*jobIndex = index;
return TRUE;
}
}
return FALSE;
}
void ResetJobSlot(u8 index)
{
gUnknown_203B490->jobSlots[index].mailType = MAIL_TYPE_NONE;
gUnknown_203B490->jobSlots[index].unk4.dungeon.id = 99;
gUnknown_203B490->jobSlots[index].unk4.dungeon.floor = 0;
gUnknown_203B490->jobSlots[index].rewardType = MONEY1;
}
void sub_8096C80(void)
{
int counter1; // r5
int counter2;
counter1 = 0;
counter2 = 0;
do {
for( ; counter1 < 8; counter1++)
{
if (gUnknown_203B490->jobSlots[counter1].mailType != 0)
break;
}
if (counter1 == 8) {
break;
}
if (counter1 > counter2) {
gUnknown_203B490->jobSlots[counter2] = gUnknown_203B490->jobSlots[counter1];
}
counter1++;
counter2++;
} while( 1 );
for(; counter2 < 8; counter2++)
{
gUnknown_203B490->jobSlots[counter2].mailType = 0;
}
}
void SortJobSlots(void)
{
s32 r1;
s32 r6;
WonderMail job;
for(r1 = 0; r1 < MAX_ACCEPTED_JOBS - 1; r1++)
{
for(r6 = r1 + 1; r6 < MAX_ACCEPTED_JOBS; r6++)
{
if(gUnknown_203B490->jobSlots[r6].mailType != 0)
{
if((gUnknown_203B490->jobSlots[r1].unk4.dungeon.id > gUnknown_203B490->jobSlots[r6].unk4.dungeon.id) ||
((gUnknown_203B490->jobSlots[r1].unk4.dungeon.id == gUnknown_203B490->jobSlots[r6].unk4.dungeon.id) &&
(gUnknown_203B490->jobSlots[r1].unk4.dungeon.floor > gUnknown_203B490->jobSlots[r6].unk4.dungeon.floor)))
{
job = gUnknown_203B490->jobSlots[r1];
gUnknown_203B490->jobSlots[r1] = gUnknown_203B490->jobSlots[r6];
gUnknown_203B490->jobSlots[r6] = job;
}
}
}
}
}
u8 *sub_8096DD8(void)
{
return gUnknown_203B490->unk190;
}
u8 *sub_8096DE8(void)
{
return gUnknown_203B490->unk1B8;
}
void ReceivePKMNNews(u8 index)
{
gUnknown_203B490->PKMNNewsReceived[index] = TRUE;
}
bool8 CheckPKMNNewsSlot(u8 index)
{
return gUnknown_203B490->PKMNNewsReceived[index];
}
u8 sub_8096E2C(void)
{
s32 index;
s32 floor = 0;
for(index = 0; index < NUM_MAILBOX_SLOTS; index++)
{
if(gUnknown_203B490->mailboxSlots[index].mailType == 1)
{
if(floor <= gUnknown_203B490->mailboxSlots[index].unk4.dungeon.floor)
if( gUnknown_203B490->mailboxSlots[index].unk4.dungeon.floor < 0x32)
floor = gUnknown_203B490->mailboxSlots[index].unk4.dungeon.floor + 1;
}
}
for(index = floor; index < 0x32; index++)
{
if(!gUnknown_203B490->PKMNNewsReceived[index]) return index;
}
return 0x38;
}
bool8 sub_8096E80(u8 floor)
{
s32 index;
for(index = 0; index < NUM_MAILBOX_SLOTS; index++)
{
if(gUnknown_203B490->mailboxSlots[index].mailType == 1)
{
if(floor == gUnknown_203B490->mailboxSlots[index].unk4.dungeon.floor)
return TRUE;
}
}
return FALSE;
}
s32 CalculateMailChecksum(WonderMail *mail)
{
s32 sum;
sum = (mail->unk2 + mail->missionType);
sum += mail->unk4.dungeon.id;
sum += mail->unk4.dungeon.floor;
sum += mail->unk4.seed << 0x8;
sum += mail->clientSpecies << 0xC;
sum += mail->targetSpecies << 0x10;
sum += mail->targetItem << 0x18;
sum += mail->rewardType;
sum += mail->itemReward;
sum += mail->friendAreaReward;
return sum;
}
void sub_8096EEC(WonderMail *mail)
{
s32 index;
for(index = 15; index > 0; index--)
{
gUnknown_203B490->unk230[index] = gUnknown_203B490->unk230[index - 1];
}
gUnknown_203B490->unk230[0].sub = mail->unk4;
gUnknown_203B490->unk230[0].checksum = CalculateMailChecksum(mail);
}
bool8 sub_8096F50(WonderMail *mail)
{
s32 index;
s32 checksum;
subStruct_203B490 *temp;
checksum = CalculateMailChecksum(mail);
for (index = 0; index < 0x10; index++) {
temp = &gUnknown_203B490->unk230[index];
if (temp->sub.dungeon.id == mail->unk4.dungeon.id)
if (temp->sub.dungeon.floor == mail->unk4.dungeon.floor)
if (temp->sub.seed == mail->unk4.seed)
if (temp->checksum == checksum)
return TRUE;
}
return FALSE;
}
u32 RestoreMailInfo(u8 *r0, u32 size)
{
s32 index;
struct unkStruct_8094924 backup;
u32 temp;
xxx_init_struct_8094924_restore_809485C(&backup, r0, size);
for(index = 0; index < NUM_MAILBOX_SLOTS; index++)
{
RestoreWonderMail(&backup, &gUnknown_203B490->mailboxSlots[index]);
}
for(index = 0; index < MAX_ACCEPTED_JOBS; index++)
{
RestoreWonderMail(&backup, &gUnknown_203B490->pelipperBoardJobs[index]);
}
for(index = 0; index < MAX_ACCEPTED_JOBS; index++)
{
RestoreWonderMail(&backup, &gUnknown_203B490->jobSlots[index]);
}
for(index = 0; index < 0x38; index++)
{
RestoreIntegerBits(&backup, &temp, 1);
if(temp & 1)
gUnknown_203B490->PKMNNewsReceived[index] = TRUE;
else
gUnknown_203B490->PKMNNewsReceived[index] = FALSE;
}
RestoreIntegerBits(&backup, &temp, 1);
if(temp & 1)
gUnknown_203B490->unk328 = TRUE;
else
gUnknown_203B490->unk328 = FALSE;
RestoreIntegerBits(&backup, gUnknown_203B490->unk190, 0x140);
RestoreIntegerBits(&backup, gUnknown_203B490->unk1B8, 0x3C0);
for(index = 0; index < 0x10; index++)
{
RestoreIntegerBits(&backup, &gUnknown_203B490->unk230[index].checksum, 0x20);
RestoreIntegerBits(&backup, &gUnknown_203B490->unk230[index].sub.seed, 0x18);
RestoreDungeonLocation(&backup, &gUnknown_203B490->unk230[index].sub.dungeon);
}
nullsub_102(&backup);
return backup.unk8;
}
u32 SaveMailInfo(u8 *r0, u32 size)
{
s32 index;
struct unkStruct_8094924 backup;
u32 temp;
xxx_init_struct_8094924_save_809486C(&backup, r0, size);
for(index = 0; index < NUM_MAILBOX_SLOTS; index++)
{
SaveWonderMail(&backup, &gUnknown_203B490->mailboxSlots[index]);
}
for(index = 0; index < MAX_ACCEPTED_JOBS; index++)
{
SaveWonderMail(&backup, &gUnknown_203B490->pelipperBoardJobs[index]);
}
for(index = 0; index < MAX_ACCEPTED_JOBS; index++)
{
SaveWonderMail(&backup, &gUnknown_203B490->jobSlots[index]);
}
for(index = 0; index < 0x38; index++)
{
if(gUnknown_203B490->PKMNNewsReceived[index])
temp = -1;
else
temp = 0;
SaveIntegerBits(&backup, &temp, 1);
}
if(gUnknown_203B490->unk328)
temp = -1;
else
temp = 0;
SaveIntegerBits(&backup, &temp, 1);
SaveIntegerBits(&backup, gUnknown_203B490->unk190, 0x140);
SaveIntegerBits(&backup, gUnknown_203B490->unk1B8, 0x3C0);
for(index = 0; index < 0x10; index++)
{
SaveIntegerBits(&backup, &gUnknown_203B490->unk230[index].checksum, 0x20);
SaveIntegerBits(&backup, &gUnknown_203B490->unk230[index].sub.seed, 0x18);
SaveDungeonLocation(&backup, &gUnknown_203B490->unk230[index].sub.dungeon);
}
nullsub_102(&backup);
return backup.unk8;
}
void RestoreWonderMail(struct unkStruct_8094924 *a, WonderMail *b)
{
RestoreIntegerBits(a, &b->mailType, 4);
RestoreIntegerBits(a, &b->missionType, 3);
RestoreIntegerBits(a, &b->unk2, 4);
RestoreIntegerBits(a, &b->clientSpecies, 9);
RestoreIntegerBits(a, &b->targetSpecies, 9);
RestoreIntegerBits(a, &b->targetItem, 8);
RestoreIntegerBits(a, &b->rewardType, 4);
RestoreIntegerBits(a, &b->itemReward, 8);
RestoreIntegerBits(a, &b->friendAreaReward, 6);
RestoreIntegerBits(a, &b->unk4.seed, 0x18);
RestoreDungeonLocation(a, &b->unk4.dungeon);
}
void SaveWonderMail(struct unkStruct_8094924 *a, WonderMail *b)
{
SaveIntegerBits(a, &b->mailType, 4);
SaveIntegerBits(a, &b->missionType, 3);
SaveIntegerBits(a, &b->unk2, 4);
SaveIntegerBits(a, &b->clientSpecies, 9);
SaveIntegerBits(a, &b->targetSpecies, 9);
SaveIntegerBits(a, &b->targetItem, 8);
SaveIntegerBits(a, &b->rewardType, 4);
SaveIntegerBits(a, &b->itemReward, 8);
SaveIntegerBits(a, &b->friendAreaReward, 6);
SaveIntegerBits(a, &b->unk4.seed, 0x18);
SaveDungeonLocation(a, &b->unk4.dungeon);
}

View File

@ -1,707 +0,0 @@
#include "constants/mailbox.h"
#include "global.h"
#include "constants/friend_area.h"
#include "constants/dungeon.h"
#include "constants/monster.h"
#include "constants/wonder_mail.h"
#include "items.h"
#include "code_80958E8.h"
#include "code_80958E8_1.h"
#include "random.h"
#include "pokemon.h"
#include "code_8096AF8.h"
#include "event_flag.h"
#include "rescue_team_info.h"
extern u8 sub_8095E38(WonderMail *, u8, u8, bool8);
extern void sub_80965F4();
u8 sub_8097318(s16 param_1);
extern bool8 GenerateMailJobInfo(WonderMail *);
bool8 sub_803C1D0(DungeonLocation *, u8);
u8 sub_8095F28(u8);
void sub_803C37C(DungeonLocation *, u8, u8 *);
bool8 sub_8096E80(u8);
u8 sub_8095E78(void);
void sub_8096078(void);
bool8 sub_80963B4(void);
static void SortMailboxSlots(void)
{
s32 r1;
s32 r6;
WonderMail job;
for(r1 = 0; r1 < NUM_MAILBOX_SLOTS - 1; r1++)
{
for(r6 = r1 + 1; r6 < NUM_MAILBOX_SLOTS; r6++)
{
if(gUnknown_203B490->mailboxSlots[r6].mailType != 0)
{
if((gUnknown_203B490->mailboxSlots[r1].unk4.dungeon.id > gUnknown_203B490->mailboxSlots[r6].unk4.dungeon.id) ||
((gUnknown_203B490->mailboxSlots[r1].unk4.dungeon.id == gUnknown_203B490->mailboxSlots[r6].unk4.dungeon.id) &&
(gUnknown_203B490->mailboxSlots[r1].unk4.dungeon.floor > gUnknown_203B490->mailboxSlots[r6].unk4.dungeon.floor)))
{
job = gUnknown_203B490->mailboxSlots[r1];
gUnknown_203B490->mailboxSlots[r1] = gUnknown_203B490->mailboxSlots[r6];
gUnknown_203B490->mailboxSlots[r6] = job;
}
}
}
}
}
void sub_80961B4(void)
{
if (sub_8096E2C() != 0) {
gUnknown_203B490->unk328 = TRUE;
}
}
bool8 sub_80961D8(void)
{
s32 num;
s32 index;
u32 floor;
s32 friendAreaReward;
WonderMail *slot;
bool8 flag = FALSE;
num = CountFilledMailboxSlots();
index = RandRange(num, NUM_MAILBOX_SLOTS);
if(num >= NUM_MAILBOX_SLOTS) return 0;
if(!gUnknown_203B490->unk328)
return 0;
else
{
gUnknown_203B490->unk328 = flag;
}
floor = 0x38;
if(sub_8001D08(0xA, 0x31, 0x1))
{
if(!gUnknown_203B490->PKMNNewsReceived[0x35])
if(!sub_8096E80(0x35)) floor = 0x35;
}
if(sub_80023E4(0xF))
{
if(!gUnknown_203B490->PKMNNewsReceived[0x34])
if(!sub_8096E80(0x34)) floor = 0x34;
if(!gUnknown_203B490->PKMNNewsReceived[0x33])
if(!sub_8096E80(0x33)) floor = 0x33;
if(!gUnknown_203B490->PKMNNewsReceived[0x32])
if(!sub_8096E80(0x32)) floor = 0x32;
}
if(GetRescueTeamRank() == LUCARIO_RANK)
{
if(!gUnknown_203B490->PKMNNewsReceived[0x36])
if(!sub_8096E80(0x36)) floor = 0x36;
}
if(sub_80023E4(6))
{
if(!gUnknown_203B490->PKMNNewsReceived[0x37])
if(!sub_8096E80(0x37)) floor = 0x37;
}
if(floor != 0x38) goto _slot;
if(num > index) goto _08096392;
floor = sub_8096E2C();
if(!sub_80023E4(0xE) && (floor > 2)) goto _0809638E;
if (floor > 0x31) goto _0809638E;
_slot:
slot = GetMailboxSlotInfo(num);
slot->mailType = 1;
slot->unk4.dungeon.id = NUM_DUNGEONS;
slot->unk4.dungeon.floor = floor;
goto _flag;
_0809638E:
for(; num <= index; num++)
{
slot = GetMailboxSlotInfo(num);
if(GenerateMailJobInfo(slot))
{
friendAreaReward = sub_8095E78();
if(!sub_803C1D0(&slot->unk4.dungeon, slot->missionType)) friendAreaReward = FRIEND_AREA_NONE;
slot->rewardType = RandRange(MONEY1, END_REWARDS);
if(slot->rewardType == FRIEND_AREA)
{
if(friendAreaReward == FRIEND_AREA_NONE)
{
slot->rewardType = MONEY1;
flag = TRUE;
}
else
{
slot->friendAreaReward = friendAreaReward;
flag = TRUE;
}
}
else
{
_flag:
flag = TRUE;
}
} else break;
}
_08096392:
if(sub_80963B4())
flag = TRUE;
sub_8096078();
SortMailboxSlots();
return flag;
}
bool8 sub_80963B4(void)
{
u8 floor;
s32 num;
WonderMail *slot;
bool8 flag = FALSE;
floor = sub_8096E2C();
num = CountFilledMailboxSlots();
if(num >= NUM_MAILBOX_SLOTS) return FALSE;
if(sub_80023E4(0xE))
{
if(floor < 0x32)
{
slot = GetMailboxSlotInfo(num);
slot->mailType = 1;
slot->unk4.dungeon.id = NUM_DUNGEONS;
slot->unk4.dungeon.floor = floor;
flag = TRUE;
}
}
return flag;
}
void sub_80963FC(void)
{
s32 index;
WonderMail *slot;
for(index = 0; index < NUM_MAILBOX_SLOTS; index++)
{
slot = GetMailboxSlotInfo(index);
if(slot->mailType != 1)
{
ResetMailboxSlot(index);
}
}
sub_8096078();
slot = GetMailboxSlotInfo(CountFilledMailboxSlots());
slot->mailType = 5;
slot->missionType = 0;
slot->unk2 = 0;
slot->unk4.dungeon.id = DUNGEON_MT_STEEL;
slot->unk4.dungeon.floor = 3;
slot->unk4.seed = 0x00ffffff & Rand32Bit();
slot->clientSpecies = MONSTER_PIDGEY;
slot->targetSpecies = MONSTER_PIDGEY;
slot->targetItem = sub_8095F28(slot->unk4.dungeon.id);
slot->rewardType = MONEY1;
do
{
sub_803C37C(&slot->unk4.dungeon, slot->missionType, &slot->itemReward);
} while (slot->targetItem == slot->itemReward);
slot->friendAreaReward = FRIEND_AREA_NONE;
sub_8096078();
SortMailboxSlots();
}
void sub_8096488(void)
{
WonderMail *mail;
s32 index;
for(index = 0; index < NUM_MAILBOX_SLOTS; index++){
ResetMailboxSlot(index);
}
mail = GetMailboxSlotInfo(0);
mail->mailType = 1;
mail->unk4.dungeon.id = NUM_DUNGEONS;
mail->unk4.dungeon.floor = 0;
}
bool8 sub_80964B4(void)
{
if ((!gUnknown_203B490->PKMNNewsReceived[0x35]) && (sub_8096E80(0x35) == 0)) {
return FALSE;
}
else {
return TRUE;
}
}
bool8 sub_80964E4(void)
{
if ((!gUnknown_203B490->PKMNNewsReceived[0x36]) && (sub_8096E80(0x36) == 0)) {
return FALSE;
}
else {
return TRUE;
}
}
s32 CountFilledPelipperBoardSlots(void)
{
s32 index;
s32 slots;
slots = 0;
for(index = 0; index < MAX_ACCEPTED_JOBS; index++) {
if (!IsPelipperBoardSlotEmpty(index)) {
slots++;
}
}
return slots;
}
UNUSED bool8 sub_8096538(WonderMail *mail)
{
s32 index;
for(index = 0; index < MAX_ACCEPTED_JOBS; index++)
{
if(gUnknown_203B490->pelipperBoardJobs[index].mailType == 0)
{
gUnknown_203B490->pelipperBoardJobs[index] = *mail;
return FALSE;
}
}
return TRUE;
}
WonderMail *GetPelipperBoardSlotInfo(u8 index)
{
return &gUnknown_203B490->pelipperBoardJobs[index];
}
bool8 IsPelipperBoardSlotEmpty(u8 index)
{
if (gUnknown_203B490->pelipperBoardJobs[index].mailType == 0)
return TRUE;
else
return FALSE;
}
void ResetPelipperBoardSlot(u8 index)
{
gUnknown_203B490->pelipperBoardJobs[index].mailType = MAIL_TYPE_NONE;
gUnknown_203B490->pelipperBoardJobs[index].unk4.dungeon.id = 99;
gUnknown_203B490->pelipperBoardJobs[index].unk4.dungeon.floor = 0;
gUnknown_203B490->pelipperBoardJobs[index].rewardType = 0;
}
void sub_80965F4(void)
{
int counter1; // r5
int counter2;
counter1 = 0;
counter2 = 0;
do {
for( ; counter1 < 8; counter1++)
{
if (gUnknown_203B490->pelipperBoardJobs[counter1].mailType != 0)
break;
}
if (counter1 == 8) {
break;
}
if (counter1 > counter2) {
gUnknown_203B490->pelipperBoardJobs[counter2] = gUnknown_203B490->pelipperBoardJobs[counter1];
}
counter1++;
counter2++;
} while( 1 );
for(; counter2 < 8; counter2++)
{
gUnknown_203B490->pelipperBoardJobs[counter2].mailType = 0;
}
}
void SortPelipperJobs(void)
{
s32 index1;
s32 index2;
WonderMail mail;
for(index1 = 0; index1 < MAX_ACCEPTED_JOBS - 1; index1++)
{
for(index2 = index1 + 1; index2 < MAX_ACCEPTED_JOBS; index2++)
{
if(gUnknown_203B490->pelipperBoardJobs[index2].mailType != MAIL_TYPE_NONE)
{
if((gUnknown_203B490->pelipperBoardJobs[index1].unk4.dungeon.id > gUnknown_203B490->pelipperBoardJobs[index2].unk4.dungeon.id) ||
((gUnknown_203B490->pelipperBoardJobs[index1].unk4.dungeon.id == gUnknown_203B490->pelipperBoardJobs[index2].unk4.dungeon.id) && (gUnknown_203B490->pelipperBoardJobs[index1].unk4.dungeon.floor > gUnknown_203B490->pelipperBoardJobs[index2].unk4.dungeon.floor)))
{
mail = gUnknown_203B490->pelipperBoardJobs[index1];
gUnknown_203B490->pelipperBoardJobs[index1] = gUnknown_203B490->pelipperBoardJobs[index2];
gUnknown_203B490->pelipperBoardJobs[index2] = mail;
}
}
}
}
}
void GeneratePelipperJobs(void)
{
s32 range;
WonderMail *mail;
s32 index;
range = RandRange(4,8);
for(index = 0; index < MAX_ACCEPTED_JOBS; index++)
{
gUnknown_203B490->pelipperBoardJobs[index].mailType = MAIL_TYPE_NONE;
}
index = 0;
if (sub_8097318(0xe) != 0) {
mail = GetPelipperBoardSlotInfo(0);
mail->mailType = MAIL_TYPE_UNK2;
mail->missionType = WONDER_MAIL_MISSION_TYPE_UNK6;
mail->unk2 = 1;
mail->unk4.dungeon.id = DUNGEON_UPROAR_FOREST;
mail->unk4.dungeon.floor = 10;
mail->unk4.seed = Rand32Bit() & 0xffffff;
mail->clientSpecies = MONSTER_WYNAUT;
mail->targetSpecies = MONSTER_MANKEY;
mail->targetItem = 0;
mail->rewardType = ITEM;
mail->itemReward = ITEM_REVIVER_SEED;
mail->friendAreaReward = 0;
index = 1;
}
if (sub_8097318(0xf) != 0) {
mail = GetPelipperBoardSlotInfo(index);
mail->mailType = MAIL_TYPE_UNK3;
mail->missionType = WONDER_MAIL_MISSION_TYPE_UNK6;
mail->unk2 = 2;
mail->unk4.dungeon.id = DUNGEON_HOWLING_FOREST;
mail->unk4.dungeon.floor = 15;
mail->unk4.seed = Rand32Bit() & 0xffffff;
mail->clientSpecies = MONSTER_SMEARGLE;
mail->targetSpecies = MONSTER_SMEARGLE;
mail->targetItem = 0;
mail->rewardType = ITEM;
mail->itemReward = ITEM_REVIVER_SEED;
mail->friendAreaReward = 0;
index++;
}
if (sub_8097318(0x1c) != 0) {
mail = GetPelipperBoardSlotInfo(index);
mail->mailType = MAIL_TYPE_UNK4;
mail->missionType = WONDER_MAIL_MISSION_TYPE_UNK6;
mail->unk2 = 3;
mail->unk4.dungeon.id = DUNGEON_WISH_CAVE;
mail->unk4.dungeon.floor = 20;
mail->unk4.seed = Rand32Bit() & 0xffffff;
mail->clientSpecies = MONSTER_MEDICHAM;
mail->targetSpecies = MONSTER_MEDICHAM;
mail->targetItem = 0;
mail->rewardType = ITEM;
mail->itemReward = ITEM_REVIVER_SEED;
mail->friendAreaReward = 0;
index++;
}
for (; index <= range; index++) {
if (!GenerateMailJobInfo(&gUnknown_203B490->pelipperBoardJobs[index])) break;
gUnknown_203B490->pelipperBoardJobs[index].rewardType = RandRange(MONEY, BLANK_4);
}
sub_80965F4();
SortPelipperJobs();
}
bool8 IsMailinJobSlot(WonderMail *mail)
{
WonderMail *jobSlot;
s32 index;
for(index = 0, jobSlot = &gUnknown_203B490->jobSlots[0]; index < MAX_ACCEPTED_JOBS; jobSlot++, index++)
{
if(jobSlot->mailType != MAIL_TYPE_NONE)
if(mail->missionType == jobSlot->missionType)
if(mail->unk2 == jobSlot->unk2)
if(mail->unk4.dungeon.id == jobSlot->unk4.dungeon.id)
if(mail->unk4.dungeon.floor == jobSlot->unk4.dungeon.floor)
if(mail->unk4.seed == jobSlot->unk4.seed)
if(mail->clientSpecies == jobSlot->clientSpecies)
if(mail->targetSpecies == jobSlot->targetSpecies)
if(mail->targetItem == jobSlot->targetItem)
if(mail->rewardType == jobSlot->rewardType)
if(mail->itemReward == jobSlot->itemReward)
if(mail->friendAreaReward == jobSlot->friendAreaReward)
return TRUE;
}
return FALSE;
}
bool8 sub_809693C(WonderMail *mail)
{
u8 dungeonIndex;
u8 floor;
bool8 escortMission;
s32 index;
dungeonIndex = mail->unk4.dungeon.id;
floor = mail->unk4.dungeon.floor;
escortMission = FALSE;
if (!IsValidWonderMail(mail)) {
return FALSE;
}
else
{
if(mail->missionType == WONDER_MAIL_MISSION_TYPE_ESCORT_CLIENT)
escortMission = TRUE;
for(index = 0; index < MAX_ACCEPTED_JOBS; index++)
{
if ((gUnknown_203B490->jobSlots[index].mailType == MAIL_TYPE_TAKEN_JOB) &&
(sub_8095E38(&gUnknown_203B490->jobSlots[index],dungeonIndex,floor,escortMission) != 0))
{
return TRUE;
}
}
}
return FALSE;
}
s32 GetNumAcceptedJobs(void)
{
s32 index;
s32 count;
count = 0;
for(index = 0; index < MAX_ACCEPTED_JOBS; index++)
{
if (!IsJobSlotEmpty(index)) {
count++;
}
}
return count;
}
s32 CountJobsinDungeon(u8 dungeon)
{
WonderMail *mail;
s32 index;
s32 count;
count = 0;
for(index = 0; index < MAX_ACCEPTED_JOBS; index++)
{
mail = GetJobSlotInfo(index);
if ((mail->unk4.dungeon.id == dungeon) &&
(((mail->mailType == MAIL_TYPE_TAKEN_JOB || (mail->mailType == MAIL_TYPE_UNK8)) || (mail->mailType == MAIL_TYPE_UNK9)))) {
count++;
}
}
return count;
}
bool8 sub_8096A08(u8 dungeon, PokemonStruct1 *pokemon)
{
WonderMail *mail;
s32 index;
u32 local_14;
s32 temp;
for(index = 0; index < MAX_ACCEPTED_JOBS; index++)
{
mail = GetJobSlotInfo(index);
if(mail->unk4.dungeon.id == dungeon)
if(mail->mailType == MAIL_TYPE_TAKEN_JOB)
if(mail->missionType == WONDER_MAIL_MISSION_TYPE_ESCORT_CLIENT)
{
temp = 0xffffff00;
local_14 &= temp;
temp = 0x4A;
local_14 |= temp;
temp = 0xffff00ff;
local_14 &= temp;
temp = 0x100;
local_14 |= temp;
sub_808CFD0(pokemon,mail->clientSpecies,NULL,0,(DungeonLocation *) &local_14,NULL);
return TRUE;
}
}
return FALSE;
}
bool8 AcceptJob(WonderMail *mail)
{
s32 index;
for(index = 0; index < MAX_ACCEPTED_JOBS; index++)
{
if(gUnknown_203B490->jobSlots[index].mailType == MAIL_TYPE_NONE)
{
gUnknown_203B490->jobSlots[index] = *mail;
return FALSE;
}
}
return TRUE;
}
WonderMail *GetJobSlotInfo(u8 index)
{
return &gUnknown_203B490->jobSlots[index];
}
bool8 IsJobSlotEmpty(u8 index)
{
if(gUnknown_203B490->jobSlots[index].mailType == MAIL_TYPE_NONE)
return TRUE;
else
return FALSE;
}
void sub_8096AF8(struct unkStruct_8096AF8 *param_1, u8 slotIndex,u8 dungeon)
{
WonderMail *jobSlot;
Item *item;
s32 index;
jobSlot = GetJobSlotInfo(slotIndex);
param_1->unk0 = FALSE;
param_1->clientSpecies = jobSlot->clientSpecies;
param_1->targetSpecies = MONSTER_NONE;
if (jobSlot->unk4.dungeon.id == dungeon) {
switch(jobSlot->missionType) {
case WONDER_MAIL_MISSION_TYPE_FIND_ITEM:
if (jobSlot->mailType == MAIL_TYPE_TAKEN_JOB) {
for(index = 0; index < INVENTORY_SIZE; index++)
{
item = &gTeamInventoryRef->teamItems[index];
if (((item->flags & ITEM_FLAG_EXISTS)) && (item->id == jobSlot->targetItem)) {
param_1->unk0 = TRUE;
}
}
}
break;
case WONDER_MAIL_MISSION_TYPE_RESCUE_CLIENT:
case WONDER_MAIL_MISSION_TYPE_DELIVER_ITEM:
if (jobSlot->mailType == MAIL_TYPE_UNK9) {
param_1->unk0 = TRUE;
}
break;
case WONDER_MAIL_MISSION_TYPE_RESCUE_TARGET:
case WONDER_MAIL_MISSION_TYPE_ESCORT_CLIENT:
if (jobSlot->mailType == MAIL_TYPE_UNK9) {
param_1->unk0 = TRUE;
param_1->targetSpecies = jobSlot->targetSpecies;
}
break;
}
}
}
// Unused
s16 sub_8096B98(u8 dungeon)
{
WonderMail *mail;
s32 index;
for(index = 0; index < MAX_ACCEPTED_JOBS; index++)
{
mail = GetJobSlotInfo(index);
if(mail->mailType == MAIL_TYPE_TAKEN_JOB)
if(mail->missionType == WONDER_MAIL_MISSION_TYPE_ESCORT_CLIENT)
if(mail->unk4.dungeon.id == dungeon)
return mail->targetSpecies;
}
return 0;
}
void sub_8096BD0(void)
{
s32 index;
WonderMail *mail;
for(mail = &gUnknown_203B490->jobSlots[0], index = 0; index < MAX_ACCEPTED_JOBS; mail++, index++)
{
switch(mail->mailType)
{
case MAIL_TYPE_UNK7:
case MAIL_TYPE_UNK8:
case MAIL_TYPE_UNK9:
ResetJobSlot(index);
break;
}
}
sub_8096C80();
SortJobSlots();
}
bool8 sub_8096C08(u8 *jobIndex)
{
s32 index;
WonderMail *mail;
for(mail = &gUnknown_203B490->jobSlots[0], index = 0; index < MAX_ACCEPTED_JOBS; mail++, index++)
{
if(mail->mailType > 4 && mail->unk2 == 4)
{
*jobIndex = index;
return TRUE;
}
}
return FALSE;
}
void ResetJobSlot(u8 index)
{
gUnknown_203B490->jobSlots[index].mailType = MAIL_TYPE_NONE;
gUnknown_203B490->jobSlots[index].unk4.dungeon.id = 99;
gUnknown_203B490->jobSlots[index].unk4.dungeon.floor = 0;
gUnknown_203B490->jobSlots[index].rewardType = MONEY1;
}
void sub_8096C80(void)
{
int counter1; // r5
int counter2;
counter1 = 0;
counter2 = 0;
do {
for( ; counter1 < 8; counter1++)
{
if (gUnknown_203B490->jobSlots[counter1].mailType != 0)
break;
}
if (counter1 == 8) {
break;
}
if (counter1 > counter2) {
gUnknown_203B490->jobSlots[counter2] = gUnknown_203B490->jobSlots[counter1];
}
counter1++;
counter2++;
} while( 1 );
for(; counter2 < 8; counter2++)
{
gUnknown_203B490->jobSlots[counter2].mailType = 0;
}
}

View File

@ -1,7 +1,4 @@
#include "global.h"
#include "constants/dungeon.h"
#include "pokemon.h"
#include "code_80958E8.h"
#include "dungeon.h"
#include "exclusive_pokemon.h"
#include "event_flag.h"
@ -14,273 +11,10 @@ ALIGNED(4) const u8 gDummyScenarioText[] = _("{COLOR_1 YELLOW_3}Scenario try dum
ALIGNED(4) const u8 gBlankMission[] = _("{COLOR_1 RED_2}???{END_COLOR_TEXT_1}");
extern void sub_800199C(u8, u8, u16, s32);
extern void SaveDungeonLocation(struct unkStruct_8094924*, DungeonLocation*);
extern void RestoreDungeonLocation(struct unkStruct_8094924*, DungeonLocation*);
extern u32 sub_8001784(u32, u32, u16);
extern void GeneratePelipperJobs(void);
extern void sub_80018D8(u8, u8, u32);
void SaveWonderMail(struct unkStruct_8094924 *a, WonderMail *b);
void RestoreWonderMail(struct unkStruct_8094924 *a, WonderMail *b);
s32 CalculateMailChecksum(WonderMail *mail);
void SortJobSlots(void)
{
s32 r1;
s32 r6;
WonderMail job;
for(r1 = 0; r1 < MAX_ACCEPTED_JOBS - 1; r1++)
{
for(r6 = r1 + 1; r6 < MAX_ACCEPTED_JOBS; r6++)
{
if(gUnknown_203B490->jobSlots[r6].mailType != 0)
{
if((gUnknown_203B490->jobSlots[r1].unk4.dungeon.id > gUnknown_203B490->jobSlots[r6].unk4.dungeon.id) ||
((gUnknown_203B490->jobSlots[r1].unk4.dungeon.id == gUnknown_203B490->jobSlots[r6].unk4.dungeon.id) &&
(gUnknown_203B490->jobSlots[r1].unk4.dungeon.floor > gUnknown_203B490->jobSlots[r6].unk4.dungeon.floor)))
{
job = gUnknown_203B490->jobSlots[r1];
gUnknown_203B490->jobSlots[r1] = gUnknown_203B490->jobSlots[r6];
gUnknown_203B490->jobSlots[r6] = job;
}
}
}
}
}
u8 *sub_8096DD8(void)
{
return gUnknown_203B490->unk190;
}
u8 *sub_8096DE8(void)
{
return gUnknown_203B490->unk1B8;
}
void ReceivePKMNNews(u8 index)
{
gUnknown_203B490->PKMNNewsReceived[index] = TRUE;
}
bool8 CheckPKMNNewsSlot(u8 index)
{
return gUnknown_203B490->PKMNNewsReceived[index];
}
u8 sub_8096E2C(void)
{
s32 index;
s32 floor = 0;
for(index = 0; index < NUM_MAILBOX_SLOTS; index++)
{
if(gUnknown_203B490->mailboxSlots[index].mailType == 1)
{
if(floor <= gUnknown_203B490->mailboxSlots[index].unk4.dungeon.floor)
if( gUnknown_203B490->mailboxSlots[index].unk4.dungeon.floor < 0x32)
floor = gUnknown_203B490->mailboxSlots[index].unk4.dungeon.floor + 1;
}
}
for(index = floor; index < 0x32; index++)
{
if(!gUnknown_203B490->PKMNNewsReceived[index]) return index;
}
return 0x38;
}
bool8 sub_8096E80(u8 floor)
{
s32 index;
for(index = 0; index < NUM_MAILBOX_SLOTS; index++)
{
if(gUnknown_203B490->mailboxSlots[index].mailType == 1)
{
if(floor == gUnknown_203B490->mailboxSlots[index].unk4.dungeon.floor)
return TRUE;
}
}
return FALSE;
}
s32 CalculateMailChecksum(WonderMail *mail)
{
s32 sum;
sum = (mail->unk2 + mail->missionType);
sum += mail->unk4.dungeon.id;
sum += mail->unk4.dungeon.floor;
sum += mail->unk4.seed << 0x8;
sum += mail->clientSpecies << 0xC;
sum += mail->targetSpecies << 0x10;
sum += mail->targetItem << 0x18;
sum += mail->rewardType;
sum += mail->itemReward;
sum += mail->friendAreaReward;
return sum;
}
void sub_8096EEC(WonderMail *mail)
{
s32 index;
for(index = 15; index > 0; index--)
{
gUnknown_203B490->unk230[index] = gUnknown_203B490->unk230[index - 1];
}
gUnknown_203B490->unk230[0].sub = mail->unk4;
gUnknown_203B490->unk230[0].checksum = CalculateMailChecksum(mail);
}
bool8 sub_8096F50(WonderMail *mail)
{
s32 index;
s32 checksum;
subStruct_203B490 *temp;
checksum = CalculateMailChecksum(mail);
for (index = 0; index < 0x10; index++) {
temp = &gUnknown_203B490->unk230[index];
if (temp->sub.dungeon.id == mail->unk4.dungeon.id)
if (temp->sub.dungeon.floor == mail->unk4.dungeon.floor)
if (temp->sub.seed == mail->unk4.seed)
if (temp->checksum == checksum)
return TRUE;
}
return FALSE;
}
u32 RestoreMailInfo(u8 *r0, u32 size)
{
s32 index;
struct unkStruct_8094924 backup;
u32 temp;
xxx_init_struct_8094924_restore_809485C(&backup, r0, size);
for(index = 0; index < NUM_MAILBOX_SLOTS; index++)
{
RestoreWonderMail(&backup, &gUnknown_203B490->mailboxSlots[index]);
}
for(index = 0; index < MAX_ACCEPTED_JOBS; index++)
{
RestoreWonderMail(&backup, &gUnknown_203B490->pelipperBoardJobs[index]);
}
for(index = 0; index < MAX_ACCEPTED_JOBS; index++)
{
RestoreWonderMail(&backup, &gUnknown_203B490->jobSlots[index]);
}
for(index = 0; index < 0x38; index++)
{
RestoreIntegerBits(&backup, &temp, 1);
if(temp & 1)
gUnknown_203B490->PKMNNewsReceived[index] = TRUE;
else
gUnknown_203B490->PKMNNewsReceived[index] = FALSE;
}
RestoreIntegerBits(&backup, &temp, 1);
if(temp & 1)
gUnknown_203B490->unk328 = TRUE;
else
gUnknown_203B490->unk328 = FALSE;
RestoreIntegerBits(&backup, gUnknown_203B490->unk190, 0x140);
RestoreIntegerBits(&backup, gUnknown_203B490->unk1B8, 0x3C0);
for(index = 0; index < 0x10; index++)
{
RestoreIntegerBits(&backup, &gUnknown_203B490->unk230[index].checksum, 0x20);
RestoreIntegerBits(&backup, &gUnknown_203B490->unk230[index].sub.seed, 0x18);
RestoreDungeonLocation(&backup, &gUnknown_203B490->unk230[index].sub.dungeon);
}
nullsub_102(&backup);
return backup.unk8;
}
u32 SaveMailInfo(u8 *r0, u32 size)
{
s32 index;
struct unkStruct_8094924 backup;
u32 temp;
xxx_init_struct_8094924_save_809486C(&backup, r0, size);
for(index = 0; index < NUM_MAILBOX_SLOTS; index++)
{
SaveWonderMail(&backup, &gUnknown_203B490->mailboxSlots[index]);
}
for(index = 0; index < MAX_ACCEPTED_JOBS; index++)
{
SaveWonderMail(&backup, &gUnknown_203B490->pelipperBoardJobs[index]);
}
for(index = 0; index < MAX_ACCEPTED_JOBS; index++)
{
SaveWonderMail(&backup, &gUnknown_203B490->jobSlots[index]);
}
for(index = 0; index < 0x38; index++)
{
if(gUnknown_203B490->PKMNNewsReceived[index])
temp = -1;
else
temp = 0;
SaveIntegerBits(&backup, &temp, 1);
}
if(gUnknown_203B490->unk328)
temp = -1;
else
temp = 0;
SaveIntegerBits(&backup, &temp, 1);
SaveIntegerBits(&backup, gUnknown_203B490->unk190, 0x140);
SaveIntegerBits(&backup, gUnknown_203B490->unk1B8, 0x3C0);
for(index = 0; index < 0x10; index++)
{
SaveIntegerBits(&backup, &gUnknown_203B490->unk230[index].checksum, 0x20);
SaveIntegerBits(&backup, &gUnknown_203B490->unk230[index].sub.seed, 0x18);
SaveDungeonLocation(&backup, &gUnknown_203B490->unk230[index].sub.dungeon);
}
nullsub_102(&backup);
return backup.unk8;
}
void RestoreWonderMail(struct unkStruct_8094924 *a, WonderMail *b)
{
RestoreIntegerBits(a, &b->mailType, 4);
RestoreIntegerBits(a, &b->missionType, 3);
RestoreIntegerBits(a, &b->unk2, 4);
RestoreIntegerBits(a, &b->clientSpecies, 9);
RestoreIntegerBits(a, &b->targetSpecies, 9);
RestoreIntegerBits(a, &b->targetItem, 8);
RestoreIntegerBits(a, &b->rewardType, 4);
RestoreIntegerBits(a, &b->itemReward, 8);
RestoreIntegerBits(a, &b->friendAreaReward, 6);
RestoreIntegerBits(a, &b->unk4.seed, 0x18);
RestoreDungeonLocation(a, &b->unk4.dungeon);
}
void SaveWonderMail(struct unkStruct_8094924 *a, WonderMail *b)
{
SaveIntegerBits(a, &b->mailType, 4);
SaveIntegerBits(a, &b->missionType, 3);
SaveIntegerBits(a, &b->unk2, 4);
SaveIntegerBits(a, &b->clientSpecies, 9);
SaveIntegerBits(a, &b->targetSpecies, 9);
SaveIntegerBits(a, &b->targetItem, 8);
SaveIntegerBits(a, &b->rewardType, 4);
SaveIntegerBits(a, &b->itemReward, 8);
SaveIntegerBits(a, &b->friendAreaReward, 6);
SaveIntegerBits(a, &b->unk4.seed, 0x18);
SaveDungeonLocation(a, &b->unk4.dungeon);
}
void sub_80972F4(void)
{
sub_80015C0(0, 0x2B);

View File

@ -13,7 +13,6 @@ extern void sub_800199C(u8, u8, u16, s32);
extern u32 sub_8001784(u32, u32, u16);
extern void sub_80018D8(u8, u8, u32);
bool8 sub_8097504(s16 mazeIndex)
{
s32 mazeIndex_s32;

View File

@ -15,10 +15,9 @@
#include "pokemon_news3.h"
#include "code_80958E8.h"
#include "code_803B050.h"
#include "code_80958E8_1.h"
#include "code_80958E8.h"
#include "wonder_mail_802C4C8.h"
#include "wonder_mail_802C860.h"
#include "code_8096AF8.h"
EWRAM_DATA_2 struct unkStruct_203B304 *gUnknown_203B304 = {0};

View File

@ -14,11 +14,10 @@
#include "pelipper_board.h"
#include "code_80118A4.h"
#include "wonder_mail_802C10C.h"
#include "code_80958E8_1.h"
#include "code_80958E8.h"
#include "code_803B050.h"
#include "wonder_mail_802C4C8.h"
#include "wonder_mail_802C860.h"
#include "code_8096AF8.h"
EWRAM_DATA_2 struct unkStruct_203B308 *gPelipperBoard = {0};
@ -80,9 +79,6 @@ extern void sub_802EC10(void);
extern void CreatePelipperAcceptedStatusBox(u32);
extern void ResetPelipperBoardSlot(u8);
extern void sub_80965F4(void);
void SetPelipperBoardState(u32);
u32 sub_802E864(void)

View File

@ -2,7 +2,7 @@
#include "globaldata.h"
#include "code_80118A4.h"
#include "code_80130A8.h"
#include "code_8096AF8.h"
#include "code_80958E8.h"
#include "constants/input.h"
#include "input.h"
#include "pokemon_mail.h"

View File

@ -3,7 +3,7 @@
#include "code_800D090.h"
#include "code_80118A4.h"
#include "code_803B050.h"
#include "code_80958E8_1.h"
#include "code_80958E8.h"
#include "constants/input.h"
#include "constants/mailbox.h"
#include "input.h"

View File

@ -3,7 +3,7 @@
#include "code_800D090.h"
#include "code_80118A4.h"
#include "code_8094F88.h"
#include "code_80958E8_1.h"
#include "code_80958E8.h"
#include "code_80972F4.h"
#include "code_80A26CC.h"
#include "constants/mailbox.h"
@ -184,4 +184,4 @@ static void DisplayMissionObjectives(void)
}
sub_80073E0(sUnknown_203B330->unk10);
}
}

View File

@ -2,7 +2,7 @@
#include "globaldata.h"
#include "code_80118A4.h"
#include "code_803B050.h"
#include "code_80958E8_1.h"
#include "code_80958E8.h"
#include "constants/input.h"
#include "input.h"
#include "memory.h"
@ -228,4 +228,4 @@ bool8 HasNoPelipperBoardJobs(void)
}
return TRUE;
}
}

View File

@ -2,7 +2,7 @@
#include "globaldata.h"
#include "code_80118A4.h"
#include "code_803B050.h"
#include "code_80958E8_1.h"
#include "code_80958E8.h"
#include "constants/input.h"
#include "input.h"
#include "memory.h"
@ -221,4 +221,4 @@ bool8 HasNoAcceptedJobs(void)
}
return TRUE;
}
}

View File

@ -3,8 +3,7 @@
#include "code_80118A4.h"
#include "code_803B050.h"
#include "code_802DE84.h"
#include "code_80958E8_1.h"
#include "code_8096AF8.h"
#include "code_80958E8.h"
#include "code_80A26CC.h"
#include "common_strings.h"
#include "input.h"
@ -308,4 +307,4 @@ static void sub_802CDB8(void)
case 1:
break;
}
}
}

View File

@ -3,8 +3,7 @@
#include "code_80130A8.h"
#include "code_802DE84.h"
#include "code_803B050.h"
#include "code_80958E8_1.h"
#include "code_8096AF8.h"
#include "code_80958E8.h"
#include "code_80972F4.h"
#include "code_8098BDC.h"
#include "common_strings.h"