Golden Sun's random-number routine is a linear congruential generator, (0x41C64E6D and 0x3039; the state is a 32-bit unsigned int on the GBA), returning the state shifted right 8 as an unsigned short: bits 8 to 23 of the state. A second routine scales one result to 0 to 99, as the result × 100, shifted right 16 (computed). These are the constants of the C standard's example rand, which returns bits 16 to 30 instead. Pokémon Emerald's random-number routine keeps the multiplier but adds 24691 and returns the top 16 bits; pret's random.h defines a second step with Golden Sun's 12345. | src/random.c L11–16include/random.h L14–17 | Code |
| The 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. | src/battle_script_commands.c L9932–9935src/battle_main.c L3115src/data/pokemon/species_info.h L39–48 | 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. | src/battle_script_commands.c L840–847src/battle_script_commands.c L9937–9985include/constants/items.h L10–21 | Code |
| Emerald computes from catch rate , ball multiplier , max HP , and current HP , then doubles it for sleep or freeze, or multiplies it by 15/10 (rounded down) for poison, bad poison, burn, or paralysis. is the species' catch rate, or for a Safari Ball the Safari catch factor × 1275 / 100, rounded down. | src/battle_script_commands.c L9987–9994src/battle_script_commands.c L9930–9935 | Code |
| An over 254 catches at once. Otherwise Emerald turns it into a threshold , with Sqrt the GBA BIOS's square root, and draws up to four 16-bit random values; each one below 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. | src/battle_script_commands.c L10009–10050include/battle_controllers.h L134–141src/random.c L11–16libagbsyscall/libagbsyscall.s L72–78 | Code |
| Computed, counting every random value as equally likely and taking the BIOS square root as rounding down: a throw catches with chance when . Since 16,711,680 is 255 × 65,536 and 1,048,560 is 16 × 65,535, is close to and four passes close to , higher for small because both roots round down. A Bulbasaur (catch rate 45) with max HP 100 in a Poké Ball has and at full HP, about 6.25%, and , at 1 HP, about 19.8%. | src/battle_script_commands.c L9987–9989src/battle_script_commands.c L10025–10028src/data/pokemon/species_info.h L48 | Code |
| Ruby and Sapphire run the same formula and shake checks as Emerald, except that their status test leaves out bad poison (bit 7, a separate status bit from poison), so a badly poisoned Pokémon gets no bonus. Emerald's test includes it. | src/battle_script_commands.c L9987–9994src/battle_script_commands.c L10025–10028src/battle_script_commands.c L841–846 | Code |
| FireRed and LeafGreen run Emerald's formula, status test (bad poison included), and shake checks unchanged; before them, a ball thrown in a ghost battle (pokefirered/run) is dodged. | src/battle_script_commands.c L9987–10028 | 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. | src/battle_script_commands.c L9987–10028src/battle_script_commands.c L845src/data/pokemon/species_info.h L48 | Code |
| Emerald'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. | src/battle_main.c L329–449include/constants/pokemon.h L5–23 | Code |
| Emerald keeps the Game Boy encoding: 20 super effective, 10 normal, 5 not effective, and 0 no effect. | include/battle_main.h L31–34 | 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. | src/battle_main.c L335–449 | Code |
| Type 9, named "???", sits between the physical and special types and has no rows. | include/constants/pokemon.h L15src/battle_main.c L462 | Code |
| Before the type chart, the type-calculation battle command applies STAB as when either attacker type equals the move's type. | src/battle_script_commands.c L1368–1373include/battle.h L471 | Code |
| For each row of the move's type, the type-damage step runs once per distinct target type it matches: , raised from 0 to 1 unless the multiplier is 0. | src/battle_script_commands.c L1321–1325src/battle_script_commands.c L1386–1406 | 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. | src/battle_script_commands.c L1327–1352 | Code |
| Against a Foresight target, the loop breaks at the Foresight marker row, skipping the Normal→Ghost and Fighting→Ghost immunities after it. | src/battle_script_commands.c L1388–1394src/battle_main.c L445–447 | Code |
| Struggle skips the type-calculation battle command entirely, so neither STAB nor the type chart touches it. | src/battle_script_commands.c L1360–1364 | 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. | src/battle_script_commands.c L1375–1384 | 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. | src/battle_script_commands.c L1409–1414src/battle_script_commands.c L8221–8238 | 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. | src/battle_main.c L369–373src/battle_script_commands.c L1386–1405src/battle_script_commands.c L1321–1325include/battle_main.h L32–34 | Code |
| Type still decides physical or special in Emerald, by whether it comes before or after type 9, "???". | include/battle.h L466–467 | 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. | data/battle_scripts_1.s L249–252src/battle_script_commands.c L1658–1662 | 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. | src/battle_script_commands.c L1641–1649 | Code |
| The 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. | src/battle_script_commands.c L605–606src/battle_script_commands.c L1267–1285src/random.c L11–16 | 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. | src/battle_script_commands.c L1296src/pokemon.c L3234–3268 | Code |
| The 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. | src/battle_script_commands.c L1128–1176src/battle_script_commands.c L588–603 | Code |
| In Emerald a plain damaging move checks accuracy before it computes damage, the reverse of Red, Blue, and Crystal. | data/battle_scripts_1.s L241–252 | Code |
| The 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. | src/battle_script_commands.c L7139–7155data/battle_scripts_1.s L604–639 | Code |
Emerald's random number generator is a linear congruential generator, , returning the top 16 bits; pret's comment traces the multiplier to the example rand in the ISO C standard. | src/random.c L8–16include/random.h L14–17 | 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. | src/main.c L108–110src/main.c L208–236src/main.c L365–366src/naming_screen.c L700–701src/random.c L8 | Code |
| On 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. | src/wild_encounter.c L493–529src/wild_encounter.c L27src/data/wild_encounters.json L39–42 | Code |
| A step onto a tile whose behavior differs from the last one skips the encounter check 40% of the time. | src/wild_encounter.c L531–539src/wild_encounter.c L599–602 | 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. | src/data/wild_encounters.json L7–11src/wild_encounter.c L182–189json_data_rules.mk L11–12src/data/wild_encounters.constants.json.txt L13–15 | Code |
| After a battle starts, and whenever a map loads, the next 4 encounter checks are skipped. | src/field_control_avatar.c L662–675src/battle_setup.c L369–370src/overworld.c L800 | Code |
| An 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 , stored in a byte, exceeds a random byte, for earlier attempts. | src/battle_util.c L407–475 | Code |
| The 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. | src/battle_main.c L4595–4750 | Code |
| FireRed and LeafGreen's critical-hit command keeps Ruby's stages and its 1 in 16, 8, 4, 3, or 2, but rules out critical hits in the Old Man's catching tutorial, in Pokédude battles, and in the first battle until a tutorial flag is set. | src/battle_script_commands.c L1253–1288src/battle_script_commands.c L606 | Code |
| FireRed and LeafGreen's accuracy-check command is Emerald's with one addition: in Pokédude battles every move, on either side, skips the accuracy roll, and in the first battle the player's damaging moves skip it until one tutorial flag is set and the player's status moves until a second. | src/battle_script_commands.c L1099–1103 | Code |
| FireRed and LeafGreen's type chart is Emerald's, entry for entry: 108 matchup rows, the Foresight marker, two Ghost immunities, and the end marker. | src/battle_main.c L335–449 | Code |
| FireRed and LeafGreen keep Emerald's STAB, before the type rows; their type-calculation command differs from Emerald's only in how it names the defender's types. | src/battle_script_commands.c L1368–1372 | Code |
| FireRed and LeafGreen's damage-calculation and damage-adjustment commands diff identical with Emerald's: the damage calculation multiplies the base damage by the critical multiplier, 2 on a critical hit, and the random factor is damage × (100 − rand % 16) / 100, 85–100%. | src/battle_script_commands.c L1290–1296 | Code |
| FireRed and LeafGreen's command that sets the multi-hit count is Emerald's, line for line: 2 or 3 hits at 3/8 each and 4 or 5 at 1/8. The battle script runs the accuracy check once, then loops the critical-hit, damage-calculation, and damage-adjustment commands for every hit. | src/battle_script_commands.c L7139–7155 | Code |
| FireRed and LeafGreen's turn-order routine is Emerald's rule: the higher-priority move first, then the higher adjusted Speed, with a tie a coin flip, and a Quick Claw that sets Speed to the maximum on its roll. It differs only in withholding the third badge's ×1.1 Speed in link battles alone, where Emerald also withholds it in recorded-link and Frontier battles. | src/battle_main.c L4639–4654 | Code |
| In Platinum the damage formula reads each move's own class (physical, special, or status) and uses Attack against Defense for a physical move, Special Attack against Special Defense for a special one, whatever the move's type. Emerald picks the pair by type, below or above type 9 in the type list, so Thunder Punch (Electric) is special in Emerald and physical in Platinum, and Shadow Ball (Ghost) is physical in Emerald and special in Platinum. | include/battle.h L466–467include/constants/pokemon.h L13–19src/data/battle_moves.h L120–124src/data/battle_moves.h L3214–3218src/pokemon.c L3232src/pokemon.c L3287 | Code |
| Platinum's critical-hit routine keeps Emerald's stage table, 1 in 16, 8, 4, 3, or 2, capped at stage 4, and its sum: +2 for Focus Energy, +1 for a held item with the critical-rate hold effect, +2 for Chansey or Farfetch'd holding an item whose hold effect names that species, plus the move's boosts, which in Platinum come from a battle-script variable rather than a list of move effects. It adds +1 for the ability Super Luck, which Emerald's sum doesn't read. Besides Battle Armor and Shell Armor, which an attacker with Mold Breaker ignores, Lucky Chant on the target's side blocks a critical, and so does a move-effect flag on the target (bit 15) that a comment in the header says is checked but never set. Platinum draws its 16-bit roll before those tests, where Emerald draws it only after its other tests pass. | src/battle_script_commands.c L605–606src/battle_script_commands.c L1267–1283 | Code |
| A critical multiplies Platinum's damage by 2 after the base formula (its +2 included), at the same step as Emerald, and by 3 when the attacker has Sniper; Emerald's multiplier has no such case. As in Emerald, the critical then ignores the attacker's lowered attacking stat, the defender's raised defending stat, and Reflect or Light Screen. | src/battle_script_commands.c L1296src/pokemon.c L3234–3268src/pokemon.c L3287–3318 | Code |
| Platinum's shake-count routine keeps Emerald's capture math: the same , the same status bonuses (×2 for sleep or freeze; ×15/10 for poison, bad poison, burn, or paralysis), a catch at once when is 255 or more, and otherwise the threshold with up to four 16-bit rolls, each below a shake, and the Master Ball's shakes set to four after the draw. The two square roots run on the DS hardware square-root unit instead of Emerald's GBA BIOS call, and both games roll with the same generator, multiplier 1,103,515,245 and increment 24,691, keeping the top 16 bits. A Pal Park battle or the catching tutorial always catches. | src/battle_script_commands.c L9987–10031include/gba/syscall.h L20libagbsyscall/libagbsyscall.s L72–78include/random.h L16src/random.c L11–16 | Code |
| Platinum keeps Emerald's ball multipliers in tenths (Ultra 20, Great and Safari 15, Poké 10; Net 30 against Water or Bug, Nest 40 less the level below 40 with a floor of 10, Repeat 30, Timer 10 plus the turn count up to 40) and Emerald's 10 for the Luxury and Premier Balls. Two balls have new multipliers: a Dusk Ball gives 35 at night, late at night, or on cave terrain, and a Quick Ball 40 while the battle's turn count is 0. The Dive Ball's 35 now asks for water terrain where Emerald asks for an underwater map. A Safari Ball multiplies the catch rate by one of 13 fractions from 10/40 to 40/10, picked by a stage that starts at 6 (×1), where Emerald uses a Safari catch factor. The Heal and Cherish Balls, also new, give 10. | src/battle_script_commands.c L9932–9985include/constants/items.h L8–21src/battle_script_commands.c L841–846 | Code |
| Ruby and Sapphire's critical-hit command, which Emerald keeps apart from a renamed helper, sums Focus Energy (+2), a move whose effect is high-critical, Sky Attack, Blaze Kick, or Poison Tail (+1), a Scope Lens (+1), and Lucky Punch or Stick on their species (+2), caps the stage at 4, and hits critically 1 time in 16, 8, 4, 3, or 2. Battle Armor or Shell Armor on the target, a flag in the attacker's third status word, Wally's tutorial, and the first battle rule it out. | src/battle_script_commands.c L1253–1289src/battle_script_commands.c L606 | Code |
| Ruby and Sapphire's accuracy-check command, which Emerald keeps with renamed constants, scales a move's percent accuracy by one combined stage ratio, applies Compound Eyes (×1.3), Sand Veil in a sandstorm and Hustle on physical moves (×0.8 each), and a target's evasion item, and misses when a roll from 1 to 100 exceeds the result. | src/battle_script_commands.c L1099–1252 | Code |
| Ruby and Sapphire's type chart holds the same 110 rows as Emerald's and Crystal's, in the same order, with literal 0xFE and 0xFF bytes where Emerald names them as constants. | src/battle_main.c L335–449 | Code |
| Ruby and Sapphire's type-calculation command applies STAB as before the type rows, as Emerald's does. | src/battle_script_commands.c L1368–1372 | Code |
| Ruby and Sapphire already use Emerald's random factor, damage × (100 − rand % 16) / 100, raised to 1 if that gives 0 from damage that wasn't 0 (zero damage stays 0); Gen 1 and 2 reach about the same 85–100% spread as a byte from 217 to 255 over 255. | src/battle_script_commands.c L1639–1651 | Code |
| A move with the 2-to-5-hit effect in Ruby and Sapphire strikes 2 or 3 times with probability 3/8 each and 4 or 5 times with 1/8 each (computed). The count comes from a random number's low two bits (0 to 3): 0 or 1 gives 2 or 3 hits, and 2 or 3 draws again for 2 to 5 hits; a nonzero count written in a battle script is used instead, and this effect's script writes 0. The accuracy check runs once, before the count is set; each hit then rolls its own critical hit and its own damage, with a random factor of 85 to 100 percent (computed). The hits stop early when the user or the target has no HP left, when the user is asleep (unless the move came from Sleep Talk), when a hit misses, fails, or doesn't affect the target, or when the target endures. In the Ruby Rev 2 ROM, the compiled routine that sets the count has the same instructions as Emerald's, calling each game's own random-number routine and reading each game's own addresses. | src/battle_script_commands.c L7139–7155src/battle_script_commands.c L472 | Code |
Ruby and Sapphire multiply the area's encounter rate by 16, cut it to 80% on the Mach or Acro Bike, apply the flute and Cleanse Tag modifiers, halve it for a lead with Stench and double it for Illuminate, cap it at 2,880, and start a battle when Random() % 2880 is below it. Emerald keeps the roll and the cap and adds ability modifiers: White Smoke halves the rate, Arena Trap doubles it, Sand Veil halves it in a sandstorm, and Stench cuts it only to 3/4 in the Battle Pyramid. | src/wild_encounter.c L495–527 | Code |
| Ruby and Sapphire's escape routine always escapes with a Smoke Ball or Run Away; otherwise, in a single battle, a Pokémon at least as fast as the foe escapes, and a slower one when , for earlier tries, beats a random byte. Emerald adds only the Battle Pyramid's and Frontier's rules. | src/battle_util.c L407–485 | Code |