summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPikalaxALT <pikalaxalt@gmail.com>2018-02-26 08:23:17 -0500
committerPikalaxALT <pikalaxalt@gmail.com>2018-02-26 08:23:17 -0500
commitf46e941f306a3f9b6a527e33f3657657da0436cb (patch)
tree3f9c4825730ba54c1bca2f256b0b50f5775d9ea6 /src
parent80906f022b3908e220f33c6b3aea1091e1dde57a (diff)
Name functions, variables, and that one flag constant
Diffstat (limited to 'src')
-rw-r--r--src/battle_setup.c6
-rw-r--r--src/gym_leader_rematch.c (renamed from src/trainer_rematch.c)55
2 files changed, 31 insertions, 30 deletions
diff --git a/src/battle_setup.c b/src/battle_setup.c
index fcc0b2e0e..fa1eb7edc 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 "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?
diff --git a/src/trainer_rematch.c b/src/gym_leader_rematch.c
index 676cfa087..355ae5534 100644
--- a/src/trainer_rematch.c
+++ b/src/gym_leader_rematch.c
@@ -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++)