Skip to content

Commit

Permalink
Document App_PixelCount, BattleSystem_CanStealItem, and BattleSystem_…
Browse files Browse the repository at this point in the history
…CanWhirlwind
  • Loading branch information
lhearachel committed Oct 29, 2023
1 parent 73297f3 commit 183a716
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 48 deletions.
29 changes: 27 additions & 2 deletions include/overlay016/ov16_0225177C.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

/**
Expand Down
11 changes: 10 additions & 1 deletion include/unk_0208C098.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/overlay010/ov10_0221F800.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/overlay013/ov13_0221FC20.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/overlay013/ov13_02221A88.c
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ static void ov13_02221ED0 (UnkStruct_ov13_022213F0 * param0, u32 param1, u16 par

v0 = &param0->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:
Expand Down
8 changes: 4 additions & 4 deletions src/overlay016/battle_script.c
Original file line number Diff line number Diff line change
Expand Up @@ -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]) {
Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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;
Expand All @@ -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);
}
}
Expand Down
44 changes: 18 additions & 26 deletions src/overlay016/ov16_0225177C.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -3105,47 +3105,39 @@ 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)
{
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)
Expand Down
2 changes: 1 addition & 1 deletion src/unk_020819DC.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
15 changes: 6 additions & 9 deletions src/unk_0208C098.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions src/unk_0208C324.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 183a716

Please sign in to comment.