diff options
author | PikalaxALT <pikalaxalt@gmail.com> | 2018-02-25 21:56:09 -0500 |
---|---|---|
committer | PikalaxALT <pikalaxalt@gmail.com> | 2018-02-25 21:56:09 -0500 |
commit | 6bfc8579adc1476b63d9d19e612fa6e665811bd1 (patch) | |
tree | e3deb95643e84b0e263cd85ebc2f711ea19f8b61 /src | |
parent | 5162393c166ab9a37ec22993df6588080f1a9aa0 (diff) |
Decompile trainer_rematch
Diffstat (limited to 'src')
-rw-r--r-- | src/trainer_rematch.c | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/src/trainer_rematch.c b/src/trainer_rematch.c new file mode 100644 index 000000000..8056396a0 --- /dev/null +++ b/src/trainer_rematch.c @@ -0,0 +1,97 @@ + +// Includes +#include "global.h" +#include "constants/flags.h" +#include "random.h" +#include "event_data.h" +#include "battle_setup.h" + +// Static type declarations + +// Static RAM declarations + +// Static ROM declarations + +void sub_81DA5D4(const u16 *data, size_t size, u32 a2); +s32 sub_81DA6CC(u32 trainerIdx); + +// .rodata + +const u16 gUnknown_0862AD34[] = {0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48}; +const u16 gUnknown_0862AD44[] = {0x41, 0x42, 0x44, 0x45, 0x46, 0x47, 0x48}; + +// .text + +void sub_81DA57C(void) +{ + if (FlagGet(FLAG_SYS_GAME_CLEAR) && (Random() % 100) <= 30) + { + if (FlagGet(FLAG_0x05B)) + sub_81DA5D4(gUnknown_0862AD34, ARRAY_COUNT(gUnknown_0862AD34), 5); + else + sub_81DA5D4(gUnknown_0862AD44, ARRAY_COUNT(gUnknown_0862AD44), 1); + } +} + +void sub_81DA5D4(const u16 *data, size_t size, u32 a2) +{ + s32 r6 = 0; + s32 r8 = 5; + u32 i; + for (i = 0; i < size; i++) + { + if (!gSaveBlock1Ptr->trainerRematches[data[i]]) + { + s32 val = sub_81DA6CC(data[i]); + if (r8 > val) + r8 = val; + r6++; + } + } + if (r6 != 0 && r8 <= a2) + { + r6 = 0; + for (i = 0; i < size; i++) + { + if (!gSaveBlock1Ptr->trainerRematches[data[i]]) + { + s32 val = sub_81DA6CC(data[i]); + if (val == r8) + r6++; + } + } + if (r6 != 0) + { + r6 = Random() % r6; + for (i = 0; i < size; i++) + { + if (!gSaveBlock1Ptr->trainerRematches[data[i]]) + { + s32 val = sub_81DA6CC(data[i]); + if (val == r8) + { + if (r6 == 0) + { + gSaveBlock1Ptr->trainerRematches[data[i]] = r8; + break; + } + r6--; + } + } + } + } + } +} + +s32 sub_81DA6CC(u32 trainerIdx) +{ + s32 i; + for (i = 0; i < 5; i++) + { + if (!HasTrainerBeenFought(gRematchTable[trainerIdx].trainerIds[i])) + { + return i; + } + } + return 5; +} |