Name functions, variables, and that one flag constant
This commit is contained in:
@@ -31,6 +31,7 @@
|
||||
#include "string_util.h"
|
||||
#include "overworld.h"
|
||||
#include "field_weather.h"
|
||||
#include "gym_leader_rematch.h"
|
||||
|
||||
enum
|
||||
{
|
||||
@@ -66,7 +67,6 @@ extern void Overworld_ClearSavedMusic(void);
|
||||
extern void CB2_WhiteOut(void);
|
||||
extern void sub_80AF6F0(void);
|
||||
extern void PlayBattleBGM(void);
|
||||
extern void sub_81DA57C(void);
|
||||
extern u8 Overworld_GetFlashLevel(void);
|
||||
extern u16 sub_81A9AA8(u8 localId);
|
||||
extern u16 sub_81D6180(u8 localId);
|
||||
@@ -945,13 +945,13 @@ static void CB2_EndFirstBattle(void)
|
||||
static void sub_80B1218(void)
|
||||
{
|
||||
if (GetGameStat(GAME_STAT_WILD_BATTLES) % 60 == 0)
|
||||
sub_81DA57C();
|
||||
UpdateGymLeaderRematch();
|
||||
}
|
||||
|
||||
static void sub_80B1234(void)
|
||||
{
|
||||
if (GetGameStat(GAME_STAT_TRAINER_BATTLES) % 20 == 0)
|
||||
sub_81DA57C();
|
||||
UpdateGymLeaderRematch();
|
||||
}
|
||||
|
||||
// why not just use the macros? maybe its because they didnt want to uncast const every time?
|
||||
|
||||
@@ -3,10 +3,10 @@
|
||||
#include "random.h"
|
||||
#include "event_data.h"
|
||||
#include "battle_setup.h"
|
||||
#include "trainer_rematch.h"
|
||||
#include "gym_leader_rematch.h"
|
||||
|
||||
static void sub_81DA5D4(const u16 *data, size_t size, u32 a2);
|
||||
static s32 sub_81DA6CC(u32 trainerIdx);
|
||||
static void UpdateGymLeaderRematchFromArray(const u16 *data, size_t size, u32 maxRematch);
|
||||
static s32 GetRematchIndex(u32 trainerIdx);
|
||||
|
||||
static const u16 GymLeaderRematches_AfterNewMauville[] = {
|
||||
REMATCH_ROXANNE,
|
||||
@@ -30,60 +30,61 @@ static const u16 GymLeaderRematches_BeforeNewMauville[] = {
|
||||
REMATCH_JUAN
|
||||
};
|
||||
|
||||
void sub_81DA57C(void)
|
||||
void UpdateGymLeaderRematch(void)
|
||||
{
|
||||
if (FlagGet(FLAG_SYS_GAME_CLEAR) && (Random() % 100) <= 30)
|
||||
{
|
||||
if (FlagGet(FLAG_0x05B))
|
||||
sub_81DA5D4(GymLeaderRematches_AfterNewMauville, ARRAY_COUNT(GymLeaderRematches_AfterNewMauville), 5);
|
||||
if (FlagGet(FLAG_WATTSON_REMATCH_AVAILABLE))
|
||||
UpdateGymLeaderRematchFromArray(GymLeaderRematches_AfterNewMauville, ARRAY_COUNT(GymLeaderRematches_AfterNewMauville), 5);
|
||||
else
|
||||
sub_81DA5D4(GymLeaderRematches_BeforeNewMauville, ARRAY_COUNT(GymLeaderRematches_BeforeNewMauville), 1);
|
||||
UpdateGymLeaderRematchFromArray(GymLeaderRematches_BeforeNewMauville, ARRAY_COUNT(GymLeaderRematches_BeforeNewMauville), 1);
|
||||
}
|
||||
}
|
||||
|
||||
static void sub_81DA5D4(const u16 *data, size_t size, u32 a2)
|
||||
static void UpdateGymLeaderRematchFromArray(const u16 *data, size_t size, u32 maxRematch)
|
||||
{
|
||||
s32 r6 = 0;
|
||||
s32 r8 = 5;
|
||||
s32 whichLeader = 0;
|
||||
s32 lowestRematchIndex = 5;
|
||||
u32 i;
|
||||
s32 rematchIndex;
|
||||
for (i = 0; i < size; i++)
|
||||
{
|
||||
if (!gSaveBlock1Ptr->trainerRematches[data[i]])
|
||||
{
|
||||
s32 val = sub_81DA6CC(data[i]);
|
||||
if (r8 > val)
|
||||
r8 = val;
|
||||
r6++;
|
||||
rematchIndex = GetRematchIndex(data[i]);
|
||||
if (lowestRematchIndex > rematchIndex)
|
||||
lowestRematchIndex = rematchIndex;
|
||||
whichLeader++;
|
||||
}
|
||||
}
|
||||
if (r6 != 0 && r8 <= a2)
|
||||
if (whichLeader != 0 && lowestRematchIndex <= maxRematch)
|
||||
{
|
||||
r6 = 0;
|
||||
whichLeader = 0;
|
||||
for (i = 0; i < size; i++)
|
||||
{
|
||||
if (!gSaveBlock1Ptr->trainerRematches[data[i]])
|
||||
{
|
||||
s32 val = sub_81DA6CC(data[i]);
|
||||
if (val == r8)
|
||||
r6++;
|
||||
rematchIndex = GetRematchIndex(data[i]);
|
||||
if (rematchIndex == lowestRematchIndex)
|
||||
whichLeader++;
|
||||
}
|
||||
}
|
||||
if (r6 != 0)
|
||||
if (whichLeader != 0)
|
||||
{
|
||||
r6 = Random() % r6;
|
||||
whichLeader = Random() % whichLeader;
|
||||
for (i = 0; i < size; i++)
|
||||
{
|
||||
if (!gSaveBlock1Ptr->trainerRematches[data[i]])
|
||||
{
|
||||
s32 val = sub_81DA6CC(data[i]);
|
||||
if (val == r8)
|
||||
rematchIndex = GetRematchIndex(data[i]);
|
||||
if (rematchIndex == lowestRematchIndex)
|
||||
{
|
||||
if (r6 == 0)
|
||||
if (whichLeader == 0)
|
||||
{
|
||||
gSaveBlock1Ptr->trainerRematches[data[i]] = r8;
|
||||
gSaveBlock1Ptr->trainerRematches[data[i]] = lowestRematchIndex;
|
||||
break;
|
||||
}
|
||||
r6--;
|
||||
whichLeader--;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -91,7 +92,7 @@ static void sub_81DA5D4(const u16 *data, size_t size, u32 a2)
|
||||
}
|
||||
}
|
||||
|
||||
static s32 sub_81DA6CC(u32 trainerIdx)
|
||||
static s32 GetRematchIndex(u32 trainerIdx)
|
||||
{
|
||||
s32 i;
|
||||
for (i = 0; i < 5; i++)
|
||||
Reference in New Issue
Block a user