read_trainer_party.asm 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. ReadTrainer:
  2. ; don't change any moves in a link battle
  3. ld a, [wLinkState]
  4. and a
  5. ret nz
  6. ; set [wEnemyPartyCount] to 0, [wEnemyPartyMons] to FF
  7. ; XXX first is total enemy pokemon?
  8. ; XXX second is species of first pokemon?
  9. ld hl, wEnemyPartyCount
  10. xor a
  11. ld [hli], a
  12. dec a
  13. ld [hl], a
  14. ; get the pointer to trainer data for this class
  15. ld a, [wCurOpponent]
  16. sub $C9 ; convert value from pokemon to trainer
  17. add a
  18. ld hl, TrainerDataPointers
  19. ld c, a
  20. ld b, 0
  21. add hl, bc ; hl points to trainer class
  22. ld a, [hli]
  23. ld h, [hl]
  24. ld l, a
  25. ld a, [wTrainerNo]
  26. ld b, a
  27. ; At this point b contains the trainer number,
  28. ; and hl points to the trainer class.
  29. ; Our next task is to iterate through the trainers,
  30. ; decrementing b each time, until we get to the right one.
  31. .outer
  32. dec b
  33. jr z, .IterateTrainer
  34. .inner
  35. ld a, [hli]
  36. and a
  37. jr nz, .inner
  38. jr .outer
  39. ; if the first byte of trainer data is FF,
  40. ; - each pokemon has a specific level
  41. ; (as opposed to the whole team being of the same level)
  42. ; - if [wLoneAttackNo] != 0, one pokemon on the team has a special move
  43. ; else the first byte is the level of every pokemon on the team
  44. .IterateTrainer
  45. ld a, [hli]
  46. cp $FF ; is the trainer special?
  47. jr z, .SpecialTrainer ; if so, check for special moves
  48. ld [wCurEnemyLVL], a
  49. .LoopTrainerData
  50. ld a, [hli]
  51. and a ; have we reached the end of the trainer data?
  52. jr z, .FinishUp
  53. ld [wcf91], a ; write species somewhere (XXX why?)
  54. ld a, ENEMY_PARTY_DATA
  55. ld [wMonDataLocation], a
  56. push hl
  57. call AddPartyMon
  58. pop hl
  59. jr .LoopTrainerData
  60. .SpecialTrainer
  61. ; if this code is being run:
  62. ; - each pokemon has a specific level
  63. ; (as opposed to the whole team being of the same level)
  64. ; - if [wLoneAttackNo] != 0, one pokemon on the team has a special move
  65. ld a, [hli]
  66. and a ; have we reached the end of the trainer data?
  67. jr z, .AddLoneMove
  68. ld [wCurEnemyLVL], a
  69. ld a, [hli]
  70. ld [wcf91], a
  71. ld a, ENEMY_PARTY_DATA
  72. ld [wMonDataLocation], a
  73. push hl
  74. call AddPartyMon
  75. pop hl
  76. jr .SpecialTrainer
  77. .AddLoneMove
  78. ; does the trainer have a single monster with a different move
  79. ld a, [wLoneAttackNo] ; Brock is 01, Misty is 02, Erika is 04, etc
  80. and a
  81. jr z, .AddTeamMove
  82. dec a
  83. add a
  84. ld c, a
  85. ld b, 0
  86. ld hl, LoneMoves
  87. add hl, bc
  88. ld a, [hli]
  89. ld d, [hl]
  90. ld hl, wEnemyMon1Moves + 2
  91. ld bc, wEnemyMon2 - wEnemyMon1
  92. call AddNTimes
  93. ld [hl], d
  94. jr .FinishUp
  95. .AddTeamMove
  96. ; check if our trainer's team has special moves
  97. ; get trainer class number
  98. ld a, [wCurOpponent]
  99. sub 200
  100. ld b, a
  101. ld hl, TeamMoves
  102. ; iterate through entries in TeamMoves, checking each for our trainer class
  103. .IterateTeamMoves
  104. ld a, [hli]
  105. cp b
  106. jr z, .GiveTeamMoves ; is there a match?
  107. inc hl ; if not, go to the next entry
  108. inc a
  109. jr nz, .IterateTeamMoves
  110. ; no matches found. is this trainer champion rival?
  111. ld a, b
  112. cp SONY3
  113. jr z, .ChampionRival
  114. jr .FinishUp ; nope
  115. .GiveTeamMoves
  116. ld a, [hl]
  117. ld [wEnemyMon5Moves + 2], a
  118. jr .FinishUp
  119. .ChampionRival ; give moves to his team
  120. ; pidgeot
  121. ld a, SKY_ATTACK
  122. ld [wEnemyMon1Moves + 2], a
  123. ; starter
  124. ld a, [wRivalStarter]
  125. cp STARTER3
  126. ld b, MEGA_DRAIN
  127. jr z, .GiveStarterMove
  128. cp STARTER1
  129. ld b, FIRE_BLAST
  130. jr z, .GiveStarterMove
  131. ld b, BLIZZARD ; must be squirtle
  132. .GiveStarterMove
  133. ld a, b
  134. ld [wEnemyMon6Moves + 2], a
  135. .FinishUp
  136. ; clear wAmountMoneyWon addresses
  137. xor a
  138. ld de, wAmountMoneyWon
  139. ld [de], a
  140. inc de
  141. ld [de], a
  142. inc de
  143. ld [de], a
  144. ld a, [wCurEnemyLVL]
  145. ld b, a
  146. .LastLoop
  147. ; update wAmountMoneyWon addresses (money to win) based on enemy's level
  148. ld hl, wTrainerBaseMoney + 1
  149. ld c, 2 ; wAmountMoneyWon is a 3-byte number
  150. push bc
  151. predef AddBCDPredef
  152. pop bc
  153. inc de
  154. inc de
  155. dec b
  156. jr nz, .LastLoop ; repeat wCurEnemyLVL times
  157. ret