re-match GetTypeEffectivenessPoints (from #1177)

This commit is contained in:
Kurausukun 2020-10-23 20:59:27 -04:00
parent 90211248af
commit 16cf49ffbe

View file

@ -2731,9 +2731,6 @@ static int SelectOpponentMonsFromParty(int *partyMovePoints, bool8 allowRandom)
#define TYPE_x2 40
#define TYPE_x4 80
// Functionally equivalent, while loop is impossible to match.
// arg2 is either 2, a personality, or an OTID
#ifdef NONMATCHING
static int GetTypeEffectivenessPoints(int move, int targetSpecies, int arg2)
{
int defType1, defType2, defAbility, moveType;
@ -2762,13 +2759,15 @@ static int GetTypeEffectivenessPoints(int move, int targetSpecies, int arg2)
i += 3;
continue;
}
else if (TYPE_EFFECT_ATK_TYPE(i) == moveType)
if (TYPE_EFFECT_ATK_TYPE(i) == moveType)
{
// BUG: * 2 is not necessary and makes the condition always false if the ability is wonder guard.
if (TYPE_EFFECT_DEF_TYPE(i) == defType1 && (defAbility != ABILITY_WONDER_GUARD || TYPE_EFFECT_MULTIPLIER(i) == TYPE_MUL_SUPER_EFFECTIVE * 2))
typePower = (typePower * TYPE_EFFECT_MULTIPLIER(i)) / 10;
if (TYPE_EFFECT_DEF_TYPE(i) == defType2 && defType1 != defType2 && (defAbility != ABILITY_WONDER_GUARD || TYPE_EFFECT_MULTIPLIER(i) == TYPE_MUL_SUPER_EFFECTIVE * 2))
typePower = (typePower * TYPE_EFFECT_MULTIPLIER(i)) / 10;
// BUG: TYPE_x2 is not necessary and makes the condition always false if the ability is wonder guard.
if (TYPE_EFFECT_DEF_TYPE(i) == defType1)
if ((defAbility == ABILITY_WONDER_GUARD && TYPE_EFFECT_MULTIPLIER(i) == TYPE_x2) || defAbility != ABILITY_WONDER_GUARD)
typePower = (typePower * TYPE_EFFECT_MULTIPLIER(i)) / 10;
if (TYPE_EFFECT_DEF_TYPE(i) == defType2 && defType1 != defType2)
if ((defAbility == ABILITY_WONDER_GUARD && TYPE_EFFECT_MULTIPLIER(i) == TYPE_x2) || defAbility != ABILITY_WONDER_GUARD)
typePower = (typePower * TYPE_EFFECT_MULTIPLIER(i)) / 10;
}
i += 3;
}
@ -2848,246 +2847,6 @@ static int GetTypeEffectivenessPoints(int move, int targetSpecies, int arg2)
return typePower;
}
#else
NAKED
static int GetTypeEffectivenessPoints(int move, int species, int arg2)
{
asm_unified(
"push {r4-r7,lr}\n\
mov r7, r10\n\
mov r6, r9\n\
mov r5, r8\n\
push {r5-r7}\n\
sub sp, 0x8\n\
adds r3, r0, 0\n\
adds r4, r1, 0\n\
str r2, [sp]\n\
movs r6, 0\n\
movs r2, 0x14\n\
cmp r3, 0\n\
beq _0818FFF0\n\
ldr r0, =0x0000ffff\n\
cmp r3, r0\n\
beq _0818FFF0\n\
ldr r0, =gBattleMoves\n\
lsls r1, r3, 1\n\
adds r1, r3\n\
lsls r1, 2\n\
adds r3, r1, r0\n\
ldrb r0, [r3, 0x1]\n\
cmp r0, 0\n\
bne _0818FFFC\n\
_0818FFF0:\n\
movs r0, 0\n\
b _08190156\n\
.pool\n\
_0818FFFC:\n\
ldr r1, =gBaseStats\n\
lsls r0, r4, 3\n\
subs r0, r4\n\
lsls r0, 2\n\
adds r0, r1\n\
ldrb r1, [r0, 0x6]\n\
mov r10, r1\n\
ldrb r1, [r0, 0x7]\n\
mov r9, r1\n\
ldrb r0, [r0, 0x16]\n\
mov r8, r0\n\
ldrb r3, [r3, 0x2]\n\
str r3, [sp, 0x4]\n\
cmp r0, 0x1A\n\
bne _0819002C\n\
cmp r3, 0x4\n\
bne _0819002C\n\
ldr r0, [sp]\n\
cmp r0, 0x1\n\
bne _081900AA\n\
movs r2, 0x8\n\
b _081900A4\n\
.pool\n\
_0819002C:\n\
ldr r0, =gTypeEffectiveness\n\
adds r1, r6, r0\n\
ldrb r0, [r1]\n\
ldr r7, =gTypeEffectiveness\n\
cmp r0, 0xFF\n\
beq _081900A4\n\
adds r4, r1, 0\n\
_0819003A:\n\
ldrb r0, [r4]\n\
cmp r0, 0xFE\n\
beq _08190096\n\
ldrb r0, [r4]\n\
ldr r1, [sp, 0x4]\n\
cmp r0, r1\n\
bne _08190096\n\
ldrb r0, [r4, 0x1]\n\
adds r5, r6, 0x1\n\
cmp r0, r10\n\
bne _0819006C\n\
adds r1, r6, 0x2\n\
mov r0, r8\n\
cmp r0, 0x19\n\
bne _0819005E\n\
ldrb r0, [r4, 0x2]\n\
cmp r0, 0x28\n\
bne _0819006C\n\
_0819005E:\n\
adds r0, r1, r7\n\
ldrb r0, [r0]\n\
muls r0, r2\n\
movs r1, 0xA\n\
bl __divsi3\n\
adds r2, r0, 0\n\
_0819006C:\n\
adds r0, r5, r7\n\
ldrb r0, [r0]\n\
cmp r0, r9\n\
bne _08190096\n\
cmp r10, r9\n\
beq _08190096\n\
adds r1, r6, 0x2\n\
mov r0, r8\n\
cmp r0, 0x19\n\
bne _08190088\n\
adds r0, r1, r7\n\
ldrb r0, [r0]\n\
cmp r0, 0x28\n\
bne _08190096\n\
_08190088:\n\
adds r0, r1, r7\n\
ldrb r0, [r0]\n\
muls r0, r2\n\
movs r1, 0xA\n\
bl __divsi3\n\
adds r2, r0, 0\n\
_08190096:\n\
adds r4, 0x3\n\
adds r6, 0x3\n\
ldr r1, =gTypeEffectiveness\n\
adds r0, r6, r1\n\
ldrb r0, [r0]\n\
cmp r0, 0xFF\n\
bne _0819003A\n\
_081900A4:\n\
ldr r0, [sp]\n\
cmp r0, 0x1\n\
beq _081900E0\n\
_081900AA:\n\
ldr r1, [sp]\n\
cmp r1, 0x1\n\
bgt _081900BC\n\
cmp r1, 0\n\
beq _081900C4\n\
b _08190154\n\
.pool\n\
_081900BC:\n\
ldr r0, [sp]\n\
cmp r0, 0x2\n\
beq _08190114\n\
b _08190154\n\
_081900C4:\n\
cmp r2, 0xA\n\
beq _08190146\n\
cmp r2, 0xA\n\
ble _08190146\n\
cmp r2, 0x28\n\
beq _0819014A\n\
cmp r2, 0x28\n\
bgt _081900DA\n\
cmp r2, 0x14\n\
beq _08190104\n\
b _08190146\n\
_081900DA:\n\
cmp r2, 0x50\n\
bne _08190146\n\
b _08190100\n\
_081900E0:\n\
cmp r2, 0xA\n\
beq _08190104\n\
cmp r2, 0xA\n\
bgt _081900F2\n\
cmp r2, 0\n\
beq _08190100\n\
cmp r2, 0x5\n\
beq _0819014A\n\
b _08190146\n\
_081900F2:\n\
cmp r2, 0x28\n\
beq _08190108\n\
cmp r2, 0x28\n\
ble _08190146\n\
cmp r2, 0x50\n\
beq _0819010E\n\
b _08190146\n\
_08190100:\n\
movs r2, 0x8\n\
b _08190154\n\
_08190104:\n\
movs r2, 0x2\n\
b _08190154\n\
_08190108:\n\
movs r2, 0x2\n\
negs r2, r2\n\
b _08190154\n\
_0819010E:\n\
movs r2, 0x4\n\
negs r2, r2\n\
b _08190154\n\
_08190114:\n\
cmp r2, 0xA\n\
beq _08190146\n\
cmp r2, 0xA\n\
bgt _08190126\n\
cmp r2, 0\n\
beq _0819013A\n\
cmp r2, 0x5\n\
beq _08190140\n\
b _08190146\n\
_08190126:\n\
cmp r2, 0x28\n\
beq _0819014E\n\
cmp r2, 0x28\n\
bgt _08190134\n\
cmp r2, 0x14\n\
beq _0819014A\n\
b _08190146\n\
_08190134:\n\
cmp r2, 0x50\n\
beq _08190152\n\
b _08190146\n\
_0819013A:\n\
movs r2, 0x10\n\
negs r2, r2\n\
b _08190154\n\
_08190140:\n\
movs r2, 0x8\n\
negs r2, r2\n\
b _08190154\n\
_08190146:\n\
movs r2, 0\n\
b _08190154\n\
_0819014A:\n\
movs r2, 0x4\n\
b _08190154\n\
_0819014E:\n\
movs r2, 0xC\n\
b _08190154\n\
_08190152:\n\
movs r2, 0x14\n\
_08190154:\n\
adds r0, r2, 0\n\
_08190156:\n\
add sp, 0x8\n\
pop {r3-r5}\n\
mov r8, r3\n\
mov r9, r4\n\
mov r10, r5\n\
pop {r4-r7}\n\
pop {r1}\n\
bx r1");
}
#endif // NONMATCHING
// Duplicate of GetFrontierTrainerFixedIvs
// NOTE: In CreateDomeOpponentMon a tournament trainer ID (0-15) is passed instead, resulting in all IVs of 3