Advertisement
Guest User

Trainer EV system

a guest
Jan 10th, 2014
369
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]: no boost
  37. ;  [33,34]: boost = level/16 = 2
  38. ;  [35,54]: boost = level/16 + level/32
  39. ;  [55,73]: boost = level/8
  40. ;  [74,77]: boost = level/8 + level/16
  41. ; [78,100]: boost = level/4
  42.  
  43. ld hl,D21B ; point to the first stat LSB (attack)
  44. ld c,5 ; there are five stats
  45. ld a,(D143) ; get enemy's level
  46.  
  47. level78to100:
  48. cp a,4E
  49. jr c,level74to77 ; if not between 78 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. level74to77:
  55. cp a,4A
  56. jr c,level55to73
  57. ld d,3
  58. call boost ; level/(2^3) = level/8
  59. ld hl,D21B
  60. ld c,5
  61. ld d,4
  62. call boost ; level/(2^4) = level/16 --> level/8 + level/16
  63. jr Original ;
  64.  
  65. level55to73:
  66. cp a,37
  67. jr c,level36to54
  68. ld d,3
  69. call boost
  70. jr Original
  71.  
  72. level35to54:
  73. cp a,23
  74. jr c,level33to34
  75. ld d,4
  76. call boost
  77. ld hl,D21B
  78. ld c,5
  79. ld d,5
  80. call boost
  81. jr Original
  82.  
  83. level33to34:
  84. cp a,21
  85. jr c,level0to32
  86. ld d,4
  87. call boost ; fallthrough
  88.  
  89. level0to32:
  90. jr Original ; no boost if level<33
  91.  
  92. #org 3EB13
  93. boost:
  94. ld a,(D143) ; get enemy's level (a gets overwritten on every loop)
  95. ld b,a
  96. ld e,d ; save d for later
  97. halve: ; halve level d times
  98. srl b
  99. dec d
  100. jr nz,halve
  101. ld a,(hl) ; a = attack LSB before boost has been applied
  102. add a,b
  103. ld (hl),a ; load a+b into the stat
  104. jr nc,finish ; overflow check
  105. dec hl ; if overflow, add 0x100 to the stat
  106. inc (hl) ; inc MSB
  107. inc hl ; point to LSB again
  108. finish:
  109. inc hl
  110. inc hl ; point to the next stat LSB
  111. dec c ; one less stat left
  112. ld d,e
  113. jr nz,boost ; loop if not done
  114. ret ; otherwise return
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement