Advertisement
Prof9

BN1 encounter check pseudocode

Feb 9th, 2015
523
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function encounterCheck() {
  2.     var area = loadByte(0x02000214);
  3.     var subarea = loadByte(0x02000215);
  4.    
  5.     var steps = loadWord(0x020003F4);
  6.     var prev = loadWord(0x020003F8);
  7.    
  8.     // If area is an overworld area, fail
  9.     if (area < 0x80) {
  10.         return false;
  11.     }
  12.     area -= 0x80;
  13.    
  14.     // If steps since last check < 64, fail
  15.     if (steps - prev < 0x40) {
  16.         return false;
  17.     }
  18.     prev = steps;
  19.     storeWord(prev, 0x020003F8);
  20.    
  21.     // Get the encounter rate curve index associated with this area
  22.     // Lower index = steeper curve = encounter rate rises more quickly
  23.     var curve = loadByte(0x080099BC + area * 0x10 + subarea);
  24.    
  25.     // Count roughly equals number of encounter checks before this one
  26.     var count = (steps / 0x40);
  27.     // Rate no longer increases after 16 encounter checks
  28.     if (count >= 0x11) {
  29.         count = 0x10;
  30.     }
  31.    
  32.     // Load the current encounter rate for this check
  33.     var rate = loadByte(0x08009934 + count * 8 + curve);
  34.    
  35.     if (rand(0x20) >= rate) {
  36.         return false;
  37.     } else {
  38.         return true;
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement