document design oddity, use constants, correct comment

This commit is contained in:
Kurausukun 2022-06-17 21:52:58 -04:00
parent de1145e790
commit 23e9455e0a

View File

@ -2,6 +2,7 @@
#include "battle.h"
#include "battle_anim.h"
#include "battle_controllers.h"
#include "battle_main.h"
#include "data.h"
#include "pokemon.h"
#include "random.h"
@ -66,13 +67,13 @@ static bool8 ShouldSwitchIfWonderGuard(void)
if (gBattleTypeFlags & (BATTLE_TYPE_TWO_OPPONENTS | BATTLE_TYPE_TOWER_LINK_MULTI))
{
if ((gActiveBattler & BIT_FLANK) == B_FLANK_LEFT)
firstId = 0, lastId = 3;
firstId = 0, lastId = PARTY_SIZE / 2;
else
firstId = 3, lastId = 6;
firstId = PARTY_SIZE / 2, lastId = PARTY_SIZE;
}
else
{
firstId = 0, lastId = 6;
firstId = 0, lastId = PARTY_SIZE;
}
if (GetBattlerSide(gActiveBattler) == B_SIDE_PLAYER)
@ -162,13 +163,13 @@ static bool8 FindMonThatAbsorbsOpponentsMove(void)
if (gBattleTypeFlags & (BATTLE_TYPE_TWO_OPPONENTS | BATTLE_TYPE_TOWER_LINK_MULTI))
{
if ((gActiveBattler & BIT_FLANK) == B_FLANK_LEFT)
firstId = 0, lastId = 3;
firstId = 0, lastId = PARTY_SIZE / 2;
else
firstId = 3, lastId = 6;
firstId = PARTY_SIZE / 2, lastId = PARTY_SIZE;
}
else
{
firstId = 0, lastId = 6;
firstId = 0, lastId = PARTY_SIZE;
}
if (GetBattlerSide(gActiveBattler) == B_SIDE_PLAYER)
@ -357,13 +358,13 @@ static bool8 FindMonWithFlagsAndSuperEffective(u8 flags, u8 moduloPercent)
if (gBattleTypeFlags & (BATTLE_TYPE_TWO_OPPONENTS | BATTLE_TYPE_TOWER_LINK_MULTI))
{
if ((gActiveBattler & BIT_FLANK) == 0)
firstId = 0, lastId = 3;
firstId = 0, lastId = PARTY_SIZE / 2;
else
firstId = 3, lastId = 6;
firstId = PARTY_SIZE / 2, lastId = PARTY_SIZE;
}
else
{
firstId = 0, lastId = 6;
firstId = 0, lastId = PARTY_SIZE;
}
if (GetBattlerSide(gActiveBattler) == B_SIDE_PLAYER)
@ -468,13 +469,13 @@ static bool8 ShouldSwitch(void)
if (gBattleTypeFlags & (BATTLE_TYPE_TWO_OPPONENTS | BATTLE_TYPE_TOWER_LINK_MULTI))
{
if ((gActiveBattler & BIT_FLANK) == B_FLANK_LEFT)
firstId = 0, lastId = 3;
firstId = 0, lastId = PARTY_SIZE / 2;
else
firstId = 3, lastId = 6;
firstId = PARTY_SIZE / 2, lastId = PARTY_SIZE;
}
else
{
firstId = 0, lastId = 6;
firstId = 0, lastId = PARTY_SIZE;
}
if (GetBattlerSide(gActiveBattler) == B_SIDE_PLAYER)
@ -559,13 +560,13 @@ void AI_TrySwitchOrUseItem(void)
if (gBattleTypeFlags & (BATTLE_TYPE_TWO_OPPONENTS | BATTLE_TYPE_TOWER_LINK_MULTI))
{
if ((gActiveBattler & BIT_FLANK) == B_FLANK_LEFT)
firstId = 0, lastId = 3;
firstId = 0, lastId = PARTY_SIZE / 2;
else
firstId = 3, lastId = 6;
firstId = PARTY_SIZE / 2, lastId = PARTY_SIZE;
}
else
{
firstId = 0, lastId = 6;
firstId = 0, lastId = PARTY_SIZE;
}
for (monToSwitchId = firstId; monToSwitchId < lastId; monToSwitchId++)
@ -615,10 +616,10 @@ static void ModulateByTypeEffectiveness(u8 atkType, u8 defType1, u8 defType2, u8
{
// Check type1.
if (TYPE_EFFECT_DEF_TYPE(i) == defType1)
*var = (*var * TYPE_EFFECT_MULTIPLIER(i)) / 10;
*var = (*var * TYPE_EFFECT_MULTIPLIER(i)) / TYPE_MUL_NORMAL;
// Check type2.
if (TYPE_EFFECT_DEF_TYPE(i) == defType2 && defType1 != defType2)
*var = (*var * TYPE_EFFECT_MULTIPLIER(i)) / 10;
*var = (*var * TYPE_EFFECT_MULTIPLIER(i)) / TYPE_MUL_NORMAL;
}
i += 3;
}
@ -627,7 +628,7 @@ static void ModulateByTypeEffectiveness(u8 atkType, u8 defType1, u8 defType2, u8
u8 GetMostSuitableMonToSwitchInto(void)
{
u8 opposingBattler;
u8 bestDmg; // Note : should be changed to u32 for obvious reasons.
u8 bestDmg; // Note: should be changed to s32 since it is also used for the actual damage done later
u8 bestMonId;
u8 battlerIn1, battlerIn2;
s32 firstId;
@ -665,13 +666,13 @@ u8 GetMostSuitableMonToSwitchInto(void)
if (gBattleTypeFlags & (BATTLE_TYPE_TWO_OPPONENTS | BATTLE_TYPE_TOWER_LINK_MULTI))
{
if ((gActiveBattler & BIT_FLANK) == B_FLANK_LEFT)
firstId = 0, lastId = 3;
firstId = 0, lastId = PARTY_SIZE / 2;
else
firstId = 3, lastId = 6;
firstId = PARTY_SIZE / 2, lastId = PARTY_SIZE;
}
else
{
firstId = 0, lastId = 6;
firstId = 0, lastId = PARTY_SIZE;
}
if (GetBattlerSide(gActiveBattler) == B_SIDE_PLAYER)
@ -683,7 +684,7 @@ u8 GetMostSuitableMonToSwitchInto(void)
while (invalidMons != 0x3F) // All mons are invalid.
{
bestDmg = 0;
bestDmg = ;
bestMonId = 6;
// Find the mon whose type is the most suitable offensively.
for (i = firstId; i < lastId; i++)
@ -699,9 +700,13 @@ u8 GetMostSuitableMonToSwitchInto(void)
{
u8 type1 = gBaseStats[species].type1;
u8 type2 = gBaseStats[species].type2;
u8 typeDmg = 10;
u8 typeDmg = TYPE_MUL_NORMAL;
ModulateByTypeEffectiveness(gBattleMons[opposingBattler].type1, type1, type2, &typeDmg);
ModulateByTypeEffectiveness(gBattleMons[opposingBattler].type2, type1, type2, &typeDmg);
/* Possible bug: this comparison gives the type that takes the most damage, when
a "good" AI would want to select the type that takes the least damage. Unknown if this
is a legitimate mistake or if it's an intentional, if weird, design choice*/
if (bestDmg < typeDmg)
{
bestDmg = typeDmg;