From fac48e608a225a335639719daaa860ecf6521b2f Mon Sep 17 00:00:00 2001 From: lhearachel Date: Sun, 22 Oct 2023 19:51:31 -0700 Subject: [PATCH 1/3] Label struct+fields: UnkStruct_ov12_02237728 -> BallThrow --- include/overlay012/ov12_02235E94.h | 2 +- include/overlay012/struct_ov12_02237728.h | 24 ++--- src/overlay012/ov12_02235E94.c | 126 +++++++++++----------- src/overlay016/battle_script.c | 28 ++--- src/overlay016/ov16_0225BFFC.c | 20 ++-- src/overlay016/ov16_0225CBB8.c | 96 ++++++++--------- src/overlay017/ov17_02247A48.c | 18 ++-- src/overlay076/ov76_0223D338.c | 44 ++++---- 8 files changed, 179 insertions(+), 179 deletions(-) diff --git a/include/overlay012/ov12_02235E94.h b/include/overlay012/ov12_02235E94.h index e01ad93496..cc344533b3 100644 --- a/include/overlay012/ov12_02235E94.h +++ b/include/overlay012/ov12_02235E94.h @@ -24,7 +24,7 @@ BOOL ov12_02236764(UnkStruct_ov12_02236648 * param0); void ov12_02236780(UnkStruct_ov12_02236648 * param0); void ov12_022368C8(BallRotation * param0, int param1); BOOL ov12_022368D0(BallRotation * param0, int param1); -BallRotation * ov12_02237728(UnkStruct_ov12_02237728 * param0); +BallRotation * ov12_02237728(BallThrow * param0); BOOL ov12_022377F8(BallRotation * param0); BOOL ov12_02237810(BallRotation * param0); void ov12_02237828(BallRotation * param0, int param1); diff --git a/include/overlay012/struct_ov12_02237728.h b/include/overlay012/struct_ov12_02237728.h index d537b9e662..571dbfca7e 100644 --- a/include/overlay012/struct_ov12_02237728.h +++ b/include/overlay012/struct_ov12_02237728.h @@ -5,17 +5,17 @@ #include "struct_decls/struct_0200C6E4_decl.h" #include "struct_decls/battle_system.h" -typedef struct { - int unk_00; - int unk_04; - int unk_08; - int unk_0C; - int unk_10; - int unk_14; - int unk_18; - UnkStruct_0200C6E4 * unk_1C; - PaletteSys * unk_20; - BattleSystem * unk_24; -} UnkStruct_ov12_02237728; +typedef struct BallThrow { + int type; + int heapID; + int mode; + int target; + int ballID; + int bgPrio; + int surface; + UnkStruct_0200C6E4 *cellActorSys; + PaletteSys *paletteSys; + BattleSystem *battleSys; +} BallThrow; #endif // POKEPLATINUM_STRUCT_OV12_02237728_H diff --git a/src/overlay012/ov12_02235E94.c b/src/overlay012/ov12_02235E94.c index 5ae9075897..1ee3bd0bef 100644 --- a/src/overlay012/ov12_02235E94.c +++ b/src/overlay012/ov12_02235E94.c @@ -105,7 +105,7 @@ typedef struct BallRotation { CellActorData * unk_30; UnkStruct_ov12_02225D50 unk_34; UnkStruct_ov12_02225F6C unk_48[2]; - UnkStruct_ov12_02237728 unk_90; + BallThrow unk_90; UnkStruct_ov12_02237C54_sub1 unk_B8; SysTask * unk_CC; UnkStruct_ov12_02236648 * unk_D0; @@ -1111,14 +1111,14 @@ static BOOL ov12_02236918 (BallRotation * param0) { UnkStruct_ov12_02236690 v0; - v0.unk_04 = param0->unk_90.unk_10; - v0.unk_08 = param0->unk_90.unk_04; + v0.unk_04 = param0->unk_90.ballID; + v0.unk_08 = param0->unk_90.heapID; v0.unk_0C = 0xFF; v0.unk_10 = 0; sub_0200D550(param0->unk_30, &v0.unk_00, &v0.unk_02); - param0->unk_D8 = ov12_02223764(param0->unk_90.unk_24, param0->unk_90.unk_04); + param0->unk_D8 = ov12_02223764(param0->unk_90.battleSys, param0->unk_90.heapID); param0->unk_D0 = ov12_02236690(&v0); } param0->unk_08++; @@ -1213,13 +1213,13 @@ static BOOL ov12_02236A6C (BallRotation * param0) int v0; v0 = sub_0200D43C(param0->unk_30); - sub_02003178(param0->unk_90.unk_20, 0x4, 1 << v0, -1, 0, 12, 0x37F); + sub_02003178(param0->unk_90.paletteSys, 0x4, 1 << v0, -1, 0, 12, 0x37F); param0->unk_08++; } break; case 1: - if (sub_0200384C(param0->unk_90.unk_20) != 0) { + if (sub_0200384C(param0->unk_90.paletteSys) != 0) { break; } @@ -1227,13 +1227,13 @@ static BOOL ov12_02236A6C (BallRotation * param0) int v1; v1 = sub_0200D43C(param0->unk_30); - sub_02003178(param0->unk_90.unk_20, 0x4, 1 << v1, -1, 12, 0, 0x37F); + sub_02003178(param0->unk_90.paletteSys, 0x4, 1 << v1, -1, 12, 0, 0x37F); } param0->unk_08++; break; default: - if (sub_0200384C(param0->unk_90.unk_20) != 0) { + if (sub_0200384C(param0->unk_90.paletteSys) != 0) { break; } @@ -1455,21 +1455,21 @@ static BOOL ov12_02236D18 (BallRotation * param0) int v0; v0 = sub_0200D43C(param0->unk_30); - sub_02003178(param0->unk_90.unk_20, 0x4, 1 << v0, -5, 0, 10, 0x0); + sub_02003178(param0->unk_90.paletteSys, 0x4, 1 << v0, -5, 0, 10, 0x0); param0->unk_08++; } break; case 1: - if (sub_0200384C(param0->unk_90.unk_20) != 0) { + if (sub_0200384C(param0->unk_90.paletteSys) != 0) { break; } { UnkStruct_ov12_02236690 v1; - v1.unk_04 = param0->unk_90.unk_10; - v1.unk_08 = param0->unk_90.unk_04; + v1.unk_04 = param0->unk_90.ballID; + v1.unk_08 = param0->unk_90.heapID; v1.unk_0C = ov12_02235FB4(v1.unk_04); v1.unk_10 = 0; @@ -1492,7 +1492,7 @@ static BOOL ov12_02236D18 (BallRotation * param0) } break; default: - if (sub_0200384C(param0->unk_90.unk_20) != 0) { + if (sub_0200384C(param0->unk_90.paletteSys) != 0) { break; } @@ -1516,12 +1516,12 @@ static BOOL ov12_02236E0C (BallRotation * param0) int v0; v0 = sub_0200D43C(param0->unk_30); - sub_02003178(param0->unk_90.unk_20, 0x4, 1 << v0, -5, 10, 0, 0x0); + sub_02003178(param0->unk_90.paletteSys, 0x4, 1 << v0, -5, 10, 0, 0x0); } param0->unk_08++; break; case 1: - if (sub_0200384C(param0->unk_90.unk_20) != 0) { + if (sub_0200384C(param0->unk_90.paletteSys) != 0) { break; } @@ -1631,7 +1631,7 @@ static BOOL ov12_02236F24 (BallRotation * param0) { int v0; - if (ov12_02235EB0(param0->unk_90.unk_00) == 1) { + if (ov12_02235EB0(param0->unk_90.type) == 1) { v0 = (LCRNG_Next() % 20) + 10; sub_0200D7C0(param0->unk_30, 0x2000 * v0); @@ -1639,26 +1639,26 @@ static BOOL ov12_02236F24 (BallRotation * param0) } break; case 1: - if (ov12_02235EB0(param0->unk_90.unk_00) == 1) { + if (ov12_02235EB0(param0->unk_90.type) == 1) { sub_0200D7C0(param0->unk_30, 0x2000); if (param0->unk_B8.unk_0C > ((param0->unk_B8.unk_08 / 2) + 10)) { sub_0200D7C0(param0->unk_30, 0x2000); } - if (ov12_02235EF0(param0->unk_90.unk_00) == 1) { + if (ov12_02235EF0(param0->unk_90.type) == 1) { if (param0->unk_B8.unk_0C == ((param0->unk_B8.unk_08 / 2) + 10)) { int v1; v1 = sub_0200D43C(param0->unk_30); - param0->unk_D4 = ov12_02226870(param0->unk_90.unk_20, param0->unk_90.unk_04, 2, v1 * 16, 16, -2, 2, 0, 14, 0xFFFF, 1002); + param0->unk_D4 = ov12_02226870(param0->unk_90.paletteSys, param0->unk_90.heapID, 2, v1 * 16, 16, -2, 2, 0, 14, 0xFFFF, 1002); } } } param0->unk_B8.unk_0C++; - if ((param0->unk_90.unk_00 >= 6) && (param0->unk_90.unk_00 <= 8)) { + if ((param0->unk_90.type >= 6) && (param0->unk_90.type <= 8)) { if ((param0->unk_B8.unk_0C > (param0->unk_B8.unk_08 / 2)) && (param0->unk_B8.unk_0C < ((param0->unk_B8.unk_08 / 2) + 5))) { break; } @@ -1670,7 +1670,7 @@ static BOOL ov12_02236F24 (BallRotation * param0) } break; case 2: - if ((ov12_02235EF0(param0->unk_90.unk_00) == 1) && (param0->unk_D4 != NULL)) { + if ((ov12_02235EF0(param0->unk_90.type) == 1) && (param0->unk_D4 != NULL)) { if (ov12_02226848(param0->unk_D4) == 1) { break; } @@ -1680,12 +1680,12 @@ static BOOL ov12_02236F24 (BallRotation * param0) return 0; } else { - if (param0->unk_90.unk_00 >= 15) { + if (param0->unk_90.type >= 15) { param0->unk_28 = 1; return 0; } - if (param0->unk_90.unk_10 == (0xFF + 18)) { + if (param0->unk_90.ballID == (0xFF + 18)) { sub_02005728(2024, 117); } @@ -1703,9 +1703,9 @@ static BOOL ov12_02236F24 (BallRotation * param0) { int v2; - if ((param0->unk_90.unk_00 != 12) && (param0->unk_90.unk_00 != 13)) { + if ((param0->unk_90.type != 12) && (param0->unk_90.type != 13)) { v2 = sub_0200D43C(param0->unk_30); - param0->unk_D4 = ov12_02226870(param0->unk_90.unk_20, param0->unk_90.unk_04, 2, v2 * 16, 16, -2, 2, 0, 14, 0xFFFF, 1002); + param0->unk_D4 = ov12_02226870(param0->unk_90.paletteSys, param0->unk_90.heapID, 2, v2 * 16, 16, -2, 2, 0, 14, 0xFFFF, 1002); } } param0->unk_28 = 1; @@ -1715,7 +1715,7 @@ static BOOL ov12_02236F24 (BallRotation * param0) break; } - if ((param0->unk_90.unk_00 != 12) && (param0->unk_90.unk_00 != 13)) { + if ((param0->unk_90.type != 12) && (param0->unk_90.type != 13)) { if (ov12_02226848(param0->unk_D4) == 1) { break; } @@ -1742,7 +1742,7 @@ static BOOL ov12_022371E4 (BallRotation * param0) { int v0; - if (ov12_02235EB0(param0->unk_90.unk_00) == 1) { + if (ov12_02235EB0(param0->unk_90.type) == 1) { v0 = (LCRNG_Next() % 20) + 10; sub_0200D7C0(param0->unk_30, 0x2000 * v0); @@ -1750,26 +1750,26 @@ static BOOL ov12_022371E4 (BallRotation * param0) } break; case 1: - if (ov12_02235EB0(param0->unk_90.unk_00) == 1) { + if (ov12_02235EB0(param0->unk_90.type) == 1) { sub_0200D7C0(param0->unk_30, 0x2000); if (param0->unk_B8.unk_0C > ((param0->unk_B8.unk_08 / 2) + 10)) { sub_0200D7C0(param0->unk_30, 0x2000); } - if (ov12_02235EF0(param0->unk_90.unk_00) == 1) { + if (ov12_02235EF0(param0->unk_90.type) == 1) { if (param0->unk_B8.unk_0C == ((param0->unk_B8.unk_08 / 2) + 10)) { int v1; v1 = sub_0200D43C(param0->unk_30); - param0->unk_D4 = ov12_02226870(param0->unk_90.unk_20, param0->unk_90.unk_04, 2, v1 * 16, 16, -2, 2, 0, 14, 0xFFFF, 1002); + param0->unk_D4 = ov12_02226870(param0->unk_90.paletteSys, param0->unk_90.heapID, 2, v1 * 16, 16, -2, 2, 0, 14, 0xFFFF, 1002); } } } param0->unk_B8.unk_0C++; - if ((param0->unk_90.unk_00 >= 6) && (param0->unk_90.unk_00 <= 8)) { + if ((param0->unk_90.type >= 6) && (param0->unk_90.type <= 8)) { if ((param0->unk_B8.unk_0C > (param0->unk_B8.unk_08 / 2)) && (param0->unk_B8.unk_0C < ((param0->unk_B8.unk_08 / 2) + 5))) { break; } @@ -1781,7 +1781,7 @@ static BOOL ov12_022371E4 (BallRotation * param0) } break; case 2: - if ((ov12_02235EF0(param0->unk_90.unk_00) == 1) && (param0->unk_D4 != NULL)) { + if ((ov12_02235EF0(param0->unk_90.type) == 1) && (param0->unk_D4 != NULL)) { if (ov12_02226848(param0->unk_D4) == 1) { break; } @@ -1791,7 +1791,7 @@ static BOOL ov12_022371E4 (BallRotation * param0) return 0; } else { - if (param0->unk_90.unk_00 >= 15) { + if (param0->unk_90.type >= 15) { param0->unk_28 = 1; return 0; @@ -1814,7 +1814,7 @@ static BOOL ov12_022371E4 (BallRotation * param0) int v2; v2 = sub_0200D43C(param0->unk_30); - param0->unk_D4 = ov12_02226870(param0->unk_90.unk_20, param0->unk_90.unk_04, 2, v2 * 16, 16, -2, 2, 0, 14, 0xFFFF, 1002); + param0->unk_D4 = ov12_02226870(param0->unk_90.paletteSys, param0->unk_90.heapID, 2, v2 * 16, 16, -2, 2, 0, 14, 0xFFFF, 1002); } param0->unk_28 = 1; @@ -1871,8 +1871,8 @@ static BOOL ov12_02237474 (BallRotation * param0) { UnkStruct_ov12_02236690 v0; - v0.unk_04 = param0->unk_90.unk_10; - v0.unk_08 = param0->unk_90.unk_04; + v0.unk_04 = param0->unk_90.ballID; + v0.unk_08 = param0->unk_90.heapID; v0.unk_0C = 0xFF; v0.unk_10 = 1; @@ -1995,7 +1995,7 @@ static void ov12_022376D0 (SysTask * param0, void * param1) return; } - v0 = Unk_ov12_0223AB84[v1->unk_90.unk_08](v1); + v0 = Unk_ov12_0223AB84[v1->unk_90.mode](v1); if (v0 == 0) { v1->unk_1C = 0; @@ -2008,11 +2008,11 @@ static void ov12_022376D0 (SysTask * param0, void * param1) sub_0200C7EC(v1->unk_2C); } -BallRotation * ov12_02237728 (UnkStruct_ov12_02237728 * param0) +BallRotation * ov12_02237728 (BallThrow * param0) { BallRotation * v0 = NULL; - v0 = Heap_AllocFromHeap(param0->unk_04, sizeof(BallRotation)); + v0 = Heap_AllocFromHeap(param0->heapID, sizeof(BallRotation)); MI_CpuClear8(v0, sizeof(BallRotation)); GF_ASSERT(v0 != NULL); @@ -2025,9 +2025,9 @@ BallRotation * ov12_02237728 (UnkStruct_ov12_02237728 * param0) v0->unk_18 = 0; v0->unk_00 = 0; v0->unk_04 = 0; - v0->unk_2C = sub_0200C704(v0->unk_90.unk_1C); + v0->unk_2C = sub_0200C704(v0->unk_90.cellActorSys); v0->unk_DC = 0; - v0->unk_24 = ov12_02235F2C(v0->unk_90.unk_00); + v0->unk_24 = ov12_02235F2C(v0->unk_90.type); v0->unk_B8.unk_0C = 0; v0->unk_20 = 16; v0->unk_21 = 0; @@ -2081,11 +2081,11 @@ BOOL ov12_0223782C (BallRotation * param0, int param1) void ov12_0223783C (BallRotation * param0) { - int v0 = param0->unk_90.unk_04; + int v0 = param0->unk_90.heapID; GF_ASSERT(param0 != NULL); - sub_0200D0B0(param0->unk_90.unk_1C, param0->unk_2C); + sub_0200D0B0(param0->unk_90.cellActorSys, param0->unk_2C); sub_0200D0F4(param0->unk_30); SysTask_Done(param0->unk_CC); Heap_FreeToHeap(param0); @@ -2093,7 +2093,7 @@ void ov12_0223783C (BallRotation * param0) void ov12_0223786C (BallRotation * param0, int param1) { - param0->unk_90.unk_08 = param1; + param0->unk_90.mode = param1; param0->unk_08 = 0; param0->unk_0C = 0; param0->unk_10 = 0; @@ -2106,14 +2106,14 @@ int ov12_02237890 (BallRotation * param0) { GF_ASSERT(param0 != NULL); - return param0->unk_90.unk_08; + return param0->unk_90.mode; } static void ov12_022378A0 (BallRotation * param0) { sub_0200D550(param0->unk_30, ¶m0->unk_B8.unk_00, ¶m0->unk_B8.unk_02); - switch (param0->unk_90.unk_00) { + switch (param0->unk_90.type) { case 0: case 1: case 2: @@ -2201,7 +2201,7 @@ static void ov12_022378A0 (BallRotation * param0) static void ov12_02237B14 (BallRotation * param0, s16 * param1, s16 * param2) { - switch (param0->unk_90.unk_00) { + switch (param0->unk_90.type) { case 0: ov12_02225864(0, 0, param1, param2); (*param2) += (32 + 8); @@ -2275,10 +2275,10 @@ static void ov12_02237C54 (BallRotation * param0) int v2; int v3; - sub_0200C7C0(param0->unk_90.unk_1C, param0->unk_2C, 10); + sub_0200C7C0(param0->unk_90.cellActorSys, param0->unk_2C, 10); - if (param0->unk_90.unk_18 == 0) { - sub_0200964C(sub_0200C738(param0->unk_90.unk_1C), 0, ((192 + 80) << FX32_SHIFT)); + if (param0->unk_90.surface == 0) { + sub_0200964C(sub_0200C738(param0->unk_90.cellActorSys), 0, ((192 + 80) << FX32_SHIFT)); } { @@ -2292,23 +2292,23 @@ static void ov12_02237C54 (BallRotation * param0) v5.val1[4] = 0; v5.val1[5] = 0; - sub_0200CB30(param0->unk_90.unk_1C, param0->unk_2C, &v5); + sub_0200CB30(param0->unk_90.cellActorSys, param0->unk_2C, &v5); } - v0 = ov12_02235FC8(param0->unk_90.unk_10, 0); - v1 = ov12_02235FC8(param0->unk_90.unk_10, 1); - v2 = ov12_02235FC8(param0->unk_90.unk_10, 2); - v3 = ov12_02235FC8(param0->unk_90.unk_10, 3); + v0 = ov12_02235FC8(param0->unk_90.ballID, 0); + v1 = ov12_02235FC8(param0->unk_90.ballID, 1); + v2 = ov12_02235FC8(param0->unk_90.ballID, 2); + v3 = ov12_02235FC8(param0->unk_90.ballID, 3); { NARC * v6; - v6 = NARC_ctor(NARC_INDEX_BATTLE__GRAPHIC__PL_BATT_OBJ, param0->unk_90.unk_04); + v6 = NARC_ctor(NARC_INDEX_BATTLE__GRAPHIC__PL_BATT_OBJ, param0->unk_90.heapID); - sub_0200CC3C(param0->unk_90.unk_1C, param0->unk_2C, v6, v0, 1, NNS_G2D_VRAM_TYPE_2DMAIN, param0->unk_90.unk_0C + 6000); - sub_0200CDC4(param0->unk_90.unk_20, 2, param0->unk_90.unk_1C, param0->unk_2C, v6, v1, 0, NNS_G2D_VRAM_TYPE_2DMAIN, 1, param0->unk_90.unk_0C + 6000); - sub_0200CE24(param0->unk_90.unk_1C, param0->unk_2C, v6, v2, 1, param0->unk_90.unk_0C + 6000); - sub_0200CE54(param0->unk_90.unk_1C, param0->unk_2C, v6, v3, 1, param0->unk_90.unk_0C + 6000); + sub_0200CC3C(param0->unk_90.cellActorSys, param0->unk_2C, v6, v0, 1, NNS_G2D_VRAM_TYPE_2DMAIN, param0->unk_90.target + 6000); + sub_0200CDC4(param0->unk_90.paletteSys, 2, param0->unk_90.cellActorSys, param0->unk_2C, v6, v1, 0, NNS_G2D_VRAM_TYPE_2DMAIN, 1, param0->unk_90.target + 6000); + sub_0200CE24(param0->unk_90.cellActorSys, param0->unk_2C, v6, v2, 1, param0->unk_90.target + 6000); + sub_0200CE54(param0->unk_90.cellActorSys, param0->unk_2C, v6, v3, 1, param0->unk_90.target + 6000); NARC_dtor(v6); } } @@ -2326,14 +2326,14 @@ static void ov12_02237D8C (BallRotation * param0) v1.unk_08 = 0; v1.unk_0C = 0; v1.unk_10 = 1; - v1.unk_2C = param0->unk_90.unk_14; + v1.unk_2C = param0->unk_90.bgPrio; v1.unk_30 = 0; for (v0 = 0; v0 < 6; v0++) { - v1.unk_14[v0] = param0->unk_90.unk_0C + 6000; + v1.unk_14[v0] = param0->unk_90.target + 6000; } - param0->unk_30 = sub_0200CE6C(param0->unk_90.unk_1C, param0->unk_2C, &v1); + param0->unk_30 = sub_0200CE6C(param0->unk_90.cellActorSys, param0->unk_2C, &v1); sub_0200D3F4(param0->unk_30, 1); sub_0200D6A4(param0->unk_30, 2); diff --git a/src/overlay016/battle_script.c b/src/overlay016/battle_script.c index a3d07ef002..71001ec08b 100644 --- a/src/overlay016/battle_script.c +++ b/src/overlay016/battle_script.c @@ -9057,26 +9057,26 @@ static void ov16_02249B80 (SysTask * param0, void * param1) case 0: if (v2->flag == 0) { { - UnkStruct_ov12_02237728 v7; - - v7.unk_08 = 3; - v7.unk_04 = 5; - v7.unk_0C = v1 + 20000; - v7.unk_10 = v2->ball; - v7.unk_1C = ov16_0223E010(v2->battleSys); - v7.unk_20 = BattleSystem_PaletteSys(v2->battleSys); - v7.unk_14 = 1; - v7.unk_18 = 0; - v7.unk_24 = v2->battleSys; + BallThrow v7; + + v7.mode = 3; + v7.heapID = 5; + v7.target = v1 + 20000; + v7.ballID = v2->ball; + v7.cellActorSys = ov16_0223E010(v2->battleSys); + v7.paletteSys = BattleSystem_PaletteSys(v2->battleSys); + v7.bgPrio = 1; + v7.surface = 0; + v7.battleSys = v2->battleSys; if (BattleSystem_BattleType(v2->battleSys) & 0x2) { if (v1 == 1) { - v7.unk_00 = 16; + v7.type = 16; } else { - v7.unk_00 = 17; + v7.type = 17; } } else { - v7.unk_00 = 15; + v7.type = 15; } v2->ballRotation = ov12_02237728(&v7); diff --git a/src/overlay016/ov16_0225BFFC.c b/src/overlay016/ov16_0225BFFC.c index 152e870aa8..a7fe360d32 100644 --- a/src/overlay016/ov16_0225BFFC.c +++ b/src/overlay016/ov16_0225BFFC.c @@ -175,7 +175,7 @@ BattlerData * ov16_0225BFFC (BattleSystem * param0, UnkStruct_ov16_0223C2C0 * pa void ov16_0225C038 (BattleSystem * param0, BattlerData * param1, int param2, int param3) { - UnkStruct_ov12_02237728 v0; + BallThrow v0; s16 v1, v2; if (BattleSystem_BattleType(param0) & (0x20 | 0x200)) { @@ -186,15 +186,15 @@ void ov16_0225C038 (BattleSystem * param0, BattlerData * param1, int param2, int return; } - v0.unk_00 = Unk_ov16_0226F174[param1->battlerType]; - v0.unk_04 = 5; - v0.unk_08 = 4; - v0.unk_0C = param1->unk_190; - v0.unk_10 = param2; - v0.unk_1C = ov16_0223E010(param0); - v0.unk_20 = BattleSystem_PaletteSys(param0); - v0.unk_18 = 0; - v0.unk_14 = 1; + v0.type = Unk_ov16_0226F174[param1->battlerType]; + v0.heapID = 5; + v0.mode = 4; + v0.target = param1->unk_190; + v0.ballID = param2; + v0.cellActorSys = ov16_0223E010(param0); + v0.paletteSys = BattleSystem_PaletteSys(param0); + v0.surface = 0; + v0.bgPrio = 1; param1->unk_84 = ov12_02237728(&v0); diff --git a/src/overlay016/ov16_0225CBB8.c b/src/overlay016/ov16_0225CBB8.c index 716dd03579..d662b5fb91 100644 --- a/src/overlay016/ov16_0225CBB8.c +++ b/src/overlay016/ov16_0225CBB8.c @@ -2016,21 +2016,21 @@ static void ov16_0225F0C0 (SysTask * param0, void * param1) switch (v0->unk_83) { case 0: { - UnkStruct_ov12_02237728 v2; + BallThrow v2; - v2.unk_00 = Unk_ov16_0226F174[v0->unk_82]; - v2.unk_04 = 5; - v2.unk_0C = v0->unk_81; - v2.unk_10 = v0->unk_8E; - v2.unk_1C = ov16_0223E010(v0->unk_00); - v2.unk_20 = BattleSystem_PaletteSys(v0->unk_00); - v2.unk_14 = 1; - v2.unk_18 = 0; + v2.type = Unk_ov16_0226F174[v0->unk_82]; + v2.heapID = 5; + v2.target = v0->unk_81; + v2.ballID = v0->unk_8E; + v2.cellActorSys = ov16_0223E010(v0->unk_00); + v2.paletteSys = BattleSystem_PaletteSys(v0->unk_00); + v2.bgPrio = 1; + v2.surface = 0; if (v0->unk_94 == 1) { - v2.unk_08 = 1; + v2.mode = 1; } else { - v2.unk_08 = 0; + v2.mode = 0; } v0->unk_0C = ov12_02237728(&v2); @@ -2271,33 +2271,33 @@ static void ov16_0225F764 (SysTask * param0, void * param1) case 4: if (v0->unk_6A & 0x1) { { - UnkStruct_ov12_02237728 v5; - - v5.unk_00 = Unk_ov16_0226F174[v0->unk_6A]; - v5.unk_04 = 5; - v5.unk_08 = 5; - v5.unk_0C = v0->unk_69; - v5.unk_10 = v0->unk_6E; - v5.unk_1C = ov16_0223E010(v0->unk_00); - v5.unk_20 = BattleSystem_PaletteSys(v0->unk_00); - v5.unk_14 = 1; - v5.unk_18 = 0; + BallThrow v5; + + v5.type = Unk_ov16_0226F174[v0->unk_6A]; + v5.heapID = 5; + v5.mode = 5; + v5.target = v0->unk_69; + v5.ballID = v0->unk_6E; + v5.cellActorSys = ov16_0223E010(v0->unk_00); + v5.paletteSys = BattleSystem_PaletteSys(v0->unk_00); + v5.bgPrio = 1; + v5.surface = 0; v0->unk_0C = ov12_02237728(&v5); } } else { { - UnkStruct_ov12_02237728 v6; + BallThrow v6; int v7[] = {0, 1, 2, 3, 4, 5}; - v6.unk_00 = v7[v0->unk_6A]; - v6.unk_04 = 5; - v6.unk_08 = 5; - v6.unk_0C = v0->unk_69; - v6.unk_10 = v0->unk_6E; - v6.unk_1C = ov16_0223E010(v0->unk_00); - v6.unk_20 = BattleSystem_PaletteSys(v0->unk_00); - v6.unk_14 = 1; - v6.unk_18 = 0; + v6.type = v7[v0->unk_6A]; + v6.heapID = 5; + v6.mode = 5; + v6.target = v0->unk_69; + v6.ballID = v0->unk_6E; + v6.cellActorSys = ov16_0223E010(v0->unk_00); + v6.paletteSys = BattleSystem_PaletteSys(v0->unk_00); + v6.bgPrio = 1; + v6.surface = 0; v0->unk_0C = ov12_02237728(&v6); } } @@ -2605,39 +2605,39 @@ static void ov16_0225FD5C (SysTask * param0, void * param1) v0->unk_0A = 1; } else { { - UnkStruct_ov12_02237728 v6; + BallThrow v6; switch (v0->unk_10) { default: case 1: - v6.unk_00 = 15; + v6.type = 15; v0->unk_18 = 3; - v6.unk_10 = 5; + v6.ballID = 5; break; case 2: - v6.unk_00 = 12; + v6.type = 12; v0->unk_18 = 0; - v6.unk_10 = (0xFF + 18); + v6.ballID = (0xFF + 18); break; case 3: - v6.unk_00 = 13; + v6.type = 13; v0->unk_18 = 0; - v6.unk_10 = (0xFF + 19); + v6.ballID = (0xFF + 19); break; case 4: - v6.unk_00 = 15; + v6.type = 15; v0->unk_18 = 3; - v6.unk_10 = (0xFF + 17); + v6.ballID = (0xFF + 17); break; } - v6.unk_04 = 5; - v6.unk_08 = 4; - v6.unk_0C = v0->unk_09; - v6.unk_1C = ov16_0223E010(v0->unk_00); - v6.unk_20 = BattleSystem_PaletteSys(v0->unk_00); - v6.unk_18 = 0; - v6.unk_24 = v0->unk_00; + v6.heapID = 5; + v6.mode = 4; + v6.target = v0->unk_09; + v6.cellActorSys = ov16_0223E010(v0->unk_00); + v6.paletteSys = BattleSystem_PaletteSys(v0->unk_00); + v6.surface = 0; + v6.battleSys = v0->unk_00; v0->unk_04->unk_84 = ov12_02237728(&v6); diff --git a/src/overlay017/ov17_02247A48.c b/src/overlay017/ov17_02247A48.c index 27d38710e0..85e62bf9c3 100644 --- a/src/overlay017/ov17_02247A48.c +++ b/src/overlay017/ov17_02247A48.c @@ -1027,15 +1027,15 @@ static void ov17_02248A24 (SysTask * param0, void * param1) break; case 1: { - UnkStruct_ov12_02237728 v1; - - v1.unk_00 = 14; - v1.unk_04 = 22; - v1.unk_08 = 0; - v1.unk_0C = 0; - v1.unk_1C = v0->unk_00->unk_0C.unk_1C; - v1.unk_20 = v0->unk_00->unk_0C.unk_44; - v1.unk_14 = 1; + BallThrow v1; + + v1.type = 14; + v1.heapID = 22; + v1.mode = 0; + v1.target = 0; + v1.cellActorSys = v0->unk_00->unk_0C.unk_1C; + v1.paletteSys = v0->unk_00->unk_0C.unk_44; + v1.bgPrio = 1; v0->unk_04 = ov12_02237728(&v1); } diff --git a/src/overlay076/ov76_0223D338.c b/src/overlay076/ov76_0223D338.c index 38bda9bea4..06d994a3a0 100644 --- a/src/overlay076/ov76_0223D338.c +++ b/src/overlay076/ov76_0223D338.c @@ -855,17 +855,17 @@ static BOOL ov76_0223DF94 (UnkStruct_ov76_0223DE00 * param0) } { - UnkStruct_ov12_02237728 v0; - - v0.unk_00 = 1; - v0.unk_04 = 53; - v0.unk_08 = 0; - v0.unk_0C = 0xFF; - v0.unk_14 = 0; - v0.unk_18 = 1; - v0.unk_1C = param0->unk_D4.unk_08; - v0.unk_20 = param0->unk_D4.unk_14; - v0.unk_10 = Pokemon_GetValue(param0->unk_428, MON_DATA_POKEBALL, NULL); + BallThrow v0; + + v0.type = 1; + v0.heapID = 53; + v0.mode = 0; + v0.target = 0xFF; + v0.bgPrio = 0; + v0.surface = 1; + v0.cellActorSys = param0->unk_D4.unk_08; + v0.paletteSys = param0->unk_D4.unk_14; + v0.ballID = Pokemon_GetValue(param0->unk_428, MON_DATA_POKEBALL, NULL); param0->unk_D4.unk_158 = ov12_02237728(&v0); param0->unk_3DC++; @@ -945,17 +945,17 @@ static BOOL ov76_0223DF94 (UnkStruct_ov76_0223DE00 * param0) param0->unk_3E0 = 0; { - UnkStruct_ov12_02237728 v5; - - v5.unk_00 = 1; - v5.unk_04 = 53; - v5.unk_08 = 5; - v5.unk_0C = 0xFF; - v5.unk_14 = 0; - v5.unk_18 = 1; - v5.unk_1C = param0->unk_D4.unk_08; - v5.unk_20 = param0->unk_D4.unk_14; - v5.unk_10 = Pokemon_GetValue(param0->unk_428, MON_DATA_POKEBALL, NULL); + BallThrow v5; + + v5.type = 1; + v5.heapID = 53; + v5.mode = 5; + v5.target = 0xFF; + v5.bgPrio = 0; + v5.surface = 1; + v5.cellActorSys = param0->unk_D4.unk_08; + v5.paletteSys = param0->unk_D4.unk_14; + v5.ballID = Pokemon_GetValue(param0->unk_428, MON_DATA_POKEBALL, NULL); param0->unk_D4.unk_158 = ov12_02237728(&v5); From d2c301cc4550f7157e7e3285a2e567738c31ea23 Mon Sep 17 00:00:00 2001 From: lhearachel Date: Sun, 22 Oct 2023 20:29:33 -0700 Subject: [PATCH 2/3] Document battle terrain, time, and species-caught checks --- include/constants/battle/terrain.h | 35 +++++++++++++++++++++++++++++ include/constants/time.h | 12 ++++++++++ include/overlay016/ov16_0223DF00.h | 32 +++++++++++++++++++++++--- include/struct_defs/battle_system.h | 9 +++++--- include/unk_0202631C.h | 2 +- src/overlay016/battle_script.c | 14 ++++++------ src/overlay016/ov16_0223B140.c | 14 ++++++------ src/overlay016/ov16_0223DF00.c | 34 ++++++++++++++-------------- src/overlay016/ov16_0225177C.c | 2 +- src/overlay016/ov16_0225CBB8.c | 2 +- src/overlay016/ov16_0226485C.c | 6 ++--- src/overlay021/ov21_021D3208.c | 4 ++-- src/unk_0202631C.c | 8 +++---- src/unk_0202CD50.c | 2 +- 14 files changed, 126 insertions(+), 50 deletions(-) create mode 100644 include/constants/battle/terrain.h create mode 100644 include/constants/time.h diff --git a/include/constants/battle/terrain.h b/include/constants/battle/terrain.h new file mode 100644 index 0000000000..9f0a242bd4 --- /dev/null +++ b/include/constants/battle/terrain.h @@ -0,0 +1,35 @@ +#ifndef POKEPLATINUM_CONSTANTS_BATTLE_TERRAIN_H +#define POKEPLATINUM_CONSTANTS_BATTLE_TERRAIN_H + +enum Terrain { + TERRAIN_PLAIN = 0, + TERRAIN_SAND, + TERRAIN_GRASS, + TERRAIN_PUDDLE, + TERRAIN_MOUNTAIN, + TERRAIN_CAVE, + TERRAIN_SNOW, + TERRAIN_WATER, + TERRAIN_ICE, + TERRAIN_BUILDING, + TERRAIN_GREAT_MARSH, + TERRAIN_BRIDGE, + + TERRAIN_AARON, + TERRAIN_BERTHA, + TERRAIN_FLINT, + TERRAIN_LUCIAN, + TERRAIN_CYNTHIA, + + TERRAIN_DISTORTION_WORLD, + TERRAIN_BATTLE_TOWER, + TERRAIN_BATTLE_FACTORY, + TERRAIN_BATTLE_ARCADE, + TERRAIN_BATTLE_CASTLE, + TERRAIN_BATTLE_HALL, + TERRAIN_GIRATINA, + + TERRAIN_MAX +}; + +#endif // POKEPLATINUM_CONSTANTS_BATTLE_TERRAIN_H \ No newline at end of file diff --git a/include/constants/time.h b/include/constants/time.h new file mode 100644 index 0000000000..007737e2ea --- /dev/null +++ b/include/constants/time.h @@ -0,0 +1,12 @@ +#ifndef POKEPLATINUM_CONSTANTS_TIME_H +#define POKEPLATINUM_CONSTANTS_TIME_H + +enum Time { + TIME_MORNING = 0, + TIME_DAY, + TIME_DUSK, + TIME_NIGHT, + TIME_MIDNIGHT, +}; + +#endif // POKEPLATINUM_CONSTANTS_TIME_H \ No newline at end of file diff --git a/include/overlay016/ov16_0223DF00.h b/include/overlay016/ov16_0223DF00.h index d3d6a7e3e3..4e8895b650 100644 --- a/include/overlay016/ov16_0223DF00.h +++ b/include/overlay016/ov16_0223DF00.h @@ -1,6 +1,9 @@ #ifndef POKEPLATINUM_OV16_0223DF00_H #define POKEPLATINUM_OV16_0223DF00_H +#include "constants/battle/terrain.h" +#include "constants/time.h" + #include "struct_decls/struct_02002F38_decl.h" #include "struct_decls/struct_02007768_decl.h" #include "struct_decls/struct_02007C7C_decl.h" @@ -119,7 +122,14 @@ u8 BattleSystem_BattlerSlot(BattleSystem * param0, int param1); u8 Battler_Side(BattleSystem * param0, int param1); void * ov16_0223E220(BattleSystem * param0); PCBoxes * ov16_0223E228(BattleSystem * param0); -int ov16_0223E22C(BattleSystem * param0); + +/** + * @brief Get the terrain type for the battle. + * + * @param battleSys + * @return The battle's terrain. + */ +enum Terrain BattleSystem_Terrain(BattleSystem *battleSys); int ov16_0223E240(BattleSystem * param0); int BattleSystem_MapHeader(BattleSystem * param0); int BattleSystem_Partner(BattleSystem * param0, int param1); @@ -139,7 +149,14 @@ int BattleSystem_Partner(BattleSystem * param0, int param1); int BattleSystem_EnemyInSlot(BattleSystem *battleSys, int attacker, int slot); BOOL ov16_0223E30C(BattleSystem * param0, int param1, int param2, int param3, int param4); u32 BattleSystem_BattleStatus(BattleSystem * param0); -int ov16_0223EBF8(BattleSystem * param0); + +/** + * @brief Get the time of day. + * + * @param battleSys + * @return The time of day (e.g., morning, day, night) + */ +enum Time BattleSystem_Time(BattleSystem *battleSys); int ov16_0223EC04(BattleSystem * param0); u8 ov16_0223EC58(BattleSystem * param0, int param1, u8 param2); u16 ov16_0223ECC4(BattleParams * param0, int * param1, int * param2); @@ -226,7 +243,16 @@ void BattleSystem_SetGaugePriority(BattleSystem * param0, int param1); u32 ov16_0223F904(Party * param0, TrainerInfo * param1); void BattleSystem_DexFlagSeen(BattleSystem * param0, int param1); void ov16_0223F9A0(BattleSystem * param0, int param1); -BOOL ov16_0223F9E0(BattleSystem * param0, int param1); + +/** + * @brief Checks if the player has previously caught a member of this species. + * + * @param battleSys + * @param species + * @return TRUE if the player has previously caught a member of the given species, + * FALSE if not. + */ +BOOL BattleSystem_CaughtSpecies(BattleSystem *battleSys, int species); void ov16_0223F9F0(void); u8 ov16_0223F9FC(BattleSystem * param0, int param1, int param2, int param3, int param4); u8 BattleMessage_Print(BattleSystem * param0, MessageLoader * param1, BattleMessage * param2, int param3); diff --git a/include/struct_defs/battle_system.h b/include/struct_defs/battle_system.h index 0b7a65e771..d6880ae895 100644 --- a/include/struct_defs/battle_system.h +++ b/include/struct_defs/battle_system.h @@ -1,6 +1,9 @@ #ifndef POKEPLATINUM_STRUCT_BATTLE_SYSTEM_T_H #define POKEPLATINUM_STRUCT_BATTLE_SYSTEM_T_H +#include "constants/battle/terrain.h" +#include "constants/time.h" + #include "struct_decls/struct_02002F38_decl.h" #include "struct_decls/struct_02007768_decl.h" #include "message.h" @@ -59,7 +62,7 @@ struct BattleSystem { TrainerInfo * unk_48[4]; UnkStruct_0207D3C0 * unk_58; UnkStruct_0207D99C * unk_5C; - UnkStruct_02026324 * unk_60; + UnkStruct_02026324 *pokedex; PCBoxes * unk_64; Party *parties[4]; UnkStruct_0202CC84 * unk_78[4]; @@ -110,11 +113,11 @@ struct BattleSystem { u8 unk_23FB_2 : 1; u8 unk_23FB_3 : 2; u8 unk_23FB_5 : 3; - int unk_23FC; + enum Terrain terrain; int unk_2400; int unk_2404; u32 battleStatusMask; - int unk_240C; + enum Time time; int safariBalls; u8 unk_2414[4]; u32 unk_2418; diff --git a/include/unk_0202631C.h b/include/unk_0202631C.h index 0382a17713..cd8fe99043 100644 --- a/include/unk_0202631C.h +++ b/include/unk_0202631C.h @@ -18,7 +18,7 @@ BOOL sub_02026EF4(const UnkStruct_02026324 * param0); BOOL sub_02026F0C(const UnkStruct_02026324 * param0); u16 sub_02026F20(const UnkStruct_02026324 * param0); u16 sub_02026F58(const UnkStruct_02026324 * param0); -BOOL sub_02026F9C(const UnkStruct_02026324 * param0, u16 param1); +BOOL Pokedex_CaughtSpecies(const UnkStruct_02026324 * param0, u16 param1); BOOL sub_02026FE8(const UnkStruct_02026324 * param0, u16 param1); u32 sub_0202702C(const UnkStruct_02026324 * param0, u8 param1); u32 sub_02027058(const UnkStruct_02026324 * param0, u16 param1, int param2); diff --git a/src/overlay016/battle_script.c b/src/overlay016/battle_script.c index 71001ec08b..a1fb956a6b 100644 --- a/src/overlay016/battle_script.c +++ b/src/overlay016/battle_script.c @@ -7090,7 +7090,7 @@ static BOOL ov16_022479E8 (BattleSystem * param0, BattleContext * param1) return 0; } - v1 = ov16_0223E22C(param0); + v1 = BattleSystem_Terrain(param0); if (v1 > 12) { v1 = 12; @@ -7130,7 +7130,7 @@ static BOOL ov16_02247A80 (BattleSystem * param0, BattleContext * param1) int v0; BattleScript_Iter(param1, 1); - v0 = ov16_0223E22C(param0); + v0 = BattleSystem_Terrain(param0); if (v0 > 12) { v0 = 12; @@ -7163,7 +7163,7 @@ static BOOL ov16_02247AB0 (BattleSystem * param0, BattleContext * param1) BattleScript_Iter(param1, 1); - v0 = ov16_0223E22C(param0); + v0 = BattleSystem_Terrain(param0); if (v0 > 12) { v0 = 12; @@ -9215,7 +9215,7 @@ static void ov16_02249B80 (SysTask * param0, void * param1) sub_02003178(v4, (0x1 | 0x2 | 0x4 | 0x8), 0xffff, 1, 0, 16, 0x0); sub_0200872C(v5, 0, 16, 0, 0x0); v2->seqNum = 32; - } else if (ov16_0223F9E0(v2->battleSys, Pokemon_GetValue(v3, MON_DATA_SPECIES, NULL))) { + } else if (BattleSystem_CaughtSpecies(v2->battleSys, Pokemon_GetValue(v3, MON_DATA_SPECIES, NULL))) { sub_02015738(ov16_0223E220(v2->battleSys), 1); sub_02003178(v4, (0x1 | 0x4), 0xffff, 1, 0, 16, 0x0); sub_0200872C(v5, 0, 16, 0, 0x0); @@ -9660,7 +9660,7 @@ static int ov16_0224A724 (BattleSystem * param0, BattleContext * param1) } break; case 7: - if (ov16_0223E22C(param0) == 7) { + if (BattleSystem_Terrain(param0) == 7) { v4 = 35; } break; @@ -9674,7 +9674,7 @@ static int ov16_0224A724 (BattleSystem * param0, BattleContext * param1) } break; case 9: - if (ov16_0223F9E0(param0, param1->battleMons[param1->defender].species) == 1) { + if (BattleSystem_CaughtSpecies(param0, param1->battleMons[param1->defender].species) == 1) { v4 = 30; } break; @@ -9686,7 +9686,7 @@ static int ov16_0224A724 (BattleSystem * param0, BattleContext * param1) } break; case 13: - if ((ov16_0223EBF8(param0) == 3) || (ov16_0223EBF8(param0) == 4) || (ov16_0223E22C(param0) == 5)) { + if ((BattleSystem_Time(param0) == 3) || (BattleSystem_Time(param0) == 4) || (BattleSystem_Terrain(param0) == 5)) { v4 = 35; } break; diff --git a/src/overlay016/ov16_0223B140.c b/src/overlay016/ov16_0223B140.c index bc881243ba..8d4d4ef5e4 100644 --- a/src/overlay016/ov16_0223B140.c +++ b/src/overlay016/ov16_0223B140.c @@ -741,8 +741,8 @@ static void ov16_0223BCB4 (UnkStruct_020067E8 * param0) sub_02015760(v0->unk_1AC); sub_0207D3EC(v0->unk_58, v1->unk_E0); Heap_FreeToHeap(v0->unk_58); - sub_02026338(v0->unk_60, v1->unk_E8); - Heap_FreeToHeap(v0->unk_60); + sub_02026338(v0->pokedex, v1->unk_E8); + Heap_FreeToHeap(v0->pokedex); v1->unk_EC = v0->unk_64; v1->unk_E4 = v0->unk_5C; @@ -969,7 +969,7 @@ static void ov16_0223C210 (BattleSystem * param0) BattleContext * v3; Pokemon * v4; - v0 = ov16_0223E22C(param0); + v0 = BattleSystem_Terrain(param0); ov16_022686CC(¶m0->unk_17C[0], param0, 0, v0); ov16_022686CC(¶m0->unk_17C[1], param0, 1, v0); @@ -1094,8 +1094,8 @@ static void ov16_0223C2C0 (BattleSystem * param0, BattleParams * param1) param0->unk_58 = sub_0207D3C0(5); sub_0207D3EC(param1->unk_E0, param0->unk_58); - param0->unk_60 = sub_02026324(5); - sub_02026338(param1->unk_E8, param0->unk_60); + param0->pokedex = sub_02026324(5); + sub_02026338(param1->unk_E8, param0->pokedex); param0->unk_64 = param1->unk_EC; param0->unk_1B0 = param1->unk_108; @@ -1106,10 +1106,10 @@ static void ov16_0223C2C0 (BattleSystem * param0, BattleParams * param1) param0->unk_2420 = param1->unk_13C; param0->unk_9C = param1->unk_10C; param0->safariBalls = param1->unk_168; - param0->unk_23FC = param1->unk_12C; + param0->terrain = param1->unk_12C; param0->unk_2400 = param1->unk_128; param0->unk_2404 = param1->unk_130; - param0->unk_240C = param1->unk_138; + param0->time = param1->unk_138; param0->unk_2418 = param1->unk_16C; param0->unk_2424 = param1->unk_140; param0->unk_242C = param1->unk_144; diff --git a/src/overlay016/ov16_0223DF00.c b/src/overlay016/ov16_0223DF00.c index f77d6a05f6..1af0e98ecb 100644 --- a/src/overlay016/ov16_0223DF00.c +++ b/src/overlay016/ov16_0223DF00.c @@ -120,14 +120,14 @@ u8 BattleSystem_BattlerSlot(BattleSystem *battleSys, int battler); u8 Battler_Side(BattleSystem * param0, int param1); void * ov16_0223E220(BattleSystem * param0); PCBoxes * ov16_0223E228(BattleSystem * param0); -int ov16_0223E22C(BattleSystem * param0); +enum Terrain BattleSystem_Terrain(BattleSystem *battleSys); int ov16_0223E240(BattleSystem * param0); int BattleSystem_MapHeader(BattleSystem * param0); int BattleSystem_Partner(BattleSystem *battleSys, int battler); int BattleSystem_EnemyInSlot(BattleSystem *battleSys, int attacker, int slot); BOOL ov16_0223E30C(BattleSystem * param0, int param1, int param2, int param3, int param4); u32 ov16_0223EBEC(BattleSystem * param0); -int ov16_0223EBF8(BattleSystem * param0); +enum Time BattleSystem_Time(BattleSystem *battleSys); int ov16_0223EC04(BattleSystem * param0); u8 ov16_0223EC58(BattleSystem * param0, int param1, u8 param2); u16 ov16_0223ECC4(BattleParams * param0, int * param1, int * param2); @@ -205,7 +205,7 @@ void BattleSystem_SetGaugePriority(BattleSystem * param0, int param1); u32 ov16_0223F904(Party * param0, TrainerInfo * param1); void BattleSystem_DexFlagSeen(BattleSystem * param0, int param1); void ov16_0223F9A0(BattleSystem * param0, int param1); -BOOL ov16_0223F9E0(BattleSystem * param0, int param1); +BOOL BattleSystem_CaughtSpecies(BattleSystem *battleSys, int species); void ov16_0223F9F0(void); u8 ov16_0223F9FC(BattleSystem * param0, int param1, int param2, int param3, int param4); u8 BattleMessage_Print(BattleSystem * param0, MessageLoader * param1, BattleMessage * param2, int param3); @@ -366,7 +366,7 @@ PaletteSys * BattleSystem_PaletteSys (BattleSystem * param0) UnkStruct_02026324 * ov16_0223E068 (BattleSystem * param0) { - return param0->unk_60; + return param0->pokedex; } u8 * ov16_0223E06C (BattleSystem * param0) @@ -505,13 +505,13 @@ PCBoxes * ov16_0223E228 (BattleSystem * param0) return param0->unk_64; } -int ov16_0223E22C (BattleSystem * param0) +enum Terrain BattleSystem_Terrain(BattleSystem *battleSys) { - if ((param0->unk_23FC > 24) || (param0->unk_23FC < 0)) { - return 24; + if (battleSys->terrain > TERRAIN_MAX || battleSys->terrain < TERRAIN_PLAIN) { + return TERRAIN_MAX; } - return param0->unk_23FC; + return battleSys->terrain; } int ov16_0223E240 (BattleSystem * param0) @@ -918,9 +918,9 @@ u32 BattleSystem_BattleStatus (BattleSystem *battleSys) return battleSys->battleStatusMask; } -int ov16_0223EBF8 (BattleSystem * param0) +enum Time BattleSystem_Time(BattleSystem *battleSys) { - return param0->unk_240C; + return battleSys->time; } int ov16_0223EC04 (BattleSystem * param0) @@ -934,7 +934,7 @@ int ov16_0223EC04 (BattleSystem * param0) case 3: case 4: case 5: - switch (param0->unk_240C) { + switch (param0->time) { case 0: case 1: v0 = 0; @@ -1096,7 +1096,7 @@ void ov16_0223EE70 (BattleSystem * param0) v3 = Pokemon_GetValue(v2, MON_DATA_SPECIES_EGG, NULL); if ((v3 == 412) && (param0->unk_2414[0] & FlagIndex(v0))) { - switch (ov16_0223E22C(param0)) { + switch (BattleSystem_Terrain(param0)) { default: case 2: v1 = 0; @@ -1706,12 +1706,12 @@ void BattleSystem_DexFlagSeen (BattleSystem * param0, int param1) if ((param0->battleType & (0x4 | 0x80)) == 0) { if ((v0 & 0x1) || (param0->battleType == (0x2 | 0x8 | 0x40)) || (param0->battleType == ((0x2 | 0x1) | 0x8 | 0x40))) { - sub_020272A4(param0->unk_60, v1); + sub_020272A4(param0->pokedex, v1); } } if (((v0 & 0x1) == 0) && (Pokemon_GetValue(v1, MON_DATA_SPECIES_EGG, NULL) == 412)) { - sub_0202736C(param0->unk_60, v1); + sub_0202736C(param0->pokedex, v1); } } @@ -1730,15 +1730,15 @@ void ov16_0223F9A0 (BattleSystem * param0, int param1) v2 = BattleContext_Get(param0, param0->battleCtx, 2, param1); v1 = BattleSystem_PartyPokemon(param0, param1, v2); - sub_0202736C(param0->unk_60, v1); + sub_0202736C(param0->pokedex, v1); } } } } -BOOL ov16_0223F9E0 (BattleSystem * param0, int param1) +BOOL BattleSystem_CaughtSpecies(BattleSystem *battleSys, int species) { - return sub_02026F9C(param0->unk_60, param1); + return Pokedex_CaughtSpecies(battleSys->pokedex, species); } void ov16_0223F9F0 (void) diff --git a/src/overlay016/ov16_0225177C.c b/src/overlay016/ov16_0225177C.c index 9a1d1d1a40..2b01b994ee 100644 --- a/src/overlay016/ov16_0225177C.c +++ b/src/overlay016/ov16_0225177C.c @@ -6087,7 +6087,7 @@ void ov16_02259A5C (BattleSystem * param0, BattleContext * param1, Pokemon * par v0 = BattleSystem_TrainerInfo(param0, 0); v1 = BattleSystem_MapHeader(param0); - v2 = ov16_0223E22C(param0); + v2 = BattleSystem_Terrain(param0); if (BattleSystem_BattleType(param0) & 0x200) { v3 = Pokemon_GetValue(param2, MON_DATA_POKEBALL, NULL); diff --git a/src/overlay016/ov16_0225CBB8.c b/src/overlay016/ov16_0225CBB8.c index d662b5fb91..9e9a1505c8 100644 --- a/src/overlay016/ov16_0225CBB8.c +++ b/src/overlay016/ov16_0225CBB8.c @@ -5195,7 +5195,7 @@ static void ov16_02263014 (SysTask * param0, void * param1) v1 = BattleSystem_BGL(v0->unk_00); v2 = BattleSystem_PaletteSys(v0->unk_00); - v3 = ov16_0223E22C(v0->unk_00); + v3 = BattleSystem_Terrain(v0->unk_00); v4 = Unk_ov16_0226F1D0[ov16_0223E240(v0->unk_00)]; v0->unk_15++; diff --git a/src/overlay016/ov16_0226485C.c b/src/overlay016/ov16_0226485C.c index 264a909001..007ddcd34e 100644 --- a/src/overlay016/ov16_0226485C.c +++ b/src/overlay016/ov16_0226485C.c @@ -564,7 +564,7 @@ void BattleIO_SlideHPGaugeIn (BattleSystem * param0, BattleContext * param1, int v0.unk_08 = param1->battleMons[param2].exp - Pokemon_GetSpeciesBaseExpAt(v2, v3); v0.unk_0C = Pokemon_GetSpeciesBaseExpAt(v2, v3 + 1) - Pokemon_GetSpeciesBaseExpAt(v2, v3); - v0.unk_07_7 = ov16_0223F9E0(param0, param1->battleMons[param2].species); + v0.unk_07_7 = BattleSystem_CaughtSpecies(param0, param1->battleMons[param2].species); v0.unk_10 = BattleSystem_NumSafariBalls(param0); v0.unk_14 = param3; @@ -1251,7 +1251,7 @@ void BattleIO_RefreshHPGauge (BattleSystem * param0, BattleContext * param1, int v0.unk_08 = param1->battleMons[param2].exp - Pokemon_GetSpeciesBaseExpAt(v2, v3); v0.unk_0C = Pokemon_GetSpeciesBaseExpAt(v2, v3 + 1) - Pokemon_GetSpeciesBaseExpAt(v2, v3); - v0.unk_07_7 = ov16_0223F9E0(param0, param1->battleMons[param2].species); + v0.unk_07_7 = BattleSystem_CaughtSpecies(param0, param1->battleMons[param2].species); v0.unk_10 = BattleSystem_NumSafariBalls(param0); ov16_02264A04(param0, 1, param2, &v0, sizeof(UnkStruct_ov16_0225C468)); @@ -1676,7 +1676,7 @@ void ov16_02266B78 (BattleSystem * param0, BattleContext * param1, UnkStruct_ov1 param2->unk_16 = param6; param2->unk_4C = param3; param2->unk_50 = param4; - param2->unk_54 = ov16_0223E22C(param0); + param2->unk_54 = BattleSystem_Terrain(param0); if (param1 != NULL) { param2->unk_04 = param1->damage; diff --git a/src/overlay021/ov21_021D3208.c b/src/overlay021/ov21_021D3208.c index 2cd313a63d..dc3ac7032b 100644 --- a/src/overlay021/ov21_021D3208.c +++ b/src/overlay021/ov21_021D3208.c @@ -629,7 +629,7 @@ static void ov21_021D39E4 (u16 * param0, int * param1, const u16 * param2, int p if (param6 == 1) { break; } else { - if (sub_02026F9C(param7, param2[v0])) { + if (Pokedex_CaughtSpecies(param7, param2[v0])) { break; } } @@ -650,7 +650,7 @@ static void ov21_021D3A60 (UnkStruct_ov21_021D3A60 * param0, const UnkStruct_020 param0->unk_F6C = 0; for (v0 = 0; v0 < param3; v0++) { - if (sub_02026F9C(param1, param2[v0])) { + if (Pokedex_CaughtSpecies(param1, param2[v0])) { param0->unk_00[param0->unk_F6C].unk_04 = 2; } else { param0->unk_00[param0->unk_F6C].unk_04 = 1; diff --git a/src/unk_0202631C.c b/src/unk_0202631C.c index b83c118a87..31de966e0d 100644 --- a/src/unk_0202631C.c +++ b/src/unk_0202631C.c @@ -772,7 +772,7 @@ u16 sub_02026DD0 (const UnkStruct_02026324 * param0) v1 = 0; for (v0 = 1; v0 <= 493; v0++) { - if (sub_02026F9C(param0, v0) == 1) { + if (Pokedex_CaughtSpecies(param0, v0) == 1) { v1++; } } @@ -815,7 +815,7 @@ u16 sub_02026E64 (const UnkStruct_02026324 * param0) v1 = 0; for (v0 = 1; v0 <= 493; v0++) { - if (sub_02026F9C(param0, v0) == 1) { + if (Pokedex_CaughtSpecies(param0, v0) == 1) { if (sub_020775A4(v0) != 0) { v1++; } @@ -878,7 +878,7 @@ u16 sub_02026F20 (const UnkStruct_02026324 * param0) v1 = 0; for (v0 = 1; v0 <= 493; v0++) { - if (sub_02026F9C(param0, v0) == 1) { + if (Pokedex_CaughtSpecies(param0, v0) == 1) { if (sub_02026D44(v0) == 1) { v1++; } @@ -911,7 +911,7 @@ u16 sub_02026F58 (const UnkStruct_02026324 * param0) return v1; } -BOOL sub_02026F9C (const UnkStruct_02026324 * param0, u16 param1) +BOOL Pokedex_CaughtSpecies (const UnkStruct_02026324 * param0, u16 param1) { inline_02026DD0(param0); diff --git a/src/unk_0202CD50.c b/src/unk_0202CD50.c index 3c5e6a348b..d10f01c1f2 100644 --- a/src/unk_0202CD50.c +++ b/src/unk_0202CD50.c @@ -413,7 +413,7 @@ u32 sub_0202D034 (UnkStruct_0202CD88 * param0) void sub_0202D040 (UnkStruct_0202CD88 * param0, const UnkStruct_02026324 * param1, u16 const param2) { - if (!sub_02026F9C(param1, param2)) { + if (!Pokedex_CaughtSpecies(param1, param2)) { sub_0202CFEC(param0, 22); } } From 7584276155b19e4f1f8f0589e752824c801dbc52 Mon Sep 17 00:00:00 2001 From: lhearachel Date: Mon, 23 Oct 2023 00:18:10 -0700 Subject: [PATCH 3/3] Document the capture formula --- include/battle/battle_context.h | 2 +- include/constants/battle.h | 1 + src/overlay016/battle_controller.c | 8 +- src/overlay016/battle_script.c | 188 ++++++++++++++++------------- src/overlay016/ov16_0225177C.c | 2 +- 5 files changed, 110 insertions(+), 91 deletions(-) diff --git a/include/battle/battle_context.h b/include/battle/battle_context.h index 5486183963..9678f28008 100644 --- a/include/battle/battle_context.h +++ b/include/battle/battle_context.h @@ -286,7 +286,7 @@ struct BattleContext { int flingTemp; int flingScript; - u8 safariCatchCount; + u8 safariCatchStage; u8 safariEscapeCount; u8 runAttempts; u8 battleEndFlag; diff --git a/include/constants/battle.h b/include/constants/battle.h index 9f37fcc573..e5ba2aad5d 100644 --- a/include/constants/battle.h +++ b/include/constants/battle.h @@ -31,6 +31,7 @@ #define BATTLE_TYPE_NO_EXPERIENCE (BATTLE_TYPE_LINK | BATTLE_TYPE_SAFARI | BATTLE_TYPE_FRONTIER | BATTLE_TYPE_PAL_PARK) #define BATTLE_TYPE_NO_ABILITIES (BATTLE_TYPE_SAFARI | BATTLE_TYPE_PAL_PARK) #define BATTLE_TYPE_2vs2_TAG (BATTLE_TYPE_2vs2 | BATTLE_TYPE_TAG) +#define BATTLE_TYPE_ALWAYS_CATCH (BATTLE_TYPE_PAL_PARK | BATTLE_TYPE_CATCH_TUTORIAL) #define MAX_LINK_BATTLERS 4 #define MAX_BATTLERS 4 diff --git a/src/overlay016/battle_controller.c b/src/overlay016/battle_controller.c index bbddb61f82..455d79d2d4 100644 --- a/src/overlay016/battle_controller.c +++ b/src/overlay016/battle_controller.c @@ -2085,8 +2085,8 @@ static void BattleController_SafariBaitCommand(BattleSystem *battleSys, BattleCo battleCtx->scriptTemp = BattleSystem_RandNext(battleSys) % 10; // TODO: This 12 could use with a constant - if (battleCtx->safariCatchCount < 12) { - battleCtx->safariCatchCount++; + if (battleCtx->safariCatchStage < 12) { + battleCtx->safariCatchStage++; } if (battleCtx->scriptTemp != 0) { @@ -2113,8 +2113,8 @@ static void BattleController_SafariRockCommand(BattleSystem *battleSys, BattleCo if (battleCtx->scriptTemp != 0) { battleCtx->msgTemp = 1; - if (battleCtx->safariCatchCount) { - battleCtx->safariCatchCount--; + if (battleCtx->safariCatchStage) { + battleCtx->safariCatchStage--; } } } diff --git a/src/overlay016/battle_script.c b/src/overlay016/battle_script.c index a1fb956a6b..5e0a28e054 100644 --- a/src/overlay016/battle_script.c +++ b/src/overlay016/battle_script.c @@ -11,6 +11,7 @@ #include "constants/battle/message_tags.h" #include "constants/battle/side_effects.h" #include "constants/battle/system_control.h" +#include "constants/battle/terrain.h" #include "constants/narc_files/battle_skill_subseq.h" #include "struct_decls/struct_02002F38_decl.h" @@ -43,6 +44,7 @@ #include "struct_defs/trainer_data.h" #include "struct_defs/battle_system.h" #include "struct_defs/struct_0208737C.h" +#include "struct_defs/fraction.h" #include "overlay012/struct_ov12_02237728.h" #include "overlay016/struct_ov16_022431BC.h" #include "overlay016/struct_ov16_022431BC_1.h" @@ -353,7 +355,7 @@ static int BattleMessage_TrainerNameTag(BattleSystem *battleSys, BattleContext * static u32 ov16_022431BC(BattleSystem * param0, BattleContext * param1, int param2); static void BattleScript_CalcEffortValues(Party *party, int slot, int species, int form); -static int ov16_0224A724(BattleSystem * param0, BattleContext * param1); +static int BattleScript_CalcCatchShakes(BattleSystem *battleSys, BattleContext *battleCtx); static void BattleScript_LoadPartyLevelUpIcon(BattleSystem * param0, BattleScriptTaskData * param1, Pokemon * param2); static void BattleScript_FreePartyLevelUpIcon(BattleSystem * param0, BattleScriptTaskData * param1); static void BattleScript_UpdateFriendship(BattleSystem *battleSys, BattleContext *battleCtx, int faintingBattler); @@ -9128,7 +9130,7 @@ static void ov16_02249B80 (SysTask * param0, void * param1) case 2: if (--v2->tmpData[1] == 0) { ov16_02265050(v2->battleSys, v1, v2->ball); - v2->tmpData[2] = ov16_0224A724(v2->battleSys, v2->battleCtx); + v2->tmpData[2] = BattleScript_CalcCatchShakes(v2->battleSys, v2->battleCtx); if (v2->tmpData[2] < 4) { v2->tmpData[3] = v2->tmpData[2]; @@ -9604,140 +9606,156 @@ static void ov16_02249B80 (SysTask * param0, void * param1) } } -static const u8 Unk_ov16_0226E570[] = { - 0x14, - 0xF, - 0xA, - 0xF +static const u8 sBasicBallMod[] = { + 20, // ITEM_ULTRA_BALL + 15, // ITEM_GREAT_BALL + 10, // ITEM_POKE_BALL + 15, // ITEM_SAFARI_BALL }; -static const u8 Unk_ov16_0226E638[][2] = { - {0xA, 0x28}, - {0xA, 0x23}, - {0xA, 0x1E}, - {0xA, 0x19}, - {0xA, 0x14}, - {0xA, 0xF}, - {0xA, 0xA}, - {0xF, 0xA}, - {0x14, 0xA}, - {0x19, 0xA}, - {0x1E, 0xA}, - {0x23, 0xA}, - {0x28, 0xA} +static const struct Fraction sSafariCatchRate[] = { + { 10, 40 }, + { 10, 35 }, + { 10, 30 }, + { 10, 25 }, + { 10, 20 }, + { 10, 15 }, + { 10, 10 }, + { 15, 10 }, + { 20, 10 }, + { 25, 10 }, + { 30, 10 }, + { 35, 10 }, + { 40, 10 } }; -static int ov16_0224A724 (BattleSystem * param0, BattleContext * param1) +/** + * @brief Computes the number of times that a Poke Ball will "shake" when + * attempting to capture a wild Pokemon. + * + * This is, effectively, the capture formula. It performs all computations which + * factor into whether a given Pokemon will be caught or not, including the wild + * Pokemon's species, the type of ball being used, and Safari Zone mechanics. + * + * @param battleSys + * @param battleCtx + * @return The number of times that a Poke Ball will shake during a capture + * attempt. 4 shakes is defined as a successful capture. + */ +static int BattleScript_CalcCatchShakes(BattleSystem *battleSys, BattleContext *battleCtx) { - int v0; - u32 v1; - u32 v2; - u32 v3; - u32 v4; - int v5; - int v6; - - if (BattleSystem_BattleType(param0) & (0x200 | 0x400)) { + if (BattleSystem_BattleType(battleSys) & BATTLE_TYPE_ALWAYS_CATCH) { return 4; } - if (param1->msgItemTemp == 5) { - v3 = PokemonPersonalData_GetSpeciesValue(param1->battleMons[param1->defender].species, 8); - v3 = v3 * Unk_ov16_0226E638[param1->safariCatchCount][0] / Unk_ov16_0226E638[param1->safariCatchCount][1]; + u32 speciesMod; + if (battleCtx->msgItemTemp == ITEM_SAFARI_BALL) { + speciesMod = PokemonPersonalData_GetSpeciesValue(battleCtx->battleMons[battleCtx->defender].species, MON_DATA_PERSONAL_CATCH_RATE); + speciesMod = speciesMod * sSafariCatchRate[battleCtx->safariCatchStage].numerator / sSafariCatchRate[battleCtx->safariCatchStage].denominator; } else { - v3 = PokemonPersonalData_GetSpeciesValue(param1->battleMons[param1->defender].species, 8); + speciesMod = PokemonPersonalData_GetSpeciesValue(battleCtx->battleMons[battleCtx->defender].species, MON_DATA_PERSONAL_CATCH_RATE); } - v4 = 10; - v5 = BattleMon_Get(param1, param1->defender, 27, NULL); - v6 = BattleMon_Get(param1, param1->defender, 28, NULL); + u32 ballMod = 10; + int type1 = BattleMon_Get(battleCtx, battleCtx->defender, BATTLEMON_TYPE_1, NULL); + int type2 = BattleMon_Get(battleCtx, battleCtx->defender, BATTLEMON_TYPE_2, NULL); - if (param1->msgItemTemp > 5) { - switch (param1->msgItemTemp) { - case 6: - if ((v5 == 11) || (v6 == 11) || (v5 == 6) || (v6 == 6)) { - v4 = 30; + if (battleCtx->msgItemTemp > ITEM_SAFARI_BALL) { + switch (battleCtx->msgItemTemp) { + case ITEM_NET_BALL: + if (type1 == TYPE_WATER || type2 == TYPE_WATER + || type1 == TYPE_BUG || type2 == TYPE_BUG) { + ballMod = 30; } break; - case 7: - if (BattleSystem_Terrain(param0) == 7) { - v4 = 35; + + case ITEM_DIVE_BALL: + if (BattleSystem_Terrain(battleSys) == TERRAIN_WATER) { + ballMod = 35; } break; - case 8: - if (param1->battleMons[param1->defender].level < 40) { - v4 = 40 - param1->battleMons[param1->defender].level; - if (v4 < 10) { - v4 = 10; + case ITEM_NEST_BALL: + if (battleCtx->battleMons[battleCtx->defender].level < 40) { + ballMod = 40 - battleCtx->battleMons[battleCtx->defender].level; + + if (ballMod < 10) { + ballMod = 10; } } break; - case 9: - if (BattleSystem_CaughtSpecies(param0, param1->battleMons[param1->defender].species) == 1) { - v4 = 30; + + case ITEM_REPEAT_BALL: + if (BattleSystem_CaughtSpecies(battleSys, battleCtx->battleMons[battleCtx->defender].species) == TRUE) { + ballMod = 30; } break; - case 10: - v4 = 10 + param1->totalTurns; - if (v4 > 40) { - v4 = 40; + case ITEM_TIMER_BALL: + ballMod = 10 + battleCtx->totalTurns; + if (ballMod > 40) { + ballMod = 40; } break; - case 13: - if ((BattleSystem_Time(param0) == 3) || (BattleSystem_Time(param0) == 4) || (BattleSystem_Terrain(param0) == 5)) { - v4 = 35; + + case ITEM_DUSK_BALL: + if (BattleSystem_Time(battleSys) == TIME_NIGHT + || BattleSystem_Time(battleSys) == TIME_MIDNIGHT + || BattleSystem_Terrain(battleSys) == TERRAIN_CAVE) { + ballMod = 35; } break; - case 15: - if (param1->totalTurns < 1) { - v4 = 40; + + case ITEM_QUICK_BALL: + if (battleCtx->totalTurns < 1) { + ballMod = 40; } break; } } else { - v4 = Unk_ov16_0226E570[param1->msgItemTemp - 2]; + ballMod = sBasicBallMod[battleCtx->msgItemTemp - ITEM_ULTRA_BALL]; } - v1 = ((v3 * v4) / 10) * (param1->battleMons[param1->defender].maxHP * 3 - param1->battleMons[param1->defender].curHP * 2) / (param1->battleMons[param1->defender].maxHP * 3); + u32 catchRate = (speciesMod * ballMod / 10) + * (battleCtx->battleMons[battleCtx->defender].maxHP * 3 - battleCtx->battleMons[battleCtx->defender].curHP * 2) + / (battleCtx->battleMons[battleCtx->defender].maxHP * 3); - if (param1->battleMons[param1->defender].status & (0x7 | 0x20)) { - v1 *= 2; + if (battleCtx->battleMons[battleCtx->defender].status & (MON_CONDITION_SLEEP | MON_CONDITION_FREEZE)) { + catchRate *= 2; } - if (param1->battleMons[param1->defender].status & (0x8 | 0x40 | 0x10 | 0x80)) { - v1 = v1 * 15 / 10; + if (battleCtx->battleMons[battleCtx->defender].status & (MON_CONDITION_POISON | MON_CONDITION_BURN | MON_CONDITION_PARALYSIS | MON_CONDITION_TOXIC)) { + catchRate = catchRate * 15 / 10; } - if (v1 >= 255) { - v0 = 4; + int shakes; + if (catchRate >= 0xFF) { + shakes = 4; } else { - v2 = (255 << 16) / v1; - - CP_SetSqrt32(v2); + u32 sqrtRate = (0xFF << 16) / catchRate; + CP_SetSqrt32(sqrtRate); CP_WaitSqrt(); - v2 = CP_GetSqrtResult32(); - - CP_SetSqrt32(v2); + sqrtRate = CP_GetSqrtResult32(); + CP_SetSqrt32(sqrtRate); CP_WaitSqrt(); - v1 = CP_GetSqrtResult32(); - v1 = (65535 << 4) / v1; + catchRate = CP_GetSqrtResult32(); + catchRate = (0xFFFF << 4) / catchRate; - for (v0 = 0; v0 < 4; v0++) { - if (BattleSystem_RandNext(param0) >= v1) { + for (shakes = 0; shakes < 4; shakes++) { + if (BattleSystem_RandNext(battleSys) >= catchRate) { break; } } - if (param1->msgItemTemp == 1) { - v0 = 4; + if (battleCtx->msgItemTemp == ITEM_MASTER_BALL) { + shakes = 4; } } - return v0; + + return shakes; } /** diff --git a/src/overlay016/ov16_0225177C.c b/src/overlay016/ov16_0225177C.c index 2b01b994ee..41775094a8 100644 --- a/src/overlay016/ov16_0225177C.c +++ b/src/overlay016/ov16_0225177C.c @@ -2071,7 +2071,7 @@ void BattleContext_InitCounters (BattleSystem * param0, BattleContext * param1) param1->battlersSwitchingMask |= FlagIndex(3); } - param1->safariCatchCount = 6; + param1->safariCatchStage = 6; param1->safariEscapeCount = 6; }