npc_movement.asm 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. PlayerStepOutFromDoor:
  2. ld hl, wd730
  3. res 1, [hl]
  4. call IsPlayerStandingOnDoorTile
  5. jr nc, .notStandingOnDoor
  6. ld a, $fc
  7. ld [wJoyIgnore], a
  8. ld hl, wd736
  9. set 1, [hl]
  10. ld a, $1
  11. ld [wSimulatedJoypadStatesIndex], a
  12. ld a, D_DOWN
  13. ld [wSimulatedJoypadStatesEnd], a
  14. xor a
  15. ld [wSpriteStateData1 + 2], a
  16. call StartSimulatingJoypadStates
  17. ret
  18. .notStandingOnDoor
  19. xor a
  20. ld [wWastedByteCD3A], a
  21. ld [wSimulatedJoypadStatesIndex], a
  22. ld [wSimulatedJoypadStatesEnd], a
  23. ld hl, wd736
  24. res 0, [hl]
  25. res 1, [hl]
  26. ld hl, wd730
  27. res 7, [hl]
  28. ret
  29. _EndNPCMovementScript:
  30. ld hl, wd730
  31. res 7, [hl]
  32. ld hl, wd72e
  33. res 7, [hl]
  34. ld hl, wd736
  35. res 0, [hl]
  36. res 1, [hl]
  37. xor a
  38. ld [wNPCMovementScriptSpriteOffset], a
  39. ld [wNPCMovementScriptPointerTableNum], a
  40. ld [wNPCMovementScriptFunctionNum], a
  41. ld [wWastedByteCD3A], a
  42. ld [wSimulatedJoypadStatesIndex], a
  43. ld [wSimulatedJoypadStatesEnd], a
  44. ret
  45. PalletMovementScriptPointerTable:
  46. dw PalletMovementScript_OakMoveLeft
  47. dw PalletMovementScript_PlayerMoveLeft
  48. dw PalletMovementScript_WaitAndWalkToLab
  49. dw PalletMovementScript_WalkToLab
  50. dw PalletMovementScript_Done
  51. PalletMovementScript_OakMoveLeft:
  52. ld a, [wXCoord]
  53. sub $a
  54. ld [wNumStepsToTake], a
  55. jr z, .playerOnLeftTile
  56. ; The player is on the right tile of the northern path out of Pallet Town and
  57. ; Prof. Oak is below.
  58. ; Make Prof. Oak step to the left.
  59. ld b, 0
  60. ld c, a
  61. ld hl, wNPCMovementDirections2
  62. ld a, NPC_MOVEMENT_LEFT
  63. call FillMemory
  64. ld [hl], $ff
  65. ld a, [wSpriteIndex]
  66. ld [H_SPRITEINDEX], a
  67. ld de, wNPCMovementDirections2
  68. call MoveSprite
  69. ld a, $1
  70. ld [wNPCMovementScriptFunctionNum], a
  71. jr .done
  72. ; The player is on the left tile of the northern path out of Pallet Town and
  73. ; Prof. Oak is below.
  74. ; Prof. Oak is already where he needs to be.
  75. .playerOnLeftTile
  76. ld a, $3
  77. ld [wNPCMovementScriptFunctionNum], a
  78. .done
  79. ld hl, wFlags_D733
  80. set 1, [hl]
  81. ld a, $fc
  82. ld [wJoyIgnore], a
  83. ret
  84. PalletMovementScript_PlayerMoveLeft:
  85. ld a, [wd730]
  86. bit 0, a ; is an NPC being moved by a script?
  87. ret nz ; return if Oak is still moving
  88. ld a, [wNumStepsToTake]
  89. ld [wSimulatedJoypadStatesIndex], a
  90. ld [hNPCMovementDirections2Index], a
  91. predef ConvertNPCMovementDirectionsToJoypadMasks
  92. call StartSimulatingJoypadStates
  93. ld a, $2
  94. ld [wNPCMovementScriptFunctionNum], a
  95. ret
  96. PalletMovementScript_WaitAndWalkToLab:
  97. ld a, [wSimulatedJoypadStatesIndex]
  98. and a ; is the player done moving left yet?
  99. ret nz
  100. PalletMovementScript_WalkToLab:
  101. xor a
  102. ld [wOverrideSimulatedJoypadStatesMask], a
  103. ld a, [wSpriteIndex]
  104. swap a
  105. ld [wNPCMovementScriptSpriteOffset], a
  106. xor a
  107. ld [wSpriteStateData2 + $06], a
  108. ld hl, wSimulatedJoypadStatesEnd
  109. ld de, RLEList_PlayerWalkToLab
  110. call DecodeRLEList
  111. dec a
  112. ld [wSimulatedJoypadStatesIndex], a
  113. ld hl, wNPCMovementDirections2
  114. ld de, RLEList_ProfOakWalkToLab
  115. call DecodeRLEList
  116. ld hl, wd72e
  117. res 7, [hl]
  118. ld hl, wd730
  119. set 7, [hl]
  120. ld a, $4
  121. ld [wNPCMovementScriptFunctionNum], a
  122. ret
  123. RLEList_ProfOakWalkToLab:
  124. db NPC_MOVEMENT_DOWN, $05
  125. db NPC_MOVEMENT_LEFT, $01
  126. db NPC_MOVEMENT_DOWN, $05
  127. db NPC_MOVEMENT_RIGHT, $03
  128. db NPC_MOVEMENT_UP, $01
  129. db $E0, $01 ; stand still
  130. db $FF
  131. RLEList_PlayerWalkToLab:
  132. db D_UP, $02
  133. db D_RIGHT, $03
  134. db D_DOWN, $05
  135. db D_LEFT, $01
  136. db D_DOWN, $06
  137. db $FF
  138. PalletMovementScript_Done:
  139. ld a, [wSimulatedJoypadStatesIndex]
  140. and a
  141. ret nz
  142. ld a, HS_PALLET_TOWN_OAK
  143. ld [wMissableObjectIndex], a
  144. predef HideObject
  145. ld hl, wd730
  146. res 7, [hl]
  147. ld hl, wd72e
  148. res 7, [hl]
  149. jp EndNPCMovementScript
  150. PewterMuseumGuyMovementScriptPointerTable:
  151. dw PewterMovementScript_WalkToMuseum
  152. dw PewterMovementScript_Done
  153. PewterMovementScript_WalkToMuseum:
  154. ld a, BANK(Music_MuseumGuy)
  155. ld [wAudioROMBank], a
  156. ld [wAudioSavedROMBank], a
  157. ld a, MUSIC_MUSEUM_GUY
  158. ld [wNewSoundID], a
  159. call PlaySound
  160. ld a, [wSpriteIndex]
  161. swap a
  162. ld [wNPCMovementScriptSpriteOffset], a
  163. call StartSimulatingJoypadStates
  164. ld hl, wSimulatedJoypadStatesEnd
  165. ld de, RLEList_PewterMuseumPlayer
  166. call DecodeRLEList
  167. dec a
  168. ld [wSimulatedJoypadStatesIndex], a
  169. xor a
  170. ld [wWhichPewterGuy], a
  171. predef PewterGuys
  172. ld hl, wNPCMovementDirections2
  173. ld de, RLEList_PewterMuseumGuy
  174. call DecodeRLEList
  175. ld hl, wd72e
  176. res 7, [hl]
  177. ld a, $1
  178. ld [wNPCMovementScriptFunctionNum], a
  179. ret
  180. RLEList_PewterMuseumPlayer:
  181. db 0, $01
  182. db D_UP, $03
  183. db D_LEFT, $0D
  184. db D_UP, $06
  185. db $FF
  186. RLEList_PewterMuseumGuy:
  187. db NPC_MOVEMENT_UP, $06
  188. db NPC_MOVEMENT_LEFT, $0D
  189. db NPC_MOVEMENT_UP, $03
  190. db NPC_MOVEMENT_LEFT, $01
  191. db $FF
  192. PewterMovementScript_Done:
  193. ld a, [wSimulatedJoypadStatesIndex]
  194. and a
  195. ret nz
  196. ld hl, wd730
  197. res 7, [hl]
  198. ld hl, wd72e
  199. res 7, [hl]
  200. jp EndNPCMovementScript
  201. PewterGymGuyMovementScriptPointerTable:
  202. dw PewterMovementScript_WalkToGym
  203. dw PewterMovementScript_Done
  204. PewterMovementScript_WalkToGym:
  205. ld a, BANK(Music_MuseumGuy)
  206. ld [wAudioROMBank], a
  207. ld [wAudioSavedROMBank], a
  208. ld a, MUSIC_MUSEUM_GUY
  209. ld [wNewSoundID], a
  210. call PlaySound
  211. ld a, [wSpriteIndex]
  212. swap a
  213. ld [wNPCMovementScriptSpriteOffset], a
  214. xor a
  215. ld [wSpriteStateData2 + $06], a
  216. ld hl, wSimulatedJoypadStatesEnd
  217. ld de, RLEList_PewterGymPlayer
  218. call DecodeRLEList
  219. dec a
  220. ld [wSimulatedJoypadStatesIndex], a
  221. ld a, 1
  222. ld [wWhichPewterGuy], a
  223. predef PewterGuys
  224. ld hl, wNPCMovementDirections2
  225. ld de, RLEList_PewterGymGuy
  226. call DecodeRLEList
  227. ld hl, wd72e
  228. res 7, [hl]
  229. ld hl, wd730
  230. set 7, [hl]
  231. ld a, $1
  232. ld [wNPCMovementScriptFunctionNum], a
  233. ret
  234. RLEList_PewterGymPlayer:
  235. db 0, $01
  236. db D_RIGHT, $02
  237. db D_DOWN, $05
  238. db D_LEFT, $0B
  239. db D_UP, $05
  240. db D_LEFT, $0F
  241. db $FF
  242. RLEList_PewterGymGuy:
  243. db NPC_MOVEMENT_DOWN, $02
  244. db NPC_MOVEMENT_LEFT, $0F
  245. db NPC_MOVEMENT_UP, $05
  246. db NPC_MOVEMENT_LEFT, $0B
  247. db NPC_MOVEMENT_DOWN, $05
  248. db NPC_MOVEMENT_RIGHT, $03
  249. db $FF
  250. FreezeEnemyTrainerSprite:
  251. ld a, [wCurMap]
  252. cp POKEMONTOWER_7
  253. ret z ; the Rockets on Pokemon Tower 7F leave after battling, so don't freeze them
  254. ld hl, RivalIDs
  255. ld a, [wEngagedTrainerClass]
  256. ld b, a
  257. .loop
  258. ld a, [hli]
  259. cp $ff
  260. jr z, .notRival
  261. cp b
  262. ret z ; the rival leaves after battling, so don't freeze him
  263. jr .loop
  264. .notRival
  265. ld a, [wSpriteIndex]
  266. ld [H_SPRITEINDEX], a
  267. jp SetSpriteMovementBytesToFF
  268. RivalIDs:
  269. db OPP_SONY1
  270. db OPP_SONY2
  271. db OPP_SONY3
  272. db $ff