Advertisement
Crystal_

Untitled

Mar 8th, 2014
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. getBadgelevel ; 3fdd
  2. ; outputs b = badgeLevel
  3. ld hl,D857 ; JohtoBadges
  4. ld b,02
  5. call CountSetBits
  6. ld e,a
  7. ld d,00
  8. ld hl,3FEF ; badgeLevelTable
  9. add hl,de
  10. ld a,(hl)
  11. ld b,a
  12. ret
  13.  
  14. badgeLevelTable ; 3fef
  15. db 14
  16. db 1E
  17. db 26
  18. db 2D
  19. db 36
  20. db 3C
  21. db 3F
  22. db 49
  23. db 52
  24. db 54
  25. db 56
  26. db 58
  27. db 5A
  28. db 5C
  29. db 5E
  30. db 60
  31. db 64
  32.  
  33. RareCandy: ; 04:6f14
  34. (...)
  35. call GetPartyParamLocation
  36. jp rcpatch ; jump from ef24
  37. jp nc,Functionee83
  38. (...)
  39.  
  40. rcpatch:
  41. push bc
  42. push af
  43. push de
  44. push hl
  45. call 3FDD ; getBadgeLevel
  46. pop hl
  47. pop de
  48. pop af
  49. ld a,(hl)
  50. cp b ; b = badgeLevel
  51. pop bc
  52. jp 6F27
  53.  
  54. DayCareMan:
  55. (...)
  56. jr z,72A4
  57. jp dcmpatch ; jump from 7289
  58. nop
  59. nop
  60. jr nc,72A4
  61. (...)
  62.  
  63. dcmpatch:
  64. push bc
  65. push af
  66. push de
  67. push hl
  68. call 3FDD ; getBadgeLevel
  69. pop hl
  70. pop de
  71. pop af
  72. ld a,(DF2B) ; monLevel
  73. cp b ; b = badgeLevel
  74. pop bc
  75. jp 728E
  76.  
  77. DayCareLady:
  78. (...)
  79. jr z,72C6
  80. jp dclpatch ; jump from 72ab
  81. nop
  82. nop
  83. jr nc,72C6
  84. (...)
  85.  
  86. dclpatch:
  87. push bc
  88. push af
  89. push de
  90. push hl
  91. call 3FDD ; getBadgeLevel
  92. pop hl
  93. pop de
  94. pop af
  95. ld a,(DF64) ; monLevel
  96. cp b ; b = badgeLevel
  97. pop bc
  98. jp 72B0
  99.  
  100. calcExpCap: ; calculate maximum experience allowed based on current badge level and Pokemon's growth rate
  101. ; outputs hQuotient = maximum experience allowed
  102. push af
  103. push bc
  104. push de
  105. push hl
  106. ld a,(D109) ; CurPartyMon
  107. ld hl,(DCAF); PartyMon1Species - (PartyMonNSpecies - PartyMonN-1Species) = PartyMon1Species - 30
  108. ld bc,0030 ; PartyMonNSpecies - PartyMonN-1Species
  109. inc a
  110. loop: ; make hl point to species of current party Pokemon
  111. add hl,bc
  112. dec a
  113. jr nz,loop
  114. ld d,(CF60) ; CurSpecies
  115. push de ; save (CF60) to restore CurSpecies later
  116. ld a,(hl)
  117. ld (CF60),a
  118. call GetBaseData ; load base data of Pokemon identified by CurSpecies into RAM, including growth rate
  119. ; Growth Rates:
  120. ; 0: exp = level^3
  121. ; 4: exp = level^3 * 4 / 5 (fast)
  122. ; 5: exp = level^3 * 5 / 4 (slow)
  123. call 3FDD ; getBadgeLevel
  124. xor a
  125. ld (FF00+B4),a ; hMultiplicand
  126. ld (FF00+B5),a ; hMultiplicand
  127. ld a,b ; badgeLevel
  128. ld (FF00+B6),a ; hMultiplicand
  129. ld (FF00+B7),a ; hMultiplier
  130. push af
  131. call Multiply ; 3119
  132. pop af
  133. ld (FF00+B7),a ;
  134. call Multiply
  135. ; we now have badgeLevel^3 at FFB3-FFB6, but FFB3 is never higher than 00
  136. ld a,(D24C) ; BaseGrowthRate
  137. and a
  138. jr z,finish ; if growth rate is 0 then exp = level^3
  139. cp 5
  140. jr z,slowExpGroup
  141. fastExpGroup: ; multiply by 4 and divide by 5
  142. ld a,4
  143. ld (FF00+B7),a
  144. call Multiply ; again, result is at FFB3-FFB6
  145. ld a,5
  146. ld b,4 ; dividend is 4 bytes long (or 3)
  147. ld (FF00+B7),a ; hDivisor
  148. call Divide ; hDividend is FFB3-FFB6
  149. jr, finish
  150. slowExpGroup: ; multiply by 5 and divide by 4
  151. ld a,5
  152. ld (FF00+B7),a
  153. call Multiply ; again, result is at FFB3-FFB6
  154. ld a,4
  155. ld b,4 ; dividend is 4 bytes long (or 3)
  156. ld (FF00+B7),a ; hDivisor
  157. call Divide ; hDividend is FFB3-FFB6
  158. finish:
  159. pop de ; restore CurSpecies
  160. ld (CF60),d ; CurSpecies
  161. call GetBaseData ; restore base data of original Pokemon
  162. pop hl
  163. pop de
  164. pop bc
  165. pop af
  166. ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement