Advertisement
Crystal_

Untitled

Oct 20th, 2014
499
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; this has been made over the routine that loads an enemy Pokemon
  2. ; had to find a point to break the routine where
  3. ; 1: stats had already been loaded into RAM
  4. ; 2: working with registers bc, de, and hl was not a problem (for convenience)
  5.  
  6. #org 3EB10
  7. jp Main ; jumps to the new stuff
  8.  
  9. #org 3FE88
  10. Main:
  11. ld a,(D22D)
  12. cp a, 2 ; are we in a trainer battle?
  13. jp z, ApplyStatBoosts ; if so the stat boosts are applied, otherwise fallthrough
  14.  
  15. #org 3FE90
  16. Original:
  17. ; original routine stuff, that is, original 3EB10-3EB37
  18. ld hl,D073
  19. ld de,C616
  20. ld bc,000B
  21. call Label3026
  22. ld a,(D204)
  23. dec a
  24. ld c,a
  25. ld b,01
  26. ld hl,DEB9
  27. ld a,03
  28. call Label2D83
  29. ld hl,D21A
  30. ld de,C6C1
  31. ld bc,000A
  32. call Label3026
  33. ret ; the original routine finishes at this point
  34.  
  35. ApplyStatBoosts:
  36. ;    [1,32]: boost = 0
  37. ;   [33,54]: boost = level/16
  38. ;   [55,73]: boost = level/16 + level/16
  39. ;   [74,77]: boost = level/8
  40. ;   [78,99]: boost = level/8 + level/32
  41. ; [100,100]: boost = level/4
  42.  
  43. ld hl,D217 ; point to the first stat LSB (Max HP)
  44. ld c,7 ; there are seven stats (HP includes Max and Cur)
  45. ld a,(D143) ; get enemy's level
  46.  
  47. level100to100:
  48. cp a,$64
  49. jr c,level78to99 ; if not between 100 and 100, skip
  50. ld d,2 ; level will be halved twice
  51. call boost ; boost the stats
  52. jr Original ; we are done
  53.  
  54. level78to99:
  55. cp a,$4E
  56. jr c,level74to77
  57. ld d,3
  58. call boost ; level/(2^3) = level/8
  59. ld hl,D217 ; hl and c are lost at this point
  60. ld c,7
  61. ld d,5
  62. call boost ; level/(2^5) = level/32 --> level/8 + level/32
  63. jr Original ;
  64.  
  65. level74to77:
  66. cp a,$4A
  67. jr c,level55to73
  68. ld d,3
  69. call boost ; level/8
  70. jr Original
  71.  
  72. level55to73:
  73. cp a,$37
  74. jr c,level33to54
  75. ld d,4
  76. call boost
  77. ld hl,D217
  78. ld c,7
  79. ld d,4
  80. call boost ; level/16 + level/16
  81. jr Original
  82.  
  83. level33to54:
  84. cp a,$21
  85. jr c,level0to32
  86. ld d,4
  87. call boost ; level/16
  88. ; fallthrough
  89.  
  90. level0to32:
  91. jr Original ; no boost if level<33
  92.  
  93. #org 3EB13
  94. boost:
  95. ld a,(D143) ; get enemy's level (a gets overwritten on every loop)
  96. ld b,a
  97. ld e,d ; save d for later
  98. halve: ; halve level d times
  99. srl b
  100. dec d
  101. jr nz,halve
  102. ld a,(hl) ; a = attack LSB before boost has been applied
  103. add a,b
  104. ld (hl),a ; load a+b into the stat
  105. jr nc,finish ; overflow check
  106. dec hl ; if overflow, add 0x100 to the stat
  107. inc (hl) ; inc MSB
  108. inc hl ; point to LSB again
  109. finish:
  110. inc hl
  111. inc hl ; point to the next stat LSB
  112. dec c ; one less stat left
  113. ld d,e
  114. jr nz,boost ; loop if not done
  115. ret ; otherwise return
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement