Facts
Released
2004-09-16 (JP); 2005-05-01 (NA)
Genre
Japanese role-playing game, Monster-taming
Platforms
Game Boy Advance
Developer
Game Freak
Publisher
Nintendo
Series
Pokémon
Code
Decompilation by pret contributors
Evidence
Code (4)
Wiki (1)
Sources
4
On this page
  1. Data
  2. Related
  3. Mechanics
  4. References
  5. Sources

Pokémon Emerald is a Generation III Game Boy Advance game, released in Japan in September 2004 and North America in May 20051. The code read here is pret’s pokeemerald decompilation, C that compiles to the original ROM.

Its type effectiveness table is Pokémon Crystal’s, row for row2. Effectiveness text now comes from flags, where a ½ row and a 2× row cancel3. Levitate acts before the rows, and Wonder Guard after4,5.

Data

  • Hit test: miss if a 1–100 roll exceeds accuracy × ratio · 13 rows

Hit test, the first 10 of 13 rows:

Net stageNumeratorDenominator
-633100
-536100
-443100
-350100
-260100
-175100
011
1133100
2166100
321

All 13 rows on its claim.

Mechanics

MechanicKindHow
Type effectiveness17 typesCrystal's 17-type chart, with abilities such as Levitate and Wonder Guard on top
Same-type attack bonusHalf againdamage × 15 / 10, just before the type rows
Damage formulaAttack over defensea critical doubles the base damage, and the random factor becomes 85–100%
Critical hitFrom stagesstages from 1 in 16 to 1 in 2, and Battle Armor and Shell Armor block it
Hit chanceMove accuracyaccuracy in percent times one combined stage ratio, checked before the damage
Multi-hit attackPer-hit damage2–5 hits, each with its own critical and damage roll
Random encounterBy area16 times the area's rate out of 2,880 per step, with bike, flute, item, and ability modifiers
FleeingSpeed ratio128 times Speed over the foe's, plus 30 per try, out of 256; a Smoke Ball or Run Away always escapes
Turn orderPriority, then Speedpriority, then Speed after stages, weather abilities, the badge, items, and paralysis
Random number generatorFormulathe ISO C example generator, returning the top 16 bits
AbilityLevitate, Wonder Guard, Run Away, and the weather-speed abilities bend the rules they touch
Held itema Scope Lens, a Smoke Ball, a Macho Brace, and a Quick Claw
CaptureFour shake checksthe ball, HP and status set a rate, and four 16-bit rolls under a threshold near 65535 (a/255)^(1/4) catch; a miss shows the shakes it passed
Physical/special splitBy typethe type decides, as in the earlier games
Every claim about this game, by concept (35)
generalPokémon Emerald (developer Game Freak, publisher Nintendo, Game Boy Advance, and Generation III core series) came out in Japan on 16 September 2004 and North America on 1 May 2005.Wiki
CaptureThe ball-throw command reads the target species' catch rate (45 for Bulbasaur), except with a Safari Ball, which uses the Safari Zone's catch factor times 1275 / 100; the factor starts at the species' catch rate times 100 / 1275.Code
The ball multiplier is in tenths: 20 for an Ultra Ball, 15 for a Great or Safari Ball, 10 for a Poké Ball; a Net Ball 30 against a Water or Bug type, a Dive Ball 35 underwater, a Nest Ball 40 less the target's level below level 40 (at least 10), a Repeat Ball 30 for a species already caught, a Timer Ball 10 plus the turn count up to 40, and 10 for the Luxury and Premier Balls and for a Net, Dive, Nest, or Repeat Ball outside its condition.Code
Emerald computes a=⌊⌊Cm/10⌋(3M−2H)/3M⌋ from catch rate C, ball multiplier m, max HP M, and current HP H, then doubles it for sleep or freeze, or multiplies it by 15/10 (rounded down) for poison, bad poison, burn, or paralysis. C is the species' catch rate, or for a Safari Ball the Safari catch factor × 1275 / 100, rounded down.Code
An a over 254 catches at once. Otherwise Emerald turns it into a threshold b=⌊1048560/Sqrt(Sqrt(⌊16711680/a⌋))⌋, with Sqrt the GBA BIOS's square root, and draws up to four 16-bit random values; each one below b is a shake. Four shakes catch; a throw that fails shows the shakes it passed, 0 to 3. A Master Ball's shakes are set to four after the draw.Code
Computed, counting every random value as equally likely and taking the BIOS square root as rounding down: a throw catches with chance (b/65536)4 when a≤254. Since 16,711,680 is 255 × 65,536 and 1,048,560 is 16 × 65,535, b is close to 65535(a/255)1/4 and four passes close to a/255, higher for small a because both roots round down. A Bulbasaur (catch rate 45) with max HP 100 in a Poké Ball has a=15 and b=32767 at full HP, about 6.25%, and a=44, b=43690 at 1 HP, about 19.8%.Code
Computed, for a Bulbasaur (catch rate 45) with max HP 100 and no status in a Poké Ball: at full HP it is caught about 6.0% of the time in Red and Blue, 6.25% in Crystal, and 6.25% in Emerald; at 1 HP, 18.0%, 17.6%, and 19.8%. Here the three formulas land close together, though they roll twice in Red and Blue, once in Crystal, and up to four times in Emerald.Code
Critical hitThe critical-hit battle command sums a critical stage, +2 for Focus Energy, +1 for a high-critical move (including Sky Attack, Blaze Kick, and Poison Tail), +1 for a Scope Lens, and +2 for Chansey with a Lucky Punch or Farfetch'd with a Stick, capped at 4; a 16-bit random number taken modulo 16, 8, 4, 3, or 2 must be 0, a chance of 1/16, 1/8, 1/4, 21,846 in 65,536 (slightly over 1/3), or 1/2, and a target with Battle Armor or Shell Armor is never hit critically.Code
The damage-calculation battle command multiplies the base damage by 2 on a critical; the base-damage formula then ignores the attacker's lowered attacking stat, the defender's raised defending stat, and Reflect or Light Screen.Code
Damage formulaType still decides physical or special in Emerald, by whether it comes before or after type 9, "???".Code
A plain damaging move rolls for a critical hit, computes the base damage, applies the type step (STAB, then the type rows), and then applies the random factor.Code
The random factor changes form from Crystal's random byte over 255: Emerald multiplies nonzero damage by 100 − (a random number mod 16), 85 to 100, divides by 100, and raises a 0 result to 1.Code
FleeingAn attempt to run always escapes with a Smoke Ball, or with the Run Away ability outside the Battle Pyramid. Otherwise, in a single battle outside the Pyramid, it escapes when the player's Pokémon is at least as fast as the foe, or when ⌊128P/E⌋+30n, stored in a byte, exceeds a random byte, for n earlier attempts.Code
Hit chanceThe accuracy-check battle command combines the attacker's accuracy stage and the target's evasion stage into one stage, multiplies the move's accuracy in percent by that stage's ratio, and misses when a roll from 1 to 100 exceeds the result, so a 100% move at even stages never misses.Code
In Emerald a plain damaging move checks accuracy before it computes damage, the reverse of Red, Blue, and Crystal.Code
Multi-hit attackThe multi-hit battle command gives 2 or 3 hits with probability 3/8 each and 4 or 5 with 1/8 each; the loop reruns the critical-hit and damage calculations for every hit, after one accuracy check.Code
Random encounterOn each step onto grass or water, the wild-encounter check multiplies the area's rate by 16, applies bike, flute, Cleanse Tag, and lead-ability modifiers, and starts a battle when a random number mod 2,880 is below it; Route 101's rate is 20.Code
A step onto a tile whose behavior differs from the last one skips the encounter check 40% of the time.Code
Computed from the land rates and the build step that turns them into slot bounds: Emerald's 12 land slots come up 20, 20, 10, 10, 10, 10, 5, 5, 4, 4, 1, and 1 percent of the time.Code
After a battle starts, and whenever a map loads, the next 4 encounter checks are skipped.Code
Random number generatorEmerald's random number generator is a linear congruential generator, x←1103515245x+24691(mod232), returning the top 16 bits; pret's comment traces the multiplier to the example rand in the ISO C standard.Code
Emerald seeds its random number generator from a hardware timer only when the player's naming screen closes, which also sets the trainer ID; the seeding from the real-time clock at power-on is compiled only into pret's BUGFIX build, so after loading a save the generator starts from 0, and the VBlank handler steps it once a frame outside link, Frontier, and recorded battles.Code
Same-type attack bonusBefore the type chart, the type-calculation battle command applies STAB as damage×15/10 when either attacker type equals the move's type.Code
Turn orderThe turn-order routine puts the higher-priority move first; at equal priority the higher Speed goes first, after stat stages, Swift Swim or Chlorophyll in their weather, the third badge's ×1.1 for the player, Macho Brace, paralysis's ×¼, and a Quick Claw that triggers; a tie is a coin flip.Code
Type effectivenessEmerald's type chart is a flat byte array of 108 non-neutral (attacker, defender, multiplier) rows over 17 types, then a Foresight marker, two Ghost immunities, and an end marker.Code
Emerald keeps the Game Boy encoding: 20 super effective, 10 normal, 5 not effective, and 0 no effect.Code
Computed by comparing the two tables row by row: Emerald's type table holds the same 110 rows as Crystal's, in the same order, so no type is new and no matchup changed.Code
Type 9, named "???", sits between the physical and special types and has no rows.Code
For each row of the move's type, the type-damage step runs once per distinct target type it matches: damage×multiplier/10, raised from 0 to 1 unless the multiplier is 0.Code
The text comes from flags the type-damage step sets per row: a 2× row cancels an earlier not-very-effective flag, a ½ row an earlier super-effective one, and ×0 sets "doesn't affect", clearing both.Code
Against a Foresight target, the loop breaks at the Foresight marker row, skipping the Normal→Ghost and Fighting→Ghost immunities after it.Code
Struggle skips the type-calculation battle command entirely, so neither STAB nor the type chart touches it.Code
The type-calculation battle command flags a Ground move against a Levitate target as missed and “doesn't affect”, and walks no type row.Code
After the type rows, a target with Wonder Guard makes a damaging move miss unless the move carries the super-effective flag without the not-very-effective one. The check is skipped on the charging turn of a two-turn move (Skull Bash, Razor Wind, Sky Attack, Solar Beam outside sunshine, the semi-invulnerable moves, and Bide), so it applies on the turn the move strikes.Code
Row order still matters: against a Water/Flying target, an Ice move's 3 damage becomes 1 at the Water row (½, rounded down), then 2 at the Flying row (×2); computed, the opposite order would give 3.Code

References

  1. ^WikiBulbapedia, “Pokémon Emerald Version”
    How we know

    Pokémon Emerald (developer Game Freak, publisher Nintendo, Game Boy Advance, and Generation III core series) came out in Japan on 16 September 2004 and North America on 1 May 2005.

    Developer: Game Freak … Publisher: Nintendo … Part of: Generation III core series … Japan: September 16, 2004 … North America: May 1, 2005
    infobox, Basic info and Release dates · archived copy ↗

    Claim page

  2. ^Codepret/pokecrystal · pret/pokeemerald · Bulbapedia, “Type/Type chart”type_matchups.asm 1–118; battle_main.c 335–449
    How we know

    Computed by comparing the two tables row by row: Emerald's type table holds the same 110 rows as Crystal's, in the same order, so no type is new and no matchup changed.

    3	db NORMAL,       ROCK,         NOT_VERY_EFFECTIVE
    4	db NORMAL,       STEEL,        NOT_VERY_EFFECTIVE
    ⋮
    112	db -2 ; end (with Foresight)
    
    data/types/type_matchups.asm lines 1–118 at 97187cd · upstream ↗
    337    TYPE_NORMAL, TYPE_ROCK, TYPE_MUL_NOT_EFFECTIVE,
    338    TYPE_NORMAL, TYPE_STEEL, TYPE_MUL_NOT_EFFECTIVE,
    ⋮
    445    TYPE_FORESIGHT, TYPE_FORESIGHT, TYPE_MUL_NO_EFFECT,
    
    src/battle_main.c lines 335–449 at 731ad5b · upstream ↗
    This matchup table is used from Generation II to Generation V.
    Type charts: Generations II-V · archived copy ↗

    Measured by a script. It fails if the result disagrees with the claim.

    Claim page

  3. ^Codepret/pokeemeraldbattle_script_commands.c 1327–1352
    How we know

    The text comes from flags the type-damage step sets per row: a 2× row cancels an earlier not-very-effective flag, a ½ row an earlier super-effective one, and ×0 sets "doesn't affect", clearing both.

    1331        gMoveResultFlags &= ~MOVE_RESULT_NOT_VERY_EFFECTIVE;
    ⋮
    1335        if (gBattleMoves[gCurrentMove].power && !(gMoveResultFlags & MOVE_RESULT_NO_EFFECT))
    ⋮
    1339            else
    ⋮
    1343    case TYPE_MUL_SUPER_EFFECTIVE:
    1344        if (gBattleMoves[gCurrentMove].power && !(gMoveResultFlags & MOVE_RESULT_NO_EFFECT))
    ⋮
    1346            if (gMoveResultFlags & MOVE_RESULT_NOT_VERY_EFFECTIVE)
    1347                gMoveResultFlags &= ~MOVE_RESULT_NOT_VERY_EFFECTIVE;
    1348            else
    1349                gMoveResultFlags |= MOVE_RESULT_SUPER_EFFECTIVE;
    
    src/battle_script_commands.c lines 1327–1352 at 731ad5b · upstream ↗

    Claim page

  4. ^Codepret/pokeemeraldbattle_script_commands.c 1375–1384
    How we know

    The type-calculation battle command flags a Ground move against a Levitate target as missed and “doesn't affect”, and walks no type row.

    1375    if (gBattleMons[gBattlerTarget].ability == ABILITY_LEVITATE && moveType == TYPE_GROUND)
    ⋮
    1377        gLastUsedAbility = gBattleMons[gBattlerTarget].ability;
    1378        gMoveResultFlags |= (MOVE_RESULT_MISSED | MOVE_RESULT_DOESNT_AFFECT_FOE);
    
    src/battle_script_commands.c lines 1375–1384 at 731ad5b · upstream ↗

    Claim page

  5. ^Codepret/pokeemeraldbattle_script_commands.c 1409–1414, 8221–8238
    How we know

    After the type rows, a target with Wonder Guard makes a damaging move miss unless the move carries the super-effective flag without the not-very-effective one. The check is skipped on the charging turn of a two-turn move (Skull Bash, Razor Wind, Sky Attack, Solar Beam outside sunshine, the semi-invulnerable moves, and Bide), so it applies on the turn the move strikes.

    1409    if (gBattleMons[gBattlerTarget].ability == ABILITY_WONDER_GUARD && AttacksThisTurn(gBattlerAttacker, gCurrentMove) == 2
    1410     && (!(gMoveResultFlags & MOVE_RESULT_SUPER_EFFECTIVE) || ((gMoveResultFlags & (MOVE_RESULT_SUPER_EFFECTIVE | MOVE_RESULT_NOT_VERY_EFFECTIVE)) == (MOVE_RESULT_SUPER_EFFECTIVE | MOVE_RESULT_NOT_VERY_EFFECTIVE)))
    1411     && gBattleMoves[gCurrentMove].power)
    ⋮
    1414        gMoveResultFlags |= MOVE_RESULT_MISSED;
    
    src/battle_script_commands.c lines 1409–1414 at 731ad5b · upstream ↗
    8221static u8 AttacksThisTurn(u8 battler, u16 move) // Note: returns 1 if it's a charging turn, otherwise 2
    ⋮
    8224    if (gBattleMoves[move].effect == EFFECT_SOLAR_BEAM
    8225        && (gBattleWeather & B_WEATHER_SUN))
    8226        return 2;
    ⋮
    8228    if (gBattleMoves[move].effect == EFFECT_SKULL_BASH
    8229     || gBattleMoves[move].effect == EFFECT_RAZOR_WIND
    8230     || gBattleMoves[move].effect == EFFECT_SKY_ATTACK
    8231     || gBattleMoves[move].effect == EFFECT_SOLAR_BEAM
    8232     || gBattleMoves[move].effect == EFFECT_SEMI_INVULNERABLE
    8233     || gBattleMoves[move].effect == EFFECT_BIDE)
    ⋮
    8235        if ((gHitMarker & HITMARKER_CHARGING))
    8236            return 1;
    ⋮
    
    src/battle_script_commands.c lines 8221–8238 at 731ad5b · upstream ↗

    Claim page

Sources

Code

Secondary