From 183a7168975a5291dc29166cafc15c1f0261e00c Mon Sep 17 00:00:00 2001 From: lhearachel Date: Sat, 28 Oct 2023 13:54:55 -0700 Subject: [PATCH] Document App_PixelCount, BattleSystem_CanStealItem, and BattleSystem_CanWhirlwind --- include/overlay016/ov16_0225177C.h | 29 ++++++++++++++++++-- include/unk_0208C098.h | 11 +++++++- src/overlay010/ov10_0221F800.c | 2 +- src/overlay013/ov13_0221FC20.c | 2 +- src/overlay013/ov13_02221A88.c | 2 +- src/overlay016/battle_script.c | 8 +++--- src/overlay016/ov16_0225177C.c | 44 ++++++++++++------------------ src/unk_020819DC.c | 2 +- src/unk_0208C098.c | 15 ++++------ src/unk_0208C324.c | 4 +-- 10 files changed, 71 insertions(+), 48 deletions(-) diff --git a/include/overlay016/ov16_0225177C.h b/include/overlay016/ov16_0225177C.h index fbb37010b3..bc1b2bf095 100644 --- a/include/overlay016/ov16_0225177C.h +++ b/include/overlay016/ov16_0225177C.h @@ -389,9 +389,34 @@ int ov16_022558CC(u8 param0, u8 param1, u8 param2); */ BOOL Move_IsInvoker(u16 move); BOOL BattleSystem_IsGhostCurse(BattleContext * param0, u16 param1, int param2); -BOOL ov16_02255980(BattleSystem * param0, BattleContext * param1, int param2); + +/** + * @brief Determine if a battler's item can be stolen. + * + * @param battleSys + * @param battleCtx + * @param battler + * @return FALSE + */ +BOOL BattleSystem_CanStealItem(BattleSystem *battleSys, BattleContext *battleCtx, int battler); BOOL ov16_022559DC(BattleContext * param0, int param1); -BOOL ov16_022559FC(BattleSystem * param0, BattleContext * param1); + +/** + * @brief Determine if a target can be Whirlwinded away by an attacker. + * + * If the attacker is of a lesser level than the target, then this routine has + * a random chance to return FALSE. Given a random integer R between 0 and 255, + * Whirlwind will fail if the following condition holds: + * + * R * (attackerLevel + defenderLevel) defenderLevel + * ----------------------------------- + 1 ≤ ------------- + * 256 4 + * + * @param battleSys + * @param battleCtx + * @return TRUE if Whirlwind should succeed, FALSE if it should fail. + */ +BOOL BattleSystem_CanWhirlwind(BattleSystem *battleSys, BattleContext *battleCtx); u8 Battler_Ability(BattleContext * param0, int param1); /** diff --git a/include/unk_0208C098.h b/include/unk_0208C098.h index a719ccb7c9..a55d58e8d0 100644 --- a/include/unk_0208C098.h +++ b/include/unk_0208C098.h @@ -8,7 +8,16 @@ int sub_0208C098(int param0); u32 sub_0208C0A4(u32 param0, u32 param1); -u8 sub_0208C0BC(u32 param0, u32 param1, u8 param2); + +/** + * @brief Determine how many pixels are needed to represent a fractional value. + * + * @param cur The current value; the fraction's numerator. + * @param max The maximum value; the fraction's denominator. + * @param maxPixels How many pixels would be used to display max / max. + * @return The number of pixels needed to display cur / max. + */ +u8 App_PixelCount(u32 cur, u32 max, u8 maxPixels); u8 sub_0208C0D4(u32 param0, u32 param1); u8 sub_0208C104(u16 param0, u16 param1, u32 param2); void sub_0208C120(u8 param0, u32 param1); diff --git a/src/overlay010/ov10_0221F800.c b/src/overlay010/ov10_0221F800.c index 26caa4d299..e424d6124a 100644 --- a/src/overlay010/ov10_0221F800.c +++ b/src/overlay010/ov10_0221F800.c @@ -2337,7 +2337,7 @@ static void ov10_02222594 (UnkStruct_ov10_0221FB28 * param0, u32 param1) break; } - v1 = sub_0208C0BC(param0->unk_214[param1].unk_06, param0->unk_214[param1].unk_08, 48); + v1 = App_PixelCount(param0->unk_214[param1].unk_06, param0->unk_214[param1].unk_08, 48); BGL_WindowColor(v0, 10, 0, 2, v1, 1); BGL_WindowColor(v0, 9, 0, 3, v1, 2); diff --git a/src/overlay013/ov13_0221FC20.c b/src/overlay013/ov13_0221FC20.c index a397d553d0..602e674d43 100644 --- a/src/overlay013/ov13_0221FC20.c +++ b/src/overlay013/ov13_0221FC20.c @@ -1476,7 +1476,7 @@ static void ov13_022214E0 (UnkStruct_ov13_022213F0 * param0, u8 param1) v2 = 0; } - v6 = sub_0208C0BC(v2, v1, 64); + v6 = App_PixelCount(v2, v1, 64); for (v7 = 0; v7 < 8; v7++) { if (v6 >= 8) { diff --git a/src/overlay013/ov13_02221A88.c b/src/overlay013/ov13_02221A88.c index 34830b3f1c..2fd22051bf 100644 --- a/src/overlay013/ov13_02221A88.c +++ b/src/overlay013/ov13_02221A88.c @@ -385,7 +385,7 @@ static void ov13_02221ED0 (UnkStruct_ov13_022213F0 * param0, u32 param1, u16 par v0 = ¶m0->unk_04[param2]; v1 = 1; - v2 = sub_0208C0BC(v0->unk_10, v0->unk_12, 48); + v2 = App_PixelCount(v0->unk_10, v0->unk_12, 48); switch (sub_0208C104(v0->unk_10, v0->unk_12, 48)) { case 0: diff --git a/src/overlay016/battle_script.c b/src/overlay016/battle_script.c index 0bf07a8bf6..8febadf2bb 100644 --- a/src/overlay016/battle_script.c +++ b/src/overlay016/battle_script.c @@ -5288,7 +5288,7 @@ static BOOL ov16_022446A0 (BattleSystem * param0, BattleContext * param1) int v1; BattleScript_Iter(param1, 1); - v1 = sub_0208C0BC(param1->battleMons[param1->attacker].curHP, param1->battleMons[param1->attacker].maxHP, 64); + v1 = App_PixelCount(param1->battleMons[param1->attacker].curHP, param1->battleMons[param1->attacker].maxHP, 64); for (v0 = 0; v0 < NELEMS(Unk_ov16_0226E584); v0++) { if (v1 <= Unk_ov16_0226E584[v0][0]) { @@ -5418,7 +5418,7 @@ static BOOL ov16_022448E8 (BattleSystem * param0, BattleContext * param1) } else { if ((param1->battleMons[param1->defender].heldItem) && (Battler_IgnorableAbility(param1, param1->attacker, param1->defender, 60) == 1)) { BattleScript_Iter(param1, v1); - } else if ((param1->battleMons[param1->attacker].heldItem) || (ov16_02255980(param0, param1, param1->defender) == 0)) { + } else if ((param1->battleMons[param1->attacker].heldItem) || (BattleSystem_CanStealItem(param0, param1, param1->defender) == 0)) { BattleScript_Iter(param1, v0); } } @@ -5553,7 +5553,7 @@ static BOOL ov16_02244BC4 (BattleSystem * param0, BattleContext * param1) if (v5 <= v6) { BattleScript_Iter(param1, v0); } else { - if (ov16_022559FC(param0, param1)) { + if (BattleSystem_CanWhirlwind(param0, param1)) { do { do { v7 = BattleSystem_RandNext(param0) % v10; @@ -5570,7 +5570,7 @@ static BOOL ov16_02244BC4 (BattleSystem * param0, BattleContext * param1) } } } else { - if (ov16_022559FC(param0, param1) == 0) { + if (BattleSystem_CanWhirlwind(param0, param1) == 0) { BattleScript_Iter(param1, v0); } } diff --git a/src/overlay016/ov16_0225177C.c b/src/overlay016/ov16_0225177C.c index 66383ede9f..6f53d6a9ff 100644 --- a/src/overlay016/ov16_0225177C.c +++ b/src/overlay016/ov16_0225177C.c @@ -95,9 +95,9 @@ BOOL BattleSystem_TypeMatchup(BattleSystem *battleSys, int idx, u8 *moveType, u8 int ov16_022558CC(u8 param0, u8 param1, u8 param2); BOOL Move_IsInvoker(u16 move); BOOL BattleSystem_IsGhostCurse(BattleContext * param0, u16 param1, int param2); -BOOL ov16_02255980(BattleSystem * param0, BattleContext * param1, int param2); +BOOL BattleSystem_CanStealItem(BattleSystem *battleSys, BattleContext *battleCtx, int battler); BOOL ov16_022559DC(BattleContext * param0, int param1); -BOOL ov16_022559FC(BattleSystem * param0, BattleContext * param1); +BOOL BattleSystem_CanWhirlwind(BattleSystem *battleSys, BattleContext *battleCtx); u8 Battler_Ability(BattleContext * param0, int param1); BOOL Battler_IgnorableAbility(BattleContext *battleCtx, int attacker, int defender, int ability); BOOL BattleSystem_AnyReplacementMons(BattleSystem *battleSys, BattleContext *battleCtx, int battler); @@ -3105,19 +3105,18 @@ BOOL BattleSystem_IsGhostCurse (BattleContext * param0, u16 param1, int param2) return (param1 == 174) && ((BattleMon_Get(param0, param2, 27, NULL) == 7) || (BattleMon_Get(param0, param2, 28, NULL) == 7)); } -BOOL ov16_02255980 (BattleSystem * param0, BattleContext * param1, int param2) +BOOL BattleSystem_CanStealItem(BattleSystem *battleSys, BattleContext *battleCtx, int battler) { - BOOL v0; - int v1; - - v0 = 0; - v1 = Battler_Side(param0, param2); + BOOL result = FALSE; + int side = Battler_Side(battleSys, battler); - if ((param1->battleMons[param2].heldItem) && ((param1->sideConditions[v1].knockedOffItemsMask & FlagIndex(param1->selectedPartySlot[param2])) == 0) && (Item_IsMail(param1->battleMons[param2].heldItem) == 0)) { - v0 = 1; + if (battleCtx->battleMons[battler].heldItem + && (battleCtx->sideConditions[side].knockedOffItemsMask & FlagIndex(battleCtx->selectedPartySlot[battler])) == FALSE + && Item_IsMail(battleCtx->battleMons[battler].heldItem) == FALSE) { + result = TRUE; } - return v0; + return result; } BOOL ov16_022559DC (BattleContext * param0, int param1) @@ -3125,27 +3124,20 @@ BOOL ov16_022559DC (BattleContext * param0, int param1) return Item_IsMail(param0->battleMons[param1].heldItem) == 0; } -BOOL ov16_022559FC (BattleSystem * param0, BattleContext * param1) +BOOL BattleSystem_CanWhirlwind(BattleSystem *battleSys, BattleContext *battleCtx) { - BOOL v0; - - v0 = 0; + BOOL result = FALSE; - if (param1->battleMons[param1->attacker].level >= param1->battleMons[param1->defender].level) { - v0 = 1; + if (ATTACKING_MON.level >= DEFENDING_MON.level) { + result = TRUE; } else { - { - int v1; - - v1 = (((BattleSystem_RandNext(param0) & 0xff) * (param1->battleMons[param1->attacker].level + param1->battleMons[param1->defender].level)) >> 8) + 1; - - if (v1 > (param1->battleMons[param1->defender].level / 4)) { - v0 = 1; - } + int tmp = (((BattleSystem_RandNext(battleSys) & 0xFF) * (ATTACKING_MON.level + DEFENDING_MON.level)) >> 8) + 1; + if (tmp > battleCtx->battleMons[battleCtx->defender].level / 4) { + result = TRUE; } } - return v0; + return result; } u8 Battler_Ability (BattleContext * param0, int param1) diff --git a/src/unk_020819DC.c b/src/unk_020819DC.c index 971e2576e0..077caae18f 100644 --- a/src/unk_020819DC.c +++ b/src/unk_020819DC.c @@ -383,7 +383,7 @@ void sub_02082104 (UnkStruct_0207F248 * param0, u8 param1) break; } - v1 = sub_0208C0BC(param0->unk_704[param1].unk_06, param0->unk_704[param1].unk_08, 48); + v1 = App_PixelCount(param0->unk_704[param1].unk_06, param0->unk_704[param1].unk_08, 48); BGL_WindowColor(v0, 10, 0, 2, v1, 1); BGL_WindowColor(v0, 9, 0, 3, v1, 2); diff --git a/src/unk_0208C098.c b/src/unk_0208C098.c index 68e743b07f..431d6d4295 100644 --- a/src/unk_0208C098.c +++ b/src/unk_0208C098.c @@ -43,17 +43,14 @@ u32 sub_0208C0A4 (u32 param0, u32 param1) return v0 >> 2; } -u8 sub_0208C0BC (u32 param0, u32 param1, u8 param2) +u8 App_PixelCount(u32 cur, u32 max, u8 maxPixels) { - u8 v0; - - v0 = param0 * param2 / param1; - - if ((v0 == 0) && (param0 > 0)) { - v0 = 1; + u8 pixels = cur * maxPixels / max; + if (pixels == 0 && cur > 0) { + pixels = 1; } - return v0; + return pixels; } u8 sub_0208C0D4 (u32 param0, u32 param1) @@ -80,7 +77,7 @@ u8 sub_0208C104 (u16 param0, u16 param1, u32 param2) return 4; } - v0 = sub_0208C0BC(param0, param1, param2); + v0 = App_PixelCount(param0, param1, param2); return sub_0208C0D4(v0, param2); } diff --git a/src/unk_0208C324.c b/src/unk_0208C324.c index f874638fcb..4032356c10 100644 --- a/src/unk_0208C324.c +++ b/src/unk_0208C324.c @@ -1383,7 +1383,7 @@ static void sub_0208D9D0 (UnkStruct_0208D7BC * param0) break; } - v2 = sub_0208C0BC(param0->unk_250.unk_24, param0->unk_250.unk_26, 48); + v2 = App_PixelCount(param0->unk_250.unk_24, param0->unk_250.unk_26, 48); for (v3 = 0; v3 < 6; v3++) { if (v2 >= 8) { @@ -1420,7 +1420,7 @@ static void sub_0208DA84 (UnkStruct_0208D7BC * param0) v1 = 0; } - v3 = sub_0208C0BC(v1, v0, 56); + v3 = App_PixelCount(v1, v0, 56); for (v4 = 0; v4 < 7; v4++) { if (v3 >= 8) {