summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/apprentice.c74
-rw-r--r--src/battle_bg.c98
-rw-r--r--src/battle_dome.c130
-rw-r--r--src/battle_factory.c30
-rw-r--r--src/battle_frontier_1.c8
-rw-r--r--src/battle_main.c8
-rw-r--r--src/battle_message.c7
-rw-r--r--src/battle_pyramid_bag.c18
-rw-r--r--src/battle_records.c4
-rw-r--r--src/battle_setup.c11
-rw-r--r--src/battle_tent.c22
-rw-r--r--src/battle_tower.c2798
-rw-r--r--src/berry_blender.c16
-rw-r--r--src/berry_tag_screen.c8
-rw-r--r--src/cable_club.c6
-rw-r--r--src/clear_save_data_screen.c8
-rw-r--r--src/credits.c16
-rw-r--r--src/daycare.c2
-rw-r--r--src/decoration.c8
-rw-r--r--src/diploma.c19
-rw-r--r--src/egg_hatch.c16
-rw-r--r--src/field_region_map.c4
-rw-r--r--src/field_specials.c92
-rwxr-xr-xsrc/item_menu.c32
-rw-r--r--src/mail.c2
-rw-r--r--src/main_menu.c46
-rw-r--r--src/map_name_popup.c4
-rw-r--r--src/menu.c10
-rw-r--r--src/mystery_event_menu.c4
-rw-r--r--src/naming_screen.c10
-rw-r--r--src/option_menu.c4
-rw-r--r--src/player_pc.c18
-rw-r--r--src/pokeblock.c24
-rw-r--r--src/pokemon.c8
-rw-r--r--src/pokemon_summary_screen.c64
-rw-r--r--src/record_mixing.c31
-rw-r--r--src/recorded_battle.c30
-rw-r--r--src/save_failed_screen.c6
-rw-r--r--src/secret_base.c3
-rwxr-xr-xsrc/shop.c32
-rw-r--r--src/start_menu.c4
-rw-r--r--src/starter_choose.c12
-rw-r--r--src/text_window.c10
-rw-r--r--src/tv.c6
-rw-r--r--src/wallclock.c8
-rw-r--r--src/wild_encounter.c4
-rw-r--r--src/window.c66
47 files changed, 3259 insertions, 582 deletions
diff --git a/src/apprentice.c b/src/apprentice.c
index f2a8aa9c0..065d9cf16 100644
--- a/src/apprentice.c
+++ b/src/apprentice.c
@@ -344,13 +344,6 @@ extern struct Unk030062ECStruct *gUnknown_030062EC;
extern struct Unk030062F0Struct *gUnknown_030062F0;
extern void (*gUnknown_030062F4)(void);
-extern void sub_8165AE8(struct Apprentice *);
-
-extern const u8 gUnknown_085DCEDC[];
-extern const u8 gUnknown_085DCF0E[];
-extern const u8 gUnknown_085DCEFA[];
-extern const u8 gUnknown_085DCF2C[];
-
// This file's functions.
static u16 sub_819FF98(u8 arg0);
static bool8 sub_81A0194(u8 arg0, u16 moveId);
@@ -382,7 +375,7 @@ static void sub_81A1218(void);
static void sub_81A1224(void);
static void sub_81A1438(void);
static void sub_81A150C(void);
-static void sub_81A15A4(void);
+static void Script_SetPlayerApprenticeTrainerGfxId(void);
static void sub_81A1644(void);
static void sub_81A1370(void);
@@ -1030,7 +1023,7 @@ static void (* const sApprenticeFunctions[])(void) =
sub_81A1224,
sub_81A1438,
sub_81A150C,
- sub_81A15A4,
+ Script_SetPlayerApprenticeTrainerGfxId,
sub_81A1644,
sub_81A1370,
};
@@ -1092,7 +1085,7 @@ void ResetAllApprenticeData(void)
for (j = 0; j < 4; j++)
gSaveBlock2Ptr->apprentices[i].playerId[j] = 0;
gSaveBlock2Ptr->apprentices[i].language = gGameLanguage;
- gSaveBlock2Ptr->apprentices[i].unk40 = 0;
+ gSaveBlock2Ptr->apprentices[i].checksum = 0;
}
Script_ResetPlayerApprentice();
@@ -1435,16 +1428,16 @@ static void sub_81A0390(u8 arg0)
for (i = 0; i < 3; i++)
{
- gSaveBlock2Ptr->apprentices[0].monData[i].species = 0;
- gSaveBlock2Ptr->apprentices[0].monData[i].item = 0;
+ gSaveBlock2Ptr->apprentices[0].party[i].species = 0;
+ gSaveBlock2Ptr->apprentices[0].party[i].item = 0;
for (j = 0; j < 4; j++)
- gSaveBlock2Ptr->apprentices[0].monData[i].moves[j] = 0;
+ gSaveBlock2Ptr->apprentices[0].party[i].moves[j] = 0;
}
j = PLAYER_APPRENTICE.field_B1_2;
for (i = 0; i < 3; i++)
{
- apprenticeMons[j] = &gSaveBlock2Ptr->apprentices[0].monData[i];
+ apprenticeMons[j] = &gSaveBlock2Ptr->apprentices[0].party[i];
j = (j + 1) % 3;
}
@@ -1975,7 +1968,7 @@ static void sub_81A0FFC(void)
StringCopy(stringDst, gText_OpenLevel);
break;
case APPRENTICE_BUFF_EASY_CHAT:
- ConvertBattleFrontierTrainerSpeechToString(gSaveBlock2Ptr->apprentices[0].easyChatWords);
+ FrontierSpeechToString(gSaveBlock2Ptr->apprentices[0].easyChatWords);
StringCopy(stringDst, gStringVar4);
break;
case APPRENTICE_BUFF_SPECIES4:
@@ -2261,7 +2254,7 @@ static void sub_81A1438(void)
StringCopy(gSaveBlock2Ptr->apprentices[0].playerName, gSaveBlock2Ptr->playerName);
gSaveBlock2Ptr->apprentices[0].language = gGameLanguage;
- sub_8165AE8(&gSaveBlock2Ptr->apprentices[0]);
+ CalcApprenticeChecksum(&gSaveBlock2Ptr->apprentices[0]);
}
static void sub_81A150C(void)
@@ -2270,51 +2263,46 @@ static void sub_81A150C(void)
u8 mapObjectGfxId;
u8 class = gApprentices[gSaveBlock2Ptr->apprentices[0].id].facilityClass;
- for (i = 0; i < 30 && gUnknown_085DCEDC[i] != class; i++)
+ // Search male classes.
+ for (i = 0; i < ARRAY_COUNT(gTowerMaleFacilityClasses) && gTowerMaleFacilityClasses[i] != class; i++)
;
-
- if (i != 30)
+ if (i != ARRAY_COUNT(gTowerMaleFacilityClasses))
{
- mapObjectGfxId = gUnknown_085DCF0E[i];
+ mapObjectGfxId = gTowerMaleTrainerGfxIds[i];
VarSet(VAR_OBJ_GFX_ID_0, mapObjectGfxId);
+ return;
}
- else
- {
- for (i = 0; i < 20 && gUnknown_085DCEFA[i] != class; i++)
- ;
- if (i != 20)
- {
- mapObjectGfxId = gUnknown_085DCF2C[i];
- VarSet(VAR_OBJ_GFX_ID_0, mapObjectGfxId);
- }
+ for (i = 0; i < ARRAY_COUNT(gTowerFemaleFacilityClasses) && gTowerFemaleFacilityClasses[i] != class; i++)
+ ;
+ if (i != ARRAY_COUNT(gTowerFemaleFacilityClasses))
+ {
+ mapObjectGfxId = gTowerFemaleTrainerGfxIds[i];
+ VarSet(VAR_OBJ_GFX_ID_0, mapObjectGfxId);
}
}
-static void sub_81A15A4(void)
+static void Script_SetPlayerApprenticeTrainerGfxId(void)
{
u8 i;
u8 mapObjectGfxId;
u8 class = gApprentices[PLAYER_APPRENTICE.id].facilityClass;
- for (i = 0; i < 30 && gUnknown_085DCEDC[i] != class; i++)
+ for (i = 0; i < ARRAY_COUNT(gTowerMaleFacilityClasses) && gTowerMaleFacilityClasses[i] != class; i++)
;
-
- if (i != 30)
+ if (i != ARRAY_COUNT(gTowerMaleFacilityClasses))
{
- mapObjectGfxId = gUnknown_085DCF0E[i];
+ mapObjectGfxId = gTowerMaleTrainerGfxIds[i];
VarSet(VAR_OBJ_GFX_ID_0, mapObjectGfxId);
+ return;
}
- else
- {
- for (i = 0; i < 20 && gUnknown_085DCEFA[i] != class; i++)
- ;
- if (i != 20)
- {
- mapObjectGfxId = gUnknown_085DCF2C[i];
- VarSet(VAR_OBJ_GFX_ID_0, mapObjectGfxId);
- }
+ for (i = 0; i < ARRAY_COUNT(gTowerFemaleFacilityClasses) && gTowerFemaleFacilityClasses[i] != class; i++)
+ ;
+ if (i != ARRAY_COUNT(gTowerFemaleFacilityClasses))
+ {
+ mapObjectGfxId = gTowerFemaleTrainerGfxIds[i];
+ VarSet(VAR_OBJ_GFX_ID_0, mapObjectGfxId);
}
}
diff --git a/src/battle_bg.c b/src/battle_bg.c
index a6c66b3c4..bbe50cc70 100644
--- a/src/battle_bg.c
+++ b/src/battle_bg.c
@@ -162,10 +162,10 @@ const struct BgTemplate gBattleBgTemplates[] =
},
};
-static const struct WindowTemplate gUnknown_0831AA18[] =
+static const struct WindowTemplate gUnknown_0831AA18[] =
{
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 2,
.tilemapTop = 15,
.width = 26,
@@ -174,7 +174,7 @@ static const struct WindowTemplate gUnknown_0831AA18[] =
.baseBlock = 0x0090,
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 1,
.tilemapTop = 35,
.width = 14,
@@ -183,7 +183,7 @@ static const struct WindowTemplate gUnknown_0831AA18[] =
.baseBlock = 0x01c0,
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 17,
.tilemapTop = 35,
.width = 12,
@@ -192,7 +192,7 @@ static const struct WindowTemplate gUnknown_0831AA18[] =
.baseBlock = 0x0190,
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 2,
.tilemapTop = 55,
.width = 8,
@@ -201,7 +201,7 @@ static const struct WindowTemplate gUnknown_0831AA18[] =
.baseBlock = 0x0300,
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 11,
.tilemapTop = 55,
.width = 8,
@@ -210,7 +210,7 @@ static const struct WindowTemplate gUnknown_0831AA18[] =
.baseBlock = 0x0310,
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 2,
.tilemapTop = 57,
.width = 8,
@@ -219,7 +219,7 @@ static const struct WindowTemplate gUnknown_0831AA18[] =
.baseBlock = 0x0320,
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 11,
.tilemapTop = 57,
.width = 8,
@@ -228,7 +228,7 @@ static const struct WindowTemplate gUnknown_0831AA18[] =
.baseBlock = 0x0330,
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 21,
.tilemapTop = 55,
.width = 4,
@@ -237,7 +237,7 @@ static const struct WindowTemplate gUnknown_0831AA18[] =
.baseBlock = 0x0290,
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 21,
.tilemapTop = 57,
.width = 0,
@@ -246,7 +246,7 @@ static const struct WindowTemplate gUnknown_0831AA18[] =
.baseBlock = 0x0298,
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 25,
.tilemapTop = 55,
.width = 4,
@@ -255,7 +255,7 @@ static const struct WindowTemplate gUnknown_0831AA18[] =
.baseBlock = 0x0298,
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 21,
.tilemapTop = 57,
.width = 8,
@@ -264,7 +264,7 @@ static const struct WindowTemplate gUnknown_0831AA18[] =
.baseBlock = 0x02a0,
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 21,
.tilemapTop = 55,
.width = 8,
@@ -273,7 +273,7 @@ static const struct WindowTemplate gUnknown_0831AA18[] =
.baseBlock = 0x02b0,
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 26,
.tilemapTop = 9,
.width = 3,
@@ -282,7 +282,7 @@ static const struct WindowTemplate gUnknown_0831AA18[] =
.baseBlock = 0x0100,
},
{
- .priority = 1,
+ .bg = 1,
.tilemapLeft = 19,
.tilemapTop = 8,
.width = 10,
@@ -291,7 +291,7 @@ static const struct WindowTemplate gUnknown_0831AA18[] =
.baseBlock = 0x0100,
},
{
- .priority = 2,
+ .bg = 2,
.tilemapLeft = 18,
.tilemapTop = 0,
.width = 12,
@@ -300,7 +300,7 @@ static const struct WindowTemplate gUnknown_0831AA18[] =
.baseBlock = 0x016e,
},
{
- .priority = 1,
+ .bg = 1,
.tilemapLeft = 2,
.tilemapTop = 3,
.width = 6,
@@ -309,7 +309,7 @@ static const struct WindowTemplate gUnknown_0831AA18[] =
.baseBlock = 0x0020,
},
{
- .priority = 2,
+ .bg = 2,
.tilemapLeft = 2,
.tilemapTop = 3,
.width = 6,
@@ -318,7 +318,7 @@ static const struct WindowTemplate gUnknown_0831AA18[] =
.baseBlock = 0x0040,
},
{
- .priority = 1,
+ .bg = 1,
.tilemapLeft = 2,
.tilemapTop = 2,
.width = 6,
@@ -327,7 +327,7 @@ static const struct WindowTemplate gUnknown_0831AA18[] =
.baseBlock = 0x0020,
},
{
- .priority = 2,
+ .bg = 2,
.tilemapLeft = 2,
.tilemapTop = 2,
.width = 6,
@@ -336,7 +336,7 @@ static const struct WindowTemplate gUnknown_0831AA18[] =
.baseBlock = 0x0040,
},
{
- .priority = 1,
+ .bg = 1,
.tilemapLeft = 2,
.tilemapTop = 6,
.width = 6,
@@ -345,7 +345,7 @@ static const struct WindowTemplate gUnknown_0831AA18[] =
.baseBlock = 0x0060,
},
{
- .priority = 2,
+ .bg = 2,
.tilemapLeft = 2,
.tilemapTop = 6,
.width = 6,
@@ -354,7 +354,7 @@ static const struct WindowTemplate gUnknown_0831AA18[] =
.baseBlock = 0x0080,
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 12,
.tilemapTop = 2,
.width = 6,
@@ -363,7 +363,7 @@ static const struct WindowTemplate gUnknown_0831AA18[] =
.baseBlock = 0x00a0,
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 4,
.tilemapTop = 2,
.width = 7,
@@ -372,7 +372,7 @@ static const struct WindowTemplate gUnknown_0831AA18[] =
.baseBlock = 0x00a0,
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 19,
.tilemapTop = 2,
.width = 7,
@@ -383,10 +383,10 @@ static const struct WindowTemplate gUnknown_0831AA18[] =
DUMMY_WIN_TEMPLATE
};
-static const struct WindowTemplate gUnknown_0831AAE0[] =
+static const struct WindowTemplate gUnknown_0831AAE0[] =
{
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 2,
.tilemapTop = 15,
.width = 26,
@@ -395,7 +395,7 @@ static const struct WindowTemplate gUnknown_0831AAE0[] =
.baseBlock = 0x0090,
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 1,
.tilemapTop = 35,
.width = 14,
@@ -404,7 +404,7 @@ static const struct WindowTemplate gUnknown_0831AAE0[] =
.baseBlock = 0x01c0,
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 17,
.tilemapTop = 35,
.width = 12,
@@ -413,7 +413,7 @@ static const struct WindowTemplate gUnknown_0831AAE0[] =
.baseBlock = 0x0190,
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 2,
.tilemapTop = 55,
.width = 8,
@@ -422,7 +422,7 @@ static const struct WindowTemplate gUnknown_0831AAE0[] =
.baseBlock = 0x0300,
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 11,
.tilemapTop = 55,
.width = 8,
@@ -431,7 +431,7 @@ static const struct WindowTemplate gUnknown_0831AAE0[] =
.baseBlock = 0x0310,
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 2,
.tilemapTop = 57,
.width = 8,
@@ -440,7 +440,7 @@ static const struct WindowTemplate gUnknown_0831AAE0[] =
.baseBlock = 0x0320,
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 11,
.tilemapTop = 57,
.width = 8,
@@ -449,7 +449,7 @@ static const struct WindowTemplate gUnknown_0831AAE0[] =
.baseBlock = 0x0330,
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 21,
.tilemapTop = 55,
.width = 4,
@@ -458,7 +458,7 @@ static const struct WindowTemplate gUnknown_0831AAE0[] =
.baseBlock = 0x0290,
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 21,
.tilemapTop = 57,
.width = 0,
@@ -467,7 +467,7 @@ static const struct WindowTemplate gUnknown_0831AAE0[] =
.baseBlock = 0x0298,
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 25,
.tilemapTop = 55,
.width = 4,
@@ -476,7 +476,7 @@ static const struct WindowTemplate gUnknown_0831AAE0[] =
.baseBlock = 0x0298,
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 21,
.tilemapTop = 57,
.width = 8,
@@ -485,7 +485,7 @@ static const struct WindowTemplate gUnknown_0831AAE0[] =
.baseBlock = 0x02a0,
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 21,
.tilemapTop = 55,
.width = 8,
@@ -494,7 +494,7 @@ static const struct WindowTemplate gUnknown_0831AAE0[] =
.baseBlock = 0x02b0,
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 26,
.tilemapTop = 9,
.width = 3,
@@ -503,7 +503,7 @@ static const struct WindowTemplate gUnknown_0831AAE0[] =
.baseBlock = 0x0100,
},
{
- .priority = 1,
+ .bg = 1,
.tilemapLeft = 19,
.tilemapTop = 8,
.width = 10,
@@ -512,7 +512,7 @@ static const struct WindowTemplate gUnknown_0831AAE0[] =
.baseBlock = 0x0100,
},
{
- .priority = 2,
+ .bg = 2,
.tilemapLeft = 18,
.tilemapTop = 0,
.width = 12,
@@ -521,7 +521,7 @@ static const struct WindowTemplate gUnknown_0831AAE0[] =
.baseBlock = 0x016e,
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 6,
.tilemapTop = 1,
.width = 8,
@@ -530,7 +530,7 @@ static const struct WindowTemplate gUnknown_0831AAE0[] =
.baseBlock = 0x0100,
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 14,
.tilemapTop = 1,
.width = 2,
@@ -539,7 +539,7 @@ static const struct WindowTemplate gUnknown_0831AAE0[] =
.baseBlock = 0x0110,
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 16,
.tilemapTop = 1,
.width = 8,
@@ -548,7 +548,7 @@ static const struct WindowTemplate gUnknown_0831AAE0[] =
.baseBlock = 0x0114,
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 12,
.tilemapTop = 4,
.width = 6,
@@ -557,7 +557,7 @@ static const struct WindowTemplate gUnknown_0831AAE0[] =
.baseBlock = 0x0124,
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 12,
.tilemapTop = 6,
.width = 6,
@@ -566,7 +566,7 @@ static const struct WindowTemplate gUnknown_0831AAE0[] =
.baseBlock = 0x0130,
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 12,
.tilemapTop = 8,
.width = 6,
@@ -575,7 +575,7 @@ static const struct WindowTemplate gUnknown_0831AAE0[] =
.baseBlock = 0x013c,
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 8,
.tilemapTop = 11,
.width = 14,
@@ -584,7 +584,7 @@ static const struct WindowTemplate gUnknown_0831AAE0[] =
.baseBlock = 0x0148,
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 2,
.tilemapTop = 15,
.width = 26,
diff --git a/src/battle_dome.c b/src/battle_dome.c
index 00f461ada..15348e458 100644
--- a/src/battle_dome.c
+++ b/src/battle_dome.c
@@ -57,18 +57,12 @@ struct UnkStruct_860DD10
extern void sub_81B8558(void);
extern u32 sub_81A39C4(void);
-extern u16 sub_8162548(u8, u8);
-extern u16 RandomizeFacilityTrainerMonId(u16);
-extern u8 GetFacilityEnemyMonLevel(void);
extern u16 sub_81A5060(u8 monId, u8 moveSlotId);
extern u8 sub_81A50F0(u8, u8);
extern u8 sub_81A50B0(u8);
-extern void sub_8162614(u16, u8);
extern void sub_81A4C30(void);
extern bool8 sub_81A3610(void);
extern u16 sub_81A4FF0(u8);
-extern u8 GetFrontierTrainerFrontSpriteId(u16);
-extern u8 GetFrontierOpponentClass(u16);
extern void ReducePlayerPartyToThree(void);
extern u8 gUnknown_0203CEF8[];
@@ -792,7 +786,7 @@ static const struct BgTemplate gUnknown_0860CE84[4] =
static const struct WindowTemplate gUnknown_0860CE94[] =
{
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 0,
.tilemapTop = 3,
.width = 8,
@@ -801,7 +795,7 @@ static const struct WindowTemplate gUnknown_0860CE94[] =
.baseBlock = 16,
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 22,
.tilemapTop = 3,
.width = 8,
@@ -810,7 +804,7 @@ static const struct WindowTemplate gUnknown_0860CE94[] =
.baseBlock = 144,
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 8,
.tilemapTop = 1,
.width = 14,
@@ -824,7 +818,7 @@ static const struct WindowTemplate gUnknown_0860CE94[] =
static const struct WindowTemplate gUnknown_0860CEB4[] =
{
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 2,
.tilemapTop = 2,
.width = 26,
@@ -833,7 +827,7 @@ static const struct WindowTemplate gUnknown_0860CEB4[] =
.baseBlock = 1,
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 16,
.tilemapTop = 5,
.width = 8,
@@ -842,7 +836,7 @@ static const struct WindowTemplate gUnknown_0860CEB4[] =
.baseBlock = 53,
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 19,
.tilemapTop = 7,
.width = 9,
@@ -851,7 +845,7 @@ static const struct WindowTemplate gUnknown_0860CEB4[] =
.baseBlock = 69,
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 16,
.tilemapTop = 10,
.width = 8,
@@ -860,7 +854,7 @@ static const struct WindowTemplate gUnknown_0860CEB4[] =
.baseBlock = 96,
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 2,
.tilemapTop = 12,
.width = 26,
@@ -869,7 +863,7 @@ static const struct WindowTemplate gUnknown_0860CEB4[] =
.baseBlock = 112,
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 5,
.tilemapTop = 2,
.width = 23,
@@ -878,7 +872,7 @@ static const struct WindowTemplate gUnknown_0860CEB4[] =
.baseBlock = 294,
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 2,
.tilemapTop = 5,
.width = 8,
@@ -887,7 +881,7 @@ static const struct WindowTemplate gUnknown_0860CEB4[] =
.baseBlock = 340,
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 20,
.tilemapTop = 5,
.width = 8,
@@ -896,7 +890,7 @@ static const struct WindowTemplate gUnknown_0860CEB4[] =
.baseBlock = 356,
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 2,
.tilemapTop = 16,
.width = 26,
@@ -905,7 +899,7 @@ static const struct WindowTemplate gUnknown_0860CEB4[] =
.baseBlock = 372,
},
{
- .priority = 1,
+ .bg = 1,
.tilemapLeft = 2,
.tilemapTop = 2,
.width = 26,
@@ -914,7 +908,7 @@ static const struct WindowTemplate gUnknown_0860CEB4[] =
.baseBlock = 1,
},
{
- .priority = 1,
+ .bg = 1,
.tilemapLeft = 16,
.tilemapTop = 5,
.width = 8,
@@ -923,7 +917,7 @@ static const struct WindowTemplate gUnknown_0860CEB4[] =
.baseBlock = 53,
},
{
- .priority = 1,
+ .bg = 1,
.tilemapLeft = 19,
.tilemapTop = 7,
.width = 9,
@@ -932,7 +926,7 @@ static const struct WindowTemplate gUnknown_0860CEB4[] =
.baseBlock = 69,
},
{
- .priority = 1,
+ .bg = 1,
.tilemapLeft = 16,
.tilemapTop = 10,
.width = 8,
@@ -941,7 +935,7 @@ static const struct WindowTemplate gUnknown_0860CEB4[] =
.baseBlock = 96,
},
{
- .priority = 1,
+ .bg = 1,
.tilemapLeft = 2,
.tilemapTop = 12,
.width = 26,
@@ -950,7 +944,7 @@ static const struct WindowTemplate gUnknown_0860CEB4[] =
.baseBlock = 112,
},
{
- .priority = 1,
+ .bg = 1,
.tilemapLeft = 5,
.tilemapTop = 2,
.width = 23,
@@ -959,7 +953,7 @@ static const struct WindowTemplate gUnknown_0860CEB4[] =
.baseBlock = 294,
},
{
- .priority = 1,
+ .bg = 1,
.tilemapLeft = 2,
.tilemapTop = 5,
.width = 8,
@@ -968,7 +962,7 @@ static const struct WindowTemplate gUnknown_0860CEB4[] =
.baseBlock = 340,
},
{
- .priority = 1,
+ .bg = 1,
.tilemapLeft = 20,
.tilemapTop = 5,
.width = 8,
@@ -977,7 +971,7 @@ static const struct WindowTemplate gUnknown_0860CEB4[] =
.baseBlock = 356,
},
{
- .priority = 1,
+ .bg = 1,
.tilemapLeft = 2,
.tilemapTop = 16,
.width = 26,
@@ -2410,7 +2404,7 @@ static void sub_818E9CC(void)
u32 battleMode = VarGet(VAR_FRONTIER_BATTLE_MODE);
gSaveBlock2Ptr->frontier.field_CA8 = 0;
- gSaveBlock2Ptr->frontier.field_CB2 = 0;
+ gSaveBlock2Ptr->frontier.curChallengeBattleNum = 0;
gSaveBlock2Ptr->frontier.field_CA9_a = 0;
gSaveBlock2Ptr->frontier.field_CA9_b = 0;
if (!(gSaveBlock2Ptr->frontier.field_CDC & gUnknown_0860D0EC[battleMode][lvlMode]))
@@ -2581,13 +2575,13 @@ static void InitDomeTrainers(void)
for (i = 0; i < 3; i++)
{
- gSaveBlock2Ptr->frontier.domeMonId[0][i] = GetMonData(&gPlayerParty[gSaveBlock2Ptr->frontier.field_CAA[i] - 1], MON_DATA_SPECIES, NULL);
+ gSaveBlock2Ptr->frontier.domeMonId[0][i] = GetMonData(&gPlayerParty[gSaveBlock2Ptr->frontier.selectedPartyMons[i] - 1], MON_DATA_SPECIES, NULL);
for (j = 0; j < 4; j++)
- gSaveBlock2Ptr->frontier.field_EFC[i].moves[j] = GetMonData(&gPlayerParty[gSaveBlock2Ptr->frontier.field_CAA[i] - 1], MON_DATA_MOVE1 + j, NULL);
+ gSaveBlock2Ptr->frontier.field_EFC[i].moves[j] = GetMonData(&gPlayerParty[gSaveBlock2Ptr->frontier.selectedPartyMons[i] - 1], MON_DATA_MOVE1 + j, NULL);
for (j = 0; j < 6; j++)
- gSaveBlock2Ptr->frontier.field_EFC[i].evs[j] = GetMonData(&gPlayerParty[gSaveBlock2Ptr->frontier.field_CAA[i] - 1], MON_DATA_HP_EV + j, NULL);
+ gSaveBlock2Ptr->frontier.field_EFC[i].evs[j] = GetMonData(&gPlayerParty[gSaveBlock2Ptr->frontier.selectedPartyMons[i] - 1], MON_DATA_HP_EV + j, NULL);
- gSaveBlock2Ptr->frontier.field_EFC[i].nature = GetNature(&gPlayerParty[gSaveBlock2Ptr->frontier.field_CAA[i] - 1]);
+ gSaveBlock2Ptr->frontier.field_EFC[i].nature = GetNature(&gPlayerParty[gSaveBlock2Ptr->frontier.selectedPartyMons[i] - 1]);
}
for (i = 1; i < DOME_TOURNAMENT_TRAINERS_COUNT; i++)
@@ -2649,7 +2643,7 @@ static void InitDomeTrainers(void)
statSums[0] = 0;
for (i = 0; i < 3; i++)
{
- trainerId = gSaveBlock2Ptr->frontier.field_CAA[i] - 1; // Great variable choice, gamefreak.
+ trainerId = gSaveBlock2Ptr->frontier.selectedPartyMons[i] - 1; // Great variable choice, gamefreak.
statSums[0] += GetMonData(&gPlayerParty[trainerId], MON_DATA_ATK, NULL);
statSums[0] += GetMonData(&gPlayerParty[trainerId], MON_DATA_DEF, NULL);
statSums[0] += GetMonData(&gPlayerParty[trainerId], MON_DATA_SPATK, NULL);
@@ -2667,7 +2661,7 @@ static void InitDomeTrainers(void)
monTypesBits >>= 1;
}
- monLevel = GetFacilityEnemyMonLevel();
+ monLevel = SetFacilityPtrsGetLevel();
statSums[0] += (monTypesCount * monLevel) / 20;
for (i = 1; i < DOME_TOURNAMENT_TRAINERS_COUNT; i++)
@@ -2810,12 +2804,12 @@ static void SwapDomeTrainers(s32 id1, s32 id2, u16 *statsArray)
static void sub_818F9B0(void)
{
- StringCopy(gStringVar1, gRoundsStringTable[gSaveBlock2Ptr->frontier.field_CB2]);
+ StringCopy(gStringVar1, gRoundsStringTable[gSaveBlock2Ptr->frontier.curChallengeBattleNum]);
}
static void sub_818F9E0(void)
{
- StringCopy(gStringVar1, gRoundsStringTable[gSaveBlock2Ptr->frontier.field_CB2]);
+ StringCopy(gStringVar1, gRoundsStringTable[gSaveBlock2Ptr->frontier.curChallengeBattleNum]);
CopyDomeTrainerName(gStringVar2, gTrainerBattleOpponent_A);
}
@@ -2833,7 +2827,7 @@ static void CreateDomeMon(u8 monPartyId, u16 tournamentTrainerId, u8 tournamentM
s32 i;
u8 happiness = 0xFF;
u8 fixedIv = GetDomeTrainerMonIvs(tournamentTrainerId); // BUG: Should be using trainerId instead of tournamentTrainerId. As a result, all Pokemon have ivs of 3.
- u8 level = GetFacilityEnemyMonLevel();
+ u8 level = SetFacilityPtrsGetLevel();
CreateMonWithEVSpreadPersonalityOTID(&gEnemyParty[monPartyId],
gFacilityTrainerMons[gSaveBlock2Ptr->frontier.domeMonId[tournamentTrainerId][tournamentMonId]].species,
level,
@@ -3466,12 +3460,12 @@ static void sub_8190298(void)
static u16 TrainerIdOfPlayerOpponent(void)
{
- return gSaveBlock2Ptr->frontier.domeTrainers[TournamentIdOfOpponent(gSaveBlock2Ptr->frontier.field_CB2, TRAINER_PLAYER)].trainerId;
+ return gSaveBlock2Ptr->frontier.domeTrainers[TournamentIdOfOpponent(gSaveBlock2Ptr->frontier.curChallengeBattleNum, TRAINER_PLAYER)].trainerId;
}
static void sub_81902E4(void)
{
- sub_8162614(gTrainerBattleOpponent_A, 0);
+ SetBattleFacilityTrainerGfxId(gTrainerBattleOpponent_A, 0);
}
static void sub_81902F8(void)
@@ -3805,7 +3799,7 @@ static void sub_8190B40(struct Sprite *sprite)
s32 taskId1 = sprite->data[0];
s32 arrId = gTasks[gTasks[taskId1].data[4]].data[1];
s32 tournmanetTrainerId = gUnknown_0860D080[arrId];
- s32 r12 = gSaveBlock2Ptr->frontier.field_CB2;
+ s32 roundId = gSaveBlock2Ptr->frontier.curChallengeBattleNum;
if (gTasks[taskId1].data[3] == 1)
{
@@ -3817,7 +3811,7 @@ static void sub_8190B40(struct Sprite *sprite)
sprite->invisible = FALSE;
}
else if (!gSaveBlock2Ptr->frontier.domeTrainers[tournmanetTrainerId].isEliminated
- && sBattleDomeStruct->unk_10 - 1 < r12)
+ && sBattleDomeStruct->unk_10 - 1 < roundId)
{
sprite->invisible = FALSE;
}
@@ -4621,7 +4615,7 @@ static u8 sub_819221C(u8 taskId)
s32 taskId2 = gTasks[taskId].data[4];
s32 r5 = gTasks[taskId2].data[1];
u8 r10 = gUnknown_0860D080[r5];
- u16 roundId = gSaveBlock2Ptr->frontier.field_CB2;
+ u16 roundId = gSaveBlock2Ptr->frontier.curChallengeBattleNum;
if (gMain.newKeys & (A_BUTTON | B_BUTTON))
retVal = 9;
@@ -5373,7 +5367,7 @@ static void sub_81938E0(void)
sub_8194D48();
gSaveBlock2Ptr->frontier.lvlMode = gSaveBlock2Ptr->frontier.field_D0A - 1;
- gSaveBlock2Ptr->frontier.field_CB2 = 3;
+ gSaveBlock2Ptr->frontier.curChallengeBattleNum = 3;
taskId = CreateTask(sub_8194220, 0);
gTasks[taskId].data[0] = 0;
gTasks[taskId].data[1] = 0;
@@ -5475,7 +5469,7 @@ static u8 sub_8193BDC(u8 taskId)
u8 retVal = 1;
s32 arrId = 4;
s32 spriteId = gTasks[taskId].data[1];
- s32 roundId = gSaveBlock2Ptr->frontier.field_CB2;
+ s32 roundId = gSaveBlock2Ptr->frontier.curChallengeBattleNum;
if (gMain.newKeys == B_BUTTON || (gMain.newKeys & A_BUTTON && spriteId == 31))
{
@@ -5536,19 +5530,19 @@ static void sub_8193D7C(void)
if (gSpecialVar_0x8005 == 1)
{
gSaveBlock2Ptr->frontier.domeTrainers[TrainerIdToTournamentId(gTrainerBattleOpponent_A)].isEliminated = 1;
- gSaveBlock2Ptr->frontier.domeTrainers[TrainerIdToTournamentId(gTrainerBattleOpponent_A)].eliminatedAt = gSaveBlock2Ptr->frontier.field_CB2;
+ gSaveBlock2Ptr->frontier.domeTrainers[TrainerIdToTournamentId(gTrainerBattleOpponent_A)].eliminatedAt = gSaveBlock2Ptr->frontier.curChallengeBattleNum;
gSaveBlock2Ptr->frontier.field_EC0[TrainerIdToTournamentId(gTrainerBattleOpponent_A)] = gBattleResults.lastUsedMovePlayer;
- if (gSaveBlock2Ptr->frontier.field_CB2 < DOME_FINAL)
- DecideRoundWinners(gSaveBlock2Ptr->frontier.field_CB2);
+ if (gSaveBlock2Ptr->frontier.curChallengeBattleNum < DOME_FINAL)
+ DecideRoundWinners(gSaveBlock2Ptr->frontier.curChallengeBattleNum);
}
else
{
gSaveBlock2Ptr->frontier.domeTrainers[TrainerIdToTournamentId(TRAINER_PLAYER)].isEliminated = 1;
- gSaveBlock2Ptr->frontier.domeTrainers[TrainerIdToTournamentId(TRAINER_PLAYER)].eliminatedAt = gSaveBlock2Ptr->frontier.field_CB2;
+ gSaveBlock2Ptr->frontier.domeTrainers[TrainerIdToTournamentId(TRAINER_PLAYER)].eliminatedAt = gSaveBlock2Ptr->frontier.curChallengeBattleNum;
gSaveBlock2Ptr->frontier.field_EC0[TrainerIdToTournamentId(TRAINER_PLAYER)] = gBattleResults.lastUsedMoveOpponent;
if (gBattleOutcome == B_OUTCOME_FORFEITED || gSpecialVar_0x8005 == 9)
gSaveBlock2Ptr->frontier.domeTrainers[TrainerIdToTournamentId(TRAINER_PLAYER)].unk3 = 1;
- for (i = gSaveBlock2Ptr->frontier.field_CB2; i < DOME_ROUNDS_COUNT; i++)
+ for (i = gSaveBlock2Ptr->frontier.curChallengeBattleNum; i < DOME_ROUNDS_COUNT; i++)
DecideRoundWinners(i);
}
}
@@ -5561,7 +5555,7 @@ static u16 GetWinningMove(s32 winnerTournamentId, s32 loserTournamentId, u8 roun
u16 bestScore = 0;
u16 bestId = 0;
s32 movePower = 0;
- GetFacilityEnemyMonLevel(); // Unused return variable.
+ SetFacilityPtrsGetLevel();
// Calc move points of all 4 moves for all 3 pokemon hitting all 3 target mons.
for (i = 0; i < 3; i++)
@@ -5761,7 +5755,7 @@ static void sub_8194220(u8 taskId)
AddTextPrinter(&textPrinter, 0, NULL);
for (i = 0; i < DOME_TOURNAMENT_TRAINERS_COUNT; i++)
{
- s32 var, var2;
+ s32 roundId, var2;
CopyDomeTrainerName(gDisplayedStringBattle, gSaveBlock2Ptr->frontier.domeTrainers[i].trainerId);
if (r10 == 1)
@@ -5774,9 +5768,9 @@ static void sub_8194220(u8 taskId)
sub_81948EC(i, var2);
}
}
- else if (gSaveBlock2Ptr->frontier.field_CB2 != DOME_ROUND2)
+ else if (gSaveBlock2Ptr->frontier.curChallengeBattleNum != DOME_ROUND2)
{
- sub_81948EC(i, gSaveBlock2Ptr->frontier.field_CB2 - 2);
+ sub_81948EC(i, gSaveBlock2Ptr->frontier.curChallengeBattleNum - 2);
}
}
else if (r10 == 0)
@@ -5789,23 +5783,23 @@ static void sub_8194220(u8 taskId)
sub_81948EC(i, var2);
}
}
- else if (gSaveBlock2Ptr->frontier.field_CB2 != DOME_ROUND1)
+ else if (gSaveBlock2Ptr->frontier.curChallengeBattleNum != DOME_ROUND1)
{
if (gTasks[taskId].data[4])
- var2 = gSaveBlock2Ptr->frontier.field_CB2;
+ var2 = gSaveBlock2Ptr->frontier.curChallengeBattleNum;
else
- var2 = gSaveBlock2Ptr->frontier.field_CB2 - 1;
+ var2 = gSaveBlock2Ptr->frontier.curChallengeBattleNum - 1;
sub_81948EC(i, var2);
}
}
if (gTasks[taskId].data[4])
- var = gSaveBlock2Ptr->frontier.field_CB2;
+ roundId = gSaveBlock2Ptr->frontier.curChallengeBattleNum;
else
- var = gSaveBlock2Ptr->frontier.field_CB2 - 1;
+ roundId = gSaveBlock2Ptr->frontier.curChallengeBattleNum - 1;
- if ( ((r10 == 1 && gSaveBlock2Ptr->frontier.domeTrainers[i].eliminatedAt < gSaveBlock2Ptr->frontier.field_CB2 - 1)
- || (r10 == 0 && gSaveBlock2Ptr->frontier.domeTrainers[i].eliminatedAt <= var))
+ if ( ((r10 == 1 && gSaveBlock2Ptr->frontier.domeTrainers[i].eliminatedAt < gSaveBlock2Ptr->frontier.curChallengeBattleNum - 1)
+ || (r10 == 0 && gSaveBlock2Ptr->frontier.domeTrainers[i].eliminatedAt <= roundId))
&& gSaveBlock2Ptr->frontier.domeTrainers[i].isEliminated)
{
if (gSaveBlock2Ptr->frontier.domeTrainers[i].trainerId == TRAINER_PLAYER)
@@ -5930,7 +5924,7 @@ static void sub_8194950(u8 taskId)
for (i = 0; i < DOME_TOURNAMENT_TRAINERS_COUNT; i++)
{
CopyDomeTrainerName(gDisplayedStringBattle, gSaveBlock2Ptr->frontier.domeTrainers[i].trainerId);
- if (gSaveBlock2Ptr->frontier.domeTrainers[i].eliminatedAt == gSaveBlock2Ptr->frontier.field_CB2 - 1
+ if (gSaveBlock2Ptr->frontier.domeTrainers[i].eliminatedAt == gSaveBlock2Ptr->frontier.curChallengeBattleNum - 1
&& gSaveBlock2Ptr->frontier.domeTrainers[i].isEliminated)
{
if (gUnknown_0860D3F1[i][0] == 0)
@@ -5945,8 +5939,8 @@ static void sub_8194950(u8 taskId)
}
if (!gSaveBlock2Ptr->frontier.domeTrainers[i].isEliminated)
{
- s32 var = gSaveBlock2Ptr->frontier.field_CB2 - 1;
- sub_81948EC(i, var);
+ s32 roundId = gSaveBlock2Ptr->frontier.curChallengeBattleNum - 1;
+ sub_81948EC(i, roundId);
}
}
}
@@ -6084,7 +6078,7 @@ static void sub_8194D68(void)
for (i = 0; i < 2; i++)
{
- s32 playerMonId = gSaveBlock2Ptr->frontier.field_CAA[gUnknown_0203CEF8[i] - 1] - 1;
+ s32 playerMonId = gSaveBlock2Ptr->frontier.selectedPartyMons[gUnknown_0203CEF8[i] - 1] - 1;
s32 count;
for (moveSlot = 0; moveSlot < 4; moveSlot++)
@@ -6110,7 +6104,7 @@ static void sub_8194E44(void)
for (i = 0; i < 2; i++)
{
- s32 playerMonId = gSaveBlock2Ptr->frontier.field_CAA[gUnknown_0203CEF8[i] - 1] - 1;
+ s32 playerMonId = gSaveBlock2Ptr->frontier.selectedPartyMons[gUnknown_0203CEF8[i] - 1] - 1;
u16 item = GetMonData(&gSaveBlock1Ptr->playerParty[playerMonId], MON_DATA_HELD_ITEM, NULL);
SetMonData(&gPlayerParty[i], MON_DATA_HELD_ITEM, &item);
}
@@ -6425,7 +6419,7 @@ static void DecideRoundWinners(u8 roundId)
static void CopyDomeTrainerName(u8 *dst, u16 trainerId)
{
s32 i = 0;
- GetFacilityEnemyMonLevel(); // Unused return value.
+ SetFacilityPtrsGetLevel();
if (trainerId == TRAINER_FRONTIER_BRAIN)
{
@@ -6440,7 +6434,7 @@ static void CopyDomeTrainerName(u8 *dst, u16 trainerId)
}
else if (trainerId < 300)
{
- for (i = 0; i < FRONTIER_TRAINER_NAME_LENGTH; i++)
+ for (i = 0; i < PLAYER_NAME_LENGTH; i++)
dst[i] = gFacilityTrainers[trainerId].trainerName[i];
}
dst[i] = EOS;
@@ -6461,7 +6455,7 @@ static void CopyDomeBrainTrainerName(u8 *dst)
{
s32 i;
- for (i = 0; i < FRONTIER_TRAINER_NAME_LENGTH; i++)
+ for (i = 0; i < PLAYER_NAME_LENGTH; i++)
dst[i] = gTrainers[TRAINER_TUCKER].trainerName[i];
dst[i] = EOS;
}
diff --git a/src/battle_factory.c b/src/battle_factory.c
index 7ebcfe8b3..c2a3207a6 100644
--- a/src/battle_factory.c
+++ b/src/battle_factory.c
@@ -323,7 +323,7 @@ static const struct BgTemplate sSelect_BgTemplates[] =
static const struct WindowTemplate sSelect_WindowTemplates[] =
{
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 0,
.tilemapTop = 2,
.width = 12,
@@ -332,7 +332,7 @@ static const struct WindowTemplate sSelect_WindowTemplates[] =
.baseBlock = 0x0001,
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 19,
.tilemapTop = 2,
.width = 11,
@@ -341,7 +341,7 @@ static const struct WindowTemplate sSelect_WindowTemplates[] =
.baseBlock = 0x0019,
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 0,
.tilemapTop = 15,
.width = 20,
@@ -350,7 +350,7 @@ static const struct WindowTemplate sSelect_WindowTemplates[] =
.baseBlock = 0x002f,
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 22,
.tilemapTop = 14,
.width = 8,
@@ -359,7 +359,7 @@ static const struct WindowTemplate sSelect_WindowTemplates[] =
.baseBlock = 0x006b,
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 22,
.tilemapTop = 14,
.width = 8,
@@ -368,7 +368,7 @@ static const struct WindowTemplate sSelect_WindowTemplates[] =
.baseBlock = 0x009b,
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 15,
.tilemapTop = 0,
.width = 15,
@@ -907,7 +907,7 @@ static const struct BgTemplate sSwap_BgTemplates[4] =
static const struct WindowTemplate sSwap_WindowTemplates[] =
{
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 0,
.tilemapTop = 2,
.width = 12,
@@ -916,7 +916,7 @@ static const struct WindowTemplate sSwap_WindowTemplates[] =
.baseBlock = 0x0001,
},
{
- .priority = 2,
+ .bg = 2,
.tilemapLeft = 19,
.tilemapTop = 2,
.width = 11,
@@ -925,7 +925,7 @@ static const struct WindowTemplate sSwap_WindowTemplates[] =
.baseBlock = 0x0019,
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 0,
.tilemapTop = 15,
.width = 20,
@@ -934,7 +934,7 @@ static const struct WindowTemplate sSwap_WindowTemplates[] =
.baseBlock = 0x002f,
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 21,
.tilemapTop = 14,
.width = 9,
@@ -943,7 +943,7 @@ static const struct WindowTemplate sSwap_WindowTemplates[] =
.baseBlock = 0x006b,
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 22,
.tilemapTop = 14,
.width = 8,
@@ -952,7 +952,7 @@ static const struct WindowTemplate sSwap_WindowTemplates[] =
.baseBlock = 0x00a1,
},
{
- .priority = 2,
+ .bg = 2,
.tilemapLeft = 21,
.tilemapTop = 15,
.width = 9,
@@ -961,7 +961,7 @@ static const struct WindowTemplate sSwap_WindowTemplates[] =
.baseBlock = 0x006b,
},
{
- .priority = 2,
+ .bg = 2,
.tilemapLeft = 10,
.tilemapTop = 2,
.width = 4,
@@ -970,7 +970,7 @@ static const struct WindowTemplate sSwap_WindowTemplates[] =
.baseBlock = 0x00c1,
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 19,
.tilemapTop = 2,
.width = 11,
@@ -979,7 +979,7 @@ static const struct WindowTemplate sSwap_WindowTemplates[] =
.baseBlock = 0x00c9,
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 15,
.tilemapTop = 0,
.width = 15,
diff --git a/src/battle_frontier_1.c b/src/battle_frontier_1.c
index ee8a42954..9ec9f8520 100644
--- a/src/battle_frontier_1.c
+++ b/src/battle_frontier_1.c
@@ -5,7 +5,7 @@
#include "random.h"
#include "battle_tower.h"
-extern void sub_8162614(u16, u8);
+extern void SetBattleFacilityTrainerGfxId(u16, u8);
extern void (* const gUnknown_0860DE50[])(void);
extern const u32 gUnknown_0860DE98[][2];
@@ -23,7 +23,7 @@ void sub_8195980(void)
u32 battleMode = VarGet(VAR_FRONTIER_BATTLE_MODE);
gSaveBlock2Ptr->frontier.field_CA8 = 0;
- gSaveBlock2Ptr->frontier.field_CB2 = 0;
+ gSaveBlock2Ptr->frontier.curChallengeBattleNum = 0;
gSaveBlock2Ptr->frontier.field_CA9_a = 0;
gSaveBlock2Ptr->frontier.field_CA9_b = 0;
if (!(gSaveBlock2Ptr->frontier.field_CDC & gUnknown_0860DE98[battleMode][lvlMode]))
@@ -90,13 +90,13 @@ void sub_8195BB0(void)
void sub_8195C20(void)
{
gTrainerBattleOpponent_A = 5 *(Random() % 255) / 64u;
- sub_8162614(gTrainerBattleOpponent_A, 0);
+ SetBattleFacilityTrainerGfxId(gTrainerBattleOpponent_A, 0);
}
void sub_8195C50(void)
{
if (gTrainerBattleOpponent_A < 300)
- ConvertBattleFrontierTrainerSpeechToString(gFacilityTrainers[gTrainerBattleOpponent_A].speechBefore);
+ FrontierSpeechToString(gFacilityTrainers[gTrainerBattleOpponent_A].speechBefore);
}
/*
diff --git a/src/battle_main.c b/src/battle_main.c
index 80ee5c425..9f1ea3c01 100644
--- a/src/battle_main.c
+++ b/src/battle_main.c
@@ -52,6 +52,7 @@
#include "international_string_util.h"
#include "pokeball.h"
#include "party_menu.h"
+#include "battle_tower.h"
struct UnknownPokemonStruct4
{
@@ -106,9 +107,6 @@ extern const u8 gText_Confusion[];
extern const u8 gText_Love[];
// functions
-extern void GetFrontierTrainerName(u8* dst, u16 trainerId); // battle tower
-extern void sub_8166188(void); // battle tower, sets link battle mons level but why?
-extern void sub_8165B88(u8* dst, u16 trainerId); // battle tower, gets language
extern void sub_81B9150(void);
extern void sub_80B3AF8(u8 taskId); // cable club
extern void sub_81A56B4(void); // battle frontier 2
@@ -1159,9 +1157,9 @@ static void CB2_HandleStartMultiPartnerBattle(void)
gLinkPlayers[3].id = 3;
GetFrontierTrainerName(gLinkPlayers[2].name, gTrainerBattleOpponent_A);
GetFrontierTrainerName(gLinkPlayers[3].name, gTrainerBattleOpponent_B);
- sub_8165B88(&language, gTrainerBattleOpponent_A);
+ GetBattleTowerTrainerLanguage(&language, gTrainerBattleOpponent_A);
gLinkPlayers[2].language = language;
- sub_8165B88(&language, gTrainerBattleOpponent_B);
+ GetBattleTowerTrainerLanguage(&language, gTrainerBattleOpponent_B);
gLinkPlayers[3].language = language;
if (sub_800A520())
diff --git a/src/battle_message.c b/src/battle_message.c
index a5f549733..99ab8bbd6 100644
--- a/src/battle_message.c
+++ b/src/battle_message.c
@@ -18,6 +18,8 @@
#include "recorded_battle.h"
#include "international_string_util.h"
#include "battle_frontier_2.h"
+#include "battle_tower.h"
+#include "data2.h"
struct BattleWindowText
{
@@ -35,7 +37,6 @@ struct BattleWindowText
extern u8 gUnknown_0203C7B4;
-extern const u8 gMoveNames[MOVES_COUNT][13];
extern const u8 gTrainerClassNames[][13];
extern const u16 gUnknown_08D85620[];
@@ -46,14 +47,10 @@ extern const u8 gText_PkmnTransferredSomeonesPC[];
extern const u8 gText_PkmnTransferredLanettesPC[];
extern u8 GetFrontierBrainTrainerClass(void); // battle_frontier_2
-extern u8 GetFrontierOpponentClass(u16 trainerId); // battle_tower
extern u8 GetTrainerHillOpponentClass(u16 trainerId); // pokenav
-extern u8 GetEreaderTrainerClassId(void); // battle_tower
extern void CopyFrontierBrainTrainerName(u8 *txtPtr); // battle_frontier_2
extern void GetTrainerHillTrainerName(u8 *txtPtr, u16 trainerId); // pokenav
-extern void GetEreaderTrainerName(u8 *txtPtr);
extern void CopyTrainerHillTrainerText(u8 arg0, u16 trainerId); // pokenav
-extern void GetFrontierTrainerName(u8 *dst, u16 trainerId);
// this file's functions
static void ChooseMoveUsedParticle(u8 *textPtr);
diff --git a/src/battle_pyramid_bag.c b/src/battle_pyramid_bag.c
index 94099aee8..fce8c9e2a 100644
--- a/src/battle_pyramid_bag.c
+++ b/src/battle_pyramid_bag.c
@@ -188,7 +188,7 @@ static const u8 sColorTable[][3] =
static const struct WindowTemplate gUnknown_0861F328[] =
{
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 14,
.tilemapTop = 2,
.width = 15,
@@ -197,7 +197,7 @@ static const struct WindowTemplate gUnknown_0861F328[] =
.baseBlock = 30
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 0,
.tilemapTop = 13,
.width = 14,
@@ -206,7 +206,7 @@ static const struct WindowTemplate gUnknown_0861F328[] =
.baseBlock = 270
},
{
- .priority = 1,
+ .bg = 1,
.tilemapLeft = 2,
.tilemapTop = 15,
.width = 27,
@@ -215,7 +215,7 @@ static const struct WindowTemplate gUnknown_0861F328[] =
.baseBlock = 354
},
{
- .priority = 1,
+ .bg = 1,
.tilemapLeft = 24,
.tilemapTop = 17,
.width = 5,
@@ -229,7 +229,7 @@ static const struct WindowTemplate gUnknown_0861F328[] =
static const struct WindowTemplate gUnknown_0861F350[] =
{
{
- .priority = 1,
+ .bg = 1,
.tilemapLeft = 22,
.tilemapTop = 17,
.width = 7,
@@ -238,7 +238,7 @@ static const struct WindowTemplate gUnknown_0861F350[] =
.baseBlock = 472
},
{
- .priority = 1,
+ .bg = 1,
.tilemapLeft = 22,
.tilemapTop = 15,
.width = 7,
@@ -247,7 +247,7 @@ static const struct WindowTemplate gUnknown_0861F350[] =
.baseBlock = 472
},
{
- .priority = 1,
+ .bg = 1,
.tilemapLeft = 15,
.tilemapTop = 15,
.width = 14,
@@ -256,7 +256,7 @@ static const struct WindowTemplate gUnknown_0861F350[] =
.baseBlock = 472
},
{
- .priority = 1,
+ .bg = 1,
.tilemapLeft = 15,
.tilemapTop = 13,
.width = 14,
@@ -265,7 +265,7 @@ static const struct WindowTemplate gUnknown_0861F350[] =
.baseBlock = 472
},
{
- .priority = 1,
+ .bg = 1,
.tilemapLeft = 24,
.tilemapTop = 15,
.width = 5,
diff --git a/src/battle_records.c b/src/battle_records.c
index feaec74db..f64b5f494 100644
--- a/src/battle_records.c
+++ b/src/battle_records.c
@@ -65,7 +65,7 @@ static const struct BgTemplate sTrainerHillRecordsBgTemplates[] =
static const struct WindowTemplate sTrainerHillRecordsWindowTemplates[] =
{
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 2,
.tilemapTop = 1,
.width = 26,
@@ -78,7 +78,7 @@ static const struct WindowTemplate sTrainerHillRecordsWindowTemplates[] =
static const struct WindowTemplate sLinkBattleRecordsWindow =
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 2,
.tilemapTop = 1,
.width = 26,
diff --git a/src/battle_setup.c b/src/battle_setup.c
index db173a38e..c18176706 100644
--- a/src/battle_setup.c
+++ b/src/battle_setup.c
@@ -31,6 +31,7 @@
#include "string_util.h"
#include "overworld.h"
#include "field_weather.h"
+#include "battle_tower.h"
#include "gym_leader_rematch.h"
#include "constants/map_types.h"
#include "constants/battle_frontier.h"
@@ -67,8 +68,6 @@ extern u16 sub_81D6180(u8 localId);
extern bool8 GetBattlePyramidTrainerFlag(u8 eventObjId);
extern bool8 GetTrainerHillTrainerFlag(u8 eventObjId);
extern bool8 sub_81D5C18(void);
-extern void sub_816306C(u8 a0);
-extern void sub_8163048(u8 a0);
extern void sub_81A9B04(void);
extern void sub_81D639C(void);
extern void sub_81D6384(void);
@@ -885,8 +884,8 @@ u8 sub_80B100C(s32 arg0)
return sUnknown_0854FE98[Random() % ARRAY_COUNT(sUnknown_0854FE98)];
}
- var = gSaveBlock2Ptr->frontier.field_CB4[gSaveBlock2Ptr->frontier.field_CB2 * 2 + 0]
- + gSaveBlock2Ptr->frontier.field_CB4[gSaveBlock2Ptr->frontier.field_CB2 * 2 + 1];
+ var = gSaveBlock2Ptr->frontier.field_CB4[gSaveBlock2Ptr->frontier.curChallengeBattleNum * 2 + 0]
+ + gSaveBlock2Ptr->frontier.field_CB4[gSaveBlock2Ptr->frontier.curChallengeBattleNum * 2 + 1];
return sUnknown_0854FE98[var % ARRAY_COUNT(sUnknown_0854FE98)];
}
@@ -1264,7 +1263,7 @@ void BattleSetup_StartTrainerBattle(void)
if (gNoOfApproachingTrainers == 2)
{
- sub_816306C(1);
+ FillFrontierTrainersParties(1);
ZeroMonData(&gEnemyParty[1]);
ZeroMonData(&gEnemyParty[2]);
ZeroMonData(&gEnemyParty[4]);
@@ -1272,7 +1271,7 @@ void BattleSetup_StartTrainerBattle(void)
}
else
{
- sub_8163048(1);
+ FillFrontierTrainerParty(1);
ZeroMonData(&gEnemyParty[1]);
ZeroMonData(&gEnemyParty[2]);
}
diff --git a/src/battle_tent.c b/src/battle_tent.c
index e30cac386..4c4bd7fc3 100644
--- a/src/battle_tent.c
+++ b/src/battle_tent.c
@@ -102,7 +102,7 @@ void sub_81B99B4(void)
static void sub_81B99D4(void)
{
gSaveBlock2Ptr->frontier.field_CA8 = 0;
- gSaveBlock2Ptr->frontier.field_CB2 = 0;
+ gSaveBlock2Ptr->frontier.curChallengeBattleNum = 0;
gSaveBlock2Ptr->frontier.field_CA9_a = FALSE;
saved_warp2_set(0, gSaveBlock1Ptr->location.mapGroup, gSaveBlock1Ptr->location.mapNum, -1);
}
@@ -120,13 +120,13 @@ static void sub_81B9A44(void)
static void sub_81B9A60(void)
{
gTrainerBattleOpponent_A = (u32)((Random() % 255) * 5) / 64;
- sub_8162614(gTrainerBattleOpponent_A, 0);
+ SetBattleFacilityTrainerGfxId(gTrainerBattleOpponent_A, 0);
}
static void sub_81B9A90(void)
{
if (gTrainerBattleOpponent_A < 300)
- ConvertBattleFrontierTrainerSpeechToString(gFacilityTrainers[gTrainerBattleOpponent_A].speechBefore);
+ FrontierSpeechToString(gFacilityTrainers[gTrainerBattleOpponent_A].speechBefore);
}
static void sub_81B9ABC(void)
@@ -164,7 +164,7 @@ void sub_81B9B80(void)
static void sub_81B9BA0(void)
{
gSaveBlock2Ptr->frontier.field_CA8 = 0;
- gSaveBlock2Ptr->frontier.field_CB2 = 0;
+ gSaveBlock2Ptr->frontier.curChallengeBattleNum = 0;
gSaveBlock2Ptr->frontier.field_CA9_a = FALSE;
saved_warp2_set(0, gSaveBlock1Ptr->location.mapGroup, gSaveBlock1Ptr->location.mapNum, -1);
}
@@ -219,7 +219,7 @@ void sub_81B9D08(void)
static void sub_81B9D28(void)
{
gSaveBlock2Ptr->frontier.field_CA8 = 0;
- gSaveBlock2Ptr->frontier.field_CB2 = 0;
+ gSaveBlock2Ptr->frontier.curChallengeBattleNum = 0;
gSaveBlock2Ptr->frontier.field_CA9_a = FALSE;
saved_warp2_set(0, gSaveBlock1Ptr->location.mapGroup, gSaveBlock1Ptr->location.mapNum, -1);
}
@@ -551,25 +551,25 @@ static void sub_81BA040(void)
do
{
trainerId = Random() % 30;
- for (i = 0; i < gSaveBlock2Ptr->frontier.field_CB2; i++)
+ for (i = 0; i < gSaveBlock2Ptr->frontier.curChallengeBattleNum; i++)
{
if (gSaveBlock2Ptr->frontier.field_CB4[i] == trainerId)
break;
}
- } while (i != gSaveBlock2Ptr->frontier.field_CB2);
+ } while (i != gSaveBlock2Ptr->frontier.curChallengeBattleNum);
gTrainerBattleOpponent_A = trainerId;
- while (gFacilityTrainers[gTrainerBattleOpponent_A].btMonPool[monPoolCount] != 0xFFFF)
+ while (gFacilityTrainers[gTrainerBattleOpponent_A].bfMonPool[monPoolCount] != 0xFFFF)
monPoolCount++;
if (monPoolCount > 8)
break;
monPoolCount = 0;
}
- if (gSaveBlock2Ptr->frontier.field_CB2 < 2)
- gSaveBlock2Ptr->frontier.field_CB4[gSaveBlock2Ptr->frontier.field_CB2] = gTrainerBattleOpponent_A;
+ if (gSaveBlock2Ptr->frontier.curChallengeBattleNum < 2)
+ gSaveBlock2Ptr->frontier.field_CB4[gSaveBlock2Ptr->frontier.curChallengeBattleNum] = gTrainerBattleOpponent_A;
- monSetsPool = gFacilityTrainers[gTrainerBattleOpponent_A].btMonPool;
+ monSetsPool = gFacilityTrainers[gTrainerBattleOpponent_A].bfMonPool;
i = 0;
while (i != 3)
{
diff --git a/src/battle_tower.c b/src/battle_tower.c
index e70d4af91..4b63c2875 100644
--- a/src/battle_tower.c
+++ b/src/battle_tower.c
@@ -1,19 +1,207 @@
#include "global.h"
+#include "battle_tower.h"
+#include "apprentice.h"
#include "event_data.h"
#include "battle_setup.h"
#include "overworld.h"
#include "random.h"
-#include "battle_tower.h"
+#include "text.h"
+#include "main.h"
+#include "international_string_util.h"
+#include "battle.h"
+#include "battle_frontier_1.h"
+#include "battle_frontier_2.h"
+#include "recorded_battle.h"
+#include "easy_chat.h"
+#include "gym_leader_rematch.h"
+#include "battle_transition.h"
+#include "trainer_see.h"
+#include "new_game.h"
+#include "string_util.h"
+#include "data2.h"
+#include "link.h"
+#include "field_message_box.h"
+#include "tv.h"
+#include "constants/battle_frontier.h"
+#include "constants/trainers.h"
+#include "constants/event_objects.h"
+#include "constants/moves.h"
+#include "constants/species.h"
+
+extern u16 gUnknown_03006298[];
extern void sub_81A3ACC(void);
+extern void CreateFrontierBrainPokemon(void);
+extern void sub_81A6CD0(void);
+extern u16 sub_81A39C4(void);
+extern void SetFrontierBrainTrainerGfxId(void);
+extern u8 GetFrontierBrainTrainerPicIndex(void);
+extern u8 GetFrontierBrainTrainerClass(void);
+extern u8 IsFrontierBrainFemale(void);
+extern void CopyFrontierBrainTrainerName(u8 *dst);
+extern void SetMonMoveAvoidReturn(struct Pokemon *mon, u16 move, u8 moveSlot);
+
+extern const u8 *const *const gUnknown_085DD690[];
+extern const u16 gBattleFrontierHeldItems[];
+extern const u8 sRubyFacilityClassToEmerald[82][2];
+extern const u16 gUnknown_085DFA46[];
+extern const struct FacilityMon gBattleFrontierMons[];
+extern const struct FacilityMon gSlateportBattleTentMons[];
+extern const struct FacilityMon gVerdanturfBattleTentMons[];
+extern const struct FacilityMon gFallarborBattleTentMons[];
+extern const struct BattleFrontierTrainer gBattleFrontierTrainers[];
+extern const struct BattleFrontierTrainer gSlateportBattleTentTrainers[];
+extern const struct BattleFrontierTrainer gVerdanturfBattleTentTrainers[];
+extern const struct BattleFrontierTrainer gFallarborBattleTentTrainers[];
-extern const u32 gUnknown_085DF9AC[][2];
-extern const u32 gUnknown_085DF9CC[][2];
-extern void (* const gUnknown_085DF96C[])(void);
+struct
+{
+ u32 facilityClass;
+ const u8 *const *strings;
+} extern const gUnknown_085DD500[50];
+
+struct
+{
+ u16 species;
+ u8 fixedIV;
+ u8 level;
+ u8 nature;
+ u8 evs[6];
+ u16 moves[4];
+} extern const sStevenMons[3];
+
+extern const u8 MossdeepCity_SpaceCenter_2F_EventScript_224157[];
+extern const u8 MossdeepCity_SpaceCenter_2F_EventScript_224166[];
+
+// EWRAM vars.
+EWRAM_DATA const struct BattleFrontierTrainer *gFacilityTrainers = NULL;
+EWRAM_DATA const struct FacilityMon *gFacilityTrainerMons = NULL;
// This file's functions.
-void sub_8164ED8(void);
-u16 sub_8164FCC(u8, u8);
+static void sub_8161F94(void);
+static void sub_8162054(void);
+static void sub_81620F4(void);
+static void ChooseNextBattleTowerTrainer(void);
+static void sub_81621C0(void);
+static void AwardBattleTowerRibbons(void);
+static void SaveBattleTowerProgress(void);
+static void sub_8163914(void);
+static void nullsub_61(void);
+static void nullsub_116(void);
+static void sub_81642A0(void);
+static void sub_8164828(void);
+static void sub_8164B74(void);
+static void sub_8164DCC(void);
+static void sub_8164DE4(void);
+static void sub_8164E04(void);
+static void ValidateBattleTowerRecordChecksums(void);
+static void SaveCurrentWinStreak(void);
+static void ValidateApprenticesChecksums(void);
+static void sub_8165E18(void);
+static void CopyEReaderTrainerFarewellMessage(void);
+static void ClearBattleTowerRecord(struct EmeraldBattleTowerRecord *record);
+static void FillTrainerParty(u16 trainerId, u8 firstMonId, u8 monCount);
+static void FillTentTrainerParty_(u16 trainerId, u8 firstMonId, u8 monCount);
+static void FillFactoryFrontierTrainerParty(u16 trainerId, u8 firstMonId);
+static void FillFactoryTentTrainerParty(u16 trainerId, u8 firstMonId);
+static u8 GetFrontierTrainerFixedIvs(u16 trainerId);
+static void FillPartnerParty(u16 trainerId);
+static void SetEReaderTrainerChecksum(struct BattleTowerEReaderTrainer *ereaderTrainer);
+static u8 SetTentPtrsGetLevel(void);
+
+// Const rom data.
+static void (* const gUnknown_085DF96C[])(void) =
+{
+ sub_8161F94,
+ sub_8162054,
+ sub_81620F4,
+ ChooseNextBattleTowerTrainer,
+ sub_81621C0,
+ AwardBattleTowerRibbons,
+ SaveBattleTowerProgress,
+ sub_8163914,
+ nullsub_61,
+ nullsub_116,
+ sub_81642A0,
+ sub_8164828,
+ sub_8164B74,
+ sub_8164DCC,
+ sub_8164DE4,
+ sub_8164E04,
+};
+
+static const u32 gUnknown_085DF9AC[][2] =
+{
+ {0x00000001, 0x00000002},
+ {0x00004000, 0x00008000},
+ {0x00010000, 0x00020000},
+ {0x00040000, 0x00080000},
+};
+
+static const u32 gUnknown_085DF9CC[][2] =
+{
+ {0xfffffffe, 0xfffffffd},
+ {0xffffbfff, 0xffff7fff},
+ {0xfffeffff, 0xfffdffff},
+ {0xfffbffff, 0xfff7ffff},
+};
+
+static const u8 gUnknown_085DF9EC[] =
+{
+ 0x01, 0x02, 0x03, 0x04, 0x05, 0x08, 0x09, 0x0a, 0x0b, 0x0c
+};
+
+static const u8 gUnknown_085DF9F6[] =
+{
+ [FRONTIER_MODE_SINGLES] = 3,
+ [FRONTIER_MODE_DOUBLES] = 4,
+ [FRONTIER_MODE_MULTIS] = 2,
+ [FRONTIER_MODE_LINK_MULTIS] = 2,
+};
+
+static const u16 gUnknown_085DF9FA[][2] =
+{
+ {0x0000, 0x0063},
+ {0x0050, 0x0077},
+ {0x0064, 0x008b},
+ {0x0078, 0x009f},
+ {0x008c, 0x00b3},
+ {0x00a0, 0x00c7},
+ {0x00b4, 0x00db},
+ {0x00c8, 0x012b},
+};
+
+static const u16 gUnknown_085DFA1A[][2] =
+{
+ {0x0064, 0x0077},
+ {0x0078, 0x008b},
+ {0x008c, 0x009f},
+ {0x00a0, 0x00b3},
+ {0x00b4, 0x00c7},
+ {0x00c8, 0x00db},
+ {0x00dc, 0x00ef},
+ {0x00c8, 0x012b},
+ {0x00b3, 0x008d},
+ {0x00c8, 0x00b7},
+};
+
+static const u8 gUnknown_085DFA42[4] =
+{
+ [FRONTIER_MODE_SINGLES] = 3,
+ [FRONTIER_MODE_DOUBLES] = 4,
+ [FRONTIER_MODE_MULTIS] = 2,
+ [FRONTIER_MODE_LINK_MULTIS] = 2,
+};
+
+static const u16 gUnknown_085DFA46[] =
+{
+ 0x0c3a, 0x0c3a, 0x0c01, 0x0a2a, 0x0607, 0x0c01
+};
+
+static const u16 gUnknown_085DFA52[] =
+{
+ 0x1039, 0x122e, 0x0c04, 0x0a3d, 0x0630, 0x0c04
+};
// code
void sub_8161F74(void)
@@ -21,25 +209,25 @@ void sub_8161F74(void)
gUnknown_085DF96C[gSpecialVar_0x8004]();
}
-void sub_8161F94(void)
+static void sub_8161F94(void)
{
u32 lvlMode = gSaveBlock2Ptr->frontier.lvlMode;
u32 battleMode = VarGet(VAR_FRONTIER_BATTLE_MODE);
gSaveBlock2Ptr->frontier.field_CA8 = 1;
- gSaveBlock2Ptr->frontier.field_CB2 = 0;
+ gSaveBlock2Ptr->frontier.curChallengeBattleNum = 0;
gSaveBlock2Ptr->frontier.field_CA9_a = 0;
gSaveBlock2Ptr->frontier.field_CA9_b = 0;
sub_81A3ACC();
if (!(gSaveBlock2Ptr->frontier.field_CDC & gUnknown_085DF9AC[battleMode][lvlMode]))
- gSaveBlock2Ptr->frontier.field_CE0[battleMode][lvlMode] = 0;
+ gSaveBlock2Ptr->frontier.winStreaks[battleMode][lvlMode] = 0;
- sub_8164ED8();
+ ValidateBattleTowerRecordChecksums();
saved_warp2_set(0, gSaveBlock1Ptr->location.mapGroup, gSaveBlock1Ptr->location.mapNum, -1);
gTrainerBattleOpponent_A = 0;
}
-void sub_8162054(void)
+static void sub_8162054(void)
{
u32 lvlMode = gSaveBlock2Ptr->frontier.lvlMode;
u32 battleMode = VarGet(VAR_FRONTIER_BATTLE_MODE);
@@ -49,7 +237,7 @@ void sub_8162054(void)
case 0:
break;
case 1:
- gSpecialVar_Result = sub_8164FCC(lvlMode, battleMode);
+ gSpecialVar_Result = GetCurrentBattleTowerWinStreak(lvlMode, battleMode);
break;
case 2:
gSpecialVar_Result = ((gSaveBlock2Ptr->frontier.field_CDC & gUnknown_085DF9AC[battleMode][lvlMode]) != 0);
@@ -60,7 +248,7 @@ void sub_8162054(void)
}
}
-void sub_81620F4(void)
+static void sub_81620F4(void)
{
u32 lvlMode = gSaveBlock2Ptr->frontier.lvlMode;
u32 battleMode = VarGet(VAR_FRONTIER_BATTLE_MODE);
@@ -70,7 +258,7 @@ void sub_81620F4(void)
case 0:
break;
case 1:
- gSaveBlock2Ptr->frontier.field_CE0[battleMode][lvlMode] = gSpecialVar_0x8006;
+ gSaveBlock2Ptr->frontier.winStreaks[battleMode][lvlMode] = gSpecialVar_0x8006;
break;
case 2:
if (gSpecialVar_0x8006)
@@ -83,3 +271,2585 @@ void sub_81620F4(void)
break;
}
}
+
+static void sub_81621C0(void)
+{
+ if (gTrainerBattleOpponent_A == TRAINER_EREADER)
+ ClearEReaderTrainer(&gSaveBlock2Ptr->frontier.ereaderTrainer);
+
+ if (gSaveBlock2Ptr->frontier.field_D04 < 9999)
+ gSaveBlock2Ptr->frontier.field_D04++;
+
+ gSaveBlock2Ptr->frontier.curChallengeBattleNum++;
+ SaveCurrentWinStreak();
+ gSpecialVar_Result = gSaveBlock2Ptr->frontier.curChallengeBattleNum;
+}
+
+static bool8 ChooseSpecialBattleTowerTrainer(void)
+{
+ s32 i, j, validMons;
+ s32 trainerIds[9];
+ s32 idsCount = 0;
+ s32 winStreak = 0;
+ u8 lvlMode = gSaveBlock2Ptr->frontier.lvlMode;
+ u8 battleMode = VarGet(VAR_FRONTIER_BATTLE_MODE);
+
+ if (VarGet(VAR_FRONTIER_FACILITY) != FRONTIER_FACILITY_TOWER)
+ return FALSE;
+
+ winStreak = GetCurrentBattleTowerWinStreak(lvlMode, battleMode);
+ for (i = 0; i < 5; i++)
+ {
+ u32 *record = (u32*)(&gSaveBlock2Ptr->frontier.towerRecords[i]);
+ u32 recordHasData = 0;
+ u32 checksum = 0;
+ for (j = 0; j < (sizeof(struct EmeraldBattleTowerRecord) - 4) / 4; j++) // - 4, because of the last field being the checksum itself.
+ {
+ recordHasData |= record[j];
+ checksum += record[j];
+ }
+ validMons = 0;
+ for (j = 0; j < 4; j++)
+ {
+ if (gSaveBlock2Ptr->frontier.towerRecords[i].party[j].species != 0
+ && gSaveBlock2Ptr->frontier.towerRecords[i].party[j].level <= GetFrontierEnemyMonLevel(lvlMode))
+ validMons++;
+ }
+
+ if (validMons >= gUnknown_085DF9F6[battleMode]
+ && gSaveBlock2Ptr->frontier.towerRecords[i].winStreak == winStreak
+ && gSaveBlock2Ptr->frontier.towerRecords[i].lvlMode == lvlMode
+ && recordHasData
+ && gSaveBlock2Ptr->frontier.towerRecords[i].checksum == checksum)
+ {
+ trainerIds[idsCount] = i + TRAINER_RECORD_MIXING_FRIEND;
+ idsCount++;
+ }
+ }
+
+ if (battleMode == FRONTIER_MODE_SINGLES)
+ {
+ ValidateApprenticesChecksums();
+ for (i = 0; i < 4; i++)
+ {
+ if (gSaveBlock2Ptr->apprentices[i].lvlMode != 0
+ && gUnknown_085DF9EC[gSaveBlock2Ptr->apprentices[i].field_1] == winStreak
+ && gSaveBlock2Ptr->apprentices[i].lvlMode - 1 == lvlMode)
+ {
+ trainerIds[idsCount] = i + TRAINER_RECORD_MIXING_APPRENTICE;
+ idsCount++;
+ }
+ }
+ }
+
+ if (idsCount != 0)
+ {
+ gTrainerBattleOpponent_A = trainerIds[Random() % idsCount];
+ return TRUE;
+ }
+ else
+ {
+ return FALSE;
+ }
+}
+
+static void ChooseNextBattleTowerTrainer(void)
+{
+ u32 lvlMode = gSaveBlock2Ptr->frontier.lvlMode;
+ if (lvlMode == FRONTIER_LVL_TENT)
+ {
+ sub_8165E18();
+ }
+ else
+ {
+ u16 id;
+ u32 battleMode = VarGet(VAR_FRONTIER_BATTLE_MODE);
+ u32 r5 = sub_81A39C4() / 7;
+ SetFacilityPtrsGetLevel();
+
+ if (battleMode == FRONTIER_MODE_MULTIS || battleMode == FRONTIER_MODE_LINK_MULTIS)
+ {
+ id = gSaveBlock2Ptr->frontier.curChallengeBattleNum;
+ gTrainerBattleOpponent_A = gSaveBlock2Ptr->frontier.field_CB4[id * 2];
+ gTrainerBattleOpponent_B = gSaveBlock2Ptr->frontier.field_CB4[id * 2 + 1];
+ SetBattleFacilityTrainerGfxId(gTrainerBattleOpponent_A, 0);
+ SetBattleFacilityTrainerGfxId(gTrainerBattleOpponent_B, 1);
+ }
+ else if (ChooseSpecialBattleTowerTrainer())
+ {
+ SetBattleFacilityTrainerGfxId(gTrainerBattleOpponent_A, 0);
+ gSaveBlock2Ptr->frontier.field_CB4[gSaveBlock2Ptr->frontier.curChallengeBattleNum] = gTrainerBattleOpponent_A;
+ }
+ else
+ {
+ s32 i;
+ while (1)
+ {
+ id = sub_8162548(r5, gSaveBlock2Ptr->frontier.curChallengeBattleNum);
+
+ // Ensure trainer wasn't previously fought in this challenge.
+ for (i = 0; i < gSaveBlock2Ptr->frontier.curChallengeBattleNum; i++)
+ {
+ if (gSaveBlock2Ptr->frontier.field_CB4[i] == id)
+ break;
+ }
+ if (i == gSaveBlock2Ptr->frontier.curChallengeBattleNum)
+ break;
+ }
+
+ gTrainerBattleOpponent_A = id;
+ SetBattleFacilityTrainerGfxId(gTrainerBattleOpponent_A, 0);
+ if (gSaveBlock2Ptr->frontier.curChallengeBattleNum + 1 < 7)
+ gSaveBlock2Ptr->frontier.field_CB4[gSaveBlock2Ptr->frontier.curChallengeBattleNum] = gTrainerBattleOpponent_A;
+ }
+ }
+}
+
+u16 sub_8162548(u8 challengeNum, u8 battleNum)
+{
+ u16 trainerId;
+
+ if (challengeNum <= 7)
+ {
+ if (battleNum == 6)
+ {
+ trainerId = (gUnknown_085DFA1A[challengeNum][1] - gUnknown_085DFA1A[challengeNum][0]) + 1;
+ trainerId = gUnknown_085DFA1A[challengeNum][0] + (Random() % trainerId);
+ }
+ else
+ {
+ trainerId = (gUnknown_085DF9FA[challengeNum][1] - gUnknown_085DF9FA[challengeNum][0]) + 1;
+ trainerId = gUnknown_085DF9FA[challengeNum][0] + (Random() % trainerId);
+ }
+ }
+ else
+ {
+ trainerId = (gUnknown_085DF9FA[7][1] - gUnknown_085DF9FA[7][0]) + 1;
+ trainerId = gUnknown_085DF9FA[7][0] + (Random() % trainerId);
+ }
+
+ return trainerId;
+}
+
+#ifdef NONMATCHING
+static u16 sub_81625B4(u8 challengeNum, u8 battleNum, u16 *trainerIdPtr, u8 *arg3) // Unused
+{
+ register u16 trainerId, count;
+
+ if (challengeNum <= 7)
+ {
+ if (battleNum == 6)
+ {
+ count = (gUnknown_085DFA1A[challengeNum][1] - gUnknown_085DFA1A[challengeNum][0]) + 1;
+ trainerId = gUnknown_085DFA1A[challengeNum][0];
+ }
+ else
+ {
+ count = (gUnknown_085DF9FA[challengeNum][1] - gUnknown_085DF9FA[challengeNum][0]) + 1;
+ trainerId = gUnknown_085DF9FA[challengeNum][0];
+ }
+ }
+ else
+ {
+ count = (gUnknown_085DF9FA[7][1] - gUnknown_085DF9FA[7][0]) + 1;
+ trainerId = gUnknown_085DF9FA[7][0];
+ }
+
+ *trainerIdPtr = trainerId;
+ *arg3 = count;
+}
+#else
+NAKED
+static u16 sub_81625B4(u8 challengeNum, u8 battleNum, u16 *trainerIdPtr, u8 *arg3)
+{
+ asm_unified(" push {r4,lr}\n\
+ adds r4, r2, 0\n\
+ lsls r0, 24\n\
+ lsrs r0, 24\n\
+ adds r2, r0, 0\n\
+ lsls r1, 24\n\
+ lsrs r1, 24\n\
+ cmp r0, 0x7\n\
+ bhi _081625F4\n\
+ cmp r1, 0x6\n\
+ bne _081625D4\n\
+ ldr r1, =gUnknown_085DFA1A\n\
+ lsls r2, r0, 2\n\
+ b _081625D8\n\
+ .pool\n\
+_081625D4:\n\
+ ldr r1, =gUnknown_085DF9FA\n\
+ lsls r2, 2\n\
+_081625D8:\n\
+ adds r0, r1, 0x2\n\
+ adds r0, r2, r0\n\
+ adds r2, r1\n\
+ ldrh r0, [r0]\n\
+ ldrh r1, [r2]\n\
+ subs r0, r1\n\
+ adds r0, 0x1\n\
+ lsls r0, 16\n\
+ lsrs r1, r0, 16\n\
+ ldrh r0, [r2]\n\
+ b _08162604\n\
+ .pool\n\
+_081625F4:\n\
+ ldr r0, =gUnknown_085DF9FA\n\
+ ldrh r1, [r0, 0x1E]\n\
+ ldrh r2, [r0, 0x1C]\n\
+ subs r1, r2\n\
+ adds r1, 0x1\n\
+ lsls r1, 16\n\
+ lsrs r1, 16\n\
+ ldrh r0, [r0, 0x1C]\n\
+_08162604:\n\
+ strh r0, [r4]\n\
+ strb r1, [r3]\n\
+ pop {r4}\n\
+ pop {r0}\n\
+ bx r0\n\
+ .pool");
+}
+#endif
+
+void SetBattleFacilityTrainerGfxId(u16 trainerId, u8 tempVarId)
+{
+ u32 i;
+ u8 facilityClass;
+ u8 trainerObjectGfxId;
+
+ SetFacilityPtrsGetLevel();
+ if (trainerId == TRAINER_EREADER)
+ {
+ facilityClass = gSaveBlock2Ptr->frontier.ereaderTrainer.facilityClass;
+ }
+ else if (trainerId == TRAINER_FRONTIER_BRAIN)
+ {
+ SetFrontierBrainTrainerGfxId();
+ return;
+ }
+ else if (trainerId < TRAINER_RECORD_MIXING_FRIEND)
+ {
+ facilityClass = gFacilityTrainers[trainerId].facilityClass;
+ }
+ else if (trainerId < TRAINER_RECORD_MIXING_APPRENTICE)
+ {
+ facilityClass = gSaveBlock2Ptr->frontier.towerRecords[trainerId - TRAINER_RECORD_MIXING_FRIEND].facilityClass;
+ }
+ else
+ {
+ facilityClass = gApprentices[gSaveBlock2Ptr->apprentices[trainerId - TRAINER_RECORD_MIXING_APPRENTICE].id].facilityClass;
+ }
+
+ // Search male classes.
+ for (i = 0; i < ARRAY_COUNT(gTowerMaleFacilityClasses); i++)
+ {
+ if (gTowerMaleFacilityClasses[i] == facilityClass)
+ break;
+ }
+ if (i != ARRAY_COUNT(gTowerMaleFacilityClasses))
+ {
+ trainerObjectGfxId = gTowerMaleTrainerGfxIds[i];
+ switch (tempVarId)
+ {
+ case 0:
+ default:
+ VarSet(VAR_OBJ_GFX_ID_0, trainerObjectGfxId);
+ return;
+ case 1:
+ VarSet(VAR_OBJ_GFX_ID_1, trainerObjectGfxId);
+ return;
+ case 15:
+ VarSet(VAR_OBJ_GFX_ID_E, trainerObjectGfxId);
+ return;
+ }
+ }
+
+ // Search female classes.
+ for (i = 0; i < ARRAY_COUNT(gTowerFemaleFacilityClasses); i++)
+ {
+ if (gTowerFemaleFacilityClasses[i] == facilityClass)
+ break;
+ }
+ if (i != ARRAY_COUNT(gTowerFemaleFacilityClasses))
+ {
+ trainerObjectGfxId = gTowerFemaleTrainerGfxIds[i];
+ switch (tempVarId)
+ {
+ case 0:
+ default:
+ VarSet(VAR_OBJ_GFX_ID_0, trainerObjectGfxId);
+ return;
+ case 1:
+ VarSet(VAR_OBJ_GFX_ID_1, trainerObjectGfxId);
+ return;
+ case 15:
+ VarSet(VAR_OBJ_GFX_ID_E, trainerObjectGfxId);
+ return;
+ }
+ }
+
+ switch (tempVarId)
+ {
+ case 0:
+ default:
+ VarSet(VAR_OBJ_GFX_ID_0, EVENT_OBJ_GFX_BOY_1);
+ return;
+ case 1:
+ VarSet(VAR_OBJ_GFX_ID_1, EVENT_OBJ_GFX_BOY_1);
+ return;
+ case 15:
+ VarSet(VAR_OBJ_GFX_ID_E, EVENT_OBJ_GFX_BOY_1);
+ return;
+ }
+}
+
+void SetEReaderTrainerGfxId(void)
+{
+ SetBattleFacilityTrainerGfxId(TRAINER_EREADER, 0);
+}
+
+u8 GetBattleFacilityTrainerGfxId(u16 trainerId)
+{
+ u32 i;
+ u8 facilityClass;
+ u8 trainerObjectGfxId;
+
+ SetFacilityPtrsGetLevel();
+ if (trainerId == TRAINER_EREADER)
+ {
+ facilityClass = gSaveBlock2Ptr->frontier.ereaderTrainer.facilityClass;
+ }
+ else if (trainerId < TRAINER_RECORD_MIXING_FRIEND)
+ {
+ facilityClass = gFacilityTrainers[trainerId].facilityClass;
+ }
+ else if (trainerId < TRAINER_RECORD_MIXING_APPRENTICE)
+ {
+ facilityClass = gSaveBlock2Ptr->frontier.towerRecords[trainerId - TRAINER_RECORD_MIXING_FRIEND].facilityClass;
+ }
+ else
+ {
+ facilityClass = gApprentices[gSaveBlock2Ptr->apprentices[trainerId - TRAINER_RECORD_MIXING_APPRENTICE].id].facilityClass;
+ }
+
+ // Search male classes.
+ for (i = 0; i < ARRAY_COUNT(gTowerMaleFacilityClasses); i++)
+ {
+ if (gTowerMaleFacilityClasses[i] == facilityClass)
+ break;
+ }
+ if (i != ARRAY_COUNT(gTowerMaleFacilityClasses))
+ {
+ trainerObjectGfxId = gTowerMaleTrainerGfxIds[i];
+ return trainerObjectGfxId;
+ }
+
+ // Search female classes.
+ for (i = 0; i < ARRAY_COUNT(gTowerFemaleFacilityClasses); i++)
+ {
+ if (gTowerFemaleFacilityClasses[i] == facilityClass)
+ break;
+ }
+ if (i != ARRAY_COUNT(gTowerFemaleFacilityClasses))
+ {
+ trainerObjectGfxId = gTowerFemaleTrainerGfxIds[i];
+ return trainerObjectGfxId;
+ }
+ else
+ {
+ return EVENT_OBJ_GFX_BOY_1;
+ }
+}
+
+void PutNewBattleTowerRecord(struct EmeraldBattleTowerRecord *newRecordEm)
+{
+ u16 slotValues[6];
+ u16 slotIds[6];
+ s32 i, j, k;
+ s32 slotsCount = 0;
+ struct EmeraldBattleTowerRecord *newRecord = newRecordEm; // Needed to match.
+
+ // Find a record slot of the same player and replace it.
+ for (i = 0; i < 5; i++)
+ {
+ k = 0;
+ for (j = 0; j < 4; j++)
+ {
+ if (gSaveBlock2Ptr->frontier.towerRecords[i].trainerId[j] != newRecord->trainerId[j])
+ break;
+ }
+ if (j == 4)
+ {
+ for (k = 0; k < PLAYER_NAME_LENGTH; k++)
+ {
+ // BUG: Wrong variable used, 'j' instead of 'k'.
+ if (gSaveBlock2Ptr->frontier.towerRecords[i].name[j] != newRecord->name[j])
+ break;
+ if (newRecord->name[j] == EOS)
+ {
+ k = PLAYER_NAME_LENGTH;
+ break;
+ }
+ }
+ }
+
+ if (k == PLAYER_NAME_LENGTH)
+ break;
+ }
+ if (i < 5)
+ {
+ gSaveBlock2Ptr->frontier.towerRecords[i] = *newRecord;
+ return;
+ }
+
+ // Find an empty record slot.
+ for (i = 0; i < 5; i++)
+ {
+ if (gSaveBlock2Ptr->frontier.towerRecords[i].winStreak == 0)
+ break;
+ }
+ if (i < 5)
+ {
+ gSaveBlock2Ptr->frontier.towerRecords[i] = *newRecord;
+ return;
+ }
+
+ // Find possible slots to replace the record.
+ slotValues[0] = gSaveBlock2Ptr->frontier.towerRecords[0].winStreak;
+ slotIds[0] = 0;
+ slotsCount++;
+
+ for (i = 1; i < 5; i++)
+ {
+ for (j = 0; j < slotsCount; j++)
+ {
+ if (gSaveBlock2Ptr->frontier.towerRecords[i].winStreak < slotValues[j])
+ {
+ j = 0;
+ slotsCount = 1;
+ slotValues[0] = gSaveBlock2Ptr->frontier.towerRecords[i].winStreak;
+ slotIds[0] = i;
+ break;
+ }
+ else if (gSaveBlock2Ptr->frontier.towerRecords[i].winStreak > slotValues[j])
+ {
+ break;
+ }
+ }
+
+ if (j == slotsCount)
+ {
+ slotValues[slotsCount] = gSaveBlock2Ptr->frontier.towerRecords[i].winStreak;
+ slotIds[slotsCount] = i;
+ slotsCount++;
+ }
+ }
+
+ i = Random() % slotsCount;
+ gSaveBlock2Ptr->frontier.towerRecords[slotIds[i]] = *newRecord;
+}
+
+u8 GetFrontierTrainerFrontSpriteId(u16 trainerId)
+{
+ SetFacilityPtrsGetLevel();
+
+ if (trainerId == TRAINER_EREADER)
+ {
+ return gFacilityClassToPicIndex[gSaveBlock2Ptr->frontier.ereaderTrainer.facilityClass];
+ }
+ else if (trainerId == TRAINER_FRONTIER_BRAIN)
+ {
+ return GetFrontierBrainTrainerPicIndex();
+ }
+ else if (trainerId < TRAINER_RECORD_MIXING_FRIEND)
+ {
+ return gFacilityClassToPicIndex[gFacilityTrainers[trainerId].facilityClass];
+ }
+ else if (trainerId < TRAINER_RECORD_MIXING_APPRENTICE)
+ {
+ if (gBattleTypeFlags & BATTLE_TYPE_RECORDED)
+ return gFacilityClassToPicIndex[sub_818649C()];
+ else
+ return gFacilityClassToPicIndex[gSaveBlock2Ptr->frontier.towerRecords[trainerId - TRAINER_RECORD_MIXING_FRIEND].facilityClass];
+ }
+ else
+ {
+ if (gBattleTypeFlags & BATTLE_TYPE_RECORDED)
+ return gFacilityClassToPicIndex[gApprentices[sub_81864A8()].facilityClass];
+ else
+ return gFacilityClassToPicIndex[gApprentices[gSaveBlock2Ptr->apprentices[trainerId - TRAINER_RECORD_MIXING_APPRENTICE].id].facilityClass];
+ }
+}
+
+u8 GetFrontierOpponentClass(u16 trainerId)
+{
+ u8 trainerClass = 0;
+ SetFacilityPtrsGetLevel();
+
+ if (trainerId == TRAINER_EREADER)
+ {
+ trainerClass = gFacilityClassToTrainerClass[gSaveBlock2Ptr->frontier.ereaderTrainer.facilityClass];
+ }
+ else if (trainerId == TRAINER_FRONTIER_BRAIN)
+ {
+ trainerClass = GetFrontierBrainTrainerClass();
+ }
+ else if (trainerId == TRAINER_STEVEN_PARTNER)
+ {
+ trainerClass = gTrainers[TRAINER_STEVEN].trainerClass;
+ }
+ else if (trainerId < TRAINER_RECORD_MIXING_FRIEND)
+ {
+ trainerClass = gFacilityClassToTrainerClass[gFacilityTrainers[trainerId].facilityClass];
+ }
+ else if (trainerId < TRAINER_RECORD_MIXING_APPRENTICE)
+ {
+ if (gBattleTypeFlags & BATTLE_TYPE_RECORDED)
+ {
+ trainerClass = gFacilityClassToTrainerClass[sub_818649C()];
+ }
+ else
+ {
+ trainerClass = gFacilityClassToTrainerClass[gSaveBlock2Ptr->frontier.towerRecords[trainerId - TRAINER_RECORD_MIXING_FRIEND].facilityClass];
+ asm("");
+ }
+ }
+ else
+ {
+ if (gBattleTypeFlags & BATTLE_TYPE_RECORDED)
+ {
+ trainerClass = gFacilityClassToTrainerClass[gApprentices[sub_81864A8()].facilityClass];
+ }
+ else
+ {
+ trainerClass = gFacilityClassToTrainerClass[gApprentices[gSaveBlock2Ptr->apprentices[trainerId - TRAINER_RECORD_MIXING_APPRENTICE].id].facilityClass];
+ asm("");
+ }
+ }
+
+ return trainerClass;
+}
+
+static u8 GetFrontierTrainerFacilityClass(u16 trainerId)
+{
+ u8 facilityClass;
+ SetFacilityPtrsGetLevel();
+
+ if (trainerId == TRAINER_EREADER)
+ {
+ facilityClass = gSaveBlock2Ptr->frontier.ereaderTrainer.facilityClass;
+ }
+ else if (trainerId < TRAINER_RECORD_MIXING_FRIEND)
+ {
+ facilityClass = gFacilityTrainers[trainerId].facilityClass;
+ }
+ else if (trainerId < TRAINER_RECORD_MIXING_APPRENTICE)
+ {
+ if (gBattleTypeFlags & BATTLE_TYPE_RECORDED)
+ facilityClass = sub_818649C();
+ else
+ facilityClass = gSaveBlock2Ptr->frontier.towerRecords[trainerId - TRAINER_RECORD_MIXING_FRIEND].facilityClass;
+ }
+ else
+ {
+ if (gBattleTypeFlags & BATTLE_TYPE_RECORDED)
+ facilityClass = gApprentices[sub_81864A8()].facilityClass;
+ else
+ facilityClass = gApprentices[gSaveBlock2Ptr->apprentices[trainerId - TRAINER_RECORD_MIXING_APPRENTICE].id].facilityClass;
+ }
+
+ return facilityClass;
+}
+
+void GetFrontierTrainerName(u8 *dst, u16 trainerId)
+{
+ s32 i = 0;
+ SetFacilityPtrsGetLevel();
+
+ if (trainerId == TRAINER_EREADER)
+ {
+ for (i = 0; i < PLAYER_NAME_LENGTH; i++)
+ dst[i] = gSaveBlock2Ptr->frontier.ereaderTrainer.name[i];
+ }
+ else if (trainerId == TRAINER_FRONTIER_BRAIN)
+ {
+ CopyFrontierBrainTrainerName(dst);
+ return;
+ }
+ else if (trainerId == TRAINER_STEVEN_PARTNER)
+ {
+ for (i = 0; i < PLAYER_NAME_LENGTH; i++)
+ dst[i] = gTrainers[TRAINER_STEVEN].trainerName[i];
+ }
+ else if (trainerId < TRAINER_RECORD_MIXING_FRIEND)
+ {
+ for (i = 0; i < PLAYER_NAME_LENGTH; i++)
+ dst[i] = gFacilityTrainers[trainerId].trainerName[i];
+ }
+ else if (trainerId < TRAINER_RECORD_MIXING_APPRENTICE)
+ {
+ if (gBattleTypeFlags & BATTLE_TYPE_RECORDED)
+ {
+ sub_8186468(dst);
+ return;
+ }
+ else
+ {
+ struct EmeraldBattleTowerRecord *record = &gSaveBlock2Ptr->frontier.towerRecords[trainerId - TRAINER_RECORD_MIXING_FRIEND];
+ TVShowConvertInternationalString(dst, record->name, record->language);
+ return;
+ }
+ }
+ else
+ {
+ u8 id, language;
+
+ if (gBattleTypeFlags & BATTLE_TYPE_RECORDED)
+ {
+ id = sub_81864A8();
+ language = sub_81864C0();
+ }
+ else
+ {
+ struct Apprentice *apprentice = &gSaveBlock2Ptr->apprentices[trainerId - TRAINER_RECORD_MIXING_APPRENTICE];
+ id = apprentice->id;
+ language = apprentice->language;
+ }
+ TVShowConvertInternationalString(dst, GetApprenticeNameInLanguage(id, language), language);
+ return;
+ }
+
+ dst[i] = EOS;
+}
+
+static bool8 IsFrontierTrainerFemale(u16 trainerId)
+{
+ u32 i;
+ u8 facilityClass;
+
+ SetFacilityPtrsGetLevel();
+ if (trainerId == TRAINER_EREADER)
+ {
+ facilityClass = gSaveBlock2Ptr->frontier.ereaderTrainer.facilityClass;
+ }
+ else if (trainerId == TRAINER_FRONTIER_BRAIN)
+ {
+ return IsFrontierBrainFemale();
+ }
+ else if (trainerId < TRAINER_RECORD_MIXING_FRIEND)
+ {
+ facilityClass = gFacilityTrainers[trainerId].facilityClass;
+ }
+ else if (trainerId < TRAINER_RECORD_MIXING_APPRENTICE)
+ {
+ facilityClass = gSaveBlock2Ptr->frontier.towerRecords[trainerId - TRAINER_RECORD_MIXING_FRIEND].facilityClass;
+ }
+ else
+ {
+ facilityClass = gApprentices[gSaveBlock2Ptr->apprentices[trainerId - TRAINER_RECORD_MIXING_APPRENTICE].id].facilityClass;
+ }
+
+ // Search female classes.
+ for (i = 0; i < ARRAY_COUNT(gTowerFemaleFacilityClasses); i++)
+ {
+ if (gTowerFemaleFacilityClasses[i] == facilityClass)
+ break;
+ }
+ if (i != ARRAY_COUNT(gTowerFemaleFacilityClasses))
+ return TRUE;
+ else
+ return FALSE;
+}
+
+void FillFrontierTrainerParty(u8 monsCount)
+{
+ ZeroEnemyPartyMons();
+ FillTrainerParty(gTrainerBattleOpponent_A, 0, monsCount);
+}
+
+void FillFrontierTrainersParties(u8 monsCount)
+{
+ ZeroEnemyPartyMons();
+ FillTrainerParty(gTrainerBattleOpponent_A, 0, monsCount);
+ FillTrainerParty(gTrainerBattleOpponent_B, 3, monsCount);
+}
+
+static void FillTentTrainerParty(u8 monsCount)
+{
+ ZeroEnemyPartyMons();
+ FillTentTrainerParty_(gTrainerBattleOpponent_A, 0, monsCount);
+}
+
+static void FillTrainerParty(u16 trainerId, u8 firstMonId, u8 monCount)
+{
+ s32 i, j;
+ u16 chosenMonIndices[4];
+ u8 friendship = 0xFF;
+ u8 level = SetFacilityPtrsGetLevel();
+ u8 fixedIV = 0;
+ u8 bfMonCount;
+ const u16 *bfMonPool = NULL;
+ u32 otID = 0;
+
+ if (trainerId < TRAINER_RECORD_MIXING_FRIEND)
+ {
+ // Normal battle frontier trainer.
+ fixedIV = GetFrontierTrainerFixedIvs(trainerId);
+ bfMonPool = gFacilityTrainers[gTrainerBattleOpponent_A].bfMonPool;
+ }
+ else if (trainerId == TRAINER_EREADER)
+ {
+ for (i = firstMonId; i < firstMonId + 3; i++)
+ sub_806819C(&gEnemyParty[i], &gSaveBlock2Ptr->frontier.ereaderTrainer.party[i - firstMonId]);
+ return;
+ }
+ else if (trainerId == TRAINER_FRONTIER_BRAIN)
+ {
+ CreateFrontierBrainPokemon();
+ return;
+ }
+ else if (trainerId < TRAINER_RECORD_MIXING_APPRENTICE)
+ {
+ // Record mixed player.
+ for (j = 0, i = firstMonId; i < firstMonId + monCount; j++, i++)
+ {
+ if (gSaveBlock2Ptr->frontier.towerRecords[trainerId - TRAINER_RECORD_MIXING_FRIEND].party[j].species != 0
+ && gSaveBlock2Ptr->frontier.towerRecords[trainerId - TRAINER_RECORD_MIXING_FRIEND].party[j].level <= level)
+ {
+ sub_8068338(&gEnemyParty[i], &gSaveBlock2Ptr->frontier.towerRecords[trainerId - TRAINER_RECORD_MIXING_FRIEND].party[j], FALSE);
+ }
+ }
+ return;
+ }
+ else
+ {
+ // Apprentice.
+ for (i = firstMonId; i < firstMonId + 3; i++)
+ CreateApprenticeMon(&gEnemyParty[i], &gSaveBlock2Ptr->apprentices[trainerId - TRAINER_RECORD_MIXING_APPRENTICE], i - firstMonId);
+ return;
+ }
+
+ // Regular battle frontier trainer.
+ // Attempt to fill the trainer's party with random Pokemon until 3 have been
+ // successfully chosen. The trainer's party may not have duplicate pokemon species
+ // or duplicate held items.
+ for (bfMonCount = 0; bfMonPool[bfMonCount] != 0xFFFF; bfMonCount++)
+ ;
+ i = 0;
+ otID = Random32();
+ while (i != monCount)
+ {
+ u16 monPoolId = bfMonPool[Random() % bfMonCount];
+ if ((level == 50 || level == 20) && monPoolId > 849)
+ continue;
+
+ // Ensure this pokemon species isn't a duplicate.
+ for (j = 0; j < i + firstMonId; j++)
+ {
+ if (GetMonData(&gEnemyParty[j], MON_DATA_SPECIES, NULL) == gFacilityTrainerMons[monPoolId].species)
+ break;
+ }
+ if (j != i + firstMonId)
+ continue;
+
+ // Ensure this Pokemon's held item isn't a duplicate.
+ for (j = 0; j < i + firstMonId; j++)
+ {
+ if (GetMonData(&gEnemyParty[j], MON_DATA_HELD_ITEM, NULL) != 0
+ && GetMonData(&gEnemyParty[j], MON_DATA_HELD_ITEM, NULL) == gBattleFrontierHeldItems[gFacilityTrainerMons[monPoolId].itemTableId])
+ break;
+ }
+ if (j != i + firstMonId)
+ continue;
+
+ // Ensure this exact pokemon index isn't a duplicate. This check doesn't seem necessary
+ // because the species and held items were already checked directly above.
+ for (j = 0; j < i; j++)
+ {
+ if (chosenMonIndices[j] == monPoolId)
+ break;
+ }
+ if (j != i)
+ continue;
+
+ chosenMonIndices[i] = monPoolId;
+
+ // Place the chosen pokemon into the trainer's party.
+ CreateMonWithEVSpreadPersonalityOTID(&gEnemyParty[i + firstMonId],
+ gFacilityTrainerMons[monPoolId].species,
+ level,
+ gFacilityTrainerMons[monPoolId].nature,
+ fixedIV,
+ gFacilityTrainerMons[monPoolId].evSpread,
+ otID);
+
+ friendship = 255;
+ // Give the chosen pokemon its specified moves.
+ for (j = 0; j < 4; j++)
+ {
+ SetMonMoveSlot(&gEnemyParty[i + firstMonId], gFacilityTrainerMons[monPoolId].moves[j], j);
+ if (gFacilityTrainerMons[monPoolId].moves[j] == MOVE_FRUSTRATION)
+ friendship = 0; // Frustration is more powerful the lower the pokemon's friendship is.
+ }
+
+ SetMonData(&gEnemyParty[i + firstMonId], MON_DATA_FRIENDSHIP, &friendship);
+ SetMonData(&gEnemyParty[i + firstMonId], MON_DATA_HELD_ITEM, &gBattleFrontierHeldItems[gFacilityTrainerMons[monPoolId].itemTableId]);
+
+ // The pokemon was successfully added to the trainer's party, so it's safe to move on to
+ // the next party slot.
+ i++;
+ }
+}
+
+// Probably an early draft before the 'CreateApprenticeMon' was written.
+static void Unused_CreateApprenticeMons(u16 trainerId, u8 firstMonId)
+{
+ s32 i, j;
+ u8 friendship = 0xFF;
+ u8 level = 0;
+ u8 fixedIV = 0;
+ struct Apprentice *apprentice = &gSaveBlock2Ptr->apprentices[0];
+
+ if (apprentice->field_1 < 5)
+ fixedIV = 6;
+ else
+ fixedIV = 9;
+
+ if (gSaveBlock2Ptr->frontier.lvlMode != FRONTIER_LVL_50)
+ level = 100;
+ else
+ level = 50;
+
+ for (i = 0; i != 3; i++)
+ {
+ CreateMonWithEVSpread(&gEnemyParty[firstMonId + i], apprentice->party[i].species, level, fixedIV, 8);
+ friendship = 0xFF;
+ for (j = 0; j < 4; j++)
+ {
+ if (apprentice->party[i].moves[j] == MOVE_FRUSTRATION)
+ friendship = 0;
+ }
+ SetMonData(&gEnemyParty[firstMonId + i], MON_DATA_FRIENDSHIP, &friendship);
+ SetMonData(&gEnemyParty[firstMonId + i], MON_DATA_HELD_ITEM, &apprentice->party[i].item);
+ }
+}
+
+u16 RandomizeFacilityTrainerMonId(u16 trainerId)
+{
+ u8 level = SetFacilityPtrsGetLevel();
+ const u16 *bfMonPool = gFacilityTrainers[trainerId].bfMonPool;
+ u8 bfMonCount = 0;
+ u32 monPoolId = bfMonPool[bfMonCount];
+
+ while (monPoolId != 0xFFFF)
+ {
+ bfMonCount++;
+ monPoolId = bfMonPool[bfMonCount];
+ if (monPoolId == 0xFFFF)
+ break;
+ }
+
+ do
+ {
+ monPoolId = bfMonPool[Random() % bfMonCount];
+ } while((level == 50 || level == 20) && monPoolId > 849);
+
+ return monPoolId;
+}
+
+static void FillFactoryTrainerParty(void)
+{
+ ZeroEnemyPartyMons();
+ if (gSaveBlock2Ptr->frontier.lvlMode != FRONTIER_LVL_TENT)
+ FillFactoryFrontierTrainerParty(gTrainerBattleOpponent_A, 0);
+ else
+ FillFactoryTentTrainerParty(gTrainerBattleOpponent_A, 0);
+}
+
+static void FillFactoryFrontierTrainerParty(u16 trainerId, u8 firstMonId)
+{
+ u8 i, j;
+ u8 friendship;
+ u8 level;
+ u8 fixedIV;
+ u32 otID;
+
+ if (trainerId < TRAINER_RECORD_MIXING_FRIEND)
+ {
+ u8 lvlMode = gSaveBlock2Ptr->frontier.lvlMode; // Unused variable.
+ u8 battleMode = VarGet(VAR_FRONTIER_BATTLE_MODE);
+ u8 challengeNum = gSaveBlock2Ptr->frontier.winStreaks[battleMode][0] / 7;
+ if (gSaveBlock2Ptr->frontier.curChallengeBattleNum < 6)
+ fixedIV = sub_81A6CA8(challengeNum, 0);
+ else
+ fixedIV = sub_81A6CA8(challengeNum, 1);
+ }
+ else if (trainerId == TRAINER_EREADER)
+ {
+ for (i = firstMonId; i < firstMonId + 3; i++)
+ sub_806819C(&gEnemyParty[i], &gSaveBlock2Ptr->frontier.ereaderTrainer.party[i - firstMonId]);
+ return;
+ }
+ else if (trainerId == TRAINER_FRONTIER_BRAIN)
+ {
+ sub_81A6CD0();
+ return;
+ }
+ else
+ {
+ fixedIV = 31;
+ }
+
+
+ level = SetFacilityPtrsGetLevel();
+ otID = T1_READ_32(gSaveBlock2Ptr->playerTrainerId);
+ for (i = 0; i < 3; i++)
+ {
+ u16 poolId = gUnknown_03006298[i];
+ CreateMonWithEVSpreadPersonalityOTID(&gEnemyParty[firstMonId + i],
+ gFacilityTrainerMons[poolId].species,
+ level,
+ gFacilityTrainerMons[poolId].nature,
+ fixedIV,
+ gFacilityTrainerMons[poolId].evSpread,
+ otID);
+
+ friendship = 0;
+ for (j = 0; j < 4; j++)
+ SetMonMoveAvoidReturn(&gEnemyParty[firstMonId + i], gFacilityTrainerMons[poolId].moves[j], j);
+
+ SetMonData(&gEnemyParty[firstMonId + i], MON_DATA_FRIENDSHIP, &friendship);
+ SetMonData(&gEnemyParty[firstMonId + i], MON_DATA_HELD_ITEM, &gBattleFrontierHeldItems[gFacilityTrainerMons[poolId].itemTableId]);
+ }
+}
+
+static void FillFactoryTentTrainerParty(u16 trainerId, u8 firstMonId)
+{
+ u8 i, j;
+ u8 friendship;
+ u8 level = 30;
+ u8 fixedIV = 0;
+ u32 otID = T1_READ_32(gSaveBlock2Ptr->playerTrainerId);
+
+ for (i = 0; i < 3; i++)
+ {
+ u16 poolId = gUnknown_03006298[i];
+ CreateMonWithEVSpreadPersonalityOTID(&gEnemyParty[firstMonId + i],
+ gFacilityTrainerMons[poolId].species,
+ level,
+ gFacilityTrainerMons[poolId].nature,
+ fixedIV,
+ gFacilityTrainerMons[poolId].evSpread,
+ otID);
+
+ friendship = 0;
+ for (j = 0; j < 4; j++)
+ {
+ SetMonMoveAvoidReturn(&gEnemyParty[firstMonId + i], gFacilityTrainerMons[poolId].moves[j], j);
+ if (gFacilityTrainerMons[poolId].moves[j] == MOVE_FRUSTRATION)
+ friendship = 0;
+ }
+
+ SetMonData(&gEnemyParty[firstMonId + i], MON_DATA_FRIENDSHIP, &friendship);
+ SetMonData(&gEnemyParty[firstMonId + i], MON_DATA_HELD_ITEM, &gBattleFrontierHeldItems[gFacilityTrainerMons[poolId].itemTableId]);
+ }
+}
+
+void FrontierSpeechToString(const u16 *words)
+{
+ ConvertEasyChatWordsToString(gStringVar4, words, 3, 2);
+ if (GetStringWidth(1, gStringVar4, -1) > 204)
+ {
+ s32 i = 0;
+
+ ConvertEasyChatWordsToString(gStringVar4, words, 2, 3);
+ while (gStringVar4[i++] != CHAR_NEWLINE)
+ ;
+ while (gStringVar4[i] != CHAR_NEWLINE)
+ i++;
+
+ gStringVar4[i] = CHAR_PROMPT_SCROLL;
+ }
+}
+
+static void sub_8163914(void)
+{
+ u16 trainerId;
+ SetFacilityPtrsGetLevel();
+
+ if (gSpecialVar_0x8005)
+ trainerId = gTrainerBattleOpponent_B;
+ else
+ trainerId = gTrainerBattleOpponent_A;
+
+ if (trainerId == TRAINER_EREADER)
+ FrontierSpeechToString(gSaveBlock2Ptr->frontier.ereaderTrainer.greeting);
+ else if (trainerId < TRAINER_RECORD_MIXING_FRIEND)
+ FrontierSpeechToString(gFacilityTrainers[trainerId].speechBefore);
+ else if (trainerId < TRAINER_RECORD_MIXING_APPRENTICE)
+ FrontierSpeechToString(gSaveBlock2Ptr->frontier.towerRecords[trainerId - TRAINER_RECORD_MIXING_FRIEND].greeting);
+ else
+ CopyFriendsApprenticeChallengeText(trainerId - TRAINER_RECORD_MIXING_APPRENTICE);
+}
+
+static void HandleSpecialTrainerBattleEnd(void)
+{
+ s32 i;
+
+ sub_81864CC();
+ switch (gBattleScripting.specialTrainerBattleType)
+ {
+ case SPECIAL_BATTLE_TOWER:
+ case SPECIAL_BATTLE_DOME:
+ case SPECIAL_BATTLE_PALACE:
+ case SPECIAL_BATTLE_ARENA:
+ case SPECIAL_BATTLE_FACTORY:
+ case SPECIAL_BATTLE_PIKE_SINGLE:
+ case SPECIAL_BATTLE_PIKE_DOUBLE:
+ case SPECIAL_BATTLE_PYRAMID:
+ if (gSaveBlock2Ptr->frontier.battlesCount < 0xFFFFFF)
+ {
+ gSaveBlock2Ptr->frontier.battlesCount++;
+ if (gSaveBlock2Ptr->frontier.battlesCount % 20 == 0)
+ UpdateGymLeaderRematch();
+ }
+ else
+ {
+ gSaveBlock2Ptr->frontier.battlesCount = 0xFFFFFF;
+ }
+ break;
+ case SPECIAL_BATTLE_SECRET_BASE:
+ for (i = 0; i < PARTY_SIZE; i++)
+ {
+ u16 itemBefore = GetMonData(&gSaveBlock1Ptr->playerParty[i], MON_DATA_HELD_ITEM);
+ SetMonData(&gPlayerParty[i], MON_DATA_HELD_ITEM, &itemBefore);
+ }
+ break;
+ case SPECIAL_BATTLE_EREADER:
+ CopyEReaderTrainerFarewellMessage();
+ break;
+ }
+
+ SetMainCallback2(CB2_ReturnToFieldContinueScriptPlayMapMusic);
+}
+
+static void Task_StartBattleAfterTransition(u8 taskId)
+{
+ if (IsBattleTransitionDone() == TRUE)
+ {
+ gMain.savedCallback = HandleSpecialTrainerBattleEnd;
+ SetMainCallback2(CB2_InitBattle);
+ DestroyTask(taskId);
+ }
+}
+
+void DoSpecialTrainerBattle(void)
+{
+ s32 i;
+
+ gBattleScripting.specialTrainerBattleType = gSpecialVar_0x8004;
+ switch (gSpecialVar_0x8004)
+ {
+ case SPECIAL_BATTLE_TOWER:
+ gBattleTypeFlags = BATTLE_TYPE_TRAINER | BATTLE_TYPE_BATTLE_TOWER;
+ switch (VarGet(VAR_FRONTIER_BATTLE_MODE))
+ {
+ case FRONTIER_MODE_SINGLES:
+ FillFrontierTrainerParty(3);
+ break;
+ case FRONTIER_MODE_DOUBLES:
+ FillFrontierTrainerParty(4);
+ gBattleTypeFlags |= BATTLE_TYPE_DOUBLE;
+ break;
+ case FRONTIER_MODE_MULTIS:
+ FillFrontierTrainersParties(2);
+ gPartnerTrainerId = gSaveBlock2Ptr->frontier.field_CB4[17];
+ FillPartnerParty(gPartnerTrainerId);
+ gBattleTypeFlags |= BATTLE_TYPE_DOUBLE | BATTLE_TYPE_INGAME_PARTNER | BATTLE_TYPE_MULTI | BATTLE_TYPE_TWO_OPPONENTS;
+ break;
+ case FRONTIER_MODE_LINK_MULTIS:
+ gBattleTypeFlags |= BATTLE_TYPE_DOUBLE | BATTLE_TYPE_LINK | BATTLE_TYPE_MULTI | BATTLE_TYPE_x800000;
+ FillFrontierTrainersParties(2);
+ break;
+ }
+ CreateTask(Task_StartBattleAfterTransition, 1);
+ PlayMapChosenOrBattleBGM(0);
+ BattleTransition_StartOnField(sub_80B100C(0));
+ break;
+ case SPECIAL_BATTLE_SECRET_BASE:
+ for (i = 0; i < PARTY_SIZE; i++)
+ {
+ u16 itemBefore = GetMonData(&gPlayerParty[i], MON_DATA_HELD_ITEM);
+ SetMonData(&gSaveBlock1Ptr->playerParty[i], MON_DATA_HELD_ITEM, &itemBefore);
+ }
+ CreateTask(Task_StartBattleAfterTransition, 1);
+ PlayMapChosenOrBattleBGM(0);
+ BattleTransition_StartOnField(sub_80B100C(12));
+ break;
+ case SPECIAL_BATTLE_EREADER:
+ ZeroEnemyPartyMons();
+ for (i = 0; i < 3; i++)
+ sub_806819C(&gEnemyParty[i], &gSaveBlock2Ptr->frontier.ereaderTrainer.party[i]);
+ gBattleTypeFlags = BATTLE_TYPE_TRAINER | BATTLE_TYPE_EREADER_TRAINER;
+ gTrainerBattleOpponent_A = 0;
+ CreateTask(Task_StartBattleAfterTransition, 1);
+ PlayMapChosenOrBattleBGM(0);
+ BattleTransition_StartOnField(sub_80B100C(13));
+ break;
+ case SPECIAL_BATTLE_DOME:
+ gBattleTypeFlags = BATTLE_TYPE_TRAINER | BATTLE_TYPE_DOME;
+ if (VarGet(VAR_FRONTIER_BATTLE_MODE) == FRONTIER_MODE_DOUBLES)
+ gBattleTypeFlags |= BATTLE_TYPE_DOUBLE;
+ if (gTrainerBattleOpponent_A == TRAINER_FRONTIER_BRAIN)
+ FillFrontierTrainerParty(2);
+ CreateTask(Task_StartBattleAfterTransition, 1);
+ sub_806E694(0);
+ BattleTransition_StartOnField(sub_80B100C(3));
+ break;
+ case SPECIAL_BATTLE_PALACE:
+ gBattleTypeFlags = BATTLE_TYPE_TRAINER | BATTLE_TYPE_PALACE;
+ if (VarGet(VAR_FRONTIER_BATTLE_MODE) == FRONTIER_MODE_DOUBLES)
+ gBattleTypeFlags |= BATTLE_TYPE_DOUBLE;
+ if (gSaveBlock2Ptr->frontier.lvlMode != FRONTIER_LVL_TENT)
+ FillFrontierTrainerParty(3);
+ else
+ FillTentTrainerParty(3);
+ CreateTask(Task_StartBattleAfterTransition, 1);
+ PlayMapChosenOrBattleBGM(0);
+ BattleTransition_StartOnField(sub_80B100C(4));
+ break;
+ case SPECIAL_BATTLE_ARENA:
+ gBattleTypeFlags = BATTLE_TYPE_TRAINER | BATTLE_TYPE_ARENA;
+ if (gSaveBlock2Ptr->frontier.lvlMode != FRONTIER_LVL_TENT)
+ FillFrontierTrainerParty(3);
+ else
+ FillTentTrainerParty(3);
+ CreateTask(Task_StartBattleAfterTransition, 1);
+ PlayMapChosenOrBattleBGM(0);
+ BattleTransition_StartOnField(sub_80B100C(5));
+ break;
+ case SPECIAL_BATTLE_FACTORY:
+ gBattleTypeFlags = BATTLE_TYPE_TRAINER | BATTLE_TYPE_FACTORY;
+ if (VarGet(VAR_FRONTIER_BATTLE_MODE) == FRONTIER_MODE_DOUBLES)
+ gBattleTypeFlags |= BATTLE_TYPE_DOUBLE;
+ FillFactoryTrainerParty();
+ CreateTask(Task_StartBattleAfterTransition, 1);
+ PlayMapChosenOrBattleBGM(0);
+ BattleTransition_StartOnField(sub_80B100C(6));
+ break;
+ case SPECIAL_BATTLE_PIKE_SINGLE:
+ gBattleTypeFlags = BATTLE_TYPE_TRAINER | BATTLE_TYPE_BATTLE_TOWER;
+ FillFrontierTrainerParty(3);
+ CreateTask(Task_StartBattleAfterTransition, 1);
+ PlayMapChosenOrBattleBGM(0);
+ BattleTransition_StartOnField(sub_80B100C(7));
+ break;
+ case SPECIAL_BATTLE_PYRAMID:
+ gBattleTypeFlags = BATTLE_TYPE_TRAINER | BATTLE_TYPE_PYRAMID;
+ FillFrontierTrainerParty(3);
+ CreateTask(Task_StartBattleAfterTransition, 1);
+ PlayMapChosenOrBattleBGM(0);
+ BattleTransition_StartOnField(sub_80B100C(10));
+ break;
+ case SPECIAL_BATTLE_PIKE_DOUBLE:
+ gBattleTypeFlags = BATTLE_TYPE_TRAINER | BATTLE_TYPE_BATTLE_TOWER | BATTLE_TYPE_DOUBLE | BATTLE_TYPE_TWO_OPPONENTS;
+ FillFrontierTrainersParties(1);
+ CreateTask(Task_StartBattleAfterTransition, 1);
+ PlayMapChosenOrBattleBGM(0);
+ BattleTransition_StartOnField(sub_80B100C(7));
+ break;
+ case SPECIAL_BATTLE_STEVEN:
+ gBattleTypeFlags = BATTLE_TYPE_TRAINER | BATTLE_TYPE_DOUBLE | BATTLE_TYPE_TWO_OPPONENTS | BATTLE_TYPE_MULTI | BATTLE_TYPE_INGAME_PARTNER;
+ FillPartnerParty(TRAINER_STEVEN_PARTNER);
+ gApproachingTrainerId = 0;
+ BattleSetup_ConfigureTrainerBattle(MossdeepCity_SpaceCenter_2F_EventScript_224157 + 1);
+ gApproachingTrainerId = 1;
+ BattleSetup_ConfigureTrainerBattle(MossdeepCity_SpaceCenter_2F_EventScript_224166 + 1);
+ gPartnerTrainerId = TRAINER_STEVEN_PARTNER;
+ CreateTask(Task_StartBattleAfterTransition, 1);
+ PlayMapChosenOrBattleBGM(0);
+ BattleTransition_StartOnField(B_TRANSITION_MAGMA);
+ break;
+ }
+}
+
+static void SaveCurrentWinStreak(void)
+{
+ u8 lvlMode = gSaveBlock2Ptr->frontier.lvlMode;
+ u8 battleMode = VarGet(VAR_FRONTIER_BATTLE_MODE);
+ u16 winStreak = GetCurrentBattleTowerWinStreak(lvlMode, battleMode);
+
+ if (gSaveBlock2Ptr->frontier.winStreaks[battleMode][lvlMode] < winStreak)
+ gSaveBlock2Ptr->frontier.winStreaks[battleMode][lvlMode] = winStreak;
+}
+
+static void sub_8163EE4(void)
+{
+ s32 i;
+ u8 lvlMode, battleMode, class;
+ struct EmeraldBattleTowerRecord *playerRecord = &gSaveBlock2Ptr->frontier.towerPlayer;
+
+ ClearBattleTowerRecord(playerRecord);
+ lvlMode = gSaveBlock2Ptr->frontier.lvlMode;
+ battleMode = VarGet(VAR_FRONTIER_BATTLE_MODE);
+ if (gSaveBlock2Ptr->playerGender != MALE)
+ {
+ class = gTowerFemaleFacilityClasses[(gSaveBlock2Ptr->playerTrainerId[0] +
+ gSaveBlock2Ptr->playerTrainerId[1] +
+ gSaveBlock2Ptr->playerTrainerId[2] +
+ gSaveBlock2Ptr->playerTrainerId[3]) % ARRAY_COUNT(gTowerFemaleFacilityClasses)];
+ }
+ else
+ {
+ class = gTowerMaleFacilityClasses[(gSaveBlock2Ptr->playerTrainerId[0] +
+ gSaveBlock2Ptr->playerTrainerId[1] +
+ gSaveBlock2Ptr->playerTrainerId[2] +
+ gSaveBlock2Ptr->playerTrainerId[3]) % ARRAY_COUNT(gTowerMaleFacilityClasses)];
+ }
+ playerRecord->lvlMode = lvlMode;
+ playerRecord->facilityClass = class;
+ CopyUnalignedWord(playerRecord->trainerId, gSaveBlock2Ptr->playerTrainerId);
+ StringCopy7(playerRecord->name, gSaveBlock2Ptr->playerName);
+ playerRecord->winStreak = GetCurrentBattleTowerWinStreak(lvlMode, battleMode);
+
+ for (i = 0; i < 6; i++)
+ {
+ playerRecord->greeting[i] = gSaveBlock1Ptr->unk2BBC[i];
+ playerRecord->unk1C[i] = gSaveBlock1Ptr->unk2BC8[i];
+ playerRecord->unk28[i] = gSaveBlock1Ptr->unk2BD4[i];
+ }
+
+ for (i = 0; i < 4; i++)
+ {
+ if (gSaveBlock2Ptr->frontier.selectedPartyMons[i] != 0)
+ sub_80686FC(&gPlayerParty[gSaveBlock2Ptr->frontier.selectedPartyMons[i] - 1], &playerRecord->party[i]);
+ }
+
+ playerRecord->language = gGameLanguage;
+ CalcEmeraldBattleTowerChecksum(&gSaveBlock2Ptr->frontier.towerPlayer);
+ SaveCurrentWinStreak();
+}
+
+static void SaveBattleTowerProgress(void)
+{
+ u16 lvlMode = gSaveBlock2Ptr->frontier.lvlMode;
+ u16 battleMode = VarGet(VAR_FRONTIER_BATTLE_MODE);
+ s32 challengeNum = (signed)(gSaveBlock2Ptr->frontier.winStreaks[battleMode][lvlMode] / 7);
+
+ if (gSpecialVar_0x8005 == 0 && (challengeNum > 1 || gSaveBlock2Ptr->frontier.curChallengeBattleNum != 0))
+ sub_8163EE4();
+
+ gSaveBlock2Ptr->frontier.field_CA8 =gSpecialVar_0x8005;
+ VarSet(VAR_TEMP_0, 0);
+ gSaveBlock2Ptr->frontier.field_CA9_a = 1;
+ sub_81A4C30();
+}
+
+static void nullsub_61(void)
+{
+
+}
+
+static void nullsub_116(void)
+{
+
+}
+
+static void sub_81640E0(u16 trainerId)
+{
+ s32 i, count;
+ u32 validSpecies[3];
+ u16 species1 = GetMonData(&gPlayerParty[0], MON_DATA_SPECIES, NULL);
+ u16 species2 = GetMonData(&gPlayerParty[1], MON_DATA_SPECIES, NULL);
+
+ count = 0;
+ for (i = 0; i < 3; i++)
+ {
+ u16 apprenticeSpecies = gSaveBlock2Ptr->apprentices[trainerId - TRAINER_RECORD_MIXING_APPRENTICE].party[i].species;
+ if (apprenticeSpecies != species1 && apprenticeSpecies != species2)
+ {
+ validSpecies[count] = i;
+ count++;
+ }
+ }
+
+ gUnknown_03006298[0] = validSpecies[Random() % count];
+ do
+ {
+ gUnknown_03006298[1] = validSpecies[Random() % count];
+ } while (gUnknown_03006298[0] == gUnknown_03006298[1]);
+}
+
+static void sub_8164188(u16 trainerId)
+{
+ s32 i, count;
+ u32 validSpecies[3];
+ u32 lvlMode = gSaveBlock2Ptr->frontier.lvlMode;
+ u16 species1 = GetMonData(&gPlayerParty[0], MON_DATA_SPECIES, NULL);
+ u16 species2 = GetMonData(&gPlayerParty[1], MON_DATA_SPECIES, NULL);
+
+ count = 0;
+ for (i = 0; i < 4; i++)
+ {
+ if (gSaveBlock2Ptr->frontier.towerRecords[trainerId - TRAINER_RECORD_MIXING_FRIEND].party[i].species != species1
+ && gSaveBlock2Ptr->frontier.towerRecords[trainerId - TRAINER_RECORD_MIXING_FRIEND].party[i].species != species2
+ && gSaveBlock2Ptr->frontier.towerRecords[trainerId - TRAINER_RECORD_MIXING_FRIEND].party[i].level <= GetFrontierEnemyMonLevel(lvlMode)
+ && gSaveBlock2Ptr->frontier.towerRecords[trainerId - TRAINER_RECORD_MIXING_FRIEND].party[i].species != 0)
+ {
+ validSpecies[count] = i;
+ count++;
+ }
+ }
+
+ gUnknown_03006298[2] = validSpecies[Random() % count];
+ do
+ {
+ gUnknown_03006298[3] = validSpecies[Random() % count];
+ } while (gUnknown_03006298[2] == gUnknown_03006298[3]);
+}
+
+static void sub_81642A0(void)
+{
+ s32 i, j, k;
+ u32 spArray[5];
+ s32 r10;
+ u16 trainerId;
+ u16 monPoolId;
+ u32 lvlMode, battleMode;
+ s32 challengeNum;
+ u32 species1, species2;
+ u32 level;
+ struct EventObjectTemplate *eventObjTemplates;
+
+ eventObjTemplates = gSaveBlock1Ptr->eventObjectTemplates;
+ lvlMode = gSaveBlock2Ptr->frontier.lvlMode;
+ battleMode = VarGet(VAR_FRONTIER_BATTLE_MODE);
+ challengeNum = gSaveBlock2Ptr->frontier.winStreaks[battleMode][lvlMode] / 7;
+ species1 = GetMonData(&gPlayerParty[0], MON_DATA_SPECIES, NULL);
+ species2 = GetMonData(&gPlayerParty[1], MON_DATA_SPECIES, NULL);
+ level = SetFacilityPtrsGetLevel();
+
+ j = 0;
+ do
+ {
+ do
+ {
+ trainerId = sub_8162548(challengeNum, 0);
+ for (i = 0; i < j; i++)
+ {
+ if (gSaveBlock2Ptr->frontier.field_CB4[i] == trainerId)
+ break;
+ if (gFacilityTrainers[gSaveBlock2Ptr->frontier.field_CB4[i]].facilityClass == gFacilityTrainers[trainerId].facilityClass)
+ break;
+ }
+ } while (i != j);
+ gSaveBlock2Ptr->frontier.field_CB4[j] = trainerId;
+ j++;
+ } while (j < 6);
+
+ r10 = 8;
+ for (i = 0; i < 6; i++)
+ {
+ trainerId = gSaveBlock2Ptr->frontier.field_CB4[i];
+ eventObjTemplates[i + 1].graphicsId = GetBattleFacilityTrainerGfxId(trainerId);
+ for (j = 0; j < 2; j++)
+ {
+ while (1)
+ {
+ monPoolId = RandomizeFacilityTrainerMonId(trainerId);
+ if (j % 2 != 0 && gFacilityTrainerMons[gSaveBlock2Ptr->frontier.field_CB4[r10 - 1]].itemTableId == gFacilityTrainerMons[monPoolId].itemTableId)
+ continue;
+
+ for (k = 8; k < r10; k++)
+ {
+ if (gFacilityTrainerMons[gSaveBlock2Ptr->frontier.field_CB4[k]].species == gFacilityTrainerMons[monPoolId].species)
+ break;
+ if (species1 == gFacilityTrainerMons[monPoolId].species)
+ break;
+ if (species2 == gFacilityTrainerMons[monPoolId].species)
+ break;
+ }
+ if (k == r10)
+ break;
+ }
+
+ gSaveBlock2Ptr->frontier.field_CB4[r10] = monPoolId;
+ r10++;
+ }
+ }
+
+ r10 = 0;
+ ValidateApprenticesChecksums();
+ for (i = 0; i < 4; i++)
+ {
+ if (gSaveBlock2Ptr->apprentices[i].lvlMode != 0
+ && gUnknown_085DF9EC[gSaveBlock2Ptr->apprentices[i].field_1] / 7 <= challengeNum
+ && gSaveBlock2Ptr->apprentices[i].lvlMode - 1 == lvlMode)
+ {
+ k = 0;
+ for (j = 0; j < 3; j++)
+ {
+ if (species1 != gSaveBlock2Ptr->apprentices[i].party[j].species
+ && species2 != gSaveBlock2Ptr->apprentices[i].party[j].species)
+ {
+ k++;
+ }
+ }
+ if (k > 2)
+ {
+ spArray[r10] = i + TRAINER_RECORD_MIXING_APPRENTICE;
+ r10++;
+ }
+ }
+ }
+ if (r10 != 0)
+ {
+ gSaveBlock2Ptr->frontier.field_CB4[6] = spArray[Random() % r10];
+ eventObjTemplates[7].graphicsId = GetBattleFacilityTrainerGfxId(gSaveBlock2Ptr->frontier.field_CB4[6]);
+ FlagClear(FLAG_HIDE_BATTLE_TOWER_MULTI_BATTLE_PARTNER_ALT_1);
+ sub_81640E0(gSaveBlock2Ptr->frontier.field_CB4[6]);
+ }
+
+ r10 = 0;
+ for (i = 0; i < 5; i++)
+ {
+ u32 *record = (u32*)(&gSaveBlock2Ptr->frontier.towerRecords[i]);
+ u32 recordHasData = 0;
+ u32 checksum = 0;
+ for (j = 0; j < (sizeof(struct EmeraldBattleTowerRecord) - 4) / 4; j++) // - 4, because of the last field being the checksum itself.
+ {
+ recordHasData |= record[j];
+ checksum += record[j];
+ }
+
+ if (gSaveBlock2Ptr->frontier.towerRecords[i].winStreak / 7 <= challengeNum
+ && gSaveBlock2Ptr->frontier.towerRecords[i].lvlMode == lvlMode
+ && recordHasData
+ && gSaveBlock2Ptr->frontier.towerRecords[i].checksum == checksum)
+ {
+ k = 0;
+ for (j = 0; j < 4; j++)
+ {
+ if (species1 != gSaveBlock2Ptr->frontier.towerRecords[i].party[j].species
+ && species2 != gSaveBlock2Ptr->frontier.towerRecords[i].party[j].species
+ && gSaveBlock2Ptr->frontier.towerRecords[i].party[j].level <= GetFrontierEnemyMonLevel(lvlMode)
+ && gSaveBlock2Ptr->frontier.towerRecords[i].party[j].species != 0)
+ {
+ k++;
+ }
+ }
+ if (k > 1)
+ {
+ spArray[r10] = i + TRAINER_RECORD_MIXING_FRIEND;
+ r10++;
+ }
+ }
+ }
+ if (r10 != 0)
+ {
+ gSaveBlock2Ptr->frontier.field_CB4[7] = spArray[Random() % r10];
+ eventObjTemplates[8].graphicsId = GetBattleFacilityTrainerGfxId(gSaveBlock2Ptr->frontier.field_CB4[7]);
+ FlagClear(FLAG_HIDE_BATTLE_TOWER_MULTI_BATTLE_PARTNER_ALT_2);
+ sub_8164188(gSaveBlock2Ptr->frontier.field_CB4[7]);
+ }
+}
+
+static void sub_81646BC(u16 trainerId, u16 monPoolId)
+{
+ u16 move = 0;
+ u16 species = 0;
+ SetFacilityPtrsGetLevel();
+
+ if (trainerId != TRAINER_EREADER)
+ {
+ if (trainerId < TRAINER_RECORD_MIXING_FRIEND)
+ {
+ move = gFacilityTrainerMons[monPoolId].moves[0];
+ species = gFacilityTrainerMons[monPoolId].species;
+ }
+ else if (trainerId < TRAINER_RECORD_MIXING_APPRENTICE)
+ {
+ move = gSaveBlock2Ptr->frontier.towerRecords[trainerId - TRAINER_RECORD_MIXING_FRIEND].party[gUnknown_03006298[gSpecialVar_0x8005 + 1]].moves[0];
+ species = gSaveBlock2Ptr->frontier.towerRecords[trainerId - TRAINER_RECORD_MIXING_FRIEND].party[gUnknown_03006298[gSpecialVar_0x8005 + 1]].species;
+ }
+ else
+ {
+ s32 i;
+
+ move = gSaveBlock2Ptr->apprentices[trainerId - TRAINER_RECORD_MIXING_APPRENTICE].party[gUnknown_03006298[gSpecialVar_0x8005 - 1]].moves[0];
+ species = gSaveBlock2Ptr->apprentices[trainerId - TRAINER_RECORD_MIXING_APPRENTICE].party[gUnknown_03006298[gSpecialVar_0x8005 - 1]].species;
+ for (i = 0; i < PLAYER_NAME_LENGTH; i++)
+ gStringVar3[i] = gSaveBlock2Ptr->apprentices[trainerId - TRAINER_RECORD_MIXING_APPRENTICE].playerName[i];
+ gStringVar3[i] = EOS;
+ ConvertInternationalString(gStringVar3, gSaveBlock2Ptr->apprentices[trainerId - TRAINER_RECORD_MIXING_APPRENTICE].language);
+ }
+ }
+
+ StringCopy(gStringVar1, gMoveNames[move]);
+ StringCopy(gStringVar2, gSpeciesNames[species]);
+}
+
+static void sub_8164828(void)
+{
+ s32 i, j, arrId;
+ s32 monPoolId;
+ s32 level = SetFacilityPtrsGetLevel();
+ s32 challengeNum = sub_81A39C4() / 7;
+ s32 k = gSpecialVar_LastTalked - 2;
+ s32 trainerId = gSaveBlock2Ptr->frontier.field_CB4[k];
+
+ for (arrId = 0; arrId < ARRAY_COUNT(gUnknown_085DD500); arrId++)
+ {
+ if (gUnknown_085DD500[arrId].facilityClass == GetFrontierTrainerFacilityClass(trainerId))
+ break;
+ }
+
+ switch (gSpecialVar_0x8005)
+ {
+ case 0:
+ if (trainerId == TRAINER_EREADER)
+ return;
+ if (trainerId < TRAINER_RECORD_MIXING_FRIEND)
+ {
+ GetFrontierTrainerName(gStringVar1, trainerId);
+ }
+ else if (trainerId < TRAINER_RECORD_MIXING_APPRENTICE)
+ {
+ GetFrontierTrainerName(gStringVar1, trainerId);
+ }
+ else
+ {
+ s32 i;
+ for (i = 0; i < PLAYER_NAME_LENGTH; i++)
+ gStringVar1[i] = gSaveBlock2Ptr->apprentices[trainerId - TRAINER_RECORD_MIXING_APPRENTICE].playerName[i];
+ gStringVar1[i] = EOS;
+ ConvertInternationalString(gStringVar1, gSaveBlock2Ptr->apprentices[trainerId - TRAINER_RECORD_MIXING_APPRENTICE].language);
+ ConvertIntToDecimalStringN(gStringVar2, gSaveBlock2Ptr->apprentices[trainerId - TRAINER_RECORD_MIXING_APPRENTICE].number, STR_CONV_MODE_LEFT_ALIGN, 3);
+ GetFrontierTrainerName(gStringVar3, trainerId);
+ }
+ break;
+ case 1:
+ monPoolId = gSaveBlock2Ptr->frontier.field_CB4[8 + k * 2];
+ sub_81646BC(trainerId, monPoolId);
+ break;
+ case 2:
+ monPoolId = gSaveBlock2Ptr->frontier.field_CB4[9 + k * 2];
+ sub_81646BC(trainerId, monPoolId);
+ break;
+ case 3:
+ gPartnerTrainerId = trainerId;
+ if (trainerId < TRAINER_RECORD_MIXING_FRIEND)
+ {
+ gSaveBlock2Ptr->frontier.field_CB4[18] = gSaveBlock2Ptr->frontier.field_CB4[8 + k * 2];
+ gSaveBlock2Ptr->frontier.field_CB4[19] = gSaveBlock2Ptr->frontier.field_CB4[9 + k * 2];
+ }
+ else if (trainerId < TRAINER_RECORD_MIXING_APPRENTICE)
+ {
+ gSaveBlock2Ptr->frontier.field_CB4[18] = gUnknown_03006298[2];
+ gSaveBlock2Ptr->frontier.field_CB4[19] = gUnknown_03006298[3];
+ }
+ else
+ {
+ gSaveBlock2Ptr->frontier.field_CB4[18] = gUnknown_03006298[0];
+ gSaveBlock2Ptr->frontier.field_CB4[19] = gUnknown_03006298[1];
+ }
+ for (k = 0; k < 14; k++)
+ {
+ while (1)
+ {
+ i = sub_8162548(challengeNum, k / 2);
+ if (gPartnerTrainerId == i)
+ continue;
+
+ for (j = 0; j < k; j++)
+ {
+ if (gSaveBlock2Ptr->frontier.field_CB4[j] == i)
+ break;
+ }
+ if (j == k)
+ break;
+ }
+ gSaveBlock2Ptr->frontier.field_CB4[k] = i;
+ }
+ gSaveBlock2Ptr->frontier.field_CB4[17] = trainerId;
+ break;
+ case 4:
+ break;
+ }
+
+ if (trainerId == TRAINER_EREADER)
+ return;
+
+ if (trainerId < TRAINER_RECORD_MIXING_FRIEND)
+ {
+ ShowFieldMessage(gUnknown_085DD500[arrId].strings[gSpecialVar_0x8005]);
+ }
+ else if (trainerId < TRAINER_RECORD_MIXING_APPRENTICE)
+ {
+ ShowFieldMessage(gUnknown_085DD500[arrId].strings[gSpecialVar_0x8005]);
+ }
+ else
+ {
+ u8 id = gSaveBlock2Ptr->apprentices[trainerId - TRAINER_RECORD_MIXING_APPRENTICE].id;
+ ShowFieldMessage(gUnknown_085DD690[id][gSpecialVar_0x8005]);
+ }
+}
+
+static void sub_8164B74(void)
+{
+ s32 challengeNum;
+ s32 i, j;
+ s32 trainerId = 0;
+ u32 lvlMode = gSaveBlock2Ptr->frontier.lvlMode;
+ u32 battleMode = VarGet(VAR_FRONTIER_BATTLE_MODE);
+ u32 battleNum = gSaveBlock2Ptr->frontier.curChallengeBattleNum;
+ GetMultiplayerId(); // Yet another pointless function call.
+
+ switch (gSpecialVar_Result)
+ {
+ case 0:
+ if (battleMode == FRONTIER_MODE_LINK_MULTIS)
+ {
+ challengeNum = gSaveBlock2Ptr->frontier.winStreaks[battleMode][lvlMode] / 7;
+ if (sub_800A520())
+ {
+ SendBlock(bitmask_all_link_players_but_self(), &challengeNum, sizeof(challengeNum));
+ gSpecialVar_Result = 1;
+ }
+ }
+ else
+ {
+ gSpecialVar_Result = 6;
+ }
+ break;
+ case 1:
+ if ((GetBlockReceivedStatus() & 3) == 3)
+ {
+ ResetBlockReceivedFlags();
+ if (gBlockRecvBuffer[0][0] > gBlockRecvBuffer[1][0])
+ challengeNum = gBlockRecvBuffer[0][0];
+ else
+ challengeNum = gBlockRecvBuffer[1][0];
+ for (i = 0; i < 14; i++)
+ {
+ do
+ {
+ trainerId = sub_8162548(challengeNum, i / 2);
+ for (j = 0; j < i; j++)
+ {
+ if (gSaveBlock2Ptr->frontier.field_CB4[j] == trainerId)
+ break;
+ }
+ } while (i != j);
+ if (i == j) // This condition is always true, because of the loop above.
+ gSaveBlock2Ptr->frontier.field_CB4[i] = trainerId;
+ }
+ gSpecialVar_Result = 2;
+ }
+ break;
+ case 2:
+ if (sub_800A520())
+ {
+ SendBlock(bitmask_all_link_players_but_self(), &gSaveBlock2Ptr->frontier.field_CB4, sizeof(gSaveBlock2Ptr->frontier.field_CB4));
+ gSpecialVar_Result = 3;
+ }
+ break;
+ case 3:
+ if ((GetBlockReceivedStatus() & 3) == 3)
+ {
+ ResetBlockReceivedFlags();
+ memcpy(&gSaveBlock2Ptr->frontier.field_CB4, gBlockRecvBuffer, sizeof(gSaveBlock2Ptr->frontier.field_CB4));
+ gTrainerBattleOpponent_A = gSaveBlock2Ptr->frontier.field_CB4[battleNum * 2];
+ gTrainerBattleOpponent_B = gSaveBlock2Ptr->frontier.field_CB4[battleNum * 2 + 1];
+ SetBattleFacilityTrainerGfxId(gTrainerBattleOpponent_A, 0);
+ SetBattleFacilityTrainerGfxId(gTrainerBattleOpponent_B, 1);
+ if (gReceivedRemoteLinkPlayers != 0 && gWirelessCommType == 0)
+ gSpecialVar_Result = 4;
+ else
+ gSpecialVar_Result = 6;
+ }
+ break;
+ case 4:
+ sub_800AC34();
+ gSpecialVar_Result = 5;
+ break;
+ case 5:
+ if (gReceivedRemoteLinkPlayers == 0)
+ {
+ gSpecialVar_Result = 6;
+ }
+ break;
+ case 6:
+ return;
+ }
+}
+
+static void sub_8164DCC(void)
+{
+ if (gWirelessCommType != 0)
+ sub_800AC34();
+}
+
+static void sub_8164DE4(void)
+{
+ SetBattleFacilityTrainerGfxId(gSaveBlock2Ptr->frontier.field_CB4[17], 0xF);
+}
+
+static void sub_8164E04(void)
+{
+ s32 i;
+ u8 text[32];
+
+ if (VarGet(VAR_FRONTIER_BATTLE_MODE) != FRONTIER_MODE_SINGLES)
+ return;
+
+ GetFrontierTrainerName(text, gTrainerBattleOpponent_A);
+ StripExtCtrlCodes(text);
+ StringCopy(gSaveBlock2Ptr->frontier.field_BD8, text);
+ GetBattleTowerTrainerLanguage(&gSaveBlock2Ptr->frontier.field_BEB, gTrainerBattleOpponent_A);
+ gSaveBlock2Ptr->frontier.field_BD6 = GetMonData(&gEnemyParty[gBattlerPartyIndexes[1]], MON_DATA_SPECIES, NULL);
+ gSaveBlock2Ptr->frontier.field_BD4 = GetMonData(&gPlayerParty[gBattlerPartyIndexes[0]], MON_DATA_SPECIES, NULL);
+ for (i = 0; i < POKEMON_NAME_LENGTH + 1; i++)
+ gSaveBlock2Ptr->frontier.field_BE0[i] = gBattleMons[0].nickname[i];
+ gSaveBlock2Ptr->frontier.field_D06 = gBattleOutcome;
+}
+
+static void ValidateBattleTowerRecordChecksums(void)
+{
+ s32 i, j;
+ u32 *record = (u32*)(&gSaveBlock2Ptr->frontier.towerPlayer);
+ u32 checksum = 0;
+
+ for (j = 0; j < (sizeof(struct EmeraldBattleTowerRecord) - 4) / 4; j++) // - 4, because of the last field being the checksum itself.
+ {
+ checksum += record[j];
+ }
+ if (gSaveBlock2Ptr->frontier.towerPlayer.checksum != checksum)
+ ClearBattleTowerRecord(&gSaveBlock2Ptr->frontier.towerPlayer);
+
+ for (i = 0; i < 5; i++)
+ {
+ record = (u32*)(&gSaveBlock2Ptr->frontier.towerRecords[i]);
+ checksum = 0;
+ for (j = 0; j < (sizeof(struct EmeraldBattleTowerRecord) - 4) / 4; j++) // - 4, because of the last field being the checksum itself.
+ {
+ checksum += record[j];
+ }
+ if (gSaveBlock2Ptr->frontier.towerRecords[i].checksum != checksum)
+ ClearBattleTowerRecord(&gSaveBlock2Ptr->frontier.towerRecords[i]);
+ }
+}
+
+void CalcEmeraldBattleTowerChecksum(struct EmeraldBattleTowerRecord *record)
+{
+ u32 i;
+
+ record->checksum = 0;
+ for (i = 0; i < (sizeof(struct EmeraldBattleTowerRecord) - 4) / 4; i++) // - 4, because of the last field being the checksum itself.
+ record->checksum += ((u32 *)record)[i];
+}
+
+void CalcRubyBattleTowerChecksum(struct RSBattleTowerRecord *record)
+{
+ u32 i;
+
+ record->checksum = 0;
+ for (i = 0; i < (sizeof(struct RSBattleTowerRecord) - 4) / 4; i++) // - 4, because of the last field being the checksum itself.
+ record->checksum += ((u32 *)record)[i];
+}
+
+static void ClearBattleTowerRecord(struct EmeraldBattleTowerRecord *record)
+{
+ u32 i;
+
+ for (i = 0; i < sizeof(struct EmeraldBattleTowerRecord) / 4; i++)
+ ((u32 *)record)[i] = 0;
+}
+
+u16 GetCurrentBattleTowerWinStreak(u8 lvlMode, u8 battleMode)
+{
+ u16 winStreak = gSaveBlock2Ptr->frontier.winStreaks[battleMode][lvlMode];
+
+ if (winStreak > 9999)
+ return 9999;
+ else
+ return winStreak;
+}
+
+static u8 GetMonCountForBattleMode(u8 battleMode)
+{
+ u8 sp[ARRAY_COUNT(gUnknown_085DFA42)];
+ memcpy(sp, gUnknown_085DFA42, sizeof(gUnknown_085DFA42));
+
+ if (battleMode < ARRAY_COUNT(gUnknown_085DFA42))
+ return sp[battleMode];
+ else
+ return 3;
+}
+
+struct RibbonCounter
+{
+ u8 partyIndex;
+ u8 count;
+};
+
+static void AwardBattleTowerRibbons(void)
+{
+ s32 i;
+ u32 partyIndex;
+ struct RibbonCounter ribbons[3]; // BUG: 4 Pokemon can receive ribbons in a double battle mode.
+ u8 ribbonType = 0;
+ u8 lvlMode = gSaveBlock2Ptr->frontier.lvlMode;
+ u8 battleMode = VarGet(VAR_FRONTIER_BATTLE_MODE);
+ u8 monCount = GetMonCountForBattleMode(battleMode);
+
+ if (lvlMode != FRONTIER_LVL_50)
+ ribbonType = MON_DATA_VICTORY_RIBBON;
+ else
+ ribbonType = MON_DATA_WINNING_RIBBON;
+
+ gSpecialVar_Result = FALSE;
+
+ if (GetCurrentBattleTowerWinStreak(lvlMode, battleMode) > 55)
+ {
+ for (i = 0; i < monCount; i++)
+ {
+ partyIndex = gSaveBlock2Ptr->frontier.selectedPartyMons[i] - 1;
+ ribbons[i].partyIndex = partyIndex;
+ ribbons[i].count = 0;
+ if (!GetMonData(&gSaveBlock1Ptr->playerParty[partyIndex], ribbonType))
+ {
+ gSpecialVar_Result = TRUE;
+ SetMonData(&gSaveBlock1Ptr->playerParty[partyIndex], ribbonType, &gSpecialVar_Result);
+ ribbons[i].count = GetRibbonCount(&gSaveBlock1Ptr->playerParty[partyIndex]);
+ }
+ }
+ }
+
+ if (gSpecialVar_Result)
+ {
+ IncrementGameStat(GAME_STAT_RECEIVED_RIBBONS);
+ for (i = 1; i < monCount; i++)
+ {
+ if (ribbons[i].count > ribbons[0].count)
+ {
+ struct RibbonCounter prevBest = ribbons[0];
+ ribbons[0] = ribbons[i];
+ ribbons[i] = prevBest;
+ }
+ }
+ if (ribbons[0].count > 4)
+ {
+ sub_80EE4DC(&gSaveBlock1Ptr->playerParty[ribbons[0].partyIndex], ribbonType);
+ }
+ }
+}
+
+// This is a leftover debugging function that is used to populate the E-Reader
+// trainer with the player's current data.
+static void FillEReaderTrainerWithPlayerData(void)
+{
+ struct BattleTowerEReaderTrainer *ereaderTrainer = &gSaveBlock2Ptr->frontier.ereaderTrainer;
+ s32 i, j;
+
+ if (gSaveBlock2Ptr->playerGender != MALE)
+ {
+ ereaderTrainer->facilityClass = gTowerFemaleFacilityClasses[(gSaveBlock2Ptr->playerTrainerId[0] + gSaveBlock2Ptr->playerTrainerId[1]
+ + gSaveBlock2Ptr->playerTrainerId[2] + gSaveBlock2Ptr->playerTrainerId[3]) % ARRAY_COUNT(gTowerFemaleFacilityClasses)];
+ }
+ else
+ {
+ ereaderTrainer->facilityClass = gTowerMaleFacilityClasses[(gSaveBlock2Ptr->playerTrainerId[0] + gSaveBlock2Ptr->playerTrainerId[1]
+ + gSaveBlock2Ptr->playerTrainerId[2] + gSaveBlock2Ptr->playerTrainerId[3]) % ARRAY_COUNT(gTowerMaleFacilityClasses)];
+ }
+
+ CopyUnalignedWord(ereaderTrainer->trainerId, gSaveBlock2Ptr->playerTrainerId);
+ StringCopy7(ereaderTrainer->name, gSaveBlock2Ptr->playerName);
+
+ ereaderTrainer->winStreak = 1;
+
+ j = 7;
+ for (i = 0; i < 6; i++)
+ {
+ ereaderTrainer->greeting[i] = gSaveBlock1Ptr->unk2BBC[i];
+ ereaderTrainer->farewellPlayerLost[i] = j;
+ ereaderTrainer->farewellPlayerWon[i] = j + 6;
+ j++;
+ }
+
+ for (i = 0; i < 3; i++)
+ sub_80686FC(&gPlayerParty[i], &ereaderTrainer->party[i]);
+
+ SetEReaderTrainerChecksum(ereaderTrainer);
+}
+
+u8 GetEreaderTrainerFrontSpriteId(void)
+{
+ return gFacilityClassToPicIndex[gSaveBlock2Ptr->frontier.ereaderTrainer.facilityClass];
+}
+
+u8 GetEreaderTrainerClassId(void)
+{
+ return gFacilityClassToTrainerClass[gSaveBlock2Ptr->frontier.ereaderTrainer.facilityClass];
+}
+
+void GetEreaderTrainerName(u8 *dst)
+{
+ s32 i;
+
+ for (i = 0; i < 5; i++)
+ dst[i] = gSaveBlock2Ptr->frontier.ereaderTrainer.name[i];
+
+ dst[i] = EOS;
+}
+
+// Checks if the saved E-Reader trainer is valid.
+void ValidateEReaderTrainer(void)
+{
+ u32 i;
+ u32 checksum;
+ struct BattleTowerEReaderTrainer *ereaderTrainer;
+
+ gSpecialVar_Result = FALSE;
+ ereaderTrainer = &gSaveBlock2Ptr->frontier.ereaderTrainer;
+
+ checksum = 0;
+ for (i = 0; i < (sizeof(struct BattleTowerEReaderTrainer) - 4) / 4; i++) // - 4, because of the last field being the checksum itself.
+ checksum |= ((u32 *)ereaderTrainer)[i];
+
+ if (checksum == 0)
+ {
+ gSpecialVar_Result = TRUE;
+ return;
+ }
+
+ checksum = 0;
+ for (i = 0; i < (sizeof(struct BattleTowerEReaderTrainer) - 4) / 4; i++) // - 4, because of the last field being the checksum itself.
+ checksum += ((u32 *)ereaderTrainer)[i];
+
+ if (gSaveBlock2Ptr->frontier.ereaderTrainer.checksum != checksum)
+ {
+ ClearEReaderTrainer(&gSaveBlock2Ptr->frontier.ereaderTrainer);
+ gSpecialVar_Result = TRUE;
+ }
+}
+
+static void SetEReaderTrainerChecksum(struct BattleTowerEReaderTrainer *ereaderTrainer)
+{
+ s32 i;
+
+ ereaderTrainer->checksum = 0;
+ for (i = 0; i < (sizeof(struct BattleTowerEReaderTrainer) - 4) / 4; i++) // - 4, because of the last field being the checksum itself.
+ ereaderTrainer->checksum += ((u32 *)ereaderTrainer)[i];
+}
+
+void ClearEReaderTrainer(struct BattleTowerEReaderTrainer *ereaderTrainer)
+{
+ u32 i;
+
+ for (i = 0; i < (sizeof(struct BattleTowerEReaderTrainer)) / 4; i++)
+ ((u32 *)ereaderTrainer)[i] = 0;
+}
+
+void CopyEReaderTrainerGreeting(void)
+{
+ FrontierSpeechToString(gSaveBlock2Ptr->frontier.ereaderTrainer.greeting);
+}
+
+static void CopyEReaderTrainerFarewellMessage(void)
+{
+ if (gBattleOutcome == B_OUTCOME_DREW)
+ gStringVar4[0] = EOS;
+ else if (gBattleOutcome == B_OUTCOME_WON)
+ FrontierSpeechToString(gSaveBlock2Ptr->frontier.ereaderTrainer.farewellPlayerWon);
+ else
+ FrontierSpeechToString(gSaveBlock2Ptr->frontier.ereaderTrainer.farewellPlayerLost);
+}
+
+void sub_81653CC(void)
+{
+ if (gSaveBlock2Ptr->frontier.field_CA8 == 1)
+ sub_80F01B8();
+ if (FlagGet(FLAG_0x077) == TRUE)
+ {
+ sub_80F01B8();
+ FlagClear(FLAG_0x077);
+ }
+}
+
+#define STEVEN_OTID 61226
+
+static void FillPartnerParty(u16 trainerId)
+{
+ s32 i, j;
+ u32 ivs, level;
+ u32 friendship;
+ u16 monPoolId;
+ u32 otID;
+ u8 trainerName[PLAYER_NAME_LENGTH + 1];
+ SetFacilityPtrsGetLevel();
+
+ if (trainerId == TRAINER_STEVEN_PARTNER)
+ {
+ for (i = 0; i < 3; i++)
+ {
+ do
+ {
+ j = Random32();
+ } while (IsShinyOtIdPersonality(STEVEN_OTID, j) || sStevenMons[i].nature != GetNatureFromPersonality(j));
+ CreateMon(&gPlayerParty[3 + i],
+ sStevenMons[i].species,
+ sStevenMons[i].level,
+ sStevenMons[i].fixedIV,
+ TRUE, i, // BUG: personality was stored in the 'j' variable. As a result, Steven's pokemon do not have the intended natures.
+ TRUE, STEVEN_OTID);
+ for (j = 0; j < 6; j++)
+ SetMonData(&gPlayerParty[3 + i], MON_DATA_HP_EV + j, &sStevenMons[i].evs[j]);
+ for (j = 0; j < 4; j++)
+ SetMonMoveSlot(&gPlayerParty[3 + i], sStevenMons[i].moves[j], j);
+ SetMonData(&gPlayerParty[3 + i], MON_DATA_OT_NAME, gTrainers[TRAINER_STEVEN].trainerName);
+ j = MALE;
+ SetMonData(&gPlayerParty[3 + i], MON_DATA_OT_GENDER, &j);
+ CalculateMonStats(&gPlayerParty[3 + i]);
+ }
+ }
+ else if (trainerId == TRAINER_EREADER)
+ {
+ // Scrapped, lol.
+ trainerName[0] = gGameLanguage;
+ }
+ else if (trainerId < TRAINER_RECORD_MIXING_FRIEND)
+ {
+ level = SetFacilityPtrsGetLevel();
+ ivs = GetFrontierTrainerFixedIvs(trainerId);
+ otID = Random32();
+ for (i = 0; i < 2; i++)
+ {
+ monPoolId = gSaveBlock2Ptr->frontier.field_CB4[i + 18];
+ CreateMonWithEVSpreadPersonalityOTID(&gPlayerParty[3 + i],
+ gFacilityTrainerMons[monPoolId].species,
+ level,
+ gFacilityTrainerMons[monPoolId].nature,
+ ivs,
+ gFacilityTrainerMons[monPoolId].evSpread,
+ otID);
+ friendship = 0xFF;
+ for (j = 0; j < 4; j++)
+ {
+ SetMonMoveSlot(&gPlayerParty[3 + i], gFacilityTrainerMons[monPoolId].moves[j], j);
+ if (gFacilityTrainerMons[monPoolId].moves[j] == MOVE_FRUSTRATION)
+ friendship = 0;
+ }
+ SetMonData(&gPlayerParty[3 + i], MON_DATA_FRIENDSHIP, &friendship);
+ SetMonData(&gPlayerParty[3 + i], MON_DATA_HELD_ITEM, &gBattleFrontierHeldItems[gFacilityTrainerMons[monPoolId].itemTableId]);
+ for (j = 0; j < PLAYER_NAME_LENGTH + 1; j++)
+ trainerName[j] = gFacilityTrainers[trainerId].trainerName[j];
+ SetMonData(&gPlayerParty[3 + i], MON_DATA_OT_NAME, &trainerName);
+ j = IsFrontierTrainerFemale(trainerId);
+ SetMonData(&gPlayerParty[3 + i], MON_DATA_OT_GENDER, &j);
+ }
+ }
+ else if (trainerId < TRAINER_RECORD_MIXING_APPRENTICE)
+ {
+ trainerId -= TRAINER_RECORD_MIXING_FRIEND;
+ for (i = 0; i < 2; i++)
+ {
+ struct EmeraldBattleTowerRecord *record = &gSaveBlock2Ptr->frontier.towerRecords[trainerId];
+ struct UnknownPokemonStruct monData = record->party[gSaveBlock2Ptr->frontier.field_CB4[18 + i]];
+ StringCopy(trainerName, record->name);
+ if (record->language == LANGUAGE_JAPANESE)
+ {
+ if (monData.nickname[0] != EXT_CTRL_CODE_BEGIN || monData.nickname[1] != EXT_CTRL_CODE_JPN)
+ {
+ monData.nickname[5] = EOS;
+ ConvertInternationalString(monData.nickname, LANGUAGE_JAPANESE);
+ }
+ }
+ else
+ {
+ if (monData.nickname[0] == EXT_CTRL_CODE_BEGIN && monData.nickname[1] == EXT_CTRL_CODE_JPN)
+ trainerName[5] = EOS;
+ }
+ sub_8068338(&gPlayerParty[3 + i], &monData, TRUE);
+ SetMonData(&gPlayerParty[3 + i], MON_DATA_OT_NAME, trainerName);
+ j = IsFrontierTrainerFemale(trainerId + TRAINER_RECORD_MIXING_FRIEND);
+ SetMonData(&gPlayerParty[3 + i], MON_DATA_OT_GENDER, &j);
+ }
+ }
+ else
+ {
+ trainerId -= TRAINER_RECORD_MIXING_APPRENTICE;
+ for (i = 0; i < 2; i++)
+ {
+ CreateApprenticeMon(&gPlayerParty[3 + i], &gSaveBlock2Ptr->apprentices[trainerId], gSaveBlock2Ptr->frontier.field_CB4[18 + i]);
+ j = IsFrontierTrainerFemale(trainerId + TRAINER_RECORD_MIXING_APPRENTICE);
+ SetMonData(&gPlayerParty[3 + i], MON_DATA_OT_GENDER, &j);
+ }
+ }
+}
+
+bool32 RubyBattleTowerRecordToEmerald(struct RSBattleTowerRecord *src, struct EmeraldBattleTowerRecord *dst)
+{
+ s32 i, validMons = 0;
+
+ for (i = 0; i < 3; i++)
+ {
+ if (src->party[i].species)
+ validMons++;
+ }
+
+ if (validMons != 3)
+ {
+ memset(dst, 0, sizeof(*dst));
+ return FALSE;
+ }
+ else
+ {
+ dst->lvlMode = src->lvlMode;
+ dst->winStreak = src->winStreak;
+ for (i = 0; i < (signed) ARRAY_COUNT(sRubyFacilityClassToEmerald); i++)
+ {
+ if (sRubyFacilityClassToEmerald[i][0] == src->facilityClass)
+ break;
+ }
+ if (i != ARRAY_COUNT(sRubyFacilityClassToEmerald))
+ dst->facilityClass = sRubyFacilityClassToEmerald[i][1];
+ else
+ dst->facilityClass = FACILITY_CLASS_YOUNGSTER;
+
+ for (i = 0; i < PLAYER_NAME_LENGTH + 1; i++)
+ dst->name[i] = src->name[i];
+ for (i = 0; i < 4; i++)
+ dst->trainerId[i] = src->trainerId[i];
+ for (i = 0; i < 6; i++)
+ dst->greeting[i] = src->greeting[i];
+ for (i = 0; i < 6; i++)
+ dst->unk1C[i] = gUnknown_085DFA46[i];
+ for (i = 0; i < 6; i++)
+ dst->unk28[i] = gUnknown_085DFA52[i];
+ for (i = 0; i < 3; i++)
+ dst->party[i] = src->party[i];
+
+ CpuFill32(0, &dst->party[3], sizeof(dst->party[3]));
+ CalcEmeraldBattleTowerChecksum(dst);
+ return TRUE;
+ }
+}
+
+bool32 EmeraldBattleTowerRecordToRuby(struct EmeraldBattleTowerRecord *src, struct RSBattleTowerRecord *dst)
+{
+ s32 i, validMons = 0;
+
+ for (i = 0; i < 3; i++)
+ {
+ if (src->party[i].species)
+ validMons++;
+ }
+
+ if (validMons != 3)
+ {
+ memset(dst, 0, sizeof(*dst));
+ return FALSE;
+ }
+ else
+ {
+ dst->lvlMode = src->lvlMode;
+ dst->winStreak = src->winStreak;
+ for (i = 0; i < (signed) ARRAY_COUNT(sRubyFacilityClassToEmerald); i++)
+ {
+ if (sRubyFacilityClassToEmerald[i][1] == src->facilityClass)
+ break;
+ }
+ if (i != ARRAY_COUNT(sRubyFacilityClassToEmerald))
+ dst->facilityClass = sRubyFacilityClassToEmerald[i][0];
+ else
+ dst->facilityClass = 0x24; // FACILITY_CLASS_YOUNGSTER in Ruby/Sapphire.
+
+ for (i = 0; i < PLAYER_NAME_LENGTH + 1; i++)
+ dst->name[i] = src->name[i];
+ for (i = 0; i < 4; i++)
+ dst->trainerId[i] = src->trainerId[i];
+ for (i = 0; i < 6; i++)
+ dst->greeting[i] = src->greeting[i];
+ for (i = 0; i < 3; i++)
+ dst->party[i] = src->party[i];
+
+ CalcRubyBattleTowerChecksum(dst);
+ return TRUE;
+ }
+}
+
+void CalcApprenticeChecksum(struct Apprentice *apprentice)
+{
+ s32 i;
+
+ apprentice->checksum = 0;
+ for (i = 0; i < (sizeof(struct Apprentice) - 4) / 4; i++)
+ apprentice->checksum += ((u32 *)apprentice)[i];
+}
+
+static void ClearApprentice(struct Apprentice *apprentice)
+{
+ s32 i;
+
+ for (i = 0; i < (sizeof(struct Apprentice)) / 4; i++)
+ ((u32 *)apprentice)[i] = 0;
+ ResetApprenticeStruct(apprentice);
+}
+
+static void ValidateApprenticesChecksums(void)
+{
+ s32 i, j;
+
+ for (i = 0; i < 4; i++)
+ {
+ u32 *data = (u32*) &gSaveBlock2Ptr->apprentices[i];
+ u32 checksum = 0;
+ for (j = 0; j < (sizeof(struct Apprentice) - 4) / 4; j++)
+ checksum += data[j];
+ if (gSaveBlock2Ptr->apprentices[i].checksum != checksum)
+ ClearApprentice(&gSaveBlock2Ptr->apprentices[i]);
+ }
+}
+
+void GetBattleTowerTrainerLanguage(u8 *dst, u16 trainerId)
+{
+ if (trainerId == TRAINER_EREADER)
+ {
+ *dst = gGameLanguage;
+ }
+ else if (trainerId < TRAINER_RECORD_MIXING_FRIEND)
+ {
+ *dst = gGameLanguage;
+ }
+ else if (trainerId < TRAINER_RECORD_MIXING_APPRENTICE)
+ {
+ if (gBattleTypeFlags & BATTLE_TYPE_RECORDED)
+ *dst = sub_81864B4();
+ else
+ *dst = gSaveBlock2Ptr->frontier.towerRecords[trainerId - TRAINER_RECORD_MIXING_FRIEND].language;
+ }
+ else
+ {
+ if (gBattleTypeFlags & BATTLE_TYPE_RECORDED)
+ *dst = sub_81864C0();
+ else
+ *dst = gSaveBlock2Ptr->apprentices[trainerId - TRAINER_RECORD_MIXING_APPRENTICE].language;
+ }
+}
+
+u8 SetFacilityPtrsGetLevel(void)
+{
+ if (gSaveBlock2Ptr->frontier.lvlMode == FRONTIER_LVL_TENT)
+ {
+ return SetTentPtrsGetLevel();
+ }
+ else
+ {
+ gFacilityTrainers = gBattleFrontierTrainers;
+ gFacilityTrainerMons = gBattleFrontierMons;
+ return GetFrontierEnemyMonLevel(gSaveBlock2Ptr->frontier.lvlMode);
+ }
+}
+
+u8 GetFrontierEnemyMonLevel(u8 lvlMode)
+{
+ u8 level;
+
+ switch (lvlMode)
+ {
+ default:
+ case FRONTIER_LVL_50:
+ level = 50;
+ break;
+ case FRONTIER_LVL_OPEN:
+ level = GetHighestLevelInPlayerParty();
+ if (level < 60)
+ level = 60;
+ break;
+ }
+
+ return level;
+}
+
+s32 GetHighestLevelInPlayerParty(void)
+{
+ s32 highestLevel = 0;
+ s32 i;
+
+ for (i = 0; i < PARTY_SIZE; i++)
+ {
+ if (GetMonData(&gPlayerParty[i], MON_DATA_SPECIES, NULL)
+ && GetMonData(&gPlayerParty[i], MON_DATA_SPECIES2, NULL) != SPECIES_EGG)
+ {
+ s32 level = GetMonData(&gPlayerParty[i], MON_DATA_LEVEL, NULL);
+ if (level > highestLevel)
+ highestLevel = level;
+ }
+ }
+
+ return highestLevel;
+}
+
+static u8 GetFrontierTrainerFixedIvs(u16 trainerId)
+{
+ u8 fixedIV = 0;
+
+ if (trainerId < 100)
+ fixedIV = 3;
+ else if (trainerId < 120)
+ fixedIV = 6;
+ else if (trainerId < 140)
+ fixedIV = 9;
+ else if (trainerId < 160)
+ fixedIV = 12;
+ else if (trainerId < 180)
+ fixedIV = 15;
+ else if (trainerId < 200)
+ fixedIV = 18;
+ else if (trainerId < 220)
+ fixedIV = 21;
+ else
+ fixedIV = 31;
+
+ return fixedIV;
+}
+
+static u16 sub_8165D40(void)
+{
+ u32 facility = VarGet(VAR_FRONTIER_FACILITY);
+
+ if (facility == FRONTIER_FACILITY_PALACE)
+ return Random() % 30;
+ else if (facility == FRONTIER_FACILITY_ARENA)
+ return Random() % 30;
+ else if (facility == FRONTIER_FACILITY_FACTORY)
+ return Random() % 30;
+ else if (facility == FRONTIER_FACILITY_TOWER)
+ return 0;
+ else
+ return 0;
+}
+
+static u8 SetTentPtrsGetLevel(void)
+{
+ u8 level = 30;
+ u32 tentFacility = VarGet(VAR_FRONTIER_FACILITY);
+
+ if (tentFacility == TENT_SLATEPORT)
+ {
+ gFacilityTrainers = gSlateportBattleTentTrainers;
+ gFacilityTrainerMons = gSlateportBattleTentMons;
+ }
+ else if (tentFacility == TENT_VERDANTURF)
+ {
+ gFacilityTrainers = gVerdanturfBattleTentTrainers;
+ gFacilityTrainerMons = gVerdanturfBattleTentMons;
+ }
+ else if (tentFacility == TENT_FALLARBOR)
+ {
+ gFacilityTrainers = gFallarborBattleTentTrainers;
+ gFacilityTrainerMons = gFallarborBattleTentMons;
+ }
+ else
+ {
+ gFacilityTrainers = gBattleFrontierTrainers;
+ gFacilityTrainerMons = gBattleFrontierMons;
+ }
+
+ level = GetHighestLevelInPlayerParty();
+ if (level < 30)
+ level = 30;
+
+ return level;
+}
+
+static void sub_8165E18(void)
+{
+ s32 i;
+ u16 trainerId;
+
+ do
+ {
+ trainerId = sub_8165D40();
+ for (i = 0; i < gSaveBlock2Ptr->frontier.curChallengeBattleNum; i++)
+ {
+ if (gSaveBlock2Ptr->frontier.field_CB4[i] == trainerId)
+ break;
+ }
+ } while (i != gSaveBlock2Ptr->frontier.curChallengeBattleNum);
+
+ gTrainerBattleOpponent_A = trainerId;
+ SetBattleFacilityTrainerGfxId(gTrainerBattleOpponent_A, 0);
+ if (gSaveBlock2Ptr->frontier.curChallengeBattleNum + 1 < 3)
+ gSaveBlock2Ptr->frontier.field_CB4[gSaveBlock2Ptr->frontier.curChallengeBattleNum] = gTrainerBattleOpponent_A;
+}
+
+static void FillTentTrainerParty_(u16 trainerId, u8 firstMonId, u8 monCount)
+{
+ s32 i, j;
+ u16 chosenMonIndices[4];
+ u8 friendship;
+ u8 level = SetTentPtrsGetLevel();
+ u8 fixedIV = 0;
+ u8 bfMonCount;
+ const u16 *bfMonPool = NULL;
+ u32 otID = 0;
+ u16 monPoolId;
+
+ bfMonPool = gFacilityTrainers[gTrainerBattleOpponent_A].bfMonPool;
+
+ bfMonCount = 0;
+ monPoolId = bfMonPool[bfMonCount];
+ while (monPoolId != 0xFFFF)
+ {
+ bfMonCount++;
+ monPoolId = bfMonPool[bfMonCount];
+ if (monPoolId == 0xFFFF)
+ break;
+ }
+
+ i = 0;
+ otID = Random32();
+ while (i != monCount)
+ {
+ u16 monPoolId = bfMonPool[Random() % bfMonCount];
+
+ // Ensure this pokemon species isn't a duplicate.
+ for (j = 0; j < i + firstMonId; j++)
+ {
+ if (GetMonData(&gEnemyParty[j], MON_DATA_SPECIES, NULL) == gFacilityTrainerMons[monPoolId].species)
+ break;
+ }
+ if (j != i + firstMonId)
+ continue;
+
+ // Ensure this Pokemon's held item isn't a duplicate.
+ for (j = 0; j < i + firstMonId; j++)
+ {
+ if (GetMonData(&gEnemyParty[j], MON_DATA_HELD_ITEM, NULL) != 0
+ && GetMonData(&gEnemyParty[j], MON_DATA_HELD_ITEM, NULL) == gBattleFrontierHeldItems[gFacilityTrainerMons[monPoolId].itemTableId])
+ break;
+ }
+ if (j != i + firstMonId)
+ continue;
+
+ // Ensure this exact pokemon index isn't a duplicate. This check doesn't seem necessary
+ // because the species and held items were already checked directly above.
+ for (j = 0; j < i; j++)
+ {
+ if (chosenMonIndices[j] == monPoolId)
+ break;
+ }
+ if (j != i)
+ continue;
+
+ chosenMonIndices[i] = monPoolId;
+
+ // Place the chosen pokemon into the trainer's party.
+ CreateMonWithEVSpreadPersonalityOTID(&gEnemyParty[i + firstMonId],
+ gFacilityTrainerMons[monPoolId].species,
+ level,
+ gFacilityTrainerMons[monPoolId].nature,
+ fixedIV,
+ gFacilityTrainerMons[monPoolId].evSpread,
+ otID);
+
+ friendship = 255;
+ // Give the chosen pokemon its specified moves.
+ for (j = 0; j < 4; j++)
+ {
+ SetMonMoveSlot(&gEnemyParty[i + firstMonId], gFacilityTrainerMons[monPoolId].moves[j], j);
+ if (gFacilityTrainerMons[monPoolId].moves[j] == MOVE_FRUSTRATION)
+ friendship = 0; // Frustration is more powerful the lower the pokemon's friendship is.
+ }
+
+ SetMonData(&gEnemyParty[i + firstMonId], MON_DATA_FRIENDSHIP, &friendship);
+ SetMonData(&gEnemyParty[i + firstMonId], MON_DATA_HELD_ITEM, &gBattleFrontierHeldItems[gFacilityTrainerMons[monPoolId].itemTableId]);
+
+ // The pokemon was successfully added to the trainer's party, so it's safe to move on to
+ // the next party slot.
+ i++;
+ }
+}
+
+u8 sub_81660B8(u8 facilityClass)
+{
+ u8 trainerObjectGfxId;
+ u8 i;
+
+ // Search male classes.
+ for (i = 0; i < ARRAY_COUNT(gTowerMaleFacilityClasses); i++)
+ {
+ if (gTowerMaleFacilityClasses[i] == facilityClass)
+ break;
+ }
+ if (i != ARRAY_COUNT(gTowerMaleFacilityClasses))
+ {
+ trainerObjectGfxId = gTowerMaleTrainerGfxIds[i];
+ return trainerObjectGfxId;
+ }
+
+ // Search female classes.
+ for (i = 0; i < ARRAY_COUNT(gTowerFemaleFacilityClasses); i++)
+ {
+ if (gTowerFemaleFacilityClasses[i] == facilityClass)
+ break;
+ }
+ if (i != ARRAY_COUNT(gTowerFemaleFacilityClasses))
+ {
+ trainerObjectGfxId = gTowerFemaleTrainerGfxIds[i];
+ return trainerObjectGfxId;
+ }
+ else
+ {
+ return EVENT_OBJ_GFX_BOY_1;
+ }
+}
+
+bool32 ValidateBattleTowerRecord(u8 recordId) // unused
+{
+ s32 i;
+ u32 *record = (u32*)(&gSaveBlock2Ptr->frontier.towerRecords[recordId]);
+ u32 checksum = 0;
+ u32 hasData = 0;
+ for (i = 0; i < (sizeof(struct EmeraldBattleTowerRecord) - 4) / 4; i++) // - 4, because of the last fjeld bejng the checksum jtself.
+ {
+ checksum += record[i];
+ hasData |= record[i];
+ }
+
+ if (checksum == 0 && hasData == 0)
+ {
+ return FALSE;
+ }
+ else if (gSaveBlock2Ptr->frontier.towerRecords[recordId].checksum != checksum)
+ {
+ ClearBattleTowerRecord(&gSaveBlock2Ptr->frontier.towerRecords[recordId]);
+ return FALSE;
+ }
+ else
+ {
+ return TRUE;
+ }
+}
+
+void sub_8166188(void)
+{
+ if (gBattleTypeFlags & (BATTLE_TYPE_LINK | BATTLE_TYPE_x2000000))
+ {
+ s32 i;
+ u8 enemyLevel = SetFacilityPtrsGetLevel();
+
+ for (i = 0; i < PARTY_SIZE; i++)
+ {
+ u32 species = GetMonData(&gEnemyParty[i], MON_DATA_SPECIES, NULL);
+ if (species)
+ {
+ SetMonData(&gEnemyParty[i], MON_DATA_EXP, &gExperienceTables[gBaseStats[species].growthRate][enemyLevel]);
+ CalculateMonStats(&gEnemyParty[i]);
+ }
+ }
+ }
+}
diff --git a/src/berry_blender.c b/src/berry_blender.c
index 8e0bc8043..643bd2e30 100644
--- a/src/berry_blender.c
+++ b/src/berry_blender.c
@@ -323,7 +323,7 @@ static const struct BgTemplate sBerryBlenderBgTemplates[3] =
static const struct WindowTemplate sBerryBlender_WindowTemplates[] =
{
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 1,
.tilemapTop = 6,
.width = 7,
@@ -332,7 +332,7 @@ static const struct WindowTemplate sBerryBlender_WindowTemplates[] =
.baseBlock = 0x28,
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 22,
.tilemapTop = 6,
.width = 7,
@@ -341,7 +341,7 @@ static const struct WindowTemplate sBerryBlender_WindowTemplates[] =
.baseBlock = 0x36,
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 1,
.tilemapTop = 12,
.width = 7,
@@ -350,7 +350,7 @@ static const struct WindowTemplate sBerryBlender_WindowTemplates[] =
.baseBlock = 0x44,
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 22,
.tilemapTop = 12,
.width = 7,
@@ -359,7 +359,7 @@ static const struct WindowTemplate sBerryBlender_WindowTemplates[] =
.baseBlock = 0x52,
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 2,
.tilemapTop = 15,
.width = 27,
@@ -368,7 +368,7 @@ static const struct WindowTemplate sBerryBlender_WindowTemplates[] =
.baseBlock = 0x60,
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 5,
.tilemapTop = 3,
.width = 21,
@@ -381,7 +381,7 @@ static const struct WindowTemplate sBerryBlender_WindowTemplates[] =
static const struct WindowTemplate sBlender_YesNoWindowTemplate =
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 21,
.tilemapTop = 9,
.width = 5,
@@ -846,7 +846,7 @@ static const u8 sUnknown_08339CD2[] =
static const struct WindowTemplate sBlenderRecordWindowTemplate =
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 6,
.tilemapTop = 4,
.width = 18,
diff --git a/src/berry_tag_screen.c b/src/berry_tag_screen.c
index 07fb6bd9e..39927ab99 100644
--- a/src/berry_tag_screen.c
+++ b/src/berry_tag_screen.c
@@ -102,7 +102,7 @@ static const u8 sTextColors[2][3] =
static const struct WindowTemplate sWindowTemplates[] =
{
{ // WIN_BERRY_NAME
- .priority = 1,
+ .bg = 1,
.tilemapLeft = 11,
.tilemapTop = 4,
.width = 8,
@@ -111,7 +111,7 @@ static const struct WindowTemplate sWindowTemplates[] =
.baseBlock = 69,
},
{ // WIN_SIZE_FIRM
- .priority = 1,
+ .bg = 1,
.tilemapLeft = 11,
.tilemapTop = 7,
.width = 18,
@@ -120,7 +120,7 @@ static const struct WindowTemplate sWindowTemplates[] =
.baseBlock = 85,
},
{ // WIN_DESC
- .priority = 1,
+ .bg = 1,
.tilemapLeft = 4,
.tilemapTop = 14,
.width = 25,
@@ -129,7 +129,7 @@ static const struct WindowTemplate sWindowTemplates[] =
.baseBlock = 157,
},
{ // WIN_BERRY_TAG
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 2,
.tilemapTop = 0,
.width = 8,
diff --git a/src/cable_club.c b/src/cable_club.c
index c54df5f24..b0e5f0500 100644
--- a/src/cable_club.c
+++ b/src/cable_club.c
@@ -34,7 +34,7 @@ extern u8 gUnknown_02032298[2];
extern u8 gUnknown_0203CEF8[];
static const struct WindowTemplate gUnknown_08550594 = {
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 16,
.tilemapTop = 11,
.width = 11,
@@ -421,7 +421,7 @@ bool32 sub_80B2AF4(u16 *arg0, u16 *arg1)
gStringVar1[0] = EOS;
gStringVar2[0] = EOS;
-
+
for (i = 0; i < 2; i++)
{
for (j = 0; j < 2; j++)
@@ -1151,7 +1151,7 @@ static void sub_80B3950(void)
void nullsub_37(void)
{
-
+
}
void sub_80B3968(void)
diff --git a/src/clear_save_data_screen.c b/src/clear_save_data_screen.c
index 839a77e4a..51f3bd291 100644
--- a/src/clear_save_data_screen.c
+++ b/src/clear_save_data_screen.c
@@ -11,8 +11,8 @@
#include "text_window.h"
#include "constants/songs.h"
-extern u8 gText_ClearAllSaveData[];
-extern u8 gText_ClearingData[];
+extern const u8 gText_ClearAllSaveData[];
+extern const u8 gText_ClearingData[];
static void Task_DoClearSaveDataScreenYesNo(u8);
static void Task_ClearSaveDataScreenYesNoChoice(u8);
@@ -46,7 +46,7 @@ static const struct BgTemplate sClearSaveBgTemplates[2] =
static const struct WindowTemplate sClearSaveTextWindow[] =
{
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 3,
.tilemapTop = 15,
.width = 26,
@@ -60,7 +60,7 @@ static const struct WindowTemplate sClearSaveTextWindow[] =
static const struct WindowTemplate sClearSaveYesNo[] =
{
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 3,
.tilemapTop = 2,
.width = 5,
diff --git a/src/credits.c b/src/credits.c
index 608c17cc6..df17ec70b 100644
--- a/src/credits.c
+++ b/src/credits.c
@@ -949,7 +949,7 @@ static const struct BgTemplate gUnknown_085E6F68[] =
static const struct WindowTemplate gUnknown_085E6F6C[] =
{
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 0,
.tilemapTop = 9,
.width = 30,
@@ -1142,7 +1142,7 @@ static void sub_81754DC(void)
{
RunTasks();
AnimateSprites();
-
+
if ((gMain.heldKeys & B_BUTTON)
&& gHasHallOfFameRecords != 0
&& gTasks[gUnknown_0203BCE2].func == sub_8175774)
@@ -1182,9 +1182,9 @@ static void sub_81755BC(const u8 *string, u8 y, u8 a2)
{
u8 x;
u8 color[3];
-
+
color[0] = 0;
-
+
if (a2 == 1)
{
color[1] = 3;
@@ -1195,7 +1195,7 @@ static void sub_81755BC(const u8 *string, u8 y, u8 a2)
color[1] = 1;
color[2] = 2;
}
-
+
x = GetStringCenterAlignXOffsetWithLetterSpacing(1, string, 0xF0, 1);
AddTextPrinterParameterized4(0, 1, x, y, 1, 0, color, -1, string);
}
@@ -1230,7 +1230,7 @@ void sub_8175620(void)
gTasks[taskIdC].data[TDC_0] = 40;
SetGpuReg(REG_OFFSET_BG0VOFS, 0xFFFC);
-
+
taskIdB = CreateTask(sub_8175DA0, 0);
gTasks[taskIdB].data[TDB_TASK_A_ID] = taskIdA;
@@ -1546,9 +1546,9 @@ static void sub_8175DA0(u8 taskIdB)
{
for (i = 0; i < 5; i++)
sub_81755BC(gCreditsEntryPointerTable[gTasks[taskIdB].data[TDB_CURRENT_PAGE]][i]->text, 5 + i * 16, gCreditsEntryPointerTable[gTasks[taskIdB].data[TDB_CURRENT_PAGE]][i]->var_1);
-
+
CopyWindowToVram(0, 2);
-
+
gTasks[taskIdB].data[TDB_CURRENT_PAGE] += 1;
gTasks[taskIdB].data[TDB_0] += 1;
diff --git a/src/daycare.c b/src/daycare.c
index c80a8b743..db46b3a4f 100644
--- a/src/daycare.c
+++ b/src/daycare.c
@@ -63,7 +63,7 @@ EWRAM_DATA static u16 sHatchedEggMotherMoves[4] = {0};
static const struct WindowTemplate sDaycareLevelMenuWindowTemplate =
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 15,
.tilemapTop = 1,
.width = 14,
diff --git a/src/decoration.c b/src/decoration.c
index 0cafad800..8bbe11039 100644
--- a/src/decoration.c
+++ b/src/decoration.c
@@ -217,7 +217,7 @@ void (*const SecretBasePC_SelectedDecorActions[][2])(u8 taskId) = {
const struct WindowTemplate gUnknown_085A6B90[4] =
{
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 1,
.tilemapTop = 1,
.width = 18,
@@ -226,7 +226,7 @@ const struct WindowTemplate gUnknown_085A6B90[4] =
.baseBlock = 0x0001
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 1,
.tilemapTop = 1,
.width = 13,
@@ -235,7 +235,7 @@ const struct WindowTemplate gUnknown_085A6B90[4] =
.baseBlock = 0x0091
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 17,
.tilemapTop = 1,
.width = 12,
@@ -244,7 +244,7 @@ const struct WindowTemplate gUnknown_085A6B90[4] =
.baseBlock = 0x017b
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 16,
.tilemapTop = 13,
.width = 13,
diff --git a/src/diploma.c b/src/diploma.c
index a1d37a70d..e2f2c6d07 100644
--- a/src/diploma.c
+++ b/src/diploma.c
@@ -11,19 +11,14 @@
#include "window.h"
#include "string_util.h"
#include "text.h"
+#include "overworld.h"
+#include "menu.h"
-extern void reset_temp_tile_data_buffers(void);
-extern int decompress_and_copy_tile_data_to_vram(u8 bg_id, void *src, int size, u16 offset, u8 mode);
-extern bool8 free_temp_tile_data_buffers_if_possible(void);
-extern void sub_80861E8(void); // rom4
extern bool16 sub_80C0944(void);
-extern void AddTextPrinterParameterized4(u8 windowId, u8 fontId, u8 x, u8 y, u8 letterSpacing, u8 lineSpacing, u8 *color, s8 speed, u8 *str);
-extern u16 gUnknown_0860F074[];
-
-extern u8 gText_DexNational[];
-extern u8 gText_DexHoenn[];
-extern u8 gText_PokedexDiploma[];
+extern const u8 gText_DexNational[];
+extern const u8 gText_DexHoenn[];
+extern const u8 gText_PokedexDiploma[];
static void MainCB2(void);
static void Task_DiplomaFadeIn(u8);
@@ -34,7 +29,7 @@ static void InitDiplomaBg(void);
static void InitDiplomaWindow(void);
static void PrintDiplomaText(u8 *, u8, u8);
-EWRAM_DATA static void **sDiplomaTilemapPtr = {NULL};
+EWRAM_DATA static u8 *sDiplomaTilemapPtr = NULL;
static void VBlankCB(void)
{
@@ -186,7 +181,7 @@ static void InitDiplomaBg(void)
static const struct WindowTemplate sDiplomaWinTemplates[2] =
{
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 5,
.tilemapTop = 2,
.width = 20,
diff --git a/src/egg_hatch.c b/src/egg_hatch.c
index 9f2526295..eeae72f36 100644
--- a/src/egg_hatch.c
+++ b/src/egg_hatch.c
@@ -26,6 +26,11 @@
#include "constants/abilities.h"
#include "daycare.h"
#include "overworld.h"
+#include "scanline_effect.h"
+#include "field_weather.h"
+#include "international_string_util.h"
+#include "naming_screen.h"
+#include "field_screen.h"
#include "battle.h" // to get rid of later
struct EggHatchData
@@ -55,14 +60,7 @@ extern const u32 gUnknown_08331F60[]; // tilemap gameboy circle
extern const u8 gText_HatchedFromEgg[];
extern const u8 gText_NickHatchPrompt[];
-extern u8 sav1_map_get_name(void);
-extern void TVShowConvertInternationalString(u8* str1, u8* str2, u8);
-extern void FadeScreen(u8, u8);
-extern void overworld_free_bg_tilemaps(void);
-extern void sub_80AF168(void);
-extern void ScanlineEffect_Stop(void);
extern void play_some_sound(void);
-extern void DoNamingScreen(u8, const u8*, u16, u8, u32, MainCallback);
extern u16 sub_80D22D0(void);
extern u8 CountPartyAliveNonEggMonsExcept(u8);
@@ -254,7 +252,7 @@ static const struct BgTemplate sBgTemplates_EggHatch[2] =
static const struct WindowTemplate sWinTemplates_EggHatch[2] =
{
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 2,
.tilemapTop = 15,
.width = 26,
@@ -267,7 +265,7 @@ static const struct WindowTemplate sWinTemplates_EggHatch[2] =
static const struct WindowTemplate sYesNoWinTemplate =
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 21,
.tilemapTop = 9,
.width = 5,
diff --git a/src/field_region_map.c b/src/field_region_map.c
index 7e8794cab..c15959afc 100644
--- a/src/field_region_map.c
+++ b/src/field_region_map.c
@@ -58,7 +58,7 @@ static const struct BgTemplate gUnknown_085E5068[] = {
static const struct WindowTemplate gUnknown_085E5070[] =
{
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 17,
.tilemapTop = 17,
.width = 12,
@@ -67,7 +67,7 @@ static const struct WindowTemplate gUnknown_085E5070[] =
.baseBlock = 1
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 22,
.tilemapTop = 1,
.width = 7,
diff --git a/src/field_specials.c b/src/field_specials.c
index a74bf40f6..e2e069d28 100644
--- a/src/field_specials.c
+++ b/src/field_specials.c
@@ -1680,7 +1680,7 @@ void sub_8139980(void)
}
const struct WindowTemplate gUnknown_085B2BAC = {
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 21,
.tilemapTop = 1,
.width = 8,
@@ -2158,13 +2158,13 @@ void sub_8139F20(void)
case 1:
case 2:
case 3:
- if (gSaveBlock2Ptr->frontier.field_CE0[var][0] >= gSaveBlock2Ptr->frontier.field_CE0[var][1])
+ if (gSaveBlock2Ptr->frontier.winStreaks[var][0] >= gSaveBlock2Ptr->frontier.winStreaks[var][1])
{
- unk = gSaveBlock2Ptr->frontier.field_CE0[var][0];
+ unk = gSaveBlock2Ptr->frontier.winStreaks[var][0];
}
else
{
- unk = gSaveBlock2Ptr->frontier.field_CE0[var][1];
+ unk = gSaveBlock2Ptr->frontier.winStreaks[var][1];
}
break;
case 4:
@@ -2244,7 +2244,7 @@ void sub_813A080(void)
u16 battleMode = VarGet(VAR_FRONTIER_BATTLE_MODE);
u8 lvlMode = gSaveBlock2Ptr->frontier.lvlMode;
- if (battleMode == 2 && !FlagGet(FLAG_0x152))
+ if (battleMode == FRONTIER_MODE_MULTIS && !FlagGet(FLAG_0x152))
{
gSpecialVar_0x8005 = 5;
gSpecialVar_0x8006 = 4;
@@ -2253,7 +2253,7 @@ void sub_813A080(void)
for (i = 0; i < 9; i++)
{
- if (gUnknown_085B2CDC[i] > gSaveBlock2Ptr->frontier.field_CE0[battleMode][lvlMode])
+ if (gUnknown_085B2CDC[i] > gSaveBlock2Ptr->frontier.winStreaks[battleMode][lvlMode])
{
gSpecialVar_0x8005 = 4;
gSpecialVar_0x8006 = i + 5;
@@ -2733,8 +2733,6 @@ static void sub_813A46C(s32 itemIndex, bool8 onInit, struct ListMenu *list)
}
}
-// stupid r5<->r6 swap
-#ifdef NONMATCHING
static void sub_813A4EC(u8 taskId)
{
struct Task *task = &gTasks[taskId];
@@ -2752,7 +2750,11 @@ static void sub_813A4EC(u8 taskId)
default:
gSpecialVar_Result = itemId;
PlaySE(SE_SELECT);
- if (!task->data[6] || itemId == task->data[1] - 1)
+ if (!task->data[6])
+ {
+ sub_813A570(taskId);
+ }
+ else if (itemId == task->data[1] - 1)
{
sub_813A570(taskId);
}
@@ -2765,72 +2767,6 @@ static void sub_813A4EC(u8 taskId)
break;
}
}
-#else
-NAKED
-static void sub_813A4EC(u8 taskId)
-{
- asm_unified("push {r4-r6,lr}\n\
- lsls r0, 24\n\
- lsrs r5, r0, 24\n\
- lsls r0, r5, 2\n\
- adds r0, r5\n\
- lsls r0, 3\n\
- ldr r1, =gTasks\n\
- adds r6, r0, r1\n\
- ldrh r0, [r6, 0x24]\n\
- lsls r0, 24\n\
- lsrs r0, 24\n\
- bl ListMenuHandleInputGetItemId\n\
- adds r4, r0, 0\n\
- movs r0, 0x2\n\
- negs r0, r0\n\
- cmp r4, r0\n\
- beq _0813A51C\n\
- adds r0, 0x1\n\
- cmp r4, r0\n\
- bne _0813A530\n\
- b _0813A566\n\
- .pool\n\
-_0813A51C:\n\
- ldr r1, =gSpecialVar_Result\n\
- movs r0, 0x7F\n\
- strh r0, [r1]\n\
- movs r0, 0x5\n\
- bl PlaySE\n\
- b _0813A54C\n\
- .pool\n\
-_0813A530:\n\
- ldr r0, =gSpecialVar_Result\n\
- strh r4, [r0]\n\
- movs r0, 0x5\n\
- bl PlaySE\n\
- movs r1, 0x14\n\
- ldrsh r0, [r6, r1]\n\
- cmp r0, 0\n\
- beq _0813A54C\n\
- movs r1, 0xA\n\
- ldrsh r0, [r6, r1]\n\
- subs r0, 0x1\n\
- cmp r4, r0\n\
- bne _0813A558\n\
-_0813A54C:\n\
- adds r0, r5, 0\n\
- bl sub_813A570\n\
- b _0813A566\n\
- .pool\n\
-_0813A558:\n\
- adds r0, r5, 0\n\
- bl sub_813A738\n\
- ldr r0, =sub_813A600\n\
- str r0, [r6]\n\
- bl EnableBothScriptContexts\n\
-_0813A566:\n\
- pop {r4-r6}\n\
- pop {r0}\n\
- bx r0\n\
- .pool");
-}
-#endif // NONMATCHING
static void sub_813A570(u8 taskId)
{
@@ -3069,7 +3005,7 @@ void sub_813A8FC(void)
void sub_813A958(void)
{
static const struct WindowTemplate gUnknown_085B311C = {
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 1,
.tilemapTop = 1,
.width = 6,
@@ -3122,7 +3058,7 @@ u16 sub_813AA04(void)
void sub_813AA18(void)
{
static const struct WindowTemplate gUnknown_085B3124 = {
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 2,
.tilemapTop = 9,
.width = 4,
@@ -3284,7 +3220,7 @@ void sub_813AC7C(void)
static void sub_813ACE8(u8 a0, u16 a1)
{
static const struct WindowTemplate gUnknown_085B3220 = {
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 1,
.tilemapTop = 7,
.width = 12,
diff --git a/src/item_menu.c b/src/item_menu.c
index bb619cac8..7dbdf716f 100755
--- a/src/item_menu.c
+++ b/src/item_menu.c
@@ -268,7 +268,7 @@ const u8 gUnknown_08614164[][3] = {
const struct WindowTemplate gUnknown_08614174[] =
{
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 14,
.tilemapTop = 2,
.width = 15,
@@ -277,7 +277,7 @@ const struct WindowTemplate gUnknown_08614174[] =
.baseBlock = 0x27,
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 0,
.tilemapTop = 13,
.width = 14,
@@ -286,7 +286,7 @@ const struct WindowTemplate gUnknown_08614174[] =
.baseBlock = 0x117,
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 4,
.tilemapTop = 1,
.width = 8,
@@ -295,7 +295,7 @@ const struct WindowTemplate gUnknown_08614174[] =
.baseBlock = 0x1A1,
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 1,
.tilemapTop = 13,
.width = 5,
@@ -304,7 +304,7 @@ const struct WindowTemplate gUnknown_08614174[] =
.baseBlock = 0x16B,
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 7,
.tilemapTop = 13,
.width = 4,
@@ -313,7 +313,7 @@ const struct WindowTemplate gUnknown_08614174[] =
.baseBlock = 0x189,
},
{
- .priority = 1,
+ .bg = 1,
.tilemapLeft = 2,
.tilemapTop = 15,
.width = 27,
@@ -327,7 +327,7 @@ const struct WindowTemplate gUnknown_08614174[] =
const struct WindowTemplate gUnknown_086141AC[] =
{
{
- .priority = 1,
+ .bg = 1,
.tilemapLeft = 22,
.tilemapTop = 17,
.width = 7,
@@ -336,7 +336,7 @@ const struct WindowTemplate gUnknown_086141AC[] =
.baseBlock = 0x21D,
},
{
- .priority = 1,
+ .bg = 1,
.tilemapLeft = 22,
.tilemapTop = 15,
.width = 7,
@@ -345,7 +345,7 @@ const struct WindowTemplate gUnknown_086141AC[] =
.baseBlock = 0x21D,
},
{
- .priority = 1,
+ .bg = 1,
.tilemapLeft = 15,
.tilemapTop = 15,
.width = 14,
@@ -354,7 +354,7 @@ const struct WindowTemplate gUnknown_086141AC[] =
.baseBlock = 0x21D,
},
{
- .priority = 1,
+ .bg = 1,
.tilemapLeft = 15,
.tilemapTop = 13,
.width = 14,
@@ -363,7 +363,7 @@ const struct WindowTemplate gUnknown_086141AC[] =
.baseBlock = 0x21D,
},
{
- .priority = 1,
+ .bg = 1,
.tilemapLeft = 2,
.tilemapTop = 15,
.width = 27,
@@ -372,7 +372,7 @@ const struct WindowTemplate gUnknown_086141AC[] =
.baseBlock = 0x1B1,
},
{
- .priority = 1,
+ .bg = 1,
.tilemapLeft = 24,
.tilemapTop = 15,
.width = 5,
@@ -381,7 +381,7 @@ const struct WindowTemplate gUnknown_086141AC[] =
.baseBlock = 0x21D,
},
{
- .priority = 1,
+ .bg = 1,
.tilemapLeft = 21,
.tilemapTop = 9,
.width = 5,
@@ -390,7 +390,7 @@ const struct WindowTemplate gUnknown_086141AC[] =
.baseBlock = 0x21D,
},
{
- .priority = 1,
+ .bg = 1,
.tilemapLeft = 24,
.tilemapTop = 17,
.width = 5,
@@ -399,7 +399,7 @@ const struct WindowTemplate gUnknown_086141AC[] =
.baseBlock = 0x21D,
},
{
- .priority = 1,
+ .bg = 1,
.tilemapLeft = 18,
.tilemapTop = 11,
.width = 10,
@@ -408,7 +408,7 @@ const struct WindowTemplate gUnknown_086141AC[] =
.baseBlock = 0x245,
},
{
- .priority = 1,
+ .bg = 1,
.tilemapLeft = 1,
.tilemapTop = 1,
.width = 10,
diff --git a/src/mail.c b/src/mail.c
index 3c12bed3f..513900746 100644
--- a/src/mail.c
+++ b/src/mail.c
@@ -146,7 +146,7 @@ static const struct BgTemplate sUnknown_0859F290[] = {
static const struct WindowTemplate sUnknown_0859F29C[] = {
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 2,
.tilemapTop = 3,
.width = 26,
diff --git a/src/main_menu.c b/src/main_menu.c
index 521b92b35..8539ab027 100644
--- a/src/main_menu.c
+++ b/src/main_menu.c
@@ -165,7 +165,7 @@ static const struct WindowTemplate sWindowTemplates_MainMenu[] =
// No saved game
// NEW GAME
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = MENU_LEFT,
.tilemapTop = MENU_TOP_WIN0,
.width = MENU_WIDTH,
@@ -175,7 +175,7 @@ static const struct WindowTemplate sWindowTemplates_MainMenu[] =
},
// OPTIONS
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = MENU_LEFT,
.tilemapTop = MENU_TOP_WIN1,
.width = MENU_WIDTH,
@@ -186,7 +186,7 @@ static const struct WindowTemplate sWindowTemplates_MainMenu[] =
// Has saved game
// CONTINUE
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = MENU_LEFT,
.tilemapTop = MENU_TOP_WIN2,
.width = MENU_WIDTH,
@@ -196,7 +196,7 @@ static const struct WindowTemplate sWindowTemplates_MainMenu[] =
},
// NEW GAME
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = MENU_LEFT,
.tilemapTop = MENU_TOP_WIN3,
.width = MENU_WIDTH,
@@ -206,7 +206,7 @@ static const struct WindowTemplate sWindowTemplates_MainMenu[] =
},
// OPTION / MYSTERY GIFT
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = MENU_LEFT,
.tilemapTop = MENU_TOP_WIN4,
.width = MENU_WIDTH,
@@ -216,7 +216,7 @@ static const struct WindowTemplate sWindowTemplates_MainMenu[] =
},
// OPTION / MYSTERY EVENTS
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = MENU_LEFT,
.tilemapTop = MENU_TOP_WIN5,
.width = MENU_WIDTH,
@@ -226,7 +226,7 @@ static const struct WindowTemplate sWindowTemplates_MainMenu[] =
},
// OPTION
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = MENU_LEFT,
.tilemapTop = MENU_TOP_WIN6,
.width = MENU_WIDTH,
@@ -236,7 +236,7 @@ static const struct WindowTemplate sWindowTemplates_MainMenu[] =
},
// Error message window
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = MENU_LEFT_ERROR,
.tilemapTop = MENU_TOP_ERROR,
.width = MENU_WIDTH_ERROR,
@@ -250,7 +250,7 @@ static const struct WindowTemplate sWindowTemplates_MainMenu[] =
static const struct WindowTemplate gUnknown_082FF080[] =
{
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 2,
.tilemapTop = 15,
.width = 27,
@@ -259,7 +259,7 @@ static const struct WindowTemplate gUnknown_082FF080[] =
.baseBlock = 1
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 3,
.tilemapTop = 5,
.width = 6,
@@ -268,7 +268,7 @@ static const struct WindowTemplate gUnknown_082FF080[] =
.baseBlock = 0x6D
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 3,
.tilemapTop = 2,
.width = 9,
@@ -323,7 +323,7 @@ static const union AffineAnimCmd sSpriteAffineAnim_PlayerShrink[] = {
AFFINEANIMCMD_END
};
-static const union AffineAnimCmd *const sSpriteAffineAnimTable_PlayerShrink[] =
+static const union AffineAnimCmd *const sSpriteAffineAnimTable_PlayerShrink[] =
{
sSpriteAffineAnim_PlayerShrink
};
@@ -2083,21 +2083,21 @@ static void DrawMainMenuWindowBorder(const struct WindowTemplate *template, u16
u16 sp14 = 7 + baseTileNum;
u16 r6 = 8 + baseTileNum;
- FillBgTilemapBufferRect(template->priority, baseTileNum, template->tilemapLeft - 1, template->tilemapTop - 1, 1, 1, 2);
- FillBgTilemapBufferRect(template->priority, r9, template->tilemapLeft, template->tilemapTop - 1, template->width, 1, 2);
- FillBgTilemapBufferRect(template->priority, r10, template->tilemapLeft + template->width, template->tilemapTop - 1, 1, 1, 2);
- FillBgTilemapBufferRect(template->priority, sp18, template->tilemapLeft - 1, template->tilemapTop, 1, template->height, 2);
- FillBgTilemapBufferRect(template->priority, spC, template->tilemapLeft + template->width, template->tilemapTop, 1, template->height, 2);
- FillBgTilemapBufferRect(template->priority, sp10, template->tilemapLeft - 1, template->tilemapTop + template->height, 1, 1, 2);
- FillBgTilemapBufferRect(template->priority, sp14, template->tilemapLeft, template->tilemapTop + template->height, template->width, 1, 2);
- FillBgTilemapBufferRect(template->priority, r6, template->tilemapLeft + template->width, template->tilemapTop + template->height, 1, 1, 2);
- CopyBgTilemapBufferToVram(template->priority);
+ FillBgTilemapBufferRect(template->bg, baseTileNum, template->tilemapLeft - 1, template->tilemapTop - 1, 1, 1, 2);
+ FillBgTilemapBufferRect(template->bg, r9, template->tilemapLeft, template->tilemapTop - 1, template->width, 1, 2);
+ FillBgTilemapBufferRect(template->bg, r10, template->tilemapLeft + template->width, template->tilemapTop - 1, 1, 1, 2);
+ FillBgTilemapBufferRect(template->bg, sp18, template->tilemapLeft - 1, template->tilemapTop, 1, template->height, 2);
+ FillBgTilemapBufferRect(template->bg, spC, template->tilemapLeft + template->width, template->tilemapTop, 1, template->height, 2);
+ FillBgTilemapBufferRect(template->bg, sp10, template->tilemapLeft - 1, template->tilemapTop + template->height, 1, 1, 2);
+ FillBgTilemapBufferRect(template->bg, sp14, template->tilemapLeft, template->tilemapTop + template->height, template->width, 1, 2);
+ FillBgTilemapBufferRect(template->bg, r6, template->tilemapLeft + template->width, template->tilemapTop + template->height, 1, 1, 2);
+ CopyBgTilemapBufferToVram(template->bg);
}
static void ClearMainMenuWindowTilemap(const struct WindowTemplate *template)
{
- FillBgTilemapBufferRect(template->priority, 0, template->tilemapLeft - 1, template->tilemapTop - 1, template->tilemapLeft + template->width + 1, template->tilemapTop + template->height + 1, 2);
- CopyBgTilemapBufferToVram(template->priority);
+ FillBgTilemapBufferRect(template->bg, 0, template->tilemapLeft - 1, template->tilemapTop - 1, template->tilemapLeft + template->width + 1, template->tilemapTop + template->height + 1, 2);
+ CopyBgTilemapBufferToVram(template->bg);
}
static void NewGameBirchSpeech_ClearGenderWindowTilemap(u8 a, u8 b, u8 c, u8 d, u8 e, u8 unused)
diff --git a/src/map_name_popup.c b/src/map_name_popup.c
index 3feffd70d..172fcc723 100644
--- a/src/map_name_popup.c
+++ b/src/map_name_popup.c
@@ -314,7 +314,7 @@ static void ShowMapNamePopUpWindow(void)
else
{
withoutPrefixPtr = &(mapDisplayHeader[3]);
- mapDisplayHeaderSource = gBattlePyramid_MapHeaderStrings[gSaveBlock2Ptr->frontier.field_CB2];
+ mapDisplayHeaderSource = gBattlePyramid_MapHeaderStrings[gSaveBlock2Ptr->frontier.curChallengeBattleNum];
}
StringCopy(withoutPrefixPtr, mapDisplayHeaderSource);
}
@@ -541,7 +541,7 @@ static void LoadMapNamePopUpWindowBg(void)
}
popUpThemeId = gRegionMapSectionId_To_PopUpThemeIdMapping[regionMapSectionId];
- LoadBgTiles(GetWindowAttribute(popupWindowId, WINDOW_PRIORITY), &(gMapPopUp_Outline_Table[popUpThemeId][0]), 0x400, 0x21D);
+ LoadBgTiles(GetWindowAttribute(popupWindowId, WINDOW_BG), &(gMapPopUp_Outline_Table[popUpThemeId][0]), 0x400, 0x21D);
CallWindowFunction(popupWindowId, sub_80D4A78);
PutWindowTilemap(popupWindowId);
if(gMapHeader.weather == WEATHER_BUBBLES)
diff --git a/src/menu.c b/src/menu.c
index 0e5d1b856..e5dce2ee0 100644
--- a/src/menu.c
+++ b/src/menu.c
@@ -66,7 +66,7 @@ static const u8 gUnknown_0860F094[] = { 8, 4, 1 };
static const struct WindowTemplate gUnknown_0860F098[] =
{
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 2,
.tilemapTop = 15,
.width = 27,
@@ -79,7 +79,7 @@ static const struct WindowTemplate gUnknown_0860F098[] =
static const struct WindowTemplate gUnknown_0860F0A8 =
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 21,
.tilemapTop = 9,
.width = 5,
@@ -782,9 +782,9 @@ u8 sub_81980F0(u8 bg, u8 xPos, u8 yPos, u8 palette, u16 baseTile)
memset(&window, 0, sizeof(window));
if (bg > 3)
- window.priority = 0;
+ window.bg = 0;
else
- window.priority = bg;
+ window.bg = bg;
window.tilemapTop = yPos;
window.height = 2;
@@ -1147,7 +1147,7 @@ void sub_81989B8(u8 windowId, u8 fontId, u8 lineHeight, u8 itemCount, const stru
void SetWindowTemplateFields(struct WindowTemplate *template, u8 bg, u8 left, u8 top, u8 width, u8 height, u8 paletteNum, u16 baseBlock)
{
- template->priority = bg;
+ template->bg = bg;
template->tilemapLeft = left;
template->tilemapTop = top;
template->width = width;
diff --git a/src/mystery_event_menu.c b/src/mystery_event_menu.c
index 7e09a4d70..0de4675d9 100644
--- a/src/mystery_event_menu.c
+++ b/src/mystery_event_menu.c
@@ -43,7 +43,7 @@ static const struct BgTemplate sBgTemplates[] =
static const struct WindowTemplate sWindowTemplates[] =
{
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 4,
.tilemapTop = 15,
.width = 22,
@@ -52,7 +52,7 @@ static const struct WindowTemplate sWindowTemplates[] =
.baseBlock = 20
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 7,
.tilemapTop = 6,
.width = 16,
diff --git a/src/naming_screen.c b/src/naming_screen.c
index ee1e78c60..a67516602 100644
--- a/src/naming_screen.c
+++ b/src/naming_screen.c
@@ -103,7 +103,7 @@ static const struct BgTemplate gUnknown_0858BE00[] =
static const struct WindowTemplate gUnknown_0858BE10[] =
{
{
- .priority = 1,
+ .bg = 1,
.tilemapLeft = 3,
.tilemapTop = 10,
.width = 19,
@@ -112,7 +112,7 @@ static const struct WindowTemplate gUnknown_0858BE10[] =
.baseBlock = 0x030
},
{
- .priority = 2,
+ .bg = 2,
.tilemapLeft = 3,
.tilemapTop = 10,
.width = 19,
@@ -121,7 +121,7 @@ static const struct WindowTemplate gUnknown_0858BE10[] =
.baseBlock = 0x0C8
},
{
- .priority = 3,
+ .bg = 3,
.tilemapLeft = 8,
.tilemapTop = 6,
.width = 17,
@@ -130,7 +130,7 @@ static const struct WindowTemplate gUnknown_0858BE10[] =
.baseBlock = 0x030
},
{
- .priority = 3,
+ .bg = 3,
.tilemapLeft = 8,
.tilemapTop = 4,
.width = 17,
@@ -139,7 +139,7 @@ static const struct WindowTemplate gUnknown_0858BE10[] =
.baseBlock = 0x052
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 0,
.tilemapTop = 0,
.width = 30,
diff --git a/src/option_menu.c b/src/option_menu.c
index 6cb208c63..122ba8d8a 100644
--- a/src/option_menu.c
+++ b/src/option_menu.c
@@ -92,7 +92,7 @@ static const u8 *const sOptionMenuItemsNames[MENUITEM_COUNT] =
static const struct WindowTemplate sOptionMenuWinTemplates[] =
{
{
- .priority = 1,
+ .bg = 1,
.tilemapLeft = 2,
.tilemapTop = 1,
.width = 26,
@@ -101,7 +101,7 @@ static const struct WindowTemplate sOptionMenuWinTemplates[] =
.baseBlock = 2
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 2,
.tilemapTop = 5,
.width = 26,
diff --git a/src/player_pc.c b/src/player_pc.c
index bdbef1b43..7a8b4192b 100644
--- a/src/player_pc.c
+++ b/src/player_pc.c
@@ -185,7 +185,7 @@ const struct MenuAction gMailboxMailOptions[] =
static const struct WindowTemplate gUnknown_085DFF24[3] =
{
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 1,
.tilemapTop = 1,
.width = 9,
@@ -194,7 +194,7 @@ static const struct WindowTemplate gUnknown_085DFF24[3] =
.baseBlock = 1
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 1,
.tilemapTop = 1,
.width = 9,
@@ -203,7 +203,7 @@ static const struct WindowTemplate gUnknown_085DFF24[3] =
.baseBlock = 1
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 1,
.tilemapTop = 1,
.width = 10,
@@ -243,7 +243,7 @@ static const struct ListMenuTemplate gUnknown_085DFF44 =
static const struct WindowTemplate gUnknown_085DFF5C[5] =
{
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 16,
.tilemapTop = 1,
.width = 13,
@@ -252,7 +252,7 @@ static const struct WindowTemplate gUnknown_085DFF5C[5] =
.baseBlock = 0x0001
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 1,
.tilemapTop = 13,
.width = 13,
@@ -261,7 +261,7 @@ static const struct WindowTemplate gUnknown_085DFF5C[5] =
.baseBlock = 0x00EB
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 1,
.tilemapTop = 8,
.width = 3,
@@ -270,7 +270,7 @@ static const struct WindowTemplate gUnknown_085DFF5C[5] =
.baseBlock = 0x0153
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 1,
.tilemapTop = 1,
.width = 13,
@@ -279,7 +279,7 @@ static const struct WindowTemplate gUnknown_085DFF5C[5] =
.baseBlock = 0x0139
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 8,
.tilemapTop = 9,
.width = 6,
@@ -291,7 +291,7 @@ static const struct WindowTemplate gUnknown_085DFF5C[5] =
static const struct WindowTemplate gUnknown_085DFF84 =
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 9,
.tilemapTop = 7,
.width = 5,
diff --git a/src/pokeblock.c b/src/pokeblock.c
index d0a867b3a..1382ff6a7 100644
--- a/src/pokeblock.c
+++ b/src/pokeblock.c
@@ -295,7 +295,7 @@ static const struct Pokeblock sFavoritePokeblocksTable[] =
static const struct WindowTemplate sWindowTemplatesForPokeblockMenu[] =
{
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 2,
.tilemapTop = 1,
.width = 9,
@@ -304,7 +304,7 @@ static const struct WindowTemplate sWindowTemplatesForPokeblockMenu[] =
.baseBlock = 0x1E
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 15,
.tilemapTop = 1,
.width = 14,
@@ -313,7 +313,7 @@ static const struct WindowTemplate sWindowTemplatesForPokeblockMenu[] =
.baseBlock = 0x30
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 2,
.tilemapTop = 13,
.width = 5,
@@ -322,7 +322,7 @@ static const struct WindowTemplate sWindowTemplatesForPokeblockMenu[] =
.baseBlock = 0x12C
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 2,
.tilemapTop = 15,
.width = 5,
@@ -331,7 +331,7 @@ static const struct WindowTemplate sWindowTemplatesForPokeblockMenu[] =
.baseBlock = 0x136
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 2,
.tilemapTop = 17,
.width = 5,
@@ -340,7 +340,7 @@ static const struct WindowTemplate sWindowTemplatesForPokeblockMenu[] =
.baseBlock = 0x140
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 8,
.tilemapTop = 13,
.width = 5,
@@ -349,7 +349,7 @@ static const struct WindowTemplate sWindowTemplatesForPokeblockMenu[] =
.baseBlock = 0x14A
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 8,
.tilemapTop = 15,
.width = 5,
@@ -358,7 +358,7 @@ static const struct WindowTemplate sWindowTemplatesForPokeblockMenu[] =
.baseBlock = 0x154
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 11,
.tilemapTop = 17,
.width = 2,
@@ -367,7 +367,7 @@ static const struct WindowTemplate sWindowTemplatesForPokeblockMenu[] =
.baseBlock = 0x15E
},
{
- .priority = 1,
+ .bg = 1,
.tilemapLeft = 7,
.tilemapTop = 5,
.width = 6,
@@ -376,7 +376,7 @@ static const struct WindowTemplate sWindowTemplatesForPokeblockMenu[] =
.baseBlock = 0x162
},
{
- .priority = 1,
+ .bg = 1,
.tilemapLeft = 7,
.tilemapTop = 7,
.width = 6,
@@ -385,7 +385,7 @@ static const struct WindowTemplate sWindowTemplatesForPokeblockMenu[] =
.baseBlock = 0x186
},
{
- .priority = 1,
+ .bg = 1,
.tilemapLeft = 2,
.tilemapTop = 15,
.width = 27,
@@ -398,7 +398,7 @@ static const struct WindowTemplate sWindowTemplatesForPokeblockMenu[] =
static const struct WindowTemplate sTossPkblockWindowTemplate =
{
- .priority = 1,
+ .bg = 1,
.tilemapLeft = 21,
.tilemapTop = 9,
.width = 5,
diff --git a/src/pokemon.c b/src/pokemon.c
index a7a91a630..b858ee925 100644
--- a/src/pokemon.c
+++ b/src/pokemon.c
@@ -2879,10 +2879,10 @@ void CreateApprenticeMon(struct Pokemon *mon, const struct Apprentice *src, u8 m
u8 language;
u32 otId = gApprentices[src->id].otId;
u32 personality = ((gApprentices[src->id].otId >> 8) | ((gApprentices[src->id].otId & 0xFF) << 8))
- + src->monData[monId].species + src->number;
+ + src->party[monId].species + src->number;
CreateMon(mon,
- src->monData[monId].species,
+ src->party[monId].species,
GetFrontierEnemyMonLevel(src->lvlMode - 1),
0x1F,
TRUE,
@@ -2890,9 +2890,9 @@ void CreateApprenticeMon(struct Pokemon *mon, const struct Apprentice *src, u8 m
TRUE,
otId);
- SetMonData(mon, MON_DATA_HELD_ITEM, &src->monData[monId].item);
+ SetMonData(mon, MON_DATA_HELD_ITEM, &src->party[monId].item);
for (i = 0; i < 4; i++)
- SetMonMoveSlot(mon, src->monData[monId].moves[i], i);
+ SetMonMoveSlot(mon, src->party[monId].moves[i], i);
evAmount = MAX_TOTAL_EVS / NUM_STATS;
for (i = 0; i < NUM_STATS; i++)
diff --git a/src/pokemon_summary_screen.c b/src/pokemon_summary_screen.c
index db2a07909..e1c2c79eb 100644
--- a/src/pokemon_summary_screen.c
+++ b/src/pokemon_summary_screen.c
@@ -314,7 +314,7 @@ static const s8 gUnknown_0861CC1C[] = {0, 2, 3, 1, 4, 5};
static const struct WindowTemplate gUnknown_0861CC24[] =
{
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 0,
.tilemapTop = 0,
.width = 11,
@@ -323,7 +323,7 @@ static const struct WindowTemplate gUnknown_0861CC24[] =
.baseBlock = 1,
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 0,
.tilemapTop = 0,
.width = 11,
@@ -332,7 +332,7 @@ static const struct WindowTemplate gUnknown_0861CC24[] =
.baseBlock = 23,
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 0,
.tilemapTop = 0,
.width = 11,
@@ -341,7 +341,7 @@ static const struct WindowTemplate gUnknown_0861CC24[] =
.baseBlock = 45,
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 0,
.tilemapTop = 0,
.width = 11,
@@ -350,7 +350,7 @@ static const struct WindowTemplate gUnknown_0861CC24[] =
.baseBlock = 67,
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 22,
.tilemapTop = 0,
.width = 8,
@@ -359,7 +359,7 @@ static const struct WindowTemplate gUnknown_0861CC24[] =
.baseBlock = 89,
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 22,
.tilemapTop = 0,
.width = 8,
@@ -368,7 +368,7 @@ static const struct WindowTemplate gUnknown_0861CC24[] =
.baseBlock = 105,
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 22,
.tilemapTop = 0,
.width = 8,
@@ -377,7 +377,7 @@ static const struct WindowTemplate gUnknown_0861CC24[] =
.baseBlock = 121,
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 11,
.tilemapTop = 4,
.width = 0,
@@ -386,7 +386,7 @@ static const struct WindowTemplate gUnknown_0861CC24[] =
.baseBlock = 137,
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 11,
.tilemapTop = 4,
.width = 18,
@@ -395,7 +395,7 @@ static const struct WindowTemplate gUnknown_0861CC24[] =
.baseBlock = 137,
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 11,
.tilemapTop = 6,
.width = 18,
@@ -404,7 +404,7 @@ static const struct WindowTemplate gUnknown_0861CC24[] =
.baseBlock = 173,
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 10,
.tilemapTop = 7,
.width = 6,
@@ -413,7 +413,7 @@ static const struct WindowTemplate gUnknown_0861CC24[] =
.baseBlock = 209,
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 22,
.tilemapTop = 7,
.width = 5,
@@ -422,7 +422,7 @@ static const struct WindowTemplate gUnknown_0861CC24[] =
.baseBlock = 245,
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 10,
.tilemapTop = 14,
.width = 11,
@@ -431,7 +431,7 @@ static const struct WindowTemplate gUnknown_0861CC24[] =
.baseBlock = 275,
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 0,
.tilemapTop = 18,
.width = 6,
@@ -440,7 +440,7 @@ static const struct WindowTemplate gUnknown_0861CC24[] =
.baseBlock = 319,
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 1,
.tilemapTop = 15,
.width = 9,
@@ -449,7 +449,7 @@ static const struct WindowTemplate gUnknown_0861CC24[] =
.baseBlock = 331,
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 1,
.tilemapTop = 15,
.width = 5,
@@ -458,7 +458,7 @@ static const struct WindowTemplate gUnknown_0861CC24[] =
.baseBlock = 367,
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 22,
.tilemapTop = 4,
.width = 0,
@@ -467,7 +467,7 @@ static const struct WindowTemplate gUnknown_0861CC24[] =
.baseBlock = 387,
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 1,
.tilemapTop = 2,
.width = 4,
@@ -476,7 +476,7 @@ static const struct WindowTemplate gUnknown_0861CC24[] =
.baseBlock = 387,
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 1,
.tilemapTop = 12,
.width = 9,
@@ -485,7 +485,7 @@ static const struct WindowTemplate gUnknown_0861CC24[] =
.baseBlock = 395,
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 1,
.tilemapTop = 14,
.width = 9,
@@ -498,7 +498,7 @@ static const struct WindowTemplate gUnknown_0861CC24[] =
static const struct WindowTemplate gUnknown_0861CCCC[] =
{
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 11,
.tilemapTop = 4,
.width = 11,
@@ -507,7 +507,7 @@ static const struct WindowTemplate gUnknown_0861CCCC[] =
.baseBlock = 449,
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 22,
.tilemapTop = 4,
.width = 7,
@@ -516,7 +516,7 @@ static const struct WindowTemplate gUnknown_0861CCCC[] =
.baseBlock = 471,
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 11,
.tilemapTop = 9,
.width = 18,
@@ -525,7 +525,7 @@ static const struct WindowTemplate gUnknown_0861CCCC[] =
.baseBlock = 485,
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 11,
.tilemapTop = 14,
.width = 18,
@@ -537,7 +537,7 @@ static const struct WindowTemplate gUnknown_0861CCCC[] =
static const struct WindowTemplate gUnknown_0861CCEC[] =
{
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 10,
.tilemapTop = 4,
.width = 10,
@@ -546,7 +546,7 @@ static const struct WindowTemplate gUnknown_0861CCEC[] =
.baseBlock = 449,
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 20,
.tilemapTop = 4,
.width = 10,
@@ -555,7 +555,7 @@ static const struct WindowTemplate gUnknown_0861CCEC[] =
.baseBlock = 469,
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 16,
.tilemapTop = 7,
.width = 6,
@@ -564,7 +564,7 @@ static const struct WindowTemplate gUnknown_0861CCEC[] =
.baseBlock = 489,
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 27,
.tilemapTop = 7,
.width = 3,
@@ -573,7 +573,7 @@ static const struct WindowTemplate gUnknown_0861CCEC[] =
.baseBlock = 525,
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 24,
.tilemapTop = 14,
.width = 6,
@@ -585,7 +585,7 @@ static const struct WindowTemplate gUnknown_0861CCEC[] =
static const struct WindowTemplate gUnknown_0861CD14[] =
{
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 15,
.tilemapTop = 4,
.width = 9,
@@ -594,7 +594,7 @@ static const struct WindowTemplate gUnknown_0861CD14[] =
.baseBlock = 449,
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 24,
.tilemapTop = 4,
.width = 6,
@@ -603,7 +603,7 @@ static const struct WindowTemplate gUnknown_0861CD14[] =
.baseBlock = 539,
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 10,
.tilemapTop = 15,
.width = 20,
diff --git a/src/record_mixing.c b/src/record_mixing.c
index 4c3c3d03c..4bb97cf1d 100644
--- a/src/record_mixing.c
+++ b/src/record_mixing.c
@@ -69,6 +69,7 @@ struct PlayerRecordsRS
struct EasyChatPair easyChatPairs[5];
struct RecordMixingDayCareMail dayCareMail;
struct RSBattleTowerRecord battleTowerRecord;
+ u16 giftItem;
u16 filler11C8[0x32];
};
@@ -81,7 +82,7 @@ struct PlayerRecordsEmerald
/* 0x1084 */ struct EasyChatPair easyChatPairs[5];
/* 0x10ac */ struct RecordMixingDayCareMail dayCareMail;
/* 0x1124 */ struct EmeraldBattleTowerRecord battleTowerRecord;
- /* 0x1210 */ u16 unk_1210;
+ /* 0x1210 */ u16 giftItem;
/* 0x1214 */ LilycoveLady lilycoveLady;
/* 0x1254 */ struct Apprentice apprentice[2];
/* 0x12dc */ struct UnkRecordMixingStruct2 unk_12dc;
@@ -132,7 +133,7 @@ static void ReceiveBattleTowerData(void *battleTowerRecord, size_t, u8);
static void ReceiveLilycoveLadyData(LilycoveLady *, size_t, u8);
static void sub_80E7B2C(const u8 *);
static void ReceiveDaycareMailData(struct RecordMixingDayCareMail *, size_t, u8, TVShow *);
-static void sub_80E7F68(u16 *item, u8 which);
+static void ReceiveGiftItem(u16 *item, u8 which);
static void sub_80E7FF8(u8 taskId);
static void sub_80E8110(struct Apprentice *arg0, struct Apprentice *arg1);
static void ReceiveApprenticeData(struct Apprentice *arg0, size_t arg1, u32 arg2);
@@ -197,10 +198,10 @@ static void SetSrcLookupPointers(void)
sOldManSave = &gSaveBlock1Ptr->oldMan;
sEasyChatPairsSave = gSaveBlock1Ptr->easyChatPairs;
gUnknown_03001148 = &gUnknown_02039F9C;
- sBattleTowerSave = &gSaveBlock2Ptr->frontier.battleTower;
+ sBattleTowerSave = &gSaveBlock2Ptr->frontier.towerPlayer;
sLilycoveLadySave = &gSaveBlock1Ptr->lilycoveLady;
gUnknown_03001154 = gSaveBlock2Ptr->apprentices;
- sBattleTowerSave_Duplicate = &gSaveBlock2Ptr->frontier.battleTower;
+ sBattleTowerSave_Duplicate = &gSaveBlock2Ptr->frontier.towerPlayer;
}
static void PrepareUnknownExchangePacket(struct PlayerRecordsRS *dest)
@@ -212,10 +213,10 @@ static void PrepareUnknownExchangePacket(struct PlayerRecordsRS *dest)
memcpy(&dest->oldMan, sOldManSave, sizeof(dest->oldMan));
memcpy(dest->easyChatPairs, sEasyChatPairsSave, sizeof(dest->easyChatPairs));
sub_80E89F8(&dest->dayCareMail);
- sub_81659DC(sBattleTowerSave, &dest->battleTowerRecord);
+ EmeraldBattleTowerRecordToRuby(sBattleTowerSave, &dest->battleTowerRecord);
if (GetMultiplayerId() == 0)
- dest->battleTowerRecord.unk_11c8 = GetRecordMixingGift();
+ dest->giftItem = GetRecordMixingGift();
}
static void PrepareExchangePacketForRubySapphire(struct PlayerRecordsRS *dest)
@@ -230,11 +231,11 @@ static void PrepareExchangePacketForRubySapphire(struct PlayerRecordsRS *dest)
memcpy(dest->easyChatPairs, sEasyChatPairsSave, sizeof(dest->easyChatPairs));
sub_80E89F8(&dest->dayCareMail);
SanitizeDayCareMailForRuby(&dest->dayCareMail);
- sub_81659DC(sBattleTowerSave, &dest->battleTowerRecord);
+ EmeraldBattleTowerRecordToRuby(sBattleTowerSave, &dest->battleTowerRecord);
SanitizeRubyBattleTowerRecord(&dest->battleTowerRecord);
if (GetMultiplayerId() == 0)
- dest->battleTowerRecord.unk_11c8 = GetRecordMixingGift();
+ dest->giftItem = GetRecordMixingGift();
}
static void PrepareExchangePacket(void)
@@ -263,7 +264,7 @@ static void PrepareExchangePacket(void)
SanitizeEmeraldBattleTowerRecord(&sSentRecord->emerald.battleTowerRecord);
if (GetMultiplayerId() == 0)
- sSentRecord->emerald.unk_1210 = GetRecordMixingGift();
+ sSentRecord->emerald.giftItem = GetRecordMixingGift();
sub_80E8110(sSentRecord->emerald.apprentice, gUnknown_03001154);
sub_80E8260(&sSentRecord->emerald.unk_12dc);
@@ -283,7 +284,7 @@ static void ReceiveExchangePacket(u32 which)
ReceivePokeNewsData(sReceivedRecords->ruby.pokeNews, sizeof(struct PlayerRecordsRS), which);
ReceiveOldManData(&sReceivedRecords->ruby.oldMan, sizeof(struct PlayerRecordsRS), which);
ReceiveEasyChatPairsData(sReceivedRecords->ruby.easyChatPairs, sizeof(struct PlayerRecordsRS), which);
- sub_80E7F68(&sReceivedRecords->ruby.battleTowerRecord.unk_11c8, which);
+ ReceiveGiftItem(&sReceivedRecords->ruby.giftItem, which);
}
else
{
@@ -296,7 +297,7 @@ static void ReceiveExchangePacket(u32 which)
ReceiveEasyChatPairsData(sReceivedRecords->emerald.easyChatPairs, sizeof(struct PlayerRecordsEmerald), which);
ReceiveDaycareMailData(&sReceivedRecords->emerald.dayCareMail, sizeof(struct PlayerRecordsEmerald), which, sReceivedRecords->emerald.tvShows);
ReceiveBattleTowerData(&sReceivedRecords->emerald.battleTowerRecord, sizeof(struct PlayerRecordsEmerald), which);
- sub_80E7F68(&sReceivedRecords->emerald.unk_1210, which);
+ ReceiveGiftItem(&sReceivedRecords->emerald.giftItem, which);
ReceiveLilycoveLadyData(&sReceivedRecords->emerald.lilycoveLady, sizeof(struct PlayerRecordsEmerald), which);
ReceiveApprenticeData(sReceivedRecords->emerald.apprentice, sizeof(struct PlayerRecordsEmerald), (u8) which);
sub_80E89AC(&sReceivedRecords->emerald.unk_12dc, sizeof(struct PlayerRecordsEmerald), (u8) which);
@@ -667,7 +668,7 @@ static void ReceiveBattleTowerData(void *battleTowerRecord, size_t recordSize, u
ShufflePlayerIndices(mixIndices);
if (Link_AnyPartnersPlayingRubyOrSapphire())
{
- if (sub_816587C((void *)battleTowerRecord + recordSize * mixIndices[which], (void *)battleTowerRecord + recordSize * which) == TRUE)
+ if (RubyBattleTowerRecordToEmerald((void *)battleTowerRecord + recordSize * mixIndices[which], (void *)battleTowerRecord + recordSize * which) == TRUE)
{
dest = (void *)battleTowerRecord + recordSize * which;
dest->language = gLinkPlayers[mixIndices[which]].language;
@@ -676,7 +677,7 @@ static void ReceiveBattleTowerData(void *battleTowerRecord, size_t recordSize, u
}
else
{
- memcpy((void *)battleTowerRecord + recordSize * which, (void *)battleTowerRecord + recordSize * mixIndices[which], sizeof(union BattleTowerRecord));
+ memcpy((void *)battleTowerRecord + recordSize * which, (void *)battleTowerRecord + recordSize * mixIndices[which], sizeof(struct EmeraldBattleTowerRecord));
dest = (void *)battleTowerRecord + recordSize * which;
for (i = 0; i < 4; i ++)
{
@@ -686,7 +687,7 @@ static void ReceiveBattleTowerData(void *battleTowerRecord, size_t recordSize, u
}
CalcEmeraldBattleTowerChecksum(dest);
}
- sub_81628A0((void *)battleTowerRecord + recordSize * which);
+ PutNewBattleTowerRecord((void *)battleTowerRecord + recordSize * which);
}
static void ReceiveLilycoveLadyData(LilycoveLady *lilycoveLady, size_t recordSize, u8 which)
@@ -1460,7 +1461,7 @@ static void ReceiveDaycareMailData(struct RecordMixingDayCareMail *src, size_t r
}
#endif // NONMATCHING
-static void sub_80E7F68(u16 *item, u8 which)
+static void ReceiveGiftItem(u16 *item, u8 which)
{
if (which != 0 && *item != ITEM_NONE && GetPocketByItemId(*item) == POCKET_KEY_ITEMS)
{
diff --git a/src/recorded_battle.c b/src/recorded_battle.c
index 355ed5e07..0a199f289 100644
--- a/src/recorded_battle.c
+++ b/src/recorded_battle.c
@@ -402,73 +402,73 @@ u32 MoveRecordedBattleToSaveData(void)
{
for (i = 0; i < 8; i++)
{
- battleSave->field_504[i] = gSaveBlock2Ptr->field_738[gTrainerBattleOpponent_A - 300].field_4[i];
+ battleSave->field_504[i] = gSaveBlock2Ptr->records[gTrainerBattleOpponent_A - 300].field_4[i];
}
- battleSave->field_50C = gSaveBlock2Ptr->field_738[gTrainerBattleOpponent_A - 300].field_1;
+ battleSave->field_50C = gSaveBlock2Ptr->records[gTrainerBattleOpponent_A - 300].field_1;
if (sUnknown_0203CCE8 == 1)
{
for (i = 0; i < 6; i++)
{
- battleSave->field_50E[i] = gSaveBlock2Ptr->field_738[gTrainerBattleOpponent_A - 300].field_28[i];
+ battleSave->field_50E[i] = gSaveBlock2Ptr->records[gTrainerBattleOpponent_A - 300].field_28[i];
}
}
else
{
for (i = 0; i < 6; i++)
{
- battleSave->field_50E[i] = gSaveBlock2Ptr->field_738[gTrainerBattleOpponent_A - 300].field_1C[i];
+ battleSave->field_50E[i] = gSaveBlock2Ptr->records[gTrainerBattleOpponent_A - 300].field_1C[i];
}
}
- battleSave->field_51A = gSaveBlock2Ptr->field_738[gTrainerBattleOpponent_A - 300].field_E4;
+ battleSave->field_51A = gSaveBlock2Ptr->records[gTrainerBattleOpponent_A - 300].field_E4;
}
else if (gTrainerBattleOpponent_B >= 300 && gTrainerBattleOpponent_B <= 399)
{
for (i = 0; i < 8; i++)
{
- battleSave->field_504[i] = gSaveBlock2Ptr->field_738[gTrainerBattleOpponent_B - 300].field_4[i];
+ battleSave->field_504[i] = gSaveBlock2Ptr->records[gTrainerBattleOpponent_B - 300].field_4[i];
}
- battleSave->field_50C = gSaveBlock2Ptr->field_738[gTrainerBattleOpponent_B - 300].field_1;
+ battleSave->field_50C = gSaveBlock2Ptr->records[gTrainerBattleOpponent_B - 300].field_1;
if (sUnknown_0203CCE8 == 1)
{
for (i = 0; i < 6; i++)
{
- battleSave->field_50E[i] = gSaveBlock2Ptr->field_738[gTrainerBattleOpponent_B - 300].field_28[i];
+ battleSave->field_50E[i] = gSaveBlock2Ptr->records[gTrainerBattleOpponent_B - 300].field_28[i];
}
}
else
{
for (i = 0; i < 6; i++)
{
- battleSave->field_50E[i] = gSaveBlock2Ptr->field_738[gTrainerBattleOpponent_B - 300].field_1C[i];
+ battleSave->field_50E[i] = gSaveBlock2Ptr->records[gTrainerBattleOpponent_B - 300].field_1C[i];
}
}
- battleSave->field_51A = gSaveBlock2Ptr->field_738[gTrainerBattleOpponent_B - 300].field_E4;
+ battleSave->field_51A = gSaveBlock2Ptr->records[gTrainerBattleOpponent_B - 300].field_E4;
}
else if (gPartnerTrainerId >= 300 && gPartnerTrainerId <= 399)
{
for (i = 0; i < 8; i++)
{
- battleSave->field_504[i] = gSaveBlock2Ptr->field_738[gPartnerTrainerId - 300].field_4[i];
+ battleSave->field_504[i] = gSaveBlock2Ptr->records[gPartnerTrainerId - 300].field_4[i];
}
- battleSave->field_50C = gSaveBlock2Ptr->field_738[gPartnerTrainerId - 300].field_1;
+ battleSave->field_50C = gSaveBlock2Ptr->records[gPartnerTrainerId - 300].field_1;
if (sUnknown_0203CCE8 == 1)
{
for (i = 0; i < 6; i++)
{
- battleSave->field_50E[i] = gSaveBlock2Ptr->field_738[gPartnerTrainerId - 300].field_28[i];
+ battleSave->field_50E[i] = gSaveBlock2Ptr->records[gPartnerTrainerId - 300].field_28[i];
}
}
else
{
for (i = 0; i < 6; i++)
{
- battleSave->field_50E[i] = gSaveBlock2Ptr->field_738[gPartnerTrainerId - 300].field_1C[i];
+ battleSave->field_50E[i] = gSaveBlock2Ptr->records[gPartnerTrainerId - 300].field_1C[i];
}
}
- battleSave->field_51A = gSaveBlock2Ptr->field_738[gPartnerTrainerId - 300].field_E4;
+ battleSave->field_51A = gSaveBlock2Ptr->records[gPartnerTrainerId - 300].field_E4;
}
*/
diff --git a/src/save_failed_screen.c b/src/save_failed_screen.c
index ae23f8245..010279a87 100644
--- a/src/save_failed_screen.c
+++ b/src/save_failed_screen.c
@@ -95,7 +95,7 @@ static const struct BgTemplate gUnknown_085EFD88[3] =
static const struct WindowTemplate gUnknown_085EFD94[] =
{
{
- .priority = 255,
+ .bg = 255,
.tilemapLeft = 0,
.tilemapTop = 0,
.width = 0,
@@ -108,7 +108,7 @@ static const struct WindowTemplate gUnknown_085EFD94[] =
static const struct WindowTemplate gUnknown_085EFD9C[] =
{
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 1,
.tilemapTop = 13,
.width = 28,
@@ -121,7 +121,7 @@ static const struct WindowTemplate gUnknown_085EFD9C[] =
static const struct WindowTemplate gUnknown_085EFDA4[] =
{
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 14,
.tilemapTop = 9,
.width = 2,
diff --git a/src/secret_base.c b/src/secret_base.c
index a684f3982..87d44fb17 100644
--- a/src/secret_base.c
+++ b/src/secret_base.c
@@ -40,6 +40,7 @@
#include "tv.h"
#include "secret_base.h"
#include "constants/map_types.h"
+#include "constants/trainers.h"
extern void mapldr_default(void);
@@ -1143,7 +1144,7 @@ const u8 *GetSecretBaseTrainerLoseText(void)
void sub_80EA2E4(void)
{
sub_813BADC(TRUE);
- gTrainerBattleOpponent_A = 0x400;
+ gTrainerBattleOpponent_A = TRAINER_SECRET_BASE;
gBattleTypeFlags = BATTLE_TYPE_TRAINER | BATTLE_TYPE_SECRET_BASE;
}
diff --git a/src/shop.c b/src/shop.c
index 510c9f4f7..35f52c8f9 100755
--- a/src/shop.c
+++ b/src/shop.c
@@ -95,14 +95,14 @@ static const struct YesNoFuncTable sShopPurchaseYesNoFuncs =
BuyMenuReturnToItemList
};
-static const struct MenuAction sShopMenuActions_BuySellQuit[] =
+static const struct MenuAction sShopMenuActions_BuySellQuit[] =
{
{ gText_ShopBuy, {.void_u8=Task_HandleShopMenuBuy} },
{ gText_ShopSell, {.void_u8=Task_HandleShopMenuSell} },
{ gText_ShopQuit, {.void_u8=Task_HandleShopMenuQuit} }
};
-static const struct MenuAction sShopMenuActions_BuyQuit[] =
+static const struct MenuAction sShopMenuActions_BuyQuit[] =
{
{ gText_ShopBuy, {.void_u8=Task_HandleShopMenuBuy} },
{ gText_ShopQuit, {.void_u8=Task_HandleShopMenuQuit} }
@@ -111,7 +111,7 @@ static const struct MenuAction sShopMenuActions_BuyQuit[] =
static const struct WindowTemplate sShopMenuWindowTemplates[] =
{
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 2,
.tilemapTop = 1,
.width = 9,
@@ -120,7 +120,7 @@ static const struct WindowTemplate sShopMenuWindowTemplates[] =
.baseBlock = 0x0008,
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 2,
.tilemapTop = 1,
.width = 9,
@@ -195,7 +195,7 @@ static const struct BgTemplate sShopBuyMenuBgTemplates[] =
static const struct WindowTemplate sShopBuyMenuWindowTemplates[] =
{
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 1,
.tilemapTop = 1,
.width = 10,
@@ -204,7 +204,7 @@ static const struct WindowTemplate sShopBuyMenuWindowTemplates[] =
.baseBlock = 0x001E,
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 14,
.tilemapTop = 2,
.width = 15,
@@ -213,7 +213,7 @@ static const struct WindowTemplate sShopBuyMenuWindowTemplates[] =
.baseBlock = 0x0032,
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 0,
.tilemapTop = 13,
.width = 14,
@@ -222,7 +222,7 @@ static const struct WindowTemplate sShopBuyMenuWindowTemplates[] =
.baseBlock = 0x0122,
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 1,
.tilemapTop = 11,
.width = 12,
@@ -231,7 +231,7 @@ static const struct WindowTemplate sShopBuyMenuWindowTemplates[] =
.baseBlock = 0x0176,
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 18,
.tilemapTop = 11,
.width = 10,
@@ -240,7 +240,7 @@ static const struct WindowTemplate sShopBuyMenuWindowTemplates[] =
.baseBlock = 0x018E,
},
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 2,
.tilemapTop = 15,
.width = 27,
@@ -251,9 +251,9 @@ static const struct WindowTemplate sShopBuyMenuWindowTemplates[] =
DUMMY_WIN_TEMPLATE
};
-static const struct WindowTemplate sShopBuyMenuYesNoWindowTemplates =
+static const struct WindowTemplate sShopBuyMenuYesNoWindowTemplates =
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 21,
.tilemapTop = 9,
.width = 5,
@@ -808,7 +808,7 @@ static void BuyMenuCollectEventObjectData(void)
gShopDataPtr->viewportObjects[r8][X_COORD] = x;
gShopDataPtr->viewportObjects[r8][Y_COORD] = y;
gShopDataPtr->viewportObjects[r8][LAYER_TYPE] = MapGridGetMetatileLayerTypeAt(facingX - 4 + x, facingY - 2 + y);
-
+
switch (gEventObjects[eventObjId].facingDirection)
{
case DIR_SOUTH:
@@ -850,7 +850,7 @@ static void BuyMenuDrawEventObjects(void)
(u16)gShopDataPtr->viewportObjects[i][X_COORD] * 16 + 8,
(u16)gShopDataPtr->viewportObjects[i][Y_COORD] * 16 + 48 - graphicsInfo->height / 2,
2);
-
+
if (BuyMenuCheckIfEventObjectOverlapsMenuBg(gShopDataPtr->viewportObjects[i]) == TRUE)
{
gSprites[spriteId].subspriteTableNum = 4;
@@ -867,7 +867,7 @@ static bool8 BuyMenuCheckIfEventObjectOverlapsMenuBg(s16 *object)
{
return TRUE;
}
- else
+ else
{
return FALSE;
}
@@ -1000,7 +1000,7 @@ static void Task_BuyHowManyDialogueInit(u8 taskId)
{
gShopDataPtr->maxQuantity = maxQuantity;
}
-
+
gTasks[taskId].func = Task_BuyHowManyDialogueHandleInput;
}
diff --git a/src/start_menu.c b/src/start_menu.c
index dcb2c4154..aaa9fec2c 100644
--- a/src/start_menu.c
+++ b/src/start_menu.c
@@ -383,14 +383,14 @@ static void ShowSafariBallsWindow(void)
static void ShowPyramidFloorWindow(void)
{
- if (gSaveBlock2Ptr->frontier.field_CB2 == 7)
+ if (gSaveBlock2Ptr->frontier.curChallengeBattleNum == 7)
sBattlePyramidFloorWindowId = AddWindow(&sPyramidFloorWindowTemplate_1);
else
sBattlePyramidFloorWindowId = AddWindow(&sPyramidFloorWindowTemplate_2);
PutWindowTilemap(sBattlePyramidFloorWindowId);
NewMenuHelpers_DrawStdWindowFrame(sBattlePyramidFloorWindowId, FALSE);
- StringCopy(gStringVar1, sPyramindFloorNames[gSaveBlock2Ptr->frontier.field_CB2]);
+ StringCopy(gStringVar1, sPyramindFloorNames[gSaveBlock2Ptr->frontier.curChallengeBattleNum]);
StringExpandPlaceholders(gStringVar4, gText_BattlePyramidFloor);
AddTextPrinterParameterized(sBattlePyramidFloorWindowId, 1, gStringVar4, 0, 1, 0xFF, NULL);
CopyWindowToVram(sBattlePyramidFloorWindowId, 2);
diff --git a/src/starter_choose.c b/src/starter_choose.c
index 5af652ccc..298c74db0 100644
--- a/src/starter_choose.c
+++ b/src/starter_choose.c
@@ -73,10 +73,10 @@ const u32 gUnknown_085B18AC[] = INCBIN_U32("graphics/misc/birch_ballarrow.4bpp.l
const u32 gUnknown_085B1BCC[] = INCBIN_U32("graphics/misc/birch_circle.4bpp.lz");
-static const struct WindowTemplate gUnknown_085B1DCC[] =
+static const struct WindowTemplate gUnknown_085B1DCC[] =
{
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 3,
.tilemapTop = 15,
.width = 24,
@@ -87,9 +87,9 @@ static const struct WindowTemplate gUnknown_085B1DCC[] =
DUMMY_WIN_TEMPLATE,
};
-static const struct WindowTemplate gUnknown_085B1DDC =
+static const struct WindowTemplate gUnknown_085B1DDC =
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 24,
.tilemapTop = 9,
.width = 5,
@@ -98,9 +98,9 @@ static const struct WindowTemplate gUnknown_085B1DDC =
.baseBlock = 0x0260
};
-static const struct WindowTemplate gUnknown_085B1DE4 =
+static const struct WindowTemplate gUnknown_085B1DE4 =
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 0,
.tilemapTop = 0,
.width = 13,
diff --git a/src/text_window.c b/src/text_window.c
index e7e8f0ca6..517f4bdb9 100644
--- a/src/text_window.c
+++ b/src/text_window.c
@@ -93,7 +93,7 @@ const struct TilesPal *GetWindowFrameTilesPal(u8 id)
void LoadMessageBoxGfx(u8 windowId, u16 destOffset, u8 palOffset)
{
- LoadBgTiles(GetWindowAttribute(windowId, WINDOW_PRIORITY), gMessageBox_Gfx, 0x1C0, destOffset);
+ LoadBgTiles(GetWindowAttribute(windowId, WINDOW_BG), gMessageBox_Gfx, 0x1C0, destOffset);
LoadPalette(GetOverworldTextboxPalettePtr(), palOffset, 0x20);
}
@@ -104,7 +104,7 @@ void LoadUserWindowBorderGfx_(u8 windowId, u16 destOffset, u8 palOffset)
void LoadWindowGfx(u8 windowId, u8 frameId, u16 destOffset, u8 palOffset)
{
- LoadBgTiles(GetWindowAttribute(windowId, WINDOW_PRIORITY), sWindowFrames[frameId].tiles, 0x120, destOffset);
+ LoadBgTiles(GetWindowAttribute(windowId, WINDOW_BG), sWindowFrames[frameId].tiles, 0x120, destOffset);
LoadPalette(sWindowFrames[frameId].pal, palOffset, 0x20);
}
@@ -115,7 +115,7 @@ void LoadUserWindowBorderGfx(u8 windowId, u16 destOffset, u8 palOffset)
void sub_8098858(u8 windowId, u16 tileNum, u8 palNum)
{
- u8 bgLayer = GetWindowAttribute(windowId, WINDOW_PRIORITY);
+ u8 bgLayer = GetWindowAttribute(windowId, WINDOW_BG);
u16 tilemapLeft = GetWindowAttribute(windowId, WINDOW_TILEMAP_LEFT);
u16 tilemapTop = GetWindowAttribute(windowId, WINDOW_TILEMAP_TOP);
u16 width = GetWindowAttribute(windowId, WINDOW_WIDTH);
@@ -133,7 +133,7 @@ void sub_8098858(u8 windowId, u16 tileNum, u8 palNum)
void sub_80989E0(u8 windowId, u16 tileNum, u8 palNum)
{
- u8 bgLayer = GetWindowAttribute(windowId, WINDOW_PRIORITY);
+ u8 bgLayer = GetWindowAttribute(windowId, WINDOW_BG);
u16 tilemapLeft = GetWindowAttribute(windowId, WINDOW_TILEMAP_LEFT);
u16 tilemapTop = GetWindowAttribute(windowId, WINDOW_TILEMAP_TOP);
u16 width = GetWindowAttribute(windowId, WINDOW_WIDTH);
@@ -151,7 +151,7 @@ void sub_80989E0(u8 windowId, u16 tileNum, u8 palNum)
void rbox_fill_rectangle(u8 windowId)
{
- u8 bgLayer = GetWindowAttribute(windowId, WINDOW_PRIORITY);
+ u8 bgLayer = GetWindowAttribute(windowId, WINDOW_BG);
u16 tilemapLeft = GetWindowAttribute(windowId, WINDOW_TILEMAP_LEFT);
u16 tilemapTop = GetWindowAttribute(windowId, WINDOW_TILEMAP_TOP);
u16 width = GetWindowAttribute(windowId, WINDOW_WIDTH);
diff --git a/src/tv.c b/src/tv.c
index fb309f6e3..897f9950b 100644
--- a/src/tv.c
+++ b/src/tv.c
@@ -1544,7 +1544,7 @@ static void InterviewAfter_BravoTrainerBattleTowerProfile(void)
StringCopy(show->bravoTrainerTower.pokemonName, gSaveBlock2Ptr->frontier.field_BD8);
show->bravoTrainerTower.species = gSaveBlock2Ptr->frontier.field_BD4;
show->bravoTrainerTower.defeatedSpecies = gSaveBlock2Ptr->frontier.field_BD6;
- show->bravoTrainerTower.numFights = sub_8164FCC(gSaveBlock2Ptr->frontier.field_D07, 0);
+ show->bravoTrainerTower.numFights = GetCurrentBattleTowerWinStreak(gSaveBlock2Ptr->frontier.field_D07, 0);
show->bravoTrainerTower.wonTheChallenge = gSaveBlock2Ptr->frontier.field_D06;
if (gSaveBlock2Ptr->frontier.field_D07 == 0)
{
@@ -2540,8 +2540,8 @@ void sub_80EE8C8(u16 winStreak, u8 facility)
show->frontier.species2 = GetMonData(&gPlayerParty[1], MON_DATA_SPECIES, NULL);
break;
case 4:
- show->frontier.species1 = GetMonData(&gSaveBlock1Ptr->playerParty[gSaveBlock2Ptr->frontier.field_CAA[0] - 1], MON_DATA_SPECIES, NULL);
- show->frontier.species2 = GetMonData(&gSaveBlock1Ptr->playerParty[gSaveBlock2Ptr->frontier.field_CAA[1] - 1], MON_DATA_SPECIES, NULL);
+ show->frontier.species1 = GetMonData(&gSaveBlock1Ptr->playerParty[gSaveBlock2Ptr->frontier.selectedPartyMons[0] - 1], MON_DATA_SPECIES, NULL);
+ show->frontier.species2 = GetMonData(&gSaveBlock1Ptr->playerParty[gSaveBlock2Ptr->frontier.selectedPartyMons[1] - 1], MON_DATA_SPECIES, NULL);
break;
}
tv_store_id_3x(show);
diff --git a/src/wallclock.c b/src/wallclock.c
index d6b2b5d50..947b7f103 100644
--- a/src/wallclock.c
+++ b/src/wallclock.c
@@ -60,10 +60,10 @@ static void SpriteCB_PMIndicator(struct Sprite *sprite);
static const u32 sUnknown_085B1F58[] = INCBIN_U32("graphics/wallclock/graphics_85b1f58.4bpp.lz");
static const u16 sUnknown_085B21D4[] = INCBIN_U16("graphics/wallclock/palette_85b21d4.gbapal");
-static const struct WindowTemplate gUnknown_085B21DC[] =
+static const struct WindowTemplate gUnknown_085B21DC[] =
{
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 3,
.tilemapTop = 17,
.width = 24,
@@ -72,7 +72,7 @@ static const struct WindowTemplate gUnknown_085B21DC[] =
.baseBlock = 512
},
{
- .priority = 2,
+ .bg = 2,
.tilemapLeft = 24,
.tilemapTop = 16,
.width = 6,
@@ -84,7 +84,7 @@ static const struct WindowTemplate gUnknown_085B21DC[] =
};
static const struct WindowTemplate gUnknown_085B21F4 =
{
- .priority = 0,
+ .bg = 0,
.tilemapLeft = 24,
.tilemapTop = 9,
.width = 5,
diff --git a/src/wild_encounter.c b/src/wild_encounter.c
index 9a22323ff..ec69ad2b5 100644
--- a/src/wild_encounter.c
+++ b/src/wild_encounter.c
@@ -5102,7 +5102,7 @@ bool8 StandardWildEncounter(u16 currMetaTileBehavior, u16 previousMetaTileBehavi
}
if (gMapHeader.mapLayoutId == 0x169)
{
- headerId = gSaveBlock2Ptr->frontier.field_CB2;
+ headerId = gSaveBlock2Ptr->frontier.curChallengeBattleNum;
if (previousMetaTileBehavior != currMetaTileBehavior && !DoGlobalWildEncounterDiceRoll())
return FALSE;
else if (DoWildEncounterRateTest(gBattlePyramidWildMonHeaders[headerId].landMonsInfo->encounterRate, FALSE) != TRUE)
@@ -5240,7 +5240,7 @@ bool8 SweetScentWildEncounter(void)
}
if (gMapHeader.mapLayoutId == 0x169)
{
- headerId = gSaveBlock2Ptr->frontier.field_CB2;
+ headerId = gSaveBlock2Ptr->frontier.curChallengeBattleNum;
if (TryGenerateWildMon(gBattlePyramidWildMonHeaders[headerId].landMonsInfo, WILD_AREA_LAND, 0) != TRUE)
return FALSE;
diff --git a/src/window.c b/src/window.c
index 57c8f5092..8efd1c281 100644
--- a/src/window.c
+++ b/src/window.c
@@ -52,7 +52,7 @@ bool16 InitWindows(const struct WindowTemplate *templates)
gWindows[i].tileData = NULL;
}
- for (i = 0, allocatedBaseBlock = 0, bgLayer = templates[i].priority; bgLayer != 0xFF && i < 0x20; ++i, bgLayer = templates[i].priority)
+ for (i = 0, allocatedBaseBlock = 0, bgLayer = templates[i].bg; bgLayer != 0xFF && i < 0x20; ++i, bgLayer = templates[i].bg)
{
if (gUnneededFireRedVariable == 1)
{
@@ -121,14 +121,14 @@ u16 AddWindow(const struct WindowTemplate *template)
for (win = 0; win < WINDOWS_MAX; ++win)
{
- if ((bgLayer = gWindows[win].window.priority) == 0xFF)
+ if ((bgLayer = gWindows[win].window.bg) == 0xFF)
break;
}
if (win == WINDOWS_MAX)
return 0xFF;
- bgLayer = template->priority;
+ bgLayer = template->bg;
allocatedBaseBlock = 0;
if (gUnneededFireRedVariable == 1)
@@ -190,14 +190,14 @@ int AddWindowWithoutTileMap(const struct WindowTemplate *template)
for (win = 0; win < WINDOWS_MAX; ++win)
{
- if (gWindows[win].window.priority == 0xFF)
+ if (gWindows[win].window.bg == 0xFF)
break;
}
if (win == WINDOWS_MAX)
return 0xFF;
- bgLayer = template->priority;
+ bgLayer = template->bg;
allocatedBaseBlock = 0;
if (gUnneededFireRedVariable == 1)
@@ -221,7 +221,7 @@ int AddWindowWithoutTileMap(const struct WindowTemplate *template)
void RemoveWindow(u8 windowId)
{
- u8 bgLayer = gWindows[windowId].window.priority;
+ u8 bgLayer = gWindows[windowId].window.bg;
if (gUnneededFireRedVariable == 1)
{
@@ -277,14 +277,14 @@ void CopyWindowToVram(u8 windowId, u8 mode)
switch (mode)
{
case 1:
- CopyBgTilemapBufferToVram(windowLocal.window.priority);
+ CopyBgTilemapBufferToVram(windowLocal.window.bg);
break;
case 2:
- LoadBgTiles(windowLocal.window.priority, windowLocal.tileData, windowSize, windowLocal.window.baseBlock);
+ LoadBgTiles(windowLocal.window.bg, windowLocal.tileData, windowSize, windowLocal.window.baseBlock);
break;
case 3:
- LoadBgTiles(windowLocal.window.priority, windowLocal.tileData, windowSize, windowLocal.window.baseBlock);
- CopyBgTilemapBufferToVram(windowLocal.window.priority);
+ LoadBgTiles(windowLocal.window.bg, windowLocal.tileData, windowSize, windowLocal.window.baseBlock);
+ CopyBgTilemapBufferToVram(windowLocal.window.bg);
break;
}
}
@@ -309,14 +309,14 @@ void CopyWindowRectToVram(u32 windowId, u32 mode, u32 x, u32 y, u32 w, u32 h)
switch (mode)
{
case 1:
- CopyBgTilemapBufferToVram(windowLocal.window.priority);
+ CopyBgTilemapBufferToVram(windowLocal.window.bg);
break;
case 2:
- LoadBgTiles(windowLocal.window.priority, windowLocal.tileData + (rectPos * 32), rectSize, windowLocal.window.baseBlock + rectPos);
+ LoadBgTiles(windowLocal.window.bg, windowLocal.tileData + (rectPos * 32), rectSize, windowLocal.window.baseBlock + rectPos);
break;
case 3:
- LoadBgTiles(windowLocal.window.priority, windowLocal.tileData + (rectPos * 32), rectSize, windowLocal.window.baseBlock + rectPos);
- CopyBgTilemapBufferToVram(windowLocal.window.priority);
+ LoadBgTiles(windowLocal.window.bg, windowLocal.tileData + (rectPos * 32), rectSize, windowLocal.window.baseBlock + rectPos);
+ CopyBgTilemapBufferToVram(windowLocal.window.bg);
break;
}
}
@@ -327,8 +327,8 @@ void PutWindowTilemap(u8 windowId)
struct Window windowLocal = gWindows[windowId];
WriteSequenceToBgTilemapBuffer(
- windowLocal.window.priority,
- GetBgAttribute(windowLocal.window.priority, 0xA) + windowLocal.window.baseBlock,
+ windowLocal.window.bg,
+ GetBgAttribute(windowLocal.window.bg, 0xA) + windowLocal.window.baseBlock,
windowLocal.window.tilemapLeft,
windowLocal.window.tilemapTop,
windowLocal.window.width,
@@ -340,13 +340,13 @@ void PutWindowTilemap(u8 windowId)
void PutWindowRectTilemapOverridePalette(u8 windowId, u8 x, u8 y, u8 width, u8 height, u8 palette)
{
struct Window windowLocal = gWindows[windowId];
- u16 currentRow = windowLocal.window.baseBlock + (y * windowLocal.window.width) + x + GetBgAttribute(windowLocal.window.priority, 0xA);
+ u16 currentRow = windowLocal.window.baseBlock + (y * windowLocal.window.width) + x + GetBgAttribute(windowLocal.window.bg, 0xA);
int i;
for (i = 0; i < height; ++i)
{
WriteSequenceToBgTilemapBuffer(
- windowLocal.window.priority,
+ windowLocal.window.bg,
currentRow,
windowLocal.window.tilemapLeft + x,
windowLocal.window.tilemapTop + y + i,
@@ -364,7 +364,7 @@ void ClearWindowTilemap(u8 windowId)
struct Window windowLocal = gWindows[windowId];
FillBgTilemapBufferRect(
- windowLocal.window.priority,
+ windowLocal.window.bg,
gUnknown_03002F60,
windowLocal.window.tilemapLeft,
windowLocal.window.tilemapTop,
@@ -376,13 +376,13 @@ void ClearWindowTilemap(u8 windowId)
void PutWindowRectTilemap(u8 windowId, u8 x, u8 y, u8 width, u8 height)
{
struct Window windowLocal = gWindows[windowId];
- u16 currentRow = windowLocal.window.baseBlock + (y * windowLocal.window.width) + x + GetBgAttribute(windowLocal.window.priority, 0xA);
+ u16 currentRow = windowLocal.window.baseBlock + (y * windowLocal.window.width) + x + GetBgAttribute(windowLocal.window.bg, 0xA);
int i;
for (i = 0; i < height; ++i)
{
WriteSequenceToBgTilemapBuffer(
- windowLocal.window.priority,
+ windowLocal.window.bg,
currentRow,
windowLocal.window.tilemapLeft + x,
windowLocal.window.tilemapTop + y + i,
@@ -529,7 +529,7 @@ void ScrollWindow(u8 windowId, u8 direction, u8 distance, u8 fillValue)
void CallWindowFunction(u8 windowId, void ( *func)(u8, u8, u8, u8, u8, u8))
{
struct WindowTemplate window = gWindows[windowId].window;
- func(window.priority, window.tilemapLeft, window.tilemapTop, window.width, window.height, window.paletteNum);
+ func(window.bg, window.tilemapLeft, window.tilemapTop, window.width, window.height, window.paletteNum);
}
bool8 SetWindowAttribute(u8 windowId, u8 attributeId, u32 value)
@@ -551,7 +551,7 @@ bool8 SetWindowAttribute(u8 windowId, u8 attributeId, u32 value)
case WINDOW_TILE_DATA:
gWindows[windowId].tileData = (u8*)(value);
return TRUE;
- case WINDOW_PRIORITY:
+ case WINDOW_BG:
case WINDOW_WIDTH:
case WINDOW_HEIGHT:
default:
@@ -563,8 +563,8 @@ u32 GetWindowAttribute(u8 windowId, u8 attributeId)
{
switch (attributeId)
{
- case WINDOW_PRIORITY:
- return gWindows[windowId].window.priority;
+ case WINDOW_BG:
+ return gWindows[windowId].window.bg;
case WINDOW_TILEMAP_LEFT:
return gWindows[windowId].window.tilemapLeft;
case WINDOW_TILEMAP_TOP:
@@ -590,7 +590,7 @@ static u8 GetNumActiveWindowsOnBg(u8 bgId)
s32 i;
for (i = 0; i < WINDOWS_MAX; i++)
{
- if (gWindows[i].window.priority == bgId)
+ if (gWindows[i].window.bg == bgId)
windowsNum++;
}
return windowsNum;
@@ -609,12 +609,12 @@ u16 AddWindow8Bit(struct WindowTemplate *template)
for (windowId = 0; windowId < 32; windowId++)
{
- if (gWindows[windowId].window.priority == 0xFF)
+ if (gWindows[windowId].window.bg == 0xFF)
break;
}
if (windowId == WINDOWS_MAX)
return 0xFF;
- bgLayer = template->priority;
+ bgLayer = template->bg;
if (gUnknown_03002F70[bgLayer] == 0)
{
u16 attribute = GetBgAttribute(bgLayer, 8);
@@ -693,14 +693,14 @@ void CopyWindowToVram8Bit(u8 windowId, u8 mode)
switch (mode)
{
case 1:
- CopyBgTilemapBufferToVram(sWindowPtr->window.priority);
+ CopyBgTilemapBufferToVram(sWindowPtr->window.bg);
break;
case 2:
- LoadBgTiles(sWindowPtr->window.priority, sWindowPtr->tileData, sWindowSize, sWindowPtr->window.baseBlock);
+ LoadBgTiles(sWindowPtr->window.bg, sWindowPtr->tileData, sWindowSize, sWindowPtr->window.baseBlock);
break;
case 3:
- LoadBgTiles(sWindowPtr->window.priority, sWindowPtr->tileData, sWindowSize, sWindowPtr->window.baseBlock);
- CopyBgTilemapBufferToVram(sWindowPtr->window.priority);
+ LoadBgTiles(sWindowPtr->window.bg, sWindowPtr->tileData, sWindowSize, sWindowPtr->window.baseBlock);
+ CopyBgTilemapBufferToVram(sWindowPtr->window.bg);
break;
}
}
@@ -711,7 +711,7 @@ static u8 GetNumActiveWindowsOnBg8Bit(u8 bgId)
s32 i;
for (i = 0; i < WINDOWS_MAX; i++)
{
- if (gWindows[i].window.priority == bgId)
+ if (gWindows[i].window.bg == bgId)
windowsNum++;
}
return windowsNum;