• Check out the relaunch of our general collection, with classic designs and new ones by our very own Pissog!

Mechanics Gen 2-4: Multiple type modifiers should apply one at a time instead of cancelling

What type of bug are you reporting? Mechanics

What is the bug?
In this game on turn 14 of a DPP Little Cup match, Stunky takes 82% from Machop Dynamic Punch, or 19 damage. This damage roll should not be possible according to the damage calc. I also confirmed with my opponent afterwards that it was not some boosting item that might change the damage roll, as well as tested it myself afterwards to try and recreate it, which I did successfully. I am not sure if this is an error on the simulators part or an error in the damage calculator

196+ Atk Machop Dynamic Punch vs. 12 HP / 0 Def Stunky: 18-22 (78.2 - 95.6%) -- guaranteed 2HKOPossible damage amounts: (18, 18, 18, 18, 18, 18, 18, 18, 18, 20, 20, 20, 20, 20, 20, 22)

196 Atk Machop Dynamic Punch vs. 12 HP / 0 Def Stunky: 16-20 (69.5 - 86.9%) -- guaranteed 2HKOPossible damage amounts: (16, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 20)

116 Atk Machop Dynamic Punch vs. 12 HP / 0 Def Stunky: 16-18 (69.5 - 78.2%) -- guaranteed 2HKOPossible damage amounts: (16, 16, 16, 16, 16, 16, 16, 16, 18, 18, 18, 18, 18, 18, 18, 18).


mathematical impossibility 2.0


Are you able to replicate it? If so, how?
I was able to recreate it multiple times on my own, showing two different damage rolls that according to the damage calc, should not be possible. I posted the hp values, showed sets, and posted the damage calc in both replays.

https://replay.pokemonshowdown.com/gen4lc-2331490587-1b88egi5rkql1vbbyu12r7hnllledd0pw



https://replay.pokemonshowdown.com/gen4lc-2331492651-k1ayft2jdhrhoaysibuk32nqh2nht6opw
 
Last edited:
For Gen 4, the damage calculator (Calc) applies type effectiveness in a different manner than the sim calculates damage (Sim). As for which is right I am not sure but DaWoblefet may know.

The Calc performs a rounded multiplication in order for each individual type's effectiveness. This order is determined by the usual ordering of types based on their ID*. So even for a neutral type effectiveness, it is first either doubled or halved, rounded, and then if there is a second type it is doubled or halved and rounded again.

The Sim only modifies damage if it detects a non-neutral effectiveness. If it is super effective, it is doubled for each super effective type/mod. If it is not very effective, it is halved for each. A neutral type effectiveness does nothing.

That is the source of the discrepancy. Someone more versed on the mechanics can provide information on which is accurate but I would be lean towards the Calc. It looks like a more purposeful calculation and sounds like how GameFreak would have implemented it.

Calc code starts on L120 for the type precedence rules and the modification is applied at L272, both in /calc/src/mechanics/gen4.ts
Sim code starts on L89 for calculating and applying type effectiveness modification in /data/mods/gen4/scripts.ts


* The order is Normal, Fire, Water, Electric, Grass, Ice, Fighting, Poison, Ground, Flying, Psychic, Bug, Rock, Ghost, Dragon, Dark, Steel
 
The damage calc is mostly correct; Gens 2-4 use a lookup table to loop through, checking for the move's type, then apply the damage modifiers in the same order they're listed, if applicable.

https://github.com/pret/pokeemerald...5bdf1b9512bad2a53/src/battle_main.c#L329-L449

That's the Gen 3 table but it's identical in Gens 2 and 4, but do note that Ice VS Fire is not where it's expected to be (the damage calc doesn't appear to account for this), probably because it was neutral in Gen 1 and they decided to add this one late into Gen 2 development. This inconsistency was carried over in every game until they stopped using tables entirely in Gen 5, and this can make a difference against any Fire-type Pokemon whose other type is weak to Ice, because the Fire interaction would otherwise be the first type checked.

Gen 1 also uses a lookup table for the same purpose but it's famously even more of a mess: https://github.com/pret/pokered/blob/master/data/types/type_matchups.asm
 
Back
Top