Advertisement
KDLPro

Encounter Code (with NatPark modification)

Mar 3rd, 2021
460
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; Modified Encounter Code
  2.  
  3. ChooseWildEncounter:
  4.     call LoadWildMonDataPointer
  5.     jp nc, .nowildbattle
  6.     call CheckEncounterRoamMon
  7.     jp c, .startwildbattle
  8.  
  9. ; Pick a random mon out of ContestMons.
  10.  
  11. .loop
  12.     call Random
  13.     cp 100 << 1
  14.     jr nc, .loop
  15.     srl a
  16.  
  17.     ld hl, ContestMons
  18.     ld de, 4
  19. .CheckMon:
  20.     sub [hl]
  21.     jr c, .GotMon
  22.     add hl, de
  23.     jr .CheckMon
  24.  
  25. .GotMon:
  26.     inc hl
  27.  
  28. ; Species
  29.     ld a, [hli]
  30.     ld [wTempWildMonSpecies], a
  31.  
  32. ; Min level
  33.     ld a, [hli]
  34.     ld d, a
  35.  
  36. ; Max level
  37.     ld a, [hl]
  38.  
  39.     sub d
  40.     jr nz, .RandomLevel
  41.  
  42. ; If min and max are the same.
  43.     ld a, d
  44.     jr .GotLevel
  45.  
  46. .RandomLevel:
  47. ; Get a random level between the min and max.
  48.     ld c, a
  49.     inc c
  50.     call Random
  51.     ldh a, [hRandomAdd]
  52.     call SimpleDivide
  53.     add d
  54.  
  55. .GotLevel:
  56.     ld [wCurPartyLevel], a
  57.  
  58.     xor a
  59.     ret
  60.  
  61. .nowildbattle
  62.     ld a, 1
  63.     and a
  64.     ret
  65.  
  66. .startwildbattle
  67.     xor a
  68.     ret
  69.    
  70. INCLUDE "data/wild/bug_contest_mons.asm"
  71.  
  72. ; Original Encounter code
  73.  
  74. ChooseWildEncounter:
  75.     call LoadWildMonDataPointer
  76.     jp nc, .nowildbattle
  77.     call CheckEncounterRoamMon
  78.     jp c, .startwildbattle
  79.  
  80.     inc hl
  81.     inc hl
  82.     inc hl
  83.     call CheckOnWater
  84.     ld de, WaterMonProbTable
  85.     jr z, .watermon
  86.     inc hl
  87.     inc hl
  88.     ld a, [wTimeOfDay]
  89.     ld bc, NUM_GRASSMON * 2
  90.     call AddNTimes
  91.     ld de, GrassMonProbTable
  92.  
  93. .watermon
  94. ; hl contains the pointer to the wild mon data, let's save that to the stack
  95.     push hl
  96. .randomloop
  97.     call Random
  98.     cp 100
  99.     jr nc, .randomloop
  100.     inc a ; 1 <= a <= 100
  101.     ld b, a
  102.     ld h, d
  103.     ld l, e
  104. ; This next loop chooses which mon to load up.
  105. .prob_bracket_loop
  106.     ld a, [hli]
  107.     cp b
  108.     jr nc, .got_it
  109.     inc hl
  110.     jr .prob_bracket_loop
  111.  
  112. .got_it
  113.     ld c, [hl]
  114.     ld b, 0
  115.     pop hl
  116.     add hl, bc ; this selects our mon
  117.     ld a, [hli]
  118.     ld b, a
  119. ; If the Pokemon is encountered by surfing, we need to give the levels some variety.
  120.     call CheckOnWater
  121.     jr nz, .ok
  122. ; Check if we buff the wild mon, and by how much.
  123.     call Random
  124.     cp 35 percent
  125.     jr c, .ok
  126.     inc b
  127.     cp 65 percent
  128.     jr c, .ok
  129.     inc b
  130.     cp 85 percent
  131.     jr c, .ok
  132.     inc b
  133.     cp 95 percent
  134.     jr c, .ok
  135.     inc b
  136. ; Store the level
  137. .ok
  138.     ld a, b
  139.     ld [wCurPartyLevel], a
  140.     ld b, [hl]
  141.     ; ld a, b
  142.     call ValidateTempWildMonSpecies
  143.     jr c, .nowildbattle
  144.  
  145.     ld a, b ; This is in the wrong place.
  146.     cp UNOWN
  147.     jr nz, .done
  148.  
  149.     ld a, [wUnlockedUnowns]
  150.     and a
  151.     jr z, .nowildbattle
  152.  
  153. .done
  154.     jr .loadwildmon
  155.  
  156. .nowildbattle
  157.     ld a, 1
  158.     and a
  159.     ret
  160.  
  161. .loadwildmon
  162.     ld a, b
  163.     ld [wTempWildMonSpecies], a
  164.  
  165. .startwildbattle
  166.     xor a
  167.     ret
  168.  
  169. INCLUDE "data/wild/probabilities.asm"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement