2015-04-01 09:23:27 +00:00
|
|
|
; try to initiate a wild pokemon encounter
|
|
|
|
; returns success in Z
|
|
|
|
TryDoWildEncounter: ; 13870 (4:7870)
|
|
|
|
ld a, [wNPCMovementScriptPointerTableNum]
|
|
|
|
and a
|
|
|
|
ret nz
|
|
|
|
ld a, [wd736]
|
|
|
|
and a
|
|
|
|
ret nz
|
|
|
|
callab IsPlayerStandingOnDoorTileOrWarpTile
|
|
|
|
jr nc, .notStandingOnDoorOrWarpTile
|
|
|
|
.CantEncounter
|
|
|
|
ld a, $1
|
|
|
|
and a
|
|
|
|
ret
|
|
|
|
.notStandingOnDoorOrWarpTile
|
|
|
|
callab IsPlayerJustOutsideMap
|
|
|
|
jr z, .CantEncounter
|
|
|
|
ld a, [wRepelRemainingSteps]
|
|
|
|
and a
|
2015-07-24 03:48:35 +00:00
|
|
|
jr z, .next
|
2015-04-01 09:23:27 +00:00
|
|
|
dec a
|
|
|
|
jr z, .lastRepelStep
|
|
|
|
ld [wRepelRemainingSteps], a
|
2015-07-24 03:48:35 +00:00
|
|
|
.next
|
2015-06-11 22:41:33 +00:00
|
|
|
; determine if wild pokemon can appear in the half-block we're standing in
|
2015-04-01 09:23:27 +00:00
|
|
|
; is the bottom right tile (9,9) of the half-block we're standing in a grass/water tile?
|
2015-07-18 20:52:03 +00:00
|
|
|
coord hl, 9, 9
|
2015-04-01 09:23:27 +00:00
|
|
|
ld c, [hl]
|
|
|
|
ld a, [W_GRASSTILE]
|
|
|
|
cp c
|
|
|
|
ld a, [W_GRASSRATE]
|
|
|
|
jr z, .CanEncounter
|
|
|
|
ld a, $14 ; in all tilesets with a water tile, this is its id
|
|
|
|
cp c
|
|
|
|
ld a, [W_WATERRATE]
|
|
|
|
jr z, .CanEncounter
|
2015-06-05 04:01:40 +00:00
|
|
|
; even if not in grass/water, standing anywhere we can encounter pokemon
|
|
|
|
; so long as the map is "indoor" and has wild pokemon defined.
|
|
|
|
; ...as long as it's not Viridian Forest or Safari Zone.
|
2015-04-01 09:23:27 +00:00
|
|
|
ld a, [W_CURMAP]
|
|
|
|
cp REDS_HOUSE_1F ; is this an indoor map?
|
|
|
|
jr c, .CantEncounter2
|
|
|
|
ld a, [W_CURMAPTILESET]
|
|
|
|
cp FOREST ; Viridian Forest/Safari Zone
|
|
|
|
jr z, .CantEncounter2
|
|
|
|
ld a, [W_GRASSRATE]
|
|
|
|
.CanEncounter
|
|
|
|
; compare encounter chance with a random number to determine if there will be an encounter
|
|
|
|
ld b, a
|
|
|
|
ld a, [hRandomAdd]
|
|
|
|
cp b
|
|
|
|
jr nc, .CantEncounter2
|
|
|
|
ld a, [hRandomSub]
|
|
|
|
ld b, a
|
|
|
|
ld hl, WildMonEncounterSlotChances
|
|
|
|
.determineEncounterSlot
|
|
|
|
ld a, [hli]
|
|
|
|
cp b
|
|
|
|
jr nc, .gotEncounterSlot
|
|
|
|
inc hl
|
|
|
|
jr .determineEncounterSlot
|
|
|
|
.gotEncounterSlot
|
2015-06-05 04:01:40 +00:00
|
|
|
; determine which wild pokemon (grass or water) can appear in the half-block we're standing in
|
2015-04-01 09:23:27 +00:00
|
|
|
ld c, [hl]
|
|
|
|
ld hl, W_GRASSMONS
|
2015-06-11 22:41:33 +00:00
|
|
|
aCoord 8, 9
|
|
|
|
cp $14 ; is the bottom left tile (8,9) of the half-block we're standing in a water tile?
|
2015-04-01 09:23:27 +00:00
|
|
|
jr nz, .gotWildEncounterType ; else, it's treated as a grass tile by default
|
|
|
|
ld hl, W_WATERMONS
|
|
|
|
; since the bottom right tile of a "left shore" half-block is $14 but the bottom left tile is not,
|
2015-06-11 22:41:33 +00:00
|
|
|
; "left shore" half-blocks (such as the one in the east coast of Cinnabar) load grass encounters.
|
2015-04-01 09:23:27 +00:00
|
|
|
.gotWildEncounterType
|
2015-07-24 03:48:35 +00:00
|
|
|
ld b, 0
|
2015-04-01 09:23:27 +00:00
|
|
|
add hl, bc
|
|
|
|
ld a, [hli]
|
|
|
|
ld [W_CURENEMYLVL], a
|
|
|
|
ld a, [hl]
|
|
|
|
ld [wcf91], a
|
|
|
|
ld [wEnemyMonSpecies2], a
|
|
|
|
ld a, [wRepelRemainingSteps]
|
|
|
|
and a
|
|
|
|
jr z, .willEncounter
|
|
|
|
ld a, [wPartyMon1Level]
|
|
|
|
ld b, a
|
|
|
|
ld a, [W_CURENEMYLVL]
|
|
|
|
cp b
|
|
|
|
jr c, .CantEncounter2 ; repel prevents encounters if the leading party mon's level is higher than the wild mon
|
|
|
|
jr .willEncounter
|
|
|
|
.lastRepelStep
|
|
|
|
ld [wRepelRemainingSteps], a
|
2015-07-24 03:48:35 +00:00
|
|
|
ld a, TEXT_REPEL_WORE_OFF
|
|
|
|
ld [hSpriteIndexOrTextID], a
|
2015-04-01 09:23:27 +00:00
|
|
|
call EnableAutoTextBoxDrawing
|
|
|
|
call DisplayTextID
|
|
|
|
.CantEncounter2
|
|
|
|
ld a, $1
|
|
|
|
and a
|
|
|
|
ret
|
|
|
|
.willEncounter
|
|
|
|
xor a
|
|
|
|
ret
|
|
|
|
|
|
|
|
WildMonEncounterSlotChances: ; 13918 (4:7918)
|
|
|
|
; There are 10 slots for wild pokemon, and this is the table that defines how common each of
|
|
|
|
; those 10 slots is. A random number is generated and then the first byte of each pair in this
|
|
|
|
; table is compared against that random number. If the random number is less than or equal
|
|
|
|
; to the first byte, then that slot is chosen. The second byte is double the slot number.
|
|
|
|
db $32, $00 ; 51/256 = 19.9% chance of slot 0
|
|
|
|
db $65, $02 ; 51/256 = 19.9% chance of slot 1
|
|
|
|
db $8C, $04 ; 39/256 = 15.2% chance of slot 2
|
|
|
|
db $A5, $06 ; 25/256 = 9.8% chance of slot 3
|
|
|
|
db $BE, $08 ; 25/256 = 9.8% chance of slot 4
|
|
|
|
db $D7, $0A ; 25/256 = 9.8% chance of slot 5
|
|
|
|
db $E4, $0C ; 13/256 = 5.1% chance of slot 6
|
|
|
|
db $F1, $0E ; 13/256 = 5.1% chance of slot 7
|
|
|
|
db $FC, $10 ; 11/256 = 4.3% chance of slot 8
|
|
|
|
db $FF, $12 ; 3/256 = 1.2% chance of slot 9
|