Name functions, variables, and that one flag constant

This commit is contained in:
PikalaxALT 2018-02-26 08:23:17 -05:00
parent 80906f022b
commit f46e941f30
7 changed files with 37 additions and 36 deletions

View File

@ -3134,7 +3134,7 @@ _081639FC:
bl __umodsi3 bl __umodsi3
cmp r0, 0 cmp r0, 0
bne _08163A78 bne _08163A78
bl sub_81DA57C bl UpdateGymLeaderRematch
b _08163A78 b _08163A78
.pool .pool
_08163A2C: _08163A2C:

View File

@ -16,7 +16,7 @@ MauvilleCity_MapScript1_1DF38B: @ 81DF38B
MauvilleCity_EventScript_1DF3A9:: @ 81DF3A9 MauvilleCity_EventScript_1DF3A9:: @ 81DF3A9
clearflag FLAG_0x391 clearflag FLAG_0x391
setflag FLAG_0x390 setflag FLAG_0x390
setflag FLAG_0x05B setflag FLAG_WATTSON_REMATCH_AVAILABLE
return return
MauvilleCity_EventScript_1DF3B3:: @ 81DF3B3 MauvilleCity_EventScript_1DF3B3:: @ 81DF3B3

View File

@ -91,7 +91,7 @@
#define FLAG_0x058 0x58 #define FLAG_0x058 0x58
#define FLAG_0x059 0x59 #define FLAG_0x059 0x59
#define FLAG_0x05A 0x5A #define FLAG_0x05A 0x5A
#define FLAG_0x05B 0x5B #define FLAG_WATTSON_REMATCH_AVAILABLE 0x5B
#define FLAG_0x05C 0x5C #define FLAG_0x05C 0x5C
#define FLAG_0x05D 0x5D #define FLAG_0x05D 0x5D
#define FLAG_0x05E 0x5E #define FLAG_0x05E 0x5E

View File

@ -82,6 +82,6 @@ enum {
REMATCH_WALLACE REMATCH_WALLACE
}; };
void sub_81DA57C(void); void UpdateGymLeaderRematch(void);
#endif //GUARD_TRAINER_REMATCH_H #endif //GUARD_TRAINER_REMATCH_H

View File

@ -267,7 +267,7 @@ SECTIONS {
src/rayquaza_scene.o(.text); src/rayquaza_scene.o(.text);
src/walda_phrase.o(.text); src/walda_phrase.o(.text);
asm/contest_link_81D9DE4.o(.text); asm/contest_link_81D9DE4.o(.text);
src/trainer_rematch.o(.text); src/gym_leader_rematch.o(.text);
src/unk_transition.o(.text); src/unk_transition.o(.text);
src/international_string_util.o(.text); src/international_string_util.o(.text);
asm/international_string_util.o(.text); asm/international_string_util.o(.text);
@ -536,7 +536,7 @@ SECTIONS {
data/pokenav.o(.rodata); data/pokenav.o(.rodata);
src/rayquaza_scene.o(.rodata); src/rayquaza_scene.o(.rodata);
src/walda_phrase.o(.rodata); src/walda_phrase.o(.rodata);
src/trainer_rematch.o(.rodata); src/gym_leader_rematch.o(.rodata);
data/unk_transition.o(.rodata); data/unk_transition.o(.rodata);
src/unk_transition.o(.rodata); src/unk_transition.o(.rodata);
data/text_input_strings.o(.rodata); data/text_input_strings.o(.rodata);

View File

@ -31,6 +31,7 @@
#include "string_util.h" #include "string_util.h"
#include "overworld.h" #include "overworld.h"
#include "field_weather.h" #include "field_weather.h"
#include "gym_leader_rematch.h"
enum enum
{ {
@ -66,7 +67,6 @@ extern void Overworld_ClearSavedMusic(void);
extern void CB2_WhiteOut(void); extern void CB2_WhiteOut(void);
extern void sub_80AF6F0(void); extern void sub_80AF6F0(void);
extern void PlayBattleBGM(void); extern void PlayBattleBGM(void);
extern void sub_81DA57C(void);
extern u8 Overworld_GetFlashLevel(void); extern u8 Overworld_GetFlashLevel(void);
extern u16 sub_81A9AA8(u8 localId); extern u16 sub_81A9AA8(u8 localId);
extern u16 sub_81D6180(u8 localId); extern u16 sub_81D6180(u8 localId);
@ -945,13 +945,13 @@ static void CB2_EndFirstBattle(void)
static void sub_80B1218(void) static void sub_80B1218(void)
{ {
if (GetGameStat(GAME_STAT_WILD_BATTLES) % 60 == 0) if (GetGameStat(GAME_STAT_WILD_BATTLES) % 60 == 0)
sub_81DA57C(); UpdateGymLeaderRematch();
} }
static void sub_80B1234(void) static void sub_80B1234(void)
{ {
if (GetGameStat(GAME_STAT_TRAINER_BATTLES) % 20 == 0) 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? // why not just use the macros? maybe its because they didnt want to uncast const every time?

View File

@ -3,10 +3,10 @@
#include "random.h" #include "random.h"
#include "event_data.h" #include "event_data.h"
#include "battle_setup.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 void UpdateGymLeaderRematchFromArray(const u16 *data, size_t size, u32 maxRematch);
static s32 sub_81DA6CC(u32 trainerIdx); static s32 GetRematchIndex(u32 trainerIdx);
static const u16 GymLeaderRematches_AfterNewMauville[] = { static const u16 GymLeaderRematches_AfterNewMauville[] = {
REMATCH_ROXANNE, REMATCH_ROXANNE,
@ -30,60 +30,61 @@ static const u16 GymLeaderRematches_BeforeNewMauville[] = {
REMATCH_JUAN REMATCH_JUAN
}; };
void sub_81DA57C(void) void UpdateGymLeaderRematch(void)
{ {
if (FlagGet(FLAG_SYS_GAME_CLEAR) && (Random() % 100) <= 30) if (FlagGet(FLAG_SYS_GAME_CLEAR) && (Random() % 100) <= 30)
{ {
if (FlagGet(FLAG_0x05B)) if (FlagGet(FLAG_WATTSON_REMATCH_AVAILABLE))
sub_81DA5D4(GymLeaderRematches_AfterNewMauville, ARRAY_COUNT(GymLeaderRematches_AfterNewMauville), 5); UpdateGymLeaderRematchFromArray(GymLeaderRematches_AfterNewMauville, ARRAY_COUNT(GymLeaderRematches_AfterNewMauville), 5);
else 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 whichLeader = 0;
s32 r8 = 5; s32 lowestRematchIndex = 5;
u32 i; u32 i;
s32 rematchIndex;
for (i = 0; i < size; i++) for (i = 0; i < size; i++)
{ {
if (!gSaveBlock1Ptr->trainerRematches[data[i]]) if (!gSaveBlock1Ptr->trainerRematches[data[i]])
{ {
s32 val = sub_81DA6CC(data[i]); rematchIndex = GetRematchIndex(data[i]);
if (r8 > val) if (lowestRematchIndex > rematchIndex)
r8 = val; lowestRematchIndex = rematchIndex;
r6++; whichLeader++;
} }
} }
if (r6 != 0 && r8 <= a2) if (whichLeader != 0 && lowestRematchIndex <= maxRematch)
{ {
r6 = 0; whichLeader = 0;
for (i = 0; i < size; i++) for (i = 0; i < size; i++)
{ {
if (!gSaveBlock1Ptr->trainerRematches[data[i]]) if (!gSaveBlock1Ptr->trainerRematches[data[i]])
{ {
s32 val = sub_81DA6CC(data[i]); rematchIndex = GetRematchIndex(data[i]);
if (val == r8) if (rematchIndex == lowestRematchIndex)
r6++; whichLeader++;
} }
} }
if (r6 != 0) if (whichLeader != 0)
{ {
r6 = Random() % r6; whichLeader = Random() % whichLeader;
for (i = 0; i < size; i++) for (i = 0; i < size; i++)
{ {
if (!gSaveBlock1Ptr->trainerRematches[data[i]]) if (!gSaveBlock1Ptr->trainerRematches[data[i]])
{ {
s32 val = sub_81DA6CC(data[i]); rematchIndex = GetRematchIndex(data[i]);
if (val == r8) if (rematchIndex == lowestRematchIndex)
{ {
if (r6 == 0) if (whichLeader == 0)
{ {
gSaveBlock1Ptr->trainerRematches[data[i]] = r8; gSaveBlock1Ptr->trainerRematches[data[i]] = lowestRematchIndex;
break; 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; s32 i;
for (i = 0; i < 5; i++) for (i = 0; i < 5; i++)