Advertisement
Guest User

wild issue

a guest
Nov 17th, 2019
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.38 KB | None | 0 0
  1. LoadWildMonData:
  2. call _GrassWildmonLookup
  3. jr c, .copy
  4. ld hl, wMornEncounterRate
  5. xor a
  6. ld [hli], a
  7. ld [hli], a
  8. ld [hl], a
  9. jr .done_copy
  10. ; jr .done_copy2
  11.  
  12. .copy
  13. inc hl
  14. inc hl
  15. ld de, wMornEncounterRate
  16. ld bc, 3
  17. call CopyBytes
  18. .done_copy
  19. call _WaterWildmonLookup
  20. ld a, 0
  21. jr nc, .no_copy
  22. inc hl
  23. inc hl
  24. ld a, [hl]
  25. ;.done_copy2
  26. ; call _ShallowWildmonLookup
  27. ; ld a, 0
  28. ; jr nc, .no_copy2
  29. ; inc hl
  30. ; inc hl
  31. ; ld a, [hl]
  32. .no_copy
  33. ld [wWaterEncounterRate], a
  34. ret
  35. ;.no_copy2
  36. ; ld [wShallowEncounterRate], a
  37. ; ret
  38.  
  39. FindNest:
  40. ; Parameters:
  41. ; e: 0 = Johto, 1 = Kanto
  42. ; wNamedObjectIndexBuffer: species
  43. hlcoord 0, 0
  44. ld bc, SCREEN_WIDTH * SCREEN_HEIGHT
  45. xor a
  46. call ByteFill
  47. ld a, e
  48. and a
  49. jr nz, .kanto
  50. decoord 0, 0
  51. ld hl, JohtoGrassWildMons
  52. call .FindGrass
  53. ld hl, JohtoWaterWildMons
  54. call .FindWater
  55. ld hl, JohtoShallowWildMons
  56. call .FindShallow
  57. call .RoamMon1
  58. call .RoamMon2
  59. ret
  60.  
  61. .kanto
  62. decoord 0, 0
  63. ld hl, KantoGrassWildMons
  64. call .FindGrass
  65. ld hl, KantoWaterWildMons
  66. jp .FindWater
  67.  
  68. .FindGrass:
  69. ld a, [hl]
  70. cp -1
  71. ret z
  72. push hl
  73. ld a, [hli]
  74. ld b, a
  75. ld a, [hli]
  76. ld c, a
  77. inc hl
  78. inc hl
  79. inc hl
  80. ld a, NUM_GRASSMON * 3
  81. call .SearchMapForMon
  82. jr nc, .next_grass
  83. ld [de], a
  84. inc de
  85.  
  86. .next_grass
  87. pop hl
  88. ld bc, GRASS_WILDDATA_LENGTH
  89. add hl, bc
  90. jr .FindGrass
  91.  
  92. .FindWater:
  93. ld a, [hl]
  94. cp -1
  95. ret z
  96. push hl
  97. ld a, [hli]
  98. ld b, a
  99. ld a, [hli]
  100. ld c, a
  101. inc hl
  102. ld a, NUM_WATERMON
  103. call .SearchMapForMon
  104. jr nc, .next_water
  105. ld [de], a
  106. inc de
  107.  
  108. .next_water
  109. pop hl
  110. ld bc, WATER_WILDDATA_LENGTH
  111. add hl, bc
  112. jr .FindWater
  113.  
  114. .FindShallow:
  115. ld a, [hl]
  116. cp -1
  117. ret z
  118. push hl
  119. ld a, [hli]
  120. ld b, a
  121. ld a, [hli]
  122. ld c, a
  123. inc hl
  124. ; ld a, NUM_SHALLOWMON
  125. ld a, NUM_WATERMON
  126. call .SearchMapForMon
  127. ; jr nc, .next_shallow
  128. jr nc, .next_water
  129. ld [de], a
  130. inc de
  131.  
  132. ;.next_shallow
  133. ; pop hl
  134. ; ld bc, SHALLOW_WILDDATA_LENGTH
  135. ; add hl, bc
  136. ; jr .FindShallow
  137.  
  138. .SearchMapForMon:
  139. inc hl
  140. .ScanMapLoop:
  141. push af
  142. ld a, [wNamedObjectIndexBuffer]
  143. cp [hl]
  144. jr z, .found
  145. inc hl
  146. inc hl
  147. pop af
  148. dec a
  149. jr nz, .ScanMapLoop
  150. and a
  151. ret
  152.  
  153. .found
  154. pop af
  155. jp .AppendNest
  156.  
  157. .AppendNest:
  158. push de
  159. call GetWorldMapLocation
  160. ld c, a
  161. hlcoord 0, 0
  162. ld de, SCREEN_WIDTH * SCREEN_HEIGHT
  163. .AppendNestLoop:
  164. ld a, [hli]
  165. cp c
  166. jr z, .found_nest
  167. dec de
  168. ld a, e
  169. or d
  170. jr nz, .AppendNestLoop
  171. ld a, c
  172. pop de
  173. scf
  174. ret
  175.  
  176. .found_nest
  177. pop de
  178. and a
  179. ret
  180.  
  181. .RoamMon1:
  182. ld a, [wRoamMon1Species]
  183. ld b, a
  184. ld a, [wNamedObjectIndexBuffer]
  185. cp b
  186. ret nz
  187. ld a, [wRoamMon1MapGroup]
  188. ld b, a
  189. ld a, [wRoamMon1MapNumber]
  190. ld c, a
  191. call .AppendNest
  192. ret nc
  193. ld [de], a
  194. inc de
  195. ret
  196.  
  197. .RoamMon2:
  198. ld a, [wRoamMon2Species]
  199. ld b, a
  200. ld a, [wNamedObjectIndexBuffer]
  201. cp b
  202. ret nz
  203. ld a, [wRoamMon2MapGroup]
  204. ld b, a
  205. ld a, [wRoamMon2MapNumber]
  206. ld c, a
  207. call .AppendNest
  208. ret nc
  209. ld [de], a
  210. inc de
  211. ret
  212.  
  213. TryWildEncounter::
  214. ; Try to trigger a wild encounter.
  215. call .EncounterRate
  216. jr nc, .no_battle
  217. call ChooseWildEncounter
  218. jr nz, .no_battle
  219. call CheckRepelEffect
  220. jr nc, .no_battle
  221. xor a
  222. ret
  223.  
  224. .no_battle
  225. xor a ; BATTLETYPE_NORMAL
  226. ld [wTempWildMonSpecies], a
  227. ld [wBattleType], a
  228. ld a, 1
  229. and a
  230. ret
  231.  
  232. .EncounterRate:
  233. call GetMapEncounterRate
  234. call ApplyMusicEffectOnEncounterRate
  235. call ApplyCleanseTagEffectOnEncounterRate
  236. call Random
  237. cp b
  238. ret
  239.  
  240. GetMapEncounterRate: ;MMMMMMAY NEED TO EDIT
  241. ld hl, wMornEncounterRate
  242. call CheckOnWater
  243. ld a, wWaterEncounterRate - wMornEncounterRate
  244. jr z, .ok
  245. call CheckOnShallow
  246. ; ld a, wShallowEncounterRate - wMornEncounterRate
  247. ld a, wWaterEncounterRate - wMornEncounterRate
  248. jr z, .ok
  249. ld a, [wTimeOfDay]
  250. .ok
  251. ld c, a
  252. ld b, 0
  253. add hl, bc
  254. ld b, [hl]
  255. ret
  256.  
  257. ApplyMusicEffectOnEncounterRate::
  258. ; Pokemon March and Ruins of Alph signal double encounter rate.
  259. ; Pokemon Lullaby halves encounter rate.
  260. ld a, [wMapMusic]
  261. cp MUSIC_POKEMON_MARCH
  262. jr z, .double
  263. cp MUSIC_RUINS_OF_ALPH_RADIO
  264. jr z, .double
  265. cp MUSIC_POKEMON_LULLABY
  266. ret nz
  267. srl b
  268. ret
  269.  
  270. .double
  271. sla b
  272. ret
  273.  
  274. ApplyCleanseTagEffectOnEncounterRate::
  275. ; Cleanse Tag halves encounter rate.
  276. ld hl, wPartyMon1Item
  277. ld de, PARTYMON_STRUCT_LENGTH
  278. ld a, [wPartyCount]
  279. ld c, a
  280. .loop
  281. ld a, [hl]
  282. cp CLEANSE_TAG
  283. jr z, .cleansetag
  284. add hl, de
  285. dec c
  286. jr nz, .loop
  287. ret
  288.  
  289. .cleansetag
  290. srl b
  291. ret
  292.  
  293. ChooseWildEncounter:
  294. call LoadWildMonDataPointer
  295. jp nc, .nowildbattle
  296. call CheckEncounterRoamMon
  297. jp c, .startwildbattle
  298.  
  299. inc hl
  300. inc hl
  301. inc hl
  302. call CheckOnShallow
  303. ld de, WaterMonProbTable
  304. jr z, .watermon
  305. call CheckOnWater
  306. ld de, WaterMonProbTable
  307. jr z, .watermon
  308. ; call CheckOnShallow
  309. ; ld de, ShallowMonProbTable
  310. ; jr z, .shallowmon
  311. ; ld de, WaterMonProbTable
  312. ; jr z, .watermon
  313. inc hl
  314. inc hl
  315. ld a, [wTimeOfDay]
  316. ld bc, NUM_GRASSMON * 2
  317. call AddNTimes
  318. ld de, GrassMonProbTable
  319.  
  320. .watermon
  321. ; hl contains the pointer to the wild mon data, let's save that to the stack
  322. push hl
  323. ;.shallowmon
  324. ; hl contains the pointer to the wild mon data, let's save that to the stack
  325. ; push hl
  326. .randomloop
  327. call Random
  328. cp 100
  329. jr nc, .randomloop
  330. inc a ; 1 <= a <= 100
  331. ld b, a
  332. ld h, d
  333. ld l, e
  334. ; This next loop chooses which mon to load up.
  335. .prob_bracket_loop
  336. ld a, [hli]
  337. cp b
  338. jr nc, .got_it
  339. inc hl
  340. jr .prob_bracket_loop
  341.  
  342. .got_it
  343. ld c, [hl]
  344. ld b, 0
  345. ld hl, wJohtoBadges
  346.  
  347. ; stormbadge
  348. bit STORMBADGE, [hl]
  349. ld e, 50
  350.  
  351. ; fogbadge
  352. bit FOGBADGE, [hl]
  353. ld e, 30
  354.  
  355. ; hivebadge
  356. bit HIVEBADGE, [hl]
  357. ld e, 10
  358.  
  359. ; no badges
  360. ld e, 0
  361. pop hl
  362. add hl, bc ; this selects our mon
  363. ld a, [hli]
  364. ld b, a
  365. add b, e
  366. ; If the Pokemon is encountered by surfing, we need to give the levels some variety.
  367. ;readvar NUM_BADGES
  368. ;ifgreater 3, .lvup
  369. ;jump .flux
  370.  
  371. ;.lvup
  372. ; inc b
  373. ; inc b
  374. ; inc b
  375. ; inc b
  376. ; inc b
  377. ; jr .flux
  378.  
  379. ;.levelbase
  380.  
  381. .flux
  382. ; Check if we buff the wild mon, and by how much.
  383. call Random
  384. cp 35 percent
  385. jr c, .ok
  386. inc b
  387. cp 65 percent
  388. jr c, .ok
  389. inc b
  390. cp 85 percent
  391. jr c, .ok
  392. inc b
  393. cp 95 percent
  394. jr c, .ok
  395. inc b
  396.  
  397. ; Store the level
  398. .ok
  399. ld a, b
  400. ld [wCurPartyLevel], a
  401. ld b, [hl]
  402. ld a, b ;
  403. call ValidateTempWildMonSpecies
  404. jr c, .nowildbattle
  405.  
  406. ;ld a, b ; This is in the wrong place.
  407. cp UNOWN
  408. jr nz, .done
  409.  
  410. ld a, [wUnlockedUnowns]
  411. and a
  412. jr z, .nowildbattle
  413.  
  414. .done
  415. jr .loadwildmon
  416.  
  417. .nowildbattle
  418. ld a, 1
  419. and a
  420. ret
  421.  
  422. .loadwildmon
  423. ld a, b
  424. ld [wTempWildMonSpecies], a
  425.  
  426. .startwildbattle
  427. xor a
  428. ret
  429.  
  430. INCLUDE "data/wild/probabilities.asm" ;CCCCCHHHHANANND
  431.  
  432. CheckRepelEffect::
  433. ; If there is no active Repel, there's no need to be here.
  434. ld a, [wRepelEffect]
  435. and a
  436. jr z, .encounter
  437. ; Get the first Pokemon in your party that isn't fainted.
  438. ld hl, wPartyMon1HP
  439. ld bc, PARTYMON_STRUCT_LENGTH - 1
  440. .loop
  441. ld a, [hli]
  442. or [hl]
  443. jr nz, .ok
  444. add hl, bc
  445. jr .loop
  446.  
  447. .ok
  448. ; to PartyMonLevel
  449. rept 4
  450. dec hl
  451. endr
  452.  
  453. ld a, [wCurPartyLevel]
  454. cp [hl]
  455. jr nc, .encounter
  456. and a
  457. ret
  458.  
  459. .encounter
  460. scf
  461. ret
  462.  
  463. LoadWildMonDataPointer:
  464. call CheckOnWater
  465. jr z, _WaterWildmonLookup
  466. call CheckOnShallow
  467. ; jr z, _ShallowWildmonLookup
  468. jr z, _WaterWildmonLookup
  469.  
  470. _GrassWildmonLookup:
  471. ld hl, SwarmGrassWildMons
  472. ld bc, GRASS_WILDDATA_LENGTH
  473. call _SwarmWildmonCheck
  474. ret c
  475. ld hl, JohtoGrassWildMons
  476. ld de, KantoGrassWildMons
  477. call _JohtoWildmonCheck
  478. ld bc, GRASS_WILDDATA_LENGTH
  479. jr _NormalWildmonOK
  480.  
  481. _WaterWildmonLookup:
  482. ld hl, SwarmWaterWildMons
  483. ld bc, WATER_WILDDATA_LENGTH
  484. call _SwarmWildmonCheck
  485. ret c
  486. ld hl, JohtoWaterWildMons
  487. ld de, KantoWaterWildMons
  488. call _JohtoWildmonCheck
  489. ld bc, WATER_WILDDATA_LENGTH
  490. jr _NormalWildmonOK
  491.  
  492. _ShallowWildmonLookup:
  493. ; ld hl, SwarmWaterWildMons
  494. ; ld bc, SHALLOW_WILDDATA_LENGTH
  495. ; call _SwarmWildmonCheck
  496. ; ret c
  497. ; ld hl, JohtoShallowWildMons
  498. ; ld de, KantoWaterWildMons
  499. ; call _JohtoWildmonCheck
  500. ; ld bc, SHALLOW_WILDDATA_LENGTH
  501. ; jr _NormalWildmonOK
  502. ld hl, SwarmWaterWildMons
  503. ld bc, WATER_WILDDATA_LENGTH
  504. call _SwarmWildmonCheck
  505. ret c
  506. ld hl, JohtoWaterWildMons
  507. ld de, KantoWaterWildMons
  508. call _JohtoWildmonCheck
  509. ld bc, WATER_WILDDATA_LENGTH
  510. jr _NormalWildmonOK
  511.  
  512. _JohtoWildmonCheck:
  513. call IsInJohto
  514. and a
  515. ret z
  516. ld h, d
  517. ld l, e
  518. ret
  519.  
  520. _SwarmWildmonCheck:
  521. call CopyCurrMapDE
  522. push hl
  523. ld hl, wSwarmFlags
  524. bit SWARMFLAGS_DUNSPARCE_SWARM_F, [hl]
  525. pop hl
  526. jr z, .CheckYanma
  527. ld a, [wDunsparceMapGroup]
  528. cp d
  529. jr nz, .CheckYanma
  530. ld a, [wDunsparceMapNumber]
  531. cp e
  532. jr nz, .CheckYanma
  533. call LookUpWildmonsForMapDE
  534. jr nc, _NoSwarmWildmon
  535. scf
  536. ret
  537.  
  538. .CheckYanma:
  539. push hl
  540. ld hl, wSwarmFlags
  541. bit SWARMFLAGS_YANMA_SWARM_F, [hl]
  542. pop hl
  543. jr z, _NoSwarmWildmon
  544. ld a, [wYanmaMapGroup]
  545. cp d
  546. jr nz, _NoSwarmWildmon
  547. ld a, [wYanmaMapNumber]
  548. cp e
  549. jr nz, _NoSwarmWildmon
  550. call LookUpWildmonsForMapDE
  551. jr nc, _NoSwarmWildmon
  552. scf
  553. ret
  554.  
  555. _NoSwarmWildmon:
  556. and a
  557. ret
  558.  
  559. _NormalWildmonOK:
  560. call CopyCurrMapDE
  561. jr LookUpWildmonsForMapDE
  562.  
  563. CopyCurrMapDE:
  564. ld a, [wMapGroup]
  565. ld d, a
  566. ld a, [wMapNumber]
  567. ld e, a
  568. ret
  569.  
  570. LookUpWildmonsForMapDE:
  571. .loop
  572. push hl
  573. ld a, [hl]
  574. inc a
  575. jr z, .nope
  576. ld a, d
  577. cp [hl]
  578. jr nz, .next
  579. inc hl
  580. ld a, e
  581. cp [hl]
  582. jr z, .yup
  583.  
  584. .next
  585. pop hl
  586. add hl, bc
  587. jr .loop
  588.  
  589. .nope
  590. pop hl
  591. and a
  592. ret
  593.  
  594. .yup
  595. pop hl
  596. scf
  597. ret
  598.  
  599. InitRoamMons:
  600. ; initialize wRoamMon structs
  601.  
  602. ; species
  603. ld a, RAIKOU
  604. ld [wRoamMon1Species], a
  605. ld a, ENTEI
  606. ld [wRoamMon2Species], a
  607.  
  608. ; level
  609. ld a, 40
  610. ld [wRoamMon1Level], a
  611. ld [wRoamMon2Level], a
  612.  
  613. ; raikou starting map
  614. ld a, GROUP_ROUTE_42
  615. ld [wRoamMon1MapGroup], a
  616. ld a, MAP_ROUTE_42
  617. ld [wRoamMon1MapNumber], a
  618.  
  619. ; entei starting map
  620. ld a, GROUP_ROUTE_37
  621. ld [wRoamMon2MapGroup], a
  622. ld a, MAP_ROUTE_37
  623. ld [wRoamMon2MapNumber], a
  624.  
  625. ; hp
  626. xor a ; generate new stats
  627. ld [wRoamMon1HP], a
  628. ld [wRoamMon2HP], a
  629.  
  630. ret
  631.  
  632. CheckEncounterRoamMon:
  633. push hl
  634. ; Don't trigger an encounter if we're on water.
  635. call CheckOnWater
  636. jr z, .DontEncounterRoamMon
  637. ; Load the current map group and number to de
  638. call CopyCurrMapDE
  639. ; Randomly select a beast.
  640. call Random
  641. cp 100 ; 25/64 chance
  642. jr nc, .DontEncounterRoamMon
  643. and %00000011 ; Of that, a 3/4 chance. Running total: 75/256, or around 29.3%.
  644. jr z, .DontEncounterRoamMon
  645. dec a ; 1/3 chance that it's Entei, 1/3 chance that it's Raikou
  646. ; Compare its current location with yours
  647. ld hl, wRoamMon1MapGroup
  648. ld c, a
  649. ld b, 0
  650. ld a, 7 ; length of the roam_struct
  651. call AddNTimes
  652. ld a, d
  653. cp [hl]
  654. jr nz, .DontEncounterRoamMon
  655. inc hl
  656. ld a, e
  657. cp [hl]
  658. jr nz, .DontEncounterRoamMon
  659. ; We've decided to take on a beast, so stage its information for battle.
  660. dec hl
  661. dec hl
  662. dec hl
  663. ld a, [hli]
  664. ld [wTempWildMonSpecies], a
  665. ld a, [hl]
  666. ld [wCurPartyLevel], a
  667. ld a, BATTLETYPE_ROAMING
  668. ld [wBattleType], a
  669.  
  670. pop hl
  671. scf
  672. ret
  673.  
  674. .DontEncounterRoamMon:
  675. pop hl
  676. and a
  677. ret
  678.  
  679. UpdateRoamMons:
  680. ld a, [wRoamMon1MapGroup]
  681. cp GROUP_N_A
  682. jr z, .SkipRaikou
  683. ld b, a
  684. ld a, [wRoamMon1MapNumber]
  685. ld c, a
  686. call .Update
  687. ld a, b
  688. ld [wRoamMon1MapGroup], a
  689. ld a, c
  690. ld [wRoamMon1MapNumber], a
  691.  
  692. .SkipRaikou:
  693. ld a, [wRoamMon2MapGroup]
  694. cp GROUP_N_A
  695. jr z, .SkipEntei
  696. ld b, a
  697. ld a, [wRoamMon2MapNumber]
  698. ld c, a
  699. call .Update
  700. ld a, b
  701. ld [wRoamMon2MapGroup], a
  702. ld a, c
  703. ld [wRoamMon2MapNumber], a
  704.  
  705. .SkipEntei:
  706. ld a, [wRoamMon3MapGroup]
  707. cp GROUP_N_A
  708. jr z, .Finished
  709. ld b, a
  710. ld a, [wRoamMon3MapNumber]
  711. ld c, a
  712. call .Update
  713. ld a, b
  714. ld [wRoamMon3MapGroup], a
  715. ld a, c
  716. ld [wRoamMon3MapNumber], a
  717.  
  718. .Finished:
  719. jp _BackUpMapIndices
  720.  
  721. .Update:
  722. ld hl, RoamMaps
  723. .loop
  724. ; Are we at the end of the table?
  725. ld a, [hl]
  726. cp -1
  727. ret z
  728. ; Is this the correct entry?
  729. ld a, b
  730. cp [hl]
  731. jr nz, .next
  732. inc hl
  733. ld a, c
  734. cp [hl]
  735. jr z, .yes
  736. ; We don't have the correct entry yet, so let's continue. A 0 terminates each entry.
  737. .next
  738. ld a, [hli]
  739. and a
  740. jr nz, .next
  741. jr .loop
  742.  
  743. ; We have the correct entry now, so let's choose a random map from it.
  744. .yes
  745. inc hl
  746. ld d, h
  747. ld e, l
  748. .update_loop
  749. ld h, d
  750. ld l, e
  751. ; Choose which map to warp to.
  752. call Random
  753. and %00011111 ; 1/8n chance it moves to a completely random map, where n is the number of roaming connections from the current map.
  754. jr z, JumpRoamMon
  755. and %11
  756. cp [hl]
  757. jr nc, .update_loop ; invalid index, try again
  758. inc hl
  759. ld c, a
  760. ld b, 0
  761. add hl, bc
  762. add hl, bc
  763. ld a, [wRoamMons_LastMapGroup]
  764. cp [hl]
  765. jr nz, .done
  766. inc hl
  767. ld a, [wRoamMons_LastMapNumber]
  768. cp [hl]
  769. jr z, .update_loop
  770. dec hl
  771.  
  772. .done
  773. ld a, [hli]
  774. ld b, a
  775. ld c, [hl]
  776. ret
  777.  
  778. JumpRoamMons:
  779. ld a, [wRoamMon1MapGroup]
  780. cp GROUP_N_A
  781. jr z, .SkipRaikou
  782. call JumpRoamMon
  783. ld a, b
  784. ld [wRoamMon1MapGroup], a
  785. ld a, c
  786. ld [wRoamMon1MapNumber], a
  787.  
  788. .SkipRaikou:
  789. ld a, [wRoamMon2MapGroup]
  790. cp GROUP_N_A
  791. jr z, .SkipEntei
  792. call JumpRoamMon
  793. ld a, b
  794. ld [wRoamMon2MapGroup], a
  795. ld a, c
  796. ld [wRoamMon2MapNumber], a
  797.  
  798. .SkipEntei:
  799. ld a, [wRoamMon3MapGroup]
  800. cp GROUP_N_A
  801. jr z, .Finished
  802. call JumpRoamMon
  803. ld a, b
  804. ld [wRoamMon3MapGroup], a
  805. ld a, c
  806. ld [wRoamMon3MapNumber], a
  807.  
  808. .Finished:
  809. jp _BackUpMapIndices
  810.  
  811. JumpRoamMon:
  812. .loop
  813. ld hl, RoamMaps
  814. .innerloop1 ; This loop happens to be unnecessary.
  815. call Random ; Choose a random number.
  816. maskbits NUM_ROAMMON_MAPS ; Mask the number to limit it between 0 and 15.
  817. cp NUM_ROAMMON_MAPS ; If the number is not less than 16, try again.
  818. jr nc, .innerloop1 ; I'm sure you can guess why this check is bogus.
  819. inc a
  820. ld b, a
  821. .innerloop2 ; Loop to get hl to the address of the chosen roam map.
  822. dec b
  823. jr z, .ok
  824. .innerloop3 ; Loop to skip the current roam map, which is terminated by a 0.
  825. ld a, [hli]
  826. and a
  827. jr nz, .innerloop3
  828. jr .innerloop2
  829. ; Check to see if the selected map is the one the player is currently in. If so, try again.
  830. .ok
  831. ld a, [wMapGroup]
  832. cp [hl]
  833. jr nz, .done
  834. inc hl
  835. ld a, [wMapNumber]
  836. cp [hl]
  837. jr z, .loop
  838. dec hl
  839. ; Return the map group and number in bc.
  840. .done
  841. ld a, [hli]
  842. ld b, a
  843. ld c, [hl]
  844. ret
  845.  
  846. _BackUpMapIndices:
  847. ld a, [wRoamMons_CurMapNumber]
  848. ld [wRoamMons_LastMapNumber], a
  849. ld a, [wRoamMons_CurMapGroup]
  850. ld [wRoamMons_LastMapGroup], a
  851. ld a, [wMapNumber]
  852. ld [wRoamMons_CurMapNumber], a
  853. ld a, [wMapGroup]
  854. ld [wRoamMons_CurMapGroup], a
  855. ret
  856.  
  857. INCLUDE "data/wild/roammon_maps.asm"
  858.  
  859. ValidateTempWildMonSpecies:
  860. ; Due to a development oversight, this function is called with the wild Pokemon's level, not its species, in a.
  861. and a
  862. jr z, .nowildmon ; = 0
  863. cp NUM_POKEMON + 1 ; 252
  864. jr nc, .nowildmon ; >= 252
  865. and a ; 1 <= Species <= 251
  866. ret
  867.  
  868. .nowildmon
  869. scf
  870. ret
  871.  
  872. ; Finds a rare wild Pokemon in the route of the trainer calling, then checks if it's been Seen already.
  873. ; The trainer will then tell you about the Pokemon if you haven't seen it.
  874. RandomUnseenWildMon:
  875. farcall GetCallerLocation
  876. ld d, b
  877. ld e, c
  878. ld hl, JohtoGrassWildMons
  879. ld bc, GRASS_WILDDATA_LENGTH
  880. call LookUpWildmonsForMapDE
  881. jr c, .GetGrassmon
  882. ld hl, KantoGrassWildMons
  883. call LookUpWildmonsForMapDE
  884. jr nc, .done
  885.  
  886. .GetGrassmon:
  887. push hl
  888. ld bc, 5 + 4 * 2 ; Location of the level of the 5th wild Pokemon in that map
  889. add hl, bc
  890. ld a, [wTimeOfDay]
  891. ld bc, NUM_GRASSMON * 2
  892. call AddNTimes
  893. .randloop1
  894. call Random
  895. and %11
  896. jr z, .randloop1
  897. dec a
  898. ld c, a
  899. ld b, 0
  900. add hl, bc
  901. add hl, bc
  902. ; We now have the pointer to one of the last (rarest) three wild Pokemon found in that area.
  903. inc hl
  904. ld c, [hl] ; Contains the species index of this rare Pokemon
  905. pop hl
  906. ld de, 5 + 0 * 2
  907. add hl, de
  908. inc hl ; Species index of the most common Pokemon on that route
  909. ld b, 4
  910. .loop2
  911. ld a, [hli]
  912. cp c ; Compare this most common Pokemon with the rare one stored in c.
  913. jr z, .done
  914. inc hl
  915. dec b
  916. jr nz, .loop2
  917. ; This Pokemon truly is rare.
  918. push bc
  919. dec c
  920. ld a, c
  921. call CheckSeenMon
  922. pop bc
  923. jr nz, .done
  924. ; Since we haven't seen it, have the caller tell us about it.
  925. ld de, wStringBuffer1
  926. call CopyName1
  927. ld a, c
  928. ld [wNamedObjectIndexBuffer], a
  929. call GetPokemonName
  930. ld hl, .SawRareMonText
  931. call PrintText
  932. xor a
  933. ld [wScriptVar], a
  934. ret
  935.  
  936. .done
  937. ld a, $1
  938. ld [wScriptVar], a
  939. ret
  940.  
  941. .SawRareMonText:
  942. ; I just saw some rare @ in @ . I'll call you if I see another rare #MON, OK?
  943. text_far _JustSawSomeRareMonText
  944. text_end
  945.  
  946. RandomPhoneWildMon:
  947. farcall GetCallerLocation
  948. ld d, b
  949. ld e, c
  950. ld hl, JohtoGrassWildMons
  951. ld bc, GRASS_WILDDATA_LENGTH
  952. call LookUpWildmonsForMapDE
  953. jr c, .ok
  954. ld hl, KantoGrassWildMons
  955. call LookUpWildmonsForMapDE
  956.  
  957. .ok
  958. ld bc, 5 + 0 * 2
  959. add hl, bc
  960. ld a, [wTimeOfDay]
  961. inc a
  962. ld bc, NUM_GRASSMON * 2
  963. .loop
  964. dec a
  965. jr z, .done
  966. add hl, bc
  967. jr .loop
  968.  
  969. .done
  970. call Random
  971. and %11
  972. ld c, a
  973. ld b, 0
  974. add hl, bc
  975. add hl, bc
  976. inc hl
  977. ld a, [hl]
  978. ld [wNamedObjectIndexBuffer], a
  979. call GetPokemonName
  980. ld hl, wStringBuffer1
  981. ld de, wStringBuffer4
  982. ld bc, MON_NAME_LENGTH
  983. jp CopyBytes
  984.  
  985. RandomPhoneMon:
  986. ; Get a random monster owned by the trainer who's calling.
  987. farcall GetCallerLocation
  988. ld hl, TrainerGroups
  989. ld a, d
  990. dec a
  991. ld c, a
  992. ld b, 0
  993. add hl, bc
  994. add hl, bc
  995. ld a, BANK(TrainerGroups)
  996. call GetFarHalfword
  997.  
  998. .skip_trainer
  999. dec e
  1000. jr z, .skipped
  1001. .skip
  1002. ld a, BANK(Trainers)
  1003. call GetFarByte
  1004. inc hl
  1005. cp -1
  1006. jr nz, .skip
  1007. jr .skip_trainer
  1008. .skipped
  1009.  
  1010. .skip_name
  1011. ld a, BANK(Trainers)
  1012. call GetFarByte
  1013. inc hl
  1014. cp "@"
  1015. jr nz, .skip_name
  1016.  
  1017. ld a, BANK(Trainers)
  1018. call GetFarByte
  1019. inc hl
  1020. ld bc, 2 ; level, species
  1021. cp TRAINERTYPE_NORMAL
  1022. jr z, .got_mon_length
  1023. ld bc, 2 + NUM_MOVES ; level, species, moves
  1024. cp TRAINERTYPE_MOVES
  1025. jr z, .got_mon_length
  1026. ld bc, 2 + 1 ; level, species, item
  1027. cp TRAINERTYPE_ITEM
  1028. jr z, .got_mon_length
  1029. ; TRAINERTYPE_ITEM_MOVES
  1030. ld bc, 2 + 1 + NUM_MOVES ; level, species, item, moves
  1031. .got_mon_length
  1032.  
  1033. ld e, 0
  1034. push hl
  1035. .count_mon
  1036. inc e
  1037. add hl, bc
  1038. ld a, BANK(Trainers)
  1039. call GetFarByte
  1040. cp -1
  1041. jr nz, .count_mon
  1042. pop hl
  1043.  
  1044. .rand
  1045. call Random
  1046. maskbits PARTY_LENGTH
  1047. cp e
  1048. jr nc, .rand
  1049.  
  1050. inc a
  1051. .get_mon
  1052. dec a
  1053. jr z, .got_mon
  1054. add hl, bc
  1055. jr .get_mon
  1056. .got_mon
  1057.  
  1058. inc hl ; species
  1059. ld a, BANK(Trainers)
  1060. call GetFarByte
  1061. ld [wNamedObjectIndexBuffer], a
  1062. call GetPokemonName
  1063. ld hl, wStringBuffer1
  1064. ld de, wStringBuffer4
  1065. ld bc, MON_NAME_LENGTH
  1066. jp CopyBytes
  1067.  
  1068. INCLUDE "data/wild/johto_grass.asm"
  1069. INCLUDE "data/wild/johto_water.asm"
  1070. INCLUDE "data/wild/kanto_grass.asm"
  1071. INCLUDE "data/wild/kanto_water.asm"
  1072. INCLUDE "data/wild/swarm_grass.asm"
  1073. INCLUDE "data/wild/swarm_water.asm"
  1074. INCLUDE "data/wild/johto_shallow.asm"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement